Skip to content

Commit 5602183

Browse files
authored
'lock levels' are deprecated, now a noop (#20539)
* 'lock levels' are deprecated, now a noop * fixes tests
1 parent 7587371 commit 5602183

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+121
-372
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
- `macros.getImpl` for `const` symbols now returns the full definition node
8585
(as `nnkConstDef`) rather than the AST of the constant value.
8686

87+
- Lock levels are deprecated, now a noop.
88+
8789
- ORC is now the default memory management strategy. Use
8890
`--mm:refc` for a transition period.
8991

compiler/ast.nim

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ type
929929
allUsages*: seq[TLineInfo]
930930

931931
TTypeSeq* = seq[PType]
932-
TLockLevel* = distinct int16
933932

934933
TTypeAttachedOp* = enum ## as usual, order is important here
935934
attachedDestructor,
@@ -963,7 +962,6 @@ type
963962
# -1 means that the size is unkwown
964963
align*: int16 # the type's alignment requirements
965964
paddingAtEnd*: int16 #
966-
lockLevel*: TLockLevel # lock level as required for deadlock checking
967965
loc*: TLoc
968966
typeInst*: PType # for generic instantiations the tyGenericInst that led to this
969967
# type.
@@ -1499,17 +1497,9 @@ proc newProcNode*(kind: TNodeKind, info: TLineInfo, body: PNode,
14991497
pragmas, exceptions, body]
15001498

15011499
const
1502-
UnspecifiedLockLevel* = TLockLevel(-1'i16)
1503-
MaxLockLevel* = 1000'i16
1504-
UnknownLockLevel* = TLockLevel(1001'i16)
15051500
AttachedOpToStr*: array[TTypeAttachedOp, string] = [
15061501
"=destroy", "=copy", "=sink", "=trace", "=deepcopy"]
15071502

1508-
proc `$`*(x: TLockLevel): string =
1509-
if x.ord == UnspecifiedLockLevel.ord: result = "<unspecified>"
1510-
elif x.ord == UnknownLockLevel.ord: result = "<unknown>"
1511-
else: result = $int16(x)
1512-
15131503
proc `$`*(s: PSym): string =
15141504
if s != nil:
15151505
result = s.name.s & "@" & $s.id
@@ -1519,7 +1509,6 @@ proc `$`*(s: PSym): string =
15191509
proc newType*(kind: TTypeKind, id: ItemId; owner: PSym): PType =
15201510
result = PType(kind: kind, owner: owner, size: defaultSize,
15211511
align: defaultAlignment, itemId: id,
1522-
lockLevel: UnspecifiedLockLevel,
15231512
uniqueId: id)
15241513
when false:
15251514
if result.itemId.module == 55 and result.itemId.item == 2:
@@ -1544,7 +1533,6 @@ proc assignType*(dest, src: PType) =
15441533
dest.n = src.n
15451534
dest.size = src.size
15461535
dest.align = src.align
1547-
dest.lockLevel = src.lockLevel
15481536
# this fixes 'type TLock = TSysLock':
15491537
if src.sym != nil:
15501538
if dest.sym != nil:

compiler/cgmeth.nim

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,6 @@ proc fixupDispatcher(meth, disp: PSym; conf: ConfigRef) =
147147
disp.ast[resultPos].kind == nkEmpty:
148148
disp.ast[resultPos] = copyTree(meth.ast[resultPos])
149149

150-
# The following code works only with lock levels, so we disable
151-
# it when they're not available.
152-
when declared(TLockLevel):
153-
proc `<`(a, b: TLockLevel): bool {.borrow.}
154-
proc `==`(a, b: TLockLevel): bool {.borrow.}
155-
if disp.typ.lockLevel == UnspecifiedLockLevel:
156-
disp.typ.lockLevel = meth.typ.lockLevel
157-
elif meth.typ.lockLevel != UnspecifiedLockLevel and
158-
meth.typ.lockLevel != disp.typ.lockLevel:
159-
message(conf, meth.info, warnLockLevel,
160-
"method has lock level $1, but another method has $2" %
161-
[$meth.typ.lockLevel, $disp.typ.lockLevel])
162-
# XXX The following code silences a duplicate warning in
163-
# checkMethodeffects() in sempass2.nim for now.
164-
if disp.typ.lockLevel < meth.typ.lockLevel:
165-
disp.typ.lockLevel = meth.typ.lockLevel
166-
167150
proc methodDef*(g: ModuleGraph; idgen: IdGenerator; s: PSym) =
168151
var witness: PSym
169152
for i in 0..<g.methods.len:

compiler/ic/ic.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ proc storeType(t: PType; c: var PackedEncoder; m: var PackedModule): PackedItemI
354354

355355
var p = PackedType(kind: t.kind, flags: t.flags, callConv: t.callConv,
356356
size: t.size, align: t.align, nonUniqueId: t.itemId.item,
357-
paddingAtEnd: t.paddingAtEnd, lockLevel: t.lockLevel)
357+
paddingAtEnd: t.paddingAtEnd)
358358
storeNode(p, t, n)
359359
p.typeInst = t.typeInst.storeType(c, m)
360360
for kid in items t.sons:
@@ -900,7 +900,7 @@ proc typeHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph;
900900
t: PackedType; si, item: int32): PType =
901901
result = PType(itemId: ItemId(module: si, item: t.nonUniqueId), kind: t.kind,
902902
flags: t.flags, size: t.size, align: t.align,
903-
paddingAtEnd: t.paddingAtEnd, lockLevel: t.lockLevel,
903+
paddingAtEnd: t.paddingAtEnd,
904904
uniqueId: ItemId(module: si, item: item),
905905
callConv: t.callConv)
906906

compiler/ic/packed_ast.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ type
8484
size*: BiggestInt
8585
align*: int16
8686
paddingAtEnd*: int16
87-
lockLevel*: TLockLevel # lock level as required for deadlock checking
8887
# not serialized: loc*: TLoc because it is backend-specific
8988
typeInst*: PackedItemId
9089
nonUniqueId*: int32

compiler/lineinfos.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ type
6868
warnUnreachableElse = "UnreachableElse", warnUnreachableCode = "UnreachableCode",
6969
warnStaticIndexCheck = "IndexCheck", warnGcUnsafe = "GcUnsafe", warnGcUnsafe2 = "GcUnsafe2",
7070
warnUninit = "Uninit", warnGcMem = "GcMem", warnDestructor = "Destructor",
71-
warnLockLevel = "LockLevel", warnResultShadowed = "ResultShadowed",
71+
warnLockLevel = "LockLevel", # deadcode
72+
warnResultShadowed = "ResultShadowed",
7273
warnInconsistentSpacing = "Spacing", warnCaseTransition = "CaseTransition",
7374
warnCycleCreated = "CycleCreated", warnObservableStores = "ObservableStores",
7475
warnStrictNotNil = "StrictNotNil",
@@ -161,7 +162,7 @@ const
161162
warnUninit: "use explicit initialization of '$1' for clarity",
162163
warnGcMem: "'$1' uses GC'ed memory",
163164
warnDestructor: "usage of a type with a destructor in a non destructible context. This will become a compile time error in the future.",
164-
warnLockLevel: "$1",
165+
warnLockLevel: "$1", # deadcode
165166
warnResultShadowed: "Special variable 'result' is shadowed.",
166167
warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
167168
warnCaseTransition: "Potential object case transition, instantiate new object instead",

compiler/main.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ proc mainCommand*(graph: ModuleGraph) =
294294
of cmdDoc0: docLikeCmd commandDoc(cache, conf)
295295
of cmdDoc:
296296
docLikeCmd():
297-
conf.setNoteDefaults(warnLockLevel, false) # issue #13218
298297
conf.setNoteDefaults(warnRstRedefinitionOfLabel, false) # issue #13218
299298
# because currently generates lots of false positives due to conflation
300299
# of labels links in doc comments, e.g. for random.rand:

compiler/pragmas.nim

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -684,23 +684,6 @@ proc pragmaLockStmt(c: PContext; it: PNode) =
684684
for i in 0..<n.len:
685685
n[i] = c.semExpr(c, n[i])
686686

687-
proc pragmaLocks(c: PContext, it: PNode): TLockLevel =
688-
if it.kind notin nkPragmaCallKinds or it.len != 2:
689-
invalidPragma(c, it)
690-
else:
691-
case it[1].kind
692-
of nkStrLit, nkRStrLit, nkTripleStrLit:
693-
if it[1].strVal == "unknown":
694-
result = UnknownLockLevel
695-
else:
696-
localError(c.config, it[1].info, "invalid string literal for locks pragma (only allowed string is \"unknown\")")
697-
else:
698-
let x = expectIntLit(c, it)
699-
if x < 0 or x > MaxLockLevel:
700-
localError(c.config, it[1].info, "integer must be within 0.." & $MaxLockLevel)
701-
else:
702-
result = TLockLevel(x)
703-
704687
proc typeBorrow(c: PContext; sym: PSym, n: PNode) =
705688
if n.kind in nkPragmaCallKinds and n.len == 2:
706689
let it = n[1]
@@ -1196,7 +1179,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
11961179
of wLocks:
11971180
if sym == nil: pragmaLockStmt(c, it)
11981181
elif sym.typ == nil: invalidPragma(c, it)
1199-
else: sym.typ.lockLevel = pragmaLocks(c, it)
1182+
else: warningDeprecated(c.config, n.info, "'Lock levels' are deprecated, now a noop")
12001183
of wBitsize:
12011184
if sym == nil or sym.kind != skField:
12021185
invalidPragma(c, it)

compiler/semcall.nim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ proc effectProblem(f, a: PType; result: var string; c: PContext) =
149149
of efTagsUnknown:
150150
result.add "\n The `.tags` requirements differ. Annotate the " &
151151
"proc with {.tags: [].} to get extended error information."
152-
of efLockLevelsDiffer:
153-
result.add "\n The `.locks` requirements differ. Annotate the " &
154-
"proc with {.locks: 0.} to get extended error information."
155152
of efEffectsDelayed:
156153
result.add "\n The `.effectsOf` annotations differ."
157154
of efTagsIllegal:

compiler/sempass2.nim

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,13 @@ type
7777
gcUnsafe, isRecursive, isTopLevel, hasSideEffect, inEnforcedGcSafe: bool
7878
hasDangerousAssign, isInnerProc: bool
7979
inEnforcedNoSideEffects: bool
80-
maxLockLevel, currLockLevel: TLockLevel
8180
currOptions: TOptions
8281
config: ConfigRef
8382
graph: ModuleGraph
8483
c: PContext
8584
escapingParams: IntSet
8685
PEffects = var TEffects
8786

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-
9387
proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo) =
9488
if typ == nil: return
9589
when false:
@@ -107,33 +101,12 @@ proc isLocalVar(a: PEffects, s: PSym): bool =
107101
s.typ != nil and (s.kind in {skVar, skResult} or (s.kind == skParam and isOutParam(s.typ))) and
108102
sfGlobal notin s.flags and s.owner == a.owner
109103

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-
117104
proc lockLocations(a: PEffects; pragma: PNode) =
118105
if pragma.kind != nkExprColonExpr:
119106
localError(a.config, pragma.info, "locks pragma without argument")
120107
return
121-
var firstLL = TLockLevel(-1'i16)
122108
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)
132109
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
137110

