IC: yet another embarrassing omission (#17743)

* IC: yet another embarrassing omission

* VM: fewer hacks that kept IC from working
This commit is contained in:
Andreas Rumpf
2021-04-17 01:12:12 +02:00
committed by GitHub
parent 201ac2b9c9
commit 8e474fbb57
4 changed files with 12 additions and 10 deletions

View File

@@ -1054,7 +1054,7 @@ const
defaultSize = -1
defaultAlignment = -1
defaultOffset = -1
defaultOffset* = -1
proc getPIdent*(a: PNode): PIdent {.inline.} =
## Returns underlying `PIdent` for `{nkSym, nkIdent}`, or `nil`.

View File

@@ -765,7 +765,8 @@ proc symHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph;
kind: s.kind, magic: s.magic, flags: s.flags,
info: translateLineInfo(c, g, si, s.info),
options: s.options,
position: s.position,
position: if s.kind in {skForVar, skVar, skLet, skTemp}: 0 else: s.position,
offset: if s.kind in routineKinds: defaultOffset else: s.offset,
name: getIdent(c.cache, g[si].fromDisk.sh.strings[s.name])
)

View File

@@ -10,6 +10,8 @@
## This module contains the type definitions for the new evaluation engine.
## An instruction is 1-3 int32s in memory, it is a register based VM.
import std / tables
import ast, idents, options, modulegraphs, lineinfos
type TInstrType* = uint64
@@ -266,6 +268,7 @@ type
profiler*: Profiler
templInstCounter*: ref int # gives every template instantiation a unique ID, needed here for getAst
vmstateDiff*: seq[(PSym, PNode)] # we remember the "diff" to global state here (feature for IC)
procToCodePos*: Table[int, int]
PStackFrame* = ref TStackFrame
TStackFrame* = object

View File

@@ -27,6 +27,8 @@
# solves the opcLdConst vs opcAsgnConst issue. Of course whether we need
# this copy depends on the involved types.
import std / tables
import
strutils, ast, types, msgs, renderer, vmdef,
intsets, magicsys, options, lowerings, lineinfos, transf
@@ -2248,8 +2250,8 @@ proc optimizeJumps(c: PCtx; start: int) =
else: discard
proc genProc(c: PCtx; s: PSym): int =
var x = s.ast[miscPos]
if x.kind == nkEmpty or x[0].kind == nkEmpty:
let pos = c.procToCodePos.getOrDefault(s.id)
if pos == 0:
#if s.name.s == "outterMacro" or s.name.s == "innerProc":
# echo "GENERATING CODE FOR ", s.name.s
let last = c.code.len-1
@@ -2260,11 +2262,7 @@ proc genProc(c: PCtx; s: PSym): int =
c.debug.setLen(last)
#c.removeLastEof
result = c.code.len+1 # skip the jump instruction
if x.kind == nkEmpty:
x = newTree(nkBracket, newIntNode(nkIntLit, result), x)
else:
x[0] = newIntNode(nkIntLit, result)
s.ast[miscPos] = x
c.procToCodePos[s.id] = result
# thanks to the jmp we can add top level statements easily and also nest
# procs easily:
let body = transformBody(c.graph, c.idgen, s, cache = not isCompileTimeProc(s))
@@ -2297,4 +2295,4 @@ proc genProc(c: PCtx; s: PSym): int =
c.prc = oldPrc
else:
c.prc.maxSlots = s.offset
result = x[0].intVal.int
result = pos