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

tool: suggest rename graph usageSym to forwardedSym #885

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions compiler/modules/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ proc importSymbol(c: PContext, n: PNode, fromMod: PSym; importSet: var IntSet):
else:
rawImportSymbol(c, s, fromMod, importSet)
if c.graph.onSymImport != nil:
c.graph.onSymImport(c.graph, n.info, s, c.graph.usageSym, false)
c.graph.onSymImport(c.graph, n.info, s, false)
else:
result =
newSym(skError, ident, nextSymId(c.idgen), getCurrOwner(c), n.info)
Expand Down Expand Up @@ -332,7 +332,7 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym =
localReport(c.config, n.info, reportSym(rsemDeprecated, realModule))

if c.graph.onSymImport != nil:
c.graph.onSymImport(c.graph, n.info, result, c.graph.usageSym, false)
c.graph.onSymImport(c.graph, n.info, result, false)

importStmtResult.add:
case result.kind
Expand Down
6 changes: 2 additions & 4 deletions compiler/modules/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type
vm*: RootRef # unfortunately the 'vm' state is shared project-wise, this will
# be clarified in later compiler implementations.
doStopCompile*: proc(): bool {.closure.}
usageSym*: PSym # for nimsuggest
forwardedSym*: PSym # for nimsuggest
owners*: seq[PSym]
methods*: seq[tuple[methods: seq[PSym], dispatcher: PSym]] # needs serialization!
systemModule*: PSym
Expand Down Expand Up @@ -158,8 +158,7 @@ type
close: TPassClose,
isFrontend: bool]

SuggestCallback* = proc (graph: ModuleGraph, info: TLineInfo, s: PSym,
usageSym: var PSym, isDecl: bool)
SuggestCallback* = proc (graph: ModuleGraph, info: TLineInfo, s: PSym, isDecl: bool)
## callback is used to decouple regular compiler code from suggest tool

proc resetForBackend*(g: ModuleGraph) =
Expand Down Expand Up @@ -528,7 +527,6 @@ proc resetAllModules*(g: ModuleGraph) =
g.importStack = @[]
g.transformed = @[]
g.inclToMod = initTable[FileIndex, FileIndex]()
g.usageSym = nil
g.owners = @[]
g.methods = @[]
initStrTable(g.compilerprocs)
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/semdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ proc markUsed*(c: PContext; info: TLineInfo; s: PSym) =
if sfError in s.flags: userError(conf, info, s)
when defined(nimsuggest):
if c.graph.onMarkUsed != nil:
c.graph.onMarkUsed(c.graph, info, s, c.graph.usageSym, false)
c.graph.onMarkUsed(c.graph, info, s, false)
if {optStyleHint, optStyleError} * conf.globalOptions != {}:
styleCheckUse(conf, info, s)
markOwnerModuleAsUsed(c, s)
2 changes: 1 addition & 1 deletion compiler/sem/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3246,7 +3246,7 @@ proc semBlock(c: PContext, n: PNode; flags: TExprFlags): PNode =
elif labl.owner == nil:
labl.owner = c.p.owner

suggestSym(c.graph, lablNode.info, labl, c.graph.usageSym)
suggestSym(c.graph, lablNode.info, labl)
styleCheckDef(c.config, labl)

lablNode
Expand Down
8 changes: 4 additions & 4 deletions compiler/sem/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ proc semBreakStmt(c: PContext, n: PNode): ElaborateAst =
# make sure the label is okay to use:
if s.kind == skLabel and s.owner.id == c.p.owner.id:
incl(s.flags, sfUsed)
suggestSym(c.graph, n.info, s, c.graph.usageSym)
suggestSym(c.graph, n.info, s)
else:
# a label not part of the current context
result.diag = PAstDiag(kind: adSemInvalidControlFlow, label: s)
Expand Down Expand Up @@ -352,7 +352,7 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
result.options = c.config.options

let info = getIdentLineInfo(n)
suggestSym(c.graph, info, result, c.graph.usageSym)
suggestSym(c.graph, info, result)

proc checkNilableOrError(c: PContext; def: PNode): PNode =
## checks if a symbol node is nilable, on success returns def, else nkError
Expand Down Expand Up @@ -2513,7 +2513,7 @@ proc semRoutineName(c: PContext, n: PNode, kind: TSymKind; allowAnon = true): PN
if c.isTopLevel:
incl(s.flags, sfGlobal)

