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