138111
proc guardGlobal(a: PEffects; n: PNode; guard: PSym) =
139112
# check whether the corresponding lock is held:
@@ -438,8 +411,6 @@ proc listEffects(a: PEffects) =
438411
for e in items(a.exc): message(a.config, e.info, hintUser, typeToString(e.typ))
439412
for e in items(a.tags): message(a.config, e.info, hintUser, typeToString(e.typ))
440413
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)
443414

444415
proc catches(tracked: PEffects, e: PType) =
445416
let e = skipTypes(e, skipPtrs)
@@ -551,25 +522,6 @@ proc importedFromC(n: PNode): bool =
551522
# when imported from C, we assume GC-safety.
552523
result = n.kind == nkSym and sfImportc in n.sym.flags
553524

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-
573525
proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
574526
let pragma = s.ast[pragmasPos]
575527
let spec = effectSpec(pragma, wRaises)
@@ -583,7 +535,6 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
583535
markGcUnsafe(tracked, s)
584536
if tfNoSideEffect notin s.typ.flags:
585537
markSideEffect(tracked, s, n.info)
586-
mergeLockLevels(tracked, n, s.getLockLevel)
587538

588539
proc procVarCheck(n: PNode; conf: ConfigRef) =
589540
if n.kind in nkSymChoices:
@@ -623,11 +574,6 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
623574
proc assumeTheWorst(tracked: PEffects; n: PNode; op: PType) =
624575
addRaiseEffect(tracked, createRaise(tracked.graph, n), nil)
625576
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)
631577