suggestSym(c.graph, getIdentLineInfo(n), s, c.graph.usageSym)
suggestSym(c.graph, getIdentLineInfo(n), s)
styleCheckDef(c.config, s)
else:
# XXX: this should be the resonsibility of the macro sanitizer instead
Expand Down Expand Up @@ -2717,7 +2717,7 @@ proc semProcAux(c: PContext, n: PNode, validPragmas: TSpecialWords,
if not comesFromShadowScope:
excl(proto.flags, sfForward)
incl(proto.flags, sfWasForwarded)
suggestSym(c.graph, s.info, proto, c.graph.usageSym)
suggestSym(c.graph, s.info, proto)
closeScope(c) # close scope with wrong parameter symbols
openScope(c) # open scope for old (correct) parameter symbols
if proto.ast[genericParamsPos].isGenericParams:
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode =
result = newSymNode(s, n.info)
# Issue #12832
when defined(nimsuggest):
suggestSym(c.graph, n.info, s, c.graph.usageSym, false)
suggestSym(c.graph, n.info, s, false)
# field access (dot expr) will be handled by builtinFieldAccess
if not isField and {optStyleHint, optStyleError} * c.config.globalOptions != {}:
styleCheckUse(c.config, n.info, s)
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
for i in 0..<n.len-2:
var f = semIdentWithPragma(c, skField, n[i], {sfExported})
let info = getIdentLineInfo(n[i])
suggestSym(c.graph, info, f, c.graph.usageSym)
suggestSym(c.graph, info, f)
f.typ = typ
f.position = pos
f.options = c.config.options
Expand Down
17 changes: 7 additions & 10 deletions compiler/tools/suggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,22 @@ when defined(nimsuggest):
let x = if info == s.info and info.col == s.info.col: ideDef else: ideUse
suggestResult(g.config, symToSuggest(g, s, isLocal=false, x, info, 100, PrefixMatch.None, false, 0))

proc findDefinition(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym) =
proc findDefinition(g: ModuleGraph; info: TLineInfo; s: PSym) =
if s.isNil: return
if isTracked(info, g.config.m.trackPos, s.name.s.len) or (s == usageSym and sfForward notin s.flags):
suggestResult(g.config, symToSuggest(g, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0, useSuppliedInfo = s == usageSym))
if isTracked(info, g.config.m.trackPos, s.name.s.len) or (g.forwardedSym == s and sfForward notin s.flags):
suggestResult(g.config, symToSuggest(g, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
if sfForward notin s.flags:
suggestQuit()
else:
usageSym = s
g.forwardedSym = s

proc ensureIdx[T](x: var T, y: int) =
if x.len <= y: x.setLen(y+1)

proc ensureSeq[T](x: var seq[T]) =
if x == nil: newSeq(x, 0)

proc suggestSym*(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.inline.} =
proc suggestSym*(g: ModuleGraph; info: TLineInfo; s: PSym; isDecl=true) {.inline.} =
## misnamed: should be 'symDeclared'
let conf = g.config
when defined(nimsuggest):
Expand All @@ -524,14 +524,11 @@ proc suggestSym*(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym; i
else:
s.addNoDup(info)

if conf.ideCmd == ideUse:
findUsages(g, info, s, usageSym)
elif conf.ideCmd == ideDef:
findDefinition(g, info, s, usageSym)
if conf.ideCmd == ideDef:
findDefinition(g, info, s)
elif conf.ideCmd == ideDus and s != nil:
if isTracked(info, conf.m.trackPos, s.name.s.len):
suggestResult(conf, symToSuggest(g, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
findUsages(g, info, s, usageSym)
elif conf.ideCmd == ideHighlight and info.fileIndex == conf.m.trackPos.fileIndex:
suggestResult(conf, symToSuggest(g, s, isLocal=false, ideHighlight, info, 100, PrefixMatch.None, false, 0))
elif conf.ideCmd == ideOutline and isDecl:
Expand Down
8 changes: 3 additions & 5 deletions nimsuggest/nimsuggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
conf.m.trackPos = newLineInfo(dirtyIdx, line, col)
conf.m.trackPosAttached = false
conf.errorCounter = 0
if conf.suggestVersion == 1:
graph.usageSym = nil
if not isKnownFile:
graph.compileProject(dirtyIdx)
if conf.suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and
Expand All @@ -259,7 +257,7 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
if isKnownFile:
graph.compileProject(modIdx)
if conf.ideCmd in {ideUse, ideDus}:
let u = if conf.suggestVersion != 1: graph.symFromInfo(conf.m.trackPos) else: graph.usageSym
let u = graph.symFromInfo(conf.m.trackPos)
if u != nil:
listUsages(graph, u)
else:
Expand Down Expand Up @@ -731,8 +729,8 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef, argv: openArray[string])
myLog(conf, "START " & conf.projectFull.string)

var graph = newModuleGraph(cache, conf)
graph.onMarkUsed = proc (g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym; isDecl: bool) =
suggestSym(g, info, s, usageSym, isDecl)
graph.onMarkUsed = proc (g: ModuleGraph; info: TLineInfo; s: PSym; isDecl: bool) =
suggestSym(g, info, s, isDecl)
graph.onSymImport = graph.onMarkUsed # same callback
if self.loadConfigsAndProcessCmdLine(cache, conf, graph, argv):
# defaulting to customizing for the C backend matches what
Expand Down
Loading