From 5db3da9b94ea3e3aa44e30dceb3befcdbde3b3e6 Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 8 Sep 2023 14:41:34 +0800 Subject: [PATCH 01/10] proc `==` TlineInfo exact match --- compiler/front/msgs.nim | 4 ---- compiler/sem/semexprs.nim | 2 +- compiler/sem/semstmts.nim | 2 +- compiler/tools/suggest.nim | 11 +++-------- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/compiler/front/msgs.nim b/compiler/front/msgs.nim index 74d75240d74..9ae45633e53 100644 --- a/compiler/front/msgs.nim +++ b/compiler/front/msgs.nim @@ -315,11 +315,7 @@ 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] = 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 From ac6a6ee1babaad4265f5421324206e781bb78a9c Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 8 Sep 2023 23:39:55 +0800 Subject: [PATCH 02/10] remove proc `==` for TLineInfo --- compiler/front/msgs.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/front/msgs.nim b/compiler/front/msgs.nim index 9ae45633e53..2a02ce4a6c6 100644 --- a/compiler/front/msgs.nim +++ b/compiler/front/msgs.nim @@ -315,9 +315,6 @@ proc errorActions( elif eh == doRaise: result = (doRaise, false) -proc `==`*(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 From 3d510ad59eda701da6603e27e4cd4c806f71bcd0 Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 9 Sep 2023 03:27:34 +0800 Subject: [PATCH 03/10] use FileLinePar in vmprofile --- compiler/ast/lineinfos.nim | 4 ++++ compiler/front/options.nim | 4 ++-- compiler/vm/vmprofiler.nim | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/ast/lineinfos.nim b/compiler/ast/lineinfos.nim index 086aa7066e1..616d6bf3fa9 100644 --- a/compiler/ast/lineinfos.nim +++ b/compiler/ast/lineinfos.nim @@ -26,6 +26,10 @@ type col*: int16 fileIndex*: FileIndex + FileLinePar* = tuple + fileIndex: typeof(TLineInfo.fileIndex) + line: typeof(TLineInfo.line) + LineColPair* = tuple line: typeof(TLineInfo.line) col: typeof(TLineInfo.col) diff --git a/compiler/front/options.nim b/compiler/front/options.nim index 23ce3ed441f..29a37e641f5 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[FileLinePar, ProfileInfo] StdOrrKind* = enum stdOrrStdout @@ -774,7 +774,7 @@ template newPackageCache*(): untyped = modeCaseSensitive) proc newProfileData(): ProfileData = - ProfileData(data: newTable[TLineInfo, ProfileInfo]()) + ProfileData(data: newTable[FileLinePar, ProfileInfo]()) proc isDefined*(conf: ConfigRef; symbol: string): bool diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index ba5ea8c6548..4977a8d4637 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: FileLinePar for fl, info in data: if info.time > infoMax.time: infoMax = info @@ -57,5 +57,5 @@ 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, flMax.fileIndex) & "(" & $flMax.line & ")" & "\n" data.del flMax From 3032c395cab4a34de0b6d17546524ae8785cb3c1 Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 9 Sep 2023 08:32:07 +0800 Subject: [PATCH 04/10] Update compiler/ast/lineinfos.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/ast/lineinfos.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ast/lineinfos.nim b/compiler/ast/lineinfos.nim index 616d6bf3fa9..41c050f005d 100644 --- a/compiler/ast/lineinfos.nim +++ b/compiler/ast/lineinfos.nim @@ -26,7 +26,9 @@ type col*: int16 fileIndex*: FileIndex - FileLinePar* = tuple + SourceLinePosition* = tuple + ## Identifies a line in a source file. Only intended for use by + ## the profiler. fileIndex: typeof(TLineInfo.fileIndex) line: typeof(TLineInfo.line) From bc863a2a327320e500dc71a91b8a541a59026b0c Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 9 Sep 2023 08:32:19 +0800 Subject: [PATCH 05/10] Update compiler/front/options.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/front/options.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/front/options.nim b/compiler/front/options.nim index 29a37e641f5..8f69232ccbe 100644 --- a/compiler/front/options.nim +++ b/compiler/front/options.nim @@ -166,7 +166,7 @@ type count*: int ProfileData* = ref object - data*: TableRef[FileLinePar, ProfileInfo] + data*: TableRef[SourceLinePosition, ProfileInfo] StdOrrKind* = enum stdOrrStdout From 814ef36eca0bcda3676b7ec0fff245420cd37cbf Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 9 Sep 2023 08:32:30 +0800 Subject: [PATCH 06/10] Update compiler/front/options.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/front/options.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/front/options.nim b/compiler/front/options.nim index 8f69232ccbe..13f1f21a43f 100644 --- a/compiler/front/options.nim +++ b/compiler/front/options.nim @@ -774,7 +774,7 @@ template newPackageCache*(): untyped = modeCaseSensitive) proc newProfileData(): ProfileData = - ProfileData(data: newTable[FileLinePar, ProfileInfo]()) + ProfileData(data: newTable[SourceLinePosition, ProfileInfo]()) proc isDefined*(conf: ConfigRef; symbol: string): bool From d7a718f5d2d940c2586bc4b5fcb87f961fe1ecec Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 9 Sep 2023 08:32:38 +0800 Subject: [PATCH 07/10] Update compiler/vm/vmprofiler.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/vm/vmprofiler.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index 4977a8d4637..3b88b78be14 100644 --- a/compiler/vm/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -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: FileLinePar + var flMax: SourceLinePosition for fl, info in data: if info.time > infoMax.time: infoMax = info From 8553516109931632347f77aa2c02d7e11bf07450 Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 9 Sep 2023 08:37:54 +0800 Subject: [PATCH 08/10] Update compiler/vm/vmprofiler.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/vm/vmprofiler.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index 3b88b78be14..d7098074b38 100644 --- a/compiler/vm/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -57,5 +57,6 @@ proc dump*(conf: ConfigRef, pd: ProfileData): string = break result.add " " & align($int(infoMax.time * 1e6), 10) & align($int(infoMax.count), 10) & " " & - toMsgFilename(conf, flMax.fileIndex) & "(" & $flMax.line & ")" & "\n" + result.toLocation(toMsgFilename(conf, flMax.fileIndex), flMax.line, 0) + result.add "\n" data.del flMax From 0d22ef95e4efb834e14436e375515493a3d08036 Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 9 Sep 2023 08:42:05 +0800 Subject: [PATCH 09/10] use newLineInfo --- compiler/vm/vmprofiler.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index d7098074b38..f234fce5bcd 100644 --- a/compiler/vm/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -57,6 +57,5 @@ proc dump*(conf: ConfigRef, pd: ProfileData): string = break result.add " " & align($int(infoMax.time * 1e6), 10) & align($int(infoMax.count), 10) & " " & - result.toLocation(toMsgFilename(conf, flMax.fileIndex), flMax.line, 0) - result.add "\n" + toMsgFilename(conf, newLineInfo(flMax.fileIndex, flMax.line.int, 0)) & "\n" data.del flMax From 997617643285c42c1f56f162f21694fdd6639aca Mon Sep 17 00:00:00 2001 From: Bung Date: Sun, 10 Sep 2023 01:32:35 +0800 Subject: [PATCH 10/10] Update compiler/vm/vmprofiler.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/vm/vmprofiler.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/vm/vmprofiler.nim b/compiler/vm/vmprofiler.nim index f234fce5bcd..ad9c578f4c9 100644 --- a/compiler/vm/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -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) & " " & - toMsgFilename(conf, newLineInfo(flMax.fileIndex, flMax.line.int, 0)) & "\n" + toMsgFilename(conf, newLineInfo(flMax.fileIndex, + flMax.line.int, + -1)) & + "\n" data.del flMax