You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
b0338b2 made sure that catching an error in the frontend would call Callback.failed.
bf38bae removed the intermediate catch that caught the errors thrown during the frontend onRun method.
Callback.failed is now a no-op.
Current semantic and questions
Frontend.onEnd runs even if exceptions are thrown during Frontend.onRun. Is that excepted? I guess this might be to allow Frontend.onEnd to recover from some errors?
If an exception is thrown in Frontend.onEnd, it swallows any exception thrown in Frontend.onRun. Here is a minimal reproduction:
@main defmain():Nothing=trythrownewException("Forever lost in the void")
finallythrownewException("Thrown from finally")
Is this expected? I think the first exception should at least be logged in debug mode. Should it also be rethrown?
The first exception which is not UnsupportedCodeException thrown during Frontend.onEnd, or during Frontend.onRun is rethrown without being reported as an error, it is only logged at the debug level. Why are UnsupportedCodeExceptions handled differently?
UnsupportedCodeException which are thrown before the first non-UnsupportedCodeException exception are reported as errors. The others are ignored. This seems weird. See def rethrow.
Proposed changes
This PR enables logging all exceptions thrown in the frontend, at debug level.
It doesn't make any other changes. In particular, the semantic described above is preserved.
Depending on the answers to my questions above, further changes might be needed.
mbovel
changed the title
Store all errors caught in the frontend
Log all errors caught in the frontend at debug level
Dec 10, 2024
privatedefrethrow():Unit=for (ex <- exceptions) ex match {
caseUnsupportedCodeException(pos, msg) =>
ctx.reporter.error(pos, msg)
case _ =>
ctx.reporter.debug(s"Rethrowing exception emitted from within the compiler: ${ex.getMessage}")
exceptions.clear()
throw ex
}
If there is an exception other than UnsupportedCodeException (which is usually thrown for features Stainless does not support), all the remaining exceptions are swallowed (due to the exceptions.clear()), and that exception is rethrown.
I think we should do something similar to the UnsupportedCodeException (with ctx.reporter.error). That said, the other kind of exceptions are usually due to a bug e.g. ClassCastException.
Regarding ThreadedFrontend.onEnd, this method in a no-op in the only concrete implementation of ThreadedFrontend (an anonymous class in DottyCompiler).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While trying to debug my modifications to the frontend, I found that some exceptions are swallowed. This makes it very hard to debug the frontend.
I found that this is due to the way errors are handled in
ThreadedFrontend.cc @mario-bucev and @samuelchassot: this is the problem I had this afternoon.
Background
Callback.failed.onRunmethod.Callback.failedis now a no-op.Current semantic and questions
Frontend.onEndruns even if exceptions are thrown duringFrontend.onRun. Is that excepted? I guess this might be to allowFrontend.onEndto recover from some errors?If an exception is thrown in
Frontend.onEnd, it swallows any exception thrown inFrontend.onRun. Here is a minimal reproduction:Is this expected? I think the first exception should at least be logged in debug mode. Should it also be rethrown?
The first exception which is not
UnsupportedCodeExceptionthrown duringFrontend.onEnd, or duringFrontend.onRunis rethrown without being reported as an error, it is only logged at the debug level. Why areUnsupportedCodeExceptions handled differently?UnsupportedCodeExceptionwhich are thrown before the first non-UnsupportedCodeExceptionexception are reported as errors. The others are ignored. This seems weird. Seedef rethrow.Proposed changes
This PR enables logging all exceptions thrown in the frontend, at debug level.
It doesn't make any other changes. In particular, the semantic described above is preserved.
Depending on the answers to my questions above, further changes might be needed.