Skip to content
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 sym of created generic instantiation type #22642

Merged
merged 5 commits into from
Sep 5, 2023

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Sep 4, 2023

fixes #22639

A tyGenericInst has its last son as the instantiated body of the original generic type. However this type keeps its original sym field from the original generic types, which means the sym's type is uninstantiated. This causes problems in the implementation of getType, where it uses the sym fields of types to represent them in AST, the relevant example for the issue being here called from here.

To fix this, create a new symbol from the original symbol for the instantiated body during the creation of tyGenericInsts with the appropriate type. Normally replaceTypeVarsS would be used for this, but here it seems to cause some recursion issue (immediately gives an error like "cannot instantiate HSlice[T, U]"), so we directly set the symbol's type to the instantiated type.

Avoiding recursion means we also cannot use replaceTypeVarsN for the symbol AST, and the symbol not having any AST crashes the implementation of getType again here, so the symbol AST is set to the original generic type AST for now which is what it was before anyway.

Not sure about this because not sure why the recursion issue is happening, putting it at the end of the proc doesn't help either. Also not sure if the cl.owner != nil and s.owner != cl.owner condition from replaceTypeVarsS is relevant here. This might also break some code if it depended on the original generic type symbol being given.

compiler/semtypinst.nim Outdated Show resolved Hide resolved
@Araq Araq merged commit 6000cc8 into nim-lang:devel Sep 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 6000cc8

Hint: mm: orc; opt: speed; options: -d:release
169682 lines; 9.123s; 758.547MiB peakmem

ringabout added a commit that referenced this pull request Sep 5, 2023
metagn added a commit to metagn/Nim that referenced this pull request Sep 5, 2023
metagn added a commit to metagn/Nim that referenced this pull request Sep 5, 2023
alaviss added a commit to alaviss/union that referenced this pull request Sep 5, 2023
Previously we performed tests against Union symbol itself to check
for inheritance.

This relied on an implementation detail where an instance of a generic
has the same type as the generic type itself.

Recent changes in the compiler shows that we cannot rely on this. Thus
the module now opt for inheriting from and testing against a pre-defined
instance of Union.

Ref nim-lang/Nim#22642
Fixes #51
alaviss added a commit to alaviss/union that referenced this pull request Sep 5, 2023
Previously we performed tests against Union symbol itself to check
for inheritance.

This relied on an implementation detail where an instance of a generic
in the AST uses the same symbol as the generic type.

The PR nim-lang/Nim#22642 changed this
implementation detail. So now, we have to account for both cases of new
and old compilers by also testing against a pre-defined instance.

Fixes #51
metagn added a commit that referenced this pull request Sep 6, 2023
reverts #22642, reopens #22639, closes #22646, refs #22650, refs
alaviss/union#51, refs #22652

The fallout is too much from #22642, we can come back to it if we can
account for all the affected code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sizeof for static arrays can yield wrong results
2 participants