summary refs log tree commit diff stats
path: root/compiler/destroyer.nim
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2018-10-24 09:11:46 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-10-24 09:11:46 +0200
commit16d82c82e37cfdc17b063e32f042e85b5d1122e2 (patch)
tree592f6b87f850cab7566dc89a119353e8b0291efa /compiler/destroyer.nim
parent3ee53a7c8ed31f41fb0abe0f4f051f5a66559467 (diff)
downloadNim-16d82c82e37cfdc17b063e32f042e85b5d1122e2.tar.gz
Remove a hack in the destroyer impl (#9479)
Generate nkHiddenAddr nodes w/ proper type attached.
Diffstat (limited to 'compiler/destroyer.nim')
-rw-r--r--compiler/destroyer.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim
index 2a82b6f3b..b621e99b9 100644
--- a/compiler/destroyer.nim
+++ b/compiler/destroyer.nim
@@ -268,9 +268,6 @@ proc patchHead(n: PNode) =
       if sfFromGeneric in s.flags:
         excl(s.flags, sfFromGeneric)
         patchHead(s.getBody)
-      if n[1].typ.isNil:
-        # XXX toptree crashes without this workaround. Figure out why.
-        return
       let t = n[1].typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
       template patch(op, field) =
         if s.name.s == op and field != nil and field != s:
@@ -296,6 +293,10 @@ proc checkForErrorPragma(c: Con; t: PType; ri: PNode; opname: string) =
       m.add c.graph.config $ c.otherRead.info
   localError(c.graph.config, ri.info, errGenerated, m)
 
+proc makePtrType(c: Con, baseType: PType): PType =
+  result = newType(tyPtr, c.owner)
+  addSonSkipIntLit(result, baseType)
+
 template genOp(opr, opname, ri) =
   let op = opr
   if op == nil:
@@ -304,7 +305,9 @@ template genOp(opr, opname, ri) =
     globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator is generic")
   patchHead op
   if sfError in op.flags: checkForErrorPragma(c, t, ri, opname)
-  result = newTree(nkCall, newSymNode(op), newTree(nkHiddenAddr, dest))
+  let addrExp = newNodeIT(nkHiddenAddr, dest.info, makePtrType(c, dest.typ))
+  addrExp.add(dest)
+  result = newTree(nkCall, newSymNode(op), addrExp)
 
 proc genSink(c: Con; t: PType; dest, ri: PNode): PNode =
   let t = t.skipTypes({tyGenericInst, tyAlias, tySink})