- adding _actual as a suffix only for calls to an actual proc and not through a global function pointer - fixes https://github.com/nim-lang/Nim/issues/11996 (#12007)
- adding forward declarations for reloadable functions within a module - fix compilation errors when 2 such functions reference each other - fixes https://github.com/nim-lang/Nim/issues/11608 - preserve permissions of copied executable binaries
This commit is contained in:
parent
547fcd69c3
commit
f2e8c39e85
4 changed files with 11 additions and 6 deletions
|
|
@ -184,8 +184,8 @@ template genParamLoop(params) {.dirty.} =
|
||||||
if params != nil: add(params, ~", ")
|
if params != nil: add(params, ~", ")
|
||||||
add(params, genArgNoParam(p, ri.sons[i]))
|
add(params, genArgNoParam(p, ri.sons[i]))
|
||||||
|
|
||||||
proc addActualPrefixForHCR(res: var Rope, module: PSym, sym: PSym) =
|
proc addActualSuffixForHCR(res: var Rope, module: PSym, sym: PSym) =
|
||||||
if sym.flags * {sfImportc, sfNonReloadable} == {} and
|
if sym.flags * {sfImportc, sfNonReloadable} == {} and sym.loc.k == locProc and
|
||||||
(sym.typ.callConv == ccInline or sym.owner.id == module.id):
|
(sym.typ.callConv == ccInline or sym.owner.id == module.id):
|
||||||
res = res & "_actual".rope
|
res = res & "_actual".rope
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
genParamLoop(params)
|
genParamLoop(params)
|
||||||
var callee = rdLoc(op)
|
var callee = rdLoc(op)
|
||||||
if p.hcrOn and ri.sons[0].kind == nkSym:
|
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)
|
fixupCall(p, le, ri, d, callee, params)
|
||||||
|
|
||||||
proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
|
|
|
||||||
|
|
@ -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)
|
fillLoc(prc.loc, locProc, prc.ast[namePos], mangleName(m, prc), OnUnknown)
|
||||||
genProcParams(m, prc.typ, rettype, params, check)
|
genProcParams(m, prc.typ, rettype, params, check)
|
||||||
# handle the 2 options for hotcodereloading codegen - function pointer
|
# 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: "")
|
let asPtrStr = rope(if asPtr: "_PTR" else: "")
|
||||||
var name = prc.loc.r
|
var name = prc.loc.r
|
||||||
if isReloadable(m, prc) and not asPtr:
|
if isReloadable(m, prc) and not asPtr:
|
||||||
|
|
|
||||||
|
|
@ -784,7 +784,7 @@ proc cgsym(m: BModule, name: string): Rope =
|
||||||
rawMessage(m.config, errGenerated, "system module needs: " & name)
|
rawMessage(m.config, errGenerated, "system module needs: " & name)
|
||||||
result = sym.loc.r
|
result = sym.loc.r
|
||||||
if m.hcrOn and sym != nil and sym.kind in {skProc..skIterator}:
|
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) =
|
proc generateHeaders(m: BModule) =
|
||||||
add(m.s[cfsHeaders], "\L#include \"nimbase.h\"\L")
|
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",
|
generatedProc = ropecg(p.module, "$N$1 {$n$2$3$4}$N$N",
|
||||||
[header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
|
[header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
|
||||||
else:
|
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])
|
generatedProc = ropecg(p.module, "$N$1 {$N", [header])
|
||||||
add(generatedProc, initGCFrame(p))
|
add(generatedProc, initGCFrame(p))
|
||||||
if optStackTrace in prc.options:
|
if optStackTrace in prc.options:
|
||||||
|
|
|
||||||
|
|
@ -421,7 +421,7 @@ when defined(createNimHcr):
|
||||||
modules.add(name, newModuleDesc())
|
modules.add(name, newModuleDesc())
|
||||||
|
|
||||||
let copiedName = name & ".copy." & dllExt
|
let copiedName = name & ".copy." & dllExt
|
||||||
copyFile(name, copiedName)
|
copyFileWithPermissions(name, copiedName)
|
||||||
|
|
||||||
let lib = loadLib(copiedName)
|
let lib = loadLib(copiedName)
|
||||||
assert lib != nil
|
assert lib != nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue