-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace assertions with proper validations in AST import #12017
Comments
Hi, I would like to work on this issue. I'm new to contributing, can you please check my understanding of the needed changes? So I would need to add a new Exception to Exceptions.h. Then, I should throw this exception in ASTJsonImporter. ASRJsonImporter::jsonToSourceUnit is then used in CompilerStack::importASTs. This function would pass the Exception to CommandLineInterface. In CommandLineInterface, I need to catch Exceptions of the new type, instead of the type "Exception". |
Generally yes, but this is only a part of the task. The other part is to ensure that the current validations are sufficient so that switching to a more specialized exception handler in Checking that will require some experimentation with invalid input and adding tests covering all cases that should be validated. Looks like we currently have nearly zero coverage for AST import. As for the exception, looks like we already have one in Overall this is not going to be a small task if we want to be sure the change does not break anything. It's not hard but might be a bit tedious to get the full coverage. If you'd rather take something smaller, I'd recommend #9627 or #10308. |
Sounds good! |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Abstract
The AST import code in
CommandLineInterface
is currently wrapped in an exception handler that catches all exceptions and prints an error message. This is most likely because the JSON input does not get validated before it's passed toASTJsonImporter
and the importer just asserts things that it expects not to happen.These assertions should be replaced with proper validations.
The
--import-asm-json
option that will be introduced in #11807 will likely suffer from the same problem.Example
This is how you can trigger a validation error now:
Motivation
The current handler suppresses all the extra debug information we include in internal compiler errors. This is what we want if these errors are actually validation errors but not for normal assertions. It means that our usual assertions result in a message looking like this:
The message is meant to be followed by error description but our assertions often have no description. This makes debugging harder.
Specification
We should define a new exception type representing a validation error and use it in
ASTJsonImporter
. Then only catch this exception inCommandLineInterface
and let other exceptions through.Since the exception handler also covers
CompilerStack->analyze()
, it's likely that the assertions inASTJsonImporter
are not enough to satisfy its assumptions. As a part of this task we need to check what exactly these assumptions are and add additional validations against them inASTJsonImporter
.Backwards Compatibility
This is just a refactor and should not cause changes visible to the user other than in internal compiler errors - and we do not provide backwards-compatibility guarantees for these.
The text was updated successfully, but these errors were encountered: