revert strictDefs as the default (#24620)

revert https://github.com/nim-lang/Nim/pull/24225

see also https://forum.nim-lang.org/t/12646
This commit is contained in:
ringabout
2025-01-17 23:08:47 +08:00
committed by GitHub
parent 70d057fcc6
commit 2af9ddc286
9 changed files with 8 additions and 14 deletions

View File

@@ -172,4 +172,3 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasDefaultFloatRoundtrip")
defineSymbol("nimHasXorSet")
defineSymbol("nimHasLegacyNoStrictDefs")

View File

@@ -49,7 +49,7 @@ define:useStdoutAsStdmsg
@if nimUseStrictDefs:
experimental:strictDefs # deadcode
experimental:strictDefs
warningAsError[Uninit]:on
warningAsError[ProveInit]:on
@end

View File

@@ -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

View File

@@ -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:
@@ -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

View File

@@ -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}
))
@@ -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:
@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -21,4 +21,3 @@ when defined(nimStrictMode):
# future work: XDeclaredButNotUsed
switch("define", "nimVersion:" & NimVersion) # deadcode
switch("experimental", "strictDefs")

View File

@@ -1,5 +1,4 @@
discard """
matrix: "--legacy:nostrictdefs"
joinable: false
"""