diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index b14615e40..1d4cdcc9b 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -128,7 +128,6 @@ type g: ControlFlowGraph jumpTargets: IntSet destroys, topLevelVars: PNode - tracingSinkedParams: bool # we aren't checking double sink for proc args in if, case, loops since they possibly not taken alreadySinkedParams: Table[int, TLineInfo] graph: ModuleGraph emptyNode: PNode @@ -367,15 +366,14 @@ proc destructiveMoveVar(n: PNode; c: var Con): PNode = result.add genWasMoved(n, c) result.add tempAsNode -proc sinkParamConsumed(c: var Con, s: PNode, tracing = true) = - assert s.kind == nkSym - let isConsumed = - if c.tracingSinkedParams and tracing: - c.alreadySinkedParams.hasKeyOrPut(s.sym.id, s.info) - else: c.alreadySinkedParams.hasKey(s.sym.id) - if isConsumed: - localError(c.graph.config, s.info, "sink parameter `" & $s.sym.name.s & - "` is already consumed at " & toFileLineCol(c. graph.config, c.alreadySinkedParams[s.sym.id])) +proc sinkParamIsLastReadCheck(c: var Con, s: PNode) = + assert s.kind == nkSym and s.sym.kind == skParam + discard isLastRead(s, c) + if c.otherRead != nil: + localError(c.graph.config, c.otherRead.info, "sink parameter `" & $s.sym.name.s & + "` is already consumed at " & toFileLineCol(c. graph.config, s.info)) + else: + c.alreadySinkedParams[s.sym.id] = s.info proc passCopyToSink(n: PNode; c: var Con): PNode = result = newNodeIT(nkStmtListExpr, n.info, n.typ) @@ -414,8 +412,8 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = elif arg.kind == nkSym and isSinkParam(arg.sym): # Sinked params can be consumed only once. We need to reset the memory # to disable the destructor which we have not elided + sinkParamIsLastReadCheck(c, arg) result = destructiveMoveVar(arg, c) - sinkParamConsumed(c, arg) elif arg.kind == nkSym and arg.sym.kind in InterestingSyms and isLastRead(arg, c): # it is the last read, can be sinked. We need to reset the memory # to disable the destructor which we have not elided @@ -431,7 +429,6 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = result.add pArg(arg[^1], c, isSink) elif arg.kind in {nkIfExpr, nkIfStmt}: result = copyNode(arg) - c.tracingSinkedParams = false for i in 0..