-
Notifications
You must be signed in to change notification settings - Fork 405
Fix a cyclic reference issue while checking type constraints #9632
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
base: master
Are you sure you want to change the base?
Conversation
based on PR shader-slang#9632 compiler fix.
based on PR shader-slang#9632 compiler fix.
based on PR shader-slang#9632 compiler fix.
ad07abf to
1782402
Compare
based on PR shader-slang#9632 compiler fix.
jkwak-work
left a comment
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.
It looks reasonable enough.
But I am not familiar enough to tell if there is a better way to solve the problem or not.
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 want to get to the bottom of the type constraint checking process and investigate why we are checking the generic parent again during checking the generic constraints, since this shouldn't happen.
When we check where Foo : IFoo<U>, the first two constraints should have already been checked and we should already have the inheritance info for U and U.Differential, so checking IFoo<U> shouldn't trigger recalculation of inheritance info of U.
A possible cause is that while checking generic constraints, we were disabling caching of inheritance info because a following constraint can add more facets to a generic type parameter. It feels to me that instead of disabling caching completely, we should just incrementally update the inheritance info of the constrained type.
|
|
||
| void removeInheritanceInfoFromCache(DeclRef<Decl>& key) | ||
| { | ||
| if (m_mapDeclRefToInheritanceInfo.tryGetValue(key)) |
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 believe we can just call remove directly without checking existence first.
based on PR shader-slang#9632 compiler fix.
based on PR #9632 compiler fix.
|
Mark this to draft, as we might need further refactor to get a better fix for this issue. |
Close #9622.
The root cause of this issue is that we diagnose the error too early when collecting the inheritance info of a generic type parameter, because some of the checking might not be ready. Assume this case:
this code will report error that
typeof(S)doesn't have member ofDifferential. That is because we checkFoo.DifferentialwhileFoo : IFoo<U>is being checked.The reason of this is because of following sequence:
Foo : IFoo<U>IFoo<U>: it will find a candidate -IFoo<T> T:XXX where T.Differential == TU.DifferentialNow in collecting the inheritance info of
U.Differential, we will find the dependent generic parent ofU, which is thefuncagain, so we will check all the type constraints offunc, and finally it will start checkingFoo.Differential : IFoo<U.Differential>. But note thatFoo : IFoo<U>is still being checked now, so theFoo's type is unknown, we cannot lookup the member ofDifferential. Therefore, error will be reported.The current solution for this issue is that we will use subVisitor to suppress the error in this case because it's ok to have error in this case. If there is error, the inheritance info will be incomplete, then the upper level caller will also fail because it can't find all the type constraints to satisfy the requirement. And we also disable the cache in this case, so in the later inheritance info collection when every thing is ready, there will still be chance to get the complete inheritance info.