authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-09 12:43:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-09 12:43:08-05:00
log92ffcc84a9d5da32a645321eee8d33c179d03562
treeab9e581daac8893d8480f05ad63319378c41d3d1
parentfc100d7b3b27bd514dca4e02c160e5b96d4da648

remove the depends_on_compile_var code

cleanup from the decision in commit 8a859afd580f438f549ee69a to remove "unnecessary if statement" error

4 files changed, 137 insertions(+), 281 deletions(-)

src/all_types.hpp-2
...@@ -149,7 +149,6 @@ enum RuntimeHintMaybe {...@@ -149,7 +149,6 @@ enum RuntimeHintMaybe {
149struct ConstExprValue {149struct ConstExprValue {
150 TypeTableEntry *type;150 TypeTableEntry *type;
151 ConstValSpecial special;151 ConstValSpecial special;
152 bool depends_on_compile_var;
153 LLVMValueRef llvm_value;152 LLVMValueRef llvm_value;
154 LLVMValueRef llvm_global;153 LLVMValueRef llvm_global;
155154
...@@ -976,7 +975,6 @@ struct TypeTableEntry {...@@ -976,7 +975,6 @@ struct TypeTableEntry {
976 ZigLLVMDIType *di_type;975 ZigLLVMDIType *di_type;
977976
978 bool zero_bits;977 bool zero_bits;
979 bool size_depends_on_compile_var;
980978
981 union {979 union {
982 TypeTableEntryPointer pointer;980 TypeTableEntryPointer pointer;
src/analyze.cpp-18
...@@ -1146,9 +1146,6 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {...@@ -1146,9 +1146,6 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
1146 continue;1146 continue;
1147 }1147 }
11481148
1149 enum_type->size_depends_on_compile_var = enum_type->size_depends_on_compile_var ||
1150 field_type->size_depends_on_compile_var;
1151
1152 if (!type_has_bits(field_type))1149 if (!type_has_bits(field_type))
1153 continue;1150 continue;
11541151
...@@ -1320,9 +1317,6 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {...@@ -1320,9 +1317,6 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
1320 continue;1317 continue;
1321 }1318 }
13221319
1323 struct_type->size_depends_on_compile_var = struct_type->size_depends_on_compile_var ||
1324 field_type->size_depends_on_compile_var;
1325
1326 if (!type_has_bits(field_type))1320 if (!type_has_bits(field_type))
1327 continue;1321 continue;
13281322
...@@ -3348,17 +3342,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -3348,17 +3342,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
3348 zig_unreachable();3342 zig_unreachable();
3349}3343}
33503344
3351static bool int_type_depends_on_compile_var(CodeGen *g, TypeTableEntry *int_type) {
3352 assert(int_type->id == TypeTableEntryIdInt);
3353
3354 for (size_t i = 0; i < CIntTypeCount; i += 1) {
3355 if (int_type == g->builtin_types.entry_c_int[i]) {
3356 return true;
3357 }
3358 }
3359 return false;
3360}
3361
3362static uint64_t max_unsigned_val(TypeTableEntry *type_entry) {3345static uint64_t max_unsigned_val(TypeTableEntry *type_entry) {
3363 assert(type_entry->id == TypeTableEntryIdInt);3346 assert(type_entry->id == TypeTableEntryIdInt);
3364 if (type_entry->data.integral.bit_count == 64) {3347 if (type_entry->data.integral.bit_count == 64) {
...@@ -3407,7 +3390,6 @@ static int64_t min_signed_val(TypeTableEntry *type_entry) {...@@ -3407,7 +3390,6 @@ static int64_t min_signed_val(TypeTableEntry *type_entry) {
3407void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) {3390void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) {
3408 if (type_entry->id == TypeTableEntryIdInt) {3391 if (type_entry->id == TypeTableEntryIdInt) {
3409 const_val->special = ConstValSpecialStatic;3392 const_val->special = ConstValSpecialStatic;
3410 const_val->depends_on_compile_var = int_type_depends_on_compile_var(g, type_entry);
3411 if (is_max) {3393 if (is_max) {
3412 if (type_entry->data.integral.is_signed) {3394 if (type_entry->data.integral.is_signed) {
3413 int64_t val = max_signed_val(type_entry);3395 int64_t val = max_signed_val(type_entry);
src/codegen.cpp-3
...@@ -3362,7 +3362,6 @@ static void define_builtin_types(CodeGen *g) {...@@ -3362,7 +3362,6 @@ static void define_builtin_types(CodeGen *g) {
3362 bool is_signed = info->is_signed;3362 bool is_signed = info->is_signed;
33633363
3364 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);3364 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
3365 entry->size_depends_on_compile_var = true;
3366 entry->type_ref = LLVMIntType(size_in_bits);3365 entry->type_ref = LLVMIntType(size_in_bits);
33673366
3368 buf_init_from_str(&entry->name, info->name);3367 buf_init_from_str(&entry->name, info->name);
...@@ -3399,7 +3398,6 @@ static void define_builtin_types(CodeGen *g) {...@@ -3399,7 +3398,6 @@ static void define_builtin_types(CodeGen *g) {
33993398
3400 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);3399 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
3401 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);3400 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
3402 entry->size_depends_on_compile_var = true;
34033401
3404 const char u_or_i = is_signed ? 'i' : 'u';3402 const char u_or_i = is_signed ? 'i' : 'u';
3405 buf_resize(&entry->name, 0);3403 buf_resize(&entry->name, 0);
...@@ -3455,7 +3453,6 @@ static void define_builtin_types(CodeGen *g) {...@@ -3455,7 +3453,6 @@ static void define_builtin_types(CodeGen *g) {
3455 {3453 {
3456 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);3454 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);
3457 entry->type_ref = LLVMX86FP80Type();3455 entry->type_ref = LLVMX86FP80Type();
3458 entry->size_depends_on_compile_var = true;
3459 buf_init_from_str(&entry->name, "c_long_double");3456 buf_init_from_str(&entry->name, "c_long_double");
3460 entry->data.floating.bit_count = 80;3457 entry->data.floating.bit_count = 80;
34613458
src/ir.cpp+137-258
...@@ -610,13 +610,12 @@ static IrInstruction *ir_build_return_from(IrBuilder *irb, IrInstruction *old_in...@@ -610,13 +610,12 @@ static IrInstruction *ir_build_return_from(IrBuilder *irb, IrInstruction *old_in
610}610}
611611
612static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,612static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,
613 TypeTableEntry *type_entry, bool depends_on_compile_var)613 TypeTableEntry *type_entry)
614{614{
615 assert(type_entry);615 assert(type_entry);
616 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);616 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
617 const_instruction->base.value.type = type_entry;617 const_instruction->base.value.type = type_entry;
618 const_instruction->base.value.special = ConstValSpecialStatic;618 const_instruction->base.value.special = ConstValSpecialStatic;
619 const_instruction->base.value.depends_on_compile_var = depends_on_compile_var;
620 return &const_instruction->base;619 return &const_instruction->base;
621}620}
622621
...@@ -667,20 +666,19 @@ static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode...@@ -667,20 +666,19 @@ static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode
667}666}
668667
669static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,668static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
670 TypeTableEntry *type_entry, bool depends_on_compile_var)669 TypeTableEntry *type_entry)
671{670{
672 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);671 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
673 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;672 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
674 const_instruction->base.value.special = ConstValSpecialStatic;673 const_instruction->base.value.special = ConstValSpecialStatic;
675 const_instruction->base.value.depends_on_compile_var = depends_on_compile_var;
676 const_instruction->base.value.data.x_type = type_entry;674 const_instruction->base.value.data.x_type = type_entry;
677 return &const_instruction->base;675 return &const_instruction->base;
678}676}
679677
680static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,678static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
681 TypeTableEntry *type_entry, bool depends_on_compile_var)679 TypeTableEntry *type_entry)
682{680{
683 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry, depends_on_compile_var);681 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
684 ir_instruction_append(irb->current_basic_block, instruction);682 ir_instruction_append(irb->current_basic_block, instruction);
685 return instruction;683 return instruction;
686}684}
...@@ -720,12 +718,11 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode...@@ -720,12 +718,11 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode
720}718}
721719
722static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,720static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,
723 FnTableEntry *fn_entry, IrInstruction *first_arg, bool depends_on_compile_var)721 FnTableEntry *fn_entry, IrInstruction *first_arg)
724{722{
725 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);723 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
726 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);724 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);
727 const_instruction->base.value.special = ConstValSpecialStatic;725 const_instruction->base.value.special = ConstValSpecialStatic;
728 const_instruction->base.value.depends_on_compile_var = depends_on_compile_var;
729 const_instruction->base.value.data.x_bound_fn.fn = fn_entry;726 const_instruction->base.value.data.x_bound_fn.fn = fn_entry;
730 const_instruction->base.value.data.x_bound_fn.first_arg = first_arg;727 const_instruction->base.value.data.x_bound_fn.first_arg = first_arg;
731 return &const_instruction->base;728 return &const_instruction->base;
...@@ -3609,7 +3606,7 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode...@@ -3609,7 +3606,7 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode
3609static IrInstruction *ir_gen_var_literal(IrBuilder *irb, Scope *scope, AstNode *node) {3606static IrInstruction *ir_gen_var_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
3610 assert(node->type == NodeTypeVarLiteral);3607 assert(node->type == NodeTypeVarLiteral);
36113608
3612 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var, false);3609 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var);
3613}3610}
36143611
3615static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld *tld,3612static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld *tld,
...@@ -3648,7 +3645,7 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld...@@ -3648,7 +3645,7 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld
3648 {3645 {
3649 TldTypeDef *tld_typedef = (TldTypeDef *)tld;3646 TldTypeDef *tld_typedef = (TldTypeDef *)tld;
3650 TypeTableEntry *typedef_type = tld_typedef->type_entry;3647 TypeTableEntry *typedef_type = tld_typedef->type_entry;
3651 IrInstruction *ref_instruction = ir_build_const_type(irb, scope, source_node, typedef_type, false);3648 IrInstruction *ref_instruction = ir_build_const_type(irb, scope, source_node, typedef_type);
3652 if (lval.is_ptr)3649 if (lval.is_ptr)
3653 return ir_build_ref(irb, scope, source_node, ref_instruction, true, false);3650 return ir_build_ref(irb, scope, source_node, ref_instruction, true, false);
3654 else3651 else
...@@ -3665,7 +3662,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3665,7 +3662,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
36653662
3666 auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);3663 auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);
3667 if (primitive_table_entry) {3664 if (primitive_table_entry) {
3668 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value, false);3665 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value);
3669 if (lval.is_ptr) {3666 if (lval.is_ptr) {
3670 return ir_build_ref(irb, scope, node, value, lval.is_const, lval.is_volatile);3667 return ir_build_ref(irb, scope, node, value, lval.is_const, lval.is_volatile);
3671 } else {3668 } else {
...@@ -4629,7 +4626,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -4629,7 +4626,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
4629 }4626 }
4630 child_scope = index_var->child_scope;4627 child_scope = index_var->child_scope;
46314628
4632 IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize, false);4629 IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize);
4633 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);4630 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
4634 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);4631 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
4635 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, zero);4632 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, zero);
...@@ -4693,7 +4690,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode...@@ -4693,7 +4690,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
4693 ScopeDecls *decls_scope = (ScopeDecls *)scope;4690 ScopeDecls *decls_scope = (ScopeDecls *)scope;
4694 TypeTableEntry *container_type = decls_scope->container_type;4691 TypeTableEntry *container_type = decls_scope->container_type;
4695 assert(container_type);4692 assert(container_type);
4696 return ir_build_const_type(irb, scope, node, container_type, false);4693 return ir_build_const_type(irb, scope, node, container_type);
4697 }4694 }
46984695
4699 if (scope->id == ScopeIdBlock)4696 if (scope->id == ScopeIdBlock)
...@@ -5260,12 +5257,12 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5260,12 +5257,12 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *scope, AstNode *nod
52605257
5261static IrInstruction *ir_gen_type_literal(IrBuilder *irb, Scope *scope, AstNode *node) {5258static IrInstruction *ir_gen_type_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
5262 assert(node->type == NodeTypeTypeLiteral);5259 assert(node->type == NodeTypeTypeLiteral);
5263 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_type, false);5260 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_type);
5264}5261}
52655262
5266static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {5263static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {
5267 assert(node->type == NodeTypeErrorType);5264 assert(node->type == NodeTypeErrorType);
5268 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_pure_error, false);5265 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_pure_error);
5269}5266}
52705267
5271static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) {5268static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
...@@ -5339,7 +5336,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN...@@ -5339,7 +5336,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
5339 if (var_node) {5336 if (var_node) {
5340 assert(var_node->type == NodeTypeSymbol);5337 assert(var_node->type == NodeTypeSymbol);
5341 IrInstruction *var_type = ir_build_const_type(irb, parent_scope, node,5338 IrInstruction *var_type = ir_build_const_type(irb, parent_scope, node,
5342 irb->codegen->builtin_types.entry_pure_error, false);5339 irb->codegen->builtin_types.entry_pure_error);
5343 Buf *var_name = var_node->data.symbol_expr.symbol;5340 Buf *var_name = var_node->data.symbol_expr.symbol;
5344 bool is_const = true;5341 bool is_const = true;
5345 bool is_shadowable = false;5342 bool is_shadowable = false;
...@@ -5427,7 +5424,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,...@@ -5427,7 +5424,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
5427 }5424 }
5428 irb->codegen->resolve_queue.append(&tld_container->base);5425 irb->codegen->resolve_queue.append(&tld_container->base);
54295426
5430 return ir_build_const_type(irb, parent_scope, node, container_type, false);5427 return ir_build_const_type(irb, parent_scope, node, container_type);
5431}5428}
54325429
5433static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) {5430static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
...@@ -5997,7 +5994,6 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,...@@ -5997,7 +5994,6 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
5997 ConstExprValue *other_val, TypeTableEntry *other_type,5994 ConstExprValue *other_val, TypeTableEntry *other_type,
5998 ConstExprValue *const_val, TypeTableEntry *new_type)5995 ConstExprValue *const_val, TypeTableEntry *new_type)
5999{5996{
6000 const_val->depends_on_compile_var = other_val->depends_on_compile_var;
6001 const_val->special = other_val->special;5997 const_val->special = other_val->special;
60025998
6003 assert(other_val != const_val);5999 assert(other_val != const_val);
...@@ -6045,7 +6041,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -6045,7 +6041,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
6045{6041{
6046 if (value->value.special != ConstValSpecialRuntime) {6042 if (value->value.special != ConstValSpecialRuntime) {
6047 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6043 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6048 source_instr->source_node, wanted_type, false);6044 source_instr->source_node, wanted_type);
6049 eval_const_expr_implicit_cast(cast_op, &value->value, value->value.type,6045 eval_const_expr_implicit_cast(cast_op, &value->value, value->value.type,
6050 &result->value, wanted_type);6046 &result->value, wanted_type);
6051 return result;6047 return result;
...@@ -6179,9 +6175,7 @@ static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_typ...@@ -6179,9 +6175,7 @@ static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_typ
6179 return result_type;6175 return result_type;
6180}6176}
61816177
6182static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_instruction,6178static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_instruction) {
6183 bool depends_on_compile_var)
6184{
6185 IrInstruction *new_instruction;6179 IrInstruction *new_instruction;
6186 if (old_instruction->id == IrInstructionIdVarPtr) {6180 if (old_instruction->id == IrInstructionIdVarPtr) {
6187 IrInstructionVarPtr *old_var_ptr_instruction = (IrInstructionVarPtr *)old_instruction;6181 IrInstructionVarPtr *old_var_ptr_instruction = (IrInstructionVarPtr *)old_instruction;
...@@ -6205,17 +6199,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in...@@ -6205,17 +6199,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in
6205 ir_link_new_instruction(new_instruction, old_instruction);6199 ir_link_new_instruction(new_instruction, old_instruction);
6206 ConstExprValue *const_val = &new_instruction->value;6200 ConstExprValue *const_val = &new_instruction->value;
6207 const_val->special = ConstValSpecialStatic;6201 const_val->special = ConstValSpecialStatic;
6208 const_val->depends_on_compile_var = depends_on_compile_var;
6209 return const_val;6202 return const_val;
6210}6203}
62116204
6212static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {6205static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
6213 ir_build_const_from(ira, instruction, false);6206 ir_build_const_from(ira, instruction);
6214 return ira->codegen->builtin_types.entry_void;6207 return ira->codegen->builtin_types.entry_void;
6215}6208}
62166209
6217static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,6210static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
6218 ConstExprValue *pointee, TypeTableEntry *pointee_type, bool depends_on_compile_var,6211 ConstExprValue *pointee, TypeTableEntry *pointee_type,
6219 ConstPtrSpecial special, bool ptr_is_const, bool ptr_is_volatile)6212 ConstPtrSpecial special, bool ptr_is_const, bool ptr_is_volatile)
6220{6213{
6221 if (pointee_type->id == TypeTableEntryIdMetaType) {6214 if (pointee_type->id == TypeTableEntryIdMetaType) {
...@@ -6225,8 +6218,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr...@@ -6225,8 +6218,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
6225 return ira->codegen->builtin_types.entry_invalid;6218 return ira->codegen->builtin_types.entry_invalid;
6226 }6219 }
62276220
6228 ConstExprValue *const_val = ir_build_const_from(ira, instruction,6221 ConstExprValue *const_val = ir_build_const_from(ira, instruction);
6229 depends_on_compile_var || pointee->depends_on_compile_var);
6230 type_ensure_zero_bits_known(ira->codegen, type_entry);6222 type_ensure_zero_bits_known(ira->codegen, type_entry);
6231 const_val->data.x_type = get_pointer_to_type_volatile(ira->codegen, type_entry,6223 const_val->data.x_type = get_pointer_to_type_volatile(ira->codegen, type_entry,
6232 ptr_is_const, ptr_is_volatile);6224 ptr_is_const, ptr_is_volatile);
...@@ -6234,8 +6226,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr...@@ -6234,8 +6226,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
6234 } else {6226 } else {
6235 TypeTableEntry *ptr_type = get_pointer_to_type_volatile(ira->codegen, pointee_type,6227 TypeTableEntry *ptr_type = get_pointer_to_type_volatile(ira->codegen, pointee_type,
6236 ptr_is_const, ptr_is_volatile);6228 ptr_is_const, ptr_is_volatile);
6237 ConstExprValue *const_val = ir_build_const_from(ira, instruction,6229 ConstExprValue *const_val = ir_build_const_from(ira, instruction);
6238 depends_on_compile_var || pointee->depends_on_compile_var);
6239 const_val->data.x_ptr.base_ptr = pointee;6230 const_val->data.x_ptr.base_ptr = pointee;
6240 const_val->data.x_ptr.index = SIZE_MAX;6231 const_val->data.x_ptr.index = SIZE_MAX;
6241 const_val->data.x_ptr.special = special;6232 const_val->data.x_ptr.special = special;
...@@ -6243,10 +6234,8 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr...@@ -6243,10 +6234,8 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
6243 }6234 }
6244}6235}
62456236
6246static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value,6237static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) {
6247 bool depends_on_compile_var)6238 ConstExprValue *const_val = ir_build_const_from(ira, instruction);
6248{
6249 ConstExprValue *const_val = ir_build_const_from(ira, instruction, depends_on_compile_var);
6250 bignum_init_unsigned(&const_val->data.x_bignum, value);6239 bignum_init_unsigned(&const_val->data.x_bignum, value);
6251 return ira->codegen->builtin_types.entry_usize;6240 return ira->codegen->builtin_types.entry_usize;
6252}6241}
...@@ -6376,7 +6365,6 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -6376,7 +6365,6 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
6376 source_instr->scope, source_instr->source_node);6365 source_instr->scope, source_instr->source_node);
6377 const_instruction->base.value.type = wanted_type;6366 const_instruction->base.value.type = wanted_type;
6378 const_instruction->base.value.special = ConstValSpecialStatic;6367 const_instruction->base.value.special = ConstValSpecialStatic;
6379 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
6380 const_instruction->base.value.data.x_maybe = val;6368 const_instruction->base.value.data.x_maybe = val;
6381 return &const_instruction->base;6369 return &const_instruction->base;
6382 }6370 }
...@@ -6435,7 +6423,6 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -6435,7 +6423,6 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
6435 source_instr->scope, source_instr->source_node);6423 source_instr->scope, source_instr->source_node);
6436 const_instruction->base.value.type = wanted_type;6424 const_instruction->base.value.type = wanted_type;
6437 const_instruction->base.value.special = ConstValSpecialStatic;6425 const_instruction->base.value.special = ConstValSpecialStatic;
6438 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
6439 const_instruction->base.value.data.x_err_union.err = nullptr;6426 const_instruction->base.value.data.x_err_union.err = nullptr;
6440 const_instruction->base.value.data.x_err_union.payload = val;6427 const_instruction->base.value.data.x_err_union.payload = val;
6441 return &const_instruction->base;6428 return &const_instruction->base;
...@@ -6460,7 +6447,6 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -6460,7 +6447,6 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
6460 source_instr->scope, source_instr->source_node);6447 source_instr->scope, source_instr->source_node);
6461 const_instruction->base.value.type = wanted_type;6448 const_instruction->base.value.type = wanted_type;
6462 const_instruction->base.value.special = ConstValSpecialStatic;6449 const_instruction->base.value.special = ConstValSpecialStatic;
6463 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
6464 const_instruction->base.value.data.x_err_union.err = val->data.x_pure_err;6450 const_instruction->base.value.data.x_err_union.err = val->data.x_pure_err;
6465 const_instruction->base.value.data.x_err_union.payload = nullptr;6451 const_instruction->base.value.data.x_err_union.payload = nullptr;
6466 return &const_instruction->base;6452 return &const_instruction->base;
...@@ -6485,7 +6471,6 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_...@@ -6485,7 +6471,6 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
6485 source_instr->scope, source_instr->source_node);6471 source_instr->scope, source_instr->source_node);
6486 const_instruction->base.value.type = wanted_type;6472 const_instruction->base.value.type = wanted_type;
6487 const_instruction->base.value.special = ConstValSpecialStatic;6473 const_instruction->base.value.special = ConstValSpecialStatic;
6488 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
6489 const_instruction->base.value.data.x_ptr.base_ptr = val;6474 const_instruction->base.value.data.x_ptr.base_ptr = val;
6490 const_instruction->base.value.data.x_ptr.index = SIZE_MAX;6475 const_instruction->base.value.data.x_ptr.index = SIZE_MAX;
6491 return &const_instruction->base;6476 return &const_instruction->base;
...@@ -6519,7 +6504,6 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -6519,7 +6504,6 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
6519 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node);6504 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node);
6520 const_instruction->base.value.type = wanted_type;6505 const_instruction->base.value.type = wanted_type;
6521 const_instruction->base.value.special = ConstValSpecialStatic;6506 const_instruction->base.value.special = ConstValSpecialStatic;
6522 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
6523 const_instruction->base.value.data.x_maybe = nullptr;6507 const_instruction->base.value.data.x_maybe = nullptr;
6524 return &const_instruction->base;6508 return &const_instruction->base;
6525}6509}
...@@ -6534,17 +6518,17 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s...@@ -6534,17 +6518,17 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
65346518
6535 if (instr_is_comptime(array)) {6519 if (instr_is_comptime(array)) {
6536 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6520 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6537 source_instr->source_node, wanted_type, false);6521 source_instr->source_node, wanted_type);
6538 init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true);6522 init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true);
6539 return result;6523 return result;
6540 }6524 }
65416525
6542 IrInstruction *start = ir_create_const(&ira->new_irb, source_instr->scope,6526 IrInstruction *start = ir_create_const(&ira->new_irb, source_instr->scope,
6543 source_instr->source_node, ira->codegen->builtin_types.entry_usize, false);6527 source_instr->source_node, ira->codegen->builtin_types.entry_usize);
6544 init_const_usize(ira->codegen, &start->value, 0);6528 init_const_usize(ira->codegen, &start->value, 0);
65456529
6546 IrInstruction *end = ir_create_const(&ira->new_irb, source_instr->scope,6530 IrInstruction *end = ir_create_const(&ira->new_irb, source_instr->scope,
6547 source_instr->source_node, ira->codegen->builtin_types.entry_usize, false);6531 source_instr->source_node, ira->codegen->builtin_types.entry_usize);
6548 init_const_usize(ira->codegen, &end->value, array_type->data.array.len);6532 init_const_usize(ira->codegen, &end->value, array_type->data.array.len);
65496533
6550 bool is_const;6534 bool is_const;
...@@ -6573,7 +6557,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -6573,7 +6557,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
6573 if (!val)6557 if (!val)
6574 return ira->codegen->invalid_instruction;6558 return ira->codegen->invalid_instruction;
6575 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6559 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6576 source_instr->source_node, wanted_type, val->depends_on_compile_var);6560 source_instr->source_node, wanted_type);
6577 init_const_unsigned_negative(&result->value, wanted_type, val->data.x_enum.tag, false);6561 init_const_unsigned_negative(&result->value, wanted_type, val->data.x_enum.tag, false);
6578 return result;6562 return result;
6579 }6563 }
...@@ -6588,7 +6572,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc...@@ -6588,7 +6572,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
6588 IrInstruction *target, TypeTableEntry *wanted_type)6572 IrInstruction *target, TypeTableEntry *wanted_type)
6589{6573{
6590 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6574 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6591 source_instr->source_node, wanted_type, target->value.depends_on_compile_var);6575 source_instr->source_node, wanted_type);
6592 init_const_undefined(ira->codegen, &result->value);6576 init_const_undefined(ira->codegen, &result->value);
6593 return result;6577 return result;
6594}6578}
...@@ -6603,7 +6587,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -6603,7 +6587,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
6603 if (!val)6587 if (!val)
6604 return ira->codegen->invalid_instruction;6588 return ira->codegen->invalid_instruction;
6605 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6589 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6606 source_instr->source_node, wanted_type, val->depends_on_compile_var);6590 source_instr->source_node, wanted_type);
6607 result->value = *val;6591 result->value = *val;
6608 result->value.type = wanted_type;6592 result->value.type = wanted_type;
6609 return result;6593 return result;
...@@ -6626,7 +6610,7 @@ static IrInstruction *ir_analyze_ptr_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -6626,7 +6610,7 @@ static IrInstruction *ir_analyze_ptr_to_int(IrAnalyze *ira, IrInstruction *sourc
6626 return ira->codegen->invalid_instruction;6610 return ira->codegen->invalid_instruction;
6627 if (val->data.x_ptr.special == ConstPtrSpecialRuntime) {6611 if (val->data.x_ptr.special == ConstPtrSpecialRuntime) {
6628 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6612 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6629 source_instr->source_node, wanted_type, val->depends_on_compile_var);6613 source_instr->source_node, wanted_type);
6630 bignum_init_unsigned(&result->value.data.x_bignum, val->data.x_ptr.index);6614 bignum_init_unsigned(&result->value.data.x_bignum, val->data.x_ptr.index);
6631 return result;6615 return result;
6632 }6616 }
...@@ -6648,7 +6632,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -6648,7 +6632,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
6648 if (!val)6632 if (!val)
6649 return ira->codegen->invalid_instruction;6633 return ira->codegen->invalid_instruction;
6650 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6634 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6651 source_instr->source_node, wanted_type, val->depends_on_compile_var);6635 source_instr->source_node, wanted_type);
6652 result->value.data.x_ptr.base_ptr = nullptr;6636 result->value.data.x_ptr.base_ptr = nullptr;
6653 result->value.data.x_ptr.index = bignum_to_twos_complement(&val->data.x_bignum);6637 result->value.data.x_ptr.index = bignum_to_twos_complement(&val->data.x_bignum);
6654 result->value.data.x_ptr.special = ConstPtrSpecialRuntime;6638 result->value.data.x_ptr.special = ConstPtrSpecialRuntime;
...@@ -6675,7 +6659,7 @@ static IrInstruction *ir_analyze_int_lit_to_ptr(IrAnalyze *ira, IrInstruction *s...@@ -6675,7 +6659,7 @@ static IrInstruction *ir_analyze_int_lit_to_ptr(IrAnalyze *ira, IrInstruction *s
6675 return ira->codegen->invalid_instruction;6659 return ira->codegen->invalid_instruction;
66766660
6677 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6661 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6678 source_instr->source_node, wanted_type, val->depends_on_compile_var);6662 source_instr->source_node, wanted_type);
6679 result->value.data.x_ptr.base_ptr = nullptr;6663 result->value.data.x_ptr.base_ptr = nullptr;
6680 result->value.data.x_ptr.index = bignum_to_twos_complement(&val->data.x_bignum);6664 result->value.data.x_ptr.index = bignum_to_twos_complement(&val->data.x_bignum);
6681 result->value.data.x_ptr.special = ConstPtrSpecialRuntime;6665 result->value.data.x_ptr.special = ConstPtrSpecialRuntime;
...@@ -6692,7 +6676,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -6692,7 +6676,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
6692 if (!val)6676 if (!val)
6693 return ira->codegen->invalid_instruction;6677 return ira->codegen->invalid_instruction;
6694 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6678 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6695 source_instr->source_node, wanted_type, val->depends_on_compile_var);6679 source_instr->source_node, wanted_type);
6696 result->value.data.x_enum.tag = val->data.x_bignum.data.x_uint;6680 result->value.data.x_enum.tag = val->data.x_bignum.data.x_uint;
6697 return result;6681 return result;
6698 }6682 }
...@@ -6711,7 +6695,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -6711,7 +6695,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
6711 return ira->codegen->invalid_instruction;6695 return ira->codegen->invalid_instruction;
67126696
6713 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,6697 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
6714 source_instr->source_node, wanted_type, true);6698 source_instr->source_node, wanted_type);
6715 bignum_init_bignum(&result->value.data.x_bignum, &val->data.x_bignum);6699 bignum_init_bignum(&result->value.data.x_bignum, &val->data.x_bignum);
6716 return result;6700 return result;
6717}6701}
...@@ -7026,10 +7010,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -7026,10 +7010,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
7026 ConstExprValue *pointee = const_ptr_pointee(&ptr->value);7010 ConstExprValue *pointee = const_ptr_pointee(&ptr->value);
7027 if (pointee->special != ConstValSpecialRuntime) {7011 if (pointee->special != ConstValSpecialRuntime) {
7028 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,7012 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
7029 source_instruction->source_node, child_type, false);7013 source_instruction->source_node, child_type);
7030 result->value = *pointee;7014 result->value = *pointee;
7031 result->value.depends_on_compile_var = pointee->depends_on_compile_var ||
7032 ptr->value.depends_on_compile_var;
7033 return result;7015 return result;
7034 }7016 }
7035 }7017 }
...@@ -7046,7 +7028,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -7046,7 +7028,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
7046 if (ptr_type->id == TypeTableEntryIdPointer) {7028 if (ptr_type->id == TypeTableEntryIdPointer) {
7047 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;7029 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
7048 return ir_create_const_type(&ira->new_irb, source_instruction->scope,7030 return ir_create_const_type(&ira->new_irb, source_instruction->scope,
7049 source_instruction->source_node, child_type, ptr_val->depends_on_compile_var);7031 source_instruction->source_node, child_type);
7050 } else {7032 } else {
7051 ir_add_error(ira, source_instruction,7033 ir_add_error(ira, source_instruction,
7052 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name)));7034 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name)));
...@@ -7071,7 +7053,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst...@@ -7071,7 +7053,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
7071 if (!val)7053 if (!val)
7072 return ira->codegen->builtin_types.entry_invalid;7054 return ira->codegen->builtin_types.entry_invalid;
7073 return ir_analyze_const_ptr(ira, source_instruction, val, value->value.type,7055 return ir_analyze_const_ptr(ira, source_instruction, val, value->value.type,
7074 value->value.depends_on_compile_var, ConstPtrSpecialNone, is_const, is_volatile);7056 ConstPtrSpecialNone, is_const, is_volatile);
7075 }7057 }
70767058
7077 TypeTableEntry *ptr_type = get_pointer_to_type_volatile(ira->codegen, value->value.type, is_const, is_volatile);7059 TypeTableEntry *ptr_type = get_pointer_to_type_volatile(ira->codegen, value->value.type, is_const, is_volatile);
...@@ -7187,8 +7169,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,...@@ -7187,8 +7169,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
7187}7169}
71887170
7189static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {7171static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
7190 bool depends_on_compile_var = const_instruction->base.value.depends_on_compile_var;7172 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base);
7191 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base, depends_on_compile_var);
7192 *out_val = const_instruction->base.value;7173 *out_val = const_instruction->base.value;
7193 return const_instruction->base.value.type;7174 return const_instruction->base.value.type;
7194}7175}
...@@ -7215,8 +7196,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -7215,8 +7196,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
7215 ConstExprValue *op1_val = &casted_op1->value;7196 ConstExprValue *op1_val = &casted_op1->value;
7216 ConstExprValue *op2_val = &casted_op2->value;7197 ConstExprValue *op2_val = &casted_op2->value;
7217 if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {7198 if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {
7218 bool depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var;7199 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
7219 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var);
72207200
7221 assert(casted_op1->value.type->id == TypeTableEntryIdBool);7201 assert(casted_op1->value.type->id == TypeTableEntryIdBool);
7222 assert(casted_op2->value.type->id == TypeTableEntryIdBool);7202 assert(casted_op2->value.type->id == TypeTableEntryIdBool);
...@@ -7246,9 +7226,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -7246,9 +7226,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
7246 (op2->value.type->id == TypeTableEntryIdNullLit && op1->value.type->id == TypeTableEntryIdMaybe) ||7226 (op2->value.type->id == TypeTableEntryIdNullLit && op1->value.type->id == TypeTableEntryIdMaybe) ||
7247 (op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit)))7227 (op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit)))
7248 {7228 {
7249 bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var;
7250 if (op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit) {7229 if (op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit) {
7251 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var);7230 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
7252 out_val->data.x_bool = (op_id == IrBinOpCmpEq);7231 out_val->data.x_bool = (op_id == IrBinOpCmpEq);
7253 return ira->codegen->builtin_types.entry_bool;7232 return ira->codegen->builtin_types.entry_bool;
7254 }7233 }
...@@ -7265,7 +7244,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -7265,7 +7244,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
7265 if (!maybe_val)7244 if (!maybe_val)
7266 return ira->codegen->builtin_types.entry_invalid;7245 return ira->codegen->builtin_types.entry_invalid;
7267 bool is_null = (maybe_val->data.x_maybe == nullptr);7246 bool is_null = (maybe_val->data.x_maybe == nullptr);
7268 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var);7247 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
7269 out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null;7248 out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
7270 return ira->codegen->builtin_types.entry_bool;7249 return ira->codegen->builtin_types.entry_bool;
7271 }7250 }
...@@ -7389,8 +7368,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -7389,8 +7368,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
7389 }7368 }
7390 }7369 }
73917370
7392 bool depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var;7371 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
7393 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var);
7394 out_val->data.x_bool = answer;7372 out_val->data.x_bool = answer;
7395 return ira->codegen->builtin_types.entry_bool;7373 return ira->codegen->builtin_types.entry_bool;
7396 }7374 }
...@@ -7463,7 +7441,6 @@ static int ir_eval_bignum(ConstExprValue *op1_val, ConstExprValue *op2_val,...@@ -7463,7 +7441,6 @@ static int ir_eval_bignum(ConstExprValue *op1_val, ConstExprValue *op2_val,
7463 }7441 }
74647442
7465 out_val->special = ConstValSpecialStatic;7443 out_val->special = ConstValSpecialStatic;
7466 out_val->depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var;
7467 return 0;7444 return 0;
7468}7445}
74697446
...@@ -7682,8 +7659,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -7682,8 +7659,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
7682 return ira->codegen->builtin_types.entry_invalid;7659 return ira->codegen->builtin_types.entry_invalid;
7683 }7660 }
76847661
7685 bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var;7662 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
7686 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
76877663
7688 TypeTableEntry *result_type;7664 TypeTableEntry *result_type;
7689 ConstExprValue *out_array_val;7665 ConstExprValue *out_array_val;
...@@ -7757,8 +7733,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp...@@ -7757,8 +7733,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
7757 return ira->codegen->builtin_types.entry_invalid;7733 return ira->codegen->builtin_types.entry_invalid;
7758 }7734 }
77597735
7760 bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var;7736 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
7761 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
77627737
7763 uint64_t new_array_len = array_len.data.x_uint;7738 uint64_t new_array_len = array_len.data.x_uint;
7764 out_val->data.x_array.size = new_array_len;7739 out_val->data.x_array.size = new_array_len;
...@@ -7913,7 +7888,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7913,7 +7888,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
7913 *mem_slot = casted_init_value->value;7888 *mem_slot = casted_init_value->value;
79147889
7915 if (is_comptime) {7890 if (is_comptime) {
7916 ir_build_const_from(ira, &decl_var_instruction->base, false);7891 ir_build_const_from(ira, &decl_var_instruction->base);
7917 return ira->codegen->builtin_types.entry_void;7892 return ira->codegen->builtin_types.entry_void;
7918 }7893 }
7919 }7894 }
...@@ -7954,7 +7929,6 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -7954,7 +7929,6 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
7954 Buf *param_name = param_decl_node->data.param_decl.name;7929 Buf *param_name = param_decl_node->data.param_decl.name;
7955 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,7930 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
7956 *exec_scope, param_name, true, arg_val);7931 *exec_scope, param_name, true, arg_val);
7957 var->value.depends_on_compile_var = true;
7958 *exec_scope = var->child_scope;7932 *exec_scope = var->child_scope;
7959 *next_proto_i += 1;7933 *next_proto_i += 1;
79607934
...@@ -8000,9 +7974,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -8000,9 +7974,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
8000 arg_val = ir_resolve_const(ira, casted_arg, UndefBad);7974 arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
8001 if (!arg_val)7975 if (!arg_val)
8002 return false;7976 return false;
8003 // This generic function instance could be called with anything, so when this variable is read it
8004 // needs to know that it depends on compile time variable data.
8005 arg_val->depends_on_compile_var = true;
8006 } else {7977 } else {
8007 arg_val = create_const_runtime(casted_arg->value.type);7978 arg_val = create_const_runtime(casted_arg->value.type);
8008 }7979 }
...@@ -8015,7 +7986,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -8015,7 +7986,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
8015 if (!is_var_args) {7986 if (!is_var_args) {
8016 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,7987 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
8017 *child_scope, param_name, true, arg_val);7988 *child_scope, param_name, true, arg_val);
8018 var->value.depends_on_compile_var = true;
8019 *child_scope = var->child_scope;7989 *child_scope = var->child_scope;
8020 var->shadowable = !comptime_arg;7990 var->shadowable = !comptime_arg;
80217991
...@@ -8133,8 +8103,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8133,8 +8103,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8133 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);8103 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);
8134 }8104 }
81358105
8136 ConstExprValue *out_val = ir_build_const_from(ira, &call_instruction->base,8106 ConstExprValue *out_val = ir_build_const_from(ira, &call_instruction->base);
8137 result->value.depends_on_compile_var);
8138 *out_val = result->value;8107 *out_val = result->value;
8139 return ir_finish_anal(ira, return_type);8108 return ir_finish_anal(ira, return_type);
8140 }8109 }
...@@ -8212,7 +8181,6 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8212,7 +8181,6 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8212 first_var_arg, inst_fn_type_id.param_count);8181 first_var_arg, inst_fn_type_id.param_count);
8213 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,8182 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
8214 impl_fn->child_scope, param_name, true, var_args_val);8183 impl_fn->child_scope, param_name, true, var_args_val);
8215 var->value.depends_on_compile_var = true;
8216 impl_fn->child_scope = var->child_scope;8184 impl_fn->child_scope = var->child_scope;
8217 }8185 }
8218 {8186 {
...@@ -8398,8 +8366,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct...@@ -8398,8 +8366,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
8398 case TypeTableEntryIdBoundFn:8366 case TypeTableEntryIdBoundFn:
8399 case TypeTableEntryIdEnumTag:8367 case TypeTableEntryIdEnumTag:
8400 {8368 {
8401 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,8369 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8402 value->value.depends_on_compile_var);
8403 TypeTableEntry *result_type = get_error_type(ira->codegen, meta_type);8370 TypeTableEntry *result_type = get_error_type(ira->codegen, meta_type);
8404 out_val->data.x_type = result_type;8371 out_val->data.x_type = result_type;
8405 return ira->codegen->builtin_types.entry_type;8372 return ira->codegen->builtin_types.entry_type;
...@@ -8443,7 +8410,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp...@@ -8443,7 +8410,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
8443 // one of the ptr instructions8410 // one of the ptr instructions
84448411
8445 if (value->value.special != ConstValSpecialRuntime) {8412 if (value->value.special != ConstValSpecialRuntime) {
8446 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, false);8413 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8447 ConstExprValue *pointee = const_ptr_pointee(&value->value);8414 ConstExprValue *pointee = const_ptr_pointee(&value->value);
8448 *out_val = *pointee;8415 *out_val = *pointee;
8449 return child_type;8416 return child_type;
...@@ -8488,8 +8455,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -8488,8 +8455,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
8488 case TypeTableEntryIdEnumTag:8455 case TypeTableEntryIdEnumTag:
8489 case TypeTableEntryIdArgTuple:8456 case TypeTableEntryIdArgTuple:
8490 {8457 {
8491 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,8458 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8492 value->value.depends_on_compile_var);
8493 out_val->data.x_type = get_maybe_type(ira->codegen, type_entry);8459 out_val->data.x_type = get_maybe_type(ira->codegen, type_entry);
8494 return ira->codegen->builtin_types.entry_type;8460 return ira->codegen->builtin_types.entry_type;
8495 }8461 }
...@@ -8519,8 +8485,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -8519,8 +8485,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
8519 if (!target_const_val)8485 if (!target_const_val)
8520 return ira->codegen->builtin_types.entry_invalid;8486 return ira->codegen->builtin_types.entry_invalid;
85218487
8522 bool depends_on_compile_var = value->value.depends_on_compile_var;8488 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8523 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var);
8524 bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum);8489 bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum);
8525 if (expr_type->id == TypeTableEntryIdFloat ||8490 if (expr_type->id == TypeTableEntryIdFloat ||
8526 expr_type->id == TypeTableEntryIdNumLitFloat ||8491 expr_type->id == TypeTableEntryIdNumLitFloat ||
...@@ -8561,8 +8526,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -8561,8 +8526,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins
8561 if (!target_const_val)8526 if (!target_const_val)
8562 return ira->codegen->builtin_types.entry_invalid;8527 return ira->codegen->builtin_types.entry_invalid;
85638528
8564 bool depends_on_compile_var = value->value.depends_on_compile_var;8529 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
8565 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
8566 bignum_not(&out_val->data.x_bignum, &target_const_val->data.x_bignum,8530 bignum_not(&out_val->data.x_bignum, &target_const_val->data.x_bignum,
8567 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);8531 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
8568 return expr_type;8532 return expr_type;
...@@ -8669,9 +8633,8 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8669,9 +8633,8 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8669 return ira->codegen->builtin_types.entry_invalid;8633 return ira->codegen->builtin_types.entry_invalid;
86708634
8671 if (value->value.special != ConstValSpecialRuntime) {8635 if (value->value.special != ConstValSpecialRuntime) {
8672 ConstExprValue *out_val = ir_build_const_from(ira, &phi_instruction->base, true);8636 ConstExprValue *out_val = ir_build_const_from(ira, &phi_instruction->base);
8673 *out_val = value->value;8637 *out_val = value->value;
8674 out_val->depends_on_compile_var = true;
8675 } else {8638 } else {
8676 phi_instruction->base.other = value;8639 phi_instruction->base.other = value;
8677 }8640 }
...@@ -8705,7 +8668,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8705,7 +8668,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8705 }8668 }
87068669
8707 if (new_incoming_blocks.length == 0) {8670 if (new_incoming_blocks.length == 0) {
8708 ir_build_const_from(ira, &phi_instruction->base, true);8671 ir_build_const_from(ira, &phi_instruction->base);
8709 return ira->codegen->builtin_types.entry_void;8672 return ira->codegen->builtin_types.entry_void;
8710 }8673 }
87118674
...@@ -8752,7 +8715,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8752,7 +8715,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8752}8715}
87538716
8754static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,8717static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
8755 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr, bool depends_on_compile_var)8718 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
8756{8719{
8757 assert(var->value.type);8720 assert(var->value.type);
8758 if (var->value.type->id == TypeTableEntryIdInvalid)8721 if (var->value.type->id == TypeTableEntryIdInvalid)
...@@ -8775,9 +8738,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -8775,9 +8738,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
8775 bool is_volatile = (var->value.type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;8738 bool is_volatile = (var->value.type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;
8776 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {8739 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {
8777 ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone;8740 ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone;
8778 depends_on_compile_var = mem_slot->depends_on_compile_var || depends_on_compile_var || is_comptime;8741 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, ptr_special, is_const, is_volatile);
8779 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type,
8780 depends_on_compile_var, ptr_special, is_const, is_volatile);
8781 } else {8742 } else {
8782 ir_build_var_ptr_from(&ira->new_irb, instruction, var, is_const, is_volatile);8743 ir_build_var_ptr_from(&ira->new_irb, instruction, var, is_const, is_volatile);
8783 type_ensure_zero_bits_known(ira->codegen, var->value.type);8744 type_ensure_zero_bits_known(ira->codegen, var->value.type);
...@@ -8788,7 +8749,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -8788,7 +8749,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
8788static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {8749static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
8789 VariableTableEntry *var = var_ptr_instruction->var;8750 VariableTableEntry *var = var_ptr_instruction->var;
8790 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,8751 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,
8791 var_ptr_instruction->is_volatile, false);8752 var_ptr_instruction->is_volatile);
8792}8753}
87938754
8794static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) {8755static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) {
...@@ -8858,16 +8819,14 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -8858,16 +8819,14 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
8858 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);8819 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
8859 assert(fn_entry);8820 assert(fn_entry);
8860 VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index);8821 VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index);
8861 bool depends_on_compile_var = array_ptr->value.depends_on_compile_var ||
8862 elem_index->value.depends_on_compile_var;
8863 bool is_const = true;8822 bool is_const = true;
8864 bool is_volatile = false;8823 bool is_volatile = false;
8865 if (var) {8824 if (var) {
8866 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,8825 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,
8867 is_const, is_volatile, depends_on_compile_var);8826 is_const, is_volatile);
8868 } else {8827 } else {
8869 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,8828 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,
8870 ira->codegen->builtin_types.entry_void, depends_on_compile_var, ConstPtrSpecialNone,8829 ira->codegen->builtin_types.entry_void, ConstPtrSpecialNone,
8871 is_const, is_volatile);8830 is_const, is_volatile);
8872 }8831 }
8873 } else {8832 } else {
...@@ -8901,9 +8860,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -8901,9 +8860,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
8901 array_ptr_val->special != ConstValSpecialRuntime &&8860 array_ptr_val->special != ConstValSpecialRuntime &&
8902 (array_type->id != TypeTableEntryIdPointer || array_ptr_val->data.x_ptr.special != ConstPtrSpecialRuntime))8861 (array_type->id != TypeTableEntryIdPointer || array_ptr_val->data.x_ptr.special != ConstPtrSpecialRuntime))
8903 {8862 {
8904 bool depends_on_compile_var = array_ptr_val->depends_on_compile_var ||8863 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
8905 casted_elem_index->value.depends_on_compile_var;
8906 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base, depends_on_compile_var);
8907 if (array_type->id == TypeTableEntryIdPointer) {8864 if (array_type->id == TypeTableEntryIdPointer) {
8908 size_t offset = array_ptr_val->data.x_ptr.index;8865 size_t offset = array_ptr_val->data.x_ptr.index;
8909 size_t new_index;8866 size_t new_index;
...@@ -8974,9 +8931,8 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -8974,9 +8931,8 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
8974 return ira->codegen->builtin_types.entry_invalid;8931 return ira->codegen->builtin_types.entry_invalid;
8975 TldFn *tld_fn = (TldFn *)tld;8932 TldFn *tld_fn = (TldFn *)tld;
8976 FnTableEntry *fn_entry = tld_fn->fn_entry;8933 FnTableEntry *fn_entry = tld_fn->fn_entry;
8977 bool depends_on_compile_var = container_ptr->value.depends_on_compile_var;
8978 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,8934 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,
8979 field_ptr_instruction->base.source_node, fn_entry, container_ptr, depends_on_compile_var);8935 field_ptr_instruction->base.source_node, fn_entry, container_ptr);
8980 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value, true, false);8936 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value, true, false);
8981 }8937 }
8982 }8938 }
...@@ -9011,11 +8967,8 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field...@@ -9011,11 +8967,8 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field
9011 if (value_is_comptime(struct_val)) {8967 if (value_is_comptime(struct_val)) {
9012 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];8968 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
9013 if (value_is_comptime(field_val)) {8969 if (value_is_comptime(field_val)) {
9014 bool depends_on_compile_var = field_val->depends_on_compile_var ||
9015 struct_val->depends_on_compile_var || ptr_val->depends_on_compile_var;
9016 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, field_val,8970 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, field_val,
9017 field_val->type, depends_on_compile_var, ConstPtrSpecialNone,8971 field_val->type, ConstPtrSpecialNone, is_const, is_volatile);
9018 is_const, is_volatile);
9019 }8972 }
9020 }8973 }
9021 }8974 }
...@@ -9045,9 +8998,7 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field...@@ -9045,9 +8998,7 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field
9045 }8998 }
9046}8999}
90479000
9048static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld,9001static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
9049 bool depends_on_compile_var)
9050{
9051 bool pointer_only = false;9002 bool pointer_only = false;
9052 resolve_top_level_decl(ira->codegen, tld, pointer_only);9003 resolve_top_level_decl(ira->codegen, tld, pointer_only);
9053 if (tld->resolution == TldResolutionInvalid)9004 if (tld->resolution == TldResolutionInvalid)
...@@ -9060,7 +9011,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -9060,7 +9011,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
9060 {9011 {
9061 TldVar *tld_var = (TldVar *)tld;9012 TldVar *tld_var = (TldVar *)tld;
9062 VariableTableEntry *var = tld_var->var;9013 VariableTableEntry *var = tld_var->var;
9063 return ir_analyze_var_ptr(ira, source_instruction, var, false, false, depends_on_compile_var);9014 return ir_analyze_var_ptr(ira, source_instruction, var, false, false);
9064 }9015 }
9065 case TldIdFn:9016 case TldIdFn:
9066 {9017 {
...@@ -9081,7 +9032,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -9081,7 +9032,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
9081 bool ptr_is_const = true;9032 bool ptr_is_const = true;
9082 bool ptr_is_volatile = false;9033 bool ptr_is_volatile = false;
9083 return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry,9034 return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry,
9084 depends_on_compile_var, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9035 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9085 }9036 }
9086 case TldIdTypeDef:9037 case TldIdTypeDef:
9087 {9038 {
...@@ -9098,7 +9049,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -9098,7 +9049,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
9098 bool ptr_is_const = true;9049 bool ptr_is_const = true;
9099 bool ptr_is_volatile = false;9050 bool ptr_is_volatile = false;
9100 return ir_analyze_const_ptr(ira, source_instruction, const_val, ira->codegen->builtin_types.entry_type,9051 return ir_analyze_const_ptr(ira, source_instruction, const_val, ira->codegen->builtin_types.entry_type,
9101 depends_on_compile_var, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9052 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9102 }9053 }
9103 }9054 }
9104 zig_unreachable();9055 zig_unreachable();
...@@ -9118,7 +9069,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9118,7 +9069,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9118 zig_unreachable();9069 zig_unreachable();
9119 }9070 }
91209071
9121 bool depends_on_compile_var = container_ptr->value.depends_on_compile_var;
9122 Buf *field_name = field_ptr_instruction->field_name;9072 Buf *field_name = field_ptr_instruction->field_name;
9123 AstNode *source_node = field_ptr_instruction->base.source_node;9073 AstNode *source_node = field_ptr_instruction->base.source_node;
91249074
...@@ -9142,7 +9092,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9142,7 +9092,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9142 bool ptr_is_const = true;9092 bool ptr_is_const = true;
9143 bool ptr_is_volatile = false;9093 bool ptr_is_volatile = false;
9144 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,9094 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
9145 usize, depends_on_compile_var, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9095 usize, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9146 } else {9096 } else {
9147 ir_add_error_node(ira, source_node,9097 ir_add_error_node(ira, source_node,
9148 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),9098 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
...@@ -9166,7 +9116,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9166,7 +9116,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9166 bool ptr_is_const = true;9116 bool ptr_is_const = true;
9167 bool ptr_is_volatile = false;9117 bool ptr_is_volatile = false;
9168 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,9118 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
9169 usize, depends_on_compile_var, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9119 usize, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9170 } else {9120 } else {
9171 ir_add_error_node(ira, source_node,9121 ir_add_error_node(ira, source_node,
9172 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),9122 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
...@@ -9204,14 +9154,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9204,14 +9154,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9204 bool ptr_is_const = true;9154 bool ptr_is_const = true;
9205 bool ptr_is_volatile = false;9155 bool ptr_is_volatile = false;
9206 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,9156 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
9207 create_const_enum_tag(child_type, field->value), child_type, depends_on_compile_var,9157 create_const_enum_tag(child_type, field->value), child_type,
9208 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9158 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9209 } else {9159 } else {
9210 bool ptr_is_const = true;9160 bool ptr_is_const = true;
9211 bool ptr_is_volatile = false;9161 bool ptr_is_volatile = false;
9212 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,9162 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
9213 create_const_unsigned_negative(child_type->data.enumeration.tag_type, field->value, false),9163 create_const_unsigned_negative(child_type->data.enumeration.tag_type, field->value, false),
9214 child_type->data.enumeration.tag_type, depends_on_compile_var,9164 child_type->data.enumeration.tag_type,
9215 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9165 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9216 }9166 }
9217 }9167 }
...@@ -9220,7 +9170,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9220,7 +9170,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9220 auto entry = container_scope->decl_table.maybe_get(field_name);9170 auto entry = container_scope->decl_table.maybe_get(field_name);
9221 Tld *tld = entry ? entry->value : nullptr;9171 Tld *tld = entry ? entry->value : nullptr;
9222 if (tld) {9172 if (tld) {
9223 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var);9173 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
9224 }9174 }
9225 ir_add_error(ira, &field_ptr_instruction->base,9175 ir_add_error(ira, &field_ptr_instruction->base,
9226 buf_sprintf("container '%s' has no member called '%s'",9176 buf_sprintf("container '%s' has no member called '%s'",
...@@ -9237,7 +9187,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9237,7 +9187,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9237 bool ptr_is_const = true;9187 bool ptr_is_const = true;
9238 bool ptr_is_volatile = false;9188 bool ptr_is_volatile = false;
9239 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,9189 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,
9240 child_type, depends_on_compile_var, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9190 child_type, ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9241 }9191 }
92429192
9243 ir_add_error(ira, &field_ptr_instruction->base,9193 ir_add_error(ira, &field_ptr_instruction->base,
...@@ -9250,14 +9200,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9250,14 +9200,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9250 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,9200 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
9251 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,9201 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
9252 child_type->data.integral.bit_count, false),9202 child_type->data.integral.bit_count, false),
9253 ira->codegen->builtin_types.entry_num_lit_int, depends_on_compile_var,9203 ira->codegen->builtin_types.entry_num_lit_int,
9254 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9204 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9255 } else if (buf_eql_str(field_name, "is_signed")) {9205 } else if (buf_eql_str(field_name, "is_signed")) {
9256 bool ptr_is_const = true;9206 bool ptr_is_const = true;
9257 bool ptr_is_volatile = false;9207 bool ptr_is_volatile = false;
9258 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,9208 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
9259 create_const_bool(ira->codegen, child_type->data.integral.is_signed),9209 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
9260 ira->codegen->builtin_types.entry_bool, depends_on_compile_var,9210 ira->codegen->builtin_types.entry_bool,
9261 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);9211 ConstPtrSpecialNone, ptr_is_const, ptr_is_volatile);
9262 } else {9212 } else {
9263 ir_add_error(ira, &field_ptr_instruction->base,9213 ir_add_error(ira, &field_ptr_instruction->base,
...@@ -9303,7 +9253,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9303,7 +9253,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9303 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));9253 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
9304 return ira->codegen->builtin_types.entry_invalid;9254 return ira->codegen->builtin_types.entry_invalid;
9305 }9255 }
9306 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var);9256 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
9307 } else {9257 } else {
9308 const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";9258 const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";
9309 ir_add_error_node(ira, source_node,9259 ir_add_error_node(ira, source_node,
...@@ -9401,10 +9351,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi...@@ -9401,10 +9351,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
9401 case TypeTableEntryIdEnumTag:9351 case TypeTableEntryIdEnumTag:
9402 case TypeTableEntryIdArgTuple:9352 case TypeTableEntryIdArgTuple:
9403 {9353 {
9404 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base, true);9354 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
9405 // TODO depends_on_compile_var should be set based on whether the type of the expression
9406 // depends_on_compile_var. but we currently don't have a thing to tell us if the type of
9407 // something depends on a compile var
9408 out_val->data.x_type = type_entry;9355 out_val->data.x_type = type_entry;
94099356
9410 return ira->codegen->builtin_types.entry_type;9357 return ira->codegen->builtin_types.entry_type;
...@@ -9438,8 +9385,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,...@@ -9438,8 +9385,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
9438 return ira->codegen->builtin_types.entry_invalid;9385 return ira->codegen->builtin_types.entry_invalid;
9439 }9386 }
94409387
9441 ConstExprValue *out_val = ir_build_const_from(ira, &to_ptr_type_instruction->base,9388 ConstExprValue *out_val = ir_build_const_from(ira, &to_ptr_type_instruction->base);
9442 value->value.depends_on_compile_var);
9443 out_val->data.x_type = ptr_type;9389 out_val->data.x_type = ptr_type;
9444 return ira->codegen->builtin_types.entry_type;9390 return ira->codegen->builtin_types.entry_type;
9445}9391}
...@@ -9459,8 +9405,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -9459,8 +9405,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
9459 return ira->codegen->builtin_types.entry_invalid;9405 return ira->codegen->builtin_types.entry_invalid;
9460 }9406 }
94619407
9462 ConstExprValue *out_val = ir_build_const_from(ira, &ptr_type_child_instruction->base,9408 ConstExprValue *out_val = ir_build_const_from(ira, &ptr_type_child_instruction->base);
9463 type_value->value.depends_on_compile_var);
9464 out_val->data.x_type = type_entry->data.pointer.child_type;9409 out_val->data.x_type = type_entry->data.pointer.child_type;
9465 return ira->codegen->builtin_types.entry_type;9410 return ira->codegen->builtin_types.entry_type;
9466}9411}
...@@ -9479,7 +9424,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_test(IrAnalyze *ira,...@@ -9479,7 +9424,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_test(IrAnalyze *ira,
9479 ira->codegen->test_fn_count += 1;9424 ira->codegen->test_fn_count += 1;
9480 }9425 }
94819426
9482 ir_build_const_from(ira, &set_fn_test_instruction->base, false);9427 ir_build_const_from(ira, &set_fn_test_instruction->base);
9483 return ira->codegen->builtin_types.entry_void;9428 return ira->codegen->builtin_types.entry_void;
9484}9429}
94859430
...@@ -9515,7 +9460,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,...@@ -9515,7 +9460,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
9515 }9460 }
9516 fn_entry->internal_linkage = !want_export;9461 fn_entry->internal_linkage = !want_export;
95179462
9518 ir_build_const_from(ira, &set_fn_visible_instruction->base, false);9463 ir_build_const_from(ira, &set_fn_visible_instruction->base);
9519 return ira->codegen->builtin_types.entry_void;9464 return ira->codegen->builtin_types.entry_void;
9520}9465}
95219466
...@@ -9564,7 +9509,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira,...@@ -9564,7 +9509,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira,
9564 *set_global_align_node = source_node;9509 *set_global_align_node = source_node;
9565 *alignment_ptr = scalar_align;9510 *alignment_ptr = scalar_align;
95669511
9567 ir_build_const_from(ira, &instruction->base, false);9512 ir_build_const_from(ira, &instruction->base);
9568 return ira->codegen->builtin_types.entry_void;9513 return ira->codegen->builtin_types.entry_void;
9569}9514}
95709515
...@@ -9603,7 +9548,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_section(IrAnalyze *ira,...@@ -9603,7 +9548,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_section(IrAnalyze *ira,
9603 *set_global_section_node = source_node;9548 *set_global_section_node = source_node;
9604 *section_name_ptr = section_name;9549 *section_name_ptr = section_name;
96059550
9606 ir_build_const_from(ira, &instruction->base, false);9551 ir_build_const_from(ira, &instruction->base);
9607 return ira->codegen->builtin_types.entry_void;9552 return ira->codegen->builtin_types.entry_void;
9608}9553}
96099554
...@@ -9620,7 +9565,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -9620,7 +9565,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
96209565
9621 if (ira->new_irb.exec->is_inline) {9566 if (ira->new_irb.exec->is_inline) {
9622 // ignore setDebugSafety when running functions at compile time9567 // ignore setDebugSafety when running functions at compile time
9623 ir_build_const_from(ira, &set_debug_safety_instruction->base, false);9568 ir_build_const_from(ira, &set_debug_safety_instruction->base);
9624 return ira->codegen->builtin_types.entry_void;9569 return ira->codegen->builtin_types.entry_void;
9625 }9570 }
96269571
...@@ -9672,7 +9617,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -9672,7 +9617,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
9672 *safety_set_node_ptr = source_node;9617 *safety_set_node_ptr = source_node;
9673 *safety_off_ptr = !want_debug_safety;9618 *safety_off_ptr = !want_debug_safety;
96749619
9675 ir_build_const_from(ira, &set_debug_safety_instruction->base, false);9620 ir_build_const_from(ira, &set_debug_safety_instruction->base);
9676 return ira->codegen->builtin_types.entry_void;9621 return ira->codegen->builtin_types.entry_void;
9677}9622}
96789623
...@@ -9723,8 +9668,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -9723,8 +9668,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
9723 {9668 {
9724 type_ensure_zero_bits_known(ira->codegen, resolved_child_type);9669 type_ensure_zero_bits_known(ira->codegen, resolved_child_type);
9725 TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const);9670 TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const);
9726 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base,9671 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
9727 child_type->value.depends_on_compile_var);
9728 out_val->data.x_type = result_type;9672 out_val->data.x_type = result_type;
9729 return ira->codegen->builtin_types.entry_type;9673 return ira->codegen->builtin_types.entry_type;
9730 }9674 }
...@@ -9814,10 +9758,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -9814,10 +9758,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
9814 case TypeTableEntryIdEnumTag:9758 case TypeTableEntryIdEnumTag:
9815 {9759 {
9816 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);9760 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
9817 bool depends_on_compile_var = child_type_value->value.depends_on_compile_var ||9761 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
9818 size_value->value.depends_on_compile_var;
9819 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base,
9820 depends_on_compile_var);
9821 out_val->data.x_type = result_type;9762 out_val->data.x_type = result_type;
9822 return ira->codegen->builtin_types.entry_type;9763 return ira->codegen->builtin_types.entry_type;
9823 }9764 }
...@@ -9833,7 +9774,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira,...@@ -9833,7 +9774,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira,
9833 if (!var_name)9774 if (!var_name)
9834 return ira->codegen->builtin_types.entry_invalid;9775 return ira->codegen->builtin_types.entry_invalid;
98359776
9836 ConstExprValue *out_val = ir_build_const_from(ira, &compile_var_instruction->base, true);9777 ConstExprValue *out_val = ir_build_const_from(ira, &compile_var_instruction->base);
9837 if (buf_eql_str(var_name, "is_big_endian")) {9778 if (buf_eql_str(var_name, "is_big_endian")) {
9838 out_val->data.x_bool = ira->codegen->is_big_endian;9779 out_val->data.x_bool = ira->codegen->is_big_endian;
9839 return ira->codegen->builtin_types.entry_bool;9780 return ira->codegen->builtin_types.entry_bool;
...@@ -9905,8 +9846,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -9905,8 +9846,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
9905 case TypeTableEntryIdEnumTag:9846 case TypeTableEntryIdEnumTag:
9906 {9847 {
9907 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);9848 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
9908 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base,9849 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);
9909 type_entry->size_depends_on_compile_var);
9910 bignum_init_unsigned(&out_val->data.x_bignum, size_in_bytes);9850 bignum_init_unsigned(&out_val->data.x_bignum, size_in_bytes);
9911 return ira->codegen->builtin_types.entry_num_lit_int;9851 return ira->codegen->builtin_types.entry_num_lit_int;
9912 }9852 }
...@@ -9927,8 +9867,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -9927,8 +9867,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
9927 if (!maybe_val)9867 if (!maybe_val)
9928 return ira->codegen->builtin_types.entry_invalid;9868 return ira->codegen->builtin_types.entry_invalid;
99299869
9930 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,9870 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
9931 maybe_val->depends_on_compile_var);
9932 out_val->data.x_bool = (maybe_val->data.x_maybe != nullptr);9871 out_val->data.x_bool = (maybe_val->data.x_maybe != nullptr);
9933 return ira->codegen->builtin_types.entry_bool;9872 return ira->codegen->builtin_types.entry_bool;
9934 }9873 }
...@@ -9936,11 +9875,11 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -9936,11 +9875,11 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
9936 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);9875 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
9937 return ira->codegen->builtin_types.entry_bool;9876 return ira->codegen->builtin_types.entry_bool;
9938 } else if (type_entry->id == TypeTableEntryIdNullLit) {9877 } else if (type_entry->id == TypeTableEntryIdNullLit) {
9939 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);9878 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
9940 out_val->data.x_bool = false;9879 out_val->data.x_bool = false;
9941 return ira->codegen->builtin_types.entry_bool;9880 return ira->codegen->builtin_types.entry_bool;
9942 } else {9881 } else {
9943 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);9882 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
9944 out_val->data.x_bool = true;9883 out_val->data.x_bool = true;
9945 return ira->codegen->builtin_types.entry_bool;9884 return ira->codegen->builtin_types.entry_bool;
9946 }9885 }
...@@ -9981,9 +9920,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -9981,9 +9920,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
9981 ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null"));9920 ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null"));
9982 return ira->codegen->builtin_types.entry_invalid;9921 return ira->codegen->builtin_types.entry_invalid;
9983 }9922 }
9984 bool depends_on_compile_var = maybe_val->depends_on_compile_var;9923 ConstExprValue *out_val = ir_build_const_from(ira, &unwrap_maybe_instruction->base);
9985 ConstExprValue *out_val = ir_build_const_from(ira, &unwrap_maybe_instruction->base,
9986 depends_on_compile_var);
9987 out_val->data.x_ptr.base_ptr = maybe_val->data.x_maybe;9924 out_val->data.x_ptr.base_ptr = maybe_val->data.x_maybe;
9988 out_val->data.x_ptr.index = SIZE_MAX;9925 out_val->data.x_ptr.index = SIZE_MAX;
9989 return result_type;9926 return result_type;
...@@ -10003,9 +9940,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC...@@ -10003,9 +9940,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
10003 if (value->value.special != ConstValSpecialRuntime) {9940 if (value->value.special != ConstValSpecialRuntime) {
10004 uint32_t result = bignum_ctz(&value->value.data.x_bignum,9941 uint32_t result = bignum_ctz(&value->value.data.x_bignum,
10005 value->value.type->data.integral.bit_count);9942 value->value.type->data.integral.bit_count);
10006 bool depends_on_compile_var = value->value.depends_on_compile_var;9943 ConstExprValue *out_val = ir_build_const_from(ira, &ctz_instruction->base);
10007 ConstExprValue *out_val = ir_build_const_from(ira, &ctz_instruction->base,
10008 depends_on_compile_var);
10009 bignum_init_unsigned(&out_val->data.x_bignum, result);9944 bignum_init_unsigned(&out_val->data.x_bignum, result);
10010 return value->value.type;9945 return value->value.type;
10011 }9946 }
...@@ -10027,9 +9962,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC...@@ -10027,9 +9962,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
10027 if (value->value.special != ConstValSpecialRuntime) {9962 if (value->value.special != ConstValSpecialRuntime) {
10028 uint32_t result = bignum_clz(&value->value.data.x_bignum,9963 uint32_t result = bignum_clz(&value->value.data.x_bignum,
10029 value->value.type->data.integral.bit_count);9964 value->value.type->data.integral.bit_count);
10030 bool depends_on_compile_var = value->value.depends_on_compile_var;9965 ConstExprValue *out_val = ir_build_const_from(ira, &clz_instruction->base);
10031 ConstExprValue *out_val = ir_build_const_from(ira, &clz_instruction->base,
10032 depends_on_compile_var);
10033 bignum_init_unsigned(&out_val->data.x_bignum, result);9966 bignum_init_unsigned(&out_val->data.x_bignum, result);
10034 return value->value.type;9967 return value->value.type;
10035 }9968 }
...@@ -10062,7 +9995,6 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_...@@ -10062,7 +9995,6 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_
10062 source_instr->scope, source_instr->source_node);9995 source_instr->scope, source_instr->source_node);
10063 const_instruction->base.value.type = value->value.type->data.enumeration.tag_type;9996 const_instruction->base.value.type = value->value.type->data.enumeration.tag_type;
10064 const_instruction->base.value.special = ConstValSpecialStatic;9997 const_instruction->base.value.special = ConstValSpecialStatic;
10065 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
10066 bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, val->data.x_enum.tag);9998 bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, val->data.x_enum.tag);
10067 return &const_instruction->base;9999 return &const_instruction->base;
10068 }10000 }
...@@ -10178,7 +10110,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10178,7 +10110,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1017810110
10179 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);10111 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
10180 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;10112 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
10181 bool depends_on_compile_var = target_value_ptr->value.depends_on_compile_var;
10182 ConstExprValue *pointee_val = nullptr;10113 ConstExprValue *pointee_val = nullptr;
10183 if (target_value_ptr->value.special != ConstValSpecialRuntime) {10114 if (target_value_ptr->value.special != ConstValSpecialRuntime) {
10184 pointee_val = const_ptr_pointee(&target_value_ptr->value);10115 pointee_val = const_ptr_pointee(&target_value_ptr->value);
...@@ -10205,8 +10136,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10205,8 +10136,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
10205 case TypeTableEntryIdNamespace:10136 case TypeTableEntryIdNamespace:
10206 case TypeTableEntryIdPureError:10137 case TypeTableEntryIdPureError:
10207 if (pointee_val) {10138 if (pointee_val) {
10208 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base,10139 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
10209 depends_on_compile_var);
10210 *out_val = *pointee_val;10140 *out_val = *pointee_val;
10211 out_val->type = target_type;10141 out_val->type = target_type;
10212 return target_type;10142 return target_type;
...@@ -10218,8 +10148,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10218,8 +10148,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
10218 {10148 {
10219 TypeTableEntry *tag_type = target_type->data.enumeration.tag_type;10149 TypeTableEntry *tag_type = target_type->data.enumeration.tag_type;
10220 if (pointee_val) {10150 if (pointee_val) {
10221 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base,10151 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
10222 depends_on_compile_var);
10223 bignum_init_unsigned(&out_val->data.x_bignum, pointee_val->data.x_enum.tag);10152 bignum_init_unsigned(&out_val->data.x_bignum, pointee_val->data.x_enum.tag);
10224 return tag_type;10153 return tag_type;
10225 }10154 }
...@@ -10285,8 +10214,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr...@@ -10285,8 +10214,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1028510214
10286 ConstExprValue *pointee_val = const_ptr_pointee(target_val_ptr);10215 ConstExprValue *pointee_val = const_ptr_pointee(target_val_ptr);
10287 if (pointee_val->type->id == TypeTableEntryIdEnum) {10216 if (pointee_val->type->id == TypeTableEntryIdEnum) {
10288 bool depends_on_compile_var = target_value_ptr->value.depends_on_compile_var;10217 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10289 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
10290 out_val->data.x_ptr.base_ptr = pointee_val->data.x_enum.payload;10218 out_val->data.x_ptr.base_ptr = pointee_val->data.x_enum.payload;
10291 out_val->data.x_ptr.index = SIZE_MAX;10219 out_val->data.x_ptr.index = SIZE_MAX;
10292 return get_pointer_to_type(ira->codegen, pointee_val->type, target_value_ptr->value.type->data.pointer.is_const);10220 return get_pointer_to_type(ira->codegen, pointee_val->type, target_value_ptr->value.type->data.pointer.is_const);
...@@ -10323,9 +10251,8 @@ static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrI...@@ -10323,9 +10251,8 @@ static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrI
10323 if (!val)10251 if (!val)
10324 return ira->codegen->builtin_types.entry_invalid;10252 return ira->codegen->builtin_types.entry_invalid;
1032510253
10326 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);10254 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10327 *out_val = *val;10255 *out_val = *val;
10328 out_val->depends_on_compile_var = true;
10329 return value->value.type;10256 return value->value.type;
10330 }10257 }
1033110258
...@@ -10338,7 +10265,6 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -10338,7 +10265,6 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
10338 Buf *import_target_str = ir_resolve_str(ira, name_value);10265 Buf *import_target_str = ir_resolve_str(ira, name_value);
10339 if (!import_target_str)10266 if (!import_target_str)
10340 return ira->codegen->builtin_types.entry_invalid;10267 return ira->codegen->builtin_types.entry_invalid;
10341 bool depends_on_compile_var = name_value->value.depends_on_compile_var;
1034210268
10343 AstNode *source_node = import_instruction->base.source_node;10269 AstNode *source_node = import_instruction->base.source_node;
10344 ImportTableEntry *import = source_node->owner;10270 ImportTableEntry *import = source_node->owner;
...@@ -10380,7 +10306,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -10380,7 +10306,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1038010306
10381 auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path);10307 auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path);
10382 if (import_entry) {10308 if (import_entry) {
10383 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var);10309 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);
10384 out_val->data.x_import = import_entry->value;10310 out_val->data.x_import = import_entry->value;
10385 return ira->codegen->builtin_types.entry_namespace;10311 return ira->codegen->builtin_types.entry_namespace;
10386 }10312 }
...@@ -10401,7 +10327,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -10401,7 +10327,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1040110327
10402 scan_decls(ira->codegen, target_import->decls_scope, target_import->root);10328 scan_decls(ira->codegen, target_import->decls_scope, target_import->root);
1040310329
10404 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var);10330 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);
10405 out_val->data.x_import = target_import;10331 out_val->data.x_import = target_import;
10406 return ira->codegen->builtin_types.entry_namespace;10332 return ira->codegen->builtin_types.entry_namespace;
1040710333
...@@ -10415,16 +10341,14 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,...@@ -10415,16 +10341,14 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
10415 if (canon_type->id == TypeTableEntryIdInvalid) {10341 if (canon_type->id == TypeTableEntryIdInvalid) {
10416 return ira->codegen->builtin_types.entry_invalid;10342 return ira->codegen->builtin_types.entry_invalid;
10417 } else if (canon_type->id == TypeTableEntryIdArray) {10343 } else if (canon_type->id == TypeTableEntryIdArray) {
10418 bool depends_on_compile_var = array_value->value.depends_on_compile_var;
10419 return ir_analyze_const_usize(ira, &array_len_instruction->base,10344 return ir_analyze_const_usize(ira, &array_len_instruction->base,
10420 canon_type->data.array.len, depends_on_compile_var);10345 canon_type->data.array.len);
10421 } else if (is_slice(canon_type)) {10346 } else if (is_slice(canon_type)) {
10422 if (array_value->value.special != ConstValSpecialRuntime) {10347 if (array_value->value.special != ConstValSpecialRuntime) {
10423 ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index];10348 ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index];
10424 if (len_val->special != ConstValSpecialRuntime) {10349 if (len_val->special != ConstValSpecialRuntime) {
10425 bool depends_on_compile_var = len_val->depends_on_compile_var;
10426 return ir_analyze_const_usize(ira, &array_len_instruction->base,10350 return ir_analyze_const_usize(ira, &array_len_instruction->base,
10427 len_val->data.x_bignum.data.x_uint, depends_on_compile_var);10351 len_val->data.x_bignum.data.x_uint);
10428 }10352 }
10429 }10353 }
10430 TypeStructField *field = &canon_type->data.structure.fields[slice_len_index];10354 TypeStructField *field = &canon_type->data.structure.fields[slice_len_index];
...@@ -10447,8 +10371,7 @@ static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionR...@@ -10447,8 +10371,7 @@ static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionR
10447}10371}
1044810372
10449static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,10373static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
10450 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,10374 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
10451 bool depends_on_compile_var)
10452{10375{
10453 if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {10376 if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {
10454 ir_add_error(ira, instruction,10377 ir_add_error(ira, instruction,
...@@ -10473,7 +10396,6 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -10473,7 +10396,6 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
10473 ConstExprValue const_val = {};10396 ConstExprValue const_val = {};
10474 const_val.special = ConstValSpecialStatic;10397 const_val.special = ConstValSpecialStatic;
10475 const_val.type = container_type;10398 const_val.type = container_type;
10476 const_val.depends_on_compile_var = depends_on_compile_var;
10477 const_val.data.x_struct.fields = allocate<ConstExprValue>(actual_field_count);10399 const_val.data.x_struct.fields = allocate<ConstExprValue>(actual_field_count);
10478 for (size_t i = 0; i < instr_field_count; i += 1) {10400 for (size_t i = 0; i < instr_field_count; i += 1) {
10479 IrInstructionContainerInitFieldsField *field = &fields[i];10401 IrInstructionContainerInitFieldsField *field = &fields[i];
...@@ -10516,7 +10438,6 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -10516,7 +10438,6 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
10516 return ira->codegen->builtin_types.entry_invalid;10438 return ira->codegen->builtin_types.entry_invalid;
1051710439
10518 const_val.data.x_struct.fields[field_index] = *field_val;10440 const_val.data.x_struct.fields[field_index] = *field_val;
10519 const_val.depends_on_compile_var = const_val.depends_on_compile_var || field_val->depends_on_compile_var;
10520 } else {10441 } else {
10521 first_non_const_instruction = casted_field_value;10442 first_non_const_instruction = casted_field_value;
10522 const_val.special = ConstValSpecialRuntime;10443 const_val.special = ConstValSpecialRuntime;
...@@ -10536,7 +10457,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -10536,7 +10457,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
10536 return ira->codegen->builtin_types.entry_invalid;10457 return ira->codegen->builtin_types.entry_invalid;
1053710458
10538 if (const_val.special == ConstValSpecialStatic) {10459 if (const_val.special == ConstValSpecialStatic) {
10539 ConstExprValue *out_val = ir_build_const_from(ira, instruction, const_val.depends_on_compile_var);10460 ConstExprValue *out_val = ir_build_const_from(ira, instruction);
10540 *out_val = const_val;10461 *out_val = const_val;
10541 return container_type;10462 return container_type;
10542 }10463 }
...@@ -10567,11 +10488,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10567,11 +10488,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10567 if (container_type->id == TypeTableEntryIdInvalid)10488 if (container_type->id == TypeTableEntryIdInvalid)
10568 return ira->codegen->builtin_types.entry_invalid;10489 return ira->codegen->builtin_types.entry_invalid;
1056910490
10570 bool depends_on_compile_var = container_type_value->value.depends_on_compile_var;
10571
10572 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {10491 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
10573 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,10492 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
10574 0, nullptr, depends_on_compile_var);10493 0, nullptr);
10575 } else if (is_slice(container_type)) {10494 } else if (is_slice(container_type)) {
10576 TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;10495 TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
10577 assert(pointer_type->id == TypeTableEntryIdPointer);10496 assert(pointer_type->id == TypeTableEntryIdPointer);
...@@ -10581,7 +10500,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10581,7 +10500,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10581 ConstExprValue const_val = {};10500 ConstExprValue const_val = {};
10582 const_val.special = ConstValSpecialStatic;10501 const_val.special = ConstValSpecialStatic;
10583 const_val.type = fixed_size_array_type;10502 const_val.type = fixed_size_array_type;
10584 const_val.depends_on_compile_var = depends_on_compile_var;
10585 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);10503 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);
10586 const_val.data.x_array.size = elem_count;10504 const_val.data.x_array.size = elem_count;
1058710505
...@@ -10609,7 +10527,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10609,7 +10527,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10609 return ira->codegen->builtin_types.entry_invalid;10527 return ira->codegen->builtin_types.entry_invalid;
1061010528
10611 const_val.data.x_array.elements[i] = *elem_val;10529 const_val.data.x_array.elements[i] = *elem_val;
10612 const_val.depends_on_compile_var = const_val.depends_on_compile_var || elem_val->depends_on_compile_var;
10613 } else {10530 } else {
10614 first_non_const_instruction = casted_arg;10531 first_non_const_instruction = casted_arg;
10615 const_val.special = ConstValSpecialRuntime;10532 const_val.special = ConstValSpecialRuntime;
...@@ -10618,7 +10535,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10618,7 +10535,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10618 }10535 }
1061910536
10620 if (const_val.special == ConstValSpecialStatic) {10537 if (const_val.special == ConstValSpecialStatic) {
10621 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, const_val.depends_on_compile_var);10538 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10622 *out_val = const_val;10539 *out_val = const_val;
10623 for (size_t i = 0; i < elem_count; i += 1) {10540 for (size_t i = 0; i < elem_count; i += 1) {
10624 ConstExprValue *elem_val = &out_val->data.x_array.elements[i];10541 ConstExprValue *elem_val = &out_val->data.x_array.elements[i];
...@@ -10681,8 +10598,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10681,8 +10598,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10681 ConstExprValue *init_val = ir_resolve_const(ira, casted_init_value, UndefOk);10598 ConstExprValue *init_val = ir_resolve_const(ira, casted_init_value, UndefOk);
10682 if (!init_val)10599 if (!init_val)
10683 return ira->codegen->builtin_types.entry_invalid;10600 return ira->codegen->builtin_types.entry_invalid;
10684 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,10601 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10685 casted_init_value->value.depends_on_compile_var);
10686 out_val->data.x_enum.tag = tag_uint;10602 out_val->data.x_enum.tag = tag_uint;
10687 out_val->data.x_enum.payload = init_val;10603 out_val->data.x_enum.payload = init_val;
10688 return enum_type;10604 return enum_type;
...@@ -10705,37 +10621,34 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i...@@ -10705,37 +10621,34 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i
10705 if (type_is_invalid(container_type))10621 if (type_is_invalid(container_type))
10706 return ira->codegen->builtin_types.entry_invalid;10622 return ira->codegen->builtin_types.entry_invalid;
1070710623
10708 bool depends_on_compile_var = container_type_value->value.depends_on_compile_var;
10709
10710 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,10624 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
10711 instruction->field_count, instruction->fields, depends_on_compile_var);10625 instruction->field_count, instruction->fields);
10712}10626}
1071310627
10714static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,10628static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
10715 IrInstruction *target_type_value, bool is_max)10629 IrInstruction *target_type_value, bool is_max)
10716{10630{
10717 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);10631 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
10718 bool depends_on_compile_var = target_type_value->value.depends_on_compile_var;
10719 TypeTableEntry *canon_type = get_underlying_type(target_type);10632 TypeTableEntry *canon_type = get_underlying_type(target_type);
10720 switch (canon_type->id) {10633 switch (canon_type->id) {
10721 case TypeTableEntryIdInvalid:10634 case TypeTableEntryIdInvalid:
10722 return ira->codegen->builtin_types.entry_invalid;10635 return ira->codegen->builtin_types.entry_invalid;
10723 case TypeTableEntryIdInt:10636 case TypeTableEntryIdInt:
10724 {10637 {
10725 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction, depends_on_compile_var);10638 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
10726 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);10639 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
10727 return ira->codegen->builtin_types.entry_num_lit_int;10640 return ira->codegen->builtin_types.entry_num_lit_int;
10728 }10641 }
10729 case TypeTableEntryIdFloat:10642 case TypeTableEntryIdFloat:
10730 {10643 {
10731 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction, depends_on_compile_var);10644 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
10732 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);10645 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
10733 return ira->codegen->builtin_types.entry_num_lit_float;10646 return ira->codegen->builtin_types.entry_num_lit_float;
10734 }10647 }
10735 case TypeTableEntryIdBool:10648 case TypeTableEntryIdBool:
10736 case TypeTableEntryIdVoid:10649 case TypeTableEntryIdVoid:
10737 {10650 {
10738 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction, depends_on_compile_var);10651 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
10739 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);10652 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
10740 return target_type;10653 return target_type;
10741 }10654 }
...@@ -10815,7 +10728,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst...@@ -10815,7 +10728,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
1081510728
10816 ir_add_error(ira, &instruction->base, buf_sprintf("found compile log statement"));10729 ir_add_error(ira, &instruction->base, buf_sprintf("found compile log statement"));
1081710730
10818 ir_build_const_from(ira, &instruction->base, false);10731 ir_build_const_from(ira, &instruction->base);
10819 return ira->codegen->builtin_types.entry_void;10732 return ira->codegen->builtin_types.entry_void;
10820}10733}
1082110734
...@@ -10835,8 +10748,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc...@@ -10835,8 +10748,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
10835 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name);10748 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name);
10836 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);10749 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
10837 }10750 }
10838 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,10751 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10839 casted_value->value.depends_on_compile_var);
10840 *out_val = *err->cached_error_name_val;10752 *out_val = *err->cached_error_name_val;
10841 return str_type;10753 return str_type;
10842 }10754 }
...@@ -10855,8 +10767,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru...@@ -10855,8 +10767,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru
10855 if (!type_entry->cached_const_name_val) {10767 if (!type_entry->cached_const_name_val) {
10856 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, &type_entry->name);10768 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, &type_entry->name);
10857 }10769 }
10858 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,10770 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10859 type_value->value.depends_on_compile_var);
10860 *out_val = *type_entry->cached_const_name_val;10771 *out_val = *type_entry->cached_const_name_val;
10861 return out_val->type;10772 return out_val->type;
10862}10773}
...@@ -10905,10 +10816,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -10905,10 +10816,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
10905 ast_render_decls(stderr, 4, child_import);10816 ast_render_decls(stderr, 4, child_import);
10906 }10817 }
1090710818
10908 // TODO to get fewer false negatives on this, we would need to track this value in10819 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
10909 // the ir executable
10910 bool depends_on_compile_var = true;
10911 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
10912 out_val->data.x_import = child_import;10820 out_val->data.x_import = child_import;
10913 return ira->codegen->builtin_types.entry_namespace;10821 return ira->codegen->builtin_types.entry_namespace;
10914}10822}
...@@ -10928,7 +10836,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru...@@ -10928,7 +10836,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
1092810836
10929 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));10837 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
1093010838
10931 ir_build_const_from(ira, &instruction->base, false);10839 ir_build_const_from(ira, &instruction->base);
10932 return ira->codegen->builtin_types.entry_void;10840 return ira->codegen->builtin_types.entry_void;
10933}10841}
1093410842
...@@ -10955,7 +10863,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc...@@ -10955,7 +10863,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
1095510863
10956 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), buf_ptr(define_value));10864 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), buf_ptr(define_value));
1095710865
10958 ir_build_const_from(ira, &instruction->base, false);10866 ir_build_const_from(ira, &instruction->base);
10959 return ira->codegen->builtin_types.entry_void;10867 return ira->codegen->builtin_types.entry_void;
10960}10868}
1096110869
...@@ -10974,7 +10882,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct...@@ -10974,7 +10882,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
1097410882
10975 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));10883 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
1097610884
10977 ir_build_const_from(ira, &instruction->base, false);10885 ir_build_const_from(ira, &instruction->base);
10978 return ira->codegen->builtin_types.entry_void;10886 return ira->codegen->builtin_types.entry_void;
10979}10887}
1098010888
...@@ -11011,8 +10919,7 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr...@@ -11011,8 +10919,7 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
11011 // TODO add dependency on the file we embedded so that we know if it changes10919 // TODO add dependency on the file we embedded so that we know if it changes
11012 // we'll have to invalidate the cache10920 // we'll have to invalidate the cache
1101310921
11014 bool depends_on_compile_var = true;10922 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11015 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11016 init_const_str_lit(ira->codegen, out_val, &file_contents);10923 init_const_str_lit(ira->codegen, out_val, &file_contents);
1101710924
11018 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(&file_contents));10925 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(&file_contents));
...@@ -11161,9 +11068,7 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru...@@ -11161,9 +11068,7 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
11161 return ira->codegen->builtin_types.entry_invalid;11068 return ira->codegen->builtin_types.entry_invalid;
11162 }11069 }
1116311070
11164 bool depends_on_compile_var = casted_op1->value.depends_on_compile_var ||11071 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11165 casted_op2->value.depends_on_compile_var;
11166 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11167 bignum_div(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum);11072 bignum_div(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum);
11168 return result_type;11073 return result_type;
11169 }11074 }
...@@ -11215,8 +11120,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc...@@ -11215,8 +11120,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
11215 }11120 }
1121611121
11217 if (target->value.special == ConstValSpecialStatic) {11122 if (target->value.special == ConstValSpecialStatic) {
11218 bool depends_on_compile_var = dest_type_value->value.depends_on_compile_var || target->value.depends_on_compile_var;11123 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11219 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11220 bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum);11124 bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum);
11221 bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count);11125 bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count);
11222 return dest_type;11126 return dest_type;
...@@ -11237,10 +11141,7 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc...@@ -11237,10 +11141,7 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
11237 if (!ir_resolve_usize(ira, bit_count_value, &bit_count))11141 if (!ir_resolve_usize(ira, bit_count_value, &bit_count))
11238 return ira->codegen->builtin_types.entry_invalid;11142 return ira->codegen->builtin_types.entry_invalid;
1123911143
11240 bool depends_on_compile_var = is_signed_value->value.depends_on_compile_var ||11144 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11241 bit_count_value->value.depends_on_compile_var;
11242
11243 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11244 out_val->data.x_type = get_int_type(ira->codegen, is_signed, bit_count);11145 out_val->data.x_type = get_int_type(ira->codegen, is_signed, bit_count);
11245 return ira->codegen->builtin_types.entry_type;11146 return ira->codegen->builtin_types.entry_type;
11246}11147}
...@@ -11257,8 +11158,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc...@@ -11257,8 +11158,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
11257 return ira->codegen->builtin_types.entry_invalid;11158 return ira->codegen->builtin_types.entry_invalid;
1125811159
11259 if (casted_value->value.special != ConstValSpecialRuntime) {11160 if (casted_value->value.special != ConstValSpecialRuntime) {
11260 bool depends_on_compile_var = casted_value->value.depends_on_compile_var;11161 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11261 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11262 out_val->data.x_bool = !casted_value->value.data.x_bool;11162 out_val->data.x_bool = !casted_value->value.data.x_bool;
11263 return bool_type;11163 return bool_type;
11264 }11164 }
...@@ -11357,7 +11257,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi...@@ -11357,7 +11257,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
11357 dest_elements[i] = *byte_val;11257 dest_elements[i] = *byte_val;
11358 }11258 }
1135911259
11360 ir_build_const_from(ira, &instruction->base, false);11260 ir_build_const_from(ira, &instruction->base);
11361 return ira->codegen->builtin_types.entry_void;11261 return ira->codegen->builtin_types.entry_void;
11362 }11262 }
1136311263
...@@ -11454,7 +11354,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -11454,7 +11354,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
11454 dest_elements[dest_start + i] = src_elements[src_start + i];11354 dest_elements[dest_start + i] = src_elements[src_start + i];
11455 }11355 }
1145611356
11457 ir_build_const_from(ira, &instruction->base, false);11357 ir_build_const_from(ira, &instruction->base);
11458 return ira->codegen->builtin_types.entry_void;11358 return ira->codegen->builtin_types.entry_void;
11459 }11359 }
1146011360
...@@ -11515,11 +11415,6 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -11515,11 +11415,6 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
11515 casted_start->value.special == ConstValSpecialStatic &&11415 casted_start->value.special == ConstValSpecialStatic &&
11516 (!end || end->value.special == ConstValSpecialStatic))11416 (!end || end->value.special == ConstValSpecialStatic))
11517 {11417 {
11518 bool depends_on_compile_var =
11519 ptr->value.depends_on_compile_var ||
11520 casted_start->value.depends_on_compile_var ||
11521 (end ? end->value.depends_on_compile_var : false);
11522
11523 ConstExprValue *base_ptr;11418 ConstExprValue *base_ptr;
11524 size_t abs_offset;11419 size_t abs_offset;
11525 size_t rel_end;11420 size_t rel_end;
...@@ -11571,7 +11466,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -11571,7 +11466,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
11571 return ira->codegen->builtin_types.entry_invalid;11466 return ira->codegen->builtin_types.entry_invalid;
11572 }11467 }
1157311468
11574 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);11469 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11575 out_val->data.x_struct.fields = allocate<ConstExprValue>(2);11470 out_val->data.x_struct.fields = allocate<ConstExprValue>(2);
1157611471
11577 ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index];11472 ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index];
...@@ -11612,8 +11507,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -11612,8 +11507,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
11612 return ira->codegen->builtin_types.entry_invalid;11507 return ira->codegen->builtin_types.entry_invalid;
11613 }11508 }
1161411509
11615 bool depends_on_compile_var = container->value.depends_on_compile_var;11510 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11616 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11617 bignum_init_unsigned(&out_val->data.x_bignum, result);11511 bignum_init_unsigned(&out_val->data.x_bignum, result);
11618 return ira->codegen->builtin_types.entry_num_lit_int;11512 return ira->codegen->builtin_types.entry_num_lit_int;
11619}11513}
...@@ -11653,8 +11547,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct...@@ -11653,8 +11547,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
11653 return ira->codegen->builtin_types.entry_invalid;11547 return ira->codegen->builtin_types.entry_invalid;
11654 } else {11548 } else {
11655 uint64_t align_in_bytes = LLVMABISizeOfType(ira->codegen->target_data_ref, type_entry->type_ref);11549 uint64_t align_in_bytes = LLVMABISizeOfType(ira->codegen->target_data_ref, type_entry->type_ref);
11656 bool depends_on_compile_var = type_value->value.depends_on_compile_var;11550 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11657 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11658 bignum_init_unsigned(&out_val->data.x_bignum, align_in_bytes);11551 bignum_init_unsigned(&out_val->data.x_bignum, align_in_bytes);
11659 return ira->codegen->builtin_types.entry_num_lit_int;11552 return ira->codegen->builtin_types.entry_num_lit_int;
11660 }11553 }
...@@ -11705,10 +11598,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -11705,10 +11598,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
11705 casted_op2->value.special == ConstValSpecialStatic &&11598 casted_op2->value.special == ConstValSpecialStatic &&
11706 casted_result_ptr->value.special == ConstValSpecialStatic)11599 casted_result_ptr->value.special == ConstValSpecialStatic)
11707 {11600 {
11708 bool depends_on_compile_var = type_value->value.depends_on_compile_var ||11601 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11709 casted_op1->value.depends_on_compile_var || casted_op2->value.depends_on_compile_var ||
11710 casted_result_ptr->value.depends_on_compile_var;
11711 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11712 BigNum *op1_bignum = &casted_op1->value.data.x_bignum;11602 BigNum *op1_bignum = &casted_op1->value.data.x_bignum;
11713 BigNum *op2_bignum = &casted_op2->value.data.x_bignum;11603 BigNum *op2_bignum = &casted_op2->value.data.x_bignum;
11714 ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->value);11604 ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->value);
...@@ -11759,8 +11649,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -11759,8 +11649,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
11759 return ira->codegen->builtin_types.entry_invalid;11649 return ira->codegen->builtin_types.entry_invalid;
1176011650
11761 if (err_union_val->special != ConstValSpecialRuntime) {11651 if (err_union_val->special != ConstValSpecialRuntime) {
11762 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,11652 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11763 err_union_val->depends_on_compile_var);
11764 out_val->data.x_bool = (err_union_val->data.x_err_union.err != nullptr);11653 out_val->data.x_bool = (err_union_val->data.x_err_union.err != nullptr);
11765 return ira->codegen->builtin_types.entry_bool;11654 return ira->codegen->builtin_types.entry_bool;
11766 }11655 }
...@@ -11769,11 +11658,11 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -11769,11 +11658,11 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
11769 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);11658 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
11770 return ira->codegen->builtin_types.entry_bool;11659 return ira->codegen->builtin_types.entry_bool;
11771 } else if (canon_type->id == TypeTableEntryIdPureError) {11660 } else if (canon_type->id == TypeTableEntryIdPureError) {
11772 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);11661 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11773 out_val->data.x_bool = true;11662 out_val->data.x_bool = true;
11774 return ira->codegen->builtin_types.entry_bool;11663 return ira->codegen->builtin_types.entry_bool;
11775 } else {11664 } else {
11776 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);11665 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11777 out_val->data.x_bool = false;11666 out_val->data.x_bool = false;
11778 return ira->codegen->builtin_types.entry_bool;11667 return ira->codegen->builtin_types.entry_bool;
11779 }11668 }
...@@ -11805,8 +11694,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -11805,8 +11694,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
11805 ErrorTableEntry *err = err_union_val->data.x_err_union.err;11694 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
11806 assert(err);11695 assert(err);
1180711696
11808 bool depends_on_compile_var = ptr_val->depends_on_compile_var || err_union_val->depends_on_compile_var;11697 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11809 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11810 out_val->data.x_pure_err = err;11698 out_val->data.x_pure_err = err;
11811 return ira->codegen->builtin_types.entry_pure_error;11699 return ira->codegen->builtin_types.entry_pure_error;
11812 }11700 }
...@@ -11855,8 +11743,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -11855,8 +11743,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
11855 return ira->codegen->builtin_types.entry_invalid;11743 return ira->codegen->builtin_types.entry_invalid;
11856 }11744 }
1185711745
11858 bool depends_on_compile_var = ptr_val->depends_on_compile_var || err_union_val->depends_on_compile_var;11746 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11859 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
11860 out_val->data.x_ptr.base_ptr = err_union_val->data.x_err_union.payload;11747 out_val->data.x_ptr.base_ptr = err_union_val->data.x_err_union.payload;
11861 out_val->data.x_ptr.index = SIZE_MAX;11748 out_val->data.x_ptr.index = SIZE_MAX;
11862 return result_type;11749 return result_type;
...@@ -11881,8 +11768,6 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -11881,8 +11768,6 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
11881 FnTypeId fn_type_id = {0};11768 FnTypeId fn_type_id = {0};
11882 init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length);11769 init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length);
1188311770
11884 bool depends_on_compile_var = false;
11885
11886 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {11771 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {
11887 AstNode *param_node = proto_node->data.fn_proto.params.at(fn_type_id.next_param_index);11772 AstNode *param_node = proto_node->data.fn_proto.params.at(fn_type_id.next_param_index);
11888 assert(param_node->type == NodeTypeParamDecl);11773 assert(param_node->type == NodeTypeParamDecl);
...@@ -11894,17 +11779,14 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -11894,17 +11779,14 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
11894 param_info->type = ir_resolve_type(ira, param_type_value);11779 param_info->type = ir_resolve_type(ira, param_type_value);
11895 if (param_info->type->id == TypeTableEntryIdInvalid)11780 if (param_info->type->id == TypeTableEntryIdInvalid)
11896 return ira->codegen->builtin_types.entry_invalid;11781 return ira->codegen->builtin_types.entry_invalid;
11897
11898 depends_on_compile_var = depends_on_compile_var || param_type_value->value.depends_on_compile_var;
11899 }11782 }
1190011783
11901 IrInstruction *return_type_value = instruction->return_type->other;11784 IrInstruction *return_type_value = instruction->return_type->other;
11902 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);11785 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
11903 if (fn_type_id.return_type->id == TypeTableEntryIdInvalid)11786 if (fn_type_id.return_type->id == TypeTableEntryIdInvalid)
11904 return ira->codegen->builtin_types.entry_invalid;11787 return ira->codegen->builtin_types.entry_invalid;
11905 depends_on_compile_var = depends_on_compile_var || return_type_value->value.depends_on_compile_var;
1190611788
11907 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);11789 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11908 out_val->data.x_type = get_fn_type(ira->codegen, &fn_type_id);11790 out_val->data.x_type = get_fn_type(ira->codegen, &fn_type_id);
11909 return ira->codegen->builtin_types.entry_type;11791 return ira->codegen->builtin_types.entry_type;
11910}11792}
...@@ -11914,7 +11796,7 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn...@@ -11914,7 +11796,7 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn
11914 if (value->value.type->id == TypeTableEntryIdInvalid)11796 if (value->value.type->id == TypeTableEntryIdInvalid)
11915 return ira->codegen->builtin_types.entry_invalid;11797 return ira->codegen->builtin_types.entry_invalid;
1191611798
11917 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);11799 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11918 out_val->data.x_bool = instr_is_comptime(value);11800 out_val->data.x_bool = instr_is_comptime(value);
11919 return ira->codegen->builtin_types.entry_bool;11801 return ira->codegen->builtin_types.entry_bool;
11920}11802}
...@@ -11978,7 +11860,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -11978,7 +11860,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
11978 } else {11860 } else {
11979 // TODO check prongs of types other than enumtag11861 // TODO check prongs of types other than enumtag
11980 }11862 }
11981 ir_build_const_from(ira, &instruction->base, false);11863 ir_build_const_from(ira, &instruction->base);
11982 return ira->codegen->builtin_types.entry_void;11864 return ira->codegen->builtin_types.entry_void;
11983}11865}
1198411866
...@@ -11988,7 +11870,7 @@ static TypeTableEntry *ir_analyze_instruction_test_type(IrAnalyze *ira, IrInstru...@@ -11988,7 +11870,7 @@ static TypeTableEntry *ir_analyze_instruction_test_type(IrAnalyze *ira, IrInstru
11988 if (type_entry->id == TypeTableEntryIdInvalid)11870 if (type_entry->id == TypeTableEntryIdInvalid)
11989 return ira->codegen->builtin_types.entry_invalid;11871 return ira->codegen->builtin_types.entry_invalid;
1199011872
11991 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, type_value->value.depends_on_compile_var);11873 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11992 out_val->data.x_bool = (type_entry->id == instruction->type_id);11874 out_val->data.x_bool = (type_entry->id == instruction->type_id);
11993 return ira->codegen->builtin_types.entry_bool;11875 return ira->codegen->builtin_types.entry_bool;
11994}11876}
...@@ -12012,10 +11894,7 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,...@@ -12012,10 +11894,7 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
12012 zig_panic("TODO refactor implicit cast tester to return bool without reporting errors");11894 zig_panic("TODO refactor implicit cast tester to return bool without reporting errors");
12013 }11895 }
1201411896
12015 // TODO in order to known depends_on_compile_var we have to known if the type of the target11897 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
12016 // depends on a compile var
12017 bool depends_on_compile_var = true;
12018 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
12019 out_val->data.x_bool = (result == ImplicitCastMatchResultYes);11898 out_val->data.x_bool = (result == ImplicitCastMatchResultYes);
12020 return ira->codegen->builtin_types.entry_bool;11899 return ira->codegen->builtin_types.entry_bool;
12021}11900}