| ... | ... | @@ -48,6 +48,7 @@ static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 48 | 48 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, |
| 49 | 49 | LValPurpose lval); |
| 50 | 50 | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| 51 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type); |
| 51 | 52 | |
| 52 | 53 | ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) { |
| 53 | 54 | assert(const_val->special == ConstValSpecialStatic); |
| ... | ... | @@ -93,7 +94,7 @@ static Buf *exec_c_import_buf(IrExecutable *exec) { |
| 93 | 94 | } |
| 94 | 95 | |
| 95 | 96 | static bool instr_is_comptime(IrInstruction *instruction) { |
| 96 | | return instruction->static_value.special != ConstValSpecialRuntime; |
| 97 | return instruction->value.special != ConstValSpecialRuntime; |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | 100 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { |
| ... | ... | @@ -450,6 +451,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionInitEnum *) { |
| 450 | 451 | return IrInstructionIdInitEnum; |
| 451 | 452 | } |
| 452 | 453 | |
| 454 | static constexpr IrInstructionId ir_instruction_id(IrInstructionPointerReinterpret *) { |
| 455 | return IrInstructionIdPointerReinterpret; |
| 456 | } |
| 457 | |
| 453 | 458 | template<typename T> |
| 454 | 459 | static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) { |
| 455 | 460 | T *special_instruction = allocate<T>(1); |
| ... | ... | @@ -485,8 +490,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so |
| 485 | 490 | IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) |
| 486 | 491 | { |
| 487 | 492 | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); |
| 488 | | cond_br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 489 | | cond_br_instruction->base.static_value.special = ConstValSpecialStatic; |
| 493 | cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 494 | cond_br_instruction->base.value.special = ConstValSpecialStatic; |
| 490 | 495 | cond_br_instruction->condition = condition; |
| 491 | 496 | cond_br_instruction->then_block = then_block; |
| 492 | 497 | cond_br_instruction->else_block = else_block; |
| ... | ... | @@ -511,8 +516,8 @@ static IrInstruction *ir_build_cond_br_from(IrBuilder *irb, IrInstruction *old_i |
| 511 | 516 | |
| 512 | 517 | static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *return_value) { |
| 513 | 518 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 514 | | return_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 515 | | return_instruction->base.static_value.special = ConstValSpecialStatic; |
| 519 | return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 520 | return_instruction->base.value.special = ConstValSpecialStatic; |
| 516 | 521 | return_instruction->value = return_value; |
| 517 | 522 | |
| 518 | 523 | ir_ref_instruction(return_value); |
| ... | ... | @@ -533,55 +538,55 @@ static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *sou |
| 533 | 538 | { |
| 534 | 539 | assert(type_entry); |
| 535 | 540 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| 536 | | const_instruction->base.type_entry = type_entry; |
| 537 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 538 | | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; |
| 541 | const_instruction->base.value.type = type_entry; |
| 542 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 543 | const_instruction->base.value.depends_on_compile_var = depends_on_compile_var; |
| 539 | 544 | return &const_instruction->base; |
| 540 | 545 | } |
| 541 | 546 | |
| 542 | 547 | static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 543 | 548 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 544 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 545 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 549 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 550 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 546 | 551 | return &const_instruction->base; |
| 547 | 552 | } |
| 548 | 553 | |
| 549 | 554 | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 550 | 555 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 551 | | const_instruction->base.static_value.special = ConstValSpecialUndef; |
| 552 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_undef; |
| 556 | const_instruction->base.value.special = ConstValSpecialUndef; |
| 557 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef; |
| 553 | 558 | return &const_instruction->base; |
| 554 | 559 | } |
| 555 | 560 | |
| 556 | 561 | static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 557 | 562 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 558 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_num_lit_int; |
| 559 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 560 | | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value); |
| 563 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; |
| 564 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 565 | bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, value); |
| 561 | 566 | return &const_instruction->base; |
| 562 | 567 | } |
| 563 | 568 | |
| 564 | 569 | static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) { |
| 565 | 570 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 566 | | const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ? |
| 571 | const_instruction->base.value.type = (bignum->kind == BigNumKindInt) ? |
| 567 | 572 | irb->codegen->builtin_types.entry_num_lit_int : irb->codegen->builtin_types.entry_num_lit_float; |
| 568 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 569 | | const_instruction->base.static_value.data.x_bignum = *bignum; |
| 573 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 574 | const_instruction->base.value.data.x_bignum = *bignum; |
| 570 | 575 | return &const_instruction->base; |
| 571 | 576 | } |
| 572 | 577 | |
| 573 | 578 | static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 574 | 579 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 575 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_null; |
| 576 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 580 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_null; |
| 581 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 577 | 582 | return &const_instruction->base; |
| 578 | 583 | } |
| 579 | 584 | |
| 580 | 585 | static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 581 | 586 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 582 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_usize; |
| 583 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 584 | | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value); |
| 587 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize; |
| 588 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 589 | bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, value); |
| 585 | 590 | return &const_instruction->base; |
| 586 | 591 | } |
| 587 | 592 | |
| ... | ... | @@ -589,9 +594,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 589 | 594 | TypeTableEntry *type_entry) |
| 590 | 595 | { |
| 591 | 596 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| 592 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_type; |
| 593 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 594 | | const_instruction->base.static_value.data.x_type = type_entry; |
| 597 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| 598 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 599 | const_instruction->base.value.data.x_type = type_entry; |
| 595 | 600 | return &const_instruction->base; |
| 596 | 601 | } |
| 597 | 602 | |
| ... | ... | @@ -605,17 +610,17 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 605 | 610 | |
| 606 | 611 | static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { |
| 607 | 612 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 608 | | const_instruction->base.type_entry = fn_entry->type_entry; |
| 609 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 610 | | const_instruction->base.static_value.data.x_fn = fn_entry; |
| 613 | const_instruction->base.value.type = fn_entry->type_entry; |
| 614 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 615 | const_instruction->base.value.data.x_fn = fn_entry; |
| 611 | 616 | return &const_instruction->base; |
| 612 | 617 | } |
| 613 | 618 | |
| 614 | 619 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) { |
| 615 | 620 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 616 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_namespace; |
| 617 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 618 | | const_instruction->base.static_value.data.x_import = import; |
| 621 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace; |
| 622 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 623 | const_instruction->base.value.data.x_import = import; |
| 619 | 624 | return &const_instruction->base; |
| 620 | 625 | } |
| 621 | 626 | |
| ... | ... | @@ -623,17 +628,17 @@ static IrInstruction *ir_build_const_scope(IrBuilder *irb, Scope *parent_scope, |
| 623 | 628 | Scope *target_scope) |
| 624 | 629 | { |
| 625 | 630 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, parent_scope, source_node); |
| 626 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block; |
| 627 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 628 | | const_instruction->base.static_value.data.x_block = target_scope; |
| 631 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_block; |
| 632 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 633 | const_instruction->base.value.data.x_block = target_scope; |
| 629 | 634 | return &const_instruction->base; |
| 630 | 635 | } |
| 631 | 636 | |
| 632 | 637 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { |
| 633 | 638 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 634 | | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_bool; |
| 635 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 636 | | const_instruction->base.static_value.data.x_bool = value; |
| 639 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool; |
| 640 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 641 | const_instruction->base.value.data.x_bool = value; |
| 637 | 642 | return &const_instruction->base; |
| 638 | 643 | } |
| 639 | 644 | |
| ... | ... | @@ -641,21 +646,17 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN |
| 641 | 646 | FnTableEntry *fn_entry, IrInstruction *first_arg, bool depends_on_compile_var) |
| 642 | 647 | { |
| 643 | 648 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 644 | | const_instruction->base.type_entry = get_bound_fn_type(irb->codegen, fn_entry); |
| 645 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 646 | | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; |
| 647 | | const_instruction->base.static_value.data.x_bound_fn.fn = fn_entry; |
| 648 | | const_instruction->base.static_value.data.x_bound_fn.first_arg = first_arg; |
| 649 | const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); |
| 650 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 651 | const_instruction->base.value.depends_on_compile_var = depends_on_compile_var; |
| 652 | const_instruction->base.value.data.x_bound_fn.fn = fn_entry; |
| 653 | const_instruction->base.value.data.x_bound_fn.first_arg = first_arg; |
| 649 | 654 | return &const_instruction->base; |
| 650 | 655 | } |
| 651 | 656 | |
| 652 | 657 | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 653 | 658 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| 654 | | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; |
| 655 | | TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str)); |
| 656 | | const_instruction->base.type_entry = type_entry; |
| 657 | | ConstExprValue *const_val = &const_instruction->base.static_value; |
| 658 | | init_const_str_lit(const_val, str); |
| 659 | init_const_str_lit(irb->codegen, &const_instruction->base.value, str); |
| 659 | 660 | |
| 660 | 661 | return &const_instruction->base; |
| 661 | 662 | } |
| ... | ... | @@ -666,32 +667,8 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNo |
| 666 | 667 | } |
| 667 | 668 | |
| 668 | 669 | static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 669 | | // first we build the underlying array |
| 670 | | size_t len_with_null = buf_len(str) + 1; |
| 671 | | ConstExprValue *array_val = allocate<ConstExprValue>(1); |
| 672 | | array_val->special = ConstValSpecialStatic; |
| 673 | | array_val->data.x_array.elements = allocate<ConstExprValue>(len_with_null); |
| 674 | | array_val->data.x_array.size = len_with_null; |
| 675 | | for (size_t i = 0; i < buf_len(str); i += 1) { |
| 676 | | ConstExprValue *this_char = &array_val->data.x_array.elements[i]; |
| 677 | | this_char->special = ConstValSpecialStatic; |
| 678 | | bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]); |
| 679 | | } |
| 680 | | ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1]; |
| 681 | | null_char->special = ConstValSpecialStatic; |
| 682 | | bignum_init_unsigned(&null_char->data.x_bignum, 0); |
| 683 | | |
| 684 | | // then make the pointer point to it |
| 685 | 670 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 686 | | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; |
| 687 | | TypeTableEntry *type_entry = get_pointer_to_type(irb->codegen, u8_type, true); |
| 688 | | const_instruction->base.type_entry = type_entry; |
| 689 | | ConstExprValue *ptr_val = &const_instruction->base.static_value; |
| 690 | | ptr_val->special = ConstValSpecialStatic; |
| 691 | | ptr_val->data.x_ptr.base_ptr = array_val; |
| 692 | | ptr_val->data.x_ptr.index = 0; |
| 693 | | ptr_val->data.x_ptr.special = ConstPtrSpecialCStr; |
| 694 | | |
| 671 | init_const_c_str_lit(irb->codegen, &const_instruction->base.value, str); |
| 695 | 672 | return &const_instruction->base; |
| 696 | 673 | } |
| 697 | 674 | |
| ... | ... | @@ -870,8 +847,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source |
| 870 | 847 | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 871 | 848 | { |
| 872 | 849 | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb->exec, scope, source_node); |
| 873 | | br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 874 | | br_instruction->base.static_value.special = ConstValSpecialStatic; |
| 850 | br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 851 | br_instruction->base.value.special = ConstValSpecialStatic; |
| 875 | 852 | br_instruction->dest_block = dest_block; |
| 876 | 853 | br_instruction->is_comptime = is_comptime; |
| 877 | 854 | |
| ... | ... | @@ -983,8 +960,8 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o |
| 983 | 960 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 984 | 961 | IrInstructionUnreachable *unreachable_instruction = |
| 985 | 962 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| 986 | | unreachable_instruction->base.static_value.special = ConstValSpecialStatic; |
| 987 | | unreachable_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 963 | unreachable_instruction->base.value.special = ConstValSpecialStatic; |
| 964 | unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 988 | 965 | return &unreachable_instruction->base; |
| 989 | 966 | } |
| 990 | 967 | |
| ... | ... | @@ -998,8 +975,8 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 998 | 975 | IrInstruction *ptr, IrInstruction *value) |
| 999 | 976 | { |
| 1000 | 977 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| 1001 | | instruction->base.static_value.special = ConstValSpecialStatic; |
| 1002 | | instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 978 | instruction->base.value.special = ConstValSpecialStatic; |
| 979 | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1003 | 980 | instruction->ptr = ptr; |
| 1004 | 981 | instruction->value = value; |
| 1005 | 982 | |
| ... | ... | @@ -1022,8 +999,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 1022 | 999 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value) |
| 1023 | 1000 | { |
| 1024 | 1001 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node); |
| 1025 | | decl_var_instruction->base.static_value.special = ConstValSpecialStatic; |
| 1026 | | decl_var_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 1002 | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1003 | decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1027 | 1004 | decl_var_instruction->var = var; |
| 1028 | 1005 | decl_var_instruction->var_type = var_type; |
| 1029 | 1006 | decl_var_instruction->init_value = init_value; |
| ... | ... | @@ -1302,8 +1279,8 @@ static IrInstruction *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode * |
| 1302 | 1279 | IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime) |
| 1303 | 1280 | { |
| 1304 | 1281 | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); |
| 1305 | | instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 1306 | | instruction->base.static_value.special = ConstValSpecialStatic; |
| 1282 | instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1283 | instruction->base.value.special = ConstValSpecialStatic; |
| 1307 | 1284 | instruction->target_value = target_value; |
| 1308 | 1285 | instruction->else_block = else_block; |
| 1309 | 1286 | instruction->case_count = case_count; |
| ... | ... | @@ -1682,13 +1659,14 @@ static IrInstruction *ir_build_memcpy_from(IrBuilder *irb, IrInstruction *old_in |
| 1682 | 1659 | } |
| 1683 | 1660 | |
| 1684 | 1661 | static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1685 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const) |
| 1662 | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const, bool safety_check_on) |
| 1686 | 1663 | { |
| 1687 | 1664 | IrInstructionSlice *instruction = ir_build_instruction<IrInstructionSlice>(irb, scope, source_node); |
| 1688 | 1665 | instruction->ptr = ptr; |
| 1689 | 1666 | instruction->start = start; |
| 1690 | 1667 | instruction->end = end; |
| 1691 | 1668 | instruction->is_const = is_const; |
| 1669 | instruction->safety_check_on = safety_check_on; |
| 1692 | 1670 | |
| 1693 | 1671 | ir_ref_instruction(ptr); |
| 1694 | 1672 | ir_ref_instruction(start); |
| ... | ... | @@ -1698,9 +1676,10 @@ static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1698 | 1676 | } |
| 1699 | 1677 | |
| 1700 | 1678 | static IrInstruction *ir_build_slice_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1701 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const) |
| 1679 | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const, bool safety_check_on) |
| 1702 | 1680 | { |
| 1703 | | IrInstruction *new_instruction = ir_build_slice(irb, old_instruction->scope, old_instruction->source_node, ptr, start, end, is_const); |
| 1681 | IrInstruction *new_instruction = ir_build_slice(irb, old_instruction->scope, |
| 1682 | old_instruction->source_node, ptr, start, end, is_const, safety_check_on); |
| 1704 | 1683 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1705 | 1684 | return new_instruction; |
| 1706 | 1685 | } |
| ... | ... | @@ -1892,6 +1871,18 @@ static IrInstruction *ir_build_init_enum_from(IrBuilder *irb, IrInstruction *old |
| 1892 | 1871 | return new_instruction; |
| 1893 | 1872 | } |
| 1894 | 1873 | |
| 1874 | static IrInstruction *ir_build_pointer_reinterpret(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1875 | IrInstruction *ptr) |
| 1876 | { |
| 1877 | IrInstructionPointerReinterpret *instruction = ir_build_instruction<IrInstructionPointerReinterpret>( |
| 1878 | irb, scope, source_node); |
| 1879 | instruction->ptr = ptr; |
| 1880 | |
| 1881 | ir_ref_instruction(ptr); |
| 1882 | |
| 1883 | return &instruction->base; |
| 1884 | } |
| 1885 | |
| 1895 | 1886 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 1896 | 1887 | results[ReturnKindUnconditional] = 0; |
| 1897 | 1888 | results[ReturnKindError] = 0; |
| ... | ... | @@ -2088,21 +2079,21 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco |
| 2088 | 2079 | ErrorMsg *msg = add_node_error(codegen, node, |
| 2089 | 2080 | buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); |
| 2090 | 2081 | add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); |
| 2091 | | variable_entry->type = codegen->builtin_types.entry_invalid; |
| 2082 | variable_entry->value.type = codegen->builtin_types.entry_invalid; |
| 2092 | 2083 | } else { |
| 2093 | 2084 | auto primitive_table_entry = codegen->primitive_type_table.maybe_get(name); |
| 2094 | 2085 | if (primitive_table_entry) { |
| 2095 | 2086 | TypeTableEntry *type = primitive_table_entry->value; |
| 2096 | 2087 | add_node_error(codegen, node, |
| 2097 | 2088 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); |
| 2098 | | variable_entry->type = codegen->builtin_types.entry_invalid; |
| 2089 | variable_entry->value.type = codegen->builtin_types.entry_invalid; |
| 2099 | 2090 | } else { |
| 2100 | 2091 | Tld *tld = find_decl(parent_scope, name); |
| 2101 | 2092 | if (tld && tld->id != TldIdVar) { |
| 2102 | 2093 | ErrorMsg *msg = add_node_error(codegen, node, |
| 2103 | 2094 | buf_sprintf("redefinition of '%s'", buf_ptr(name))); |
| 2104 | 2095 | add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here")); |
| 2105 | | variable_entry->type = codegen->builtin_types.entry_invalid; |
| 2096 | variable_entry->value.type = codegen->builtin_types.entry_invalid; |
| 2106 | 2097 | } |
| 2107 | 2098 | } |
| 2108 | 2099 | } |
| ... | ... | @@ -3275,7 +3266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 3275 | 3266 | // is inside var->child_scope |
| 3276 | 3267 | |
| 3277 | 3268 | if (!is_extern && !variable_declaration->expr) { |
| 3278 | | var->type = irb->codegen->builtin_types.entry_invalid; |
| 3269 | var->value.type = irb->codegen->builtin_types.entry_invalid; |
| 3279 | 3270 | add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized")); |
| 3280 | 3271 | return irb->codegen->invalid_instruction; |
| 3281 | 3272 | } |
| ... | ... | @@ -3988,7 +3979,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node) |
| 3988 | 3979 | end_value = nullptr; |
| 3989 | 3980 | } |
| 3990 | 3981 | |
| 3991 | | return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, slice_expr->is_const); |
| 3982 | return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, slice_expr->is_const, true); |
| 3992 | 3983 | } |
| 3993 | 3984 | |
| 3994 | 3985 | static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| ... | ... | @@ -4348,7 +4339,7 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) { |
| 4348 | 4339 | if (instruction->id == IrInstructionIdReturn) { |
| 4349 | 4340 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; |
| 4350 | 4341 | IrInstruction *value = ret_inst->value; |
| 4351 | | assert(value->static_value.special != ConstValSpecialRuntime); |
| 4342 | assert(value->value.special != ConstValSpecialRuntime); |
| 4352 | 4343 | return value; |
| 4353 | 4344 | } else if (ir_has_side_effects(instruction)) { |
| 4354 | 4345 | return nullptr; |
| ... | ... | @@ -4372,7 +4363,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 4372 | 4363 | return false; |
| 4373 | 4364 | } |
| 4374 | 4365 | |
| 4375 | | ConstExprValue *const_val = &instruction->static_value; |
| 4366 | ConstExprValue *const_val = &instruction->value; |
| 4376 | 4367 | assert(const_val->special != ConstValSpecialRuntime); |
| 4377 | 4368 | if (other_type_underlying->id == TypeTableEntryIdFloat) { |
| 4378 | 4369 | return true; |
| ... | ... | @@ -4514,15 +4505,15 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 4514 | 4505 | static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) { |
| 4515 | 4506 | assert(instruction_count >= 1); |
| 4516 | 4507 | IrInstruction *prev_inst = instructions[0]; |
| 4517 | | if (prev_inst->type_entry->id == TypeTableEntryIdInvalid) { |
| 4508 | if (prev_inst->value.type->id == TypeTableEntryIdInvalid) { |
| 4518 | 4509 | return ira->codegen->builtin_types.entry_invalid; |
| 4519 | 4510 | } |
| 4520 | | bool any_are_pure_error = (prev_inst->type_entry->id == TypeTableEntryIdPureError); |
| 4521 | | bool any_are_null = (prev_inst->type_entry->id == TypeTableEntryIdNullLit); |
| 4511 | bool any_are_pure_error = (prev_inst->value.type->id == TypeTableEntryIdPureError); |
| 4512 | bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNullLit); |
| 4522 | 4513 | for (size_t i = 1; i < instruction_count; i += 1) { |
| 4523 | 4514 | IrInstruction *cur_inst = instructions[i]; |
| 4524 | | TypeTableEntry *cur_type = cur_inst->type_entry; |
| 4525 | | TypeTableEntry *prev_type = prev_inst->type_entry; |
| 4515 | TypeTableEntry *cur_type = cur_inst->value.type; |
| 4516 | TypeTableEntry *prev_type = prev_inst->value.type; |
| 4526 | 4517 | if (cur_type->id == TypeTableEntryIdInvalid) { |
| 4527 | 4518 | return cur_type; |
| 4528 | 4519 | } else if (prev_type->id == TypeTableEntryIdUnreachable) { |
| ... | ... | @@ -4598,32 +4589,32 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 4598 | 4589 | return ira->codegen->builtin_types.entry_invalid; |
| 4599 | 4590 | } |
| 4600 | 4591 | } |
| 4601 | | if (any_are_pure_error && prev_inst->type_entry->id != TypeTableEntryIdPureError) { |
| 4602 | | if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt || |
| 4603 | | prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat) |
| 4592 | if (any_are_pure_error && prev_inst->value.type->id != TypeTableEntryIdPureError) { |
| 4593 | if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt || |
| 4594 | prev_inst->value.type->id == TypeTableEntryIdNumLitFloat) |
| 4604 | 4595 | { |
| 4605 | 4596 | ir_add_error_node(ira, source_node, |
| 4606 | 4597 | buf_sprintf("unable to make error union out of number literal")); |
| 4607 | 4598 | return ira->codegen->builtin_types.entry_invalid; |
| 4608 | | } else if (prev_inst->type_entry->id == TypeTableEntryIdNullLit) { |
| 4599 | } else if (prev_inst->value.type->id == TypeTableEntryIdNullLit) { |
| 4609 | 4600 | ir_add_error_node(ira, source_node, |
| 4610 | 4601 | buf_sprintf("unable to make error union out of null literal")); |
| 4611 | 4602 | return ira->codegen->builtin_types.entry_invalid; |
| 4612 | 4603 | } else { |
| 4613 | | return get_error_type(ira->codegen, prev_inst->type_entry); |
| 4604 | return get_error_type(ira->codegen, prev_inst->value.type); |
| 4614 | 4605 | } |
| 4615 | | } else if (any_are_null && prev_inst->type_entry->id != TypeTableEntryIdNullLit) { |
| 4616 | | if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt || |
| 4617 | | prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat) |
| 4606 | } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNullLit) { |
| 4607 | if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt || |
| 4608 | prev_inst->value.type->id == TypeTableEntryIdNumLitFloat) |
| 4618 | 4609 | { |
| 4619 | 4610 | ir_add_error_node(ira, source_node, |
| 4620 | 4611 | buf_sprintf("unable to make maybe out of number literal")); |
| 4621 | 4612 | return ira->codegen->builtin_types.entry_invalid; |
| 4622 | 4613 | } else { |
| 4623 | | return get_maybe_type(ira->codegen, prev_inst->type_entry); |
| 4614 | return get_maybe_type(ira->codegen, prev_inst->value.type); |
| 4624 | 4615 | } |
| 4625 | 4616 | } else { |
| 4626 | | return prev_inst->type_entry; |
| 4617 | return prev_inst->value.type; |
| 4627 | 4618 | } |
| 4628 | 4619 | } |
| 4629 | 4620 | |
| ... | ... | @@ -4649,9 +4640,7 @@ static void eval_const_expr_implicit_cast(CastOp cast_op, |
| 4649 | 4640 | case CastOpNoop: |
| 4650 | 4641 | case CastOpWidenOrShorten: |
| 4651 | 4642 | *const_val = *other_val; |
| 4652 | | break; |
| 4653 | | case CastOpPointerReinterpret: |
| 4654 | | zig_panic("TODO compile time pointer reinterpret"); |
| 4643 | const_val->type = new_type; |
| 4655 | 4644 | break; |
| 4656 | 4645 | case CastOpPtrToInt: |
| 4657 | 4646 | case CastOpIntToPtr: |
| ... | ... | @@ -4659,24 +4648,6 @@ static void eval_const_expr_implicit_cast(CastOp cast_op, |
| 4659 | 4648 | case CastOpBytesToSlice: |
| 4660 | 4649 | // can't do it |
| 4661 | 4650 | break; |
| 4662 | | case CastOpToUnknownSizeArray: |
| 4663 | | { |
| 4664 | | assert(other_type->id == TypeTableEntryIdArray); |
| 4665 | | assert(other_val->data.x_array.size == other_type->data.array.len); |
| 4666 | | |
| 4667 | | const_val->data.x_struct.fields = allocate<ConstExprValue>(2); |
| 4668 | | ConstExprValue *ptr_field = &const_val->data.x_struct.fields[slice_ptr_index]; |
| 4669 | | ConstExprValue *len_field = &const_val->data.x_struct.fields[slice_len_index]; |
| 4670 | | |
| 4671 | | ptr_field->special = ConstValSpecialStatic; |
| 4672 | | ptr_field->data.x_ptr.base_ptr = other_val; |
| 4673 | | |
| 4674 | | len_field->special = ConstValSpecialStatic; |
| 4675 | | bignum_init_unsigned(&len_field->data.x_bignum, other_type->data.array.len); |
| 4676 | | |
| 4677 | | const_val->special = ConstValSpecialStatic; |
| 4678 | | break; |
| 4679 | | } |
| 4680 | 4651 | case CastOpErrToInt: |
| 4681 | 4652 | { |
| 4682 | 4653 | uint64_t value; |
| ... | ... | @@ -4722,14 +4693,15 @@ static void eval_const_expr_implicit_cast(CastOp cast_op, |
| 4722 | 4693 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 4723 | 4694 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) |
| 4724 | 4695 | { |
| 4725 | | if (value->static_value.special != ConstValSpecialRuntime) { |
| 4726 | | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, false); |
| 4727 | | eval_const_expr_implicit_cast(cast_op, &value->static_value, value->type_entry, |
| 4728 | | &result->static_value, wanted_type); |
| 4696 | if (value->value.special != ConstValSpecialRuntime) { |
| 4697 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 4698 | source_instr->source_node, wanted_type, false); |
| 4699 | eval_const_expr_implicit_cast(cast_op, &value->value, value->value.type, |
| 4700 | &result->value, wanted_type); |
| 4729 | 4701 | return result; |
| 4730 | 4702 | } else { |
| 4731 | 4703 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); |
| 4732 | | result->type_entry = wanted_type; |
| 4704 | result->value.type = wanted_type; |
| 4733 | 4705 | if (need_alloca) { |
| 4734 | 4706 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 4735 | 4707 | if (fn_entry) |
| ... | ... | @@ -4861,7 +4833,7 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in |
| 4861 | 4833 | new_instruction = &const_instruction->base; |
| 4862 | 4834 | } |
| 4863 | 4835 | ir_link_new_instruction(new_instruction, old_instruction); |
| 4864 | | ConstExprValue *const_val = &new_instruction->static_value; |
| 4836 | ConstExprValue *const_val = &new_instruction->value; |
| 4865 | 4837 | const_val->special = ConstValSpecialStatic; |
| 4866 | 4838 | const_val->depends_on_compile_var = depends_on_compile_var; |
| 4867 | 4839 | return const_val; |
| ... | ... | @@ -4906,15 +4878,15 @@ enum UndefAllowed { |
| 4906 | 4878 | }; |
| 4907 | 4879 | |
| 4908 | 4880 | static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 4909 | | switch (value->static_value.special) { |
| 4881 | switch (value->value.special) { |
| 4910 | 4882 | case ConstValSpecialStatic: |
| 4911 | | return &value->static_value; |
| 4883 | return &value->value; |
| 4912 | 4884 | case ConstValSpecialRuntime: |
| 4913 | 4885 | ir_add_error(ira, value, buf_sprintf("unable to evaluate constant expression")); |
| 4914 | 4886 | return nullptr; |
| 4915 | 4887 | case ConstValSpecialUndef: |
| 4916 | 4888 | if (undef_allowed == UndefOk) { |
| 4917 | | return &value->static_value; |
| 4889 | return &value->value; |
| 4918 | 4890 | } else { |
| 4919 | 4891 | ir_add_error(ira, value, buf_sprintf("use of undefined value")); |
| 4920 | 4892 | return nullptr; |
| ... | ... | @@ -4979,12 +4951,12 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 4979 | 4951 | } |
| 4980 | 4952 | |
| 4981 | 4953 | static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 4982 | | if (type_value->type_entry->id == TypeTableEntryIdInvalid) |
| 4954 | if (type_value->value.type->id == TypeTableEntryIdInvalid) |
| 4983 | 4955 | return ira->codegen->builtin_types.entry_invalid; |
| 4984 | 4956 | |
| 4985 | | if (type_value->type_entry->id != TypeTableEntryIdMetaType) { |
| 4957 | if (type_value->value.type->id != TypeTableEntryIdMetaType) { |
| 4986 | 4958 | ir_add_error(ira, type_value, |
| 4987 | | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->type_entry->name))); |
| 4959 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); |
| 4988 | 4960 | return ira->codegen->builtin_types.entry_invalid; |
| 4989 | 4961 | } |
| 4990 | 4962 | |
| ... | ... | @@ -4999,12 +4971,12 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 4999 | 4971 | if (fn_value == ira->codegen->invalid_instruction) |
| 5000 | 4972 | return nullptr; |
| 5001 | 4973 | |
| 5002 | | if (fn_value->type_entry->id == TypeTableEntryIdInvalid) |
| 4974 | if (fn_value->value.type->id == TypeTableEntryIdInvalid) |
| 5003 | 4975 | return nullptr; |
| 5004 | 4976 | |
| 5005 | | if (fn_value->type_entry->id != TypeTableEntryIdFn) { |
| 4977 | if (fn_value->value.type->id != TypeTableEntryIdFn) { |
| 5006 | 4978 | ir_add_error_node(ira, fn_value->source_node, |
| 5007 | | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->type_entry->name))); |
| 4979 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); |
| 5008 | 4980 | return nullptr; |
| 5009 | 4981 | } |
| 5010 | 4982 | |
| ... | ... | @@ -5019,47 +4991,88 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc |
| 5019 | 4991 | assert(wanted_type->id == TypeTableEntryIdMaybe); |
| 5020 | 4992 | |
| 5021 | 4993 | if (instr_is_comptime(value)) { |
| 5022 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 4994 | TypeTableEntry *payload_type = wanted_type->data.maybe.child_type; |
| 4995 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 4996 | if (casted_payload->value.type->id == TypeTableEntryIdInvalid) |
| 4997 | return ira->codegen->invalid_instruction; |
| 4998 | |
| 4999 | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 5023 | 5000 | if (!val) |
| 5024 | 5001 | return ira->codegen->invalid_instruction; |
| 5025 | 5002 | |
| 5026 | 5003 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 5027 | 5004 | source_instr->scope, source_instr->source_node); |
| 5028 | | const_instruction->base.type_entry = wanted_type; |
| 5029 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 5030 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 5031 | | const_instruction->base.static_value.data.x_maybe = &value->static_value; |
| 5005 | const_instruction->base.value.type = wanted_type; |
| 5006 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 5007 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 5008 | const_instruction->base.value.data.x_maybe = val; |
| 5032 | 5009 | return &const_instruction->base; |
| 5033 | 5010 | } |
| 5034 | 5011 | |
| 5035 | 5012 | IrInstruction *result = ir_build_maybe_wrap(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 5036 | | result->type_entry = wanted_type; |
| 5037 | | result->static_value.data.rh_maybe = RuntimeHintMaybeNonNull; |
| 5013 | result->value.type = wanted_type; |
| 5014 | result->value.data.rh_maybe = RuntimeHintMaybeNonNull; |
| 5038 | 5015 | ir_add_alloca(ira, result, wanted_type); |
| 5039 | 5016 | return result; |
| 5040 | 5017 | } |
| 5041 | 5018 | |
| 5042 | | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { |
| 5019 | static IrInstruction *ir_analyze_pointer_reinterpret(IrAnalyze *ira, IrInstruction *source_instr, |
| 5020 | IrInstruction *ptr, TypeTableEntry *wanted_type) |
| 5021 | { |
| 5022 | assert(wanted_type->id == TypeTableEntryIdPointer); |
| 5023 | |
| 5024 | if (ptr->value.type->id != TypeTableEntryIdPointer) { |
| 5025 | ir_add_error(ira, ptr, |
| 5026 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name))); |
| 5027 | return ira->codegen->invalid_instruction; |
| 5028 | } |
| 5029 | |
| 5030 | if (instr_is_comptime(ptr)) { |
| 5031 | ConstExprValue *val = ir_resolve_const(ira, ptr, UndefOk); |
| 5032 | if (!val) |
| 5033 | return ira->codegen->invalid_instruction; |
| 5034 | |
| 5035 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 5036 | source_instr->scope, source_instr->source_node); |
| 5037 | const_instruction->base.value = *val; |
| 5038 | const_instruction->base.value.type = wanted_type; |
| 5039 | return &const_instruction->base; |
| 5040 | } |
| 5041 | |
| 5042 | IrInstruction *result = ir_build_pointer_reinterpret(&ira->new_irb, source_instr->scope, |
| 5043 | source_instr->source_node, ptr); |
| 5044 | result->value.type = wanted_type; |
| 5045 | return result; |
| 5046 | } |
| 5047 | |
| 5048 | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 5049 | IrInstruction *value, TypeTableEntry *wanted_type) |
| 5050 | { |
| 5043 | 5051 | assert(wanted_type->id == TypeTableEntryIdErrorUnion); |
| 5044 | 5052 | |
| 5045 | 5053 | if (instr_is_comptime(value)) { |
| 5046 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 5054 | TypeTableEntry *payload_type = wanted_type->data.error.child_type; |
| 5055 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 5056 | if (casted_payload->value.type->id == TypeTableEntryIdInvalid) |
| 5057 | return ira->codegen->invalid_instruction; |
| 5058 | |
| 5059 | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 5047 | 5060 | if (!val) |
| 5048 | 5061 | return ira->codegen->invalid_instruction; |
| 5049 | 5062 | |
| 5050 | 5063 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 5051 | 5064 | source_instr->scope, source_instr->source_node); |
| 5052 | | const_instruction->base.type_entry = wanted_type; |
| 5053 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 5054 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 5055 | | const_instruction->base.static_value.data.x_err_union.err = nullptr; |
| 5056 | | const_instruction->base.static_value.data.x_err_union.payload = val; |
| 5065 | const_instruction->base.value.type = wanted_type; |
| 5066 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 5067 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 5068 | const_instruction->base.value.data.x_err_union.err = nullptr; |
| 5069 | const_instruction->base.value.data.x_err_union.payload = val; |
| 5057 | 5070 | return &const_instruction->base; |
| 5058 | 5071 | } |
| 5059 | 5072 | |
| 5060 | 5073 | IrInstruction *result = ir_build_err_wrap_payload(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 5061 | | result->type_entry = wanted_type; |
| 5062 | | result->static_value.data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 5074 | result->value.type = wanted_type; |
| 5075 | result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 5063 | 5076 | ir_add_alloca(ira, result, wanted_type); |
| 5064 | 5077 | return result; |
| 5065 | 5078 | } |
| ... | ... | @@ -5074,17 +5087,17 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 5074 | 5087 | |
| 5075 | 5088 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 5076 | 5089 | source_instr->scope, source_instr->source_node); |
| 5077 | | const_instruction->base.type_entry = wanted_type; |
| 5078 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 5079 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 5080 | | const_instruction->base.static_value.data.x_err_union.err = val->data.x_pure_err; |
| 5081 | | const_instruction->base.static_value.data.x_err_union.payload = nullptr; |
| 5090 | const_instruction->base.value.type = wanted_type; |
| 5091 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 5092 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 5093 | const_instruction->base.value.data.x_err_union.err = val->data.x_pure_err; |
| 5094 | const_instruction->base.value.data.x_err_union.payload = nullptr; |
| 5082 | 5095 | return &const_instruction->base; |
| 5083 | 5096 | } |
| 5084 | 5097 | |
| 5085 | 5098 | IrInstruction *result = ir_build_err_wrap_code(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 5086 | | result->type_entry = wanted_type; |
| 5087 | | result->static_value.data.rh_error_union = RuntimeHintErrorUnionError; |
| 5099 | result->value.type = wanted_type; |
| 5100 | result->value.data.rh_error_union = RuntimeHintErrorUnionError; |
| 5088 | 5101 | ir_add_alloca(ira, result, wanted_type); |
| 5089 | 5102 | return result; |
| 5090 | 5103 | } |
| ... | ... | @@ -5097,11 +5110,11 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ |
| 5097 | 5110 | |
| 5098 | 5111 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 5099 | 5112 | source_instr->scope, source_instr->source_node); |
| 5100 | | const_instruction->base.type_entry = wanted_type; |
| 5101 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 5102 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 5103 | | const_instruction->base.static_value.data.x_ptr.base_ptr = val; |
| 5104 | | const_instruction->base.static_value.data.x_ptr.index = SIZE_MAX; |
| 5113 | const_instruction->base.value.type = wanted_type; |
| 5114 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 5115 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 5116 | const_instruction->base.value.data.x_ptr.base_ptr = val; |
| 5117 | const_instruction->base.value.data.x_ptr.index = SIZE_MAX; |
| 5105 | 5118 | return &const_instruction->base; |
| 5106 | 5119 | } |
| 5107 | 5120 | |
| ... | ... | @@ -5130,17 +5143,48 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 5130 | 5143 | assert(val); |
| 5131 | 5144 | |
| 5132 | 5145 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, source_instr->scope, source_instr->source_node); |
| 5133 | | const_instruction->base.type_entry = wanted_type; |
| 5134 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 5135 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 5136 | | const_instruction->base.static_value.data.x_maybe = nullptr; |
| 5146 | const_instruction->base.value.type = wanted_type; |
| 5147 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 5148 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 5149 | const_instruction->base.value.data.x_maybe = nullptr; |
| 5137 | 5150 | return &const_instruction->base; |
| 5138 | 5151 | } |
| 5139 | 5152 | |
| 5153 | static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 5154 | IrInstruction *array, TypeTableEntry *wanted_type) |
| 5155 | { |
| 5156 | assert(is_slice(wanted_type)); |
| 5157 | |
| 5158 | TypeTableEntry *array_type = array->value.type; |
| 5159 | assert(array_type->id == TypeTableEntryIdArray); |
| 5160 | |
| 5161 | if (instr_is_comptime(array)) { |
| 5162 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 5163 | source_instr->source_node, wanted_type, false); |
| 5164 | init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true); |
| 5165 | return result; |
| 5166 | } |
| 5167 | |
| 5168 | IrInstruction *start = ir_create_const(&ira->new_irb, source_instr->scope, |
| 5169 | source_instr->source_node, ira->codegen->builtin_types.entry_usize, false); |
| 5170 | init_const_usize(ira->codegen, &start->value, 0); |
| 5171 | |
| 5172 | IrInstruction *end = ir_create_const(&ira->new_irb, source_instr->scope, |
| 5173 | source_instr->source_node, ira->codegen->builtin_types.entry_usize, false); |
| 5174 | init_const_usize(ira->codegen, &end->value, array_type->data.array.len); |
| 5175 | |
| 5176 | IrInstruction *result = ir_build_slice(&ira->new_irb, source_instr->scope, |
| 5177 | source_instr->source_node, array, start, end, true, false); |
| 5178 | TypeTableEntry *child_type = array_type->data.array.child_type; |
| 5179 | result->value.type = get_slice_type(ira->codegen, child_type, true); |
| 5180 | ir_add_alloca(ira, result, result->value.type); |
| 5181 | return result; |
| 5182 | } |
| 5183 | |
| 5140 | 5184 | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 5141 | 5185 | TypeTableEntry *wanted_type, IrInstruction *value) |
| 5142 | 5186 | { |
| 5143 | | TypeTableEntry *actual_type = value->type_entry; |
| 5187 | TypeTableEntry *actual_type = value->value.type; |
| 5144 | 5188 | TypeTableEntry *wanted_type_canon = get_underlying_type(wanted_type); |
| 5145 | 5189 | TypeTableEntry *actual_type_canon = get_underlying_type(actual_type); |
| 5146 | 5190 | |
| ... | ... | @@ -5213,7 +5257,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 5213 | 5257 | wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type, |
| 5214 | 5258 | actual_type->data.array.child_type)) |
| 5215 | 5259 | { |
| 5216 | | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpToUnknownSizeArray, true); |
| 5260 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 5217 | 5261 | } |
| 5218 | 5262 | |
| 5219 | 5263 | // explicit cast from []T to []u8 or []u8 to []T |
| ... | ... | @@ -5251,7 +5295,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 5251 | 5295 | if ((actual_type->id == TypeTableEntryIdPointer || actual_type->id == TypeTableEntryIdFn) && |
| 5252 | 5296 | (wanted_type->id == TypeTableEntryIdPointer || wanted_type->id == TypeTableEntryIdFn)) |
| 5253 | 5297 | { |
| 5254 | | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpPointerReinterpret, false); |
| 5298 | return ir_analyze_pointer_reinterpret(ira, source_instr, value, wanted_type); |
| 5255 | 5299 | } |
| 5256 | 5300 | |
| 5257 | 5301 | // explicit cast from maybe pointer to another maybe pointer |
| ... | ... | @@ -5262,7 +5306,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 5262 | 5306 | (wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer || |
| 5263 | 5307 | wanted_type->data.maybe.child_type->id == TypeTableEntryIdFn)) |
| 5264 | 5308 | { |
| 5265 | | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpPointerReinterpret, false); |
| 5309 | return ir_analyze_pointer_reinterpret(ira, source_instr, value, wanted_type); |
| 5266 | 5310 | } |
| 5267 | 5311 | |
| 5268 | 5312 | // explicit cast from child type of maybe type to maybe type |
| ... | ... | @@ -5394,22 +5438,22 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 5394 | 5438 | assert(value); |
| 5395 | 5439 | assert(value != ira->codegen->invalid_instruction); |
| 5396 | 5440 | assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid); |
| 5397 | | assert(value->type_entry); |
| 5398 | | assert(value->type_entry->id != TypeTableEntryIdInvalid); |
| 5441 | assert(value->value.type); |
| 5442 | assert(value->value.type->id != TypeTableEntryIdInvalid); |
| 5399 | 5443 | if (expected_type == nullptr) |
| 5400 | 5444 | return value; // anything will do |
| 5401 | | if (expected_type == value->type_entry) |
| 5445 | if (expected_type == value->value.type) |
| 5402 | 5446 | return value; // match |
| 5403 | | if (value->type_entry->id == TypeTableEntryIdUnreachable) |
| 5447 | if (value->value.type->id == TypeTableEntryIdUnreachable) |
| 5404 | 5448 | return value; |
| 5405 | 5449 | |
| 5406 | | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->type_entry, value); |
| 5450 | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->value.type, value); |
| 5407 | 5451 | switch (result) { |
| 5408 | 5452 | case ImplicitCastMatchResultNo: |
| 5409 | 5453 | ir_add_error(ira, value, |
| 5410 | 5454 | buf_sprintf("expected type '%s', found '%s'", |
| 5411 | 5455 | buf_ptr(&expected_type->name), |
| 5412 | | buf_ptr(&value->type_entry->name))); |
| 5456 | buf_ptr(&value->value.type->name))); |
| 5413 | 5457 | return ira->codegen->invalid_instruction; |
| 5414 | 5458 | |
| 5415 | 5459 | case ImplicitCastMatchResultYes: |
| ... | ... | @@ -5422,23 +5466,23 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 5422 | 5466 | } |
| 5423 | 5467 | |
| 5424 | 5468 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) { |
| 5425 | | TypeTableEntry *type_entry = ptr->type_entry; |
| 5469 | TypeTableEntry *type_entry = ptr->value.type; |
| 5426 | 5470 | if (type_entry->id == TypeTableEntryIdInvalid) { |
| 5427 | 5471 | return ira->codegen->invalid_instruction; |
| 5428 | 5472 | } else if (type_entry->id == TypeTableEntryIdPointer) { |
| 5429 | 5473 | TypeTableEntry *child_type = type_entry->data.pointer.child_type; |
| 5430 | | if (ptr->static_value.special != ConstValSpecialRuntime) { |
| 5431 | | ConstExprValue *pointee = const_ptr_pointee(&ptr->static_value); |
| 5474 | if (ptr->value.special != ConstValSpecialRuntime) { |
| 5475 | ConstExprValue *pointee = const_ptr_pointee(&ptr->value); |
| 5432 | 5476 | if (pointee->special != ConstValSpecialRuntime) { |
| 5433 | 5477 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, |
| 5434 | 5478 | source_instruction->source_node, child_type, pointee->depends_on_compile_var); |
| 5435 | | result->static_value = *pointee; |
| 5479 | result->value = *pointee; |
| 5436 | 5480 | return result; |
| 5437 | 5481 | } |
| 5438 | 5482 | } |
| 5439 | 5483 | // TODO if the instruction is a get pointer instruction we can skip it |
| 5440 | 5484 | IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr); |
| 5441 | | load_ptr_instruction->type_entry = child_type; |
| 5485 | load_ptr_instruction->value.type = child_type; |
| 5442 | 5486 | return load_ptr_instruction; |
| 5443 | 5487 | } else if (type_entry->id == TypeTableEntryIdMetaType) { |
| 5444 | 5488 | ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad); |
| ... | ... | @@ -5465,18 +5509,18 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 5465 | 5509 | static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 5466 | 5510 | bool is_const) |
| 5467 | 5511 | { |
| 5468 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5512 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5469 | 5513 | return ira->codegen->builtin_types.entry_invalid; |
| 5470 | 5514 | |
| 5471 | 5515 | if (instr_is_comptime(value)) { |
| 5472 | 5516 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 5473 | 5517 | if (!val) |
| 5474 | 5518 | return ira->codegen->builtin_types.entry_invalid; |
| 5475 | | return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry, |
| 5519 | return ir_analyze_const_ptr(ira, source_instruction, val, value->value.type, |
| 5476 | 5520 | false, ConstPtrSpecialNone, is_const); |
| 5477 | 5521 | } |
| 5478 | 5522 | |
| 5479 | | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, value->type_entry, true); |
| 5523 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, value->value.type, true); |
| 5480 | 5524 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 5481 | 5525 | assert(fn_entry); |
| 5482 | 5526 | IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value, is_const); |
| ... | ... | @@ -5485,11 +5529,11 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst |
| 5485 | 5529 | } |
| 5486 | 5530 | |
| 5487 | 5531 | static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) { |
| 5488 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5532 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5489 | 5533 | return false; |
| 5490 | 5534 | |
| 5491 | 5535 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize); |
| 5492 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 5536 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 5493 | 5537 | return false; |
| 5494 | 5538 | |
| 5495 | 5539 | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -5501,11 +5545,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out |
| 5501 | 5545 | } |
| 5502 | 5546 | |
| 5503 | 5547 | static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 5504 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5548 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5505 | 5549 | return false; |
| 5506 | 5550 | |
| 5507 | 5551 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 5508 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 5552 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 5509 | 5553 | return false; |
| 5510 | 5554 | |
| 5511 | 5555 | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -5517,11 +5561,11 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 5517 | 5561 | } |
| 5518 | 5562 | |
| 5519 | 5563 | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { |
| 5520 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5564 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5521 | 5565 | return false; |
| 5522 | 5566 | |
| 5523 | 5567 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum); |
| 5524 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 5568 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 5525 | 5569 | return false; |
| 5526 | 5570 | |
| 5527 | 5571 | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -5533,12 +5577,12 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 5533 | 5577 | } |
| 5534 | 5578 | |
| 5535 | 5579 | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 5536 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5580 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5537 | 5581 | return nullptr; |
| 5538 | 5582 | |
| 5539 | 5583 | TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true); |
| 5540 | 5584 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 5541 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 5585 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 5542 | 5586 | return nullptr; |
| 5543 | 5587 | |
| 5544 | 5588 | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -5567,7 +5611,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, |
| 5567 | 5611 | IrInstructionReturn *return_instruction) |
| 5568 | 5612 | { |
| 5569 | 5613 | IrInstruction *value = return_instruction->value->other; |
| 5570 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 5614 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 5571 | 5615 | return ir_unreach_error(ira); |
| 5572 | 5616 | ira->implicit_return_type_list.append(value); |
| 5573 | 5617 | |
| ... | ... | @@ -5580,19 +5624,19 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, |
| 5580 | 5624 | } |
| 5581 | 5625 | |
| 5582 | 5626 | static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { |
| 5583 | | bool depends_on_compile_var = const_instruction->base.static_value.depends_on_compile_var; |
| 5627 | bool depends_on_compile_var = const_instruction->base.value.depends_on_compile_var; |
| 5584 | 5628 | ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base, depends_on_compile_var); |
| 5585 | | *out_val = const_instruction->base.static_value; |
| 5586 | | return const_instruction->base.type_entry; |
| 5629 | *out_val = const_instruction->base.value; |
| 5630 | return const_instruction->base.value.type; |
| 5587 | 5631 | } |
| 5588 | 5632 | |
| 5589 | 5633 | static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 5590 | 5634 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 5591 | | if (op1->type_entry->id == TypeTableEntryIdInvalid) |
| 5635 | if (op1->value.type->id == TypeTableEntryIdInvalid) |
| 5592 | 5636 | return ira->codegen->builtin_types.entry_invalid; |
| 5593 | 5637 | |
| 5594 | 5638 | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 5595 | | if (op2->type_entry->id == TypeTableEntryIdInvalid) |
| 5639 | if (op2->value.type->id == TypeTableEntryIdInvalid) |
| 5596 | 5640 | return ira->codegen->builtin_types.entry_invalid; |
| 5597 | 5641 | |
| 5598 | 5642 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -5605,14 +5649,14 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 5605 | 5649 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 5606 | 5650 | return ira->codegen->builtin_types.entry_invalid; |
| 5607 | 5651 | |
| 5608 | | ConstExprValue *op1_val = &casted_op1->static_value; |
| 5609 | | ConstExprValue *op2_val = &casted_op2->static_value; |
| 5652 | ConstExprValue *op1_val = &casted_op1->value; |
| 5653 | ConstExprValue *op2_val = &casted_op2->value; |
| 5610 | 5654 | if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) { |
| 5611 | 5655 | bool depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var; |
| 5612 | 5656 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var); |
| 5613 | 5657 | |
| 5614 | | assert(casted_op1->type_entry->id == TypeTableEntryIdBool); |
| 5615 | | assert(casted_op2->type_entry->id == TypeTableEntryIdBool); |
| 5658 | assert(casted_op1->value.type->id == TypeTableEntryIdBool); |
| 5659 | assert(casted_op2->value.type->id == TypeTableEntryIdBool); |
| 5616 | 5660 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 5617 | 5661 | out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| 5618 | 5662 | } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { |
| ... | ... | @@ -5701,8 +5745,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 5701 | 5745 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 5702 | 5746 | return ira->codegen->builtin_types.entry_invalid; |
| 5703 | 5747 | |
| 5704 | | ConstExprValue *op1_val = &casted_op1->static_value; |
| 5705 | | ConstExprValue *op2_val = &casted_op2->static_value; |
| 5748 | ConstExprValue *op1_val = &casted_op1->value; |
| 5749 | ConstExprValue *op2_val = &casted_op2->value; |
| 5706 | 5750 | if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) { |
| 5707 | 5751 | bool type_can_gt_lt_cmp = (resolved_type->id == TypeTableEntryIdNumLitFloat || |
| 5708 | 5752 | resolved_type->id == TypeTableEntryIdNumLitInt || |
| ... | ... | @@ -5729,7 +5773,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 5729 | 5773 | |
| 5730 | 5774 | answer = bignum_cmp(&op1_val->data.x_bignum, &op2_val->data.x_bignum); |
| 5731 | 5775 | } else { |
| 5732 | | bool are_equal = const_values_equal(op1_val, op2_val, resolved_type); |
| 5776 | bool are_equal = const_values_equal(op1_val, op2_val); |
| 5733 | 5777 | if (op_id == IrBinOpCmpEq) { |
| 5734 | 5778 | answer = are_equal; |
| 5735 | 5779 | } else if (op_id == IrBinOpCmpNotEq) { |
| ... | ... | @@ -5872,8 +5916,8 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 5872 | 5916 | AstNode *source_node = bin_op_instruction->base.source_node; |
| 5873 | 5917 | ir_add_error_node(ira, source_node, |
| 5874 | 5918 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 5875 | | buf_ptr(&op1->type_entry->name), |
| 5876 | | buf_ptr(&op2->type_entry->name))); |
| 5919 | buf_ptr(&op1->value.type->name), |
| 5920 | buf_ptr(&op2->value.type->name))); |
| 5877 | 5921 | return ira->codegen->builtin_types.entry_invalid; |
| 5878 | 5922 | } |
| 5879 | 5923 | |
| ... | ... | @@ -5886,10 +5930,10 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 5886 | 5930 | return ira->codegen->builtin_types.entry_invalid; |
| 5887 | 5931 | |
| 5888 | 5932 | |
| 5889 | | if (casted_op1->static_value.special != ConstValSpecialRuntime && casted_op2->static_value.special != ConstValSpecialRuntime) { |
| 5890 | | ConstExprValue *op1_val = &casted_op1->static_value; |
| 5891 | | ConstExprValue *op2_val = &casted_op2->static_value; |
| 5892 | | ConstExprValue *out_val = &bin_op_instruction->base.static_value; |
| 5933 | if (casted_op1->value.special != ConstValSpecialRuntime && casted_op2->value.special != ConstValSpecialRuntime) { |
| 5934 | ConstExprValue *op1_val = &casted_op1->value; |
| 5935 | ConstExprValue *op2_val = &casted_op2->value; |
| 5936 | ConstExprValue *out_val = &bin_op_instruction->base.value; |
| 5893 | 5937 | |
| 5894 | 5938 | bin_op_instruction->base.other = &bin_op_instruction->base; |
| 5895 | 5939 | |
| ... | ... | @@ -5919,12 +5963,12 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 5919 | 5963 | |
| 5920 | 5964 | static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 5921 | 5965 | IrInstruction *op1 = instruction->op1->other; |
| 5922 | | TypeTableEntry *op1_canon_type = get_underlying_type(op1->type_entry); |
| 5966 | TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type); |
| 5923 | 5967 | if (op1_canon_type->id == TypeTableEntryIdInvalid) |
| 5924 | 5968 | return ira->codegen->builtin_types.entry_invalid; |
| 5925 | 5969 | |
| 5926 | 5970 | IrInstruction *op2 = instruction->op2->other; |
| 5927 | | TypeTableEntry *op2_canon_type = get_underlying_type(op2->type_entry); |
| 5971 | TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type); |
| 5928 | 5972 | if (op2_canon_type->id == TypeTableEntryIdInvalid) |
| 5929 | 5973 | return ira->codegen->builtin_types.entry_invalid; |
| 5930 | 5974 | |
| ... | ... | @@ -5955,7 +5999,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 5955 | 5999 | op1_array_end = op1_array_val->data.x_array.size - 1; |
| 5956 | 6000 | } else { |
| 5957 | 6001 | ir_add_error(ira, op1, |
| 5958 | | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->type_entry->name))); |
| 6002 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name))); |
| 5959 | 6003 | // TODO if meta_type is type decl, add note pointing to type decl declaration |
| 5960 | 6004 | return ira->codegen->builtin_types.entry_invalid; |
| 5961 | 6005 | } |
| ... | ... | @@ -5967,7 +6011,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 5967 | 6011 | if (op2_canon_type->data.array.child_type != child_type) { |
| 5968 | 6012 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 5969 | 6013 | buf_ptr(&child_type->name), |
| 5970 | | buf_ptr(&op2->type_entry->name))); |
| 6014 | buf_ptr(&op2->value.type->name))); |
| 5971 | 6015 | return ira->codegen->builtin_types.entry_invalid; |
| 5972 | 6016 | } |
| 5973 | 6017 | op2_array_val = op2_val; |
| ... | ... | @@ -5980,7 +6024,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 5980 | 6024 | if (child_type != ira->codegen->builtin_types.entry_u8) { |
| 5981 | 6025 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 5982 | 6026 | buf_ptr(&child_type->name), |
| 5983 | | buf_ptr(&op2->type_entry->name))); |
| 6027 | buf_ptr(&op2->value.type->name))); |
| 5984 | 6028 | return ira->codegen->builtin_types.entry_invalid; |
| 5985 | 6029 | } |
| 5986 | 6030 | op2_array_val = op2_val->data.x_ptr.base_ptr; |
| ... | ... | @@ -5988,12 +6032,12 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 5988 | 6032 | op2_array_end = op2_array_val->data.x_array.size - 1; |
| 5989 | 6033 | } else { |
| 5990 | 6034 | ir_add_error(ira, op2, |
| 5991 | | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->type_entry->name))); |
| 6035 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name))); |
| 5992 | 6036 | // TODO if meta_type is type decl, add note pointing to type decl declaration |
| 5993 | 6037 | return ira->codegen->builtin_types.entry_invalid; |
| 5994 | 6038 | } |
| 5995 | 6039 | |
| 5996 | | bool depends_on_compile_var = op1->static_value.depends_on_compile_var || op2->static_value.depends_on_compile_var; |
| 6040 | bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var; |
| 5997 | 6041 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 5998 | 6042 | |
| 5999 | 6043 | TypeTableEntry *result_type; |
| ... | ... | @@ -6008,6 +6052,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 6008 | 6052 | |
| 6009 | 6053 | out_array_val = allocate<ConstExprValue>(1); |
| 6010 | 6054 | out_array_val->special = ConstValSpecialStatic; |
| 6055 | out_array_val->type = result_type; |
| 6011 | 6056 | out_val->data.x_ptr.base_ptr = out_array_val; |
| 6012 | 6057 | out_val->data.x_ptr.index = 0; |
| 6013 | 6058 | out_val->data.x_ptr.special = ConstPtrSpecialCStr; |
| ... | ... | @@ -6026,8 +6071,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 6026 | 6071 | } |
| 6027 | 6072 | if (next_index < new_len) { |
| 6028 | 6073 | ConstExprValue *null_byte = &out_array_val->data.x_array.elements[next_index]; |
| 6029 | | null_byte->special = ConstValSpecialStatic; |
| 6030 | | bignum_init_unsigned(&null_byte->data.x_bignum, 0); |
| 6074 | init_const_unsigned_negative(null_byte, child_type, 0, false); |
| 6031 | 6075 | next_index += 1; |
| 6032 | 6076 | } |
| 6033 | 6077 | assert(next_index == new_len); |
| ... | ... | @@ -6037,11 +6081,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 6037 | 6081 | |
| 6038 | 6082 | static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 6039 | 6083 | IrInstruction *op1 = instruction->op1->other; |
| 6040 | | if (op1->type_entry->id == TypeTableEntryIdInvalid) |
| 6084 | if (op1->value.type->id == TypeTableEntryIdInvalid) |
| 6041 | 6085 | return ira->codegen->builtin_types.entry_invalid; |
| 6042 | 6086 | |
| 6043 | 6087 | IrInstruction *op2 = instruction->op2->other; |
| 6044 | | if (op2->type_entry->id == TypeTableEntryIdInvalid) |
| 6088 | if (op2->value.type->id == TypeTableEntryIdInvalid) |
| 6045 | 6089 | return ira->codegen->builtin_types.entry_invalid; |
| 6046 | 6090 | |
| 6047 | 6091 | ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad); |
| ... | ... | @@ -6052,9 +6096,9 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 6052 | 6096 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 6053 | 6097 | return ira->codegen->builtin_types.entry_invalid; |
| 6054 | 6098 | |
| 6055 | | TypeTableEntry *array_canon_type = get_underlying_type(op1->type_entry); |
| 6099 | TypeTableEntry *array_canon_type = get_underlying_type(op1->value.type); |
| 6056 | 6100 | if (array_canon_type->id != TypeTableEntryIdArray) { |
| 6057 | | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->type_entry->name))); |
| 6101 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 6058 | 6102 | // TODO if meta_type is type decl, add note pointing to type decl declaration |
| 6059 | 6103 | return ira->codegen->builtin_types.entry_invalid; |
| 6060 | 6104 | } |
| ... | ... | @@ -6068,7 +6112,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 6068 | 6112 | return ira->codegen->builtin_types.entry_invalid; |
| 6069 | 6113 | } |
| 6070 | 6114 | |
| 6071 | | bool depends_on_compile_var = op1->static_value.depends_on_compile_var || op2->static_value.depends_on_compile_var; |
| 6115 | bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var; |
| 6072 | 6116 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 6073 | 6117 | |
| 6074 | 6118 | uint64_t new_array_len = array_len.data.x_uint; |
| ... | ... | @@ -6130,9 +6174,9 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6130 | 6174 | VariableTableEntry *var = decl_var_instruction->var; |
| 6131 | 6175 | |
| 6132 | 6176 | IrInstruction *init_value = decl_var_instruction->init_value->other; |
| 6133 | | if (init_value->type_entry->id == TypeTableEntryIdInvalid) { |
| 6134 | | var->type = ira->codegen->builtin_types.entry_invalid; |
| 6135 | | return var->type; |
| 6177 | if (init_value->value.type->id == TypeTableEntryIdInvalid) { |
| 6178 | var->value.type = ira->codegen->builtin_types.entry_invalid; |
| 6179 | return var->value.type; |
| 6136 | 6180 | } |
| 6137 | 6181 | |
| 6138 | 6182 | AstNodeVariableDeclaration *variable_declaration = &var->decl_node->data.variable_declaration; |
| ... | ... | @@ -6148,15 +6192,15 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6148 | 6192 | TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type); |
| 6149 | 6193 | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 6150 | 6194 | if (explicit_type->id == TypeTableEntryIdInvalid) { |
| 6151 | | var->type = ira->codegen->builtin_types.entry_invalid; |
| 6152 | | return var->type; |
| 6195 | var->value.type = ira->codegen->builtin_types.entry_invalid; |
| 6196 | return var->value.type; |
| 6153 | 6197 | } |
| 6154 | 6198 | } |
| 6155 | 6199 | |
| 6156 | 6200 | AstNode *source_node = decl_var_instruction->base.source_node; |
| 6157 | 6201 | |
| 6158 | 6202 | IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type); |
| 6159 | | TypeTableEntry *result_type = get_underlying_type(casted_init_value->type_entry); |
| 6203 | TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type); |
| 6160 | 6204 | switch (result_type->id) { |
| 6161 | 6205 | case TypeTableEntryIdTypeDecl: |
| 6162 | 6206 | zig_unreachable(); |
| ... | ... | @@ -6165,7 +6209,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6165 | 6209 | break; |
| 6166 | 6210 | case TypeTableEntryIdNumLitFloat: |
| 6167 | 6211 | case TypeTableEntryIdNumLitInt: |
| 6168 | | if (is_export || is_extern || casted_init_value->static_value.special == ConstValSpecialRuntime) { |
| 6212 | if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) { |
| 6169 | 6213 | ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type")); |
| 6170 | 6214 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 6171 | 6215 | } |
| ... | ... | @@ -6180,7 +6224,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6180 | 6224 | break; |
| 6181 | 6225 | case TypeTableEntryIdMetaType: |
| 6182 | 6226 | case TypeTableEntryIdNamespace: |
| 6183 | | if (casted_init_value->static_value.special == ConstValSpecialRuntime) { |
| 6227 | if (casted_init_value->value.special == ConstValSpecialRuntime) { |
| 6184 | 6228 | ir_add_error_node(ira, source_node, |
| 6185 | 6229 | buf_sprintf("variable of type '%s' must be constant", buf_ptr(&result_type->name))); |
| 6186 | 6230 | result_type = ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -6206,16 +6250,16 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6206 | 6250 | break; |
| 6207 | 6251 | } |
| 6208 | 6252 | |
| 6209 | | var->type = result_type; |
| 6210 | | assert(var->type); |
| 6253 | var->value.type = result_type; |
| 6254 | assert(var->value.type); |
| 6211 | 6255 | |
| 6212 | 6256 | bool is_comptime = ir_get_var_is_comptime(var); |
| 6213 | 6257 | |
| 6214 | | if (casted_init_value->static_value.special != ConstValSpecialRuntime) { |
| 6258 | if (casted_init_value->value.special != ConstValSpecialRuntime) { |
| 6215 | 6259 | if (var->mem_slot_index != SIZE_MAX) { |
| 6216 | 6260 | assert(var->mem_slot_index < ira->exec_context.mem_slot_count); |
| 6217 | 6261 | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 6218 | | *mem_slot = casted_init_value->static_value; |
| 6262 | *mem_slot = casted_init_value->value; |
| 6219 | 6263 | |
| 6220 | 6264 | if (is_comptime) { |
| 6221 | 6265 | ir_build_const_from(ira, &decl_var_instruction->base, false); |
| ... | ... | @@ -6225,7 +6269,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 6225 | 6269 | } else if (is_comptime) { |
| 6226 | 6270 | ir_add_error(ira, &decl_var_instruction->base, |
| 6227 | 6271 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 6228 | | var->type = ira->codegen->builtin_types.entry_invalid; |
| 6272 | var->value.type = ira->codegen->builtin_types.entry_invalid; |
| 6229 | 6273 | return ira->codegen->builtin_types.entry_invalid; |
| 6230 | 6274 | } |
| 6231 | 6275 | |
| ... | ... | @@ -6249,7 +6293,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 6249 | 6293 | return false; |
| 6250 | 6294 | |
| 6251 | 6295 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 6252 | | if (casted_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6296 | if (casted_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6253 | 6297 | return false; |
| 6254 | 6298 | |
| 6255 | 6299 | ConstExprValue *first_arg_val = ir_resolve_const(ira, casted_arg, UndefBad); |
| ... | ... | @@ -6258,7 +6302,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 6258 | 6302 | |
| 6259 | 6303 | Buf *param_name = param_decl_node->data.param_decl.name; |
| 6260 | 6304 | VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, |
| 6261 | | *exec_scope, param_name, casted_arg->type_entry, true, first_arg_val); |
| 6305 | *exec_scope, param_name, true, first_arg_val); |
| 6262 | 6306 | *exec_scope = var->child_scope; |
| 6263 | 6307 | *next_proto_i += 1; |
| 6264 | 6308 | |
| ... | ... | @@ -6278,7 +6322,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 6278 | 6322 | return false; |
| 6279 | 6323 | |
| 6280 | 6324 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 6281 | | if (casted_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6325 | if (casted_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6282 | 6326 | return false; |
| 6283 | 6327 | |
| 6284 | 6328 | bool inline_arg = param_decl_node->data.param_decl.is_inline; |
| ... | ... | @@ -6294,24 +6338,22 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 6294 | 6338 | // needs to know that it depends on compile time variable data. |
| 6295 | 6339 | arg_val->depends_on_compile_var = true; |
| 6296 | 6340 | } else { |
| 6297 | | arg_val = nullptr; |
| 6341 | arg_val = create_const_runtime(casted_arg->value.type); |
| 6298 | 6342 | } |
| 6299 | 6343 | |
| 6300 | 6344 | Buf *param_name = param_decl_node->data.param_decl.name; |
| 6301 | 6345 | VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, |
| 6302 | | *child_scope, param_name, casted_arg->type_entry, true, arg_val); |
| 6346 | *child_scope, param_name, true, arg_val); |
| 6303 | 6347 | *child_scope = var->child_scope; |
| 6304 | 6348 | |
| 6305 | 6349 | if (inline_arg || is_var_type) { |
| 6306 | | GenericParamValue *generic_param = &generic_id->params[generic_id->param_count]; |
| 6307 | | generic_param->type = casted_arg->type_entry; |
| 6308 | | generic_param->value = arg_val; |
| 6350 | generic_id->params[generic_id->param_count] = *arg_val; |
| 6309 | 6351 | generic_id->param_count += 1; |
| 6310 | 6352 | } |
| 6311 | 6353 | if (!inline_arg) { |
| 6312 | | if (type_requires_comptime(var->type)) { |
| 6354 | if (type_requires_comptime(var->value.type)) { |
| 6313 | 6355 | ir_add_error(ira, arg, |
| 6314 | | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&var->type->name))); |
| 6356 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&var->value.type->name))); |
| 6315 | 6357 | return false; |
| 6316 | 6358 | } |
| 6317 | 6359 | |
| ... | ... | @@ -6319,7 +6361,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 6319 | 6361 | |
| 6320 | 6362 | casted_args[fn_type_id->param_count] = casted_arg; |
| 6321 | 6363 | FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count]; |
| 6322 | | param_info->type = casted_arg->type_entry; |
| 6364 | param_info->type = casted_arg->value.type; |
| 6323 | 6365 | param_info->is_noalias = param_decl_node->data.param_decl.is_noalias; |
| 6324 | 6366 | impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node; |
| 6325 | 6367 | fn_type_id->param_count += 1; |
| ... | ... | @@ -6376,7 +6418,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6376 | 6418 | size_t next_proto_i = 0; |
| 6377 | 6419 | if (first_arg_ptr) { |
| 6378 | 6420 | IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 6379 | | if (first_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6421 | if (first_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6380 | 6422 | return ira->codegen->builtin_types.entry_invalid; |
| 6381 | 6423 | |
| 6382 | 6424 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i)) |
| ... | ... | @@ -6385,7 +6427,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6385 | 6427 | |
| 6386 | 6428 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 6387 | 6429 | IrInstruction *old_arg = call_instruction->args[call_i]->other; |
| 6388 | | if (old_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6430 | if (old_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6389 | 6431 | return ira->codegen->builtin_types.entry_invalid; |
| 6390 | 6432 | |
| 6391 | 6433 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| ... | ... | @@ -6408,15 +6450,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6408 | 6450 | result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, |
| 6409 | 6451 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry, |
| 6410 | 6452 | nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec); |
| 6411 | | if (result->type_entry->id == TypeTableEntryIdInvalid) |
| 6453 | if (result->value.type->id == TypeTableEntryIdInvalid) |
| 6412 | 6454 | return ira->codegen->builtin_types.entry_invalid; |
| 6413 | 6455 | |
| 6414 | 6456 | ira->codegen->memoized_fn_eval_table.put(exec_scope, result); |
| 6415 | 6457 | } |
| 6416 | 6458 | |
| 6417 | 6459 | ConstExprValue *out_val = ir_build_const_from(ira, &call_instruction->base, |
| 6418 | | result->static_value.depends_on_compile_var); |
| 6419 | | *out_val = result->static_value; |
| 6460 | result->value.depends_on_compile_var); |
| 6461 | *out_val = result->value; |
| 6420 | 6462 | return ir_finish_anal(ira, return_type); |
| 6421 | 6463 | } |
| 6422 | 6464 | |
| ... | ... | @@ -6441,12 +6483,12 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6441 | 6483 | GenericFnTypeId *generic_id = allocate<GenericFnTypeId>(1); |
| 6442 | 6484 | generic_id->fn_entry = fn_entry; |
| 6443 | 6485 | generic_id->param_count = 0; |
| 6444 | | generic_id->params = allocate<GenericParamValue>(src_param_count); |
| 6486 | generic_id->params = allocate<ConstExprValue>(src_param_count); |
| 6445 | 6487 | size_t next_proto_i = 0; |
| 6446 | 6488 | |
| 6447 | 6489 | if (first_arg_ptr) { |
| 6448 | 6490 | IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 6449 | | if (first_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6491 | if (first_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6450 | 6492 | return ira->codegen->builtin_types.entry_invalid; |
| 6451 | 6493 | |
| 6452 | 6494 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope, |
| ... | ... | @@ -6457,7 +6499,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6457 | 6499 | } |
| 6458 | 6500 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 6459 | 6501 | IrInstruction *arg = call_instruction->args[call_i]->other; |
| 6460 | | if (arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6502 | if (arg->value.type->id == TypeTableEntryIdInvalid) |
| 6461 | 6503 | return ira->codegen->builtin_types.entry_invalid; |
| 6462 | 6504 | |
| 6463 | 6505 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, |
| ... | ... | @@ -6513,7 +6555,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6513 | 6555 | size_t next_arg_index = 0; |
| 6514 | 6556 | if (first_arg_ptr) { |
| 6515 | 6557 | IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 6516 | | if (first_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6558 | if (first_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6517 | 6559 | return ira->codegen->builtin_types.entry_invalid; |
| 6518 | 6560 | |
| 6519 | 6561 | TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type; |
| ... | ... | @@ -6521,7 +6563,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6521 | 6563 | return ira->codegen->builtin_types.entry_invalid; |
| 6522 | 6564 | |
| 6523 | 6565 | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 6524 | | if (casted_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6566 | if (casted_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6525 | 6567 | return ira->codegen->builtin_types.entry_invalid; |
| 6526 | 6568 | |
| 6527 | 6569 | casted_args[next_arg_index] = casted_arg; |
| ... | ... | @@ -6529,7 +6571,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6529 | 6571 | } |
| 6530 | 6572 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 6531 | 6573 | IrInstruction *old_arg = call_instruction->args[call_i]->other; |
| 6532 | | if (old_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6574 | if (old_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6533 | 6575 | return ira->codegen->builtin_types.entry_invalid; |
| 6534 | 6576 | IrInstruction *casted_arg; |
| 6535 | 6577 | if (next_arg_index < src_param_count) { |
| ... | ... | @@ -6537,7 +6579,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6537 | 6579 | if (param_type->id == TypeTableEntryIdInvalid) |
| 6538 | 6580 | return ira->codegen->builtin_types.entry_invalid; |
| 6539 | 6581 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 6540 | | if (casted_arg->type_entry->id == TypeTableEntryIdInvalid) |
| 6582 | if (casted_arg->value.type->id == TypeTableEntryIdInvalid) |
| 6541 | 6583 | return ira->codegen->builtin_types.entry_invalid; |
| 6542 | 6584 | } else { |
| 6543 | 6585 | casted_arg = old_arg; |
| ... | ... | @@ -6562,13 +6604,13 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6562 | 6604 | |
| 6563 | 6605 | static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { |
| 6564 | 6606 | IrInstruction *fn_ref = call_instruction->fn_ref->other; |
| 6565 | | if (fn_ref->type_entry->id == TypeTableEntryIdInvalid) |
| 6607 | if (fn_ref->value.type->id == TypeTableEntryIdInvalid) |
| 6566 | 6608 | return ira->codegen->builtin_types.entry_invalid; |
| 6567 | 6609 | |
| 6568 | 6610 | bool is_inline = call_instruction->is_inline || ir_should_inline(&ira->new_irb); |
| 6569 | 6611 | |
| 6570 | | if (is_inline || fn_ref->static_value.special != ConstValSpecialRuntime) { |
| 6571 | | if (fn_ref->type_entry->id == TypeTableEntryIdMetaType) { |
| 6612 | if (is_inline || fn_ref->value.special != ConstValSpecialRuntime) { |
| 6613 | if (fn_ref->value.type->id == TypeTableEntryIdMetaType) { |
| 6572 | 6614 | TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref); |
| 6573 | 6615 | if (dest_type->id == TypeTableEntryIdInvalid) |
| 6574 | 6616 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -6584,34 +6626,34 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 6584 | 6626 | IrInstruction *arg = call_instruction->args[0]->other; |
| 6585 | 6627 | |
| 6586 | 6628 | IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg); |
| 6587 | | if (cast_instruction->type_entry->id == TypeTableEntryIdInvalid) |
| 6629 | if (cast_instruction->value.type->id == TypeTableEntryIdInvalid) |
| 6588 | 6630 | return ira->codegen->builtin_types.entry_invalid; |
| 6589 | 6631 | |
| 6590 | 6632 | ir_link_new_instruction(cast_instruction, &call_instruction->base); |
| 6591 | | return ir_finish_anal(ira, cast_instruction->type_entry); |
| 6592 | | } else if (fn_ref->type_entry->id == TypeTableEntryIdFn) { |
| 6633 | return ir_finish_anal(ira, cast_instruction->value.type); |
| 6634 | } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { |
| 6593 | 6635 | FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 6594 | 6636 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 6595 | 6637 | fn_ref, nullptr, is_inline); |
| 6596 | | } else if (fn_ref->type_entry->id == TypeTableEntryIdBoundFn) { |
| 6597 | | assert(fn_ref->static_value.special == ConstValSpecialStatic); |
| 6598 | | FnTableEntry *fn_table_entry = fn_ref->static_value.data.x_bound_fn.fn; |
| 6599 | | IrInstruction *first_arg_ptr = fn_ref->static_value.data.x_bound_fn.first_arg; |
| 6638 | } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) { |
| 6639 | assert(fn_ref->value.special == ConstValSpecialStatic); |
| 6640 | FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; |
| 6641 | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; |
| 6600 | 6642 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 6601 | 6643 | nullptr, first_arg_ptr, is_inline); |
| 6602 | 6644 | } else { |
| 6603 | 6645 | ir_add_error_node(ira, fn_ref->source_node, |
| 6604 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name))); |
| 6646 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 6605 | 6647 | return ira->codegen->builtin_types.entry_invalid; |
| 6606 | 6648 | } |
| 6607 | 6649 | } |
| 6608 | 6650 | |
| 6609 | | if (fn_ref->type_entry->id == TypeTableEntryIdFn) { |
| 6610 | | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->type_entry, |
| 6651 | if (fn_ref->value.type->id == TypeTableEntryIdFn) { |
| 6652 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 6611 | 6653 | fn_ref, nullptr, false); |
| 6612 | 6654 | } else { |
| 6613 | 6655 | ir_add_error_node(ira, fn_ref->source_node, |
| 6614 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name))); |
| 6656 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 6615 | 6657 | return ira->codegen->builtin_types.entry_invalid; |
| 6616 | 6658 | } |
| 6617 | 6659 | } |
| ... | ... | @@ -6620,10 +6662,6 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 6620 | 6662 | assert(un_op_instruction->op_id == IrUnOpError); |
| 6621 | 6663 | IrInstruction *value = un_op_instruction->value->other; |
| 6622 | 6664 | |
| 6623 | | TypeTableEntry *type_entry = value->type_entry; |
| 6624 | | if (type_entry->id == TypeTableEntryIdInvalid) |
| 6625 | | return ira->codegen->builtin_types.entry_invalid; |
| 6626 | | |
| 6627 | 6665 | TypeTableEntry *meta_type = ir_resolve_type(ira, value); |
| 6628 | 6666 | TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type); |
| 6629 | 6667 | switch (underlying_meta_type->id) { |
| ... | ... | @@ -6648,7 +6686,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 6648 | 6686 | case TypeTableEntryIdEnumTag: |
| 6649 | 6687 | { |
| 6650 | 6688 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, |
| 6651 | | value->static_value.depends_on_compile_var); |
| 6689 | value->value.depends_on_compile_var); |
| 6652 | 6690 | TypeTableEntry *result_type = get_error_type(ira->codegen, meta_type); |
| 6653 | 6691 | out_val->data.x_type = result_type; |
| 6654 | 6692 | return ira->codegen->builtin_types.entry_type; |
| ... | ... | @@ -6674,7 +6712,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 6674 | 6712 | static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 6675 | 6713 | IrInstruction *value = un_op_instruction->value->other; |
| 6676 | 6714 | |
| 6677 | | TypeTableEntry *ptr_type = value->type_entry; |
| 6715 | TypeTableEntry *ptr_type = value->value.type; |
| 6678 | 6716 | TypeTableEntry *child_type; |
| 6679 | 6717 | if (ptr_type->id == TypeTableEntryIdInvalid) { |
| 6680 | 6718 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -6690,9 +6728,9 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp |
| 6690 | 6728 | // this dereference is always an rvalue because in the IR gen we identify lvalue and emit |
| 6691 | 6729 | // one of the ptr instructions |
| 6692 | 6730 | |
| 6693 | | if (value->static_value.special != ConstValSpecialRuntime) { |
| 6731 | if (value->value.special != ConstValSpecialRuntime) { |
| 6694 | 6732 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, false); |
| 6695 | | ConstExprValue *pointee = const_ptr_pointee(&value->static_value); |
| 6733 | ConstExprValue *pointee = const_ptr_pointee(&value->value); |
| 6696 | 6734 | *out_val = *pointee; |
| 6697 | 6735 | return child_type; |
| 6698 | 6736 | } |
| ... | ... | @@ -6735,7 +6773,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 6735 | 6773 | case TypeTableEntryIdEnumTag: |
| 6736 | 6774 | { |
| 6737 | 6775 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, |
| 6738 | | value->static_value.depends_on_compile_var); |
| 6776 | value->value.depends_on_compile_var); |
| 6739 | 6777 | out_val->data.x_type = get_maybe_type(ira->codegen, type_entry); |
| 6740 | 6778 | return ira->codegen->builtin_types.entry_type; |
| 6741 | 6779 | } |
| ... | ... | @@ -6750,7 +6788,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 6750 | 6788 | |
| 6751 | 6789 | static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 6752 | 6790 | IrInstruction *value = un_op_instruction->value->other; |
| 6753 | | TypeTableEntry *expr_type = value->type_entry; |
| 6791 | TypeTableEntry *expr_type = value->value.type; |
| 6754 | 6792 | if (expr_type->id == TypeTableEntryIdInvalid) |
| 6755 | 6793 | return ira->codegen->builtin_types.entry_invalid; |
| 6756 | 6794 | |
| ... | ... | @@ -6765,7 +6803,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un |
| 6765 | 6803 | if (!target_const_val) |
| 6766 | 6804 | return ira->codegen->builtin_types.entry_invalid; |
| 6767 | 6805 | |
| 6768 | | bool depends_on_compile_var = value->static_value.depends_on_compile_var; |
| 6806 | bool depends_on_compile_var = value->value.depends_on_compile_var; |
| 6769 | 6807 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var); |
| 6770 | 6808 | bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum); |
| 6771 | 6809 | if (expr_type->id == TypeTableEntryIdFloat || |
| ... | ... | @@ -6846,7 +6884,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 6846 | 6884 | |
| 6847 | 6885 | static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 6848 | 6886 | IrInstruction *condition = cond_br_instruction->condition->other; |
| 6849 | | if (condition->type_entry->id == TypeTableEntryIdInvalid) |
| 6887 | if (condition->value.type->id == TypeTableEntryIdInvalid) |
| 6850 | 6888 | return ir_unreach_error(ira); |
| 6851 | 6889 | |
| 6852 | 6890 | bool is_comptime; |
| ... | ... | @@ -6891,18 +6929,18 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 6891 | 6929 | if (predecessor != ira->const_predecessor_bb) |
| 6892 | 6930 | continue; |
| 6893 | 6931 | IrInstruction *value = phi_instruction->incoming_values[i]->other; |
| 6894 | | assert(value->type_entry); |
| 6895 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 6932 | assert(value->value.type); |
| 6933 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 6896 | 6934 | return ira->codegen->builtin_types.entry_invalid; |
| 6897 | 6935 | |
| 6898 | | if (value->static_value.special != ConstValSpecialRuntime) { |
| 6936 | if (value->value.special != ConstValSpecialRuntime) { |
| 6899 | 6937 | ConstExprValue *out_val = ir_build_const_from(ira, &phi_instruction->base, |
| 6900 | | value->static_value.depends_on_compile_var); |
| 6901 | | *out_val = value->static_value; |
| 6938 | value->value.depends_on_compile_var); |
| 6939 | *out_val = value->value; |
| 6902 | 6940 | } else { |
| 6903 | 6941 | phi_instruction->base.other = value; |
| 6904 | 6942 | } |
| 6905 | | return value->type_entry; |
| 6943 | return value->value.type; |
| 6906 | 6944 | } |
| 6907 | 6945 | zig_unreachable(); |
| 6908 | 6946 | } |
| ... | ... | @@ -6919,10 +6957,10 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 6919 | 6957 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 6920 | 6958 | assert(old_value); |
| 6921 | 6959 | IrInstruction *new_value = old_value->other; |
| 6922 | | if (!new_value || new_value->type_entry->id == TypeTableEntryIdUnreachable) |
| 6960 | if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable) |
| 6923 | 6961 | continue; |
| 6924 | 6962 | |
| 6925 | | if (new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 6963 | if (new_value->value.type->id == TypeTableEntryIdInvalid) |
| 6926 | 6964 | return ira->codegen->builtin_types.entry_invalid; |
| 6927 | 6965 | |
| 6928 | 6966 | |
| ... | ... | @@ -6935,7 +6973,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 6935 | 6973 | if (new_incoming_blocks.length == 1) { |
| 6936 | 6974 | IrInstruction *first_value = new_incoming_values.at(0); |
| 6937 | 6975 | phi_instruction->base.other = first_value; |
| 6938 | | return first_value->type_entry; |
| 6976 | return first_value->value.type; |
| 6939 | 6977 | } |
| 6940 | 6978 | |
| 6941 | 6979 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, |
| ... | ... | @@ -6973,16 +7011,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 6973 | 7011 | } |
| 6974 | 7012 | |
| 6975 | 7013 | static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var) { |
| 6976 | | assert(var->type); |
| 6977 | | if (var->type->id == TypeTableEntryIdInvalid) |
| 6978 | | return var->type; |
| 7014 | assert(var->value.type); |
| 7015 | if (var->value.type->id == TypeTableEntryIdInvalid) |
| 7016 | return var->value.type; |
| 6979 | 7017 | |
| 6980 | 7018 | bool is_comptime = ir_get_var_is_comptime(var); |
| 6981 | 7019 | |
| 6982 | 7020 | ConstExprValue *mem_slot = nullptr; |
| 6983 | 7021 | FnTableEntry *fn_entry = scope_fn_entry(var->parent_scope); |
| 6984 | | if (var->src_is_const && var->value) { |
| 6985 | | mem_slot = var->value; |
| 7022 | if (var->src_is_const && var->value.special == ConstValSpecialStatic) { |
| 7023 | mem_slot = &var->value; |
| 6986 | 7024 | assert(mem_slot->special != ConstValSpecialRuntime); |
| 6987 | 7025 | } else if (fn_entry) { |
| 6988 | 7026 | // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing. |
| ... | ... | @@ -6992,10 +7030,10 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc |
| 6992 | 7030 | |
| 6993 | 7031 | if (mem_slot && mem_slot->special != ConstValSpecialRuntime) { |
| 6994 | 7032 | ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone; |
| 6995 | | return ir_analyze_const_ptr(ira, instruction, mem_slot, var->type, false, ptr_special, var->src_is_const); |
| 7033 | return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, var->src_is_const); |
| 6996 | 7034 | } else { |
| 6997 | 7035 | ir_build_var_ptr_from(&ira->new_irb, instruction, var); |
| 6998 | | return get_pointer_to_type(ira->codegen, var->type, var->src_is_const); |
| 7036 | return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const); |
| 6999 | 7037 | } |
| 7000 | 7038 | } |
| 7001 | 7039 | |
| ... | ... | @@ -7006,15 +7044,15 @@ static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstruct |
| 7006 | 7044 | |
| 7007 | 7045 | static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 7008 | 7046 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; |
| 7009 | | if (array_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 7047 | if (array_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 7010 | 7048 | return ira->codegen->builtin_types.entry_invalid; |
| 7011 | 7049 | |
| 7012 | 7050 | IrInstruction *elem_index = elem_ptr_instruction->elem_index->other; |
| 7013 | | if (elem_index->type_entry->id == TypeTableEntryIdInvalid) |
| 7051 | if (elem_index->value.type->id == TypeTableEntryIdInvalid) |
| 7014 | 7052 | return ira->codegen->builtin_types.entry_invalid; |
| 7015 | 7053 | |
| 7016 | 7054 | // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing. |
| 7017 | | TypeTableEntry *ptr_type = array_ptr->type_entry; |
| 7055 | TypeTableEntry *ptr_type = array_ptr->value.type; |
| 7018 | 7056 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 7019 | 7057 | |
| 7020 | 7058 | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; |
| ... | ... | @@ -7045,8 +7083,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 7045 | 7083 | return ira->codegen->builtin_types.entry_invalid; |
| 7046 | 7084 | |
| 7047 | 7085 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 7048 | | if (casted_elem_index->static_value.special != ConstValSpecialRuntime) { |
| 7049 | | uint64_t index = casted_elem_index->static_value.data.x_bignum.data.x_uint; |
| 7086 | if (casted_elem_index->value.special != ConstValSpecialRuntime) { |
| 7087 | uint64_t index = casted_elem_index->value.data.x_bignum.data.x_uint; |
| 7050 | 7088 | if (array_type->id == TypeTableEntryIdArray) { |
| 7051 | 7089 | uint64_t array_len = array_type->data.array.len; |
| 7052 | 7090 | if (index >= array_len) { |
| ... | ... | @@ -7059,12 +7097,12 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 7059 | 7097 | } |
| 7060 | 7098 | |
| 7061 | 7099 | ConstExprValue *array_ptr_val; |
| 7062 | | if (array_ptr->static_value.special != ConstValSpecialRuntime && |
| 7063 | | (array_ptr_val = const_ptr_pointee(&array_ptr->static_value)) && |
| 7100 | if (array_ptr->value.special != ConstValSpecialRuntime && |
| 7101 | (array_ptr_val = const_ptr_pointee(&array_ptr->value)) && |
| 7064 | 7102 | array_ptr_val->special != ConstValSpecialRuntime) |
| 7065 | 7103 | { |
| 7066 | 7104 | bool depends_on_compile_var = array_ptr_val->depends_on_compile_var || |
| 7067 | | casted_elem_index->static_value.depends_on_compile_var; |
| 7105 | casted_elem_index->value.depends_on_compile_var; |
| 7068 | 7106 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base, depends_on_compile_var); |
| 7069 | 7107 | if (array_type->id == TypeTableEntryIdPointer) { |
| 7070 | 7108 | size_t offset = array_ptr_val->data.x_ptr.index; |
| ... | ... | @@ -7136,7 +7174,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 7136 | 7174 | return ira->codegen->builtin_types.entry_invalid; |
| 7137 | 7175 | TldFn *tld_fn = (TldFn *)tld; |
| 7138 | 7176 | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 7139 | | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; |
| 7177 | bool depends_on_compile_var = container_ptr->value.depends_on_compile_var; |
| 7140 | 7178 | IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope, |
| 7141 | 7179 | field_ptr_instruction->base.source_node, fn_entry, container_ptr, depends_on_compile_var); |
| 7142 | 7180 | return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value, true); |
| ... | ... | @@ -7206,6 +7244,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 7206 | 7244 | // the same one every time |
| 7207 | 7245 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| 7208 | 7246 | const_val->special = ConstValSpecialStatic; |
| 7247 | const_val->type = fn_entry->type_entry; |
| 7209 | 7248 | const_val->data.x_fn = fn_entry; |
| 7210 | 7249 | |
| 7211 | 7250 | bool ptr_is_const = true; |
| ... | ... | @@ -7221,6 +7260,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 7221 | 7260 | // the same one every time |
| 7222 | 7261 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| 7223 | 7262 | const_val->special = ConstValSpecialStatic; |
| 7263 | const_val->type = ira->codegen->builtin_types.entry_type; |
| 7224 | 7264 | const_val->data.x_type = tld_typedef->type_entry; |
| 7225 | 7265 | |
| 7226 | 7266 | bool ptr_is_const = true; |
| ... | ... | @@ -7233,26 +7273,26 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 7233 | 7273 | |
| 7234 | 7274 | static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 7235 | 7275 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; |
| 7236 | | if (container_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 7276 | if (container_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 7237 | 7277 | return ira->codegen->builtin_types.entry_invalid; |
| 7238 | 7278 | |
| 7239 | 7279 | TypeTableEntry *container_type; |
| 7240 | | if (container_ptr->type_entry->id == TypeTableEntryIdPointer) { |
| 7241 | | container_type = container_ptr->type_entry->data.pointer.child_type; |
| 7242 | | } else if (container_ptr->type_entry->id == TypeTableEntryIdMetaType) { |
| 7243 | | container_type = container_ptr->type_entry; |
| 7280 | if (container_ptr->value.type->id == TypeTableEntryIdPointer) { |
| 7281 | container_type = container_ptr->value.type->data.pointer.child_type; |
| 7282 | } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) { |
| 7283 | container_type = container_ptr->value.type; |
| 7244 | 7284 | } else { |
| 7245 | 7285 | zig_unreachable(); |
| 7246 | 7286 | } |
| 7247 | 7287 | |
| 7248 | | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; |
| 7288 | bool depends_on_compile_var = container_ptr->value.depends_on_compile_var; |
| 7249 | 7289 | Buf *field_name = field_ptr_instruction->field_name; |
| 7250 | 7290 | AstNode *source_node = field_ptr_instruction->base.source_node; |
| 7251 | 7291 | |
| 7252 | 7292 | if (container_type->id == TypeTableEntryIdInvalid) { |
| 7253 | 7293 | return container_type; |
| 7254 | 7294 | } else if (is_container_ref(container_type)) { |
| 7255 | | assert(container_ptr->type_entry->id == TypeTableEntryIdPointer); |
| 7295 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 7256 | 7296 | if (container_type->id == TypeTableEntryIdPointer) { |
| 7257 | 7297 | TypeTableEntry *bare_type = container_ref_type(container_type); |
| 7258 | 7298 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); |
| ... | ... | @@ -7263,8 +7303,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7263 | 7303 | } else if (container_type->id == TypeTableEntryIdArray) { |
| 7264 | 7304 | if (buf_eql_str(field_name, "len")) { |
| 7265 | 7305 | ConstExprValue *len_val = allocate<ConstExprValue>(1); |
| 7266 | | len_val->special = ConstValSpecialStatic; |
| 7267 | | bignum_init_unsigned(&len_val->data.x_bignum, container_type->data.array.len); |
| 7306 | init_const_usize(ira->codegen, len_val, container_type->data.array.len); |
| 7268 | 7307 | |
| 7269 | 7308 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| 7270 | 7309 | bool ptr_is_const = true; |
| ... | ... | @@ -7282,11 +7321,11 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7282 | 7321 | return ira->codegen->builtin_types.entry_invalid; |
| 7283 | 7322 | |
| 7284 | 7323 | TypeTableEntry *child_type; |
| 7285 | | if (container_ptr->type_entry->id == TypeTableEntryIdMetaType) { |
| 7324 | if (container_ptr->value.type->id == TypeTableEntryIdMetaType) { |
| 7286 | 7325 | TypeTableEntry *ptr_type = container_ptr_val->data.x_type; |
| 7287 | 7326 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 7288 | 7327 | child_type = ptr_type->data.pointer.child_type; |
| 7289 | | } else if (container_ptr->type_entry->id == TypeTableEntryIdPointer) { |
| 7328 | } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) { |
| 7290 | 7329 | ConstExprValue *child_val = const_ptr_pointee(container_ptr_val); |
| 7291 | 7330 | child_type = child_val->data.x_type; |
| 7292 | 7331 | } else { |
| ... | ... | @@ -7303,14 +7342,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7303 | 7342 | if (field->type_entry->id == TypeTableEntryIdVoid) { |
| 7304 | 7343 | bool ptr_is_const = true; |
| 7305 | 7344 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 7306 | | create_const_enum_tag(field->value), child_type, depends_on_compile_var, |
| 7345 | create_const_enum_tag(child_type, field->value), child_type, depends_on_compile_var, |
| 7307 | 7346 | ConstPtrSpecialNone, ptr_is_const); |
| 7308 | 7347 | } else { |
| 7309 | 7348 | bool ptr_is_const = true; |
| 7310 | 7349 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 7311 | | create_const_unsigned_negative(field->value, false), |
| 7312 | | child_type->data.enumeration.tag_type, depends_on_compile_var, |
| 7313 | | ConstPtrSpecialNone, ptr_is_const); |
| 7350 | create_const_unsigned_negative(child_type->data.enumeration.tag_type, field->value, false), |
| 7351 | child_type->data.enumeration.tag_type, depends_on_compile_var, |
| 7352 | ConstPtrSpecialNone, ptr_is_const); |
| 7314 | 7353 | } |
| 7315 | 7354 | } |
| 7316 | 7355 | } |
| ... | ... | @@ -7329,6 +7368,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7329 | 7368 | if (err_table_entry) { |
| 7330 | 7369 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| 7331 | 7370 | const_val->special = ConstValSpecialStatic; |
| 7371 | const_val->type = child_type; |
| 7332 | 7372 | const_val->data.x_pure_err = err_table_entry->value; |
| 7333 | 7373 | |
| 7334 | 7374 | bool ptr_is_const = true; |
| ... | ... | @@ -7343,13 +7383,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7343 | 7383 | if (buf_eql_str(field_name, "bit_count")) { |
| 7344 | 7384 | bool ptr_is_const = true; |
| 7345 | 7385 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 7346 | | create_const_unsigned_negative(child_type->data.integral.bit_count, false), |
| 7386 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 7387 | child_type->data.integral.bit_count, false), |
| 7347 | 7388 | ira->codegen->builtin_types.entry_num_lit_int, depends_on_compile_var, |
| 7348 | 7389 | ConstPtrSpecialNone, ptr_is_const); |
| 7349 | 7390 | } else if (buf_eql_str(field_name, "is_signed")) { |
| 7350 | 7391 | bool ptr_is_const = true; |
| 7351 | 7392 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 7352 | | create_const_bool(child_type->data.integral.is_signed), |
| 7393 | create_const_bool(ira->codegen, child_type->data.integral.is_signed), |
| 7353 | 7394 | ira->codegen->builtin_types.entry_bool, depends_on_compile_var, |
| 7354 | 7395 | ConstPtrSpecialNone, ptr_is_const); |
| 7355 | 7396 | } else { |
| ... | ... | @@ -7364,7 +7405,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 7364 | 7405 | return ira->codegen->builtin_types.entry_invalid; |
| 7365 | 7406 | } |
| 7366 | 7407 | } else if (container_type->id == TypeTableEntryIdNamespace) { |
| 7367 | | assert(container_ptr->type_entry->id == TypeTableEntryIdPointer); |
| 7408 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 7368 | 7409 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 7369 | 7410 | if (!container_ptr_val) |
| 7370 | 7411 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -7414,30 +7455,30 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc |
| 7414 | 7455 | IrInstruction *ptr = load_ptr_instruction->ptr->other; |
| 7415 | 7456 | IrInstruction *result = ir_get_deref(ira, &load_ptr_instruction->base, ptr); |
| 7416 | 7457 | ir_link_new_instruction(result, &load_ptr_instruction->base); |
| 7417 | | assert(result->type_entry); |
| 7418 | | return result->type_entry; |
| 7458 | assert(result->value.type); |
| 7459 | return result->value.type; |
| 7419 | 7460 | } |
| 7420 | 7461 | |
| 7421 | 7462 | static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { |
| 7422 | 7463 | IrInstruction *ptr = store_ptr_instruction->ptr->other; |
| 7423 | | if (ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 7424 | | return ptr->type_entry; |
| 7464 | if (ptr->value.type->id == TypeTableEntryIdInvalid) |
| 7465 | return ptr->value.type; |
| 7425 | 7466 | |
| 7426 | 7467 | IrInstruction *value = store_ptr_instruction->value->other; |
| 7427 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 7428 | | return value->type_entry; |
| 7468 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 7469 | return value->value.type; |
| 7429 | 7470 | |
| 7430 | | TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type; |
| 7471 | TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type; |
| 7431 | 7472 | IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); |
| 7432 | 7473 | if (casted_value == ira->codegen->invalid_instruction) |
| 7433 | 7474 | return ira->codegen->builtin_types.entry_invalid; |
| 7434 | 7475 | |
| 7435 | | if (ptr->static_value.special != ConstValSpecialRuntime) { |
| 7436 | | bool is_inline = (ptr->static_value.data.x_ptr.special == ConstPtrSpecialInline); |
| 7437 | | if (casted_value->static_value.special != ConstValSpecialRuntime) { |
| 7438 | | ConstExprValue *dest_val = const_ptr_pointee(&ptr->static_value); |
| 7476 | if (ptr->value.special != ConstValSpecialRuntime) { |
| 7477 | bool is_inline = (ptr->value.data.x_ptr.special == ConstPtrSpecialInline); |
| 7478 | if (casted_value->value.special != ConstValSpecialRuntime) { |
| 7479 | ConstExprValue *dest_val = const_ptr_pointee(&ptr->value); |
| 7439 | 7480 | if (dest_val->special != ConstValSpecialRuntime) { |
| 7440 | | *dest_val = casted_value->static_value; |
| 7481 | *dest_val = casted_value->value; |
| 7441 | 7482 | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 7442 | 7483 | } |
| 7443 | 7484 | } |
| ... | ... | @@ -7448,11 +7489,11 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 7448 | 7489 | } |
| 7449 | 7490 | } |
| 7450 | 7491 | |
| 7451 | | if (ptr->static_value.special != ConstValSpecialRuntime) { |
| 7492 | if (ptr->value.special != ConstValSpecialRuntime) { |
| 7452 | 7493 | // This memory location is transforming from known at compile time to known at runtime. |
| 7453 | 7494 | // We must emit our own var ptr instruction. |
| 7454 | 7495 | // TODO can we delete this code now that we have inline var? |
| 7455 | | ptr->static_value.special = ConstValSpecialRuntime; |
| 7496 | ptr->value.special = ConstValSpecialRuntime; |
| 7456 | 7497 | IrInstruction *new_ptr_inst; |
| 7457 | 7498 | if (ptr->id == IrInstructionIdVarPtr) { |
| 7458 | 7499 | IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr; |
| ... | ... | @@ -7469,7 +7510,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 7469 | 7510 | } else { |
| 7470 | 7511 | zig_unreachable(); |
| 7471 | 7512 | } |
| 7472 | | new_ptr_inst->type_entry = ptr->type_entry; |
| 7513 | new_ptr_inst->value.type = ptr->value.type; |
| 7473 | 7514 | ir_build_store_ptr(&ira->new_irb, store_ptr_instruction->base.scope, |
| 7474 | 7515 | store_ptr_instruction->base.source_node, new_ptr_inst, casted_value); |
| 7475 | 7516 | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| ... | ... | @@ -7481,7 +7522,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 7481 | 7522 | |
| 7482 | 7523 | static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 7483 | 7524 | IrInstruction *expr_value = typeof_instruction->value->other; |
| 7484 | | TypeTableEntry *type_entry = expr_value->type_entry; |
| 7525 | TypeTableEntry *type_entry = expr_value->value.type; |
| 7485 | 7526 | switch (type_entry->id) { |
| 7486 | 7527 | case TypeTableEntryIdInvalid: |
| 7487 | 7528 | return type_entry; |
| ... | ... | @@ -7547,7 +7588,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 7547 | 7588 | } |
| 7548 | 7589 | |
| 7549 | 7590 | ConstExprValue *out_val = ir_build_const_from(ira, &to_ptr_type_instruction->base, |
| 7550 | | type_value->static_value.depends_on_compile_var); |
| 7591 | type_value->value.depends_on_compile_var); |
| 7551 | 7592 | out_val->data.x_type = ptr_type; |
| 7552 | 7593 | return ira->codegen->builtin_types.entry_type; |
| 7553 | 7594 | } |
| ... | ... | @@ -7568,7 +7609,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 7568 | 7609 | } |
| 7569 | 7610 | |
| 7570 | 7611 | ConstExprValue *out_val = ir_build_const_from(ira, &ptr_type_child_instruction->base, |
| 7571 | | type_value->static_value.depends_on_compile_var); |
| 7612 | type_value->value.depends_on_compile_var); |
| 7572 | 7613 | out_val->data.x_type = type_entry->data.pointer.child_type; |
| 7573 | 7614 | return ira->codegen->builtin_types.entry_type; |
| 7574 | 7615 | } |
| ... | ... | @@ -7631,7 +7672,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira, |
| 7631 | 7672 | IrInstructionSetDebugSafety *set_debug_safety_instruction) |
| 7632 | 7673 | { |
| 7633 | 7674 | IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other; |
| 7634 | | TypeTableEntry *target_type = target_instruction->type_entry; |
| 7675 | TypeTableEntry *target_type = target_instruction->value.type; |
| 7635 | 7676 | if (target_type->id == TypeTableEntryIdInvalid) |
| 7636 | 7677 | return ira->codegen->builtin_types.entry_invalid; |
| 7637 | 7678 | ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad); |
| ... | ... | @@ -7694,7 +7735,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 7694 | 7735 | IrInstructionSliceType *slice_type_instruction) |
| 7695 | 7736 | { |
| 7696 | 7737 | IrInstruction *child_type = slice_type_instruction->child_type->other; |
| 7697 | | if (child_type->type_entry->id == TypeTableEntryIdInvalid) |
| 7738 | if (child_type->value.type->id == TypeTableEntryIdInvalid) |
| 7698 | 7739 | return ira->codegen->builtin_types.entry_invalid; |
| 7699 | 7740 | bool is_const = slice_type_instruction->is_const; |
| 7700 | 7741 | |
| ... | ... | @@ -7736,7 +7777,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 7736 | 7777 | { |
| 7737 | 7778 | TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const); |
| 7738 | 7779 | ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base, |
| 7739 | | child_type->static_value.depends_on_compile_var); |
| 7780 | child_type->value.depends_on_compile_var); |
| 7740 | 7781 | out_val->data.x_type = result_type; |
| 7741 | 7782 | return ira->codegen->builtin_types.entry_type; |
| 7742 | 7783 | } |
| ... | ... | @@ -7770,7 +7811,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA |
| 7770 | 7811 | |
| 7771 | 7812 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 7772 | 7813 | input_list[i] = asm_instruction->input_list[i]->other; |
| 7773 | | if (input_list[i]->type_entry->id == TypeTableEntryIdInvalid) |
| 7814 | if (input_list[i]->value.type->id == TypeTableEntryIdInvalid) |
| 7774 | 7815 | return ira->codegen->builtin_types.entry_invalid; |
| 7775 | 7816 | } |
| 7776 | 7817 | |
| ... | ... | @@ -7825,8 +7866,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 7825 | 7866 | case TypeTableEntryIdEnumTag: |
| 7826 | 7867 | { |
| 7827 | 7868 | TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size); |
| 7828 | | bool depends_on_compile_var = child_type_value->static_value.depends_on_compile_var || |
| 7829 | | size_value->static_value.depends_on_compile_var; |
| 7869 | bool depends_on_compile_var = child_type_value->value.depends_on_compile_var || |
| 7870 | size_value->value.depends_on_compile_var; |
| 7830 | 7871 | ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base, |
| 7831 | 7872 | depends_on_compile_var); |
| 7832 | 7873 | out_val->data.x_type = result_type; |
| ... | ... | @@ -7927,10 +7968,10 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 7927 | 7968 | |
| 7928 | 7969 | static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 7929 | 7970 | IrInstruction *value = instruction->value->other; |
| 7930 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 7971 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 7931 | 7972 | return ira->codegen->builtin_types.entry_invalid; |
| 7932 | 7973 | |
| 7933 | | TypeTableEntry *type_entry = value->type_entry; |
| 7974 | TypeTableEntry *type_entry = value->value.type; |
| 7934 | 7975 | |
| 7935 | 7976 | if (type_entry->id == TypeTableEntryIdMaybe) { |
| 7936 | 7977 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -7961,11 +8002,11 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 7961 | 8002 | IrInstructionUnwrapMaybe *unwrap_maybe_instruction) |
| 7962 | 8003 | { |
| 7963 | 8004 | IrInstruction *value = unwrap_maybe_instruction->value->other; |
| 7964 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 8005 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 7965 | 8006 | return ira->codegen->builtin_types.entry_invalid; |
| 7966 | 8007 | |
| 7967 | 8008 | // This will be a pointer type because test null IR instruction operates on a pointer to a thing. |
| 7968 | | TypeTableEntry *ptr_type = value->type_entry; |
| 8009 | TypeTableEntry *ptr_type = value->value.type; |
| 7969 | 8010 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 7970 | 8011 | |
| 7971 | 8012 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; |
| ... | ... | @@ -8008,59 +8049,59 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 8008 | 8049 | |
| 8009 | 8050 | static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { |
| 8010 | 8051 | IrInstruction *value = ctz_instruction->value->other; |
| 8011 | | if (value->type_entry->id == TypeTableEntryIdInvalid) { |
| 8052 | if (value->value.type->id == TypeTableEntryIdInvalid) { |
| 8012 | 8053 | return ira->codegen->builtin_types.entry_invalid; |
| 8013 | | } else if (value->type_entry->id == TypeTableEntryIdInt) { |
| 8014 | | if (value->static_value.special != ConstValSpecialRuntime) { |
| 8015 | | uint32_t result = bignum_ctz(&value->static_value.data.x_bignum, |
| 8016 | | value->type_entry->data.integral.bit_count); |
| 8017 | | bool depends_on_compile_var = value->static_value.depends_on_compile_var; |
| 8054 | } else if (value->value.type->id == TypeTableEntryIdInt) { |
| 8055 | if (value->value.special != ConstValSpecialRuntime) { |
| 8056 | uint32_t result = bignum_ctz(&value->value.data.x_bignum, |
| 8057 | value->value.type->data.integral.bit_count); |
| 8058 | bool depends_on_compile_var = value->value.depends_on_compile_var; |
| 8018 | 8059 | ConstExprValue *out_val = ir_build_const_from(ira, &ctz_instruction->base, |
| 8019 | 8060 | depends_on_compile_var); |
| 8020 | 8061 | bignum_init_unsigned(&out_val->data.x_bignum, result); |
| 8021 | | return value->type_entry; |
| 8062 | return value->value.type; |
| 8022 | 8063 | } |
| 8023 | 8064 | |
| 8024 | 8065 | ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value); |
| 8025 | | return value->type_entry; |
| 8066 | return value->value.type; |
| 8026 | 8067 | } else { |
| 8027 | 8068 | ir_add_error_node(ira, ctz_instruction->base.source_node, |
| 8028 | | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name))); |
| 8069 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 8029 | 8070 | return ira->codegen->builtin_types.entry_invalid; |
| 8030 | 8071 | } |
| 8031 | 8072 | } |
| 8032 | 8073 | |
| 8033 | 8074 | static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { |
| 8034 | 8075 | IrInstruction *value = clz_instruction->value->other; |
| 8035 | | if (value->type_entry->id == TypeTableEntryIdInvalid) { |
| 8076 | if (value->value.type->id == TypeTableEntryIdInvalid) { |
| 8036 | 8077 | return ira->codegen->builtin_types.entry_invalid; |
| 8037 | | } else if (value->type_entry->id == TypeTableEntryIdInt) { |
| 8038 | | if (value->static_value.special != ConstValSpecialRuntime) { |
| 8039 | | uint32_t result = bignum_clz(&value->static_value.data.x_bignum, |
| 8040 | | value->type_entry->data.integral.bit_count); |
| 8041 | | bool depends_on_compile_var = value->static_value.depends_on_compile_var; |
| 8078 | } else if (value->value.type->id == TypeTableEntryIdInt) { |
| 8079 | if (value->value.special != ConstValSpecialRuntime) { |
| 8080 | uint32_t result = bignum_clz(&value->value.data.x_bignum, |
| 8081 | value->value.type->data.integral.bit_count); |
| 8082 | bool depends_on_compile_var = value->value.depends_on_compile_var; |
| 8042 | 8083 | ConstExprValue *out_val = ir_build_const_from(ira, &clz_instruction->base, |
| 8043 | 8084 | depends_on_compile_var); |
| 8044 | 8085 | bignum_init_unsigned(&out_val->data.x_bignum, result); |
| 8045 | | return value->type_entry; |
| 8086 | return value->value.type; |
| 8046 | 8087 | } |
| 8047 | 8088 | |
| 8048 | 8089 | ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value); |
| 8049 | | return value->type_entry; |
| 8090 | return value->value.type; |
| 8050 | 8091 | } else { |
| 8051 | 8092 | ir_add_error_node(ira, clz_instruction->base.source_node, |
| 8052 | | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name))); |
| 8093 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 8053 | 8094 | return ira->codegen->builtin_types.entry_invalid; |
| 8054 | 8095 | } |
| 8055 | 8096 | } |
| 8056 | 8097 | |
| 8057 | 8098 | static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| 8058 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 8099 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 8059 | 8100 | return ira->codegen->invalid_instruction; |
| 8060 | 8101 | |
| 8061 | | if (value->type_entry->id != TypeTableEntryIdEnum) { |
| 8102 | if (value->value.type->id != TypeTableEntryIdEnum) { |
| 8062 | 8103 | ir_add_error(ira, source_instr, |
| 8063 | | buf_sprintf("expected enum type, found '%s'", buf_ptr(&value->type_entry->name))); |
| 8104 | buf_sprintf("expected enum type, found '%s'", buf_ptr(&value->value.type->name))); |
| 8064 | 8105 | return ira->codegen->invalid_instruction; |
| 8065 | 8106 | } |
| 8066 | 8107 | |
| ... | ... | @@ -8071,10 +8112,10 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_ |
| 8071 | 8112 | |
| 8072 | 8113 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 8073 | 8114 | source_instr->scope, source_instr->source_node); |
| 8074 | | const_instruction->base.type_entry = value->type_entry->data.enumeration.tag_type; |
| 8075 | | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 8076 | | const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var; |
| 8077 | | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, val->data.x_enum.tag); |
| 8115 | const_instruction->base.value.type = value->value.type->data.enumeration.tag_type; |
| 8116 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 8117 | const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var; |
| 8118 | bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, val->data.x_enum.tag); |
| 8078 | 8119 | return &const_instruction->base; |
| 8079 | 8120 | } |
| 8080 | 8121 | |
| ... | ... | @@ -8085,7 +8126,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 8085 | 8126 | IrInstructionSwitchBr *switch_br_instruction) |
| 8086 | 8127 | { |
| 8087 | 8128 | IrInstruction *target_value = switch_br_instruction->target_value->other; |
| 8088 | | if (target_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8129 | if (target_value->value.type->id == TypeTableEntryIdInvalid) |
| 8089 | 8130 | return ir_unreach_error(ira); |
| 8090 | 8131 | |
| 8091 | 8132 | size_t case_count = switch_br_instruction->case_count; |
| ... | ... | @@ -8103,24 +8144,24 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 8103 | 8144 | for (size_t i = 0; i < case_count; i += 1) { |
| 8104 | 8145 | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 8105 | 8146 | IrInstruction *case_value = old_case->value->other; |
| 8106 | | if (case_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8147 | if (case_value->value.type->id == TypeTableEntryIdInvalid) |
| 8107 | 8148 | return ir_unreach_error(ira); |
| 8108 | 8149 | |
| 8109 | | if (case_value->type_entry->id == TypeTableEntryIdEnum) { |
| 8150 | if (case_value->value.type->id == TypeTableEntryIdEnum) { |
| 8110 | 8151 | case_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, case_value); |
| 8111 | | if (case_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8152 | if (case_value->value.type->id == TypeTableEntryIdInvalid) |
| 8112 | 8153 | return ir_unreach_error(ira); |
| 8113 | 8154 | } |
| 8114 | 8155 | |
| 8115 | | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->type_entry); |
| 8116 | | if (casted_case_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8156 | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type); |
| 8157 | if (casted_case_value->value.type->id == TypeTableEntryIdInvalid) |
| 8117 | 8158 | return ir_unreach_error(ira); |
| 8118 | 8159 | |
| 8119 | 8160 | ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); |
| 8120 | 8161 | if (!case_val) |
| 8121 | 8162 | return ir_unreach_error(ira); |
| 8122 | 8163 | |
| 8123 | | if (const_values_equal(target_val, case_val, target_value->type_entry)) { |
| 8164 | if (const_values_equal(target_val, case_val)) { |
| 8124 | 8165 | old_dest_block = old_case->block; |
| 8125 | 8166 | break; |
| 8126 | 8167 | } |
| ... | ... | @@ -8144,17 +8185,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 8144 | 8185 | |
| 8145 | 8186 | IrInstruction *old_value = old_case->value; |
| 8146 | 8187 | IrInstruction *new_value = old_value->other; |
| 8147 | | if (new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8188 | if (new_value->value.type->id == TypeTableEntryIdInvalid) |
| 8148 | 8189 | continue; |
| 8149 | 8190 | |
| 8150 | | if (new_value->type_entry->id == TypeTableEntryIdEnum) { |
| 8191 | if (new_value->value.type->id == TypeTableEntryIdEnum) { |
| 8151 | 8192 | new_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, new_value); |
| 8152 | | if (new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8193 | if (new_value->value.type->id == TypeTableEntryIdInvalid) |
| 8153 | 8194 | continue; |
| 8154 | 8195 | } |
| 8155 | 8196 | |
| 8156 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->type_entry); |
| 8157 | | if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8197 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type); |
| 8198 | if (casted_new_value->value.type->id == TypeTableEntryIdInvalid) |
| 8158 | 8199 | continue; |
| 8159 | 8200 | |
| 8160 | 8201 | if (!ir_resolve_const(ira, casted_new_value, UndefBad)) |
| ... | ... | @@ -8173,15 +8214,15 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 8173 | 8214 | IrInstructionSwitchTarget *switch_target_instruction) |
| 8174 | 8215 | { |
| 8175 | 8216 | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other; |
| 8176 | | if (target_value_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 8217 | if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 8177 | 8218 | return ira->codegen->builtin_types.entry_invalid; |
| 8178 | 8219 | |
| 8179 | | assert(target_value_ptr->type_entry->id == TypeTableEntryIdPointer); |
| 8180 | | TypeTableEntry *target_type = target_value_ptr->type_entry->data.pointer.child_type; |
| 8181 | | bool depends_on_compile_var = target_value_ptr->static_value.depends_on_compile_var; |
| 8220 | assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); |
| 8221 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 8222 | bool depends_on_compile_var = target_value_ptr->value.depends_on_compile_var; |
| 8182 | 8223 | ConstExprValue *pointee_val = nullptr; |
| 8183 | | if (target_value_ptr->static_value.special != ConstValSpecialRuntime) { |
| 8184 | | pointee_val = const_ptr_pointee(&target_value_ptr->static_value); |
| 8224 | if (target_value_ptr->value.special != ConstValSpecialRuntime) { |
| 8225 | pointee_val = const_ptr_pointee(&target_value_ptr->value); |
| 8185 | 8226 | if (pointee_val->special == ConstValSpecialRuntime) |
| 8186 | 8227 | pointee_val = nullptr; |
| 8187 | 8228 | } |
| ... | ... | @@ -8206,6 +8247,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 8206 | 8247 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base, |
| 8207 | 8248 | depends_on_compile_var); |
| 8208 | 8249 | *out_val = *pointee_val; |
| 8250 | out_val->type = target_type; |
| 8209 | 8251 | return target_type; |
| 8210 | 8252 | } |
| 8211 | 8253 | |
| ... | ... | @@ -8223,7 +8265,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 8223 | 8265 | |
| 8224 | 8266 | IrInstruction *enum_value = ir_build_load_ptr(&ira->new_irb, switch_target_instruction->base.scope, |
| 8225 | 8267 | switch_target_instruction->base.source_node, target_value_ptr); |
| 8226 | | enum_value->type_entry = target_type; |
| 8268 | enum_value->value.type = target_type; |
| 8227 | 8269 | ir_build_enum_tag_from(&ira->new_irb, &switch_target_instruction->base, enum_value); |
| 8228 | 8270 | return tag_type; |
| 8229 | 8271 | } |
| ... | ... | @@ -8251,24 +8293,24 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 8251 | 8293 | |
| 8252 | 8294 | static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 8253 | 8295 | IrInstruction *target_value_ptr = instruction->target_value_ptr->other; |
| 8254 | | if (target_value_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 8296 | if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 8255 | 8297 | return ira->codegen->builtin_types.entry_invalid; |
| 8256 | 8298 | |
| 8257 | 8299 | IrInstruction *prong_value = instruction->prong_value->other; |
| 8258 | | if (prong_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8300 | if (prong_value->value.type->id == TypeTableEntryIdInvalid) |
| 8259 | 8301 | return ira->codegen->builtin_types.entry_invalid; |
| 8260 | 8302 | |
| 8261 | | assert(target_value_ptr->type_entry->id == TypeTableEntryIdPointer); |
| 8262 | | TypeTableEntry *target_type = target_value_ptr->type_entry->data.pointer.child_type; |
| 8303 | assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); |
| 8304 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 8263 | 8305 | if (target_type->id == TypeTableEntryIdEnum) { |
| 8264 | 8306 | ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); |
| 8265 | 8307 | if (!prong_val) |
| 8266 | 8308 | return ira->codegen->builtin_types.entry_invalid; |
| 8267 | 8309 | |
| 8268 | 8310 | TypeEnumField *field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint]; |
| 8269 | | if (prong_value->type_entry->id == TypeTableEntryIdEnumTag) { |
| 8311 | if (prong_value->value.type->id == TypeTableEntryIdEnumTag) { |
| 8270 | 8312 | field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint]; |
| 8271 | | } else if (prong_value->type_entry->id == TypeTableEntryIdEnum) { |
| 8313 | } else if (prong_value->value.type->id == TypeTableEntryIdEnum) { |
| 8272 | 8314 | field = &target_type->data.enumeration.fields[prong_val->data.x_enum.tag]; |
| 8273 | 8315 | } else { |
| 8274 | 8316 | zig_unreachable(); |
| ... | ... | @@ -8280,7 +8322,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 8280 | 8322 | |
| 8281 | 8323 | ir_build_enum_field_ptr_from(&ira->new_irb, &instruction->base, target_value_ptr, field); |
| 8282 | 8324 | return get_pointer_to_type(ira->codegen, field->type_entry, |
| 8283 | | target_value_ptr->type_entry->data.pointer.is_const); |
| 8325 | target_value_ptr->value.type->data.pointer.is_const); |
| 8284 | 8326 | } else { |
| 8285 | 8327 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 8286 | 8328 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| ... | ... | @@ -8293,14 +8335,14 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc |
| 8293 | 8335 | IrInstruction *value = enum_tag_instruction->value->other; |
| 8294 | 8336 | IrInstruction *new_instruction = ir_analyze_enum_tag(ira, &enum_tag_instruction->base, value); |
| 8295 | 8337 | ir_link_new_instruction(new_instruction, &enum_tag_instruction->base); |
| 8296 | | return new_instruction->type_entry; |
| 8338 | return new_instruction->value.type; |
| 8297 | 8339 | } |
| 8298 | 8340 | |
| 8299 | 8341 | static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira, |
| 8300 | 8342 | IrInstructionStaticEval *static_eval_instruction) |
| 8301 | 8343 | { |
| 8302 | 8344 | IrInstruction *value = static_eval_instruction->value->other; |
| 8303 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 8345 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 8304 | 8346 | return ira->codegen->builtin_types.entry_invalid; |
| 8305 | 8347 | |
| 8306 | 8348 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -8309,7 +8351,7 @@ static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira, |
| 8309 | 8351 | |
| 8310 | 8352 | ConstExprValue *out_val = ir_build_const_from(ira, &static_eval_instruction->base, val->depends_on_compile_var); |
| 8311 | 8353 | *out_val = *val; |
| 8312 | | return value->type_entry; |
| 8354 | return value->value.type; |
| 8313 | 8355 | } |
| 8314 | 8356 | |
| 8315 | 8357 | static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { |
| ... | ... | @@ -8317,7 +8359,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 8317 | 8359 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 8318 | 8360 | if (!import_target_str) |
| 8319 | 8361 | return ira->codegen->builtin_types.entry_invalid; |
| 8320 | | bool depends_on_compile_var = name_value->static_value.depends_on_compile_var; |
| 8362 | bool depends_on_compile_var = name_value->value.depends_on_compile_var; |
| 8321 | 8363 | |
| 8322 | 8364 | AstNode *source_node = import_instruction->base.source_node; |
| 8323 | 8365 | ImportTableEntry *import = source_node->owner; |
| ... | ... | @@ -8390,16 +8432,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 8390 | 8432 | IrInstructionArrayLen *array_len_instruction) |
| 8391 | 8433 | { |
| 8392 | 8434 | IrInstruction *array_value = array_len_instruction->array_value->other; |
| 8393 | | TypeTableEntry *canon_type = get_underlying_type(array_value->type_entry); |
| 8435 | TypeTableEntry *canon_type = get_underlying_type(array_value->value.type); |
| 8394 | 8436 | if (canon_type->id == TypeTableEntryIdInvalid) { |
| 8395 | 8437 | return ira->codegen->builtin_types.entry_invalid; |
| 8396 | 8438 | } else if (canon_type->id == TypeTableEntryIdArray) { |
| 8397 | | bool depends_on_compile_var = array_value->static_value.depends_on_compile_var; |
| 8439 | bool depends_on_compile_var = array_value->value.depends_on_compile_var; |
| 8398 | 8440 | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 8399 | 8441 | canon_type->data.array.len, depends_on_compile_var); |
| 8400 | 8442 | } else if (is_slice(canon_type)) { |
| 8401 | | if (array_value->static_value.special != ConstValSpecialRuntime) { |
| 8402 | | ConstExprValue *len_val = &array_value->static_value.data.x_struct.fields[slice_len_index]; |
| 8443 | if (array_value->value.special != ConstValSpecialRuntime) { |
| 8444 | ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index]; |
| 8403 | 8445 | if (len_val->special != ConstValSpecialRuntime) { |
| 8404 | 8446 | bool depends_on_compile_var = len_val->depends_on_compile_var; |
| 8405 | 8447 | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| ... | ... | @@ -8409,12 +8451,12 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 8409 | 8451 | TypeStructField *field = &canon_type->data.structure.fields[slice_len_index]; |
| 8410 | 8452 | IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope, |
| 8411 | 8453 | array_len_instruction->base.source_node, array_value, field); |
| 8412 | | len_ptr->type_entry = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true); |
| 8454 | len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true); |
| 8413 | 8455 | ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr); |
| 8414 | 8456 | return ira->codegen->builtin_types.entry_usize; |
| 8415 | 8457 | } else { |
| 8416 | 8458 | ir_add_error_node(ira, array_len_instruction->base.source_node, |
| 8417 | | buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->type_entry->name))); |
| 8459 | buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name))); |
| 8418 | 8460 | // TODO if this is a typedecl, add error note showing the declaration of the type decl |
| 8419 | 8461 | return ira->codegen->builtin_types.entry_invalid; |
| 8420 | 8462 | } |
| ... | ... | @@ -8444,13 +8486,14 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 8444 | 8486 | |
| 8445 | 8487 | ConstExprValue const_val = {}; |
| 8446 | 8488 | const_val.special = ConstValSpecialStatic; |
| 8489 | const_val.type = container_type; |
| 8447 | 8490 | const_val.depends_on_compile_var = depends_on_compile_var; |
| 8448 | 8491 | const_val.data.x_struct.fields = allocate<ConstExprValue>(actual_field_count); |
| 8449 | 8492 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 8450 | 8493 | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 8451 | 8494 | |
| 8452 | 8495 | IrInstruction *field_value = field->value->other; |
| 8453 | | if (field_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8496 | if (field_value->value.type->id == TypeTableEntryIdInvalid) |
| 8454 | 8497 | return ira->codegen->builtin_types.entry_invalid; |
| 8455 | 8498 | |
| 8456 | 8499 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| ... | ... | @@ -8481,7 +8524,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 8481 | 8524 | new_fields[field_index].type_struct_field = type_field; |
| 8482 | 8525 | |
| 8483 | 8526 | if (const_val.special == ConstValSpecialStatic) { |
| 8484 | | if (is_comptime || casted_field_value->static_value.special != ConstValSpecialRuntime) { |
| 8527 | if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime) { |
| 8485 | 8528 | ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk); |
| 8486 | 8529 | if (!field_val) |
| 8487 | 8530 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -8529,16 +8572,16 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8529 | 8572 | IrInstructionContainerInitList *instruction) |
| 8530 | 8573 | { |
| 8531 | 8574 | IrInstruction *container_type_value = instruction->container_type->other; |
| 8532 | | if (container_type_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8575 | if (container_type_value->value.type->id == TypeTableEntryIdInvalid) |
| 8533 | 8576 | return ira->codegen->builtin_types.entry_invalid; |
| 8534 | 8577 | |
| 8535 | 8578 | size_t elem_count = instruction->item_count; |
| 8536 | | if (container_type_value->type_entry->id == TypeTableEntryIdMetaType) { |
| 8579 | if (container_type_value->value.type->id == TypeTableEntryIdMetaType) { |
| 8537 | 8580 | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); |
| 8538 | 8581 | if (container_type->id == TypeTableEntryIdInvalid) |
| 8539 | 8582 | return ira->codegen->builtin_types.entry_invalid; |
| 8540 | 8583 | |
| 8541 | | bool depends_on_compile_var = container_type_value->static_value.depends_on_compile_var; |
| 8584 | bool depends_on_compile_var = container_type_value->value.depends_on_compile_var; |
| 8542 | 8585 | |
| 8543 | 8586 | if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) { |
| 8544 | 8587 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| ... | ... | @@ -8547,9 +8590,11 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8547 | 8590 | TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8548 | 8591 | assert(pointer_type->id == TypeTableEntryIdPointer); |
| 8549 | 8592 | TypeTableEntry *child_type = pointer_type->data.pointer.child_type; |
| 8593 | TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); |
| 8550 | 8594 | |
| 8551 | 8595 | ConstExprValue const_val = {}; |
| 8552 | 8596 | const_val.special = ConstValSpecialStatic; |
| 8597 | const_val.type = fixed_size_array_type; |
| 8553 | 8598 | const_val.depends_on_compile_var = depends_on_compile_var; |
| 8554 | 8599 | const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count); |
| 8555 | 8600 | const_val.data.x_array.size = elem_count; |
| ... | ... | @@ -8562,7 +8607,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8562 | 8607 | |
| 8563 | 8608 | for (size_t i = 0; i < elem_count; i += 1) { |
| 8564 | 8609 | IrInstruction *arg_value = instruction->items[i]->other; |
| 8565 | | if (arg_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8610 | if (arg_value->value.type->id == TypeTableEntryIdInvalid) |
| 8566 | 8611 | return ira->codegen->builtin_types.entry_invalid; |
| 8567 | 8612 | |
| 8568 | 8613 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type); |
| ... | ... | @@ -8572,7 +8617,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8572 | 8617 | new_items[i] = casted_arg; |
| 8573 | 8618 | |
| 8574 | 8619 | if (const_val.special == ConstValSpecialStatic) { |
| 8575 | | if (is_comptime || casted_arg->static_value.special != ConstValSpecialRuntime) { |
| 8620 | if (is_comptime || casted_arg->value.special != ConstValSpecialRuntime) { |
| 8576 | 8621 | ConstExprValue *elem_val = ir_resolve_const(ira, casted_arg, UndefBad); |
| 8577 | 8622 | if (!elem_val) |
| 8578 | 8623 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -8586,7 +8631,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8586 | 8631 | } |
| 8587 | 8632 | } |
| 8588 | 8633 | |
| 8589 | | TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); |
| 8590 | 8634 | if (const_val.special == ConstValSpecialStatic) { |
| 8591 | 8635 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, const_val.depends_on_compile_var); |
| 8592 | 8636 | *out_val = const_val; |
| ... | ... | @@ -8619,7 +8663,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8619 | 8663 | buf_ptr(&container_type->name))); |
| 8620 | 8664 | return ira->codegen->builtin_types.entry_invalid; |
| 8621 | 8665 | } |
| 8622 | | } else if (container_type_value->type_entry->id == TypeTableEntryIdEnumTag) { |
| 8666 | } else if (container_type_value->value.type->id == TypeTableEntryIdEnumTag) { |
| 8623 | 8667 | if (elem_count != 1) { |
| 8624 | 8668 | ir_add_error(ira, &instruction->base, buf_sprintf("enum initialization requires exactly one element")); |
| 8625 | 8669 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -8628,7 +8672,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8628 | 8672 | if (!tag_value) |
| 8629 | 8673 | return ira->codegen->builtin_types.entry_invalid; |
| 8630 | 8674 | |
| 8631 | | TypeTableEntry *enum_type = container_type_value->type_entry->data.enum_tag.enum_type; |
| 8675 | TypeTableEntry *enum_type = container_type_value->value.type->data.enum_tag.enum_type; |
| 8632 | 8676 | |
| 8633 | 8677 | uint64_t tag_uint = tag_value->data.x_bignum.data.x_uint; |
| 8634 | 8678 | TypeEnumField *field = &enum_type->data.enumeration.fields[tag_uint]; |
| ... | ... | @@ -8645,7 +8689,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8645 | 8689 | if (!init_val) |
| 8646 | 8690 | return ira->codegen->builtin_types.entry_invalid; |
| 8647 | 8691 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, |
| 8648 | | casted_init_value->static_value.depends_on_compile_var); |
| 8692 | casted_init_value->value.depends_on_compile_var); |
| 8649 | 8693 | out_val->data.x_enum.tag = tag_uint; |
| 8650 | 8694 | out_val->data.x_enum.payload = init_val; |
| 8651 | 8695 | return enum_type; |
| ... | ... | @@ -8657,7 +8701,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 8657 | 8701 | return enum_type; |
| 8658 | 8702 | } else { |
| 8659 | 8703 | ir_add_error(ira, container_type_value, |
| 8660 | | buf_sprintf("expected type, found '%s'", buf_ptr(&container_type_value->type_entry->name))); |
| 8704 | buf_sprintf("expected type, found '%s'", buf_ptr(&container_type_value->value.type->name))); |
| 8661 | 8705 | return ira->codegen->builtin_types.entry_invalid; |
| 8662 | 8706 | } |
| 8663 | 8707 | } |
| ... | ... | @@ -8668,7 +8712,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i |
| 8668 | 8712 | if (container_type->id == TypeTableEntryIdInvalid) |
| 8669 | 8713 | return ira->codegen->builtin_types.entry_invalid; |
| 8670 | 8714 | |
| 8671 | | bool depends_on_compile_var = container_type_value->static_value.depends_on_compile_var; |
| 8715 | bool depends_on_compile_var = container_type_value->value.depends_on_compile_var; |
| 8672 | 8716 | |
| 8673 | 8717 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 8674 | 8718 | instruction->field_count, instruction->fields, depends_on_compile_var); |
| ... | ... | @@ -8678,7 +8722,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 8678 | 8722 | IrInstruction *target_type_value, bool is_max) |
| 8679 | 8723 | { |
| 8680 | 8724 | TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value); |
| 8681 | | bool depends_on_compile_var = target_type_value->static_value.depends_on_compile_var; |
| 8725 | bool depends_on_compile_var = target_type_value->value.depends_on_compile_var; |
| 8682 | 8726 | TypeTableEntry *canon_type = get_underlying_type(target_type); |
| 8683 | 8727 | switch (canon_type->id) { |
| 8684 | 8728 | case TypeTableEntryIdInvalid: |
| ... | ... | @@ -8763,35 +8807,22 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 8763 | 8807 | |
| 8764 | 8808 | static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 8765 | 8809 | IrInstruction *value = instruction->value->other; |
| 8766 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 8810 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 8767 | 8811 | return ira->codegen->builtin_types.entry_invalid; |
| 8768 | 8812 | |
| 8769 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, value->type_entry); |
| 8770 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8813 | IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type); |
| 8814 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 8771 | 8815 | return ira->codegen->builtin_types.entry_invalid; |
| 8772 | 8816 | |
| 8773 | 8817 | TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true); |
| 8774 | | if (casted_value->static_value.special == ConstValSpecialStatic) { |
| 8775 | | ErrorTableEntry *err = casted_value->static_value.data.x_pure_err; |
| 8818 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 8819 | ErrorTableEntry *err = casted_value->value.data.x_pure_err; |
| 8776 | 8820 | if (!err->cached_error_name_val) { |
| 8777 | | err->cached_error_name_val = allocate<ConstExprValue>(1); |
| 8778 | | err->cached_error_name_val->special = ConstValSpecialStatic; |
| 8779 | | err->cached_error_name_val->data.x_struct.fields = allocate<ConstExprValue>(2); |
| 8780 | | |
| 8781 | | ConstExprValue *array_val = allocate<ConstExprValue>(1); |
| 8782 | | init_const_str_lit(array_val, &err->name); |
| 8783 | | |
| 8784 | | ConstExprValue *ptr_val = &err->cached_error_name_val->data.x_struct.fields[slice_ptr_index]; |
| 8785 | | ptr_val->special = ConstValSpecialStatic; |
| 8786 | | ptr_val->data.x_ptr.base_ptr = array_val; |
| 8787 | | ptr_val->data.x_ptr.index = 0; |
| 8788 | | |
| 8789 | | ConstExprValue *len_val = &err->cached_error_name_val->data.x_struct.fields[slice_len_index]; |
| 8790 | | len_val->special = ConstValSpecialStatic; |
| 8791 | | bignum_init_unsigned(&len_val->data.x_bignum, buf_len(&err->name)); |
| 8821 | ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name); |
| 8822 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 8792 | 8823 | } |
| 8793 | 8824 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, |
| 8794 | | casted_value->static_value.depends_on_compile_var); |
| 8825 | casted_value->value.depends_on_compile_var); |
| 8795 | 8826 | *out_val = *err->cached_error_name_val; |
| 8796 | 8827 | return str_type; |
| 8797 | 8828 | } |
| ... | ... | @@ -8813,7 +8844,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 8813 | 8844 | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 8814 | 8845 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 8815 | 8846 | &cimport_scope->buf, block_node, nullptr, nullptr); |
| 8816 | | if (result->type_entry->id == TypeTableEntryIdInvalid) |
| 8847 | if (result->value.type->id == TypeTableEntryIdInvalid) |
| 8817 | 8848 | return ira->codegen->builtin_types.entry_invalid; |
| 8818 | 8849 | |
| 8819 | 8850 | find_libc_include_path(ira->codegen); |
| ... | ... | @@ -8855,7 +8886,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 8855 | 8886 | |
| 8856 | 8887 | static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 8857 | 8888 | IrInstruction *name_value = instruction->name->other; |
| 8858 | | if (name_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8889 | if (name_value->value.type->id == TypeTableEntryIdInvalid) |
| 8859 | 8890 | return ira->codegen->builtin_types.entry_invalid; |
| 8860 | 8891 | |
| 8861 | 8892 | Buf *include_name = ir_resolve_str(ira, name_value); |
| ... | ... | @@ -8874,7 +8905,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru |
| 8874 | 8905 | |
| 8875 | 8906 | static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 8876 | 8907 | IrInstruction *name = instruction->name->other; |
| 8877 | | if (name->type_entry->id == TypeTableEntryIdInvalid) |
| 8908 | if (name->value.type->id == TypeTableEntryIdInvalid) |
| 8878 | 8909 | return ira->codegen->builtin_types.entry_invalid; |
| 8879 | 8910 | |
| 8880 | 8911 | Buf *define_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -8882,7 +8913,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc |
| 8882 | 8913 | return ira->codegen->builtin_types.entry_invalid; |
| 8883 | 8914 | |
| 8884 | 8915 | IrInstruction *value = instruction->value->other; |
| 8885 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 8916 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 8886 | 8917 | return ira->codegen->builtin_types.entry_invalid; |
| 8887 | 8918 | |
| 8888 | 8919 | Buf *define_value = ir_resolve_str(ira, value); |
| ... | ... | @@ -8901,7 +8932,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc |
| 8901 | 8932 | |
| 8902 | 8933 | static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 8903 | 8934 | IrInstruction *name = instruction->name->other; |
| 8904 | | if (name->type_entry->id == TypeTableEntryIdInvalid) |
| 8935 | if (name->value.type->id == TypeTableEntryIdInvalid) |
| 8905 | 8936 | return ira->codegen->builtin_types.entry_invalid; |
| 8906 | 8937 | |
| 8907 | 8938 | Buf *undef_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -8920,7 +8951,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct |
| 8920 | 8951 | |
| 8921 | 8952 | static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 8922 | 8953 | IrInstruction *name = instruction->name->other; |
| 8923 | | if (name->type_entry->id == TypeTableEntryIdInvalid) |
| 8954 | if (name->value.type->id == TypeTableEntryIdInvalid) |
| 8924 | 8955 | return ira->codegen->builtin_types.entry_invalid; |
| 8925 | 8956 | |
| 8926 | 8957 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| ... | ... | @@ -8953,26 +8984,26 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr |
| 8953 | 8984 | |
| 8954 | 8985 | bool depends_on_compile_var = true; |
| 8955 | 8986 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 8956 | | init_const_str_lit(out_val, &file_contents); |
| 8987 | init_const_str_lit(ira->codegen, out_val, &file_contents); |
| 8957 | 8988 | |
| 8958 | 8989 | return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(&file_contents)); |
| 8959 | 8990 | } |
| 8960 | 8991 | |
| 8961 | 8992 | static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { |
| 8962 | 8993 | IrInstruction *ptr = instruction->ptr->other; |
| 8963 | | if (ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 8994 | if (ptr->value.type->id == TypeTableEntryIdInvalid) |
| 8964 | 8995 | return ira->codegen->builtin_types.entry_invalid; |
| 8965 | 8996 | |
| 8966 | 8997 | IrInstruction *cmp_value = instruction->cmp_value->other; |
| 8967 | | if (cmp_value->type_entry->id == TypeTableEntryIdInvalid) |
| 8998 | if (cmp_value->value.type->id == TypeTableEntryIdInvalid) |
| 8968 | 8999 | return ira->codegen->builtin_types.entry_invalid; |
| 8969 | 9000 | |
| 8970 | 9001 | IrInstruction *new_value = instruction->new_value->other; |
| 8971 | | if (new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9002 | if (new_value->value.type->id == TypeTableEntryIdInvalid) |
| 8972 | 9003 | return ira->codegen->builtin_types.entry_invalid; |
| 8973 | 9004 | |
| 8974 | 9005 | IrInstruction *success_order_value = instruction->success_order_value->other; |
| 8975 | | if (success_order_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9006 | if (success_order_value->value.type->id == TypeTableEntryIdInvalid) |
| 8976 | 9007 | return ira->codegen->builtin_types.entry_invalid; |
| 8977 | 9008 | |
| 8978 | 9009 | AtomicOrder success_order; |
| ... | ... | @@ -8980,27 +9011,27 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 8980 | 9011 | return ira->codegen->builtin_types.entry_invalid; |
| 8981 | 9012 | |
| 8982 | 9013 | IrInstruction *failure_order_value = instruction->failure_order_value->other; |
| 8983 | | if (failure_order_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9014 | if (failure_order_value->value.type->id == TypeTableEntryIdInvalid) |
| 8984 | 9015 | return ira->codegen->builtin_types.entry_invalid; |
| 8985 | 9016 | |
| 8986 | 9017 | AtomicOrder failure_order; |
| 8987 | 9018 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 8988 | 9019 | return ira->codegen->builtin_types.entry_invalid; |
| 8989 | 9020 | |
| 8990 | | if (ptr->type_entry->id != TypeTableEntryIdPointer) { |
| 9021 | if (ptr->value.type->id != TypeTableEntryIdPointer) { |
| 8991 | 9022 | ir_add_error(ira, instruction->ptr, |
| 8992 | | buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr->type_entry->name))); |
| 9023 | buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr->value.type->name))); |
| 8993 | 9024 | return ira->codegen->builtin_types.entry_invalid; |
| 8994 | 9025 | } |
| 8995 | 9026 | |
| 8996 | | TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type; |
| 9027 | TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type; |
| 8997 | 9028 | |
| 8998 | 9029 | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type); |
| 8999 | | if (casted_cmp_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9030 | if (casted_cmp_value->value.type->id == TypeTableEntryIdInvalid) |
| 9000 | 9031 | return ira->codegen->builtin_types.entry_invalid; |
| 9001 | 9032 | |
| 9002 | 9033 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type); |
| 9003 | | if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9034 | if (casted_new_value->value.type->id == TypeTableEntryIdInvalid) |
| 9004 | 9035 | return ira->codegen->builtin_types.entry_invalid; |
| 9005 | 9036 | |
| 9006 | 9037 | if (success_order < AtomicOrderMonotonic) { |
| ... | ... | @@ -9031,7 +9062,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 9031 | 9062 | |
| 9032 | 9063 | static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 9033 | 9064 | IrInstruction *order_value = instruction->order_value->other; |
| 9034 | | if (order_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9065 | if (order_value->value.type->id == TypeTableEntryIdInvalid) |
| 9035 | 9066 | return ira->codegen->builtin_types.entry_invalid; |
| 9036 | 9067 | |
| 9037 | 9068 | AtomicOrder order; |
| ... | ... | @@ -9044,11 +9075,11 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio |
| 9044 | 9075 | |
| 9045 | 9076 | static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstructionDivExact *instruction) { |
| 9046 | 9077 | IrInstruction *op1 = instruction->op1->other; |
| 9047 | | if (op1->type_entry->id == TypeTableEntryIdInvalid) |
| 9078 | if (op1->value.type->id == TypeTableEntryIdInvalid) |
| 9048 | 9079 | return ira->codegen->builtin_types.entry_invalid; |
| 9049 | 9080 | |
| 9050 | 9081 | IrInstruction *op2 = instruction->op2->other; |
| 9051 | | if (op2->type_entry->id == TypeTableEntryIdInvalid) |
| 9082 | if (op2->value.type->id == TypeTableEntryIdInvalid) |
| 9052 | 9083 | return ira->codegen->builtin_types.entry_invalid; |
| 9053 | 9084 | |
| 9054 | 9085 | |
| ... | ... | @@ -9070,15 +9101,15 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru |
| 9070 | 9101 | } |
| 9071 | 9102 | |
| 9072 | 9103 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type); |
| 9073 | | if (casted_op1->type_entry->id == TypeTableEntryIdInvalid) |
| 9104 | if (casted_op1->value.type->id == TypeTableEntryIdInvalid) |
| 9074 | 9105 | return ira->codegen->builtin_types.entry_invalid; |
| 9075 | 9106 | |
| 9076 | 9107 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type); |
| 9077 | | if (casted_op2->type_entry->id == TypeTableEntryIdInvalid) |
| 9108 | if (casted_op2->value.type->id == TypeTableEntryIdInvalid) |
| 9078 | 9109 | return ira->codegen->builtin_types.entry_invalid; |
| 9079 | 9110 | |
| 9080 | | if (casted_op1->static_value.special == ConstValSpecialStatic && |
| 9081 | | casted_op2->static_value.special == ConstValSpecialStatic) |
| 9111 | if (casted_op1->value.special == ConstValSpecialStatic && |
| 9112 | casted_op2->value.special == ConstValSpecialStatic) |
| 9082 | 9113 | { |
| 9083 | 9114 | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 9084 | 9115 | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| ... | ... | @@ -9101,8 +9132,8 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru |
| 9101 | 9132 | return ira->codegen->builtin_types.entry_invalid; |
| 9102 | 9133 | } |
| 9103 | 9134 | |
| 9104 | | bool depends_on_compile_var = casted_op1->static_value.depends_on_compile_var || |
| 9105 | | casted_op2->static_value.depends_on_compile_var; |
| 9135 | bool depends_on_compile_var = casted_op1->value.depends_on_compile_var || |
| 9136 | casted_op2->value.depends_on_compile_var; |
| 9106 | 9137 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9107 | 9138 | bignum_div(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum); |
| 9108 | 9139 | return result_type; |
| ... | ... | @@ -9129,7 +9160,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc |
| 9129 | 9160 | } |
| 9130 | 9161 | |
| 9131 | 9162 | IrInstruction *target = instruction->target->other; |
| 9132 | | TypeTableEntry *src_type = target->type_entry; |
| 9163 | TypeTableEntry *src_type = target->value.type; |
| 9133 | 9164 | TypeTableEntry *canon_src_type = get_underlying_type(src_type); |
| 9134 | 9165 | if (canon_src_type->id == TypeTableEntryIdInvalid) |
| 9135 | 9166 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -9154,10 +9185,10 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc |
| 9154 | 9185 | return ira->codegen->builtin_types.entry_invalid; |
| 9155 | 9186 | } |
| 9156 | 9187 | |
| 9157 | | if (target->static_value.special == ConstValSpecialStatic) { |
| 9158 | | bool depends_on_compile_var = dest_type_value->static_value.depends_on_compile_var || target->static_value.depends_on_compile_var; |
| 9188 | if (target->value.special == ConstValSpecialStatic) { |
| 9189 | bool depends_on_compile_var = dest_type_value->value.depends_on_compile_var || target->value.depends_on_compile_var; |
| 9159 | 9190 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9160 | | bignum_init_bignum(&out_val->data.x_bignum, &target->static_value.data.x_bignum); |
| 9191 | bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum); |
| 9161 | 9192 | bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count); |
| 9162 | 9193 | return dest_type; |
| 9163 | 9194 | } |
| ... | ... | @@ -9177,8 +9208,8 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc |
| 9177 | 9208 | if (!ir_resolve_usize(ira, bit_count_value, &bit_count)) |
| 9178 | 9209 | return ira->codegen->builtin_types.entry_invalid; |
| 9179 | 9210 | |
| 9180 | | bool depends_on_compile_var = is_signed_value->static_value.depends_on_compile_var || |
| 9181 | | bit_count_value->static_value.depends_on_compile_var; |
| 9211 | bool depends_on_compile_var = is_signed_value->value.depends_on_compile_var || |
| 9212 | bit_count_value->value.depends_on_compile_var; |
| 9182 | 9213 | |
| 9183 | 9214 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9184 | 9215 | out_val->data.x_type = get_int_type(ira->codegen, is_signed, bit_count); |
| ... | ... | @@ -9187,19 +9218,19 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc |
| 9187 | 9218 | |
| 9188 | 9219 | static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 9189 | 9220 | IrInstruction *value = instruction->value->other; |
| 9190 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 9221 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 9191 | 9222 | return ira->codegen->builtin_types.entry_invalid; |
| 9192 | 9223 | |
| 9193 | 9224 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; |
| 9194 | 9225 | |
| 9195 | 9226 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 9196 | | if (casted_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9227 | if (casted_value->value.type->id == TypeTableEntryIdInvalid) |
| 9197 | 9228 | return ira->codegen->builtin_types.entry_invalid; |
| 9198 | 9229 | |
| 9199 | | if (casted_value->static_value.special != ConstValSpecialRuntime) { |
| 9200 | | bool depends_on_compile_var = casted_value->static_value.depends_on_compile_var; |
| 9230 | if (casted_value->value.special != ConstValSpecialRuntime) { |
| 9231 | bool depends_on_compile_var = casted_value->value.depends_on_compile_var; |
| 9201 | 9232 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9202 | | out_val->data.x_bool = !casted_value->static_value.data.x_bool; |
| 9233 | out_val->data.x_bool = !casted_value->value.data.x_bool; |
| 9203 | 9234 | return bool_type; |
| 9204 | 9235 | } |
| 9205 | 9236 | |
| ... | ... | @@ -9209,11 +9240,11 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc |
| 9209 | 9240 | |
| 9210 | 9241 | static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructionAlloca *instruction) { |
| 9211 | 9242 | IrInstruction *type_value = instruction->type_value->other; |
| 9212 | | if (type_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9243 | if (type_value->value.type->id == TypeTableEntryIdInvalid) |
| 9213 | 9244 | return ira->codegen->builtin_types.entry_invalid; |
| 9214 | 9245 | |
| 9215 | 9246 | IrInstruction *count_value = instruction->count->other; |
| 9216 | | if (count_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9247 | if (count_value->value.type->id == TypeTableEntryIdInvalid) |
| 9217 | 9248 | return ira->codegen->builtin_types.entry_invalid; |
| 9218 | 9249 | |
| 9219 | 9250 | TypeTableEntry *child_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -9234,15 +9265,15 @@ static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructi |
| 9234 | 9265 | |
| 9235 | 9266 | static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 9236 | 9267 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 9237 | | if (dest_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9268 | if (dest_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9238 | 9269 | return ira->codegen->builtin_types.entry_invalid; |
| 9239 | 9270 | |
| 9240 | 9271 | IrInstruction *byte_value = instruction->byte->other; |
| 9241 | | if (byte_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9272 | if (byte_value->value.type->id == TypeTableEntryIdInvalid) |
| 9242 | 9273 | return ira->codegen->builtin_types.entry_invalid; |
| 9243 | 9274 | |
| 9244 | 9275 | IrInstruction *count_value = instruction->count->other; |
| 9245 | | if (count_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9276 | if (count_value->value.type->id == TypeTableEntryIdInvalid) |
| 9246 | 9277 | return ira->codegen->builtin_types.entry_invalid; |
| 9247 | 9278 | |
| 9248 | 9279 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| ... | ... | @@ -9250,22 +9281,22 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 9250 | 9281 | TypeTableEntry *u8_ptr = get_pointer_to_type(ira->codegen, u8, false); |
| 9251 | 9282 | |
| 9252 | 9283 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 9253 | | if (casted_dest_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9284 | if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9254 | 9285 | return ira->codegen->builtin_types.entry_invalid; |
| 9255 | 9286 | |
| 9256 | 9287 | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 9257 | | if (casted_byte->type_entry->id == TypeTableEntryIdInvalid) |
| 9288 | if (casted_byte->value.type->id == TypeTableEntryIdInvalid) |
| 9258 | 9289 | return ira->codegen->builtin_types.entry_invalid; |
| 9259 | 9290 | |
| 9260 | 9291 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 9261 | | if (casted_count->type_entry->id == TypeTableEntryIdInvalid) |
| 9292 | if (casted_count->value.type->id == TypeTableEntryIdInvalid) |
| 9262 | 9293 | return ira->codegen->builtin_types.entry_invalid; |
| 9263 | 9294 | |
| 9264 | | if (casted_dest_ptr->static_value.special == ConstValSpecialStatic && |
| 9265 | | casted_byte->static_value.special == ConstValSpecialStatic && |
| 9266 | | casted_count->static_value.special == ConstValSpecialStatic) |
| 9295 | if (casted_dest_ptr->value.special == ConstValSpecialStatic && |
| 9296 | casted_byte->value.special == ConstValSpecialStatic && |
| 9297 | casted_count->value.special == ConstValSpecialStatic) |
| 9267 | 9298 | { |
| 9268 | | ConstExprValue *dest_ptr_val = &casted_dest_ptr->static_value; |
| 9299 | ConstExprValue *dest_ptr_val = &casted_dest_ptr->value; |
| 9269 | 9300 | |
| 9270 | 9301 | ConstExprValue *dest_elements; |
| 9271 | 9302 | size_t start; |
| ... | ... | @@ -9281,14 +9312,14 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 9281 | 9312 | bound_end = array_val->data.x_array.size; |
| 9282 | 9313 | } |
| 9283 | 9314 | |
| 9284 | | size_t count = casted_count->static_value.data.x_bignum.data.x_uint; |
| 9315 | size_t count = casted_count->value.data.x_bignum.data.x_uint; |
| 9285 | 9316 | size_t end = start + count; |
| 9286 | 9317 | if (end > bound_end) { |
| 9287 | 9318 | ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access")); |
| 9288 | 9319 | return ira->codegen->builtin_types.entry_invalid; |
| 9289 | 9320 | } |
| 9290 | 9321 | |
| 9291 | | ConstExprValue *byte_val = &casted_byte->static_value; |
| 9322 | ConstExprValue *byte_val = &casted_byte->value; |
| 9292 | 9323 | for (size_t i = start; i < end; i += 1) { |
| 9293 | 9324 | dest_elements[i] = *byte_val; |
| 9294 | 9325 | } |
| ... | ... | @@ -9303,15 +9334,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 9303 | 9334 | |
| 9304 | 9335 | static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 9305 | 9336 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 9306 | | if (dest_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9337 | if (dest_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9307 | 9338 | return ira->codegen->builtin_types.entry_invalid; |
| 9308 | 9339 | |
| 9309 | 9340 | IrInstruction *src_ptr = instruction->src_ptr->other; |
| 9310 | | if (src_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9341 | if (src_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9311 | 9342 | return ira->codegen->builtin_types.entry_invalid; |
| 9312 | 9343 | |
| 9313 | 9344 | IrInstruction *count_value = instruction->count->other; |
| 9314 | | if (count_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9345 | if (count_value->value.type->id == TypeTableEntryIdInvalid) |
| 9315 | 9346 | return ira->codegen->builtin_types.entry_invalid; |
| 9316 | 9347 | |
| 9317 | 9348 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| ... | ... | @@ -9320,24 +9351,24 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 9320 | 9351 | TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 9321 | 9352 | |
| 9322 | 9353 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 9323 | | if (casted_dest_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9354 | if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9324 | 9355 | return ira->codegen->builtin_types.entry_invalid; |
| 9325 | 9356 | |
| 9326 | 9357 | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 9327 | | if (casted_src_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9358 | if (casted_src_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9328 | 9359 | return ira->codegen->builtin_types.entry_invalid; |
| 9329 | 9360 | |
| 9330 | 9361 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 9331 | | if (casted_count->type_entry->id == TypeTableEntryIdInvalid) |
| 9362 | if (casted_count->value.type->id == TypeTableEntryIdInvalid) |
| 9332 | 9363 | return ira->codegen->builtin_types.entry_invalid; |
| 9333 | 9364 | |
| 9334 | | if (casted_dest_ptr->static_value.special == ConstValSpecialStatic && |
| 9335 | | casted_src_ptr->static_value.special == ConstValSpecialStatic && |
| 9336 | | casted_count->static_value.special == ConstValSpecialStatic) |
| 9365 | if (casted_dest_ptr->value.special == ConstValSpecialStatic && |
| 9366 | casted_src_ptr->value.special == ConstValSpecialStatic && |
| 9367 | casted_count->value.special == ConstValSpecialStatic) |
| 9337 | 9368 | { |
| 9338 | | size_t count = casted_count->static_value.data.x_bignum.data.x_uint; |
| 9369 | size_t count = casted_count->value.data.x_bignum.data.x_uint; |
| 9339 | 9370 | |
| 9340 | | ConstExprValue *dest_ptr_val = &casted_dest_ptr->static_value; |
| 9371 | ConstExprValue *dest_ptr_val = &casted_dest_ptr->value; |
| 9341 | 9372 | ConstExprValue *dest_elements; |
| 9342 | 9373 | size_t dest_start; |
| 9343 | 9374 | size_t dest_end; |
| ... | ... | @@ -9357,7 +9388,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 9357 | 9388 | return ira->codegen->builtin_types.entry_invalid; |
| 9358 | 9389 | } |
| 9359 | 9390 | |
| 9360 | | ConstExprValue *src_ptr_val = &casted_src_ptr->static_value; |
| 9391 | ConstExprValue *src_ptr_val = &casted_src_ptr->value; |
| 9361 | 9392 | ConstExprValue *src_elements; |
| 9362 | 9393 | size_t src_start; |
| 9363 | 9394 | size_t src_end; |
| ... | ... | @@ -9393,31 +9424,31 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 9393 | 9424 | |
| 9394 | 9425 | static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { |
| 9395 | 9426 | IrInstruction *ptr = instruction->ptr->other; |
| 9396 | | if (ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9427 | if (ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9397 | 9428 | return ira->codegen->builtin_types.entry_invalid; |
| 9398 | 9429 | |
| 9399 | 9430 | IrInstruction *start = instruction->start->other; |
| 9400 | | if (start->type_entry->id == TypeTableEntryIdInvalid) |
| 9431 | if (start->value.type->id == TypeTableEntryIdInvalid) |
| 9401 | 9432 | return ira->codegen->builtin_types.entry_invalid; |
| 9402 | 9433 | |
| 9403 | 9434 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| 9404 | 9435 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 9405 | | if (casted_start->type_entry->id == TypeTableEntryIdInvalid) |
| 9436 | if (casted_start->value.type->id == TypeTableEntryIdInvalid) |
| 9406 | 9437 | return ira->codegen->builtin_types.entry_invalid; |
| 9407 | 9438 | |
| 9408 | 9439 | IrInstruction *end; |
| 9409 | 9440 | if (instruction->end) { |
| 9410 | 9441 | end = instruction->end->other; |
| 9411 | | if (end->type_entry->id == TypeTableEntryIdInvalid) |
| 9442 | if (end->value.type->id == TypeTableEntryIdInvalid) |
| 9412 | 9443 | return ira->codegen->builtin_types.entry_invalid; |
| 9413 | 9444 | end = ir_implicit_cast(ira, end, usize); |
| 9414 | | if (end->type_entry->id == TypeTableEntryIdInvalid) |
| 9445 | if (end->value.type->id == TypeTableEntryIdInvalid) |
| 9415 | 9446 | return ira->codegen->builtin_types.entry_invalid; |
| 9416 | 9447 | } else { |
| 9417 | 9448 | end = nullptr; |
| 9418 | 9449 | } |
| 9419 | 9450 | |
| 9420 | | TypeTableEntry *array_type = get_underlying_type(ptr->type_entry); |
| 9451 | TypeTableEntry *array_type = get_underlying_type(ptr->value.type); |
| 9421 | 9452 | |
| 9422 | 9453 | TypeTableEntry *return_type; |
| 9423 | 9454 | |
| ... | ... | @@ -9435,38 +9466,38 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 9435 | 9466 | instruction->is_const); |
| 9436 | 9467 | } else { |
| 9437 | 9468 | ir_add_error(ira, &instruction->base, |
| 9438 | | buf_sprintf("slice of non-array type '%s'", buf_ptr(&ptr->type_entry->name))); |
| 9469 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&ptr->value.type->name))); |
| 9439 | 9470 | // TODO if this is a typedecl, add error note showing the declaration of the type decl |
| 9440 | 9471 | return ira->codegen->builtin_types.entry_invalid; |
| 9441 | 9472 | } |
| 9442 | 9473 | |
| 9443 | | if (ptr->static_value.special == ConstValSpecialStatic && |
| 9444 | | casted_start->static_value.special == ConstValSpecialStatic && |
| 9445 | | (!end || end->static_value.special == ConstValSpecialStatic)) |
| 9474 | if (ptr->value.special == ConstValSpecialStatic && |
| 9475 | casted_start->value.special == ConstValSpecialStatic && |
| 9476 | (!end || end->value.special == ConstValSpecialStatic)) |
| 9446 | 9477 | { |
| 9447 | 9478 | bool depends_on_compile_var = |
| 9448 | | ptr->static_value.depends_on_compile_var || |
| 9449 | | casted_start->static_value.depends_on_compile_var || |
| 9450 | | (end ? end->static_value.depends_on_compile_var : false); |
| 9479 | ptr->value.depends_on_compile_var || |
| 9480 | casted_start->value.depends_on_compile_var || |
| 9481 | (end ? end->value.depends_on_compile_var : false); |
| 9451 | 9482 | |
| 9452 | 9483 | ConstExprValue *base_ptr; |
| 9453 | 9484 | size_t abs_offset; |
| 9454 | 9485 | size_t rel_end; |
| 9455 | 9486 | if (array_type->id == TypeTableEntryIdArray) { |
| 9456 | | base_ptr = &ptr->static_value; |
| 9487 | base_ptr = &ptr->value; |
| 9457 | 9488 | abs_offset = 0; |
| 9458 | 9489 | rel_end = array_type->data.array.len; |
| 9459 | 9490 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 9460 | | base_ptr = ptr->static_value.data.x_ptr.base_ptr; |
| 9461 | | abs_offset = ptr->static_value.data.x_ptr.index; |
| 9491 | base_ptr = ptr->value.data.x_ptr.base_ptr; |
| 9492 | abs_offset = ptr->value.data.x_ptr.index; |
| 9462 | 9493 | if (abs_offset == SIZE_MAX) { |
| 9463 | 9494 | rel_end = 1; |
| 9464 | 9495 | } else { |
| 9465 | 9496 | rel_end = base_ptr->data.x_array.size - abs_offset; |
| 9466 | 9497 | } |
| 9467 | 9498 | } else if (is_slice(array_type)) { |
| 9468 | | ConstExprValue *ptr_val = &ptr->static_value.data.x_struct.fields[slice_ptr_index]; |
| 9469 | | ConstExprValue *len_val = &ptr->static_value.data.x_struct.fields[slice_len_index]; |
| 9499 | ConstExprValue *ptr_val = &ptr->value.data.x_struct.fields[slice_ptr_index]; |
| 9500 | ConstExprValue *len_val = &ptr->value.data.x_struct.fields[slice_len_index]; |
| 9470 | 9501 | base_ptr = ptr_val->data.x_ptr.base_ptr; |
| 9471 | 9502 | abs_offset = ptr_val->data.x_ptr.index; |
| 9472 | 9503 | |
| ... | ... | @@ -9479,7 +9510,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 9479 | 9510 | zig_unreachable(); |
| 9480 | 9511 | } |
| 9481 | 9512 | |
| 9482 | | uint64_t start_scalar = casted_start->static_value.data.x_bignum.data.x_uint; |
| 9513 | uint64_t start_scalar = casted_start->value.data.x_bignum.data.x_uint; |
| 9483 | 9514 | if (start_scalar > rel_end) { |
| 9484 | 9515 | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 9485 | 9516 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -9487,7 +9518,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 9487 | 9518 | |
| 9488 | 9519 | uint64_t end_scalar; |
| 9489 | 9520 | if (end) { |
| 9490 | | end_scalar = end->static_value.data.x_bignum.data.x_uint; |
| 9521 | end_scalar = end->value.data.x_bignum.data.x_uint; |
| 9491 | 9522 | } else { |
| 9492 | 9523 | end_scalar = rel_end; |
| 9493 | 9524 | } |
| ... | ... | @@ -9504,18 +9535,17 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 9504 | 9535 | out_val->data.x_struct.fields = allocate<ConstExprValue>(2); |
| 9505 | 9536 | |
| 9506 | 9537 | ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index]; |
| 9507 | | ptr_val->special = ConstValSpecialStatic; |
| 9508 | | ptr_val->data.x_ptr.base_ptr = base_ptr; |
| 9509 | | ptr_val->data.x_ptr.index = (abs_offset != SIZE_MAX) ? (abs_offset + start_scalar) : SIZE_MAX; |
| 9538 | size_t index = (abs_offset != SIZE_MAX) ? (abs_offset + start_scalar) : SIZE_MAX; |
| 9539 | init_const_ptr(ira->codegen, ptr_val, base_ptr, index, instruction->is_const); |
| 9510 | 9540 | |
| 9511 | 9541 | ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index]; |
| 9512 | | len_val->special = ConstValSpecialStatic; |
| 9513 | | bignum_init_unsigned(&len_val->data.x_bignum, rel_end); |
| 9542 | init_const_usize(ira->codegen, len_val, rel_end); |
| 9514 | 9543 | |
| 9515 | 9544 | return return_type; |
| 9516 | 9545 | } |
| 9517 | 9546 | |
| 9518 | | IrInstruction *new_instruction = ir_build_slice_from(&ira->new_irb, &instruction->base, ptr, casted_start, end, instruction->is_const); |
| 9547 | IrInstruction *new_instruction = ir_build_slice_from(&ira->new_irb, &instruction->base, ptr, |
| 9548 | casted_start, end, instruction->is_const, instruction->safety_check_on); |
| 9519 | 9549 | ir_add_alloca(ira, new_instruction, return_type); |
| 9520 | 9550 | |
| 9521 | 9551 | return return_type; |
| ... | ... | @@ -9523,7 +9553,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 9523 | 9553 | |
| 9524 | 9554 | static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 9525 | 9555 | IrInstruction *container = instruction->container->other; |
| 9526 | | if (container->type_entry->id == TypeTableEntryIdInvalid) |
| 9556 | if (container->value.type->id == TypeTableEntryIdInvalid) |
| 9527 | 9557 | return ira->codegen->builtin_types.entry_invalid; |
| 9528 | 9558 | TypeTableEntry *container_type = ir_resolve_type(ira, container); |
| 9529 | 9559 | TypeTableEntry *canon_type = get_underlying_type(container_type); |
| ... | ... | @@ -9542,7 +9572,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 9542 | 9572 | return ira->codegen->builtin_types.entry_invalid; |
| 9543 | 9573 | } |
| 9544 | 9574 | |
| 9545 | | bool depends_on_compile_var = container->static_value.depends_on_compile_var; |
| 9575 | bool depends_on_compile_var = container->value.depends_on_compile_var; |
| 9546 | 9576 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9547 | 9577 | bignum_init_unsigned(&out_val->data.x_bignum, result); |
| 9548 | 9578 | return ira->codegen->builtin_types.entry_num_lit_int; |
| ... | ... | @@ -9571,7 +9601,7 @@ static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIn |
| 9571 | 9601 | |
| 9572 | 9602 | static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 9573 | 9603 | IrInstruction *type_value = instruction->type_value->other; |
| 9574 | | if (type_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9604 | if (type_value->value.type->id == TypeTableEntryIdInvalid) |
| 9575 | 9605 | return ira->codegen->builtin_types.entry_invalid; |
| 9576 | 9606 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); |
| 9577 | 9607 | |
| ... | ... | @@ -9583,7 +9613,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct |
| 9583 | 9613 | return ira->codegen->builtin_types.entry_invalid; |
| 9584 | 9614 | } else { |
| 9585 | 9615 | uint64_t align_in_bytes = LLVMABISizeOfType(ira->codegen->target_data_ref, type_entry->type_ref); |
| 9586 | | bool depends_on_compile_var = type_value->static_value.depends_on_compile_var; |
| 9616 | bool depends_on_compile_var = type_value->value.depends_on_compile_var; |
| 9587 | 9617 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9588 | 9618 | bignum_init_unsigned(&out_val->data.x_bignum, align_in_bytes); |
| 9589 | 9619 | return ira->codegen->builtin_types.entry_num_lit_int; |
| ... | ... | @@ -9592,7 +9622,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct |
| 9592 | 9622 | |
| 9593 | 9623 | static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 9594 | 9624 | IrInstruction *type_value = instruction->type_value->other; |
| 9595 | | if (type_value->type_entry->id == TypeTableEntryIdInvalid) |
| 9625 | if (type_value->value.type->id == TypeTableEntryIdInvalid) |
| 9596 | 9626 | return ira->codegen->builtin_types.entry_invalid; |
| 9597 | 9627 | TypeTableEntry *dest_type = ir_resolve_type(ira, type_value); |
| 9598 | 9628 | TypeTableEntry *canon_type = get_underlying_type(dest_type); |
| ... | ... | @@ -9607,41 +9637,41 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 9607 | 9637 | } |
| 9608 | 9638 | |
| 9609 | 9639 | IrInstruction *op1 = instruction->op1->other; |
| 9610 | | if (op1->type_entry->id == TypeTableEntryIdInvalid) |
| 9640 | if (op1->value.type->id == TypeTableEntryIdInvalid) |
| 9611 | 9641 | return ira->codegen->builtin_types.entry_invalid; |
| 9612 | 9642 | |
| 9613 | 9643 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 9614 | | if (casted_op1->type_entry->id == TypeTableEntryIdInvalid) |
| 9644 | if (casted_op1->value.type->id == TypeTableEntryIdInvalid) |
| 9615 | 9645 | return ira->codegen->builtin_types.entry_invalid; |
| 9616 | 9646 | |
| 9617 | 9647 | IrInstruction *op2 = instruction->op2->other; |
| 9618 | | if (op2->type_entry->id == TypeTableEntryIdInvalid) |
| 9648 | if (op2->value.type->id == TypeTableEntryIdInvalid) |
| 9619 | 9649 | return ira->codegen->builtin_types.entry_invalid; |
| 9620 | 9650 | |
| 9621 | 9651 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 9622 | | if (casted_op2->type_entry->id == TypeTableEntryIdInvalid) |
| 9652 | if (casted_op2->value.type->id == TypeTableEntryIdInvalid) |
| 9623 | 9653 | return ira->codegen->builtin_types.entry_invalid; |
| 9624 | 9654 | |
| 9625 | 9655 | IrInstruction *result_ptr = instruction->result_ptr->other; |
| 9626 | | if (result_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9656 | if (result_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9627 | 9657 | return ira->codegen->builtin_types.entry_invalid; |
| 9628 | 9658 | |
| 9629 | 9659 | TypeTableEntry *expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); |
| 9630 | 9660 | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 9631 | | if (casted_result_ptr->type_entry->id == TypeTableEntryIdInvalid) |
| 9661 | if (casted_result_ptr->value.type->id == TypeTableEntryIdInvalid) |
| 9632 | 9662 | return ira->codegen->builtin_types.entry_invalid; |
| 9633 | 9663 | |
| 9634 | | if (casted_op1->static_value.special == ConstValSpecialStatic && |
| 9635 | | casted_op2->static_value.special == ConstValSpecialStatic && |
| 9636 | | casted_result_ptr->static_value.special == ConstValSpecialStatic) |
| 9664 | if (casted_op1->value.special == ConstValSpecialStatic && |
| 9665 | casted_op2->value.special == ConstValSpecialStatic && |
| 9666 | casted_result_ptr->value.special == ConstValSpecialStatic) |
| 9637 | 9667 | { |
| 9638 | | bool depends_on_compile_var = type_value->static_value.depends_on_compile_var || |
| 9639 | | casted_op1->static_value.depends_on_compile_var || casted_op2->static_value.depends_on_compile_var || |
| 9640 | | casted_result_ptr->static_value.depends_on_compile_var; |
| 9668 | bool depends_on_compile_var = type_value->value.depends_on_compile_var || |
| 9669 | casted_op1->value.depends_on_compile_var || casted_op2->value.depends_on_compile_var || |
| 9670 | casted_result_ptr->value.depends_on_compile_var; |
| 9641 | 9671 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9642 | | BigNum *op1_bignum = &casted_op1->static_value.data.x_bignum; |
| 9643 | | BigNum *op2_bignum = &casted_op2->static_value.data.x_bignum; |
| 9644 | | ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->static_value); |
| 9672 | BigNum *op1_bignum = &casted_op1->value.data.x_bignum; |
| 9673 | BigNum *op2_bignum = &casted_op2->value.data.x_bignum; |
| 9674 | ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->value); |
| 9645 | 9675 | BigNum *dest_bignum = &pointee_val->data.x_bignum; |
| 9646 | 9676 | switch (instruction->op) { |
| 9647 | 9677 | case IrOverflowOpAdd: |
| ... | ... | @@ -9674,10 +9704,10 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 9674 | 9704 | |
| 9675 | 9705 | static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { |
| 9676 | 9706 | IrInstruction *value = instruction->value->other; |
| 9677 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 9707 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 9678 | 9708 | return ira->codegen->builtin_types.entry_invalid; |
| 9679 | 9709 | |
| 9680 | | TypeTableEntry *non_canon_type = value->type_entry; |
| 9710 | TypeTableEntry *non_canon_type = value->value.type; |
| 9681 | 9711 | |
| 9682 | 9712 | TypeTableEntry *canon_type = get_underlying_type(non_canon_type); |
| 9683 | 9713 | if (canon_type->id == TypeTableEntryIdInvalid) { |
| ... | ... | @@ -9713,9 +9743,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 9713 | 9743 | IrInstructionUnwrapErrCode *instruction) |
| 9714 | 9744 | { |
| 9715 | 9745 | IrInstruction *value = instruction->value->other; |
| 9716 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 9746 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 9717 | 9747 | return ira->codegen->builtin_types.entry_invalid; |
| 9718 | | TypeTableEntry *ptr_type = value->type_entry; |
| 9748 | TypeTableEntry *ptr_type = value->value.type; |
| 9719 | 9749 | |
| 9720 | 9750 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 9721 | 9751 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| ... | ... | @@ -9756,9 +9786,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 9756 | 9786 | IrInstructionUnwrapErrPayload *instruction) |
| 9757 | 9787 | { |
| 9758 | 9788 | IrInstruction *value = instruction->value->other; |
| 9759 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 9789 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 9760 | 9790 | return ira->codegen->builtin_types.entry_invalid; |
| 9761 | | TypeTableEntry *ptr_type = value->type_entry; |
| 9791 | TypeTableEntry *ptr_type = value->value.type; |
| 9762 | 9792 | |
| 9763 | 9793 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 9764 | 9794 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| ... | ... | @@ -9824,14 +9854,14 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 9824 | 9854 | if (param_info->type->id == TypeTableEntryIdInvalid) |
| 9825 | 9855 | return ira->codegen->builtin_types.entry_invalid; |
| 9826 | 9856 | |
| 9827 | | depends_on_compile_var = depends_on_compile_var || param_type_value->static_value.depends_on_compile_var; |
| 9857 | depends_on_compile_var = depends_on_compile_var || param_type_value->value.depends_on_compile_var; |
| 9828 | 9858 | } |
| 9829 | 9859 | |
| 9830 | 9860 | IrInstruction *return_type_value = instruction->return_type->other; |
| 9831 | 9861 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); |
| 9832 | 9862 | if (fn_type_id.return_type->id == TypeTableEntryIdInvalid) |
| 9833 | 9863 | return ira->codegen->builtin_types.entry_invalid; |
| 9834 | | depends_on_compile_var = depends_on_compile_var || return_type_value->static_value.depends_on_compile_var; |
| 9864 | depends_on_compile_var = depends_on_compile_var || return_type_value->value.depends_on_compile_var; |
| 9835 | 9865 | |
| 9836 | 9866 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 9837 | 9867 | out_val->data.x_type = get_fn_type(ira->codegen, &fn_type_id); |
| ... | ... | @@ -9840,7 +9870,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 9840 | 9870 | |
| 9841 | 9871 | static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 9842 | 9872 | IrInstruction *value = instruction->value->other; |
| 9843 | | if (value->type_entry->id == TypeTableEntryIdInvalid) |
| 9873 | if (value->value.type->id == TypeTableEntryIdInvalid) |
| 9844 | 9874 | return ira->codegen->builtin_types.entry_invalid; |
| 9845 | 9875 | |
| 9846 | 9876 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false); |
| ... | ... | @@ -9851,6 +9881,11 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn |
| 9851 | 9881 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 9852 | 9882 | switch (instruction->id) { |
| 9853 | 9883 | case IrInstructionIdInvalid: |
| 9884 | case IrInstructionIdPointerReinterpret: |
| 9885 | case IrInstructionIdStructInit: |
| 9886 | case IrInstructionIdStructFieldPtr: |
| 9887 | case IrInstructionIdEnumFieldPtr: |
| 9888 | case IrInstructionIdInitEnum: |
| 9854 | 9889 | zig_unreachable(); |
| 9855 | 9890 | case IrInstructionIdReturn: |
| 9856 | 9891 | return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction); |
| ... | ... | @@ -9996,10 +10031,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 9996 | 10031 | case IrInstructionIdErrWrapCode: |
| 9997 | 10032 | case IrInstructionIdErrWrapPayload: |
| 9998 | 10033 | case IrInstructionIdCast: |
| 9999 | | case IrInstructionIdStructFieldPtr: |
| 10000 | | case IrInstructionIdEnumFieldPtr: |
| 10001 | | case IrInstructionIdStructInit: |
| 10002 | | case IrInstructionIdInitEnum: |
| 10003 | 10034 | zig_panic("TODO analyze more instructions"); |
| 10004 | 10035 | } |
| 10005 | 10036 | zig_unreachable(); |
| ... | ... | @@ -10007,9 +10038,9 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 10007 | 10038 | |
| 10008 | 10039 | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { |
| 10009 | 10040 | TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction); |
| 10010 | | instruction->type_entry = instruction_type; |
| 10041 | instruction->value.type = instruction_type; |
| 10011 | 10042 | if (instruction->other) { |
| 10012 | | instruction->other->type_entry = instruction_type; |
| 10043 | instruction->other->value.type = instruction_type; |
| 10013 | 10044 | } else { |
| 10014 | 10045 | assert(instruction_type->id == TypeTableEntryIdInvalid || |
| 10015 | 10046 | instruction_type->id == TypeTableEntryIdUnreachable); |
| ... | ... | @@ -10156,6 +10187,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 10156 | 10187 | case IrInstructionIdFnProto: |
| 10157 | 10188 | case IrInstructionIdTestComptime: |
| 10158 | 10189 | case IrInstructionIdInitEnum: |
| 10190 | case IrInstructionIdPointerReinterpret: |
| 10159 | 10191 | return false; |
| 10160 | 10192 | case IrInstructionIdAsm: |
| 10161 | 10193 | { |