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

[WIP] Pervasive replacement of nkRecWhen in generic types #8748

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

LemonBoy
Copy link
Contributor

Long story short, even if the type contains no reference at all to its
generic parameters we still have to walk its AST and evaluate any
nkRecWhen nodes that semRecordNodeAux skipped due to the type being a
generic one.

We also must be careful to modify the type n node in place since it
may be referenced by the caller as seen in the tillegaltyperecursion
test.

I found this to be the nicest solution to the problem, we can't perform this resolution before the type is fully constructed as some when statements may refer to generic parameters and performing yet another (it'd be the third) pass over the type in order to resolve the remaining nkRecWhen is not that nice performance-wise.

This fixes #8417 and half of #7378.

@zah
Copy link
Member

zah commented Aug 23, 2018

Hrm, OK, but we could also have changed the definition of containsGenericType to take into account the problematic when branches.

@LemonBoy LemonBoy changed the title Pervasive replacement of nkRecWhen in generic types [WIP] Pervasive replacement of nkRecWhen in generic types Aug 23, 2018
@@ -185,6 +218,11 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode =
for i in countup(0, sonsLen(n) - 1):
var it = n.sons[i]
if it == nil: illFormedAst(n, cl.c.config)
if mdbg:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this debug code.

@@ -198,6 +236,9 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode =
if branch == nil: branch = it.sons[0]
else: illFormedAst(n, cl.c.config)
if branch != nil:
if mdbg:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this debug code.

var branch: PNode = nil # the branch to take
for i in countup(0, sonsLen(n) - 1):
var it = n.sons[i]
if mdbg:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this debug code.

Long story short, even if the type contains no reference at all to its
generic parameters we still have to walk its AST and evaluate any
nkRecWhen nodes that semRecordNodeAux skipped due to the type being a
generic one.

We also must be careful to modify the type `n` node in place since it
may be referenced by the caller as seen in the tillegaltyperecursion
test.

Moreover we also can't have the nkSym drift away from their original
values in order not to break the JS nkObjConstr codegen.
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.

Compiler crash when X[A: static[int]]'s body is dependent on another const
3 participants