summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-05-13 08:19:44 -0700
committerGitHub <noreply@github.com>2020-05-13 17:19:44 +0200
commit3573a4f9c13ff2f68afbd1931fc06cc463eb1748 (patch)
treed8d675e5bb5f00ec6664699a26af72ff22e9c76b /compiler
parenta3719df8b327ce33d4fdbfc7be06b058e9a2ea48 (diff)
downloadNim-3573a4f9c13ff2f68afbd1931fc06cc463eb1748.tar.gz
no more guessing where compiler msgs came from (#14317)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lineinfos.nim8
-rw-r--r--compiler/msgs.nim48
2 files changed, 37 insertions, 19 deletions
diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim
index d6c863842..2fd5a5a60 100644
--- a/compiler/lineinfos.nim
+++ b/compiler/lineinfos.nim
@@ -53,7 +53,8 @@ type
     hintSource, hintPerformance, hintStackTrace, hintGCStats,
     hintGlobalVar, hintExpandMacro,
     hintUser, hintUserRaw,
-    hintExtendedContext
+    hintExtendedContext,
+    hintMsgOrigin, # since 1.3.5
 
 const
   MsgKindToStr*: array[TMsgKind, string] = [
@@ -140,6 +141,7 @@ const
     hintUser: "$1",
     hintUserRaw: "$1",
     hintExtendedContext: "$1",
+    hintMsgOrigin: "$1",
   ]
 
 const
@@ -166,7 +168,7 @@ const
     "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
     "Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
     "Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
-    "User", "UserRaw", "ExtendedContext",
+    "User", "UserRaw", "ExtendedContext", "MsgOrigin",
   ]
 
 const
@@ -192,7 +194,7 @@ proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
   result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
   result[1] = result[2] - {warnProveField, warnProveIndex,
     warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
-    hintSource, hintGlobalVar, hintGCStats}
+    hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}
   result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
     hintProcessing, hintPattern, hintExecuting, hintLinking, hintCC}
 
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 43ed8f2a8..a43977606 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -12,6 +12,8 @@ import
   lineinfos, pathutils
 import std/private/miscdollars
 
+type InstantiationInfo = typeof(instantiationInfo())
+
 proc toCChar*(c: char; result: var string) =
   case c
   of '\0'..'\x1F', '\x7F'..'\xFF':
@@ -255,6 +257,9 @@ proc toLinenumber*(info: TLineInfo): int {.inline.} =
 proc toColumn*(info: TLineInfo): int {.inline.} =
   result = info.col
 
+proc toFileLineCol(info: InstantiationInfo): string {.inline.} =
+  result.toLocation(info.filename, info.line, info.column + ColOffset)
+
 proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
   result.toLocation(toMsgFilename(conf, info), info.line.int, info.col.int + ColOffset)
 
@@ -487,7 +492,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
   conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
 
 proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
-               eh: TErrorHandling) =
+               eh: TErrorHandling, info2: InstantiationInfo) {.noinline.} =
   var
     title: string
     color: ForegroundColor
@@ -533,36 +538,47 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
         styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
       if conf.hasHint(hintSource):
         conf.writeSurroundingSrc(info)
+      if conf.hasHint(hintMsgOrigin):
+        styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle, " compiler msg initiated here", KindColor, KindFormat % HintsToStr[ord(hintMsgOrigin) - ord(hintMin)], resetStyle)
+
   handleError(conf, msg, eh, s)
 
-proc fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
+template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
   # this fixes bug #7080 so that it is at least obvious 'fatal'
   # was executed.
   conf.m.errorOutputs = {eStdOut, eStdErr}
-  liMessage(conf, info, msg, arg, doAbort)
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, msg, arg, doAbort, info2)
 
-proc globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
-  liMessage(conf, info, msg, arg, doRaise)
+template globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, msg, arg, doRaise, info2)
 
-proc globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
-  liMessage(conf, info, errGenerated, arg, doRaise)
+template globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, errGenerated, arg, doRaise, info2)
 
-proc localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
-  liMessage(conf, info, msg, arg, doNothing)
+template localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, msg, arg, doNothing, info2)
 
-proc localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
-  liMessage(conf, info, errGenerated, arg, doNothing)
+template localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, errGenerated, arg, doNothing, info2)
 
-proc localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
-  localError(conf, info, format % params)
+template localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, errGenerated, format % params, doNothing, info2)
 
-proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
-  liMessage(conf, info, msg, arg, doNothing)
+template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
+  const info2 = instantiationInfo(-1, fullPaths = true)
+  liMessage(conf, info, msg, arg, doNothing, info2)
 
 proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
   if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
+  const info2 = instantiationInfo(-1, fullPaths = true)
   writeContext(conf, info)
-  liMessage(conf, info, errInternal, errMsg, doAbort)
+  liMessage(conf, info, errInternal, errMsg, doAbort, info2)
 
 proc internalError*(conf: ConfigRef; errMsg: string) =
   if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return