@@ -3275,14 +3275,15 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
3275
3275
}
3276
3276
3277
3277
ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3278
- ZigFn *fn_entry = allocate<ZigFn>(1);
3278
+ ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3279
+ fn_entry->ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
3279
3280
3280
3281
fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
3281
3282
3282
3283
fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
3283
3284
fn_entry->analyzed_executable.backward_branch_quota = &fn_entry->prealloc_backward_branch_quota;
3284
3285
fn_entry->analyzed_executable.fn_entry = fn_entry;
3285
- fn_entry->ir_executable. fn_entry = fn_entry;
3286
+ fn_entry->ir_executable-> fn_entry = fn_entry;
3286
3287
fn_entry->fn_inline = inline_value;
3287
3288
3288
3289
return fn_entry;
@@ -4610,7 +4611,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
4610
4611
assert(!fn_type->data.fn.is_generic);
4611
4612
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
4612
4613
4613
- ZigType *block_return_type = ir_analyze(g, & fn->ir_executable,
4614
+ ZigType *block_return_type = ir_analyze(g, fn->ir_executable,
4614
4615
&fn->analyzed_executable, fn_type_id->return_type, return_type_node);
4615
4616
fn->src_implicit_return_type = block_return_type;
4616
4617
@@ -4706,15 +4707,15 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
4706
4707
assert(!fn_type->data.fn.is_generic);
4707
4708
4708
4709
ir_gen_fn(g, fn_table_entry);
4709
- if (fn_table_entry->ir_executable. first_err_trace_msg != nullptr) {
4710
+ if (fn_table_entry->ir_executable-> first_err_trace_msg != nullptr) {
4710
4711
fn_table_entry->anal_state = FnAnalStateInvalid;
4711
4712
return;
4712
4713
}
4713
4714
if (g->verbose_ir) {
4714
4715
fprintf(stderr, "\n");
4715
4716
ast_render(stderr, fn_table_entry->body_node, 4);
4716
4717
fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4717
- ir_print(g, stderr, & fn_table_entry->ir_executable, 4, IrPassSrc);
4718
+ ir_print(g, stderr, fn_table_entry->ir_executable, 4, IrPassSrc);
4718
4719
fprintf(stderr, "}\n");
4719
4720
}
4720
4721
@@ -6453,20 +6454,31 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
6453
6454
}
6454
6455
6455
6456
bool ir_get_var_is_comptime(ZigVar *var) {
6457
+ if (var->is_comptime_memoized)
6458
+ return var->is_comptime_memoized_value;
6459
+
6460
+ var->is_comptime_memoized = true;
6461
+
6456
6462
// The is_comptime field can be left null, which means not comptime.
6457
- if (var->is_comptime == nullptr)
6458
- return false;
6463
+ if (var->is_comptime == nullptr) {
6464
+ var->is_comptime_memoized_value = false;
6465
+ return var->is_comptime_memoized_value;
6466
+ }
6459
6467
// When the is_comptime field references an instruction that has to get analyzed, this
6460
6468
// is the value.
6461
6469
if (var->is_comptime->child != nullptr) {
6462
6470
assert(var->is_comptime->child->value->type->id == ZigTypeIdBool);
6463
- return var->is_comptime->child->value->data.x_bool;
6471
+ var->is_comptime_memoized_value = var->is_comptime->child->value->data.x_bool;
6472
+ var->is_comptime = nullptr;
6473
+ return var->is_comptime_memoized_value;
6464
6474
}
6465
6475
// As an optimization, is_comptime values which are constant are allowed
6466
6476
// to be omitted from analysis. In this case, there is no child instruction
6467
6477
// and we simply look at the unanalyzed const parent instruction.
6468
6478
assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6469
- return var->is_comptime->value->data.x_bool;
6479
+ var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;
6480
+ var->is_comptime = nullptr;
6481
+ return var->is_comptime_memoized_value;
6470
6482
}
6471
6483
6472
6484
bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
0 commit comments