-
Notifications
You must be signed in to change notification settings - Fork 381
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
fix: remove import cycles #3304
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
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) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these cases should be catchable already by the cyclic-import detector in the store; can you take a look at what's going on there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by the cyclic-import detector in the store
, the Store
in gnovm/pkg/test/imports.go
does not seem to have cycle detection
FYI the self-import in faucet had been there for 2 years
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah no apologies I thought about it for two seconds and you're right (because the import will not consider any _test.go files, correctly so)
the store has cyclic import detection, see pkg/gnolang/store.go:
gno/gnovm/pkg/gnolang/store.go
Lines 214 to 225 in 5c31552
// Gets package from cache, or loads it from baseStore, or gets it from package getter. | |
func (ds *defaultStore) GetPackage(pkgPath string, isImport bool) *PackageValue { | |
// helper to detect circular imports | |
if isImport { | |
if slices.Contains(ds.current, pkgPath) { | |
panic(fmt.Sprintf("import cycle detected: %q (through %v)", pkgPath, ds.current)) | |
} | |
ds.current = append(ds.current, pkgPath) | |
defer func() { | |
ds.current = ds.current[:len(ds.current)-1] | |
}() | |
} |
// find stdlibs | ||
libs := []string{} | ||
gnoRoot := gnoenv.RootDir() | ||
stdlibsDir := filepath.Join(gnoRoot, "gnovm", "stdlibs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for stdlibs, instead, i think you could change misc/genstd
(note: this binary as well, if it were to stay, would also have to be misc/), by having its import order generator also consider test files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, when I cherry-pick c6728c5 on master, I get:
go run github.com/gnolang/gno/misc/genstd
panic: cyclical package initialization on "bytes" (bytes -> io -> bytes)
I like having code that is dedicated to detecting any cycles in stdlibs and examples though, I'll move the nocycles
code into a test somewhere I think when I get to the polishing step on this PR
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
WIP
contribs/nocycles
binary to detect import cycles in stdlibs and examplesGo 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.
NOTES:
testing
should have non-external tests to avoid a cycle ontesting
TODO: