summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-07-27 23:12:31 (GMT)
committerGitHub <noreply@github.com>2020-07-27 23:12:31 (GMT)
commitbc2c0e9a574b5c039b4601a880920afa54dee543 (patch)
tree97ffa6d19faa7c470629c261da6ef4fe6632f3e4 /Parser
parente962e3f65a086d9d3b848483fd01215d96ecc5f9 (diff)
downloadcpython-bc2c0e9a574b5c039b4601a880920afa54dee543.zip
cpython-bc2c0e9a574b5c039b4601a880920afa54dee543.tar.gz
cpython-bc2c0e9a574b5c039b4601a880920afa54dee543.tar.bz2
[3.9] Validate the AST produced by the parser in debug mode (GH-21643) (GH-21646)
This will improve the debug experience if something fails in the produced AST. Previously, errors in the produced AST can be felt much later like in the garbage collector or the compiler, making debugging them much more difficult.. (cherry picked from commit 1332226b32da44087a55e1d71990ee6899dfd28a) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen/pegen.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index beb2b2d..184cadc 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -4,6 +4,7 @@
#include "pegen.h"
#include "parse_string.h"
+#include "ast.h"
PyObject *
_PyPegen_new_type_comment(Parser *p, char *s)
@@ -1136,6 +1137,14 @@ _PyPegen_run_parser(Parser *p)
return RAISE_SYNTAX_ERROR("multiple statements found while compiling a single statement");
}
+#if defined(Py_DEBUG) && defined(Py_BUILD_CORE)
+ if (p->start_rule == Py_single_input ||
+ p->start_rule == Py_file_input ||
+ p->start_rule == Py_eval_input)
+ {
+ assert(PyAST_Validate(res));
+ }
+#endif
return res;
}