| ... | ... | @@ -3379,10 +3379,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value) { |
| 3379 | 3379 | } |
| 3380 | 3380 | |
| 3381 | 3381 | IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 3382 | | TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota) |
| 3382 | TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, |
| 3383 | FnTableEntry *fn_entry) |
| 3383 | 3384 | { |
| 3384 | 3385 | IrExecutable ir_executable = {0}; |
| 3385 | 3386 | ir_executable.is_inline = true; |
| 3387 | ir_executable.fn_entry = fn_entry; |
| 3386 | 3388 | ir_gen(codegen, node, scope, &ir_executable); |
| 3387 | 3389 | |
| 3388 | 3390 | if (ir_executable.invalid) |
| ... | ... | @@ -3397,6 +3399,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 3397 | 3399 | } |
| 3398 | 3400 | IrExecutable analyzed_executable = {0}; |
| 3399 | 3401 | analyzed_executable.is_inline = true; |
| 3402 | analyzed_executable.fn_entry = fn_entry; |
| 3400 | 3403 | analyzed_executable.backward_branch_count = backward_branch_count; |
| 3401 | 3404 | analyzed_executable.backward_branch_quota = backward_branch_quota; |
| 3402 | 3405 | TypeTableEntry *result_type = ir_analyze(codegen, &ir_executable, &analyzed_executable, expected_type, node); |
| ... | ... | @@ -4501,7 +4504,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 4501 | 4504 | // Analyze the fn body block like any other constant expression. |
| 4502 | 4505 | AstNode *body_node = fn_entry->fn_def_node->data.fn_def.body; |
| 4503 | 4506 | IrInstruction *result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, |
| 4504 | | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota); |
| 4507 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry); |
| 4505 | 4508 | if (result->type_entry->id == TypeTableEntryIdInvalid) |
| 4506 | 4509 | return ira->codegen->builtin_types.entry_invalid; |
| 4507 | 4510 | |
| ... | ... | @@ -4926,7 +4929,16 @@ static TypeTableEntry *ir_analyze_unwrap_maybe(IrAnalyze *ira, IrInstructionUnOp |
| 4926 | 4929 | return type_entry; |
| 4927 | 4930 | } else if (type_entry->id == TypeTableEntryIdMaybe) { |
| 4928 | 4931 | if (value->static_value.special != ConstValSpecialRuntime) { |
| 4929 | | zig_panic("TODO compile time eval unwrap maybe"); |
| 4932 | bool depends_on_compile_var = value->static_value.depends_on_compile_var; |
| 4933 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var); |
| 4934 | ConstExprValue *child_val = value->static_value.data.x_maybe; |
| 4935 | if (!child_val) { |
| 4936 | ir_add_error(ira, &un_op_instruction->base, |
| 4937 | buf_sprintf("unable to unwrap null")); |
| 4938 | return ira->codegen->builtin_types.entry_invalid; |
| 4939 | } |
| 4940 | *out_val = *child_val; |
| 4941 | return type_entry->data.maybe.child_type; |
| 4930 | 4942 | } |
| 4931 | 4943 | ir_build_un_op_from(&ira->new_irb, &un_op_instruction->base, IrUnOpUnwrapMaybe, value); |
| 4932 | 4944 | return type_entry->data.maybe.child_type; |
| ... | ... | @@ -6102,10 +6114,14 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 6102 | 6114 | assert(value->static_value.data.x_ptr.index == SIZE_MAX); |
| 6103 | 6115 | |
| 6104 | 6116 | if (maybe_val->special != ConstValSpecialRuntime) { |
| 6117 | if (!maybe_val->data.x_maybe) { |
| 6118 | ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null")); |
| 6119 | return ira->codegen->builtin_types.entry_invalid; |
| 6120 | } |
| 6105 | 6121 | bool depends_on_compile_var = maybe_val->depends_on_compile_var; |
| 6106 | 6122 | ConstExprValue *out_val = ir_build_const_from(ira, &unwrap_maybe_instruction->base, |
| 6107 | 6123 | depends_on_compile_var); |
| 6108 | | out_val->data.x_ptr.base_ptr = maybe_val; |
| 6124 | out_val->data.x_ptr.base_ptr = maybe_val->data.x_maybe; |
| 6109 | 6125 | out_val->data.x_ptr.index = SIZE_MAX; |
| 6110 | 6126 | return result_type; |
| 6111 | 6127 | } |