Check there are no side effects before optimizing away compile time expressions. (#9934)
This commit is contained in:
parent
bcbe317d17
commit
e87910197a
3 changed files with 56 additions and 8 deletions
|
|
@ -710,16 +710,20 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
|
|||
let a = getConstExpr(c.module, n.sons[i], c.graph)
|
||||
if a == nil: return n
|
||||
call.add(a)
|
||||
|
||||
#echo "NOW evaluating at compile time: ", call.renderTree
|
||||
if sfCompileTime in callee.flags:
|
||||
result = evalStaticExpr(c.module, c.graph, call, c.p.owner)
|
||||
if result.isNil:
|
||||
localError(c.config, n.info, errCannotInterpretNodeX % renderTree(call))
|
||||
else: result = fixupTypeAfterEval(c, result, n)
|
||||
if c.inStaticContext == 0 or sfNoSideEffect in callee.flags:
|
||||
if sfCompileTime in callee.flags:
|
||||
result = evalStaticExpr(c.module, c.graph, call, c.p.owner)
|
||||
if result.isNil:
|
||||
localError(c.config, n.info, errCannotInterpretNodeX % renderTree(call))
|
||||
else: result = fixupTypeAfterEval(c, result, n)
|
||||
else:
|
||||
result = evalConstExpr(c.module, c.graph, call)
|
||||
if result.isNil: result = n
|
||||
else: result = fixupTypeAfterEval(c, result, n)
|
||||
else:
|
||||
result = evalConstExpr(c.module, c.graph, call)
|
||||
if result.isNil: result = n
|
||||
else: result = fixupTypeAfterEval(c, result, n)
|
||||
result = n
|
||||
#if result != n:
|
||||
# echo "SUCCESS evaluated at compile time: ", call.renderTree
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue