| ... | ... | @@ -83,10 +83,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 83 | 83 | .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?), |
| 84 | 84 | .set_eval_branch_quota => return analyzeInstSetEvalBranchQuota(mod, scope, old_inst.castTag(.set_eval_branch_quota).?), |
| 85 | 85 | .str => return analyzeInstStr(mod, scope, old_inst.castTag(.str).?), |
| 86 | | .int => { |
| 87 | | const big_int = old_inst.castTag(.int).?.positionals.int; |
| 88 | | return mod.constIntBig(scope, old_inst.src, Type.initTag(.comptime_int), big_int); |
| 89 | | }, |
| 86 | .int => return analyzeInstInt(mod, scope, old_inst.castTag(.int).?), |
| 90 | 87 | .inttype => return analyzeInstIntType(mod, scope, old_inst.castTag(.inttype).?), |
| 91 | 88 | .loop => return analyzeInstLoop(mod, scope, old_inst.castTag(.loop).?), |
| 92 | 89 | .param_type => return analyzeInstParamType(mod, scope, old_inst.castTag(.param_type).?), |
| ... | ... | @@ -161,6 +158,9 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 161 | 158 | } |
| 162 | 159 | |
| 163 | 160 | pub fn analyzeBody(mod: *Module, block: *Scope.Block, body: zir.Module.Body) !void { |
| 161 | const tracy = trace(@src()); |
| 162 | defer tracy.end(); |
| 163 | |
| 164 | 164 | for (body.instructions) |src_inst| { |
| 165 | 165 | const analyzed_inst = try analyzeInst(mod, &block.base, src_inst); |
| 166 | 166 | try block.inst_table.putNoClobber(src_inst, analyzed_inst); |
| ... | ... | @@ -317,6 +317,8 @@ pub fn resolveInstConst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerE |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | fn analyzeInstConst(mod: *Module, scope: *Scope, const_inst: *zir.Inst.Const) InnerError!*Inst { |
| 320 | const tracy = trace(@src()); |
| 321 | defer tracy.end(); |
| 320 | 322 | // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions |
| 321 | 323 | // after analysis. |
| 322 | 324 | const typed_value_copy = try const_inst.positionals.typed_value.copy(scope.arena()); |
| ... | ... | @@ -336,29 +338,41 @@ fn analyzeInstCoerceResultBlockPtr( |
| 336 | 338 | scope: *Scope, |
| 337 | 339 | inst: *zir.Inst.CoerceResultBlockPtr, |
| 338 | 340 | ) InnerError!*Inst { |
| 341 | const tracy = trace(@src()); |
| 342 | defer tracy.end(); |
| 339 | 343 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultBlockPtr", .{}); |
| 340 | 344 | } |
| 341 | 345 | |
| 342 | 346 | fn analyzeInstBitCastRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 347 | const tracy = trace(@src()); |
| 348 | defer tracy.end(); |
| 343 | 349 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitCastRef", .{}); |
| 344 | 350 | } |
| 345 | 351 | |
| 346 | 352 | fn analyzeInstBitCastResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 353 | const tracy = trace(@src()); |
| 354 | defer tracy.end(); |
| 347 | 355 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitCastResultPtr", .{}); |
| 348 | 356 | } |
| 349 | 357 | |
| 350 | 358 | fn analyzeInstCoerceResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 359 | const tracy = trace(@src()); |
| 360 | defer tracy.end(); |
| 351 | 361 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultPtr", .{}); |
| 352 | 362 | } |
| 353 | 363 | |
| 354 | 364 | /// Equivalent to `as(ptr_child_type(typeof(ptr)), value)`. |
| 355 | 365 | fn analyzeInstCoerceToPtrElem(mod: *Module, scope: *Scope, inst: *zir.Inst.CoerceToPtrElem) InnerError!*Inst { |
| 366 | const tracy = trace(@src()); |
| 367 | defer tracy.end(); |
| 356 | 368 | const ptr = try resolveInst(mod, scope, inst.positionals.ptr); |
| 357 | 369 | const operand = try resolveInst(mod, scope, inst.positionals.value); |
| 358 | 370 | return mod.coerce(scope, ptr.ty.elemType(), operand); |
| 359 | 371 | } |
| 360 | 372 | |
| 361 | 373 | fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { |
| 374 | const tracy = trace(@src()); |
| 375 | defer tracy.end(); |
| 362 | 376 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 363 | 377 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 364 | 378 | const ret_type = fn_ty.fnReturnType(); |
| ... | ... | @@ -367,6 +381,8 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr |
| 367 | 381 | } |
| 368 | 382 | |
| 369 | 383 | fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 384 | const tracy = trace(@src()); |
| 385 | defer tracy.end(); |
| 370 | 386 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 371 | 387 | const ptr_type = try mod.simplePtrType(scope, inst.base.src, operand.ty, false, .One); |
| 372 | 388 | |
| ... | ... | @@ -382,6 +398,8 @@ fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError! |
| 382 | 398 | } |
| 383 | 399 | |
| 384 | 400 | fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { |
| 401 | const tracy = trace(@src()); |
| 402 | defer tracy.end(); |
| 385 | 403 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 386 | 404 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 387 | 405 | const ret_type = fn_ty.fnReturnType(); |
| ... | ... | @@ -389,6 +407,8 @@ fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr |
| 389 | 407 | } |
| 390 | 408 | |
| 391 | 409 | fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 410 | const tracy = trace(@src()); |
| 411 | defer tracy.end(); |
| 392 | 412 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 393 | 413 | switch (operand.ty.zigTypeTag()) { |
| 394 | 414 | .Void, .NoReturn => return mod.constVoid(scope, operand.src), |
| ... | ... | @@ -397,6 +417,8 @@ fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp |
| 397 | 417 | } |
| 398 | 418 | |
| 399 | 419 | fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 420 | const tracy = trace(@src()); |
| 421 | defer tracy.end(); |
| 400 | 422 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 401 | 423 | switch (operand.ty.zigTypeTag()) { |
| 402 | 424 | .ErrorSet, .ErrorUnion => return mod.fail(scope, operand.src, "error is discarded", .{}), |
| ... | ... | @@ -405,6 +427,8 @@ fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst. |
| 405 | 427 | } |
| 406 | 428 | |
| 407 | 429 | fn analyzeInstEnsureIndexable(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 430 | const tracy = trace(@src()); |
| 431 | defer tracy.end(); |
| 408 | 432 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 409 | 433 | const elem_ty = operand.ty.elemType(); |
| 410 | 434 | if (elem_ty.isIndexable()) { |
| ... | ... | @@ -418,6 +442,8 @@ fn analyzeInstEnsureIndexable(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) |
| 418 | 442 | } |
| 419 | 443 | |
| 420 | 444 | fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 445 | const tracy = trace(@src()); |
| 446 | defer tracy.end(); |
| 421 | 447 | const var_type = try resolveType(mod, scope, inst.positionals.operand); |
| 422 | 448 | const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One); |
| 423 | 449 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); |
| ... | ... | @@ -425,6 +451,8 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro |
| 425 | 451 | } |
| 426 | 452 | |
| 427 | 453 | fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 454 | const tracy = trace(@src()); |
| 455 | defer tracy.end(); |
| 428 | 456 | const var_type = try resolveType(mod, scope, inst.positionals.operand); |
| 429 | 457 | try mod.validateVarType(scope, inst.base.src, var_type); |
| 430 | 458 | const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One); |
| ... | ... | @@ -438,6 +466,8 @@ fn analyzeInstAllocInferred( |
| 438 | 466 | inst: *zir.Inst.NoOp, |
| 439 | 467 | mut_tag: Type.Tag, |
| 440 | 468 | ) InnerError!*Inst { |
| 469 | const tracy = trace(@src()); |
| 470 | defer tracy.end(); |
| 441 | 471 | const val_payload = try scope.arena().create(Value.Payload.InferredAlloc); |
| 442 | 472 | val_payload.* = .{ |
| 443 | 473 | .data = .{}, |
| ... | ... | @@ -464,6 +494,8 @@ fn analyzeInstResolveInferredAlloc( |
| 464 | 494 | scope: *Scope, |
| 465 | 495 | inst: *zir.Inst.UnOp, |
| 466 | 496 | ) InnerError!*Inst { |
| 497 | const tracy = trace(@src()); |
| 498 | defer tracy.end(); |
| 467 | 499 | const ptr = try resolveInst(mod, scope, inst.positionals.operand); |
| 468 | 500 | const ptr_val = ptr.castTag(.constant).?.val; |
| 469 | 501 | const inferred_alloc = ptr_val.castTag(.inferred_alloc).?; |
| ... | ... | @@ -491,6 +523,8 @@ fn analyzeInstStoreToInferredPtr( |
| 491 | 523 | scope: *Scope, |
| 492 | 524 | inst: *zir.Inst.BinOp, |
| 493 | 525 | ) InnerError!*Inst { |
| 526 | const tracy = trace(@src()); |
| 527 | defer tracy.end(); |
| 494 | 528 | const ptr = try resolveInst(mod, scope, inst.positionals.lhs); |
| 495 | 529 | const value = try resolveInst(mod, scope, inst.positionals.rhs); |
| 496 | 530 | const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?; |
| ... | ... | @@ -518,12 +552,16 @@ fn analyzeInstSetEvalBranchQuota( |
| 518 | 552 | } |
| 519 | 553 | |
| 520 | 554 | fn analyzeInstStore(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 555 | const tracy = trace(@src()); |
| 556 | defer tracy.end(); |
| 521 | 557 | const ptr = try resolveInst(mod, scope, inst.positionals.lhs); |
| 522 | 558 | const value = try resolveInst(mod, scope, inst.positionals.rhs); |
| 523 | 559 | return mod.storePtr(scope, inst.base.src, ptr, value); |
| 524 | 560 | } |
| 525 | 561 | |
| 526 | 562 | fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType) InnerError!*Inst { |
| 563 | const tracy = trace(@src()); |
| 564 | defer tracy.end(); |
| 527 | 565 | const fn_inst = try resolveInst(mod, scope, inst.positionals.func); |
| 528 | 566 | const arg_index = inst.positionals.arg_index; |
| 529 | 567 | |
| ... | ... | @@ -553,6 +591,8 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType) |
| 553 | 591 | } |
| 554 | 592 | |
| 555 | 593 | fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst { |
| 594 | const tracy = trace(@src()); |
| 595 | defer tracy.end(); |
| 556 | 596 | // The bytes references memory inside the ZIR module, which can get deallocated |
| 557 | 597 | // after semantic analysis is complete. We need the memory to be in the new anonymous Decl's arena. |
| 558 | 598 | var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa); |
| ... | ... | @@ -566,7 +606,16 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr |
| 566 | 606 | return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl); |
| 567 | 607 | } |
| 568 | 608 | |
| 609 | fn analyzeInstInt(mod: *Module, scope: *Scope, inst: *zir.Inst.Int) InnerError!*Inst { |
| 610 | const tracy = trace(@src()); |
| 611 | defer tracy.end(); |
| 612 | |
| 613 | return mod.constIntBig(scope, inst.base.src, Type.initTag(.comptime_int), inst.positionals.int); |
| 614 | } |
| 615 | |
| 569 | 616 | fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst { |
| 617 | const tracy = trace(@src()); |
| 618 | defer tracy.end(); |
| 570 | 619 | const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name); |
| 571 | 620 | const exported_decl = mod.lookupDeclName(scope, export_inst.positionals.decl_name) orelse |
| 572 | 621 | return mod.fail(scope, export_inst.base.src, "decl '{s}' not found", .{export_inst.positionals.decl_name}); |
| ... | ... | @@ -575,11 +624,15 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) |
| 575 | 624 | } |
| 576 | 625 | |
| 577 | 626 | fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 627 | const tracy = trace(@src()); |
| 628 | defer tracy.end(); |
| 578 | 629 | const msg = try resolveConstString(mod, scope, inst.positionals.operand); |
| 579 | 630 | return mod.fail(scope, inst.base.src, "{s}", .{msg}); |
| 580 | 631 | } |
| 581 | 632 | |
| 582 | 633 | fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst { |
| 634 | const tracy = trace(@src()); |
| 635 | defer tracy.end(); |
| 583 | 636 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 584 | 637 | if (b.inlining) |inlining| { |
| 585 | 638 | const param_index = inlining.param_index; |
| ... | ... | @@ -601,6 +654,8 @@ fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!* |
| 601 | 654 | } |
| 602 | 655 | |
| 603 | 656 | fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError!*Inst { |
| 657 | const tracy = trace(@src()); |
| 658 | defer tracy.end(); |
| 604 | 659 | const parent_block = scope.cast(Scope.Block).?; |
| 605 | 660 | |
| 606 | 661 | // Reserve space for a Loop instruction so that generated Break instructions can |
| ... | ... | @@ -639,6 +694,8 @@ fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError |
| 639 | 694 | } |
| 640 | 695 | |
| 641 | 696 | fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst { |
| 697 | const tracy = trace(@src()); |
| 698 | defer tracy.end(); |
| 642 | 699 | const parent_block = scope.cast(Scope.Block).?; |
| 643 | 700 | |
| 644 | 701 | var child_block: Scope.Block = .{ |
| ... | ... | @@ -667,6 +724,8 @@ fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_c |
| 667 | 724 | } |
| 668 | 725 | |
| 669 | 726 | fn analyzeInstBlock(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst { |
| 727 | const tracy = trace(@src()); |
| 728 | defer tracy.end(); |
| 670 | 729 | const parent_block = scope.cast(Scope.Block).?; |
| 671 | 730 | |
| 672 | 731 | // Reserve space for a Block instruction so that generated Break instructions can |
| ... | ... | @@ -717,6 +776,9 @@ fn analyzeBlockBody( |
| 717 | 776 | child_block: *Scope.Block, |
| 718 | 777 | merges: *Scope.Block.Merges, |
| 719 | 778 | ) InnerError!*Inst { |
| 779 | const tracy = trace(@src()); |
| 780 | defer tracy.end(); |
| 781 | |
| 720 | 782 | const parent_block = scope.cast(Scope.Block).?; |
| 721 | 783 | |
| 722 | 784 | // Blocks must terminate with noreturn instruction. |
| ... | ... | @@ -755,23 +817,31 @@ fn analyzeBlockBody( |
| 755 | 817 | } |
| 756 | 818 | |
| 757 | 819 | fn analyzeInstBreakpoint(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { |
| 820 | const tracy = trace(@src()); |
| 821 | defer tracy.end(); |
| 758 | 822 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); |
| 759 | 823 | return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .breakpoint); |
| 760 | 824 | } |
| 761 | 825 | |
| 762 | 826 | fn analyzeInstBreak(mod: *Module, scope: *Scope, inst: *zir.Inst.Break) InnerError!*Inst { |
| 827 | const tracy = trace(@src()); |
| 828 | defer tracy.end(); |
| 763 | 829 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 764 | 830 | const block = inst.positionals.block; |
| 765 | 831 | return analyzeBreak(mod, scope, inst.base.src, block, operand); |
| 766 | 832 | } |
| 767 | 833 | |
| 768 | 834 | fn analyzeInstBreakVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) InnerError!*Inst { |
| 835 | const tracy = trace(@src()); |
| 836 | defer tracy.end(); |
| 769 | 837 | const block = inst.positionals.block; |
| 770 | 838 | const void_inst = try mod.constVoid(scope, inst.base.src); |
| 771 | 839 | return analyzeBreak(mod, scope, inst.base.src, block, void_inst); |
| 772 | 840 | } |
| 773 | 841 | |
| 774 | 842 | fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { |
| 843 | const tracy = trace(@src()); |
| 844 | defer tracy.end(); |
| 775 | 845 | if (scope.cast(Scope.Block)) |b| { |
| 776 | 846 | if (!b.is_comptime) { |
| 777 | 847 | return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .dbg_stmt); |
| ... | ... | @@ -781,26 +851,37 @@ fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr |
| 781 | 851 | } |
| 782 | 852 | |
| 783 | 853 | fn analyzeInstDeclRefStr(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRefStr) InnerError!*Inst { |
| 854 | const tracy = trace(@src()); |
| 855 | defer tracy.end(); |
| 784 | 856 | const decl_name = try resolveConstString(mod, scope, inst.positionals.name); |
| 785 | 857 | return mod.analyzeDeclRefByName(scope, inst.base.src, decl_name); |
| 786 | 858 | } |
| 787 | 859 | |
| 788 | 860 | fn analyzeInstDeclRef(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRef) InnerError!*Inst { |
| 861 | const tracy = trace(@src()); |
| 862 | defer tracy.end(); |
| 789 | 863 | return mod.analyzeDeclRefByName(scope, inst.base.src, inst.positionals.name); |
| 790 | 864 | } |
| 791 | 865 | |
| 792 | 866 | fn analyzeInstDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerError!*Inst { |
| 867 | const tracy = trace(@src()); |
| 868 | defer tracy.end(); |
| 793 | 869 | const decl = try analyzeDeclVal(mod, scope, inst); |
| 794 | 870 | const ptr = try mod.analyzeDeclRef(scope, inst.base.src, decl); |
| 795 | 871 | return mod.analyzeDeref(scope, inst.base.src, ptr, inst.base.src); |
| 796 | 872 | } |
| 797 | 873 | |
| 798 | 874 | fn analyzeInstDeclValInModule(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclValInModule) InnerError!*Inst { |
| 875 | const tracy = trace(@src()); |
| 876 | defer tracy.end(); |
| 799 | 877 | const decl = inst.positionals.decl; |
| 800 | 878 | return mod.analyzeDeclRef(scope, inst.base.src, decl); |
| 801 | 879 | } |
| 802 | 880 | |
| 803 | 881 | fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst { |
| 882 | const tracy = trace(@src()); |
| 883 | defer tracy.end(); |
| 884 | |
| 804 | 885 | const func = try resolveInst(mod, scope, inst.positionals.func); |
| 805 | 886 | if (func.ty.zigTypeTag() != .Fn) |
| 806 | 887 | return mod.fail(scope, inst.positionals.func.src, "type '{}' not a function", .{func.ty}); |
| ... | ... | @@ -943,19 +1024,15 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError |
| 943 | 1024 | // the block_inst above. |
| 944 | 1025 | try analyzeBody(mod, &child_block, module_fn.zir); |
| 945 | 1026 | |
| 946 | | const result = try analyzeBlockBody(mod, scope, &child_block, merges); |
| 947 | | if (result.castTag(.constant)) |constant| { |
| 948 | | log.debug("inline call resulted in {}", .{constant.val}); |
| 949 | | } else { |
| 950 | | log.debug("inline call resulted in {}", .{result}); |
| 951 | | } |
| 952 | | return result; |
| 1027 | return analyzeBlockBody(mod, scope, &child_block, merges); |
| 953 | 1028 | } |
| 954 | 1029 | |
| 955 | 1030 | return mod.addCall(b, inst.base.src, ret_type, func, casted_args); |
| 956 | 1031 | } |
| 957 | 1032 | |
| 958 | 1033 | fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst { |
| 1034 | const tracy = trace(@src()); |
| 1035 | defer tracy.end(); |
| 959 | 1036 | const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type); |
| 960 | 1037 | const new_func = try scope.arena().create(Module.Fn); |
| 961 | 1038 | new_func.* = .{ |
| ... | ... | @@ -971,16 +1048,22 @@ fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError! |
| 971 | 1048 | } |
| 972 | 1049 | |
| 973 | 1050 | fn analyzeInstIntType(mod: *Module, scope: *Scope, inttype: *zir.Inst.IntType) InnerError!*Inst { |
| 1051 | const tracy = trace(@src()); |
| 1052 | defer tracy.end(); |
| 974 | 1053 | return mod.fail(scope, inttype.base.src, "TODO implement inttype", .{}); |
| 975 | 1054 | } |
| 976 | 1055 | |
| 977 | 1056 | fn analyzeInstOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp) InnerError!*Inst { |
| 1057 | const tracy = trace(@src()); |
| 1058 | defer tracy.end(); |
| 978 | 1059 | const child_type = try resolveType(mod, scope, optional.positionals.operand); |
| 979 | 1060 | |
| 980 | 1061 | return mod.constType(scope, optional.base.src, try mod.optionalType(scope, child_type)); |
| 981 | 1062 | } |
| 982 | 1063 | |
| 983 | 1064 | fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) InnerError!*Inst { |
| 1065 | const tracy = trace(@src()); |
| 1066 | defer tracy.end(); |
| 984 | 1067 | // TODO these should be lazily evaluated |
| 985 | 1068 | const len = try resolveInstConst(mod, scope, array.positionals.lhs); |
| 986 | 1069 | const elem_type = try resolveType(mod, scope, array.positionals.rhs); |
| ... | ... | @@ -989,6 +1072,8 @@ fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) Inn |
| 989 | 1072 | } |
| 990 | 1073 | |
| 991 | 1074 | fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.ArrayTypeSentinel) InnerError!*Inst { |
| 1075 | const tracy = trace(@src()); |
| 1076 | defer tracy.end(); |
| 992 | 1077 | // TODO these should be lazily evaluated |
| 993 | 1078 | const len = try resolveInstConst(mod, scope, array.positionals.len); |
| 994 | 1079 | const sentinel = try resolveInstConst(mod, scope, array.positionals.sentinel); |
| ... | ... | @@ -998,6 +1083,8 @@ fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.Ar |
| 998 | 1083 | } |
| 999 | 1084 | |
| 1000 | 1085 | fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1086 | const tracy = trace(@src()); |
| 1087 | defer tracy.end(); |
| 1001 | 1088 | const error_union = try resolveType(mod, scope, inst.positionals.lhs); |
| 1002 | 1089 | const payload = try resolveType(mod, scope, inst.positionals.rhs); |
| 1003 | 1090 | |
| ... | ... | @@ -1009,12 +1096,16 @@ fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) |
| 1009 | 1096 | } |
| 1010 | 1097 | |
| 1011 | 1098 | fn analyzeInstAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 1099 | const tracy = trace(@src()); |
| 1100 | defer tracy.end(); |
| 1012 | 1101 | const return_type = try resolveType(mod, scope, inst.positionals.operand); |
| 1013 | 1102 | |
| 1014 | 1103 | return mod.constType(scope, inst.base.src, try mod.anyframeType(scope, return_type)); |
| 1015 | 1104 | } |
| 1016 | 1105 | |
| 1017 | 1106 | fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError!*Inst { |
| 1107 | const tracy = trace(@src()); |
| 1108 | defer tracy.end(); |
| 1018 | 1109 | // The declarations arena will store the hashmap. |
| 1019 | 1110 | var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa); |
| 1020 | 1111 | errdefer new_decl_arena.deinit(); |
| ... | ... | @@ -1045,10 +1136,14 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In |
| 1045 | 1136 | } |
| 1046 | 1137 | |
| 1047 | 1138 | fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1139 | const tracy = trace(@src()); |
| 1140 | defer tracy.end(); |
| 1048 | 1141 | return mod.fail(scope, inst.base.src, "TODO implement merge_error_sets", .{}); |
| 1049 | 1142 | } |
| 1050 | 1143 | |
| 1051 | 1144 | fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst { |
| 1145 | const tracy = trace(@src()); |
| 1146 | defer tracy.end(); |
| 1052 | 1147 | const duped_name = try scope.arena().dupe(u8, inst.positionals.name); |
| 1053 | 1148 | return mod.constInst(scope, inst.base.src, .{ |
| 1054 | 1149 | .ty = Type.initTag(.enum_literal), |
| ... | ... | @@ -1057,6 +1152,8 @@ fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiter |
| 1057 | 1152 | } |
| 1058 | 1153 | |
| 1059 | 1154 | fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst { |
| 1155 | const tracy = trace(@src()); |
| 1156 | defer tracy.end(); |
| 1060 | 1157 | const operand = try resolveInst(mod, scope, unwrap.positionals.operand); |
| 1061 | 1158 | assert(operand.ty.zigTypeTag() == .Pointer); |
| 1062 | 1159 | |
| ... | ... | @@ -1087,18 +1184,26 @@ fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp |
| 1087 | 1184 | } |
| 1088 | 1185 | |
| 1089 | 1186 | fn analyzeInstUnwrapErr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst { |
| 1187 | const tracy = trace(@src()); |
| 1188 | defer tracy.end(); |
| 1090 | 1189 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErr", .{}); |
| 1091 | 1190 | } |
| 1092 | 1191 | |
| 1093 | 1192 | fn analyzeInstUnwrapErrCode(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst { |
| 1193 | const tracy = trace(@src()); |
| 1194 | defer tracy.end(); |
| 1094 | 1195 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErrCode", .{}); |
| 1095 | 1196 | } |
| 1096 | 1197 | |
| 1097 | 1198 | fn analyzeInstEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst { |
| 1199 | const tracy = trace(@src()); |
| 1200 | defer tracy.end(); |
| 1098 | 1201 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstEnsureErrPayloadVoid", .{}); |
| 1099 | 1202 | } |
| 1100 | 1203 | |
| 1101 | 1204 | fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst { |
| 1205 | const tracy = trace(@src()); |
| 1206 | defer tracy.end(); |
| 1102 | 1207 | const return_type = try resolveType(mod, scope, fntype.positionals.return_type); |
| 1103 | 1208 | |
| 1104 | 1209 | // Hot path for some common function types. |
| ... | ... | @@ -1140,16 +1245,22 @@ fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) Inne |
| 1140 | 1245 | } |
| 1141 | 1246 | |
| 1142 | 1247 | fn analyzeInstPrimitive(mod: *Module, scope: *Scope, primitive: *zir.Inst.Primitive) InnerError!*Inst { |
| 1248 | const tracy = trace(@src()); |
| 1249 | defer tracy.end(); |
| 1143 | 1250 | return mod.constInst(scope, primitive.base.src, primitive.positionals.tag.toTypedValue()); |
| 1144 | 1251 | } |
| 1145 | 1252 | |
| 1146 | 1253 | fn analyzeInstAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*Inst { |
| 1254 | const tracy = trace(@src()); |
| 1255 | defer tracy.end(); |
| 1147 | 1256 | const dest_type = try resolveType(mod, scope, as.positionals.lhs); |
| 1148 | 1257 | const new_inst = try resolveInst(mod, scope, as.positionals.rhs); |
| 1149 | 1258 | return mod.coerce(scope, dest_type, new_inst); |
| 1150 | 1259 | } |
| 1151 | 1260 | |
| 1152 | 1261 | fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) InnerError!*Inst { |
| 1262 | const tracy = trace(@src()); |
| 1263 | defer tracy.end(); |
| 1153 | 1264 | const ptr = try resolveInst(mod, scope, ptrtoint.positionals.operand); |
| 1154 | 1265 | if (ptr.ty.zigTypeTag() != .Pointer) { |
| 1155 | 1266 | return mod.fail(scope, ptrtoint.positionals.operand.src, "expected pointer, found '{}'", .{ptr.ty}); |
| ... | ... | @@ -1161,6 +1272,8 @@ fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) In |
| 1161 | 1272 | } |
| 1162 | 1273 | |
| 1163 | 1274 | fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr) InnerError!*Inst { |
| 1275 | const tracy = trace(@src()); |
| 1276 | defer tracy.end(); |
| 1164 | 1277 | const object_ptr = try resolveInst(mod, scope, fieldptr.positionals.object_ptr); |
| 1165 | 1278 | const field_name = try resolveConstString(mod, scope, fieldptr.positionals.field_name); |
| 1166 | 1279 | |
| ... | ... | @@ -1263,6 +1376,8 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr |
| 1263 | 1376 | } |
| 1264 | 1377 | |
| 1265 | 1378 | fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1379 | const tracy = trace(@src()); |
| 1380 | defer tracy.end(); |
| 1266 | 1381 | const dest_type = try resolveType(mod, scope, inst.positionals.lhs); |
| 1267 | 1382 | const operand = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1268 | 1383 | |
| ... | ... | @@ -1299,12 +1414,16 @@ fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE |
| 1299 | 1414 | } |
| 1300 | 1415 | |
| 1301 | 1416 | fn analyzeInstBitCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1417 | const tracy = trace(@src()); |
| 1418 | defer tracy.end(); |
| 1302 | 1419 | const dest_type = try resolveType(mod, scope, inst.positionals.lhs); |
| 1303 | 1420 | const operand = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1304 | 1421 | return mod.bitcast(scope, dest_type, operand); |
| 1305 | 1422 | } |
| 1306 | 1423 | |
| 1307 | 1424 | fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1425 | const tracy = trace(@src()); |
| 1426 | defer tracy.end(); |
| 1308 | 1427 | const dest_type = try resolveType(mod, scope, inst.positionals.lhs); |
| 1309 | 1428 | const operand = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1310 | 1429 | |
| ... | ... | @@ -1341,6 +1460,8 @@ fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inne |
| 1341 | 1460 | } |
| 1342 | 1461 | |
| 1343 | 1462 | fn analyzeInstElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.ElemPtr) InnerError!*Inst { |
| 1463 | const tracy = trace(@src()); |
| 1464 | defer tracy.end(); |
| 1344 | 1465 | const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr); |
| 1345 | 1466 | const uncasted_index = try resolveInst(mod, scope, inst.positionals.index); |
| 1346 | 1467 | const elem_index = try mod.coerce(scope, Type.initTag(.usize), uncasted_index); |
| ... | ... | @@ -1377,6 +1498,8 @@ fn analyzeInstElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.ElemPtr) Inne |
| 1377 | 1498 | } |
| 1378 | 1499 | |
| 1379 | 1500 | fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerError!*Inst { |
| 1501 | const tracy = trace(@src()); |
| 1502 | defer tracy.end(); |
| 1380 | 1503 | const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr); |
| 1381 | 1504 | const start = try resolveInst(mod, scope, inst.positionals.start); |
| 1382 | 1505 | const end = if (inst.kw_args.end) |end| try resolveInst(mod, scope, end) else null; |
| ... | ... | @@ -1386,6 +1509,8 @@ fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerErr |
| 1386 | 1509 | } |
| 1387 | 1510 | |
| 1388 | 1511 | fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1512 | const tracy = trace(@src()); |
| 1513 | defer tracy.end(); |
| 1389 | 1514 | const array_ptr = try resolveInst(mod, scope, inst.positionals.lhs); |
| 1390 | 1515 | const start = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1391 | 1516 | |
| ... | ... | @@ -1393,6 +1518,8 @@ fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn |
| 1393 | 1518 | } |
| 1394 | 1519 | |
| 1395 | 1520 | fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1521 | const tracy = trace(@src()); |
| 1522 | defer tracy.end(); |
| 1396 | 1523 | const start = try resolveInst(mod, scope, inst.positionals.lhs); |
| 1397 | 1524 | const end = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1398 | 1525 | |
| ... | ... | @@ -1415,6 +1542,8 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In |
| 1415 | 1542 | } |
| 1416 | 1543 | |
| 1417 | 1544 | fn analyzeInstSwitchBr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr) InnerError!*Inst { |
| 1545 | const tracy = trace(@src()); |
| 1546 | defer tracy.end(); |
| 1418 | 1547 | const target_ptr = try resolveInst(mod, scope, inst.positionals.target_ptr); |
| 1419 | 1548 | const target = try mod.analyzeDeref(scope, inst.base.src, target_ptr, inst.positionals.target_ptr.src); |
| 1420 | 1549 | try validateSwitch(mod, scope, target, inst); |
| ... | ... | @@ -1616,6 +1745,8 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw |
| 1616 | 1745 | } |
| 1617 | 1746 | |
| 1618 | 1747 | fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 1748 | const tracy = trace(@src()); |
| 1749 | defer tracy.end(); |
| 1619 | 1750 | const operand = try resolveConstString(mod, scope, inst.positionals.operand); |
| 1620 | 1751 | |
| 1621 | 1752 | const file_scope = mod.analyzeImport(scope, inst.base.src, operand) catch |err| switch (err) { |
| ... | ... | @@ -1634,10 +1765,14 @@ fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErr |
| 1634 | 1765 | } |
| 1635 | 1766 | |
| 1636 | 1767 | fn analyzeInstShl(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1768 | const tracy = trace(@src()); |
| 1769 | defer tracy.end(); |
| 1637 | 1770 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShl", .{}); |
| 1638 | 1771 | } |
| 1639 | 1772 | |
| 1640 | 1773 | fn analyzeInstShr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1774 | const tracy = trace(@src()); |
| 1775 | defer tracy.end(); |
| 1641 | 1776 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShr", .{}); |
| 1642 | 1777 | } |
| 1643 | 1778 | |
| ... | ... | @@ -1705,14 +1840,20 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE |
| 1705 | 1840 | } |
| 1706 | 1841 | |
| 1707 | 1842 | fn analyzeInstBitNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 1843 | const tracy = trace(@src()); |
| 1844 | defer tracy.end(); |
| 1708 | 1845 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitNot", .{}); |
| 1709 | 1846 | } |
| 1710 | 1847 | |
| 1711 | 1848 | fn analyzeInstArrayCat(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1849 | const tracy = trace(@src()); |
| 1850 | defer tracy.end(); |
| 1712 | 1851 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayCat", .{}); |
| 1713 | 1852 | } |
| 1714 | 1853 | |
| 1715 | 1854 | fn analyzeInstArrayMul(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1855 | const tracy = trace(@src()); |
| 1856 | defer tracy.end(); |
| 1716 | 1857 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayMul", .{}); |
| 1717 | 1858 | } |
| 1718 | 1859 | |
| ... | ... | @@ -1818,11 +1959,15 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir |
| 1818 | 1959 | } |
| 1819 | 1960 | |
| 1820 | 1961 | fn analyzeInstDeref(mod: *Module, scope: *Scope, deref: *zir.Inst.UnOp) InnerError!*Inst { |
| 1962 | const tracy = trace(@src()); |
| 1963 | defer tracy.end(); |
| 1821 | 1964 | const ptr = try resolveInst(mod, scope, deref.positionals.operand); |
| 1822 | 1965 | return mod.analyzeDeref(scope, deref.base.src, ptr, deref.positionals.operand.src); |
| 1823 | 1966 | } |
| 1824 | 1967 | |
| 1825 | 1968 | fn analyzeInstAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerError!*Inst { |
| 1969 | const tracy = trace(@src()); |
| 1970 | defer tracy.end(); |
| 1826 | 1971 | const return_type = try resolveType(mod, scope, assembly.positionals.return_type); |
| 1827 | 1972 | const asm_source = try resolveConstString(mod, scope, assembly.positionals.asm_source); |
| 1828 | 1973 | const output = if (assembly.kw_args.output) |o| try resolveConstString(mod, scope, o) else null; |
| ... | ... | @@ -1867,6 +2012,8 @@ fn analyzeInstCmp( |
| 1867 | 2012 | inst: *zir.Inst.BinOp, |
| 1868 | 2013 | op: std.math.CompareOperator, |
| 1869 | 2014 | ) InnerError!*Inst { |
| 2015 | const tracy = trace(@src()); |
| 2016 | defer tracy.end(); |
| 1870 | 2017 | const lhs = try resolveInst(mod, scope, inst.positionals.lhs); |
| 1871 | 2018 | const rhs = try resolveInst(mod, scope, inst.positionals.rhs); |
| 1872 | 2019 | |
| ... | ... | @@ -1918,11 +2065,15 @@ fn analyzeInstCmp( |
| 1918 | 2065 | } |
| 1919 | 2066 | |
| 1920 | 2067 | fn analyzeInstTypeOf(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 2068 | const tracy = trace(@src()); |
| 2069 | defer tracy.end(); |
| 1921 | 2070 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 1922 | 2071 | return mod.constType(scope, inst.base.src, operand.ty); |
| 1923 | 2072 | } |
| 1924 | 2073 | |
| 1925 | 2074 | fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer) InnerError!*Inst { |
| 2075 | const tracy = trace(@src()); |
| 2076 | defer tracy.end(); |
| 1926 | 2077 | var insts_to_res = try mod.gpa.alloc(*ir.Inst, inst.positionals.items.len); |
| 1927 | 2078 | defer mod.gpa.free(insts_to_res); |
| 1928 | 2079 | for (inst.positionals.items) |item, i| { |
| ... | ... | @@ -1933,6 +2084,8 @@ fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer |
| 1933 | 2084 | } |
| 1934 | 2085 | |
| 1935 | 2086 | fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 2087 | const tracy = trace(@src()); |
| 2088 | defer tracy.end(); |
| 1936 | 2089 | const uncasted_operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 1937 | 2090 | const bool_type = Type.initTag(.bool); |
| 1938 | 2091 | const operand = try mod.coerce(scope, bool_type, uncasted_operand); |
| ... | ... | @@ -1944,6 +2097,8 @@ fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerEr |
| 1944 | 2097 | } |
| 1945 | 2098 | |
| 1946 | 2099 | fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 2100 | const tracy = trace(@src()); |
| 2101 | defer tracy.end(); |
| 1947 | 2102 | const bool_type = Type.initTag(.bool); |
| 1948 | 2103 | const uncasted_lhs = try resolveInst(mod, scope, inst.positionals.lhs); |
| 1949 | 2104 | const lhs = try mod.coerce(scope, bool_type, uncasted_lhs); |
| ... | ... | @@ -1966,16 +2121,22 @@ fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerEr |
| 1966 | 2121 | } |
| 1967 | 2122 | |
| 1968 | 2123 | fn analyzeInstIsNonNull(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst { |
| 2124 | const tracy = trace(@src()); |
| 2125 | defer tracy.end(); |
| 1969 | 2126 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 1970 | 2127 | return mod.analyzeIsNull(scope, inst.base.src, operand, invert_logic); |
| 1971 | 2128 | } |
| 1972 | 2129 | |
| 1973 | 2130 | fn analyzeInstIsErr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 2131 | const tracy = trace(@src()); |
| 2132 | defer tracy.end(); |
| 1974 | 2133 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 1975 | 2134 | return mod.analyzeIsErr(scope, inst.base.src, operand); |
| 1976 | 2135 | } |
| 1977 | 2136 | |
| 1978 | 2137 | fn analyzeInstCondBr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerError!*Inst { |
| 2138 | const tracy = trace(@src()); |
| 2139 | defer tracy.end(); |
| 1979 | 2140 | const uncasted_cond = try resolveInst(mod, scope, inst.positionals.condition); |
| 1980 | 2141 | const cond = try mod.coerce(scope, Type.initTag(.bool), uncasted_cond); |
| 1981 | 2142 | |
| ... | ... | @@ -2026,6 +2187,8 @@ fn analyzeInstUnreachable( |
| 2026 | 2187 | unreach: *zir.Inst.NoOp, |
| 2027 | 2188 | safety_check: bool, |
| 2028 | 2189 | ) InnerError!*Inst { |
| 2190 | const tracy = trace(@src()); |
| 2191 | defer tracy.end(); |
| 2029 | 2192 | const b = try mod.requireRuntimeBlock(scope, unreach.base.src); |
| 2030 | 2193 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 2031 | 2194 | if (safety_check and mod.wantSafety(scope)) { |
| ... | ... | @@ -2036,6 +2199,8 @@ fn analyzeInstUnreachable( |
| 2036 | 2199 | } |
| 2037 | 2200 | |
| 2038 | 2201 | fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 2202 | const tracy = trace(@src()); |
| 2203 | defer tracy.end(); |
| 2039 | 2204 | const operand = try resolveInst(mod, scope, inst.positionals.operand); |
| 2040 | 2205 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 2041 | 2206 | |
| ... | ... | @@ -2049,6 +2214,8 @@ fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError! |
| 2049 | 2214 | } |
| 2050 | 2215 | |
| 2051 | 2216 | fn analyzeInstRetVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { |
| 2217 | const tracy = trace(@src()); |
| 2218 | defer tracy.end(); |
| 2052 | 2219 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 2053 | 2220 | if (b.inlining) |inlining| { |
| 2054 | 2221 | // We are inlining a function call; rewrite the `retvoid` as a `breakvoid`. |
| ... | ... | @@ -2109,12 +2276,16 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr |
| 2109 | 2276 | } |
| 2110 | 2277 | |
| 2111 | 2278 | fn analyzeInstSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*Inst { |
| 2279 | const tracy = trace(@src()); |
| 2280 | defer tracy.end(); |
| 2112 | 2281 | const elem_type = try resolveType(mod, scope, inst.positionals.operand); |
| 2113 | 2282 | const ty = try mod.simplePtrType(scope, inst.base.src, elem_type, mutable, size); |
| 2114 | 2283 | return mod.constType(scope, inst.base.src, ty); |
| 2115 | 2284 | } |
| 2116 | 2285 | |
| 2117 | 2286 | fn analyzeInstPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.PtrType) InnerError!*Inst { |
| 2287 | const tracy = trace(@src()); |
| 2288 | defer tracy.end(); |
| 2118 | 2289 | // TODO lazy values |
| 2119 | 2290 | const @"align" = if (inst.kw_args.@"align") |some| |
| 2120 | 2291 | @truncate(u32, try resolveInt(mod, scope, some, Type.initTag(.u32))) |