authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-03 14:06:37-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-03 14:06:37-05:00
logef5e7bb4693ed7e1582fb0b68cab01e00638d615
treea8f7b989773c54785096bc93eb1b054477948c9a
parentabf5ae6897bb23e49e4232ab8be7ed61ea9520b6

*WIP* error sets - an inferred error set can end up being the global one


6 files changed, 346 insertions(+), 311 deletions(-)

TODO-2
...@@ -26,6 +26,4 @@ comptime test for err...@@ -26,6 +26,4 @@ comptime test for err
2626
27undefined in infer error 27undefined in infer error
2828
29change readlink back to inferred error
30
31syntax - ?a!b should be ?(a!b) but it's (?a)!b29syntax - ?a!b should be ?(a!b) but it's (?a)!b
src/analyze.cpp+15-178
...@@ -3372,180 +3372,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so...@@ -3372,180 +3372,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so
3372 g->tld_ref_source_node_stack.pop();3372 g->tld_ref_source_node_stack.pop();
3373}3373}
33743374
3375ConstCastOnly types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type) {
3376 ConstCastOnly result = {};
3377 result.id = ConstCastResultIdOk;
3378
3379 if (expected_type == actual_type)
3380 return result;
3381
3382 // pointer const
3383 if (expected_type->id == TypeTableEntryIdPointer &&
3384 actual_type->id == TypeTableEntryIdPointer &&
3385 (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const) &&
3386 (!actual_type->data.pointer.is_volatile || expected_type->data.pointer.is_volatile) &&
3387 actual_type->data.pointer.bit_offset == expected_type->data.pointer.bit_offset &&
3388 actual_type->data.pointer.unaligned_bit_count == expected_type->data.pointer.unaligned_bit_count &&
3389 actual_type->data.pointer.alignment >= expected_type->data.pointer.alignment)
3390 {
3391 ConstCastOnly child = types_match_const_cast_only(g, expected_type->data.pointer.child_type, actual_type->data.pointer.child_type);
3392 if (child.id != ConstCastResultIdOk) {
3393 result.id = ConstCastResultIdPointerChild;
3394 result.data.pointer_child = allocate_nonzero<ConstCastOnly>(1);
3395 *result.data.pointer_child = child;
3396 }
3397 return result;
3398 }
3399
3400 // slice const
3401 if (expected_type->id == TypeTableEntryIdStruct && actual_type->id == TypeTableEntryIdStruct &&
3402 expected_type->data.structure.is_slice && actual_type->data.structure.is_slice)
3403 {
3404 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
3405 TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
3406 if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) &&
3407 (!actual_ptr_type->data.pointer.is_volatile || expected_ptr_type->data.pointer.is_volatile) &&
3408 actual_ptr_type->data.pointer.bit_offset == expected_ptr_type->data.pointer.bit_offset &&
3409 actual_ptr_type->data.pointer.unaligned_bit_count == expected_ptr_type->data.pointer.unaligned_bit_count &&
3410 actual_ptr_type->data.pointer.alignment >= expected_ptr_type->data.pointer.alignment)
3411 {
3412 ConstCastOnly child = types_match_const_cast_only(g, expected_ptr_type->data.pointer.child_type,
3413 actual_ptr_type->data.pointer.child_type);
3414 if (child.id != ConstCastResultIdOk) {
3415 result.id = ConstCastResultIdSliceChild;
3416 result.data.slice_child = allocate_nonzero<ConstCastOnly>(1);
3417 *result.data.slice_child = child;
3418 }
3419 return result;
3420 }
3421 }
3422
3423 // maybe
3424 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {
3425 ConstCastOnly child = types_match_const_cast_only(g, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type);
3426 if (child.id != ConstCastResultIdOk) {
3427 result.id = ConstCastResultIdNullableChild;
3428 result.data.nullable_child = allocate_nonzero<ConstCastOnly>(1);
3429 *result.data.nullable_child = child;
3430 }
3431 return result;
3432 }
3433
3434 // error union
3435 if (expected_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {
3436 ConstCastOnly payload_child = types_match_const_cast_only(g, expected_type->data.error_union.payload_type, actual_type->data.error_union.payload_type);
3437 if (payload_child.id != ConstCastResultIdOk) {
3438 result.id = ConstCastResultIdErrorUnionPayload;
3439 result.data.error_union_payload = allocate_nonzero<ConstCastOnly>(1);
3440 *result.data.error_union_payload = payload_child;
3441 return result;
3442 }
3443 ConstCastOnly error_set_child = types_match_const_cast_only(g, expected_type->data.error_union.err_set_type, actual_type->data.error_union.err_set_type);
3444 if (error_set_child.id != ConstCastResultIdOk) {
3445 result.id = ConstCastResultIdErrorUnionErrorSet;
3446 result.data.error_union_error_set = allocate_nonzero<ConstCastOnly>(1);
3447 *result.data.error_union_error_set = error_set_child;
3448 return result;
3449 }
3450 return result;
3451 }
3452
3453 // error set
3454 if (expected_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {
3455 TypeTableEntry *contained_set = actual_type;
3456 TypeTableEntry *container_set = expected_type;
3457
3458 if (container_set == g->builtin_types.entry_global_error_set || container_set->data.error_set.infer_fn != nullptr) {
3459 return result;
3460 }
3461
3462 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(g->errors_by_index.length);
3463 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
3464 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
3465 errors[error_entry->value] = error_entry;
3466 }
3467 for (uint32_t i = 0; i < contained_set->data.error_set.err_count; i += 1) {
3468 ErrorTableEntry *contained_error_entry = contained_set->data.error_set.errors[i];
3469 ErrorTableEntry *error_entry = errors[contained_error_entry->value];
3470 if (error_entry == nullptr) {
3471 if (result.id == ConstCastResultIdOk) {
3472 result.id = ConstCastResultIdErrSet;
3473 }
3474 result.data.error_set.missing_errors.append(contained_error_entry);
3475 }
3476 }
3477 free(errors);
3478 return result;
3479 }
3480
3481 // fn
3482 if (expected_type->id == TypeTableEntryIdFn &&
3483 actual_type->id == TypeTableEntryIdFn)
3484 {
3485 if (expected_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
3486 result.id = ConstCastResultIdFnAlign;
3487 return result;
3488 }
3489 if (expected_type->data.fn.fn_type_id.cc != actual_type->data.fn.fn_type_id.cc) {
3490 result.id = ConstCastResultIdFnCC;
3491 return result;
3492 }
3493 if (expected_type->data.fn.fn_type_id.is_var_args != actual_type->data.fn.fn_type_id.is_var_args) {
3494 result.id = ConstCastResultIdFnVarArgs;
3495 return result;
3496 }
3497 if (expected_type->data.fn.is_generic != actual_type->data.fn.is_generic) {
3498 result.id = ConstCastResultIdFnIsGeneric;
3499 return result;
3500 }
3501 if (!expected_type->data.fn.is_generic &&
3502 actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable)
3503 {
3504 ConstCastOnly child = types_match_const_cast_only(g, expected_type->data.fn.fn_type_id.return_type, actual_type->data.fn.fn_type_id.return_type);
3505 if (child.id != ConstCastResultIdOk) {
3506 result.id = ConstCastResultIdFnReturnType;
3507 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);
3508 *result.data.return_type = child;
3509 }
3510 return result;
3511 }
3512 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
3513 result.id = ConstCastResultIdFnArgCount;
3514 return result;
3515 }
3516 if (expected_type->data.fn.fn_type_id.next_param_index != actual_type->data.fn.fn_type_id.next_param_index) {
3517 result.id = ConstCastResultIdFnGenericArgCount;
3518 return result;
3519 }
3520 assert(expected_type->data.fn.is_generic ||
3521 expected_type->data.fn.fn_type_id.next_param_index == expected_type->data.fn.fn_type_id.param_count);
3522 for (size_t i = 0; i < expected_type->data.fn.fn_type_id.next_param_index; i += 1) {
3523 // note it's reversed for parameters
3524 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
3525 FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i];
3526
3527 ConstCastOnly arg_child = types_match_const_cast_only(g, actual_param_info->type, expected_param_info->type);
3528 if (arg_child.id != ConstCastResultIdOk) {
3529 result.id = ConstCastResultIdFnArg;
3530 result.data.fn_arg.arg_index = i;
3531 result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1);
3532 *result.data.fn_arg.child = arg_child;
3533 return result;
3534 }
3535
3536 if (expected_param_info->is_noalias != actual_param_info->is_noalias) {
3537 result.id = ConstCastResultIdFnArgNoAlias;
3538 result.data.arg_no_alias.arg_index = i;
3539 return result;
3540 }
3541 }
3542 return result;
3543 }
3544
3545 result.id = ConstCastResultIdType;
3546 return result;
3547}
3548
3549Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {3375Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
3550 // we must resolve all the use decls3376 // we must resolve all the use decls
3551 ImportTableEntry *import = get_scope_import(scope);3377 ImportTableEntry *import = get_scope_import(scope);
...@@ -3906,10 +3732,16 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ...@@ -3906,10 +3732,16 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
3906 }3732 }
39073733
3908 return_err_set_type->data.error_set.infer_fn = nullptr;3734 return_err_set_type->data.error_set.infer_fn = nullptr;
3909 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;3735 if (type_is_global_error_set(inferred_err_set_type)) {
3910 return_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);3736 return_err_set_type->data.error_set.err_count = UINT32_MAX;
3911 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {3737 } else {
3912 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];3738 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
3739 if (inferred_err_set_type->data.error_set.err_count > 0) {
3740 return_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
3741 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
3742 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
3743 }
3744 }
3913 }3745 }
3914 }3746 }
3915 }3747 }
...@@ -5833,3 +5665,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {...@@ -5833,3 +5665,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
5833 return var_value;5665 return var_value;
5834}5666}
58355667
5668bool type_is_global_error_set(TypeTableEntry *err_set_type) {
5669 assert(err_set_type->id == TypeTableEntryIdErrorSet);
5670 assert(err_set_type->data.error_set.infer_fn == nullptr);
5671 return err_set_type->data.error_set.err_count == UINT32_MAX;
5672}
src/analyze.hpp+1-52
...@@ -56,6 +56,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt...@@ -56,6 +56,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
56TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);56TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
57bool type_is_complete(TypeTableEntry *type_entry);57bool type_is_complete(TypeTableEntry *type_entry);
58bool type_is_invalid(TypeTableEntry *type_entry);58bool type_is_invalid(TypeTableEntry *type_entry);
59bool type_is_global_error_set(TypeTableEntry *err_set_type);
59bool type_has_zero_bits_known(TypeTableEntry *type_entry);60bool type_has_zero_bits_known(TypeTableEntry *type_entry);
60void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);61void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
61ScopeDecls *get_container_scope(TypeTableEntry *type_entry);62ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
...@@ -190,56 +191,4 @@ void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);...@@ -190,56 +191,4 @@ void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
190191
191TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);192TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
192193
193enum ConstCastResultId {
194 ConstCastResultIdOk,
195 ConstCastResultIdErrSet,
196 ConstCastResultIdPointerChild,
197 ConstCastResultIdSliceChild,
198 ConstCastResultIdNullableChild,
199 ConstCastResultIdErrorUnionPayload,
200 ConstCastResultIdErrorUnionErrorSet,
201 ConstCastResultIdFnAlign,
202 ConstCastResultIdFnCC,
203 ConstCastResultIdFnVarArgs,
204 ConstCastResultIdFnIsGeneric,
205 ConstCastResultIdFnReturnType,
206 ConstCastResultIdFnArgCount,
207 ConstCastResultIdFnGenericArgCount,
208 ConstCastResultIdFnArg,
209 ConstCastResultIdFnArgNoAlias,
210 ConstCastResultIdType,
211};
212
213struct ConstCastErrSetMismatch {
214 ZigList<ErrorTableEntry *> missing_errors;
215};
216
217struct ConstCastOnly;
218
219struct ConstCastArg {
220 size_t arg_index;
221 ConstCastOnly *child;
222};
223
224struct ConstCastArgNoAlias {
225 size_t arg_index;
226};
227
228struct ConstCastOnly {
229 ConstCastResultId id;
230 union {
231 ConstCastErrSetMismatch error_set;
232 ConstCastOnly *pointer_child;
233 ConstCastOnly *slice_child;
234 ConstCastOnly *nullable_child;
235 ConstCastOnly *error_union_payload;
236 ConstCastOnly *error_union_error_set;
237 ConstCastOnly *return_type;
238 ConstCastArg fn_arg;
239 ConstCastArgNoAlias arg_no_alias;
240 } data;
241};
242
243ConstCastOnly types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type);
244
245#endif194#endif
src/codegen.cpp+1
...@@ -5216,6 +5216,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -5216,6 +5216,7 @@ static void define_builtin_types(CodeGen *g) {
5216 {5216 {
5217 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);5217 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);
5218 buf_init_from_str(&entry->name, "error");5218 buf_init_from_str(&entry->name, "error");
5219 entry->data.error_set.err_count = UINT32_MAX;
52195220
5220 // TODO allow overriding this type and keep track of max value and emit an5221 // TODO allow overriding this type and keep track of max value and emit an
5221 // error if there are too many errors declared5222 // error if there are too many errors declared
src/ir.cpp+328-78
...@@ -45,6 +45,59 @@ static LVal make_lval_addr(bool is_const, bool is_volatile) {...@@ -45,6 +45,59 @@ static LVal make_lval_addr(bool is_const, bool is_volatile) {
45 return { true, is_const, is_volatile };45 return { true, is_const, is_volatile };
46}46}
4747
48enum ConstCastResultId {
49 ConstCastResultIdOk,
50 ConstCastResultIdErrSet,
51 ConstCastResultIdErrSetGlobal,
52 ConstCastResultIdPointerChild,
53 ConstCastResultIdSliceChild,
54 ConstCastResultIdNullableChild,
55 ConstCastResultIdErrorUnionPayload,
56 ConstCastResultIdErrorUnionErrorSet,
57 ConstCastResultIdFnAlign,
58 ConstCastResultIdFnCC,
59 ConstCastResultIdFnVarArgs,
60 ConstCastResultIdFnIsGeneric,
61 ConstCastResultIdFnReturnType,
62 ConstCastResultIdFnArgCount,
63 ConstCastResultIdFnGenericArgCount,
64 ConstCastResultIdFnArg,
65 ConstCastResultIdFnArgNoAlias,
66 ConstCastResultIdType,
67 ConstCastResultIdUnresolvedInferredErrSet,
68};
69
70struct ConstCastErrSetMismatch {
71 ZigList<ErrorTableEntry *> missing_errors;
72};
73
74struct ConstCastOnly;
75
76struct ConstCastArg {
77 size_t arg_index;
78 ConstCastOnly *child;
79};
80
81struct ConstCastArgNoAlias {
82 size_t arg_index;
83};
84
85struct ConstCastOnly {
86 ConstCastResultId id;
87 union {
88 ConstCastErrSetMismatch error_set;
89 ConstCastOnly *pointer_child;
90 ConstCastOnly *slice_child;
91 ConstCastOnly *nullable_child;
92 ConstCastOnly *error_union_payload;
93 ConstCastOnly *error_union_error_set;
94 ConstCastOnly *return_type;
95 ConstCastArg fn_arg;
96 ConstCastArgNoAlias arg_no_alias;
97 } data;
98};
99
100
48static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);101static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
49static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);102static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);
50static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);103static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
...@@ -6416,6 +6469,220 @@ static bool slice_is_const(TypeTableEntry *type) {...@@ -6416,6 +6469,220 @@ static bool slice_is_const(TypeTableEntry *type) {
6416 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;6469 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
6417}6470}
64186471
6472static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) {
6473 assert(err_set_type->id == TypeTableEntryIdErrorSet);
6474 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
6475 if (infer_fn != nullptr) {
6476 if (infer_fn->anal_state == FnAnalStateInvalid) {
6477 return false;
6478 } else if (infer_fn->anal_state == FnAnalStateReady) {
6479 analyze_fn_body(ira->codegen, infer_fn);
6480 if (err_set_type->data.error_set.infer_fn != nullptr) {
6481 assert(ira->codegen->errors.length != 0);
6482 return false;
6483 }
6484 } else {
6485 ir_add_error_node(ira, source_node,
6486 buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet",
6487 buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name)));
6488 return false;
6489 }
6490 }
6491 return true;
6492}
6493
6494static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *expected_type,
6495 TypeTableEntry *actual_type, AstNode *source_node)
6496{
6497 CodeGen *g = ira->codegen;
6498 ConstCastOnly result = {};
6499 result.id = ConstCastResultIdOk;
6500
6501 if (expected_type == actual_type)
6502 return result;
6503
6504 // pointer const
6505 if (expected_type->id == TypeTableEntryIdPointer &&
6506 actual_type->id == TypeTableEntryIdPointer &&
6507 (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const) &&
6508 (!actual_type->data.pointer.is_volatile || expected_type->data.pointer.is_volatile) &&
6509 actual_type->data.pointer.bit_offset == expected_type->data.pointer.bit_offset &&
6510 actual_type->data.pointer.unaligned_bit_count == expected_type->data.pointer.unaligned_bit_count &&
6511 actual_type->data.pointer.alignment >= expected_type->data.pointer.alignment)
6512 {
6513 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.pointer.child_type, actual_type->data.pointer.child_type, source_node);
6514 if (child.id != ConstCastResultIdOk) {
6515 result.id = ConstCastResultIdPointerChild;
6516 result.data.pointer_child = allocate_nonzero<ConstCastOnly>(1);
6517 *result.data.pointer_child = child;
6518 }
6519 return result;
6520 }
6521
6522 // slice const
6523 if (expected_type->id == TypeTableEntryIdStruct && actual_type->id == TypeTableEntryIdStruct &&
6524 expected_type->data.structure.is_slice && actual_type->data.structure.is_slice)
6525 {
6526 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
6527 TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
6528 if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) &&
6529 (!actual_ptr_type->data.pointer.is_volatile || expected_ptr_type->data.pointer.is_volatile) &&
6530 actual_ptr_type->data.pointer.bit_offset == expected_ptr_type->data.pointer.bit_offset &&
6531 actual_ptr_type->data.pointer.unaligned_bit_count == expected_ptr_type->data.pointer.unaligned_bit_count &&
6532 actual_ptr_type->data.pointer.alignment >= expected_ptr_type->data.pointer.alignment)
6533 {
6534 ConstCastOnly child = types_match_const_cast_only(ira, expected_ptr_type->data.pointer.child_type,
6535 actual_ptr_type->data.pointer.child_type, source_node);
6536 if (child.id != ConstCastResultIdOk) {
6537 result.id = ConstCastResultIdSliceChild;
6538 result.data.slice_child = allocate_nonzero<ConstCastOnly>(1);
6539 *result.data.slice_child = child;
6540 }
6541 return result;
6542 }
6543 }
6544
6545 // maybe
6546 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {
6547 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node);
6548 if (child.id != ConstCastResultIdOk) {
6549 result.id = ConstCastResultIdNullableChild;
6550 result.data.nullable_child = allocate_nonzero<ConstCastOnly>(1);
6551 *result.data.nullable_child = child;
6552 }
6553 return result;
6554 }
6555
6556 // error union
6557 if (expected_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {
6558 ConstCastOnly payload_child = types_match_const_cast_only(ira, expected_type->data.error_union.payload_type, actual_type->data.error_union.payload_type, source_node);
6559 if (payload_child.id != ConstCastResultIdOk) {
6560 result.id = ConstCastResultIdErrorUnionPayload;
6561 result.data.error_union_payload = allocate_nonzero<ConstCastOnly>(1);
6562 *result.data.error_union_payload = payload_child;
6563 return result;
6564 }
6565 ConstCastOnly error_set_child = types_match_const_cast_only(ira, expected_type->data.error_union.err_set_type, actual_type->data.error_union.err_set_type, source_node);
6566 if (error_set_child.id != ConstCastResultIdOk) {
6567 result.id = ConstCastResultIdErrorUnionErrorSet;
6568 result.data.error_union_error_set = allocate_nonzero<ConstCastOnly>(1);
6569 *result.data.error_union_error_set = error_set_child;
6570 return result;
6571 }
6572 return result;
6573 }
6574
6575 // error set
6576 if (expected_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {
6577 TypeTableEntry *contained_set = actual_type;
6578 TypeTableEntry *container_set = expected_type;
6579
6580 if (!resolve_inferred_error_set(ira, container_set, source_node)) {
6581 result.id = ConstCastResultIdUnresolvedInferredErrSet;
6582 return result;
6583 }
6584
6585 if (type_is_global_error_set(container_set)) {
6586 return result;
6587 }
6588
6589 if (!resolve_inferred_error_set(ira, contained_set, source_node)) {
6590 result.id = ConstCastResultIdUnresolvedInferredErrSet;
6591 return result;
6592 }
6593
6594 if (type_is_global_error_set(contained_set)) {
6595 result.id = ConstCastResultIdErrSetGlobal;
6596 return result;
6597 }
6598
6599 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(g->errors_by_index.length);
6600 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
6601 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
6602 errors[error_entry->value] = error_entry;
6603 }
6604 for (uint32_t i = 0; i < contained_set->data.error_set.err_count; i += 1) {
6605 ErrorTableEntry *contained_error_entry = contained_set->data.error_set.errors[i];
6606 ErrorTableEntry *error_entry = errors[contained_error_entry->value];
6607 if (error_entry == nullptr) {
6608 if (result.id == ConstCastResultIdOk) {
6609 result.id = ConstCastResultIdErrSet;
6610 }
6611 result.data.error_set.missing_errors.append(contained_error_entry);
6612 }
6613 }
6614 free(errors);
6615 return result;
6616 }
6617
6618 // fn
6619 if (expected_type->id == TypeTableEntryIdFn &&
6620 actual_type->id == TypeTableEntryIdFn)
6621 {
6622 if (expected_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
6623 result.id = ConstCastResultIdFnAlign;
6624 return result;
6625 }
6626 if (expected_type->data.fn.fn_type_id.cc != actual_type->data.fn.fn_type_id.cc) {
6627 result.id = ConstCastResultIdFnCC;
6628 return result;
6629 }
6630 if (expected_type->data.fn.fn_type_id.is_var_args != actual_type->data.fn.fn_type_id.is_var_args) {
6631 result.id = ConstCastResultIdFnVarArgs;
6632 return result;
6633 }
6634 if (expected_type->data.fn.is_generic != actual_type->data.fn.is_generic) {
6635 result.id = ConstCastResultIdFnIsGeneric;
6636 return result;
6637 }
6638 if (!expected_type->data.fn.is_generic &&
6639 actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable)
6640 {
6641 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.fn.fn_type_id.return_type, actual_type->data.fn.fn_type_id.return_type, source_node);
6642 if (child.id != ConstCastResultIdOk) {
6643 result.id = ConstCastResultIdFnReturnType;
6644 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);
6645 *result.data.return_type = child;
6646 }
6647 return result;
6648 }
6649 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
6650 result.id = ConstCastResultIdFnArgCount;
6651 return result;
6652 }
6653 if (expected_type->data.fn.fn_type_id.next_param_index != actual_type->data.fn.fn_type_id.next_param_index) {
6654 result.id = ConstCastResultIdFnGenericArgCount;
6655 return result;
6656 }
6657 assert(expected_type->data.fn.is_generic ||
6658 expected_type->data.fn.fn_type_id.next_param_index == expected_type->data.fn.fn_type_id.param_count);
6659 for (size_t i = 0; i < expected_type->data.fn.fn_type_id.next_param_index; i += 1) {
6660 // note it's reversed for parameters
6661 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
6662 FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i];
6663
6664 ConstCastOnly arg_child = types_match_const_cast_only(ira, actual_param_info->type, expected_param_info->type, source_node);
6665 if (arg_child.id != ConstCastResultIdOk) {
6666 result.id = ConstCastResultIdFnArg;
6667 result.data.fn_arg.arg_index = i;
6668 result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1);
6669 *result.data.fn_arg.child = arg_child;
6670 return result;
6671 }
6672
6673 if (expected_param_info->is_noalias != actual_param_info->is_noalias) {
6674 result.id = ConstCastResultIdFnArgNoAlias;
6675 result.data.arg_no_alias.arg_index = i;
6676 return result;
6677 }
6678 }
6679 return result;
6680 }
6681
6682 result.id = ConstCastResultIdType;
6683 return result;
6684}
6685
6419enum ImplicitCastMatchResult {6686enum ImplicitCastMatchResult {
6420 ImplicitCastMatchResultNo,6687 ImplicitCastMatchResultNo,
6421 ImplicitCastMatchResultYes,6688 ImplicitCastMatchResultYes,
...@@ -6425,7 +6692,8 @@ enum ImplicitCastMatchResult {...@@ -6425,7 +6692,8 @@ enum ImplicitCastMatchResult {
6425static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type,6692static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type,
6426 TypeTableEntry *actual_type, IrInstruction *value)6693 TypeTableEntry *actual_type, IrInstruction *value)
6427{6694{
6428 ConstCastOnly const_cast_result = types_match_const_cast_only(ira->codegen, expected_type, actual_type);6695 AstNode *source_node = value->source_node;
6696 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, expected_type, actual_type, source_node);
6429 if (const_cast_result.id == ConstCastResultIdOk) {6697 if (const_cast_result.id == ConstCastResultIdOk) {
6430 return ImplicitCastMatchResultYes;6698 return ImplicitCastMatchResultYes;
6431 }6699 }
...@@ -6520,7 +6788,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6520,7 +6788,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6520 assert(ptr_type->id == TypeTableEntryIdPointer);6788 assert(ptr_type->id == TypeTableEntryIdPointer);
65216789
6522 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&6790 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6523 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)6791 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6524 {6792 {
6525 return ImplicitCastMatchResultYes;6793 return ImplicitCastMatchResultYes;
6526 }6794 }
...@@ -6539,7 +6807,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6539,7 +6807,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6539 TypeTableEntry *array_type = actual_type->data.pointer.child_type;6807 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
65406808
6541 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&6809 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
6542 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk)6810 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6543 {6811 {
6544 return ImplicitCastMatchResultYes;6812 return ImplicitCastMatchResultYes;
6545 }6813 }
...@@ -6555,7 +6823,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6555,7 +6823,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6555 expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;6823 expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
6556 assert(ptr_type->id == TypeTableEntryIdPointer);6824 assert(ptr_type->id == TypeTableEntryIdPointer);
6557 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&6825 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6558 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)6826 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6559 {6827 {
6560 return ImplicitCastMatchResultYes;6828 return ImplicitCastMatchResultYes;
6561 }6829 }
...@@ -6570,7 +6838,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6570,7 +6838,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6570 expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;6838 expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
6571 assert(ptr_type->id == TypeTableEntryIdPointer);6839 assert(ptr_type->id == TypeTableEntryIdPointer);
6572 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&6840 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6573 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)6841 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6574 {6842 {
6575 return ImplicitCastMatchResultYes;6843 return ImplicitCastMatchResultYes;
6576 }6844 }
...@@ -6650,7 +6918,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6650,7 +6918,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6650 // implicitly take a const pointer to something6918 // implicitly take a const pointer to something
6651 if (!type_requires_comptime(actual_type)) {6919 if (!type_requires_comptime(actual_type)) {
6652 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);6920 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
6653 if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual).id == ConstCastResultIdOk) {6921 if (types_match_const_cast_only(ira, expected_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) {
6654 return ImplicitCastMatchResultYes;6922 return ImplicitCastMatchResultYes;
6655 }6923 }
6656 }6924 }
...@@ -6658,27 +6926,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6658,27 +6926,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6658 return ImplicitCastMatchResultNo;6926 return ImplicitCastMatchResultNo;
6659}6927}
66606928
6661static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) {
6662 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
6663 if (infer_fn != nullptr) {
6664 if (infer_fn->anal_state == FnAnalStateInvalid) {
6665 return false;
6666 } else if (infer_fn->anal_state == FnAnalStateReady) {
6667 analyze_fn_body(ira->codegen, infer_fn);
6668 if (err_set_type->data.error_set.infer_fn != nullptr) {
6669 assert(ira->codegen->errors.length != 0);
6670 return false;
6671 }
6672 } else {
6673 ir_add_error_node(ira, source_node,
6674 buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet",
6675 buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name)));
6676 return false;
6677 }
6678 }
6679 return true;
6680}
6681
6682static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {6929static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {
6683 assert(instruction_count >= 1);6930 assert(instruction_count >= 1);
6684 IrInstruction *prev_inst = instructions[0];6931 IrInstruction *prev_inst = instructions[0];
...@@ -6687,17 +6934,19 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6687,17 +6934,19 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6687 }6934 }
6688 ErrorTableEntry **errors = nullptr;6935 ErrorTableEntry **errors = nullptr;
6689 TypeTableEntry *err_set_type = nullptr;6936 TypeTableEntry *err_set_type = nullptr;
6690 if (prev_inst->value.type == ira->codegen->builtin_types.entry_global_error_set) {6937 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
6691 err_set_type = ira->codegen->builtin_types.entry_global_error_set;6938 if (type_is_global_error_set(prev_inst->value.type)) {
6692 } else if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {6939 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6693 err_set_type = prev_inst->value.type;6940 } else {
6694 errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);6941 err_set_type = prev_inst->value.type;
6695 if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) {6942 if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) {
6696 return ira->codegen->builtin_types.entry_invalid;6943 return ira->codegen->builtin_types.entry_invalid;
6697 }6944 }
6698 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {6945 errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
6699 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];6946 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
6700 errors[error_entry->value] = error_entry;6947 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];
6948 errors[error_entry->value] = error_entry;
6949 }
6701 }6950 }
6702 }6951 }
67036952
...@@ -6734,18 +6983,18 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6734,18 +6983,18 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6734 if (prev_type->id == TypeTableEntryIdErrorSet) {6983 if (prev_type->id == TypeTableEntryIdErrorSet) {
6735 assert(err_set_type != nullptr);6984 assert(err_set_type != nullptr);
6736 if (cur_type->id == TypeTableEntryIdErrorSet) {6985 if (cur_type->id == TypeTableEntryIdErrorSet) {
6737 if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) {6986 if (type_is_global_error_set(err_set_type)) {
6738 continue;6987 continue;
6739 }6988 }
6740 if (cur_type == ira->codegen->builtin_types.entry_global_error_set) {6989 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
6990 return ira->codegen->builtin_types.entry_invalid;
6991 }
6992 if (type_is_global_error_set(cur_type)) {
6741 err_set_type = ira->codegen->builtin_types.entry_global_error_set;6993 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6742 prev_inst = cur_inst;6994 prev_inst = cur_inst;
6743 continue;6995 continue;
6744 }6996 }
67456997
6746 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
6747 return ira->codegen->builtin_types.entry_invalid;
6748 }
6749 // if err_set_type is a superset of cur_type, keep err_set_type.6998 // if err_set_type is a superset of cur_type, keep err_set_type.
6750 // if cur_type is a superset of err_set_type, switch err_set_type to cur_type6999 // if cur_type is a superset of err_set_type, switch err_set_type to cur_type
6751 bool prev_is_superset = true;7000 bool prev_is_superset = true;
...@@ -6791,12 +7040,15 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6791,12 +7040,15 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6791 assert(errors != nullptr);7040 assert(errors != nullptr);
6792 continue;7041 continue;
6793 } else if (cur_type->id == TypeTableEntryIdErrorUnion) {7042 } else if (cur_type->id == TypeTableEntryIdErrorUnion) {
6794 if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) {7043 if (type_is_global_error_set(err_set_type)) {
6795 prev_inst = cur_inst;7044 prev_inst = cur_inst;
6796 continue;7045 continue;
6797 }7046 }
6798 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;7047 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
6799 if (cur_err_set_type == ira->codegen->builtin_types.entry_global_error_set) {7048 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
7049 return ira->codegen->builtin_types.entry_invalid;
7050 }
7051 if (type_is_global_error_set(cur_err_set_type)) {
6800 err_set_type = ira->codegen->builtin_types.entry_global_error_set;7052 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6801 prev_inst = cur_inst;7053 prev_inst = cur_inst;
6802 continue;7054 continue;
...@@ -6807,9 +7059,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6807,9 +7059,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6807 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];7059 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];
6808 errors[error_entry->value] = nullptr;7060 errors[error_entry->value] = nullptr;
6809 }7061 }
6810 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
6811 return ira->codegen->builtin_types.entry_invalid;
6812 }
6813 for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) {7062 for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) {
6814 ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i];7063 ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i];
6815 errors[error_entry->value] = error_entry;7064 errors[error_entry->value] = error_entry;
...@@ -6845,11 +7094,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6845,11 +7094,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6845 if (prev_type->id == TypeTableEntryIdArray) {7094 if (prev_type->id == TypeTableEntryIdArray) {
6846 convert_to_const_slice = true;7095 convert_to_const_slice = true;
6847 }7096 }
6848 if (cur_type == ira->codegen->builtin_types.entry_global_error_set) {7097 if (type_is_global_error_set(cur_type)) {
6849 err_set_type = ira->codegen->builtin_types.entry_global_error_set;7098 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6850 continue;7099 continue;
6851 }7100 }
6852 if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) {7101 if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) {
6853 continue;7102 continue;
6854 }7103 }
6855 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {7104 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
...@@ -6884,11 +7133,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6884,11 +7133,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6884 }7133 }
6885 }7134 }
68867135
6887 if (types_match_const_cast_only(ira->codegen, prev_type, cur_type).id == ConstCastResultIdOk) {7136 if (types_match_const_cast_only(ira, prev_type, cur_type, source_node).id == ConstCastResultIdOk) {
6888 continue;7137 continue;
6889 }7138 }
68907139
6891 if (types_match_const_cast_only(ira->codegen, cur_type, prev_type).id == ConstCastResultIdOk) {7140 if (types_match_const_cast_only(ira, cur_type, prev_type, source_node).id == ConstCastResultIdOk) {
6892 prev_inst = cur_inst;7141 prev_inst = cur_inst;
6893 continue;7142 continue;
6894 }7143 }
...@@ -6911,26 +7160,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6911,26 +7160,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6911 }7160 }
69127161
6913 if (prev_type->id == TypeTableEntryIdErrorUnion &&7162 if (prev_type->id == TypeTableEntryIdErrorUnion &&
6914 types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type).id == ConstCastResultIdOk)7163 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, source_node).id == ConstCastResultIdOk)
6915 {7164 {
6916 continue;7165 continue;
6917 }7166 }
69187167
6919 if (cur_type->id == TypeTableEntryIdErrorUnion &&7168 if (cur_type->id == TypeTableEntryIdErrorUnion &&
6920 types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type).id == ConstCastResultIdOk)7169 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, source_node).id == ConstCastResultIdOk)
6921 {7170 {
6922 prev_inst = cur_inst;7171 prev_inst = cur_inst;
6923 continue;7172 continue;
6924 }7173 }
69257174
6926 if (prev_type->id == TypeTableEntryIdMaybe &&7175 if (prev_type->id == TypeTableEntryIdMaybe &&
6927 types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type).id == ConstCastResultIdOk)7176 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node).id == ConstCastResultIdOk)
6928 {7177 {
6929 continue;7178 continue;
6930 }7179 }
69317180
6932 if (cur_type->id == TypeTableEntryIdMaybe &&7181 if (cur_type->id == TypeTableEntryIdMaybe &&
6933 types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type).id == ConstCastResultIdOk)7182 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node).id == ConstCastResultIdOk)
6934 {7183 {
6935 prev_inst = cur_inst;7184 prev_inst = cur_inst;
6936 continue;7185 continue;
...@@ -6968,7 +7217,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6968,7 +7217,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69687217
6969 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&7218 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
6970 cur_type->data.array.len != prev_type->data.array.len &&7219 cur_type->data.array.len != prev_type->data.array.len &&
6971 types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type).id == ConstCastResultIdOk)7220 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6972 {7221 {
6973 convert_to_const_slice = true;7222 convert_to_const_slice = true;
6974 prev_inst = cur_inst;7223 prev_inst = cur_inst;
...@@ -6977,7 +7226,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6977,7 +7226,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69777226
6978 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&7227 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
6979 cur_type->data.array.len != prev_type->data.array.len &&7228 cur_type->data.array.len != prev_type->data.array.len &&
6980 types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type).id == ConstCastResultIdOk)7229 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6981 {7230 {
6982 convert_to_const_slice = true;7231 convert_to_const_slice = true;
6983 continue;7232 continue;
...@@ -6986,8 +7235,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6986,8 +7235,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6986 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&7235 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
6987 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||7236 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
6988 cur_type->data.array.len == 0) &&7237 cur_type->data.array.len == 0) &&
6989 types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,7238 types_match_const_cast_only(ira, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
6990 cur_type->data.array.child_type).id == ConstCastResultIdOk)7239 cur_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
6991 {7240 {
6992 convert_to_const_slice = false;7241 convert_to_const_slice = false;
6993 continue;7242 continue;
...@@ -6996,8 +7245,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -6996,8 +7245,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6996 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&7245 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
6997 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||7246 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
6998 prev_type->data.array.len == 0) &&7247 prev_type->data.array.len == 0) &&
6999 types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,7248 types_match_const_cast_only(ira, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
7000 prev_type->data.array.child_type).id == ConstCastResultIdOk)7249 prev_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
7001 {7250 {
7002 prev_inst = cur_inst;7251 prev_inst = cur_inst;
7003 convert_to_const_slice = false;7252 convert_to_const_slice = false;
...@@ -7581,7 +7830,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -7581,7 +7830,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
7581 zig_panic("TODO explicit error set cast");7830 zig_panic("TODO explicit error set cast");
75827831
7583 if (container_set->data.error_set.infer_fn == nullptr &&7832 if (container_set->data.error_set.infer_fn == nullptr &&
7584 container_set != ira->codegen->builtin_types.entry_global_error_set)7833 !type_is_global_error_set(container_set))
7585 {7834 {
7586 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);7835 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
7587 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {7836 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
...@@ -8103,7 +8352,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -8103,7 +8352,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
8103 } else {8352 } else {
8104 zig_unreachable();8353 zig_unreachable();
8105 }8354 }
8106 if (err_set_type != ira->codegen->builtin_types.entry_global_error_set) {8355 if (!type_is_global_error_set(err_set_type)) {
8107 if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) {8356 if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) {
8108 return ira->codegen->invalid_instruction;8357 return ira->codegen->invalid_instruction;
8109 }8358 }
...@@ -8140,6 +8389,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8140,6 +8389,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8140 TypeTableEntry *wanted_type, IrInstruction *value)8389 TypeTableEntry *wanted_type, IrInstruction *value)
8141{8390{
8142 TypeTableEntry *actual_type = value->value.type;8391 TypeTableEntry *actual_type = value->value.type;
8392 AstNode *source_node = source_instr->source_node;
81438393
8144 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {8394 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
8145 return ira->codegen->invalid_instruction;8395 return ira->codegen->invalid_instruction;
...@@ -8149,7 +8399,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8149,7 +8399,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8149 return value;8399 return value;
81508400
8151 // explicit match or non-const to const8401 // explicit match or non-const to const
8152 if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type).id == ConstCastResultIdOk) {8402 if (types_match_const_cast_only(ira, wanted_type, actual_type, source_node).id == ConstCastResultIdOk) {
8153 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);8403 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);
8154 }8404 }
81558405
...@@ -8195,7 +8445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8195,7 +8445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8195 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;8445 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
8196 assert(ptr_type->id == TypeTableEntryIdPointer);8446 assert(ptr_type->id == TypeTableEntryIdPointer);
8197 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&8447 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8198 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)8448 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
8199 {8449 {
8200 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);8450 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
8201 }8451 }
...@@ -8213,7 +8463,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8213,7 +8463,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8213 TypeTableEntry *array_type = actual_type->data.pointer.child_type;8463 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
82148464
8215 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&8465 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
8216 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk)8466 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
8217 {8467 {
8218 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);8468 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
8219 }8469 }
...@@ -8229,7 +8479,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8229,7 +8479,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8229 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;8479 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
8230 assert(ptr_type->id == TypeTableEntryIdPointer);8480 assert(ptr_type->id == TypeTableEntryIdPointer);
8231 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&8481 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8232 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)8482 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
8233 {8483 {
8234 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);8484 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
8235 if (type_is_invalid(cast1->value.type))8485 if (type_is_invalid(cast1->value.type))
...@@ -8252,7 +8502,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8252,7 +8502,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8252 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;8502 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
8253 assert(ptr_type->id == TypeTableEntryIdPointer);8503 assert(ptr_type->id == TypeTableEntryIdPointer);
8254 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&8504 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8255 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)8505 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
8256 {8506 {
8257 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);8507 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
8258 if (type_is_invalid(cast1->value.type))8508 if (type_is_invalid(cast1->value.type))
...@@ -8314,7 +8564,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8314,7 +8564,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83148564
8315 // explicit cast from child type of maybe type to maybe type8565 // explicit cast from child type of maybe type to maybe type
8316 if (wanted_type->id == TypeTableEntryIdMaybe) {8566 if (wanted_type->id == TypeTableEntryIdMaybe) {
8317 if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type).id == ConstCastResultIdOk) {8567 if (types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, actual_type, source_node).id == ConstCastResultIdOk) {
8318 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);8568 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
8319 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||8569 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
8320 actual_type->id == TypeTableEntryIdNumLitFloat)8570 actual_type->id == TypeTableEntryIdNumLitFloat)
...@@ -8336,7 +8586,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8336,7 +8586,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83368586
8337 // explicit cast from child type of error type to error type8587 // explicit cast from child type of error type to error type
8338 if (wanted_type->id == TypeTableEntryIdErrorUnion) {8588 if (wanted_type->id == TypeTableEntryIdErrorUnion) {
8339 if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type).id == ConstCastResultIdOk) {8589 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, source_node).id == ConstCastResultIdOk) {
8340 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);8590 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
8341 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||8591 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
8342 actual_type->id == TypeTableEntryIdNumLitFloat)8592 actual_type->id == TypeTableEntryIdNumLitFloat)
...@@ -8358,7 +8608,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8358,7 +8608,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8358 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;8608 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
8359 assert(ptr_type->id == TypeTableEntryIdPointer);8609 assert(ptr_type->id == TypeTableEntryIdPointer);
8360 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&8610 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8361 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk)8611 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
8362 {8612 {
8363 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);8613 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
8364 if (type_is_invalid(cast1->value.type))8614 if (type_is_invalid(cast1->value.type))
...@@ -8385,7 +8635,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8385,7 +8635,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8385 actual_type->id != TypeTableEntryIdMaybe)8635 actual_type->id != TypeTableEntryIdMaybe)
8386 {8636 {
8387 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;8637 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
8388 if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type).id == ConstCastResultIdOk ||8638 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk ||
8389 actual_type->id == TypeTableEntryIdNullLit ||8639 actual_type->id == TypeTableEntryIdNullLit ||
8390 actual_type->id == TypeTableEntryIdNumLitInt ||8640 actual_type->id == TypeTableEntryIdNumLitInt ||
8391 actual_type->id == TypeTableEntryIdNumLitFloat)8641 actual_type->id == TypeTableEntryIdNumLitFloat)
...@@ -8535,7 +8785,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -8535,7 +8785,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
8535 // explicit cast from something to const pointer of it8785 // explicit cast from something to const pointer of it
8536 if (!type_requires_comptime(actual_type)) {8786 if (!type_requires_comptime(actual_type)) {
8537 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);8787 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
8538 if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual).id == ConstCastResultIdOk) {8788 if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) {
8539 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);8789 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
8540 }8790 }
8541 }8791 }
...@@ -9700,8 +9950,8 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction...@@ -9700,8 +9950,8 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
9700 if (type_is_invalid(op2_type))9950 if (type_is_invalid(op2_type))
9701 return ira->codegen->builtin_types.entry_invalid;9951 return ira->codegen->builtin_types.entry_invalid;
97029952
9703 if (op1_type == ira->codegen->builtin_types.entry_global_error_set ||9953 if (type_is_global_error_set(op1_type) ||
9704 op2_type == ira->codegen->builtin_types.entry_global_error_set)9954 type_is_global_error_set(op2_type))
9705 {9955 {
9706 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);9956 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
9707 out_val->data.x_type = ira->codegen->builtin_types.entry_global_error_set;9957 out_val->data.x_type = ira->codegen->builtin_types.entry_global_error_set;
...@@ -11716,7 +11966,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -11716,7 +11966,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
11716 } else if (child_type->id == TypeTableEntryIdErrorSet) {11966 } else if (child_type->id == TypeTableEntryIdErrorSet) {
11717 ErrorTableEntry *err_entry;11967 ErrorTableEntry *err_entry;
11718 TypeTableEntry *err_set_type;11968 TypeTableEntry *err_set_type;
11719 if (child_type == ira->codegen->builtin_types.entry_global_error_set) {11969 if (type_is_global_error_set(child_type)) {
11720 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);11970 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);
11721 if (existing_entry) {11971 if (existing_entry) {
11722 err_entry = existing_entry->value;11972 err_entry = existing_entry->value;
...@@ -14764,7 +15014,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -14764,7 +15014,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
14764 if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) {15014 if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) {
14765 return ira->codegen->builtin_types.entry_invalid;15015 return ira->codegen->builtin_types.entry_invalid;
14766 }15016 }
14767 if (err_set_type != ira->codegen->builtin_types.entry_global_error_set &&15017 if (!type_is_global_error_set(err_set_type) &&
14768 err_set_type->data.error_set.err_count == 0)15018 err_set_type->data.error_set.err_count == 0)
14769 {15019 {
14770 assert(err_set_type->data.error_set.infer_fn == nullptr);15020 assert(err_set_type->data.error_set.infer_fn == nullptr);
std/os/index.zig+1-1
...@@ -1072,7 +1072,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {...@@ -1072,7 +1072,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {
1072}1072}
10731073
1074/// Read value of a symbolic link.1074/// Read value of a symbolic link.
1075pub fn readLink(allocator: &Allocator, pathname: []const u8) error![]u8 {1075pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 {
1076 const path_buf = try allocator.alloc(u8, pathname.len + 1);1076 const path_buf = try allocator.alloc(u8, pathname.len + 1);
1077 defer allocator.free(path_buf);1077 defer allocator.free(path_buf);
10781078