From 6b6beb601ecd0d1806346ca106bc19bf03c4f02c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 30 Jan 2012 10:28:52 -0700 Subject: [PATCH] add PLT_VALIDATE_COMPILE to enable extra checking of the compiler Setting the environment variable causes the bytecode compiler to run the bytecode validator (which is normally applied to input from a bytecode file) immediately on all of the compiler's own results. --- collects/scribblings/reference/eval.scrbl | 7 ++++++- src/racket/src/eval.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/collects/scribblings/reference/eval.scrbl b/collects/scribblings/reference/eval.scrbl index 41de77867d..b8c142334a 100644 --- a/collects/scribblings/reference/eval.scrbl +++ b/collects/scribblings/reference/eval.scrbl @@ -400,7 +400,12 @@ optimized for the special case of immediate evaluation. When a compiled form is written to an output port, the written form starts with @litchar{#~}. See @secref["print-compiled"] for more -information.} +information. + +For internal testing purposes, when the +@as-index{@envvar{PLT_VALIDATE_COMPILE}} environment variable is set, +the default compilation handler runs a bytecode validator on its own +compilation results.} @defproc[(compile [top-level-form any/c]) compiled-expression?]{ diff --git a/src/racket/src/eval.c b/src/racket/src/eval.c index af1247a707..6033e1370a 100644 --- a/src/racket/src/eval.c +++ b/src/racket/src/eval.c @@ -168,6 +168,8 @@ SHARED_OK int scheme_startup_use_jit = INIT_JIT_ON; void scheme_set_startup_use_jit(int v) { scheme_startup_use_jit = v; } +SHARED_OK static int valdiate_compile_result = 0; + /* THREAD LOCAL SHARED */ THREAD_LOCAL_DECL(volatile int scheme_fuel_counter); #ifdef USE_STACK_BOUNDARY_VAR @@ -349,6 +351,13 @@ scheme_init_eval (Scheme_Env *env) GLOBAL_PARAMETER("compile-enforce-module-constants", compile_module_constants, MZCONFIG_COMPILE_MODULE_CONSTS, env); GLOBAL_PARAMETER("eval-jit-enabled", use_jit, MZCONFIG_USE_JIT, env); GLOBAL_PARAMETER("compile-context-preservation-enabled", disallow_inline, MZCONFIG_DISALLOW_INLINE, env); + + if (getenv("PLT_VALIDATE_COMPILE")) { + /* Enables validation of bytecode as it is generated, + to double-check that the compiler is producing + valid bytecode as it should. */ + valdiate_compile_result = 1; + } } void scheme_init_eval_places() @@ -3919,7 +3928,7 @@ static void *compile_k(void) top->code = o; top->prefix = rp; - if (0) { /* <- change to 1 to check compilation result */ + if (valdiate_compile_result) { scheme_validate_code(NULL, top->code, top->max_let_depth, top->prefix->num_toplevels,