Skip to content

Commit 8e474fb

Browse files
authored
IC: yet another embarrassing omission (#17743)
* IC: yet another embarrassing omission * VM: fewer hacks that kept IC from working
1 parent 201ac2b commit 8e474fb

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

compiler/ast.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ const
10541054

10551055
defaultSize = -1
10561056
defaultAlignment = -1
1057-
defaultOffset = -1
1057+
defaultOffset* = -1
10581058

10591059
proc getPIdent*(a: PNode): PIdent {.inline.} =
10601060
## Returns underlying `PIdent` for `{nkSym, nkIdent}`, or `nil`.

compiler/ic/ic.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ proc symHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph;
765765
kind: s.kind, magic: s.magic, flags: s.flags,
766766
info: translateLineInfo(c, g, si, s.info),
767767
options: s.options,
768-
position: s.position,
768+
position: if s.kind in {skForVar, skVar, skLet, skTemp}: 0 else: s.position,
769+
offset: if s.kind in routineKinds: defaultOffset else: s.offset,
769770
name: getIdent(c.cache, g[si].fromDisk.sh.strings[s.name])
770771
)
771772

compiler/vmdef.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
## This module contains the type definitions for the new evaluation engine.
1111
## An instruction is 1-3 int32s in memory, it is a register based VM.
1212

13+
import std / tables
14+
1315
import ast, idents, options, modulegraphs, lineinfos
1416

1517
type TInstrType* = uint64
@@ -266,6 +268,7 @@ type
266268
profiler*: Profiler
267269
templInstCounter*: ref int # gives every template instantiation a unique ID, needed here for getAst
268270
vmstateDiff*: seq[(PSym, PNode)] # we remember the "diff" to global state here (feature for IC)
271+
procToCodePos*: Table[int, int]
269272

270273
PStackFrame* = ref TStackFrame
271274
TStackFrame* = object

compiler/vmgen.nim

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# solves the opcLdConst vs opcAsgnConst issue. Of course whether we need
2828
# this copy depends on the involved types.
2929

30+
import std / tables
31+
3032
import
3133
strutils, ast, types, msgs, renderer, vmdef,
3234
intsets, magicsys, options, lowerings, lineinfos, transf
@@ -2248,8 +2250,8 @@ proc optimizeJumps(c: PCtx; start: int) =
22482250
else: discard
22492251

22502252
proc genProc(c: PCtx; s: PSym): int =
2251-
var x = s.ast[miscPos]
2252-
if x.kind == nkEmpty or x[0].kind == nkEmpty:
2253+
let pos = c.procToCodePos.getOrDefault(s.id)
2254+
if pos == 0:
22532255
#if s.name.s == "outterMacro" or s.name.s == "innerProc":
22542256
# echo "GENERATING CODE FOR ", s.name.s
22552257
let last = c.code.len-1
@@ -2260,11 +2262,7 @@ proc genProc(c: PCtx; s: PSym): int =
22602262
c.debug.setLen(last)
22612263
#c.removeLastEof
22622264
result = c.code.len+1 # skip the jump instruction
2263-
if x.kind == nkEmpty:
2264-
x = newTree(nkBracket, newIntNode(nkIntLit, result), x)
2265-
else:
2266-
x[0] = newIntNode(nkIntLit, result)
2267-
s.ast[miscPos] = x
2265+
c.procToCodePos[s.id] = result
22682266
# thanks to the jmp we can add top level statements easily and also nest
22692267
# procs easily:
22702268
let body = transformBody(c.graph, c.idgen, s, cache = not isCompileTimeProc(s))
@@ -2297,4 +2295,4 @@ proc genProc(c: PCtx; s: PSym): int =
22972295
c.prc = oldPrc
22982296
else:
22992297
c.prc.maxSlots = s.offset
2300-
result = x[0].intVal.int
2298+
result = pos

0 commit comments

Comments
 (0)