diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-04-20 17:54:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-20 17:54:39 -0700 |
| commit | 163d3068e332703cc499446fff37230a7c68e8f2 (patch) | |
| tree | a1d0b9507ab01c908811603d8cde47736bdbe3ef /source/slang/lower-to-ir.cpp | |
| parent | 2f782d403ae5729b6c93fbe92577ee01f7a8d608 (diff) | |
Better diagnostics when compilation is aborted (#517)
* Improve messages when compilation is aborted.
Make sure to include the information from any `Slang::Exception` that was thrown, so that the poor user can at least point us at our own message string from an assertion failure.
This doesn't provide them line-number information in their code or the Slang codebase, so there is still work to be done in making the compiler more friendly about this stuff.
* When aborting compilation, try to note what source location we were working on
This is handled by having exception handlers on the stack at key bottleneck points in semantic checking and IR generation, which can then emit a diagnostic to note what we were working on when things failed.
This is not intended to be an indiciation to the user that their code is at fault for a compiler crash (it is always our fault), but might give them a chance to work around whatever bug is blocking them.
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index e5cf19a10..fffd8acf3 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -355,6 +355,11 @@ struct IRGenContext { return shared->compileRequest->mSession; } + + CompileRequest* getCompileRequest() + { + return shared->compileRequest; + } }; void setGlobalValue(SharedIRGenContext* sharedContext, Decl* decl, LoweredValInfo value) @@ -2680,7 +2685,19 @@ void lowerStmt( StmtLoweringVisitor visitor; visitor.context = context; - return visitor.dispatch(stmt); + + try + { + visitor.dispatch(stmt); + } + // Don't emit any context message for an explicit `AbortCompilationException` + // because it should only happen when an error is already emitted. + catch(AbortCompilationException&) { throw; } + catch(...) + { + context->getCompileRequest()->noteInternalErrorLoc(stmt->loc); + throw; + } } static LoweredValInfo maybeMoveMutableTemp( @@ -4380,7 +4397,21 @@ LoweredValInfo lowerDecl( DeclLoweringVisitor visitor; visitor.context = &subContext; - return visitor.dispatch(decl); + + + + try + { + return visitor.dispatch(decl); + } + // Don't emit any context message for an explicit `AbortCompilationException` + // because it should only happen when an error is already emitted. + catch(AbortCompilationException&) { throw; } + catch(...) + { + context->getCompileRequest()->noteInternalErrorLoc(decl->loc); + throw; + } } // Ensure that a version of the given declaration has been emitted to the IR |
