Implement static analysis of unformed usage on local variables. (#1831)

- An introprocedural forward analysis that checks the may-be-formed states on local variables.
 - Returns compilation error on usage of must-be-unformed variables. 
 - Implemented as a pass of `ASTNode` traversal. 
 - Currently supports detection of: function parameter, return expression and rhs of assign.
This commit is contained in:
Zenong Zhang
2022-08-03 15:28:51 -07:00
committed by GitHub
parent 094311133d
commit 2f4905bf70
10 changed files with 292 additions and 8 deletions
+6 -2
View File
@@ -12,6 +12,7 @@
#include "explorer/interpreter/interpreter.h"
#include "explorer/interpreter/resolve_control_flow.h"
#include "explorer/interpreter/resolve_names.h"
#include "explorer/interpreter/resolve_unformed.h"
#include "explorer/interpreter/type_checker.h"
#include "llvm/Support/Error.h"
@@ -45,8 +46,11 @@ auto ExecProgram(Nonnull<Arena*> arena, AST ast,
}
CARBON_RETURN_IF_ERROR(TypeChecker(arena, trace_stream).TypeCheck(ast));
if (trace_stream) {
**trace_stream << "\n";
**trace_stream << "********** type checking complete **********\n";
**trace_stream << "********** resolving unformed variables **********\n";
}
CARBON_RETURN_IF_ERROR(ResolveUnformed(ast));
if (trace_stream) {
**trace_stream << "********** printing declarations **********\n";
for (const auto decl : ast.declarations) {
**trace_stream << *decl;
}