diff --git a/compiler/ast/lineinfos.nim b/compiler/ast/lineinfos.nim index 086aa7066e1..41c050f005d 100644 --- a/compiler/ast/lineinfos.nim +++ b/compiler/ast/lineinfos.nim @@ -26,6 +26,12 @@ type col*: int16 fileIndex*: FileIndex + SourceLinePosition* = tuple + ## Identifies a line in a source file. Only intended for use by + ## the profiler. + fileIndex: typeof(TLineInfo.fileIndex) + line: typeof(TLineInfo.line) + LineColPair* = tuple line: typeof(TLineInfo.line) col: typeof(TLineInfo.col) diff --git a/compiler/front/msgs.nim b/compiler/front/msgs.nim index 74d75240d74..2a02ce4a6c6 100644 --- a/compiler/front/msgs.nim +++ b/compiler/front/msgs.nim @@ -315,13 +315,6 @@ proc errorActions( elif eh == doRaise: result = (doRaise, false) - -proc `==`*(a, b: TLineInfo): bool = - result = a.line == b.line and a.fileIndex == b.fileIndex - -proc exactEquals*(a, b: TLineInfo): bool = - result = a.fileIndex == b.fileIndex and a.line == b.line and a.col == b.col - proc getContext*(conf: ConfigRef; lastinfo: TLineInfo): seq[ReportContext] = ## Get list of context context entries from the current message context ## information. Context messages can later be used in the diff --git a/compiler/front/options.nim b/compiler/front/options.nim index 23ce3ed441f..13f1f21a43f 100644 --- a/compiler/front/options.nim +++ b/compiler/front/options.nim @@ -166,7 +166,7 @@ type count*: int ProfileData* = ref object - data*: TableRef[TLineInfo, ProfileInfo] + data*: TableRef[SourceLinePosition, ProfileInfo] StdOrrKind* = enum stdOrrStdout @@ -774,7 +774,7 @@ template newPackageCache*(): untyped = modeCaseSensitive) proc newProfileData(): ProfileData = - ProfileData(data: newTable[TLineInfo, ProfileInfo]()) + ProfileData(data: newTable[SourceLinePosition, ProfileInfo]()) proc isDefined*(conf: ConfigRef; symbol: string): bool diff --git a/compiler/sem/semexprs.nim b/compiler/sem/semexprs.nim index 06c979829b3..eefaba436fd 100644 --- a/compiler/sem/semexprs.nim +++ b/compiler/sem/semexprs.nim @@ -1775,7 +1775,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = when defined(nimsuggest): if c.config.cmd == cmdIdeTools: suggestExpr(c, n) - if exactEquals(c.config.m.trackPos, n[1].info): suggestExprNoCheck(c, n) + if c.config.m.trackPos == n[1].info: suggestExprNoCheck(c, n) let s = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared, checkModule}) if s.isError: diff --git a/compiler/sem/semstmts.nim b/compiler/sem/semstmts.nim index c0042483a3b..33898c4fc9a 100644 --- a/compiler/sem/semstmts.nim +++ b/compiler/sem/semstmts.nim @@ -1691,7 +1691,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode = setCaseContextIdx(c, i) var x = n[i] when defined(nimsuggest): - if c.config.ideCmd == ideSug and exactEquals(c.config.m.trackPos, x.info) and caseTyp.kind == tyEnum: + if c.config.ideCmd == ideSug and c.config.m.trackPos == x.info and caseTyp.kind == tyEnum: suggestEnum(c, x, caseTyp) case x.kind of nkOfBranch: diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 36302f928ea..10ef40926fa 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -469,17 +469,12 @@ proc isTracked*(current, trackPos: TLineInfo, tokenLen: int): bool = return true when defined(nimsuggest): - # Since TLineInfo defined a == operator that doesn't include the column, - # we map TLineInfo to a unique int here for this lookup table: - proc infoToInt(info: TLineInfo): int64 = - info.fileIndex.int64 + info.line.int64 shl 32 + info.col.int64 shl 48 proc addNoDup(s: PSym; info: TLineInfo) = # ensure nothing gets too slow: if s.allUsages.len > 500: return - let infoAsInt = info.infoToInt for infoB in s.allUsages: - if infoB.infoToInt == infoAsInt: return + if infoB == info: return s.allUsages.add(info) proc findUsages(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym) = @@ -496,7 +491,7 @@ when defined(nimsuggest): proc listUsages*(g: ModuleGraph; s: PSym) = #echo "usages ", s.allUsages.len for info in s.allUsages: - let x = if info == s.info and info.col == s.info.col: ideDef else: ideUse + let x = if info == s.info: 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) = @@ -608,7 +603,7 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) = suggestQuit() proc suggestExpr*(c: PContext, n: PNode) = - if exactEquals(c.config.m.trackPos, n.info): suggestExprNoCheck(c, n) + if c.config.m.trackPos == n.info: suggestExprNoCheck(c, n) proc suggestDecl*(c: PContext, n: PNode; s: PSym) = let attached = c.config.m.trackPosAttached diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index ba5ea8c6548..ad9c578f4c9 100644 --- a/compiler/vm/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -28,7 +28,7 @@ proc leaveImpl(prof: var Profiler, c: TCtx) {.noinline.} = while frameIdx >= 0: let frame = c.sframes[frameIdx] if frame.prc != nil: - let li = frame.prc.info + let li = (frame.prc.info.fileIndex, frame.prc.info.line) if li notin data: data[li] = ProfileInfo() data[li].time += tLeave - prof.tEnter @@ -48,7 +48,7 @@ proc dump*(conf: ConfigRef, pd: ProfileData): string = result = "\nprof: µs #instr location\n" for i in 0..<32: var infoMax: ProfileInfo - var flMax: TLineInfo + var flMax: SourceLinePosition for fl, info in data: if info.time > infoMax.time: infoMax = info @@ -57,5 +57,8 @@ proc dump*(conf: ConfigRef, pd: ProfileData): string = break result.add " " & align($int(infoMax.time * 1e6), 10) & align($int(infoMax.count), 10) & " " & - conf.toFileLineCol(flMax) & "\n" + toMsgFilename(conf, newLineInfo(flMax.fileIndex, + flMax.line.int, + -1)) & + "\n" data.del flMax