| ... | ... | @@ -71,27 +71,25 @@ const const_tzir_inst_list = blk: { |
| 71 | 71 | |
| 72 | 72 | pub fn root(sema: *Sema, root_block: *Scope.Block) !void { |
| 73 | 73 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; |
| 74 | | return sema.body(root_block, root_body); |
| 74 | return sema.analyzeBody(root_block, root_body); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | pub fn rootAsType( |
| 78 | 78 | sema: *Sema, |
| 79 | 79 | root_block: *Scope.Block, |
| 80 | 80 | zir_result_inst: zir.Inst.Index, |
| 81 | | body: zir.Body, |
| 82 | 81 | ) !Type { |
| 83 | 82 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; |
| 84 | | try sema.body(root_block, root_body); |
| 83 | try sema.analyzeBody(root_block, root_body); |
| 85 | 84 | |
| 86 | 85 | const result_inst = sema.inst_map[zir_result_inst]; |
| 87 | 86 | // Source location is unneeded because resolveConstValue must have already |
| 88 | 87 | // been successfully called when coercing the value to a type, from the |
| 89 | 88 | // result location. |
| 90 | | const val = try sema.resolveConstValue(root_block, .unneeded, result_inst); |
| 91 | | return val.toType(root_block.arena); |
| 89 | return sema.resolveType(root_block, .unneeded, result_inst); |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | | pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !void { |
| 92 | pub fn analyzeBody(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !void { |
| 95 | 93 | const tracy = trace(@src()); |
| 96 | 94 | defer tracy.end(); |
| 97 | 95 | |
| ... | ... | @@ -154,7 +152,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 154 | 152 | .field_val => try sema.zirFieldVal(block, zir_inst), |
| 155 | 153 | .field_ptr_named => try sema.zirFieldPtrNamed(block, zir_inst), |
| 156 | 154 | .field_val_named => try sema.zirFieldValNamed(block, zir_inst), |
| 157 | | .deref => try sema.zirDeref(block, zir_inst), |
| 155 | .deref_node => try sema.zirDerefNode(block, zir_inst), |
| 158 | 156 | .as => try sema.zirAs(block, zir_inst), |
| 159 | 157 | .@"asm" => try sema.zirAsm(block, zir_inst, false), |
| 160 | 158 | .asm_volatile => try sema.zirAsm(block, zir_inst, true), |
| ... | ... | @@ -162,8 +160,10 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 162 | 160 | .unreachable_unsafe => try sema.zirUnreachable(block, zir_inst, false), |
| 163 | 161 | .ret_tok => try sema.zirRetTok(block, zir_inst), |
| 164 | 162 | .ret_node => try sema.zirRetNode(block, zir_inst), |
| 165 | | .fn_type => try sema.zirFnType(block, zir_inst), |
| 166 | | .fn_type_cc => try sema.zirFnTypeCc(block, zir_inst), |
| 163 | .fn_type => try sema.zirFnType(block, zir_inst, false), |
| 164 | .fn_type_cc => try sema.zirFnTypeCc(block, zir_inst, false), |
| 165 | .fn_type_var_args => try sema.zirFnType(block, zir_inst, true), |
| 166 | .fn_type_cc_var_args => try sema.zirFnTypeCc(block, zir_inst, true), |
| 167 | 167 | .intcast => try sema.zirIntcast(block, zir_inst), |
| 168 | 168 | .bitcast => try sema.zirBitcast(block, zir_inst), |
| 169 | 169 | .floatcast => try sema.zirFloatcast(block, zir_inst), |
| ... | ... | @@ -230,10 +230,15 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 230 | 230 | .import => try sema.zirImport(block, zir_inst), |
| 231 | 231 | .bool_and => try sema.zirBoolOp(block, zir_inst, false), |
| 232 | 232 | .bool_or => try sema.zirBoolOp(block, zir_inst, true), |
| 233 | | .void_value => try sema.mod.constVoid(block.arena, .unneeded), |
| 234 | | .switchbr => try sema.zirSwitchBr(block, zir_inst, false), |
| 235 | | .switchbr_ref => try sema.zirSwitchBr(block, zir_inst, true), |
| 236 | | .switch_range => try sema.zirSwitchRange(block, zir_inst), |
| 233 | .@"await" => try sema.zirAwait(block, zir_inst), |
| 234 | .nosuspend_await => try sema.zirNosuspendAwait(block, zir_inst), |
| 235 | .suspend_block_one => @panic("TODO"), |
| 236 | .suspend_block => @panic("TODO"), |
| 237 | .@"resume" => @panic("TODO"), |
| 238 | // TODO |
| 239 | //.switchbr => try sema.zirSwitchBr(block, zir_inst, false), |
| 240 | //.switchbr_ref => try sema.zirSwitchBr(block, zir_inst, true), |
| 241 | //.switch_range => try sema.zirSwitchRange(block, zir_inst), |
| 237 | 242 | }; |
| 238 | 243 | if (map[zir_inst].ty.isNoReturn()) { |
| 239 | 244 | break; |
| ... | ... | @@ -241,7 +246,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 241 | 246 | } |
| 242 | 247 | } |
| 243 | 248 | |
| 244 | | fn resolveInst(sema: *Sema, block: *Scope.Block, zir_ref: zir.Inst.Ref) *const ir.Inst { |
| 249 | pub fn resolveInst(sema: *Sema, block: *Scope.Block, zir_ref: zir.Inst.Ref) *const ir.Inst { |
| 245 | 250 | var i = zir_ref; |
| 246 | 251 | |
| 247 | 252 | // First section of indexes correspond to a set number of constant values. |
| ... | ... | @@ -277,7 +282,7 @@ fn resolveConstString( |
| 277 | 282 | const wanted_type = Type.initTag(.const_slice_u8); |
| 278 | 283 | const coerced_inst = try sema.coerce(block, wanted_type, tzir_inst); |
| 279 | 284 | const val = try sema.resolveConstValue(block, src, coerced_inst); |
| 280 | | return val.toAllocatedBytes(block.arena); |
| 285 | return val.toAllocatedBytes(sema.arena); |
| 281 | 286 | } |
| 282 | 287 | |
| 283 | 288 | fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: zir.Inst.Ref) !Type { |
| ... | ... | @@ -355,7 +360,7 @@ fn zirConst(sema: *Sema, block: *Scope.Block, const_inst: zir.Inst.Index) InnerE |
| 355 | 360 | defer tracy.end(); |
| 356 | 361 | // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions |
| 357 | 362 | // after analysis. |
| 358 | | const typed_value_copy = try const_inst.positionals.typed_value.copy(block.arena); |
| 363 | const typed_value_copy = try const_inst.positionals.typed_value.copy(sema.arena); |
| 359 | 364 | return sema.mod.constInst(scope, const_inst.base.src, typed_value_copy); |
| 360 | 365 | } |
| 361 | 366 | |
| ... | ... | @@ -377,14 +382,14 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In |
| 377 | 382 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement zirCoerceResultPtr", .{}); |
| 378 | 383 | } |
| 379 | 384 | |
| 380 | | fn zirRetPtr(sema: *Module, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| 385 | fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| 381 | 386 | const tracy = trace(@src()); |
| 382 | 387 | defer tracy.end(); |
| 383 | 388 | |
| 384 | 389 | try sema.requireFunctionBlock(block, inst.base.src); |
| 385 | 390 | const fn_ty = block.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 386 | 391 | const ret_type = fn_ty.fnReturnType(); |
| 387 | | const ptr_type = try sema.mod.simplePtrType(block.arena, ret_type, true, .One); |
| 392 | const ptr_type = try sema.mod.simplePtrType(sema.arena, ret_type, true, .One); |
| 388 | 393 | return block.addNoOp(inst.base.src, ptr_type, .alloc); |
| 389 | 394 | } |
| 390 | 395 | |
| ... | ... | @@ -403,7 +408,7 @@ fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 403 | 408 | try sema.requireFunctionBlock(block, inst.base.src); |
| 404 | 409 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 405 | 410 | const ret_type = fn_ty.fnReturnType(); |
| 406 | | return sema.mod.constType(block.arena, inst.base.src, ret_type); |
| 411 | return sema.mod.constType(sema.arena, inst.base.src, ret_type); |
| 407 | 412 | } |
| 408 | 413 | |
| 409 | 414 | fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -414,7 +419,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) I |
| 414 | 419 | const operand = sema.resolveInst(block, inst_data.operand); |
| 415 | 420 | const src = inst_data.src(); |
| 416 | 421 | switch (operand.ty.zigTypeTag()) { |
| 417 | | .Void, .NoReturn => return sema.mod.constVoid(block.arena, .unneeded), |
| 422 | .Void, .NoReturn => return sema.mod.constVoid(sema.arena, .unneeded), |
| 418 | 423 | else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}), |
| 419 | 424 | } |
| 420 | 425 | } |
| ... | ... | @@ -428,7 +433,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde |
| 428 | 433 | const src = inst_data.src(); |
| 429 | 434 | switch (operand.ty.zigTypeTag()) { |
| 430 | 435 | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| 431 | | else => return sema.mod.constVoid(block.arena, .unneeded), |
| 436 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 432 | 437 | } |
| 433 | 438 | } |
| 434 | 439 | |
| ... | ... | @@ -473,7 +478,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!* |
| 473 | 478 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 474 | 479 | const var_decl_src = inst_data.src(); |
| 475 | 480 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 476 | | const ptr_type = try sema.mod.simplePtrType(block.arena, var_type, true, .One); |
| 481 | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 477 | 482 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 478 | 483 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 479 | 484 | } |
| ... | ... | @@ -487,7 +492,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro |
| 487 | 492 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 488 | 493 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 489 | 494 | try sema.validateVarType(block, ty_src, var_type); |
| 490 | | const ptr_type = try sema.mod.simplePtrType(block.arena, var_type, true, .One); |
| 495 | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 491 | 496 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 492 | 497 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 493 | 498 | } |
| ... | ... | @@ -500,7 +505,7 @@ fn zirAllocInferred( |
| 500 | 505 | ) InnerError!*Inst { |
| 501 | 506 | const tracy = trace(@src()); |
| 502 | 507 | defer tracy.end(); |
| 503 | | const val_payload = try block.arena.create(Value.Payload.InferredAlloc); |
| 508 | const val_payload = try sema.arena.create(Value.Payload.InferredAlloc); |
| 504 | 509 | val_payload.* = .{ |
| 505 | 510 | .data = .{}, |
| 506 | 511 | }; |
| ... | ... | @@ -540,13 +545,13 @@ fn zirResolveInferredAlloc( |
| 540 | 545 | if (var_is_mut) { |
| 541 | 546 | try sema.validateVarType(block, ty_src, final_elem_ty); |
| 542 | 547 | } |
| 543 | | const final_ptr_ty = try sema.mod.simplePtrType(block.arena, final_elem_ty, true, .One); |
| 548 | const final_ptr_ty = try sema.mod.simplePtrType(sema.arena, final_elem_ty, true, .One); |
| 544 | 549 | |
| 545 | 550 | // Change it to a normal alloc. |
| 546 | 551 | ptr.ty = final_ptr_ty; |
| 547 | 552 | ptr.tag = .alloc; |
| 548 | 553 | |
| 549 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 554 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 550 | 555 | } |
| 551 | 556 | |
| 552 | 557 | fn zirStoreToBlockPtr( |
| ... | ... | @@ -560,7 +565,7 @@ fn zirStoreToBlockPtr( |
| 560 | 565 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 561 | 566 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 562 | 567 | const value = sema.resolveInst(bin_inst.rhs); |
| 563 | | const ptr_ty = try sema.mod.simplePtrType(block.arena, value.ty, true, .One); |
| 568 | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 564 | 569 | // TODO detect when this store should be done at compile-time. For example, |
| 565 | 570 | // if expressions should force it when the condition is compile-time known. |
| 566 | 571 | try sema.requireRuntimeBlock(block, src); |
| ... | ... | @@ -582,9 +587,9 @@ fn zirStoreToInferredPtr( |
| 582 | 587 | const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?; |
| 583 | 588 | // Add the stored instruction to the set we will use to resolve peer types |
| 584 | 589 | // for the inferred allocation. |
| 585 | | try inferred_alloc.data.stored_inst_list.append(block.arena, value); |
| 590 | try inferred_alloc.data.stored_inst_list.append(sema.arena, value); |
| 586 | 591 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 587 | | const ptr_ty = try sema.mod.simplePtrType(block.arena, value.ty, true, .One); |
| 592 | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 588 | 593 | try sema.requireRuntimeBlock(block, src); |
| 589 | 594 | const bitcasted_ptr = try block.addUnOp(inst.base.src, ptr_ty, .bitcast, ptr); |
| 590 | 595 | return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value); |
| ... | ... | @@ -601,7 +606,7 @@ fn zirSetEvalBranchQuota( |
| 601 | 606 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); |
| 602 | 607 | if (sema.branch_quota < quota) |
| 603 | 608 | sema.branch_quota = quota; |
| 604 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 609 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 605 | 610 | } |
| 606 | 611 | |
| 607 | 612 | fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -635,7 +640,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr |
| 635 | 640 | const param_count = fn_ty.fnParamLen(); |
| 636 | 641 | if (param_index >= param_count) { |
| 637 | 642 | if (fn_ty.fnIsVarArgs()) { |
| 638 | | return sema.mod.constType(block.arena, inst.base.src, Type.initTag(.var_args_param)); |
| 643 | return sema.mod.constType(sema.arena, inst.base.src, Type.initTag(.var_args_param)); |
| 639 | 644 | } |
| 640 | 645 | return sema.mod.fail(&block.base, inst.base.src, "arg index {d} out of bounds; '{}' has {d} argument(s)", .{ |
| 641 | 646 | param_index, |
| ... | ... | @@ -646,7 +651,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr |
| 646 | 651 | |
| 647 | 652 | // TODO support generic functions |
| 648 | 653 | const param_type = fn_ty.fnParamType(param_index); |
| 649 | | return sema.mod.constType(block.arena, inst.base.src, param_type); |
| 654 | return sema.mod.constType(sema.arena, inst.base.src, param_type); |
| 650 | 655 | } |
| 651 | 656 | |
| 652 | 657 | fn zirStr(sema: *Sema, block: *Scope.Block, str_inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -714,7 +719,7 @@ fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 714 | 719 | .lazy = inst_data.src(), |
| 715 | 720 | }; |
| 716 | 721 | } |
| 717 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 722 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 718 | 723 | } |
| 719 | 724 | |
| 720 | 725 | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -724,7 +729,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 724 | 729 | // Reserve space for a Loop instruction so that generated Break instructions can |
| 725 | 730 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 726 | 731 | // comptime evaluated. |
| 727 | | const loop_inst = try parent_block.arena.create(Inst.Loop); |
| 732 | const loop_inst = try sema.arena.create(Inst.Loop); |
| 728 | 733 | loop_inst.* = .{ |
| 729 | 734 | .base = .{ |
| 730 | 735 | .tag = Inst.Loop.base_tag, |
| ... | ... | @@ -741,19 +746,19 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 741 | 746 | .owner_decl = parent_block.owner_decl, |
| 742 | 747 | .src_decl = parent_block.src_decl, |
| 743 | 748 | .instructions = .{}, |
| 744 | | .arena = parent_block.arena, |
| 749 | .arena = sema.arena, |
| 745 | 750 | .inlining = parent_block.inlining, |
| 746 | 751 | .is_comptime = parent_block.is_comptime, |
| 747 | 752 | .branch_quota = parent_block.branch_quota, |
| 748 | 753 | }; |
| 749 | 754 | defer child_block.instructions.deinit(mod.gpa); |
| 750 | 755 | |
| 751 | | try sema.body(&child_block, inst.positionals.body); |
| 756 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 752 | 757 | |
| 753 | 758 | // Loop repetition is implied so the last instruction may or may not be a noreturn instruction. |
| 754 | 759 | |
| 755 | 760 | try parent_block.instructions.append(mod.gpa, &loop_inst.base); |
| 756 | | loop_inst.body = .{ .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items) }; |
| 761 | loop_inst.body = .{ .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items) }; |
| 757 | 762 | return &loop_inst.base; |
| 758 | 763 | } |
| 759 | 764 | |
| ... | ... | @@ -765,10 +770,10 @@ fn zirBlockFlat(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index, i |
| 765 | 770 | defer child_block.instructions.deinit(mod.gpa); |
| 766 | 771 | child_block.is_comptime = child_block.is_comptime or is_comptime; |
| 767 | 772 | |
| 768 | | try sema.body(&child_block, inst.positionals.body); |
| 773 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 769 | 774 | |
| 770 | 775 | // Move the analyzed instructions into the parent block arena. |
| 771 | | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items); |
| 776 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items); |
| 772 | 777 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 773 | 778 | |
| 774 | 779 | // The result of a flat block is the last instruction. |
| ... | ... | @@ -789,7 +794,7 @@ fn zirBlock( |
| 789 | 794 | // Reserve space for a Block instruction so that generated Break instructions can |
| 790 | 795 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 791 | 796 | // comptime evaluated. |
| 792 | | const block_inst = try parent_block.arena.create(Inst.Block); |
| 797 | const block_inst = try sema.arena.create(Inst.Block); |
| 793 | 798 | block_inst.* = .{ |
| 794 | 799 | .base = .{ |
| 795 | 800 | .tag = Inst.Block.base_tag, |
| ... | ... | @@ -806,7 +811,7 @@ fn zirBlock( |
| 806 | 811 | .owner_decl = parent_block.owner_decl, |
| 807 | 812 | .src_decl = parent_block.src_decl, |
| 808 | 813 | .instructions = .{}, |
| 809 | | .arena = parent_block.arena, |
| 814 | .arena = sema.arena, |
| 810 | 815 | // TODO @as here is working around a stage1 miscompilation bug :( |
| 811 | 816 | .label = @as(?Scope.Block.Label, Scope.Block.Label{ |
| 812 | 817 | .zir_block = inst, |
| ... | ... | @@ -826,7 +831,7 @@ fn zirBlock( |
| 826 | 831 | defer merges.results.deinit(mod.gpa); |
| 827 | 832 | defer merges.br_list.deinit(mod.gpa); |
| 828 | 833 | |
| 829 | | try sema.body(&child_block, inst.positionals.body); |
| 834 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 830 | 835 | |
| 831 | 836 | return analyzeBlockBody(mod, scope, &child_block, merges); |
| 832 | 837 | } |
| ... | ... | @@ -847,7 +852,7 @@ fn analyzeBlockBody( |
| 847 | 852 | if (merges.results.items.len == 0) { |
| 848 | 853 | // No need for a block instruction. We can put the new instructions |
| 849 | 854 | // directly into the parent block. |
| 850 | | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items); |
| 855 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items); |
| 851 | 856 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 852 | 857 | return copied_instructions[copied_instructions.len - 1]; |
| 853 | 858 | } |
| ... | ... | @@ -858,7 +863,7 @@ fn analyzeBlockBody( |
| 858 | 863 | if (br_block == merges.block_inst) { |
| 859 | 864 | // No need for a block instruction. We can put the new instructions directly |
| 860 | 865 | // into the parent block. Here we omit the break instruction. |
| 861 | | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items[0..last_inst_index]); |
| 866 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items[0..last_inst_index]); |
| 862 | 867 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 863 | 868 | return merges.results.items[0]; |
| 864 | 869 | } |
| ... | ... | @@ -873,7 +878,7 @@ fn analyzeBlockBody( |
| 873 | 878 | const resolved_ty = try sema.resolvePeerTypes(parent_block, merges.results.items); |
| 874 | 879 | merges.block_inst.base.ty = resolved_ty; |
| 875 | 880 | merges.block_inst.body = .{ |
| 876 | | .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items), |
| 881 | .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items), |
| 877 | 882 | }; |
| 878 | 883 | // Now that the block has its type resolved, we need to go back into all the break |
| 879 | 884 | // instructions, and insert type coercion on the operands. |
| ... | ... | @@ -905,7 +910,7 @@ fn analyzeBlockBody( |
| 905 | 910 | }, |
| 906 | 911 | .block = merges.block_inst, |
| 907 | 912 | .body = .{ |
| 908 | | .instructions = try parent_block.arena.dupe(*Inst, coerce_block.instructions.items), |
| 913 | .instructions = try sema.arena.dupe(*Inst, coerce_block.instructions.items), |
| 909 | 914 | }, |
| 910 | 915 | }; |
| 911 | 916 | } |
| ... | ... | @@ -936,7 +941,7 @@ fn zirBreakVoidTok(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 936 | 941 | |
| 937 | 942 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 938 | 943 | const zir_block = inst_data.operand; |
| 939 | | const void_inst = try sema.mod.constVoid(block.arena, .unneeded); |
| 944 | const void_inst = try sema.mod.constVoid(sema.arena, .unneeded); |
| 940 | 945 | return analyzeBreak(mod, block, inst_data.src(), zir_block, void_inst); |
| 941 | 946 | } |
| 942 | 947 | |
| ... | ... | @@ -984,7 +989,7 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 984 | 989 | defer tracy.end(); |
| 985 | 990 | |
| 986 | 991 | if (b.is_comptime) { |
| 987 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 992 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 988 | 993 | } |
| 989 | 994 | |
| 990 | 995 | const src_node = sema.code.instructions.items(.data)[inst].node; |
| ... | ... | @@ -1090,7 +1095,7 @@ fn analyzeCall( |
| 1090 | 1095 | } |
| 1091 | 1096 | |
| 1092 | 1097 | // TODO handle function calls of generic functions |
| 1093 | | const casted_args = try block.arena.alloc(*Inst, zir_args.len); |
| 1098 | const casted_args = try sema.arena.alloc(*Inst, zir_args.len); |
| 1094 | 1099 | for (zir_args) |zir_arg, i| { |
| 1095 | 1100 | // the args are already casted to the result of a param type instruction. |
| 1096 | 1101 | casted_args[i] = sema.resolveInst(block, zir_arg); |
| ... | ... | @@ -1117,7 +1122,7 @@ fn analyzeCall( |
| 1117 | 1122 | // set to in the `Scope.Block`. |
| 1118 | 1123 | // This block instruction will be used to capture the return value from the |
| 1119 | 1124 | // inlined function. |
| 1120 | | const block_inst = try block.arena.create(Inst.Block); |
| 1125 | const block_inst = try sema.arena.create(Inst.Block); |
| 1121 | 1126 | block_inst.* = .{ |
| 1122 | 1127 | .base = .{ |
| 1123 | 1128 | .tag = Inst.Block.base_tag, |
| ... | ... | @@ -1154,7 +1159,7 @@ fn analyzeCall( |
| 1154 | 1159 | .owner_decl = scope.ownerDecl().?, |
| 1155 | 1160 | .src_decl = module_fn.owner_decl, |
| 1156 | 1161 | .instructions = .{}, |
| 1157 | | .arena = block.arena, |
| 1162 | .arena = sema.arena, |
| 1158 | 1163 | .label = null, |
| 1159 | 1164 | .inlining = &inlining, |
| 1160 | 1165 | .is_comptime = is_comptime_call, |
| ... | ... | @@ -1171,7 +1176,7 @@ fn analyzeCall( |
| 1171 | 1176 | |
| 1172 | 1177 | // This will have return instructions analyzed as break instructions to |
| 1173 | 1178 | // the block_inst above. |
| 1174 | | try sema.body(&child_block, module_fn.zir); |
| 1179 | try sema.analyzeBody(&child_block, module_fn.zir); |
| 1175 | 1180 | |
| 1176 | 1181 | return analyzeBlockBody(mod, scope, &child_block, merges); |
| 1177 | 1182 | } |
| ... | ... | @@ -1191,9 +1196,9 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, optional: zir.Inst.Index) I |
| 1191 | 1196 | |
| 1192 | 1197 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 1193 | 1198 | const child_type = try sema.resolveType(block, inst_data.operand); |
| 1194 | | const opt_type = try mod.optionalType(block.arena, child_type); |
| 1199 | const opt_type = try mod.optionalType(sema.arena, child_type); |
| 1195 | 1200 | |
| 1196 | | return sema.mod.constType(block.arena, inst_data.src(), opt_type); |
| 1201 | return sema.mod.constType(sema.arena, inst_data.src(), opt_type); |
| 1197 | 1202 | } |
| 1198 | 1203 | |
| 1199 | 1204 | fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1203,9 +1208,9 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I |
| 1203 | 1208 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 1204 | 1209 | const ptr = sema.resolveInst(block, inst_data.operand); |
| 1205 | 1210 | const elem_ty = ptr.ty.elemType(); |
| 1206 | | const opt_ty = try mod.optionalType(block.arena, elem_ty); |
| 1211 | const opt_ty = try mod.optionalType(sema.arena, elem_ty); |
| 1207 | 1212 | |
| 1208 | | return sema.mod.constType(block.arena, inst_data.src(), opt_ty); |
| 1213 | return sema.mod.constType(sema.arena, inst_data.src(), opt_ty); |
| 1209 | 1214 | } |
| 1210 | 1215 | |
| 1211 | 1216 | fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1215,7 +1220,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerEr |
| 1215 | 1220 | const len = try resolveInstConst(mod, scope, array.positionals.lhs); |
| 1216 | 1221 | const elem_type = try sema.resolveType(block, array.positionals.rhs); |
| 1217 | 1222 | |
| 1218 | | return sema.mod.constType(block.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type)); |
| 1223 | return sema.mod.constType(sema.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type)); |
| 1219 | 1224 | } |
| 1220 | 1225 | |
| 1221 | 1226 | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1226,7 +1231,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) |
| 1226 | 1231 | const sentinel = try resolveInstConst(mod, scope, array.positionals.sentinel); |
| 1227 | 1232 | const elem_type = try sema.resolveType(block, array.positionals.elem_type); |
| 1228 | 1233 | |
| 1229 | | return sema.mod.constType(block.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type)); |
| 1234 | return sema.mod.constType(sema.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type)); |
| 1230 | 1235 | } |
| 1231 | 1236 | |
| 1232 | 1237 | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1241,7 +1246,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn |
| 1241 | 1246 | return sema.mod.fail(&block.base, inst.base.src, "expected error set type, found {}", .{error_union.elemType()}); |
| 1242 | 1247 | } |
| 1243 | 1248 | |
| 1244 | | return sema.mod.constType(block.arena, inst.base.src, try mod.errorUnionType(scope, error_union, payload)); |
| 1249 | return sema.mod.constType(sema.arena, inst.base.src, try mod.errorUnionType(scope, error_union, payload)); |
| 1245 | 1250 | } |
| 1246 | 1251 | |
| 1247 | 1252 | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1252,9 +1257,9 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 1252 | 1257 | const src = inst_data.src(); |
| 1253 | 1258 | const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; |
| 1254 | 1259 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 1255 | | const anyframe_type = try sema.mod.anyframeType(block.arena, return_type); |
| 1260 | const anyframe_type = try sema.mod.anyframeType(sema.arena, return_type); |
| 1256 | 1261 | |
| 1257 | | return sema.mod.constType(block.arena, src, anyframe_type); |
| 1262 | return sema.mod.constType(sema.arena, src, anyframe_type); |
| 1258 | 1263 | } |
| 1259 | 1264 | |
| 1260 | 1265 | fn zirErrorSet(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1296,10 +1301,10 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 1296 | 1301 | |
| 1297 | 1302 | // Create an anonymous error set type with only this error value, and return the value. |
| 1298 | 1303 | const entry = try mod.getErrorValue(inst.positionals.name); |
| 1299 | | const result_type = try Type.Tag.error_set_single.create(block.arena, entry.key); |
| 1304 | const result_type = try Type.Tag.error_set_single.create(sema.arena, entry.key); |
| 1300 | 1305 | return sema.mod.constInst(scope, inst.base.src, .{ |
| 1301 | 1306 | .ty = result_type, |
| 1302 | | .val = try Value.Tag.@"error".create(block.arena, .{ |
| 1307 | .val = try Value.Tag.@"error".create(sema.arena, .{ |
| 1303 | 1308 | .name = entry.key, |
| 1304 | 1309 | }), |
| 1305 | 1310 | }); |
| ... | ... | @@ -1388,10 +1393,10 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, zir_inst: zir.Inst.Index) In |
| 1388 | 1393 | const tracy = trace(@src()); |
| 1389 | 1394 | defer tracy.end(); |
| 1390 | 1395 | |
| 1391 | | const duped_name = try block.arena.dupe(u8, inst.positionals.name); |
| 1396 | const duped_name = try sema.arena.dupe(u8, inst.positionals.name); |
| 1392 | 1397 | return sema.mod.constInst(scope, inst.base.src, .{ |
| 1393 | 1398 | .ty = Type.initTag(.enum_literal), |
| 1394 | | .val = try Value.Tag.enum_literal.create(block.arena, duped_name), |
| 1399 | .val = try Value.Tag.enum_literal.create(sema.arena, duped_name), |
| 1395 | 1400 | }); |
| 1396 | 1401 | } |
| 1397 | 1402 | |
| ... | ... | @@ -1415,11 +1420,11 @@ fn zirOptionalPayloadPtr( |
| 1415 | 1420 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 1416 | 1421 | } |
| 1417 | 1422 | |
| 1418 | | const child_type = try opt_type.optionalChildAlloc(block.arena); |
| 1419 | | const child_pointer = try sema.mod.simplePtrType(block.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); |
| 1423 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 1424 | const child_pointer = try sema.mod.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); |
| 1420 | 1425 | |
| 1421 | 1426 | if (optional_ptr.value()) |pointer_val| { |
| 1422 | | const val = try pointer_val.pointerDeref(block.arena); |
| 1427 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1423 | 1428 | if (val.isNull()) { |
| 1424 | 1429 | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 1425 | 1430 | } |
| ... | ... | @@ -1456,7 +1461,7 @@ fn zirOptionalPayload( |
| 1456 | 1461 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 1457 | 1462 | } |
| 1458 | 1463 | |
| 1459 | | const child_type = try opt_type.optionalChildAlloc(block.arena); |
| 1464 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 1460 | 1465 | |
| 1461 | 1466 | if (operand.value()) |val| { |
| 1462 | 1467 | if (val.isNull()) { |
| ... | ... | @@ -1528,10 +1533,10 @@ fn zirErrUnionPayloadPtr( |
| 1528 | 1533 | if (operand.ty.elemType().zigTypeTag() != .ErrorUnion) |
| 1529 | 1534 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); |
| 1530 | 1535 | |
| 1531 | | const operand_pointer_ty = try sema.mod.simplePtrType(block.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); |
| 1536 | const operand_pointer_ty = try sema.mod.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); |
| 1532 | 1537 | |
| 1533 | 1538 | if (operand.value()) |pointer_val| { |
| 1534 | | const val = try pointer_val.pointerDeref(block.arena); |
| 1539 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1535 | 1540 | if (val.getError()) |name| { |
| 1536 | 1541 | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 1537 | 1542 | } |
| ... | ... | @@ -1540,7 +1545,7 @@ fn zirErrUnionPayloadPtr( |
| 1540 | 1545 | return sema.mod.constInst(scope, src, .{ |
| 1541 | 1546 | .ty = operand_pointer_ty, |
| 1542 | 1547 | .val = try Value.Tag.ref_val.create( |
| 1543 | | block.arena, |
| 1548 | sema.arena, |
| 1544 | 1549 | data, |
| 1545 | 1550 | ), |
| 1546 | 1551 | }); |
| ... | ... | @@ -1592,7 +1597,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In |
| 1592 | 1597 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); |
| 1593 | 1598 | |
| 1594 | 1599 | if (operand.value()) |pointer_val| { |
| 1595 | | const val = try pointer_val.pointerDeref(block.arena); |
| 1600 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1596 | 1601 | assert(val.getError() != null); |
| 1597 | 1602 | const data = val.castTag(.error_union).?.data; |
| 1598 | 1603 | return sema.mod.constInst(scope, src, .{ |
| ... | ... | @@ -1617,40 +1622,46 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde |
| 1617 | 1622 | if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) { |
| 1618 | 1623 | return sema.mod.fail(&block.base, src, "expression value is ignored", .{}); |
| 1619 | 1624 | } |
| 1620 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 1625 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 1621 | 1626 | } |
| 1622 | 1627 | |
| 1623 | | fn zirFnType(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1628 | fn zirFnType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1624 | 1629 | const tracy = trace(@src()); |
| 1625 | 1630 | defer tracy.end(); |
| 1626 | 1631 | |
| 1627 | | return fnTypeCommon( |
| 1628 | | mod, |
| 1629 | | scope, |
| 1630 | | &fntype.base, |
| 1631 | | fntype.positionals.param_types, |
| 1632 | | fntype.positionals.return_type, |
| 1632 | const inst_data = sema.code.instructions.items(.data)[inst].fn_type; |
| 1633 | const extra = sema.code.extraData(zir.Inst.FnType, inst_data.payload_index); |
| 1634 | const param_types = sema.code.extra[extra.end..][0..extra.data.param_types_len]; |
| 1635 | |
| 1636 | return sema.fnTypeCommon( |
| 1637 | block, |
| 1638 | .unneeded, |
| 1639 | param_types, |
| 1640 | inst_data.return_type, |
| 1633 | 1641 | .Unspecified, |
| 1634 | 1642 | var_args, |
| 1635 | 1643 | ); |
| 1636 | 1644 | } |
| 1637 | 1645 | |
| 1638 | | fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1646 | fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1639 | 1647 | const tracy = trace(@src()); |
| 1640 | 1648 | defer tracy.end(); |
| 1641 | 1649 | |
| 1642 | | const cc_tv = try resolveInstConst(mod, scope, fntype.positionals.cc); |
| 1650 | const inst_data = sema.code.instructions.items(.data)[inst].fn_type; |
| 1651 | const extra = sema.code.extraData(zir.Inst.FnTypeCc, inst_data.payload_index); |
| 1652 | const param_types = sema.code.extra[extra.end..][0..extra.data.param_types_len]; |
| 1653 | |
| 1654 | const cc_tv = try resolveInstConst(mod, scope, extra.data.cc); |
| 1643 | 1655 | // TODO once we're capable of importing and analyzing decls from |
| 1644 | 1656 | // std.builtin, this needs to change |
| 1645 | 1657 | const cc_str = cc_tv.val.castTag(.enum_literal).?.data; |
| 1646 | 1658 | const cc = std.meta.stringToEnum(std.builtin.CallingConvention, cc_str) orelse |
| 1647 | | return sema.mod.fail(&block.base, fntype.positionals.cc.src, "Unknown calling convention {s}", .{cc_str}); |
| 1648 | | return fnTypeCommon( |
| 1649 | | mod, |
| 1650 | | scope, |
| 1651 | | &fntype.base, |
| 1652 | | fntype.positionals.param_types, |
| 1653 | | fntype.positionals.return_type, |
| 1659 | return sema.mod.fail(&block.base, .todo, "Unknown calling convention {s}", .{cc_str}); |
| 1660 | return sema.fnTypeCommon( |
| 1661 | block, |
| 1662 | .unneeded, |
| 1663 | param_types, |
| 1664 | inst_data.return_type, |
| 1654 | 1665 | cc, |
| 1655 | 1666 | var_args, |
| 1656 | 1667 | ); |
| ... | ... | @@ -1659,9 +1670,9 @@ fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_arg |
| 1659 | 1670 | fn fnTypeCommon( |
| 1660 | 1671 | sema: *Sema, |
| 1661 | 1672 | block: *Scope.Block, |
| 1662 | | zir_inst: zir.Inst.Index, |
| 1663 | | zir_param_types: []zir.Inst.Index, |
| 1664 | | zir_return_type: zir.Inst.Index, |
| 1673 | src: LazySrcLoc, |
| 1674 | zir_param_types: []const zir.Inst.Ref, |
| 1675 | zir_return_type: zir.Inst.Ref, |
| 1665 | 1676 | cc: std.builtin.CallingConvention, |
| 1666 | 1677 | var_args: bool, |
| 1667 | 1678 | ) InnerError!*Inst { |
| ... | ... | @@ -1670,39 +1681,39 @@ fn fnTypeCommon( |
| 1670 | 1681 | // Hot path for some common function types. |
| 1671 | 1682 | if (zir_param_types.len == 0 and !var_args) { |
| 1672 | 1683 | if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) { |
| 1673 | | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_noreturn_no_args)); |
| 1684 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_noreturn_no_args)); |
| 1674 | 1685 | } |
| 1675 | 1686 | |
| 1676 | 1687 | if (return_type.zigTypeTag() == .Void and cc == .Unspecified) { |
| 1677 | | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_void_no_args)); |
| 1688 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_void_no_args)); |
| 1678 | 1689 | } |
| 1679 | 1690 | |
| 1680 | 1691 | if (return_type.zigTypeTag() == .NoReturn and cc == .Naked) { |
| 1681 | | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_naked_noreturn_no_args)); |
| 1692 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_naked_noreturn_no_args)); |
| 1682 | 1693 | } |
| 1683 | 1694 | |
| 1684 | 1695 | if (return_type.zigTypeTag() == .Void and cc == .C) { |
| 1685 | | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_ccc_void_no_args)); |
| 1696 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_ccc_void_no_args)); |
| 1686 | 1697 | } |
| 1687 | 1698 | } |
| 1688 | 1699 | |
| 1689 | | const param_types = try block.arena.alloc(Type, zir_param_types.len); |
| 1700 | const param_types = try sema.arena.alloc(Type, zir_param_types.len); |
| 1690 | 1701 | for (zir_param_types) |param_type, i| { |
| 1691 | 1702 | const resolved = try sema.resolveType(block, param_type); |
| 1692 | 1703 | // TODO skip for comptime params |
| 1693 | 1704 | if (!resolved.isValidVarType(false)) { |
| 1694 | | return sema.mod.fail(&block.base, param_type.src, "parameter of type '{}' must be declared comptime", .{resolved}); |
| 1705 | return sema.mod.fail(&block.base, .todo, "parameter of type '{}' must be declared comptime", .{resolved}); |
| 1695 | 1706 | } |
| 1696 | 1707 | param_types[i] = resolved; |
| 1697 | 1708 | } |
| 1698 | 1709 | |
| 1699 | | const fn_ty = try Type.Tag.function.create(block.arena, .{ |
| 1710 | const fn_ty = try Type.Tag.function.create(sema.arena, .{ |
| 1700 | 1711 | .param_types = param_types, |
| 1701 | 1712 | .return_type = return_type, |
| 1702 | 1713 | .cc = cc, |
| 1703 | 1714 | .is_var_args = var_args, |
| 1704 | 1715 | }); |
| 1705 | | return sema.mod.constType(block.arena, zir_inst.src, fn_ty); |
| 1716 | return sema.mod.constType(sema.arena, src, fn_ty); |
| 1706 | 1717 | } |
| 1707 | 1718 | |
| 1708 | 1719 | fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -1981,11 +1992,11 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 1981 | 1992 | |
| 1982 | 1993 | switch (start.ty.zigTypeTag()) { |
| 1983 | 1994 | .Int, .ComptimeInt => {}, |
| 1984 | | else => return sema.mod.constVoid(block.arena, .unneeded), |
| 1995 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 1985 | 1996 | } |
| 1986 | 1997 | switch (end.ty.zigTypeTag()) { |
| 1987 | 1998 | .Int, .ComptimeInt => {}, |
| 1988 | | else => return sema.mod.constVoid(block.arena, .unneeded), |
| 1999 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 1989 | 2000 | } |
| 1990 | 2001 | // .switch_range must be inside a comptime scope |
| 1991 | 2002 | const start_val = start.value().?; |
| ... | ... | @@ -1993,7 +2004,7 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 1993 | 2004 | if (start_val.compare(.gte, end_val)) { |
| 1994 | 2005 | return sema.mod.fail(&block.base, inst.base.src, "range start value must be smaller than the end value", .{}); |
| 1995 | 2006 | } |
| 1996 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 2007 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 1997 | 2008 | } |
| 1998 | 2009 | |
| 1999 | 2010 | fn zirSwitchBr( |
| ... | ... | @@ -2021,22 +2032,22 @@ fn zirSwitchBr( |
| 2021 | 2032 | const item = try sema.resolveConstValue(parent_block, case_src, casted); |
| 2022 | 2033 | |
| 2023 | 2034 | if (target_val.eql(item)) { |
| 2024 | | try sema.body(scope.cast(Scope.Block).?, case.body); |
| 2035 | try sema.analyzeBody(scope.cast(Scope.Block).?, case.body); |
| 2025 | 2036 | return mod.constNoReturn(scope, inst.base.src); |
| 2026 | 2037 | } |
| 2027 | 2038 | } |
| 2028 | | try sema.body(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2039 | try sema.analyzeBody(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2029 | 2040 | return mod.constNoReturn(scope, inst.base.src); |
| 2030 | 2041 | } |
| 2031 | 2042 | |
| 2032 | 2043 | if (inst.positionals.cases.len == 0) { |
| 2033 | 2044 | // no cases just analyze else_branch |
| 2034 | | try sema.body(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2045 | try sema.analyzeBody(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2035 | 2046 | return mod.constNoReturn(scope, inst.base.src); |
| 2036 | 2047 | } |
| 2037 | 2048 | |
| 2038 | 2049 | try sema.requireRuntimeBlock(parent_block, inst.base.src); |
| 2039 | | const cases = try parent_block.arena.alloc(Inst.SwitchBr.Case, inst.positionals.cases.len); |
| 2050 | const cases = try sema.arena.alloc(Inst.SwitchBr.Case, inst.positionals.cases.len); |
| 2040 | 2051 | |
| 2041 | 2052 | var case_block: Scope.Block = .{ |
| 2042 | 2053 | .parent = parent_block, |
| ... | ... | @@ -2045,7 +2056,7 @@ fn zirSwitchBr( |
| 2045 | 2056 | .owner_decl = parent_block.owner_decl, |
| 2046 | 2057 | .src_decl = parent_block.src_decl, |
| 2047 | 2058 | .instructions = .{}, |
| 2048 | | .arena = parent_block.arena, |
| 2059 | .arena = sema.arena, |
| 2049 | 2060 | .inlining = parent_block.inlining, |
| 2050 | 2061 | .is_comptime = parent_block.is_comptime, |
| 2051 | 2062 | .branch_quota = parent_block.branch_quota, |
| ... | ... | @@ -2060,19 +2071,19 @@ fn zirSwitchBr( |
| 2060 | 2071 | const casted = try sema.coerce(scope, target.ty, resolved); |
| 2061 | 2072 | const item = try sema.resolveConstValue(parent_block, case_src, casted); |
| 2062 | 2073 | |
| 2063 | | try sema.body(&case_block, case.body); |
| 2074 | try sema.analyzeBody(&case_block, case.body); |
| 2064 | 2075 | |
| 2065 | 2076 | cases[i] = .{ |
| 2066 | 2077 | .item = item, |
| 2067 | | .body = .{ .instructions = try parent_block.arena.dupe(*Inst, case_block.instructions.items) }, |
| 2078 | .body = .{ .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items) }, |
| 2068 | 2079 | }; |
| 2069 | 2080 | } |
| 2070 | 2081 | |
| 2071 | 2082 | case_block.instructions.items.len = 0; |
| 2072 | | try sema.body(&case_block, inst.positionals.else_body); |
| 2083 | try sema.analyzeBody(&case_block, inst.positionals.else_body); |
| 2073 | 2084 | |
| 2074 | 2085 | const else_body: ir.Body = .{ |
| 2075 | | .instructions = try parent_block.arena.dupe(*Inst, case_block.instructions.items), |
| 2086 | .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items), |
| 2076 | 2087 | }; |
| 2077 | 2088 | |
| 2078 | 2089 | return mod.addSwitchBr(parent_block, inst.base.src, target, cases, else_body); |
| ... | ... | @@ -2232,7 +2243,7 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! |
| 2232 | 2243 | return sema.mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 2233 | 2244 | }, |
| 2234 | 2245 | }; |
| 2235 | | return sema.mod.constType(block.arena, src, file_scope.root_container.ty); |
| 2246 | return sema.mod.constType(sema.arena, src, file_scope.root_container.ty); |
| 2236 | 2247 | } |
| 2237 | 2248 | |
| 2238 | 2249 | fn zirShl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -2412,14 +2423,14 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: |
| 2412 | 2423 | const value = switch (inst.base.tag) { |
| 2413 | 2424 | .add => blk: { |
| 2414 | 2425 | const val = if (is_int) |
| 2415 | | try Module.intAdd(block.arena, lhs_val, rhs_val) |
| 2426 | try Module.intAdd(sema.arena, lhs_val, rhs_val) |
| 2416 | 2427 | else |
| 2417 | 2428 | try mod.floatAdd(scope, res_type, inst.base.src, lhs_val, rhs_val); |
| 2418 | 2429 | break :blk val; |
| 2419 | 2430 | }, |
| 2420 | 2431 | .sub => blk: { |
| 2421 | 2432 | const val = if (is_int) |
| 2422 | | try Module.intSub(block.arena, lhs_val, rhs_val) |
| 2433 | try Module.intSub(sema.arena, lhs_val, rhs_val) |
| 2423 | 2434 | else |
| 2424 | 2435 | try mod.floatSub(scope, res_type, inst.base.src, lhs_val, rhs_val); |
| 2425 | 2436 | break :blk val; |
| ... | ... | @@ -2435,7 +2446,7 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: |
| 2435 | 2446 | }); |
| 2436 | 2447 | } |
| 2437 | 2448 | |
| 2438 | | fn zirDeref(sema: *Sema, block: *Scope.Block, deref: zir.Inst.Index) InnerError!*Inst { |
| 2449 | fn zirDerefNode(sema: *Sema, block: *Scope.Block, deref: zir.Inst.Index) InnerError!*Inst { |
| 2439 | 2450 | const tracy = trace(@src()); |
| 2440 | 2451 | defer tracy.end(); |
| 2441 | 2452 | |
| ... | ... | @@ -2473,9 +2484,9 @@ fn zirAsm( |
| 2473 | 2484 | }; |
| 2474 | 2485 | } else null; |
| 2475 | 2486 | |
| 2476 | | const args = try block.arena.alloc(*Inst, extra.data.args.len); |
| 2477 | | const inputs = try block.arena.alloc([]const u8, extra.data.args_len); |
| 2478 | | const clobbers = try block.arena.alloc([]const u8, extra.data.clobbers_len); |
| 2487 | const args = try sema.arena.alloc(*Inst, extra.data.args.len); |
| 2488 | const inputs = try sema.arena.alloc([]const u8, extra.data.args_len); |
| 2489 | const clobbers = try sema.arena.alloc([]const u8, extra.data.clobbers_len); |
| 2479 | 2490 | |
| 2480 | 2491 | for (args) |*arg| { |
| 2481 | 2492 | const uncasted = sema.resolveInst(block, sema.code.extra[extra_i]); |
| ... | ... | @@ -2492,7 +2503,7 @@ fn zirAsm( |
| 2492 | 2503 | } |
| 2493 | 2504 | |
| 2494 | 2505 | try sema.requireRuntimeBlock(block, src); |
| 2495 | | const inst = try block.arena.create(Inst.Assembly); |
| 2506 | const inst = try sema.arena.create(Inst.Assembly); |
| 2496 | 2507 | inst.* = .{ |
| 2497 | 2508 | .base = .{ |
| 2498 | 2509 | .tag = .assembly, |
| ... | ... | @@ -2532,7 +2543,7 @@ fn zirCmp( |
| 2532 | 2543 | const rhs_ty_tag = rhs.ty.zigTypeTag(); |
| 2533 | 2544 | if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) { |
| 2534 | 2545 | // null == null, null != null |
| 2535 | | return mod.constBool(block.arena, inst.base.src, op == .eq); |
| 2546 | return mod.constBool(sema.arena, inst.base.src, op == .eq); |
| 2536 | 2547 | } else if (is_equality_cmp and |
| 2537 | 2548 | ((lhs_ty_tag == .Null and rhs_ty_tag == .Optional) or |
| 2538 | 2549 | rhs_ty_tag == .Null and lhs_ty_tag == .Optional)) |
| ... | ... | @@ -2559,7 +2570,7 @@ fn zirCmp( |
| 2559 | 2570 | if (rhs.value()) |rval| { |
| 2560 | 2571 | if (lhs.value()) |lval| { |
| 2561 | 2572 | // TODO optimisation oppurtunity: evaluate if std.mem.eql is faster with the names, or calling to Module.getErrorValue to get the values and then compare them is faster |
| 2562 | | return mod.constBool(block.arena, inst.base.src, std.mem.eql(u8, lval.castTag(.@"error").?.data.name, rval.castTag(.@"error").?.data.name) == (op == .eq)); |
| 2573 | return mod.constBool(sema.arena, inst.base.src, std.mem.eql(u8, lval.castTag(.@"error").?.data.name, rval.castTag(.@"error").?.data.name) == (op == .eq)); |
| 2563 | 2574 | } |
| 2564 | 2575 | } |
| 2565 | 2576 | try sema.requireRuntimeBlock(block, inst.base.src); |
| ... | ... | @@ -2573,7 +2584,7 @@ fn zirCmp( |
| 2573 | 2584 | if (!is_equality_cmp) { |
| 2574 | 2585 | return sema.mod.fail(&block.base, inst.base.src, "{s} operator not allowed for types", .{@tagName(op)}); |
| 2575 | 2586 | } |
| 2576 | | return mod.constBool(block.arena, inst.base.src, lhs.value().?.eql(rhs.value().?) == (op == .eq)); |
| 2587 | return mod.constBool(sema.arena, inst.base.src, lhs.value().?.eql(rhs.value().?) == (op == .eq)); |
| 2577 | 2588 | } |
| 2578 | 2589 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement more cmp analysis", .{}); |
| 2579 | 2590 | } |
| ... | ... | @@ -2584,7 +2595,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! |
| 2584 | 2595 | |
| 2585 | 2596 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 2586 | 2597 | const operand = sema.resolveInst(block, inst_data.operand); |
| 2587 | | return sema.mod.constType(block.arena, inst_data.src(), operand.ty); |
| 2598 | return sema.mod.constType(sema.arena, inst_data.src(), operand.ty); |
| 2588 | 2599 | } |
| 2589 | 2600 | |
| 2590 | 2601 | fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -2607,7 +2618,7 @@ fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 2607 | 2618 | } |
| 2608 | 2619 | |
| 2609 | 2620 | const result_type = try sema.resolvePeerTypes(block, inst_list, src_list); |
| 2610 | | return sema.mod.constType(block.arena, src, result_type); |
| 2621 | return sema.mod.constType(sema.arena, src, result_type); |
| 2611 | 2622 | } |
| 2612 | 2623 | |
| 2613 | 2624 | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -2621,7 +2632,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 2621 | 2632 | const bool_type = Type.initTag(.bool); |
| 2622 | 2633 | const operand = try sema.coerce(scope, bool_type, uncasted_operand); |
| 2623 | 2634 | if (try mod.resolveDefinedValue(scope, operand)) |val| { |
| 2624 | | return mod.constBool(block.arena, src, !val.toBool()); |
| 2635 | return mod.constBool(sema.arena, src, !val.toBool()); |
| 2625 | 2636 | } |
| 2626 | 2637 | try sema.requireRuntimeBlock(block, src); |
| 2627 | 2638 | return block.addUnOp(src, bool_type, .not, operand); |
| ... | ... | @@ -2646,9 +2657,9 @@ fn zirBoolOp( |
| 2646 | 2657 | if (lhs.value()) |lhs_val| { |
| 2647 | 2658 | if (rhs.value()) |rhs_val| { |
| 2648 | 2659 | if (is_bool_or) { |
| 2649 | | return mod.constBool(block.arena, inst.base.src, lhs_val.toBool() or rhs_val.toBool()); |
| 2660 | return mod.constBool(sema.arena, inst.base.src, lhs_val.toBool() or rhs_val.toBool()); |
| 2650 | 2661 | } else { |
| 2651 | | return mod.constBool(block.arena, inst.base.src, lhs_val.toBool() and rhs_val.toBool()); |
| 2662 | return mod.constBool(sema.arena, inst.base.src, lhs_val.toBool() and rhs_val.toBool()); |
| 2652 | 2663 | } |
| 2653 | 2664 | } |
| 2654 | 2665 | } |
| ... | ... | @@ -2717,7 +2728,7 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2717 | 2728 | |
| 2718 | 2729 | if (try mod.resolveDefinedValue(scope, cond)) |cond_val| { |
| 2719 | 2730 | const body = if (cond_val.toBool()) &inst.positionals.then_body else &inst.positionals.else_body; |
| 2720 | | try sema.body(parent_block, body.*); |
| 2731 | try sema.analyzeBody(parent_block, body.*); |
| 2721 | 2732 | return mod.constNoReturn(scope, inst.base.src); |
| 2722 | 2733 | } |
| 2723 | 2734 | |
| ... | ... | @@ -2728,13 +2739,13 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2728 | 2739 | .owner_decl = parent_block.owner_decl, |
| 2729 | 2740 | .src_decl = parent_block.src_decl, |
| 2730 | 2741 | .instructions = .{}, |
| 2731 | | .arena = parent_block.arena, |
| 2742 | .arena = sema.arena, |
| 2732 | 2743 | .inlining = parent_block.inlining, |
| 2733 | 2744 | .is_comptime = parent_block.is_comptime, |
| 2734 | 2745 | .branch_quota = parent_block.branch_quota, |
| 2735 | 2746 | }; |
| 2736 | 2747 | defer true_block.instructions.deinit(mod.gpa); |
| 2737 | | try sema.body(&true_block, inst.positionals.then_body); |
| 2748 | try sema.analyzeBody(&true_block, inst.positionals.then_body); |
| 2738 | 2749 | |
| 2739 | 2750 | var false_block: Scope.Block = .{ |
| 2740 | 2751 | .parent = parent_block, |
| ... | ... | @@ -2743,16 +2754,16 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2743 | 2754 | .owner_decl = parent_block.owner_decl, |
| 2744 | 2755 | .src_decl = parent_block.src_decl, |
| 2745 | 2756 | .instructions = .{}, |
| 2746 | | .arena = parent_block.arena, |
| 2757 | .arena = sema.arena, |
| 2747 | 2758 | .inlining = parent_block.inlining, |
| 2748 | 2759 | .is_comptime = parent_block.is_comptime, |
| 2749 | 2760 | .branch_quota = parent_block.branch_quota, |
| 2750 | 2761 | }; |
| 2751 | 2762 | defer false_block.instructions.deinit(mod.gpa); |
| 2752 | | try sema.body(&false_block, inst.positionals.else_body); |
| 2763 | try sema.analyzeBody(&false_block, inst.positionals.else_body); |
| 2753 | 2764 | |
| 2754 | | const then_body: ir.Body = .{ .instructions = try block.arena.dupe(*Inst, true_block.instructions.items) }; |
| 2755 | | const else_body: ir.Body = .{ .instructions = try block.arena.dupe(*Inst, false_block.instructions.items) }; |
| 2765 | const then_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, true_block.instructions.items) }; |
| 2766 | const else_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, false_block.instructions.items) }; |
| 2756 | 2767 | return mod.addCondBr(parent_block, inst.base.src, cond, then_body, else_body); |
| 2757 | 2768 | } |
| 2758 | 2769 | |
| ... | ... | @@ -2797,7 +2808,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2797 | 2808 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; |
| 2798 | 2809 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); |
| 2799 | 2810 | const ty = try sema.mod.ptrType( |
| 2800 | | block.arena, |
| 2811 | sema.arena, |
| 2801 | 2812 | elem_type, |
| 2802 | 2813 | null, |
| 2803 | 2814 | 0, |
| ... | ... | @@ -2808,7 +2819,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2808 | 2819 | inst_data.is_volatile, |
| 2809 | 2820 | inst_data.size, |
| 2810 | 2821 | ); |
| 2811 | | return sema.mod.constType(block.arena, .unneeded, ty); |
| 2822 | return sema.mod.constType(sema.arena, .unneeded, ty); |
| 2812 | 2823 | } |
| 2813 | 2824 | |
| 2814 | 2825 | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -2861,7 +2872,17 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 2861 | 2872 | inst_data.flags.is_volatile, |
| 2862 | 2873 | inst_data.size, |
| 2863 | 2874 | ); |
| 2864 | | return sema.mod.constType(block.arena, .unneeded, ty); |
| 2875 | return sema.mod.constType(sema.arena, .unneeded, ty); |
| 2876 | } |
| 2877 | |
| 2878 | fn zirAwait(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| 2879 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2880 | return sema.mod.fail(&block.base, inst_data.src(), "TODO implement Sema await", .{}); |
| 2881 | } |
| 2882 | |
| 2883 | fn zirNosuspendAwait(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| 2884 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2885 | return sema.mod.fail(&block.base, inst_data.src(), "TODO implement Sema nosuspend_await", .{}); |
| 2865 | 2886 | } |
| 2866 | 2887 | |
| 2867 | 2888 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| ... | ... | @@ -2877,7 +2898,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void |
| 2877 | 2898 | } |
| 2878 | 2899 | } |
| 2879 | 2900 | |
| 2880 | | fn validateVarType(sema: *Module, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void { |
| 2901 | fn validateVarType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void { |
| 2881 | 2902 | if (!ty.isValidVarType(false)) { |
| 2882 | 2903 | return mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{ty}); |
| 2883 | 2904 | } |
| ... | ... | @@ -2890,7 +2911,7 @@ pub const PanicId = enum { |
| 2890 | 2911 | }; |
| 2891 | 2912 | |
| 2892 | 2913 | fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: PanicId) !void { |
| 2893 | | const block_inst = try parent_block.arena.create(Inst.Block); |
| 2914 | const block_inst = try sema.arena.create(Inst.Block); |
| 2894 | 2915 | block_inst.* = .{ |
| 2895 | 2916 | .base = .{ |
| 2896 | 2917 | .tag = Inst.Block.base_tag, |
| ... | ... | @@ -2898,14 +2919,14 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2898 | 2919 | .src = ok.src, |
| 2899 | 2920 | }, |
| 2900 | 2921 | .body = .{ |
| 2901 | | .instructions = try parent_block.arena.alloc(*Inst, 1), // Only need space for the condbr. |
| 2922 | .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the condbr. |
| 2902 | 2923 | }, |
| 2903 | 2924 | }; |
| 2904 | 2925 | |
| 2905 | 2926 | const ok_body: ir.Body = .{ |
| 2906 | | .instructions = try parent_block.arena.alloc(*Inst, 1), // Only need space for the br_void. |
| 2927 | .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the br_void. |
| 2907 | 2928 | }; |
| 2908 | | const br_void = try parent_block.arena.create(Inst.BrVoid); |
| 2929 | const br_void = try sema.arena.create(Inst.BrVoid); |
| 2909 | 2930 | br_void.* = .{ |
| 2910 | 2931 | .base = .{ |
| 2911 | 2932 | .tag = .br_void, |
| ... | ... | @@ -2923,7 +2944,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2923 | 2944 | .owner_decl = parent_block.owner_decl, |
| 2924 | 2945 | .src_decl = parent_block.src_decl, |
| 2925 | 2946 | .instructions = .{}, |
| 2926 | | .arena = parent_block.arena, |
| 2947 | .arena = sema.arena, |
| 2927 | 2948 | .inlining = parent_block.inlining, |
| 2928 | 2949 | .is_comptime = parent_block.is_comptime, |
| 2929 | 2950 | .branch_quota = parent_block.branch_quota, |
| ... | ... | @@ -2933,9 +2954,9 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2933 | 2954 | |
| 2934 | 2955 | _ = try mod.safetyPanic(&fail_block, ok.src, panic_id); |
| 2935 | 2956 | |
| 2936 | | const fail_body: ir.Body = .{ .instructions = try parent_block.arena.dupe(*Inst, fail_block.instructions.items) }; |
| 2957 | const fail_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, fail_block.instructions.items) }; |
| 2937 | 2958 | |
| 2938 | | const condbr = try parent_block.arena.create(Inst.CondBr); |
| 2959 | const condbr = try sema.arena.create(Inst.CondBr); |
| 2939 | 2960 | condbr.* = .{ |
| 2940 | 2961 | .base = .{ |
| 2941 | 2962 | .tag = .condbr, |
| ... | ... | @@ -3296,7 +3317,7 @@ fn storePtr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ptr: *Inst, uncas |
| 3296 | 3317 | const elem_ty = ptr.ty.elemType(); |
| 3297 | 3318 | const value = try sema.coerce(scope, elem_ty, uncasted_value); |
| 3298 | 3319 | if (elem_ty.onePossibleValue() != null) |
| 3299 | | return sema.mod.constVoid(block.arena, .unneeded); |
| 3320 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 3300 | 3321 | |
| 3301 | 3322 | // TODO handle comptime pointer writes |
| 3302 | 3323 | // TODO handle if the element type requires comptime |
| ... | ... | @@ -3438,7 +3459,7 @@ fn analyzeIsNull( |
| 3438 | 3459 | if (operand.value()) |opt_val| { |
| 3439 | 3460 | const is_null = opt_val.isNull(); |
| 3440 | 3461 | const bool_value = if (invert_logic) !is_null else is_null; |
| 3441 | | return mod.constBool(block.arena, src, bool_value); |
| 3462 | return mod.constBool(sema.arena, src, bool_value); |
| 3442 | 3463 | } |
| 3443 | 3464 | try sema.requireRuntimeBlock(block, src); |
| 3444 | 3465 | const inst_tag: Inst.Tag = if (invert_logic) .is_non_null else .is_null; |
| ... | ... | @@ -3447,11 +3468,11 @@ fn analyzeIsNull( |
| 3447 | 3468 | |
| 3448 | 3469 | fn analyzeIsErr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, operand: *Inst) InnerError!*Inst { |
| 3449 | 3470 | const ot = operand.ty.zigTypeTag(); |
| 3450 | | if (ot != .ErrorSet and ot != .ErrorUnion) return mod.constBool(block.arena, src, false); |
| 3451 | | if (ot == .ErrorSet) return mod.constBool(block.arena, src, true); |
| 3471 | if (ot != .ErrorSet and ot != .ErrorUnion) return mod.constBool(sema.arena, src, false); |
| 3472 | if (ot == .ErrorSet) return mod.constBool(sema.arena, src, true); |
| 3452 | 3473 | assert(ot == .ErrorUnion); |
| 3453 | 3474 | if (operand.value()) |err_union| { |
| 3454 | | return mod.constBool(block.arena, src, err_union.getError() != null); |
| 3475 | return mod.constBool(sema.arena, src, err_union.getError() != null); |
| 3455 | 3476 | } |
| 3456 | 3477 | try sema.requireRuntimeBlock(block, src); |
| 3457 | 3478 | return mod.addUnOp(b, src, Type.initTag(.bool), .is_err, operand); |
| ... | ... | @@ -3616,7 +3637,7 @@ fn cmpNumeric( |
| 3616 | 3637 | |
| 3617 | 3638 | if (lhs.value()) |lhs_val| { |
| 3618 | 3639 | if (rhs.value()) |rhs_val| { |
| 3619 | | return mod.constBool(block.arena, src, Value.compare(lhs_val, op, rhs_val)); |
| 3640 | return mod.constBool(sema.arena, src, Value.compare(lhs_val, op, rhs_val)); |
| 3620 | 3641 | } |
| 3621 | 3642 | } |
| 3622 | 3643 | |
| ... | ... | @@ -3684,8 +3705,8 @@ fn cmpNumeric( |
| 3684 | 3705 | const zcmp = lhs_val.orderAgainstZero(); |
| 3685 | 3706 | if (lhs_val.floatHasFraction()) { |
| 3686 | 3707 | switch (op) { |
| 3687 | | .eq => return mod.constBool(block.arena, src, false), |
| 3688 | | .neq => return mod.constBool(block.arena, src, true), |
| 3708 | .eq => return mod.constBool(sema.arena, src, false), |
| 3709 | .neq => return mod.constBool(sema.arena, src, true), |
| 3689 | 3710 | else => {}, |
| 3690 | 3711 | } |
| 3691 | 3712 | if (zcmp == .lt) { |
| ... | ... | @@ -3719,8 +3740,8 @@ fn cmpNumeric( |
| 3719 | 3740 | const zcmp = rhs_val.orderAgainstZero(); |
| 3720 | 3741 | if (rhs_val.floatHasFraction()) { |
| 3721 | 3742 | switch (op) { |
| 3722 | | .eq => return mod.constBool(block.arena, src, false), |
| 3723 | | .neq => return mod.constBool(block.arena, src, true), |
| 3743 | .eq => return mod.constBool(sema.arena, src, false), |
| 3744 | .neq => return mod.constBool(sema.arena, src, true), |
| 3724 | 3745 | else => {}, |
| 3725 | 3746 | } |
| 3726 | 3747 | if (zcmp == .lt) { |