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

fixes #16246 #18800

Merged
merged 1 commit into from
Sep 4, 2021
Merged

fixes #16246 #18800

merged 1 commit into from
Sep 4, 2021

Conversation

Araq
Copy link
Member

@Araq Araq commented Sep 4, 2021

No description provided.

@@ -1144,6 +1145,13 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
result = sameFlags(a, b)
if result and PickyCAliases in c.flags:
# additional requirement for the caching of generics for importc'ed types:
# the symbols must be identical too:
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that I should learn: Why is checking the flags here equivalent to the symbols being identical? Is it just because we have checked for equality of the actual type etc. before in this proc?

Also it seems confusing that sameFlags is called before, but then we check more flags here.

In general what makes reading compiler code hard for me is that most procs have no short comment about their intent, e.g. this sameTypeAux could use a couple of lines saying what is needed for a type to be considered the same for instance.

Copy link
Member Author

@Araq Araq Sep 4, 2021

Choose a reason for hiding this comment

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

Given that I should learn: Why is checking the flags here equivalent to the symbols being identical? Is it just because we have checked for equality of the actual type etc. before in this proc?

Because we have established they are of the type kind which for tyInt etc means they are atomic types. Arguably we could also have checked for a.sym == b.sym instead but this would be worse for type aliases to cint, e.g. type myint = cint.

Also it seems confusing that sameFlags is called before, but then we check more flags here.

sameFlags looks at the type flags but importc is stored as a sym flag. These are different things.

this sameTypeAux could use a couple of lines saying what is needed for a type to be considered the same for instance.

Nim's type system has both structural and nominal type system aspects and type equality is supposed to follow from the spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification!

@Vindaar
Copy link
Contributor

Vindaar commented Sep 4, 2021

Thanks a lot! I just tested the changes locally and indeed it fixes the issue here as well in a different (but similar) piece of code than the one originally shown in the issue.

It also fixes the problem I reported for the C++ backend that happened without ARC interestingly enough.

@Araq
Copy link
Member Author

Araq commented Sep 4, 2021

It also fixes the problem I reported for the C++ backend that happened without ARC interestingly enough.

That is not unexpected as Orc only made the bug manifest in a novel way, the bug was there from the beginning, more or less.

@Araq Araq merged commit e8dad48 into devel Sep 4, 2021
@Araq Araq deleted the araq-fixes-16246 branch September 4, 2021 13:57
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
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.

2 participants