usage of NimNode triggers .compileTime context; fixes #1679
This commit is contained in:
parent
14354b436f
commit
612cd25d5d
5 changed files with 16 additions and 2 deletions
|
|
@ -477,6 +477,8 @@ type
|
||||||
# wildcard type.
|
# wildcard type.
|
||||||
tfHasAsgn # type has overloaded assignment operator
|
tfHasAsgn # type has overloaded assignment operator
|
||||||
tfBorrowDot # distinct type borrows '.'
|
tfBorrowDot # distinct type borrows '.'
|
||||||
|
tfTriggersCompileTime # uses the NimNode type which make the proc
|
||||||
|
# implicitly '.compiletime'
|
||||||
|
|
||||||
TTypeFlags* = set[TTypeFlag]
|
TTypeFlags* = set[TTypeFlag]
|
||||||
|
|
||||||
|
|
@ -1380,6 +1382,9 @@ proc propagateToOwner*(owner, elem: PType) =
|
||||||
o2.flags.incl tfHasAsgn
|
o2.flags.incl tfHasAsgn
|
||||||
owner.flags.incl tfHasAsgn
|
owner.flags.incl tfHasAsgn
|
||||||
|
|
||||||
|
if tfTriggersCompileTime in elem.flags:
|
||||||
|
owner.flags.incl tfTriggersCompileTime
|
||||||
|
|
||||||
if owner.kind notin {tyProc, tyGenericInst, tyGenericBody,
|
if owner.kind notin {tyProc, tyGenericInst, tyGenericBody,
|
||||||
tyGenericInvocation, tyPtr}:
|
tyGenericInvocation, tyPtr}:
|
||||||
let elemB = elem.skipTypes({tyGenericInst})
|
let elemB = elem.skipTypes({tyGenericInst})
|
||||||
|
|
|
||||||
|
|
@ -1741,6 +1741,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
of mEcho: genEcho(p, e[1].skipConv)
|
of mEcho: genEcho(p, e[1].skipConv)
|
||||||
of mArrToSeq: genArrToSeq(p, e, d)
|
of mArrToSeq: genArrToSeq(p, e, d)
|
||||||
of mNLen..mNError, mSlurp..mQuoteAst:
|
of mNLen..mNError, mSlurp..mQuoteAst:
|
||||||
|
echo "from here ", p.prc.name.s, " ", p.prc.info
|
||||||
|
writestacktrace()
|
||||||
localError(e.info, errXMustBeCompileTime, e.sons[0].sym.name.s)
|
localError(e.info, errXMustBeCompileTime, e.sons[0].sym.name.s)
|
||||||
of mSpawn:
|
of mSpawn:
|
||||||
let n = lowerings.wrapProcForSpawn(p.module.module, e, e.typ, nil, nil)
|
let n = lowerings.wrapProcForSpawn(p.module.module, e, e.typ, nil, nil)
|
||||||
|
|
@ -1973,6 +1975,9 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
genProc(p.module, sym)
|
genProc(p.module, sym)
|
||||||
putLocIntoDest(p, d, sym.loc)
|
putLocIntoDest(p, d, sym.loc)
|
||||||
of skProc, skConverter, skIterators:
|
of skProc, skConverter, skIterators:
|
||||||
|
if sfCompileTime in sym.flags:
|
||||||
|
localError(n.info, "request to generate code for .compileTime proc: " &
|
||||||
|
sym.name.s)
|
||||||
genProc(p.module, sym)
|
genProc(p.module, sym)
|
||||||
if sym.loc.r == nil or sym.loc.t == nil:
|
if sym.loc.r == nil or sym.loc.t == nil:
|
||||||
internalError(n.info, "expr: proc not init " & sym.name.s)
|
internalError(n.info, "expr: proc not init " & sym.name.s)
|
||||||
|
|
@ -2126,7 +2131,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
# due to a bug/limitation in the lambda lifting, unused inner procs
|
# due to a bug/limitation in the lambda lifting, unused inner procs
|
||||||
# are not transformed correctly. We work around this issue (#411) here
|
# are not transformed correctly. We work around this issue (#411) here
|
||||||
# by ensuring it's no inner proc (owner is a module):
|
# by ensuring it's no inner proc (owner is a module):
|
||||||
if prc.skipGenericOwner.kind == skModule:
|
if prc.skipGenericOwner.kind == skModule and sfCompileTime notin prc.flags:
|
||||||
if (optDeadCodeElim notin gGlobalOptions and
|
if (optDeadCodeElim notin gGlobalOptions and
|
||||||
sfDeadCodeElim notin getModule(prc).flags) or
|
sfDeadCodeElim notin getModule(prc).flags) or
|
||||||
({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
|
({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
inc i
|
inc i
|
||||||
pushProcCon(c, result)
|
pushProcCon(c, result)
|
||||||
instantiateProcType(c, pt, result, info)
|
instantiateProcType(c, pt, result, info)
|
||||||
|
if tfTriggersCompileTime in result.typ.flags:
|
||||||
|
incl(result.flags, sfCompileTime)
|
||||||
n.sons[genericParamsPos] = ast.emptyNode
|
n.sons[genericParamsPos] = ast.emptyNode
|
||||||
var oldPrc = genericCacheGet(fn, entry[])
|
var oldPrc = genericCacheGet(fn, entry[])
|
||||||
if oldPrc == nil:
|
if oldPrc == nil:
|
||||||
|
|
|
||||||
|
|
@ -1132,6 +1132,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
# semParamList(c, n.sons[ParamsPos], nil, s)
|
# semParamList(c, n.sons[ParamsPos], nil, s)
|
||||||
else:
|
else:
|
||||||
s.typ = newProcType(c, n.info)
|
s.typ = newProcType(c, n.info)
|
||||||
|
if tfTriggersCompileTime in s.typ.flags: incl(s.flags, sfCompileTime)
|
||||||
if n.sons[patternPos].kind != nkEmpty:
|
if n.sons[patternPos].kind != nkEmpty:
|
||||||
n.sons[patternPos] = semPattern(c, n.sons[patternPos])
|
n.sons[patternPos] = semPattern(c, n.sons[patternPos])
|
||||||
if s.kind in skIterators:
|
if s.kind in skIterators:
|
||||||
|
|
|
||||||
|
|
@ -1375,7 +1375,8 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
of mOrdinal:
|
of mOrdinal:
|
||||||
setMagicType(m, tyOrdinal, 0)
|
setMagicType(m, tyOrdinal, 0)
|
||||||
rawAddSon(m.typ, newTypeS(tyNone, c))
|
rawAddSon(m.typ, newTypeS(tyNone, c))
|
||||||
of mPNimrodNode: discard
|
of mPNimrodNode:
|
||||||
|
incl m.typ.flags, tfTriggersCompileTime
|
||||||
of mShared:
|
of mShared:
|
||||||
setMagicType(m, tyObject, 0)
|
setMagicType(m, tyObject, 0)
|
||||||
m.typ.n = newNodeI(nkRecList, m.info)
|
m.typ.n = newNodeI(nkRecList, m.info)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue