Skip to content

Commit

Permalink
fixes a bug that keeps Nimbus from compiling with --gc:orc (nim-lang#…
Browse files Browse the repository at this point in the history
…17005)

* fixes a bug that keeps Nimbus from compiling with --gc:orc

* better fix
  • Loading branch information
Araq authored and ardek66 committed Mar 26, 2021
1 parent 7c4747d commit 3d75e96
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type
guards: TModel # nested guards
locked: seq[PNode] # locked locations
gcUnsafe, isRecursive, isTopLevel, hasSideEffect, inEnforcedGcSafe: bool
hasDangerousAssign: bool
hasDangerousAssign, isInnerProc: bool
inEnforcedNoSideEffects: bool
maxLockLevel, currLockLevel: TLockLevel
currOptions: TOptions
Expand Down Expand Up @@ -269,6 +269,9 @@ proc useVarNoInitCheck(a: PEffects; n: PNode; s: PSym) =
markSideEffect(a, s)
else:
markSideEffect(a, s)
if s.owner != a.owner and s.kind in {skVar, skLet, skForVar, skResult, skParam} and
{sfGlobal, sfThread} * s.flags == {}:
a.isInnerProc = true

proc useVar(a: PEffects, n: PNode) =
let s = n.sym
Expand Down Expand Up @@ -1252,6 +1255,15 @@ proc hasRealBody(s: PSym): bool =
## which is not a real implementation, refs #14314
result = {sfForward, sfImportc} * s.flags == {}

proc maybeWrappedInClosure(tracked: PEffects; t: PType): bool {.inline.} =
## The spec does say when to produce destructors. However, the spec
## was written in mind with the idea that "lambda lifting" already
## happened. Not true in our implementation, so we need to workaround
## here:
result = tracked.isInnerProc and
sfSystemModule notin tracked.c.module.flags and
tfCheckedForDestructor notin t.flags and containsGarbageCollectedRef(t)

proc trackProc*(c: PContext; s: PSym, body: PNode) =
let g = c.graph
var effects = s.typ.n[0]
Expand All @@ -1270,7 +1282,8 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
let param = params[i].sym
let typ = param.typ
if isSinkTypeForParam(typ) or
(t.config.selectedGC in {gcArc, gcOrc} and isClosure(typ.skipTypes(abstractInst))):
(t.config.selectedGC in {gcArc, gcOrc} and
(isClosure(typ.skipTypes(abstractInst)) or maybeWrappedInClosure(t, typ))):
createTypeBoundOps(t, typ, param.info)
when false:
if typ.kind == tyOut and param.id notin t.init:
Expand Down

0 comments on commit 3d75e96

Please sign in to comment.