From 7ad8c44e286847a7443a4172bc454ae84f315b6d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 1 Feb 2023 02:22:10 +0800 Subject: [PATCH] fixes #16790; fixes #19075; put big arrays on the constant seqs; don't inline them in the VM; big performance boost (#21318) * don't inline arrays in VM * add a test for #19075 (cherry picked from commit b5f64f55d02a8ba980244596dcf310dd76b48fd8) --- compiler/vmgen.nim | 7 +++++-- tests/vm/t19075.nim | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/vm/t19075.nim diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index af99d45e215c..98226750ebdc 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -30,7 +30,7 @@ import tables import - strutils, ast, types, msgs, renderer, vmdef, + strutils, ast, types, msgs, renderer, vmdef, trees, intsets, magicsys, options, lowerings, lineinfos, transf, astmsgs from modulegraphs import getBody @@ -2073,7 +2073,10 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) = genLit(c, n, dest) of skConst: let constVal = if s.ast != nil: s.ast else: s.typ.n - gen(c, constVal, dest) + if dontInlineConstant(n, constVal): + genLit(c, constVal, dest) + else: + gen(c, constVal, dest) of skEnumField: # we never reach this case - as of the time of this comment, # skEnumField is folded to an int in semfold.nim, but this code diff --git a/tests/vm/t19075.nim b/tests/vm/t19075.nim new file mode 100644 index 000000000000..89ca9cb1979b --- /dev/null +++ b/tests/vm/t19075.nim @@ -0,0 +1,19 @@ +discard """ + timeout: 10 + joinable: false +""" + +# bug #19075 +const size = 50_000 + +const stuff = block: + var a: array[size, int] + a + +const zeugs = block: + var zeugs: array[size, int] + for i in 0..