diff --git a/compiler/ast.nim b/compiler/ast.nim index ff0e01adc9..c003db0002 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -296,7 +296,8 @@ proc incl*(s: PSym; flags: set[TSymFlag]) {.inline.} = s.flagsImpl.incl(flags) proc incl*(s: PSym; flag: TLocFlag) {.inline.} = - assert s.state != Sealed + #assert s.state != Sealed + # locImpl is a backend field so do not protect it against mutations if s.state == Partial: loadSym(s) s.locImpl.flags.incl(flag) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index 57a30a8e0d..1cc8ff2cbe 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -717,6 +717,16 @@ proc writeNifModule*(config: ConfigRef; thisModule: int32; n: PNode; # do not write the (stmts .. ) wrapper: for i in 3 ..< content.len-1: dest.add content[i] + + # ensure the hooks we announced end up in the NIF file regardless of + # whether they have been used: + for op in opsLog: + if op.module == thisModule.int: + let s = op.sym + if s.state != Sealed: + s.state = Sealed + writeSymDef w, dest, s + dest.addParRi() writeFile(dest, d) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index cc54b515b6..62ea950263 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -68,11 +68,17 @@ proc findPendingModule(m: BModule, s: PSym): BModule = if m.config.symbolFiles == v2Sf or optCompress in m.config.globalOptions: let ms = s.itemId.module #getModule(s) result = m.g.modules[ms] + elif m.config.cmd in {cmdNifC, cmdM}: + var ms = getModule(s) + if ms.position >= m.g.modules.len: + result = newModule(m.g, ms, m.config, idGeneratorFromModule(ms)) + else: + result = m.g.modules[ms.position] + if result == nil: + result = newModule(m.g, ms, m.config, idGeneratorFromModule(ms)) else: var ms = getModule(s) result = m.g.modules[ms.position] - if result == nil: - result = newModule(m.g, ms, m.config, idGeneratorFromModule(ms)) proc initLoc(k: TLocKind, lode: PNode, s: TStorageLoc, flags: TLocFlags = {}): TLoc = result = TLoc(k: k, storage: s, lode: lode,