From 57a291db333a1d3b6b551ac0aa1799446f660e7e Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 25 Aug 2018 20:46:22 +0200 Subject: optimize away genericReset for result assignment; refs #8745 --- compiler/cgen.nim | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) (limited to 'compiler/cgen.nim') diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 2cb431ff9..dea8b1e8a 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -705,9 +705,10 @@ proc containsResult(n: PNode): bool = for i in 0.. 0: + result = allPathsAsgnResult(n[0]) + of nkIfStmt, nkIfExpr: + var exhaustive = false + result = InitSkippable + for it in n: + # Every condition must not use 'result': + if it.len == 2 and containsResult(it[0]): + return InitRequired + if it.len == 1: exhaustive = true + allPathsInBranch(it.lastSon) + # if the 'if' statement is not exhaustive and yet it touched 'result' + # in some way, say Unknown. + if not exhaustive: result = Unknown + of nkCaseStmt: + if containsResult(n[0]): return InitRequired + result = InitSkippable + var exhaustive = skipTypes(n[0].typ, + abstractVarRange-{tyTypeDesc}).kind notin {tyFloat..tyFloat128, tyString} + for i in 1..