Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes addr/hiddenAddr in strictdefs #23477

Merged
merged 9 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions compiler/astalgo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ proc initTabIter*(ti: var TTabIter, tab: TStrTable): PSym =
result = nextIter(ti, tab)

iterator items*(tab: TStrTable): PSym =
var it: TTabIter
var it: TTabIter = default(TTabIter)
var s = initTabIter(it, tab)
while s != nil:
yield s
Expand Down Expand Up @@ -758,14 +758,6 @@ proc iiTablePut(t: var TIITable, key, val: int) =
iiTableRawInsert(t.data, key, val)
inc(t.counter)

proc isAddrNode*(n: PNode): bool =
case n.kind
of nkAddr, nkHiddenAddr: true
of nkCallKinds:
if n[0].kind == nkSym and n[0].sym.magic == mAddr: true
else: false
else: false

proc listSymbolNames*(symbols: openArray[PSym]): string =
result = ""
for sym in symbols:
Expand Down
4 changes: 2 additions & 2 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ proc getRecordFields(m: BModule; typ: PType, check: var IntSet): Rope =
genMemberProcHeader(m, prc, header, false, true)
result.addf "$1;$n", [header]
if isCtorGen and not isDefaultCtorGen:
var ch: IntSet
var ch: IntSet = default(IntSet)
result.addf "$1() = default;$n", [getTypeDescAux(m, typ, ch, dkOther)]

