Skip to content

Commit

Permalink
progress: adds legacy:nostrictdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Nov 7, 2024
1 parent 82eea40 commit df6093c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasEnsureMove")
defineSymbol("nimHasNoReturnError")

defineSymbol("nimUseStrictDefs")
defineSymbol("nimUseStrictDefs") # deadcode
defineSymbol("nimHasNolineTooLong")

defineSymbol("nimHasCastExtendedVm")
Expand All @@ -171,3 +171,5 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasJsNoLambdaLifting")
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 @@ -47,7 +47,7 @@ define:useStdoutAsStdmsg


@if nimUseStrictDefs:
experimental:strictDefs
experimental:strictDefs # deadcode
warningAsError[Uninit]:on
warningAsError[ProveInit]:on
@end
Expand Down
4 changes: 3 additions & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type
strictEffects,
unicodeOperators, # deadcode
flexibleOptionalParams,
strictDefs,
strictDefs, # deadcode
strictCaseObjects,
inferGenericTypes,
openSym, # remove nfDisabledOpenSym when this is default
Expand All @@ -248,6 +248,8 @@ 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: 3 additions & 2 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 strictDefs in c.features and aa == arAddressableConst and
elif noStrictDefs notin c.config.legacyFeatures 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 @@ -2050,7 +2050,8 @@ 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
strictDefs in c.features and isLocalSym(root)
noStrictDefs notin c.config.legacyFeatures 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 @@ -220,7 +220,7 @@ proc initVar(a: PEffects, n: PNode; volatileCheck: bool) =
if volatileCheck: makeVolatile(a, s)
for x in a.init:
if x == s.id:
if strictDefs in a.c.features and s.kind == skLet:
if noStrictDefs notin a.c.config.legacyFeatures and s.kind == skLet:
localError(a.config, n.info, errXCannotBeAssignedTo %
renderTree(n, {renderNoComments}
))
Expand Down Expand Up @@ -378,7 +378,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 strictDefs in a.c.features:
if noStrictDefs notin a.c.config.legacyFeatures:
if s.kind == skLet:
localError(a.config, n.info, errLetNeedsInit)
else:
Expand Down Expand Up @@ -1658,7 +1658,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
strictDefs in c.features) and
noStrictDefs notin c.config.legacyFeatures) and
s.kind in {skProc, skFunc, skConverter, skMethod} and s.magic == mNone:
var res = s.ast[resultPos].sym # get result symbol
if res.id notin t.init and breaksBlock(body) != bsNoReturn:
Expand Down
2 changes: 1 addition & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,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 (strictDefs notin c.features or not isLocalSym(v)):
if v.kind == skLet and sfImportc notin v.flags and (noStrictDefs in c.config.legacyFeatures 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 @@ -2277,7 +2277,7 @@ proc isLValue(c: PContext; n: PNode, isOutParam = false): bool {.inline.} =
result = c.inUncheckedAssignSection > 0
of arAddressableConst:
let sym = getRoot(n)
result = strictDefs in c.features and sym != nil and sym.kind == skLet and isOutParam
result = noStrictDefs notin c.config.legacyFeatures and sym != nil and sym.kind == skLet and isOutParam
else:
result = false

Expand Down
2 changes: 1 addition & 1 deletion testament/important_packages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pkg "plotly", "nim c examples/all.nim"
pkg "pnm"
pkg "polypbren"
pkg "presto"
# pkg "prologue", "nimble tcompile"
pkg "prologue", "nimble tcompile"
pkg "protobuf", "nim c -o:protobuff -r src/protobuf.nim"
pkg "rbtree"
pkg "react", "nimble example"
Expand Down
5 changes: 1 addition & 4 deletions tests/cpp/tasync_cpp.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
discard """
targets: "cpp"
output: "hello"
disabled: true
cmd: "nim cpp --clearNimblePath --nimblePath:build/deps/pkgs2 $file"
cmd: "nim cpp --legacy:nostrictdefs --clearNimblePath --nimblePath:build/deps/pkgs2 $file"
"""

# TODO:

# bug #3299

import jester
Expand Down
10 changes: 5 additions & 5 deletions tests/msgs/twarningaserror.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discard """
matrix: "--legacy:nostrictdefs"
joinable: false
"""

Expand Down Expand Up @@ -28,9 +29,8 @@ template gn2 =
discard fn()
{.warningAsError[ProveInit]:off.}

when false: # TODO: adds nostrictdefs
doAssert not compiles(fn1())
doAssert compiles(fn2())
doAssert not compiles(fn1())
doAssert compiles(fn2())

doAssert not compiles(gn1())
doAssert compiles(gn2())
doAssert not compiles(gn1())
doAssert compiles(gn2())

0 comments on commit df6093c

Please sign in to comment.