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
2626
2727undefined in infer error
2828
29change readlink back to inferred error
30
3129syntax - ?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
33723372 g->tld_ref_source_node_stack.pop();
33733373}
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
35493375Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
35503376 // we must resolve all the use decls
35513377 ImportTableEntry *import = get_scope_import(scope);
......@@ -3906,10 +3732,16 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
39063732 }
39073733
39083734 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;
3910 return_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
3911 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
3912 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
3735 if (type_is_global_error_set(inferred_err_set_type)) {
3736 return_err_set_type->data.error_set.err_count = UINT32_MAX;
3737 } else {
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 }
39133745 }
39143746 }
39153747 }
......@@ -5833,3 +5665,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
58335665 return var_value;
58345666}
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
5656TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
5757bool type_is_complete(TypeTableEntry *type_entry);
5858bool type_is_invalid(TypeTableEntry *type_entry);
59bool type_is_global_error_set(TypeTableEntry *err_set_type);
5960bool type_has_zero_bits_known(TypeTableEntry *type_entry);
6061void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
6162ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
......@@ -190,56 +191,4 @@ void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
190191
191192TypeTableEntry *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
245194#endif
src/codegen.cpp+1
......@@ -5216,6 +5216,7 @@ static void define_builtin_types(CodeGen *g) {
52165216 {
52175217 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);
52185218 buf_init_from_str(&entry->name, "error");
5219 entry->data.error_set.err_count = UINT32_MAX;
52195220
52205221 // TODO allow overriding this type and keep track of max value and emit an
52215222 // 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) {
4545 return { true, is_const, is_volatile };
4646}
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
48101static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
49102static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);
50103static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
......@@ -6416,6 +6469,220 @@ static bool slice_is_const(TypeTableEntry *type) {
64166469 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
64176470}
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
64196686enum ImplicitCastMatchResult {
64206687 ImplicitCastMatchResultNo,
64216688 ImplicitCastMatchResultYes,
......@@ -6425,7 +6692,8 @@ enum ImplicitCastMatchResult {
64256692static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type,
64266693 TypeTableEntry *actual_type, IrInstruction *value)
64276694{
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);
64296697 if (const_cast_result.id == ConstCastResultIdOk) {
64306698 return ImplicitCastMatchResultYes;
64316699 }
......@@ -6520,7 +6788,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65206788 assert(ptr_type->id == TypeTableEntryIdPointer);
65216789
65226790 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)
65246792 {
65256793 return ImplicitCastMatchResultYes;
65266794 }
......@@ -6539,7 +6807,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65396807 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
65406808
65416809 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)
65436811 {
65446812 return ImplicitCastMatchResultYes;
65456813 }
......@@ -6555,7 +6823,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65556823 expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
65566824 assert(ptr_type->id == TypeTableEntryIdPointer);
65576825 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)
65596827 {
65606828 return ImplicitCastMatchResultYes;
65616829 }
......@@ -6570,7 +6838,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65706838 expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
65716839 assert(ptr_type->id == TypeTableEntryIdPointer);
65726840 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)
65746842 {
65756843 return ImplicitCastMatchResultYes;
65766844 }
......@@ -6650,7 +6918,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
66506918 // implicitly take a const pointer to something
66516919 if (!type_requires_comptime(actual_type)) {
66526920 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) {
66546922 return ImplicitCastMatchResultYes;
66556923 }
66566924 }
......@@ -6658,27 +6926,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
66586926 return ImplicitCastMatchResultNo;
66596927}
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
66826929static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {
66836930 assert(instruction_count >= 1);
66846931 IrInstruction *prev_inst = instructions[0];
......@@ -6687,17 +6934,19 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
66876934 }
66886935 ErrorTableEntry **errors = nullptr;
66896936 TypeTableEntry *err_set_type = nullptr;
6690 if (prev_inst->value.type == ira->codegen->builtin_types.entry_global_error_set) {
6691 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6692 } else if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
6693 err_set_type = prev_inst->value.type;
6694 errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
6695 if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) {
6696 return ira->codegen->builtin_types.entry_invalid;
6697 }
6698 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
6699 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];
6700 errors[error_entry->value] = error_entry;
6937 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
6938 if (type_is_global_error_set(prev_inst->value.type)) {
6939 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
6940 } else {
6941 err_set_type = prev_inst->value.type;
6942 if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) {
6943 return ira->codegen->builtin_types.entry_invalid;
6944 }
6945 errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
6946 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
6947 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];
6948 errors[error_entry->value] = error_entry;
6949 }
67016950 }
67026951 }
67036952
......@@ -6734,18 +6983,18 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
67346983 if (prev_type->id == TypeTableEntryIdErrorSet) {
67356984 assert(err_set_type != nullptr);
67366985 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)) {
67386987 continue;
67396988 }
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)) {
67416993 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
67426994 prev_inst = cur_inst;
67436995 continue;
67446996 }
67456997
6746 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
6747 return ira->codegen->builtin_types.entry_invalid;
6748 }
67496998 // if err_set_type is a superset of cur_type, keep err_set_type.
67506999 // if cur_type is a superset of err_set_type, switch err_set_type to cur_type
67517000 bool prev_is_superset = true;
......@@ -6791,12 +7040,15 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
67917040 assert(errors != nullptr);
67927041 continue;
67937042 } 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)) {
67957044 prev_inst = cur_inst;
67967045 continue;
67977046 }
67987047 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)) {
68007052 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
68017053 prev_inst = cur_inst;
68027054 continue;
......@@ -6807,9 +7059,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68077059 ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i];
68087060 errors[error_entry->value] = nullptr;
68097061 }
6810 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
6811 return ira->codegen->builtin_types.entry_invalid;
6812 }
68137062 for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) {
68147063 ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i];
68157064 errors[error_entry->value] = error_entry;
......@@ -6845,11 +7094,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68457094 if (prev_type->id == TypeTableEntryIdArray) {
68467095 convert_to_const_slice = true;
68477096 }
6848 if (cur_type == ira->codegen->builtin_types.entry_global_error_set) {
7097 if (type_is_global_error_set(cur_type)) {
68497098 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
68507099 continue;
68517100 }
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)) {
68537102 continue;
68547103 }
68557104 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
68847133 }
68857134 }
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) {
68887137 continue;
68897138 }
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) {
68927141 prev_inst = cur_inst;
68937142 continue;
68947143 }
......@@ -6911,26 +7160,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69117160 }
69127161
69137162 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)
69157164 {
69167165 continue;
69177166 }
69187167
69197168 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)
69217170 {
69227171 prev_inst = cur_inst;
69237172 continue;
69247173 }
69257174
69267175 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)
69287177 {
69297178 continue;
69307179 }
69317180
69327181 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)
69347183 {
69357184 prev_inst = cur_inst;
69367185 continue;
......@@ -6968,7 +7217,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69687217
69697218 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
69707219 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)
69727221 {
69737222 convert_to_const_slice = true;
69747223 prev_inst = cur_inst;
......@@ -6977,7 +7226,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69777226
69787227 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
69797228 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)
69817230 {
69827231 convert_to_const_slice = true;
69837232 continue;
......@@ -6986,8 +7235,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69867235 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
69877236 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
69887237 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,
6990 cur_type->data.array.child_type).id == ConstCastResultIdOk)
7238 types_match_const_cast_only(ira, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
7239 cur_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
69917240 {
69927241 convert_to_const_slice = false;
69937242 continue;
......@@ -6996,8 +7245,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
69967245 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
69977246 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
69987247 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,
7000 prev_type->data.array.child_type).id == ConstCastResultIdOk)
7248 types_match_const_cast_only(ira, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
7249 prev_type->data.array.child_type, source_node).id == ConstCastResultIdOk)
70017250 {
70027251 prev_inst = cur_inst;
70037252 convert_to_const_slice = false;
......@@ -7581,7 +7830,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
75817830 zig_panic("TODO explicit error set cast");
75827831
75837832 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))
75857834 {
75867835 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
75877836 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
81038352 } else {
81048353 zig_unreachable();
81058354 }
8106 if (err_set_type != ira->codegen->builtin_types.entry_global_error_set) {
8355 if (!type_is_global_error_set(err_set_type)) {
81078356 if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) {
81088357 return ira->codegen->invalid_instruction;
81098358 }
......@@ -8140,6 +8389,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81408389 TypeTableEntry *wanted_type, IrInstruction *value)
81418390{
81428391 TypeTableEntry *actual_type = value->value.type;
8392 AstNode *source_node = source_instr->source_node;
81438393
81448394 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
81458395 return ira->codegen->invalid_instruction;
......@@ -8149,7 +8399,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81498399 return value;
81508400
81518401 // 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) {
81538403 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);
81548404 }
81558405
......@@ -8195,7 +8445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81958445 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
81968446 assert(ptr_type->id == TypeTableEntryIdPointer);
81978447 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)
81998449 {
82008450 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
82018451 }
......@@ -8213,7 +8463,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
82138463 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
82148464
82158465 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)
82178467 {
82188468 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
82198469 }
......@@ -8229,7 +8479,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
82298479 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
82308480 assert(ptr_type->id == TypeTableEntryIdPointer);
82318481 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)
82338483 {
82348484 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
82358485 if (type_is_invalid(cast1->value.type))
......@@ -8252,7 +8502,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
82528502 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
82538503 assert(ptr_type->id == TypeTableEntryIdPointer);
82548504 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)
82568506 {
82578507 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
82588508 if (type_is_invalid(cast1->value.type))
......@@ -8314,7 +8564,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83148564
83158565 // explicit cast from child type of maybe type to maybe type
83168566 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) {
83188568 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
83198569 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
83208570 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8336,7 +8586,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83368586
83378587 // explicit cast from child type of error type to error type
83388588 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) {
83408590 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
83418591 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
83428592 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8358,7 +8608,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83588608 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
83598609 assert(ptr_type->id == TypeTableEntryIdPointer);
83608610 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)
83628612 {
83638613 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
83648614 if (type_is_invalid(cast1->value.type))
......@@ -8385,7 +8635,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83858635 actual_type->id != TypeTableEntryIdMaybe)
83868636 {
83878637 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 ||
83898639 actual_type->id == TypeTableEntryIdNullLit ||
83908640 actual_type->id == TypeTableEntryIdNumLitInt ||
83918641 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8535,7 +8785,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
85358785 // explicit cast from something to const pointer of it
85368786 if (!type_requires_comptime(actual_type)) {
85378787 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) {
85398789 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
85408790 }
85418791 }
......@@ -9700,8 +9950,8 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
97009950 if (type_is_invalid(op2_type))
97019951 return ira->codegen->builtin_types.entry_invalid;
97029952
9703 if (op1_type == ira->codegen->builtin_types.entry_global_error_set ||
9704 op2_type == ira->codegen->builtin_types.entry_global_error_set)
9953 if (type_is_global_error_set(op1_type) ||
9954 type_is_global_error_set(op2_type))
97059955 {
97069956 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
97079957 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
1171611966 } else if (child_type->id == TypeTableEntryIdErrorSet) {
1171711967 ErrorTableEntry *err_entry;
1171811968 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)) {
1172011970 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);
1172111971 if (existing_entry) {
1172211972 err_entry = existing_entry->value;
......@@ -14764,7 +15014,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1476415014 if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) {
1476515015 return ira->codegen->builtin_types.entry_invalid;
1476615016 }
14767 if (err_set_type != ira->codegen->builtin_types.entry_global_error_set &&
15017 if (!type_is_global_error_set(err_set_type) &&
1476815018 err_set_type->data.error_set.err_count == 0)
1476915019 {
1477015020 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 {
10721072}
10731073
10741074/// 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 {
10761076 const path_buf = try allocator.alloc(u8, pathname.len + 1);
10771077 defer allocator.free(path_buf);
10781078