proc fillObjectFields*(m: BModule; typ: PType) =
Expand Down Expand Up @@ -1624,7 +1624,7 @@ proc generateRttiDestructor(g: ModuleGraph; typ: PType; owner: PSym; kind: TType
))
)
else:
let addrOf = newNodeIT(nkAddr, info, theProc.typ.firstParamType)
let addrOf = newNodeIT(nkHiddenAddr, info, theProc.typ.firstParamType)
addrOf.add newDeref(newTreeIT(
nkCast, info, castType, newNodeIT(nkType, info, castType),
newSymNode(dest)
Expand Down
4 changes: 2 additions & 2 deletions compiler/evalffi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ proc fficast*(conf: ConfigRef, x: PNode, destTyp: PType): PNode =
proc callForeignFunction*(conf: ConfigRef, call: PNode): PNode =
internalAssert conf, call[0].kind == nkPtrLit

var cif: TCif
var cif: TCif = default(TCif)
var sig: ParamList = default(ParamList)
# use the arguments' types for varargs support:
for i in 1..<call.len:
Expand Down Expand Up @@ -474,7 +474,7 @@ proc callForeignFunction*(conf: ConfigRef, fn: PNode, fntyp: PType,
info: TLineInfo): PNode =
internalAssert conf, fn.kind == nkPtrLit

var cif: TCif
var cif: TCif = default(TCif)
var sig: ParamList = default(ParamList)
for i in 0..len-1:
var aTyp = args[i+start].typ
Expand Down
2 changes: 1 addition & 1 deletion compiler/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ proc importSymbol(c: PContext, n: PNode, fromMod: PSym; importSet: var IntSet) =
# for an enumeration we have to add all identifiers
if multiImport:
# for a overloadable syms add all overloaded routines
var it: ModuleIter
var it: ModuleIter = default(ModuleIter)
var e = initModuleIter(it, c.graph, fromMod, s.name)
while e != nil:
if e.name.id != s.name.id: internalError(c.config, n.info, "importSymbol: 3")
Expand Down
2 changes: 1 addition & 1 deletion compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
p.body.add("++excHandler;\L")
var tmpFramePtr = rope"F"
lineF(p, "try {$n", [])
var a: TCompRes
var a: TCompRes = default(TCompRes)
gen(p, n[0], a)
moveInto(p, a, r)
var generalCatchBranchExists = false
Expand Down
16 changes: 8 additions & 8 deletions compiler/lookups.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ proc nextIdentIter(ti: var ModuleIter; marked: var IntSet; im: ImportedModule;
return result

iterator symbols(im: ImportedModule; marked: var IntSet; name: PIdent; g: ModuleGraph): PSym =
var ti: ModuleIter
var ti: ModuleIter = default(ModuleIter)
var candidate = initIdentIter(ti, marked, im, name, g)
while candidate != nil:
yield candidate
Expand All @@ -150,7 +150,7 @@ iterator importedItems*(c: PContext; name: PIdent): PSym =
yield s

proc allPureEnumFields(c: PContext; name: PIdent): seq[PSym] =
var ti: TIdentIter
var ti: TIdentIter = default(TIdentIter)
result = @[]
var res = initIdentIter(ti, c.pureEnumFields, name)
while res != nil:
Expand Down Expand Up @@ -222,7 +222,7 @@ proc debugScopes*(c: PContext; limit=0, max = int.high) {.deprecated.} =
proc searchInScopesAllCandidatesFilterBy*(c: PContext, s: PIdent, filter: TSymKinds): seq[PSym] =
result = @[]
for scope in allScopes(c.currentScope):
var ti: TIdentIter
var ti: TIdentIter = default(TIdentIter)
var candidate = initIdentIter(ti, scope.symbols, s)
while candidate != nil:
if candidate.kind in filter:
Expand All @@ -240,7 +240,7 @@ proc searchInScopesFilterBy*(c: PContext, s: PIdent, filter: TSymKinds): seq[PSy
result = @[]
block outer:
for scope in allScopes(c.currentScope):
var ti: TIdentIter
var ti: TIdentIter = default(TIdentIter)
var candidate = initIdentIter(ti, scope.symbols, s)
while candidate != nil:
if candidate.kind in filter:
Expand Down Expand Up @@ -272,7 +272,7 @@ proc isAmbiguous*(c: PContext, s: PIdent, filter: TSymKinds, sym: var PSym): boo
result = false
block outer:
for scope in allScopes(c.currentScope):
var ti: TIdentIter
var ti: TIdentIter = default(TIdentIter)
var candidate = initIdentIter(ti, scope.symbols, s)
var scopeHasCandidate = false
while candidate != nil:
Expand Down Expand Up @@ -347,7 +347,7 @@ proc getSymRepr*(conf: ConfigRef; s: PSym, getDeclarationPath = true): string =

proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) =
# check if all symbols have been used and defined:
var it: TTabIter
var it: TTabIter = default(TTabIter)
var s = initTabIter(it, scope.symbols)
var missingImpls = 0
var unusedSyms: seq[tuple[sym: PSym, key: string]] = @[]
Expand Down Expand Up @@ -558,7 +558,7 @@ proc errorUseQualifier(c: PContext; info: TLineInfo; s: PSym; amb: var bool): PS
amb = false

proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) =
var amb: bool
var amb: bool = false
discard errorUseQualifier(c, info, s, amb)

proc errorUseQualifier*(c: PContext; info: TLineInfo; candidates: seq[PSym]; prefix = "use one of") =
Expand Down Expand Up @@ -675,7 +675,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
result = strTableGet(c.topLevelScope.symbols, ident)
else:
if c.importModuleLookup.getOrDefault(m.name.id).len > 1:
var amb: bool
var amb: bool = false
result = errorUseQualifier(c, n.info, m, amb)
else:
result = someSym(c.graph, m, ident)
Expand Down
2 changes: 1 addition & 1 deletion compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ proc commandScan(cache: IdentCache, config: ConfigRef) =
var stream = llStreamOpen(f, fmRead)
if stream != nil:
var
L: Lexer
L: Lexer = default(Lexer)
tok: Token = default(Token)
openLexer(L, f, stream, cache, config)
while true:
Expand Down
4 changes: 2 additions & 2 deletions compiler/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ proc nextModuleIter*(mi: var ModuleIter; g: ModuleGraph): PSym =
iterator allSyms*(g: ModuleGraph; m: PSym): PSym =
let importHidden = optImportHidden in m.options
if isCachedModule(g, m):
var rodIt: RodIter
var rodIt: RodIter = default(RodIter)
var r = initRodIterAllSyms(rodIt, g.config, g.cache, g.packed, FileIndex m.position, importHidden)
while r != nil:
yield r
Expand All @@ -280,7 +280,7 @@ proc systemModuleSym*(g: ModuleGraph; name: PIdent): PSym =
result = someSym(g, g.systemModule, name)

iterator systemModuleSyms*(g: ModuleGraph; name: PIdent): PSym =
var mi: ModuleIter
var mi: ModuleIter = default(ModuleIter)
var r = initModuleIter(mi, g, g.systemModule, name)
while r != nil:
yield r
Expand Down
4 changes: 2 additions & 2 deletions compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ proc fileInfoIdx*(conf: ConfigRef; filename: AbsoluteFile; isKnownFile: var bool
conf.m.filenameToIndexTbl[canon2] = result

proc fileInfoIdx*(conf: ConfigRef; filename: AbsoluteFile): FileIndex =
var dummy: bool
var dummy: bool = false
result = fileInfoIdx(conf, filename, dummy)

proc fileInfoIdx*(conf: ConfigRef; filename: RelativeFile; isKnownFile: var bool): FileIndex =
fileInfoIdx(conf, AbsoluteFile expandFilename(filename.string), isKnownFile)

proc fileInfoIdx*(conf: ConfigRef; filename: RelativeFile): FileIndex =
var dummy: bool
var dummy: bool = false
fileInfoIdx(conf, AbsoluteFile expandFilename(filename.string), dummy)

proc newLineInfo*(fileInfoIdx: FileIndex, line, col: int): TLineInfo =
Expand Down
2 changes: 1 addition & 1 deletion compiler/nimeval.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ proc selectUniqueSymbol*(i: Interpreter; name: string;
assert i != nil
assert i.mainModule != nil, "no main module selected"
let n = getIdent(i.graph.cache, name)
var it: ModuleIter
var it: ModuleIter = default(ModuleIter)
var s = initModuleIter(it, i.graph, i.mainModule, n)
result = nil
while s != nil:
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ proc optimize*(n: PNode): PNode =
Now assume 'use' raises, then we shouldn't do the 'wasMoved(s)'
]#
var c: Con = Con()
var b: BasicBlock
var b: BasicBlock = default(BasicBlock)
analyse(c, b, n)
if c.somethingTodo:
result = shallowCopy(n)
Expand Down
2 changes: 1 addition & 1 deletion compiler/pipelines.nim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator
stream: PLLStream): bool =
if graph.stopCompile(): return true
var
p: Parser
p: Parser = default(Parser)
s: PLLStream
fileIdx = module.fileIdx

Expand Down
4 changes: 2 additions & 2 deletions compiler/procfind.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ proc equalGenericParams(procA, procB: PNode): bool =
proc searchForProcAux(c: PContext, scope: PScope, fn: PSym): PSym =
const flags = {ExactGenericParams, ExactTypeDescValues,
ExactConstraints, IgnoreCC}
var it: TIdentIter
var it: TIdentIter = default(TIdentIter)
result = initIdentIter(it, scope.symbols, fn.name)
while result != nil:
if result.kind == fn.kind: #and sameType(result.typ, fn.typ, flags):
Expand Down Expand Up @@ -76,7 +76,7 @@ when false:
proc searchForBorrowProc*(c: PContext, startScope: PScope, fn: PSym): PSym =
# Searches for the fn in the symbol table. If the parameter lists are suitable
# for borrowing the sym in the symbol table is returned, else nil.
var it: TIdentIter
var it: TIdentIter = default(TIdentIter)
for scope in walkScopes(startScope):
result = initIdentIter(it, scope.symbols, fn.Name)
while result != nil:
Expand Down
2 changes: 1 addition & 1 deletion compiler/reorder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ proc getStrongComponents(g: var DepG): seq[seq[DepN]] =
## Tarjan's algorithm. Performs a topological sort
## and detects strongly connected components.
result = @[]
var s: seq[DepN]
var s: seq[DepN] = @[]
var idx = 0
for v in g.mitems:
if v.idx < 0:
Expand Down
8 changes: 4 additions & 4 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
# `matches` may find new symbols, so keep track of count
var symCount = c.currentScope.symbols.counter

var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
# https://github.com/nim-lang/Nim/issues/21272
# prevent mutation during iteration by storing them in a seq
# luckily `initCandidateSymbols` does just that
Expand Down Expand Up @@ -411,7 +411,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =

proc bracketNotFoundError(c: PContext; n: PNode) =
var errors: CandidateErrors = @[]
var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
let headSymbol = n[0]
var symx = initOverloadIter(o, c, headSymbol)
while symx != nil:
Expand All @@ -434,7 +434,7 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string =
# also avoid slowdowns in evaluating `compiles(expr)`.
discard
else:
var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
var sym = initOverloadIter(o, c, f)
while sym != nil:
result &= "\n found $1" % [getSymRepr(c.config, sym)]
Expand Down Expand Up @@ -479,7 +479,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
filter, result, alt, errors, efExplain in flags,
errorsEnabled, flags)

var dummyErrors: CandidateErrors
var dummyErrors: CandidateErrors = @[]
template pickSpecialOp(headSymbol) =
pickBestCandidate(c, headSymbol, n, orig, initialBinding,
filter, result, alt, dummyErrors, efExplain in flags,
Expand Down
13 changes: 5 additions & 8 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
let headSymbol = macroCall[0]
var cands = 0
var cand: PSym = nil
var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
var symx = initOverloadIter(o, c, headSymbol)
while symx != nil:
if symx.kind in {skTemplate, skMacro} and symx.typ.len == macroCall.len:
Expand Down Expand Up @@ -2448,9 +2448,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: P
of mAddr:
markUsed(c, n.info, s)
checkSonsLen(n, 2, c.config)
result[0] = newSymNode(s, n[0].info)
result[1] = semAddrArg(c, n[1])
result.typ = makePtrType(c, result[1].typ)
result = semAddr(c, n[1])
of mTypeOf:
markUsed(c, n.info, s)
result = semTypeOf(c, n)
Expand Down Expand Up @@ -2861,7 +2859,7 @@ proc semExport(c: PContext, n: PNode): PNode =
result = newNodeI(nkExportStmt, n.info)
for i in 0..<n.len:
let a = n[i]
var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
var s = initOverloadIter(o, c, a)
if s == nil:
localError(c.config, a.info, errGenerated, "cannot export: " & renderTree(a))
Expand Down Expand Up @@ -2991,7 +2989,7 @@ proc getNilType(c: PContext): PType =
c.nilTypeCache = result

proc enumFieldSymChoice(c: PContext, n: PNode, s: PSym): PNode =
var o: TOverloadIter
var o: TOverloadIter = default(TOverloadIter)
var i = 0
var a = initOverloadIter(o, c, n)
while a != nil:
Expand Down Expand Up @@ -3335,8 +3333,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
of nkAddr:
result = n
checkSonsLen(n, 1, c.config)
result[0] = semAddrArg(c, n[0])
result.typ = makePtrType(c, result[0].typ)
result = semAddr(c, n[0])
of nkHiddenAddr, nkHiddenDeref:
checkSonsLen(n, 1, c.config)
n[0] = semExpr(c, n[0], flags, expectedType)
Expand Down
2 changes: 1 addition & 1 deletion compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ proc semGenericStmt(c: PContext, n: PNode,
#var s = qualifiedLookUp(c, n, luf)
#if s != nil: result = semGenericStmtSymbol(c, n, s)
# XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
var dummy: bool
var dummy: bool = false
result = fuzzyLookup(c, n, flags, ctx, dummy)
of nkSym:
let a = n.sym
Expand Down
10 changes: 5 additions & 5 deletions compiler/semmagic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ proc addDefaultFieldForNew(c: PContext, n: PNode): PNode =
if asgnExpr.sons.len > 1:
result = newTree(nkAsgn, result[1], asgnExpr)

proc semAddrArg(c: PContext; n: PNode): PNode =
proc semAddr(c: PContext; n: PNode): PNode =
result = newNodeI(nkAddr, n.info)
let x = semExprWithType(c, n)
if x.kind == nkSym:
x.sym.flags.incl(sfAddrTaken)
if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}:
localError(c.config, n.info, errExprHasNoAddress)
result = x
result.add x
result.typ = makePtrType(c, x.typ)

proc semTypeOf(c: PContext; n: PNode): PNode =
var m = BiggestInt 1 # typeOfIter
Expand Down Expand Up @@ -561,9 +563,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
case n[0].sym.magic
of mAddr:
checkSonsLen(n, 2, c.config)
result = n
result[1] = semAddrArg(c, n[1])
result.typ = makePtrType(c, result[1].typ)
result = semAddr(c, n[1])
of mTypeOf:
result = semTypeOf(c, n)
of mSizeOf:
Expand Down
5 changes: 3 additions & 2 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
if paramType != nil and tfNotNil in paramType.flags and n.typ != nil:
let ntyp = n.typ.skipTypesOrNil({tyVar, tyLent, tySink})
if ntyp != nil and tfNotNil notin ntyp.flags:
if isAddrNode(n):
if n.kind in {nkAddr, nkHiddenAddr}:
# addr(x[]) can't be proven, but addr(x) can:
if not containsNode(n, {nkDerefExpr, nkHiddenDeref}): return
elif (n.kind == nkSym and n.sym.kind in routineKinds) or
Expand Down Expand Up @@ -1204,7 +1204,8 @@ proc track(tracked: PEffects, n: PNode) =
# bug #15038: ensure consistency
if not hasDestructor(n.typ) and sameType(n.typ, n.sym.typ): n.typ = n.sym.typ
of nkHiddenAddr, nkAddr:
if n[0].kind == nkSym and isLocalSym(tracked, n[0].sym):
if n[0].kind == nkSym and isLocalSym(tracked, n[0].sym) and
n.typ.kind != tyVar:
ringabout marked this conversation as resolved.
Show resolved Hide resolved
useVarNoInitCheck(tracked, n[0], n[0].sym)
else:
track(tracked, n[0])
Expand Down
Loading
Loading