From 9828392df3ac05ead78e14bde7b5865309df8a95 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 2 Oct 2020 18:53:22 +0200 Subject: [PATCH] implements https://github.com/nim-lang/RFCs/issues/257 (#15466) --- compiler/parampatterns.nim | 2 ++ compiler/transf.nim | 7 ------- compiler/trees.nim | 7 +++++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler/parampatterns.nim b/compiler/parampatterns.nim index ed8f2c16a3..c2be4b1345 100644 --- a/compiler/parampatterns.nim +++ b/compiler/parampatterns.nim @@ -223,6 +223,8 @@ proc isAssignable*(owner: PSym, n: PNode; isUnsafeAddr=false): TAssignableResult result = arLValue elif isUnsafeAddr and n.sym.kind == skParam: result = arLValue + elif isUnsafeAddr and n.sym.kind == skConst and dontInlineConstant(n, n.sym.ast): + result = arLValue elif n.sym.kind in kinds: if owner != nil and owner == n.sym.owner and sfGlobal notin n.sym.flags: diff --git a/compiler/transf.nim b/compiler/transf.nim index 5dd2754145..c8dbf5e041 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -850,13 +850,6 @@ proc transformExceptBranch(c: PTransf, n: PNode): PNode = else: result = transformSons(c, n) -proc dontInlineConstant(orig, cnst: PNode): bool {.inline.} = - # symbols that expand to a complex constant (array, etc.) should not be - # inlined, unless it's the empty array: - result = orig.kind == nkSym and - cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket} and - cnst.len != 0 - proc commonOptimizations*(g: ModuleGraph; c: PSym, n: PNode): PNode = result = n for i in 0..