Skip to content

Commit

Permalink
fixes nim-lang#16790; fixes nim-lang#19075; put big arrays on the con…
Browse files Browse the repository at this point in the history
…stant seqs; don't inline them in the VM; big performance boost (nim-lang#21318)

* don't inline arrays in VM

* add a test for nim-lang#19075
  • Loading branch information
ringabout authored and capocasa committed Mar 31, 2023
1 parent fe7e021 commit ec952b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/vm/t19075.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ec952b8

Please sign in to comment.