summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-02-01 02:22:10 +0800
committerGitHub <noreply@github.com>2023-01-31 19:22:10 +0100
commitb5f64f55d02a8ba980244596dcf310dd76b48fd8 (patch)
treeb1cecd05599e60e2b3ae635201cfe218c84a723a
parentebaa07b955182dd98a1bfe06de4195fe1d306c5e (diff)
downloadNim-b5f64f55d02a8ba980244596dcf310dd76b48fd8.tar.gz
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
-rw-r--r--compiler/vmgen.nim7
-rw-r--r--tests/vm/t19075.nim19
2 files changed, 24 insertions, 2 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index bca961a63..bdf7b679e 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -32,7 +32,7 @@ when defined(nimPreviewSlimSystem):
   import std/assertions
 
 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
@@ -2054,7 +2054,10 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
       genLit(c, n, dest)
     of skConst:
       let constVal = if s.astdef != nil: s.astdef 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 000000000..89ca9cb19
--- /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..<size:
+        zeugs[i] = stuff[i]
+    zeugs
+
+doAssert zeugs[0] == 0
\ No newline at end of file