77
77
gcUnsafe, isRecursive, isTopLevel, hasSideEffect, inEnforcedGcSafe: bool
78
78
hasDangerousAssign, isInnerProc: bool
79
79
inEnforcedNoSideEffects: bool
80
- maxLockLevel, currLockLevel: TLockLevel
81
80
currOptions: TOptions
82
81
config: ConfigRef
83
82
graph: ModuleGraph
84
83
c: PContext
85
84
escapingParams: IntSet
86
85
PEffects = var TEffects
87
86
88
- proc `<` (a, b: TLockLevel ): bool {.borrow .}
89
- proc `<=` (a, b: TLockLevel ): bool {.borrow .}
90
- proc `==` (a, b: TLockLevel ): bool {.borrow .}
91
- proc max (a, b: TLockLevel ): TLockLevel {.borrow .}
92
-
93
87
proc createTypeBoundOps (tracked: PEffects , typ: PType ; info: TLineInfo ) =
94
88
if typ == nil : return
95
89
when false :
@@ -107,33 +101,12 @@ proc isLocalVar(a: PEffects, s: PSym): bool =
107
101
s.typ != nil and (s.kind in {skVar, skResult} or (s.kind == skParam and isOutParam (s.typ))) and
108
102
sfGlobal notin s.flags and s.owner == a.owner
109
103
110
- proc getLockLevel (t: PType ): TLockLevel =
111
- var t = t
112
- # tyGenericInst(TLock {tyGenericBody}, tyStatic, tyObject):
113
- if t.kind == tyGenericInst and t.len == 3 : t = t[1 ]
114
- if t.kind == tyStatic and t.n != nil and t.n.kind in {nkCharLit.. nkInt64Lit}:
115
- result = t.n.intVal.TLockLevel
116
-
117
104
proc lockLocations (a: PEffects ; pragma: PNode ) =
118
105
if pragma.kind != nkExprColonExpr:
119
106
localError (a.config, pragma.info, " locks pragma without argument" )
120
107
return
121
- var firstLL = TLockLevel (- 1 'i16 )
122
108
for x in pragma[1 ]:
123
- let thisLL = getLockLevel (x.typ)
124
- if thisLL != 0 .TLockLevel :
125
- if thisLL < 0 .TLockLevel or thisLL > MaxLockLevel .TLockLevel :
126
- localError (a.config, x.info, " invalid lock level: " & $ thisLL)
127
- elif firstLL < 0 .TLockLevel : firstLL = thisLL
128
- elif firstLL != thisLL:
129
- localError (a.config, x.info,
130
- " multi-lock requires the same static lock level for every operand" )
131
- a.maxLockLevel = max (a.maxLockLevel, firstLL)
132
109
a.locked.add x
133
- if firstLL >= 0 .TLockLevel and firstLL != a.currLockLevel:
134
- if a.currLockLevel > 0 .TLockLevel and a.currLockLevel <= firstLL:
135
- localError (a.config, pragma.info, " invalid nested locking" )
136
- a.currLockLevel = firstLL
137
110
138
111
proc guardGlobal (a: PEffects ; n: PNode ; guard: PSym ) =
139
112
# check whether the corresponding lock is held:
@@ -438,8 +411,6 @@ proc listEffects(a: PEffects) =
438
411
for e in items (a.exc): message (a.config, e.info, hintUser, typeToString (e.typ))
439
412
for e in items (a.tags): message (a.config, e.info, hintUser, typeToString (e.typ))
440
413
for e in items (a.forbids): message (a.config, e.info, hintUser, typeToString (e.typ))
441
- # if a.maxLockLevel != 0:
442
- # message(e.info, hintUser, "lockLevel: " & a.maxLockLevel)
443
414
444
415
proc catches (tracked: PEffects , e: PType ) =
445
416
let e = skipTypes (e, skipPtrs)
@@ -551,25 +522,6 @@ proc importedFromC(n: PNode): bool =
551
522
# when imported from C, we assume GC-safety.
552
523
result = n.kind == nkSym and sfImportc in n.sym.flags
553
524
554
- proc getLockLevel (s: PSym ): TLockLevel =
555
- result = s.typ.lockLevel
556
- if result == UnspecifiedLockLevel :
557
- if {sfImportc, sfNoSideEffect} * s.flags != {} or
558
- tfNoSideEffect in s.typ.flags:
559
- result = 0 .TLockLevel
560
- else :
561
- result = UnknownLockLevel
562
- # message(??.config, s.info, warnUser, "FOR THIS " & s.name.s)
563
-
564
- proc mergeLockLevels (tracked: PEffects , n: PNode , lockLevel: TLockLevel ) =
565
- if lockLevel >= tracked.currLockLevel:
566
- # if in lock section:
567
- if tracked.currLockLevel > 0 .TLockLevel :
568
- localError tracked.config, n.info, errGenerated,
569
- " expected lock level < " & $ tracked.currLockLevel &
570
- " but got lock level " & $ lockLevel
571
- tracked.maxLockLevel = max (tracked.maxLockLevel, lockLevel)
572
-
573
525
proc propagateEffects (tracked: PEffects , n: PNode , s: PSym ) =
574
526
let pragma = s.ast[pragmasPos]
575
527
let spec = effectSpec (pragma, wRaises)
@@ -583,7 +535,6 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
583
535
markGcUnsafe (tracked, s)
584
536
if tfNoSideEffect notin s.typ.flags:
585
537
markSideEffect (tracked, s, n.info)
586
- mergeLockLevels (tracked, n, s.getLockLevel)
587
538
588
539
proc procVarCheck (n: PNode ; conf: ConfigRef ) =
589
540
if n.kind in nkSymChoices:
@@ -623,11 +574,6 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
623
574
proc assumeTheWorst (tracked: PEffects ; n: PNode ; op: PType ) =
624
575
addRaiseEffect (tracked, createRaise (tracked.graph, n), nil )
625
576
addTag (tracked, createTag (tracked.graph, n), nil )
626
- let lockLevel = if op.lockLevel == UnspecifiedLockLevel : UnknownLockLevel
627
- else : op.lockLevel
628
- # if lockLevel == UnknownLockLevel:
629
- # message(??.config, n.info, warnUser, "had to assume the worst here")
630
- mergeLockLevels (tracked, n, lockLevel)
631
577
632
578
proc isOwnedProcVar (tracked: PEffects ; n: PNode ): bool =
633
579
# XXX prove the soundness of this effect system rule
@@ -885,10 +831,9 @@ proc trackCall(tracked: PEffects; n: PNode) =
885
831
if a.kind == nkSym:
886
832
if a.sym == tracked.owner: tracked.isRecursive = true
887
833
# even for recursive calls we need to check the lock levels (!):
888
- mergeLockLevels (tracked, n, a.sym.getLockLevel)
889
834
if sfSideEffect in a.sym.flags: markSideEffect (tracked, a, n.info)
890
835
else :
891
- mergeLockLevels (tracked, n, op.lockLevel)
836
+ discard
892
837
var effectList = op.n[0 ]
893
838
if a.kind == nkSym and a.sym.kind == skMethod:
894
839
propagateEffects (tracked, n, a.sym)
@@ -967,7 +912,6 @@ proc trackCall(tracked: PEffects; n: PNode) =
967
912
type
968
913
PragmaBlockContext = object
969
914
oldLocked: int
970
- oldLockLevel: TLockLevel
971
915
enforcedGcSafety, enforceNoSideEffects: bool
972
916
oldExc, oldTags, oldForbids: int
973
917
exc, tags, forbids: PNode
@@ -976,7 +920,6 @@ proc createBlockContext(tracked: PEffects): PragmaBlockContext =
976
920
var oldForbidsLen = 0
977
921
if tracked.forbids != nil : oldForbidsLen = tracked.forbids.len
978
922
result = PragmaBlockContext (oldLocked: tracked.locked.len,
979
- oldLockLevel: tracked.currLockLevel,
980
923
enforcedGcSafety: false , enforceNoSideEffects: false ,
981
924
oldExc: tracked.exc.len, oldTags: tracked.tags.len,
982
925
oldForbids: oldForbidsLen)
@@ -989,7 +932,6 @@ proc unapplyBlockContext(tracked: PEffects; bc: PragmaBlockContext) =
989
932
if bc.enforcedGcSafety: tracked.inEnforcedGcSafe = false
990
933
if bc.enforceNoSideEffects: tracked.inEnforcedNoSideEffects = false
991
934
setLen (tracked.locked, bc.oldLocked)
992
- tracked.currLockLevel = bc.oldLockLevel
993
935
if bc.exc != nil :
994
936
# beware that 'raises: []' is very different from not saying
995
937
# anything about 'raises' in the 'cast' at all. Same applies for 'tags'.
@@ -1396,17 +1338,6 @@ proc checkMethodEffects*(g: ModuleGraph; disp, branch: PSym) =
1396
1338
localError (g.config, branch.info, " for method '" & branch.name.s &
1397
1339
" ' the `.requires` or `.ensures` properties are incompatible." )
1398
1340
1399
- if branch.typ.lockLevel > disp.typ.lockLevel:
1400
- when true :
1401
- message (g.config, branch.info, warnLockLevel,
1402
- " base method has lock level $1, but dispatcher has $2" %
1403
- [$ branch.typ.lockLevel, $ disp.typ.lockLevel])
1404
- else :
1405
- # XXX make this an error after bigbreak has been released:
1406
- localError (g.config, branch.info,
1407
- " base method has lock level $1, but dispatcher has $2" %
1408
- [$ branch.typ.lockLevel, $ disp.typ.lockLevel])
1409
-
1410
1341
proc setEffectsForProcType * (g: ModuleGraph ; t: PType , n: PNode ; s: PSym = nil ) =
1411
1342
var effects = t.n[0 ]
1412
1343
if t.kind != tyProc or effects.kind != nkEffectList: return
@@ -1592,13 +1523,6 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
1592
1523
s.typ.flags.incl tfGcSafe
1593
1524
if not t.hasSideEffect and sfSideEffect notin s.flags:
1594
1525
s.typ.flags.incl tfNoSideEffect
1595
- if s.typ.lockLevel == UnspecifiedLockLevel :
1596
- s.typ.lockLevel = t.maxLockLevel
1597
- elif t.maxLockLevel > s.typ.lockLevel:
1598
- # localError(s.info,
1599
- message (g.config, s.info, warnLockLevel,
1600
- " declared lock level is $1, but real lock level is $2" %
1601
- [$ s.typ.lockLevel, $ t.maxLockLevel])
1602
1526
when defined (drnim):
1603
1527
if c.graph.strongSemCheck != nil : c.graph.strongSemCheck (c.graph, s, body)
1604
1528
when defined (useDfa):
0 commit comments