Skip to content

Commit e6280df

Browse files
committed
dump module when verify_scopes fails
1 parent 6ba42f1 commit e6280df

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/shady/analysis/verify.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void verify_same_arena(Module* mod) {
4242
destroy_dict(visitor.once);
4343
}
4444

45-
static void verify_scoping(Module* mod) {
45+
static void verify_scoping(const CompilerConfig* config, Module* mod) {
4646
struct List* scopes = build_scopes(mod);
4747
for (size_t i = 0; i < entries_count_list(scopes); i++) {
4848
Scope* scope = read_list(Scope*, scopes)[i];
@@ -54,7 +54,10 @@ static void verify_scoping(Module* mod) {
5454
log_node(ERROR, leaking);
5555
error_print("\n");
5656
}
57-
assert(entries_count_dict(entry_vars->free_set) == 0);
57+
if (entries_count_dict(entry_vars->free_set) > 0) {
58+
log_module(ERROR, config, mod);
59+
error_die();
60+
}
5861
destroy_scope_variables_map(map);
5962
destroy_scope(scope);
6063
}
@@ -118,12 +121,12 @@ static void verify_bodies(Module* mod) {
118121
}
119122
}
120123

121-
void verify_module(Module* mod) {
124+
void verify_module(const CompilerConfig* config, Module* mod) {
122125
verify_same_arena(mod);
123126
// before we normalize the IR, scopes are broken because decls appear where they should not
124127
// TODO add a normalized flag to the IR and check grammar is adhered to strictly
125128
if (get_module_arena(mod)->config.check_types) {
126-
verify_scoping(mod);
129+
verify_scoping(config, mod);
127130
verify_bodies(mod);
128131
}
129132
}

src/shady/analysis/verify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#include "shady/ir.h"
55

6-
void verify_module(Module*);
6+
void verify_module(const CompilerConfig*, Module*);
77

88
#endif

src/shady/compile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ old_mod = *pmod; \
1717
*pmod = pass_name(config, *pmod); \
1818
(*pmod)->sealed = true; \
1919
if (SHADY_RUN_VERIFY) \
20-
verify_module(*pmod); \
20+
verify_module(config, *pmod); \
2121
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena) \
2222
destroy_ir_arena(get_module_arena(old_mod)); \
2323
old_mod = *pmod; \
@@ -26,7 +26,7 @@ if (config->optimisations.cleanup.after_every_pass) \
2626
debugvv_print("After "#pass_name" pass: \n"); \
2727
log_module(DEBUGVV, config, *pmod); \
2828
if (SHADY_RUN_VERIFY) \
29-
verify_module(*pmod); \
29+
verify_module(config, *pmod); \
3030
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena) \
3131
destroy_ir_arena(get_module_arena(old_mod)); \
3232
if (config->hooks.after_pass.fn) \

src/shady/passes/opt_mem2reg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ Module* opt_mem2reg(const CompilerConfig* config, Module* src) {
688688
destroy_dict(ctx.bb_new_args);
689689
destroy_arena(ctx.a);
690690

691-
verify_module(dst);
691+
verify_module(config, dst);
692692

693693
if (get_module_arena(src) != initial_arena)
694694
destroy_ir_arena(get_module_arena(src));

src/shady/print.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,6 @@ void print_module(Printer* printer, Module* mod, PrintConfig config) {
973973
};
974974
print_mod_impl(&ctx, mod);
975975
flush(ctx.printer);
976-
destroy_printer(ctx.printer);
977976
}
978977

979978
void print_node(Printer* printer, const Node* node, PrintConfig config) {

0 commit comments

Comments
 (0)