authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-20 11:07:17+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-06-20 11:07:17+01:00
logf73be120f4254c080c48081dfc5834a7ebc9d9cf
treee70598bed09659eb61c230620c1ddf88c14db905
parentccd3cc3266762c1fea93cdc0190eaf71718d9e6a
parent2b677d1660018434757f9c9efec3c712675e6c47
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20299 from mlugg/the-great-decl-split

The Great Decl Split (preliminary work): refactor source locations and eliminate `Sema.Block.src_decl`.

34 files changed, 2991 insertions(+), 3346 deletions(-)

lib/std/zig.zig-373
......@@ -350,379 +350,6 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![
350350 return buffer.toOwnedSlice();
351351}
352352
353pub const DeclIndex = enum(u32) {
354 _,
355
356 pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
357 return @enumFromInt(@intFromEnum(i));
358 }
359};
360
361pub const OptionalDeclIndex = enum(u32) {
362 none = std.math.maxInt(u32),
363 _,
364
365 pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
366 return @enumFromInt(@intFromEnum(oi orelse return .none));
367 }
368
369 pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
370 if (oi == .none) return null;
371 return @enumFromInt(@intFromEnum(oi));
372 }
373};
374
375/// Resolving a source location into a byte offset may require doing work
376/// that we would rather not do unless the error actually occurs.
377/// Therefore we need a data structure that contains the information necessary
378/// to lazily produce a `SrcLoc` as required.
379/// Most of the offsets in this data structure are relative to the containing Decl.
380/// This makes the source location resolve properly even when a Decl gets
381/// shifted up or down in the file, as long as the Decl's contents itself
382/// do not change.
383pub const LazySrcLoc = union(enum) {
384 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
385 /// that all code paths which would need to resolve the source location are
386 /// unreachable. If you are debugging this tag incorrectly being this value,
387 /// look into using reverse-continue with a memory watchpoint to see where the
388 /// value is being set to this tag.
389 unneeded,
390 /// Means the source location points to an entire file; not any particular
391 /// location within the file. `file_scope` union field will be active.
392 entire_file,
393 /// The source location points to a byte offset within a source file,
394 /// offset from 0. The source file is determined contextually.
395 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
396 byte_abs: u32,
397 /// The source location points to a token within a source file,
398 /// offset from 0. The source file is determined contextually.
399 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
400 token_abs: u32,
401 /// The source location points to an AST node within a source file,
402 /// offset from 0. The source file is determined contextually.
403 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
404 node_abs: u32,
405 /// The source location points to a byte offset within a source file,
406 /// offset from the byte offset of the Decl within the file.
407 /// The Decl is determined contextually.
408 byte_offset: u32,
409 /// This data is the offset into the token list from the Decl token.
410 /// The Decl is determined contextually.
411 token_offset: u32,
412 /// The source location points to an AST node, which is this value offset
413 /// from its containing Decl node AST index.
414 /// The Decl is determined contextually.
415 node_offset: TracedOffset,
416 /// The source location points to the main token of an AST node, found
417 /// by taking this AST node index offset from the containing Decl AST node.
418 /// The Decl is determined contextually.
419 node_offset_main_token: i32,
420 /// The source location points to the beginning of a struct initializer.
421 /// The Decl is determined contextually.
422 node_offset_initializer: i32,
423 /// The source location points to a variable declaration type expression,
424 /// found by taking this AST node index offset from the containing
425 /// Decl AST node, which points to a variable declaration AST node. Next, navigate
426 /// to the type expression.
427 /// The Decl is determined contextually.
428 node_offset_var_decl_ty: i32,
429 /// The source location points to the alignment expression of a var decl.
430 /// The Decl is determined contextually.
431 node_offset_var_decl_align: i32,
432 /// The source location points to the linksection expression of a var decl.
433 /// The Decl is determined contextually.
434 node_offset_var_decl_section: i32,
435 /// The source location points to the addrspace expression of a var decl.
436 /// The Decl is determined contextually.
437 node_offset_var_decl_addrspace: i32,
438 /// The source location points to the initializer of a var decl.
439 /// The Decl is determined contextually.
440 node_offset_var_decl_init: i32,
441 /// The source location points to the first parameter of a builtin
442 /// function call, found by taking this AST node index offset from the containing
443 /// Decl AST node, which points to a builtin call AST node. Next, navigate
444 /// to the first parameter.
445 /// The Decl is determined contextually.
446 node_offset_builtin_call_arg0: i32,
447 /// Same as `node_offset_builtin_call_arg0` except arg index 1.
448 node_offset_builtin_call_arg1: i32,
449 node_offset_builtin_call_arg2: i32,
450 node_offset_builtin_call_arg3: i32,
451 node_offset_builtin_call_arg4: i32,
452 node_offset_builtin_call_arg5: i32,
453 /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls
454 /// to pointer cast builtins.
455 node_offset_ptrcast_operand: i32,
456 /// The source location points to the index expression of an array access
457 /// expression, found by taking this AST node index offset from the containing
458 /// Decl AST node, which points to an array access AST node. Next, navigate
459 /// to the index expression.
460 /// The Decl is determined contextually.
461 node_offset_array_access_index: i32,
462 /// The source location points to the LHS of a slice expression
463 /// expression, found by taking this AST node index offset from the containing
464 /// Decl AST node, which points to a slice AST node. Next, navigate
465 /// to the sentinel expression.
466 /// The Decl is determined contextually.
467 node_offset_slice_ptr: i32,
468 /// The source location points to start expression of a slice expression
469 /// expression, found by taking this AST node index offset from the containing
470 /// Decl AST node, which points to a slice AST node. Next, navigate
471 /// to the sentinel expression.
472 /// The Decl is determined contextually.
473 node_offset_slice_start: i32,
474 /// The source location points to the end expression of a slice
475 /// expression, found by taking this AST node index offset from the containing
476 /// Decl AST node, which points to a slice AST node. Next, navigate
477 /// to the sentinel expression.
478 /// The Decl is determined contextually.
479 node_offset_slice_end: i32,
480 /// The source location points to the sentinel expression of a slice
481 /// expression, found by taking this AST node index offset from the containing
482 /// Decl AST node, which points to a slice AST node. Next, navigate
483 /// to the sentinel expression.
484 /// The Decl is determined contextually.
485 node_offset_slice_sentinel: i32,
486 /// The source location points to the callee expression of a function
487 /// call expression, found by taking this AST node index offset from the containing
488 /// Decl AST node, which points to a function call AST node. Next, navigate
489 /// to the callee expression.
490 /// The Decl is determined contextually.
491 node_offset_call_func: i32,
492 /// The payload is offset from the containing Decl AST node.
493 /// The source location points to the field name of:
494 /// * a field access expression (`a.b`), or
495 /// * the callee of a method call (`a.b()`)
496 /// The Decl is determined contextually.
497 node_offset_field_name: i32,
498 /// The payload is offset from the containing Decl AST node.
499 /// The source location points to the field name of the operand ("b" node)
500 /// of a field initialization expression (`.a = b`)
501 /// The Decl is determined contextually.
502 node_offset_field_name_init: i32,
503 /// The source location points to the pointer of a pointer deref expression,
504 /// found by taking this AST node index offset from the containing
505 /// Decl AST node, which points to a pointer deref AST node. Next, navigate
506 /// to the pointer expression.
507 /// The Decl is determined contextually.
508 node_offset_deref_ptr: i32,
509 /// The source location points to the assembly source code of an inline assembly
510 /// expression, found by taking this AST node index offset from the containing
511 /// Decl AST node, which points to inline assembly AST node. Next, navigate
512 /// to the asm template source code.
513 /// The Decl is determined contextually.
514 node_offset_asm_source: i32,
515 /// The source location points to the return type of an inline assembly
516 /// expression, found by taking this AST node index offset from the containing
517 /// Decl AST node, which points to inline assembly AST node. Next, navigate
518 /// to the return type expression.
519 /// The Decl is determined contextually.
520 node_offset_asm_ret_ty: i32,
521 /// The source location points to the condition expression of an if
522 /// expression, found by taking this AST node index offset from the containing
523 /// Decl AST node, which points to an if expression AST node. Next, navigate
524 /// to the condition expression.
525 /// The Decl is determined contextually.
526 node_offset_if_cond: i32,
527 /// The source location points to a binary expression, such as `a + b`, found
528 /// by taking this AST node index offset from the containing Decl AST node.
529 /// The Decl is determined contextually.
530 node_offset_bin_op: i32,
531 /// The source location points to the LHS of a binary expression, found
532 /// by taking this AST node index offset from the containing Decl AST node,
533 /// which points to a binary expression AST node. Next, navigate to the LHS.
534 /// The Decl is determined contextually.
535 node_offset_bin_lhs: i32,
536 /// The source location points to the RHS of a binary expression, found
537 /// by taking this AST node index offset from the containing Decl AST node,
538 /// which points to a binary expression AST node. Next, navigate to the RHS.
539 /// The Decl is determined contextually.
540 node_offset_bin_rhs: i32,
541 /// The source location points to the operand of a switch expression, found
542 /// by taking this AST node index offset from the containing Decl AST node,
543 /// which points to a switch expression AST node. Next, navigate to the operand.
544 /// The Decl is determined contextually.
545 node_offset_switch_operand: i32,
546 /// The source location points to the else/`_` prong of a switch expression, found
547 /// by taking this AST node index offset from the containing Decl AST node,
548 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
549 /// The Decl is determined contextually.
550 node_offset_switch_special_prong: i32,
551 /// The source location points to all the ranges of a switch expression, found
552 /// by taking this AST node index offset from the containing Decl AST node,
553 /// which points to a switch expression AST node. Next, navigate to any of the
554 /// range nodes. The error applies to all of them.
555 /// The Decl is determined contextually.
556 node_offset_switch_range: i32,
557 /// The source location points to the capture of a switch_prong.
558 /// The Decl is determined contextually.
559 node_offset_switch_prong_capture: i32,
560 /// The source location points to the tag capture of a switch_prong.
561 /// The Decl is determined contextually.
562 node_offset_switch_prong_tag_capture: i32,
563 /// The source location points to the align expr of a function type
564 /// expression, found by taking this AST node index offset from the containing
565 /// Decl AST node, which points to a function type AST node. Next, navigate to
566 /// the calling convention node.
567 /// The Decl is determined contextually.
568 node_offset_fn_type_align: i32,
569 /// The source location points to the addrspace expr of a function type
570 /// expression, found by taking this AST node index offset from the containing
571 /// Decl AST node, which points to a function type AST node. Next, navigate to
572 /// the calling convention node.
573 /// The Decl is determined contextually.
574 node_offset_fn_type_addrspace: i32,
575 /// The source location points to the linksection expr of a function type
576 /// expression, found by taking this AST node index offset from the containing
577 /// Decl AST node, which points to a function type AST node. Next, navigate to
578 /// the calling convention node.
579 /// The Decl is determined contextually.
580 node_offset_fn_type_section: i32,
581 /// The source location points to the calling convention of a function type
582 /// expression, found by taking this AST node index offset from the containing
583 /// Decl AST node, which points to a function type AST node. Next, navigate to
584 /// the calling convention node.
585 /// The Decl is determined contextually.
586 node_offset_fn_type_cc: i32,
587 /// The source location points to the return type of a function type
588 /// expression, found by taking this AST node index offset from the containing
589 /// Decl AST node, which points to a function type AST node. Next, navigate to
590 /// the return type node.
591 /// The Decl is determined contextually.
592 node_offset_fn_type_ret_ty: i32,
593 node_offset_param: i32,
594 token_offset_param: i32,
595 /// The source location points to the type expression of an `anyframe->T`
596 /// expression, found by taking this AST node index offset from the containing
597 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
598 /// to the type expression.
599 /// The Decl is determined contextually.
600 node_offset_anyframe_type: i32,
601 /// The source location points to the string literal of `extern "foo"`, found
602 /// by taking this AST node index offset from the containing
603 /// Decl AST node, which points to a function prototype or variable declaration
604 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
605 /// The Decl is determined contextually.
606 node_offset_lib_name: i32,
607 /// The source location points to the len expression of an `[N:S]T`
608 /// expression, found by taking this AST node index offset from the containing
609 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
610 /// to the len expression.
611 /// The Decl is determined contextually.
612 node_offset_array_type_len: i32,
613 /// The source location points to the sentinel expression of an `[N:S]T`
614 /// expression, found by taking this AST node index offset from the containing
615 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
616 /// to the sentinel expression.
617 /// The Decl is determined contextually.
618 node_offset_array_type_sentinel: i32,
619 /// The source location points to the elem expression of an `[N:S]T`
620 /// expression, found by taking this AST node index offset from the containing
621 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
622 /// to the elem expression.
623 /// The Decl is determined contextually.
624 node_offset_array_type_elem: i32,
625 /// The source location points to the operand of an unary expression.
626 /// The Decl is determined contextually.
627 node_offset_un_op: i32,
628 /// The source location points to the elem type of a pointer.
629 /// The Decl is determined contextually.
630 node_offset_ptr_elem: i32,
631 /// The source location points to the sentinel of a pointer.
632 /// The Decl is determined contextually.
633 node_offset_ptr_sentinel: i32,
634 /// The source location points to the align expr of a pointer.
635 /// The Decl is determined contextually.
636 node_offset_ptr_align: i32,
637 /// The source location points to the addrspace expr of a pointer.
638 /// The Decl is determined contextually.
639 node_offset_ptr_addrspace: i32,
640 /// The source location points to the bit-offset of a pointer.
641 /// The Decl is determined contextually.
642 node_offset_ptr_bitoffset: i32,
643 /// The source location points to the host size of a pointer.
644 /// The Decl is determined contextually.
645 node_offset_ptr_hostsize: i32,
646 /// The source location points to the tag type of an union or an enum.
647 /// The Decl is determined contextually.
648 node_offset_container_tag: i32,
649 /// The source location points to the default value of a field.
650 /// The Decl is determined contextually.
651 node_offset_field_default: i32,
652 /// The source location points to the type of an array or struct initializer.
653 /// The Decl is determined contextually.
654 node_offset_init_ty: i32,
655 /// The source location points to the LHS of an assignment.
656 /// The Decl is determined contextually.
657 node_offset_store_ptr: i32,
658 /// The source location points to the RHS of an assignment.
659 /// The Decl is determined contextually.
660 node_offset_store_operand: i32,
661 /// The source location points to the operand of a `return` statement, or
662 /// the `return` itself if there is no explicit operand.
663 /// The Decl is determined contextually.
664 node_offset_return_operand: i32,
665 /// The source location points to a for loop input.
666 /// The Decl is determined contextually.
667 for_input: struct {
668 /// Points to the for loop AST node.
669 for_node_offset: i32,
670 /// Picks one of the inputs from the condition.
671 input_index: u32,
672 },
673 /// The source location points to one of the captures of a for loop, found
674 /// by taking this AST node index offset from the containing
675 /// Decl AST node, which points to one of the input nodes of a for loop.
676 /// Next, navigate to the corresponding capture.
677 /// The Decl is determined contextually.
678 for_capture_from_input: i32,
679 /// The source location points to the argument node of a function call.
680 call_arg: struct {
681 decl: DeclIndex,
682 /// Points to the function call AST node.
683 call_node_offset: i32,
684 /// The index of the argument the source location points to.
685 arg_index: u32,
686 },
687 fn_proto_param: struct {
688 decl: DeclIndex,
689 /// Points to the function prototype AST node.
690 fn_proto_node_offset: i32,
691 /// The index of the parameter the source location points to.
692 param_index: u32,
693 },
694 array_cat_lhs: ArrayCat,
695 array_cat_rhs: ArrayCat,
696
697 const ArrayCat = struct {
698 /// Points to the array concat AST node.
699 array_cat_offset: i32,
700 /// The index of the element the source location points to.
701 elem_index: u32,
702 };
703
704 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
705
706 noinline fn nodeOffsetDebug(node_offset: i32) LazySrcLoc {
707 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
708 result.node_offset.trace.addAddr(@returnAddress(), "init");
709 return result;
710 }
711
712 fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {
713 return .{ .node_offset = .{ .x = node_offset } };
714 }
715
716 /// This wraps a simple integer in debug builds so that later on we can find out
717 /// where in semantic analysis the value got set.
718 pub const TracedOffset = struct {
719 x: i32,
720 trace: std.debug.Trace = std.debug.Trace.init,
721
722 const want_tracing = false;
723 };
724};
725
726353const std = @import("std.zig");
727354const tokenizer = @import("zig/tokenizer.zig");
728355const assert = std.debug.assert;
lib/std/zig/AstGen.zig+32-12
......@@ -4011,7 +4011,7 @@ fn fnDecl(
40114011
40124012 // We insert this at the beginning so that its instruction index marks the
40134013 // start of the top level declaration.
4014 const decl_inst = try gz.makeBlockInst(.declaration, fn_proto.ast.proto_node);
4014 const decl_inst = try gz.makeDeclaration(fn_proto.ast.proto_node);
40154015 astgen.advanceSourceCursorToNode(decl_node);
40164016
40174017 var decl_gz: GenZir = .{
......@@ -4393,7 +4393,7 @@ fn globalVarDecl(
43934393 const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;
43944394 // We do this at the beginning so that the instruction index marks the range start
43954395 // of the top level declaration.
4396 const decl_inst = try gz.makeBlockInst(.declaration, node);
4396 const decl_inst = try gz.makeDeclaration(node);
43974397
43984398 const name_token = var_decl.ast.mut_token + 1;
43994399 astgen.advanceSourceCursorToNode(node);
......@@ -4555,7 +4555,7 @@ fn comptimeDecl(
45554555
45564556 // Up top so the ZIR instruction index marks the start range of this
45574557 // top-level declaration.
4558 const decl_inst = try gz.makeBlockInst(.declaration, node);
4558 const decl_inst = try gz.makeDeclaration(node);
45594559 wip_members.nextDecl(decl_inst);
45604560 astgen.advanceSourceCursorToNode(node);
45614561
......@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(
46074607 };
46084608 // Up top so the ZIR instruction index marks the start range of this
46094609 // top-level declaration.
4610 const decl_inst = try gz.makeBlockInst(.declaration, node);
4610 const decl_inst = try gz.makeDeclaration(node);
46114611 wip_members.nextDecl(decl_inst);
46124612 astgen.advanceSourceCursorToNode(node);
46134613
......@@ -4651,7 +4651,7 @@ fn testDecl(
46514651
46524652 // Up top so the ZIR instruction index marks the start range of this
46534653 // top-level declaration.
4654 const decl_inst = try gz.makeBlockInst(.declaration, node);
4654 const decl_inst = try gz.makeDeclaration(node);
46554655
46564656 wip_members.nextDecl(decl_inst);
46574657 astgen.advanceSourceCursorToNode(node);
......@@ -9366,9 +9366,10 @@ fn builtinCall(
93669366 try gz.instructions.ensureUnusedCapacity(gpa, 1);
93679367 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
93689368
9369 const payload_index = try gz.astgen.addExtra(Zir.Inst.UnNode{
9370 .node = gz.nodeIndexToRelative(node),
9369 const payload_index = try gz.astgen.addExtra(Zir.Inst.Reify{
9370 .node = node, // Absolute node index -- see the definition of `Reify`.
93719371 .operand = operand,
9372 .src_line = astgen.source_line,
93729373 });
93739374 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
93749375 gz.astgen.instructions.appendAssumeCapacity(.{
......@@ -13076,6 +13077,21 @@ const GenZir = struct {
1307613077 return new_index;
1307713078 }
1307813079
13080 /// Note that this returns a `Zir.Inst.Index` not a ref.
13081 /// Does *not* append the block instruction to the scope.
13082 /// Leaves the `payload_index` field undefined. Use `setDeclaration` to finalize.
13083 fn makeDeclaration(gz: *GenZir, node: Ast.Node.Index) !Zir.Inst.Index {
13084 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
13085 try gz.astgen.instructions.append(gz.astgen.gpa, .{
13086 .tag = .declaration,
13087 .data = .{ .declaration = .{
13088 .src_node = node,
13089 .payload_index = undefined,
13090 } },
13091 });
13092 return new_index;
13093 }
13094
1307913095 /// Note that this returns a `Zir.Inst.Index` not a ref.
1308013096 /// Leaves the `payload_index` field undefined.
1308113097 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
......@@ -13122,7 +13138,8 @@ const GenZir = struct {
1312213138 .fields_hash_1 = fields_hash_arr[1],
1312313139 .fields_hash_2 = fields_hash_arr[2],
1312413140 .fields_hash_3 = fields_hash_arr[3],
13125 .src_node = gz.nodeIndexToRelative(args.src_node),
13141 .src_line = astgen.source_line,
13142 .src_node = args.src_node,
1312613143 });
1312713144
1312813145 if (args.captures_len != 0) {
......@@ -13182,7 +13199,8 @@ const GenZir = struct {
1318213199 .fields_hash_1 = fields_hash_arr[1],
1318313200 .fields_hash_2 = fields_hash_arr[2],
1318413201 .fields_hash_3 = fields_hash_arr[3],
13185 .src_node = gz.nodeIndexToRelative(args.src_node),
13202 .src_line = astgen.source_line,
13203 .src_node = args.src_node,
1318613204 });
1318713205
1318813206 if (args.tag_type != .none) {
......@@ -13243,7 +13261,8 @@ const GenZir = struct {
1324313261 .fields_hash_1 = fields_hash_arr[1],
1324413262 .fields_hash_2 = fields_hash_arr[2],
1324513263 .fields_hash_3 = fields_hash_arr[3],
13246 .src_node = gz.nodeIndexToRelative(args.src_node),
13264 .src_line = astgen.source_line,
13265 .src_node = args.src_node,
1324713266 });
1324813267
1324913268 if (args.tag_type != .none) {
......@@ -13291,7 +13310,8 @@ const GenZir = struct {
1329113310
1329213311 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);
1329313312 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{
13294 .src_node = gz.nodeIndexToRelative(args.src_node),
13313 .src_line = astgen.source_line,
13314 .src_node = args.src_node,
1329513315 });
1329613316
1329713317 if (args.captures_len != 0) {
......@@ -13902,7 +13922,7 @@ fn setDeclaration(
1390213922 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
1390313923 },
1390413924 };
13905 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node.payload_index = try astgen.addExtra(extra);
13925 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].declaration.payload_index = try astgen.addExtra(extra);
1390613926 if (extra.flags.has_doc_comment) {
1390713927 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));
1390813928 }
lib/std/zig/Zir.zig+32-65
......@@ -20,7 +20,6 @@ const BigIntMutable = std.math.big.int.Mutable;
2020const Ast = std.zig.Ast;
2121
2222const Zir = @This();
23const LazySrcLoc = std.zig.LazySrcLoc;
2423
2524instructions: std.MultiArrayList(Inst).Slice,
2625/// In order to store references to strings in fewer bytes, we copy all
......@@ -287,7 +286,7 @@ pub const Inst = struct {
287286 /// namespace type, e.g. within a `struct_decl` instruction. It represents a
288287 /// single source declaration (`const`/`var`/`fn`), containing the name,
289288 /// attributes, type, and value of the declaration.
290 /// Uses the `pl_node` union field. Payload is `Declaration`.
289 /// Uses the `declaration` union field. Payload is `Declaration`.
291290 declaration,
292291 /// Implements `suspend {...}`.
293292 /// Uses the `pl_node` union field. Payload is `Block`.
......@@ -1596,7 +1595,7 @@ pub const Inst = struct {
15961595 .block = .pl_node,
15971596 .block_comptime = .pl_node,
15981597 .block_inline = .pl_node,
1599 .declaration = .pl_node,
1598 .declaration = .declaration,
16001599 .suspend_block = .pl_node,
16011600 .bool_not = .un_node,
16021601 .bool_br_and = .pl_node,
......@@ -1982,7 +1981,7 @@ pub const Inst = struct {
19821981 /// `operand` is payload index to `UnNode`.
19831982 error_from_int,
19841983 /// Implement builtin `@Type`.
1985 /// `operand` is payload index to `UnNode`.
1984 /// `operand` is payload index to `Reify`.
19861985 /// `small` contains `NameStrategy`.
19871986 reify,
19881987 /// Implements the `@asyncCall` builtin.
......@@ -2221,10 +2220,6 @@ pub const Inst = struct {
22212220 src_node: i32,
22222221 /// The meaning of this operand depends on the corresponding `Tag`.
22232222 operand: Ref,
2224
2225 pub fn src(self: @This()) LazySrcLoc {
2226 return LazySrcLoc.nodeOffset(self.src_node);
2227 }
22282223 },
22292224 /// Used for unary operators, with a token source location.
22302225 un_tok: struct {
......@@ -2232,10 +2227,6 @@ pub const Inst = struct {
22322227 src_tok: Ast.TokenIndex,
22332228 /// The meaning of this operand depends on the corresponding `Tag`.
22342229 operand: Ref,
2235
2236 pub fn src(self: @This()) LazySrcLoc {
2237 return .{ .token_offset = self.src_tok };
2238 }
22392230 },
22402231 pl_node: struct {
22412232 /// Offset from Decl AST node index.
......@@ -2244,10 +2235,6 @@ pub const Inst = struct {
22442235 /// index into extra.
22452236 /// `Tag` determines what lives there.
22462237 payload_index: u32,
2247
2248 pub fn src(self: @This()) LazySrcLoc {
2249 return LazySrcLoc.nodeOffset(self.src_node);
2250 }
22512238 },
22522239 pl_tok: struct {
22532240 /// Offset from Decl AST token index.
......@@ -2255,10 +2242,6 @@ pub const Inst = struct {
22552242 /// index into extra.
22562243 /// `Tag` determines what lives there.
22572244 payload_index: u32,
2258
2259 pub fn src(self: @This()) LazySrcLoc {
2260 return .{ .token_offset = self.src_tok };
2261 }
22622245 },
22632246 bin: Bin,
22642247 /// For strings which may contain null bytes.
......@@ -2281,10 +2264,6 @@ pub const Inst = struct {
22812264 pub fn get(self: @This(), code: Zir) [:0]const u8 {
22822265 return code.nullTerminatedString(self.start);
22832266 }
2284
2285 pub fn src(self: @This()) LazySrcLoc {
2286 return .{ .token_offset = self.src_tok };
2287 }
22882267 },
22892268 /// Offset from Decl AST token index.
22902269 tok: Ast.TokenIndex,
......@@ -2313,19 +2292,11 @@ pub const Inst = struct {
23132292 src_node: i32,
23142293 signedness: std.builtin.Signedness,
23152294 bit_count: u16,
2316
2317 pub fn src(self: @This()) LazySrcLoc {
2318 return LazySrcLoc.nodeOffset(self.src_node);
2319 }
23202295 },
23212296 @"unreachable": struct {
23222297 /// Offset from Decl AST node index.
23232298 /// `Tag` determines which kind of AST node this points to.
23242299 src_node: i32,
2325
2326 pub fn src(self: @This()) LazySrcLoc {
2327 return LazySrcLoc.nodeOffset(self.src_node);
2328 }
23292300 },
23302301 @"break": struct {
23312302 operand: Ref,
......@@ -2339,10 +2310,6 @@ pub const Inst = struct {
23392310 src_node: i32,
23402311 /// The meaning of this operand depends on the corresponding `Tag`.
23412312 inst: Index,
2342
2343 pub fn src(self: @This()) LazySrcLoc {
2344 return LazySrcLoc.nodeOffset(self.src_node);
2345 }
23462313 },
23472314 str_op: struct {
23482315 /// Offset into `string_bytes`. Null-terminated.
......@@ -2370,6 +2337,12 @@ pub const Inst = struct {
23702337 /// The index being accessed.
23712338 idx: u32,
23722339 },
2340 declaration: struct {
2341 /// This node provides a new absolute baseline node for all instructions within this struct.
2342 src_node: Ast.Node.Index,
2343 /// index into extra to a `Declaration` payload.
2344 payload_index: u32,
2345 },
23732346
23742347 // Make sure we don't accidentally add a field to make this union
23752348 // bigger than expected. Note that in Debug builds, Zig is allowed
......@@ -2408,6 +2381,7 @@ pub const Inst = struct {
24082381 defer_err_code,
24092382 save_err_ret_index,
24102383 elem_val_imm,
2384 declaration,
24112385 };
24122386 };
24132387
......@@ -2860,6 +2834,14 @@ pub const Inst = struct {
28602834 index: u32,
28612835 };
28622836
2837 pub const Reify = struct {
2838 /// This node is absolute, because `reify` instructions are tracked across updates, and
2839 /// this simplifies the logic for getting source locations for types.
2840 node: Ast.Node.Index,
2841 operand: Ref,
2842 src_line: u32,
2843 };
2844
28632845 pub const SwitchBlockErrUnion = struct {
28642846 operand: Ref,
28652847 bits: Bits,
......@@ -3018,11 +3000,9 @@ pub const Inst = struct {
30183000 fields_hash_1: u32,
30193001 fields_hash_2: u32,
30203002 fields_hash_3: u32,
3021 src_node: i32,
3022
3023 pub fn src(self: StructDecl) LazySrcLoc {
3024 return LazySrcLoc.nodeOffset(self.src_node);
3025 }
3003 src_line: u32,
3004 /// This node provides a new absolute baseline node for all instructions within this struct.
3005 src_node: Ast.Node.Index,
30263006
30273007 pub const Small = packed struct {
30283008 has_captures_len: bool,
......@@ -3150,11 +3130,9 @@ pub const Inst = struct {
31503130 fields_hash_1: u32,
31513131 fields_hash_2: u32,
31523132 fields_hash_3: u32,
3153 src_node: i32,
3154
3155 pub fn src(self: EnumDecl) LazySrcLoc {
3156 return LazySrcLoc.nodeOffset(self.src_node);
3157 }
3133 src_line: u32,
3134 /// This node provides a new absolute baseline node for all instructions within this struct.
3135 src_node: Ast.Node.Index,
31583136
31593137 pub const Small = packed struct {
31603138 has_tag_type: bool,
......@@ -3198,11 +3176,9 @@ pub const Inst = struct {
31983176 fields_hash_1: u32,
31993177 fields_hash_2: u32,
32003178 fields_hash_3: u32,
3201 src_node: i32,
3202
3203 pub fn src(self: UnionDecl) LazySrcLoc {
3204 return LazySrcLoc.nodeOffset(self.src_node);
3205 }
3179 src_line: u32,
3180 /// This node provides a new absolute baseline node for all instructions within this struct.
3181 src_node: Ast.Node.Index,
32063182
32073183 pub const Small = packed struct {
32083184 has_tag_type: bool,
......@@ -3230,11 +3206,9 @@ pub const Inst = struct {
32303206 /// 2. capture: Capture, // for every captures_len
32313207 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
32323208 pub const OpaqueDecl = struct {
3233 src_node: i32,
3234
3235 pub fn src(self: OpaqueDecl) LazySrcLoc {
3236 return LazySrcLoc.nodeOffset(self.src_node);
3237 }
3209 src_line: u32,
3210 /// This node provides a new absolute baseline node for all instructions within this struct.
3211 src_node: Ast.Node.Index,
32383212
32393213 pub const Small = packed struct {
32403214 has_captures_len: bool,
......@@ -3352,10 +3326,6 @@ pub const Inst = struct {
33523326 parent_ptr_type: Ref,
33533327 field_name: Ref,
33543328 field_ptr: Ref,
3355
3356 pub fn src(self: FieldParentPtr) LazySrcLoc {
3357 return LazySrcLoc.nodeOffset(self.src_node);
3358 }
33593329 };
33603330
33613331 pub const Shuffle = struct {
......@@ -3505,10 +3475,6 @@ pub const Inst = struct {
35053475 block: Ref,
35063476 /// If `.none`, restore unconditionally.
35073477 operand: Ref,
3508
3509 pub fn src(self: RestoreErrRetIndex) LazySrcLoc {
3510 return LazySrcLoc.nodeOffset(self.src_node);
3511 }
35123478 };
35133479};
35143480
......@@ -3772,6 +3738,7 @@ fn findDeclsInner(
37723738 .union_decl,
37733739 .enum_decl,
37743740 .opaque_decl,
3741 .reify,
37753742 => return list.append(inst),
37763743
37773744 else => return,
......@@ -4046,7 +4013,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
40464013
40474014pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {
40484015 assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);
4049 const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4016 const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].declaration;
40504017 const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);
40514018 return .{
40524019 extra.data,
src/Compilation.zig+17-20
......@@ -2639,7 +2639,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26392639 .root => |pkg| blk: {
26402640 break :blk try Module.ErrorMsg.init(
26412641 mod.gpa,
2642 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2642 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26432643 "root of module {s}",
26442644 .{pkg.fully_qualified_name},
26452645 );
......@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26512651 if (omitted > 0) {
26522652 notes[num_notes] = try Module.ErrorMsg.init(
26532653 mod.gpa,
2654 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2654 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26552655 "{} more references omitted",
26562656 .{omitted},
26572657 );
......@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26602660
26612661 const err = try Module.ErrorMsg.create(
26622662 mod.gpa,
2663 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2663 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26642664 "file exists in multiple modules",
26652665 .{},
26662666 );
......@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30403040 }
30413041 }
30423042
3043 if (comp.module) |module| {
3044 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {
3045 const keys = module.compile_log_decls.keys();
3046 const values = module.compile_log_decls.values();
3043 if (comp.module) |zcu| {
3044 if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
3045 const values = zcu.compile_log_decls.values();
30473046 // First one will be the error; subsequent ones will be notes.
3048 const err_decl = module.declPtr(keys[0]);
3049 const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module);
3050 const err_msg = Module.ErrorMsg{
3047 const src_loc = values[0].src().upgrade(zcu);
3048 const err_msg: Module.ErrorMsg = .{
30513049 .src_loc = src_loc,
30523050 .msg = "found compile log statement",
3053 .notes = try gpa.alloc(Module.ErrorMsg, module.compile_log_decls.count() - 1),
3051 .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_decls.count() - 1),
30543052 };
30553053 defer gpa.free(err_msg.notes);
30563054
3057 for (keys[1..], 0..) |key, i| {
3058 const note_decl = module.declPtr(key);
3059 err_msg.notes[i] = .{
3060 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module),
3055 for (values[1..], err_msg.notes) |src_info, *note| {
3056 note.* = .{
3057 .src_loc = src_info.src().upgrade(zcu),
30613058 .msg = "also here",
30623059 };
30633060 }
30643061
3065 try addModuleErrorMsg(module, &bundle, err_msg);
3062 try addModuleErrorMsg(zcu, &bundle, err_msg);
30663063 }
30673064 }
30683065
......@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34923489 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
34933490 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
34943491 gpa,
3495 decl.srcLoc(module),
3492 decl.navSrcLoc(module).upgrade(module),
34963493 "unable to update line number: {s}",
34973494 .{@errorName(err)},
34983495 ));
......@@ -3993,7 +3990,7 @@ fn workerAstGenFile(
39933990 if (!res.is_pkg) {
39943991 res.file.addReference(mod.*, .{ .import = .{
39953992 .file_scope = file,
3996 .parent_decl_node = 0,
3993 .base_node = 0,
39973994 .lazy = .{ .token_abs = item.data.token },
39983995 } }) catch continue;
39993996 }
......@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(
43704367 const src_loc: Module.SrcLoc = switch (src) {
43714368 .root => .{
43724369 .file_scope = file,
4373 .parent_decl_node = 0,
4370 .base_node = 0,
43744371 .lazy = .entire_file,
43754372 },
43764373 .import => |info| blk: {
......@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(
43784375
43794376 break :blk .{
43804377 .file_scope = importing_file,
4381 .parent_decl_node = 0,
4378 .base_node = 0,
43824379 .lazy = .{ .token_abs = info.import_tok },
43834380 };
43844381 },
src/InternPool.zig+25-4
......@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {
101101 }
102102 pub const Index = enum(u32) {
103103 _,
104 pub fn resolveFull(i: TrackedInst.Index, ip: *const InternPool) TrackedInst {
105 return ip.tracked_insts.keys()[@intFromEnum(i)];
106 }
104107 pub fn resolve(i: TrackedInst.Index, ip: *const InternPool) Zir.Inst.Index {
105 return ip.tracked_insts.keys()[@intFromEnum(i)].inst;
108 return i.resolveFull(ip).inst;
106109 }
107110 pub fn toOptional(i: TrackedInst.Index) Optional {
108111 return @enumFromInt(@intFromEnum(i));
......@@ -391,8 +394,27 @@ pub const RuntimeIndex = enum(u32) {
391394
392395pub const ComptimeAllocIndex = enum(u32) { _ };
393396
394pub const DeclIndex = std.zig.DeclIndex;
395pub const OptionalDeclIndex = std.zig.OptionalDeclIndex;
397pub const DeclIndex = enum(u32) {
398 _,
399
400 pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
401 return @enumFromInt(@intFromEnum(i));
402 }
403};
404
405pub const OptionalDeclIndex = enum(u32) {
406 none = std.math.maxInt(u32),
407 _,
408
409 pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
410 return @enumFromInt(@intFromEnum(oi orelse return .none));
411 }
412
413 pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
414 if (oi == .none) return null;
415 return @enumFromInt(@intFromEnum(oi));
416 }
417};
396418
397419pub const NamespaceIndex = enum(u32) {
398420 _,
......@@ -6935,7 +6957,6 @@ fn finishFuncInstance(
69356957 const decl_index = try ip.createDecl(gpa, .{
69366958 .name = undefined,
69376959 .src_namespace = fn_owner_decl.src_namespace,
6938 .src_node = fn_owner_decl.src_node,
69396960 .src_line = fn_owner_decl.src_line,
69406961 .has_tv = true,
69416962 .owns_tv = true,
src/Module.zig+826-717
......@@ -13,7 +13,6 @@ const BigIntConst = std.math.big.int.Const;
1313const BigIntMutable = std.math.big.int.Mutable;
1414const Target = std.Target;
1515const Ast = std.zig.Ast;
16const LazySrcLoc = std.zig.LazySrcLoc;
1716
1817/// Deprecated, use `Zcu`.
1918const Module = Zcu;
......@@ -89,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp
8988/// an update is requested, as well as to cache `@import` results.
9089/// Keys are fully resolved file paths. This table owns the keys and values.
9190import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
91/// This acts as a map from `path_digest` to the corresponding `File`.
92/// The value is omitted, as keys are ordered identically to `import_table`.
93path_digest_map: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, void) = .{},
9294/// The set of all the files which have been loaded with `@embedFile` in the Module.
9395/// We keep track of this in order to iterate over it and check which files have been
9496/// modified on the file system when an update is requested, as well as to cache
......@@ -108,8 +110,17 @@ intern_pool: InternPool = .{},
108110/// a Decl can have a failed_decls entry but have analysis status of success.
109111failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
110112/// Keep track of one `@compileLog` callsite per owner Decl.
111/// The value is the AST node index offset from the Decl.
112compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, i32) = .{},
113/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
114compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, extern struct {
115 base_node_inst: InternPool.TrackedInst.Index,
116 node_offset: i32,
117 pub fn src(self: @This()) LazySrcLoc {
118 return .{
119 .base_node_inst = self.base_node_inst,
120 .offset = LazySrcLoc.Offset.nodeOffset(self.node_offset),
121 };
122 }
123}) = .{},
113124/// Using a map here for consistency with the other fields here.
114125/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.
115126failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
......@@ -258,9 +269,6 @@ pub const Export = struct {
258269 src: LazySrcLoc,
259270 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
260271 owner_decl: Decl.Index,
261 /// The Decl containing the export statement. Inline function calls
262 /// may cause this to be different from the owner_decl.
263 src_decl: Decl.Index,
264272 exported: Exported,
265273 status: enum {
266274 in_progress,
......@@ -279,12 +287,7 @@ pub const Export = struct {
279287 };
280288
281289 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
282 const src_decl = mod.declPtr(exp.src_decl);
283 return .{
284 .file_scope = src_decl.getFileScope(mod),
285 .parent_decl_node = src_decl.src_node,
286 .lazy = exp.src,
287 };
290 return exp.src.upgrade(mod);
288291 }
289292};
290293
......@@ -344,9 +347,6 @@ pub const Decl = struct {
344347 /// there is no parent.
345348 src_namespace: Namespace.Index,
346349
347 /// The AST node index of this declaration.
348 /// Must be recomputed when the corresponding source file is modified.
349 src_node: Ast.Node.Index,
350350 /// Line number corresponding to `src_node`. Stored separately so that source files
351351 /// do not need to be loaded into memory in order to compute debug line numbers.
352352 /// This value is absolute.
......@@ -413,31 +413,11 @@ pub const Decl = struct {
413413 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {
414414 const zir = decl.getFileScope(zcu).zir;
415415 const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool);
416 const pl_node = zir.instructions.items(.data)[@intFromEnum(zir_index)].pl_node;
417 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);
416 const declaration = zir.instructions.items(.data)[@intFromEnum(zir_index)].declaration;
417 const extra = zir.extraData(Zir.Inst.Declaration, declaration.payload_index);
418418 return extra.data.getBodies(@intCast(extra.end), zir);
419419 }
420420
421 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
422 return @bitCast(offset + @as(i32, @bitCast(decl.src_node)));
423 }
424
425 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {
426 return @as(i32, @bitCast(node_index)) - @as(i32, @bitCast(decl.src_node));
427 }
428
429 pub fn srcLoc(decl: Decl, zcu: *Zcu) SrcLoc {
430 return decl.nodeOffsetSrcLoc(0, zcu);
431 }
432
433 pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32, zcu: *Zcu) SrcLoc {
434 return .{
435 .file_scope = decl.getFileScope(zcu),
436 .parent_decl_node = decl.src_node,
437 .lazy = LazySrcLoc.nodeOffset(node_offset),
438 };
439 }
440
441421 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
442422 if (decl.name_fully_qualified) {
443423 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});
......@@ -552,101 +532,6 @@ pub const Decl = struct {
552532 return decl.typeOf(zcu).abiAlignment(zcu);
553533 }
554534
555 /// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
556 pub fn toSrcLoc(decl: *Decl, lazy: LazySrcLoc, mod: *Module) SrcLoc {
557 return switch (lazy) {
558 .unneeded,
559 .entire_file,
560 .byte_abs,
561 .token_abs,
562 .node_abs,
563 => .{
564 .file_scope = decl.getFileScope(mod),
565 .parent_decl_node = 0,
566 .lazy = lazy,
567 },
568
569 .byte_offset,
570 .token_offset,
571 .node_offset,
572 .node_offset_main_token,
573 .node_offset_initializer,
574 .node_offset_var_decl_ty,
575 .node_offset_var_decl_align,
576 .node_offset_var_decl_section,
577 .node_offset_var_decl_addrspace,
578 .node_offset_var_decl_init,
579 .node_offset_builtin_call_arg0,
580 .node_offset_builtin_call_arg1,
581 .node_offset_builtin_call_arg2,
582 .node_offset_builtin_call_arg3,
583 .node_offset_builtin_call_arg4,
584 .node_offset_builtin_call_arg5,
585 .node_offset_ptrcast_operand,
586 .node_offset_array_access_index,
587 .node_offset_slice_ptr,
588 .node_offset_slice_start,
589 .node_offset_slice_end,
590 .node_offset_slice_sentinel,
591 .node_offset_call_func,
592 .node_offset_field_name,
593 .node_offset_field_name_init,
594 .node_offset_deref_ptr,
595 .node_offset_asm_source,
596 .node_offset_asm_ret_ty,
597 .node_offset_if_cond,
598 .node_offset_bin_op,
599 .node_offset_bin_lhs,
600 .node_offset_bin_rhs,
601 .node_offset_switch_operand,
602 .node_offset_switch_special_prong,
603 .node_offset_switch_range,
604 .node_offset_switch_prong_capture,
605 .node_offset_switch_prong_tag_capture,
606 .node_offset_fn_type_align,
607 .node_offset_fn_type_addrspace,
608 .node_offset_fn_type_section,
609 .node_offset_fn_type_cc,
610 .node_offset_fn_type_ret_ty,
611 .node_offset_param,
612 .token_offset_param,
613 .node_offset_anyframe_type,
614 .node_offset_lib_name,
615 .node_offset_array_type_len,
616 .node_offset_array_type_sentinel,
617 .node_offset_array_type_elem,
618 .node_offset_un_op,
619 .node_offset_ptr_elem,
620 .node_offset_ptr_sentinel,
621 .node_offset_ptr_align,
622 .node_offset_ptr_addrspace,
623 .node_offset_ptr_bitoffset,
624 .node_offset_ptr_hostsize,
625 .node_offset_container_tag,
626 .node_offset_field_default,
627 .node_offset_init_ty,
628 .node_offset_store_ptr,
629 .node_offset_store_operand,
630 .node_offset_return_operand,
631 .for_input,
632 .for_capture_from_input,
633 .array_cat_lhs,
634 .array_cat_rhs,
635 => .{
636 .file_scope = decl.getFileScope(mod),
637 .parent_decl_node = decl.src_node,
638 .lazy = lazy,
639 },
640 inline .call_arg,
641 .fn_proto_param,
642 => |x| .{
643 .file_scope = decl.getFileScope(mod),
644 .parent_decl_node = mod.declPtr(x.decl).src_node,
645 .lazy = lazy,
646 },
647 };
648 }
649
650535 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {
651536 assert(decl.has_tv);
652537 const decl_ty = decl.typeOf(zcu);
......@@ -662,6 +547,23 @@ pub const Decl = struct {
662547 },
663548 });
664549 }
550
551 /// Returns the source location of this `Decl`.
552 /// Asserts that this `Decl` corresponds to what will in future be a `Nav` (Named
553 /// Addressable Value): a source-level declaration or generic instantiation.
554 pub fn navSrcLoc(decl: Decl, zcu: *Zcu) LazySrcLoc {
555 return .{
556 .base_node_inst = decl.zir_decl_index.unwrap() orelse inst: {
557 // generic instantiation
558 assert(decl.has_tv);
559 assert(decl.owns_tv);
560 const owner = zcu.funcInfo(decl.val.toIntern()).generic_owner;
561 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
562 break :inst generic_owner_decl.zir_decl_index.unwrap().?;
563 },
564 .offset = LazySrcLoc.Offset.nodeOffset(0),
565 };
566 }
665567};
666568
667569/// This state is attached to every Decl when Module emit_h is non-null.
......@@ -836,8 +738,7 @@ pub const File = struct {
836738 /// List of references to this file, used for multi-package errors.
837739 references: std.ArrayListUnmanaged(Reference) = .{},
838740 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.
839 /// undefined until `zir_loaded == true`.
840 path_digest: Cache.BinDigest = undefined,
741 path_digest: Cache.BinDigest,
841742
842743 /// The most recent successful ZIR for this file, with no errors.
843744 /// This is only populated when a previously successful ZIR
......@@ -1138,18 +1039,17 @@ pub const ErrorMsg = struct {
11381039/// Canonical reference to a position within a source file.
11391040pub const SrcLoc = struct {
11401041 file_scope: *File,
1141 /// Might be 0 depending on tag of `lazy`.
1142 parent_decl_node: Ast.Node.Index,
1143 /// Relative to `parent_decl_node`.
1144 lazy: LazySrcLoc,
1042 base_node: Ast.Node.Index,
1043 /// Relative to `base_node`.
1044 lazy: LazySrcLoc.Offset,
11451045
1146 pub fn declSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
1046 pub fn baseSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
11471047 const tree = src_loc.file_scope.tree;
1148 return tree.firstToken(src_loc.parent_decl_node);
1048 return tree.firstToken(src_loc.base_node);
11491049 }
11501050
1151 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1152 return @bitCast(offset + @as(i32, @bitCast(src_loc.parent_decl_node)));
1051 pub fn relativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1052 return @bitCast(offset + @as(i32, @bitCast(src_loc.base_node)));
11531053 }
11541054
11551055 pub const Span = Ast.Span;
......@@ -1173,14 +1073,14 @@ pub const SrcLoc = struct {
11731073 },
11741074 .byte_offset => |byte_off| {
11751075 const tree = try src_loc.file_scope.getTree(gpa);
1176 const tok_index = src_loc.declSrcToken();
1076 const tok_index = src_loc.baseSrcToken();
11771077 const start = tree.tokens.items(.start)[tok_index] + byte_off;
11781078 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
11791079 return Span{ .start = start, .end = end, .main = start };
11801080 },
11811081 .token_offset => |tok_off| {
11821082 const tree = try src_loc.file_scope.getTree(gpa);
1183 const tok_index = src_loc.declSrcToken() + tok_off;
1083 const tok_index = src_loc.baseSrcToken() + tok_off;
11841084 const start = tree.tokens.items(.start)[tok_index];
11851085 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
11861086 return Span{ .start = start, .end = end, .main = start };
......@@ -1188,25 +1088,25 @@ pub const SrcLoc = struct {
11881088 .node_offset => |traced_off| {
11891089 const node_off = traced_off.x;
11901090 const tree = try src_loc.file_scope.getTree(gpa);
1191 const node = src_loc.declRelativeToNodeIndex(node_off);
1091 const node = src_loc.relativeToNodeIndex(node_off);
11921092 assert(src_loc.file_scope.tree_loaded);
11931093 return tree.nodeToSpan(node);
11941094 },
11951095 .node_offset_main_token => |node_off| {
11961096 const tree = try src_loc.file_scope.getTree(gpa);
1197 const node = src_loc.declRelativeToNodeIndex(node_off);
1097 const node = src_loc.relativeToNodeIndex(node_off);
11981098 const main_token = tree.nodes.items(.main_token)[node];
11991099 return tree.tokensToSpan(main_token, main_token, main_token);
12001100 },
12011101 .node_offset_bin_op => |node_off| {
12021102 const tree = try src_loc.file_scope.getTree(gpa);
1203 const node = src_loc.declRelativeToNodeIndex(node_off);
1103 const node = src_loc.relativeToNodeIndex(node_off);
12041104 assert(src_loc.file_scope.tree_loaded);
12051105 return tree.nodeToSpan(node);
12061106 },
12071107 .node_offset_initializer => |node_off| {
12081108 const tree = try src_loc.file_scope.getTree(gpa);
1209 const node = src_loc.declRelativeToNodeIndex(node_off);
1109 const node = src_loc.relativeToNodeIndex(node_off);
12101110 return tree.tokensToSpan(
12111111 tree.firstToken(node) - 3,
12121112 tree.lastToken(node),
......@@ -1215,7 +1115,7 @@ pub const SrcLoc = struct {
12151115 },
12161116 .node_offset_var_decl_ty => |node_off| {
12171117 const tree = try src_loc.file_scope.getTree(gpa);
1218 const node = src_loc.declRelativeToNodeIndex(node_off);
1118 const node = src_loc.relativeToNodeIndex(node_off);
12191119 const node_tags = tree.nodes.items(.tag);
12201120 const full = switch (node_tags[node]) {
12211121 .global_var_decl,
......@@ -1239,41 +1139,51 @@ pub const SrcLoc = struct {
12391139 },
12401140 .node_offset_var_decl_align => |node_off| {
12411141 const tree = try src_loc.file_scope.getTree(gpa);
1242 const node = src_loc.declRelativeToNodeIndex(node_off);
1142 const node = src_loc.relativeToNodeIndex(node_off);
12431143 const full = tree.fullVarDecl(node).?;
12441144 return tree.nodeToSpan(full.ast.align_node);
12451145 },
12461146 .node_offset_var_decl_section => |node_off| {
12471147 const tree = try src_loc.file_scope.getTree(gpa);
1248 const node = src_loc.declRelativeToNodeIndex(node_off);
1148 const node = src_loc.relativeToNodeIndex(node_off);
12491149 const full = tree.fullVarDecl(node).?;
12501150 return tree.nodeToSpan(full.ast.section_node);
12511151 },
12521152 .node_offset_var_decl_addrspace => |node_off| {
12531153 const tree = try src_loc.file_scope.getTree(gpa);
1254 const node = src_loc.declRelativeToNodeIndex(node_off);
1154 const node = src_loc.relativeToNodeIndex(node_off);
12551155 const full = tree.fullVarDecl(node).?;
12561156 return tree.nodeToSpan(full.ast.addrspace_node);
12571157 },
12581158 .node_offset_var_decl_init => |node_off| {
12591159 const tree = try src_loc.file_scope.getTree(gpa);
1260 const node = src_loc.declRelativeToNodeIndex(node_off);
1160 const node = src_loc.relativeToNodeIndex(node_off);
12611161 const full = tree.fullVarDecl(node).?;
12621162 return tree.nodeToSpan(full.ast.init_node);
12631163 },
1264 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),
1265 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),
1266 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),
1267 .node_offset_builtin_call_arg3 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 3),
1268 .node_offset_builtin_call_arg4 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 4),
1269 .node_offset_builtin_call_arg5 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 5),
1164 .node_offset_builtin_call_arg => |builtin_arg| {
1165 const tree = try src_loc.file_scope.getTree(gpa);
1166 const node_datas = tree.nodes.items(.data);
1167 const node_tags = tree.nodes.items(.tag);
1168 const node = src_loc.relativeToNodeIndex(builtin_arg.builtin_call_node);
1169 const param = switch (node_tags[node]) {
1170 .builtin_call_two, .builtin_call_two_comma => switch (builtin_arg.arg_index) {
1171 0 => node_datas[node].lhs,
1172 1 => node_datas[node].rhs,
1173 else => unreachable,
1174 },
1175 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + builtin_arg.arg_index],
1176 else => unreachable,
1177 };
1178 return tree.nodeToSpan(param);
1179 },
12701180 .node_offset_ptrcast_operand => |node_off| {
12711181 const tree = try src_loc.file_scope.getTree(gpa);
12721182 const main_tokens = tree.nodes.items(.main_token);
12731183 const node_datas = tree.nodes.items(.data);
12741184 const node_tags = tree.nodes.items(.tag);
12751185
1276 var node = src_loc.declRelativeToNodeIndex(node_off);
1186 var node = src_loc.relativeToNodeIndex(node_off);
12771187 while (true) {
12781188 switch (node_tags[node]) {
12791189 .builtin_call_two, .builtin_call_two_comma => {},
......@@ -1305,7 +1215,7 @@ pub const SrcLoc = struct {
13051215 .node_offset_array_access_index => |node_off| {
13061216 const tree = try src_loc.file_scope.getTree(gpa);
13071217 const node_datas = tree.nodes.items(.data);
1308 const node = src_loc.declRelativeToNodeIndex(node_off);
1218 const node = src_loc.relativeToNodeIndex(node_off);
13091219 return tree.nodeToSpan(node_datas[node].rhs);
13101220 },
13111221 .node_offset_slice_ptr,
......@@ -1314,7 +1224,7 @@ pub const SrcLoc = struct {
13141224 .node_offset_slice_sentinel,
13151225 => |node_off| {
13161226 const tree = try src_loc.file_scope.getTree(gpa);
1317 const node = src_loc.declRelativeToNodeIndex(node_off);
1227 const node = src_loc.relativeToNodeIndex(node_off);
13181228 const full = tree.fullSlice(node).?;
13191229 const part_node = switch (src_loc.lazy) {
13201230 .node_offset_slice_ptr => full.ast.sliced,
......@@ -1327,7 +1237,7 @@ pub const SrcLoc = struct {
13271237 },
13281238 .node_offset_call_func => |node_off| {
13291239 const tree = try src_loc.file_scope.getTree(gpa);
1330 const node = src_loc.declRelativeToNodeIndex(node_off);
1240 const node = src_loc.relativeToNodeIndex(node_off);
13311241 var buf: [1]Ast.Node.Index = undefined;
13321242 const full = tree.fullCall(&buf, node).?;
13331243 return tree.nodeToSpan(full.ast.fn_expr);
......@@ -1336,7 +1246,7 @@ pub const SrcLoc = struct {
13361246 const tree = try src_loc.file_scope.getTree(gpa);
13371247 const node_datas = tree.nodes.items(.data);
13381248 const node_tags = tree.nodes.items(.tag);
1339 const node = src_loc.declRelativeToNodeIndex(node_off);
1249 const node = src_loc.relativeToNodeIndex(node_off);
13401250 var buf: [1]Ast.Node.Index = undefined;
13411251 const tok_index = switch (node_tags[node]) {
13421252 .field_access => node_datas[node].rhs,
......@@ -1360,7 +1270,7 @@ pub const SrcLoc = struct {
13601270 },
13611271 .node_offset_field_name_init => |node_off| {
13621272 const tree = try src_loc.file_scope.getTree(gpa);
1363 const node = src_loc.declRelativeToNodeIndex(node_off);
1273 const node = src_loc.relativeToNodeIndex(node_off);
13641274 const tok_index = tree.firstToken(node) - 2;
13651275 const start = tree.tokens.items(.start)[tok_index];
13661276 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
......@@ -1368,18 +1278,18 @@ pub const SrcLoc = struct {
13681278 },
13691279 .node_offset_deref_ptr => |node_off| {
13701280 const tree = try src_loc.file_scope.getTree(gpa);
1371 const node = src_loc.declRelativeToNodeIndex(node_off);
1281 const node = src_loc.relativeToNodeIndex(node_off);
13721282 return tree.nodeToSpan(node);
13731283 },
13741284 .node_offset_asm_source => |node_off| {
13751285 const tree = try src_loc.file_scope.getTree(gpa);
1376 const node = src_loc.declRelativeToNodeIndex(node_off);
1286 const node = src_loc.relativeToNodeIndex(node_off);
13771287 const full = tree.fullAsm(node).?;
13781288 return tree.nodeToSpan(full.ast.template);
13791289 },
13801290 .node_offset_asm_ret_ty => |node_off| {
13811291 const tree = try src_loc.file_scope.getTree(gpa);
1382 const node = src_loc.declRelativeToNodeIndex(node_off);
1292 const node = src_loc.relativeToNodeIndex(node_off);
13831293 const full = tree.fullAsm(node).?;
13841294 const asm_output = full.outputs[0];
13851295 const node_datas = tree.nodes.items(.data);
......@@ -1388,7 +1298,7 @@ pub const SrcLoc = struct {
13881298
13891299 .node_offset_if_cond => |node_off| {
13901300 const tree = try src_loc.file_scope.getTree(gpa);
1391 const node = src_loc.declRelativeToNodeIndex(node_off);
1301 const node = src_loc.relativeToNodeIndex(node_off);
13921302 const node_tags = tree.nodes.items(.tag);
13931303 const src_node = switch (node_tags[node]) {
13941304 .if_simple,
......@@ -1417,7 +1327,7 @@ pub const SrcLoc = struct {
14171327 },
14181328 .for_input => |for_input| {
14191329 const tree = try src_loc.file_scope.getTree(gpa);
1420 const node = src_loc.declRelativeToNodeIndex(for_input.for_node_offset);
1330 const node = src_loc.relativeToNodeIndex(for_input.for_node_offset);
14211331 const for_full = tree.fullFor(node).?;
14221332 const src_node = for_full.ast.inputs[for_input.input_index];
14231333 return tree.nodeToSpan(src_node);
......@@ -1425,7 +1335,7 @@ pub const SrcLoc = struct {
14251335 .for_capture_from_input => |node_off| {
14261336 const tree = try src_loc.file_scope.getTree(gpa);
14271337 const token_tags = tree.tokens.items(.tag);
1428 const input_node = src_loc.declRelativeToNodeIndex(node_off);
1338 const input_node = src_loc.relativeToNodeIndex(node_off);
14291339 // We have to actually linear scan the whole AST to find the for loop
14301340 // that contains this input.
14311341 const node_tags = tree.nodes.items(.tag);
......@@ -1466,7 +1376,7 @@ pub const SrcLoc = struct {
14661376 },
14671377 .call_arg => |call_arg| {
14681378 const tree = try src_loc.file_scope.getTree(gpa);
1469 const node = src_loc.declRelativeToNodeIndex(call_arg.call_node_offset);
1379 const node = src_loc.relativeToNodeIndex(call_arg.call_node_offset);
14701380 var buf: [2]Ast.Node.Index = undefined;
14711381 const call_full = tree.fullCall(buf[0..1], node) orelse {
14721382 const node_tags = tree.nodes.items(.tag);
......@@ -1502,43 +1412,49 @@ pub const SrcLoc = struct {
15021412 };
15031413 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);
15041414 },
1505 .fn_proto_param => |fn_proto_param| {
1415 .fn_proto_param, .fn_proto_param_type => |fn_proto_param| {
15061416 const tree = try src_loc.file_scope.getTree(gpa);
1507 const node = src_loc.declRelativeToNodeIndex(fn_proto_param.fn_proto_node_offset);
1417 const node = src_loc.relativeToNodeIndex(fn_proto_param.fn_proto_node_offset);
15081418 var buf: [1]Ast.Node.Index = undefined;
15091419 const full = tree.fullFnProto(&buf, node).?;
15101420 var it = full.iterate(tree);
15111421 var i: usize = 0;
15121422 while (it.next()) |param| : (i += 1) {
1513 if (i == fn_proto_param.param_index) {
1514 if (param.anytype_ellipsis3) |token| return tree.tokenToSpan(token);
1515 const first_token = param.comptime_noalias orelse
1516 param.name_token orelse
1517 tree.firstToken(param.type_expr);
1518 return tree.tokensToSpan(
1519 first_token,
1520 tree.lastToken(param.type_expr),
1521 first_token,
1522 );
1423 if (i != fn_proto_param.param_index) continue;
1424
1425 switch (src_loc.lazy) {
1426 .fn_proto_param_type => if (param.anytype_ellipsis3) |tok| {
1427 return tree.tokenToSpan(tok);
1428 } else {
1429 return tree.nodeToSpan(param.type_expr);
1430 },
1431 .fn_proto_param => if (param.anytype_ellipsis3) |tok| {
1432 const first = param.comptime_noalias orelse param.name_token orelse tok;
1433 return tree.tokensToSpan(first, tok, first);
1434 } else {
1435 const first = param.comptime_noalias orelse param.name_token orelse tree.firstToken(param.type_expr);
1436 return tree.tokensToSpan(first, tree.lastToken(param.type_expr), first);
1437 },
1438 else => unreachable,
15231439 }
15241440 }
15251441 unreachable;
15261442 },
15271443 .node_offset_bin_lhs => |node_off| {
15281444 const tree = try src_loc.file_scope.getTree(gpa);
1529 const node = src_loc.declRelativeToNodeIndex(node_off);
1445 const node = src_loc.relativeToNodeIndex(node_off);
15301446 const node_datas = tree.nodes.items(.data);
15311447 return tree.nodeToSpan(node_datas[node].lhs);
15321448 },
15331449 .node_offset_bin_rhs => |node_off| {
15341450 const tree = try src_loc.file_scope.getTree(gpa);
1535 const node = src_loc.declRelativeToNodeIndex(node_off);
1451 const node = src_loc.relativeToNodeIndex(node_off);
15361452 const node_datas = tree.nodes.items(.data);
15371453 return tree.nodeToSpan(node_datas[node].rhs);
15381454 },
15391455 .array_cat_lhs, .array_cat_rhs => |cat| {
15401456 const tree = try src_loc.file_scope.getTree(gpa);
1541 const node = src_loc.declRelativeToNodeIndex(cat.array_cat_offset);
1457 const node = src_loc.relativeToNodeIndex(cat.array_cat_offset);
15421458 const node_datas = tree.nodes.items(.data);
15431459 const arr_node = if (src_loc.lazy == .array_cat_lhs)
15441460 node_datas[node].lhs
......@@ -1566,14 +1482,14 @@ pub const SrcLoc = struct {
15661482
15671483 .node_offset_switch_operand => |node_off| {
15681484 const tree = try src_loc.file_scope.getTree(gpa);
1569 const node = src_loc.declRelativeToNodeIndex(node_off);
1485 const node = src_loc.relativeToNodeIndex(node_off);
15701486 const node_datas = tree.nodes.items(.data);
15711487 return tree.nodeToSpan(node_datas[node].lhs);
15721488 },
15731489
15741490 .node_offset_switch_special_prong => |node_off| {
15751491 const tree = try src_loc.file_scope.getTree(gpa);
1576 const switch_node = src_loc.declRelativeToNodeIndex(node_off);
1492 const switch_node = src_loc.relativeToNodeIndex(node_off);
15771493 const node_datas = tree.nodes.items(.data);
15781494 const node_tags = tree.nodes.items(.tag);
15791495 const main_tokens = tree.nodes.items(.main_token);
......@@ -1593,7 +1509,7 @@ pub const SrcLoc = struct {
15931509
15941510 .node_offset_switch_range => |node_off| {
15951511 const tree = try src_loc.file_scope.getTree(gpa);
1596 const switch_node = src_loc.declRelativeToNodeIndex(node_off);
1512 const switch_node = src_loc.relativeToNodeIndex(node_off);
15971513 const node_datas = tree.nodes.items(.data);
15981514 const node_tags = tree.nodes.items(.tag);
15991515 const main_tokens = tree.nodes.items(.main_token);
......@@ -1614,56 +1530,30 @@ pub const SrcLoc = struct {
16141530 }
16151531 } else unreachable;
16161532 },
1617 .node_offset_switch_prong_capture,
1618 .node_offset_switch_prong_tag_capture,
1619 => |node_off| {
1620 const tree = try src_loc.file_scope.getTree(gpa);
1621 const case_node = src_loc.declRelativeToNodeIndex(node_off);
1622 const case = tree.fullSwitchCase(case_node).?;
1623 const token_tags = tree.tokens.items(.tag);
1624 const start_tok = switch (src_loc.lazy) {
1625 .node_offset_switch_prong_capture => case.payload_token.?,
1626 .node_offset_switch_prong_tag_capture => blk: {
1627 var tok = case.payload_token.?;
1628 if (token_tags[tok] == .asterisk) tok += 1;
1629 tok += 2; // skip over comma
1630 break :blk tok;
1631 },
1632 else => unreachable,
1633 };
1634 const end_tok = switch (token_tags[start_tok]) {
1635 .asterisk => start_tok + 1,
1636 else => start_tok,
1637 };
1638 const start = tree.tokens.items(.start)[start_tok];
1639 const end_start = tree.tokens.items(.start)[end_tok];
1640 const end = end_start + @as(u32, @intCast(tree.tokenSlice(end_tok).len));
1641 return Span{ .start = start, .end = end, .main = start };
1642 },
16431533 .node_offset_fn_type_align => |node_off| {
16441534 const tree = try src_loc.file_scope.getTree(gpa);
1645 const node = src_loc.declRelativeToNodeIndex(node_off);
1535 const node = src_loc.relativeToNodeIndex(node_off);
16461536 var buf: [1]Ast.Node.Index = undefined;
16471537 const full = tree.fullFnProto(&buf, node).?;
16481538 return tree.nodeToSpan(full.ast.align_expr);
16491539 },
16501540 .node_offset_fn_type_addrspace => |node_off| {
16511541 const tree = try src_loc.file_scope.getTree(gpa);
1652 const node = src_loc.declRelativeToNodeIndex(node_off);
1542 const node = src_loc.relativeToNodeIndex(node_off);
16531543 var buf: [1]Ast.Node.Index = undefined;
16541544 const full = tree.fullFnProto(&buf, node).?;
16551545 return tree.nodeToSpan(full.ast.addrspace_expr);
16561546 },
16571547 .node_offset_fn_type_section => |node_off| {
16581548 const tree = try src_loc.file_scope.getTree(gpa);
1659 const node = src_loc.declRelativeToNodeIndex(node_off);
1549 const node = src_loc.relativeToNodeIndex(node_off);
16601550 var buf: [1]Ast.Node.Index = undefined;
16611551 const full = tree.fullFnProto(&buf, node).?;
16621552 return tree.nodeToSpan(full.ast.section_expr);
16631553 },
16641554 .node_offset_fn_type_cc => |node_off| {
16651555 const tree = try src_loc.file_scope.getTree(gpa);
1666 const node = src_loc.declRelativeToNodeIndex(node_off);
1556 const node = src_loc.relativeToNodeIndex(node_off);
16671557 var buf: [1]Ast.Node.Index = undefined;
16681558 const full = tree.fullFnProto(&buf, node).?;
16691559 return tree.nodeToSpan(full.ast.callconv_expr);
......@@ -1671,7 +1561,7 @@ pub const SrcLoc = struct {
16711561
16721562 .node_offset_fn_type_ret_ty => |node_off| {
16731563 const tree = try src_loc.file_scope.getTree(gpa);
1674 const node = src_loc.declRelativeToNodeIndex(node_off);
1564 const node = src_loc.relativeToNodeIndex(node_off);
16751565 var buf: [1]Ast.Node.Index = undefined;
16761566 const full = tree.fullFnProto(&buf, node).?;
16771567 return tree.nodeToSpan(full.ast.return_type);
......@@ -1679,7 +1569,7 @@ pub const SrcLoc = struct {
16791569 .node_offset_param => |node_off| {
16801570 const tree = try src_loc.file_scope.getTree(gpa);
16811571 const token_tags = tree.tokens.items(.tag);
1682 const node = src_loc.declRelativeToNodeIndex(node_off);
1572 const node = src_loc.relativeToNodeIndex(node_off);
16831573
16841574 var first_tok = tree.firstToken(node);
16851575 while (true) switch (token_tags[first_tok - 1]) {
......@@ -1695,7 +1585,7 @@ pub const SrcLoc = struct {
16951585 .token_offset_param => |token_off| {
16961586 const tree = try src_loc.file_scope.getTree(gpa);
16971587 const token_tags = tree.tokens.items(.tag);
1698 const main_token = tree.nodes.items(.main_token)[src_loc.parent_decl_node];
1588 const main_token = tree.nodes.items(.main_token)[src_loc.base_node];
16991589 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));
17001590
17011591 var first_tok = tok_index;
......@@ -1713,13 +1603,13 @@ pub const SrcLoc = struct {
17131603 .node_offset_anyframe_type => |node_off| {
17141604 const tree = try src_loc.file_scope.getTree(gpa);
17151605 const node_datas = tree.nodes.items(.data);
1716 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1606 const parent_node = src_loc.relativeToNodeIndex(node_off);
17171607 return tree.nodeToSpan(node_datas[parent_node].rhs);
17181608 },
17191609
17201610 .node_offset_lib_name => |node_off| {
17211611 const tree = try src_loc.file_scope.getTree(gpa);
1722 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1612 const parent_node = src_loc.relativeToNodeIndex(node_off);
17231613 var buf: [1]Ast.Node.Index = undefined;
17241614 const full = tree.fullFnProto(&buf, parent_node).?;
17251615 const tok_index = full.lib_name.?;
......@@ -1730,21 +1620,21 @@ pub const SrcLoc = struct {
17301620
17311621 .node_offset_array_type_len => |node_off| {
17321622 const tree = try src_loc.file_scope.getTree(gpa);
1733 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1623 const parent_node = src_loc.relativeToNodeIndex(node_off);
17341624
17351625 const full = tree.fullArrayType(parent_node).?;
17361626 return tree.nodeToSpan(full.ast.elem_count);
17371627 },
17381628 .node_offset_array_type_sentinel => |node_off| {
17391629 const tree = try src_loc.file_scope.getTree(gpa);
1740 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1630 const parent_node = src_loc.relativeToNodeIndex(node_off);
17411631
17421632 const full = tree.fullArrayType(parent_node).?;
17431633 return tree.nodeToSpan(full.ast.sentinel);
17441634 },
17451635 .node_offset_array_type_elem => |node_off| {
17461636 const tree = try src_loc.file_scope.getTree(gpa);
1747 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1637 const parent_node = src_loc.relativeToNodeIndex(node_off);
17481638
17491639 const full = tree.fullArrayType(parent_node).?;
17501640 return tree.nodeToSpan(full.ast.elem_type);
......@@ -1752,48 +1642,48 @@ pub const SrcLoc = struct {
17521642 .node_offset_un_op => |node_off| {
17531643 const tree = try src_loc.file_scope.getTree(gpa);
17541644 const node_datas = tree.nodes.items(.data);
1755 const node = src_loc.declRelativeToNodeIndex(node_off);
1645 const node = src_loc.relativeToNodeIndex(node_off);
17561646
17571647 return tree.nodeToSpan(node_datas[node].lhs);
17581648 },
17591649 .node_offset_ptr_elem => |node_off| {
17601650 const tree = try src_loc.file_scope.getTree(gpa);
1761 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1651 const parent_node = src_loc.relativeToNodeIndex(node_off);
17621652
17631653 const full = tree.fullPtrType(parent_node).?;
17641654 return tree.nodeToSpan(full.ast.child_type);
17651655 },
17661656 .node_offset_ptr_sentinel => |node_off| {
17671657 const tree = try src_loc.file_scope.getTree(gpa);
1768 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1658 const parent_node = src_loc.relativeToNodeIndex(node_off);
17691659
17701660 const full = tree.fullPtrType(parent_node).?;
17711661 return tree.nodeToSpan(full.ast.sentinel);
17721662 },
17731663 .node_offset_ptr_align => |node_off| {
17741664 const tree = try src_loc.file_scope.getTree(gpa);
1775 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1665 const parent_node = src_loc.relativeToNodeIndex(node_off);
17761666
17771667 const full = tree.fullPtrType(parent_node).?;
17781668 return tree.nodeToSpan(full.ast.align_node);
17791669 },
17801670 .node_offset_ptr_addrspace => |node_off| {
17811671 const tree = try src_loc.file_scope.getTree(gpa);
1782 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1672 const parent_node = src_loc.relativeToNodeIndex(node_off);
17831673
17841674 const full = tree.fullPtrType(parent_node).?;
17851675 return tree.nodeToSpan(full.ast.addrspace_node);
17861676 },
17871677 .node_offset_ptr_bitoffset => |node_off| {
17881678 const tree = try src_loc.file_scope.getTree(gpa);
1789 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1679 const parent_node = src_loc.relativeToNodeIndex(node_off);
17901680
17911681 const full = tree.fullPtrType(parent_node).?;
17921682 return tree.nodeToSpan(full.ast.bit_range_start);
17931683 },
17941684 .node_offset_ptr_hostsize => |node_off| {
17951685 const tree = try src_loc.file_scope.getTree(gpa);
1796 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1686 const parent_node = src_loc.relativeToNodeIndex(node_off);
17971687
17981688 const full = tree.fullPtrType(parent_node).?;
17991689 return tree.nodeToSpan(full.ast.bit_range_end);
......@@ -1801,7 +1691,7 @@ pub const SrcLoc = struct {
18011691 .node_offset_container_tag => |node_off| {
18021692 const tree = try src_loc.file_scope.getTree(gpa);
18031693 const node_tags = tree.nodes.items(.tag);
1804 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1694 const parent_node = src_loc.relativeToNodeIndex(node_off);
18051695
18061696 switch (node_tags[parent_node]) {
18071697 .container_decl_arg, .container_decl_arg_trailing => {
......@@ -1823,7 +1713,7 @@ pub const SrcLoc = struct {
18231713 .node_offset_field_default => |node_off| {
18241714 const tree = try src_loc.file_scope.getTree(gpa);
18251715 const node_tags = tree.nodes.items(.tag);
1826 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1716 const parent_node = src_loc.relativeToNodeIndex(node_off);
18271717
18281718 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {
18291719 .container_field => tree.containerField(parent_node),
......@@ -1834,7 +1724,7 @@ pub const SrcLoc = struct {
18341724 },
18351725 .node_offset_init_ty => |node_off| {
18361726 const tree = try src_loc.file_scope.getTree(gpa);
1837 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1727 const parent_node = src_loc.relativeToNodeIndex(node_off);
18381728
18391729 var buf: [2]Ast.Node.Index = undefined;
18401730 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
......@@ -1847,7 +1737,7 @@ pub const SrcLoc = struct {
18471737 const tree = try src_loc.file_scope.getTree(gpa);
18481738 const node_tags = tree.nodes.items(.tag);
18491739 const node_datas = tree.nodes.items(.data);
1850 const node = src_loc.declRelativeToNodeIndex(node_off);
1740 const node = src_loc.relativeToNodeIndex(node_off);
18511741
18521742 switch (node_tags[node]) {
18531743 .assign => {
......@@ -1860,7 +1750,7 @@ pub const SrcLoc = struct {
18601750 const tree = try src_loc.file_scope.getTree(gpa);
18611751 const node_tags = tree.nodes.items(.tag);
18621752 const node_datas = tree.nodes.items(.data);
1863 const node = src_loc.declRelativeToNodeIndex(node_off);
1753 const node = src_loc.relativeToNodeIndex(node_off);
18641754
18651755 switch (node_tags[node]) {
18661756 .assign => {
......@@ -1871,7 +1761,7 @@ pub const SrcLoc = struct {
18711761 },
18721762 .node_offset_return_operand => |node_off| {
18731763 const tree = try src_loc.file_scope.getTree(gpa);
1874 const node = src_loc.declRelativeToNodeIndex(node_off);
1764 const node = src_loc.relativeToNodeIndex(node_off);
18751765 const node_tags = tree.nodes.items(.tag);
18761766 const node_datas = tree.nodes.items(.data);
18771767 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {
......@@ -1879,29 +1769,629 @@ pub const SrcLoc = struct {
18791769 }
18801770 return tree.nodeToSpan(node);
18811771 },
1772 .container_field_name,
1773 .container_field_value,
1774 .container_field_type,
1775 .container_field_align,
1776 => |field_idx| {
1777 const tree = try src_loc.file_scope.getTree(gpa);
1778 const node = src_loc.relativeToNodeIndex(0);
1779 var buf: [2]Ast.Node.Index = undefined;
1780 const container_decl = tree.fullContainerDecl(&buf, node) orelse
1781 return tree.nodeToSpan(node);
1782
1783 var cur_field_idx: usize = 0;
1784 for (container_decl.ast.members) |member_node| {
1785 const field = tree.fullContainerField(member_node) orelse continue;
1786 if (cur_field_idx < field_idx) {
1787 cur_field_idx += 1;
1788 continue;
1789 }
1790 const field_component_node = switch (src_loc.lazy) {
1791 .container_field_name => 0,
1792 .container_field_value => field.ast.value_expr,
1793 .container_field_type => field.ast.type_expr,
1794 .container_field_align => field.ast.align_expr,
1795 else => unreachable,
1796 };
1797 if (field_component_node == 0) {
1798 return tree.tokenToSpan(field.ast.main_token);
1799 } else {
1800 return tree.nodeToSpan(field_component_node);
1801 }
1802 } else unreachable;
1803 },
1804 .init_elem => |init_elem| {
1805 const tree = try src_loc.file_scope.getTree(gpa);
1806 const init_node = src_loc.relativeToNodeIndex(init_elem.init_node_offset);
1807 var buf: [2]Ast.Node.Index = undefined;
1808 if (tree.fullArrayInit(&buf, init_node)) |full| {
1809 const elem_node = full.ast.elements[init_elem.elem_index];
1810 return tree.nodeToSpan(elem_node);
1811 } else if (tree.fullStructInit(&buf, init_node)) |full| {
1812 const field_node = full.ast.fields[init_elem.elem_index];
1813 return tree.tokensToSpan(
1814 tree.firstToken(field_node) - 3,
1815 tree.lastToken(field_node),
1816 tree.nodes.items(.main_token)[field_node] - 2,
1817 );
1818 } else unreachable;
1819 },
1820 .init_field_name,
1821 .init_field_linkage,
1822 .init_field_section,
1823 .init_field_visibility,
1824 .init_field_rw,
1825 .init_field_locality,
1826 .init_field_cache,
1827 .init_field_library,
1828 .init_field_thread_local,
1829 => |builtin_call_node| {
1830 const wanted = switch (src_loc.lazy) {
1831 .init_field_name => "name",
1832 .init_field_linkage => "linkage",
1833 .init_field_section => "section",
1834 .init_field_visibility => "visibility",
1835 .init_field_rw => "rw",
1836 .init_field_locality => "locality",
1837 .init_field_cache => "cache",
1838 .init_field_library => "library",
1839 .init_field_thread_local => "thread_local",
1840 else => unreachable,
1841 };
1842 const tree = try src_loc.file_scope.getTree(gpa);
1843 const node_datas = tree.nodes.items(.data);
1844 const node_tags = tree.nodes.items(.tag);
1845 const node = src_loc.relativeToNodeIndex(builtin_call_node);
1846 const arg_node = switch (node_tags[node]) {
1847 .builtin_call_two, .builtin_call_two_comma => node_datas[node].rhs,
1848 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + 1],
1849 else => unreachable,
1850 };
1851 var buf: [2]Ast.Node.Index = undefined;
1852 const full = tree.fullStructInit(&buf, arg_node) orelse
1853 return tree.nodeToSpan(arg_node);
1854 for (full.ast.fields) |field_node| {
1855 // . IDENTIFIER = field_node
1856 const name_token = tree.firstToken(field_node) - 2;
1857 const name = tree.tokenSlice(name_token);
1858 if (std.mem.eql(u8, name, wanted)) {
1859 return tree.tokensToSpan(
1860 name_token - 1,
1861 tree.lastToken(field_node),
1862 tree.nodes.items(.main_token)[field_node] - 2,
1863 );
1864 }
1865 }
1866 return tree.nodeToSpan(arg_node);
1867 },
1868 .switch_case_item,
1869 .switch_case_item_range_first,
1870 .switch_case_item_range_last,
1871 .switch_capture,
1872 .switch_tag_capture,
1873 => {
1874 const switch_node_offset, const want_case_idx = switch (src_loc.lazy) {
1875 .switch_case_item,
1876 .switch_case_item_range_first,
1877 .switch_case_item_range_last,
1878 => |x| .{ x.switch_node_offset, x.case_idx },
1879 .switch_capture,
1880 .switch_tag_capture,
1881 => |x| .{ x.switch_node_offset, x.case_idx },
1882 else => unreachable,
1883 };
1884
1885 const tree = try src_loc.file_scope.getTree(gpa);
1886 const node_datas = tree.nodes.items(.data);
1887 const node_tags = tree.nodes.items(.tag);
1888 const main_tokens = tree.nodes.items(.main_token);
1889 const switch_node = src_loc.relativeToNodeIndex(switch_node_offset);
1890 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
1891 const case_nodes = tree.extra_data[extra.start..extra.end];
1892
1893 var multi_i: u32 = 0;
1894 var scalar_i: u32 = 0;
1895 const case = for (case_nodes) |case_node| {
1896 const case = tree.fullSwitchCase(case_node).?;
1897 const is_special = special: {
1898 if (case.ast.values.len == 0) break :special true;
1899 if (case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .identifier) {
1900 break :special mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_");
1901 }
1902 break :special false;
1903 };
1904 if (is_special) {
1905 if (want_case_idx.isSpecial()) {
1906 break case;
1907 }
1908 }
1909
1910 const is_multi = case.ast.values.len != 1 or
1911 node_tags[case.ast.values[0]] == .switch_range;
1912
1913 if (!want_case_idx.isSpecial()) switch (want_case_idx.kind) {
1914 .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case,
1915 .multi => if (is_multi and want_case_idx.index == multi_i) break case,
1916 };
1917
1918 if (is_multi) {
1919 multi_i += 1;
1920 } else {
1921 scalar_i += 1;
1922 }
1923 } else unreachable;
1924
1925 const want_item = switch (src_loc.lazy) {
1926 .switch_case_item,
1927 .switch_case_item_range_first,
1928 .switch_case_item_range_last,
1929 => |x| x.item_idx,
1930 .switch_capture, .switch_tag_capture => {
1931 const token_tags = tree.tokens.items(.tag);
1932 const start = switch (src_loc.lazy) {
1933 .switch_capture => case.payload_token.?,
1934 .switch_tag_capture => tok: {
1935 var tok = case.payload_token.?;
1936 if (token_tags[tok] == .asterisk) tok += 1;
1937 tok += 2; // skip over comma
1938 break :tok tok;
1939 },
1940 else => unreachable,
1941 };
1942 const end = switch (token_tags[start]) {
1943 .asterisk => start + 1,
1944 else => start,
1945 };
1946 return tree.tokensToSpan(start, end, start);
1947 },
1948 else => unreachable,
1949 };
1950
1951 switch (want_item.kind) {
1952 .single => {
1953 var item_i: u32 = 0;
1954 for (case.ast.values) |item_node| {
1955 if (node_tags[item_node] == .switch_range) continue;
1956 if (item_i != want_item.index) {
1957 item_i += 1;
1958 continue;
1959 }
1960 return tree.nodeToSpan(item_node);
1961 } else unreachable;
1962 },
1963 .range => {
1964 var range_i: u32 = 0;
1965 for (case.ast.values) |item_node| {
1966 if (node_tags[item_node] != .switch_range) continue;
1967 if (range_i != want_item.index) {
1968 range_i += 1;
1969 continue;
1970 }
1971 return switch (src_loc.lazy) {
1972 .switch_case_item => tree.nodeToSpan(item_node),
1973 .switch_case_item_range_first => tree.nodeToSpan(node_datas[item_node].lhs),
1974 .switch_case_item_range_last => tree.nodeToSpan(node_datas[item_node].rhs),
1975 else => unreachable,
1976 };
1977 } else unreachable;
1978 },
1979 }
1980 },
18821981 }
18831982 }
1983};
18841984
1885 pub fn byteOffsetBuiltinCallArg(
1886 src_loc: SrcLoc,
1887 gpa: Allocator,
1888 node_off: i32,
1889 arg_index: u32,
1890 ) !Span {
1891 const tree = try src_loc.file_scope.getTree(gpa);
1892 const node_datas = tree.nodes.items(.data);
1893 const node_tags = tree.nodes.items(.tag);
1894 const node = src_loc.declRelativeToNodeIndex(node_off);
1895 const param = switch (node_tags[node]) {
1896 .builtin_call_two, .builtin_call_two_comma => switch (arg_index) {
1897 0 => node_datas[node].lhs,
1898 1 => node_datas[node].rhs,
1985pub const LazySrcLoc = struct {
1986 /// This instruction provides the source node locations are resolved relative to.
1987 /// It is a `declaration`, `struct_decl`, `union_decl`, `enum_decl`, or `opaque_decl`.
1988 /// This must be valid even if `relative` is an absolute value, since it is required to
1989 /// determine the file which the `LazySrcLoc` refers to.
1990 base_node_inst: InternPool.TrackedInst.Index,
1991 /// This field determines the source location relative to `base_node_inst`.
1992 offset: Offset,
1993
1994 pub const Offset = union(enum) {
1995 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1996 /// that all code paths which would need to resolve the source location are
1997 /// unreachable. If you are debugging this tag incorrectly being this value,
1998 /// look into using reverse-continue with a memory watchpoint to see where the
1999 /// value is being set to this tag.
2000 /// `base_node_inst` is unused.
2001 unneeded,
2002 /// Means the source location points to an entire file; not any particular
2003 /// location within the file. `file_scope` union field will be active.
2004 entire_file,
2005 /// The source location points to a byte offset within a source file,
2006 /// offset from 0. The source file is determined contextually.
2007 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2008 byte_abs: u32,
2009 /// The source location points to a token within a source file,
2010 /// offset from 0. The source file is determined contextually.
2011 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2012 token_abs: u32,
2013 /// The source location points to an AST node within a source file,
2014 /// offset from 0. The source file is determined contextually.
2015 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2016 node_abs: u32,
2017 /// The source location points to a byte offset within a source file,
2018 /// offset from the byte offset of the base node within the file.
2019 byte_offset: u32,
2020 /// This data is the offset into the token list from the base node's first token.
2021 token_offset: u32,
2022 /// The source location points to an AST node, which is this value offset
2023 /// from its containing base node AST index.
2024 node_offset: TracedOffset,
2025 /// The source location points to the main token of an AST node, found
2026 /// by taking this AST node index offset from the containing base node.
2027 node_offset_main_token: i32,
2028 /// The source location points to the beginning of a struct initializer.
2029 node_offset_initializer: i32,
2030 /// The source location points to a variable declaration type expression,
2031 /// found by taking this AST node index offset from the containing
2032 /// base node, which points to a variable declaration AST node. Next, navigate
2033 /// to the type expression.
2034 node_offset_var_decl_ty: i32,
2035 /// The source location points to the alignment expression of a var decl.
2036 node_offset_var_decl_align: i32,
2037 /// The source location points to the linksection expression of a var decl.
2038 node_offset_var_decl_section: i32,
2039 /// The source location points to the addrspace expression of a var decl.
2040 node_offset_var_decl_addrspace: i32,
2041 /// The source location points to the initializer of a var decl.
2042 node_offset_var_decl_init: i32,
2043 /// The source location points to the given argument of a builtin function call.
2044 /// `builtin_call_node` points to the builtin call.
2045 /// `arg_index` is the index of the argument which hte source location refers to.
2046 node_offset_builtin_call_arg: struct {
2047 builtin_call_node: i32,
2048 arg_index: u32,
2049 },
2050 /// Like `node_offset_builtin_call_arg` but recurses through arbitrarily many calls
2051 /// to pointer cast builtins (taking the first argument of the most nested).
2052 node_offset_ptrcast_operand: i32,
2053 /// The source location points to the index expression of an array access
2054 /// expression, found by taking this AST node index offset from the containing
2055 /// base node, which points to an array access AST node. Next, navigate
2056 /// to the index expression.
2057 node_offset_array_access_index: i32,
2058 /// The source location points to the LHS of a slice expression
2059 /// expression, found by taking this AST node index offset from the containing
2060 /// base node, which points to a slice AST node. Next, navigate
2061 /// to the sentinel expression.
2062 node_offset_slice_ptr: i32,
2063 /// The source location points to start expression of a slice expression
2064 /// expression, found by taking this AST node index offset from the containing
2065 /// base node, which points to a slice AST node. Next, navigate
2066 /// to the sentinel expression.
2067 node_offset_slice_start: i32,
2068 /// The source location points to the end expression of a slice
2069 /// expression, found by taking this AST node index offset from the containing
2070 /// base node, which points to a slice AST node. Next, navigate
2071 /// to the sentinel expression.
2072 node_offset_slice_end: i32,
2073 /// The source location points to the sentinel expression of a slice
2074 /// expression, found by taking this AST node index offset from the containing
2075 /// base node, which points to a slice AST node. Next, navigate
2076 /// to the sentinel expression.
2077 node_offset_slice_sentinel: i32,
2078 /// The source location points to the callee expression of a function
2079 /// call expression, found by taking this AST node index offset from the containing
2080 /// base node, which points to a function call AST node. Next, navigate
2081 /// to the callee expression.
2082 node_offset_call_func: i32,
2083 /// The payload is offset from the containing base node.
2084 /// The source location points to the field name of:
2085 /// * a field access expression (`a.b`), or
2086 /// * the callee of a method call (`a.b()`)
2087 node_offset_field_name: i32,
2088 /// The payload is offset from the containing base node.
2089 /// The source location points to the field name of the operand ("b" node)
2090 /// of a field initialization expression (`.a = b`)
2091 node_offset_field_name_init: i32,
2092 /// The source location points to the pointer of a pointer deref expression,
2093 /// found by taking this AST node index offset from the containing
2094 /// base node, which points to a pointer deref AST node. Next, navigate
2095 /// to the pointer expression.
2096 node_offset_deref_ptr: i32,
2097 /// The source location points to the assembly source code of an inline assembly
2098 /// expression, found by taking this AST node index offset from the containing
2099 /// base node, which points to inline assembly AST node. Next, navigate
2100 /// to the asm template source code.
2101 node_offset_asm_source: i32,
2102 /// The source location points to the return type of an inline assembly
2103 /// expression, found by taking this AST node index offset from the containing
2104 /// base node, which points to inline assembly AST node. Next, navigate
2105 /// to the return type expression.
2106 node_offset_asm_ret_ty: i32,
2107 /// The source location points to the condition expression of an if
2108 /// expression, found by taking this AST node index offset from the containing
2109 /// base node, which points to an if expression AST node. Next, navigate
2110 /// to the condition expression.
2111 node_offset_if_cond: i32,
2112 /// The source location points to a binary expression, such as `a + b`, found
2113 /// by taking this AST node index offset from the containing base node.
2114 node_offset_bin_op: i32,
2115 /// The source location points to the LHS of a binary expression, found
2116 /// by taking this AST node index offset from the containing base node,
2117 /// which points to a binary expression AST node. Next, navigate to the LHS.
2118 node_offset_bin_lhs: i32,
2119 /// The source location points to the RHS of a binary expression, found
2120 /// by taking this AST node index offset from the containing base node,
2121 /// which points to a binary expression AST node. Next, navigate to the RHS.
2122 node_offset_bin_rhs: i32,
2123 /// The source location points to the operand of a switch expression, found
2124 /// by taking this AST node index offset from the containing base node,
2125 /// which points to a switch expression AST node. Next, navigate to the operand.
2126 node_offset_switch_operand: i32,
2127 /// The source location points to the else/`_` prong of a switch expression, found
2128 /// by taking this AST node index offset from the containing base node,
2129 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
2130 node_offset_switch_special_prong: i32,
2131 /// The source location points to all the ranges of a switch expression, found
2132 /// by taking this AST node index offset from the containing base node,
2133 /// which points to a switch expression AST node. Next, navigate to any of the
2134 /// range nodes. The error applies to all of them.
2135 node_offset_switch_range: i32,
2136 /// The source location points to the align expr of a function type
2137 /// expression, found by taking this AST node index offset from the containing
2138 /// base node, which points to a function type AST node. Next, navigate to
2139 /// the calling convention node.
2140 node_offset_fn_type_align: i32,
2141 /// The source location points to the addrspace expr of a function type
2142 /// expression, found by taking this AST node index offset from the containing
2143 /// base node, which points to a function type AST node. Next, navigate to
2144 /// the calling convention node.
2145 node_offset_fn_type_addrspace: i32,
2146 /// The source location points to the linksection expr of a function type
2147 /// expression, found by taking this AST node index offset from the containing
2148 /// base node, which points to a function type AST node. Next, navigate to
2149 /// the calling convention node.
2150 node_offset_fn_type_section: i32,
2151 /// The source location points to the calling convention of a function type
2152 /// expression, found by taking this AST node index offset from the containing
2153 /// base node, which points to a function type AST node. Next, navigate to
2154 /// the calling convention node.
2155 node_offset_fn_type_cc: i32,
2156 /// The source location points to the return type of a function type
2157 /// expression, found by taking this AST node index offset from the containing
2158 /// base node, which points to a function type AST node. Next, navigate to
2159 /// the return type node.
2160 node_offset_fn_type_ret_ty: i32,
2161 node_offset_param: i32,
2162 token_offset_param: i32,
2163 /// The source location points to the type expression of an `anyframe->T`
2164 /// expression, found by taking this AST node index offset from the containing
2165 /// base node, which points to a `anyframe->T` expression AST node. Next, navigate
2166 /// to the type expression.
2167 node_offset_anyframe_type: i32,
2168 /// The source location points to the string literal of `extern "foo"`, found
2169 /// by taking this AST node index offset from the containing
2170 /// base node, which points to a function prototype or variable declaration
2171 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
2172 node_offset_lib_name: i32,
2173 /// The source location points to the len expression of an `[N:S]T`
2174 /// expression, found by taking this AST node index offset from the containing
2175 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2176 /// to the len expression.
2177 node_offset_array_type_len: i32,
2178 /// The source location points to the sentinel expression of an `[N:S]T`
2179 /// expression, found by taking this AST node index offset from the containing
2180 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2181 /// to the sentinel expression.
2182 node_offset_array_type_sentinel: i32,
2183 /// The source location points to the elem expression of an `[N:S]T`
2184 /// expression, found by taking this AST node index offset from the containing
2185 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2186 /// to the elem expression.
2187 node_offset_array_type_elem: i32,
2188 /// The source location points to the operand of an unary expression.
2189 node_offset_un_op: i32,
2190 /// The source location points to the elem type of a pointer.
2191 node_offset_ptr_elem: i32,
2192 /// The source location points to the sentinel of a pointer.
2193 node_offset_ptr_sentinel: i32,
2194 /// The source location points to the align expr of a pointer.
2195 node_offset_ptr_align: i32,
2196 /// The source location points to the addrspace expr of a pointer.
2197 node_offset_ptr_addrspace: i32,
2198 /// The source location points to the bit-offset of a pointer.
2199 node_offset_ptr_bitoffset: i32,
2200 /// The source location points to the host size of a pointer.
2201 node_offset_ptr_hostsize: i32,
2202 /// The source location points to the tag type of an union or an enum.
2203 node_offset_container_tag: i32,
2204 /// The source location points to the default value of a field.
2205 node_offset_field_default: i32,
2206 /// The source location points to the type of an array or struct initializer.
2207 node_offset_init_ty: i32,
2208 /// The source location points to the LHS of an assignment.
2209 node_offset_store_ptr: i32,
2210 /// The source location points to the RHS of an assignment.
2211 node_offset_store_operand: i32,
2212 /// The source location points to the operand of a `return` statement, or
2213 /// the `return` itself if there is no explicit operand.
2214 node_offset_return_operand: i32,
2215 /// The source location points to a for loop input.
2216 for_input: struct {
2217 /// Points to the for loop AST node.
2218 for_node_offset: i32,
2219 /// Picks one of the inputs from the condition.
2220 input_index: u32,
2221 },
2222 /// The source location points to one of the captures of a for loop, found
2223 /// by taking this AST node index offset from the containing
2224 /// base node, which points to one of the input nodes of a for loop.
2225 /// Next, navigate to the corresponding capture.
2226 for_capture_from_input: i32,
2227 /// The source location points to the argument node of a function call.
2228 call_arg: struct {
2229 /// Points to the function call AST node.
2230 call_node_offset: i32,
2231 /// The index of the argument the source location points to.
2232 arg_index: u32,
2233 },
2234 fn_proto_param: FnProtoParam,
2235 fn_proto_param_type: FnProtoParam,
2236 array_cat_lhs: ArrayCat,
2237 array_cat_rhs: ArrayCat,
2238 /// The source location points to the name of the field at the given index
2239 /// of the container type declaration at the base node.
2240 container_field_name: u32,
2241 /// Like `continer_field_name`, but points at the field's default value.
2242 container_field_value: u32,
2243 /// Like `continer_field_name`, but points at the field's type.
2244 container_field_type: u32,
2245 /// Like `continer_field_name`, but points at the field's alignment.
2246 container_field_align: u32,
2247 /// The source location points to the given element/field of a struct or
2248 /// array initialization expression.
2249 init_elem: struct {
2250 /// Points to the AST node of the initialization expression.
2251 init_node_offset: i32,
2252 /// The index of the field/element the source location points to.
2253 elem_index: u32,
2254 },
2255 // The following source locations are like `init_elem`, but refer to a
2256 // field with a specific name. If such a field is not given, the entire
2257 // initialization expression is used instead.
2258 // The `i32` points to the AST node of a builtin call, whose *second*
2259 // argument is the init expression.
2260 init_field_name: i32,
2261 init_field_linkage: i32,
2262 init_field_section: i32,
2263 init_field_visibility: i32,
2264 init_field_rw: i32,
2265 init_field_locality: i32,
2266 init_field_cache: i32,
2267 init_field_library: i32,
2268 init_field_thread_local: i32,
2269 /// The source location points to the value of an item in a specific
2270 /// case of a `switch`.
2271 switch_case_item: SwitchItem,
2272 /// The source location points to the "first" value of a range item in
2273 /// a specific case of a `switch`.
2274 switch_case_item_range_first: SwitchItem,
2275 /// The source location points to the "last" value of a range item in
2276 /// a specific case of a `switch`.
2277 switch_case_item_range_last: SwitchItem,
2278 /// The source location points to the main capture of a specific case of
2279 /// a `switch`.
2280 switch_capture: SwitchCapture,
2281 /// The source location points to the "tag" capture (second capture) of
2282 /// a specific case of a `switch`.
2283 switch_tag_capture: SwitchCapture,
2284
2285 pub const FnProtoParam = struct {
2286 /// The offset of the function prototype AST node.
2287 fn_proto_node_offset: i32,
2288 /// The index of the parameter the source location points to.
2289 param_index: u32,
2290 };
2291
2292 pub const SwitchItem = struct {
2293 /// The offset of the switch AST node.
2294 switch_node_offset: i32,
2295 /// The index of the case to point to within this switch.
2296 case_idx: SwitchCaseIndex,
2297 /// The index of the item to point to within this case.
2298 item_idx: SwitchItemIndex,
2299 };
2300
2301 pub const SwitchCapture = struct {
2302 /// The offset of the switch AST node.
2303 switch_node_offset: i32,
2304 /// The index of the case whose capture to point to.
2305 case_idx: SwitchCaseIndex,
2306 };
2307
2308 pub const SwitchCaseIndex = packed struct(u32) {
2309 kind: enum(u1) { scalar, multi },
2310 index: u31,
2311
2312 pub const special: SwitchCaseIndex = @bitCast(@as(u32, std.math.maxInt(u32)));
2313 pub fn isSpecial(idx: SwitchCaseIndex) bool {
2314 return @as(u32, @bitCast(idx)) == @as(u32, @bitCast(special));
2315 }
2316 };
2317
2318 pub const SwitchItemIndex = packed struct(u32) {
2319 kind: enum(u1) { single, range },
2320 index: u31,
2321 };
2322
2323 const ArrayCat = struct {
2324 /// Points to the array concat AST node.
2325 array_cat_offset: i32,
2326 /// The index of the element the source location points to.
2327 elem_index: u32,
2328 };
2329
2330 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
2331
2332 noinline fn nodeOffsetDebug(node_offset: i32) Offset {
2333 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
2334 result.node_offset.trace.addAddr(@returnAddress(), "init");
2335 return result;
2336 }
2337
2338 fn nodeOffsetRelease(node_offset: i32) Offset {
2339 return .{ .node_offset = .{ .x = node_offset } };
2340 }
2341
2342 /// This wraps a simple integer in debug builds so that later on we can find out
2343 /// where in semantic analysis the value got set.
2344 pub const TracedOffset = struct {
2345 x: i32,
2346 trace: std.debug.Trace = std.debug.Trace.init,
2347
2348 const want_tracing = false;
2349 };
2350 };
2351
2352 pub const unneeded: LazySrcLoc = .{
2353 .base_node_inst = undefined,
2354 .offset = .unneeded,
2355 };
2356
2357 pub fn resolveBaseNode(base_node_inst: InternPool.TrackedInst.Index, zcu: *Zcu) struct { *File, Ast.Node.Index } {
2358 const want_path_digest, const zir_inst = inst: {
2359 const info = base_node_inst.resolveFull(&zcu.intern_pool);
2360 break :inst .{ info.path_digest, info.inst };
2361 };
2362 const file = file: {
2363 const index = zcu.path_digest_map.getIndex(want_path_digest).?;
2364 break :file zcu.import_table.values()[index];
2365 };
2366 assert(file.zir_loaded);
2367
2368 const zir = file.zir;
2369 const inst = zir.instructions.get(@intFromEnum(zir_inst));
2370 const base_node: Ast.Node.Index = switch (inst.tag) {
2371 .declaration => inst.data.declaration.src_node,
2372 .extended => switch (inst.data.extended.opcode) {
2373 .struct_decl => zir.extraData(Zir.Inst.StructDecl, inst.data.extended.operand).data.src_node,
2374 .union_decl => zir.extraData(Zir.Inst.UnionDecl, inst.data.extended.operand).data.src_node,
2375 .enum_decl => zir.extraData(Zir.Inst.EnumDecl, inst.data.extended.operand).data.src_node,
2376 .opaque_decl => zir.extraData(Zir.Inst.OpaqueDecl, inst.data.extended.operand).data.src_node,
2377 .reify => zir.extraData(Zir.Inst.Reify, inst.data.extended.operand).data.node,
18992378 else => unreachable,
19002379 },
1901 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + arg_index],
19022380 else => unreachable,
19032381 };
1904 return tree.nodeToSpan(param);
2382 return .{ file, base_node };
2383 }
2384
2385 /// Resolve the file and AST node of `base_node_inst` to get a resolved `SrcLoc`.
2386 /// TODO: it is incorrect to store a `SrcLoc` anywhere due to incremental compilation.
2387 /// Probably the type should be removed entirely and this resolution performed on-the-fly when needed.
2388 pub fn upgrade(lazy: LazySrcLoc, zcu: *Zcu) SrcLoc {
2389 const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);
2390 return .{
2391 .file_scope = file,
2392 .base_node = base_node,
2393 .lazy = lazy.offset,
2394 };
19052395 }
19062396};
19072397
......@@ -1910,11 +2400,6 @@ pub const CompileError = error{
19102400 OutOfMemory,
19112401 /// When this is returned, the compile error for the failure has already been recorded.
19122402 AnalysisFail,
1913 /// Returned when a compile error needed to be reported but a provided LazySrcLoc was set
1914 /// to the `unneeded` tag. The source location was, in fact, needed. It is expected that
1915 /// somewhere up the call stack, the operation will be retried after doing expensive work
1916 /// to compute a source location.
1917 NeededSourceLocation,
19182403 /// A Type or Value was needed to be used during semantic analysis, but it was not available
19192404 /// because the function is generic. This is only seen when analyzing the body of a param
19202405 /// instruction.
......@@ -1950,6 +2435,7 @@ pub fn deinit(zcu: *Zcu) void {
19502435 value.destroy(zcu);
19512436 }
19522437 zcu.import_table.deinit(gpa);
2438 zcu.path_digest_map.deinit(gpa);
19532439
19542440 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
19552441 gpa.free(path);
......@@ -2114,26 +2600,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
21142600 const stat = try source_file.stat();
21152601
21162602 const want_local_cache = file.mod == mod.main_mod;
2117 const bin_digest = hash: {
2118 var path_hash: Cache.HashHelper = .{};
2119 path_hash.addBytes(build_options.version);
2120 path_hash.add(builtin.zig_backend);
2121 if (!want_local_cache) {
2122 path_hash.addOptionalBytes(file.mod.root.root_dir.path);
2123 path_hash.addBytes(file.mod.root.sub_path);
2124 }
2125 path_hash.addBytes(file.sub_file_path);
2126 var bin: Cache.BinDigest = undefined;
2127 path_hash.hasher.final(&bin);
2128 break :hash bin;
2129 };
2130 file.path_digest = bin_digest;
21312603 const hex_digest = hex: {
21322604 var hex: Cache.HexDigest = undefined;
21332605 _ = std.fmt.bufPrint(
21342606 &hex,
21352607 "{s}",
2136 .{std.fmt.fmtSliceHexLower(&bin_digest)},
2608 .{std.fmt.fmtSliceHexLower(&file.path_digest)},
21372609 ) catch unreachable;
21382610 break :hex hex;
21392611 };
......@@ -3023,7 +3495,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
30233495 }
30243496 return error.AnalysisFail;
30253497 },
3026 error.NeededSourceLocation => unreachable,
30273498 error.GenericPoison => unreachable,
30283499 else => |e| {
30293500 decl.analysis = .sema_failure;
......@@ -3031,7 +3502,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
30313502 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
30323503 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
30333504 mod.gpa,
3034 decl.srcLoc(mod),
3505 decl.navSrcLoc(mod).upgrade(mod),
30353506 "unable to analyze: {s}",
30363507 .{@errorName(e)},
30373508 ));
......@@ -3205,7 +3676,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
32053676 decl_index,
32063677 try Module.ErrorMsg.create(
32073678 gpa,
3208 decl.srcLoc(zcu),
3679 decl.navSrcLoc(zcu).upgrade(zcu),
32093680 "invalid liveness: {s}",
32103681 .{@errorName(err)},
32113682 ),
......@@ -3229,7 +3700,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
32293700 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
32303701 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
32313702 gpa,
3232 decl.srcLoc(zcu),
3703 decl.navSrcLoc(zcu).upgrade(zcu),
32333704 "unable to codegen: {s}",
32343705 .{@errorName(err)},
32353706 ));
......@@ -3464,7 +3935,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
34643935 });
34653936 errdefer mod.destroyNamespace(new_namespace_index);
34663937
3467 const new_decl_index = try mod.allocateNewDecl(new_namespace_index, 0);
3938 const new_decl_index = try mod.allocateNewDecl(new_namespace_index);
34683939 const new_decl = mod.declPtr(new_decl_index);
34693940 errdefer @panic("TODO error handling");
34703941
......@@ -3611,7 +4082,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
36114082 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
36124083 defer analysis_arena.deinit();
36134084
3614 var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
4085 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36154086 defer comptime_err_ret_trace.deinit();
36164087
36174088 var sema: Sema = .{
......@@ -3641,11 +4112,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
36414112 var block_scope: Sema.Block = .{
36424113 .parent = null,
36434114 .sema = &sema,
3644 .src_decl = decl_index,
36454115 .namespace = decl.src_namespace,
36464116 .instructions = .{},
36474117 .inlining = null,
36484118 .is_comptime = true,
4119 .src_base_inst = decl.zir_decl_index.unwrap().?,
4120 .type_name_ctx = decl.name,
36494121 };
36504122 defer block_scope.instructions.deinit(gpa);
36514123
......@@ -3655,11 +4127,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
36554127 // We'll do some other bits with the Sema. Clear the type target index just
36564128 // in case they analyze any type.
36574129 sema.builtin_type_target_index = .none;
3658 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };
3659 const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };
3660 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
3661 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
3662 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
4130 const align_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_align = 0 });
4131 const section_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_section = 0 });
4132 const address_space_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_addrspace = 0 });
4133 const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 });
4134 const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 });
36634135 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);
36644136 const decl_ty = decl_val.typeOf(mod);
36654137
......@@ -3793,7 +4265,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
37934265 }
37944266
37954267 if (decl.is_exported) {
3796 const export_src: LazySrcLoc = .{ .token_offset = @intFromBool(decl.is_pub) };
4268 const export_src: LazySrcLoc = block_scope.src(.{ .token_offset = @intFromBool(decl.is_pub) });
37974269 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});
37984270 // The scope needs to have the decl in it.
37994271 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
......@@ -3873,6 +4345,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
38734345 keep_resolved_path = true; // It's now owned by import_table.
38744346 gop.value_ptr.* = builtin_file;
38754347 try builtin_file.addReference(zcu.*, .{ .root = mod });
4348 try zcu.path_digest_map.put(gpa, builtin_file.path_digest, {});
38764349 return .{
38774350 .file = builtin_file,
38784351 .is_new = false,
......@@ -3900,8 +4373,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
39004373 .status = .never_loaded,
39014374 .mod = mod,
39024375 .root_decl = .none,
4376 .path_digest = digest: {
4377 const want_local_cache = mod == zcu.main_mod;
4378 var path_hash: Cache.HashHelper = .{};
4379 path_hash.addBytes(build_options.version);
4380 path_hash.add(builtin.zig_backend);
4381 if (!want_local_cache) {
4382 path_hash.addOptionalBytes(mod.root.root_dir.path);
4383 path_hash.addBytes(mod.root.sub_path);
4384 }
4385 path_hash.addBytes(sub_file_path);
4386 var bin: Cache.BinDigest = undefined;
4387 path_hash.hasher.final(&bin);
4388 break :digest bin;
4389 },
39034390 };
39044391 try new_file.addReference(zcu.*, .{ .root = mod });
4392 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
39054393 return ImportFileResult{
39064394 .file = new_file,
39074395 .is_new = true,
......@@ -3910,23 +4398,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
39104398}
39114399
39124400pub fn importFile(
3913 mod: *Module,
4401 zcu: *Zcu,
39144402 cur_file: *File,
39154403 import_string: []const u8,
39164404) !ImportFileResult {
39174405 if (std.mem.eql(u8, import_string, "std")) {
3918 return mod.importPkg(mod.std_mod);
4406 return zcu.importPkg(zcu.std_mod);
39194407 }
39204408 if (std.mem.eql(u8, import_string, "root")) {
3921 return mod.importPkg(mod.root_mod);
4409 return zcu.importPkg(zcu.root_mod);
39224410 }
39234411 if (cur_file.mod.deps.get(import_string)) |pkg| {
3924 return mod.importPkg(pkg);
4412 return zcu.importPkg(pkg);
39254413 }
39264414 if (!mem.endsWith(u8, import_string, ".zig")) {
39274415 return error.ModuleNotFound;
39284416 }
3929 const gpa = mod.gpa;
4417 const gpa = zcu.gpa;
39304418
39314419 // The resolved path is used as the key in the import table, to detect if
39324420 // an import refers to the same as another, despite different relative paths
......@@ -3942,8 +4430,8 @@ pub fn importFile(
39424430 var keep_resolved_path = false;
39434431 defer if (!keep_resolved_path) gpa.free(resolved_path);
39444432
3945 const gop = try mod.import_table.getOrPut(gpa, resolved_path);
3946 errdefer _ = mod.import_table.pop();
4433 const gop = try zcu.import_table.getOrPut(gpa, resolved_path);
4434 errdefer _ = zcu.import_table.pop();
39474435 if (gop.found_existing) return ImportFileResult{
39484436 .file = gop.value_ptr.*,
39494437 .is_new = false,
......@@ -3988,7 +4476,22 @@ pub fn importFile(
39884476 .status = .never_loaded,
39894477 .mod = cur_file.mod,
39904478 .root_decl = .none,
4479 .path_digest = digest: {
4480 const want_local_cache = cur_file.mod == zcu.main_mod;
4481 var path_hash: Cache.HashHelper = .{};
4482 path_hash.addBytes(build_options.version);
4483 path_hash.add(builtin.zig_backend);
4484 if (!want_local_cache) {
4485 path_hash.addOptionalBytes(cur_file.mod.root.root_dir.path);
4486 path_hash.addBytes(cur_file.mod.root.sub_path);
4487 }
4488 path_hash.addBytes(sub_file_path);
4489 var bin: Cache.BinDigest = undefined;
4490 path_hash.hasher.final(&bin);
4491 break :digest bin;
4492 },
39914493 };
4494 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
39924495 return ImportFileResult{
39934496 .file = new_file,
39944497 .is_new = true,
......@@ -4255,12 +4758,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
42554758 const zir = namespace.file_scope.zir;
42564759 const ip = &zcu.intern_pool;
42574760
4258 const pl_node = zir.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node;
4259 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);
4761 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
4762 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
42604763 const declaration = extra.data;
42614764
42624765 const line = iter.parent_decl.src_line + declaration.line_offset;
4263 const decl_node = iter.parent_decl.relativeToNodeIndex(pl_node.src_node);
42644766
42654767 // Every Decl needs a name.
42664768 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {
......@@ -4348,14 +4850,13 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
43484850 const was_exported = decl.is_exported;
43494851 assert(decl.kind == kind); // ZIR tracking should preserve this
43504852 decl.name = decl_name;
4351 decl.src_node = decl_node;
43524853 decl.src_line = line;
43534854 decl.is_pub = declaration.flags.is_pub;
43544855 decl.is_exported = declaration.flags.is_export;
43554856 break :decl_index .{ was_exported, decl_index };
43564857 } else decl_index: {
43574858 // Create and set up a new Decl.
4358 const new_decl_index = try zcu.allocateNewDecl(namespace_index, decl_node);
4859 const new_decl_index = try zcu.allocateNewDecl(namespace_index);
43594860 const new_decl = zcu.declPtr(new_decl_index);
43604861 new_decl.kind = kind;
43614862 new_decl.name = decl_name;
......@@ -4509,7 +5010,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45095010
45105011 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));
45115012
4512 var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
5013 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
45135014 defer comptime_err_ret_trace.deinit();
45145015
45155016 // In the case of a generic function instance, this is the type of the
......@@ -4559,11 +5060,19 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45595060 var inner_block: Sema.Block = .{
45605061 .parent = null,
45615062 .sema = &sema,
4562 .src_decl = decl_index,
45635063 .namespace = decl.src_namespace,
45645064 .instructions = .{},
45655065 .inlining = null,
45665066 .is_comptime = false,
5067 .src_base_inst = inst: {
5068 const owner_info = if (func.generic_owner == .none)
5069 func
5070 else
5071 mod.funcInfo(func.generic_owner);
5072 const orig_decl = mod.declPtr(owner_info.owner_decl);
5073 break :inst orig_decl.zir_decl_index.unwrap().?;
5074 },
5075 .type_name_ctx = decl.name,
45675076 };
45685077 defer inner_block.instructions.deinit(gpa);
45695078
......@@ -4605,7 +5114,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46055114 runtime_param_index += 1;
46065115
46075116 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {
4608 error.NeededSourceLocation => unreachable,
46095117 error.GenericPoison => unreachable,
46105118 error.ComptimeReturn => unreachable,
46115119 error.ComptimeBreak => unreachable,
......@@ -4639,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46395147
46405148 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
46415149 // TODO make these unreachable instead of @panic
4642 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
46435150 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
46445151 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
46455152 else => |e| return e,
......@@ -4661,7 +5168,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46615168 {
46625169 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
46635170 // TODO make these unreachable instead of @panic
4664 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
46655171 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
46665172 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
46675173 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),
......@@ -4682,8 +5188,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46825188 // state to success, so that "unable to resolve inferred error set" errors
46835189 // can be emitted here.
46845190 if (sema.fn_ret_ty_ies) |ies| {
4685 sema.resolveInferredErrorSetPtr(&inner_block, LazySrcLoc.nodeOffset(0), ies) catch |err| switch (err) {
4686 error.NeededSourceLocation => unreachable,
5191 sema.resolveInferredErrorSetPtr(&inner_block, .{
5192 .base_node_inst = inner_block.src_base_inst,
5193 .offset = LazySrcLoc.Offset.nodeOffset(0),
5194 }, ies) catch |err| switch (err) {
46875195 error.GenericPoison => unreachable,
46885196 error.ComptimeReturn => unreachable,
46895197 error.ComptimeBreak => unreachable,
......@@ -4707,7 +5215,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
47075215 // so that dependencies on the function body will now be satisfied rather than
47085216 // result in circular dependency errors.
47095217 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {
4710 error.NeededSourceLocation => unreachable,
47115218 error.GenericPoison => unreachable,
47125219 error.ComptimeReturn => unreachable,
47135220 error.ComptimeBreak => unreachable,
......@@ -4724,7 +5231,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
47245231 // the backends.
47255232 for (sema.types_to_resolve.keys()) |ty| {
47265233 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {
4727 error.NeededSourceLocation => unreachable,
47285234 error.GenericPoison => unreachable,
47295235 error.ComptimeReturn => unreachable,
47305236 error.ComptimeBreak => unreachable,
......@@ -4752,17 +5258,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
47525258 return mod.intern_pool.destroyNamespace(mod.gpa, index);
47535259}
47545260
4755pub fn allocateNewDecl(
4756 mod: *Module,
4757 namespace: Namespace.Index,
4758 src_node: Ast.Node.Index,
4759) !Decl.Index {
4760 const ip = &mod.intern_pool;
4761 const gpa = mod.gpa;
4762 const decl_index = try ip.createDecl(gpa, .{
5261pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
5262 const gpa = zcu.gpa;
5263 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
47635264 .name = undefined,
47645265 .src_namespace = namespace,
4765 .src_node = src_node,
47665266 .src_line = undefined,
47675267 .has_tv = false,
47685268 .owns_tv = false,
......@@ -4777,10 +5277,10 @@ pub fn allocateNewDecl(
47775277 .kind = .anon,
47785278 });
47795279
4780 if (mod.emit_h) |mod_emit_h| {
4781 if (@intFromEnum(decl_index) >= mod_emit_h.allocated_emit_h.len) {
4782 try mod_emit_h.allocated_emit_h.append(gpa, .{});
4783 assert(@intFromEnum(decl_index) == mod_emit_h.allocated_emit_h.len);
5280 if (zcu.emit_h) |zcu_emit_h| {
5281 if (@intFromEnum(decl_index) >= zcu_emit_h.allocated_emit_h.len) {
5282 try zcu_emit_h.allocated_emit_h.append(gpa, .{});
5283 assert(@intFromEnum(decl_index) == zcu_emit_h.allocated_emit_h.len);
47845284 }
47855285 }
47865286
......@@ -4874,376 +5374,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
48745374 }
48755375}
48765376
4877pub const SwitchProngSrc = union(enum) {
4878 /// The item for a scalar prong.
4879 scalar: u32,
4880 /// A given single item for a multi prong.
4881 multi: Multi,
4882 /// A given range item for a multi prong.
4883 range: Multi,
4884 /// The item for the special prong.
4885 special,
4886 /// The main capture for a scalar prong.
4887 scalar_capture: u32,
4888 /// The main capture for a multi prong.
4889 multi_capture: u32,
4890 /// The main capture for the special prong.
4891 special_capture,
4892 /// The tag capture for a scalar prong.
4893 scalar_tag_capture: u32,
4894 /// The tag capture for a multi prong.
4895 multi_tag_capture: u32,
4896 /// The tag capture for the special prong.
4897 special_tag_capture,
4898
4899 pub const Multi = struct {
4900 prong: u32,
4901 item: u32,
4902 };
4903
4904 pub const RangeExpand = enum { none, first, last };
4905
4906 /// This function is intended to be called only when it is certain that we need
4907 /// the LazySrcLoc in order to emit a compile error.
4908 pub fn resolve(
4909 prong_src: SwitchProngSrc,
4910 mod: *Module,
4911 decl: *Decl,
4912 switch_node_offset: i32,
4913 /// Ignored if `prong_src` is not `.range`
4914 range_expand: RangeExpand,
4915 ) LazySrcLoc {
4916 @setCold(true);
4917 const gpa = mod.gpa;
4918 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
4919 // In this case we emit a warning + a less precise source location.
4920 log.warn("unable to load {s}: {s}", .{
4921 decl.getFileScope(mod).sub_file_path, @errorName(err),
4922 });
4923 return LazySrcLoc.nodeOffset(0);
4924 };
4925 const switch_node = decl.relativeToNodeIndex(switch_node_offset);
4926 const main_tokens = tree.nodes.items(.main_token);
4927 const node_datas = tree.nodes.items(.data);
4928 const node_tags = tree.nodes.items(.tag);
4929 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
4930 const case_nodes = tree.extra_data[extra.start..extra.end];
4931
4932 var multi_i: u32 = 0;
4933 var scalar_i: u32 = 0;
4934 const case_node = for (case_nodes) |case_node| {
4935 const case = tree.fullSwitchCase(case_node).?;
4936
4937 const is_special = special: {
4938 if (case.ast.values.len == 0) break :special true;
4939 if (case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .identifier) {
4940 break :special mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_");
4941 }
4942 break :special false;
4943 };
4944
4945 if (is_special) {
4946 switch (prong_src) {
4947 .special, .special_capture, .special_tag_capture => break case_node,
4948 else => continue,
4949 }
4950 }
4951
4952 const is_multi = case.ast.values.len != 1 or
4953 node_tags[case.ast.values[0]] == .switch_range;
4954
4955 switch (prong_src) {
4956 .scalar,
4957 .scalar_capture,
4958 .scalar_tag_capture,
4959 => |i| if (!is_multi and i == scalar_i) break case_node,
4960
4961 .multi_capture,
4962 .multi_tag_capture,
4963 => |i| if (is_multi and i == multi_i) break case_node,
4964
4965 .multi,
4966 .range,
4967 => |m| if (is_multi and m.prong == multi_i) break case_node,
4968
4969 .special,
4970 .special_capture,
4971 .special_tag_capture,
4972 => {},
4973 }
4974
4975 if (is_multi) {
4976 multi_i += 1;
4977 } else {
4978 scalar_i += 1;
4979 }
4980 } else unreachable;
4981
4982 const case = tree.fullSwitchCase(case_node).?;
4983
4984 switch (prong_src) {
4985 .scalar, .special => return LazySrcLoc.nodeOffset(
4986 decl.nodeIndexToRelative(case.ast.values[0]),
4987 ),
4988 .multi => |m| {
4989 var item_i: u32 = 0;
4990 for (case.ast.values) |item_node| {
4991 if (node_tags[item_node] == .switch_range) continue;
4992 if (item_i == m.item) return LazySrcLoc.nodeOffset(
4993 decl.nodeIndexToRelative(item_node),
4994 );
4995 item_i += 1;
4996 }
4997 unreachable;
4998 },
4999 .range => |m| {
5000 var range_i: u32 = 0;
5001 for (case.ast.values) |range| {
5002 if (node_tags[range] != .switch_range) continue;
5003 if (range_i == m.item) switch (range_expand) {
5004 .none => return LazySrcLoc.nodeOffset(
5005 decl.nodeIndexToRelative(range),
5006 ),
5007 .first => return LazySrcLoc.nodeOffset(
5008 decl.nodeIndexToRelative(node_datas[range].lhs),
5009 ),
5010 .last => return LazySrcLoc.nodeOffset(
5011 decl.nodeIndexToRelative(node_datas[range].rhs),
5012 ),
5013 };
5014 range_i += 1;
5015 }
5016 unreachable;
5017 },
5018 .scalar_capture, .multi_capture, .special_capture => {
5019 return .{ .node_offset_switch_prong_capture = decl.nodeIndexToRelative(case_node) };
5020 },
5021 .scalar_tag_capture, .multi_tag_capture, .special_tag_capture => {
5022 return .{ .node_offset_switch_prong_tag_capture = decl.nodeIndexToRelative(case_node) };
5023 },
5024 }
5025 }
5026};
5027
5028pub const PeerTypeCandidateSrc = union(enum) {
5029 /// Do not print out error notes for candidate sources
5030 none: void,
5031 /// When we want to know the the src of candidate i, look up at
5032 /// index i in this slice
5033 override: []const ?LazySrcLoc,
5034 /// resolvePeerTypes originates from a @TypeOf(...) call
5035 typeof_builtin_call_node_offset: i32,
5036
5037 pub fn resolve(
5038 self: PeerTypeCandidateSrc,
5039 mod: *Module,
5040 decl: *Decl,
5041 candidate_i: usize,
5042 ) ?LazySrcLoc {
5043 @setCold(true);
5044 const gpa = mod.gpa;
5045
5046 switch (self) {
5047 .none => {
5048 return null;
5049 },
5050 .override => |candidate_srcs| {
5051 if (candidate_i >= candidate_srcs.len)
5052 return null;
5053 return candidate_srcs[candidate_i];
5054 },
5055 .typeof_builtin_call_node_offset => |node_offset| {
5056 switch (candidate_i) {
5057 0 => return LazySrcLoc{ .node_offset_builtin_call_arg0 = node_offset },
5058 1 => return LazySrcLoc{ .node_offset_builtin_call_arg1 = node_offset },
5059 2 => return LazySrcLoc{ .node_offset_builtin_call_arg2 = node_offset },
5060 3 => return LazySrcLoc{ .node_offset_builtin_call_arg3 = node_offset },
5061 4 => return LazySrcLoc{ .node_offset_builtin_call_arg4 = node_offset },
5062 5 => return LazySrcLoc{ .node_offset_builtin_call_arg5 = node_offset },
5063 else => {},
5064 }
5065
5066 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5067 // In this case we emit a warning + a less precise source location.
5068 log.warn("unable to load {s}: {s}", .{
5069 decl.getFileScope(mod).sub_file_path, @errorName(err),
5070 });
5071 return LazySrcLoc.nodeOffset(0);
5072 };
5073 const node = decl.relativeToNodeIndex(node_offset);
5074 const node_datas = tree.nodes.items(.data);
5075 const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
5076
5077 return LazySrcLoc{ .node_abs = params[candidate_i] };
5078 },
5079 }
5080 }
5081};
5082
5083const FieldSrcQuery = struct {
5084 index: usize,
5085 range: enum { name, type, value, alignment } = .name,
5086};
5087
5088fn queryFieldSrc(
5089 tree: Ast,
5090 query: FieldSrcQuery,
5091 file_scope: *File,
5092 container_decl: Ast.full.ContainerDecl,
5093) SrcLoc {
5094 var field_index: usize = 0;
5095 for (container_decl.ast.members) |member_node| {
5096 const field = tree.fullContainerField(member_node) orelse continue;
5097 if (field_index == query.index) {
5098 return switch (query.range) {
5099 .name => .{
5100 .file_scope = file_scope,
5101 .parent_decl_node = 0,
5102 .lazy = .{ .token_abs = field.ast.main_token },
5103 },
5104 .type => .{
5105 .file_scope = file_scope,
5106 .parent_decl_node = 0,
5107 .lazy = .{ .node_abs = field.ast.type_expr },
5108 },
5109 .value => .{
5110 .file_scope = file_scope,
5111 .parent_decl_node = 0,
5112 .lazy = .{ .node_abs = field.ast.value_expr },
5113 },
5114 .alignment => .{
5115 .file_scope = file_scope,
5116 .parent_decl_node = 0,
5117 .lazy = .{ .node_abs = field.ast.align_expr },
5118 },
5119 };
5120 }
5121 field_index += 1;
5122 }
5123 unreachable;
5124}
5125
5126pub fn paramSrc(
5127 func_node_offset: i32,
5128 mod: *Module,
5129 decl: *Decl,
5130 param_i: usize,
5131) LazySrcLoc {
5132 @setCold(true);
5133 const gpa = mod.gpa;
5134 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5135 // In this case we emit a warning + a less precise source location.
5136 log.warn("unable to load {s}: {s}", .{
5137 decl.getFileScope(mod).sub_file_path, @errorName(err),
5138 });
5139 return LazySrcLoc.nodeOffset(0);
5140 };
5141 const node = decl.relativeToNodeIndex(func_node_offset);
5142 var buf: [1]Ast.Node.Index = undefined;
5143 const full = tree.fullFnProto(&buf, node).?;
5144 var it = full.iterate(tree);
5145 var i: usize = 0;
5146 while (it.next()) |param| : (i += 1) {
5147 if (i == param_i) {
5148 if (param.anytype_ellipsis3) |some| {
5149 const main_token = tree.nodes.items(.main_token)[decl.src_node];
5150 return .{ .token_offset_param = @as(i32, @bitCast(some)) - @as(i32, @bitCast(main_token)) };
5151 }
5152 return .{ .node_offset_param = decl.nodeIndexToRelative(param.type_expr) };
5153 }
5154 }
5155 unreachable;
5156}
5157
5158pub fn initSrc(
5159 mod: *Module,
5160 init_node_offset: i32,
5161 decl: *Decl,
5162 init_index: usize,
5163) LazySrcLoc {
5164 @setCold(true);
5165 const gpa = mod.gpa;
5166 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5167 // In this case we emit a warning + a less precise source location.
5168 log.warn("unable to load {s}: {s}", .{
5169 decl.getFileScope(mod).sub_file_path, @errorName(err),
5170 });
5171 return LazySrcLoc.nodeOffset(0);
5172 };
5173 const node_tags = tree.nodes.items(.tag);
5174 const node = decl.relativeToNodeIndex(init_node_offset);
5175 var buf: [2]Ast.Node.Index = undefined;
5176 switch (node_tags[node]) {
5177 .array_init_one,
5178 .array_init_one_comma,
5179 .array_init_dot_two,
5180 .array_init_dot_two_comma,
5181 .array_init_dot,
5182 .array_init_dot_comma,
5183 .array_init,
5184 .array_init_comma,
5185 => {
5186 const full = tree.fullArrayInit(&buf, node).?.ast.elements;
5187 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index]));
5188 },
5189 .struct_init_one,
5190 .struct_init_one_comma,
5191 .struct_init_dot_two,
5192 .struct_init_dot_two_comma,
5193 .struct_init_dot,
5194 .struct_init_dot_comma,
5195 .struct_init,
5196 .struct_init_comma,
5197 => {
5198 const full = tree.fullStructInit(&buf, node).?.ast.fields;
5199 return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) };
5200 },
5201 else => return LazySrcLoc.nodeOffset(init_node_offset),
5202 }
5203}
5204
5205pub fn optionsSrc(mod: *Module, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
5206 @setCold(true);
5207 const gpa = mod.gpa;
5208 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5209 // In this case we emit a warning + a less precise source location.
5210 log.warn("unable to load {s}: {s}", .{
5211 decl.getFileScope(mod).sub_file_path, @errorName(err),
5212 });
5213 return LazySrcLoc.nodeOffset(0);
5214 };
5215
5216 const o_i: struct { off: i32, i: u8 } = switch (base_src) {
5217 .node_offset_builtin_call_arg0 => |n| .{ .off = n, .i = 0 },
5218 .node_offset_builtin_call_arg1 => |n| .{ .off = n, .i = 1 },
5219 else => unreachable,
5220 };
5221
5222 const node = decl.relativeToNodeIndex(o_i.off);
5223 const node_datas = tree.nodes.items(.data);
5224 const node_tags = tree.nodes.items(.tag);
5225 const arg_node = switch (node_tags[node]) {
5226 .builtin_call_two, .builtin_call_two_comma => switch (o_i.i) {
5227 0 => node_datas[node].lhs,
5228 1 => node_datas[node].rhs,
5229 else => unreachable,
5230 },
5231 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + o_i.i],
5232 else => unreachable,
5233 };
5234 var buf: [2]std.zig.Ast.Node.Index = undefined;
5235 const init_nodes = if (tree.fullStructInit(&buf, arg_node)) |struct_init| struct_init.ast.fields else return base_src;
5236 for (init_nodes) |init_node| {
5237 // . IDENTIFIER = init_node
5238 const name_token = tree.firstToken(init_node) - 2;
5239 const name = tree.tokenSlice(name_token);
5240 if (std.mem.eql(u8, name, wanted)) {
5241 return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(init_node) };
5242 }
5243 }
5244 return base_src;
5245}
5246
52475377/// Called from `Compilation.update`, after everything is done, just before
52485378/// reporting compile errors. In this function we emit exported symbol collision
52495379/// errors and communicate exported symbols to the linker backend.
......@@ -5477,7 +5607,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
54775607 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
54785608 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
54795609 gpa,
5480 decl.srcLoc(zcu),
5610 decl.navSrcLoc(zcu).upgrade(zcu),
54815611 "unable to codegen: {s}",
54825612 .{@errorName(err)},
54835613 ));
......@@ -5508,7 +5638,7 @@ fn reportRetryableFileError(
55085638 mod.gpa,
55095639 .{
55105640 .file_scope = file,
5511 .parent_decl_node = 0,
5641 .base_node = 0,
55125642 .lazy = .entire_file,
55135643 },
55145644 format,
......@@ -6083,27 +6213,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func
60836213 return mod.intern_pool.indexToKey(func_index).func;
60846214}
60856215
6086pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQuery) SrcLoc {
6087 @setCold(true);
6088 const owner_decl = mod.declPtr(owner_decl_index);
6089 const file = owner_decl.getFileScope(mod);
6090 const tree = file.getTree(mod.gpa) catch |err| {
6091 // In this case we emit a warning + a less precise source location.
6092 log.warn("unable to load {s}: {s}", .{
6093 file.sub_file_path, @errorName(err),
6094 });
6095 return owner_decl.srcLoc(mod);
6096 };
6097 const node = owner_decl.relativeToNodeIndex(0);
6098 var buf: [2]Ast.Node.Index = undefined;
6099 if (tree.fullContainerDecl(&buf, node)) |container_decl| {
6100 return queryFieldSrc(tree.*, query, file, container_decl);
6101 } else {
6102 // This type was generated using @Type
6103 return owner_decl.srcLoc(mod);
6104 }
6105}
6106
61076216pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
61086217 return mod.intern_pool.toEnum(E, val.toIntern());
61096218}
src/RangeSet.zig+4-4
......@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;
77const Value = @import("Value.zig");
88const Module = @import("Module.zig");
99const RangeSet = @This();
10const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;
10const LazySrcLoc = @import("Module.zig").LazySrcLoc;
1111
1212ranges: std.ArrayList(Range),
1313module: *Module,
......@@ -15,7 +15,7 @@ module: *Module,
1515pub const Range = struct {
1616 first: InternPool.Index,
1717 last: InternPool.Index,
18 src: SwitchProngSrc,
18 src: LazySrcLoc,
1919};
2020
2121pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {
......@@ -33,8 +33,8 @@ pub fn add(
3333 self: *RangeSet,
3434 first: InternPool.Index,
3535 last: InternPool.Index,
36 src: SwitchProngSrc,
37) !?SwitchProngSrc {
36 src: LazySrcLoc,
37) !?LazySrcLoc {
3838 const mod = self.module;
3939 const ip = &mod.intern_pool;
4040
src/Sema.zig+1789-1906
......@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},
1616air_extra: std.ArrayListUnmanaged(u32) = .{},
1717/// Maps ZIR to AIR.
1818inst_map: InstMap = .{},
19/// When analyzing an inline function call, owner_decl is the Decl of the caller
20/// and `src_decl` of `Block` is the `Decl` of the callee.
21/// This `Decl` owns the arena memory of this `Sema`.
19/// When analyzing an inline function call, owner_decl is the Decl of the caller.
2220owner_decl: *Decl,
2321owner_decl_index: InternPool.DeclIndex,
2422/// For an inline or comptime function call, this will be the root parent function
......@@ -34,7 +32,7 @@ func_index: InternPool.Index,
3432func_is_naked: bool,
3533/// Used to restore the error return trace when returning a non-error from a function.
3634error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none,
37comptime_err_ret_trace: *std.ArrayList(Module.SrcLoc),
35comptime_err_ret_trace: *std.ArrayList(LazySrcLoc),
3836/// When semantic analysis needs to know the return type of the function whose body
3937/// is being analyzed, this `Type` should be used instead of going through `func`.
4038/// This will correctly handle the case of a comptime/inline function call of a
......@@ -65,9 +63,7 @@ generic_owner: InternPool.Index = .none,
6563/// instantiation callsite so that compile errors on the parameter types of the
6664/// instantiation can point back to the instantiation site in addition to the
6765/// declaration site.
68generic_call_src: LazySrcLoc = .unneeded,
69/// Corresponds to `generic_call_src`.
70generic_call_decl: InternPool.OptionalDeclIndex = .none,
66generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
7167/// The key is types that must be fully resolved prior to machine code
7268/// generation pass. Types are added to this set when resolving them
7369/// immediately could cause a dependency loop, but they do need to be resolved
......@@ -131,7 +127,6 @@ const MaybeComptimeAlloc = struct {
131127 /// If the instruction is one of these three tags, `src` may be `.unneeded`.
132128 stores: std.MultiArrayList(struct {
133129 inst: Air.Inst.Index,
134 src_decl: InternPool.DeclIndex,
135130 src: LazySrcLoc,
136131 }) = .{},
137132};
......@@ -182,7 +177,7 @@ const Namespace = Module.Namespace;
182177const CompileError = Module.CompileError;
183178const SemaError = Module.SemaError;
184179const Decl = Module.Decl;
185const LazySrcLoc = std.zig.LazySrcLoc;
180const LazySrcLoc = Zcu.LazySrcLoc;
186181const RangeSet = @import("RangeSet.zig");
187182const target_util = @import("target.zig");
188183const Package = @import("Package.zig");
......@@ -345,7 +340,6 @@ pub const Block = struct {
345340 /// Shared among all child blocks.
346341 sema: *Sema,
347342 /// The namespace to use for lookups from this source block
348 /// When analyzing fields, this is different from src_decl.src_namespace.
349343 namespace: InternPool.NamespaceIndex,
350344 /// The AIR instructions generated for this block.
351345 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
......@@ -361,12 +355,8 @@ pub const Block = struct {
361355 label: ?*Label = null,
362356 inlining: ?*Inlining,
363357 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
364 runtime_cond: ?Module.SrcLoc = null,
365 runtime_loop: ?Module.SrcLoc = null,
366 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
367 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
368 /// for the one that will be the same for all Block instances.
369 src_decl: InternPool.DeclIndex,
358 runtime_cond: ?LazySrcLoc = null,
359 runtime_loop: ?LazySrcLoc = null,
370360 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
371361 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
372362 runtime_index: Value.RuntimeIndex = .zero,
......@@ -395,13 +385,45 @@ pub const Block = struct {
395385 /// `block` in order for codegen to match lexical scoping for debug vars.
396386 need_debug_scope: ?*bool = null,
397387
388 /// Relative source locations encountered while traversing this block should be
389 /// treated as relative to the AST node of this ZIR instruction.
390 src_base_inst: InternPool.TrackedInst.Index,
391
392 /// The name of the current "context" for naming namespace types.
393 /// The interpretation of this depends on the name strategy in ZIR, but the name
394 /// is always incorporated into the type name somehow.
395 /// See `Sema.createAnonymousDeclTypeNamed`.
396 type_name_ctx: InternPool.NullTerminatedString,
397
398 /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block.
399 /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`.
400 pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc {
401 return .{
402 .base_node_inst = block.src_base_inst,
403 .offset = offset,
404 };
405 }
406
407 fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc {
408 return block.src(.{ .node_offset_builtin_call_arg = .{
409 .builtin_call_node = builtin_call_node,
410 .arg_index = arg_index,
411 } });
412 }
413
414 fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc {
415 return block.src(LazySrcLoc.Offset.nodeOffset(node_offset));
416 }
417
418 fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc {
419 return block.src(.{ .token_offset = tok_offset });
420 }
421
398422 const ComptimeReason = union(enum) {
399423 c_import: struct {
400 block: *Block,
401424 src: LazySrcLoc,
402425 },
403426 comptime_ret_ty: struct {
404 block: *Block,
405427 func: Air.Inst.Ref,
406428 func_src: LazySrcLoc,
407429 return_ty: Type,
......@@ -413,27 +435,23 @@ pub const Block = struct {
413435 const prefix = "expression is evaluated at comptime because ";
414436 switch (cr) {
415437 .c_import => |ci| {
416 try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{});
438 try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{});
417439 },
418440 .comptime_ret_ty => |rt| {
419 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {
420 var src_loc = fn_decl.srcLoc(mod);
421 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
422 break :blk src_loc;
423 } else blk: {
424 const src_decl = mod.declPtr(rt.block.src_decl);
425 break :blk src_decl.toSrcLoc(rt.func_src, mod);
426 };
441 const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{
442 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
443 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
444 } else rt.func_src;
427445 if (rt.return_ty.isGenericPoison()) {
428 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
446 return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
429447 }
430 try mod.errNoteNonLazy(
431 src_loc,
448 try sema.errNote(
449 ret_ty_src,
432450 parent,
433451 prefix ++ "the function returns a comptime-only type '{}'",
434452 .{rt.return_ty.fmt(mod)},
435453 );
436 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);
454 try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty);
437455 },
438456 }
439457 }
......@@ -497,7 +515,6 @@ pub const Block = struct {
497515 return .{
498516 .parent = parent,
499517 .sema = parent.sema,
500 .src_decl = parent.src_decl,
501518 .namespace = parent.namespace,
502519 .instructions = .{},
503520 .label = null,
......@@ -513,6 +530,8 @@ pub const Block = struct {
513530 .c_import_buf = parent.c_import_buf,
514531 .error_return_trace_index = parent.error_return_trace_index,
515532 .need_debug_scope = parent.need_debug_scope,
533 .src_base_inst = parent.src_base_inst,
534 .type_name_ctx = parent.type_name_ctx,
516535 };
517536 }
518537
......@@ -803,14 +822,6 @@ pub const Block = struct {
803822 return result_index;
804823 }
805824
806 fn addUnreachable(block: *Block, src: LazySrcLoc, safety_check: bool) !void {
807 if (safety_check and block.wantSafety()) {
808 try block.sema.safetyPanic(block, src, .unreach);
809 } else {
810 _ = try block.addNoOp(.unreach);
811 }
812 }
813
814825 pub fn ownerModule(block: Block) *Package.Module {
815826 const zcu = block.sema.mod;
816827 return zcu.namespacePtr(block.namespace).file_scope.mod;
......@@ -981,9 +992,16 @@ fn analyzeBodyInner(
981992 while (true) {
982993 crash_info.setBodyIndex(i);
983994 const inst = body[i];
984 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{
985 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,
986 });
995
996 // The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away.
997 if (build_options.enable_logging) {
998 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
999 const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest;
1000 const index = mod.path_digest_map.getIndex(path_digest).?;
1001 break :sub_file_path mod.import_table.values()[index].sub_file_path;
1002 }, inst });
1003 }
1004
9871005 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
9881006 // zig fmt: off
9891007 .alloc => try sema.zirAlloc(block, inst),
......@@ -1225,7 +1243,7 @@ fn analyzeBodyInner(
12251243 .@"asm" => try sema.zirAsm( block, extended, false),
12261244 .asm_expr => try sema.zirAsm( block, extended, true),
12271245 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),
1228 .compile_log => try sema.zirCompileLog( extended),
1246 .compile_log => try sema.zirCompileLog( block, extended),
12291247 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),
12301248 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),
12311249 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
......@@ -1449,7 +1467,7 @@ fn analyzeBodyInner(
14491467 .check_comptime_control_flow => {
14501468 if (!block.is_comptime) {
14511469 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1452 const src = inst_data.src();
1470 const src = block.nodeOffset(inst_data.src_node);
14531471 const inline_block = inst_data.operand.toIndex().?;
14541472
14551473 var check_block = block;
......@@ -1463,10 +1481,9 @@ fn analyzeBodyInner(
14631481 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {
14641482 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
14651483 const msg = msg: {
1466 const msg = try sema.errMsg(block, src, "comptime control flow inside runtime block", .{});
1484 const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{});
14671485 errdefer msg.destroy(sema.gpa);
1468
1469 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
1486 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
14701487 break :msg msg;
14711488 };
14721489 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -1482,13 +1499,13 @@ fn analyzeBodyInner(
14821499 },
14831500 .restore_err_ret_index_unconditional => {
14841501 const un_node = datas[@intFromEnum(inst)].un_node;
1485 try sema.restoreErrRetIndex(block, un_node.src(), un_node.operand, .none);
1502 try sema.restoreErrRetIndex(block, block.nodeOffset(un_node.src_node), un_node.operand, .none);
14861503 i += 1;
14871504 continue;
14881505 },
14891506 .restore_err_ret_index_fn_entry => {
14901507 const un_node = datas[@intFromEnum(inst)].un_node;
1491 try sema.restoreErrRetIndex(block, un_node.src(), .none, un_node.operand);
1508 try sema.restoreErrRetIndex(block, block.nodeOffset(un_node.src_node), .none, un_node.operand);
14921509 i += 1;
14931510 continue;
14941511 },
......@@ -1510,7 +1527,7 @@ fn analyzeBodyInner(
15101527 .repeat => {
15111528 if (block.is_comptime) {
15121529 // Send comptime control flow back to the beginning of this block.
1513 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
1530 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
15141531 try sema.emitBackwardBranch(block, src);
15151532 i = 0;
15161533 continue;
......@@ -1523,7 +1540,7 @@ fn analyzeBodyInner(
15231540 },
15241541 .repeat_inline => {
15251542 // Send comptime control flow back to the beginning of this block.
1526 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
1543 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
15271544 try sema.emitBackwardBranch(block, src);
15281545 i = 0;
15291546 continue;
......@@ -1667,7 +1684,7 @@ fn analyzeBodyInner(
16671684 try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]);
16681685 block.instructions.items.len = block_index;
16691686
1670 const block_result = try sema.resolveAnalyzedBlock(block, inst_data.src(), &labeled_block.block, &labeled_block.label.merges, need_debug_scope);
1687 const block_result = try sema.resolveAnalyzedBlock(block, block.nodeOffset(inst_data.src_node), &labeled_block.block, &labeled_block.label.merges, need_debug_scope);
16711688 {
16721689 // Destroy the ad-hoc block entry so that it does not interfere with
16731690 // the next iteration of comptime control flow, if any.
......@@ -1693,7 +1710,7 @@ fn analyzeBodyInner(
16931710 }
16941711 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
16951712 const inst_data = datas[@intFromEnum(inst)].pl_node;
1696 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
1713 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
16971714 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
16981715 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
16991716 const else_body = sema.code.bodySlice(
......@@ -1713,7 +1730,7 @@ fn analyzeBodyInner(
17131730 },
17141731 .condbr_inline => blk: {
17151732 const inst_data = datas[@intFromEnum(inst)].pl_node;
1716 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
1733 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
17171734 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
17181735 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
17191736 const else_body = sema.code.bodySlice(
......@@ -1736,8 +1753,8 @@ fn analyzeBodyInner(
17361753 .@"try" => blk: {
17371754 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
17381755 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1739 const src = inst_data.src();
1740 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1756 const src = block.nodeOffset(inst_data.src_node);
1757 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17411758 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
17421759 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17431760 const err_union = try sema.resolveInst(extra.data.operand);
......@@ -1762,8 +1779,8 @@ fn analyzeBodyInner(
17621779 .try_ptr => blk: {
17631780 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
17641781 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1765 const src = inst_data.src();
1766 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1782 const src = block.nodeOffset(inst_data.src_node);
1783 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17671784 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
17681785 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17691786 const operand = try sema.resolveInst(extra.data.operand);
......@@ -1927,14 +1944,14 @@ fn resolveDestType(
19271944 // Cast builtins use their result type as the destination type, but
19281945 // it could be an anytype argument, which we can't catch in AstGen.
19291946 const msg = msg: {
1930 const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name});
1947 const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name});
19311948 errdefer msg.destroy(sema.gpa);
1932 switch (sema.genericPoisonReason(zir_ref)) {
1933 .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}),
1934 .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
1949 switch (sema.genericPoisonReason(block, zir_ref)) {
1950 .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}),
1951 .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
19351952 .unknown => {},
19361953 }
1937 try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{});
1954 try sema.errNote(src, msg, "use @as to provide explicit result type", .{});
19381955 break :msg msg;
19391956 };
19401957 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -1963,7 +1980,7 @@ const GenericPoisonReason = union(enum) {
19631980
19641981/// Backtracks through ZIR instructions to determine the reason a generic poison
19651982/// type was created. Used for error reporting.
1966fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
1983fn genericPoisonReason(sema: *Sema, block: *Block, ref: Zir.Inst.Ref) GenericPoisonReason {
19671984 var cur = ref;
19681985 while (true) {
19691986 const inst = cur.toIndex() orelse return .unknown;
......@@ -1999,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
19992016 cur = un_node.operand;
20002017 } else {
20012018 // This must be an anyopaque pointer!
2002 return .{ .anyopaque_ptr = un_node.src() };
2019 return .{ .anyopaque_ptr = block.nodeOffset(un_node.src_node) };
20032020 }
20042021 },
20052022 .call, .field_call => {
......@@ -2007,7 +2024,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
20072024 // evaluating an `anytype` function parameter.
20082025 // TODO: better source location - function decl rather than call
20092026 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2010 return .{ .anytype_param = pl_node.src() };
2027 return .{ .anytype_param = block.nodeOffset(pl_node.src_node) };
20112028 },
20122029 else => return .unknown,
20132030 }
......@@ -2039,7 +2056,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
20392056 var err_trace_block = block.makeSubBlock();
20402057 defer err_trace_block.instructions.deinit(gpa);
20412058
2042 const src: LazySrcLoc = .unneeded;
2059 const src: LazySrcLoc = LazySrcLoc.unneeded;
20432060
20442061 // var addrs: [err_return_trace_addr_count]usize = undefined;
20452062 const err_return_trace_addr_count = 32;
......@@ -2200,9 +2217,9 @@ pub fn resolveFinalDeclValue(
22002217
22012218fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
22022219 const msg = msg: {
2203 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
2220 const msg = try sema.errMsg(src, "unable to resolve comptime value", .{});
22042221 errdefer msg.destroy(sema.gpa);
2205 try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason});
2222 try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason});
22062223
22072224 if (reason.block_comptime_reason) |block_comptime_reason| {
22082225 try block_comptime_reason.explain(sema, msg);
......@@ -2229,12 +2246,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T
22292246fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
22302247 const mod = sema.mod;
22312248 const msg = msg: {
2232 const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{
2249 const msg = try sema.errMsg(src, "expected optional type, found '{}'", .{
22332250 non_optional_ty.fmt(mod),
22342251 });
22352252 errdefer msg.destroy(sema.gpa);
22362253 if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {
2237 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
2254 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
22382255 }
22392256 try addDeclaredHereNote(sema, msg, non_optional_ty);
22402257 break :msg msg;
......@@ -2245,12 +2262,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
22452262fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
22462263 const mod = sema.mod;
22472264 const msg = msg: {
2248 const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{
2265 const msg = try sema.errMsg(src, "type '{}' does not support array initialization syntax", .{
22492266 ty.fmt(mod),
22502267 });
22512268 errdefer msg.destroy(sema.gpa);
22522269 if (ty.isSlice(mod)) {
2253 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
2270 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
22542271 }
22552272 break :msg msg;
22562273 };
......@@ -2279,11 +2296,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
22792296 const zcu = sema.mod;
22802297 if (int_ty.zigTypeTag(zcu) == .Vector) {
22812298 const msg = msg: {
2282 const msg = try sema.errMsg(block, src, "overflow of vector type '{}' with value '{}'", .{
2299 const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{
22832300 int_ty.fmt(zcu), val.fmtValue(zcu, sema),
22842301 });
22852302 errdefer msg.destroy(sema.gpa);
2286 try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index});
2303 try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index});
22872304 break :msg msg;
22882305 };
22892306 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2296,15 +2313,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
22962313fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
22972314 const mod = sema.mod;
22982315 const msg = msg: {
2299 const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{});
2316 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});
23002317 errdefer msg.destroy(sema.gpa);
23012318
23022319 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;
2303 const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
2304 .index = field_index,
2305 .range = .value,
2306 });
2307 try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{});
2320 try sema.errNote(.{
2321 .base_node_inst = struct_type.zir_index.unwrap().?,
2322 .offset = .{ .container_field_value = @intCast(field_index) },
2323 }, msg, "default value set here", .{});
23082324 break :msg msg;
23092325 };
23102326 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2312,7 +2328,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
23122328
23132329fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
23142330 const msg = msg: {
2315 const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{});
2331 const msg = try sema.errMsg(src, "async has not been implemented in the self-hosted compiler yet", .{});
23162332 errdefer msg.destroy(sema.gpa);
23172333 break :msg msg;
23182334 };
......@@ -2333,9 +2349,9 @@ fn failWithInvalidFieldAccess(
23332349 const child_ty = inner_ty.optionalChild(mod);
23342350 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
23352351 const msg = msg: {
2336 const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2352 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
23372353 errdefer msg.destroy(sema.gpa);
2338 try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2354 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
23392355 break :msg msg;
23402356 };
23412357 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2343,9 +2359,9 @@ fn failWithInvalidFieldAccess(
23432359 const child_ty = inner_ty.errorUnionPayload(mod);
23442360 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
23452361 const msg = msg: {
2346 const msg = try sema.errMsg(block, src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2362 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
23472363 errdefer msg.destroy(sema.gpa);
2348 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
2364 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
23492365 break :msg msg;
23502366 };
23512367 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2378,11 +2394,11 @@ fn failWithComptimeErrorRetTrace(
23782394) CompileError {
23792395 const mod = sema.mod;
23802396 const msg = msg: {
2381 const msg = try sema.errMsg(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
2397 const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
23822398 errdefer msg.destroy(sema.gpa);
23832399
23842400 for (sema.comptime_err_ret_trace.items) |src_loc| {
2385 try mod.errNoteNonLazy(src_loc, msg, "error returned here", .{});
2401 try sema.errNote(src_loc, msg, "error returned here", .{});
23862402 }
23872403 break :msg msg;
23882404 };
......@@ -2391,17 +2407,15 @@ fn failWithComptimeErrorRetTrace(
23912407
23922408/// We don't return a pointer to the new error note because the pointer
23932409/// becomes invalid when you add another one.
2394fn errNote(
2410pub fn errNote(
23952411 sema: *Sema,
2396 block: *Block,
23972412 src: LazySrcLoc,
23982413 parent: *Module.ErrorMsg,
23992414 comptime format: []const u8,
24002415 args: anytype,
24012416) error{OutOfMemory}!void {
2402 const mod = sema.mod;
2403 const src_decl = mod.declPtr(block.src_decl);
2404 return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args);
2417 const zcu = sema.mod;
2418 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
24052419}
24062420
24072421fn addFieldErrNote(
......@@ -2413,52 +2427,23 @@ fn addFieldErrNote(
24132427 args: anytype,
24142428) !void {
24152429 @setCold(true);
2416 const mod = sema.mod;
2417 const decl_index = container_ty.getOwnerDecl(mod);
2418 const decl = mod.declPtr(decl_index);
2419
2420 const field_src = blk: {
2421 const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| {
2422 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
2423 break :blk decl.srcLoc(mod);
2424 };
2425
2426 const container_node = decl.relativeToNodeIndex(0);
2427 const node_tags = tree.nodes.items(.tag);
2428 var buf: [2]std.zig.Ast.Node.Index = undefined;
2429 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod);
2430
2431 var it_index: usize = 0;
2432 for (container_decl.ast.members) |member_node| {
2433 switch (node_tags[member_node]) {
2434 .container_field_init,
2435 .container_field_align,
2436 .container_field,
2437 => {
2438 if (it_index == field_index) {
2439 break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod);
2440 }
2441 it_index += 1;
2442 },
2443 else => continue,
2444 }
2445 }
2446 unreachable;
2430 const zcu = sema.mod;
2431 const type_src = container_ty.srcLocOrNull(zcu) orelse return;
2432 const field_src: LazySrcLoc = .{
2433 .base_node_inst = type_src.base_node_inst,
2434 .offset = .{ .container_field_name = @intCast(field_index) },
24472435 };
2448 try mod.errNoteNonLazy(field_src, parent, format, args);
2436 try sema.errNote(field_src, parent, format, args);
24492437}
24502438
24512439pub fn errMsg(
24522440 sema: *Sema,
2453 block: *Block,
24542441 src: LazySrcLoc,
24552442 comptime format: []const u8,
24562443 args: anytype,
2457) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg {
2458 const mod = sema.mod;
2459 if (src == .unneeded) return error.NeededSourceLocation;
2460 const src_decl = mod.declPtr(block.src_decl);
2461 return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args);
2444) Allocator.Error!*Module.ErrorMsg {
2445 assert(src.offset != .unneeded);
2446 return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args);
24622447}
24632448
24642449pub fn fail(
......@@ -2468,7 +2453,7 @@ pub fn fail(
24682453 comptime format: []const u8,
24692454 args: anytype,
24702455) CompileError {
2471 const err_msg = try sema.errMsg(block, src, format, args);
2456 const err_msg = try sema.errMsg(src, format, args);
24722457 inline for (args) |arg| {
24732458 if (@TypeOf(arg) == Type.Formatter) {
24742459 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
......@@ -2502,7 +2487,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25022487 var block_it = start_block;
25032488 while (block_it.inlining) |inlining| {
25042489 try sema.errNote(
2505 inlining.call_block,
25062490 inlining.call_src,
25072491 err_msg,
25082492 "called from here",
......@@ -2536,7 +2520,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25362520 const decl = mod.declPtr(ref.referencer);
25372521 try reference_stack.append(.{
25382522 .decl = decl.name,
2539 .src_loc = decl.toSrcLoc(ref.src, mod),
2523 .src_loc = ref.src.upgrade(mod),
25402524 });
25412525 }
25422526 referenced_by = ref.referencer;
......@@ -2571,15 +2555,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25712555/// Reference trace is preserved.
25722556fn reparentOwnedErrorMsg(
25732557 sema: *Sema,
2574 block: *Block,
25752558 src: LazySrcLoc,
25762559 msg: *Module.ErrorMsg,
25772560 comptime format: []const u8,
25782561 args: anytype,
25792562) !void {
25802563 const mod = sema.mod;
2581 const src_decl = mod.declPtr(block.src_decl);
2582 const resolved_src = src_decl.toSrcLoc(src, mod);
2564 const resolved_src = src.upgrade(mod);
25832565 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25842566
25852567 const orig_notes = msg.notes.len;
......@@ -2716,7 +2698,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27162698 sema.code.nullTerminatedString(str),
27172699 .no_embedded_nulls,
27182700 );
2719 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2701 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
27202702 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
27212703 },
27222704 .decl_ref => |str| capture: {
......@@ -2725,7 +2707,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27252707 sema.code.nullTerminatedString(str),
27262708 .no_embedded_nulls,
27272709 );
2728 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2710 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
27292711 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
27302712 },
27312713 };
......@@ -2776,7 +2758,13 @@ fn zirStructDecl(
27762758 const ip = &mod.intern_pool;
27772759 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
27782760 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
2779 const src = extra.data.src();
2761
2762 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2763 const src: LazySrcLoc = .{
2764 .base_node_inst = tracked_inst,
2765 .offset = LazySrcLoc.Offset.nodeOffset(0),
2766 };
2767
27802768 var extra_index = extra.end;
27812769
27822770 const captures_len = if (small.has_captures_len) blk: {
......@@ -2820,7 +2808,7 @@ fn zirStructDecl(
28202808 .any_aligned_fields = small.any_aligned_fields,
28212809 .has_namespace = true or decls_len > 0, // TODO: see below
28222810 .key = .{ .declared = .{
2823 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
2811 .zir_index = tracked_inst,
28242812 .captures = captures,
28252813 } },
28262814 };
......@@ -2835,11 +2823,11 @@ fn zirStructDecl(
28352823
28362824 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
28372825 block,
2838 src,
28392826 Value.fromInterned(wip_ty.index),
28402827 small.name_strategy,
28412828 "struct",
28422829 inst,
2830 extra.data.src_line,
28432831 );
28442832 mod.declPtr(new_decl_index).owns_tv = true;
28452833 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -2872,42 +2860,26 @@ fn zirStructDecl(
28722860fn createAnonymousDeclTypeNamed(
28732861 sema: *Sema,
28742862 block: *Block,
2875 src: LazySrcLoc,
28762863 val: Value,
28772864 name_strategy: Zir.Inst.NameStrategy,
28782865 anon_prefix: []const u8,
28792866 inst: ?Zir.Inst.Index,
2867 src_line: u32,
28802868) !InternPool.DeclIndex {
28812869 const zcu = sema.mod;
28822870 const ip = &zcu.intern_pool;
28832871 const gpa = sema.gpa;
28842872 const namespace = block.namespace;
2885 const src_decl = zcu.declPtr(block.src_decl);
2886 const src_node = src_decl.relativeToNodeIndex(src.node_offset.x);
2887 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);
2873 const new_decl_index = try zcu.allocateNewDecl(namespace);
28882874 errdefer zcu.destroyDecl(new_decl_index);
28892875
28902876 switch (name_strategy) {
2891 .anon => {
2892 // It would be neat to have "struct:line:column" but this name has
2893 // to survive incremental updates, where it may have been shifted down
2894 // or up to a different line, but unchanged, and thus not unnecessarily
2895 // semantically analyzed.
2896 // This name is also used as the key in the parent namespace so it cannot be
2897 // renamed.
2898
2899 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2900 src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2901 }, .no_embedded_nulls) catch unreachable;
2902 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2903 return new_decl_index;
2904 },
2877 .anon => {}, // handled after switch
29052878 .parent => {
2906 const name = zcu.declPtr(block.src_decl).name;
2907 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2879 try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx);
29082880 return new_decl_index;
29092881 },
2910 .func => {
2882 .func => func_strat: {
29112883 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip));
29122884 const zir_tags = sema.code.instructions.items(.tag);
29132885
......@@ -2915,7 +2887,7 @@ fn createAnonymousDeclTypeNamed(
29152887 defer buf.deinit();
29162888
29172889 const writer = buf.writer();
2918 try writer.print("{}(", .{zcu.declPtr(block.src_decl).name.fmt(ip)});
2890 try writer.print("{}(", .{block.type_name_ctx.fmt(ip)});
29192891
29202892 var arg_i: usize = 0;
29212893 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
......@@ -2926,8 +2898,7 @@ fn createAnonymousDeclTypeNamed(
29262898 // If not then this is a struct type being returned from a non-generic
29272899 // function and the name doesn't matter since it will later
29282900 // result in a compile error.
2929 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch
2930 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);
2901 const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat
29312902
29322903 if (arg_i != 0) try writer.writeByte(',');
29332904
......@@ -2950,7 +2921,7 @@ fn createAnonymousDeclTypeNamed(
29502921
29512922 try writer.writeByte(')');
29522923 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);
2953 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2924 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
29542925 return new_decl_index;
29552926 },
29562927 .dbg_var => {
......@@ -2962,16 +2933,31 @@ fn createAnonymousDeclTypeNamed(
29622933 if (zir_data[i].str_op.operand != ref) continue;
29632934
29642935 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{
2965 src_decl.name.fmt(ip), zir_data[i].str_op.getStr(sema.code),
2936 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
29662937 }, .no_embedded_nulls);
2967 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2938 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
29682939 return new_decl_index;
29692940 },
29702941 else => {},
29712942 };
2972 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);
2943 // fall through to anon strat
29732944 },
29742945 }
2946
2947 // anon strat handling.
2948
2949 // It would be neat to have "struct:line:column" but this name has
2950 // to survive incremental updates, where it may have been shifted down
2951 // or up to a different line, but unchanged, and thus not unnecessarily
2952 // semantically analyzed.
2953 // This name is also used as the key in the parent namespace so it cannot be
2954 // renamed.
2955
2956 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2957 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2958 }, .no_embedded_nulls) catch unreachable;
2959 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
2960 return new_decl_index;
29752961}
29762962
29772963fn zirEnumDecl(
......@@ -2990,8 +2976,9 @@ fn zirEnumDecl(
29902976 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
29912977 var extra_index: usize = extra.end;
29922978
2993 const src = extra.data.src();
2994 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
2979 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2980 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
2981 const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } };
29952982
29962983 const tag_type_ref = if (small.has_tag_type) blk: {
29972984 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
......@@ -3051,7 +3038,7 @@ fn zirEnumDecl(
30513038 .explicit,
30523039 .fields_len = fields_len,
30533040 .key = .{ .declared = .{
3054 .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst),
3041 .zir_index = tracked_inst,
30553042 .captures = captures,
30563043 } },
30573044 };
......@@ -3071,11 +3058,11 @@ fn zirEnumDecl(
30713058
30723059 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
30733060 block,
3074 src,
30753061 Value.fromInterned(wip_ty.index),
30763062 small.name_strategy,
30773063 "enum",
30783064 inst,
3065 extra.data.src_line,
30793066 );
30803067 const new_decl = mod.declPtr(new_decl_index);
30813068 new_decl.owns_tv = true;
......@@ -3132,11 +3119,12 @@ fn zirEnumDecl(
31323119 var enum_block: Block = .{
31333120 .parent = null,
31343121 .sema = sema,
3135 .src_decl = new_decl_index,
31363122 .namespace = new_namespace_index.unwrap() orelse block.namespace,
31373123 .instructions = .{},
31383124 .inlining = null,
31393125 .is_comptime = true,
3126 .src_base_inst = tracked_inst,
3127 .type_name_ctx = new_decl.name,
31403128 };
31413129 defer enum_block.instructions.deinit(sema.gpa);
31423130
......@@ -3145,9 +3133,9 @@ fn zirEnumDecl(
31453133 }
31463134
31473135 if (tag_type_ref != .none) {
3148 const ty = try sema.resolveType(block, tag_ty_src, tag_type_ref);
3136 const ty = try sema.resolveType(&enum_block, tag_ty_src, tag_type_ref);
31493137 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {
3150 return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});
3138 return sema.fail(&enum_block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});
31513139 }
31523140 break :ty ty;
31533141 } else if (fields_len == 0) {
......@@ -3184,36 +3172,33 @@ fn zirEnumDecl(
31843172
31853173 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
31863174
3175 const value_src: LazySrcLoc = .{
3176 .base_node_inst = tracked_inst,
3177 .offset = .{ .container_field_value = field_i },
3178 };
3179
31873180 const tag_overflow = if (has_tag_value) overflow: {
31883181 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
31893182 extra_index += 1;
31903183 const tag_inst = try sema.resolveInst(tag_val_ref);
3191 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
3192 error.NeededSourceLocation => {
3193 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3194 .index = field_i,
3195 .range = .value,
3196 }).lazy;
3197 _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{
3198 .needed_comptime_reason = "enum tag value must be comptime-known",
3199 });
3200 unreachable;
3201 },
3202 else => |e| return e,
3203 };
3184 last_tag_val = try sema.resolveConstDefinedValue(block, .{
3185 .base_node_inst = tracked_inst,
3186 .offset = .{ .container_field_name = field_i },
3187 }, tag_inst, .{
3188 .needed_comptime_reason = "enum tag value must be comptime-known",
3189 });
32043190 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;
32053191 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);
32063192 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
32073193 assert(conflict.kind == .value); // AstGen validated names are unique
3208 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3209 .index = field_i,
3210 .range = .value,
3211 }).lazy;
3212 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3194 const other_field_src: LazySrcLoc = .{
3195 .base_node_inst = tracked_inst,
3196 .offset = .{ .container_field_value = conflict.prev_field_idx },
3197 };
32133198 const msg = msg: {
3214 const msg = try sema.errMsg(block, value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3199 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
32153200 errdefer msg.destroy(gpa);
3216 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
3201 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
32173202 break :msg msg;
32183203 };
32193204 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3228,12 +3213,14 @@ fn zirEnumDecl(
32283213 if (overflow != null) break :overflow true;
32293214 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
32303215 assert(conflict.kind == .value); // AstGen validated names are unique
3231 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;
3232 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3216 const other_field_src: LazySrcLoc = .{
3217 .base_node_inst = tracked_inst,
3218 .offset = .{ .container_field_value = conflict.prev_field_idx },
3219 };
32333220 const msg = msg: {
3234 const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3221 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
32353222 errdefer msg.destroy(gpa);
3236 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
3223 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
32373224 break :msg msg;
32383225 };
32393226 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3248,11 +3235,7 @@ fn zirEnumDecl(
32483235 };
32493236
32503237 if (tag_overflow) {
3251 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3252 .index = field_i,
3253 .range = if (has_tag_value) .value else .name,
3254 }).lazy;
3255 const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{
3238 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{
32563239 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),
32573240 });
32583241 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3279,7 +3262,8 @@ fn zirUnionDecl(
32793262 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
32803263 var extra_index: usize = extra.end;
32813264
3282 const src = extra.data.src();
3265 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3266 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
32833267
32843268 extra_index += @intFromBool(small.has_tag_type);
32853269 const captures_len = if (small.has_captures_len) blk: {
......@@ -3327,7 +3311,7 @@ fn zirUnionDecl(
33273311 .field_types = &.{}, // set later
33283312 .field_aligns = &.{}, // set later
33293313 .key = .{ .declared = .{
3330 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
3314 .zir_index = tracked_inst,
33313315 .captures = captures,
33323316 } },
33333317 };
......@@ -3342,11 +3326,11 @@ fn zirUnionDecl(
33423326
33433327 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
33443328 block,
3345 src,
33463329 Value.fromInterned(wip_ty.index),
33473330 small.name_strategy,
33483331 "union",
33493332 inst,
3333 extra.data.src_line,
33503334 );
33513335 mod.declPtr(new_decl_index).owns_tv = true;
33523336 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -3394,7 +3378,8 @@ fn zirOpaqueDecl(
33943378 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
33953379 var extra_index: usize = extra.end;
33963380
3397 const src = extra.data.src();
3381 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3382 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
33983383
33993384 const captures_len = if (small.has_captures_len) blk: {
34003385 const captures_len = sema.code.extra[extra_index];
......@@ -3414,7 +3399,7 @@ fn zirOpaqueDecl(
34143399 const opaque_init: InternPool.OpaqueTypeInit = .{
34153400 .has_namespace = decls_len != 0,
34163401 .key = .{ .declared = .{
3417 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
3402 .zir_index = tracked_inst,
34183403 .captures = captures,
34193404 } },
34203405 };
......@@ -3430,11 +3415,11 @@ fn zirOpaqueDecl(
34303415
34313416 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
34323417 block,
3433 src,
34343418 Value.fromInterned(wip_ty.index),
34353419 small.name_strategy,
34363420 "opaque",
34373421 inst,
3422 extra.data.src_line,
34383423 );
34393424 mod.declPtr(new_decl_index).owns_tv = true;
34403425 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -3525,7 +3510,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
35253510
35263511 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
35273512 const operand = try sema.resolveInst(inst_data.operand);
3528 return sema.analyzeRef(block, inst_data.src(), operand);
3513 return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand);
35293514}
35303515
35313516fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -3534,7 +3519,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
35343519
35353520 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
35363521 const operand = try sema.resolveInst(inst_data.operand);
3537 const src = inst_data.src();
3522 const src = block.nodeOffset(inst_data.src_node);
35383523
35393524 return sema.ensureResultUsed(block, sema.typeOf(operand), src);
35403525}
......@@ -3551,19 +3536,19 @@ fn ensureResultUsed(
35513536 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
35523537 .ErrorUnion => {
35533538 const msg = msg: {
3554 const msg = try sema.errMsg(block, src, "error union is ignored", .{});
3539 const msg = try sema.errMsg(src, "error union is ignored", .{});
35553540 errdefer msg.destroy(sema.gpa);
3556 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
3541 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
35573542 break :msg msg;
35583543 };
35593544 return sema.failWithOwnedErrorMsg(block, msg);
35603545 },
35613546 else => {
35623547 const msg = msg: {
3563 const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});
3548 const msg = try sema.errMsg(src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});
35643549 errdefer msg.destroy(sema.gpa);
3565 try sema.errNote(block, src, msg, "all non-void values must be used", .{});
3566 try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{});
3550 try sema.errNote(src, msg, "all non-void values must be used", .{});
3551 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
35673552 break :msg msg;
35683553 };
35693554 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3578,15 +3563,15 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
35783563 const mod = sema.mod;
35793564 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
35803565 const operand = try sema.resolveInst(inst_data.operand);
3581 const src = inst_data.src();
3566 const src = block.nodeOffset(inst_data.src_node);
35823567 const operand_ty = sema.typeOf(operand);
35833568 switch (operand_ty.zigTypeTag(mod)) {
35843569 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
35853570 .ErrorUnion => {
35863571 const msg = msg: {
3587 const msg = try sema.errMsg(block, src, "error union is discarded", .{});
3572 const msg = try sema.errMsg(src, "error union is discarded", .{});
35883573 errdefer msg.destroy(sema.gpa);
3589 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
3574 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
35903575 break :msg msg;
35913576 };
35923577 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3601,7 +3586,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
36013586
36023587 const mod = sema.mod;
36033588 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3604 const src = inst_data.src();
3589 const src = block.nodeOffset(inst_data.src_node);
36053590 const operand = try sema.resolveInst(inst_data.operand);
36063591 const operand_ty = sema.typeOf(operand);
36073592 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)
......@@ -3612,9 +3597,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
36123597 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);
36133598 if (payload_ty != .Void and payload_ty != .NoReturn) {
36143599 const msg = msg: {
3615 const msg = try sema.errMsg(block, src, "error union payload is ignored", .{});
3600 const msg = try sema.errMsg(src, "error union payload is ignored", .{});
36163601 errdefer msg.destroy(sema.gpa);
3617 try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{});
3602 try sema.errNote(src, msg, "payload value can be explicitly ignored with '|_|'", .{});
36183603 break :msg msg;
36193604 };
36203605 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3626,7 +3611,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
36263611 defer tracy.end();
36273612
36283613 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3629 const src = inst_data.src();
3614 const src = block.nodeOffset(inst_data.src_node);
36303615 const object = try sema.resolveInst(inst_data.operand);
36313616
36323617 return indexablePtrLen(sema, block, src, object);
......@@ -3668,8 +3653,8 @@ fn zirAllocExtended(
36683653) CompileError!Air.Inst.Ref {
36693654 const gpa = sema.gpa;
36703655 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3671 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
3672 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
3656 const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node });
3657 const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node });
36733658 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);
36743659
36753660 var extra_index: usize = extra.end;
......@@ -3745,7 +3730,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
37453730 defer tracy.end();
37463731
37473732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3748 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
3733 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
37493734 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
37503735 return sema.analyzeComptimeAlloc(block, var_ty, .none);
37513736}
......@@ -3811,7 +3796,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
38113796 if (try sema.typeRequiresComptime(elem_ty)) {
38123797 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
38133798 // TODO: source location of runtime control flow
3814 const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
3799 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
38153800 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});
38163801 }
38173802
......@@ -3980,7 +3965,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
39803965 .ty = opt_ty.toIntern(),
39813966 .val = payload_val.toIntern(),
39823967 } });
3983 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);
3968 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);
39843969 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();
39853970 },
39863971 .eu_payload => ptr: {
......@@ -3993,7 +3978,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
39933978 .ty = eu_ty.toIntern(),
39943979 .val = .{ .payload = payload_val.toIntern() },
39953980 } });
3996 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);
3981 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);
39973982 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();
39983983 },
39993984 .field => |idx| ptr: {
......@@ -4006,7 +3991,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40063991 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);
40073992 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);
40083993 const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val);
4009 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
3994 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
40103995 }
40113996 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();
40123997 },
......@@ -4028,14 +4013,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40284013 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
40294014 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
40304015 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
4031 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
4016 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
40324017 },
40334018 else => unreachable,
40344019 }
40354020 }
40364021
40374022 // The value is finalized - load it!
4038 const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();
4023 const val = (try sema.pointerDeref(block, LazySrcLoc.unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();
40394024 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);
40404025}
40414026
......@@ -4138,7 +4123,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
41384123 defer tracy.end();
41394124
41404125 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4141 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4126 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
41424127 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
41434128 if (block.is_comptime) {
41444129 return sema.analyzeComptimeAlloc(block, var_ty, .none);
......@@ -4161,7 +4146,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
41614146 defer tracy.end();
41624147
41634148 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4164 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4149 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
41654150 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
41664151 if (block.is_comptime) {
41674152 return sema.analyzeComptimeAlloc(block, var_ty, .none);
......@@ -4220,8 +4205,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
42204205 const mod = sema.mod;
42214206 const gpa = sema.gpa;
42224207 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4223 const src = inst_data.src();
4224 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4208 const src = block.nodeOffset(inst_data.src_node);
4209 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
42254210 const ptr = try sema.resolveInst(inst_data.operand);
42264211 const ptr_inst = ptr.toIndex().?;
42274212 const target = mod.getTarget();
......@@ -4361,7 +4346,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43614346 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
43624347 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
43634348 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
4364 const src = inst_data.src();
4349 const src = block.nodeOffset(inst_data.src_node);
43654350
43664351 var len: Air.Inst.Ref = .none;
43674352 var len_val: ?Value = null;
......@@ -4384,20 +4369,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43844369 .Int, .ComptimeInt => true,
43854370 else => false,
43864371 };
4387 const arg_src: LazySrcLoc = .{ .for_input = .{
4372 const arg_src = block.src(.{ .for_input = .{
43884373 .for_node_offset = inst_data.src_node,
43894374 .input_index = i,
4390 } };
4375 } });
43914376 const arg_len_uncoerced = if (is_int) object else l: {
43924377 if (!object_ty.isIndexable(mod)) {
43934378 // Instead of using checkIndexable we customize this error.
43944379 const msg = msg: {
4395 const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});
4380 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});
43964381 errdefer msg.destroy(sema.gpa);
4397 try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
4382 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
43984383
43994384 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {
4400 try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
4385 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
44014386 }
44024387
44034388 break :msg msg;
......@@ -4417,16 +4402,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44174402 if (len_val) |v| {
44184403 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {
44194404 const msg = msg: {
4420 const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{});
4405 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});
44214406 errdefer msg.destroy(gpa);
4422 const a_src: LazySrcLoc = .{ .for_input = .{
4407 const a_src = block.src(.{ .for_input = .{
44234408 .for_node_offset = inst_data.src_node,
44244409 .input_index = len_idx,
4425 } };
4426 try sema.errNote(block, a_src, msg, "length {} here", .{
4410 } });
4411 try sema.errNote(a_src, msg, "length {} here", .{
44274412 v.fmtValue(sema.mod, sema),
44284413 });
4429 try sema.errNote(block, arg_src, msg, "length {} here", .{
4414 try sema.errNote(arg_src, msg, "length {} here", .{
44304415 arg_val.fmtValue(sema.mod, sema),
44314416 });
44324417 break :msg msg;
......@@ -4446,7 +4431,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44464431
44474432 if (len == .none) {
44484433 const msg = msg: {
4449 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});
4434 const msg = try sema.errMsg(src, "unbounded for loop", .{});
44504435 errdefer msg.destroy(gpa);
44514436 for (args, 0..) |zir_arg, i_usize| {
44524437 const i: u32 = @intCast(i_usize);
......@@ -4459,11 +4444,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44594444 .Int, .ComptimeInt => continue,
44604445 else => {},
44614446 }
4462 const arg_src: LazySrcLoc = .{ .for_input = .{
4447 const arg_src = block.src(.{ .for_input = .{
44634448 .for_node_offset = inst_data.src_node,
44644449 .input_index = i,
4465 } };
4466 try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{
4450 } });
4451 try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{
44674452 object_ty.fmt(sema.mod),
44684453 });
44694454 }
......@@ -4504,16 +4489,16 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL
45044489fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
45054490 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
45064491 const ptr = try sema.resolveInst(un_node.operand);
4507 return sema.optEuBasePtrInit(block, ptr, un_node.src());
4492 return sema.optEuBasePtrInit(block, ptr, block.nodeOffset(un_node.src_node));
45084493}
45094494
45104495fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
45114496 const mod = sema.mod;
45124497 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4513 const src = pl_node.src();
4498 const src = block.nodeOffset(pl_node.src_node);
45144499 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
45154500 const uncoerced_val = try sema.resolveInst(extra.rhs);
4516 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) {
4501 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) {
45174502 error.GenericPoison => return uncoerced_val,
45184503 else => |e| return e,
45194504 };
......@@ -4561,7 +4546,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
45614546fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
45624547 const mod = sema.mod;
45634548 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
4564 const src = un_tok.src();
4549 const src = block.tokenOffset(un_tok.src_tok);
45654550 // In case of GenericPoison, we don't actually have a type, so this will be
45664551 // treated as an untyped address-of operator.
45674552 const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) {
......@@ -4575,9 +4560,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
45754560 if (ty_operand.isGenericPoison()) return;
45764561 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {
45774562 return sema.failWithOwnedErrorMsg(block, msg: {
4578 const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});
4563 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});
45794564 errdefer msg.destroy(sema.gpa);
4580 try sema.errNote(block, src, msg, "address-of operator always returns a pointer", .{});
4565 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
45814566 break :msg msg;
45824567 });
45834568 }
......@@ -4590,9 +4575,9 @@ fn zirValidateArrayInitRefTy(
45904575) CompileError!Air.Inst.Ref {
45914576 const mod = sema.mod;
45924577 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4593 const src = pl_node.src();
4578 const src = block.nodeOffset(pl_node.src_node);
45944579 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
4595 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) {
4580 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) {
45964581 error.GenericPoison => return .generic_poison_type,
45974582 else => |e| return e,
45984583 };
......@@ -4632,8 +4617,8 @@ fn zirValidateArrayInitTy(
46324617) CompileError!void {
46334618 const mod = sema.mod;
46344619 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4635 const src = inst_data.src();
4636 const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node };
4620 const src = block.nodeOffset(inst_data.src_node);
4621 const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node });
46374622 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
46384623 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
46394624 // It's okay for the type to be unknown: this will result in an anonymous array init.
......@@ -4695,7 +4680,7 @@ fn zirValidateStructInitTy(
46954680) CompileError!void {
46964681 const mod = sema.mod;
46974682 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4698 const src = inst_data.src();
4683 const src = block.nodeOffset(inst_data.src_node);
46994684 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
47004685 // It's okay for the type to be unknown: this will result in an anonymous struct init.
47014686 error.GenericPoison => return,
......@@ -4720,7 +4705,7 @@ fn zirValidatePtrStructInit(
47204705
47214706 const mod = sema.mod;
47224707 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4723 const init_src = validate_inst.src();
4708 const init_src = block.nodeOffset(validate_inst.src_node);
47244709 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
47254710 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
47264711 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
......@@ -4759,7 +4744,6 @@ fn validateUnionInit(
47594744 if (instrs.len != 1) {
47604745 const msg = msg: {
47614746 const msg = try sema.errMsg(
4762 block,
47634747 init_src,
47644748 "cannot initialize multiple union fields at once; unions can only have one active field",
47654749 .{},
......@@ -4768,8 +4752,8 @@ fn validateUnionInit(
47684752
47694753 for (instrs[1..]) |inst| {
47704754 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4771 const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };
4772 try sema.errNote(block, inst_src, msg, "additional initializer here", .{});
4755 const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node });
4756 try sema.errNote(inst_src, msg, "additional initializer here", .{});
47734757 }
47744758 try sema.addDeclaredHereNote(msg, union_ty);
47754759 break :msg msg;
......@@ -4786,7 +4770,7 @@ fn validateUnionInit(
47864770
47874771 const field_ptr = instrs[0];
47884772 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4789 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4773 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
47904774 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
47914775 const field_name = try mod.intern_pool.getOrPutString(
47924776 gpa,
......@@ -4895,15 +4879,15 @@ fn validateUnionInit(
48954879 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
48964880 return;
48974881 } else if (try sema.typeRequiresComptime(union_ty)) {
4898 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
4882 return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{
48994883 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
49004884 });
49014885 }
4902 if (init_ref) |v| try sema.validateRuntimeValue(block, field_ptr_data.src(), v);
4886 if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v);
49034887
49044888 const new_tag = Air.internedToRef(tag_val.toIntern());
49054889 const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);
4906 try sema.checkComptimeKnownStore(block, set_tag_inst, .unneeded); // `unneeded` since this isn't a "proper" store
4890 try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
49074891}
49084892
49094893fn validateStructInit(
......@@ -4929,7 +4913,7 @@ fn validateStructInit(
49294913
49304914 for (instrs, field_indices) |field_ptr, *field_index| {
49314915 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4932 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4916 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
49334917 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
49344918 struct_ptr_zir_ref = field_ptr_extra.lhs;
49354919 const field_name = try ip.getOrPutString(
......@@ -4966,18 +4950,18 @@ fn validateStructInit(
49664950 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
49674951 const template = "missing tuple field with index {d}";
49684952 if (root_msg) |msg| {
4969 try sema.errNote(block, init_src, msg, template, .{i});
4953 try sema.errNote(init_src, msg, template, .{i});
49704954 } else {
4971 root_msg = try sema.errMsg(block, init_src, template, .{i});
4955 root_msg = try sema.errMsg(init_src, template, .{i});
49724956 }
49734957 continue;
49744958 };
49754959 const template = "missing struct field: {}";
49764960 const args = .{field_name.fmt(ip)};
49774961 if (root_msg) |msg| {
4978 try sema.errNote(block, init_src, msg, template, args);
4962 try sema.errNote(init_src, msg, template, args);
49794963 } else {
4980 root_msg = try sema.errMsg(block, init_src, template, args);
4964 root_msg = try sema.errMsg(init_src, template, args);
49814965 }
49824966 continue;
49834967 }
......@@ -4992,16 +4976,7 @@ fn validateStructInit(
49924976 }
49934977
49944978 if (root_msg) |msg| {
4995 if (mod.typeToStruct(struct_ty)) |struct_type| {
4996 const decl = mod.declPtr(struct_type.decl.unwrap().?);
4997 const fqn = try decl.fullyQualifiedName(mod);
4998 try mod.errNoteNonLazy(
4999 decl.srcLoc(mod),
5000 msg,
5001 "struct '{}' declared here",
5002 .{fqn.fmt(ip)},
5003 );
5004 }
4979 try sema.addDeclaredHereNote(msg, struct_ty);
50054980 root_msg = null;
50064981 return sema.failWithOwnedErrorMsg(block, msg);
50074982 }
......@@ -5086,7 +5061,7 @@ fn validateStructInit(
50865061 field_values[i] = val.toIntern();
50875062 } else if (require_comptime) {
50885063 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
5089 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
5064 return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{
50905065 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
50915066 });
50925067 } else {
......@@ -5103,18 +5078,18 @@ fn validateStructInit(
51035078 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
51045079 const template = "missing tuple field with index {d}";
51055080 if (root_msg) |msg| {
5106 try sema.errNote(block, init_src, msg, template, .{i});
5081 try sema.errNote(init_src, msg, template, .{i});
51075082 } else {
5108 root_msg = try sema.errMsg(block, init_src, template, .{i});
5083 root_msg = try sema.errMsg(init_src, template, .{i});
51095084 }
51105085 continue;
51115086 };
51125087 const template = "missing struct field: {}";
51135088 const args = .{field_name.fmt(ip)};
51145089 if (root_msg) |msg| {
5115 try sema.errNote(block, init_src, msg, template, args);
5090 try sema.errNote(init_src, msg, template, args);
51165091 } else {
5117 root_msg = try sema.errMsg(block, init_src, template, args);
5092 root_msg = try sema.errMsg(init_src, template, args);
51185093 }
51195094 continue;
51205095 }
......@@ -5122,21 +5097,12 @@ fn validateStructInit(
51225097 }
51235098
51245099 if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) {
5125 root_msg = try sema.errMsg(block, init_src, "runtime value contains reference to comptime var", .{});
5126 try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
5100 root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{});
5101 try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
51275102 }
51285103
51295104 if (root_msg) |msg| {
5130 if (mod.typeToStruct(struct_ty)) |struct_type| {
5131 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5132 const fqn = try decl.fullyQualifiedName(mod);
5133 try mod.errNoteNonLazy(
5134 decl.srcLoc(mod),
5135 msg,
5136 "struct '{}' declared here",
5137 .{fqn.fmt(ip)},
5138 );
5139 }
5105 try sema.addDeclaredHereNote(msg, struct_ty);
51405106 root_msg = null;
51415107 return sema.failWithOwnedErrorMsg(block, msg);
51425108 }
......@@ -5210,7 +5176,7 @@ fn zirValidatePtrArrayInit(
52105176) CompileError!void {
52115177 const mod = sema.mod;
52125178 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5213 const init_src = validate_inst.src();
5179 const init_src = block.nodeOffset(validate_inst.src_node);
52145180 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
52155181 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
52165182 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
......@@ -5238,9 +5204,9 @@ fn zirValidatePtrArrayInit(
52385204 if (default_val == .unreachable_value) {
52395205 const template = "missing tuple field with index {d}";
52405206 if (root_msg) |msg| {
5241 try sema.errNote(block, init_src, msg, template, .{i});
5207 try sema.errNote(init_src, msg, template, .{i});
52425208 } else {
5243 root_msg = try sema.errMsg(block, init_src, template, .{i});
5209 root_msg = try sema.errMsg(init_src, template, .{i});
52445210 }
52455211 continue;
52465212 }
......@@ -5415,7 +5381,7 @@ fn zirValidatePtrArrayInit(
54155381fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
54165382 const mod = sema.mod;
54175383 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5418 const src = inst_data.src();
5384 const src = block.nodeOffset(inst_data.src_node);
54195385 const operand = try sema.resolveInst(inst_data.operand);
54205386 const operand_ty = sema.typeOf(operand);
54215387
......@@ -5440,15 +5406,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
54405406 } else if (try sema.typeRequiresComptime(elem_ty)) {
54415407 const msg = msg: {
54425408 const msg = try sema.errMsg(
5443 block,
54445409 src,
54455410 "values of type '{}' must be comptime-known, but operand value is runtime-known",
54465411 .{elem_ty.fmt(mod)},
54475412 );
54485413 errdefer msg.destroy(sema.gpa);
54495414
5450 const src_decl = mod.declPtr(block.src_decl);
5451 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty);
5415 try sema.explainWhyTypeIsComptime(msg, src, elem_ty);
54525416 break :msg msg;
54535417 };
54545418 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5459,8 +5423,8 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54595423 const mod = sema.mod;
54605424 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
54615425 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
5462 const src = inst_data.src();
5463 const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node);
5426 const src = block.nodeOffset(inst_data.src_node);
5427 const destructure_src = block.nodeOffset(extra.destructure_node);
54645428 const operand = try sema.resolveInst(extra.operand);
54655429 const operand_ty = sema.typeOf(operand);
54665430
......@@ -5472,21 +5436,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54725436
54735437 if (!can_destructure) {
54745438 return sema.failWithOwnedErrorMsg(block, msg: {
5475 const msg = try sema.errMsg(block, src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});
5439 const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});
54765440 errdefer msg.destroy(sema.gpa);
5477 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});
5441 try sema.errNote(destructure_src, msg, "result destructured here", .{});
54785442 break :msg msg;
54795443 });
54805444 }
54815445
54825446 if (operand_ty.arrayLen(mod) != extra.expect_len) {
54835447 return sema.failWithOwnedErrorMsg(block, msg: {
5484 const msg = try sema.errMsg(block, src, "expected {} elements for destructure, found {}", .{
5448 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{
54855449 extra.expect_len,
54865450 operand_ty.arrayLen(mod),
54875451 });
54885452 errdefer msg.destroy(sema.gpa);
5489 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});
5453 try sema.errNote(destructure_src, msg, "result destructured here", .{});
54905454 break :msg msg;
54915455 });
54925456 }
......@@ -5521,24 +5485,24 @@ fn failWithBadMemberAccess(
55215485fn failWithBadStructFieldAccess(
55225486 sema: *Sema,
55235487 block: *Block,
5488 struct_ty: Type,
55245489 struct_type: InternPool.LoadedStructType,
55255490 field_src: LazySrcLoc,
55265491 field_name: InternPool.NullTerminatedString,
55275492) CompileError {
5528 const mod = sema.mod;
5493 const zcu = sema.mod;
55295494 const gpa = sema.gpa;
5530 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5531 const fqn = try decl.fullyQualifiedName(mod);
5495 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5496 const fqn = try decl.fullyQualifiedName(zcu);
55325497
55335498 const msg = msg: {
55345499 const msg = try sema.errMsg(
5535 block,
55365500 field_src,
55375501 "no field named '{}' in struct '{}'",
5538 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5502 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
55395503 );
55405504 errdefer msg.destroy(gpa);
5541 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "struct declared here", .{});
5505 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});
55425506 break :msg msg;
55435507 };
55445508 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5547,25 +5511,25 @@ fn failWithBadStructFieldAccess(
55475511fn failWithBadUnionFieldAccess(
55485512 sema: *Sema,
55495513 block: *Block,
5514 union_ty: Type,
55505515 union_obj: InternPool.LoadedUnionType,
55515516 field_src: LazySrcLoc,
55525517 field_name: InternPool.NullTerminatedString,
55535518) CompileError {
5554 const mod = sema.mod;
5519 const zcu = sema.mod;
55555520 const gpa = sema.gpa;
55565521
5557 const decl = mod.declPtr(union_obj.decl);
5558 const fqn = try decl.fullyQualifiedName(mod);
5522 const decl = zcu.declPtr(union_obj.decl);
5523 const fqn = try decl.fullyQualifiedName(zcu);
55595524
55605525 const msg = msg: {
55615526 const msg = try sema.errMsg(
5562 block,
55635527 field_src,
55645528 "no field named '{}' in union '{}'",
5565 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5529 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
55665530 );
55675531 errdefer msg.destroy(gpa);
5568 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{});
5532 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});
55695533 break :msg msg;
55705534 };
55715535 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5573,16 +5537,15 @@ fn failWithBadUnionFieldAccess(
55735537
55745538fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
55755539 const mod = sema.mod;
5576 const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return;
5540 const src_loc = decl_ty.srcLocOrNull(mod) orelse return;
55775541 const category = switch (decl_ty.zigTypeTag(mod)) {
55785542 .Union => "union",
55795543 .Struct => "struct",
55805544 .Enum => "enum",
55815545 .Opaque => "opaque",
5582 .ErrorSet => "error set",
55835546 else => unreachable,
55845547 };
5585 try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category});
5548 try sema.errNote(src_loc, parent, "{s} declared here", .{category});
55865549}
55875550
55885551fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -5590,7 +5553,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
55905553 defer tracy.end();
55915554
55925555 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5593 const src = pl_node.src();
5556 const src = block.nodeOffset(pl_node.src_node);
55945557 const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
55955558 const ptr = try sema.resolveInst(bin.lhs);
55965559 const operand = try sema.resolveInst(bin.rhs);
......@@ -5672,7 +5635,7 @@ fn storeToInferredAllocComptime(
56725635
56735636fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
56745637 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5675 const src = inst_data.src();
5638 const src = block.nodeOffset(inst_data.src_node);
56765639 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{
56775640 .needed_comptime_reason = "eval branch quota must be comptime-known",
56785641 }));
......@@ -5687,7 +5650,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
56875650 const zir_tags = sema.code.instructions.items(.tag);
56885651 const zir_datas = sema.code.instructions.items(.data);
56895652 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
5690 const src = inst_data.src();
5653 const src = block.nodeOffset(inst_data.src_node);
56915654 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
56925655 const ptr = try sema.resolveInst(extra.lhs);
56935656 const operand = try sema.resolveInst(extra.rhs);
......@@ -5707,8 +5670,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
57075670 else => {},
57085671 };
57095672
5710 const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node };
5711 const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };
5673 const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
5674 const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node });
57125675 const air_tag: Air.Inst.Tag = if (is_ret)
57135676 .ret_ptr
57145677 else if (block.wantSafety())
......@@ -5821,8 +5784,8 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58215784 defer tracy.end();
58225785
58235786 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5824 const src = inst_data.src();
5825 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5787 const src = block.nodeOffset(inst_data.src_node);
5788 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
58265789 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
58275790 .needed_comptime_reason = "compile error string must be comptime-known",
58285791 });
......@@ -5831,6 +5794,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58315794
58325795fn zirCompileLog(
58335796 sema: *Sema,
5797 block: *Block,
58345798 extended: Zir.Inst.Extended.InstData,
58355799) CompileError!Air.Inst.Ref {
58365800 const mod = sema.mod;
......@@ -5863,20 +5827,21 @@ fn zirCompileLog(
58635827 else
58645828 sema.owner_decl_index;
58655829 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5866 if (!gop.found_existing) {
5867 gop.value_ptr.* = src_node;
5868 }
5830 if (!gop.found_existing) gop.value_ptr.* = .{
5831 .base_node_inst = block.src_base_inst,
5832 .node_offset = src_node,
5833 };
58695834 return .void_value;
58705835}
58715836
58725837fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
58735838 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5874 const src = inst_data.src();
5839 const src = block.nodeOffset(inst_data.src_node);
58755840 const msg_inst = try sema.resolveInst(inst_data.operand);
58765841
58775842 // `panicWithMsg` would perform this coercion for us, but we can get a better
58785843 // source location if we do it here.
5879 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node });
5844 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0));
58805845
58815846 if (block.is_comptime) {
58825847 return sema.fail(block, src, "encountered @panic at comptime", .{});
......@@ -5886,7 +5851,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
58865851
58875852fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
58885853 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
5889 const src = LazySrcLoc.nodeOffset(src_node);
5854 const src = block.nodeOffset(src_node);
58905855 if (block.is_comptime)
58915856 return sema.fail(block, src, "encountered @trap at comptime", .{});
58925857 _ = try block.addNoOp(.trap);
......@@ -5898,7 +5863,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
58985863
58995864 const mod = sema.mod;
59005865 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5901 const src = inst_data.src();
5866 const src = parent_block.nodeOffset(inst_data.src_node);
59025867 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
59035868 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
59045869 const gpa = sema.gpa;
......@@ -5933,7 +5898,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
59335898 var child_block = parent_block.makeSubBlock();
59345899 child_block.label = &label;
59355900 child_block.runtime_cond = null;
5936 child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod);
5901 child_block.runtime_loop = src;
59375902 child_block.runtime_index.increment();
59385903 const merges = &child_block.label.?.merges;
59395904
......@@ -5971,7 +5936,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59715936 const comp = mod.comp;
59725937 const gpa = sema.gpa;
59735938 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5974 const src = pl_node.src();
5939 const src = parent_block.nodeOffset(pl_node.src_node);
59755940 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
59765941 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
59775942
......@@ -5982,14 +5947,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59825947 var c_import_buf = std.ArrayList(u8).init(gpa);
59835948 defer c_import_buf.deinit();
59845949
5985 var comptime_reason: Block.ComptimeReason = .{ .c_import = .{
5986 .block = parent_block,
5987 .src = src,
5988 } };
5950 const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } };
59895951 var child_block: Block = .{
59905952 .parent = parent_block,
59915953 .sema = sema,
5992 .src_decl = parent_block.src_decl,
59935954 .namespace = parent_block.namespace,
59945955 .instructions = .{},
59955956 .inlining = parent_block.inlining,
......@@ -5999,6 +5960,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59995960 .runtime_cond = parent_block.runtime_cond,
60005961 .runtime_loop = parent_block.runtime_loop,
60015962 .runtime_index = parent_block.runtime_index,
5963 .src_base_inst = parent_block.src_base_inst,
5964 .type_name_ctx = parent_block.type_name_ctx,
60025965 };
60035966 defer child_block.instructions.deinit(gpa);
60045967
......@@ -6010,11 +5973,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60105973
60115974 if (c_import_res.errors.errorMessageCount() != 0) {
60125975 const msg = msg: {
6013 const msg = try sema.errMsg(&child_block, src, "C import failed", .{});
5976 const msg = try sema.errMsg(src, "C import failed", .{});
60145977 errdefer msg.destroy(gpa);
60155978
60165979 if (!comp.config.link_libc)
6017 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});
5980 try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
60185981
60195982 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
60205983 if (!gop.found_existing) {
......@@ -6073,7 +6036,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60736036
60746037fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
60756038 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6076 const src = inst_data.src();
6039 const src = parent_block.nodeOffset(inst_data.src_node);
60776040 return sema.failWithUseOfAsync(parent_block, src);
60786041}
60796042
......@@ -6082,7 +6045,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
60826045 defer tracy.end();
60836046
60846047 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6085 const src = pl_node.src();
6048 const src = parent_block.nodeOffset(pl_node.src_node);
60866049 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
60876050 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
60886051 const gpa = sema.gpa;
......@@ -6109,7 +6072,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
61096072 var child_block: Block = .{
61106073 .parent = parent_block,
61116074 .sema = sema,
6112 .src_decl = parent_block.src_decl,
61136075 .namespace = parent_block.namespace,
61146076 .instructions = .{},
61156077 .label = &label,
......@@ -6124,6 +6086,8 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
61246086 .runtime_loop = parent_block.runtime_loop,
61256087 .runtime_index = parent_block.runtime_index,
61266088 .error_return_trace_index = parent_block.error_return_trace_index,
6089 .src_base_inst = parent_block.src_base_inst,
6090 .type_name_ctx = parent_block.type_name_ctx,
61276091 };
61286092
61296093 defer child_block.instructions.deinit(gpa);
......@@ -6318,14 +6282,13 @@ fn resolveAnalyzedBlock(
63186282 const type_src = src; // TODO: better source location
63196283 if (try sema.typeRequiresComptime(resolved_ty)) {
63206284 const msg = msg: {
6321 const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
6285 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
63226286 errdefer msg.destroy(sema.gpa);
63236287
63246288 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
6325 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
6289 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
63266290
6327 const child_src_decl = mod.declPtr(child_block.src_decl);
6328 try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty);
6291 try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty);
63296292
63306293 break :msg msg;
63316294 };
......@@ -6417,9 +6380,9 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
64176380 const mod = sema.mod;
64186381 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
64196382 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
6420 const src = inst_data.src();
6421 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6422 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6383 const src = block.nodeOffset(inst_data.src_node);
6384 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6385 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
64236386 const decl_name = try mod.intern_pool.getOrPutString(
64246387 mod.gpa,
64256388 sema.code.nullTerminatedString(extra.decl_name),
......@@ -6433,13 +6396,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
64336396 break :index_blk maybe_index orelse
64346397 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
64356398 } else try sema.lookupIdentifier(block, operand_src, decl_name);
6436 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
6437 error.NeededSourceLocation => {
6438 _ = try sema.resolveExportOptions(block, options_src, extra.options);
6439 unreachable;
6440 },
6441 else => |e| return e,
6442 };
6399 const options = try sema.resolveExportOptions(block, options_src, extra.options);
64436400 {
64446401 try sema.ensureDeclAnalyzed(decl_index);
64456402 const exported_decl = mod.declPtr(decl_index);
......@@ -6457,9 +6414,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
64576414 const mod = sema.mod;
64586415 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
64596416 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
6460 const src = inst_data.src();
6461 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6462 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6417 const src = block.nodeOffset(inst_data.src_node);
6418 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6419 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
64636420 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
64646421 .needed_comptime_reason = "export target must be comptime-known",
64656422 });
......@@ -6475,7 +6432,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
64756432 .opts = options,
64766433 .src = src,
64776434 .owner_decl = sema.owner_decl_index,
6478 .src_decl = block.src_decl,
64796435 .exported = .{ .value = operand.toIntern() },
64806436 .status = .in_progress,
64816437 });
......@@ -6500,11 +6456,10 @@ pub fn analyzeExport(
65006456
65016457 if (!try sema.validateExternType(export_ty, .other)) {
65026458 const msg = msg: {
6503 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)});
6459 const msg = try sema.errMsg(src, "unable to export type '{}'", .{export_ty.fmt(mod)});
65046460 errdefer msg.destroy(gpa);
65056461
6506 const src_decl = mod.declPtr(block.src_decl);
6507 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
6462 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
65086463
65096464 try sema.addDeclaredHereNote(msg, export_ty);
65106465 break :msg msg;
......@@ -6523,7 +6478,6 @@ pub fn analyzeExport(
65236478 .opts = options,
65246479 .src = src,
65256480 .owner_decl = sema.owner_decl_index,
6526 .src_decl = block.src_decl,
65276481 .exported = .{ .decl_index = exported_decl_index },
65286482 .status = .in_progress,
65296483 });
......@@ -6563,8 +6517,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {
65636517fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
65646518 const mod = sema.mod;
65656519 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6566 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6567 const src = LazySrcLoc.nodeOffset(extra.node);
6520 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6521 const src = block.nodeOffset(extra.node);
65686522 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
65696523 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {
65706524 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
......@@ -6583,9 +6537,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65836537
65846538 if (sema.prev_stack_alignment_src) |prev_src| {
65856539 const msg = msg: {
6586 const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{});
6540 const msg = try sema.errMsg(src, "multiple @setAlignStack in the same function body", .{});
65876541 errdefer msg.destroy(sema.gpa);
6588 try sema.errNote(block, prev_src, msg, "other instance here", .{});
6542 try sema.errNote(prev_src, msg, "other instance here", .{});
65896543 break :msg msg;
65906544 };
65916545 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -6606,7 +6560,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66066560 const mod = sema.mod;
66076561 const ip = &mod.intern_pool;
66086562 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6609 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6563 const operand_src = block.builtinCallArgSrc(extra.node, 0);
66106564 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
66116565 .needed_comptime_reason = "operand to @setCold must be comptime-known",
66126566 });
......@@ -6616,7 +6570,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66166570
66176571fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
66186572 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6619 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6573 const src = block.builtinCallArgSrc(extra.node, 0);
66206574 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
66216575 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
66226576 });
......@@ -6624,7 +6578,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
66246578
66256579fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
66266580 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
6627 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6581 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
66286582 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
66296583 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
66306584 });
......@@ -6634,7 +6588,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
66346588 if (block.is_comptime) return;
66356589
66366590 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6637 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6591 const order_src = block.builtinCallArgSrc(extra.node, 0);
66386592 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
66396593 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
66406594 });
......@@ -6664,7 +6618,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
66646618 if (label.zir_block == zir_block) {
66656619 const br_ref = try start_block.addBr(label.merges.block_inst, operand);
66666620 const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node)
6667 LazySrcLoc.nodeOffset(extra.operand_src_node)
6621 start_block.nodeOffset(extra.operand_src_node)
66686622 else
66696623 null;
66706624 try label.merges.src_locs.append(sema.gpa, src_loc);
......@@ -6774,21 +6728,21 @@ fn addDbgVar(
67746728fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
67756729 const mod = sema.mod;
67766730 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6777 const src = inst_data.src();
6731 const src = block.tokenOffset(inst_data.src_tok);
67786732 const decl_name = try mod.intern_pool.getOrPutString(
67796733 sema.gpa,
67806734 inst_data.get(sema.code),
67816735 .no_embedded_nulls,
67826736 );
67836737 const decl_index = try sema.lookupIdentifier(block, src, decl_name);
6784 try sema.addReferencedBy(block, src, decl_index);
6738 try sema.addReferencedBy(src, decl_index);
67856739 return sema.analyzeDeclRef(decl_index);
67866740}
67876741
67886742fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
67896743 const mod = sema.mod;
67906744 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6791 const src = inst_data.src();
6745 const src = block.tokenOffset(inst_data.src_tok);
67926746 const decl_name = try mod.intern_pool.getOrPutString(
67936747 sema.gpa,
67946748 inst_data.get(sema.code),
......@@ -6891,12 +6845,14 @@ fn lookupInNamespace(
68916845 },
68926846 else => {
68936847 const msg = msg: {
6894 const msg = try sema.errMsg(block, src, "ambiguous reference", .{});
6848 const msg = try sema.errMsg(src, "ambiguous reference", .{});
68956849 errdefer msg.destroy(gpa);
68966850 for (candidates.items) |candidate_index| {
68976851 const candidate = mod.declPtr(candidate_index);
6898 const src_loc = candidate.srcLoc(mod);
6899 try mod.errNoteNonLazy(src_loc, msg, "declared here", .{});
6852 try sema.errNote(.{
6853 .base_node_inst = candidate.zir_decl_index.unwrap().?,
6854 .offset = LazySrcLoc.Offset.nodeOffset(0),
6855 }, msg, "declared here", .{});
69006856 }
69016857 break :msg msg;
69026858 };
......@@ -6938,16 +6894,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
69386894 if (!block.ownerModule().error_tracing) return .none;
69396895
69406896 const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {
6941 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6897 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69426898 else => |e| return e,
69436899 };
69446900 sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) {
6945 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6901 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69466902 else => |e| return e,
69476903 };
69486904 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6949 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {
6950 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),
6905 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6906 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
69516907 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69526908 error.OutOfMemory => |e| return e,
69536909 };
......@@ -7055,8 +7011,8 @@ fn zirCall(
70557011
70567012 const mod = sema.mod;
70577013 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
7058 const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };
7059 const call_src = inst_data.src();
7014 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
7015 const call_src = block.nodeOffset(inst_data.src_node);
70607016 const ExtraType = switch (kind) {
70617017 .direct => Zir.Inst.Call,
70627018 .field => Zir.Inst.FieldCall,
......@@ -7077,7 +7033,7 @@ fn zirCall(
70777033 sema.code.nullTerminatedString(extra.data.field_name_start),
70787034 .no_embedded_nulls,
70797035 );
7080 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
7036 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
70817037 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
70827038 },
70837039 };
......@@ -7187,11 +7143,11 @@ fn checkCallArgumentCount(
71877143 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
71887144 {
71897145 const msg = msg: {
7190 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{
7146 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{
71917147 callee_ty.fmt(mod),
71927148 });
71937149 errdefer msg.destroy(sema.gpa);
7194 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
7150 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
71957151 break :msg msg;
71967152 };
71977153 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7217,7 +7173,6 @@ fn checkCallArgumentCount(
72177173 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
72187174 const msg = msg: {
72197175 const msg = try sema.errMsg(
7220 block,
72217176 func_src,
72227177 "{s}expected {s}{d} argument(s), found {d}",
72237178 .{
......@@ -7229,7 +7184,12 @@ fn checkCallArgumentCount(
72297184 );
72307185 errdefer msg.destroy(sema.gpa);
72317186
7232 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
7187 if (maybe_decl) |fn_decl| {
7188 try sema.errNote(.{
7189 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
7190 .offset = LazySrcLoc.Offset.nodeOffset(0),
7191 }, msg, "function declared here", .{});
7192 }
72337193 break :msg msg;
72347194 };
72357195 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7337,18 +7297,16 @@ const CallArgsInfo = union(enum) {
73377297 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {
73387298 return switch (cai) {
73397299 .resolved => |resolved| resolved.src,
7340 .call_builtin => |call_builtin| .{ .call_arg = .{
7341 .decl = block.src_decl,
7300 .call_builtin => |call_builtin| block.src(.{ .call_arg = .{
73427301 .call_node_offset = call_builtin.call_node_offset,
73437302 .arg_index = @intCast(arg_index),
7344 } },
7303 } }),
73457304 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {
73467305 return zir_call.bound_arg_src;
7347 } else .{ .call_arg = .{
7348 .decl = block.src_decl,
7306 } else block.src(.{ .call_arg = .{
73497307 .call_node_offset = zir_call.call_node_offset,
73507308 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),
7351 } },
7309 } }),
73527310 };
73537311 }
73547312
......@@ -7460,7 +7418,6 @@ const InlineCallSema = struct {
74607418 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
74617419 other_generic_owner: InternPool.Index,
74627420 other_generic_call_src: LazySrcLoc,
7463 other_generic_call_decl: InternPool.OptionalDeclIndex,
74647421
74657422 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
74667423 /// change that. The other parameters contain data for the callee Sema. The other modified
......@@ -7482,8 +7439,7 @@ const InlineCallSema = struct {
74827439 .other_inst_map = .{},
74837440 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,
74847441 .other_generic_owner = .none,
7485 .other_generic_call_src = .unneeded,
7486 .other_generic_call_decl = .none,
7442 .other_generic_call_src = LazySrcLoc.unneeded,
74877443 };
74887444 }
74897445
......@@ -7530,7 +7486,6 @@ const InlineCallSema = struct {
75307486 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);
75317487 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);
75327488 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);
7533 std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
75347489 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
75357490 // zig fmt: on
75367491 }
......@@ -7562,14 +7517,16 @@ fn analyzeCall(
75627517 const maybe_decl = try sema.funcDeclSrc(func);
75637518 const msg = msg: {
75647519 const msg = try sema.errMsg(
7565 block,
75667520 func_src,
75677521 "unable to call function with naked calling convention",
75687522 .{},
75697523 );
75707524 errdefer msg.destroy(sema.gpa);
75717525
7572 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
7526 if (maybe_decl) |fn_decl| try sema.errNote(.{
7527 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
7528 .offset = LazySrcLoc.Offset.nodeOffset(0),
7529 }, msg, "function declared here", .{});
75737530 break :msg msg;
75747531 };
75757532 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7608,7 +7565,6 @@ fn analyzeCall(
76087565 is_inline_call = ct;
76097566 if (ct) {
76107567 comptime_reason = &.{ .comptime_ret_ty = .{
7611 .block = block,
76127568 .func = func,
76137569 .func_src = func_src,
76147570 .return_ty = Type.fromInterned(func_ty_info.return_type),
......@@ -7622,12 +7578,12 @@ fn analyzeCall(
76227578
76237579 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {
76247580 const msg = msg: {
7625 const msg = try sema.errMsg(block, call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});
7581 const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});
76267582 errdefer msg.destroy(sema.gpa);
76277583
76287584 switch (operation) {
76297585 .call, .@"@call", .@"@panic", .@"error return" => {},
7630 .@"safety check" => try sema.errNote(block, call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),
7586 .@"safety check" => try sema.errNote(call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),
76317587 }
76327588 break :msg msg;
76337589 };
......@@ -7654,7 +7610,6 @@ fn analyzeCall(
76547610 is_inline_call = true;
76557611 is_comptime_call = true;
76567612 comptime_reason = &.{ .comptime_ret_ty = .{
7657 .block = block,
76587613 .func = func,
76597614 .func_src = func_src,
76607615 .return_ty = Type.fromInterned(func_ty_info.return_type),
......@@ -7749,7 +7704,6 @@ fn analyzeCall(
77497704 var child_block: Block = .{
77507705 .parent = null,
77517706 .sema = sema,
7752 .src_decl = module_fn.owner_decl,
77537707 .namespace = fn_owner_decl.src_namespace,
77547708 .instructions = .{},
77557709 .label = null,
......@@ -7761,6 +7715,8 @@ fn analyzeCall(
77617715 .runtime_cond = block.runtime_cond,
77627716 .runtime_loop = block.runtime_loop,
77637717 .runtime_index = block.runtime_index,
7718 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
7719 .type_name_ctx = fn_owner_decl.name,
77647720 };
77657721
77667722 const merges = &child_block.inlining.?.merges;
......@@ -7834,7 +7790,7 @@ fn analyzeCall(
78347790 var block_it = block;
78357791 while (block_it.inlining) |parent_inlining| {
78367792 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {
7837 const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{});
7793 const err_msg = try sema.errMsg(call_src, "inline call is recursive", .{});
78387794 return sema.failWithOwnedErrorMsg(null, err_msg);
78397795 }
78407796 block_it = parent_inlining.call_block;
......@@ -7849,7 +7805,7 @@ fn analyzeCall(
78497805 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))
78507806 else
78517807 try sema.resolveInst(fn_info.ret_ty_ref);
7852 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
7808 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
78537809 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
78547810 if (module_fn.analysis(ip).inferred_error_set) {
78557811 // Create a fresh inferred error set type for inline/comptime calls.
......@@ -7920,7 +7876,7 @@ fn analyzeCall(
79207876 };
79217877
79227878 if (is_comptime_call) {
7923 const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined);
7879 const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined);
79247880 const result_interned = result_val.toIntern();
79257881
79267882 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -8081,7 +8037,7 @@ fn analyzeInlineCallArg(
80818037 // Evaluate the parameter type expression now that previous ones have
80828038 // been mapped, and coerce the corresponding argument to it.
80838039 const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
8084 const param_src = pl_tok.src();
8040 const param_src = param_block.tokenOffset(pl_tok.src_tok);
80858041 const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index);
80868042 const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len);
80878043 const param_ty = param_ty: {
......@@ -8261,7 +8217,6 @@ fn instantiateGenericCall(
82618217 .comptime_args = comptime_args,
82628218 .generic_owner = generic_owner,
82638219 .generic_call_src = call_src,
8264 .generic_call_decl = block.src_decl.toOptional(),
82658220 .branch_quota = sema.branch_quota,
82668221 .branch_count = sema.branch_count,
82678222 .comptime_err_ret_trace = sema.comptime_err_ret_trace,
......@@ -8271,11 +8226,12 @@ fn instantiateGenericCall(
82718226 var child_block: Block = .{
82728227 .parent = null,
82738228 .sema = &child_sema,
8274 .src_decl = generic_owner_func.owner_decl,
82758229 .namespace = namespace_index,
82768230 .instructions = .{},
82778231 .inlining = null,
82788232 .is_comptime = true,
8233 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
8234 .type_name_ctx = fn_owner_decl.name,
82798235 };
82808236 defer child_block.instructions.deinit(gpa);
82818237
......@@ -8306,22 +8262,23 @@ fn instantiateGenericCall(
83068262 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;
83078263 const prev_generic_owner = child_sema.generic_owner;
83088264 const prev_generic_call_src = child_sema.generic_call_src;
8309 const prev_generic_call_decl = child_sema.generic_call_decl;
83108265 child_block.params = .{};
83118266 child_sema.no_partial_func_ty = true;
83128267 child_sema.generic_owner = .none;
8313 child_sema.generic_call_src = .unneeded;
8314 child_sema.generic_call_decl = .none;
8268 child_sema.generic_call_src = LazySrcLoc.unneeded;
83158269 defer {
83168270 child_block.params = prev_params;
83178271 child_sema.no_partial_func_ty = prev_no_partial_func_ty;
83188272 child_sema.generic_owner = prev_generic_owner;
83198273 child_sema.generic_call_src = prev_generic_call_src;
8320 child_sema.generic_call_decl = prev_generic_call_decl;
83218274 }
83228275
83238276 const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst);
8324 break :param_ty try child_sema.analyzeAsType(&child_block, param_data.src(), param_ty_inst);
8277 break :param_ty try child_sema.analyzeAsType(
8278 &child_block,
8279 child_block.tokenOffset(param_data.src_tok),
8280 param_ty_inst,
8281 );
83258282 },
83268283 else => unreachable,
83278284 }
......@@ -8353,14 +8310,14 @@ fn instantiateGenericCall(
83538310 .param_anytype_comptime,
83548311 => return sema.failWithOwnedErrorMsg(block, msg: {
83558312 const arg_src = args_info.argSrc(block, arg_index);
8356 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{});
8313 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to comptime parameter", .{});
83578314 errdefer msg.destroy(sema.gpa);
8358 const param_src = switch (param_tag) {
8359 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),
8360 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),
8315 const param_src = child_block.tokenOffset(switch (param_tag) {
8316 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8317 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
83618318 else => unreachable,
8362 };
8363 try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{});
8319 });
8320 try child_sema.errNote(param_src, msg, "declared comptime here", .{});
83648321 break :msg msg;
83658322 }),
83668323
......@@ -8368,16 +8325,15 @@ fn instantiateGenericCall(
83688325 .param_anytype,
83698326 => return sema.failWithOwnedErrorMsg(block, msg: {
83708327 const arg_src = args_info.argSrc(block, arg_index);
8371 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
8328 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
83728329 errdefer msg.destroy(sema.gpa);
8373 const param_src = switch (param_tag) {
8374 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),
8375 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),
8330 const param_src = child_block.tokenOffset(switch (param_tag) {
8331 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8332 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
83768333 else => unreachable,
8377 };
8378 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});
8379 const src_decl = mod.declPtr(block.src_decl);
8380 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty);
8334 });
8335 try child_sema.errNote(param_src, msg, "declared here", .{});
8336 try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty);
83818337 break :msg msg;
83828338 }),
83838339
......@@ -8414,12 +8370,12 @@ fn instantiateGenericCall(
84148370 // We've already handled parameters, so don't resolve the whole body. Instead, just
84158371 // do the instructions after the params (i.e. the func itself).
84168372 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
8417 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
8373 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
84188374
84198375 const callee = mod.funcInfo(callee_index);
84208376 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
84218377
8422 try sema.addReferencedBy(block, call_src, callee.owner_decl);
8378 try sema.addReferencedBy(call_src, callee.owner_decl);
84238379
84248380 // Make a runtime call to the new function, making sure to omit the comptime args.
84258381 const func_ty = Type.fromInterned(callee.ty);
......@@ -8501,7 +8457,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85018457
85028458 const mod = sema.mod;
85038459 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8504 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
8460 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
85058461 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
85068462 if (child_type.zigTypeTag(mod) == .Opaque) {
85078463 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});
......@@ -8516,7 +8472,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85168472fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85178473 const mod = sema.mod;
85188474 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
8519 const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) {
8475 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {
85208476 // Since this is a ZIR instruction that returns a type, encountering
85218477 // generic poison should not result in a failed compilation, but the
85228478 // generic poison type. This prevents unnecessary failures when
......@@ -8539,7 +8495,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
85398495fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85408496 const mod = sema.mod;
85418497 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8542 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
8498 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
85438499 error.GenericPoison => return .generic_poison_type,
85448500 else => |e| return e,
85458501 };
......@@ -8557,7 +8513,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
85578513fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85588514 const mod = sema.mod;
85598515 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8560 const src = un_node.src();
8516 const src = block.nodeOffset(un_node.src_node);
85618517 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {
85628518 error.GenericPoison => return .generic_poison_type,
85638519 else => |e| return e,
......@@ -8573,7 +8529,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
85738529fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85748530 const mod = sema.mod;
85758531 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8576 const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
8532 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
85778533 // Since this is a ZIR instruction that returns a type, encountering
85788534 // generic poison should not result in a failed compilation, but the
85798535 // generic poison type. This prevents unnecessary failures when
......@@ -8582,7 +8538,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
85828538 else => |e| return e,
85838539 };
85848540 if (!vec_ty.isVector(mod)) {
8585 return sema.fail(block, un_node.src(), "expected vector type, found '{}'", .{vec_ty.fmt(mod)});
8541 return sema.fail(block, block.nodeOffset(un_node.src_node), "expected vector type, found '{}'", .{vec_ty.fmt(mod)});
85868542 }
85878543 return Air.internedToRef(vec_ty.childType(mod).toIntern());
85888544}
......@@ -8590,8 +8546,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
85908546fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85918547 const mod = sema.mod;
85928548 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8593 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8594 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
8549 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8550 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
85958551 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
85968552 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
85978553 .needed_comptime_reason = "vector length must be comptime-known",
......@@ -8611,8 +8567,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
86118567
86128568 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
86138569 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8614 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
8615 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8570 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8571 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
86168572 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
86178573 .needed_comptime_reason = "array length must be comptime-known",
86188574 });
......@@ -8632,9 +8588,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
86328588
86338589 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
86348590 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
8635 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
8636 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };
8637 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8591 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8592 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
8593 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
86388594 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
86398595 .needed_comptime_reason = "array length must be comptime-known",
86408596 });
......@@ -8669,10 +8625,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
86698625
86708626 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
86718627 if (true) {
8672 return sema.failWithUseOfAsync(block, inst_data.src());
8628 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
86738629 }
86748630 const mod = sema.mod;
8675 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };
8631 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });
86768632 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
86778633 const anyframe_type = try mod.anyframeType(return_type);
86788634
......@@ -8686,8 +8642,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
86868642 const mod = sema.mod;
86878643 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
86888644 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8689 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
8690 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
8645 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8646 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
86918647 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
86928648 const payload = try sema.resolveType(block, rhs_src, extra.rhs);
86938649
......@@ -8739,8 +8695,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87398695 const mod = sema.mod;
87408696 const ip = &mod.intern_pool;
87418697 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8742 const src = LazySrcLoc.nodeOffset(extra.node);
8743 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
8698 const src = block.nodeOffset(extra.node);
8699 const operand_src = block.builtinCallArgSrc(extra.node, 0);
87448700 const uncasted_operand = try sema.resolveInst(extra.operand);
87458701 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
87468702 const err_int_ty = try mod.errorIntType();
......@@ -8782,8 +8738,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87828738
87838739 const mod = sema.mod;
87848740 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8785 const src = LazySrcLoc.nodeOffset(extra.node);
8786 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
8741 const src = block.nodeOffset(extra.node);
8742 const operand_src = block.builtinCallArgSrc(extra.node, 0);
87878743 const uncasted_operand = try sema.resolveInst(extra.operand);
87888744 const err_int_ty = try mod.errorIntType();
87898745 const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);
......@@ -8822,16 +8778,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
88228778 const ip = &mod.intern_pool;
88238779 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
88248780 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8825 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
8826 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
8827 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
8781 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
8782 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8783 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
88288784 const lhs = try sema.resolveInst(extra.lhs);
88298785 const rhs = try sema.resolveInst(extra.rhs);
88308786 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {
88318787 const msg = msg: {
8832 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});
8788 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});
88338789 errdefer msg.destroy(sema.gpa);
8834 try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
8790 try sema.errNote(src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
88358791 break :msg msg;
88368792 };
88378793 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -8885,8 +8841,8 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88858841fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
88868842 const mod = sema.mod;
88878843 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8888 const src = inst_data.src();
8889 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8844 const src = block.nodeOffset(inst_data.src_node);
8845 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
88908846 const operand = try sema.resolveInst(inst_data.operand);
88918847 const operand_ty = sema.typeOf(operand);
88928848
......@@ -8943,8 +8899,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
89438899 const mod = sema.mod;
89448900 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
89458901 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8946 const src = inst_data.src();
8947 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8902 const src = block.nodeOffset(inst_data.src_node);
8903 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
89488904 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
89498905 const operand = try sema.resolveInst(extra.rhs);
89508906
......@@ -9012,7 +8968,7 @@ fn zirOptionalPayloadPtr(
90128968
90138969 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
90148970 const optional_ptr = try sema.resolveInst(inst_data.operand);
9015 const src = inst_data.src();
8971 const src = block.nodeOffset(inst_data.src_node);
90168972
90178973 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);
90188974}
......@@ -9096,7 +9052,7 @@ fn zirOptionalPayload(
90969052
90979053 const mod = sema.mod;
90989054 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9099 const src = inst_data.src();
9055 const src = block.nodeOffset(inst_data.src_node);
91009056 const operand = try sema.resolveInst(inst_data.operand);
91019057 const operand_ty = sema.typeOf(operand);
91029058 const result_ty = switch (operand_ty.zigTypeTag(mod)) {
......@@ -9148,7 +9104,7 @@ fn zirErrUnionPayload(
91489104
91499105 const mod = sema.mod;
91509106 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9151 const src = inst_data.src();
9107 const src = block.nodeOffset(inst_data.src_node);
91529108 const operand = try sema.resolveInst(inst_data.operand);
91539109 const operand_src = src;
91549110 const err_union_ty = sema.typeOf(operand);
......@@ -9201,7 +9157,7 @@ fn zirErrUnionPayloadPtr(
92019157
92029158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
92039159 const operand = try sema.resolveInst(inst_data.operand);
9204 const src = inst_data.src();
9160 const src = block.nodeOffset(inst_data.src_node);
92059161
92069162 return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false);
92079163}
......@@ -9285,7 +9241,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
92859241 defer tracy.end();
92869242
92879243 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9288 const src = inst_data.src();
9244 const src = block.nodeOffset(inst_data.src_node);
92899245 const operand = try sema.resolveInst(inst_data.operand);
92909246 return sema.analyzeErrUnionCode(block, src, operand);
92919247}
......@@ -9318,7 +9274,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
93189274 defer tracy.end();
93199275
93209276 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9321 const src = inst_data.src();
9277 const src = block.nodeOffset(inst_data.src_node);
93229278 const operand = try sema.resolveInst(inst_data.operand);
93239279 return sema.analyzeErrUnionCodePtr(block, src, operand);
93249280}
......@@ -9360,7 +9316,7 @@ fn zirFunc(
93609316 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
93619317 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
93629318 const target = sema.mod.getTarget();
9363 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };
9319 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
93649320
93659321 var extra_index = extra.end;
93669322
......@@ -9396,13 +9352,17 @@ fn zirFunc(
93969352 src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;
93979353 }
93989354
9399 // If this instruction has a body it means it's the type of the `owner_decl`
9400 // otherwise it's a function type without a `callconv` attribute and should
9401 // never be `.C`.
9402 const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(block.src_decl).is_exported)
9403 .C
9404 else
9405 .Unspecified;
9355 // If this instruction has a body, then it's a function declaration, and we decide
9356 // the callconv based on whether it is exported. Otherwise, the callconv defaults
9357 // to `.Unspecified`.
9358 const cc: std.builtin.CallingConvention = if (has_body) cc: {
9359 const fn_is_exported = if (sema.generic_owner != .none) exported: {
9360 const generic_owner_fn = mod.funcInfo(sema.generic_owner);
9361 const generic_owner_decl = mod.declPtr(generic_owner_fn.owner_decl);
9362 break :exported generic_owner_decl.is_exported;
9363 } else sema.owner_decl.is_exported;
9364 break :cc if (fn_is_exported) .C else .Unspecified;
9365 } else .Unspecified;
94069366
94079367 return sema.funcCommon(
94089368 block,
......@@ -9441,18 +9401,15 @@ fn resolveGenericBody(
94419401 const prev_no_partial_func_type = sema.no_partial_func_ty;
94429402 const prev_generic_owner = sema.generic_owner;
94439403 const prev_generic_call_src = sema.generic_call_src;
9444 const prev_generic_call_decl = sema.generic_call_decl;
94459404 block.params = .{};
94469405 sema.no_partial_func_ty = true;
94479406 sema.generic_owner = .none;
9448 sema.generic_call_src = .unneeded;
9449 sema.generic_call_decl = .none;
9407 sema.generic_call_src = LazySrcLoc.unneeded;
94509408 defer {
94519409 block.params = prev_params;
94529410 sema.no_partial_func_ty = prev_no_partial_func_type;
94539411 sema.generic_owner = prev_generic_owner;
94549412 sema.generic_call_src = prev_generic_call_src;
9455 sema.generic_call_decl = prev_generic_call_decl;
94569413 }
94579414
94589415 const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err;
......@@ -9562,9 +9519,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
95629519
95639520 if (!callConvSupportsVarArgs(cc)) {
95649521 const msg = msg: {
9565 const msg = try sema.errMsg(block, src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
9522 const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
95669523 errdefer msg.destroy(sema.gpa);
9567 try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
9524 try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
95689525 break :msg msg;
95699526 };
95709527 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -9604,9 +9561,9 @@ fn funcCommon(
96049561 const gpa = sema.gpa;
96059562 const target = mod.getTarget();
96069563 const ip = &mod.intern_pool;
9607 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
9608 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };
9609 const func_src = LazySrcLoc.nodeOffset(src_node_offset);
9564 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset });
9565 const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset });
9566 const func_src = block.nodeOffset(src_node_offset);
96109567
96119568 var is_generic = bare_return_type.isGenericPoison() or
96129569 alignment == null or
......@@ -9635,11 +9592,10 @@ fn funcCommon(
96359592 const index = std.math.cast(u5, i) orelse break :blk false;
96369593 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
96379594 };
9638 const param_src: LazySrcLoc = .{ .fn_proto_param = .{
9639 .decl = block.src_decl,
9595 const param_src = block.src(.{ .fn_proto_param = .{
96409596 .fn_proto_node_offset = src_node_offset,
96419597 .param_index = @intCast(i),
9642 } };
9598 } });
96439599 const requires_comptime = try sema.typeRequiresComptime(param_ty);
96449600 if (param_is_comptime or requires_comptime) {
96459601 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
......@@ -9660,13 +9616,12 @@ fn funcCommon(
96609616 }
96619617 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {
96629618 const msg = msg: {
9663 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
9619 const msg = try sema.errMsg(param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
96649620 param_ty.fmt(mod), @tagName(cc_resolved),
96659621 });
96669622 errdefer msg.destroy(sema.gpa);
96679623
9668 const src_decl = mod.declPtr(block.src_decl);
9669 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty);
9624 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
96709625
96719626 try sema.addDeclaredHereNote(msg, param_ty);
96729627 break :msg msg;
......@@ -9675,13 +9630,12 @@ fn funcCommon(
96759630 }
96769631 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {
96779632 const msg = msg: {
9678 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' must be declared comptime", .{
9633 const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{
96799634 param_ty.fmt(mod),
96809635 });
96819636 errdefer msg.destroy(sema.gpa);
96829637
9683 const src_decl = mod.declPtr(block.src_decl);
9684 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty);
9638 try sema.explainWhyTypeIsComptime(msg, param_src, param_ty);
96859639
96869640 try sema.addDeclaredHereNote(msg, param_ty);
96879641 break :msg msg;
......@@ -9842,9 +9796,9 @@ fn funcCommon(
98429796 assert(section != .generic);
98439797 assert(address_space != null);
98449798 assert(!is_generic);
9845 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, .{
9799 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, block.src(.{
98469800 .node_offset_lib_name = src_node_offset,
9847 }, lib_name);
9801 }), lib_name);
98489802 const func_index = try ip.getExternFunc(gpa, .{
98499803 .ty = func_ty,
98509804 .decl = sema.owner_decl_index,
......@@ -9956,13 +9910,12 @@ fn finishFunc(
99569910 !try sema.validateExternType(return_type, .ret_ty))
99579911 {
99589912 const msg = msg: {
9959 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
9913 const msg = try sema.errMsg(ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
99609914 return_type.fmt(mod), @tagName(cc_resolved),
99619915 });
99629916 errdefer msg.destroy(gpa);
99639917
9964 const src_decl = mod.declPtr(block.src_decl);
9965 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty);
9918 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty);
99669919
99679920 try sema.addDeclaredHereNote(msg, return_type);
99689921 break :msg msg;
......@@ -9978,12 +9931,11 @@ fn finishFunc(
99789931 } else break :comptime_check;
99799932
99809933 const msg = try sema.errMsg(
9981 block,
99829934 ret_ty_src,
99839935 "function with comptime-only return type '{}' requires all parameters to be comptime",
99849936 .{return_type.fmt(mod)},
99859937 );
9986 try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type);
9938 try sema.explainWhyTypeIsComptime(msg, ret_ty_src, return_type);
99879939
99889940 const tags = sema.code.instructions.items(.tag);
99899941 const data = sema.code.instructions.items(.data);
......@@ -9994,16 +9946,16 @@ fn finishFunc(
99949946 param_body[0..block.params.len],
99959947 ) |is_comptime, name_nts, param_index| {
99969948 if (!is_comptime) {
9997 const param_src = switch (tags[@intFromEnum(param_index)]) {
9998 .param => data[@intFromEnum(param_index)].pl_tok.src(),
9999 .param_anytype => data[@intFromEnum(param_index)].str_tok.src(),
9949 const param_src = block.tokenOffset(switch (tags[@intFromEnum(param_index)]) {
9950 .param => data[@intFromEnum(param_index)].pl_tok.src_tok,
9951 .param_anytype => data[@intFromEnum(param_index)].str_tok.src_tok,
100009952 else => unreachable,
10001 };
9953 });
100029954 const name = sema.code.nullTerminatedString(name_nts);
100039955 if (name.len != 0) {
10004 try sema.errNote(block, param_src, msg, "param '{s}' is required to be comptime", .{name});
9956 try sema.errNote(param_src, msg, "param '{s}' is required to be comptime", .{name});
100059957 } else {
10006 try sema.errNote(block, param_src, msg, "param is required to be comptime", .{});
9958 try sema.errNote(param_src, msg, "param is required to be comptime", .{});
100079959 }
100089960 }
100099961 }
......@@ -10081,7 +10033,7 @@ fn zirParam(
1008110033 comptime_syntax: bool,
1008210034) CompileError!void {
1008310035 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
10084 const src = inst_data.src();
10036 const src = block.tokenOffset(inst_data.src_tok);
1008510037 const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
1008610038 const param_name: Zir.NullTerminatedString = extra.data.name;
1008710039 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
......@@ -10093,18 +10045,15 @@ fn zirParam(
1009310045 const prev_no_partial_func_type = sema.no_partial_func_ty;
1009410046 const prev_generic_owner = sema.generic_owner;
1009510047 const prev_generic_call_src = sema.generic_call_src;
10096 const prev_generic_call_decl = sema.generic_call_decl;
1009710048 block.params = .{};
1009810049 sema.no_partial_func_ty = true;
1009910050 sema.generic_owner = .none;
10100 sema.generic_call_src = .unneeded;
10101 sema.generic_call_decl = .none;
10051 sema.generic_call_src = LazySrcLoc.unneeded;
1010210052 defer {
1010310053 block.params = prev_params;
1010410054 sema.no_partial_func_ty = prev_no_partial_func_type;
1010510055 sema.generic_owner = prev_generic_owner;
1010610056 sema.generic_call_src = prev_generic_call_src;
10107 sema.generic_call_decl = prev_generic_call_decl;
1010810057 }
1010910058
1011010059 if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| {
......@@ -10191,7 +10140,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1019110140 defer tracy.end();
1019210141
1019310142 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10194 const src = inst_data.src();
10143 const src = block.nodeOffset(inst_data.src_node);
1019510144 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
1019610145 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);
1019710146}
......@@ -10201,7 +10150,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1020110150 defer tracy.end();
1020210151
1020310152 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10204 const src = inst_data.src();
10153 const src = block.nodeOffset(inst_data.src_node);
1020510154 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
1020610155 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true);
1020710156}
......@@ -10246,7 +10195,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1024610195
1024710196 const zcu = sema.mod;
1024810197 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
10249 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10198 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1025010199 const operand = try sema.resolveInst(inst_data.operand);
1025110200 const operand_ty = sema.typeOf(operand);
1025210201 const ptr_ty = operand_ty.scalarType(zcu);
......@@ -10257,10 +10206,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1025710206 const pointee_ty = ptr_ty.childType(zcu);
1025810207 if (try sema.typeRequiresComptime(ptr_ty)) {
1025910208 const msg = msg: {
10260 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});
10209 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});
1026110210 errdefer msg.destroy(sema.gpa);
10262 const src_decl = zcu.declPtr(block.src_decl);
10263 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty);
10211 try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty);
1026410212 break :msg msg;
1026510213 };
1026610214 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -10298,7 +10246,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1029810246 .storage = .{ .elems = new_elems },
1029910247 } }));
1030010248 }
10301 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
10249 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src);
1030210250 try sema.validateRuntimeValue(block, ptr_src, operand);
1030310251 if (!is_vector) {
1030410252 return block.addUnOp(.int_from_ptr, operand);
......@@ -10320,8 +10268,8 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1032010268
1032110269 const mod = sema.mod;
1032210270 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10323 const src = inst_data.src();
10324 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10271 const src = block.nodeOffset(inst_data.src_node);
10272 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1032510273 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1032610274 const field_name = try mod.intern_pool.getOrPutString(
1032710275 sema.gpa,
......@@ -10338,8 +10286,8 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1033810286
1033910287 const mod = sema.mod;
1034010288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10341 const src = inst_data.src();
10342 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10289 const src = block.nodeOffset(inst_data.src_node);
10290 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1034310291 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1034410292 const field_name = try mod.intern_pool.getOrPutString(
1034510293 sema.gpa,
......@@ -10356,8 +10304,8 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1035610304
1035710305 const mod = sema.mod;
1035810306 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10359 const src = inst_data.src();
10360 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
10307 const src = block.nodeOffset(inst_data.src_node);
10308 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
1036110309 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1036210310 const field_name = try mod.intern_pool.getOrPutString(
1036310311 sema.gpa,
......@@ -10381,8 +10329,8 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1038110329 defer tracy.end();
1038210330
1038310331 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10384 const src = inst_data.src();
10385 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
10332 const src = block.nodeOffset(inst_data.src_node);
10333 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1038610334 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
1038710335 const object = try sema.resolveInst(extra.lhs);
1038810336 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
......@@ -10396,8 +10344,8 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1039610344 defer tracy.end();
1039710345
1039810346 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10399 const src = inst_data.src();
10400 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
10347 const src = block.nodeOffset(inst_data.src_node);
10348 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1040110349 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
1040210350 const object_ptr = try sema.resolveInst(extra.lhs);
1040310351 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
......@@ -10411,14 +10359,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1041110359 defer tracy.end();
1041210360
1041310361 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10414 const src = inst_data.src();
10415 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10362 const src = block.nodeOffset(inst_data.src_node);
10363 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1041610364 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1041710365
1041810366 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
1041910367 const operand = try sema.resolveInst(extra.rhs);
1042010368
10421 return sema.intCast(block, inst_data.src(), dest_ty, src, operand, operand_src, true);
10369 return sema.intCast(block, block.nodeOffset(inst_data.src_node), dest_ty, src, operand, operand_src, true);
1042210370}
1042310371
1042410372fn intCast(
......@@ -10581,8 +10529,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1058110529
1058210530 const mod = sema.mod;
1058310531 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10584 const src = inst_data.src();
10585 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10532 const src = block.nodeOffset(inst_data.src_node);
10533 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1058610534 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1058710535
1058810536 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
......@@ -10608,10 +10556,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1060810556
1060910557 .Enum => {
1061010558 const msg = msg: {
10611 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10559 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
1061210560 errdefer msg.destroy(sema.gpa);
1061310561 switch (operand_ty.zigTypeTag(mod)) {
10614 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10562 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
1061510563 else => {},
1061610564 }
1061710565
......@@ -10622,11 +10570,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1062210570
1062310571 .Pointer => {
1062410572 const msg = msg: {
10625 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10573 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
1062610574 errdefer msg.destroy(sema.gpa);
1062710575 switch (operand_ty.zigTypeTag(mod)) {
10628 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10629 .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
10576 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10577 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
1063010578 else => {},
1063110579 }
1063210580
......@@ -10672,10 +10620,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1067210620
1067310621 .Enum => {
1067410622 const msg = msg: {
10675 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10623 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
1067610624 errdefer msg.destroy(sema.gpa);
1067710625 switch (dest_ty.zigTypeTag(mod)) {
10678 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),
10626 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),
1067910627 else => {},
1068010628 }
1068110629
......@@ -10685,11 +10633,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1068510633 },
1068610634 .Pointer => {
1068710635 const msg = msg: {
10688 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10636 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
1068910637 errdefer msg.destroy(sema.gpa);
1069010638 switch (dest_ty.zigTypeTag(mod)) {
10691 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),
10692 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
10639 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),
10640 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
1069310641 else => {},
1069410642 }
1069510643
......@@ -10715,7 +10663,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1071510663 .Vector,
1071610664 => {},
1071710665 }
10718 return sema.bitCast(block, dest_ty, operand, inst_data.src(), operand_src);
10666 return sema.bitCast(block, dest_ty, operand, block.nodeOffset(inst_data.src_node), operand_src);
1071910667}
1072010668
1072110669fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10724,8 +10672,8 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1072410672
1072510673 const mod = sema.mod;
1072610674 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10727 const src = inst_data.src();
10728 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10675 const src = block.nodeOffset(inst_data.src_node);
10676 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1072910677 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1073010678
1073110679 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
......@@ -10778,7 +10726,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1077810726 if (dest_is_comptime_float) {
1077910727 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{});
1078010728 }
10781 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
10729 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src);
1078210730
1078310731 const src_bits = operand_scalar_ty.floatBits(target);
1078410732 const dst_bits = dest_scalar_ty.floatBits(target);
......@@ -10803,7 +10751,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1080310751 defer tracy.end();
1080410752
1080510753 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10806 const src = inst_data.src();
10754 const src = block.nodeOffset(inst_data.src_node);
1080710755 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1080810756 const array = try sema.resolveInst(extra.lhs);
1080910757 const elem_index = try sema.resolveInst(extra.rhs);
......@@ -10815,8 +10763,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1081510763 defer tracy.end();
1081610764
1081710765 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10818 const src = inst_data.src();
10819 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
10766 const src = block.nodeOffset(inst_data.src_node);
10767 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
1082010768 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1082110769 const array = try sema.resolveInst(extra.lhs);
1082210770 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
......@@ -10832,7 +10780,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1083210780 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
1083310781 const array = try sema.resolveInst(inst_data.operand);
1083410782 const elem_index = try mod.intRef(Type.usize, inst_data.idx);
10835 return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false);
10783 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);
1083610784}
1083710785
1083810786fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10841,20 +10789,20 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1084110789
1084210790 const mod = sema.mod;
1084310791 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10844 const src = inst_data.src();
10792 const src = block.nodeOffset(inst_data.src_node);
1084510793 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1084610794 const array_ptr = try sema.resolveInst(extra.lhs);
1084710795 const elem_index = try sema.resolveInst(extra.rhs);
1084810796 const indexable_ty = sema.typeOf(array_ptr);
1084910797 if (indexable_ty.zigTypeTag(mod) != .Pointer) {
10850 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };
10798 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
1085110799 const msg = msg: {
10852 const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{
10800 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{
1085310801 indexable_ty.fmt(mod),
1085410802 });
1085510803 errdefer msg.destroy(sema.gpa);
1085610804 if (indexable_ty.isIndexable(mod)) {
10857 try sema.errNote(block, src, msg, "consider using '&' here", .{});
10805 try sema.errNote(src, msg, "consider using '&' here", .{});
1085810806 }
1085910807 break :msg msg;
1086010808 };
......@@ -10868,8 +10816,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1086810816 defer tracy.end();
1086910817
1087010818 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10871 const src = inst_data.src();
10872 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
10819 const src = block.nodeOffset(inst_data.src_node);
10820 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
1087310821 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1087410822 const array_ptr = try sema.resolveInst(extra.lhs);
1087510823 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
......@@ -10883,7 +10831,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1088310831
1088410832 const mod = sema.mod;
1088510833 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10886 const src = inst_data.src();
10834 const src = block.nodeOffset(inst_data.src_node);
1088710835 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
1088810836 const array_ptr = try sema.resolveInst(extra.ptr);
1088910837 const elem_index = try sema.mod.intRef(Type.usize, extra.index);
......@@ -10902,15 +10850,15 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1090210850 defer tracy.end();
1090310851
1090410852 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10905 const src = inst_data.src();
10853 const src = block.nodeOffset(inst_data.src_node);
1090610854 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
1090710855 const array_ptr = try sema.resolveInst(extra.lhs);
1090810856 const start = try sema.resolveInst(extra.start);
10909 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10910 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10911 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10857 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10858 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10859 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1091210860
10913 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded, ptr_src, start_src, end_src, false);
10861 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false);
1091410862}
1091510863
1091610864fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10918,16 +10866,16 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1091810866 defer tracy.end();
1091910867
1092010868 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10921 const src = inst_data.src();
10869 const src = block.nodeOffset(inst_data.src_node);
1092210870 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
1092310871 const array_ptr = try sema.resolveInst(extra.lhs);
1092410872 const start = try sema.resolveInst(extra.start);
1092510873 const end = try sema.resolveInst(extra.end);
10926 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10927 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10928 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10874 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10875 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10876 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1092910877
10930 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded, ptr_src, start_src, end_src, false);
10878 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false);
1093110879}
1093210880
1093310881fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10935,16 +10883,16 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1093510883 defer tracy.end();
1093610884
1093710885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10938 const src = inst_data.src();
10939 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
10886 const src = block.nodeOffset(inst_data.src_node);
10887 const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1094010888 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
1094110889 const array_ptr = try sema.resolveInst(extra.lhs);
1094210890 const start = try sema.resolveInst(extra.start);
1094310891 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);
1094410892 const sentinel = try sema.resolveInst(extra.sentinel);
10945 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10946 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10947 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10893 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10894 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10895 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1094810896
1094910897 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);
1095010898}
......@@ -10954,19 +10902,19 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1095410902 defer tracy.end();
1095510903
1095610904 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10957 const src = inst_data.src();
10905 const src = block.nodeOffset(inst_data.src_node);
1095810906 const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
1095910907 const array_ptr = try sema.resolveInst(extra.lhs);
1096010908 const start = try sema.resolveInst(extra.start);
1096110909 const len = try sema.resolveInst(extra.len);
1096210910 const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel);
10963 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10964 const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset };
10965 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10911 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10912 const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset });
10913 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1096610914 const sentinel_src: LazySrcLoc = if (sentinel == .none)
10967 .unneeded
10915 LazySrcLoc.unneeded
1096810916 else
10969 .{ .node_offset_slice_sentinel = inst_data.src_node };
10917 block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1097010918
1097110919 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);
1097210920}
......@@ -11000,8 +10948,8 @@ const SwitchProngAnalysis = struct {
1100010948 prong_type: enum { normal, special },
1100110949 prong_body: []const Zir.Inst.Index,
1100210950 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11003 /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field.
11004 raw_capture_src: Module.SwitchProngSrc,
10951 /// Must use the `switch_capture` field in `offset`.
10952 capture_src: LazySrcLoc,
1100510953 /// The set of all values which can reach this prong. May be undefined
1100610954 /// if the prong is special or contains ranges.
1100710955 case_vals: []const Air.Inst.Ref,
......@@ -11014,10 +10962,12 @@ const SwitchProngAnalysis = struct {
1101410962 merges: *Block.Merges,
1101510963 ) CompileError!Air.Inst.Ref {
1101610964 const sema = spa.sema;
11017 const src = sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src();
10965 const src = spa.parent_block.nodeOffset(
10966 sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src_node,
10967 );
1101810968
1101910969 if (has_tag_capture) {
11020 const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture);
10970 const tag_ref = try spa.analyzeTagCapture(child_block, capture_src, inline_case_capture);
1102110971 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
1102210972 }
1102310973 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
......@@ -11032,7 +10982,7 @@ const SwitchProngAnalysis = struct {
1103210982 child_block,
1103310983 capture == .by_ref,
1103410984 prong_type == .special,
11035 raw_capture_src,
10985 capture_src,
1103610986 case_vals,
1103710987 inline_case_capture,
1103810988 );
......@@ -11058,8 +11008,8 @@ const SwitchProngAnalysis = struct {
1105811008 prong_type: enum { normal, special },
1105911009 prong_body: []const Zir.Inst.Index,
1106011010 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11061 /// Must use the `scalar`, `special`, or `multi_capture` union field.
11062 raw_capture_src: Module.SwitchProngSrc,
11011 /// Must use the `switch_capture` field in `offset`.
11012 capture_src: LazySrcLoc,
1106311013 /// The set of all values which can reach this prong. May be undefined
1106411014 /// if the prong is special or contains ranges.
1106511015 case_vals: []const Air.Inst.Ref,
......@@ -11073,7 +11023,7 @@ const SwitchProngAnalysis = struct {
1107311023 const sema = spa.sema;
1107411024
1107511025 if (has_tag_capture) {
11076 const tag_ref = try spa.analyzeTagCapture(case_block, raw_capture_src, inline_case_capture);
11026 const tag_ref = try spa.analyzeTagCapture(case_block, capture_src, inline_case_capture);
1107711027 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
1107811028 }
1107911029 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
......@@ -11088,7 +11038,7 @@ const SwitchProngAnalysis = struct {
1108811038 case_block,
1108911039 capture == .by_ref,
1109011040 prong_type == .special,
11091 raw_capture_src,
11041 capture_src,
1109211042 case_vals,
1109311043 inline_case_capture,
1109411044 );
......@@ -11109,23 +11059,18 @@ const SwitchProngAnalysis = struct {
1110911059 fn analyzeTagCapture(
1111011060 spa: SwitchProngAnalysis,
1111111061 block: *Block,
11112 raw_capture_src: Module.SwitchProngSrc,
11062 capture_src: LazySrcLoc,
1111311063 inline_case_capture: Air.Inst.Ref,
1111411064 ) CompileError!Air.Inst.Ref {
1111511065 const sema = spa.sema;
1111611066 const mod = sema.mod;
1111711067 const operand_ty = sema.typeOf(spa.operand);
1111811068 if (operand_ty.zigTypeTag(mod) != .Union) {
11119 const zir_datas = sema.code.instructions.items(.data);
11120 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;
11121 const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) {
11122 .scalar_capture => |i| .{ .scalar_tag_capture = i },
11123 .multi_capture => |i| .{ .multi_tag_capture = i },
11124 .special_capture => .special_tag_capture,
11125 else => unreachable,
11069 const tag_capture_src: LazySrcLoc = .{
11070 .base_node_inst = capture_src.base_node_inst,
11071 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
1112611072 };
11127 const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none);
11128 return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{
11073 return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{
1112911074 operand_ty.fmt(mod),
1113011075 });
1113111076 }
......@@ -11138,7 +11083,7 @@ const SwitchProngAnalysis = struct {
1113811083 block: *Block,
1113911084 capture_byref: bool,
1114011085 is_special_prong: bool,
11141 raw_capture_src: Module.SwitchProngSrc,
11086 capture_src: LazySrcLoc,
1114211087 case_vals: []const Air.Inst.Ref,
1114311088 inline_case_capture: Air.Inst.Ref,
1114411089 ) CompileError!Air.Inst.Ref {
......@@ -11151,10 +11096,10 @@ const SwitchProngAnalysis = struct {
1115111096
1115211097 const operand_ty = sema.typeOf(spa.operand);
1115311098 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;
11154 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
11099 const operand_src = block.src(.{ .node_offset_switch_operand = switch_node_offset });
1115511100
1115611101 if (inline_case_capture != .none) {
11157 const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
11102 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inline_case_capture, undefined) catch unreachable;
1115811103 if (operand_ty.zigTypeTag(zcu) == .Union) {
1115911104 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
1116011105 const union_obj = zcu.typeToUnion(operand_ty).?;
......@@ -11195,7 +11140,7 @@ const SwitchProngAnalysis = struct {
1119511140 .ErrorSet => if (spa.else_error_ty) |ty| {
1119611141 return sema.bitCast(block, ty, spa.operand, operand_src, null);
1119711142 } else {
11198 try block.addUnreachable(operand_src, false);
11143 try sema.analyzeUnreachable(block, operand_src, false);
1119911144 return .unreachable_value;
1120011145 },
1120111146 else => return spa.operand,
......@@ -11205,14 +11150,14 @@ const SwitchProngAnalysis = struct {
1120511150 switch (operand_ty.zigTypeTag(zcu)) {
1120611151 .Union => {
1120711152 const union_obj = zcu.typeToUnion(operand_ty).?;
11208 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11153 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1120911154
1121011155 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;
1121111156 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1121211157
1121311158 const field_indices = try sema.arena.alloc(u32, case_vals.len);
1121411159 for (case_vals, field_indices) |item, *field_idx| {
11215 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
11160 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1121611161 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;
1121711162 }
1121811163
......@@ -11232,27 +11177,22 @@ const SwitchProngAnalysis = struct {
1123211177 }
1123311178
1123411179 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11235 @memset(case_srcs, .unneeded);
11236
11237 break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11238 error.NeededSourceLocation => {
11239 // This must be a multi-prong so this must be a `multi_capture` src
11240 const multi_idx = raw_capture_src.multi_capture;
11241 const src_decl_ptr = zcu.declPtr(block.src_decl);
11242 for (case_srcs, 0..) |*case_src, i| {
11243 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
11244 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11245 }
11246 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11247 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {
11248 error.AnalysisFail => {
11249 const msg = sema.err orelse return error.AnalysisFail;
11250 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});
11251 return error.AnalysisFail;
11252 },
11253 else => |e| return e,
11254 };
11255 unreachable;
11180 for (case_srcs, 0..) |*case_src, i| {
11181 case_src.* = .{
11182 .base_node_inst = capture_src.base_node_inst,
11183 .offset = .{ .switch_case_item = .{
11184 .switch_node_offset = switch_node_offset,
11185 .case_idx = capture_src.offset.switch_capture.case_idx,
11186 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11187 } },
11188 };
11189 }
11190
11191 break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11192 error.AnalysisFail => {
11193 const msg = sema.err orelse return error.AnalysisFail;
11194 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11195 return error.AnalysisFail;
1125611196 },
1125711197 else => |e| return e,
1125811198 };
......@@ -11280,28 +11220,23 @@ const SwitchProngAnalysis = struct {
1128011220 dummy.* = try zcu.undefRef(field_ptr_ty);
1128111221 }
1128211222 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11283 @memset(case_srcs, .unneeded);
11284
11285 break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11286 error.NeededSourceLocation => {
11287 // This must be a multi-prong so this must be a `multi_capture` src
11288 const multi_idx = raw_capture_src.multi_capture;
11289 const src_decl_ptr = zcu.declPtr(block.src_decl);
11290 for (case_srcs, 0..) |*case_src, i| {
11291 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
11292 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11293 }
11294 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11295 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {
11296 error.AnalysisFail => {
11297 const msg = sema.err orelse return error.AnalysisFail;
11298 try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{});
11299 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});
11300 return error.AnalysisFail;
11301 },
11302 else => |e| return e,
11303 };
11304 unreachable;
11223 for (case_srcs, 0..) |*case_src, i| {
11224 case_src.* = .{
11225 .base_node_inst = capture_src.base_node_inst,
11226 .offset = .{ .switch_case_item = .{
11227 .switch_node_offset = switch_node_offset,
11228 .case_idx = capture_src.offset.switch_capture.case_idx,
11229 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11230 } },
11231 };
11232 }
11233
11234 break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11235 error.AnalysisFail => {
11236 const msg = sema.err orelse return error.AnalysisFail;
11237 try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{});
11238 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11239 return error.AnalysisFail;
1130511240 },
1130611241 else => |e| return e,
1130711242 };
......@@ -11336,7 +11271,7 @@ const SwitchProngAnalysis = struct {
1133611271 const first_non_imc = in_mem: {
1133711272 for (field_indices, 0..) |field_idx, i| {
1133811273 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11339 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {
11274 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
1134011275 break :in_mem i;
1134111276 }
1134211277 }
......@@ -11359,7 +11294,7 @@ const SwitchProngAnalysis = struct {
1135911294 const next = first_non_imc + 1;
1136011295 for (field_indices[next..], next..) |field_idx, i| {
1136111296 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11362 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {
11297 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
1136311298 in_mem_coercible.unset(i);
1136411299 }
1136511300 }
......@@ -11388,20 +11323,19 @@ const SwitchProngAnalysis = struct {
1138811323 var coerce_block = block.makeSubBlock();
1138911324 defer coerce_block.instructions.deinit(sema.gpa);
1139011325
11326 const case_src: LazySrcLoc = .{
11327 .base_node_inst = capture_src.base_node_inst,
11328 .offset = .{ .switch_case_item = .{
11329 .switch_node_offset = switch_node_offset,
11330 .case_idx = capture_src.offset.switch_capture.case_idx,
11331 .item_idx = .{ .kind = .single, .index = @intCast(idx) },
11332 } },
11333 };
11334
1139111335 const field_idx = field_indices[idx];
1139211336 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1139311337 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);
11394 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
11395 error.NeededSourceLocation => {
11396 const multi_idx = raw_capture_src.multi_capture;
11397 const src_decl_ptr = zcu.declPtr(block.src_decl);
11398 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } };
11399 const case_src = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11400 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
11401 unreachable;
11402 },
11403 else => |e| return e,
11404 };
11338 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1140511339 _ = try coerce_block.addBr(capture_block_inst, coerced);
1140611340
1140711341 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
......@@ -11455,7 +11389,6 @@ const SwitchProngAnalysis = struct {
1145511389 },
1145611390 .ErrorSet => {
1145711391 if (capture_byref) {
11458 const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none);
1145911392 return sema.fail(
1146011393 block,
1146111394 capture_src,
......@@ -11465,7 +11398,7 @@ const SwitchProngAnalysis = struct {
1146511398 }
1146611399
1146711400 if (case_vals.len == 1) {
11468 const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11401 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1146911402 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);
1147011403 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1147111404 }
......@@ -11473,7 +11406,7 @@ const SwitchProngAnalysis = struct {
1147311406 var names: InferredErrorSet.NameMap = .{};
1147411407 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1147511408 for (case_vals) |err| {
11476 const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable;
11409 const err_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, err, undefined) catch unreachable;
1147711410 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});
1147811411 }
1147911412 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());
......@@ -11527,10 +11460,10 @@ fn switchCond(
1152711460 try sema.resolveTypeFields(operand_ty);
1152811461 const enum_ty = operand_ty.unionTagType(mod) orelse {
1152911462 const msg = msg: {
11530 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
11463 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});
1153111464 errdefer msg.destroy(sema.gpa);
11532 if (operand_ty.declSrcLocOrNull(mod)) |union_src| {
11533 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
11465 if (operand_ty.srcLocOrNull(mod)) |union_src| {
11466 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
1153411467 }
1153511468 break :msg msg;
1153611469 };
......@@ -11554,7 +11487,7 @@ fn switchCond(
1155411487 }
1155511488}
1155611489
11557const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);
11490const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc);
1155811491
1155911492fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1156011493 const tracy = trace(@src());
......@@ -11563,13 +11496,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1156311496 const mod = sema.mod;
1156411497 const gpa = sema.gpa;
1156511498 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11566 const switch_src = inst_data.src();
11499 const switch_src = block.nodeOffset(inst_data.src_node);
1156711500 const switch_src_node_offset = inst_data.src_node;
11568 const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset };
11569 const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset };
11501 const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset });
11502 const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset });
1157011503 const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
11571 const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset };
11572 const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset };
11504 const main_operand_src = block.src(.{ .node_offset_if_cond = extra.data.main_src_node_offset });
11505 const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset });
1157311506
1157411507 const raw_operand_val = try sema.resolveInst(extra.data.operand);
1157511508
......@@ -11675,7 +11608,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1167511608 var child_block: Block = .{
1167611609 .parent = block,
1167711610 .sema = sema,
11678 .src_decl = block.src_decl,
1167911611 .namespace = block.namespace,
1168011612 .instructions = .{},
1168111613 .label = &label,
......@@ -11689,6 +11621,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1168911621 .runtime_index = block.runtime_index,
1169011622 .error_return_trace_index = block.error_return_trace_index,
1169111623 .want_safety = block.want_safety,
11624 .src_base_inst = block.src_base_inst,
11625 .type_name_ctx = block.type_name_ctx,
1169211626 };
1169311627 const merges = &child_block.label.?.merges;
1169411628 defer child_block.instructions.deinit(gpa);
......@@ -11755,6 +11689,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1175511689 try sema.switchCond(block, switch_operand_src, spa.operand),
1175611690 err_val,
1175711691 operand_err_set_ty,
11692 switch_src_node_offset,
1175811693 .{
1175911694 .body = else_case.body,
1176011695 .end = else_case.end,
......@@ -11796,7 +11731,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1179611731
1179711732 var sub_block = child_block.makeSubBlock();
1179811733 sub_block.runtime_loop = null;
11799 sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod);
11734 sub_block.runtime_cond = main_operand_src;
1180011735 sub_block.runtime_index.increment();
1180111736 sub_block.need_debug_scope = null; // this body is emitted regardless
1180211737 defer sub_block.instructions.deinit(gpa);
......@@ -11871,10 +11806,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1187111806 const mod = sema.mod;
1187211807 const gpa = sema.gpa;
1187311808 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11874 const src = inst_data.src();
11809 const src = block.nodeOffset(inst_data.src_node);
1187511810 const src_node_offset = inst_data.src_node;
11876 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
11877 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };
11811 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
11812 const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset });
1187811813 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
1187911814
1188011815 const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: {
......@@ -11941,7 +11876,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1194111876 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
1194211877
1194311878 // Duplicate checking variables later also used for `inline else`.
11944 var seen_enum_fields: []?Module.SwitchProngSrc = &.{};
11879 var seen_enum_fields: []?LazySrcLoc = &.{};
1194511880 var seen_errors = SwitchErrorSet.init(gpa);
1194611881 var range_set = RangeSet.init(gpa, mod);
1194711882 var true_count: u8 = 0;
......@@ -11964,21 +11899,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1196411899 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {
1196511900 const msg = msg: {
1196611901 const msg = try sema.errMsg(
11967 block,
1196811902 src,
1196911903 "'_' prong only allowed when switching on non-exhaustive enums",
1197011904 .{},
1197111905 );
1197211906 errdefer msg.destroy(gpa);
1197311907 try sema.errNote(
11974 block,
1197511908 special_prong_src,
1197611909 msg,
1197711910 "'_' prong here",
1197811911 .{},
1197911912 );
1198011913 try sema.errNote(
11981 block,
1198211914 src,
1198311915 msg,
1198411916 "consider using 'else'",
......@@ -11993,7 +11925,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1199311925 switch (operand_ty.zigTypeTag(mod)) {
1199411926 .Union => unreachable, // handled in `switchCond`
1199511927 .Enum => {
11996 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount(mod));
11928 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod));
1199711929 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);
1199811930 @memset(seen_enum_fields, null);
1199911931 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
......@@ -12013,8 +11945,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1201311945 &range_set,
1201411946 item_ref,
1201511947 operand_ty,
12016 src_node_offset,
12017 .{ .scalar = scalar_i },
11948 block.src(.{ .switch_case_item = .{
11949 .switch_node_offset = src_node_offset,
11950 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
11951 .item_idx = .{ .kind = .single, .index = 0 },
11952 } }),
1201811953 ));
1201911954 }
1202011955 }
......@@ -12038,8 +11973,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1203811973 &range_set,
1203911974 item_ref,
1204011975 operand_ty,
12041 src_node_offset,
12042 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
11976 block.src(.{ .switch_case_item = .{
11977 .switch_node_offset = src_node_offset,
11978 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
11979 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
11980 } }),
1204311981 ));
1204411982 }
1204511983
......@@ -12060,7 +11998,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1206011998 } else if (!all_tags_handled) {
1206111999 const msg = msg: {
1206212000 const msg = try sema.errMsg(
12063 block,
1206412001 src,
1206512002 "switch must handle all possibilities",
1206612003 .{},
......@@ -12078,8 +12015,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1207812015 .{field_name.fmt(&mod.intern_pool)},
1207912016 );
1208012017 }
12081 try mod.errNoteNonLazy(
12082 operand_ty.declSrcLoc(mod),
12018 try sema.errNote(
12019 operand_ty.srcLoc(mod),
1208312020 msg,
1208412021 "enum '{}' declared here",
1208512022 .{operand_ty.fmt(mod)},
......@@ -12123,8 +12060,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1212312060 &range_set,
1212412061 item_ref,
1212512062 operand_ty,
12126 src_node_offset,
12127 .{ .scalar = scalar_i },
12063 block.src(.{ .switch_case_item = .{
12064 .switch_node_offset = src_node_offset,
12065 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12066 .item_idx = .{ .kind = .single, .index = 0 },
12067 } }),
1212812068 ));
1212912069 }
1213012070 }
......@@ -12147,8 +12087,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1214712087 &range_set,
1214812088 item_ref,
1214912089 operand_ty,
12150 src_node_offset,
12151 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12090 block.src(.{ .switch_case_item = .{
12091 .switch_node_offset = src_node_offset,
12092 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12093 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12094 } }),
1215212095 ));
1215312096 }
1215412097
......@@ -12166,8 +12109,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1216612109 item_first,
1216712110 item_last,
1216812111 operand_ty,
12169 src_node_offset,
12170 .{ .range = .{ .prong = multi_i, .item = range_i } },
12112 block.src(.{ .switch_case_item = .{
12113 .switch_node_offset = src_node_offset,
12114 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12115 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12116 } }),
1217112117 );
1217212118 case_vals.appendAssumeCapacity(vals[0]);
1217312119 case_vals.appendAssumeCapacity(vals[1]);
......@@ -12218,8 +12164,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1221812164 &true_count,
1221912165 &false_count,
1222012166 item_ref,
12221 src_node_offset,
12222 .{ .scalar = scalar_i },
12167 block.src(.{ .switch_case_item = .{
12168 .switch_node_offset = src_node_offset,
12169 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12170 .item_idx = .{ .kind = .single, .index = 0 },
12171 } }),
1222312172 ));
1222412173 }
1222512174 }
......@@ -12242,8 +12191,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1224212191 &true_count,
1224312192 &false_count,
1224412193 item_ref,
12245 src_node_offset,
12246 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12194 block.src(.{ .switch_case_item = .{
12195 .switch_node_offset = src_node_offset,
12196 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12197 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12198 } }),
1224712199 ));
1224812200 }
1224912201
......@@ -12301,8 +12253,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1230112253 &seen_values,
1230212254 item_ref,
1230312255 operand_ty,
12304 src_node_offset,
12305 .{ .scalar = scalar_i },
12256 block.src(.{ .switch_case_item = .{
12257 .switch_node_offset = src_node_offset,
12258 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12259 .item_idx = .{ .kind = .single, .index = 0 },
12260 } }),
1230612261 ));
1230712262 }
1230812263 }
......@@ -12325,8 +12280,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1232512280 &seen_values,
1232612281 item_ref,
1232712282 operand_ty,
12328 src_node_offset,
12329 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12283 block.src(.{ .switch_case_item = .{
12284 .switch_node_offset = src_node_offset,
12285 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12286 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12287 } }),
1233012288 ));
1233112289 }
1233212290
......@@ -12382,7 +12340,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1238212340 var child_block: Block = .{
1238312341 .parent = block,
1238412342 .sema = sema,
12385 .src_decl = block.src_decl,
1238612343 .namespace = block.namespace,
1238712344 .instructions = .{},
1238812345 .label = &label,
......@@ -12396,6 +12353,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1239612353 .runtime_index = block.runtime_index,
1239712354 .want_safety = block.want_safety,
1239812355 .error_return_trace_index = block.error_return_trace_index,
12356 .src_base_inst = block.src_base_inst,
12357 .type_name_ctx = block.type_name_ctx,
1239912358 };
1240012359 const merges = &child_block.label.?.merges;
1240112360 defer child_block.instructions.deinit(gpa);
......@@ -12409,6 +12368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1240912368 operand,
1241012369 operand_val,
1241112370 operand_ty,
12371 src_node_offset,
1241212372 special,
1241312373 case_vals,
1241412374 scalar_cases_len,
......@@ -12441,7 +12401,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1244112401 .special,
1244212402 special.body,
1244312403 special.capture,
12444 .special_capture,
12404 block.src(.{ .switch_capture = .{
12405 .switch_node_offset = src_node_offset,
12406 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12407 } }),
1244512408 undefined, // case_vals may be undefined for special prongs
1244612409 .none,
1244712410 false,
......@@ -12508,9 +12471,9 @@ fn analyzeSwitchRuntimeBlock(
1250812471 union_originally: bool,
1250912472 maybe_union_ty: Type,
1251012473 err_set: bool,
12511 src_node_offset: i32,
12474 switch_node_offset: i32,
1251212475 special_prong_src: LazySrcLoc,
12513 seen_enum_fields: []?Module.SwitchProngSrc,
12476 seen_enum_fields: []?LazySrcLoc,
1251412477 seen_errors: SwitchErrorSet,
1251512478 range_set: RangeSet,
1251612479 true_count: u8,
......@@ -12531,7 +12494,7 @@ fn analyzeSwitchRuntimeBlock(
1253112494
1253212495 var case_block = child_block.makeSubBlock();
1253312496 case_block.runtime_loop = null;
12534 case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod);
12497 case_block.runtime_cond = operand_src;
1253512498 case_block.runtime_index.increment();
1253612499 case_block.need_debug_scope = null; // this body is emitted regardless
1253712500 defer case_block.instructions.deinit(gpa);
......@@ -12553,7 +12516,7 @@ fn analyzeSwitchRuntimeBlock(
1255312516 // `item` is already guaranteed to be constant known.
1255412517
1255512518 const analyze_body = if (union_originally) blk: {
12556 const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12519 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1255712520 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
1255812521 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1255912522 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
......@@ -12567,7 +12530,10 @@ fn analyzeSwitchRuntimeBlock(
1256712530 .normal,
1256812531 body,
1256912532 info.capture,
12570 .{ .scalar_capture = @intCast(scalar_i) },
12533 child_block.src(.{ .switch_capture = .{
12534 .switch_node_offset = switch_node_offset,
12535 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12536 } }),
1257112537 &.{item},
1257212538 if (info.is_inline) item else .none,
1257312539 info.has_tag_capture,
......@@ -12622,8 +12588,8 @@ fn analyzeSwitchRuntimeBlock(
1262212588 const item_first_ref = range_items[0];
1262312589 const item_last_ref = range_items[1];
1262412590
12625 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12626 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
12591 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
12592 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;
1262712593
1262812594 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
1262912595 // Previous validation has resolved any possible lazy values.
......@@ -12639,17 +12605,11 @@ fn analyzeSwitchRuntimeBlock(
1263912605 case_block.instructions.shrinkRetainingCapacity(0);
1264012606 case_block.error_return_trace_index = child_block.error_return_trace_index;
1264112607
12642 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
12643 error.NeededSourceLocation => {
12644 const case_src = Module.SwitchProngSrc{
12645 .range = .{ .prong = multi_i, .item = range_i },
12646 };
12647 const decl = mod.declPtr(case_block.src_decl);
12648 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12649 unreachable;
12650 },
12651 else => return err,
12652 };
12608 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12609 .switch_node_offset = switch_node_offset,
12610 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12611 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12612 } }));
1265312613 emit_bb = true;
1265412614
1265512615 try spa.analyzeProngRuntime(
......@@ -12657,7 +12617,10 @@ fn analyzeSwitchRuntimeBlock(
1265712617 .normal,
1265812618 body,
1265912619 info.capture,
12660 .{ .multi_capture = multi_i },
12620 child_block.src(.{ .switch_capture = .{
12621 .switch_node_offset = switch_node_offset,
12622 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12623 } }),
1266112624 undefined, // case_vals may be undefined for ranges
1266212625 item_ref,
1266312626 info.has_tag_capture,
......@@ -12680,22 +12643,16 @@ fn analyzeSwitchRuntimeBlock(
1268012643 case_block.error_return_trace_index = child_block.error_return_trace_index;
1268112644
1268212645 const analyze_body = if (union_originally) blk: {
12683 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12646 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1268412647 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1268512648 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1268612649 } else true;
1268712650
12688 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
12689 error.NeededSourceLocation => {
12690 const case_src = Module.SwitchProngSrc{
12691 .multi = .{ .prong = multi_i, .item = @intCast(item_i) },
12692 };
12693 const decl = mod.declPtr(case_block.src_decl);
12694 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12695 unreachable;
12696 },
12697 else => return err,
12698 };
12651 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12652 .switch_node_offset = switch_node_offset,
12653 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12654 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12655 } }));
1269912656 emit_bb = true;
1270012657
1270112658 if (analyze_body) {
......@@ -12704,7 +12661,10 @@ fn analyzeSwitchRuntimeBlock(
1270412661 .normal,
1270512662 body,
1270612663 info.capture,
12707 .{ .multi_capture = multi_i },
12664 child_block.src(.{ .switch_capture = .{
12665 .switch_node_offset = switch_node_offset,
12666 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12667 } }),
1270812668 &.{item},
1270912669 item,
1271012670 info.has_tag_capture,
......@@ -12734,7 +12694,7 @@ fn analyzeSwitchRuntimeBlock(
1273412694
1273512695 const analyze_body = if (union_originally)
1273612696 for (items) |item| {
12737 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12697 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1273812698 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1273912699 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1274012700 } else false
......@@ -12751,7 +12711,10 @@ fn analyzeSwitchRuntimeBlock(
1275112711 .normal,
1275212712 body,
1275312713 info.capture,
12754 .{ .multi_capture = multi_i },
12714 child_block.src(.{ .switch_capture = .{
12715 .switch_node_offset = switch_node_offset,
12716 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12717 } }),
1275512718 items,
1275612719 .none,
1275712720 false,
......@@ -12835,7 +12798,10 @@ fn analyzeSwitchRuntimeBlock(
1283512798 .normal,
1283612799 body,
1283712800 info.capture,
12838 .{ .multi_capture = multi_i },
12801 child_block.src(.{ .switch_capture = .{
12802 .switch_node_offset = switch_node_offset,
12803 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12804 } }),
1283912805 items,
1284012806 .none,
1284112807 false,
......@@ -12900,7 +12866,10 @@ fn analyzeSwitchRuntimeBlock(
1290012866 .special,
1290112867 special.body,
1290212868 special.capture,
12903 .special_capture,
12869 child_block.src(.{ .switch_capture = .{
12870 .switch_node_offset = switch_node_offset,
12871 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12872 } }),
1290412873 &.{item_ref},
1290512874 item_ref,
1290612875 special.has_tag_capture,
......@@ -12945,7 +12914,10 @@ fn analyzeSwitchRuntimeBlock(
1294512914 .special,
1294612915 special.body,
1294712916 special.capture,
12948 .special_capture,
12917 child_block.src(.{ .switch_capture = .{
12918 .switch_node_offset = switch_node_offset,
12919 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12920 } }),
1294912921 &.{item_ref},
1295012922 item_ref,
1295112923 special.has_tag_capture,
......@@ -12976,7 +12948,10 @@ fn analyzeSwitchRuntimeBlock(
1297612948 .special,
1297712949 special.body,
1297812950 special.capture,
12979 .special_capture,
12951 child_block.src(.{ .switch_capture = .{
12952 .switch_node_offset = switch_node_offset,
12953 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12954 } }),
1298012955 &.{item_ref},
1298112956 item_ref,
1298212957 special.has_tag_capture,
......@@ -13004,7 +12979,10 @@ fn analyzeSwitchRuntimeBlock(
1300412979 .special,
1300512980 special.body,
1300612981 special.capture,
13007 .special_capture,
12982 child_block.src(.{ .switch_capture = .{
12983 .switch_node_offset = switch_node_offset,
12984 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12985 } }),
1300812986 &.{.bool_true},
1300912987 .bool_true,
1301012988 special.has_tag_capture,
......@@ -13030,7 +13008,10 @@ fn analyzeSwitchRuntimeBlock(
1303013008 .special,
1303113009 special.body,
1303213010 special.capture,
13033 .special_capture,
13011 child_block.src(.{ .switch_capture = .{
13012 .switch_node_offset = switch_node_offset,
13013 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13014 } }),
1303413015 &.{.bool_false},
1303513016 .bool_false,
1303613017 special.has_tag_capture,
......@@ -13080,7 +13061,10 @@ fn analyzeSwitchRuntimeBlock(
1308013061 .special,
1308113062 special.body,
1308213063 special.capture,
13083 .special_capture,
13064 child_block.src(.{ .switch_capture = .{
13065 .switch_node_offset = switch_node_offset,
13066 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13067 } }),
1308413068 undefined, // case_vals may be undefined for special prongs
1308513069 .none,
1308613070 false,
......@@ -13140,6 +13124,7 @@ fn resolveSwitchComptime(
1314013124 cond_operand: Air.Inst.Ref,
1314113125 operand_val: Value,
1314213126 operand_ty: Type,
13127 switch_node_offset: i32,
1314313128 special: SpecialProng,
1314413129 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),
1314513130 scalar_cases_len: u32,
......@@ -13160,7 +13145,7 @@ fn resolveSwitchComptime(
1316013145 extra_index += info.body_len;
1316113146
1316213147 const item = case_vals.items[scalar_i];
13163 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;
13148 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1316413149 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1316513150 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
1316613151 return spa.resolveProngComptime(
......@@ -13168,7 +13153,10 @@ fn resolveSwitchComptime(
1316813153 .normal,
1316913154 body,
1317013155 info.capture,
13171 .{ .scalar_capture = @intCast(scalar_i) },
13156 child_block.src(.{ .switch_capture = .{
13157 .switch_node_offset = switch_node_offset,
13158 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13159 } }),
1317213160 &.{item},
1317313161 if (info.is_inline) cond_operand else .none,
1317413162 info.has_tag_capture,
......@@ -13194,7 +13182,7 @@ fn resolveSwitchComptime(
1319413182
1319513183 for (items) |item| {
1319613184 // Validation above ensured these will succeed.
13197 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;
13185 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1319813186 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1319913187 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
1320013188 return spa.resolveProngComptime(
......@@ -13202,7 +13190,10 @@ fn resolveSwitchComptime(
1320213190 .normal,
1320313191 body,
1320413192 info.capture,
13205 .{ .multi_capture = @intCast(multi_i) },
13193 child_block.src(.{ .switch_capture = .{
13194 .switch_node_offset = switch_node_offset,
13195 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13196 } }),
1320613197 items,
1320713198 if (info.is_inline) cond_operand else .none,
1320813199 info.has_tag_capture,
......@@ -13218,8 +13209,8 @@ fn resolveSwitchComptime(
1321813209 case_val_idx += 2;
1321913210
1322013211 // Validation above ensured these will succeed.
13221 const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable;
13222 const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable;
13212 const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable;
13213 const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable;
1322313214 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1322413215 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1322513216 {
......@@ -13229,7 +13220,10 @@ fn resolveSwitchComptime(
1322913220 .normal,
1323013221 body,
1323113222 info.capture,
13232 .{ .multi_capture = @intCast(multi_i) },
13223 child_block.src(.{ .switch_capture = .{
13224 .switch_node_offset = switch_node_offset,
13225 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13226 } }),
1323313227 undefined, // case_vals may be undefined for ranges
1323413228 if (info.is_inline) cond_operand else .none,
1323513229 info.has_tag_capture,
......@@ -13251,7 +13245,10 @@ fn resolveSwitchComptime(
1325113245 .special,
1325213246 special.body,
1325313247 special.capture,
13254 .special_capture,
13248 child_block.src(.{ .switch_capture = .{
13249 .switch_node_offset = switch_node_offset,
13250 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13251 } }),
1325513252 undefined, // case_vals may be undefined for special prongs
1325613253 if (special.is_inline) cond_operand else .none,
1325713254 special.has_tag_capture,
......@@ -13337,36 +13334,19 @@ fn resolveSwitchItemVal(
1333713334 item_ref: Zir.Inst.Ref,
1333813335 /// Coerce `item_ref` to this type.
1333913336 coerce_ty: Type,
13340 switch_node_offset: i32,
13341 switch_prong_src: Module.SwitchProngSrc,
13342 range_expand: Module.SwitchProngSrc.RangeExpand,
13337 item_src: LazySrcLoc,
1334313338) CompileError!ResolvedSwitchItem {
13344 const mod = sema.mod;
1334513339 const uncoerced_item = try sema.resolveInst(item_ref);
1334613340
1334713341 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
1334813342 // Only if we know for sure we need to report a compile error do we resolve the
1334913343 // full source locations.
1335013344
13351 const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) {
13352 error.NeededSourceLocation => {
13353 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
13354 _ = try sema.coerce(block, coerce_ty, uncoerced_item, src);
13355 unreachable;
13356 },
13357 else => |e| return e,
13358 };
13345 const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src);
1335913346
13360 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {
13361 error.NeededSourceLocation => {
13362 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
13363 _ = try sema.resolveConstDefinedValue(block, src, item, .{
13364 .needed_comptime_reason = "switch prong values must be comptime-known",
13365 });
13366 unreachable;
13367 },
13368 else => |e| return e,
13369 };
13347 const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{
13348 .needed_comptime_reason = "switch prong values must be comptime-known",
13349 });
1337013350
1337113351 const val = try sema.resolveLazyValue(maybe_lazy);
1337213352 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {
......@@ -13393,7 +13373,7 @@ fn validateErrSetSwitch(
1339313373 const ip = &mod.intern_pool;
1339413374
1339513375 const src_node_offset = inst_data.src_node;
13396 const src = inst_data.src();
13376 const src = block.nodeOffset(src_node_offset);
1339713377
1339813378 var extra_index: usize = else_case.end;
1339913379 {
......@@ -13409,8 +13389,11 @@ fn validateErrSetSwitch(
1340913389 seen_errors,
1341013390 item_ref,
1341113391 operand_ty,
13412 src_node_offset,
13413 .{ .scalar = scalar_i },
13392 block.src(.{ .switch_case_item = .{
13393 .switch_node_offset = src_node_offset,
13394 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13395 .item_idx = .{ .kind = .single, .index = 0 },
13396 } }),
1341413397 ));
1341513398 }
1341613399 }
......@@ -13433,8 +13416,11 @@ fn validateErrSetSwitch(
1343313416 seen_errors,
1343413417 item_ref,
1343513418 operand_ty,
13436 src_node_offset,
13437 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
13419 block.src(.{ .switch_case_item = .{
13420 .switch_node_offset = src_node_offset,
13421 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13422 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
13423 } }),
1343813424 ));
1343913425 }
1344013426
......@@ -13463,7 +13449,6 @@ fn validateErrSetSwitch(
1346313449 if (!seen_errors.contains(error_name) and !has_else) {
1346413450 const msg = maybe_msg orelse blk: {
1346513451 maybe_msg = try sema.errMsg(
13466 block,
1346713452 src,
1346813453 "switch must handle all possibilities",
1346913454 .{},
......@@ -13472,7 +13457,6 @@ fn validateErrSetSwitch(
1347213457 };
1347313458
1347413459 try sema.errNote(
13475 block,
1347613460 src,
1347713461 msg,
1347813462 "unhandled error value: 'error.{}'",
......@@ -13550,18 +13534,24 @@ fn validateSwitchRange(
1355013534 first_ref: Zir.Inst.Ref,
1355113535 last_ref: Zir.Inst.Ref,
1355213536 operand_ty: Type,
13553 src_node_offset: i32,
13554 switch_prong_src: Module.SwitchProngSrc,
13537 item_src: LazySrcLoc,
1355513538) CompileError![2]Air.Inst.Ref {
1355613539 const mod = sema.mod;
13557 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);
13558 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);
13540 const first_src: LazySrcLoc = .{
13541 .base_node_inst = item_src.base_node_inst,
13542 .offset = .{ .switch_case_item_range_first = item_src.offset.switch_case_item },
13543 };
13544 const last_src: LazySrcLoc = .{
13545 .base_node_inst = item_src.base_node_inst,
13546 .offset = .{ .switch_case_item_range_last = item_src.offset.switch_case_item },
13547 };
13548 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, first_src);
13549 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, last_src);
1355913550 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {
13560 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);
13561 return sema.fail(block, src, "range start value is greater than the end value", .{});
13551 return sema.fail(block, item_src, "range start value is greater than the end value", .{});
1356213552 }
13563 const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src);
13564 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13553 const maybe_prev_src = try range_set.add(first.val, last.val, item_src);
13554 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1356513555 return .{ first.ref, last.ref };
1356613556}
1356713557
......@@ -13571,36 +13561,34 @@ fn validateSwitchItemInt(
1357113561 range_set: *RangeSet,
1357213562 item_ref: Zir.Inst.Ref,
1357313563 operand_ty: Type,
13574 src_node_offset: i32,
13575 switch_prong_src: Module.SwitchProngSrc,
13564 item_src: LazySrcLoc,
1357613565) CompileError!Air.Inst.Ref {
13577 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13578 const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src);
13579 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13566 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13567 const maybe_prev_src = try range_set.add(item.val, item.val, item_src);
13568 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1358013569 return item.ref;
1358113570}
1358213571
1358313572fn validateSwitchItemEnum(
1358413573 sema: *Sema,
1358513574 block: *Block,
13586 seen_fields: []?Module.SwitchProngSrc,
13575 seen_fields: []?LazySrcLoc,
1358713576 range_set: *RangeSet,
1358813577 item_ref: Zir.Inst.Ref,
1358913578 operand_ty: Type,
13590 src_node_offset: i32,
13591 switch_prong_src: Module.SwitchProngSrc,
13579 item_src: LazySrcLoc,
1359213580) CompileError!Air.Inst.Ref {
1359313581 const ip = &sema.mod.intern_pool;
13594 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13582 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
1359513583 const int = ip.indexToKey(item.val).enum_tag.int;
1359613584 const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse {
13597 const maybe_prev_src = try range_set.add(int, int, switch_prong_src);
13598 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13585 const maybe_prev_src = try range_set.add(int, int, item_src);
13586 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1359913587 return item.ref;
1360013588 };
1360113589 const maybe_prev_src = seen_fields[field_index];
13602 seen_fields[field_index] = switch_prong_src;
13603 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13590 seen_fields[field_index] = item_src;
13591 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1360413592 return item.ref;
1360513593}
1360613594
......@@ -13610,50 +13598,41 @@ fn validateSwitchItemError(
1361013598 seen_errors: *SwitchErrorSet,
1361113599 item_ref: Zir.Inst.Ref,
1361213600 operand_ty: Type,
13613 src_node_offset: i32,
13614 switch_prong_src: Module.SwitchProngSrc,
13601 item_src: LazySrcLoc,
1361513602) CompileError!Air.Inst.Ref {
1361613603 const ip = &sema.mod.intern_pool;
13617 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13604 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
1361813605 const error_name = ip.indexToKey(item.val).err.name;
13619 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
13606 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, item_src)) |prev|
1362013607 prev.value
1362113608 else
1362213609 null;
13623 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13610 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1362413611 return item.ref;
1362513612}
1362613613
1362713614fn validateSwitchDupe(
1362813615 sema: *Sema,
1362913616 block: *Block,
13630 maybe_prev_src: ?Module.SwitchProngSrc,
13631 switch_prong_src: Module.SwitchProngSrc,
13632 src_node_offset: i32,
13617 maybe_prev_src: ?LazySrcLoc,
13618 item_src: LazySrcLoc,
1363313619) CompileError!void {
13634 const prev_prong_src = maybe_prev_src orelse return;
13635 const mod = sema.mod;
13636 const block_src_decl = mod.declPtr(block.src_decl);
13637 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13638 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13639 const msg = msg: {
13620 const prev_item_src = maybe_prev_src orelse return;
13621 return sema.failWithOwnedErrorMsg(block, msg: {
1364013622 const msg = try sema.errMsg(
13641 block,
13642 src,
13623 item_src,
1364313624 "duplicate switch value",
1364413625 .{},
1364513626 );
1364613627 errdefer msg.destroy(sema.gpa);
1364713628 try sema.errNote(
13648 block,
13649 prev_src,
13629 prev_item_src,
1365013630 msg,
1365113631 "previous value here",
1365213632 .{},
1365313633 );
1365413634 break :msg msg;
13655 };
13656 return sema.failWithOwnedErrorMsg(block, msg);
13635 });
1365713636}
1365813637
1365913638fn validateSwitchItemBool(
......@@ -13662,25 +13641,21 @@ fn validateSwitchItemBool(
1366213641 true_count: *u8,
1366313642 false_count: *u8,
1366413643 item_ref: Zir.Inst.Ref,
13665 src_node_offset: i32,
13666 switch_prong_src: Module.SwitchProngSrc,
13644 item_src: LazySrcLoc,
1366713645) CompileError!Air.Inst.Ref {
13668 const mod = sema.mod;
13669 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);
13646 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src);
1367013647 if (Value.fromInterned(item.val).toBool()) {
1367113648 true_count.* += 1;
1367213649 } else {
1367313650 false_count.* += 1;
1367413651 }
1367513652 if (true_count.* > 1 or false_count.* > 1) {
13676 const block_src_decl = sema.mod.declPtr(block.src_decl);
13677 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13678 return sema.fail(block, src, "duplicate switch value", .{});
13653 return sema.fail(block, item_src, "duplicate switch value", .{});
1367913654 }
1368013655 return item.ref;
1368113656}
1368213657
13683const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc);
13658const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc);
1368413659
1368513660fn validateSwitchItemSparse(
1368613661 sema: *Sema,
......@@ -13688,12 +13663,11 @@ fn validateSwitchItemSparse(
1368813663 seen_values: *ValueSrcMap,
1368913664 item_ref: Zir.Inst.Ref,
1369013665 operand_ty: Type,
13691 src_node_offset: i32,
13692 switch_prong_src: Module.SwitchProngSrc,
13666 item_src: LazySrcLoc,
1369313667) CompileError!Air.Inst.Ref {
13694 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13695 const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref;
13696 try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset);
13668 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13669 const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref;
13670 try sema.validateSwitchDupe(block, kv.value, item_src);
1369713671 unreachable;
1369813672}
1369913673
......@@ -13707,19 +13681,17 @@ fn validateSwitchNoRange(
1370713681 if (ranges_len == 0)
1370813682 return;
1370913683
13710 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
13711 const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset };
13684 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
13685 const range_src = block.src(.{ .node_offset_switch_range = src_node_offset });
1371213686
1371313687 const msg = msg: {
1371413688 const msg = try sema.errMsg(
13715 block,
1371613689 operand_src,
1371713690 "ranges not allowed when switching on type '{}'",
1371813691 .{operand_ty.fmt(sema.mod)},
1371913692 );
1372013693 errdefer msg.destroy(sema.gpa);
1372113694 try sema.errNote(
13722 block,
1372313695 range_src,
1372413696 msg,
1372513697 "range here",
......@@ -13833,7 +13805,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1383313805 }
1383413806 } else return;
1383513807 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
13836 const src = inst_data.src();
13808 const src = block.nodeOffset(inst_data.src_node);
1383713809
1383813810 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
1383913811 if (val.getErrorName(sema.mod).unwrap()) |name| {
......@@ -13846,8 +13818,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1384613818 const mod = sema.mod;
1384713819 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1384813820 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13849 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13850 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
13821 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13822 const name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1385113823 const ty = try sema.resolveType(block, ty_src, extra.lhs);
1385213824 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
1385313825 .needed_comptime_reason = "field name must be comptime-known",
......@@ -13897,9 +13869,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1389713869 const mod = sema.mod;
1389813870 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1389913871 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13900 const src = inst_data.src();
13901 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13902 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
13872 const src = block.nodeOffset(inst_data.src_node);
13873 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13874 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1390313875 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
1390413876 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
1390513877 .needed_comptime_reason = "decl name must be comptime-known",
......@@ -13929,7 +13901,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1392913901
1393013902 const mod = sema.mod;
1393113903 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
13932 const operand_src = inst_data.src();
13904 const operand_src = block.tokenOffset(inst_data.src_tok);
1393313905 const operand = inst_data.get(sema.code);
1393413906
1393513907 const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) {
......@@ -13958,7 +13930,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1395813930
1395913931 const mod = sema.mod;
1396013932 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
13961 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13933 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1396213934 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
1396313935 .needed_comptime_reason = "file path name must be comptime-known",
1396413936 });
......@@ -13967,8 +13939,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1396713939 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
1396813940 }
1396913941
13970 const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod);
13971 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
13942 const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) {
1397213943 error.ImportOutsideModulePath => {
1397313944 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
1397413945 },
......@@ -14009,9 +13980,9 @@ fn zirShl(
1400913980
1401013981 const mod = sema.mod;
1401113982 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14012 const src = inst_data.src();
14013 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14014 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
13983 const src = block.nodeOffset(inst_data.src_node);
13984 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
13985 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1401513986 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1401613987 const lhs = try sema.resolveInst(extra.lhs);
1401713988 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14179,9 +14150,9 @@ fn zirShr(
1417914150
1418014151 const mod = sema.mod;
1418114152 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14182 const src = inst_data.src();
14183 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14184 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14153 const src = block.nodeOffset(inst_data.src_node);
14154 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14155 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1418514156 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1418614157 const lhs = try sema.resolveInst(extra.lhs);
1418714158 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14314,9 +14285,9 @@ fn zirBitwise(
1431414285
1431514286 const mod = sema.mod;
1431614287 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14317 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14318 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14319 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14288 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
14289 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14290 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1432014291 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1432114292 const lhs = try sema.resolveInst(extra.lhs);
1432214293 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14368,8 +14339,8 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1436814339
1436914340 const mod = sema.mod;
1437014341 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
14371 const src = inst_data.src();
14372 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
14342 const src = block.nodeOffset(inst_data.src_node);
14343 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1437314344
1437414345 const operand = try sema.resolveInst(inst_data.operand);
1437514346 const operand_type = sema.typeOf(operand);
......@@ -14415,7 +14386,7 @@ fn analyzeTupleCat(
1441514386 const mod = sema.mod;
1441614387 const lhs_ty = sema.typeOf(lhs);
1441714388 const rhs_ty = sema.typeOf(rhs);
14418 const src = LazySrcLoc.nodeOffset(src_node);
14389 const src = block.nodeOffset(src_node);
1441914390
1442014391 const lhs_len = lhs_ty.structFieldCount(mod);
1442114392 const rhs_len = rhs_ty.structFieldCount(mod);
......@@ -14442,10 +14413,10 @@ fn analyzeTupleCat(
1444214413 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
1444314414 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
1444414415 values[i] = default_val.toIntern();
14445 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14416 const operand_src = block.src(.{ .array_cat_lhs = .{
1444614417 .array_cat_offset = src_node,
1444714418 .elem_index = i,
14448 } };
14419 } });
1444914420 if (default_val.toIntern() == .unreachable_value) {
1445014421 runtime_src = operand_src;
1445114422 values[i] = .none;
......@@ -14456,10 +14427,10 @@ fn analyzeTupleCat(
1445614427 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
1445714428 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
1445814429 values[i + lhs_len] = default_val.toIntern();
14459 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14430 const operand_src = block.src(.{ .array_cat_rhs = .{
1446014431 .array_cat_offset = src_node,
1446114432 .elem_index = i,
14462 } };
14433 } });
1446314434 if (default_val.toIntern() == .unreachable_value) {
1446414435 runtime_src = operand_src;
1446514436 values[i + lhs_len] = .none;
......@@ -14487,18 +14458,18 @@ fn analyzeTupleCat(
1448714458 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
1448814459 var i: u32 = 0;
1448914460 while (i < lhs_len) : (i += 1) {
14490 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14461 const operand_src = block.src(.{ .array_cat_lhs = .{
1449114462 .array_cat_offset = src_node,
1449214463 .elem_index = i,
14493 } };
14464 } });
1449414465 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);
1449514466 }
1449614467 i = 0;
1449714468 while (i < rhs_len) : (i += 1) {
14498 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14469 const operand_src = block.src(.{ .array_cat_rhs = .{
1449914470 .array_cat_offset = src_node,
1450014471 .elem_index = i,
14501 } };
14472 } });
1450214473 element_refs[i + lhs_len] =
1450314474 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
1450414475 }
......@@ -14517,7 +14488,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1451714488 const rhs = try sema.resolveInst(extra.rhs);
1451814489 const lhs_ty = sema.typeOf(lhs);
1451914490 const rhs_ty = sema.typeOf(rhs);
14520 const src = inst_data.src();
14491 const src = block.nodeOffset(inst_data.src_node);
1452114492
1452214493 const lhs_is_tuple = lhs_ty.isTuple(mod);
1452314494 const rhs_is_tuple = rhs_ty.isTuple(mod);
......@@ -14525,8 +14496,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1452514496 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
1452614497 }
1452714498
14528 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14529 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14499 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14500 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1453014501
1453114502 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
1453214503 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);
......@@ -14638,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1463814609 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
1463914610 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1464014611 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14641 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14612 const operand_src = block.src(.{ .array_cat_lhs = .{
1464214613 .array_cat_offset = inst_data.src_node,
1464314614 .elem_index = elem_i,
14644 } };
14615 } });
1464514616 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
1464614617 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
1464714618 element_vals[elem_i] = coerced_elem_val.toIntern();
......@@ -14651,10 +14622,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1465114622 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
1465214623 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1465314624 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14654 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14625 const operand_src = block.src(.{ .array_cat_rhs = .{
1465514626 .array_cat_offset = inst_data.src_node,
1465614627 .elem_index = @intCast(rhs_elem_i),
14657 } };
14628 } });
1465814629 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
1465914630 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
1466014631 element_vals[elem_i] = coerced_elem_val.toIntern();
......@@ -14683,10 +14654,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1468314654 while (elem_i < lhs_len) : (elem_i += 1) {
1468414655 const elem_index = try mod.intRef(Type.usize, elem_i);
1468514656 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14686 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14657 const operand_src = block.src(.{ .array_cat_lhs = .{
1468714658 .array_cat_offset = inst_data.src_node,
1468814659 .elem_index = elem_i,
14689 } };
14660 } });
1469014661 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);
1469114662 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
1469214663 }
......@@ -14695,10 +14666,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1469514666 const elem_index = try mod.intRef(Type.usize, elem_i);
1469614667 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);
1469714668 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14698 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14669 const operand_src = block.src(.{ .array_cat_rhs = .{
1469914670 .array_cat_offset = inst_data.src_node,
1470014671 .elem_index = @intCast(rhs_elem_i),
14701 } };
14672 } });
1470214673 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);
1470314674 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
1470414675 }
......@@ -14717,20 +14688,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1471714688 var elem_i: u32 = 0;
1471814689 while (elem_i < lhs_len) : (elem_i += 1) {
1471914690 const index = try mod.intRef(Type.usize, elem_i);
14720 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14691 const operand_src = block.src(.{ .array_cat_lhs = .{
1472114692 .array_cat_offset = inst_data.src_node,
1472214693 .elem_index = elem_i,
14723 } };
14694 } });
1472414695 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);
1472514696 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
1472614697 }
1472714698 while (elem_i < result_len) : (elem_i += 1) {
1472814699 const rhs_elem_i = elem_i - lhs_len;
1472914700 const index = try mod.intRef(Type.usize, rhs_elem_i);
14730 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14701 const operand_src = block.src(.{ .array_cat_rhs = .{
1473114702 .array_cat_offset = inst_data.src_node,
1473214703 .elem_index = @intCast(rhs_elem_i),
14733 } };
14704 } });
1473414705 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);
1473514706 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
1473614707 }
......@@ -14792,8 +14763,8 @@ fn analyzeTupleMul(
1479214763) CompileError!Air.Inst.Ref {
1479314764 const mod = sema.mod;
1479414765 const operand_ty = sema.typeOf(operand);
14795 const src = LazySrcLoc.nodeOffset(src_node);
14796 const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node };
14766 const src = block.nodeOffset(src_node);
14767 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });
1479714768
1479814769 const tuple_len = operand_ty.structFieldCount(mod);
1479914770 const final_len = std.math.mul(usize, tuple_len, factor) catch
......@@ -14810,10 +14781,10 @@ fn analyzeTupleMul(
1481014781 for (0..tuple_len) |i| {
1481114782 types[i] = operand_ty.structFieldType(i, mod).toIntern();
1481214783 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
14813 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14784 const operand_src = block.src(.{ .array_cat_lhs = .{
1481414785 .array_cat_offset = src_node,
1481514786 .elem_index = @intCast(i),
14816 } };
14787 } });
1481714788 if (values[i] == .unreachable_value) {
1481814789 runtime_src = operand_src;
1481914790 values[i] = .none; // TODO don't treat unreachable_value as special
......@@ -14845,10 +14816,10 @@ fn analyzeTupleMul(
1484514816 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
1484614817 var i: u32 = 0;
1484714818 while (i < tuple_len) : (i += 1) {
14848 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14819 const operand_src = block.src(.{ .array_cat_lhs = .{
1484914820 .array_cat_offset = src_node,
1485014821 .elem_index = i,
14851 } };
14822 } });
1485214823 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);
1485314824 }
1485414825 i = 1;
......@@ -14868,10 +14839,10 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1486814839 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
1486914840 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
1487014841 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);
14871 const src: LazySrcLoc = inst_data.src();
14872 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14873 const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node };
14874 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14842 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
14843 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14844 const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node });
14845 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1487514846
1487614847 const lhs, const lhs_ty = coerced_lhs: {
1487714848 // If we have a result type, we might be able to do this more efficiently
......@@ -14920,11 +14891,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1492014891 // Analyze the lhs first, to catch the case that someone tried to do exponentiation
1492114892 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {
1492214893 const msg = msg: {
14923 const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
14894 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
1492414895 errdefer msg.destroy(sema.gpa);
1492514896 switch (lhs_ty.zigTypeTag(mod)) {
1492614897 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
14927 try sema.errNote(block, operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
14898 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
1492814899 },
1492914900 else => {},
1493014901 }
......@@ -15038,9 +15009,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1503815009fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1503915010 const mod = sema.mod;
1504015011 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15041 const src = inst_data.src();
15012 const src = block.nodeOffset(inst_data.src_node);
1504215013 const lhs_src = src;
15043 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
15014 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1504415015
1504515016 const rhs = try sema.resolveInst(inst_data.operand);
1504615017 const rhs_ty = sema.typeOf(rhs);
......@@ -15070,9 +15041,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1507015041fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1507115042 const mod = sema.mod;
1507215043 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15073 const src = inst_data.src();
15044 const src = block.nodeOffset(inst_data.src_node);
1507415045 const lhs_src = src;
15075 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
15046 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1507615047
1507715048 const rhs = try sema.resolveInst(inst_data.operand);
1507815049 const rhs_ty = sema.typeOf(rhs);
......@@ -15098,9 +15069,9 @@ fn zirArithmetic(
1509815069 defer tracy.end();
1509915070
1510015071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15101 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15102 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15103 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15072 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15073 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15074 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1510415075 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1510515076 const lhs = try sema.resolveInst(extra.lhs);
1510615077 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15111,9 +15082,9 @@ fn zirArithmetic(
1511115082fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1511215083 const mod = sema.mod;
1511315084 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15114 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15115 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15116 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15085 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15086 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15087 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1511715088 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1511815089 const lhs = try sema.resolveInst(extra.lhs);
1511915090 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15276,9 +15247,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1527615247fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1527715248 const mod = sema.mod;
1527815249 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15279 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15280 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15281 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15250 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15251 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15252 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1528215253 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1528315254 const lhs = try sema.resolveInst(extra.lhs);
1528415255 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15441,9 +15412,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1544115412fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1544215413 const mod = sema.mod;
1544315414 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15444 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15445 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15446 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15415 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15416 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15417 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1544715418 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1544815419 const lhs = try sema.resolveInst(extra.lhs);
1544915420 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15551,9 +15522,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1555115522fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1555215523 const mod = sema.mod;
1555315524 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15554 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15555 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15556 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15525 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15526 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15527 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1555715528 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1555815529 const lhs = try sema.resolveInst(extra.lhs);
1555915530 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15792,9 +15763,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
1579215763fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1579315764 const mod = sema.mod;
1579415765 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15795 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15796 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15797 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15766 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15767 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15768 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1579815769 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1579915770 const lhs = try sema.resolveInst(extra.lhs);
1580015771 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15976,9 +15947,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1597615947fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1597715948 const mod = sema.mod;
1597815949 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15979 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15980 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15981 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15950 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15951 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15952 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1598215953 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1598315954 const lhs = try sema.resolveInst(extra.lhs);
1598415955 const rhs = try sema.resolveInst(extra.rhs);
......@@ -16071,9 +16042,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1607116042fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1607216043 const mod = sema.mod;
1607316044 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16074 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
16075 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
16076 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
16045 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16046 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
16047 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1607716048 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1607816049 const lhs = try sema.resolveInst(extra.lhs);
1607916050 const rhs = try sema.resolveInst(extra.rhs);
......@@ -16173,10 +16144,10 @@ fn zirOverflowArithmetic(
1617316144 defer tracy.end();
1617416145
1617516146 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
16176 const src = LazySrcLoc.nodeOffset(extra.node);
16147 const src = block.nodeOffset(extra.node);
1617716148
16178 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
16179 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
16149 const lhs_src = block.builtinCallArgSrc(extra.node, 0);
16150 const rhs_src = block.builtinCallArgSrc(extra.node, 1);
1618016151
1618116152 const uncasted_lhs = try sema.resolveInst(extra.lhs);
1618216153 const uncasted_rhs = try sema.resolveInst(extra.rhs);
......@@ -16988,7 +16959,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In
1698816959 defer tracy.end();
1698916960
1699016961 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
16991 const src = inst_data.src();
16962 const src = block.nodeOffset(inst_data.src_node);
1699216963 const ptr_src = src; // TODO better source location
1699316964 const ptr = try sema.resolveInst(inst_data.operand);
1699416965 return sema.analyzeLoad(block, src, ptr, ptr_src);
......@@ -17004,8 +16975,8 @@ fn zirAsm(
1700416975 defer tracy.end();
1700516976
1700616977 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
17007 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
17008 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
16978 const src = block.nodeOffset(extra.data.src_node);
16979 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
1700916980 const outputs_len: u5 = @truncate(extended.small);
1701016981 const inputs_len: u5 = @truncate(extended.small >> 5);
1701116982 const clobbers_len: u5 = @truncate(extended.small >> 10);
......@@ -17178,9 +17149,9 @@ fn zirCmpEq(
1717817149 const mod = sema.mod;
1717917150 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1718017151 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17181 const src: LazySrcLoc = inst_data.src();
17182 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17183 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
17152 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17153 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17154 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1718417155 const lhs = try sema.resolveInst(extra.lhs);
1718517156 const rhs = try sema.resolveInst(extra.rhs);
1718617157
......@@ -17259,9 +17230,9 @@ fn analyzeCmpUnionTag(
1725917230 try sema.resolveTypeFields(union_ty);
1726017231 const union_tag_ty = union_ty.unionTagType(mod) orelse {
1726117232 const msg = msg: {
17262 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
17233 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1726317234 errdefer msg.destroy(sema.gpa);
17264 try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
17235 try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
1726517236 break :msg msg;
1726617237 };
1726717238 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -17294,9 +17265,9 @@ fn zirCmp(
1729417265
1729517266 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1729617267 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17297 const src: LazySrcLoc = inst_data.src();
17298 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17299 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
17268 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17269 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17270 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1730017271 const lhs = try sema.resolveInst(extra.lhs);
1730117272 const rhs = try sema.resolveInst(extra.rhs);
1730217273 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
......@@ -17438,7 +17409,7 @@ fn runtimeBoolCmp(
1743817409fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1743917410 const mod = sema.mod;
1744017411 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17441 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17412 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1744217413 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1744317414 switch (ty.zigTypeTag(mod)) {
1744417415 .Fn,
......@@ -17481,7 +17452,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1748117452fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1748217453 const mod = sema.mod;
1748317454 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17484 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17455 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1748517456 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
1748617457 switch (operand_ty.zigTypeTag(mod)) {
1748717458 .Fn,
......@@ -17525,7 +17496,7 @@ fn zirThis(
1752517496) CompileError!Air.Inst.Ref {
1752617497 const mod = sema.mod;
1752717498 const this_decl_index = mod.namespacePtr(block.namespace).decl_index;
17528 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
17499 const src = block.nodeOffset(@bitCast(extended.operand));
1752917500 return sema.analyzeDeclVal(block, src, this_decl_index);
1753017501}
1753117502
......@@ -17535,7 +17506,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1753517506 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);
1753617507
1753717508 const src_node: i32 = @bitCast(extended.operand);
17538 const src = LazySrcLoc.nodeOffset(src_node);
17509 const src = block.nodeOffset(src_node);
1753917510
1754017511 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {
1754117512 .@"comptime" => |index| return Air.internedToRef(index),
......@@ -17549,7 +17520,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1754917520 if (!block.is_typeof and sema.func_index == .none) {
1755017521 const msg = msg: {
1755117522 const name = name: {
17552 const file = sema.owner_decl.getFileScope(mod);
17523 // TODO: we should probably store this name in the ZIR to avoid this complexity.
17524 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
1755317525 const tree = file.getTree(sema.gpa) catch |err| {
1755417526 // In this case we emit a warning + a less precise source location.
1755517527 log.warn("unable to load {s}: {s}", .{
......@@ -17557,15 +17529,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1755717529 });
1755817530 break :name null;
1755917531 };
17560 const node = sema.owner_decl.relativeToNodeIndex(src_node);
17532 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
1756117533 const token = tree.nodes.items(.main_token)[node];
1756217534 break :name tree.tokenSlice(token);
1756317535 };
1756417536
1756517537 const msg = if (name) |some|
17566 try sema.errMsg(block, src, "'{s}' not accessible outside function scope", .{some})
17538 try sema.errMsg(src, "'{s}' not accessible outside function scope", .{some})
1756717539 else
17568 try sema.errMsg(block, src, "variable not accessible outside function scope", .{});
17540 try sema.errMsg(src, "variable not accessible outside function scope", .{});
1756917541 errdefer msg.destroy(sema.gpa);
1757017542
1757117543 // TODO add "declared here" note
......@@ -17577,7 +17549,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1757717549 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
1757817550 const msg = msg: {
1757917551 const name = name: {
17580 const file = sema.owner_decl.getFileScope(mod);
17552 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
1758117553 const tree = file.getTree(sema.gpa) catch |err| {
1758217554 // In this case we emit a warning + a less precise source location.
1758317555 log.warn("unable to load {s}: {s}", .{
......@@ -17585,18 +17557,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1758517557 });
1758617558 break :name null;
1758717559 };
17588 const node = sema.owner_decl.relativeToNodeIndex(src_node);
17560 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
1758917561 const token = tree.nodes.items(.main_token)[node];
1759017562 break :name tree.tokenSlice(token);
1759117563 };
1759217564
1759317565 const msg = if (name) |some|
17594 try sema.errMsg(block, src, "'{s}' not accessible from inner function", .{some})
17566 try sema.errMsg(src, "'{s}' not accessible from inner function", .{some})
1759517567 else
17596 try sema.errMsg(block, src, "variable not accessible from inner function", .{});
17568 try sema.errMsg(src, "variable not accessible from inner function", .{});
1759717569 errdefer msg.destroy(sema.gpa);
1759817570
17599 try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{});
17571 try sema.errNote(block.nodeOffset(0), msg, "crossed function definition here", .{});
1760017572
1760117573 // TODO add "declared here" note
1760217574 break :msg msg;
......@@ -17628,7 +17600,7 @@ fn zirFrameAddress(
1762817600 block: *Block,
1762917601 extended: Zir.Inst.Extended.InstData,
1763017602) CompileError!Air.Inst.Ref {
17631 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
17603 const src = block.nodeOffset(@bitCast(extended.operand));
1763217604 try sema.requireRuntimeBlock(block, src, null);
1763317605 return try block.addNoOp(.frame_addr);
1763417606}
......@@ -17721,7 +17693,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1772117693 const gpa = sema.gpa;
1772217694 const ip = &mod.intern_pool;
1772317695 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17724 const src = inst_data.src();
17696 const src = block.nodeOffset(inst_data.src_node);
1772517697 const ty = try sema.resolveType(block, src, inst_data.operand);
1772617698 const type_info_ty = try sema.getBuiltinType("Type");
1772717699 const type_info_tag_ty = type_info_ty.unionTagType(mod).?;
......@@ -18884,7 +18856,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1888418856 var child_block: Block = .{
1888518857 .parent = block,
1888618858 .sema = sema,
18887 .src_decl = block.src_decl,
1888818859 .namespace = block.namespace,
1888918860 .instructions = .{},
1889018861 .inlining = block.inlining,
......@@ -18892,6 +18863,8 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1889218863 .is_typeof = true,
1889318864 .want_safety = false,
1889418865 .error_return_trace_index = block.error_return_trace_index,
18866 .src_base_inst = block.src_base_inst,
18867 .type_name_ctx = block.type_name_ctx,
1889518868 };
1889618869 defer child_block.instructions.deinit(sema.gpa);
1889718870
......@@ -18903,7 +18876,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1890318876
1890418877fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1890518878 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
18906 const src = inst_data.src();
18879 const src = block.nodeOffset(inst_data.src_node);
1890718880 const operand = try sema.resolveInst(inst_data.operand);
1890818881 const operand_ty = sema.typeOf(operand);
1890918882 const res_ty = try sema.log2IntType(block, operand_ty, src);
......@@ -18956,13 +18929,12 @@ fn zirTypeofPeer(
1895618929 defer tracy.end();
1895718930
1895818931 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
18959 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
18932 const src = block.nodeOffset(extra.data.src_node);
1896018933 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
1896118934
1896218935 var child_block: Block = .{
1896318936 .parent = block,
1896418937 .sema = sema,
18965 .src_decl = block.src_decl,
1896618938 .namespace = block.namespace,
1896718939 .instructions = .{},
1896818940 .inlining = block.inlining,
......@@ -18971,6 +18943,8 @@ fn zirTypeofPeer(
1897118943 .runtime_cond = block.runtime_cond,
1897218944 .runtime_loop = block.runtime_loop,
1897318945 .runtime_index = block.runtime_index,
18946 .src_base_inst = block.src_base_inst,
18947 .type_name_ctx = block.type_name_ctx,
1897418948 };
1897518949 defer child_block.instructions.deinit(sema.gpa);
1897618950 // Ignore the result, we only care about the instructions in `args`.
......@@ -18995,8 +18969,8 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1899518969
1899618970 const mod = sema.mod;
1899718971 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
18998 const src = inst_data.src();
18999 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
18972 const src = block.nodeOffset(inst_data.src_node);
18973 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1900018974 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1900118975
1900218976 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
......@@ -19027,8 +19001,8 @@ fn zirBoolBr(
1902719001
1902819002 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);
1902919003 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19030 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19031 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
19004 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19005 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1903219006
1903319007 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);
1903419008
......@@ -19059,7 +19033,7 @@ fn zirBoolBr(
1905919033
1906019034 var child_block = parent_block.makeSubBlock();
1906119035 child_block.runtime_loop = null;
19062 child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod);
19036 child_block.runtime_cond = lhs_src;
1906319037 child_block.runtime_index.increment();
1906419038 defer child_block.instructions.deinit(gpa);
1906519039
......@@ -19152,7 +19126,7 @@ fn zirIsNonNull(
1915219126 defer tracy.end();
1915319127
1915419128 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19155 const src = inst_data.src();
19129 const src = block.nodeOffset(inst_data.src_node);
1915619130 const operand = try sema.resolveInst(inst_data.operand);
1915719131 try sema.checkNullableType(block, src, sema.typeOf(operand));
1915819132 return sema.analyzeIsNull(block, src, operand, true);
......@@ -19168,7 +19142,7 @@ fn zirIsNonNullPtr(
1916819142
1916919143 const mod = sema.mod;
1917019144 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19171 const src = inst_data.src();
19145 const src = block.nodeOffset(inst_data.src_node);
1917219146 const ptr = try sema.resolveInst(inst_data.operand);
1917319147 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
1917419148 if ((try sema.resolveValue(ptr)) == null) {
......@@ -19193,7 +19167,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1919319167 defer tracy.end();
1919419168
1919519169 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19196 const src = inst_data.src();
19170 const src = block.nodeOffset(inst_data.src_node);
1919719171 const operand = try sema.resolveInst(inst_data.operand);
1919819172 try sema.checkErrorType(block, src, sema.typeOf(operand));
1919919173 return sema.analyzeIsNonErr(block, src, operand);
......@@ -19205,7 +19179,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1920519179
1920619180 const mod = sema.mod;
1920719181 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19208 const src = inst_data.src();
19182 const src = block.nodeOffset(inst_data.src_node);
1920919183 const ptr = try sema.resolveInst(inst_data.operand);
1921019184 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));
1921119185 const loaded = try sema.analyzeLoad(block, src, ptr, src);
......@@ -19217,7 +19191,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1921719191 defer tracy.end();
1921819192
1921919193 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19220 const src = inst_data.src();
19194 const src = block.nodeOffset(inst_data.src_node);
1922119195 const operand = try sema.resolveInst(inst_data.operand);
1922219196 return sema.analyzeIsNonErr(block, src, operand);
1922319197}
......@@ -19232,7 +19206,7 @@ fn zirCondbr(
1923219206
1923319207 const mod = sema.mod;
1923419208 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19235 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
19209 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
1923619210 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1923719211
1923819212 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
......@@ -19255,7 +19229,7 @@ fn zirCondbr(
1925519229 // instructions array in between using it for the then block and else block.
1925619230 var sub_block = parent_block.makeSubBlock();
1925719231 sub_block.runtime_loop = null;
19258 sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod);
19232 sub_block.runtime_cond = cond_src;
1925919233 sub_block.runtime_index.increment();
1926019234 sub_block.need_debug_scope = null; // this body is emitted regardless
1926119235 defer sub_block.instructions.deinit(gpa);
......@@ -19299,8 +19273,8 @@ fn zirCondbr(
1929919273
1930019274fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1930119275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19302 const src = inst_data.src();
19303 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19276 const src = parent_block.nodeOffset(inst_data.src_node);
19277 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1930419278 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1930519279 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1930619280 const err_union = try sema.resolveInst(extra.data.operand);
......@@ -19346,8 +19320,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1934619320
1934719321fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1934819322 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19349 const src = inst_data.src();
19350 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19323 const src = parent_block.nodeOffset(inst_data.src_node);
19324 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1935119325 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1935219326 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1935319327 const operand = try sema.resolveInst(extra.data.operand);
......@@ -19437,12 +19411,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
1943719411 .block = .{
1943819412 .parent = block,
1943919413 .sema = sema,
19440 .src_decl = block.src_decl,
1944119414 .namespace = block.namespace,
1944219415 .instructions = .{},
1944319416 .label = &labeled_block.label,
1944419417 .inlining = block.inlining,
1944519418 .is_comptime = block.is_comptime,
19419 .src_base_inst = block.src_base_inst,
19420 .type_name_ctx = block.type_name_ctx,
1944619421 },
1944719422 };
1944819423 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
......@@ -19471,17 +19446,17 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, block_inst: Zir.Inst.Index,
1947119446
1947219447fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1947319448 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
19474 const src = inst_data.src();
19449 const src = block.nodeOffset(inst_data.src_node);
1947519450
1947619451 if (block.is_comptime) {
1947719452 return sema.fail(block, src, "reached unreachable code", .{});
1947819453 }
1947919454 // TODO Add compile error for @optimizeFor occurring too late in a scope.
19480 block.addUnreachable(src, true) catch |err| switch (err) {
19455 sema.analyzeUnreachable(block, src, true) catch |err| switch (err) {
1948119456 error.AnalysisFail => {
1948219457 const msg = sema.err orelse return err;
1948319458 if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err;
19484 try sema.errNote(block, src, msg, "the end of a naked function is implicitly unreachable", .{});
19459 try sema.errNote(src, msg, "the end of a naked function is implicitly unreachable", .{});
1948519460 return err;
1948619461 },
1948719462 else => |e| return e,
......@@ -19495,13 +19470,13 @@ fn zirRetErrValue(
1949519470) CompileError!void {
1949619471 const mod = sema.mod;
1949719472 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
19473 const src = block.tokenOffset(inst_data.src_tok);
1949819474 const err_name = try mod.intern_pool.getOrPutString(
1949919475 sema.gpa,
1950019476 inst_data.get(sema.code),
1950119477 .no_embedded_nulls,
1950219478 );
1950319479 _ = try mod.getErrorValue(err_name);
19504 const src = inst_data.src();
1950519480 // Return the error code from the function.
1950619481 const error_set_type = try mod.singleErrorSetType(err_name);
1950719482 const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{
......@@ -19521,38 +19496,38 @@ fn zirRetImplicit(
1952119496
1952219497 const mod = sema.mod;
1952319498 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
19524 const r_brace_src = inst_data.src();
19499 const r_brace_src = block.tokenOffset(inst_data.src_tok);
1952519500 if (block.inlining == null and sema.func_is_naked) {
1952619501 assert(!block.is_comptime);
1952719502 if (block.wantSafety()) {
1952819503 // Calling a safety function from a naked function would not be legal.
1952919504 _ = try block.addNoOp(.trap);
1953019505 } else {
19531 try block.addUnreachable(r_brace_src, false);
19506 try sema.analyzeUnreachable(block, r_brace_src, false);
1953219507 }
1953319508 return;
1953419509 }
1953519510
1953619511 const operand = try sema.resolveInst(inst_data.operand);
19537 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
19512 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });
1953819513 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
1953919514 if (base_tag == .NoReturn) {
1954019515 const msg = msg: {
19541 const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{
19516 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
1954219517 sema.fn_ret_ty.fmt(mod),
1954319518 });
1954419519 errdefer msg.destroy(sema.gpa);
19545 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
19520 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
1954619521 break :msg msg;
1954719522 };
1954819523 return sema.failWithOwnedErrorMsg(block, msg);
1954919524 } else if (base_tag != .Void) {
1955019525 const msg = msg: {
19551 const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
19526 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
1955219527 sema.fn_ret_ty.fmt(mod),
1955319528 });
1955419529 errdefer msg.destroy(sema.gpa);
19555 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
19530 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
1955619531 break :msg msg;
1955719532 };
1955819533 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -19567,9 +19542,9 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1956719542
1956819543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1956919544 const operand = try sema.resolveInst(inst_data.operand);
19570 const src = inst_data.src();
19545 const src = block.nodeOffset(inst_data.src_node);
1957119546
19572 return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node });
19547 return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node }));
1957319548}
1957419549
1957519550fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -19577,12 +19552,12 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1957719552 defer tracy.end();
1957819553
1957919554 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19580 const src = inst_data.src();
19555 const src = block.nodeOffset(inst_data.src_node);
1958119556 const ret_ptr = try sema.resolveInst(inst_data.operand);
1958219557
1958319558 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {
1958419559 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);
19585 return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node });
19560 return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node }));
1958619561 }
1958719562
1958819563 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
......@@ -19676,7 +19651,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1967619651
1967719652fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
1967819653 const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
19679 return sema.restoreErrRetIndex(start_block, extra.src(), extra.block, extra.operand);
19654 return sema.restoreErrRetIndex(start_block, start_block.nodeOffset(extra.src_node), extra.block, extra.operand);
1968019655}
1968119656
1968219657/// If `operand` is non-error (or is `none`), restores the error return trace to
......@@ -19795,9 +19770,7 @@ fn analyzeRet(
1979519770 inlining.comptime_result = operand;
1979619771
1979719772 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19798 const src_decl = mod.declPtr(block.src_decl);
19799 const src_loc = src_decl.toSrcLoc(src, mod);
19800 try sema.comptime_err_ret_trace.append(src_loc);
19773 try sema.comptime_err_ret_trace.append(src);
1980119774 }
1980219775 return error.ComptimeReturn;
1980319776 }
......@@ -19811,10 +19784,10 @@ fn analyzeRet(
1981119784 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});
1981219785 } else if (sema.func_is_naked) {
1981319786 const msg = msg: {
19814 const msg = try sema.errMsg(block, src, "cannot return from naked function", .{});
19787 const msg = try sema.errMsg(src, "cannot return from naked function", .{});
1981519788 errdefer msg.destroy(sema.gpa);
1981619789
19817 try sema.errNote(block, src, msg, "can only return using assembly", .{});
19790 try sema.errNote(src, msg, "can only return using assembly", .{});
1981819791 break :msg msg;
1981919792 };
1982019793 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -19850,18 +19823,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1985019823 const mod = sema.mod;
1985119824 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
1985219825 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
19853 const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node };
19854 const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node };
19855 const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node };
19856 const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node };
19857 const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };
19858 const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };
19826 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
19827 const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node });
19828 const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node });
19829 const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node });
19830 const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node });
19831 const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node });
1985919832
1986019833 const elem_ty = blk: {
1986119834 const air_inst = try sema.resolveInst(extra.data.elem_type);
1986219835 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
1986319836 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {
19864 try sema.errNote(block, elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
19837 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
1986519838 }
1986619839 return err;
1986719840 };
......@@ -19953,11 +19926,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1995319926 } else if (inst_data.size == .C) {
1995419927 if (!try sema.validateExternType(elem_ty, .other)) {
1995519928 const msg = msg: {
19956 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
19929 const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
1995719930 errdefer msg.destroy(sema.gpa);
1995819931
19959 const src_decl = mod.declPtr(block.src_decl);
19960 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other);
19932 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other);
1996119933
1996219934 try sema.addDeclaredHereNote(msg, elem_ty);
1996319935 break :msg msg;
......@@ -19971,10 +19943,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997119943
1997219944 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {
1997319945 return sema.failWithOwnedErrorMsg(block, msg: {
19974 const msg = try sema.errMsg(block, elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});
19946 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});
1997519947 errdefer msg.destroy(sema.gpa);
19976 const src_decl = mod.declPtr(block.src_decl);
19977 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty);
19948 try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty);
1997819949 break :msg msg;
1997919950 });
1998019951 }
......@@ -20003,8 +19974,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2000319974 defer tracy.end();
2000419975
2000519976 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20006 const src = inst_data.src();
20007 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
19977 const src = block.nodeOffset(inst_data.src_node);
19978 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
2000819979 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
2000919980 const mod = sema.mod;
2001019981
......@@ -20023,7 +19994,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2002319994
2002419995 const mod = sema.mod;
2002519996 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20026 const src = inst_data.src();
19997 const src = block.nodeOffset(inst_data.src_node);
2002719998 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
2002819999 // Generic poison means this is an untyped anonymous empty struct init
2002920000 error.GenericPoison => return .empty_struct,
......@@ -20098,9 +20069,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
2009820069
2009920070fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2010020071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20101 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20102 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20103 const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
20072 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20073 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20074 const init_src = block.builtinCallArgSrc(inst_data.src_node, 2);
2010420075 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
2010520076 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
2010620077 if (union_ty.zigTypeTag(sema.mod) != .Union) {
......@@ -20155,7 +20126,7 @@ fn zirStructInit(
2015520126 const zir_datas = sema.code.instructions.items(.data);
2015620127 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
2015720128 const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
20158 const src = inst_data.src();
20129 const src = block.nodeOffset(inst_data.src_node);
2015920130
2016020131 const mod = sema.mod;
2016120132 const ip = &mod.intern_pool;
......@@ -20194,7 +20165,7 @@ fn zirStructInit(
2019420165 extra_index = item.end;
2019520166
2019620167 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20197 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20168 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
2019820169 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2019920170 const field_name = try ip.getOrPutString(
2020020171 gpa,
......@@ -20235,7 +20206,7 @@ fn zirStructInit(
2023520206 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
2023620207
2023720208 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20238 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20209 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
2023920210 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2024020211 const field_name = try ip.getOrPutString(
2024120212 gpa,
......@@ -20249,7 +20220,7 @@ fn zirStructInit(
2024920220
2025020221 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2025120222 return sema.failWithOwnedErrorMsg(block, msg: {
20252 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
20223 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2025320224 errdefer msg.destroy(sema.gpa);
2025420225
2025520226 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{
......@@ -20327,16 +20298,12 @@ fn finishStructInit(
2032720298 for (0..anon_struct.types.len) |i| {
2032820299 if (field_inits[i] != .none) {
2032920300 // Coerce the init value to the field type.
20301 const field_src = block.src(.{ .init_elem = .{
20302 .init_node_offset = init_src.offset.node_offset.x,
20303 .elem_index = @intCast(i),
20304 } });
2033020305 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);
20331 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {
20332 error.NeededSourceLocation => {
20333 const decl = mod.declPtr(block.src_decl);
20334 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20335 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20336 unreachable;
20337 },
20338 else => |e| return e,
20339 };
20306 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
2034020307 continue;
2034120308 }
2034220309
......@@ -20346,18 +20313,18 @@ fn finishStructInit(
2034620313 if (anon_struct.names.len == 0) {
2034720314 const template = "missing tuple field with index {d}";
2034820315 if (root_msg) |msg| {
20349 try sema.errNote(block, init_src, msg, template, .{i});
20316 try sema.errNote(init_src, msg, template, .{i});
2035020317 } else {
20351 root_msg = try sema.errMsg(block, init_src, template, .{i});
20318 root_msg = try sema.errMsg(init_src, template, .{i});
2035220319 }
2035320320 } else {
2035420321 const field_name = anon_struct.names.get(ip)[i];
2035520322 const template = "missing struct field: {}";
2035620323 const args = .{field_name.fmt(ip)};
2035720324 if (root_msg) |msg| {
20358 try sema.errNote(block, init_src, msg, template, args);
20325 try sema.errNote(init_src, msg, template, args);
2035920326 } else {
20360 root_msg = try sema.errMsg(block, init_src, template, args);
20327 root_msg = try sema.errMsg(init_src, template, args);
2036120328 }
2036220329 }
2036320330 } else {
......@@ -20370,16 +20337,12 @@ fn finishStructInit(
2037020337 for (0..struct_type.field_types.len) |i| {
2037120338 if (field_inits[i] != .none) {
2037220339 // Coerce the init value to the field type.
20340 const field_src = block.src(.{ .init_elem = .{
20341 .init_node_offset = init_src.offset.node_offset.x,
20342 .elem_index = @intCast(i),
20343 } });
2037320344 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
20374 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {
20375 error.NeededSourceLocation => {
20376 const decl = mod.declPtr(block.src_decl);
20377 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20378 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20379 unreachable;
20380 },
20381 else => |e| return e,
20382 };
20345 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
2038320346 continue;
2038420347 }
2038520348
......@@ -20392,16 +20355,16 @@ fn finishStructInit(
2039220355 const template = "missing struct field: {}";
2039320356 const args = .{field_name.fmt(ip)};
2039420357 if (root_msg) |msg| {
20395 try sema.errNote(block, init_src, msg, template, args);
20358 try sema.errNote(init_src, msg, template, args);
2039620359 } else {
20397 root_msg = try sema.errMsg(block, init_src, template, args);
20360 root_msg = try sema.errMsg(init_src, template, args);
2039820361 }
2039920362 } else {
2040020363 const template = "missing tuple field with index {d}";
2040120364 if (root_msg) |msg| {
20402 try sema.errNote(block, init_src, msg, template, .{i});
20365 try sema.errNote(init_src, msg, template, .{i});
2040320366 } else {
20404 root_msg = try sema.errMsg(block, init_src, template, .{i});
20367 root_msg = try sema.errMsg(init_src, template, .{i});
2040520368 }
2040620369 }
2040720370 } else {
......@@ -20413,16 +20376,7 @@ fn finishStructInit(
2041320376 }
2041420377
2041520378 if (root_msg) |msg| {
20416 if (mod.typeToStruct(struct_ty)) |struct_type| {
20417 const decl = mod.declPtr(struct_type.decl.unwrap().?);
20418 const fqn = try decl.fullyQualifiedName(mod);
20419 try mod.errNoteNonLazy(
20420 decl.srcLoc(mod),
20421 msg,
20422 "struct '{}' declared here",
20423 .{fqn.fmt(ip)},
20424 );
20425 }
20379 try sema.addDeclaredHereNote(msg, struct_ty);
2042620380 root_msg = null;
2042720381 return sema.failWithOwnedErrorMsg(block, msg);
2042820382 }
......@@ -20449,9 +20403,10 @@ fn finishStructInit(
2044920403 };
2045020404
2045120405 if (try sema.typeRequiresComptime(struct_ty)) {
20452 const decl = mod.declPtr(block.src_decl);
20453 const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index);
20454 return sema.failWithNeededComptime(block, field_src, .{
20406 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
20407 .init_node_offset = init_src.offset.node_offset.x,
20408 .elem_index = @intCast(runtime_index),
20409 } }), .{
2045520410 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
2045620411 });
2045720412 }
......@@ -20479,15 +20434,10 @@ fn finishStructInit(
2047920434 return sema.makePtrConst(block, alloc);
2048020435 }
2048120436
20482 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20483 error.NeededSourceLocation => {
20484 const decl = mod.declPtr(block.src_decl);
20485 const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index);
20486 try sema.requireRuntimeBlock(block, dest_src, field_src);
20487 unreachable;
20488 },
20489 else => |e| return e,
20490 };
20437 try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{
20438 .init_node_offset = init_src.offset.node_offset.x,
20439 .elem_index = @intCast(runtime_index),
20440 } }));
2049120441 try sema.resolveStructFieldInits(struct_ty);
2049220442 try sema.queueFullTypeResolution(struct_ty);
2049320443 const struct_val = try block.addAggregateInit(struct_ty, field_inits);
......@@ -20500,7 +20450,7 @@ fn zirStructInitAnon(
2050020450 inst: Zir.Inst.Index,
2050120451) CompileError!Air.Inst.Ref {
2050220452 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20503 const src = inst_data.src();
20453 const src = block.nodeOffset(inst_data.src_node);
2050420454 const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
2050520455 return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false);
2050620456}
......@@ -20555,9 +20505,11 @@ fn structInitAnon(
2055520505 field_ty.* = sema.typeOf(init).toIntern();
2055620506 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
2055720507 const msg = msg: {
20558 const decl = mod.declPtr(block.src_decl);
20559 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));
20560 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20508 const field_src = block.src(.{ .init_elem = .{
20509 .init_node_offset = src.offset.node_offset.x,
20510 .elem_index = @intCast(i_usize),
20511 } });
20512 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2056120513 errdefer msg.destroy(sema.gpa);
2056220514
2056320515 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
......@@ -20589,15 +20541,10 @@ fn structInitAnon(
2058920541 return sema.addConstantMaybeRef(tuple_val, is_ref);
2059020542 };
2059120543
20592 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20593 error.NeededSourceLocation => {
20594 const decl = mod.declPtr(block.src_decl);
20595 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
20596 try sema.requireRuntimeBlock(block, src, field_src);
20597 unreachable;
20598 },
20599 else => |e| return e,
20600 };
20544 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20545 .init_node_offset = src.offset.node_offset.x,
20546 .elem_index = @intCast(runtime_index),
20547 } }));
2060120548
2060220549 if (is_ref) {
2060320550 const target = mod.getTarget();
......@@ -20652,7 +20599,7 @@ fn zirArrayInit(
2065220599 const mod = sema.mod;
2065320600 const gpa = sema.gpa;
2065420601 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20655 const src = inst_data.src();
20602 const src = block.nodeOffset(inst_data.src_node);
2065620603
2065720604 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
2065820605 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
......@@ -20676,15 +20623,19 @@ fn zirArrayInit(
2067620623 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
2067720624 defer gpa.free(resolved_args);
2067820625 for (resolved_args, 0..) |*dest, i| {
20626 const elem_src = block.src(.{ .init_elem = .{
20627 .init_node_offset = src.offset.node_offset.x,
20628 .elem_index = @intCast(i),
20629 } });
2067920630 // Less inits than needed.
2068020631 if (i + 2 > args.len) if (is_tuple) {
2068120632 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
2068220633 if (default_val == .unreachable_value) {
2068320634 const template = "missing tuple field with index {d}";
2068420635 if (root_msg) |msg| {
20685 try sema.errNote(block, src, msg, template, .{i});
20636 try sema.errNote(src, msg, template, .{i});
2068620637 } else {
20687 root_msg = try sema.errMsg(block, src, template, .{i});
20638 root_msg = try sema.errMsg(src, template, .{i});
2068820639 }
2068920640 } else {
2069020641 dest.* = Air.internedToRef(default_val);
......@@ -20701,29 +20652,17 @@ fn zirArrayInit(
2070120652 array_ty.structFieldType(i, mod)
2070220653 else
2070320654 array_ty.elemType2(mod);
20704 dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
20705 error.NeededSourceLocation => {
20706 const decl = mod.declPtr(block.src_decl);
20707 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
20708 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
20709 unreachable;
20710 },
20711 else => return err,
20712 };
20655 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
2071320656 if (is_tuple) {
2071420657 if (array_ty.structFieldIsComptime(i, mod))
2071520658 try sema.resolveStructFieldInits(array_ty);
2071620659 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
2071720660 const init_val = try sema.resolveValue(dest.*) orelse {
20718 const decl = mod.declPtr(block.src_decl);
20719 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
2072020661 return sema.failWithNeededComptime(block, elem_src, .{
2072120662 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
2072220663 });
2072320664 };
2072420665 if (!field_val.eql(init_val, elem_ty, mod)) {
20725 const decl = mod.declPtr(block.src_decl);
20726 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
2072720666 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
2072820667 }
2072920668 }
......@@ -20756,15 +20695,10 @@ fn zirArrayInit(
2075620695 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
2075720696 };
2075820697
20759 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20760 error.NeededSourceLocation => {
20761 const decl = mod.declPtr(block.src_decl);
20762 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
20763 try sema.requireRuntimeBlock(block, src, elem_src);
20764 unreachable;
20765 },
20766 else => return err,
20767 };
20698 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20699 .init_node_offset = src.offset.node_offset.x,
20700 .elem_index = runtime_index,
20701 } }));
2076820702 try sema.queueFullTypeResolution(array_ty);
2076920703
2077020704 if (is_ref) {
......@@ -20815,7 +20749,7 @@ fn zirArrayInitAnon(
2081520749 inst: Zir.Inst.Index,
2081620750) CompileError!Air.Inst.Ref {
2081720751 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20818 const src = inst_data.src();
20752 const src = block.nodeOffset(inst_data.src_node);
2081920753 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
2082020754 const operands = sema.code.refSlice(extra.end, extra.data.operands_len);
2082120755 return sema.arrayInitAnon(block, src, operands, false);
......@@ -20843,7 +20777,7 @@ fn arrayInitAnon(
2084320777 types[i] = sema.typeOf(elem).toIntern();
2084420778 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
2084520779 const msg = msg: {
20846 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20780 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2084720781 errdefer msg.destroy(gpa);
2084820782
2084920783 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
......@@ -20914,8 +20848,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In
2091420848fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2091520849 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2091620850 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
20917 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20918 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20851 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20852 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2091920853 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
2092020854 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
2092120855 .needed_comptime_reason = "field name must be comptime-known",
......@@ -20928,8 +20862,8 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2092820862 const ip = &mod.intern_pool;
2092920863 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2093020864 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
20931 const ty_src = inst_data.src();
20932 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
20865 const ty_src = block.nodeOffset(inst_data.src_node);
20866 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
2093320867 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {
2093420868 // Since this is a ZIR instruction that returns a type, encountering
2093520869 // generic poison should not result in a failed compilation, but the
......@@ -20969,7 +20903,7 @@ fn fieldType(
2096920903 .struct_type => {
2097020904 const struct_type = ip.loadStructType(cur_ty.toIntern());
2097120905 const field_index = struct_type.nameIndex(ip, field_name) orelse
20972 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);
20906 return sema.failWithBadStructFieldAccess(block, cur_ty, struct_type, field_src, field_name);
2097320907 const field_ty = struct_type.field_types.get(ip)[field_index];
2097420908 return Air.internedToRef(field_ty);
2097520909 },
......@@ -20978,7 +20912,7 @@ fn fieldType(
2097820912 .Union => {
2097920913 const union_obj = mod.typeToUnion(cur_ty).?;
2098020914 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
20981 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
20915 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
2098220916 const field_ty = union_obj.field_types.get(ip)[field_index];
2098320917 return Air.internedToRef(field_ty);
2098420918 },
......@@ -21029,14 +20963,14 @@ fn zirFrame(
2102920963 block: *Block,
2103020964 extended: Zir.Inst.Extended.InstData,
2103120965) CompileError!Air.Inst.Ref {
21032 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
20966 const src = block.nodeOffset(@bitCast(extended.operand));
2103320967 return sema.failWithUseOfAsync(block, src);
2103420968}
2103520969
2103620970fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2103720971 const mod = sema.mod;
2103820972 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21039 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20973 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2104020974 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
2104120975 if (ty.isNoReturn(mod)) {
2104220976 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)});
......@@ -21051,7 +20985,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2105120985fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2105220986 const mod = sema.mod;
2105320987 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21054 const src = inst_data.src();
20988 const src = block.nodeOffset(inst_data.src_node);
2105520989 const operand = try sema.resolveInst(inst_data.operand);
2105620990 const operand_ty = sema.typeOf(operand);
2105720991 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
......@@ -21100,7 +21034,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2110021034
2110121035fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2110221036 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21103 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21037 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2110421038 const uncoerced_operand = try sema.resolveInst(inst_data.operand);
2110521039 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);
2110621040
......@@ -21122,7 +21056,7 @@ fn zirAbs(
2112221056 const mod = sema.mod;
2112321057 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2112421058 const operand = try sema.resolveInst(inst_data.operand);
21125 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21059 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2112621060 const operand_ty = sema.typeOf(operand);
2112721061 const scalar_ty = operand_ty.scalarType(mod);
2112821062
......@@ -21190,7 +21124,7 @@ fn zirUnaryMath(
2119021124 const mod = sema.mod;
2119121125 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2119221126 const operand = try sema.resolveInst(inst_data.operand);
21193 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21127 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2119421128 const operand_ty = sema.typeOf(operand);
2119521129 const scalar_ty = operand_ty.scalarType(mod);
2119621130
......@@ -21212,8 +21146,8 @@ fn zirUnaryMath(
2121221146
2121321147fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2121421148 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21215 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21216 const src = inst_data.src();
21149 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21150 const src = block.nodeOffset(inst_data.src_node);
2121721151 const operand = try sema.resolveInst(inst_data.operand);
2121821152 const operand_ty = sema.typeOf(operand);
2121921153 const mod = sema.mod;
......@@ -21222,7 +21156,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2122221156 try sema.resolveTypeLayout(operand_ty);
2122321157 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
2122421158 .EnumLiteral => {
21225 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
21159 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined);
2122621160 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
2122721161 return sema.addNullTerminatedStrLit(tag_name);
2122821162 },
......@@ -21245,13 +21179,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2124521179 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
2124621180 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {
2124721181 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
21248 const enum_decl = mod.declPtr(enum_decl_index);
2124921182 const msg = msg: {
21250 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{
21251 val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip),
21183 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{
21184 val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip),
2125221185 });
2125321186 errdefer msg.destroy(sema.gpa);
21254 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
21187 try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{});
2125521188 break :msg msg;
2125621189 };
2125721190 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -21281,11 +21214,23 @@ fn zirReify(
2128121214 const gpa = sema.gpa;
2128221215 const ip = &mod.intern_pool;
2128321216 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
21284 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21285 const src = LazySrcLoc.nodeOffset(extra.node);
21217 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
21218 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
21219 const src: LazySrcLoc = .{
21220 .base_node_inst = tracked_inst,
21221 .offset = LazySrcLoc.Offset.nodeOffset(0),
21222 };
21223 const operand_src: LazySrcLoc = .{
21224 .base_node_inst = tracked_inst,
21225 .offset = .{
21226 .node_offset_builtin_call_arg = .{
21227 .builtin_call_node = 0, // `tracked_inst` is precisely the `reify` instruction, so offset is 0
21228 .arg_index = 0,
21229 },
21230 },
21231 };
2128621232 const type_info_ty = try sema.getBuiltinType("Type");
2128721233 const uncasted_operand = try sema.resolveInst(extra.operand);
21288 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2128921234 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
2129021235 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
2129121236 .needed_comptime_reason = "operand to @Type must be comptime-known",
......@@ -21438,11 +21383,10 @@ fn zirReify(
2143821383 } else if (ptr_size == .C) {
2143921384 if (!try sema.validateExternType(elem_ty, .other)) {
2144021385 const msg = msg: {
21441 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
21386 const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
2144221387 errdefer msg.destroy(gpa);
2144321388
21444 const src_decl = mod.declPtr(block.src_decl);
21445 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other);
21389 try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other);
2144621390
2144721391 try sema.addDeclaredHereNote(msg, elem_ty);
2144821392 break :msg msg;
......@@ -21602,7 +21546,7 @@ fn zirReify(
2160221546 .needed_comptime_reason = "struct fields must be comptime-known",
2160321547 });
2160421548
21605 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool());
21549 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool(), extra.src_line);
2160621550 },
2160721551 .Enum => {
2160821552 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21631,7 +21575,7 @@ fn zirReify(
2163121575 .needed_comptime_reason = "enum fields must be comptime-known",
2163221576 });
2163321577
21634 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy);
21578 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy, extra.src_line);
2163521579 },
2163621580 .Opaque => {
2163721581 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21658,11 +21602,11 @@ fn zirReify(
2165821602
2165921603 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2166021604 block,
21661 src,
2166221605 Value.fromInterned(wip_ty.index),
2166321606 name_strategy,
2166421607 "opaque",
2166521608 inst,
21609 extra.src_line,
2166621610 );
2166721611 mod.declPtr(new_decl_index).owns_tv = true;
2166821612 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21699,7 +21643,7 @@ fn zirReify(
2169921643 .needed_comptime_reason = "union fields must be comptime-known",
2170021644 });
2170121645
21702 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy);
21646 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy, extra.src_line);
2170321647 },
2170421648 .Fn => {
2170521649 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21801,6 +21745,7 @@ fn reifyEnum(
2180121745 is_exhaustive: bool,
2180221746 fields_val: Value,
2180321747 name_strategy: Zir.Inst.NameStrategy,
21748 src_line: u32,
2180421749) CompileError!Air.Inst.Ref {
2180521750 const mod = sema.mod;
2180621751 const gpa = sema.gpa;
......@@ -21858,11 +21803,11 @@ fn reifyEnum(
2185821803
2185921804 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2186021805 block,
21861 src,
2186221806 Value.fromInterned(wip_ty.index),
2186321807 name_strategy,
2186421808 "enum",
2186521809 inst,
21810 src_line,
2186621811 );
2186721812 mod.declPtr(new_decl_index).owns_tv = true;
2186821813 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21892,17 +21837,17 @@ fn reifyEnum(
2189221837 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {
2189321838 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {
2189421839 .name => msg: {
21895 const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{field_name.fmt(ip)});
21840 const msg = try sema.errMsg(src, "duplicate enum field '{}'", .{field_name.fmt(ip)});
2189621841 errdefer msg.destroy(gpa);
2189721842 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21898 try sema.errNote(block, src, msg, "other field here", .{});
21843 try sema.errNote(src, msg, "other field here", .{});
2189921844 break :msg msg;
2190021845 },
2190121846 .value => msg: {
21902 const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});
21847 const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});
2190321848 errdefer msg.destroy(gpa);
2190421849 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21905 try sema.errNote(block, src, msg, "other enum tag value here", .{});
21850 try sema.errNote(src, msg, "other enum tag value here", .{});
2190621851 break :msg msg;
2190721852 },
2190821853 });
......@@ -21926,6 +21871,7 @@ fn reifyUnion(
2192621871 opt_tag_type_val: Value,
2192721872 fields_val: Value,
2192821873 name_strategy: Zir.Inst.NameStrategy,
21874 src_line: u32,
2192921875) CompileError!Air.Inst.Ref {
2193021876 const mod = sema.mod;
2193121877 const gpa = sema.gpa;
......@@ -22005,11 +21951,11 @@ fn reifyUnion(
2200521951
2200621952 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2200721953 block,
22008 src,
2200921954 Value.fromInterned(wip_ty.index),
2201021955 name_strategy,
2201121956 "union",
2201221957 inst,
21958 src_line,
2201321959 );
2201421960 mod.declPtr(new_decl_index).owns_tv = true;
2201521961 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -22061,7 +22007,7 @@ fn reifyUnion(
2206122007 }
2206222008
2206322009 if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: {
22064 const msg = try sema.errMsg(block, src, "enum fields missing in union", .{});
22010 const msg = try sema.errMsg(src, "enum fields missing in union", .{});
2206522011 errdefer msg.destroy(gpa);
2206622012 var it = seen_tags.iterator(.{ .kind = .unset });
2206722013 while (it.next()) |enum_index| {
......@@ -22105,7 +22051,7 @@ fn reifyUnion(
2210522051 }
2210622052 }
2210722053
22108 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index));
22054 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index), src_line);
2210922055 break :tag_ty .{ enum_tag_ty, false };
2211022056 };
2211122057 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
......@@ -22114,7 +22060,7 @@ fn reifyUnion(
2211422060 const field_ty = Type.fromInterned(field_ty_ip);
2211522061 if (field_ty.zigTypeTag(mod) == .Opaque) {
2211622062 return sema.failWithOwnedErrorMsg(block, msg: {
22117 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
22063 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
2211822064 errdefer msg.destroy(gpa);
2211922065
2212022066 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22123,22 +22069,20 @@ fn reifyUnion(
2212322069 }
2212422070 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {
2212522071 return sema.failWithOwnedErrorMsg(block, msg: {
22126 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22072 const msg = try sema.errMsg(src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
2212722073 errdefer msg.destroy(gpa);
2212822074
22129 const src_decl = mod.declPtr(block.src_decl);
22130 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field);
22075 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field);
2213122076
2213222077 try sema.addDeclaredHereNote(msg, field_ty);
2213322078 break :msg msg;
2213422079 });
2213522080 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
2213622081 return sema.failWithOwnedErrorMsg(block, msg: {
22137 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22082 const msg = try sema.errMsg(src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
2213822083 errdefer msg.destroy(gpa);
2213922084
22140 const src_decl = mod.declPtr(block.src_decl);
22141 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
22085 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
2214222086
2214322087 try sema.addDeclaredHereNote(msg, field_ty);
2214422088 break :msg msg;
......@@ -22168,6 +22112,7 @@ fn reifyStruct(
2216822112 fields_val: Value,
2216922113 name_strategy: Zir.Inst.NameStrategy,
2217022114 is_tuple: bool,
22115 src_line: u32,
2217122116) CompileError!Air.Inst.Ref {
2217222117 const mod = sema.mod;
2217322118 const gpa = sema.gpa;
......@@ -22264,11 +22209,11 @@ fn reifyStruct(
2226422209
2226522210 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2226622211 block,
22267 src,
2226822212 Value.fromInterned(wip_ty.index),
2226922213 name_strategy,
2227022214 "struct",
2227122215 inst,
22216 src_line,
2227222217 );
2227322218 mod.declPtr(new_decl_index).owns_tv = true;
2227422219 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -22355,7 +22300,7 @@ fn reifyStruct(
2235522300
2235622301 if (field_ty.zigTypeTag(mod) == .Opaque) {
2235722302 return sema.failWithOwnedErrorMsg(block, msg: {
22358 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
22303 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2235922304 errdefer msg.destroy(gpa);
2236022305
2236122306 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22364,7 +22309,7 @@ fn reifyStruct(
2236422309 }
2236522310 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2236622311 return sema.failWithOwnedErrorMsg(block, msg: {
22367 const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{});
22312 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
2236822313 errdefer msg.destroy(gpa);
2236922314
2237022315 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22373,22 +22318,20 @@ fn reifyStruct(
2237322318 }
2237422319 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {
2237522320 return sema.failWithOwnedErrorMsg(block, msg: {
22376 const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22321 const msg = try sema.errMsg(src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
2237722322 errdefer msg.destroy(gpa);
2237822323
22379 const src_decl = sema.mod.declPtr(block.src_decl);
22380 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field);
22324 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field);
2238122325
2238222326 try sema.addDeclaredHereNote(msg, field_ty);
2238322327 break :msg msg;
2238422328 });
2238522329 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
2238622330 return sema.failWithOwnedErrorMsg(block, msg: {
22387 const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22331 const msg = try sema.errMsg(src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
2238822332 errdefer msg.destroy(gpa);
2238922333
22390 const src_decl = sema.mod.declPtr(block.src_decl);
22391 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
22334 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
2239222335
2239322336 try sema.addDeclaredHereNote(msg, field_ty);
2239422337 break :msg msg;
......@@ -22403,7 +22346,7 @@ fn reifyStruct(
2240322346 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
2240422347 error.AnalysisFail => {
2240522348 const msg = sema.err orelse return err;
22406 try sema.errNote(block, src, msg, "while checking a field of this struct", .{});
22349 try sema.errNote(src, msg, "while checking a field of this struct", .{});
2240722350 return err;
2240822351 },
2240922352 else => return err,
......@@ -22434,22 +22377,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
2243422377}
2243522378
2243622379fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22437 const mod = sema.mod;
2243822380 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22439 const src = LazySrcLoc.nodeOffset(extra.node);
22440 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22441 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
22381 const src = block.nodeOffset(extra.node);
22382 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
22383 const ty_src = block.builtinCallArgSrc(extra.node, 1);
2244222384
2244322385 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
2244422386 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2244522387
2244622388 if (!try sema.validateExternType(arg_ty, .param_ty)) {
2244722389 const msg = msg: {
22448 const msg = try sema.errMsg(block, ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});
22390 const msg = try sema.errMsg(ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});
2244922391 errdefer msg.destroy(sema.gpa);
2245022392
22451 const src_decl = sema.mod.declPtr(block.src_decl);
22452 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty);
22393 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
2245322394
2245422395 try sema.addDeclaredHereNote(msg, arg_ty);
2245522396 break :msg msg;
......@@ -22463,8 +22404,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2246322404
2246422405fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2246522406 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22466 const src = LazySrcLoc.nodeOffset(extra.node);
22467 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22407 const src = block.nodeOffset(extra.node);
22408 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2246822409
2246922410 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
2247022411 const va_list_ty = try sema.getBuiltinType("VaList");
......@@ -22475,8 +22416,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2247522416
2247622417fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2247722418 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22478 const src = LazySrcLoc.nodeOffset(extra.node);
22479 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22419 const src = block.nodeOffset(extra.node);
22420 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2248022421
2248122422 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
2248222423
......@@ -22485,7 +22426,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2248522426}
2248622427
2248722428fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22488 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
22429 const src = block.nodeOffset(@bitCast(extended.operand));
2248922430
2249022431 const va_list_ty = try sema.getBuiltinType("VaList");
2249122432 try sema.requireRuntimeBlock(block, src, null);
......@@ -22500,7 +22441,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2250022441 const ip = &mod.intern_pool;
2250122442
2250222443 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22503 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22444 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2250422445 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2250522446
2250622447 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);
......@@ -22509,22 +22450,22 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2250922450
2251022451fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2251122452 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22512 const src = inst_data.src();
22453 const src = block.nodeOffset(inst_data.src_node);
2251322454 return sema.failWithUseOfAsync(block, src);
2251422455}
2251522456
2251622457fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2251722458 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22518 const src = inst_data.src();
22459 const src = block.nodeOffset(inst_data.src_node);
2251922460 return sema.failWithUseOfAsync(block, src);
2252022461}
2252122462
2252222463fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2252322464 const mod = sema.mod;
2252422465 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22525 const src = inst_data.src();
22466 const src = block.nodeOffset(inst_data.src_node);
2252622467 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22527 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22468 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2252822469 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
2252922470 const operand = try sema.resolveInst(extra.rhs);
2253022471 const operand_ty = sema.typeOf(operand);
......@@ -22547,7 +22488,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2254722488 });
2254822489 }
2254922490
22550 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
22491 try sema.requireRuntimeBlock(block, src, operand_src);
2255122492 if (dest_scalar_ty.intInfo(mod).bits == 0) {
2255222493 if (!is_vector) {
2255322494 if (block.wantSafety()) {
......@@ -22604,9 +22545,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2260422545fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2260522546 const mod = sema.mod;
2260622547 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22607 const src = inst_data.src();
22548 const src = block.nodeOffset(inst_data.src_node);
2260822549 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22609 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22550 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2261022551 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
2261122552 const operand = try sema.resolveInst(extra.rhs);
2261222553 const operand_ty = sema.typeOf(operand);
......@@ -22646,11 +22587,11 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2264622587fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2264722588 const mod = sema.mod;
2264822589 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22649 const src = inst_data.src();
22590 const src = block.nodeOffset(inst_data.src_node);
2265022591
2265122592 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2265222593
22653 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22594 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2265422595 const operand_res = try sema.resolveInst(extra.rhs);
2265522596
2265622597 const uncoerced_operand_ty = sema.typeOf(operand_res);
......@@ -22673,9 +22614,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2267322614
2267422615 if (ptr_ty.isSlice(mod)) {
2267522616 const msg = msg: {
22676 const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
22617 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
2267722618 errdefer msg.destroy(sema.gpa);
22678 try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{});
22619 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
2267922620 break :msg msg;
2268022621 };
2268122622 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -22700,11 +22641,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2270022641 }
2270122642 if (try sema.typeRequiresComptime(ptr_ty)) {
2270222643 return sema.failWithOwnedErrorMsg(block, msg: {
22703 const msg = try sema.errMsg(block, src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
22644 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
2270422645 errdefer msg.destroy(sema.gpa);
2270522646
22706 const src_decl = mod.declPtr(block.src_decl);
22707 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty);
22647 try sema.explainWhyTypeIsComptime(msg, src, ptr_ty);
2270822648 break :msg msg;
2270922649 });
2271022650 }
......@@ -22789,8 +22729,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2278922729 const mod = sema.mod;
2279022730 const ip = &mod.intern_pool;
2279122731 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22792 const src = LazySrcLoc.nodeOffset(extra.node);
22793 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22732 const src = block.nodeOffset(extra.node);
22733 const operand_src = block.builtinCallArgSrc(extra.node, 0);
2279422734 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
2279522735 const operand = try sema.resolveInst(extra.rhs);
2279622736 const base_operand_ty = sema.typeOf(operand);
......@@ -22810,12 +22750,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2281022750 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
2281122751 {
2281222752 return sema.failWithOwnedErrorMsg(block, msg: {
22813 const msg = try sema.errMsg(block, src, "payload types of error unions must match", .{});
22753 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
2281422754 errdefer msg.destroy(sema.gpa);
2281522755 const dest_ty = base_dest_ty.errorUnionPayload(mod);
2281622756 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22817 try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22818 try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
22757 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22758 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
2281922759 try addDeclaredHereNote(sema, msg, dest_ty);
2282022760 try addDeclaredHereNote(sema, msg, operand_ty);
2282122761 break :msg msg;
......@@ -22914,8 +22854,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2291422854 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2291522855 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2291622856 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22917 const src = LazySrcLoc.nodeOffset(extra.node);
22918 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
22857 const src = block.nodeOffset(extra.node);
22858 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
2291922859 const operand = try sema.resolveInst(extra.rhs);
2292022860 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
2292122861 return sema.ptrCastFull(
......@@ -22931,8 +22871,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2293122871
2293222872fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2293322873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22934 const src = inst_data.src();
22935 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22874 const src = block.nodeOffset(inst_data.src_node);
22875 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2293622876 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2293722877 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
2293822878 const operand = try sema.resolveInst(extra.rhs);
......@@ -23002,7 +22942,7 @@ fn ptrCastFull(
2300222942 if (src_info.flags.size == .C) break :check_size;
2300322943 if (dest_info.flags.size == .C) break :check_size;
2300422944 return sema.failWithOwnedErrorMsg(block, msg: {
23005 const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{
22945 const msg = try sema.errMsg(src, "cannot implicitly convert {s} pointer to {s} pointer", .{
2300622946 pointerSizeString(src_info.flags.size),
2300722947 pointerSizeString(dest_info.flags.size),
2300822948 });
......@@ -23011,9 +22951,9 @@ fn ptrCastFull(
2301122951 (src_info.flags.size == .Slice or
2301222952 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
2301322953 {
23014 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});
22954 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2301522955 } else {
23016 try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{});
22956 try sema.errNote(src, msg, "use @ptrCast to change pointer size", .{});
2301722957 }
2301822958 break :msg msg;
2301922959 });
......@@ -23038,13 +22978,13 @@ fn ptrCastFull(
2303822978 );
2303922979 if (imc_res == .ok) break :check_child;
2304022980 return sema.failWithOwnedErrorMsg(block, msg: {
23041 const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{
22981 const msg = try sema.errMsg(src, "pointer element type '{}' cannot coerce into element type '{}'", .{
2304222982 src_child.fmt(mod),
2304322983 dest_child.fmt(mod),
2304422984 });
2304522985 errdefer msg.destroy(sema.gpa);
23046 try imc_res.report(sema, block, src, msg);
23047 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{});
22986 try imc_res.report(sema, src, msg);
22987 try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{});
2304822988 break :msg msg;
2304922989 });
2305022990 }
......@@ -23066,41 +23006,41 @@ fn ptrCastFull(
2306623006 }
2306723007 return sema.failWithOwnedErrorMsg(block, msg: {
2306823008 const msg = if (src_info.sentinel == .none) blk: {
23069 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{
23009 break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{
2307023010 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
2307123011 });
2307223012 } else blk: {
23073 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
23013 break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
2307423014 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),
2307523015 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
2307623016 });
2307723017 };
2307823018 errdefer msg.destroy(sema.gpa);
23079 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{});
23019 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
2308023020 break :msg msg;
2308123021 });
2308223022 }
2308323023
2308423024 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
2308523025 return sema.failWithOwnedErrorMsg(block, msg: {
23086 const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
23026 const msg = try sema.errMsg(src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
2308723027 src_info.packed_offset.host_size,
2308823028 dest_info.packed_offset.host_size,
2308923029 });
2309023030 errdefer msg.destroy(sema.gpa);
23091 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{});
23031 try sema.errNote(src, msg, "use @ptrCast to cast pointer host size", .{});
2309223032 break :msg msg;
2309323033 });
2309423034 }
2309523035
2309623036 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
2309723037 return sema.failWithOwnedErrorMsg(block, msg: {
23098 const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
23038 const msg = try sema.errMsg(src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
2309923039 src_info.packed_offset.bit_offset,
2310023040 dest_info.packed_offset.bit_offset,
2310123041 });
2310223042 errdefer msg.destroy(sema.gpa);
23103 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{});
23043 try sema.errNote(src, msg, "use @ptrCast to cast pointer bit offset", .{});
2310423044 break :msg msg;
2310523045 });
2310623046 }
......@@ -23112,12 +23052,12 @@ fn ptrCastFull(
2311223052 if (dest_allows_zero) break :check_allowzero;
2311323053
2311423054 return sema.failWithOwnedErrorMsg(block, msg: {
23115 const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{
23055 const msg = try sema.errMsg(src, "'{}' could have null values which are illegal in type '{}'", .{
2311623056 operand_ty.fmt(mod),
2311723057 dest_ty.fmt(mod),
2311823058 });
2311923059 errdefer msg.destroy(sema.gpa);
23120 try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{});
23060 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
2312123061 break :msg msg;
2312223062 });
2312323063 }
......@@ -23138,15 +23078,15 @@ fn ptrCastFull(
2313823078 if (!flags.align_cast) {
2313923079 if (dest_align.compare(.gt, src_align)) {
2314023080 return sema.failWithOwnedErrorMsg(block, msg: {
23141 const msg = try sema.errMsg(block, src, "{s} increases pointer alignment", .{operation});
23081 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
2314223082 errdefer msg.destroy(sema.gpa);
23143 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
23083 try sema.errNote(operand_src, msg, "'{}' has alignment '{d}'", .{
2314423084 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,
2314523085 });
23146 try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{
23086 try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{
2314723087 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,
2314823088 });
23149 try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{});
23089 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
2315023090 break :msg msg;
2315123091 });
2315223092 }
......@@ -23155,15 +23095,15 @@ fn ptrCastFull(
2315523095 if (!flags.addrspace_cast) {
2315623096 if (src_info.flags.address_space != dest_info.flags.address_space) {
2315723097 return sema.failWithOwnedErrorMsg(block, msg: {
23158 const msg = try sema.errMsg(block, src, "{s} changes pointer address space", .{operation});
23098 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
2315923099 errdefer msg.destroy(sema.gpa);
23160 try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{
23100 try sema.errNote(operand_src, msg, "'{}' has address space '{s}'", .{
2316123101 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),
2316223102 });
23163 try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{
23103 try sema.errNote(src, msg, "'{}' has address space '{s}'", .{
2316423104 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),
2316523105 });
23166 try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{});
23106 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
2316723107 break :msg msg;
2316823108 });
2316923109 }
......@@ -23171,9 +23111,9 @@ fn ptrCastFull(
2317123111 // Some address space casts are always disallowed
2317223112 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
2317323113 return sema.failWithOwnedErrorMsg(block, msg: {
23174 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});
23114 const msg = try sema.errMsg(src, "invalid address space cast", .{});
2317523115 errdefer msg.destroy(sema.gpa);
23176 try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
23116 try sema.errNote(operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
2317723117 @tagName(src_info.flags.address_space),
2317823118 @tagName(dest_info.flags.address_space),
2317923119 });
......@@ -23185,9 +23125,9 @@ fn ptrCastFull(
2318523125 if (!flags.const_cast) {
2318623126 if (src_info.flags.is_const and !dest_info.flags.is_const) {
2318723127 return sema.failWithOwnedErrorMsg(block, msg: {
23188 const msg = try sema.errMsg(block, src, "{s} discards const qualifier", .{operation});
23128 const msg = try sema.errMsg(src, "{s} discards const qualifier", .{operation});
2318923129 errdefer msg.destroy(sema.gpa);
23190 try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{});
23130 try sema.errNote(src, msg, "use @constCast to discard const qualifier", .{});
2319123131 break :msg msg;
2319223132 });
2319323133 }
......@@ -23196,9 +23136,9 @@ fn ptrCastFull(
2319623136 if (!flags.volatile_cast) {
2319723137 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
2319823138 return sema.failWithOwnedErrorMsg(block, msg: {
23199 const msg = try sema.errMsg(block, src, "{s} discards volatile qualifier", .{operation});
23139 const msg = try sema.errMsg(src, "{s} discards volatile qualifier", .{operation});
2320023140 errdefer msg.destroy(sema.gpa);
23201 try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{});
23141 try sema.errNote(src, msg, "use @volatileCast to discard volatile qualifier", .{});
2320223142 break :msg msg;
2320323143 });
2320423144 }
......@@ -23347,8 +23287,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2334723287 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2334823288 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2334923289 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
23350 const src = LazySrcLoc.nodeOffset(extra.node);
23351 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
23290 const src = block.nodeOffset(extra.node);
23291 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
2335223292 const operand = try sema.resolveInst(extra.operand);
2335323293 const operand_ty = sema.typeOf(operand);
2335423294 try sema.checkPtrOperand(block, operand_src, operand_ty);
......@@ -23378,8 +23318,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2337823318fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2337923319 const mod = sema.mod;
2338023320 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23381 const src = inst_data.src();
23382 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23321 const src = block.nodeOffset(inst_data.src_node);
23322 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2338323323 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2338423324 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
2338523325 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);
......@@ -23417,16 +23357,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2341723357 if (operand_info.bits < dest_info.bits) {
2341823358 const msg = msg: {
2341923359 const msg = try sema.errMsg(
23420 block,
2342123360 src,
2342223361 "destination type '{}' has more bits than source type '{}'",
2342323362 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
2342423363 );
2342523364 errdefer msg.destroy(sema.gpa);
23426 try sema.errNote(block, src, msg, "destination type has {d} bits", .{
23365 try sema.errNote(src, msg, "destination type has {d} bits", .{
2342723366 dest_info.bits,
2342823367 });
23429 try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{
23368 try sema.errNote(operand_src, msg, "operand type has {d} bits", .{
2343023369 operand_info.bits,
2343123370 });
2343223371 break :msg msg;
......@@ -23468,8 +23407,8 @@ fn zirBitCount(
2346823407) CompileError!Air.Inst.Ref {
2346923408 const mod = sema.mod;
2347023409 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23471 const src = inst_data.src();
23472 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23410 const src = block.nodeOffset(inst_data.src_node);
23411 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2347323412 const operand = try sema.resolveInst(inst_data.operand);
2347423413 const operand_ty = sema.typeOf(operand);
2347523414 _ = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23522,8 +23461,8 @@ fn zirBitCount(
2352223461fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2352323462 const mod = sema.mod;
2352423463 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23525 const src = inst_data.src();
23526 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23464 const src = block.nodeOffset(inst_data.src_node);
23465 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2352723466 const operand = try sema.resolveInst(inst_data.operand);
2352823467 const operand_ty = sema.typeOf(operand);
2352923468 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23578,8 +23517,8 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2357823517
2357923518fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2358023519 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23581 const src = inst_data.src();
23582 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23520 const src = block.nodeOffset(inst_data.src_node);
23521 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2358323522 const operand = try sema.resolveInst(inst_data.operand);
2358423523 const operand_ty = sema.typeOf(operand);
2358523524 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23637,9 +23576,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2363723576
2363823577fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
2363923578 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23640 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
23641 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
23642 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
23579 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
23580 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
23581 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
2364323582 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2364423583
2364523584 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
......@@ -23752,14 +23691,13 @@ fn checkPtrOperand(
2375223691 .Fn => {
2375323692 const msg = msg: {
2375423693 const msg = try sema.errMsg(
23755 block,
2375623694 ty_src,
2375723695 "expected pointer, found '{}'",
2375823696 .{ty.fmt(mod)},
2375923697 );
2376023698 errdefer msg.destroy(sema.gpa);
2376123699
23762 try sema.errNote(block, ty_src, msg, "use '&' to obtain a function pointer", .{});
23700 try sema.errNote(ty_src, msg, "use '&' to obtain a function pointer", .{});
2376323701
2376423702 break :msg msg;
2376523703 };
......@@ -23784,14 +23722,13 @@ fn checkPtrType(
2378423722 .Fn => {
2378523723 const msg = msg: {
2378623724 const msg = try sema.errMsg(
23787 block,
2378823725 ty_src,
2378923726 "expected pointer type, found '{}'",
2379023727 .{ty.fmt(mod)},
2379123728 );
2379223729 errdefer msg.destroy(sema.gpa);
2379323730
23794 try sema.errNote(block, ty_src, msg, "use '*const ' to make a function pointer type", .{});
23731 try sema.errNote(ty_src, msg, "use '*const ' to make a function pointer type", .{});
2379523732
2379623733 break :msg msg;
2379723734 };
......@@ -24045,26 +23982,26 @@ fn checkVectorizableBinaryOperands(
2404523982 const rhs_len = rhs_ty.arrayLen(mod);
2404623983 if (lhs_len != rhs_len) {
2404723984 const msg = msg: {
24048 const msg = try sema.errMsg(block, src, "vector length mismatch", .{});
23985 const msg = try sema.errMsg(src, "vector length mismatch", .{});
2404923986 errdefer msg.destroy(sema.gpa);
24050 try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len});
24051 try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len});
23987 try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len});
23988 try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len});
2405223989 break :msg msg;
2405323990 };
2405423991 return sema.failWithOwnedErrorMsg(block, msg);
2405523992 }
2405623993 } else {
2405723994 const msg = msg: {
24058 const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{
23995 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{}' and '{}'", .{
2405923996 lhs_ty.fmt(mod), rhs_ty.fmt(mod),
2406023997 });
2406123998 errdefer msg.destroy(sema.gpa);
2406223999 if (lhs_is_vector) {
24063 try sema.errNote(block, lhs_src, msg, "vector here", .{});
24064 try sema.errNote(block, rhs_src, msg, "scalar here", .{});
24000 try sema.errNote(lhs_src, msg, "vector here", .{});
24001 try sema.errNote(rhs_src, msg, "scalar here", .{});
2406524002 } else {
24066 try sema.errNote(block, lhs_src, msg, "scalar here", .{});
24067 try sema.errNote(block, rhs_src, msg, "vector here", .{});
24003 try sema.errNote(lhs_src, msg, "scalar here", .{});
24004 try sema.errNote(rhs_src, msg, "vector here", .{});
2406824005 }
2406924006 break :msg msg;
2407024007 };
......@@ -24072,12 +24009,6 @@ fn checkVectorizableBinaryOperands(
2407224009 }
2407324010}
2407424011
24075fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
24076 if (base_src == .unneeded) return .unneeded;
24077 const mod = sema.mod;
24078 return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted);
24079}
24080
2408124012fn resolveExportOptions(
2408224013 sema: *Sema,
2408324014 block: *Block,
......@@ -24091,10 +24022,10 @@ fn resolveExportOptions(
2409124022 const air_ref = try sema.resolveInst(zir_ref);
2409224023 const options = try sema.coerce(block, export_options_ty, air_ref, src);
2409324024
24094 const name_src = sema.maybeOptionsSrc(block, src, "name");
24095 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
24096 const section_src = sema.maybeOptionsSrc(block, src, "section");
24097 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
24025 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24026 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24027 const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24028 const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2409824029
2409924030 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
2410024031 const name = try sema.toConstString(block, name_src, name_operand, .{
......@@ -24191,14 +24122,14 @@ fn zirCmpxchg(
2419124122 1 => .cmpxchg_strong,
2419224123 else => unreachable,
2419324124 };
24194 const src = LazySrcLoc.nodeOffset(extra.node);
24125 const src = block.nodeOffset(extra.node);
2419524126 // zig fmt: off
24196 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
24197 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
24198 const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
24199 const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };
24200 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node };
24201 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node };
24127 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24128 const ptr_src = block.builtinCallArgSrc(extra.node, 1);
24129 const expected_src = block.builtinCallArgSrc(extra.node, 2);
24130 const new_value_src = block.builtinCallArgSrc(extra.node, 3);
24131 const success_order_src = block.builtinCallArgSrc(extra.node, 4);
24132 const failure_order_src = block.builtinCallArgSrc(extra.node, 5);
2420224133 // zig fmt: on
2420324134 const expected_value = try sema.resolveInst(extra.expected_value);
2420424135 const elem_ty = sema.typeOf(expected_value);
......@@ -24287,8 +24218,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2428724218 const mod = sema.mod;
2428824219 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2428924220 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24290 const src = inst_data.src();
24291 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24221 const src = block.nodeOffset(inst_data.src_node);
24222 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2429224223 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2429324224
2429424225 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});
......@@ -24309,15 +24240,15 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2430924240 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
2431024241 }
2431124242
24312 try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src);
24243 try sema.requireRuntimeBlock(block, src, scalar_src);
2431324244 return block.addTyOp(.splat, dest_ty, scalar);
2431424245}
2431524246
2431624247fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2431724248 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2431824249 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24319 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24320 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24250 const op_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24251 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2432124252 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
2432224253 .needed_comptime_reason = "@reduce operation must be comptime-known",
2432324254 });
......@@ -24374,7 +24305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2437424305 return Air.internedToRef(accum.toIntern());
2437524306 }
2437624307
24377 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
24308 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src);
2437824309 return block.addInst(.{
2437924310 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
2438024311 .data = .{ .reduce = .{
......@@ -24388,8 +24319,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2438824319 const mod = sema.mod;
2438924320 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2439024321 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
24391 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24392 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24322 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24323 const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2439324324
2439424325 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2439524326 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
......@@ -24424,9 +24355,9 @@ fn analyzeShuffle(
2442424355 mask_len: u32,
2442524356) CompileError!Air.Inst.Ref {
2442624357 const mod = sema.mod;
24427 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node };
24428 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node };
24429 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node };
24358 const a_src = block.builtinCallArgSrc(src_node, 1);
24359 const b_src = block.builtinCallArgSrc(src_node, 2);
24360 const mask_src = block.builtinCallArgSrc(src_node, 3);
2443024361 var a = a_arg;
2443124362 var b = b_arg;
2443224363
......@@ -24490,16 +24421,16 @@ fn analyzeShuffle(
2449024421 }
2449124422 if (unsigned >= operand_info[chosen][0]) {
2449224423 const msg = msg: {
24493 const msg = try sema.errMsg(block, mask_src, "mask index '{d}' has out-of-bounds selection", .{i});
24424 const msg = try sema.errMsg(mask_src, "mask index '{d}' has out-of-bounds selection", .{i});
2449424425 errdefer msg.destroy(sema.gpa);
2449524426
24496 try sema.errNote(block, operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{
24427 try sema.errNote(operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{
2449724428 unsigned,
2449824429 operand_info[chosen][2].fmt(sema.mod),
2449924430 });
2450024431
2450124432 if (chosen == 0) {
24502 try sema.errNote(block, b_src, msg, "selections from the second vector are specified with negative numbers", .{});
24433 try sema.errNote(b_src, msg, "selections from the second vector are specified with negative numbers", .{});
2450324434 }
2450424435
2450524436 break :msg msg;
......@@ -24577,11 +24508,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2457724508 const mod = sema.mod;
2457824509 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2457924510
24580 const src = LazySrcLoc.nodeOffset(extra.node);
24581 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
24582 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
24583 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
24584 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };
24511 const src = block.nodeOffset(extra.node);
24512 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24513 const pred_src = block.builtinCallArgSrc(extra.node, 1);
24514 const a_src = block.builtinCallArgSrc(extra.node, 2);
24515 const b_src = block.builtinCallArgSrc(extra.node, 3);
2458524516
2458624517 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2458724518 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
......@@ -24668,9 +24599,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2466824599 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2466924600 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
2467024601 // zig fmt: off
24671 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24672 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24673 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24602 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24603 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24604 const order_src = block.builtinCallArgSrc(inst_data.src_node, 2);
2467424605 // zig fmt: on
2467524606 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2467624607 const uncasted_ptr = try sema.resolveInst(extra.ptr);
......@@ -24701,7 +24632,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2470124632 }
2470224633 }
2470324634
24704 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
24635 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src);
2470524636 return block.addInst(.{
2470624637 .tag = .atomic_load,
2470724638 .data = .{ .atomic_load = .{
......@@ -24715,13 +24646,13 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2471524646 const mod = sema.mod;
2471624647 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2471724648 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
24718 const src = inst_data.src();
24649 const src = block.nodeOffset(inst_data.src_node);
2471924650 // zig fmt: off
24720 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24721 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24722 const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24723 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24724 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
24651 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24652 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24653 const op_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24654 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24655 const order_src = block.builtinCallArgSrc(inst_data.src_node, 4);
2472524656 // zig fmt: on
2472624657 const operand = try sema.resolveInst(extra.operand);
2472724658 const elem_ty = sema.typeOf(operand);
......@@ -24800,12 +24731,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2480024731fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2480124732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2480224733 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
24803 const src = inst_data.src();
24734 const src = block.nodeOffset(inst_data.src_node);
2480424735 // zig fmt: off
24805 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24806 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24807 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24808 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24736 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24737 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24738 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24739 const order_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2480924740 // zig fmt: on
2481024741 const operand = try sema.resolveInst(extra.operand);
2481124742 const elem_ty = sema.typeOf(operand);
......@@ -24836,11 +24767,11 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2483624767fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2483724768 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2483824769 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
24839 const src = inst_data.src();
24770 const src = block.nodeOffset(inst_data.src_node);
2484024771
24841 const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24842 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24843 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24772 const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24773 const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24774 const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2484424775
2484524776 const addend = try sema.resolveInst(extra.addend);
2484624777 const ty = sema.typeOf(addend);
......@@ -24903,10 +24834,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2490324834
2490424835 const mod = sema.mod;
2490524836 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24906 const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24907 const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24908 const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24909 const call_src = inst_data.src();
24837 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24838 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24839 const args_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24840 const call_src = block.nodeOffset(inst_data.src_node);
2491024841
2491124842 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
2491224843 const func = try sema.resolveInst(extra.callee);
......@@ -25000,9 +24931,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2500024931 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2500124932 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2500224933 assert(!flags.ptr_cast);
25003 const inst_src = extra.src();
25004 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node };
25005 const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node };
24934 const inst_src = block.nodeOffset(extra.src_node);
24935 const field_name_src = block.builtinCallArgSrc(extra.src_node, 0);
24936 const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1);
2500624937
2500724938 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");
2500824939 try sema.checkPtrType(block, inst_src, parent_ptr_ty, true);
......@@ -25191,9 +25122,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte
2519125122 };
2519225123 if (ptr.byte_offset < byte_subtract) {
2519325124 return sema.failWithOwnedErrorMsg(block, msg: {
25194 const msg = try sema.errMsg(block, src, "pointer computation here causes undefined behavior", .{});
25125 const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{});
2519525126 errdefer msg.destroy(sema.gpa);
25196 try sema.errNote(block, src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
25127 try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
2519725128 break :msg msg;
2519825129 });
2519925130 }
......@@ -25210,9 +25141,9 @@ fn zirMinMax(
2521025141) CompileError!Air.Inst.Ref {
2521125142 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2521225143 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25213 const src = inst_data.src();
25214 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25215 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25144 const src = block.nodeOffset(inst_data.src_node);
25145 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25146 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2521625147 const lhs = try sema.resolveInst(extra.lhs);
2521725148 const rhs = try sema.resolveInst(extra.rhs);
2521825149 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
......@@ -25228,22 +25159,14 @@ fn zirMinMaxMulti(
2522825159) CompileError!Air.Inst.Ref {
2522925160 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
2523025161 const src_node = extra.data.src_node;
25231 const src = LazySrcLoc.nodeOffset(src_node);
25162 const src = block.nodeOffset(src_node);
2523225163 const operands = sema.code.refSlice(extra.end, extended.small);
2523325164
2523425165 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
2523525166 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);
2523625167
2523725168 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {
25238 op_src.* = switch (i) {
25239 0 => .{ .node_offset_builtin_call_arg0 = src_node },
25240 1 => .{ .node_offset_builtin_call_arg1 = src_node },
25241 2 => .{ .node_offset_builtin_call_arg2 = src_node },
25242 3 => .{ .node_offset_builtin_call_arg3 = src_node },
25243 4 => .{ .node_offset_builtin_call_arg4 = src_node },
25244 5 => .{ .node_offset_builtin_call_arg5 = src_node },
25245 else => src, // TODO: better source location
25246 };
25169 op_src.* = block.builtinCallArgSrc(src_node, @intCast(i));
2524725170 air_ref.* = try sema.resolveInst(zir_ref);
2524825171 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));
2524925172 }
......@@ -25511,9 +25434,9 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
2551125434fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2551225435 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2551325436 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25514 const src = inst_data.src();
25515 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25516 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25437 const src = block.nodeOffset(inst_data.src_node);
25438 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25439 const src_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2551725440 const dest_ptr = try sema.resolveInst(extra.lhs);
2551825441 const src_ptr = try sema.resolveInst(extra.rhs);
2551925442 const dest_ty = sema.typeOf(dest_ptr);
......@@ -25529,12 +25452,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2552925452
2553025453 if (dest_len == .none and src_len == .none) {
2553125454 const msg = msg: {
25532 const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{});
25455 const msg = try sema.errMsg(src, "unknown @memcpy length", .{});
2553325456 errdefer msg.destroy(sema.gpa);
25534 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{
25457 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
2553525458 dest_ty.fmt(sema.mod),
2553625459 });
25537 try sema.errNote(block, src_src, msg, "source type '{}' provides no length", .{
25460 try sema.errNote(src_src, msg, "source type '{}' provides no length", .{
2553825461 src_ty.fmt(sema.mod),
2553925462 });
2554025463 break :msg msg;
......@@ -25551,12 +25474,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2555125474 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
2555225475 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
2555325476 const msg = msg: {
25554 const msg = try sema.errMsg(block, src, "non-matching @memcpy lengths", .{});
25477 const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{});
2555525478 errdefer msg.destroy(sema.gpa);
25556 try sema.errNote(block, dest_src, msg, "length {} here", .{
25479 try sema.errNote(dest_src, msg, "length {} here", .{
2555725480 dest_len_val.fmtValue(sema.mod, sema),
2555825481 });
25559 try sema.errNote(block, src_src, msg, "length {} here", .{
25482 try sema.errNote(src_src, msg, "length {} here", .{
2556025483 src_len_val.fmtValue(sema.mod, sema),
2556125484 });
2556225485 break :msg msg;
......@@ -25664,7 +25587,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2566425587 } else if (dest_len == .none and len_val == null) {
2566525588 // Change the dest to a slice, since its type must have the length.
2566625589 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
25667 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);
25590 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false);
2566825591 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
2566925592 if (new_src_ptr_ty.isSlice(mod)) {
2567025593 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
......@@ -25731,9 +25654,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2573125654 const ip = &mod.intern_pool;
2573225655 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2573325656 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25734 const src = inst_data.src();
25735 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25736 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25657 const src = block.nodeOffset(inst_data.src_node);
25658 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25659 const value_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2573725660 const dest_ptr = try sema.resolveInst(extra.lhs);
2573825661 const uncoerced_elem = try sema.resolveInst(extra.rhs);
2573925662 const dest_ptr_ty = sema.typeOf(dest_ptr);
......@@ -25755,9 +25678,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2575525678 .Many, .C => {},
2575625679 }
2575725680 return sema.failWithOwnedErrorMsg(block, msg: {
25758 const msg = try sema.errMsg(block, src, "unknown @memset length", .{});
25681 const msg = try sema.errMsg(src, "unknown @memset length", .{});
2575925682 errdefer msg.destroy(sema.gpa);
25760 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{
25683 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
2576125684 dest_ptr_ty.fmt(mod),
2576225685 });
2576325686 break :msg msg;
......@@ -25810,13 +25733,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2581025733
2581125734fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2581225735 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25813 const src = LazySrcLoc.nodeOffset(extra.node);
25736 const src = block.nodeOffset(extra.node);
2581425737 return sema.failWithUseOfAsync(block, src);
2581525738}
2581625739
2581725740fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2581825741 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
25819 const src = inst_data.src();
25742 const src = block.nodeOffset(inst_data.src_node);
2582025743 return sema.failWithUseOfAsync(block, src);
2582125744}
2582225745
......@@ -25826,7 +25749,7 @@ fn zirAwait(
2582625749 inst: Zir.Inst.Index,
2582725750) CompileError!Air.Inst.Ref {
2582825751 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
25829 const src = inst_data.src();
25752 const src = block.nodeOffset(inst_data.src_node);
2583025753
2583125754 return sema.failWithUseOfAsync(block, src);
2583225755}
......@@ -25837,7 +25760,7 @@ fn zirAwaitNosuspend(
2583725760 extended: Zir.Inst.Extended.InstData,
2583825761) CompileError!Air.Inst.Ref {
2583925762 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25840 const src = LazySrcLoc.nodeOffset(extra.node);
25763 const src = block.nodeOffset(extra.node);
2584125764
2584225765 return sema.failWithUseOfAsync(block, src);
2584325766}
......@@ -25849,8 +25772,8 @@ fn zirVarExtended(
2584925772) CompileError!Air.Inst.Ref {
2585025773 const mod = sema.mod;
2585125774 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
25852 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
25853 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
25775 const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 });
25776 const init_src = block.src(.{ .node_offset_var_decl_init = 0 });
2585425777 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);
2585525778
2585625779 var extra_index: usize = extra.end;
......@@ -25915,11 +25838,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2591525838 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
2591625839 const target = mod.getTarget();
2591725840
25918 const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node };
25919 const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node };
25920 const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node };
25921 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };
25922 const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };
25841 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
25842 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
25843 const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node });
25844 const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node });
25845 const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
2592325846 const has_body = extra.data.body_len != 0;
2592425847
2592525848 var extra_index: usize = extra.end;
......@@ -26146,7 +26069,7 @@ fn zirCUndef(
2614626069 extended: Zir.Inst.Extended.InstData,
2614726070) CompileError!Air.Inst.Ref {
2614826071 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26149 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26072 const src = block.builtinCallArgSrc(extra.node, 0);
2615026073
2615126074 const name = try sema.resolveConstString(block, src, extra.operand, .{
2615226075 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
......@@ -26161,7 +26084,7 @@ fn zirCInclude(
2616126084 extended: Zir.Inst.Extended.InstData,
2616226085) CompileError!Air.Inst.Ref {
2616326086 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26164 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26087 const src = block.builtinCallArgSrc(extra.node, 0);
2616526088
2616626089 const name = try sema.resolveConstString(block, src, extra.operand, .{
2616726090 .needed_comptime_reason = "path being included must be comptime-known",
......@@ -26177,8 +26100,8 @@ fn zirCDefine(
2617726100) CompileError!Air.Inst.Ref {
2617826101 const mod = sema.mod;
2617926102 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26180 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26181 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26103 const name_src = block.builtinCallArgSrc(extra.node, 0);
26104 const val_src = block.builtinCallArgSrc(extra.node, 1);
2618226105
2618326106 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
2618426107 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
......@@ -26201,8 +26124,8 @@ fn zirWasmMemorySize(
2620126124 extended: Zir.Inst.Extended.InstData,
2620226125) CompileError!Air.Inst.Ref {
2620326126 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26204 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26205 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26127 const index_src = block.builtinCallArgSrc(extra.node, 0);
26128 const builtin_src = block.nodeOffset(extra.node);
2620626129 const target = sema.mod.getTarget();
2620726130 if (!target.isWasm()) {
2620826131 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
......@@ -26227,9 +26150,9 @@ fn zirWasmMemoryGrow(
2622726150 extended: Zir.Inst.Extended.InstData,
2622826151) CompileError!Air.Inst.Ref {
2622926152 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26230 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26231 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26232 const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26153 const builtin_src = block.nodeOffset(extra.node);
26154 const index_src = block.builtinCallArgSrc(extra.node, 0);
26155 const delta_src = block.builtinCallArgSrc(extra.node, 1);
2623326156 const target = sema.mod.getTarget();
2623426157 if (!target.isWasm()) {
2623526158 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
......@@ -26262,9 +26185,9 @@ fn resolvePrefetchOptions(
2626226185 const options_ty = try sema.getBuiltinType("PrefetchOptions");
2626326186 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2626426187
26265 const rw_src = sema.maybeOptionsSrc(block, src, "rw");
26266 const locality_src = sema.maybeOptionsSrc(block, src, "locality");
26267 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
26188 const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26189 const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26190 const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2626826191
2626926192 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
2627026193 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
......@@ -26294,18 +26217,12 @@ fn zirPrefetch(
2629426217 extended: Zir.Inst.Extended.InstData,
2629526218) CompileError!Air.Inst.Ref {
2629626219 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26297 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26298 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26220 const ptr_src = block.builtinCallArgSrc(extra.node, 0);
26221 const opts_src = block.builtinCallArgSrc(extra.node, 1);
2629926222 const ptr = try sema.resolveInst(extra.lhs);
2630026223 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
2630126224
26302 const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
26303 error.NeededSourceLocation => {
26304 _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26305 unreachable;
26306 },
26307 else => |e| return e,
26308 };
26225 const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
2630926226
2631026227 if (!block.is_comptime) {
2631126228 _ = try block.addInst(.{
......@@ -26340,10 +26257,10 @@ fn resolveExternOptions(
2634026257 const extern_options_ty = try sema.getBuiltinType("ExternOptions");
2634126258 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
2634226259
26343 const name_src = sema.maybeOptionsSrc(block, src, "name");
26344 const library_src = sema.maybeOptionsSrc(block, src, "library");
26345 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
26346 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
26260 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26261 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26262 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26263 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2634726264
2634826265 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
2634926266 const name = try sema.toConstString(block, name_src, name_ref, .{
......@@ -26401,8 +26318,8 @@ fn zirBuiltinExtern(
2640126318 const mod = sema.mod;
2640226319 const ip = &mod.intern_pool;
2640326320 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26404 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26405 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26321 const ty_src = block.builtinCallArgSrc(extra.node, 0);
26322 const options_src = block.builtinCallArgSrc(extra.node, 1);
2640626323
2640726324 var ty = try sema.resolveType(block, ty_src, extra.lhs);
2640826325 if (!ty.isPtrAtRuntime(mod)) {
......@@ -26410,29 +26327,22 @@ fn zirBuiltinExtern(
2641026327 }
2641126328 if (!try sema.validateExternType(ty, .other)) {
2641226329 const msg = msg: {
26413 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
26330 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
2641426331 errdefer msg.destroy(sema.gpa);
26415 const src_decl = sema.mod.declPtr(block.src_decl);
26416 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other);
26332 try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other);
2641726333 break :msg msg;
2641826334 };
2641926335 return sema.failWithOwnedErrorMsg(block, msg);
2642026336 }
2642126337
26422 const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
26423 error.NeededSourceLocation => {
26424 _ = try sema.resolveExternOptions(block, options_src, extra.rhs);
26425 unreachable;
26426 },
26427 else => |e| return e,
26428 };
26338 const options = try sema.resolveExternOptions(block, options_src, extra.rhs);
2642926339
2643026340 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
2643126341 ty = try mod.optionalType(ty.toIntern());
2643226342 }
2643326343 const ptr_info = ty.ptrInfo(mod);
2643426344
26435 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node);
26345 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace);
2643626346 errdefer mod.destroyDecl(new_decl_index);
2643726347 const new_decl = mod.declPtr(new_decl_index);
2643826348 try mod.initNewAnonDecl(
......@@ -26482,8 +26392,8 @@ fn zirWorkItem(
2648226392 zir_tag: Zir.Inst.Extended,
2648326393) CompileError!Air.Inst.Ref {
2648426394 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26485 const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26486 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26395 const dimension_src = block.builtinCallArgSrc(extra.node, 0);
26396 const builtin_src = block.nodeOffset(extra.node);
2648726397 const target = sema.mod.getTarget();
2648826398
2648926399 switch (target.cpu.arch) {
......@@ -26524,11 +26434,11 @@ fn zirInComptime(
2652426434fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
2652526435 if (block.is_comptime) {
2652626436 const msg = msg: {
26527 const msg = try sema.errMsg(block, src, "unable to evaluate comptime expression", .{});
26437 const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{});
2652826438 errdefer msg.destroy(sema.gpa);
2652926439
2653026440 if (runtime_src) |some| {
26531 try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{});
26441 try sema.errNote(some, msg, "operation is runtime due to this operand", .{});
2653226442 }
2653326443 if (block.comptime_reason) |some| {
2653426444 try some.explain(sema, msg);
......@@ -26551,10 +26461,9 @@ fn validateVarType(
2655126461 if (is_extern) {
2655226462 if (!try sema.validateExternType(var_ty, .other)) {
2655326463 const msg = msg: {
26554 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
26464 const msg = try sema.errMsg(src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
2655526465 errdefer msg.destroy(sema.gpa);
26556 const src_decl = mod.declPtr(block.src_decl);
26557 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other);
26466 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
2655826467 break :msg msg;
2655926468 };
2656026469 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -26573,13 +26482,12 @@ fn validateVarType(
2657326482 if (!try sema.typeRequiresComptime(var_ty)) return;
2657426483
2657526484 const msg = msg: {
26576 const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});
26485 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});
2657726486 errdefer msg.destroy(sema.gpa);
2657826487
26579 const src_decl = mod.declPtr(block.src_decl);
26580 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty);
26488 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
2658126489 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26582 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
26490 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2658326491 }
2658426492
2658526493 break :msg msg;
......@@ -26592,7 +26500,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
2659226500fn explainWhyTypeIsComptime(
2659326501 sema: *Sema,
2659426502 msg: *Module.ErrorMsg,
26595 src_loc: Module.SrcLoc,
26503 src_loc: LazySrcLoc,
2659626504 ty: Type,
2659726505) CompileError!void {
2659826506 var type_set = TypeSet{};
......@@ -26605,7 +26513,7 @@ fn explainWhyTypeIsComptime(
2660526513fn explainWhyTypeIsComptimeInner(
2660626514 sema: *Sema,
2660726515 msg: *Module.ErrorMsg,
26608 src_loc: Module.SrcLoc,
26516 src_loc: LazySrcLoc,
2660926517 ty: Type,
2661026518 type_set: *TypeSet,
2661126519) CompileError!void {
......@@ -26623,13 +26531,13 @@ fn explainWhyTypeIsComptimeInner(
2662326531 => return,
2662426532
2662526533 .Fn => {
26626 try mod.errNoteNonLazy(src_loc, msg, "use '*const {}' for a function pointer type", .{
26534 try sema.errNote(src_loc, msg, "use '*const {}' for a function pointer type", .{
2662726535 ty.fmt(sema.mod),
2662826536 });
2662926537 },
2663026538
2663126539 .Type => {
26632 try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{});
26540 try sema.errNote(src_loc, msg, "types are not available at runtime", .{});
2663326541 },
2663426542
2663526543 .ComptimeFloat,
......@@ -26641,7 +26549,7 @@ fn explainWhyTypeIsComptimeInner(
2664126549 => return,
2664226550
2664326551 .Opaque => {
26644 try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
26552 try sema.errNote(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
2664526553 },
2664626554
2664726555 .Array, .Vector => {
......@@ -26652,14 +26560,14 @@ fn explainWhyTypeIsComptimeInner(
2665226560 if (elem_ty.zigTypeTag(mod) == .Fn) {
2665326561 const fn_info = mod.typeToFunc(elem_ty).?;
2665426562 if (fn_info.is_generic) {
26655 try mod.errNoteNonLazy(src_loc, msg, "function is generic", .{});
26563 try sema.errNote(src_loc, msg, "function is generic", .{});
2665626564 }
2665726565 switch (fn_info.cc) {
26658 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),
26566 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
2665926567 else => {},
2666026568 }
2666126569 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {
26662 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});
26570 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
2666326571 }
2666426572 return;
2666526573 }
......@@ -26679,14 +26587,14 @@ fn explainWhyTypeIsComptimeInner(
2667926587 if (mod.typeToStruct(ty)) |struct_type| {
2668026588 for (0..struct_type.field_types.len) |i| {
2668126589 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26682 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
26683 .index = i,
26684 .range = .type,
26685 });
26590 const field_src: LazySrcLoc = .{
26591 .base_node_inst = struct_type.zir_index.unwrap().?,
26592 .offset = .{ .container_field_type = @intCast(i) },
26593 };
2668626594
2668726595 if (try sema.typeRequiresComptime(field_ty)) {
26688 try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
26689 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);
26596 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
26597 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2669026598 }
2669126599 }
2669226600 }
......@@ -26699,14 +26607,14 @@ fn explainWhyTypeIsComptimeInner(
2669926607 if (mod.typeToUnion(ty)) |union_obj| {
2670026608 for (0..union_obj.field_types.len) |i| {
2670126609 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26702 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{
26703 .index = i,
26704 .range = .type,
26705 });
26610 const field_src: LazySrcLoc = .{
26611 .base_node_inst = union_obj.zir_index,
26612 .offset = .{ .container_field_type = @intCast(i) },
26613 };
2670626614
2670726615 if (try sema.typeRequiresComptime(field_ty)) {
26708 try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
26709 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);
26616 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
26617 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2671026618 }
2671126619 }
2671226620 }
......@@ -26796,7 +26704,7 @@ fn validateExternType(
2679626704fn explainWhyTypeIsNotExtern(
2679726705 sema: *Sema,
2679826706 msg: *Module.ErrorMsg,
26799 src_loc: Module.SrcLoc,
26707 src_loc: LazySrcLoc,
2680026708 ty: Type,
2680126709 position: ExternPosition,
2680226710) CompileError!void {
......@@ -26821,55 +26729,55 @@ fn explainWhyTypeIsNotExtern(
2682126729
2682226730 .Pointer => {
2682326731 if (ty.isSlice(mod)) {
26824 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26732 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2682526733 } else {
2682626734 const pointee_ty = ty.childType(mod);
2682726735 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {
26828 try mod.errNoteNonLazy(src_loc, msg, "pointer to extern function must be 'const'", .{});
26736 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});
2682926737 } else if (try sema.typeRequiresComptime(ty)) {
26830 try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
26738 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
2683126739 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2683226740 }
2683326741 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);
2683426742 }
2683526743 },
26836 .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
26837 .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
26744 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
26745 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
2683826746 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {
26839 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
26747 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
2684026748 } else {
26841 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
26749 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
2684226750 },
2684326751 .Fn => {
2684426752 if (position != .other) {
26845 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26846 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26753 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26754 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2684726755 return;
2684826756 }
2684926757 switch (ty.fnCallingConvention(mod)) {
26850 .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}),
26851 .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}),
26852 .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}),
26758 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
26759 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
26760 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
2685326761 else => return,
2685426762 }
2685526763 },
2685626764 .Enum => {
2685726765 const tag_ty = ty.intTagType(mod);
26858 try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
26766 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
2685926767 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
2686026768 },
26861 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),
26862 .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
26769 .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),
26770 .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
2686326771 .Array => {
2686426772 if (position == .ret_ty) {
26865 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a return type", .{});
26773 return sema.errNote(src_loc, msg, "arrays are not allowed as a return type", .{});
2686626774 } else if (position == .param_ty) {
26867 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a parameter type", .{});
26775 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
2686826776 }
2686926777 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
2687026778 },
2687126779 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),
26872 .Optional => try mod.errNoteNonLazy(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
26780 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
2687326781 }
2687426782}
2687526783
......@@ -26912,7 +26820,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
2691226820fn explainWhyTypeIsNotPacked(
2691326821 sema: *Sema,
2691426822 msg: *Module.ErrorMsg,
26915 src_loc: Module.SrcLoc,
26823 src_loc: LazySrcLoc,
2691626824 ty: Type,
2691726825) CompileError!void {
2691826826 const mod = sema.mod;
......@@ -26938,19 +26846,19 @@ fn explainWhyTypeIsNotPacked(
2693826846 .AnyFrame,
2693926847 .Optional,
2694026848 .Array,
26941 => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
26849 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
2694226850 .Pointer => if (ty.isSlice(mod)) {
26943 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26851 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2694426852 } else {
26945 try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
26853 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
2694626854 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2694726855 },
2694826856 .Fn => {
26949 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26950 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26857 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26858 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2695126859 },
26952 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),
26953 .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
26860 .Struct => try sema.errNote(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),
26861 .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
2695426862 }
2695526863}
2695626864
......@@ -27001,11 +26909,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
2700126909 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
2700226910 const msg_decl_index = (sema.namespaceLookup(
2700326911 block,
27004 .unneeded,
26912 LazySrcLoc.unneeded,
2700526913 panic_messages_ty.getNamespaceIndex(mod),
2700626914 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
2700726915 ) catch |err| switch (err) {
27008 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),
26916 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
2700926917 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
2701026918 error.OutOfMemory => |e| return e,
2701126919 }).?;
......@@ -27027,11 +26935,12 @@ fn addSafetyCheck(
2702726935 var fail_block: Block = .{
2702826936 .parent = parent_block,
2702926937 .sema = sema,
27030 .src_decl = parent_block.src_decl,
2703126938 .namespace = parent_block.namespace,
2703226939 .instructions = .{},
2703326940 .inlining = parent_block.inlining,
2703426941 .is_comptime = false,
26942 .src_base_inst = parent_block.src_base_inst,
26943 .type_name_ctx = parent_block.type_name_ctx,
2703526944 };
2703626945
2703726946 defer fail_block.instructions.deinit(gpa);
......@@ -27135,11 +27044,12 @@ fn panicUnwrapError(
2713527044 var fail_block: Block = .{
2713627045 .parent = parent_block,
2713727046 .sema = sema,
27138 .src_decl = parent_block.src_decl,
2713927047 .namespace = parent_block.namespace,
2714027048 .instructions = .{},
2714127049 .inlining = parent_block.inlining,
2714227050 .is_comptime = false,
27051 .src_base_inst = parent_block.src_base_inst,
27052 .type_name_ctx = parent_block.type_name_ctx,
2714327053 };
2714427054
2714527055 defer fail_block.instructions.deinit(gpa);
......@@ -27251,11 +27161,12 @@ fn safetyCheckFormatted(
2725127161 var fail_block: Block = .{
2725227162 .parent = parent_block,
2725327163 .sema = sema,
27254 .src_decl = parent_block.src_decl,
2725527164 .namespace = parent_block.namespace,
2725627165 .instructions = .{},
2725727166 .inlining = parent_block.inlining,
2725827167 .is_comptime = false,
27168 .src_base_inst = parent_block.src_base_inst,
27169 .type_name_ctx = parent_block.type_name_ctx,
2725927170 };
2726027171
2726127172 defer fail_block.instructions.deinit(gpa);
......@@ -27279,13 +27190,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2727927190 sema.branch_count += 1;
2728027191 if (sema.branch_count > sema.branch_quota) {
2728127192 const msg = try sema.errMsg(
27282 block,
2728327193 src,
2728427194 "evaluation exceeded {d} backwards branches",
2728527195 .{sema.branch_quota},
2728627196 );
2728727197 try sema.errNote(
27288 block,
2728927198 src,
2729027199 msg,
2729127200 "use @setEvalBranchQuota() to raise the branch limit from {d}",
......@@ -27451,10 +27360,10 @@ fn fieldVal(
2745127360 },
2745227361 else => {
2745327362 const msg = msg: {
27454 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)});
27363 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(mod)});
2745527364 errdefer msg.destroy(sema.gpa);
27456 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});
27457 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
27365 if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27366 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
2745827367 break :msg msg;
2745927368 };
2746027369 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -27612,7 +27521,7 @@ fn fieldPtr(
2761227521 }
2761327522 },
2761427523 .Type => {
27615 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);
27524 _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined);
2761627525 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2761727526 const inner = if (is_pointer_to)
2761827527 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -27805,7 +27714,7 @@ fn fieldCallBind(
2780527714 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse
2780627715 break :found_decl null;
2780727716
27808 try sema.addReferencedBy(block, src, decl_idx);
27717 try sema.addReferencedBy(src, decl_idx);
2780927718 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);
2781027719 const decl_type = sema.typeOf(decl_val);
2781127720 if (mod.typeToFunc(decl_type)) |func_type| f: {
......@@ -27864,7 +27773,7 @@ fn fieldCallBind(
2786427773 };
2786527774
2786627775 const msg = msg: {
27867 const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{
27776 const msg = try sema.errMsg(src, "no field or member function named '{}' in '{}'", .{
2786827777 field_name.fmt(ip),
2786927778 concrete_ty.fmt(mod),
2787027779 });
......@@ -27872,10 +27781,13 @@ fn fieldCallBind(
2787227781 try sema.addDeclaredHereNote(msg, concrete_ty);
2787327782 if (found_decl) |decl_idx| {
2787427783 const decl = mod.declPtr(decl_idx);
27875 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)});
27784 try sema.errNote(.{
27785 .base_node_inst = decl.zir_decl_index.unwrap().?,
27786 .offset = LazySrcLoc.Offset.nodeOffset(0),
27787 }, msg, "'{}' is not a member function", .{field_name.fmt(ip)});
2787627788 }
2787727789 if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {
27878 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
27790 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2787927791 }
2788027792 break :msg msg;
2788127793 };
......@@ -27933,11 +27845,14 @@ fn namespaceLookup(
2793327845 const decl = mod.declPtr(decl_index);
2793427846 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
2793527847 const msg = msg: {
27936 const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{
27848 const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{
2793727849 decl_name.fmt(&mod.intern_pool),
2793827850 });
2793927851 errdefer msg.destroy(gpa);
27940 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
27852 try sema.errNote(.{
27853 .base_node_inst = decl.zir_decl_index.unwrap().?,
27854 .offset = LazySrcLoc.Offset.nodeOffset(0),
27855 }, msg, "declared here", .{});
2794127856 break :msg msg;
2794227857 };
2794327858 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -27955,7 +27870,7 @@ fn namespaceLookupRef(
2795527870 decl_name: InternPool.NullTerminatedString,
2795627871) CompileError!?Air.Inst.Ref {
2795727872 const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null;
27958 try sema.addReferencedBy(block, src, decl);
27873 try sema.addReferencedBy(src, decl);
2795927874 return try sema.analyzeDeclRef(decl);
2796027875}
2796127876
......@@ -28002,7 +27917,7 @@ fn structFieldPtr(
2800227917 const struct_type = mod.typeToStruct(struct_ty).?;
2800327918
2800427919 const field_index = struct_type.nameIndex(ip, field_name) orelse
28005 return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name);
27920 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
2800627921
2800727922 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
2800827923}
......@@ -28117,7 +28032,7 @@ fn structFieldVal(
2811728032 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);
2811828033
2811928034 const field_index = struct_type.nameIndex(ip, field_name) orelse
28120 return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name);
28035 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
2812128036 if (struct_type.fieldIsComptime(ip, field_index)) {
2812228037 try sema.resolveStructFieldInits(struct_ty);
2812328038 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
......@@ -28270,7 +28185,7 @@ fn unionFieldPtr(
2827028185
2827128186 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
2827228187 const msg = msg: {
28273 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
28188 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2827428189 errdefer msg.destroy(sema.gpa);
2827528190
2827628191 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
......@@ -28303,7 +28218,7 @@ fn unionFieldPtr(
2830328218 const msg = msg: {
2830428219 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
2830528220 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
28306 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
28221 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2830728222 field_name.fmt(ip),
2830828223 active_field_name.fmt(ip),
2830928224 });
......@@ -28371,7 +28286,7 @@ fn unionFieldVal(
2837128286 const msg = msg: {
2837228287 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
2837328288 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
28374 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
28289 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2837528290 field_name.fmt(ip), active_field_name.fmt(ip),
2837628291 });
2837728292 errdefer msg.destroy(sema.gpa);
......@@ -28594,15 +28509,13 @@ fn validateRuntimeElemAccess(
2859428509 if (try sema.typeRequiresComptime(elem_ty)) {
2859528510 const msg = msg: {
2859628511 const msg = try sema.errMsg(
28597 block,
2859828512 elem_index_src,
2859928513 "values of type '{}' must be comptime-known, but index value is runtime-known",
2860028514 .{parent_ty.fmt(mod)},
2860128515 );
2860228516 errdefer msg.destroy(sema.gpa);
2860328517
28604 const src_decl = mod.declPtr(block.src_decl);
28605 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty);
28518 try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty);
2860628519
2860728520 break :msg msg;
2860828521 };
......@@ -28990,21 +28903,18 @@ const CoerceOpts = struct {
2899028903 func_inst: Air.Inst.Ref = .none,
2899128904 param_i: u32 = undefined,
2899228905
28993 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {
28906 fn get(info: @This(), sema: *Sema) !?LazySrcLoc {
2899428907 if (info.func_inst == .none) return null;
28995 const mod = sema.mod;
28996 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;
28997 const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i);
28998 if (param_src == .node_offset_param) {
28999 return Module.SrcLoc{
29000 .file_scope = fn_decl.getFileScope(mod),
29001 .parent_decl_node = fn_decl.src_node,
29002 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
29003 };
29004 }
29005 return fn_decl.toSrcLoc(param_src, mod);
28908 const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null;
28909 return .{
28910 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
28911 .offset = .{ .fn_proto_param_type = .{
28912 .fn_proto_node_offset = 0,
28913 .param_index = info.param_i,
28914 } },
28915 };
2900628916 }
29007 } = .{},
28917 } = .{ .func_inst = .none, .param_i = undefined },
2900828918};
2900928919
2901028920fn coerceExtra(
......@@ -29097,7 +29007,7 @@ fn coerceExtra(
2909729007
2909829008 // Function body to function pointer.
2909929009 if (inst_ty.zigTypeTag(zcu) == .Fn) {
29100 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
29010 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2910129011 const fn_decl = fn_val.pointerDecl(zcu).?;
2910229012 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2910329013 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -29345,9 +29255,9 @@ fn coerceExtra(
2934529255 // pointer to tuple to slice
2934629256 if (!dest_info.flags.is_const) {
2934729257 const err_msg = err_msg: {
29348 const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});
29258 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});
2934929259 errdefer err_msg.destroy(sema.gpa);
29350 try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
29260 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2935129261 break :err_msg err_msg;
2935229262 };
2935329263 return sema.failWithOwnedErrorMsg(block, err_msg);
......@@ -29434,7 +29344,7 @@ fn coerceExtra(
2943429344 },
2943529345 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {
2943629346 .ComptimeFloat => {
29437 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
29347 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2943829348 const result_val = try val.floatCast(dest_ty, zcu);
2943929349 return Air.internedToRef(result_val.toIntern());
2944029350 },
......@@ -29493,7 +29403,7 @@ fn coerceExtra(
2949329403 .Enum => switch (inst_ty.zigTypeTag(zcu)) {
2949429404 .EnumLiteral => {
2949529405 // enum literal to enum
29496 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
29406 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2949729407 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;
2949829408 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
2949929409 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{
......@@ -29627,54 +29537,58 @@ fn coerceExtra(
2962729537
2962829538 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {
2962929539 const msg = msg: {
29630 const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{});
29540 const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{});
2963129541 errdefer msg.destroy(sema.gpa);
2963229542
29633 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29634 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);
29635 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{});
29543 const ret_ty_src: LazySrcLoc = .{
29544 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29545 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29546 };
29547 try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{});
2963629548 break :msg msg;
2963729549 };
2963829550 return sema.failWithOwnedErrorMsg(block, msg);
2963929551 }
2964029552
2964129553 const msg = msg: {
29642 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });
29554 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });
2964329555 errdefer msg.destroy(sema.gpa);
2964429556
2964529557 // E!T to T
2964629558 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and
2964729559 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
2964829560 {
29649 try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{});
29650 try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
29561 try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{});
29562 try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
2965129563 }
2965229564
2965329565 // ?T to T
2965429566 if (inst_ty.zigTypeTag(zcu) == .Optional and
2965529567 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
2965629568 {
29657 try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{});
29658 try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
29569 try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{});
29570 try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2965929571 }
2966029572
29661 try in_memory_result.report(sema, block, inst_src, msg);
29573 try in_memory_result.report(sema, inst_src, msg);
2966229574
2966329575 // Add notes about function return type
2966429576 if (opts.is_ret and
2966529577 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)
2966629578 {
29667 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29668 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);
29579 const ret_ty_src: LazySrcLoc = .{
29580 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29581 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29582 };
2966929583 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {
29670 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function cannot return an error", .{});
29584 try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{});
2967129585 } else {
29672 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function return type declared here", .{});
29586 try sema.errNote(ret_ty_src, msg, "function return type declared here", .{});
2967329587 }
2967429588 }
2967529589
2967629590 if (try opts.param_src.get(sema)) |param_src| {
29677 try zcu.errNoteNonLazy(param_src, msg, "parameter type declared here", .{});
29591 try sema.errNote(param_src, msg, "parameter type declared here", .{});
2967829592 }
2967929593
2968029594 // TODO maybe add "cannot store an error in type '{}'" note
......@@ -29809,7 +29723,7 @@ const InMemoryCoercionResult = union(enum) {
2980929723 return res;
2981029724 }
2981129725
29812 fn report(res: *const InMemoryCoercionResult, sema: *Sema, block: *Block, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
29726 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
2981329727 const mod = sema.mod;
2981429728 var cur = res;
2981529729 while (true) switch (cur.*) {
......@@ -29820,93 +29734,93 @@ const InMemoryCoercionResult = union(enum) {
2982029734 break;
2982129735 },
2982229736 .int_not_coercible => |int| {
29823 try sema.errNote(block, src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{
29737 try sema.errNote(src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{
2982429738 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,
2982529739 });
2982629740 break;
2982729741 },
2982829742 .error_union_payload => |pair| {
29829 try sema.errNote(block, src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{
29743 try sema.errNote(src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{
2983029744 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2983129745 });
2983229746 cur = pair.child;
2983329747 },
2983429748 .array_len => |lens| {
29835 try sema.errNote(block, src, msg, "array of length {d} cannot cast into an array of length {d}", .{
29749 try sema.errNote(src, msg, "array of length {d} cannot cast into an array of length {d}", .{
2983629750 lens.actual, lens.wanted,
2983729751 });
2983829752 break;
2983929753 },
2984029754 .array_sentinel => |sentinel| {
2984129755 if (sentinel.actual.toIntern() != .unreachable_value) {
29842 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
29756 try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
2984329757 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
2984429758 });
2984529759 } else {
29846 try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{
29760 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{
2984729761 sentinel.wanted.fmtValue(mod, sema),
2984829762 });
2984929763 }
2985029764 break;
2985129765 },
2985229766 .array_elem => |pair| {
29853 try sema.errNote(block, src, msg, "array element type '{}' cannot cast into array element type '{}'", .{
29767 try sema.errNote(src, msg, "array element type '{}' cannot cast into array element type '{}'", .{
2985429768 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2985529769 });
2985629770 cur = pair.child;
2985729771 },
2985829772 .vector_len => |lens| {
29859 try sema.errNote(block, src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{
29773 try sema.errNote(src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{
2986029774 lens.actual, lens.wanted,
2986129775 });
2986229776 break;
2986329777 },
2986429778 .vector_elem => |pair| {
29865 try sema.errNote(block, src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{
29779 try sema.errNote(src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{
2986629780 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2986729781 });
2986829782 cur = pair.child;
2986929783 },
2987029784 .optional_shape => |pair| {
29871 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29785 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
2987229786 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),
2987329787 });
2987429788 break;
2987529789 },
2987629790 .optional_child => |pair| {
29877 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29791 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
2987829792 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2987929793 });
2988029794 cur = pair.child;
2988129795 },
2988229796 .from_anyerror => {
29883 try sema.errNote(block, src, msg, "global error set cannot cast into a smaller set", .{});
29797 try sema.errNote(src, msg, "global error set cannot cast into a smaller set", .{});
2988429798 break;
2988529799 },
2988629800 .missing_error => |missing_errors| {
2988729801 for (missing_errors) |err| {
29888 try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
29802 try sema.errNote(src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
2988929803 }
2989029804 break;
2989129805 },
2989229806 .fn_var_args => |wanted_var_args| {
2989329807 if (wanted_var_args) {
29894 try sema.errNote(block, src, msg, "non-variadic function cannot cast into a variadic function", .{});
29808 try sema.errNote(src, msg, "non-variadic function cannot cast into a variadic function", .{});
2989529809 } else {
29896 try sema.errNote(block, src, msg, "variadic function cannot cast into a non-variadic function", .{});
29810 try sema.errNote(src, msg, "variadic function cannot cast into a non-variadic function", .{});
2989729811 }
2989829812 break;
2989929813 },
2990029814 .fn_generic => |wanted_generic| {
2990129815 if (wanted_generic) {
29902 try sema.errNote(block, src, msg, "non-generic function cannot cast into a generic function", .{});
29816 try sema.errNote(src, msg, "non-generic function cannot cast into a generic function", .{});
2990329817 } else {
29904 try sema.errNote(block, src, msg, "generic function cannot cast into a non-generic function", .{});
29818 try sema.errNote(src, msg, "generic function cannot cast into a non-generic function", .{});
2990529819 }
2990629820 break;
2990729821 },
2990829822 .fn_param_count => |lens| {
29909 try sema.errNote(block, src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{
29823 try sema.errNote(src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{
2991029824 lens.actual, lens.wanted,
2991129825 });
2991229826 break;
......@@ -29923,69 +29837,69 @@ const InMemoryCoercionResult = union(enum) {
2992329837 }
2992429838 }
2992529839 if (!actual_noalias) {
29926 try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});
29840 try sema.errNote(src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});
2992729841 } else {
29928 try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});
29842 try sema.errNote(src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});
2992929843 }
2993029844 break;
2993129845 },
2993229846 .fn_param_comptime => |param| {
2993329847 if (param.wanted) {
29934 try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});
29848 try sema.errNote(src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});
2993529849 } else {
29936 try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});
29850 try sema.errNote(src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});
2993729851 }
2993829852 break;
2993929853 },
2994029854 .fn_param => |param| {
29941 try sema.errNote(block, src, msg, "parameter {d} '{}' cannot cast into '{}'", .{
29855 try sema.errNote(src, msg, "parameter {d} '{}' cannot cast into '{}'", .{
2994229856 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),
2994329857 });
2994429858 cur = param.child;
2994529859 },
2994629860 .fn_cc => |cc| {
29947 try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
29861 try sema.errNote(src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
2994829862 break;
2994929863 },
2995029864 .fn_return_type => |pair| {
29951 try sema.errNote(block, src, msg, "return type '{}' cannot cast into return type '{}'", .{
29865 try sema.errNote(src, msg, "return type '{}' cannot cast into return type '{}'", .{
2995229866 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2995329867 });
2995429868 cur = pair.child;
2995529869 },
2995629870 .ptr_child => |pair| {
29957 try sema.errNote(block, src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{
29871 try sema.errNote(src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{
2995829872 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2995929873 });
2996029874 cur = pair.child;
2996129875 },
2996229876 .ptr_addrspace => |@"addrspace"| {
29963 try sema.errNote(block, src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });
29877 try sema.errNote(src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });
2996429878 break;
2996529879 },
2996629880 .ptr_sentinel => |sentinel| {
2996729881 if (sentinel.actual.toIntern() != .unreachable_value) {
29968 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
29882 try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
2996929883 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
2997029884 });
2997129885 } else {
29972 try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{
29886 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{
2997329887 sentinel.wanted.fmtValue(mod, sema),
2997429888 });
2997529889 }
2997629890 break;
2997729891 },
2997829892 .ptr_size => |size| {
29979 try sema.errNote(block, src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });
29893 try sema.errNote(src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });
2998029894 break;
2998129895 },
2998229896 .ptr_qualifiers => |qualifiers| {
2998329897 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;
2998429898 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;
2998529899 if (!ok_const) {
29986 try sema.errNote(block, src, msg, "cast discards const qualifier", .{});
29900 try sema.errNote(src, msg, "cast discards const qualifier", .{});
2998729901 } else if (!ok_volatile) {
29988 try sema.errNote(block, src, msg, "cast discards volatile qualifier", .{});
29902 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
2998929903 }
2999029904 break;
2999129905 },
......@@ -29993,11 +29907,11 @@ const InMemoryCoercionResult = union(enum) {
2999329907 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);
2999429908 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);
2999529909 if (actual_allow_zero and !wanted_allow_zero) {
29996 try sema.errNote(block, src, msg, "'{}' could have null values which are illegal in type '{}'", .{
29910 try sema.errNote(src, msg, "'{}' could have null values which are illegal in type '{}'", .{
2999729911 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2999829912 });
2999929913 } else {
30000 try sema.errNote(block, src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{
29914 try sema.errNote(src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{
3000129915 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3000229916 });
3000329917 }
......@@ -30005,34 +29919,34 @@ const InMemoryCoercionResult = union(enum) {
3000529919 },
3000629920 .ptr_bit_range => |bit_range| {
3000729921 if (bit_range.actual_host != bit_range.wanted_host) {
30008 try sema.errNote(block, src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{
29922 try sema.errNote(src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{
3000929923 bit_range.actual_host, bit_range.wanted_host,
3001029924 });
3001129925 }
3001229926 if (bit_range.actual_offset != bit_range.wanted_offset) {
30013 try sema.errNote(block, src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{
29927 try sema.errNote(src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{
3001429928 bit_range.actual_offset, bit_range.wanted_offset,
3001529929 });
3001629930 }
3001729931 break;
3001829932 },
3001929933 .ptr_alignment => |pair| {
30020 try sema.errNote(block, src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{
29934 try sema.errNote(src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{
3002129935 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,
3002229936 });
3002329937 break;
3002429938 },
3002529939 .double_ptr_to_anyopaque => |pair| {
30026 try sema.errNote(block, src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{
29940 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{
3002729941 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3002829942 });
3002929943 break;
3003029944 },
3003129945 .slice_to_anyopaque => |pair| {
30032 try sema.errNote(block, src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{
29946 try sema.errNote(src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{
3003329947 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3003429948 });
30035 try sema.errNote(block, src, msg, "consider using '.ptr'", .{});
29949 try sema.errNote(src, msg, "consider using '.ptr'", .{});
3003629950 break;
3003729951 },
3003829952 };
......@@ -30646,7 +30560,7 @@ fn coerceVarArgParam(
3064630560 .{},
3064730561 ),
3064830562 .Fn => fn_ptr: {
30649 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
30563 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
3065030564 const fn_decl = fn_val.pointerDecl(mod).?;
3065130565 break :fn_ptr try sema.analyzeDeclRef(fn_decl);
3065230566 },
......@@ -30694,11 +30608,10 @@ fn coerceVarArgParam(
3069430608 const coerced_ty = sema.typeOf(coerced);
3069530609 if (!try sema.validateExternType(coerced_ty, .param_ty)) {
3069630610 const msg = msg: {
30697 const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
30611 const msg = try sema.errMsg(inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
3069830612 errdefer msg.destroy(sema.gpa);
3069930613
30700 const src_decl = sema.mod.declPtr(block.src_decl);
30701 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty);
30614 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
3070230615
3070330616 try sema.addDeclaredHereNote(msg, coerced_ty);
3070430617 break :msg msg;
......@@ -30858,7 +30771,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
3085830771 {
3085930772 try maybe_comptime_alloc.stores.append(sema.arena, .{
3086030773 .inst = store_inst,
30861 .src_decl = block.src_decl,
3086230774 .src = store_src,
3086330775 });
3086430776 return;
......@@ -30892,8 +30804,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt
3089230804
3089330805 try maybe_comptime_alloc.stores.append(sema.arena, .{
3089430806 .inst = new_ptr_inst,
30895 .src_decl = block.src_decl,
30896 .src = .unneeded,
30807 .src = LazySrcLoc.unneeded,
3089730808 });
3089830809 },
3089930810 .ptr_elem_ptr => {
......@@ -30916,10 +30827,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3091630827 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;
3091730828 // Since the alloc has been determined to be runtime, we must check that
3091830829 // all other stores to it are permitted to be runtime values.
30919 const mod = sema.mod;
3092030830 const slice = maybe_comptime_alloc.stores.slice();
30921 for (slice.items(.inst), slice.items(.src_decl), slice.items(.src)) |other_inst, other_src_decl, other_src| {
30922 if (other_src == .unneeded) {
30831 for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| {
30832 if (other_src.offset == .unneeded) {
3092330833 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {
3092430834 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,
3092530835 else => unreachable, // assertion failure
......@@ -30929,10 +30839,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3092930839 const other_operand = other_data.rhs;
3093030840 if (!sema.checkRuntimeValue(other_operand)) {
3093130841 return sema.failWithOwnedErrorMsg(block, msg: {
30932 const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod);
30933 const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{});
30842 const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{});
3093430843 errdefer msg.destroy(sema.gpa);
30935 try mod.errNoteNonLazy(other_src_resolved, msg, "comptime var pointers are not available at runtime", .{});
30844 try sema.errNote(other_src, msg, "comptime var pointers are not available at runtime", .{});
3093630845 break :msg msg;
3093730846 });
3093830847 }
......@@ -31194,11 +31103,11 @@ fn coerceEnumToUnion(
3119431103
3119531104 const tag_ty = union_ty.unionTagType(mod) orelse {
3119631105 const msg = msg: {
31197 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31106 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3119831107 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
3119931108 });
3120031109 errdefer msg.destroy(sema.gpa);
31201 try sema.errNote(block, union_ty_src, msg, "cannot coerce enum to untagged union", .{});
31110 try sema.errNote(union_ty_src, msg, "cannot coerce enum to untagged union", .{});
3120231111 try sema.addDeclaredHereNote(msg, union_ty);
3120331112 break :msg msg;
3120431113 };
......@@ -31218,7 +31127,7 @@ fn coerceEnumToUnion(
3121831127 try sema.resolveTypeFields(field_ty);
3121931128 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3122031129 const msg = msg: {
31221 const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{});
31130 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
3122231131 errdefer msg.destroy(sema.gpa);
3122331132
3122431133 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
......@@ -31233,7 +31142,7 @@ fn coerceEnumToUnion(
3123331142 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
3123431143 const msg = msg: {
3123531144 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
31236 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
31145 const msg = try sema.errMsg(inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
3123731146 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),
3123831147 field_ty.fmt(sema.mod), field_name.fmt(ip),
3123931148 });
......@@ -31255,7 +31164,7 @@ fn coerceEnumToUnion(
3125531164
3125631165 if (tag_ty.isNonexhaustiveEnum(mod)) {
3125731166 const msg = msg: {
31258 const msg = try sema.errMsg(block, inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
31167 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
3125931168 union_ty.fmt(sema.mod),
3126031169 });
3126131170 errdefer msg.destroy(sema.gpa);
......@@ -31273,7 +31182,6 @@ fn coerceEnumToUnion(
3127331182 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
3127431183 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
3127531184 const err_msg = msg orelse try sema.errMsg(
31276 block,
3127731185 inst_src,
3127831186 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
3127931187 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
......@@ -31297,7 +31205,6 @@ fn coerceEnumToUnion(
3129731205
3129831206 const msg = msg: {
3129931207 const msg = try sema.errMsg(
31300 block,
3130131208 inst_src,
3130231209 "runtime coercion from enum '{}' to union '{}' which has non-void fields",
3130331210 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
......@@ -31356,12 +31263,10 @@ fn coerceAnonStructToUnion(
3135631263 assert(field_count != 1);
3135731264 const msg = msg: {
3135831265 const msg = if (field_count > 1) try sema.errMsg(
31359 block,
3136031266 inst_src,
3136131267 "cannot initialize multiple union fields at once; unions can only have one active field",
3136231268 .{},
3136331269 ) else try sema.errMsg(
31364 block,
3136531270 inst_src,
3136631271 "union initializer must initialize one field",
3136731272 .{},
......@@ -31438,12 +31343,12 @@ fn coerceArrayLike(
3143831343 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
3143931344 if (dest_len != inst_len) {
3144031345 const msg = msg: {
31441 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31346 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3144231347 dest_ty.fmt(mod), inst_ty.fmt(mod),
3144331348 });
3144431349 errdefer msg.destroy(sema.gpa);
31445 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});
31446 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
31350 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31351 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
3144731352 break :msg msg;
3144831353 };
3144931354 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -31525,12 +31430,12 @@ fn coerceTupleToArray(
3152531430
3152631431 if (dest_len != inst_len) {
3152731432 const msg = msg: {
31528 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31433 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3152931434 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
3153031435 });
3153131436 errdefer msg.destroy(sema.gpa);
31532 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});
31533 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
31437 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31438 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
3153431439 break :msg msg;
3153531440 };
3153631441 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -31701,9 +31606,9 @@ fn coerceTupleToStruct(
3170131606 const template = "missing struct field: {}";
3170231607 const args = .{field_name.fmt(ip)};
3170331608 if (root_msg) |msg| {
31704 try sema.errNote(block, field_src, msg, template, args);
31609 try sema.errNote(field_src, msg, template, args);
3170531610 } else {
31706 root_msg = try sema.errMsg(block, field_src, template, args);
31611 root_msg = try sema.errMsg(field_src, template, args);
3170731612 }
3170831613 continue;
3170931614 }
......@@ -31839,18 +31744,18 @@ fn coerceTupleToTuple(
3183931744 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
3184031745 const template = "missing tuple field: {d}";
3184131746 if (root_msg) |msg| {
31842 try sema.errNote(block, field_src, msg, template, .{i});
31747 try sema.errNote(field_src, msg, template, .{i});
3184331748 } else {
31844 root_msg = try sema.errMsg(block, field_src, template, .{i});
31749 root_msg = try sema.errMsg(field_src, template, .{i});
3184531750 }
3184631751 continue;
3184731752 };
3184831753 const template = "missing struct field: {}";
3184931754 const args = .{field_name.fmt(ip)};
3185031755 if (root_msg) |msg| {
31851 try sema.errNote(block, field_src, msg, template, args);
31756 try sema.errNote(field_src, msg, template, args);
3185231757 } else {
31853 root_msg = try sema.errMsg(block, field_src, template, args);
31758 root_msg = try sema.errMsg(field_src, template, args);
3185431759 }
3185531760 continue;
3185631761 }
......@@ -31884,7 +31789,7 @@ fn analyzeDeclVal(
3188431789 src: LazySrcLoc,
3188531790 decl_index: InternPool.DeclIndex,
3188631791) CompileError!Air.Inst.Ref {
31887 try sema.addReferencedBy(block, src, decl_index);
31792 try sema.addReferencedBy(src, decl_index);
3188831793 if (sema.decl_val_table.get(decl_index)) |result| {
3188931794 return result;
3189031795 }
......@@ -31900,21 +31805,14 @@ fn analyzeDeclVal(
3190031805
3190131806fn addReferencedBy(
3190231807 sema: *Sema,
31903 block: *Block,
3190431808 src: LazySrcLoc,
3190531809 decl_index: InternPool.DeclIndex,
3190631810) !void {
3190731811 if (sema.mod.comp.reference_trace == 0) return;
31908 if (src == .unneeded) {
31909 // We can't use NeededSourceLocation, since sites handling that assume it means a compile
31910 // error. Our long-term strategy here is to gradually transition from NeededSourceLocation
31911 // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this
31912 // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in
31913 // debug so we can fix this case.
31914 if (std.debug.runtime_safety) unreachable else return;
31915 }
3191631812 try sema.mod.reference_table.put(sema.gpa, decl_index, .{
31917 .referencer = block.src_decl,
31813 // TODO: this can make the reference trace suboptimal. This will be fixed
31814 // once the reference table is reworked for incremental compilation.
31815 .referencer = sema.owner_decl_index,
3191831816 .src = src,
3191931817 });
3192031818}
......@@ -31924,7 +31822,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
3192431822 const ip = &mod.intern_pool;
3192531823 const decl = mod.declPtr(decl_index);
3192631824 if (decl.analysis == .in_progress) {
31927 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{});
31825 const msg = try sema.errMsg(.{
31826 .base_node_inst = decl.zir_decl_index.unwrap().?,
31827 .offset = LazySrcLoc.Offset.nodeOffset(0),
31828 }, "dependency loop detected", .{});
3192831829 return sema.failWithOwnedErrorMsg(null, msg);
3192931830 }
3193031831
......@@ -32419,10 +32320,9 @@ fn analyzeSlice(
3241932320 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
3242032321 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
3242132322 const msg = msg: {
32422 const msg = try sema.errMsg(block, start_src, bounds_error_message, .{});
32323 const msg = try sema.errMsg(start_src, bounds_error_message, .{});
3242332324 errdefer msg.destroy(sema.gpa);
3242432325 try sema.errNote(
32425 block,
3242632326 start_src,
3242732327 msg,
3242832328 "expected '{}', found '{}'",
......@@ -32436,10 +32336,9 @@ fn analyzeSlice(
3243632336 return sema.failWithOwnedErrorMsg(block, msg);
3243732337 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
3243832338 const msg = msg: {
32439 const msg = try sema.errMsg(block, end_src, bounds_error_message, .{});
32339 const msg = try sema.errMsg(end_src, bounds_error_message, .{});
3244032340 errdefer msg.destroy(sema.gpa);
3244132341 try sema.errNote(
32442 block,
3244332342 end_src,
3244432343 msg,
3244532344 "expected '{}', found '{}'",
......@@ -32693,9 +32592,9 @@ fn analyzeSlice(
3269332592
3269432593 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
3269532594 const msg = msg: {
32696 const msg = try sema.errMsg(block, src, "value in memory does not match slice sentinel", .{});
32595 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3269732596 errdefer msg.destroy(sema.gpa);
32698 try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{
32597 try sema.errNote(src, msg, "expected '{}', found '{}'", .{
3269932598 expected_sentinel.fmtValue(mod, sema),
3270032599 actual_sentinel.fmtValue(mod, sema),
3270132600 });
......@@ -33567,6 +33466,31 @@ const PeerResolveStrategy = enum {
3356733466 }
3356833467};
3356933468
33469const PeerTypeCandidateSrc = union(enum) {
33470 /// Do not print out error notes for candidate sources
33471 none: void,
33472 /// When we want to know the the src of candidate i, look up at
33473 /// index i in this slice
33474 override: []const ?LazySrcLoc,
33475 /// resolvePeerTypes originates from a @TypeOf(...) call
33476 typeof_builtin_call_node_offset: i32,
33477
33478 pub fn resolve(
33479 self: PeerTypeCandidateSrc,
33480 block: *Block,
33481 candidate_i: usize,
33482 ) ?LazySrcLoc {
33483 return switch (self) {
33484 .none => null,
33485 .override => |candidate_srcs| if (candidate_i >= candidate_srcs.len)
33486 null
33487 else
33488 candidate_srcs[candidate_i],
33489 .typeof_builtin_call_node_offset => |node_offset| block.builtinCallArgSrc(node_offset, @intCast(candidate_i)),
33490 };
33491 }
33492};
33493
3357033494const PeerResolveResult = union(enum) {
3357133495 /// The peer type resolution was successful, and resulted in the given type.
3357233496 success: Type,
......@@ -33591,10 +33515,9 @@ const PeerResolveResult = union(enum) {
3359133515 block: *Block,
3359233516 src: LazySrcLoc,
3359333517 instructions: []const Air.Inst.Ref,
33594 candidate_srcs: Module.PeerTypeCandidateSrc,
33518 candidate_srcs: PeerTypeCandidateSrc,
3359533519 ) !*Module.ErrorMsg {
3359633520 const mod = sema.mod;
33597 const decl_ptr = mod.declPtr(block.src_decl);
3359833521
3359933522 var opt_msg: ?*Module.ErrorMsg = null;
3360033523 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
......@@ -33622,9 +33545,9 @@ const PeerResolveResult = union(enum) {
3362233545 const fmt = "struct field '{}' has conflicting types";
3362333546 const args = .{field_error.field_name.fmt(&mod.intern_pool)};
3362433547 if (opt_msg) |msg| {
33625 try sema.errNote(block, src, msg, fmt, args);
33548 try sema.errNote(src, msg, fmt, args);
3362633549 } else {
33627 opt_msg = try sema.errMsg(block, src, fmt, args);
33550 opt_msg = try sema.errMsg(src, fmt, args);
3362833551 }
3362933552
3363033553 // Continue on to child error
......@@ -33646,8 +33569,8 @@ const PeerResolveResult = union(enum) {
3364633569 peer_tys[conflict_idx[1]],
3364733570 };
3364833571 const conflict_srcs: [2]?LazySrcLoc = .{
33649 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]),
33650 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]),
33572 candidate_srcs.resolve(block, conflict_idx[0]),
33573 candidate_srcs.resolve(block, conflict_idx[1]),
3365133574 };
3365233575
3365333576 const fmt = "incompatible types: '{}' and '{}'";
......@@ -33656,16 +33579,16 @@ const PeerResolveResult = union(enum) {
3365633579 conflict_tys[1].fmt(mod),
3365733580 };
3365833581 const msg = if (opt_msg) |msg| msg: {
33659 try sema.errNote(block, src, msg, fmt, args);
33582 try sema.errNote(src, msg, fmt, args);
3366033583 break :msg msg;
3366133584 } else msg: {
33662 const msg = try sema.errMsg(block, src, fmt, args);
33585 const msg = try sema.errMsg(src, fmt, args);
3366333586 opt_msg = msg;
3366433587 break :msg msg;
3366533588 };
3366633589
33667 if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});
33668 if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
33590 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});
33591 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
3366933592
3367033593 // No child error
3367133594 break;
......@@ -33680,7 +33603,7 @@ fn resolvePeerTypes(
3368033603 block: *Block,
3368133604 src: LazySrcLoc,
3368233605 instructions: []const Air.Inst.Ref,
33683 candidate_srcs: Module.PeerTypeCandidateSrc,
33606 candidate_srcs: PeerTypeCandidateSrc,
3368433607) !Type {
3368533608 switch (instructions.len) {
3368633609 0 => return Type.noreturn,
......@@ -35119,9 +35042,9 @@ pub fn resolveStructAlignment(
3511935042}
3512035043
3512135044fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35122 const mod = sema.mod;
35123 const ip = &mod.intern_pool;
35124 const struct_type = mod.typeToStruct(ty) orelse return;
35045 const zcu = sema.mod;
35046 const ip = &zcu.intern_pool;
35047 const struct_type = zcu.typeToStruct(ty) orelse return;
3512535048
3512635049 if (struct_type.haveLayout(ip))
3512735050 return;
......@@ -35129,16 +35052,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3512935052 try sema.resolveTypeFields(ty);
3513035053
3513135054 if (struct_type.layout == .@"packed") {
35132 try semaBackingIntType(mod, struct_type);
35055 try semaBackingIntType(zcu, struct_type);
3513335056 return;
3513435057 }
3513535058
3513635059 if (struct_type.setLayoutWip(ip)) {
35137 const msg = try Module.ErrorMsg.create(
35138 sema.gpa,
35139 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35060 const msg = try sema.errMsg(
35061 ty.srcLoc(zcu),
3514035062 "struct '{}' depends on itself",
35141 .{ty.fmt(mod)},
35063 .{ty.fmt(zcu)},
3514235064 );
3514335065 return sema.failWithOwnedErrorMsg(null, msg);
3514435066 }
......@@ -35175,9 +35097,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3517535097 }
3517635098
3517735099 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35178 const msg = try Module.ErrorMsg.create(
35179 sema.gpa,
35180 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35100 const msg = try sema.errMsg(
35101 ty.srcLoc(zcu),
3518135102 "struct layout depends on it having runtime bits",
3518235103 .{},
3518335104 );
......@@ -35185,11 +35106,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3518535106 }
3518635107
3518735108 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and
35188 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))
35109 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3518935110 {
35190 const msg = try Module.ErrorMsg.create(
35191 sema.gpa,
35192 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35111 const msg = try sema.errMsg(
35112 ty.srcLoc(zcu),
3519335113 "struct layout depends on being pointer aligned",
3519435114 .{},
3519535115 );
......@@ -35221,7 +35141,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3522135141 return a_align.compare(.gt, b_align);
3522235142 }
3522335143 };
35224 if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) {
35144 if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) {
3522535145 // TODO: don't handle tuples differently. This logic exists only because it
3522635146 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!
3522735147 // Likewise, implement field reordering support in all the backends!
......@@ -35272,7 +35192,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3527235192 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3527335193 defer analysis_arena.deinit();
3527435194
35275 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
35195 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3527635196 defer comptime_err_ret_trace.deinit();
3527735197
3527835198 var sema: Sema = .{
......@@ -35294,11 +35214,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3529435214 var block: Block = .{
3529535215 .parent = null,
3529635216 .sema = &sema,
35297 .src_decl = decl_index,
3529835217 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,
3529935218 .instructions = .{},
3530035219 .inlining = null,
3530135220 .is_comptime = true,
35221 .src_base_inst = struct_type.zir_index.unwrap().?,
35222 .type_name_ctx = decl.name,
3530235223 };
3530335224 defer assert(block.instructions.items.len == 0);
3530435225
......@@ -35331,7 +35252,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3533135252 const backing_int_body_len = zir.extra[extra_index];
3533235253 extra_index += 1;
3533335254
35334 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
35255 const backing_int_src: LazySrcLoc = .{
35256 .base_node_inst = struct_type.zir_index.unwrap().?,
35257 .offset = .{ .node_offset_container_tag = 0 },
35258 };
3533535259 const backing_int_ty = blk: {
3533635260 if (backing_int_body_len == 0) {
3533735261 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
......@@ -35347,7 +35271,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3534735271 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
3534835272 } else {
3534935273 if (fields_bit_sum > std.math.maxInt(u16)) {
35350 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
35274 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3535135275 }
3535235276 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
3535335277 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
......@@ -35374,9 +35298,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3537435298 const mod = sema.mod;
3537535299 if (!ty.isIndexable(mod)) {
3537635300 const msg = msg: {
35377 const msg = try sema.errMsg(block, src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});
35301 const msg = try sema.errMsg(src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});
3537835302 errdefer msg.destroy(sema.gpa);
35379 try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{});
35303 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
3538035304 break :msg msg;
3538135305 };
3538235306 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -35397,9 +35321,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
3539735321 }
3539835322 }
3539935323 const msg = msg: {
35400 const msg = try sema.errMsg(block, src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});
35324 const msg = try sema.errMsg(src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});
3540135325 errdefer msg.destroy(sema.gpa);
35402 try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
35326 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
3540335327 break :msg msg;
3540435328 };
3540535329 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -35450,8 +35374,8 @@ pub fn resolveUnionAlignment(
3545035374
3545135375/// This logic must be kept in sync with `Module.getUnionLayout`.
3545235376fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35453 const mod = sema.mod;
35454 const ip = &mod.intern_pool;
35377 const zcu = sema.mod;
35378 const ip = &zcu.intern_pool;
3545535379
3545635380 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));
3545735381
......@@ -35461,11 +35385,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3546135385 switch (union_type.flagsPtr(ip).status) {
3546235386 .none, .have_field_types => {},
3546335387 .field_types_wip, .layout_wip => {
35464 const msg = try Module.ErrorMsg.create(
35465 sema.gpa,
35466 mod.declPtr(union_type.decl).srcLoc(mod),
35388 const msg = try sema.errMsg(
35389 ty.srcLoc(zcu),
3546735390 "union '{}' depends on itself",
35468 .{ty.fmt(mod)},
35391 .{ty.fmt(zcu)},
3546935392 );
3547035393 return sema.failWithOwnedErrorMsg(null, msg);
3547135394 },
......@@ -35484,7 +35407,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3548435407 for (0..union_type.field_types.len) |field_index| {
3548535408 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
3548635409
35487 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(mod) == .NoReturn) continue; // TODO: should this affect alignment?
35410 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(zcu) == .NoReturn) continue; // TODO: should this affect alignment?
3548835411
3548935412 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
3549035413 error.AnalysisFail => {
......@@ -35526,7 +35449,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3552635449 } else {
3552735450 // {Payload, Tag}
3552835451 size += max_size;
35529 size = switch (mod.getTarget().ofmt) {
35452 size = switch (zcu.getTarget().ofmt) {
3553035453 .c => max_align,
3553135454 else => tag_align,
3553235455 }.forward(size);
......@@ -35545,9 +35468,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3554535468 flags.status = .have_layout;
3554635469
3554735470 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35548 const msg = try Module.ErrorMsg.create(
35549 sema.gpa,
35550 mod.declPtr(union_type.decl).srcLoc(mod),
35471 const msg = try sema.errMsg(
35472 ty.srcLoc(zcu),
3555135473 "union layout depends on it having runtime bits",
3555235474 .{},
3555335475 );
......@@ -35555,11 +35477,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3555535477 }
3555635478
3555735479 if (union_type.flagsPtr(ip).assumed_pointer_aligned and
35558 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))
35480 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3555935481 {
35560 const msg = try Module.ErrorMsg.create(
35561 sema.gpa,
35562 mod.declPtr(union_type.decl).srcLoc(mod),
35482 const msg = try sema.errMsg(
35483 ty.srcLoc(zcu),
3556335484 "union layout depends on being pointer aligned",
3556435485 .{},
3556535486 );
......@@ -35783,12 +35704,12 @@ pub fn resolveTypeFieldsStruct(
3578335704 ty: InternPool.Index,
3578435705 struct_type: InternPool.LoadedStructType,
3578535706) CompileError!void {
35786 const mod = sema.mod;
35787 const ip = &mod.intern_pool;
35707 const zcu = sema.mod;
35708 const ip = &zcu.intern_pool;
3578835709 // If there is no owner decl it means the struct has no fields.
3578935710 const owner_decl = struct_type.decl.unwrap() orelse return;
3579035711
35791 switch (mod.declPtr(owner_decl).analysis) {
35712 switch (zcu.declPtr(owner_decl).analysis) {
3579235713 .file_failure,
3579335714 .dependency_failure,
3579435715 .sema_failure,
......@@ -35802,20 +35723,19 @@ pub fn resolveTypeFieldsStruct(
3580235723 if (struct_type.haveFieldTypes(ip)) return;
3580335724
3580435725 if (struct_type.setTypesWip(ip)) {
35805 const msg = try Module.ErrorMsg.create(
35806 sema.gpa,
35807 mod.declPtr(owner_decl).srcLoc(mod),
35726 const msg = try sema.errMsg(
35727 Type.fromInterned(ty).srcLoc(zcu),
3580835728 "struct '{}' depends on itself",
35809 .{Type.fromInterned(ty).fmt(mod)},
35729 .{Type.fromInterned(ty).fmt(zcu)},
3581035730 );
3581135731 return sema.failWithOwnedErrorMsg(null, msg);
3581235732 }
3581335733 defer struct_type.clearTypesWip(ip);
3581435734
35815 semaStructFields(mod, sema.arena, struct_type) catch |err| switch (err) {
35735 semaStructFields(zcu, sema.arena, struct_type) catch |err| switch (err) {
3581635736 error.AnalysisFail => {
35817 if (mod.declPtr(owner_decl).analysis == .complete) {
35818 mod.declPtr(owner_decl).analysis = .dependency_failure;
35737 if (zcu.declPtr(owner_decl).analysis == .complete) {
35738 zcu.declPtr(owner_decl).analysis = .dependency_failure;
3581935739 }
3582035740 return error.AnalysisFail;
3582135741 },
......@@ -35824,9 +35744,9 @@ pub fn resolveTypeFieldsStruct(
3582435744}
3582535745
3582635746pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35827 const mod = sema.mod;
35828 const ip = &mod.intern_pool;
35829 const struct_type = mod.typeToStruct(ty) orelse return;
35747 const zcu = sema.mod;
35748 const ip = &zcu.intern_pool;
35749 const struct_type = zcu.typeToStruct(ty) orelse return;
3583035750 const owner_decl = struct_type.decl.unwrap() orelse return;
3583135751
3583235752 // Inits can start as resolved
......@@ -35835,20 +35755,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
3583535755 try sema.resolveStructLayout(ty);
3583635756
3583735757 if (struct_type.setInitsWip(ip)) {
35838 const msg = try Module.ErrorMsg.create(
35839 sema.gpa,
35840 mod.declPtr(owner_decl).srcLoc(mod),
35758 const msg = try sema.errMsg(
35759 ty.srcLoc(zcu),
3584135760 "struct '{}' depends on itself",
35842 .{ty.fmt(mod)},
35761 .{ty.fmt(zcu)},
3584335762 );
3584435763 return sema.failWithOwnedErrorMsg(null, msg);
3584535764 }
3584635765 defer struct_type.clearInitsWip(ip);
3584735766
35848 semaStructFieldInits(mod, sema.arena, struct_type) catch |err| switch (err) {
35767 semaStructFieldInits(zcu, sema.arena, struct_type) catch |err| switch (err) {
3584935768 error.AnalysisFail => {
35850 if (mod.declPtr(owner_decl).analysis == .complete) {
35851 mod.declPtr(owner_decl).analysis = .dependency_failure;
35769 if (zcu.declPtr(owner_decl).analysis == .complete) {
35770 zcu.declPtr(owner_decl).analysis = .dependency_failure;
3585235771 }
3585335772 return error.AnalysisFail;
3585435773 },
......@@ -35858,9 +35777,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
3585835777}
3585935778
3586035779pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {
35861 const mod = sema.mod;
35862 const ip = &mod.intern_pool;
35863 const owner_decl = mod.declPtr(union_type.decl);
35780 const zcu = sema.mod;
35781 const ip = &zcu.intern_pool;
35782 const owner_decl = zcu.declPtr(union_type.decl);
3586435783 switch (owner_decl.analysis) {
3586535784 .file_failure,
3586635785 .dependency_failure,
......@@ -35874,11 +35793,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3587435793 switch (union_type.flagsPtr(ip).status) {
3587535794 .none => {},
3587635795 .field_types_wip => {
35877 const msg = try Module.ErrorMsg.create(
35878 sema.gpa,
35879 owner_decl.srcLoc(mod),
35796 const msg = try sema.errMsg(
35797 ty.srcLoc(zcu),
3588035798 "union '{}' depends on itself",
35881 .{ty.fmt(mod)},
35799 .{ty.fmt(zcu)},
3588235800 );
3588335801 return sema.failWithOwnedErrorMsg(null, msg);
3588435802 },
......@@ -35892,7 +35810,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589235810
3589335811 union_type.flagsPtr(ip).status = .field_types_wip;
3589435812 errdefer union_type.flagsPtr(ip).status = .none;
35895 semaUnionFields(mod, sema.arena, union_type) catch |err| switch (err) {
35813 semaUnionFields(zcu, sema.arena, union_type) catch |err| switch (err) {
3589635814 error.AnalysisFail => {
3589735815 if (owner_decl.analysis == .complete) {
3589835816 owner_decl.analysis = .dependency_failure;
......@@ -35942,10 +35860,13 @@ fn resolveInferredErrorSet(
3594235860 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {
3594335861 if (ies_func_info.is_generic) {
3594435862 const msg = msg: {
35945 const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});
35863 const msg = try sema.errMsg(src, "unable to resolve inferred error set of generic function", .{});
3594635864 errdefer msg.destroy(sema.gpa);
3594735865
35948 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{});
35866 try sema.errNote(.{
35867 .base_node_inst = ies_func_owner_decl.zir_decl_index.unwrap().?,
35868 .offset = LazySrcLoc.Offset.nodeOffset(0),
35869 }, msg, "generic function declared here", .{});
3594935870 break :msg msg;
3595035871 };
3595135872 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -36126,7 +36047,7 @@ fn semaStructFields(
3612636047 },
3612736048 };
3612836049
36129 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36050 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3613036051 defer comptime_err_ret_trace.deinit();
3613136052
3613236053 var sema: Sema = .{
......@@ -36148,11 +36069,12 @@ fn semaStructFields(
3614836069 var block_scope: Block = .{
3614936070 .parent = null,
3615036071 .sema = &sema,
36151 .src_decl = decl_index,
3615236072 .namespace = namespace_index,
3615336073 .instructions = .{},
3615436074 .inlining = null,
3615536075 .is_comptime = true,
36076 .src_base_inst = struct_type.zir_index.unwrap().?,
36077 .type_name_ctx = decl.name,
3615636078 };
3615736079 defer assert(block_scope.instructions.items.len == 0);
3615836080
......@@ -36231,35 +36153,19 @@ fn semaStructFields(
3623136153 // so that init values may depend on type layout.
3623236154
3623336155 for (fields, 0..) |zir_field, field_i| {
36156 const ty_src: LazySrcLoc = .{
36157 .base_node_inst = struct_type.zir_index.unwrap().?,
36158 .offset = .{ .container_field_type = @intCast(field_i) },
36159 };
3623436160 const field_ty: Type = ty: {
3623536161 if (zir_field.type_ref != .none) {
36236 break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) {
36237 error.NeededSourceLocation => {
36238 const ty_src = mod.fieldSrcLoc(decl_index, .{
36239 .index = field_i,
36240 .range = .type,
36241 }).lazy;
36242 _ = try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
36243 unreachable;
36244 },
36245 else => |e| return e,
36246 };
36162 break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
3624736163 }
3624836164 assert(zir_field.type_body_len != 0);
3624936165 const body = zir.bodySlice(extra_index, zir_field.type_body_len);
3625036166 extra_index += body.len;
3625136167 const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36252 break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) {
36253 error.NeededSourceLocation => {
36254 const ty_src = mod.fieldSrcLoc(decl_index, .{
36255 .index = field_i,
36256 .range = .type,
36257 }).lazy;
36258 _ = try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
36259 unreachable;
36260 },
36261 else => |e| return e,
36262 };
36168 break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
3626336169 };
3626436170 if (field_ty.isGenericPoison()) {
3626536171 return error.GenericPoison;
......@@ -36269,11 +36175,7 @@ fn semaStructFields(
3626936175
3627036176 if (field_ty.zigTypeTag(mod) == .Opaque) {
3627136177 const msg = msg: {
36272 const ty_src = mod.fieldSrcLoc(decl_index, .{
36273 .index = field_i,
36274 .range = .type,
36275 }).lazy;
36276 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
36178 const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
3627736179 errdefer msg.destroy(sema.gpa);
3627836180
3627936181 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36283,11 +36185,7 @@ fn semaStructFields(
3628336185 }
3628436186 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3628536187 const msg = msg: {
36286 const ty_src = mod.fieldSrcLoc(decl_index, .{
36287 .index = field_i,
36288 .range = .type,
36289 }).lazy;
36290 const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{});
36188 const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{});
3629136189 errdefer msg.destroy(sema.gpa);
3629236190
3629336191 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36298,11 +36196,7 @@ fn semaStructFields(
3629836196 switch (struct_type.layout) {
3629936197 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {
3630036198 const msg = msg: {
36301 const ty_src = mod.fieldSrcLoc(decl_index, .{
36302 .index = field_i,
36303 .range = .type,
36304 });
36305 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36199 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3630636200 errdefer msg.destroy(sema.gpa);
3630736201
3630836202 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);
......@@ -36314,11 +36208,7 @@ fn semaStructFields(
3631436208 },
3631536209 .@"packed" => if (!try sema.validatePackedType(field_ty)) {
3631636210 const msg = msg: {
36317 const ty_src = mod.fieldSrcLoc(decl_index, .{
36318 .index = field_i,
36319 .range = .type,
36320 });
36321 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36211 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3632236212 errdefer msg.destroy(sema.gpa);
3632336213
3632436214 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
......@@ -36335,17 +36225,11 @@ fn semaStructFields(
3633536225 const body = zir.bodySlice(extra_index, zir_field.align_body_len);
3633636226 extra_index += body.len;
3633736227 const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36338 const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {
36339 error.NeededSourceLocation => {
36340 const align_src = mod.fieldSrcLoc(decl_index, .{
36341 .index = field_i,
36342 .range = .alignment,
36343 }).lazy;
36344 _ = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
36345 unreachable;
36346 },
36347 else => |e| return e,
36228 const align_src: LazySrcLoc = .{
36229 .base_node_inst = struct_type.zir_index.unwrap().?,
36230 .offset = .{ .container_field_align = @intCast(field_i) },
3634836231 };
36232 const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
3634936233 struct_type.field_aligns.get(ip)[field_i] = field_align;
3635036234 }
3635136235
......@@ -36374,7 +36258,7 @@ fn semaStructFieldInits(
3637436258 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
3637536259 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3637636260
36377 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36261 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3637836262 defer comptime_err_ret_trace.deinit();
3637936263
3638036264 var sema: Sema = .{
......@@ -36396,11 +36280,12 @@ fn semaStructFieldInits(
3639636280 var block_scope: Block = .{
3639736281 .parent = null,
3639836282 .sema = &sema,
36399 .src_decl = decl_index,
3640036283 .namespace = namespace_index,
3640136284 .instructions = .{},
3640236285 .inlining = null,
3640336286 .is_comptime = true,
36287 .src_base_inst = struct_type.zir_index.unwrap().?,
36288 .type_name_ctx = decl.name,
3640436289 };
3640536290 defer assert(block_scope.instructions.items.len == 0);
3640636291
......@@ -36474,33 +36359,20 @@ fn semaStructFieldInits(
3647436359 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
3647536360 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
3647636361
36477 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36478 const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) {
36479 error.NeededSourceLocation => {
36480 const init_src = mod.fieldSrcLoc(decl_index, .{
36481 .index = field_i,
36482 .range = .value,
36483 }).lazy;
36484 _ = try sema.coerce(&block_scope, field_ty, init, init_src);
36485 unreachable;
36486 },
36487 else => |e| return e,
36362 const init_src: LazySrcLoc = .{
36363 .base_node_inst = struct_type.zir_index.unwrap().?,
36364 .offset = .{ .container_field_value = @intCast(field_i) },
3648836365 };
36489 const default_val = (try sema.resolveValue(coerced)) orelse {
36490 const init_src = mod.fieldSrcLoc(decl_index, .{
36491 .index = field_i,
36492 .range = .value,
36493 }).lazy;
36366
36367 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36368 const coerced = try sema.coerce(&block_scope, field_ty, init, init_src);
36369 const default_val = try sema.resolveValue(coerced) orelse {
3649436370 return sema.failWithNeededComptime(&block_scope, init_src, .{
3649536371 .needed_comptime_reason = "struct field default value must be comptime-known",
3649636372 });
3649736373 };
3649836374
3649936375 if (default_val.canMutateComptimeVarState(mod)) {
36500 const init_src = mod.fieldSrcLoc(decl_index, .{
36501 .index = field_i,
36502 .range = .value,
36503 }).lazy;
3650436376 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});
3650536377 }
3650636378 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
......@@ -36520,9 +36392,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3652036392 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
3652136393 assert(extended.opcode == .union_decl);
3652236394 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
36523 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;
36524
36525 const src = LazySrcLoc.nodeOffset(0);
36395 const extra = zir.extraData(Zir.Inst.UnionDecl, extended.operand);
36396 var extra_index: usize = extra.end;
3652636397
3652736398 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
3652836399 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
......@@ -36562,7 +36433,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3656236433
3656336434 const decl = mod.declPtr(decl_index);
3656436435
36565 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36436 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3656636437 defer comptime_err_ret_trace.deinit();
3656736438
3656836439 var sema: Sema = .{
......@@ -36584,14 +36455,17 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3658436455 var block_scope: Block = .{
3658536456 .parent = null,
3658636457 .sema = &sema,
36587 .src_decl = decl_index,
3658836458 .namespace = union_type.namespace.unwrap().?,
3658936459 .instructions = .{},
3659036460 .inlining = null,
3659136461 .is_comptime = true,
36462 .src_base_inst = union_type.zir_index,
36463 .type_name_ctx = decl.name,
3659236464 };
3659336465 defer assert(block_scope.instructions.items.len == 0);
3659436466
36467 const src = block_scope.nodeOffset(0);
36468
3659536469 if (body.len != 0) {
3659636470 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);
3659736471 }
......@@ -36601,7 +36475,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3660136475 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};
3660236476 var explicit_tags_seen: []bool = &.{};
3660336477 if (tag_type_ref != .none) {
36604 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
36478 const tag_ty_src: LazySrcLoc = .{
36479 .base_node_inst = union_type.zir_index,
36480 .offset = .{ .node_offset_container_tag = 0 },
36481 };
3660536482 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);
3660636483 if (small.auto_enum_tag) {
3660736484 // The provided type is an integer type and we must construct the enum tag type here.
......@@ -36614,9 +36491,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3661436491 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);
3661536492 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
3661636493 const msg = msg: {
36617 const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{});
36494 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
3661836495 errdefer msg.destroy(sema.gpa);
36619 try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
36496 try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
3662036497 int_tag_ty.fmt(mod),
3662136498 fields_len - 1,
3662236499 });
......@@ -36701,19 +36578,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3670136578 break :blk try sema.resolveInst(tag_ref);
3670236579 } else .none;
3670336580
36581 const name_src: LazySrcLoc = .{
36582 .base_node_inst = union_type.zir_index,
36583 .offset = .{ .container_field_name = field_i },
36584 };
36585 const value_src: LazySrcLoc = .{
36586 .base_node_inst = union_type.zir_index,
36587 .offset = .{ .container_field_value = field_i },
36588 };
36589 const align_src: LazySrcLoc = .{
36590 .base_node_inst = union_type.zir_index,
36591 .offset = .{ .container_field_align = field_i },
36592 };
36593 const type_src: LazySrcLoc = .{
36594 .base_node_inst = union_type.zir_index,
36595 .offset = .{ .container_field_type = field_i },
36596 };
36597
3670436598 if (enum_field_vals.capacity() > 0) {
3670536599 const enum_tag_val = if (tag_ref != .none) blk: {
36706 const val = sema.semaUnionFieldVal(&block_scope, .unneeded, int_tag_ty, tag_ref) catch |err| switch (err) {
36707 error.NeededSourceLocation => {
36708 const val_src = mod.fieldSrcLoc(union_type.decl, .{
36709 .index = field_i,
36710 .range = .value,
36711 }).lazy;
36712 _ = try sema.semaUnionFieldVal(&block_scope, val_src, int_tag_ty, tag_ref);
36713 unreachable;
36714 },
36715 else => |e| return e,
36716 };
36600 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);
3671736601 last_tag_val = val;
3671836602
3671936603 break :blk val;
......@@ -36728,12 +36612,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3672836612 };
3672936613 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());
3673036614 if (gop.found_existing) {
36731 const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy;
36732 const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy;
36615 const other_value_src: LazySrcLoc = .{
36616 .base_node_inst = union_type.zir_index,
36617 .offset = .{ .container_field_value = @intCast(gop.index) },
36618 };
3673336619 const msg = msg: {
36734 const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
36620 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
3673536621 errdefer msg.destroy(gpa);
36736 try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{});
36622 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
3673736623 break :msg msg;
3673836624 };
3673936625 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36751,17 +36637,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3675136637 else if (field_type_ref == .none)
3675236638 Type.noreturn
3675336639 else
36754 sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) {
36755 error.NeededSourceLocation => {
36756 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36757 .index = field_i,
36758 .range = .type,
36759 }).lazy;
36760 _ = try sema.resolveType(&block_scope, ty_src, field_type_ref);
36761 unreachable;
36762 },
36763 else => |e| return e,
36764 };
36640 try sema.resolveType(&block_scope, type_src, field_type_ref);
3676536641
3676636642 if (field_ty.isGenericPoison()) {
3676736643 return error.GenericPoison;
......@@ -36770,11 +36646,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3677036646 if (explicit_tags_seen.len > 0) {
3677136647 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
3677236648 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
36773 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36774 .index = field_i,
36775 .range = .name,
36776 }).lazy;
36777 return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
36649 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
3677836650 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
3677936651 });
3678036652 };
......@@ -36787,17 +36659,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3678736659 // Enforce the enum fields and the union fields being in the same order.
3678836660 if (enum_index != field_i) {
3678936661 const msg = msg: {
36790 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36791 .index = field_i,
36792 .range = .name,
36793 }).lazy;
36794 const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy;
36795 const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{
36662 const enum_field_src: LazySrcLoc = .{
36663 .base_node_inst = tag_info.zir_index.unwrap().?,
36664 .offset = .{ .container_field_name = enum_index },
36665 };
36666 const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{
3679636667 field_name.fmt(ip),
3679736668 });
3679836669 errdefer msg.destroy(sema.gpa);
36799 const decl_ptr = mod.declPtr(tag_info.decl);
36800 try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{});
36670 try sema.errNote(enum_field_src, msg, "enum field here", .{});
3680136671 break :msg msg;
3680236672 };
3680336673 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36806,11 +36676,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3680636676
3680736677 if (field_ty.zigTypeTag(mod) == .Opaque) {
3680836678 const msg = msg: {
36809 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36810 .index = field_i,
36811 .range = .type,
36812 }).lazy;
36813 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
36679 const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
3681436680 errdefer msg.destroy(sema.gpa);
3681536681
3681636682 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36823,14 +36689,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3682336689 !try sema.validateExternType(field_ty, .union_field))
3682436690 {
3682536691 const msg = msg: {
36826 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36827 .index = field_i,
36828 .range = .type,
36829 });
36830 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36692 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3683136693 errdefer msg.destroy(sema.gpa);
3683236694
36833 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .union_field);
36695 try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field);
3683436696
3683536697 try sema.addDeclaredHereNote(msg, field_ty);
3683636698 break :msg msg;
......@@ -36838,14 +36700,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3683836700 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3683936701 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
3684036702 const msg = msg: {
36841 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36842 .index = field_i,
36843 .range = .type,
36844 });
36845 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36703 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3684636704 errdefer msg.destroy(sema.gpa);
3684736705
36848 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
36706 try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty);
3684936707
3685036708 try sema.addDeclaredHereNote(msg, field_ty);
3685136709 break :msg msg;
......@@ -36857,17 +36715,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3685736715
3685836716 if (small.any_aligned_fields) {
3685936717 field_aligns.appendAssumeCapacity(if (align_ref != .none)
36860 sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {
36861 error.NeededSourceLocation => {
36862 const align_src = mod.fieldSrcLoc(union_type.decl, .{
36863 .index = field_i,
36864 .range = .alignment,
36865 }).lazy;
36866 _ = try sema.resolveAlign(&block_scope, align_src, align_ref);
36867 unreachable;
36868 },
36869 else => |e| return e,
36870 }
36718 try sema.resolveAlign(&block_scope, align_src, align_ref)
3687136719 else
3687236720 .none);
3687336721 } else {
......@@ -36882,7 +36730,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3688236730 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
3688336731 if (tag_info.names.len > fields_len) {
3688436732 const msg = msg: {
36885 const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{});
36733 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});
3688636734 errdefer msg.destroy(sema.gpa);
3688736735
3688836736 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
......@@ -36897,10 +36745,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3689736745 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3689836746 }
3689936747 } else if (enum_field_vals.count() > 0) {
36900 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl));
36748 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl), extra.data.src_line);
3690136749 union_type.tagTypePtr(ip).* = enum_ty;
3690236750 } else {
36903 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl));
36751 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl), extra.data.src_line);
3690436752 union_type.tagTypePtr(ip).* = enum_ty;
3690536753 }
3690636754}
......@@ -36918,13 +36766,13 @@ fn generateUnionTagTypeNumbered(
3691836766 enum_field_names: []const InternPool.NullTerminatedString,
3691936767 enum_field_vals: []const InternPool.Index,
3692036768 union_owner_decl: *Module.Decl,
36769 src_line: u32,
3692136770) !InternPool.Index {
3692236771 const mod = sema.mod;
3692336772 const gpa = sema.gpa;
3692436773 const ip = &mod.intern_pool;
3692536774
36926 const src_decl = mod.declPtr(block.src_decl);
36927 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36775 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3692836776 errdefer mod.destroyDecl(new_decl_index);
3692936777 const fqn = try union_owner_decl.fullyQualifiedName(mod);
3693036778 const name = try ip.getOrPutStringFmt(
......@@ -36935,7 +36783,7 @@ fn generateUnionTagTypeNumbered(
3693536783 );
3693636784 try mod.initNewAnonDecl(
3693736785 new_decl_index,
36938 src_decl.src_line,
36786 src_line,
3693936787 Value.@"unreachable",
3694036788 name,
3694136789 );
......@@ -36968,6 +36816,7 @@ fn generateUnionTagTypeSimple(
3696836816 block: *Block,
3696936817 enum_field_names: []const InternPool.NullTerminatedString,
3697036818 union_owner_decl: *Module.Decl,
36819 src_line: u32,
3697136820) !InternPool.Index {
3697236821 const mod = sema.mod;
3697336822 const ip = &mod.intern_pool;
......@@ -36975,8 +36824,7 @@ fn generateUnionTagTypeSimple(
3697536824
3697636825 const new_decl_index = new_decl_index: {
3697736826 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36978 const src_decl = mod.declPtr(block.src_decl);
36979 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36827 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3698036828 errdefer mod.destroyDecl(new_decl_index);
3698136829 const name = try ip.getOrPutStringFmt(
3698236830 gpa,
......@@ -36986,7 +36834,7 @@ fn generateUnionTagTypeSimple(
3698636834 );
3698736835 try mod.initNewAnonDecl(
3698836836 new_decl_index,
36989 src_decl.src_line,
36837 src_line,
3699036838 Value.@"unreachable",
3699136839 name,
3699236840 );
......@@ -37016,19 +36864,33 @@ fn generateUnionTagTypeSimple(
3701636864}
3701736865
3701836866fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37019 const gpa = sema.gpa;
37020 const src = LazySrcLoc.nodeOffset(0);
36867 const zcu = sema.mod;
3702136868
3702236869 var block: Block = .{
3702336870 .parent = null,
3702436871 .sema = sema,
37025 .src_decl = sema.owner_decl_index,
3702636872 .namespace = sema.owner_decl.src_namespace,
3702736873 .instructions = .{},
3702836874 .inlining = null,
3702936875 .is_comptime = true,
36876 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36877 assert(sema.owner_decl.has_tv);
36878 assert(sema.owner_decl.owns_tv);
36879 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36880 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36881 .Fn => {
36882 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36883 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36884 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36885 },
36886 else => unreachable,
36887 }
36888 },
36889 .type_name_ctx = sema.owner_decl.name,
3703036890 };
37031 defer block.instructions.deinit(gpa);
36891 defer block.instructions.deinit(sema.gpa);
36892
36893 const src = block.nodeOffset(0);
3703236894
3703336895 const decl_index = try getBuiltinDecl(sema, &block, name);
3703436896 return sema.analyzeDeclVal(&block, src, decl_index);
......@@ -37037,7 +36899,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3703736899fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
3703836900 const gpa = sema.gpa;
3703936901
37040 const src = LazySrcLoc.nodeOffset(0);
36902 const src = block.nodeOffset(0);
3704136903
3704236904 const mod = sema.mod;
3704336905 const ip = &mod.intern_pool;
......@@ -37064,19 +36926,34 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
3706436926}
3706536927
3706636928fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36929 const zcu = sema.mod;
3706736930 const ty_inst = try sema.getBuiltin(name);
3706836931
3706936932 var block: Block = .{
3707036933 .parent = null,
3707136934 .sema = sema,
37072 .src_decl = sema.owner_decl_index,
3707336935 .namespace = sema.owner_decl.src_namespace,
3707436936 .instructions = .{},
3707536937 .inlining = null,
3707636938 .is_comptime = true,
36939 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36940 assert(sema.owner_decl.has_tv);
36941 assert(sema.owner_decl.owns_tv);
36942 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36943 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36944 .Fn => {
36945 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36946 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36947 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36948 },
36949 else => unreachable,
36950 }
36951 },
36952 .type_name_ctx = sema.owner_decl.name,
3707736953 };
3707836954 defer block.instructions.deinit(sema.gpa);
37079 const src = LazySrcLoc.nodeOffset(0);
36955
36956 const src = block.nodeOffset(0);
3708036957
3708136958 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {
3708236959 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),
......@@ -37092,12 +36969,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3709236969/// that the types are already resolved.
3709336970/// TODO assert the return value matches `ty.onePossibleValue`
3709436971pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37095 const mod = sema.mod;
37096 const ip = &mod.intern_pool;
36972 const zcu = sema.mod;
36973 const ip = &zcu.intern_pool;
3709736974 return switch (ty.toIntern()) {
3709836975 .u0_type,
3709936976 .i0_type,
37100 => try mod.intValue(ty, 0),
36977 => try zcu.intValue(ty, 0),
3710136978 .u1_type,
3710236979 .u8_type,
3710336980 .i8_type,
......@@ -37160,7 +37037,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3716037037 .anyframe_type => unreachable,
3716137038 .null_type => Value.null,
3716237039 .undefined_type => Value.undef,
37163 .optional_noreturn_type => try mod.nullValue(ty),
37040 .optional_noreturn_type => try zcu.nullValue(ty),
3716437041 .generic_poison_type => error.GenericPoison,
3716537042 .empty_struct_type => Value.empty_struct,
3716637043 // values, not types
......@@ -37274,13 +37151,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3727437151 => switch (ip.indexToKey(ty.toIntern())) {
3727537152 inline .array_type, .vector_type => |seq_type, seq_tag| {
3727637153 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
37277 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37154 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3727837155 .ty = ty.toIntern(),
3727937156 .storage = .{ .elems = &.{} },
3728037157 } })));
3728137158
3728237159 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
37283 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37160 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3728437161 .ty = ty.toIntern(),
3728537162 .storage = .{ .repeated_elem = opv.toIntern() },
3728637163 } })));
......@@ -37295,7 +37172,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3729537172 if (struct_type.field_types.len == 0) {
3729637173 // In this case the struct has no fields at all and
3729737174 // therefore has one possible value.
37298 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37175 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3729937176 .ty = ty.toIntern(),
3730037177 .storage = .{ .elems = &.{} },
3730137178 } })));
......@@ -37312,12 +37189,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3731237189 continue;
3731337190 }
3731437191 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
37315 if (field_ty.eql(ty, mod)) {
37316 const msg = try Module.ErrorMsg.create(
37317 sema.gpa,
37318 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
37192 if (field_ty.eql(ty, zcu)) {
37193 const msg = try sema.errMsg(
37194 ty.srcLoc(zcu),
3731937195 "struct '{}' depends on itself",
37320 .{ty.fmt(mod)},
37196 .{ty.fmt(zcu)},
3732137197 );
3732237198 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
3732337199 return sema.failWithOwnedErrorMsg(null, msg);
......@@ -37329,7 +37205,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3732937205
3733037206 // In this case the struct has no runtime-known fields and
3733137207 // therefore has one possible value.
37332 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37208 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3733337209 .ty = ty.toIntern(),
3733437210 .storage = .{ .elems = field_vals },
3733537211 } })));
......@@ -37342,7 +37218,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3734237218 // In this case the struct has all comptime-known fields and
3734337219 // therefore has one possible value.
3734437220 // TODO: write something like getCoercedInts to avoid needing to dupe
37345 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37221 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3734637222 .ty = ty.toIntern(),
3734737223 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
3734837224 } })));
......@@ -37354,23 +37230,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3735437230 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
3735537231 return null;
3735637232 if (union_obj.field_types.len == 0) {
37357 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
37233 const only = try zcu.intern(.{ .empty_enum_value = ty.toIntern() });
3735837234 return Value.fromInterned(only);
3735937235 }
3736037236 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
37361 if (only_field_ty.eql(ty, mod)) {
37362 const msg = try Module.ErrorMsg.create(
37363 sema.gpa,
37364 mod.declPtr(union_obj.decl).srcLoc(mod),
37237 if (only_field_ty.eql(ty, zcu)) {
37238 const msg = try sema.errMsg(
37239 ty.srcLoc(zcu),
3736537240 "union '{}' depends on itself",
37366 .{ty.fmt(mod)},
37241 .{ty.fmt(zcu)},
3736737242 );
3736837243 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});
3736937244 return sema.failWithOwnedErrorMsg(null, msg);
3737037245 }
3737137246 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
3737237247 return null;
37373 const only = try mod.intern(.{ .un = .{
37248 const only = try zcu.intern(.{ .un = .{
3737437249 .ty = ty.toIntern(),
3737537250 .tag = tag_val.toIntern(),
3737637251 .val = val_val.toIntern(),
......@@ -37385,7 +37260,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3738537260 if (enum_type.tag_ty == .comptime_int_type) return null;
3738637261
3738737262 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {
37388 const only = try mod.intern(.{ .enum_tag = .{
37263 const only = try zcu.intern(.{ .enum_tag = .{
3738937264 .ty = ty.toIntern(),
3739037265 .int = int_opv.toIntern(),
3739137266 } });
......@@ -37395,18 +37270,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3739537270 return null;
3739637271 },
3739737272 .auto, .explicit => {
37398 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null;
37273 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
3739937274
3740037275 return Value.fromInterned(switch (enum_type.names.len) {
37401 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),
37402 1 => try mod.intern(.{ .enum_tag = .{
37276 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }),
37277 1 => try zcu.intern(.{ .enum_tag = .{
3740337278 .ty = ty.toIntern(),
3740437279 .int = if (enum_type.values.len == 0)
37405 (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
37280 (try zcu.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
3740637281 else
37407 try mod.intern_pool.getCoercedInts(
37408 mod.gpa,
37409 mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
37282 try zcu.intern_pool.getCoercedInts(
37283 zcu.gpa,
37284 zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
3741037285 enum_type.tag_ty,
3741137286 ),
3741237287 } }),
......@@ -37744,7 +37619,7 @@ fn unionFieldIndex(
3774437619 try sema.resolveTypeFields(union_ty);
3774537620 const union_obj = mod.typeToUnion(union_ty).?;
3774637621 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
37747 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
37622 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
3774837623 return @intCast(field_index);
3774937624}
3775037625
......@@ -37763,7 +37638,7 @@ fn structFieldIndex(
3776337638 } else {
3776437639 const struct_type = mod.typeToStruct(struct_ty).?;
3776537640 return struct_type.nameIndex(ip, field_name) orelse
37766 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);
37641 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
3776737642 }
3776837643}
3776937644
......@@ -38535,9 +38410,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {
3853538410fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {
3853638411 if (sema.checkRuntimeValue(val)) return;
3853738412 return sema.failWithOwnedErrorMsg(block, msg: {
38538 const msg = try sema.errMsg(block, val_src, "runtime value contains reference to comptime var", .{});
38413 const msg = try sema.errMsg(val_src, "runtime value contains reference to comptime var", .{});
3853938414 errdefer msg.destroy(sema.gpa);
38540 try sema.errNote(block, val_src, msg, "comptime var pointers are not available at runtime", .{});
38415 try sema.errNote(val_src, msg, "comptime var pointers are not available at runtime", .{});
3854138416 break :msg msg;
3854238417 });
3854338418}
......@@ -38628,6 +38503,14 @@ fn maybeDerefSliceAsArray(
3862838503 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);
3862938504}
3863038505
38506fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: bool) !void {
38507 if (safety_check and block.wantSafety()) {
38508 try sema.safetyPanic(block, src, .unreach);
38509 } else {
38510 _ = try block.addNoOp(.unreach);
38511 }
38512}
38513
3863138514pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
3863238515pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
3863338516
src/Sema/comptime_ptr_access.zig+6-5
......@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(
10251025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {
10261026 if (block.runtime_cond) |cond_src| {
10271027 const msg = msg: {
1028 const msg = try sema.errMsg(block, src, "store to comptime variable depends on runtime condition", .{});
1028 const msg = try sema.errMsg(src, "store to comptime variable depends on runtime condition", .{});
10291029 errdefer msg.destroy(sema.gpa);
1030 try sema.mod.errNoteNonLazy(cond_src, msg, "runtime condition here", .{});
1030 try sema.errNote(cond_src, msg, "runtime condition here", .{});
10311031 break :msg msg;
10321032 };
10331033 return sema.failWithOwnedErrorMsg(block, msg);
10341034 }
10351035 if (block.runtime_loop) |loop_src| {
10361036 const msg = msg: {
1037 const msg = try sema.errMsg(block, src, "cannot store to comptime variable in non-inline loop", .{});
1037 const msg = try sema.errMsg(src, "cannot store to comptime variable in non-inline loop", .{});
10381038 errdefer msg.destroy(sema.gpa);
1039 try sema.mod.errNoteNonLazy(loop_src, msg, "non-inline loop here", .{});
1039 try sema.errNote(loop_src, msg, "non-inline loop here", .{});
10401040 break :msg msg;
10411041 };
10421042 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -1048,7 +1048,6 @@ fn checkComptimeVarStore(
10481048const std = @import("std");
10491049const assert = std.debug.assert;
10501050const Allocator = std.mem.Allocator;
1051const LazySrcLoc = std.zig.LazySrcLoc;
10521051
10531052const InternPool = @import("../InternPool.zig");
10541053const ComptimeAllocIndex = InternPool.ComptimeAllocIndex;
......@@ -1057,3 +1056,5 @@ const Block = Sema.Block;
10571056const MutableValue = @import("../mutable_value.zig").MutableValue;
10581057const Type = @import("../type.zig").Type;
10591058const Value = @import("../Value.zig");
1059const Zcu = @import("../Module.zig");
1060const LazySrcLoc = Zcu.LazySrcLoc;
src/Value.zig-1
......@@ -4014,7 +4014,6 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu) Allocator.
40144014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {
40154015 error.OutOfMemory => |e| return e,
40164016 error.AnalysisFail,
4017 error.NeededSourceLocation,
40184017 error.GenericPoison,
40194018 error.ComptimeReturn,
40204019 error.ComptimeBreak,
src/arch/wasm/CodeGen.zig+2-3
......@@ -16,7 +16,6 @@ const Decl = Module.Decl;
1616const Type = @import("../../type.zig").Type;
1717const Value = @import("../../Value.zig");
1818const Compilation = @import("../../Compilation.zig");
19const LazySrcLoc = std.zig.LazySrcLoc;
2019const link = @import("../../link.zig");
2120const Air = @import("../../Air.zig");
2221const Liveness = @import("../../Liveness.zig");
......@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
766765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
767766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
768767 const mod = func.bin_file.base.comp.module.?;
769 const src_loc = func.decl.srcLoc(mod);
768 const src_loc = func.decl.navSrcLoc(mod).upgrade(mod);
770769 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
771770 return error.CodegenFail;
772771}
......@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(
31233122 }
31243123
31253124 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;
3126 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.srcLoc(mod));
3125 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.navSrcLoc(mod).upgrade(mod));
31273126 switch (res) {
31283127 .ok => {},
31293128 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
......@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257257 const comp = emit.bin_file.base.comp;
258258 const zcu = comp.module.?;
259259 const gpa = comp.gpa;
260 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).srcLoc(zcu), format, args);
260 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu).upgrade(zcu), format, args);
261261 return error.EmitFail;
262262}
263263
src/codegen/c.zig+1-2
......@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;
1313const C = link.File.C;
1414const Decl = Zcu.Decl;
1515const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = std.zig.LazySrcLoc;
1716const Air = @import("../Air.zig");
1817const Liveness = @import("../Liveness.zig");
1918const InternPool = @import("../InternPool.zig");
......@@ -638,7 +637,7 @@ pub const DeclGen = struct {
638637 const zcu = dg.zcu;
639638 const decl_index = dg.pass.decl;
640639 const decl = zcu.declPtr(decl_index);
641 const src_loc = decl.srcLoc(zcu);
640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);
642641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
643642 return error.AnalysisFail;
644643 }
src/codegen/c/Type.zig+1-1
......@@ -2581,8 +2581,8 @@ pub const AlignAs = packed struct {
25812581const Alignment = @import("../../InternPool.zig").Alignment;
25822582const assert = std.debug.assert;
25832583const CType = @This();
2584const DeclIndex = std.zig.DeclIndex;
25852584const Module = @import("../../Package/Module.zig");
25862585const std = @import("std");
25872586const Type = @import("../../type.zig").Type;
25882587const Zcu = @import("../../Module.zig");
2588const DeclIndex = @import("../../InternPool.zig").DeclIndex;
src/codegen/llvm.zig+3-4
......@@ -22,7 +22,6 @@ const Air = @import("../Air.zig");
2222const Liveness = @import("../Liveness.zig");
2323const Value = @import("../Value.zig");
2424const Type = @import("../type.zig").Type;
25const LazySrcLoc = std.zig.LazySrcLoc;
2625const x86_64_abi = @import("../arch/x86_64/abi.zig");
2726const wasm_c_abi = @import("../arch/wasm/abi.zig");
2827const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
......@@ -2067,7 +2066,7 @@ pub const Object = struct {
20672066 try o.builder.metadataString(name),
20682067 file,
20692068 scope,
2070 owner_decl.src_node + 1, // Line
2069 owner_decl.src_line + 1, // Line
20712070 try o.lowerDebugType(int_ty),
20722071 ty.abiSize(mod) * 8,
20732072 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
......@@ -2237,7 +2236,7 @@ pub const Object = struct {
22372236 try o.builder.metadataString(name),
22382237 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
22392238 try o.namespaceToDebugScope(owner_decl.src_namespace),
2240 owner_decl.src_node + 1, // Line
2239 owner_decl.src_line + 1, // Line
22412240 .none, // Underlying type
22422241 0, // Size
22432242 0, // Align
......@@ -4729,7 +4728,7 @@ pub const DeclGen = struct {
47294728 const o = dg.object;
47304729 const gpa = o.gpa;
47314730 const mod = o.module;
4732 const src_loc = dg.decl.srcLoc(mod);
4731 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);
47334732 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
47344733 return error.CodegenFail;
47354734 }
src/codegen/spirv.zig+2-3
......@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");
99const Decl = Module.Decl;
1010const Type = @import("../type.zig").Type;
1111const Value = @import("../Value.zig");
12const LazySrcLoc = std.zig.LazySrcLoc;
1312const Air = @import("../Air.zig");
1413const Liveness = @import("../Liveness.zig");
1514const InternPool = @import("../InternPool.zig");
......@@ -414,7 +413,7 @@ const DeclGen = struct {
414413 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
415414 @setCold(true);
416415 const mod = self.module;
417 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
416 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);
418417 assert(self.error_msg == null);
419418 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
420419 return error.CodegenFail;
......@@ -6438,7 +6437,7 @@ const DeclGen = struct {
64386437 // TODO: Translate proper error locations.
64396438 assert(as.errors.items.len != 0);
64406439 assert(self.error_msg == null);
6441 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
6440 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);
64426441 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
64436442 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);
64446443
src/crash_report.zig+11-15
......@@ -10,6 +10,7 @@ const native_os = builtin.os.tag;
1010
1111const Module = @import("Module.zig");
1212const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");
1314const Zir = std.zig.Zir;
1415const Decl = Module.Decl;
1516
......@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {
7677 const stderr = io.getStdErr().writer();
7778 const block: *Sema.Block = anal.block;
7879 const mod = anal.sema.mod;
79 const block_src_decl = mod.declPtr(block.src_decl);
80
81 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
8082
8183 try stderr.writeAll("Analyzing ");
82 try writeFullyQualifiedDeclWithFile(mod, block_src_decl, stderr);
84 try writeFilePath(file, stderr);
8385 try stderr.writeAll("\n");
8486
8587 print_zir.renderInstructionContext(
8688 allocator,
8789 anal.body,
8890 anal.body_index,
89 mod.namespacePtr(block.namespace).file_scope,
90 block_src_decl.src_node,
91 file,
92 src_base_node,
9193 6, // indent
9294 stderr,
9395 ) catch |err| switch (err) {
......@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {
9597 else => |e| return e,
9698 };
9799 try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");
98 try writeFilePath(mod.namespacePtr(block.namespace).file_scope, stderr);
100 try writeFilePath(file, stderr);
99101 try stderr.writeAll("\n\n");
100102
101103 var parent = anal.parent;
102104 while (parent) |curr| {
103105 fba.reset();
104106 try stderr.writeAll(" in ");
105 const curr_block_src_decl = mod.declPtr(curr.block.src_decl);
106 try writeFullyQualifiedDeclWithFile(mod, curr_block_src_decl, stderr);
107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);
108 try writeFilePath(cur_block_file, stderr);
107109 try stderr.writeAll("\n > ");
108110 print_zir.renderSingleInstruction(
109111 allocator,
110112 curr.body[curr.body_index],
111 mod.namespacePtr(curr.block.namespace).file_scope,
112 curr_block_src_decl.src_node,
113 cur_block_file,
114 cur_block_src_base_node,
113115 6, // indent
114116 stderr,
115117 ) catch |err| switch (err) {
......@@ -138,12 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
138140 try writer.writeAll(file.sub_file_path);
139141}
140142
141fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, writer: anytype) !void {
142 try writeFilePath(decl.getFileScope(mod), writer);
143 try writer.writeAll(": ");
144 try decl.renderFullyQualifiedDebugName(mod, writer);
145}
146
147143pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
148144 PanicSwitch.preDispatch();
149145 @setCold(true);
src/link/Coff.zig+6-6
......@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11441144
11451145 const res = try codegen.generateFunction(
11461146 &self.base,
1147 decl.srcLoc(mod),
1147 decl.navSrcLoc(mod).upgrade(mod),
11481148 func_index,
11491149 air,
11501150 liveness,
......@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
11811181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
11821182 defer gpa.free(sym_name);
11831183 const ty = val.typeOf(mod);
1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) {
1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod).upgrade(mod))) {
11851185 .ok => |atom_index| atom_index,
11861186 .fail => |em| {
11871187 decl.analysis = .codegen_failure;
......@@ -1272,7 +1272,7 @@ pub fn updateDecl(
12721272 defer code_buffer.deinit();
12731273
12741274 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1275 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{
1275 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{
12761276 .parent_atom_index = atom.getSymbolIndex().?,
12771277 });
12781278 const code = switch (res) {
......@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(
13131313 const atom = self.getAtomPtr(atom_index);
13141314 const local_sym_index = atom.getSymbolIndex().?;
13151315
1316 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1317 mod.declPtr(owner_decl).srcLoc(mod)
1316 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1317 src.upgrade(mod)
13181318 else
13191319 Module.SrcLoc{
13201320 .file_scope = undefined,
1321 .parent_decl_node = undefined,
1321 .base_node = undefined,
13221322 .lazy = .unneeded,
13231323 };
13241324 const res = try codegen.generateLazySymbol(
src/link/Elf/ZigObject.zig+8-8
......@@ -1074,7 +1074,7 @@ pub fn updateFunc(
10741074 const res = if (decl_state) |*ds|
10751075 try codegen.generateFunction(
10761076 &elf_file.base,
1077 decl.srcLoc(mod),
1077 decl.navSrcLoc(mod).upgrade(mod),
10781078 func_index,
10791079 air,
10801080 liveness,
......@@ -1084,7 +1084,7 @@ pub fn updateFunc(
10841084 else
10851085 try codegen.generateFunction(
10861086 &elf_file.base,
1087 decl.srcLoc(mod),
1087 decl.navSrcLoc(mod).upgrade(mod),
10881088 func_index,
10891089 air,
10901090 liveness,
......@@ -1158,13 +1158,13 @@ pub fn updateDecl(
11581158 // TODO implement .debug_info for global variables
11591159 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11601160 const res = if (decl_state) |*ds|
1161 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .{
1161 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{
11621162 .dwarf = ds,
11631163 }, .{
11641164 .parent_atom_index = sym_index,
11651165 })
11661166 else
1167 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{
1167 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{
11681168 .parent_atom_index = sym_index,
11691169 });
11701170
......@@ -1221,12 +1221,12 @@ fn updateLazySymbol(
12211221 break :blk try self.strtab.insert(gpa, name);
12221222 };
12231223
1224 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1225 mod.declPtr(owner_decl).srcLoc(mod)
1224 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1225 src.upgrade(mod)
12261226 else
12271227 Module.SrcLoc{
12281228 .file_scope = undefined,
1229 .parent_decl_node = undefined,
1229 .base_node = undefined,
12301230 .lazy = .unneeded,
12311231 };
12321232 const res = try codegen.generateLazySymbol(
......@@ -1306,7 +1306,7 @@ pub fn lowerUnnamedConst(
13061306 val,
13071307 ty.abiAlignment(mod),
13081308 elf_file.zig_data_rel_ro_section_index.?,
1309 decl.srcLoc(mod),
1309 decl.navSrcLoc(mod).upgrade(mod),
13101310 )) {
13111311 .ok => |sym_index| sym_index,
13121312 .fail => |em| {
src/link/MachO/ZigObject.zig+6-6
......@@ -682,7 +682,7 @@ pub fn updateFunc(
682682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683683 const res = try codegen.generateFunction(
684684 &macho_file.base,
685 decl.srcLoc(mod),
685 decl.navSrcLoc(mod).upgrade(mod),
686686 func_index,
687687 air,
688688 liveness,
......@@ -756,7 +756,7 @@ pub fn updateDecl(
756756
757757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
758758 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
759 const res = try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), decl_val, &code_buffer, dio, .{
759 const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, dio, .{
760760 .parent_atom_index = sym_index,
761761 });
762762
......@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(
11041104 val,
11051105 val.typeOf(mod).abiAlignment(mod),
11061106 macho_file.zig_const_sect_index.?,
1107 decl.srcLoc(mod),
1107 decl.navSrcLoc(mod).upgrade(mod),
11081108 )) {
11091109 .ok => |sym_index| sym_index,
11101110 .fail => |em| {
......@@ -1294,12 +1294,12 @@ fn updateLazySymbol(
12941294 break :blk try self.strtab.insert(gpa, name);
12951295 };
12961296
1297 const src = if (lazy_sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1298 mod.declPtr(owner_decl).srcLoc(mod)
1297 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|
1298 src.upgrade(mod)
12991299 else
13001300 Module.SrcLoc{
13011301 .file_scope = undefined,
1302 .parent_decl_node = undefined,
1302 .base_node = undefined,
13031303 .lazy = .unneeded,
13041304 };
13051305 const res = try codegen.generateLazySymbol(
src/link/Plan9.zig+7-7
......@@ -433,7 +433,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
433433
434434 const res = try codegen.generateFunction(
435435 &self.base,
436 decl.srcLoc(mod),
436 decl.navSrcLoc(mod).upgrade(mod),
437437 func_index,
438438 air,
439439 liveness,
......@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
499499 };
500500 self.syms.items[info.sym_index.?] = sym;
501501
502 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), val, &code_buffer, .{
502 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), val, &code_buffer, .{
503503 .none = {},
504504 }, .{
505505 .parent_atom_index = new_atom_idx,
......@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
538538 defer code_buffer.deinit();
539539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
540540 // TODO we need the symbol index for symbol in the table of locals for the containing atom
541 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .{ .none = {} }, .{
541 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{ .none = {} }, .{
542542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
543543 });
544544 const code = switch (res) {
......@@ -1020,7 +1020,7 @@ fn addDeclExports(
10201020 {
10211021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
10221022 gpa,
1023 mod.declPtr(decl_index).srcLoc(mod),
1023 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),
10241024 "plan9 does not support extra sections",
10251025 .{},
10261026 ));
......@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
12121212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12131213
12141214 // generate the code
1215 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1216 mod.declPtr(owner_decl).srcLoc(mod)
1215 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1216 src.upgrade(mod)
12171217 else
12181218 Module.SrcLoc{
12191219 .file_scope = undefined,
1220 .parent_decl_node = undefined,
1220 .base_node = undefined,
12211221 .lazy = .unneeded,
12221222 };
12231223 const res = try codegen.generateLazySymbol(
src/link/Wasm/ZigObject.zig+15-5
......@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270270 const res = try codegen.generateSymbol(
271271 &wasm_file.base,
272 decl.srcLoc(mod),
272 decl.navSrcLoc(mod).upgrade(mod),
273273 val,
274274 &code_writer,
275275 .none,
......@@ -308,7 +308,7 @@ pub fn updateFunc(
308308 defer code_writer.deinit();
309309 const result = try codegen.generateFunction(
310310 &wasm_file.base,
311 decl.srcLoc(mod),
311 decl.navSrcLoc(mod).upgrade(mod),
312312 func_index,
313313 air,
314314 liveness,
......@@ -484,7 +484,17 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
484484 });
485485 defer gpa.free(name);
486486
487 switch (try zig_object.lowerConst(wasm_file, name, val, decl.srcLoc(mod))) {
487 // We want to lower the source location of `decl`. However, when generating
488 // lazy functions (for e.g. `@tagName`), `decl` may correspond to a type
489 // rather than a `Nav`!
490 // The future split of `Decl` into `Nav` and `Cau` may require rethinking this
491 // logic. For now, just get the source location conditionally as needed.
492 const decl_src = if (decl.typeOf(mod).toIntern() == .type_type)
493 decl.val.toType().srcLoc(mod)
494 else
495 decl.navSrcLoc(mod);
496
497 switch (try zig_object.lowerConst(wasm_file, name, val, decl_src.upgrade(mod))) {
488498 .ok => |atom_index| {
489499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
490500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
......@@ -867,7 +877,7 @@ pub fn updateExports(
867877 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
868878 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
869879 gpa,
870 decl.srcLoc(mod),
880 decl.navSrcLoc(mod).upgrade(mod),
871881 "Unimplemented: ExportOptions.section '{s}'",
872882 .{section},
873883 ));
......@@ -900,7 +910,7 @@ pub fn updateExports(
900910 .link_once => {
901911 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
902912 gpa,
903 decl.srcLoc(mod),
913 decl.navSrcLoc(mod).upgrade(mod),
904914 "Unimplemented: LinkOnce",
905915 .{},
906916 ));
src/main.zig+3
......@@ -5966,6 +5966,7 @@ fn cmdAstCheck(
59665966 .zir = undefined,
59675967 .mod = undefined,
59685968 .root_decl = .none,
5969 .path_digest = undefined,
59695970 };
59705971 if (zig_source_file) |file_name| {
59715972 var f = fs.cwd().openFile(file_name, .{}) catch |err| {
......@@ -6284,6 +6285,7 @@ fn cmdDumpZir(
62846285 .zir = try Module.loadZirCache(gpa, f),
62856286 .mod = undefined,
62866287 .root_decl = .none,
6288 .path_digest = undefined,
62876289 };
62886290 defer file.zir.deinit(gpa);
62896291
......@@ -6354,6 +6356,7 @@ fn cmdChangelist(
63546356 .zir = undefined,
63556357 .mod = undefined,
63566358 .root_decl = .none,
6359 .path_digest = undefined,
63576360 };
63586361
63596362 file.mod = try Package.Module.createLimited(arena, .{
src/print_value.zig+1-1
......@@ -32,7 +32,7 @@ pub fn format(
3232 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {
3333 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
3434 error.ComptimeBreak, error.ComptimeReturn => unreachable,
35 error.AnalysisFail, error.NeededSourceLocation => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
35 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
3636 else => |e| return e,
3737 };
3838}
src/print_zir.zig+162-157
......@@ -6,8 +6,9 @@ const Ast = std.zig.Ast;
66const InternPool = @import("InternPool.zig");
77
88const Zir = std.zig.Zir;
9const Module = @import("Module.zig");
10const LazySrcLoc = std.zig.LazySrcLoc;
9const Zcu = @import("Module.zig");
10const Module = Zcu;
11const LazySrcLoc = Zcu.LazySrcLoc;
1112
1213/// Write human-readable, debug formatted ZIR code to a file.
1314pub fn renderAsTextToFile(
......@@ -47,12 +48,11 @@ pub fn renderAsTextToFile(
4748 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
4849 extra_index = item.end;
4950
50 const src: LazySrcLoc = .{ .token_abs = item.data.token };
5151 const import_path = scope_file.zir.nullTerminatedString(item.data.name);
5252 try stream.print(" @import(\"{}\") ", .{
5353 std.zig.fmtEscapes(import_path),
5454 });
55 try writer.writeSrc(stream, src);
55 try writer.writeSrcTokAbs(stream, item.data.token);
5656 try stream.writeAll("\n");
5757 }
5858 }
......@@ -187,7 +187,7 @@ const Writer = struct {
187187 } = .{},
188188
189189 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {
190 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(self.parent_decl_node))));
190 return @bitCast(offset + @as(i32, @bitCast(self.parent_decl_node)));
191191 }
192192
193193 fn writeInstToStream(
......@@ -569,7 +569,6 @@ const Writer = struct {
569569 .wasm_memory_size,
570570 .int_from_error,
571571 .error_from_int,
572 .reify,
573572 .c_va_copy,
574573 .c_va_end,
575574 .work_item_id,
......@@ -577,10 +576,20 @@ const Writer = struct {
577576 .work_group_id,
578577 => {
579578 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
580 const src = LazySrcLoc.nodeOffset(inst_data.node);
581579 try self.writeInstRef(stream, inst_data.operand);
582580 try stream.writeAll(")) ");
583 try self.writeSrc(stream, src);
581 try self.writeSrcNode(stream, inst_data.node);
582 },
583
584 .reify => {
585 const inst_data = self.code.extraData(Zir.Inst.Reify, extended.operand).data;
586 try stream.print("{d}, ", .{inst_data.src_line});
587 try self.writeInstRef(stream, inst_data.operand);
588 try stream.writeAll(")) ");
589 const prev_parent_decl_node = self.parent_decl_node;
590 self.parent_decl_node = inst_data.node;
591 defer self.parent_decl_node = prev_parent_decl_node;
592 try self.writeSrcNode(stream, 0);
584593 },
585594
586595 .builtin_extern,
......@@ -591,12 +600,11 @@ const Writer = struct {
591600 .c_va_arg,
592601 => {
593602 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
594 const src = LazySrcLoc.nodeOffset(inst_data.node);
595603 try self.writeInstRef(stream, inst_data.lhs);
596604 try stream.writeAll(", ");
597605 try self.writeInstRef(stream, inst_data.rhs);
598606 try stream.writeAll(")) ");
599 try self.writeSrc(stream, src);
607 try self.writeSrcNode(stream, inst_data.node);
600608 },
601609
602610 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
......@@ -611,9 +619,8 @@ const Writer = struct {
611619 }
612620
613621 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
614 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
615622 try stream.writeAll(")) ");
616 try self.writeSrc(stream, src);
623 try self.writeSrcNode(stream, @bitCast(extended.operand));
617624 }
618625
619626 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -630,7 +637,7 @@ const Writer = struct {
630637 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
631638 try self.writeInstRef(stream, inst_data.operand);
632639 try stream.writeAll(") ");
633 try self.writeSrc(stream, inst_data.src());
640 try self.writeSrcNode(stream, inst_data.src_node);
634641 }
635642
636643 fn writeUnTok(
......@@ -641,7 +648,7 @@ const Writer = struct {
641648 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
642649 try self.writeInstRef(stream, inst_data.operand);
643650 try stream.writeAll(") ");
644 try self.writeSrc(stream, inst_data.src());
651 try self.writeSrcTok(stream, inst_data.src_tok);
645652 }
646653
647654 fn writeValidateDestructure(
......@@ -653,9 +660,9 @@ const Writer = struct {
653660 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
654661 try self.writeInstRef(stream, extra.operand);
655662 try stream.print(", {d}) (destructure=", .{extra.expect_len});
656 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.destructure_node));
663 try self.writeSrcNode(stream, extra.destructure_node);
657664 try stream.writeAll(") ");
658 try self.writeSrc(stream, inst_data.src());
665 try self.writeSrcNode(stream, inst_data.src_node);
659666 }
660667
661668 fn writeValidateArrayInitTy(
......@@ -667,7 +674,7 @@ const Writer = struct {
667674 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
668675 try self.writeInstRef(stream, extra.ty);
669676 try stream.print(", {d}) ", .{extra.init_count});
670 try self.writeSrc(stream, inst_data.src());
677 try self.writeSrcNode(stream, inst_data.src_node);
671678 }
672679
673680 fn writeArrayTypeSentinel(
......@@ -683,7 +690,7 @@ const Writer = struct {
683690 try stream.writeAll(", ");
684691 try self.writeInstRef(stream, extra.elem_type);
685692 try stream.writeAll(") ");
686 try self.writeSrc(stream, inst_data.src());
693 try self.writeSrcNode(stream, inst_data.src_node);
687694 }
688695
689696 fn writePtrType(
......@@ -728,7 +735,7 @@ const Writer = struct {
728735 try stream.writeAll(")");
729736 }
730737 try stream.writeAll(") ");
731 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.data.src_node));
738 try self.writeSrcNode(stream, extra.data.src_node);
732739 }
733740
734741 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -763,11 +770,10 @@ const Writer = struct {
763770 fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
764771 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
765772 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
766 const src = inst_data.src();
767773 const number = extra.get();
768774 // TODO improve std.format to be able to print f128 values
769775 try stream.print("{d}) ", .{@as(f64, @floatCast(number))});
770 try self.writeSrc(stream, src);
776 try self.writeSrcNode(stream, inst_data.src_node);
771777 }
772778
773779 fn writeStr(
......@@ -787,7 +793,7 @@ const Writer = struct {
787793 try stream.writeAll(", ");
788794 try self.writeInstRef(stream, extra.start);
789795 try stream.writeAll(") ");
790 try self.writeSrc(stream, inst_data.src());
796 try self.writeSrcNode(stream, inst_data.src_node);
791797 }
792798
793799 fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -799,7 +805,7 @@ const Writer = struct {
799805 try stream.writeAll(", ");
800806 try self.writeInstRef(stream, extra.end);
801807 try stream.writeAll(") ");
802 try self.writeSrc(stream, inst_data.src());
808 try self.writeSrcNode(stream, inst_data.src_node);
803809 }
804810
805811 fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -813,7 +819,7 @@ const Writer = struct {
813819 try stream.writeAll(", ");
814820 try self.writeInstRef(stream, extra.sentinel);
815821 try stream.writeAll(") ");
816 try self.writeSrc(stream, inst_data.src());
822 try self.writeSrcNode(stream, inst_data.src_node);
817823 }
818824
819825 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -829,7 +835,7 @@ const Writer = struct {
829835 try self.writeInstRef(stream, extra.sentinel);
830836 }
831837 try stream.writeAll(") ");
832 try self.writeSrc(stream, inst_data.src());
838 try self.writeSrcNode(stream, inst_data.src_node);
833839 }
834840
835841 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -841,7 +847,7 @@ const Writer = struct {
841847 try stream.writeAll(", ");
842848 try self.writeInstRef(stream, extra.init);
843849 try stream.writeAll(") ");
844 try self.writeSrc(stream, inst_data.src());
850 try self.writeSrcNode(stream, inst_data.src_node);
845851 }
846852
847853 fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -855,7 +861,7 @@ const Writer = struct {
855861 try stream.writeAll(", ");
856862 try self.writeInstRef(stream, extra.mask);
857863 try stream.writeAll(") ");
858 try self.writeSrc(stream, inst_data.src());
864 try self.writeSrcNode(stream, inst_data.src_node);
859865 }
860866
861867 fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
......@@ -868,7 +874,7 @@ const Writer = struct {
868874 try stream.writeAll(", ");
869875 try self.writeInstRef(stream, extra.b);
870876 try stream.writeAll(") ");
871 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));
877 try self.writeSrcNode(stream, extra.node);
872878 }
873879
874880 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -880,7 +886,7 @@ const Writer = struct {
880886 try stream.writeAll(", ");
881887 try self.writeInstRef(stream, extra.addend);
882888 try stream.writeAll(") ");
883 try self.writeSrc(stream, inst_data.src());
889 try self.writeSrcNode(stream, inst_data.src_node);
884890 }
885891
886892 fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -896,7 +902,7 @@ const Writer = struct {
896902 try stream.writeAll(", ");
897903 try self.writeInstRef(stream, extra.args);
898904 try stream.writeAll(") ");
899 try self.writeSrc(stream, inst_data.src());
905 try self.writeSrcNode(stream, inst_data.src_node);
900906 }
901907
902908 fn writeFieldParentPtr(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
......@@ -913,7 +919,7 @@ const Writer = struct {
913919 try stream.writeAll(", ");
914920 try self.writeInstRef(stream, extra.field_ptr);
915921 try stream.writeAll(") ");
916 try self.writeSrc(stream, extra.src());
922 try self.writeSrcNode(stream, extra.src_node);
917923 }
918924
919925 fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
......@@ -926,7 +932,7 @@ const Writer = struct {
926932 try stream.writeAll(", ");
927933 try self.writeInstRef(stream, extra.args);
928934 try stream.writeAll(") ");
929 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));
935 try self.writeSrcNode(stream, extra.node);
930936 }
931937
932938 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -944,7 +950,7 @@ const Writer = struct {
944950 }
945951 try self.writeBracedBody(stream, body);
946952 try stream.writeAll(") ");
947 try self.writeSrc(stream, inst_data.src());
953 try self.writeSrcTok(stream, inst_data.src_tok);
948954 }
949955
950956 fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -954,7 +960,7 @@ const Writer = struct {
954960 try stream.writeAll(", ");
955961 try self.writeInstRef(stream, extra.rhs);
956962 try stream.writeAll(") ");
957 try self.writeSrc(stream, inst_data.src());
963 try self.writeSrcNode(stream, inst_data.src_node);
958964 }
959965
960966 fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -967,7 +973,7 @@ const Writer = struct {
967973 try self.writeInstRef(stream, arg);
968974 }
969975 try stream.writeAll("}) ");
970 try self.writeSrc(stream, inst_data.src());
976 try self.writeSrcNode(stream, inst_data.src_node);
971977 }
972978
973979 fn writeArrayMul(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -979,7 +985,7 @@ const Writer = struct {
979985 try stream.writeAll(", ");
980986 try self.writeInstRef(stream, extra.rhs);
981987 try stream.writeAll(") ");
982 try self.writeSrc(stream, inst_data.src());
988 try self.writeSrcNode(stream, inst_data.src_node);
983989 }
984990
985991 fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -994,7 +1000,7 @@ const Writer = struct {
9941000
9951001 try self.writeInstRef(stream, extra.ptr);
9961002 try stream.print(", {d}) ", .{extra.index});
997 try self.writeSrc(stream, inst_data.src());
1003 try self.writeSrcNode(stream, inst_data.src_node);
9981004 }
9991005
10001006 fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1006,7 +1012,7 @@ const Writer = struct {
10061012 try stream.print(", {p}, ", .{std.zig.fmtId(decl_name)});
10071013 try self.writeInstRef(stream, extra.options);
10081014 try stream.writeAll(") ");
1009 try self.writeSrc(stream, inst_data.src());
1015 try self.writeSrcNode(stream, inst_data.src_node);
10101016 }
10111017
10121018 fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1017,7 +1023,7 @@ const Writer = struct {
10171023 try stream.writeAll(", ");
10181024 try self.writeInstRef(stream, extra.options);
10191025 try stream.writeAll(") ");
1020 try self.writeSrc(stream, inst_data.src());
1026 try self.writeSrcNode(stream, inst_data.src_node);
10211027 }
10221028
10231029 fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1027,7 +1033,7 @@ const Writer = struct {
10271033 try self.writeInstRef(stream, extra.ptr_ty);
10281034 try stream.writeAll(", ");
10291035 try stream.print(", {}) ", .{extra.elem_count});
1030 try self.writeSrc(stream, inst_data.src());
1036 try self.writeSrcNode(stream, inst_data.src_node);
10311037 }
10321038
10331039 fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1051,12 +1057,11 @@ const Writer = struct {
10511057 try stream.writeAll("]");
10521058 }
10531059 try stream.writeAll(") ");
1054 try self.writeSrc(stream, inst_data.src());
1060 try self.writeSrcNode(stream, inst_data.src_node);
10551061 }
10561062
10571063 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10581064 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
1059 const src = LazySrcLoc.nodeOffset(extra.node);
10601065
10611066 try self.writeInstRef(stream, extra.ptr);
10621067 try stream.writeAll(", ");
......@@ -1068,14 +1073,13 @@ const Writer = struct {
10681073 try stream.writeAll(", ");
10691074 try self.writeInstRef(stream, extra.failure_order);
10701075 try stream.writeAll(") ");
1071 try self.writeSrc(stream, src);
1076 try self.writeSrcNode(stream, extra.node);
10721077 }
10731078
10741079 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10751080 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
10761081 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10771082 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1078 const src = LazySrcLoc.nodeOffset(extra.node);
10791083 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
10801084 if (flags.align_cast) try stream.writeAll("align_cast, ");
10811085 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");
......@@ -1085,19 +1089,18 @@ const Writer = struct {
10851089 try stream.writeAll(", ");
10861090 try self.writeInstRef(stream, extra.rhs);
10871091 try stream.writeAll(")) ");
1088 try self.writeSrc(stream, src);
1092 try self.writeSrcNode(stream, extra.node);
10891093 }
10901094
10911095 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10921096 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
10931097 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10941098 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1095 const src = LazySrcLoc.nodeOffset(extra.node);
10961099 if (flags.const_cast) try stream.writeAll("const_cast, ");
10971100 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
10981101 try self.writeInstRef(stream, extra.operand);
10991102 try stream.writeAll(")) ");
1100 try self.writeSrc(stream, src);
1103 try self.writeSrcNode(stream, extra.node);
11011104 }
11021105
11031106 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1110,7 +1113,7 @@ const Writer = struct {
11101113 try stream.writeAll(", ");
11111114 try self.writeInstRef(stream, extra.ordering);
11121115 try stream.writeAll(") ");
1113 try self.writeSrc(stream, inst_data.src());
1116 try self.writeSrcNode(stream, inst_data.src_node);
11141117 }
11151118
11161119 fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1123,7 +1126,7 @@ const Writer = struct {
11231126 try stream.writeAll(", ");
11241127 try self.writeInstRef(stream, extra.ordering);
11251128 try stream.writeAll(") ");
1126 try self.writeSrc(stream, inst_data.src());
1129 try self.writeSrcNode(stream, inst_data.src_node);
11271130 }
11281131
11291132 fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1138,7 +1141,7 @@ const Writer = struct {
11381141 try stream.writeAll(", ");
11391142 try self.writeInstRef(stream, extra.ordering);
11401143 try stream.writeAll(") ");
1141 try self.writeSrc(stream, inst_data.src());
1144 try self.writeSrcNode(stream, inst_data.src_node);
11421145 }
11431146
11441147 fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1159,7 +1162,7 @@ const Writer = struct {
11591162 try stream.writeAll("]");
11601163 }
11611164 try stream.writeAll(") ");
1162 try self.writeSrc(stream, inst_data.src());
1165 try self.writeSrcNode(stream, inst_data.src_node);
11631166 }
11641167
11651168 fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1168,7 +1171,7 @@ const Writer = struct {
11681171 try self.writeInstRef(stream, extra.container_type);
11691172 const field_name = self.code.nullTerminatedString(extra.name_start);
11701173 try stream.print(", {s}) ", .{field_name});
1171 try self.writeSrc(stream, inst_data.src());
1174 try self.writeSrcNode(stream, inst_data.src_node);
11721175 }
11731176
11741177 fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1178,12 +1181,11 @@ const Writer = struct {
11781181 try stream.writeAll(", ");
11791182 try self.writeInstRef(stream, extra.field_name);
11801183 try stream.writeAll(") ");
1181 try self.writeSrc(stream, inst_data.src());
1184 try self.writeSrcNode(stream, inst_data.src_node);
11821185 }
11831186
11841187 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
11851188 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
1186 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
11871189 const operands = self.code.refSlice(extra.end, extended.small);
11881190
11891191 for (operands, 0..) |operand, i| {
......@@ -1191,7 +1193,7 @@ const Writer = struct {
11911193 try self.writeInstRef(stream, operand);
11921194 }
11931195 try stream.writeAll(")) ");
1194 try self.writeSrc(stream, src);
1196 try self.writeSrcNode(stream, extra.data.src_node);
11951197 }
11961198
11971199 fn writeInstNode(
......@@ -1202,7 +1204,7 @@ const Writer = struct {
12021204 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
12031205 try self.writeInstIndex(stream, inst_data.inst);
12041206 try stream.writeAll(") ");
1205 try self.writeSrc(stream, inst_data.src());
1207 try self.writeSrcNode(stream, inst_data.src_node);
12061208 }
12071209
12081210 fn writeAsm(
......@@ -1212,7 +1214,6 @@ const Writer = struct {
12121214 tmpl_is_expr: bool,
12131215 ) !void {
12141216 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
1215 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
12161217 const outputs_len = @as(u5, @truncate(extended.small));
12171218 const inputs_len = @as(u5, @truncate(extended.small >> 5));
12181219 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
......@@ -1283,18 +1284,17 @@ const Writer = struct {
12831284 }
12841285 }
12851286 try stream.writeAll(")) ");
1286 try self.writeSrc(stream, src);
1287 try self.writeSrcNode(stream, extra.data.src_node);
12871288 }
12881289
12891290 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
12901291 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1291 const src = LazySrcLoc.nodeOffset(extra.node);
12921292
12931293 try self.writeInstRef(stream, extra.lhs);
12941294 try stream.writeAll(", ");
12951295 try self.writeInstRef(stream, extra.rhs);
12961296 try stream.writeAll(")) ");
1297 try self.writeSrc(stream, src);
1297 try self.writeSrcNode(stream, extra.node);
12981298 }
12991299
13001300 fn writeCall(
......@@ -1347,13 +1347,13 @@ const Writer = struct {
13471347 }
13481348
13491349 try stream.writeAll("]) ");
1350 try self.writeSrc(stream, inst_data.src());
1350 try self.writeSrcNode(stream, inst_data.src_node);
13511351 }
13521352
13531353 fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
13541354 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13551355 try self.writePlNodeBlockWithoutSrc(stream, inst);
1356 try self.writeSrc(stream, inst_data.src());
1356 try self.writeSrcNode(stream, inst_data.src_node);
13571357 }
13581358
13591359 fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1375,7 +1375,7 @@ const Writer = struct {
13751375 try stream.writeAll(", ");
13761376 try self.writeBracedBody(stream, else_body);
13771377 try stream.writeAll(") ");
1378 try self.writeSrc(stream, inst_data.src());
1378 try self.writeSrcNode(stream, inst_data.src_node);
13791379 }
13801380
13811381 fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1386,13 +1386,18 @@ const Writer = struct {
13861386 try stream.writeAll(", ");
13871387 try self.writeBracedBody(stream, body);
13881388 try stream.writeAll(") ");
1389 try self.writeSrc(stream, inst_data.src());
1389 try self.writeSrcNode(stream, inst_data.src_node);
13901390 }
13911391
13921392 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1393 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
1393 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
13941394
13951395 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);
1396
1397 const prev_parent_decl_node = self.parent_decl_node;
1398 self.parent_decl_node = extra.data.src_node;
1399 defer self.parent_decl_node = prev_parent_decl_node;
1400
13961401 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
13971402 extra.data.fields_hash_0,
13981403 extra.data.fields_hash_1,
......@@ -1465,10 +1470,6 @@ const Writer = struct {
14651470 if (decls_len == 0) {
14661471 try stream.writeAll("{}, ");
14671472 } else {
1468 const prev_parent_decl_node = self.parent_decl_node;
1469 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1470 defer self.parent_decl_node = prev_parent_decl_node;
1471
14721473 try stream.writeAll("{\n");
14731474 self.indent += 2;
14741475 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
......@@ -1479,7 +1480,7 @@ const Writer = struct {
14791480 }
14801481
14811482 if (fields_len == 0) {
1482 try stream.writeAll("{}, {})");
1483 try stream.writeAll("{}, {}) ");
14831484 } else {
14841485 const bits_per_field = 4;
14851486 const fields_per_u32 = 32 / bits_per_field;
......@@ -1546,8 +1547,6 @@ const Writer = struct {
15461547 }
15471548 }
15481549
1549 const prev_parent_decl_node = self.parent_decl_node;
1550 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
15511550 try stream.writeAll("{\n");
15521551 self.indent += 2;
15531552
......@@ -1595,18 +1594,22 @@ const Writer = struct {
15951594 try stream.writeAll(",\n");
15961595 }
15971596
1598 self.parent_decl_node = prev_parent_decl_node;
15991597 self.indent -= 2;
16001598 try stream.writeByteNTimes(' ', self.indent);
1601 try stream.writeAll("})");
1599 try stream.writeAll("}) ");
16021600 }
1603 try self.writeSrcNode(stream, extra.data.src_node);
1601 try self.writeSrcNode(stream, 0);
16041602 }
16051603
16061604 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
16071605 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
16081606
16091607 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);
1608
1609 const prev_parent_decl_node = self.parent_decl_node;
1610 self.parent_decl_node = extra.data.src_node;
1611 defer self.parent_decl_node = prev_parent_decl_node;
1612
16101613 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
16111614 extra.data.fields_hash_0,
16121615 extra.data.fields_hash_1,
......@@ -1670,10 +1673,6 @@ const Writer = struct {
16701673 if (decls_len == 0) {
16711674 try stream.writeAll("{}");
16721675 } else {
1673 const prev_parent_decl_node = self.parent_decl_node;
1674 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1675 defer self.parent_decl_node = prev_parent_decl_node;
1676
16771676 try stream.writeAll("{\n");
16781677 self.indent += 2;
16791678 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
......@@ -1689,8 +1688,8 @@ const Writer = struct {
16891688 }
16901689
16911690 if (fields_len == 0) {
1692 try stream.writeAll("})");
1693 try self.writeSrcNode(stream, extra.data.src_node);
1691 try stream.writeAll("}) ");
1692 try self.writeSrcNode(stream, 0);
16941693 return;
16951694 }
16961695 try stream.writeAll(", ");
......@@ -1698,8 +1697,6 @@ const Writer = struct {
16981697 const body = self.code.bodySlice(extra_index, body_len);
16991698 extra_index += body.len;
17001699
1701 const prev_parent_decl_node = self.parent_decl_node;
1702 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
17031700 try self.writeBracedDecl(stream, body);
17041701 try stream.writeAll(", {\n");
17051702
......@@ -1763,17 +1760,21 @@ const Writer = struct {
17631760 try stream.writeAll(",\n");
17641761 }
17651762
1766 self.parent_decl_node = prev_parent_decl_node;
17671763 self.indent -= 2;
17681764 try stream.writeByteNTimes(' ', self.indent);
1769 try stream.writeAll("})");
1770 try self.writeSrcNode(stream, extra.data.src_node);
1765 try stream.writeAll("}) ");
1766 try self.writeSrcNode(stream, 0);
17711767 }
17721768
17731769 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
17741770 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17751771
17761772 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);
1773
1774 const prev_parent_decl_node = self.parent_decl_node;
1775 self.parent_decl_node = extra.data.src_node;
1776 defer self.parent_decl_node = prev_parent_decl_node;
1777
17771778 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
17781779 extra.data.fields_hash_0,
17791780 extra.data.fields_hash_1,
......@@ -1835,10 +1836,6 @@ const Writer = struct {
18351836 if (decls_len == 0) {
18361837 try stream.writeAll("{}, ");
18371838 } else {
1838 const prev_parent_decl_node = self.parent_decl_node;
1839 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1840 defer self.parent_decl_node = prev_parent_decl_node;
1841
18421839 try stream.writeAll("{\n");
18431840 self.indent += 2;
18441841 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
......@@ -1856,12 +1853,9 @@ const Writer = struct {
18561853 const body = self.code.bodySlice(extra_index, body_len);
18571854 extra_index += body.len;
18581855
1859 const prev_parent_decl_node = self.parent_decl_node;
1860 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
18611856 try self.writeBracedDecl(stream, body);
18621857 if (fields_len == 0) {
1863 try stream.writeAll(", {})");
1864 self.parent_decl_node = prev_parent_decl_node;
1858 try stream.writeAll(", {}) ");
18651859 } else {
18661860 try stream.writeAll(", {\n");
18671861
......@@ -1900,12 +1894,11 @@ const Writer = struct {
19001894 }
19011895 try stream.writeAll(",\n");
19021896 }
1903 self.parent_decl_node = prev_parent_decl_node;
19041897 self.indent -= 2;
19051898 try stream.writeByteNTimes(' ', self.indent);
1906 try stream.writeAll("})");
1899 try stream.writeAll("}) ");
19071900 }
1908 try self.writeSrcNode(stream, extra.data.src_node);
1901 try self.writeSrcNode(stream, 0);
19091902 }
19101903
19111904 fn writeOpaqueDecl(
......@@ -1915,6 +1908,11 @@ const Writer = struct {
19151908 ) !void {
19161909 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
19171910 const extra = self.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
1911
1912 const prev_parent_decl_node = self.parent_decl_node;
1913 self.parent_decl_node = extra.data.src_node;
1914 defer self.parent_decl_node = prev_parent_decl_node;
1915
19181916 var extra_index: usize = extra.end;
19191917
19201918 const captures_len = if (small.has_captures_len) blk: {
......@@ -1946,20 +1944,16 @@ const Writer = struct {
19461944 }
19471945
19481946 if (decls_len == 0) {
1949 try stream.writeAll("{})");
1947 try stream.writeAll("{}) ");
19501948 } else {
1951 const prev_parent_decl_node = self.parent_decl_node;
1952 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1953 defer self.parent_decl_node = prev_parent_decl_node;
1954
19551949 try stream.writeAll("{\n");
19561950 self.indent += 2;
19571951 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
19581952 self.indent -= 2;
19591953 try stream.writeByteNTimes(' ', self.indent);
1960 try stream.writeAll("})");
1954 try stream.writeAll("}) ");
19611955 }
1962 try self.writeSrcNode(stream, extra.data.src_node);
1956 try self.writeSrcNode(stream, 0);
19631957 }
19641958
19651959 fn writeErrorSetDecl(
......@@ -1988,7 +1982,7 @@ const Writer = struct {
19881982 try stream.writeByteNTimes(' ', self.indent);
19891983 try stream.writeAll("}) ");
19901984
1991 try self.writeSrc(stream, inst_data.src());
1985 try self.writeSrcNode(stream, inst_data.src_node);
19921986 }
19931987
19941988 fn writeSwitchBlockErrUnion(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2125,7 +2119,7 @@ const Writer = struct {
21252119 self.indent -= 2;
21262120
21272121 try stream.writeAll(") ");
2128 try self.writeSrc(stream, inst_data.src());
2122 try self.writeSrcNode(stream, inst_data.src_node);
21292123 }
21302124
21312125 fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2255,7 +2249,7 @@ const Writer = struct {
22552249 self.indent -= 2;
22562250
22572251 try stream.writeAll(") ");
2258 try self.writeSrc(stream, inst_data.src());
2252 try self.writeSrcNode(stream, inst_data.src_node);
22592253 }
22602254
22612255 fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2264,7 +2258,7 @@ const Writer = struct {
22642258 const name = self.code.nullTerminatedString(extra.field_name_start);
22652259 try self.writeInstRef(stream, extra.lhs);
22662260 try stream.print(", \"{}\") ", .{std.zig.fmtEscapes(name)});
2267 try self.writeSrc(stream, inst_data.src());
2261 try self.writeSrcNode(stream, inst_data.src_node);
22682262 }
22692263
22702264 fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2274,7 +2268,7 @@ const Writer = struct {
22742268 try stream.writeAll(", ");
22752269 try self.writeInstRef(stream, extra.field_name);
22762270 try stream.writeAll(") ");
2277 try self.writeSrc(stream, inst_data.src());
2271 try self.writeSrcNode(stream, inst_data.src_node);
22782272 }
22792273
22802274 fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2284,7 +2278,7 @@ const Writer = struct {
22842278 try stream.writeAll(", ");
22852279 try self.writeInstRef(stream, extra.operand);
22862280 try stream.writeAll(") ");
2287 try self.writeSrc(stream, inst_data.src());
2281 try self.writeSrcNode(stream, inst_data.src_node);
22882282 }
22892283
22902284 fn writeNode(
......@@ -2293,9 +2287,8 @@ const Writer = struct {
22932287 inst: Zir.Inst.Index,
22942288 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
22952289 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
2296 const src = LazySrcLoc.nodeOffset(src_node);
22972290 try stream.writeAll(") ");
2298 try self.writeSrc(stream, src);
2291 try self.writeSrcNode(stream, src_node);
22992292 }
23002293
23012294 fn writeStrTok(
......@@ -2306,7 +2299,7 @@ const Writer = struct {
23062299 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
23072300 const str = inst_data.get(self.code);
23082301 try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)});
2309 try self.writeSrc(stream, inst_data.src());
2302 try self.writeSrcTok(stream, inst_data.src_tok);
23102303 }
23112304
23122305 fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2323,7 +2316,6 @@ const Writer = struct {
23232316 inferred_error_set: bool,
23242317 ) !void {
23252318 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2326 const src = inst_data.src();
23272319 const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index);
23282320
23292321 var extra_index = extra.end;
......@@ -2370,7 +2362,7 @@ const Writer = struct {
23702362 ret_ty_body,
23712363
23722364 body,
2373 src,
2365 inst_data.src_node,
23742366 src_locs,
23752367 0,
23762368 );
......@@ -2379,7 +2371,6 @@ const Writer = struct {
23792371 fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
23802372 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23812373 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
2382 const src = inst_data.src();
23832374
23842375 var extra_index: usize = extra.end;
23852376 var align_ref: Zir.Inst.Ref = .none;
......@@ -2476,7 +2467,7 @@ const Writer = struct {
24762467 ret_ty_ref,
24772468 ret_ty_body,
24782469 body,
2479 src,
2470 inst_data.src_node,
24802471 src_locs,
24812472 noalias_bits,
24822473 );
......@@ -2515,7 +2506,6 @@ const Writer = struct {
25152506 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
25162507 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
25172508 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
2518 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
25192509
25202510 var extra_index: usize = extra.end;
25212511 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
......@@ -2533,7 +2523,7 @@ const Writer = struct {
25332523 try self.writeOptionalInstRef(stream, ",ty=", type_inst);
25342524 try self.writeOptionalInstRef(stream, ",align=", align_inst);
25352525 try stream.writeAll(")) ");
2536 try self.writeSrc(stream, src);
2526 try self.writeSrcNode(stream, extra.data.src_node);
25372527 }
25382528
25392529 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
......@@ -2557,7 +2547,7 @@ const Writer = struct {
25572547 try stream.writeAll(", ");
25582548 try self.writeBracedBody(stream, body);
25592549 try stream.writeAll(") ");
2560 try self.writeSrc(stream, inst_data.src());
2550 try self.writeSrcNode(stream, inst_data.src_node);
25612551 }
25622552
25632553 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2567,7 +2557,7 @@ const Writer = struct {
25672557 .unsigned => 'u',
25682558 };
25692559 try stream.print("{c}{d}) ", .{ prefix, int_type.bit_count });
2570 try self.writeSrc(stream, int_type.src());
2560 try self.writeSrcNode(stream, int_type.src_node);
25712561 }
25722562
25732563 fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2585,7 +2575,7 @@ const Writer = struct {
25852575 try self.writeInstRef(stream, extra.operand);
25862576
25872577 try stream.writeAll(") ");
2588 try self.writeSrc(stream, extra.src());
2578 try self.writeSrcNode(stream, extra.src_node);
25892579 }
25902580
25912581 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2611,7 +2601,7 @@ const Writer = struct {
26112601 try self.writeInstRef(stream, arg);
26122602 }
26132603 try stream.writeAll("}) ");
2614 try self.writeSrc(stream, inst_data.src());
2604 try self.writeSrcNode(stream, inst_data.src_node);
26152605 }
26162606
26172607 fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2626,7 +2616,7 @@ const Writer = struct {
26262616 try self.writeInstRef(stream, arg);
26272617 }
26282618 try stream.writeAll("}) ");
2629 try self.writeSrc(stream, inst_data.src());
2619 try self.writeSrcNode(stream, inst_data.src_node);
26302620 }
26312621
26322622 fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2646,13 +2636,13 @@ const Writer = struct {
26462636 try self.writeInstRef(stream, elem);
26472637 }
26482638 try stream.writeAll("}) ");
2649 try self.writeSrc(stream, inst_data.src());
2639 try self.writeSrcNode(stream, inst_data.src_node);
26502640 }
26512641
26522642 fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
26532643 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
26542644 try stream.writeAll(") ");
2655 try self.writeSrc(stream, inst_data.src());
2645 try self.writeSrcNode(stream, inst_data.src_node);
26562646 }
26572647
26582648 fn writeFuncCommon(
......@@ -2673,7 +2663,7 @@ const Writer = struct {
26732663 ret_ty_ref: Zir.Inst.Ref,
26742664 ret_ty_body: []const Zir.Inst.Index,
26752665 body: []const Zir.Inst.Index,
2676 src: LazySrcLoc,
2666 src_node: i32,
26772667 src_locs: Zir.Inst.Func.SrcLocs,
26782668 noalias_bits: u32,
26792669 ) !void {
......@@ -2700,7 +2690,7 @@ const Writer = struct {
27002690 src_locs.rbrace_line + 1, @as(u16, @truncate(src_locs.columns >> 16)) + 1,
27012691 });
27022692 }
2703 try self.writeSrc(stream, src);
2693 try self.writeSrcNode(stream, src_node);
27042694 }
27052695
27062696 fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -2729,11 +2719,16 @@ const Writer = struct {
27292719 }
27302720
27312721 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2732 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2722 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration;
27332723 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);
27342724 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {
27352725 break :dc @enumFromInt(self.code.extra[extra.end]);
27362726 } else null;
2727
2728 const prev_parent_decl_node = self.parent_decl_node;
2729 defer self.parent_decl_node = prev_parent_decl_node;
2730 self.parent_decl_node = inst_data.src_node;
2731
27372732 if (extra.data.flags.is_pub) try stream.writeAll("pub ");
27382733 if (extra.data.flags.is_export) try stream.writeAll("export ");
27392734 switch (extra.data.name) {
......@@ -2757,10 +2752,6 @@ const Writer = struct {
27572752 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });
27582753
27592754 {
2760 const prev_parent_decl_node = self.parent_decl_node;
2761 defer self.parent_decl_node = prev_parent_decl_node;
2762 self.parent_decl_node = self.relativeToNodeIndex(inst_data.src_node);
2763
27642755 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);
27652756
27662757 try stream.writeAll(" value=");
......@@ -2783,13 +2774,12 @@ const Writer = struct {
27832774 }
27842775
27852776 try stream.writeAll(") ");
2786 try self.writeSrc(stream, inst_data.src());
2777 try self.writeSrcNode(stream, 0);
27872778 }
27882779
27892780 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2790 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
27912781 try stream.print("{d})) ", .{extended.small});
2792 try self.writeSrc(stream, src);
2782 try self.writeSrcNode(stream, @bitCast(extended.operand));
27932783 }
27942784
27952785 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
......@@ -2865,29 +2855,44 @@ const Writer = struct {
28652855 try stream.writeAll(name);
28662856 }
28672857
2868 fn writeSrc(self: *Writer, stream: anytype, src: LazySrcLoc) !void {
2869 if (self.file.tree_loaded) {
2870 const tree = self.file.tree;
2871 const src_loc: Module.SrcLoc = .{
2872 .file_scope = self.file,
2873 .parent_decl_node = self.parent_decl_node,
2874 .lazy = src,
2875 };
2876 const src_span = src_loc.span(self.gpa) catch unreachable;
2877 const start = self.line_col_cursor.find(tree.source, src_span.start);
2878 const end = self.line_col_cursor.find(tree.source, src_span.end);
2879 try stream.print("{s}:{d}:{d} to :{d}:{d}", .{
2880 @tagName(src), start.line + 1, start.column + 1,
2881 end.line + 1, end.column + 1,
2882 });
2883 }
2858 fn writeSrcNode(self: *Writer, stream: anytype, src_node: i32) !void {
2859 if (!self.file.tree_loaded) return;
2860 const tree = self.file.tree;
2861 const abs_node = self.relativeToNodeIndex(src_node);
2862 const src_span = tree.nodeToSpan(abs_node);
2863 const start = self.line_col_cursor.find(tree.source, src_span.start);
2864 const end = self.line_col_cursor.find(tree.source, src_span.end);
2865 try stream.print("node_offset:{d}:{d} to :{d}:{d}", .{
2866 start.line + 1, start.column + 1,
2867 end.line + 1, end.column + 1,
2868 });
28842869 }
28852870
2886 fn writeSrcNode(self: *Writer, stream: anytype, src_node: ?i32) !void {
2887 const node_offset = src_node orelse return;
2888 const src = LazySrcLoc.nodeOffset(node_offset);
2889 try stream.writeAll(" ");
2890 return self.writeSrc(stream, src);
2871 fn writeSrcTok(self: *Writer, stream: anytype, src_tok: u32) !void {
2872 if (!self.file.tree_loaded) return;
2873 const tree = self.file.tree;
2874 const abs_tok = tree.firstToken(self.parent_decl_node) + src_tok;
2875 const span_start = tree.tokens.items(.start)[abs_tok];
2876 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(abs_tok).len));
2877 const start = self.line_col_cursor.find(tree.source, span_start);
2878 const end = self.line_col_cursor.find(tree.source, span_end);
2879 try stream.print("token_offset:{d}:{d} to :{d}:{d}", .{
2880 start.line + 1, start.column + 1,
2881 end.line + 1, end.column + 1,
2882 });
2883 }
2884
2885 fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: u32) !void {
2886 if (!self.file.tree_loaded) return;
2887 const tree = self.file.tree;
2888 const span_start = tree.tokens.items(.start)[src_tok];
2889 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
2890 const start = self.line_col_cursor.find(tree.source, span_start);
2891 const end = self.line_col_cursor.find(tree.source, span_end);
2892 try stream.print("token_abs:{d}:{d} to :{d}:{d}", .{
2893 start.line + 1, start.column + 1,
2894 end.line + 1, end.column + 1,
2895 });
28912896 }
28922897
28932898 fn writeBracedDecl(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
src/type.zig+20-9
......@@ -3317,15 +3317,6 @@ pub const Type = struct {
33173317 }
33183318 }
33193319
3320 pub fn declSrcLoc(ty: Type, mod: *Module) Module.SrcLoc {
3321 return declSrcLocOrNull(ty, mod).?;
3322 }
3323
3324 pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc {
3325 const decl = ty.getOwnerDeclOrNull(mod) orelse return null;
3326 return mod.declPtr(decl).srcLoc(mod);
3327 }
3328
33293320 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
33303321 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
33313322 }
......@@ -3341,6 +3332,26 @@ pub const Type = struct {
33413332 };
33423333 }
33433334
3335 pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
3336 const ip = &zcu.intern_pool;
3337 return .{
3338 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
3339 .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {
3340 .declared => |d| d.zir_index,
3341 .reified => |r| r.zir_index,
3342 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index, // must be declared since we can't generate tags when reifying
3343 .empty_struct => return null,
3344 },
3345 else => return null,
3346 },
3347 .offset = Module.LazySrcLoc.Offset.nodeOffset(0),
3348 };
3349 }
3350
3351 pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc {
3352 return ty.srcLocOrNull(zcu).?;
3353 }
3354
33443355 pub fn isGenericPoison(ty: Type) bool {
33453356 return ty.toIntern() == .generic_poison_type;
33463357 }
test/cases/compile_errors/enum_value_already_taken.zig+1-1
......@@ -15,4 +15,4 @@ export fn entry() void {
1515// target=native
1616//
1717// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here
18// :4:9: note: other occurrence here
test/cases/compile_errors/export_function_with_comptime_parameter.zig+1-1
......@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
66// backend=stage2
77// target=native
88//
9// :1:27: error: comptime parameters not allowed in function with calling convention 'C'
9// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/export_generic_function.zig+1-1
......@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
77// backend=stage2
88// target=native
99//
10// :1:20: error: generic parameters not allowed in function with calling convention 'C'
10// :1:15: error: generic parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/extern_function_with_comptime_parameter.zig+1-1
......@@ -19,5 +19,5 @@ comptime {
1919// target=native
2020//
2121// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
22// :6:41: error: generic parameters not allowed in function with calling convention 'C'
22// :6:30: error: generic parameters not allowed in function with calling convention 'C'
2323// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/missing_field_in_struct_value_expression.zig+2-2
......@@ -27,9 +27,9 @@ export fn h() void {
2727// target=native
2828//
2929// :9:16: error: missing struct field: x
30// :1:11: note: struct 'tmp.A' declared here
30// :1:11: note: struct declared here
3131// :18:16: error: missing tuple field with index 1
3232// :16:11: note: struct declared here
3333// :22:16: error: missing tuple field with index 0
3434// :22:16: note: missing tuple field with index 1
35// :16:11: note: struct 'tmp.B' declared here
35// :16:11: note: struct declared here
test/cases/compile_errors/missing_struct_field_in_fn_called_at_comptime.zig+1-1
......@@ -14,5 +14,5 @@ comptime {
1414// target=native
1515//
1616// :5:17: error: missing struct field: b
17// :1:11: note: struct 'tmp.S' declared here
17// :1:11: note: struct declared here
1818// :9:15: note: called from here
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig+2-2
......@@ -17,5 +17,5 @@ pub export fn entr2() void {
1717// backend=stage2
1818// target=native
1919//
20// :4:9: error: range start value is greater than the end value
21// :11:9: error: range start value is greater than the end value
20// :4:10: error: range start value is greater than the end value
21// :11:11: error: range start value is greater than the end value
test/cases/compile_errors/union_auto-enum_value_already_taken.zig+2-2
......@@ -14,5 +14,5 @@ export fn entry() void {
1414// backend=stage2
1515// target=native
1616//
17// :6:5: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here
17// :6:9: error: enum tag value 60 already taken
18// :4:9: note: other occurrence here