authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-04 14:33:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-04 14:33:32-07:00
log462c1d8c7424547051e643648797b9097245b046
tree2cab87d6fb17683fb0e6dac631e09bd5a773779a
parentfc38b42521027b2ddcba688ba07bd2f6eb2737bc

stage2: add more perf tracing points


1 files changed, 182 insertions(+), 11 deletions(-)

src/zir_sema.zig+182-11
......@@ -83,10 +83,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
8383 .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?),
8484 .set_eval_branch_quota => return analyzeInstSetEvalBranchQuota(mod, scope, old_inst.castTag(.set_eval_branch_quota).?),
8585 .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).?),
9087 .inttype => return analyzeInstIntType(mod, scope, old_inst.castTag(.inttype).?),
9188 .loop => return analyzeInstLoop(mod, scope, old_inst.castTag(.loop).?),
9289 .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!
161158}
162159
163160pub fn analyzeBody(mod: *Module, block: *Scope.Block, body: zir.Module.Body) !void {
161 const tracy = trace(@src());
162 defer tracy.end();
163
164164 for (body.instructions) |src_inst| {
165165 const analyzed_inst = try analyzeInst(mod, &block.base, src_inst);
166166 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
317317}
318318
319319fn analyzeInstConst(mod: *Module, scope: *Scope, const_inst: *zir.Inst.Const) InnerError!*Inst {
320 const tracy = trace(@src());
321 defer tracy.end();
320322 // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions
321323 // after analysis.
322324 const typed_value_copy = try const_inst.positionals.typed_value.copy(scope.arena());
......@@ -336,29 +338,41 @@ fn analyzeInstCoerceResultBlockPtr(
336338 scope: *Scope,
337339 inst: *zir.Inst.CoerceResultBlockPtr,
338340) InnerError!*Inst {
341 const tracy = trace(@src());
342 defer tracy.end();
339343 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultBlockPtr", .{});
340344}
341345
342346fn analyzeInstBitCastRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
347 const tracy = trace(@src());
348 defer tracy.end();
343349 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitCastRef", .{});
344350}
345351
346352fn analyzeInstBitCastResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
353 const tracy = trace(@src());
354 defer tracy.end();
347355 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitCastResultPtr", .{});
348356}
349357
350358fn analyzeInstCoerceResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
359 const tracy = trace(@src());
360 defer tracy.end();
351361 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultPtr", .{});
352362}
353363
354364/// Equivalent to `as(ptr_child_type(typeof(ptr)), value)`.
355365fn analyzeInstCoerceToPtrElem(mod: *Module, scope: *Scope, inst: *zir.Inst.CoerceToPtrElem) InnerError!*Inst {
366 const tracy = trace(@src());
367 defer tracy.end();
356368 const ptr = try resolveInst(mod, scope, inst.positionals.ptr);
357369 const operand = try resolveInst(mod, scope, inst.positionals.value);
358370 return mod.coerce(scope, ptr.ty.elemType(), operand);
359371}
360372
361373fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
374 const tracy = trace(@src());
375 defer tracy.end();
362376 const b = try mod.requireFunctionBlock(scope, inst.base.src);
363377 const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty;
364378 const ret_type = fn_ty.fnReturnType();
......@@ -367,6 +381,8 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr
367381}
368382
369383fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
384 const tracy = trace(@src());
385 defer tracy.end();
370386 const operand = try resolveInst(mod, scope, inst.positionals.operand);
371387 const ptr_type = try mod.simplePtrType(scope, inst.base.src, operand.ty, false, .One);
372388
......@@ -382,6 +398,8 @@ fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!
382398}
383399
384400fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
401 const tracy = trace(@src());
402 defer tracy.end();
385403 const b = try mod.requireFunctionBlock(scope, inst.base.src);
386404 const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty;
387405 const ret_type = fn_ty.fnReturnType();
......@@ -389,6 +407,8 @@ fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr
389407}
390408
391409fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
410 const tracy = trace(@src());
411 defer tracy.end();
392412 const operand = try resolveInst(mod, scope, inst.positionals.operand);
393413 switch (operand.ty.zigTypeTag()) {
394414 .Void, .NoReturn => return mod.constVoid(scope, operand.src),
......@@ -397,6 +417,8 @@ fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp
397417}
398418
399419fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
420 const tracy = trace(@src());
421 defer tracy.end();
400422 const operand = try resolveInst(mod, scope, inst.positionals.operand);
401423 switch (operand.ty.zigTypeTag()) {
402424 .ErrorSet, .ErrorUnion => return mod.fail(scope, operand.src, "error is discarded", .{}),
......@@ -405,6 +427,8 @@ fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.
405427}
406428
407429fn analyzeInstEnsureIndexable(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
430 const tracy = trace(@src());
431 defer tracy.end();
408432 const operand = try resolveInst(mod, scope, inst.positionals.operand);
409433 const elem_ty = operand.ty.elemType();
410434 if (elem_ty.isIndexable()) {
......@@ -418,6 +442,8 @@ fn analyzeInstEnsureIndexable(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp)
418442}
419443
420444fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
445 const tracy = trace(@src());
446 defer tracy.end();
421447 const var_type = try resolveType(mod, scope, inst.positionals.operand);
422448 const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One);
423449 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
......@@ -425,6 +451,8 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro
425451}
426452
427453fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
454 const tracy = trace(@src());
455 defer tracy.end();
428456 const var_type = try resolveType(mod, scope, inst.positionals.operand);
429457 try mod.validateVarType(scope, inst.base.src, var_type);
430458 const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One);
......@@ -438,6 +466,8 @@ fn analyzeInstAllocInferred(
438466 inst: *zir.Inst.NoOp,
439467 mut_tag: Type.Tag,
440468) InnerError!*Inst {
469 const tracy = trace(@src());
470 defer tracy.end();
441471 const val_payload = try scope.arena().create(Value.Payload.InferredAlloc);
442472 val_payload.* = .{
443473 .data = .{},
......@@ -464,6 +494,8 @@ fn analyzeInstResolveInferredAlloc(
464494 scope: *Scope,
465495 inst: *zir.Inst.UnOp,
466496) InnerError!*Inst {
497 const tracy = trace(@src());
498 defer tracy.end();
467499 const ptr = try resolveInst(mod, scope, inst.positionals.operand);
468500 const ptr_val = ptr.castTag(.constant).?.val;
469501 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
......@@ -491,6 +523,8 @@ fn analyzeInstStoreToInferredPtr(
491523 scope: *Scope,
492524 inst: *zir.Inst.BinOp,
493525) InnerError!*Inst {
526 const tracy = trace(@src());
527 defer tracy.end();
494528 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);
495529 const value = try resolveInst(mod, scope, inst.positionals.rhs);
496530 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;
......@@ -518,12 +552,16 @@ fn analyzeInstSetEvalBranchQuota(
518552}
519553
520554fn analyzeInstStore(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
555 const tracy = trace(@src());
556 defer tracy.end();
521557 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);
522558 const value = try resolveInst(mod, scope, inst.positionals.rhs);
523559 return mod.storePtr(scope, inst.base.src, ptr, value);
524560}
525561
526562fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType) InnerError!*Inst {
563 const tracy = trace(@src());
564 defer tracy.end();
527565 const fn_inst = try resolveInst(mod, scope, inst.positionals.func);
528566 const arg_index = inst.positionals.arg_index;
529567
......@@ -553,6 +591,8 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
553591}
554592
555593fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst {
594 const tracy = trace(@src());
595 defer tracy.end();
556596 // The bytes references memory inside the ZIR module, which can get deallocated
557597 // after semantic analysis is complete. We need the memory to be in the new anonymous Decl's arena.
558598 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
566606 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);
567607}
568608
609fn 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
569616fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {
617 const tracy = trace(@src());
618 defer tracy.end();
570619 const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name);
571620 const exported_decl = mod.lookupDeclName(scope, export_inst.positionals.decl_name) orelse
572621 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)
575624}
576625
577626fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
627 const tracy = trace(@src());
628 defer tracy.end();
578629 const msg = try resolveConstString(mod, scope, inst.positionals.operand);
579630 return mod.fail(scope, inst.base.src, "{s}", .{msg});
580631}
581632
582633fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst {
634 const tracy = trace(@src());
635 defer tracy.end();
583636 const b = try mod.requireFunctionBlock(scope, inst.base.src);
584637 if (b.inlining) |inlining| {
585638 const param_index = inlining.param_index;
......@@ -601,6 +654,8 @@ fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*
601654}
602655
603656fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError!*Inst {
657 const tracy = trace(@src());
658 defer tracy.end();
604659 const parent_block = scope.cast(Scope.Block).?;
605660
606661 // 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
639694}
640695
641696fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst {
697 const tracy = trace(@src());
698 defer tracy.end();
642699 const parent_block = scope.cast(Scope.Block).?;
643700
644701 var child_block: Scope.Block = .{
......@@ -667,6 +724,8 @@ fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_c
667724}
668725
669726fn analyzeInstBlock(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst {
727 const tracy = trace(@src());
728 defer tracy.end();
670729 const parent_block = scope.cast(Scope.Block).?;
671730
672731 // Reserve space for a Block instruction so that generated Break instructions can
......@@ -717,6 +776,9 @@ fn analyzeBlockBody(
717776 child_block: *Scope.Block,
718777 merges: *Scope.Block.Merges,
719778) InnerError!*Inst {
779 const tracy = trace(@src());
780 defer tracy.end();
781
720782 const parent_block = scope.cast(Scope.Block).?;
721783
722784 // Blocks must terminate with noreturn instruction.
......@@ -755,23 +817,31 @@ fn analyzeBlockBody(
755817}
756818
757819fn analyzeInstBreakpoint(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
820 const tracy = trace(@src());
821 defer tracy.end();
758822 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
759823 return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .breakpoint);
760824}
761825
762826fn analyzeInstBreak(mod: *Module, scope: *Scope, inst: *zir.Inst.Break) InnerError!*Inst {
827 const tracy = trace(@src());
828 defer tracy.end();
763829 const operand = try resolveInst(mod, scope, inst.positionals.operand);
764830 const block = inst.positionals.block;
765831 return analyzeBreak(mod, scope, inst.base.src, block, operand);
766832}
767833
768834fn analyzeInstBreakVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) InnerError!*Inst {
835 const tracy = trace(@src());
836 defer tracy.end();
769837 const block = inst.positionals.block;
770838 const void_inst = try mod.constVoid(scope, inst.base.src);
771839 return analyzeBreak(mod, scope, inst.base.src, block, void_inst);
772840}
773841
774842fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
843 const tracy = trace(@src());
844 defer tracy.end();
775845 if (scope.cast(Scope.Block)) |b| {
776846 if (!b.is_comptime) {
777847 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
781851}
782852
783853fn analyzeInstDeclRefStr(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRefStr) InnerError!*Inst {
854 const tracy = trace(@src());
855 defer tracy.end();
784856 const decl_name = try resolveConstString(mod, scope, inst.positionals.name);
785857 return mod.analyzeDeclRefByName(scope, inst.base.src, decl_name);
786858}
787859
788860fn analyzeInstDeclRef(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRef) InnerError!*Inst {
861 const tracy = trace(@src());
862 defer tracy.end();
789863 return mod.analyzeDeclRefByName(scope, inst.base.src, inst.positionals.name);
790864}
791865
792866fn analyzeInstDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerError!*Inst {
867 const tracy = trace(@src());
868 defer tracy.end();
793869 const decl = try analyzeDeclVal(mod, scope, inst);
794870 const ptr = try mod.analyzeDeclRef(scope, inst.base.src, decl);
795871 return mod.analyzeDeref(scope, inst.base.src, ptr, inst.base.src);
796872}
797873
798874fn analyzeInstDeclValInModule(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclValInModule) InnerError!*Inst {
875 const tracy = trace(@src());
876 defer tracy.end();
799877 const decl = inst.positionals.decl;
800878 return mod.analyzeDeclRef(scope, inst.base.src, decl);
801879}
802880
803881fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {
882 const tracy = trace(@src());
883 defer tracy.end();
884
804885 const func = try resolveInst(mod, scope, inst.positionals.func);
805886 if (func.ty.zigTypeTag() != .Fn)
806887 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
9431024 // the block_inst above.
9441025 try analyzeBody(mod, &child_block, module_fn.zir);
9451026
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);
9531028 }
9541029
9551030 return mod.addCall(b, inst.base.src, ret_type, func, casted_args);
9561031}
9571032
9581033fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst {
1034 const tracy = trace(@src());
1035 defer tracy.end();
9591036 const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type);
9601037 const new_func = try scope.arena().create(Module.Fn);
9611038 new_func.* = .{
......@@ -971,16 +1048,22 @@ fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!
9711048}
9721049
9731050fn analyzeInstIntType(mod: *Module, scope: *Scope, inttype: *zir.Inst.IntType) InnerError!*Inst {
1051 const tracy = trace(@src());
1052 defer tracy.end();
9741053 return mod.fail(scope, inttype.base.src, "TODO implement inttype", .{});
9751054}
9761055
9771056fn analyzeInstOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp) InnerError!*Inst {
1057 const tracy = trace(@src());
1058 defer tracy.end();
9781059 const child_type = try resolveType(mod, scope, optional.positionals.operand);
9791060
9801061 return mod.constType(scope, optional.base.src, try mod.optionalType(scope, child_type));
9811062}
9821063
9831064fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) InnerError!*Inst {
1065 const tracy = trace(@src());
1066 defer tracy.end();
9841067 // TODO these should be lazily evaluated
9851068 const len = try resolveInstConst(mod, scope, array.positionals.lhs);
9861069 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
9891072}
9901073
9911074fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.ArrayTypeSentinel) InnerError!*Inst {
1075 const tracy = trace(@src());
1076 defer tracy.end();
9921077 // TODO these should be lazily evaluated
9931078 const len = try resolveInstConst(mod, scope, array.positionals.len);
9941079 const sentinel = try resolveInstConst(mod, scope, array.positionals.sentinel);
......@@ -998,6 +1083,8 @@ fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.Ar
9981083}
9991084
10001085fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1086 const tracy = trace(@src());
1087 defer tracy.end();
10011088 const error_union = try resolveType(mod, scope, inst.positionals.lhs);
10021089 const payload = try resolveType(mod, scope, inst.positionals.rhs);
10031090
......@@ -1009,12 +1096,16 @@ fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp)
10091096}
10101097
10111098fn analyzeInstAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1099 const tracy = trace(@src());
1100 defer tracy.end();
10121101 const return_type = try resolveType(mod, scope, inst.positionals.operand);
10131102
10141103 return mod.constType(scope, inst.base.src, try mod.anyframeType(scope, return_type));
10151104}
10161105
10171106fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError!*Inst {
1107 const tracy = trace(@src());
1108 defer tracy.end();
10181109 // The declarations arena will store the hashmap.
10191110 var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa);
10201111 errdefer new_decl_arena.deinit();
......@@ -1045,10 +1136,14 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In
10451136}
10461137
10471138fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1139 const tracy = trace(@src());
1140 defer tracy.end();
10481141 return mod.fail(scope, inst.base.src, "TODO implement merge_error_sets", .{});
10491142}
10501143
10511144fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst {
1145 const tracy = trace(@src());
1146 defer tracy.end();
10521147 const duped_name = try scope.arena().dupe(u8, inst.positionals.name);
10531148 return mod.constInst(scope, inst.base.src, .{
10541149 .ty = Type.initTag(.enum_literal),
......@@ -1057,6 +1152,8 @@ fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiter
10571152}
10581153
10591154fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {
1155 const tracy = trace(@src());
1156 defer tracy.end();
10601157 const operand = try resolveInst(mod, scope, unwrap.positionals.operand);
10611158 assert(operand.ty.zigTypeTag() == .Pointer);
10621159
......@@ -1087,18 +1184,26 @@ fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp
10871184}
10881185
10891186fn analyzeInstUnwrapErr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {
1187 const tracy = trace(@src());
1188 defer tracy.end();
10901189 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErr", .{});
10911190}
10921191
10931192fn analyzeInstUnwrapErrCode(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
1193 const tracy = trace(@src());
1194 defer tracy.end();
10941195 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErrCode", .{});
10951196}
10961197
10971198fn analyzeInstEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
1199 const tracy = trace(@src());
1200 defer tracy.end();
10981201 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstEnsureErrPayloadVoid", .{});
10991202}
11001203
11011204fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst {
1205 const tracy = trace(@src());
1206 defer tracy.end();
11021207 const return_type = try resolveType(mod, scope, fntype.positionals.return_type);
11031208
11041209 // Hot path for some common function types.
......@@ -1140,16 +1245,22 @@ fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) Inne
11401245}
11411246
11421247fn analyzeInstPrimitive(mod: *Module, scope: *Scope, primitive: *zir.Inst.Primitive) InnerError!*Inst {
1248 const tracy = trace(@src());
1249 defer tracy.end();
11431250 return mod.constInst(scope, primitive.base.src, primitive.positionals.tag.toTypedValue());
11441251}
11451252
11461253fn analyzeInstAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*Inst {
1254 const tracy = trace(@src());
1255 defer tracy.end();
11471256 const dest_type = try resolveType(mod, scope, as.positionals.lhs);
11481257 const new_inst = try resolveInst(mod, scope, as.positionals.rhs);
11491258 return mod.coerce(scope, dest_type, new_inst);
11501259}
11511260
11521261fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) InnerError!*Inst {
1262 const tracy = trace(@src());
1263 defer tracy.end();
11531264 const ptr = try resolveInst(mod, scope, ptrtoint.positionals.operand);
11541265 if (ptr.ty.zigTypeTag() != .Pointer) {
11551266 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
11611272}
11621273
11631274fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr) InnerError!*Inst {
1275 const tracy = trace(@src());
1276 defer tracy.end();
11641277 const object_ptr = try resolveInst(mod, scope, fieldptr.positionals.object_ptr);
11651278 const field_name = try resolveConstString(mod, scope, fieldptr.positionals.field_name);
11661279
......@@ -1263,6 +1376,8 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr
12631376}
12641377
12651378fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1379 const tracy = trace(@src());
1380 defer tracy.end();
12661381 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
12671382 const operand = try resolveInst(mod, scope, inst.positionals.rhs);
12681383
......@@ -1299,12 +1414,16 @@ fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
12991414}
13001415
13011416fn analyzeInstBitCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1417 const tracy = trace(@src());
1418 defer tracy.end();
13021419 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
13031420 const operand = try resolveInst(mod, scope, inst.positionals.rhs);
13041421 return mod.bitcast(scope, dest_type, operand);
13051422}
13061423
13071424fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1425 const tracy = trace(@src());
1426 defer tracy.end();
13081427 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
13091428 const operand = try resolveInst(mod, scope, inst.positionals.rhs);
13101429
......@@ -1341,6 +1460,8 @@ fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inne
13411460}
13421461
13431462fn analyzeInstElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.ElemPtr) InnerError!*Inst {
1463 const tracy = trace(@src());
1464 defer tracy.end();
13441465 const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr);
13451466 const uncasted_index = try resolveInst(mod, scope, inst.positionals.index);
13461467 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
13771498}
13781499
13791500fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerError!*Inst {
1501 const tracy = trace(@src());
1502 defer tracy.end();
13801503 const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr);
13811504 const start = try resolveInst(mod, scope, inst.positionals.start);
13821505 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
13861509}
13871510
13881511fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1512 const tracy = trace(@src());
1513 defer tracy.end();
13891514 const array_ptr = try resolveInst(mod, scope, inst.positionals.lhs);
13901515 const start = try resolveInst(mod, scope, inst.positionals.rhs);
13911516
......@@ -1393,6 +1518,8 @@ fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
13931518}
13941519
13951520fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1521 const tracy = trace(@src());
1522 defer tracy.end();
13961523 const start = try resolveInst(mod, scope, inst.positionals.lhs);
13971524 const end = try resolveInst(mod, scope, inst.positionals.rhs);
13981525
......@@ -1415,6 +1542,8 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In
14151542}
14161543
14171544fn analyzeInstSwitchBr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr) InnerError!*Inst {
1545 const tracy = trace(@src());
1546 defer tracy.end();
14181547 const target_ptr = try resolveInst(mod, scope, inst.positionals.target_ptr);
14191548 const target = try mod.analyzeDeref(scope, inst.base.src, target_ptr, inst.positionals.target_ptr.src);
14201549 try validateSwitch(mod, scope, target, inst);
......@@ -1616,6 +1745,8 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
16161745}
16171746
16181747fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1748 const tracy = trace(@src());
1749 defer tracy.end();
16191750 const operand = try resolveConstString(mod, scope, inst.positionals.operand);
16201751
16211752 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
16341765}
16351766
16361767fn analyzeInstShl(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1768 const tracy = trace(@src());
1769 defer tracy.end();
16371770 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShl", .{});
16381771}
16391772
16401773fn analyzeInstShr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1774 const tracy = trace(@src());
1775 defer tracy.end();
16411776 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShr", .{});
16421777}
16431778
......@@ -1705,14 +1840,20 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
17051840}
17061841
17071842fn analyzeInstBitNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1843 const tracy = trace(@src());
1844 defer tracy.end();
17081845 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitNot", .{});
17091846}
17101847
17111848fn analyzeInstArrayCat(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1849 const tracy = trace(@src());
1850 defer tracy.end();
17121851 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayCat", .{});
17131852}
17141853
17151854fn analyzeInstArrayMul(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1855 const tracy = trace(@src());
1856 defer tracy.end();
17161857 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayMul", .{});
17171858}
17181859
......@@ -1818,11 +1959,15 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir
18181959}
18191960
18201961fn analyzeInstDeref(mod: *Module, scope: *Scope, deref: *zir.Inst.UnOp) InnerError!*Inst {
1962 const tracy = trace(@src());
1963 defer tracy.end();
18211964 const ptr = try resolveInst(mod, scope, deref.positionals.operand);
18221965 return mod.analyzeDeref(scope, deref.base.src, ptr, deref.positionals.operand.src);
18231966}
18241967
18251968fn analyzeInstAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerError!*Inst {
1969 const tracy = trace(@src());
1970 defer tracy.end();
18261971 const return_type = try resolveType(mod, scope, assembly.positionals.return_type);
18271972 const asm_source = try resolveConstString(mod, scope, assembly.positionals.asm_source);
18281973 const output = if (assembly.kw_args.output) |o| try resolveConstString(mod, scope, o) else null;
......@@ -1867,6 +2012,8 @@ fn analyzeInstCmp(
18672012 inst: *zir.Inst.BinOp,
18682013 op: std.math.CompareOperator,
18692014) InnerError!*Inst {
2015 const tracy = trace(@src());
2016 defer tracy.end();
18702017 const lhs = try resolveInst(mod, scope, inst.positionals.lhs);
18712018 const rhs = try resolveInst(mod, scope, inst.positionals.rhs);
18722019
......@@ -1918,11 +2065,15 @@ fn analyzeInstCmp(
19182065}
19192066
19202067fn analyzeInstTypeOf(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2068 const tracy = trace(@src());
2069 defer tracy.end();
19212070 const operand = try resolveInst(mod, scope, inst.positionals.operand);
19222071 return mod.constType(scope, inst.base.src, operand.ty);
19232072}
19242073
19252074fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer) InnerError!*Inst {
2075 const tracy = trace(@src());
2076 defer tracy.end();
19262077 var insts_to_res = try mod.gpa.alloc(*ir.Inst, inst.positionals.items.len);
19272078 defer mod.gpa.free(insts_to_res);
19282079 for (inst.positionals.items) |item, i| {
......@@ -1933,6 +2084,8 @@ fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer
19332084}
19342085
19352086fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2087 const tracy = trace(@src());
2088 defer tracy.end();
19362089 const uncasted_operand = try resolveInst(mod, scope, inst.positionals.operand);
19372090 const bool_type = Type.initTag(.bool);
19382091 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
19442097}
19452098
19462099fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
2100 const tracy = trace(@src());
2101 defer tracy.end();
19472102 const bool_type = Type.initTag(.bool);
19482103 const uncasted_lhs = try resolveInst(mod, scope, inst.positionals.lhs);
19492104 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
19662121}
19672122
19682123fn analyzeInstIsNonNull(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst {
2124 const tracy = trace(@src());
2125 defer tracy.end();
19692126 const operand = try resolveInst(mod, scope, inst.positionals.operand);
19702127 return mod.analyzeIsNull(scope, inst.base.src, operand, invert_logic);
19712128}
19722129
19732130fn analyzeInstIsErr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2131 const tracy = trace(@src());
2132 defer tracy.end();
19742133 const operand = try resolveInst(mod, scope, inst.positionals.operand);
19752134 return mod.analyzeIsErr(scope, inst.base.src, operand);
19762135}
19772136
19782137fn analyzeInstCondBr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerError!*Inst {
2138 const tracy = trace(@src());
2139 defer tracy.end();
19792140 const uncasted_cond = try resolveInst(mod, scope, inst.positionals.condition);
19802141 const cond = try mod.coerce(scope, Type.initTag(.bool), uncasted_cond);
19812142
......@@ -2026,6 +2187,8 @@ fn analyzeInstUnreachable(
20262187 unreach: *zir.Inst.NoOp,
20272188 safety_check: bool,
20282189) InnerError!*Inst {
2190 const tracy = trace(@src());
2191 defer tracy.end();
20292192 const b = try mod.requireRuntimeBlock(scope, unreach.base.src);
20302193 // TODO Add compile error for @optimizeFor occurring too late in a scope.
20312194 if (safety_check and mod.wantSafety(scope)) {
......@@ -2036,6 +2199,8 @@ fn analyzeInstUnreachable(
20362199}
20372200
20382201fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2202 const tracy = trace(@src());
2203 defer tracy.end();
20392204 const operand = try resolveInst(mod, scope, inst.positionals.operand);
20402205 const b = try mod.requireFunctionBlock(scope, inst.base.src);
20412206
......@@ -2049,6 +2214,8 @@ fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!
20492214}
20502215
20512216fn analyzeInstRetVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
2217 const tracy = trace(@src());
2218 defer tracy.end();
20522219 const b = try mod.requireFunctionBlock(scope, inst.base.src);
20532220 if (b.inlining) |inlining| {
20542221 // 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
21092276}
21102277
21112278fn 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();
21122281 const elem_type = try resolveType(mod, scope, inst.positionals.operand);
21132282 const ty = try mod.simplePtrType(scope, inst.base.src, elem_type, mutable, size);
21142283 return mod.constType(scope, inst.base.src, ty);
21152284}
21162285
21172286fn analyzeInstPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.PtrType) InnerError!*Inst {
2287 const tracy = trace(@src());
2288 defer tracy.end();
21182289 // TODO lazy values
21192290 const @"align" = if (inst.kw_args.@"align") |some|
21202291 @truncate(u32, try resolveInt(mod, scope, some, Type.initTag(.u32)))