Skip to content

Commit 86dc14b

Browse files
committed
progress
1 parent 72ddb4b commit 86dc14b

32 files changed

+168
-539
lines changed

compiler/ast/errorhandling.nim

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ import
4444
options,
4545
]
4646

47-
when defined(nimDebugUnreportedErrors):
48-
import std/tables
49-
5047
proc errorSubNode*(n: PNode): PNode =
5148
## find the first error node, or nil, under `n` using a depth first traversal
5249
case n.kind
@@ -118,9 +115,9 @@ proc newError*(
118115
if diag.instLoc.filename in ["???", ""]:
119116
diag.instLoc = inst # compilerInfoPos
120117

121-
when defined(nimDebugUnreportedErrors):
122-
if diag.kind != adWrappedError:
123-
conf.unreportedErrors[result.diag.diagId] = result
118+
if diag.kind notin {adWrappedError, adWrappedSymError}:
119+
# invoke the diagnostic/report handler
120+
conf.handle(conf.astDiagToLegacyReport(conf, diag), inst)
124121

125122
template newError*(
126123
conf: ConfigRef,
@@ -169,9 +166,6 @@ proc buildErrorList(config: ConfigRef, n: PNode, errs: var seq[PNode]) =
169166
discard
170167
of nkError:
171168
buildErrorList(config, n.diag.wrongNode, errs)
172-
when defined(nimDebugUnreportedErrors):
173-
if n.errorKind == adWrappedError and errs.len == 0:
174-
echo "Empty WrappedError: ", config $ n.info
175169
errs.add n
176170
of nkWithSons:
177171
for i in 0..<n.len:

compiler/ast/errorreporting.nim

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1 @@
1-
#
2-
#
3-
# The Nim Compiler
4-
# (c) Copyright 2021 Saem Ghani
5-
#
6-
# See the file "copying.txt", included in this
7-
# distribution, for details about the copyright.
8-
#
9-
10-
## module handles reporting errors, it's used in conjunction with errorhandling
11-
##
12-
## Todo:
13-
## * write an error reporting proc that handles string conversion and also
14-
## determines which error handling strategy to use doNothing, raise, etc.
15-
16-
import
17-
compiler/ast/[
18-
ast,
19-
errorhandling,
20-
renderer,
21-
reports,
22-
]
23-
24-
when defined(nimDebugUnreportedErrors):
25-
import std/tables
26-
27-
from compiler/front/options import ConfigRef
28-
from compiler/front/msgs import TErrorHandling, astDiagToLegacyReportKind
29-
30-
export compilerInstInfo, walkErrors, errorKind
31-
# export because keeping the declaration in `errorhandling` acts as a reminder
32-
# of what the contract is with the subtleties around line and column info
33-
# overloading
34-
35-
proc errorHandling*(err: PNode): TErrorHandling =
36-
## which error handling strategy should be used given the error, use with
37-
## `msg.liMessage` when reporting errors.
38-
assert err.isError, "err can't be nil and must be an nkError"
39-
case err.diag.astDiagToLegacyReportKind:
40-
of rsemCustomGlobalError: doRaise
41-
of rsemFatalError: doAbort
42-
else: doNothing
43-
44-
template localReport*(conf: ConfigRef, node: PNode) =
45-
## Write out existing sem report that is stored in the nkError node
46-
{.line.}:
47-
assert node.kind == nkError, $node.kind
48-
49-
when defined(nimDebugUnreportedErrors):
50-
conf.unreportedErrors.del node.id
51-
for err in walkErrors(conf, node):
52-
conf.unreportedErrors.del err.id
53-
54-
for err in walkErrors(conf, node):
55-
if true or canReport(conf, err):
56-
handleReport(conf, err.diag, instLoc(), node.errorHandling)
1+
# TODO: remove

compiler/ast/parser.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ proc getTok(p: var Parser) =
134134
p.lex.rawGetTok(p.tok)
135135

136136
if p.tok.tokType == tkError:
137-
p.lex.config.handleLexerDiag(p.tok.error, instLoc(-1), doAbort)
137+
p.lex.config.handleLexerDiag(p.tok.error, instLoc(-1), isFatal=true)
138138

139139
for d in p.lex.errorsHintsAndWarnings(lexDiagOffset):
140140
p.lex.config.handleLexerDiag(d, instLoc(-1))

compiler/ast/report_enums.nim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ type
297297
# nimsuggest
298298
rsemSugNoSymbolAtPosition
299299

300-
# Global Errors
301-
rsemCustomGlobalError
302-
## just like custom error, but treat it like a "raise" and fast track the
303-
## "graceful" abort of this compilation run, used by `errorreporting` to
304-
## bridge into the existing `msgs.liMessage` and `msgs.handleError`.
305-
306300
# Module errors
307301
rsemSystemNeeds
308302
rsemInvalidModulePath

compiler/ast/reports_sem.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,4 @@ func reportSym*(
250250
kind: ReportKind,
251251
sym: PSym, ast: PNode = nil, str: string = "", typ: PType = nil,
252252
): SemReport =
253-
SemReport(kind: kind, ast: ast, str: str, typ: typ, sym: sym)
253+
SemReport(kind: kind, ast: ast, str: str, typ: typ, sym: sym)

compiler/front/cli_reporter.nim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,9 +1746,6 @@ proc reportBody*(conf: ConfigRef, r: SemReport): string =
17461746
of rsemNodeNotAllowed:
17471747
result = "'$1' not allowed here" % r.ast.render
17481748

1749-
of rsemCustomGlobalError:
1750-
result = r.str
1751-
17521749
of rsemCannotImportItself:
17531750
result = "module '$1' cannot import itself" % r.symstr
17541751

compiler/front/main.nim

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ when not defined(leanCompiler):
8585
compiler/backend/jsbackend,
8686
compiler/tools/[docgen, docgen2]
8787

88-
when defined(nimDebugUnreportedErrors):
89-
import std/exitprocs
90-
import compiler/utils/astrepr
91-
92-
proc echoAndResetUnreportedErrors(conf: ConfigRef) =
93-
if conf.unreportedErrors.len > 0:
94-
echo "Unreported errors:"
95-
for nodeId, node in conf.unreportedErrors:
96-
var reprConf = defaultTReprConf
97-
reprConf.flags.incl trfShowNodeErrors
98-
echo conf.treeRepr(node)
99-
conf.unreportedErrors.clear
100-
10188
type
10289
InternalStateDump = ref object
10390
version*: string
@@ -518,9 +505,6 @@ proc mainCommand*(graph: ModuleGraph) =
518505
if conf.cmd in cmdDocLike + {cmdRst2html, cmdRst2tex}: ret = ret / htmldocsDir
519506
conf.outDir = ret
520507

521-
when defined(nimDebugUnreportedErrors):
522-
addExitProc proc = echoAndResetUnreportedErrors(conf)
523-
524508
when defined(gcOrc) and not defined(leakTest):
525509
# Compilation is currently very taxing on ORC due to frequent
526510
# creations and destructions of ref objects with potential cycles.
@@ -718,9 +702,6 @@ proc mainCommand*(graph: ModuleGraph) =
718702
if conf.isEnabled(rintSuccessX):
719703
conf.writeln(cmdOutStatus, $genSuccessX(conf))
720704

721-
when defined(nimDebugUnreportedErrors):
722-
echoAndResetUnreportedErrors(conf)
723-
724705
when PrintRopeCacheStats:
725706
echo "rope cache stats: "
726707
echo " tries : ", gCacheTries

0 commit comments

Comments
 (0)