Skip to content

Commit

Permalink
revert strictDefs as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Jan 17, 2025
1 parent 70d057f commit 3fe1cb5
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,3 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasDefaultFloatRoundtrip")
defineSymbol("nimHasXorSet")

defineSymbol("nimHasLegacyNoStrictDefs")
2 changes: 1 addition & 1 deletion compiler/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ define:useStdoutAsStdmsg


@if nimUseStrictDefs:
experimental:strictDefs # deadcode
experimental:strictDefs
warningAsError[Uninit]:on
warningAsError[ProveInit]:on
@end
Expand Down
2 changes: 0 additions & 2 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ type
## Useful for libraries that rely on local passC
jsNoLambdaLifting
## Old transformation for closures in JS backend
noStrictDefs
## disable "strictdefs"

SymbolFilesOption* = enum
disabledSf, writeOnlySf, readOnlySf, v2Sf, stressTest
Expand Down
5 changes: 2 additions & 3 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ proc newHiddenAddrTaken(c: PContext, n: PNode, isOutParam: bool): PNode =
if aa notin {arLValue, arLocalLValue}:
if aa == arDiscriminant and c.inUncheckedAssignSection > 0:
discard "allow access within a cast(unsafeAssign) section"
elif noStrictDefs notin c.config.legacyFeatures and aa == arAddressableConst and
elif strictDefs in c.features and aa == arAddressableConst and
sym != nil and sym.kind == skLet and isOutParam:
discard "allow let varaibles to be passed to out parameters"
else:
Expand Down Expand Up @@ -2068,8 +2068,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
let root = getRoot(a)
let useStrictDefLet = root != nil and root.kind == skLet and
assignable == arAddressableConst and
noStrictDefs notin c.config.legacyFeatures and
isLocalSym(root)
strictDefs in c.features and isLocalSym(root)
if le == nil:
localError(c.config, a.info, "expression has no type")
elif (skipTypes(le, {tyGenericInst, tyAlias, tySink}).kind notin {tyVar} and
Expand Down
6 changes: 3 additions & 3 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ proc initVar(a: PEffects, n: PNode; volatileCheck: bool) =
if volatileCheck: makeVolatile(a, s)
for x in a.init:
if x == s.id:
if noStrictDefs notin a.c.config.legacyFeatures and s.kind == skLet:
if strictDefs in a.c.features and s.kind == skLet:
localError(a.config, n.info, errXCannotBeAssignedTo %
renderTree(n, {renderNoComments}
))
Expand Down Expand Up @@ -379,7 +379,7 @@ proc useVar(a: PEffects, n: PNode) =
if s.typ.requiresInit:
message(a.config, n.info, warnProveInit, s.name.s)
elif a.leftPartOfAsgn <= 0:
if noStrictDefs notin a.c.config.legacyFeatures:
if strictDefs in a.c.features:
if s.kind == skLet:
localError(a.config, n.info, errLetNeedsInit)
else:
Expand Down Expand Up @@ -1664,7 +1664,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =

if not isEmptyType(s.typ.returnType) and
(s.typ.returnType.requiresInit or s.typ.returnType.skipTypes(abstractInst).kind == tyVar or
noStrictDefs notin c.config.legacyFeatures) and
strictDefs in c.features) and
s.kind in {skProc, skFunc, skConverter, skMethod} and s.magic == mNone and
sfNoInit notin s.flags:
var res = s.ast[resultPos].sym # get result symbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
else:
checkNilable(c, v)
# allow let to not be initialised if imported from C:
if v.kind == skLet and sfImportc notin v.flags and (noStrictDefs in c.config.legacyFeatures or not isLocalSym(v)):
if v.kind == skLet and sfImportc notin v.flags and (strictDefs notin c.features or not isLocalSym(v)):
localError(c.config, a.info, errLetNeedsInit)
if sfCompileTime in v.flags:
var x = newNodeI(result.kind, v.info)
Expand Down
2 changes: 1 addition & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ proc isLValue(c: PContext; n: PNode, isOutParam = false): bool {.inline.} =
result = c.inUncheckedAssignSection > 0
of arAddressableConst:
let sym = getRoot(n)
result = noStrictDefs notin c.config.legacyFeatures and sym != nil and sym.kind == skLet and isOutParam
result = strictDefs in c.features and sym != nil and sym.kind == skLet and isOutParam
else:
result = false

Expand Down
1 change: 0 additions & 1 deletion config/config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ when defined(nimStrictMode):
# future work: XDeclaredButNotUsed

switch("define", "nimVersion:" & NimVersion) # deadcode
switch("experimental", "strictDefs")
1 change: 0 additions & 1 deletion tests/msgs/twarningaserror.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
matrix: "--legacy:nostrictdefs"
joinable: false
"""

Expand Down

0 comments on commit 3fe1cb5

Please sign in to comment.