diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-19 09:36:35 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-19 18:15:37 -0700 |
| commit | 3f48e1c0d84bf4909954154ad147559656e87516 (patch) | |
| tree | 0b93a109d51e6565560ad785519a863386490e2a /source/slang/slang.cpp | |
| parent | a2b8b4c20632d79721052abd232fe2d1bdf2700d (diff) | |
Try to improve handling of failures during compilation
The change is mostly about trying to make sure the compiler "fails safe" when it encounters an internal assumption that isn't met.
Most internal errors will now throw exceptions (yes, exceptions are evil, but this will work for now), and these get caught in `spCompile` so that they don't propagate to the user (they just see a message that compilation aborted due to an internal error).
Subsequent changes are going to need to work on diagnosing as many of these situations as possible, so that users can at least know what construct in their code was unexpected or unhandled by the compiler.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 89db62ec8..caa50ad0e 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -571,7 +571,7 @@ void Session::addBuiltinSource( OutputDebugStringA(compileRequest->mDiagnosticOutput.Buffer()); #endif - assert(!"error in stdlib"); + SLANG_UNEXPECTED("error in Slang standard library"); } // Extract the AST for the code we just parsed @@ -831,8 +831,16 @@ SLANG_API int spCompile( { auto req = REQ(request); - int anyErrors = req->executeActions(); - return anyErrors; + try + { + int anyErrors = req->executeActions(); + return anyErrors; + } + catch (...) + { + req->mSink.diagnose(Slang::CodePosition(), Slang::Diagnostics::compilationAborted); + return 1; + } } SLANG_API int |
