v3: keep the module of selectively imported generics in global types - #28946
Open
medvednikov wants to merge 1 commit into
Open
medvednikov wants to merge 1 commit into
medvednikov wants to merge 1 commit into
Conversation
With `import foo { Foo }`, a module global `__global g Foo[Bar]` was
emitted as `Foo_bar__Bar` instead of `foo__Foo_bar__Bar`, so the C
output failed to compile.
cgen parses global types after monomorphization has erased the generic
struct templates from `structs`, so the selective import lookup no
longer recognized `foo.Foo` and fell back to the bare name. Accept
candidates that are still known as generic struct templates.
The transformer also normalized global types without the declaring
file set, which skipped the file's selective imports and broke
expressions such as `g_map['a'].iter()`. Normalize them in the
declaring file and module.
Fixes #28881
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
import foo { Foo }in modulebar, a module global__global bar_value Foo[Bar]was emitted asFoo_bar__Barinstead offoo__Foo_bar__Bar, so the generated C failed withunknown type name 'Foo_bar__Bar'. Spelling the type asfoo.Foo[Bar]worked. There were two gaps, and each change below is needed on its own.resolve_selective_import_type_symbol): cgen reads global types after monomorphization has erased generic struct templates such asfoo.Foofromstructs. The selective import lookup then no longer recognizedfoo.Fooand fell back to the bareFoo. It now also accepts candidates that are still known as generic struct templates (struct_generic_params). Candidates are tried in the same order as before, so nothing that resolved before resolves differently. This alone fixes the reported iterator case.collect_types): global types were normalized without the declaring file set, so the file's selective imports were ignored. For example,bar_by_name['a'].iter()on amap[string]Foo[Bar]global still failed withuse of undeclared identifier 'Foo_bar__Bar'. They are now normalized withcur_file/cur_moduleset to the declaring file and module, using the same save/restore pattern as elsewhere in the transformer.Fixes #28881
Validation
All runs use
V_MACOS_V3_NO_FALLBACK=1, so a V3 failure is not hidden by the compatibility fallback.New
vlib/v/tests/selective_import_generic_global_28881/:Foo[Bar],[]Foo[Bar],map[string]Foo[Bar], a plain struct andPair[string, Bar], all named only through a selective import;1/1 passed; it fails on master.
./v -silent vlib/v/compiler_errors_test.v: 1721 passed, 0 failed./v -silent test vlib/v/gen/c/: 27/27 passed./v -silent test vlib/v/transform/: 17/17 passedvlib/v/types/*_test.v(withoutchecker_ownership_alias_test.v, which hangs on master, V3: checker_ownership_alias_test.v never finishes compiling (-d ownership compiler spins at 100% CPU) #28923): 30/30 passed./v -silent test vlib/v/tests/generics/: 320 passed, 1 failed (generic_sort_multi_instantiation_test.v, same failure on master)The 41
vlib/v/testsfiles that use__globalor selective imports: 41/41 passed