diff options
-rw-r--r-- | compiler/ccgcalls.nim | 6 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 2 | ||||
-rw-r--r-- | compiler/cgen.nim | 7 | ||||
-rw-r--r-- | lib/nimhcr.nim | 2 |
4 files changed, 11 insertions, 6 deletions
diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 9201af466..2ae56863b 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -184,8 +184,8 @@ template genParamLoop(params) {.dirty.} = if params != nil: add(params, ~", ") add(params, genArgNoParam(p, ri.sons[i])) -proc addActualPrefixForHCR(res: var Rope, module: PSym, sym: PSym) = - if sym.flags * {sfImportc, sfNonReloadable} == {} and +proc addActualSuffixForHCR(res: var Rope, module: PSym, sym: PSym) = + if sym.flags * {sfImportc, sfNonReloadable} == {} and sym.loc.k == locProc and (sym.typ.callConv == ccInline or sym.owner.id == module.id): res = res & "_actual".rope @@ -203,7 +203,7 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) = genParamLoop(params) var callee = rdLoc(op) if p.hcrOn and ri.sons[0].kind == nkSym: - callee.addActualPrefixForHCR(p.module.module, ri.sons[0].sym) + callee.addActualSuffixForHCR(p.module.module, ri.sons[0].sym) fixupCall(p, le, ri, d, callee, params) proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) = diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 28a9bf028..584e69b30 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -956,7 +956,7 @@ proc genProcHeader(m: BModule, prc: PSym, asPtr: bool = false): Rope = fillLoc(prc.loc, locProc, prc.ast[namePos], mangleName(m, prc), OnUnknown) genProcParams(m, prc.typ, rettype, params, check) # handle the 2 options for hotcodereloading codegen - function pointer - # (instead of forward declaration) or header for function budy with "_actual" postfix + # (instead of forward declaration) or header for function body with "_actual" postfix let asPtrStr = rope(if asPtr: "_PTR" else: "") var name = prc.loc.r if isReloadable(m, prc) and not asPtr: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index e961530f2..033003485 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -784,7 +784,7 @@ proc cgsym(m: BModule, name: string): Rope = rawMessage(m.config, errGenerated, "system module needs: " & name) result = sym.loc.r if m.hcrOn and sym != nil and sym.kind in {skProc..skIterator}: - result.addActualPrefixForHCR(m.module, sym) + result.addActualSuffixForHCR(m.module, sym) proc generateHeaders(m: BModule) = add(m.s[cfsHeaders], "\L#include \"nimbase.h\"\L") @@ -1033,6 +1033,11 @@ proc genProcAux(m: BModule, prc: PSym) = generatedProc = ropecg(p.module, "$N$1 {$n$2$3$4}$N$N", [header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)]) else: + if m.hcrOn and isReloadable(m, prc): + # Add forward declaration for "_actual"-suffixed functions defined in the same module (or inline). + # This fixes the use of methods and also the case when 2 functions within the same module + # call each other using directly the "_actual" versions (an optimization) - see issue #11608 + addf(m.s[cfsProcHeaders], "$1;\n", [header]) generatedProc = ropecg(p.module, "$N$1 {$N", [header]) add(generatedProc, initGCFrame(p)) if optStackTrace in prc.options: diff --git a/lib/nimhcr.nim b/lib/nimhcr.nim index 79f3fd350..201d4f5ad 100644 --- a/lib/nimhcr.nim +++ b/lib/nimhcr.nim @@ -421,7 +421,7 @@ when defined(createNimHcr): modules.add(name, newModuleDesc()) let copiedName = name & ".copy." & dllExt - copyFile(name, copiedName) + copyFileWithPermissions(name, copiedName) let lib = loadLib(copiedName) assert lib != nil |