new minor language feature: .noSideEffect blocks like .gcsafe blocks
This commit is contained in:
parent
93cf0ef52e
commit
413580bc04
7 changed files with 30 additions and 12 deletions
|
|
@ -56,6 +56,7 @@ type
|
|||
guards: TModel # nested guards
|
||||
locked: seq[PNode] # locked locations
|
||||
gcUnsafe, isRecursive, isToplevel, hasSideEffect, inEnforcedGcSafe: bool
|
||||
inEnforcedNoSideEffects: bool
|
||||
maxLockLevel, currLockLevel: TLockLevel
|
||||
config: ConfigRef
|
||||
graph: ModuleGraph
|
||||
|
|
@ -194,10 +195,10 @@ proc markGcUnsafe(a: PEffects; reason: PNode) =
|
|||
|
||||
when true:
|
||||
template markSideEffect(a: PEffects; reason: typed) =
|
||||
a.hasSideEffect = true
|
||||
if not a.inEnforcedNoSideEffects: a.hasSideEffect = true
|
||||
else:
|
||||
template markSideEffect(a: PEffects; reason: typed) =
|
||||
a.hasSideEffect = true
|
||||
if not a.inEnforcedNoSideEffects: a.hasSideEffect = true
|
||||
markGcUnsafe(a, reason)
|
||||
|
||||
proc listGcUnsafety(s: PSym; onlyWarning: bool; cycleCheck: var IntSet; conf: ConfigRef) =
|
||||
|
|
@ -846,15 +847,20 @@ proc track(tracked: PEffects, n: PNode) =
|
|||
let oldLocked = tracked.locked.len
|
||||
let oldLockLevel = tracked.currLockLevel
|
||||
var enforcedGcSafety = false
|
||||
var enforceNoSideEffects = false
|
||||
for i in 0 ..< pragmaList.len:
|
||||
let pragma = whichPragma(pragmaList.sons[i])
|
||||
if pragma == wLocks:
|
||||
lockLocations(tracked, pragmaList.sons[i])
|
||||
elif pragma == wGcSafe:
|
||||
enforcedGcSafety = true
|
||||
elif pragma == wNosideeffect:
|
||||
enforceNoSideEffects = true
|
||||
if enforcedGcSafety: tracked.inEnforcedGcSafe = true
|
||||
if enforceNoSideEffects: tracked.inEnforcedNoSideEffects = true
|
||||
track(tracked, n.lastSon)
|
||||
if enforcedGcSafety: tracked.inEnforcedGcSafe = false
|
||||
if enforceNoSideEffects: tracked.inEnforcedNoSideEffects = false
|
||||
setLen(tracked.locked, oldLocked)
|
||||
tracked.currLockLevel = oldLockLevel
|
||||
of nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef, nkIteratorDef,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue