From a36d8bbf6c493e30df45bbb0a17fd793e7c1f12e Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 25 Apr 2019 13:54:04 +0200 Subject: [PATCH] introduce a special typing rule that makes seq[owned ref T] easier to use; remains to be investigated... --- compiler/injectdestructors.nim | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 5958d89aec..73ff0869c9 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -419,6 +419,15 @@ proc sinkParamIsLastReadCheck(c: var Con, s: PNode) = localError(c.graph.config, c.otherRead.info, "sink parameter `" & $s.sym.name.s & "` is already consumed at " & toFileLineCol(c. graph.config, s.info)) +proc isSinkTypeForParam(t: PType): bool = + # a parameter like 'seq[owned T]' must not be used only once, but its + # elements must, so we detect this case here: + if isSinkType(t): + if t.skipTypes({tyGenericInst, tyAlias}).kind in {tyArray, tyVarargs, tyOpenArray, tySequence}: + result = false + else: + result = true + proc passCopyToSink(n: PNode; c: var Con): PNode = result = newNodeIT(nkStmtListExpr, n.info, n.typ) let tmp = getTemp(c, n.typ, n.info) @@ -452,7 +461,7 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = let L = if parameters != nil: parameters.len else: 0 result.add arg[0] for i in 1..