632578
proc isOwnedProcVar(tracked: PEffects; n: PNode): bool =
633579
# XXX prove the soundness of this effect system rule
@@ -885,10 +831,9 @@ proc trackCall(tracked: PEffects; n: PNode) =
885831
if a.kind == nkSym:
886832
if a.sym == tracked.owner: tracked.isRecursive = true
887833
# even for recursive calls we need to check the lock levels (!):
888-
mergeLockLevels(tracked, n, a.sym.getLockLevel)
889834
if sfSideEffect in a.sym.flags: markSideEffect(tracked, a, n.info)
890835
else:
891-
mergeLockLevels(tracked, n, op.lockLevel)
836+
discard
892837
var effectList = op.n[0]
893838
if a.kind == nkSym and a.sym.kind == skMethod:
894839
propagateEffects(tracked, n, a.sym)
@@ -967,7 +912,6 @@ proc trackCall(tracked: PEffects; n: PNode) =
967912
type
968913
PragmaBlockContext = object
969914
oldLocked: int
970-
oldLockLevel: TLockLevel
971915
enforcedGcSafety, enforceNoSideEffects: bool
972916
oldExc, oldTags, oldForbids: int
973917
exc, tags, forbids: PNode
@@ -976,7 +920,6 @@ proc createBlockContext(tracked: PEffects): PragmaBlockContext =
976920
var oldForbidsLen = 0
977921
if tracked.forbids != nil: oldForbidsLen = tracked.forbids.len
978922
result = PragmaBlockContext(oldLocked: tracked.locked.len,
979-
oldLockLevel: tracked.currLockLevel,
980923
enforcedGcSafety: false, enforceNoSideEffects: false,
981924
oldExc: tracked.exc.len, oldTags: tracked.tags.len,
982925
oldForbids: oldForbidsLen)
@@ -989,7 +932,6 @@ proc unapplyBlockContext(tracked: PEffects; bc: PragmaBlockContext) =
989932
if bc.enforcedGcSafety: tracked.inEnforcedGcSafe = false
990933
if bc.enforceNoSideEffects: tracked.inEnforcedNoSideEffects = false
991934
setLen(tracked.locked, bc.oldLocked)
992-
tracked.currLockLevel = bc.oldLockLevel
993935
if bc.exc != nil:
994936
# beware that 'raises: []' is very different from not saying
995937
# anything about 'raises' in the 'cast' at all. Same applies for 'tags'.
@@ -1396,17 +1338,6 @@ proc checkMethodEffects*(g: ModuleGraph; disp, branch: PSym) =
13961338
localError(g.config, branch.info, "for method '" & branch.name.s &
13971339
"' the `.requires` or `.ensures` properties are incompatible.")
13981340

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-
14101341
proc setEffectsForProcType*(g: ModuleGraph; t: PType, n: PNode; s: PSym = nil) =
14111342
var effects = t.n[0]
14121343
if t.kind != tyProc or effects.kind != nkEffectList: return
@@ -1592,13 +1523,6 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
15921523
s.typ.flags.incl tfGcSafe
15931524
if not t.hasSideEffect and sfSideEffect notin s.flags:
15941525
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])
16021526
when defined(drnim):
16031527
if c.graph.strongSemCheck != nil: c.graph.strongSemCheck(c.graph, s, body)
16041528
when defined(useDfa):

0 commit comments

Comments
 (0)