Disable the new generic params handling for immediate template and macros
Since immediate templates are not subjected to the standard sigmatching algorithm, they will have a number of deficiencies when it comes to generic params: Type dependencies between the parameters won't be honoured and the bound generic symbols won't be resolvable within their bodies. We could try to fix this, but it may be wiser to just deprecate immediate templates and macros now that we have working untyped parameters. Disabling the new features is admittedly not the greatest way to handle this situations as it introduces inconsistency in the language, but at least it makes the code backwards-compatible with the previous version of the compiler instead of triggering more serious problems.
This commit is contained in:
parent
02f97489b7
commit
fe124ceadc
3 changed files with 21 additions and 6 deletions
|
|
@ -66,7 +66,16 @@ proc evalTemplateArgs(n: PNode, s: PSym): PNode =
|
||||||
else: 0
|
else: 0
|
||||||
|
|
||||||
var
|
var
|
||||||
genericParams = s.ast[genericParamsPos].len
|
# XXX: Since immediate templates are not subjected to the
|
||||||
|
# standard sigmatching algorithm, they will have a number
|
||||||
|
# of deficiencies when it comes to generic params:
|
||||||
|
# Type dependencies between the parameters won't be honoured
|
||||||
|
# and the bound generic symbols won't be resolvable within
|
||||||
|
# their bodies. We could try to fix this, but it may be
|
||||||
|
# wiser to just deprecate immediate templates and macros
|
||||||
|
# now that we have working untyped parameters.
|
||||||
|
genericParams = if sfImmediate in s.flags: 0
|
||||||
|
else: s.ast[genericParamsPos].len
|
||||||
expectedRegularParams = <s.typ.len
|
expectedRegularParams = <s.typ.len
|
||||||
givenRegularParams = totalParams - genericParams
|
givenRegularParams = totalParams - genericParams
|
||||||
|
|
||||||
|
|
@ -81,6 +90,7 @@ proc evalTemplateArgs(n: PNode, s: PSym): PNode =
|
||||||
# not supplied by the user
|
# not supplied by the user
|
||||||
for i in givenRegularParams+1 .. expectedRegularParams:
|
for i in givenRegularParams+1 .. expectedRegularParams:
|
||||||
let default = s.typ.n.sons[i].sym.ast
|
let default = s.typ.n.sons[i].sym.ast
|
||||||
|
internalAssert default != nil
|
||||||
if default.kind == nkEmpty:
|
if default.kind == nkEmpty:
|
||||||
localError(n.info, errWrongNumberOfArguments)
|
localError(n.info, errWrongNumberOfArguments)
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
|
|
|
||||||
|
|
@ -1521,10 +1521,11 @@ proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode =
|
||||||
for i in 1.. <sym.typ.len:
|
for i in 1.. <sym.typ.len:
|
||||||
tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i])
|
tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i])
|
||||||
|
|
||||||
let gp = sym.ast[genericParamsPos]
|
if sfImmediate notin sym.flags:
|
||||||
for i in 0 .. <gp.len:
|
let gp = sym.ast[genericParamsPos]
|
||||||
let idx = sym.typ.len + i
|
for i in 0 .. <gp.len:
|
||||||
tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ)
|
let idx = sym.typ.len + i
|
||||||
|
tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ)
|
||||||
|
|
||||||
# temporary storage:
|
# temporary storage:
|
||||||
#for i in L .. <maxSlots: tos.slots[i] = newNode(nkEmpty)
|
#for i in L .. <maxSlots: tos.slots[i] = newNode(nkEmpty)
|
||||||
|
|
|
||||||
|
|
@ -1845,9 +1845,13 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.prc = p
|
c.prc = p
|
||||||
# iterate over the parameters and allocate space for them:
|
# iterate over the parameters and allocate space for them:
|
||||||
genParams(c, s.typ.n)
|
genParams(c, s.typ.n)
|
||||||
|
|
||||||
# allocate additional space for any generically bound parameters
|
# allocate additional space for any generically bound parameters
|
||||||
if s.kind == skMacro and s.ast[genericParamsPos].kind != nkEmpty:
|
if s.kind == skMacro and
|
||||||
|
sfImmediate notin s.flags and
|
||||||
|
s.ast[genericParamsPos].kind != nkEmpty:
|
||||||
genGenericParams(c, s.ast[genericParamsPos])
|
genGenericParams(c, s.ast[genericParamsPos])
|
||||||
|
|
||||||
if tfCapturesEnv in s.typ.flags:
|
if tfCapturesEnv in s.typ.flags:
|
||||||
#let env = s.ast.sons[paramsPos].lastSon.sym
|
#let env = s.ast.sons[paramsPos].lastSon.sym
|
||||||
#assert env.position == 2
|
#assert env.position == 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue