Skip to content

fix: remove import cycles #3304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 89 commits into from
Jan 23, 2025
Merged

Conversation

n0izn0iz
Copy link
Contributor

@n0izn0iz n0izn0iz commented Dec 8, 2024

Depends on #3323

  • add test in examples/no_cycles_test.go to detect import cycles in stdlibs and examples
  • add matchString native injection in the testing stdlib to avoid a cycle in regexp tests
  • remove other import cycles

Go never allows import cycles. Our stdlibs have a lot of import cycles, and some examples import self which is not allowed in golang either.
Keeping support for import cycles in stdlib and importing self will require a lot of hacky and weird logic in generic package loading code so I try to tackle this first.

TODO:

  • fix tests
  • check cycles with the test stdlibs overlay applied -> be explicit about the lack of support for modifying imports in testing stdlibs overlay

@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related labels Dec 8, 2024
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Dec 8, 2024

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: n0izn0iz/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

Attention: Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/tests/stdlibs/testing/native_testing.go 50.00% 2 Missing and 1 partial ⚠️
gnovm/stdlibs/testing/testing.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@n0izn0iz n0izn0iz marked this pull request as ready for review January 9, 2025 21:13
@n0izn0iz n0izn0iz requested a review from thehowl January 9, 2025 21:18
albttx pushed a commit that referenced this pull request Jan 10, 2025
This makes the imports utils split imports by file kinds, allowing to
make explicit decisions about what imports to use at the various
callsites

- Create `FileKind` enum to categorize gno files, with variants
`PackageSource`, `Test`, `XTest` and `Filetest`
- Create `GetFileKind` util to derive the `FileKind` from a file name
and body
- Create `ImportsMap` type that maps `FileKind`s to lists of imports. It
has a single method `Merge` to select and merge various imports from
multiple `FileKind`s
- Modify the`packages.Imports` helper to return an `ImportsMap` instead
of a `[]string` and adapt callsites by using`ImportMap.Merge` to
preserve existing behavior

This is something I need for #3304 and #2932 but to help reviews I made
an atomic PR here instead

---------

Signed-off-by: Norman Meier <[email protected]>
Co-authored-by: Morgan <[email protected]>
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the non-trivial changes, good overall.

@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 21, 2025
@jefft0 jefft0 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 22, 2025
@jefft0
Copy link
Contributor

jefft0 commented Jan 22, 2025

Removed the review/triage-pending label because this PR was reviewed by core dev thehowl.

@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 22, 2025
@Gno2D2 Gno2D2 requested a review from a team January 23, 2025 16:36
@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 23, 2025
@Gno2D2 Gno2D2 requested a review from a team January 23, 2025 16:42
@thehowl thehowl merged commit fd24486 into gnolang:master Jan 23, 2025
71 of 72 checks passed
stefann-01 pushed a commit to stefann-01/gno that referenced this pull request Jan 24, 2025
Depends on gnolang#3323 

- add test in `examples/no_cycles_test.go` to detect import cycles in
stdlibs and examples
- add `matchString` native injection in the `testing` stdlib to avoid a
cycle in `regexp` tests
- remove other import cycles

Go never allows import cycles. Our stdlibs have a lot of import cycles,
and some examples import self which is not allowed in golang either.
Keeping support for import cycles in stdlib and importing self will
require a lot of hacky and weird logic in generic package loading code
so I try to tackle this first.

TODO:

- [x] fix tests
- [x] ~~check cycles with the test stdlibs overlay applied~~ -> be
explicit about the lack of support for modifying imports in testing
stdlibs overlay

---------

Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman <[email protected]>
Signed-off-by: Norman <[email protected]>
Co-authored-by: Morgan <[email protected]>
Co-authored-by: Norman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Development

Successfully merging this pull request may close these issues.

5 participants