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![...@@ -350,379 +350,6 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![
350 return buffer.toOwnedSlice();350 return buffer.toOwnedSlice();
351}351}
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
726const std = @import("std.zig");353const std = @import("std.zig");
727const tokenizer = @import("zig/tokenizer.zig");354const tokenizer = @import("zig/tokenizer.zig");
728const assert = std.debug.assert;355const assert = std.debug.assert;
lib/std/zig/AstGen.zig+32-12
...@@ -4011,7 +4011,7 @@ fn fnDecl(...@@ -4011,7 +4011,7 @@ fn fnDecl(
40114011
4012 // We insert this at the beginning so that its instruction index marks the4012 // We insert this at the beginning so that its instruction index marks the
4013 // start of the top level declaration.4013 // 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);
4015 astgen.advanceSourceCursorToNode(decl_node);4015 astgen.advanceSourceCursorToNode(decl_node);
40164016
4017 var decl_gz: GenZir = .{4017 var decl_gz: GenZir = .{
...@@ -4393,7 +4393,7 @@ fn globalVarDecl(...@@ -4393,7 +4393,7 @@ fn globalVarDecl(
4393 const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;4393 const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;
4394 // We do this at the beginning so that the instruction index marks the range start4394 // We do this at the beginning so that the instruction index marks the range start
4395 // of the top level declaration.4395 // of the top level declaration.
4396 const decl_inst = try gz.makeBlockInst(.declaration, node);4396 const decl_inst = try gz.makeDeclaration(node);
43974397
4398 const name_token = var_decl.ast.mut_token + 1;4398 const name_token = var_decl.ast.mut_token + 1;
4399 astgen.advanceSourceCursorToNode(node);4399 astgen.advanceSourceCursorToNode(node);
...@@ -4555,7 +4555,7 @@ fn comptimeDecl(...@@ -4555,7 +4555,7 @@ fn comptimeDecl(
45554555
4556 // Up top so the ZIR instruction index marks the start range of this4556 // Up top so the ZIR instruction index marks the start range of this
4557 // top-level declaration.4557 // top-level declaration.
4558 const decl_inst = try gz.makeBlockInst(.declaration, node);4558 const decl_inst = try gz.makeDeclaration(node);
4559 wip_members.nextDecl(decl_inst);4559 wip_members.nextDecl(decl_inst);
4560 astgen.advanceSourceCursorToNode(node);4560 astgen.advanceSourceCursorToNode(node);
45614561
...@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(...@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(
4607 };4607 };
4608 // Up top so the ZIR instruction index marks the start range of this4608 // Up top so the ZIR instruction index marks the start range of this
4609 // top-level declaration.4609 // top-level declaration.
4610 const decl_inst = try gz.makeBlockInst(.declaration, node);4610 const decl_inst = try gz.makeDeclaration(node);
4611 wip_members.nextDecl(decl_inst);4611 wip_members.nextDecl(decl_inst);
4612 astgen.advanceSourceCursorToNode(node);4612 astgen.advanceSourceCursorToNode(node);
46134613
...@@ -4651,7 +4651,7 @@ fn testDecl(...@@ -4651,7 +4651,7 @@ fn testDecl(
46514651
4652 // Up top so the ZIR instruction index marks the start range of this4652 // Up top so the ZIR instruction index marks the start range of this
4653 // top-level declaration.4653 // top-level declaration.
4654 const decl_inst = try gz.makeBlockInst(.declaration, node);4654 const decl_inst = try gz.makeDeclaration(node);
46554655
4656 wip_members.nextDecl(decl_inst);4656 wip_members.nextDecl(decl_inst);
4657 astgen.advanceSourceCursorToNode(node);4657 astgen.advanceSourceCursorToNode(node);
...@@ -9366,9 +9366,10 @@ fn builtinCall(...@@ -9366,9 +9366,10 @@ fn builtinCall(
9366 try gz.instructions.ensureUnusedCapacity(gpa, 1);9366 try gz.instructions.ensureUnusedCapacity(gpa, 1);
9367 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);9367 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
93689368
9369 const payload_index = try gz.astgen.addExtra(Zir.Inst.UnNode{9369 const payload_index = try gz.astgen.addExtra(Zir.Inst.Reify{
9370 .node = gz.nodeIndexToRelative(node),9370 .node = node, // Absolute node index -- see the definition of `Reify`.
9371 .operand = operand,9371 .operand = operand,
9372 .src_line = astgen.source_line,
9372 });9373 });
9373 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);9374 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
9374 gz.astgen.instructions.appendAssumeCapacity(.{9375 gz.astgen.instructions.appendAssumeCapacity(.{
...@@ -13076,6 +13077,21 @@ const GenZir = struct {...@@ -13076,6 +13077,21 @@ const GenZir = struct {
13076 return new_index;13077 return new_index;
13077 }13078 }
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
13079 /// Note that this returns a `Zir.Inst.Index` not a ref.13095 /// Note that this returns a `Zir.Inst.Index` not a ref.
13080 /// Leaves the `payload_index` field undefined.13096 /// Leaves the `payload_index` field undefined.
13081 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {13097 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
...@@ -13122,7 +13138,8 @@ const GenZir = struct {...@@ -13122,7 +13138,8 @@ const GenZir = struct {
13122 .fields_hash_1 = fields_hash_arr[1],13138 .fields_hash_1 = fields_hash_arr[1],
13123 .fields_hash_2 = fields_hash_arr[2],13139 .fields_hash_2 = fields_hash_arr[2],
13124 .fields_hash_3 = fields_hash_arr[3],13140 .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,
13126 });13143 });
1312713144
13128 if (args.captures_len != 0) {13145 if (args.captures_len != 0) {
...@@ -13182,7 +13199,8 @@ const GenZir = struct {...@@ -13182,7 +13199,8 @@ const GenZir = struct {
13182 .fields_hash_1 = fields_hash_arr[1],13199 .fields_hash_1 = fields_hash_arr[1],
13183 .fields_hash_2 = fields_hash_arr[2],13200 .fields_hash_2 = fields_hash_arr[2],
13184 .fields_hash_3 = fields_hash_arr[3],13201 .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,
13186 });13204 });
1318713205
13188 if (args.tag_type != .none) {13206 if (args.tag_type != .none) {
...@@ -13243,7 +13261,8 @@ const GenZir = struct {...@@ -13243,7 +13261,8 @@ const GenZir = struct {
13243 .fields_hash_1 = fields_hash_arr[1],13261 .fields_hash_1 = fields_hash_arr[1],
13244 .fields_hash_2 = fields_hash_arr[2],13262 .fields_hash_2 = fields_hash_arr[2],
13245 .fields_hash_3 = fields_hash_arr[3],13263 .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,
13247 });13266 });
1324813267
13249 if (args.tag_type != .none) {13268 if (args.tag_type != .none) {
...@@ -13291,7 +13310,8 @@ const GenZir = struct {...@@ -13291,7 +13310,8 @@ const GenZir = struct {
1329113310
13292 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);13311 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);
13293 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{13312 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,
13295 });13315 });
1329613316
13297 if (args.captures_len != 0) {13317 if (args.captures_len != 0) {
...@@ -13902,7 +13922,7 @@ fn setDeclaration(...@@ -13902,7 +13922,7 @@ fn setDeclaration(
13902 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,13922 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
13903 },13923 },
13904 };13924 };
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);
13906 if (extra.flags.has_doc_comment) {13926 if (extra.flags.has_doc_comment) {
13907 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));13927 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));
13908 }13928 }
lib/std/zig/Zir.zig+32-65
...@@ -20,7 +20,6 @@ const BigIntMutable = std.math.big.int.Mutable;...@@ -20,7 +20,6 @@ const BigIntMutable = std.math.big.int.Mutable;
20const Ast = std.zig.Ast;20const Ast = std.zig.Ast;
2121
22const Zir = @This();22const Zir = @This();
23const LazySrcLoc = std.zig.LazySrcLoc;
2423
25instructions: std.MultiArrayList(Inst).Slice,24instructions: std.MultiArrayList(Inst).Slice,
26/// In order to store references to strings in fewer bytes, we copy all25/// In order to store references to strings in fewer bytes, we copy all
...@@ -287,7 +286,7 @@ pub const Inst = struct {...@@ -287,7 +286,7 @@ pub const Inst = struct {
287 /// namespace type, e.g. within a `struct_decl` instruction. It represents a286 /// namespace type, e.g. within a `struct_decl` instruction. It represents a
288 /// single source declaration (`const`/`var`/`fn`), containing the name,287 /// single source declaration (`const`/`var`/`fn`), containing the name,
289 /// attributes, type, and value of the declaration.288 /// 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`.
291 declaration,290 declaration,
292 /// Implements `suspend {...}`.291 /// Implements `suspend {...}`.
293 /// Uses the `pl_node` union field. Payload is `Block`.292 /// Uses the `pl_node` union field. Payload is `Block`.
...@@ -1596,7 +1595,7 @@ pub const Inst = struct {...@@ -1596,7 +1595,7 @@ pub const Inst = struct {
1596 .block = .pl_node,1595 .block = .pl_node,
1597 .block_comptime = .pl_node,1596 .block_comptime = .pl_node,
1598 .block_inline = .pl_node,1597 .block_inline = .pl_node,
1599 .declaration = .pl_node,1598 .declaration = .declaration,
1600 .suspend_block = .pl_node,1599 .suspend_block = .pl_node,
1601 .bool_not = .un_node,1600 .bool_not = .un_node,
1602 .bool_br_and = .pl_node,1601 .bool_br_and = .pl_node,
...@@ -1982,7 +1981,7 @@ pub const Inst = struct {...@@ -1982,7 +1981,7 @@ pub const Inst = struct {
1982 /// `operand` is payload index to `UnNode`.1981 /// `operand` is payload index to `UnNode`.
1983 error_from_int,1982 error_from_int,
1984 /// Implement builtin `@Type`.1983 /// Implement builtin `@Type`.
1985 /// `operand` is payload index to `UnNode`.1984 /// `operand` is payload index to `Reify`.
1986 /// `small` contains `NameStrategy`.1985 /// `small` contains `NameStrategy`.
1987 reify,1986 reify,
1988 /// Implements the `@asyncCall` builtin.1987 /// Implements the `@asyncCall` builtin.
...@@ -2221,10 +2220,6 @@ pub const Inst = struct {...@@ -2221,10 +2220,6 @@ pub const Inst = struct {
2221 src_node: i32,2220 src_node: i32,
2222 /// The meaning of this operand depends on the corresponding `Tag`.2221 /// The meaning of this operand depends on the corresponding `Tag`.
2223 operand: Ref,2222 operand: Ref,
2224
2225 pub fn src(self: @This()) LazySrcLoc {
2226 return LazySrcLoc.nodeOffset(self.src_node);
2227 }
2228 },2223 },
2229 /// Used for unary operators, with a token source location.2224 /// Used for unary operators, with a token source location.
2230 un_tok: struct {2225 un_tok: struct {
...@@ -2232,10 +2227,6 @@ pub const Inst = struct {...@@ -2232,10 +2227,6 @@ pub const Inst = struct {
2232 src_tok: Ast.TokenIndex,2227 src_tok: Ast.TokenIndex,
2233 /// The meaning of this operand depends on the corresponding `Tag`.2228 /// The meaning of this operand depends on the corresponding `Tag`.
2234 operand: Ref,2229 operand: Ref,
2235
2236 pub fn src(self: @This()) LazySrcLoc {
2237 return .{ .token_offset = self.src_tok };
2238 }
2239 },2230 },
2240 pl_node: struct {2231 pl_node: struct {
2241 /// Offset from Decl AST node index.2232 /// Offset from Decl AST node index.
...@@ -2244,10 +2235,6 @@ pub const Inst = struct {...@@ -2244,10 +2235,6 @@ pub const Inst = struct {
2244 /// index into extra.2235 /// index into extra.
2245 /// `Tag` determines what lives there.2236 /// `Tag` determines what lives there.
2246 payload_index: u32,2237 payload_index: u32,
2247
2248 pub fn src(self: @This()) LazySrcLoc {
2249 return LazySrcLoc.nodeOffset(self.src_node);
2250 }
2251 },2238 },
2252 pl_tok: struct {2239 pl_tok: struct {
2253 /// Offset from Decl AST token index.2240 /// Offset from Decl AST token index.
...@@ -2255,10 +2242,6 @@ pub const Inst = struct {...@@ -2255,10 +2242,6 @@ pub const Inst = struct {
2255 /// index into extra.2242 /// index into extra.
2256 /// `Tag` determines what lives there.2243 /// `Tag` determines what lives there.
2257 payload_index: u32,2244 payload_index: u32,
2258
2259 pub fn src(self: @This()) LazySrcLoc {
2260 return .{ .token_offset = self.src_tok };
2261 }
2262 },2245 },
2263 bin: Bin,2246 bin: Bin,
2264 /// For strings which may contain null bytes.2247 /// For strings which may contain null bytes.
...@@ -2281,10 +2264,6 @@ pub const Inst = struct {...@@ -2281,10 +2264,6 @@ pub const Inst = struct {
2281 pub fn get(self: @This(), code: Zir) [:0]const u8 {2264 pub fn get(self: @This(), code: Zir) [:0]const u8 {
2282 return code.nullTerminatedString(self.start);2265 return code.nullTerminatedString(self.start);
2283 }2266 }
2284
2285 pub fn src(self: @This()) LazySrcLoc {
2286 return .{ .token_offset = self.src_tok };
2287 }
2288 },2267 },
2289 /// Offset from Decl AST token index.2268 /// Offset from Decl AST token index.
2290 tok: Ast.TokenIndex,2269 tok: Ast.TokenIndex,
...@@ -2313,19 +2292,11 @@ pub const Inst = struct {...@@ -2313,19 +2292,11 @@ pub const Inst = struct {
2313 src_node: i32,2292 src_node: i32,
2314 signedness: std.builtin.Signedness,2293 signedness: std.builtin.Signedness,
2315 bit_count: u16,2294 bit_count: u16,
2316
2317 pub fn src(self: @This()) LazySrcLoc {
2318 return LazySrcLoc.nodeOffset(self.src_node);
2319 }
2320 },2295 },
2321 @"unreachable": struct {2296 @"unreachable": struct {
2322 /// Offset from Decl AST node index.2297 /// Offset from Decl AST node index.
2323 /// `Tag` determines which kind of AST node this points to.2298 /// `Tag` determines which kind of AST node this points to.
2324 src_node: i32,2299 src_node: i32,
2325
2326 pub fn src(self: @This()) LazySrcLoc {
2327 return LazySrcLoc.nodeOffset(self.src_node);
2328 }
2329 },2300 },
2330 @"break": struct {2301 @"break": struct {
2331 operand: Ref,2302 operand: Ref,
...@@ -2339,10 +2310,6 @@ pub const Inst = struct {...@@ -2339,10 +2310,6 @@ pub const Inst = struct {
2339 src_node: i32,2310 src_node: i32,
2340 /// The meaning of this operand depends on the corresponding `Tag`.2311 /// The meaning of this operand depends on the corresponding `Tag`.
2341 inst: Index,2312 inst: Index,
2342
2343 pub fn src(self: @This()) LazySrcLoc {
2344 return LazySrcLoc.nodeOffset(self.src_node);
2345 }
2346 },2313 },
2347 str_op: struct {2314 str_op: struct {
2348 /// Offset into `string_bytes`. Null-terminated.2315 /// Offset into `string_bytes`. Null-terminated.
...@@ -2370,6 +2337,12 @@ pub const Inst = struct {...@@ -2370,6 +2337,12 @@ pub const Inst = struct {
2370 /// The index being accessed.2337 /// The index being accessed.
2371 idx: u32,2338 idx: u32,
2372 },2339 },
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
2374 // Make sure we don't accidentally add a field to make this union2347 // Make sure we don't accidentally add a field to make this union
2375 // bigger than expected. Note that in Debug builds, Zig is allowed2348 // bigger than expected. Note that in Debug builds, Zig is allowed
...@@ -2408,6 +2381,7 @@ pub const Inst = struct {...@@ -2408,6 +2381,7 @@ pub const Inst = struct {
2408 defer_err_code,2381 defer_err_code,
2409 save_err_ret_index,2382 save_err_ret_index,
2410 elem_val_imm,2383 elem_val_imm,
2384 declaration,
2411 };2385 };
2412 };2386 };
24132387
...@@ -2860,6 +2834,14 @@ pub const Inst = struct {...@@ -2860,6 +2834,14 @@ pub const Inst = struct {
2860 index: u32,2834 index: u32,
2861 };2835 };
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
2863 pub const SwitchBlockErrUnion = struct {2845 pub const SwitchBlockErrUnion = struct {
2864 operand: Ref,2846 operand: Ref,
2865 bits: Bits,2847 bits: Bits,
...@@ -3018,11 +3000,9 @@ pub const Inst = struct {...@@ -3018,11 +3000,9 @@ pub const Inst = struct {
3018 fields_hash_1: u32,3000 fields_hash_1: u32,
3019 fields_hash_2: u32,3001 fields_hash_2: u32,
3020 fields_hash_3: u32,3002 fields_hash_3: u32,
3021 src_node: i32,3003 src_line: u32,
30223004 /// This node provides a new absolute baseline node for all instructions within this struct.
3023 pub fn src(self: StructDecl) LazySrcLoc {3005 src_node: Ast.Node.Index,
3024 return LazySrcLoc.nodeOffset(self.src_node);
3025 }
30263006
3027 pub const Small = packed struct {3007 pub const Small = packed struct {
3028 has_captures_len: bool,3008 has_captures_len: bool,
...@@ -3150,11 +3130,9 @@ pub const Inst = struct {...@@ -3150,11 +3130,9 @@ pub const Inst = struct {
3150 fields_hash_1: u32,3130 fields_hash_1: u32,
3151 fields_hash_2: u32,3131 fields_hash_2: u32,
3152 fields_hash_3: u32,3132 fields_hash_3: u32,
3153 src_node: i32,3133 src_line: u32,
31543134 /// This node provides a new absolute baseline node for all instructions within this struct.
3155 pub fn src(self: EnumDecl) LazySrcLoc {3135 src_node: Ast.Node.Index,
3156 return LazySrcLoc.nodeOffset(self.src_node);
3157 }
31583136
3159 pub const Small = packed struct {3137 pub const Small = packed struct {
3160 has_tag_type: bool,3138 has_tag_type: bool,
...@@ -3198,11 +3176,9 @@ pub const Inst = struct {...@@ -3198,11 +3176,9 @@ pub const Inst = struct {
3198 fields_hash_1: u32,3176 fields_hash_1: u32,
3199 fields_hash_2: u32,3177 fields_hash_2: u32,
3200 fields_hash_3: u32,3178 fields_hash_3: u32,
3201 src_node: i32,3179 src_line: u32,
32023180 /// This node provides a new absolute baseline node for all instructions within this struct.
3203 pub fn src(self: UnionDecl) LazySrcLoc {3181 src_node: Ast.Node.Index,
3204 return LazySrcLoc.nodeOffset(self.src_node);
3205 }
32063182
3207 pub const Small = packed struct {3183 pub const Small = packed struct {
3208 has_tag_type: bool,3184 has_tag_type: bool,
...@@ -3230,11 +3206,9 @@ pub const Inst = struct {...@@ -3230,11 +3206,9 @@ pub const Inst = struct {
3230 /// 2. capture: Capture, // for every captures_len3206 /// 2. capture: Capture, // for every captures_len
3231 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction3207 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
3232 pub const OpaqueDecl = struct {3208 pub const OpaqueDecl = struct {
3233 src_node: i32,3209 src_line: u32,
32343210 /// This node provides a new absolute baseline node for all instructions within this struct.
3235 pub fn src(self: OpaqueDecl) LazySrcLoc {3211 src_node: Ast.Node.Index,
3236 return LazySrcLoc.nodeOffset(self.src_node);
3237 }
32383212
3239 pub const Small = packed struct {3213 pub const Small = packed struct {
3240 has_captures_len: bool,3214 has_captures_len: bool,
...@@ -3352,10 +3326,6 @@ pub const Inst = struct {...@@ -3352,10 +3326,6 @@ pub const Inst = struct {
3352 parent_ptr_type: Ref,3326 parent_ptr_type: Ref,
3353 field_name: Ref,3327 field_name: Ref,
3354 field_ptr: Ref,3328 field_ptr: Ref,
3355
3356 pub fn src(self: FieldParentPtr) LazySrcLoc {
3357 return LazySrcLoc.nodeOffset(self.src_node);
3358 }
3359 };3329 };
33603330
3361 pub const Shuffle = struct {3331 pub const Shuffle = struct {
...@@ -3505,10 +3475,6 @@ pub const Inst = struct {...@@ -3505,10 +3475,6 @@ pub const Inst = struct {
3505 block: Ref,3475 block: Ref,
3506 /// If `.none`, restore unconditionally.3476 /// If `.none`, restore unconditionally.
3507 operand: Ref,3477 operand: Ref,
3508
3509 pub fn src(self: RestoreErrRetIndex) LazySrcLoc {
3510 return LazySrcLoc.nodeOffset(self.src_node);
3511 }
3512 };3478 };
3513};3479};
35143480
...@@ -3772,6 +3738,7 @@ fn findDeclsInner(...@@ -3772,6 +3738,7 @@ fn findDeclsInner(
3772 .union_decl,3738 .union_decl,
3773 .enum_decl,3739 .enum_decl,
3774 .opaque_decl,3740 .opaque_decl,
3741 .reify,
3775 => return list.append(inst),3742 => return list.append(inst),
37763743
3777 else => return,3744 else => return,
...@@ -4046,7 +4013,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -4046,7 +4013,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
40464013
4047pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {4014pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {
4048 assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);4015 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;
4050 const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);4017 const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);
4051 return .{4018 return .{
4052 extra.data,4019 extra.data,
src/Compilation.zig+17-20
...@@ -2639,7 +2639,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2639,7 +2639,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2639 .root => |pkg| blk: {2639 .root => |pkg| blk: {
2640 break :blk try Module.ErrorMsg.init(2640 break :blk try Module.ErrorMsg.init(
2641 mod.gpa,2641 mod.gpa,
2642 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2642 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2643 "root of module {s}",2643 "root of module {s}",
2644 .{pkg.fully_qualified_name},2644 .{pkg.fully_qualified_name},
2645 );2645 );
...@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2651 if (omitted > 0) {2651 if (omitted > 0) {
2652 notes[num_notes] = try Module.ErrorMsg.init(2652 notes[num_notes] = try Module.ErrorMsg.init(
2653 mod.gpa,2653 mod.gpa,
2654 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2654 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2655 "{} more references omitted",2655 "{} more references omitted",
2656 .{omitted},2656 .{omitted},
2657 );2657 );
...@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26602660
2661 const err = try Module.ErrorMsg.create(2661 const err = try Module.ErrorMsg.create(
2662 mod.gpa,2662 mod.gpa,
2663 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2663 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2664 "file exists in multiple modules",2664 "file exists in multiple modules",
2665 .{},2665 .{},
2666 );2666 );
...@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3040 }3040 }
3041 }3041 }
30423042
3043 if (comp.module) |module| {3043 if (comp.module) |zcu| {
3044 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {3044 if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
3045 const keys = module.compile_log_decls.keys();3045 const values = zcu.compile_log_decls.values();
3046 const values = module.compile_log_decls.values();
3047 // First one will be the error; subsequent ones will be notes.3046 // First one will be the error; subsequent ones will be notes.
3048 const err_decl = module.declPtr(keys[0]);3047 const src_loc = values[0].src().upgrade(zcu);
3049 const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module);3048 const err_msg: Module.ErrorMsg = .{
3050 const err_msg = Module.ErrorMsg{
3051 .src_loc = src_loc,3049 .src_loc = src_loc,
3052 .msg = "found compile log statement",3050 .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),
3054 };3052 };
3055 defer gpa.free(err_msg.notes);3053 defer gpa.free(err_msg.notes);
30563054
3057 for (keys[1..], 0..) |key, i| {3055 for (values[1..], err_msg.notes) |src_info, *note| {
3058 const note_decl = module.declPtr(key);3056 note.* = .{
3059 err_msg.notes[i] = .{3057 .src_loc = src_info.src().upgrade(zcu),
3060 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module),
3061 .msg = "also here",3058 .msg = "also here",
3062 };3059 };
3063 }3060 }
30643061
3065 try addModuleErrorMsg(module, &bundle, err_msg);3062 try addModuleErrorMsg(zcu, &bundle, err_msg);
3066 }3063 }
3067 }3064 }
30683065
...@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo...@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
3492 try module.failed_decls.ensureUnusedCapacity(gpa, 1);3489 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
3493 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(3490 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3494 gpa,3491 gpa,
3495 decl.srcLoc(module),3492 decl.navSrcLoc(module).upgrade(module),
3496 "unable to update line number: {s}",3493 "unable to update line number: {s}",
3497 .{@errorName(err)},3494 .{@errorName(err)},
3498 ));3495 ));
...@@ -3993,7 +3990,7 @@ fn workerAstGenFile(...@@ -3993,7 +3990,7 @@ fn workerAstGenFile(
3993 if (!res.is_pkg) {3990 if (!res.is_pkg) {
3994 res.file.addReference(mod.*, .{ .import = .{3991 res.file.addReference(mod.*, .{ .import = .{
3995 .file_scope = file,3992 .file_scope = file,
3996 .parent_decl_node = 0,3993 .base_node = 0,
3997 .lazy = .{ .token_abs = item.data.token },3994 .lazy = .{ .token_abs = item.data.token },
3998 } }) catch continue;3995 } }) catch continue;
3999 }3996 }
...@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(...@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(
4370 const src_loc: Module.SrcLoc = switch (src) {4367 const src_loc: Module.SrcLoc = switch (src) {
4371 .root => .{4368 .root => .{
4372 .file_scope = file,4369 .file_scope = file,
4373 .parent_decl_node = 0,4370 .base_node = 0,
4374 .lazy = .entire_file,4371 .lazy = .entire_file,
4375 },4372 },
4376 .import => |info| blk: {4373 .import => |info| blk: {
...@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(...@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(
43784375
4379 break :blk .{4376 break :blk .{
4380 .file_scope = importing_file,4377 .file_scope = importing_file,
4381 .parent_decl_node = 0,4378 .base_node = 0,
4382 .lazy = .{ .token_abs = info.import_tok },4379 .lazy = .{ .token_abs = info.import_tok },
4383 };4380 };
4384 },4381 },
src/InternPool.zig+25-4
...@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {...@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {
101 }101 }
102 pub const Index = enum(u32) {102 pub const Index = enum(u32) {
103 _,103 _,
104 pub fn resolveFull(i: TrackedInst.Index, ip: *const InternPool) TrackedInst {
105 return ip.tracked_insts.keys()[@intFromEnum(i)];
106 }
104 pub fn resolve(i: TrackedInst.Index, ip: *const InternPool) Zir.Inst.Index {107 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;
106 }109 }
107 pub fn toOptional(i: TrackedInst.Index) Optional {110 pub fn toOptional(i: TrackedInst.Index) Optional {
108 return @enumFromInt(@intFromEnum(i));111 return @enumFromInt(@intFromEnum(i));
...@@ -391,8 +394,27 @@ pub const RuntimeIndex = enum(u32) {...@@ -391,8 +394,27 @@ pub const RuntimeIndex = enum(u32) {
391394
392pub const ComptimeAllocIndex = enum(u32) { _ };395pub const ComptimeAllocIndex = enum(u32) { _ };
393396
394pub const DeclIndex = std.zig.DeclIndex;397pub const DeclIndex = enum(u32) {
395pub const OptionalDeclIndex = std.zig.OptionalDeclIndex;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
397pub const NamespaceIndex = enum(u32) {419pub const NamespaceIndex = enum(u32) {
398 _,420 _,
...@@ -6935,7 +6957,6 @@ fn finishFuncInstance(...@@ -6935,7 +6957,6 @@ fn finishFuncInstance(
6935 const decl_index = try ip.createDecl(gpa, .{6957 const decl_index = try ip.createDecl(gpa, .{
6936 .name = undefined,6958 .name = undefined,
6937 .src_namespace = fn_owner_decl.src_namespace,6959 .src_namespace = fn_owner_decl.src_namespace,
6938 .src_node = fn_owner_decl.src_node,
6939 .src_line = fn_owner_decl.src_line,6960 .src_line = fn_owner_decl.src_line,
6940 .has_tv = true,6961 .has_tv = true,
6941 .owns_tv = true,6962 .owns_tv = true,
src/Module.zig+826-717
...@@ -13,7 +13,6 @@ const BigIntConst = std.math.big.int.Const;...@@ -13,7 +13,6 @@ const BigIntConst = std.math.big.int.Const;
13const BigIntMutable = std.math.big.int.Mutable;13const BigIntMutable = std.math.big.int.Mutable;
14const Target = std.Target;14const Target = std.Target;
15const Ast = std.zig.Ast;15const Ast = std.zig.Ast;
16const LazySrcLoc = std.zig.LazySrcLoc;
1716
18/// Deprecated, use `Zcu`.17/// Deprecated, use `Zcu`.
19const Module = Zcu;18const Module = Zcu;
...@@ -89,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp...@@ -89,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp
89/// an update is requested, as well as to cache `@import` results.88/// an update is requested, as well as to cache `@import` results.
90/// Keys are fully resolved file paths. This table owns the keys and values.89/// Keys are fully resolved file paths. This table owns the keys and values.
91import_table: std.StringArrayHashMapUnmanaged(*File) = .{},90import_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) = .{},
92/// The set of all the files which have been loaded with `@embedFile` in the Module.94/// The set of all the files which have been loaded with `@embedFile` in the Module.
93/// We keep track of this in order to iterate over it and check which files have been95/// We keep track of this in order to iterate over it and check which files have been
94/// modified on the file system when an update is requested, as well as to cache96/// modified on the file system when an update is requested, as well as to cache
...@@ -108,8 +110,17 @@ intern_pool: InternPool = .{},...@@ -108,8 +110,17 @@ intern_pool: InternPool = .{},
108/// a Decl can have a failed_decls entry but have analysis status of success.110/// a Decl can have a failed_decls entry but have analysis status of success.
109failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},111failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
110/// Keep track of one `@compileLog` callsite per owner Decl.112/// Keep track of one `@compileLog` callsite per owner Decl.
111/// The value is the AST node index offset from the Decl.113/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
112compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, i32) = .{},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}) = .{},
113/// Using a map here for consistency with the other fields here.124/// Using a map here for consistency with the other fields here.
114/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.125/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.
115failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},126failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
...@@ -258,9 +269,6 @@ pub const Export = struct {...@@ -258,9 +269,6 @@ pub const Export = struct {
258 src: LazySrcLoc,269 src: LazySrcLoc,
259 /// The Decl that performs the export. Note that this is *not* the Decl being exported.270 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
260 owner_decl: Decl.Index,271 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,
264 exported: Exported,272 exported: Exported,
265 status: enum {273 status: enum {
266 in_progress,274 in_progress,
...@@ -279,12 +287,7 @@ pub const Export = struct {...@@ -279,12 +287,7 @@ pub const Export = struct {
279 };287 };
280288
281 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {289 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
282 const src_decl = mod.declPtr(exp.src_decl);290 return exp.src.upgrade(mod);
283 return .{
284 .file_scope = src_decl.getFileScope(mod),
285 .parent_decl_node = src_decl.src_node,
286 .lazy = exp.src,
287 };
288 }291 }
289};292};
290293
...@@ -344,9 +347,6 @@ pub const Decl = struct {...@@ -344,9 +347,6 @@ pub const Decl = struct {
344 /// there is no parent.347 /// there is no parent.
345 src_namespace: Namespace.Index,348 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,
350 /// Line number corresponding to `src_node`. Stored separately so that source files350 /// Line number corresponding to `src_node`. Stored separately so that source files
351 /// do not need to be loaded into memory in order to compute debug line numbers.351 /// do not need to be loaded into memory in order to compute debug line numbers.
352 /// This value is absolute.352 /// This value is absolute.
...@@ -413,31 +413,11 @@ pub const Decl = struct {...@@ -413,31 +413,11 @@ pub const Decl = struct {
413 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {413 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {
414 const zir = decl.getFileScope(zcu).zir;414 const zir = decl.getFileScope(zcu).zir;
415 const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool);415 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;416 const declaration = zir.instructions.items(.data)[@intFromEnum(zir_index)].declaration;
417 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);417 const extra = zir.extraData(Zir.Inst.Declaration, declaration.payload_index);
418 return extra.data.getBodies(@intCast(extra.end), zir);418 return extra.data.getBodies(@intCast(extra.end), zir);
419 }419 }
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
441 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {421 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
442 if (decl.name_fully_qualified) {422 if (decl.name_fully_qualified) {
443 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});423 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});
...@@ -552,101 +532,6 @@ pub const Decl = struct {...@@ -552,101 +532,6 @@ pub const Decl = struct {
552 return decl.typeOf(zcu).abiAlignment(zcu);532 return decl.typeOf(zcu).abiAlignment(zcu);
553 }533 }
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
650 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {535 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {
651 assert(decl.has_tv);536 assert(decl.has_tv);
652 const decl_ty = decl.typeOf(zcu);537 const decl_ty = decl.typeOf(zcu);
...@@ -662,6 +547,23 @@ pub const Decl = struct {...@@ -662,6 +547,23 @@ pub const Decl = struct {
662 },547 },
663 });548 });
664 }549 }
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 }
665};567};
666568
667/// This state is attached to every Decl when Module emit_h is non-null.569/// This state is attached to every Decl when Module emit_h is non-null.
...@@ -836,8 +738,7 @@ pub const File = struct {...@@ -836,8 +738,7 @@ pub const File = struct {
836 /// List of references to this file, used for multi-package errors.738 /// List of references to this file, used for multi-package errors.
837 references: std.ArrayListUnmanaged(Reference) = .{},739 references: std.ArrayListUnmanaged(Reference) = .{},
838 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.740 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.
839 /// undefined until `zir_loaded == true`.741 path_digest: Cache.BinDigest,
840 path_digest: Cache.BinDigest = undefined,
841742
842 /// The most recent successful ZIR for this file, with no errors.743 /// The most recent successful ZIR for this file, with no errors.
843 /// This is only populated when a previously successful ZIR744 /// This is only populated when a previously successful ZIR
...@@ -1138,18 +1039,17 @@ pub const ErrorMsg = struct {...@@ -1138,18 +1039,17 @@ pub const ErrorMsg = struct {
1138/// Canonical reference to a position within a source file.1039/// Canonical reference to a position within a source file.
1139pub const SrcLoc = struct {1040pub const SrcLoc = struct {
1140 file_scope: *File,1041 file_scope: *File,
1141 /// Might be 0 depending on tag of `lazy`.1042 base_node: Ast.Node.Index,
1142 parent_decl_node: Ast.Node.Index,1043 /// Relative to `base_node`.
1143 /// Relative to `parent_decl_node`.1044 lazy: LazySrcLoc.Offset,
1144 lazy: LazySrcLoc,
11451045
1146 pub fn declSrcToken(src_loc: SrcLoc) Ast.TokenIndex {1046 pub fn baseSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
1147 const tree = src_loc.file_scope.tree;1047 const tree = src_loc.file_scope.tree;
1148 return tree.firstToken(src_loc.parent_decl_node);1048 return tree.firstToken(src_loc.base_node);
1149 }1049 }
11501050
1151 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {1051 pub fn relativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1152 return @bitCast(offset + @as(i32, @bitCast(src_loc.parent_decl_node)));1052 return @bitCast(offset + @as(i32, @bitCast(src_loc.base_node)));
1153 }1053 }
11541054
1155 pub const Span = Ast.Span;1055 pub const Span = Ast.Span;
...@@ -1173,14 +1073,14 @@ pub const SrcLoc = struct {...@@ -1173,14 +1073,14 @@ pub const SrcLoc = struct {
1173 },1073 },
1174 .byte_offset => |byte_off| {1074 .byte_offset => |byte_off| {
1175 const tree = try src_loc.file_scope.getTree(gpa);1075 const tree = try src_loc.file_scope.getTree(gpa);
1176 const tok_index = src_loc.declSrcToken();1076 const tok_index = src_loc.baseSrcToken();
1177 const start = tree.tokens.items(.start)[tok_index] + byte_off;1077 const start = tree.tokens.items(.start)[tok_index] + byte_off;
1178 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1078 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
1179 return Span{ .start = start, .end = end, .main = start };1079 return Span{ .start = start, .end = end, .main = start };
1180 },1080 },
1181 .token_offset => |tok_off| {1081 .token_offset => |tok_off| {
1182 const tree = try src_loc.file_scope.getTree(gpa);1082 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;
1184 const start = tree.tokens.items(.start)[tok_index];1084 const start = tree.tokens.items(.start)[tok_index];
1185 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1085 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
1186 return Span{ .start = start, .end = end, .main = start };1086 return Span{ .start = start, .end = end, .main = start };
...@@ -1188,25 +1088,25 @@ pub const SrcLoc = struct {...@@ -1188,25 +1088,25 @@ pub const SrcLoc = struct {
1188 .node_offset => |traced_off| {1088 .node_offset => |traced_off| {
1189 const node_off = traced_off.x;1089 const node_off = traced_off.x;
1190 const tree = try src_loc.file_scope.getTree(gpa);1090 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);
1192 assert(src_loc.file_scope.tree_loaded);1092 assert(src_loc.file_scope.tree_loaded);
1193 return tree.nodeToSpan(node);1093 return tree.nodeToSpan(node);
1194 },1094 },
1195 .node_offset_main_token => |node_off| {1095 .node_offset_main_token => |node_off| {
1196 const tree = try src_loc.file_scope.getTree(gpa);1096 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);
1198 const main_token = tree.nodes.items(.main_token)[node];1098 const main_token = tree.nodes.items(.main_token)[node];
1199 return tree.tokensToSpan(main_token, main_token, main_token);1099 return tree.tokensToSpan(main_token, main_token, main_token);
1200 },1100 },
1201 .node_offset_bin_op => |node_off| {1101 .node_offset_bin_op => |node_off| {
1202 const tree = try src_loc.file_scope.getTree(gpa);1102 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);
1204 assert(src_loc.file_scope.tree_loaded);1104 assert(src_loc.file_scope.tree_loaded);
1205 return tree.nodeToSpan(node);1105 return tree.nodeToSpan(node);
1206 },1106 },
1207 .node_offset_initializer => |node_off| {1107 .node_offset_initializer => |node_off| {
1208 const tree = try src_loc.file_scope.getTree(gpa);1108 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);
1210 return tree.tokensToSpan(1110 return tree.tokensToSpan(
1211 tree.firstToken(node) - 3,1111 tree.firstToken(node) - 3,
1212 tree.lastToken(node),1112 tree.lastToken(node),
...@@ -1215,7 +1115,7 @@ pub const SrcLoc = struct {...@@ -1215,7 +1115,7 @@ pub const SrcLoc = struct {
1215 },1115 },
1216 .node_offset_var_decl_ty => |node_off| {1116 .node_offset_var_decl_ty => |node_off| {
1217 const tree = try src_loc.file_scope.getTree(gpa);1117 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);
1219 const node_tags = tree.nodes.items(.tag);1119 const node_tags = tree.nodes.items(.tag);
1220 const full = switch (node_tags[node]) {1120 const full = switch (node_tags[node]) {
1221 .global_var_decl,1121 .global_var_decl,
...@@ -1239,41 +1139,51 @@ pub const SrcLoc = struct {...@@ -1239,41 +1139,51 @@ pub const SrcLoc = struct {
1239 },1139 },
1240 .node_offset_var_decl_align => |node_off| {1140 .node_offset_var_decl_align => |node_off| {
1241 const tree = try src_loc.file_scope.getTree(gpa);1141 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);
1243 const full = tree.fullVarDecl(node).?;1143 const full = tree.fullVarDecl(node).?;
1244 return tree.nodeToSpan(full.ast.align_node);1144 return tree.nodeToSpan(full.ast.align_node);
1245 },1145 },
1246 .node_offset_var_decl_section => |node_off| {1146 .node_offset_var_decl_section => |node_off| {
1247 const tree = try src_loc.file_scope.getTree(gpa);1147 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);
1249 const full = tree.fullVarDecl(node).?;1149 const full = tree.fullVarDecl(node).?;
1250 return tree.nodeToSpan(full.ast.section_node);1150 return tree.nodeToSpan(full.ast.section_node);
1251 },1151 },
1252 .node_offset_var_decl_addrspace => |node_off| {1152 .node_offset_var_decl_addrspace => |node_off| {
1253 const tree = try src_loc.file_scope.getTree(gpa);1153 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);
1255 const full = tree.fullVarDecl(node).?;1155 const full = tree.fullVarDecl(node).?;
1256 return tree.nodeToSpan(full.ast.addrspace_node);1156 return tree.nodeToSpan(full.ast.addrspace_node);
1257 },1157 },
1258 .node_offset_var_decl_init => |node_off| {1158 .node_offset_var_decl_init => |node_off| {
1259 const tree = try src_loc.file_scope.getTree(gpa);1159 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);
1261 const full = tree.fullVarDecl(node).?;1161 const full = tree.fullVarDecl(node).?;
1262 return tree.nodeToSpan(full.ast.init_node);1162 return tree.nodeToSpan(full.ast.init_node);
1263 },1163 },
1264 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),1164 .node_offset_builtin_call_arg => |builtin_arg| {
1265 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),1165 const tree = try src_loc.file_scope.getTree(gpa);
1266 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),1166 const node_datas = tree.nodes.items(.data);
1267 .node_offset_builtin_call_arg3 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 3),1167 const node_tags = tree.nodes.items(.tag);
1268 .node_offset_builtin_call_arg4 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 4),1168 const node = src_loc.relativeToNodeIndex(builtin_arg.builtin_call_node);
1269 .node_offset_builtin_call_arg5 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 5),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 },
1270 .node_offset_ptrcast_operand => |node_off| {1180 .node_offset_ptrcast_operand => |node_off| {
1271 const tree = try src_loc.file_scope.getTree(gpa);1181 const tree = try src_loc.file_scope.getTree(gpa);
1272 const main_tokens = tree.nodes.items(.main_token);1182 const main_tokens = tree.nodes.items(.main_token);
1273 const node_datas = tree.nodes.items(.data);1183 const node_datas = tree.nodes.items(.data);
1274 const node_tags = tree.nodes.items(.tag);1184 const node_tags = tree.nodes.items(.tag);
12751185
1276 var node = src_loc.declRelativeToNodeIndex(node_off);1186 var node = src_loc.relativeToNodeIndex(node_off);
1277 while (true) {1187 while (true) {
1278 switch (node_tags[node]) {1188 switch (node_tags[node]) {
1279 .builtin_call_two, .builtin_call_two_comma => {},1189 .builtin_call_two, .builtin_call_two_comma => {},
...@@ -1305,7 +1215,7 @@ pub const SrcLoc = struct {...@@ -1305,7 +1215,7 @@ pub const SrcLoc = struct {
1305 .node_offset_array_access_index => |node_off| {1215 .node_offset_array_access_index => |node_off| {
1306 const tree = try src_loc.file_scope.getTree(gpa);1216 const tree = try src_loc.file_scope.getTree(gpa);
1307 const node_datas = tree.nodes.items(.data);1217 const node_datas = tree.nodes.items(.data);
1308 const node = src_loc.declRelativeToNodeIndex(node_off);1218 const node = src_loc.relativeToNodeIndex(node_off);
1309 return tree.nodeToSpan(node_datas[node].rhs);1219 return tree.nodeToSpan(node_datas[node].rhs);
1310 },1220 },
1311 .node_offset_slice_ptr,1221 .node_offset_slice_ptr,
...@@ -1314,7 +1224,7 @@ pub const SrcLoc = struct {...@@ -1314,7 +1224,7 @@ pub const SrcLoc = struct {
1314 .node_offset_slice_sentinel,1224 .node_offset_slice_sentinel,
1315 => |node_off| {1225 => |node_off| {
1316 const tree = try src_loc.file_scope.getTree(gpa);1226 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);
1318 const full = tree.fullSlice(node).?;1228 const full = tree.fullSlice(node).?;
1319 const part_node = switch (src_loc.lazy) {1229 const part_node = switch (src_loc.lazy) {
1320 .node_offset_slice_ptr => full.ast.sliced,1230 .node_offset_slice_ptr => full.ast.sliced,
...@@ -1327,7 +1237,7 @@ pub const SrcLoc = struct {...@@ -1327,7 +1237,7 @@ pub const SrcLoc = struct {
1327 },1237 },
1328 .node_offset_call_func => |node_off| {1238 .node_offset_call_func => |node_off| {
1329 const tree = try src_loc.file_scope.getTree(gpa);1239 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);
1331 var buf: [1]Ast.Node.Index = undefined;1241 var buf: [1]Ast.Node.Index = undefined;
1332 const full = tree.fullCall(&buf, node).?;1242 const full = tree.fullCall(&buf, node).?;
1333 return tree.nodeToSpan(full.ast.fn_expr);1243 return tree.nodeToSpan(full.ast.fn_expr);
...@@ -1336,7 +1246,7 @@ pub const SrcLoc = struct {...@@ -1336,7 +1246,7 @@ pub const SrcLoc = struct {
1336 const tree = try src_loc.file_scope.getTree(gpa);1246 const tree = try src_loc.file_scope.getTree(gpa);
1337 const node_datas = tree.nodes.items(.data);1247 const node_datas = tree.nodes.items(.data);
1338 const node_tags = tree.nodes.items(.tag);1248 const node_tags = tree.nodes.items(.tag);
1339 const node = src_loc.declRelativeToNodeIndex(node_off);1249 const node = src_loc.relativeToNodeIndex(node_off);
1340 var buf: [1]Ast.Node.Index = undefined;1250 var buf: [1]Ast.Node.Index = undefined;
1341 const tok_index = switch (node_tags[node]) {1251 const tok_index = switch (node_tags[node]) {
1342 .field_access => node_datas[node].rhs,1252 .field_access => node_datas[node].rhs,
...@@ -1360,7 +1270,7 @@ pub const SrcLoc = struct {...@@ -1360,7 +1270,7 @@ pub const SrcLoc = struct {
1360 },1270 },
1361 .node_offset_field_name_init => |node_off| {1271 .node_offset_field_name_init => |node_off| {
1362 const tree = try src_loc.file_scope.getTree(gpa);1272 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);
1364 const tok_index = tree.firstToken(node) - 2;1274 const tok_index = tree.firstToken(node) - 2;
1365 const start = tree.tokens.items(.start)[tok_index];1275 const start = tree.tokens.items(.start)[tok_index];
1366 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1276 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
...@@ -1368,18 +1278,18 @@ pub const SrcLoc = struct {...@@ -1368,18 +1278,18 @@ pub const SrcLoc = struct {
1368 },1278 },
1369 .node_offset_deref_ptr => |node_off| {1279 .node_offset_deref_ptr => |node_off| {
1370 const tree = try src_loc.file_scope.getTree(gpa);1280 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);
1372 return tree.nodeToSpan(node);1282 return tree.nodeToSpan(node);
1373 },1283 },
1374 .node_offset_asm_source => |node_off| {1284 .node_offset_asm_source => |node_off| {
1375 const tree = try src_loc.file_scope.getTree(gpa);1285 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);
1377 const full = tree.fullAsm(node).?;1287 const full = tree.fullAsm(node).?;
1378 return tree.nodeToSpan(full.ast.template);1288 return tree.nodeToSpan(full.ast.template);
1379 },1289 },
1380 .node_offset_asm_ret_ty => |node_off| {1290 .node_offset_asm_ret_ty => |node_off| {
1381 const tree = try src_loc.file_scope.getTree(gpa);1291 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);
1383 const full = tree.fullAsm(node).?;1293 const full = tree.fullAsm(node).?;
1384 const asm_output = full.outputs[0];1294 const asm_output = full.outputs[0];
1385 const node_datas = tree.nodes.items(.data);1295 const node_datas = tree.nodes.items(.data);
...@@ -1388,7 +1298,7 @@ pub const SrcLoc = struct {...@@ -1388,7 +1298,7 @@ pub const SrcLoc = struct {
13881298
1389 .node_offset_if_cond => |node_off| {1299 .node_offset_if_cond => |node_off| {
1390 const tree = try src_loc.file_scope.getTree(gpa);1300 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);
1392 const node_tags = tree.nodes.items(.tag);1302 const node_tags = tree.nodes.items(.tag);
1393 const src_node = switch (node_tags[node]) {1303 const src_node = switch (node_tags[node]) {
1394 .if_simple,1304 .if_simple,
...@@ -1417,7 +1327,7 @@ pub const SrcLoc = struct {...@@ -1417,7 +1327,7 @@ pub const SrcLoc = struct {
1417 },1327 },
1418 .for_input => |for_input| {1328 .for_input => |for_input| {
1419 const tree = try src_loc.file_scope.getTree(gpa);1329 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);
1421 const for_full = tree.fullFor(node).?;1331 const for_full = tree.fullFor(node).?;
1422 const src_node = for_full.ast.inputs[for_input.input_index];1332 const src_node = for_full.ast.inputs[for_input.input_index];
1423 return tree.nodeToSpan(src_node);1333 return tree.nodeToSpan(src_node);
...@@ -1425,7 +1335,7 @@ pub const SrcLoc = struct {...@@ -1425,7 +1335,7 @@ pub const SrcLoc = struct {
1425 .for_capture_from_input => |node_off| {1335 .for_capture_from_input => |node_off| {
1426 const tree = try src_loc.file_scope.getTree(gpa);1336 const tree = try src_loc.file_scope.getTree(gpa);
1427 const token_tags = tree.tokens.items(.tag);1337 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);
1429 // We have to actually linear scan the whole AST to find the for loop1339 // We have to actually linear scan the whole AST to find the for loop
1430 // that contains this input.1340 // that contains this input.
1431 const node_tags = tree.nodes.items(.tag);1341 const node_tags = tree.nodes.items(.tag);
...@@ -1466,7 +1376,7 @@ pub const SrcLoc = struct {...@@ -1466,7 +1376,7 @@ pub const SrcLoc = struct {
1466 },1376 },
1467 .call_arg => |call_arg| {1377 .call_arg => |call_arg| {
1468 const tree = try src_loc.file_scope.getTree(gpa);1378 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);
1470 var buf: [2]Ast.Node.Index = undefined;1380 var buf: [2]Ast.Node.Index = undefined;
1471 const call_full = tree.fullCall(buf[0..1], node) orelse {1381 const call_full = tree.fullCall(buf[0..1], node) orelse {
1472 const node_tags = tree.nodes.items(.tag);1382 const node_tags = tree.nodes.items(.tag);
...@@ -1502,43 +1412,49 @@ pub const SrcLoc = struct {...@@ -1502,43 +1412,49 @@ pub const SrcLoc = struct {
1502 };1412 };
1503 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);1413 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);
1504 },1414 },
1505 .fn_proto_param => |fn_proto_param| {1415 .fn_proto_param, .fn_proto_param_type => |fn_proto_param| {
1506 const tree = try src_loc.file_scope.getTree(gpa);1416 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);
1508 var buf: [1]Ast.Node.Index = undefined;1418 var buf: [1]Ast.Node.Index = undefined;
1509 const full = tree.fullFnProto(&buf, node).?;1419 const full = tree.fullFnProto(&buf, node).?;
1510 var it = full.iterate(tree);1420 var it = full.iterate(tree);
1511 var i: usize = 0;1421 var i: usize = 0;
1512 while (it.next()) |param| : (i += 1) {1422 while (it.next()) |param| : (i += 1) {
1513 if (i == fn_proto_param.param_index) {1423 if (i != fn_proto_param.param_index) continue;
1514 if (param.anytype_ellipsis3) |token| return tree.tokenToSpan(token);1424
1515 const first_token = param.comptime_noalias orelse1425 switch (src_loc.lazy) {
1516 param.name_token orelse1426 .fn_proto_param_type => if (param.anytype_ellipsis3) |tok| {
1517 tree.firstToken(param.type_expr);1427 return tree.tokenToSpan(tok);
1518 return tree.tokensToSpan(1428 } else {
1519 first_token,1429 return tree.nodeToSpan(param.type_expr);
1520 tree.lastToken(param.type_expr),1430 },
1521 first_token,1431 .fn_proto_param => if (param.anytype_ellipsis3) |tok| {
1522 );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,
1523 }1439 }
1524 }1440 }
1525 unreachable;1441 unreachable;
1526 },1442 },
1527 .node_offset_bin_lhs => |node_off| {1443 .node_offset_bin_lhs => |node_off| {
1528 const tree = try src_loc.file_scope.getTree(gpa);1444 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);
1530 const node_datas = tree.nodes.items(.data);1446 const node_datas = tree.nodes.items(.data);
1531 return tree.nodeToSpan(node_datas[node].lhs);1447 return tree.nodeToSpan(node_datas[node].lhs);
1532 },1448 },
1533 .node_offset_bin_rhs => |node_off| {1449 .node_offset_bin_rhs => |node_off| {
1534 const tree = try src_loc.file_scope.getTree(gpa);1450 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);
1536 const node_datas = tree.nodes.items(.data);1452 const node_datas = tree.nodes.items(.data);
1537 return tree.nodeToSpan(node_datas[node].rhs);1453 return tree.nodeToSpan(node_datas[node].rhs);
1538 },1454 },
1539 .array_cat_lhs, .array_cat_rhs => |cat| {1455 .array_cat_lhs, .array_cat_rhs => |cat| {
1540 const tree = try src_loc.file_scope.getTree(gpa);1456 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);
1542 const node_datas = tree.nodes.items(.data);1458 const node_datas = tree.nodes.items(.data);
1543 const arr_node = if (src_loc.lazy == .array_cat_lhs)1459 const arr_node = if (src_loc.lazy == .array_cat_lhs)
1544 node_datas[node].lhs1460 node_datas[node].lhs
...@@ -1566,14 +1482,14 @@ pub const SrcLoc = struct {...@@ -1566,14 +1482,14 @@ pub const SrcLoc = struct {
15661482
1567 .node_offset_switch_operand => |node_off| {1483 .node_offset_switch_operand => |node_off| {
1568 const tree = try src_loc.file_scope.getTree(gpa);1484 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);
1570 const node_datas = tree.nodes.items(.data);1486 const node_datas = tree.nodes.items(.data);
1571 return tree.nodeToSpan(node_datas[node].lhs);1487 return tree.nodeToSpan(node_datas[node].lhs);
1572 },1488 },
15731489
1574 .node_offset_switch_special_prong => |node_off| {1490 .node_offset_switch_special_prong => |node_off| {
1575 const tree = try src_loc.file_scope.getTree(gpa);1491 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);
1577 const node_datas = tree.nodes.items(.data);1493 const node_datas = tree.nodes.items(.data);
1578 const node_tags = tree.nodes.items(.tag);1494 const node_tags = tree.nodes.items(.tag);
1579 const main_tokens = tree.nodes.items(.main_token);1495 const main_tokens = tree.nodes.items(.main_token);
...@@ -1593,7 +1509,7 @@ pub const SrcLoc = struct {...@@ -1593,7 +1509,7 @@ pub const SrcLoc = struct {
15931509
1594 .node_offset_switch_range => |node_off| {1510 .node_offset_switch_range => |node_off| {
1595 const tree = try src_loc.file_scope.getTree(gpa);1511 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);
1597 const node_datas = tree.nodes.items(.data);1513 const node_datas = tree.nodes.items(.data);
1598 const node_tags = tree.nodes.items(.tag);1514 const node_tags = tree.nodes.items(.tag);
1599 const main_tokens = tree.nodes.items(.main_token);1515 const main_tokens = tree.nodes.items(.main_token);
...@@ -1614,56 +1530,30 @@ pub const SrcLoc = struct {...@@ -1614,56 +1530,30 @@ pub const SrcLoc = struct {
1614 }1530 }
1615 } else unreachable;1531 } else unreachable;
1616 },1532 },
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 },
1643 .node_offset_fn_type_align => |node_off| {1533 .node_offset_fn_type_align => |node_off| {
1644 const tree = try src_loc.file_scope.getTree(gpa);1534 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);
1646 var buf: [1]Ast.Node.Index = undefined;1536 var buf: [1]Ast.Node.Index = undefined;
1647 const full = tree.fullFnProto(&buf, node).?;1537 const full = tree.fullFnProto(&buf, node).?;
1648 return tree.nodeToSpan(full.ast.align_expr);1538 return tree.nodeToSpan(full.ast.align_expr);
1649 },1539 },
1650 .node_offset_fn_type_addrspace => |node_off| {1540 .node_offset_fn_type_addrspace => |node_off| {
1651 const tree = try src_loc.file_scope.getTree(gpa);1541 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);
1653 var buf: [1]Ast.Node.Index = undefined;1543 var buf: [1]Ast.Node.Index = undefined;
1654 const full = tree.fullFnProto(&buf, node).?;1544 const full = tree.fullFnProto(&buf, node).?;
1655 return tree.nodeToSpan(full.ast.addrspace_expr);1545 return tree.nodeToSpan(full.ast.addrspace_expr);
1656 },1546 },
1657 .node_offset_fn_type_section => |node_off| {1547 .node_offset_fn_type_section => |node_off| {
1658 const tree = try src_loc.file_scope.getTree(gpa);1548 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);
1660 var buf: [1]Ast.Node.Index = undefined;1550 var buf: [1]Ast.Node.Index = undefined;
1661 const full = tree.fullFnProto(&buf, node).?;1551 const full = tree.fullFnProto(&buf, node).?;
1662 return tree.nodeToSpan(full.ast.section_expr);1552 return tree.nodeToSpan(full.ast.section_expr);
1663 },1553 },
1664 .node_offset_fn_type_cc => |node_off| {1554 .node_offset_fn_type_cc => |node_off| {
1665 const tree = try src_loc.file_scope.getTree(gpa);1555 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);
1667 var buf: [1]Ast.Node.Index = undefined;1557 var buf: [1]Ast.Node.Index = undefined;
1668 const full = tree.fullFnProto(&buf, node).?;1558 const full = tree.fullFnProto(&buf, node).?;
1669 return tree.nodeToSpan(full.ast.callconv_expr);1559 return tree.nodeToSpan(full.ast.callconv_expr);
...@@ -1671,7 +1561,7 @@ pub const SrcLoc = struct {...@@ -1671,7 +1561,7 @@ pub const SrcLoc = struct {
16711561
1672 .node_offset_fn_type_ret_ty => |node_off| {1562 .node_offset_fn_type_ret_ty => |node_off| {
1673 const tree = try src_loc.file_scope.getTree(gpa);1563 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);
1675 var buf: [1]Ast.Node.Index = undefined;1565 var buf: [1]Ast.Node.Index = undefined;
1676 const full = tree.fullFnProto(&buf, node).?;1566 const full = tree.fullFnProto(&buf, node).?;
1677 return tree.nodeToSpan(full.ast.return_type);1567 return tree.nodeToSpan(full.ast.return_type);
...@@ -1679,7 +1569,7 @@ pub const SrcLoc = struct {...@@ -1679,7 +1569,7 @@ pub const SrcLoc = struct {
1679 .node_offset_param => |node_off| {1569 .node_offset_param => |node_off| {
1680 const tree = try src_loc.file_scope.getTree(gpa);1570 const tree = try src_loc.file_scope.getTree(gpa);
1681 const token_tags = tree.tokens.items(.tag);1571 const token_tags = tree.tokens.items(.tag);
1682 const node = src_loc.declRelativeToNodeIndex(node_off);1572 const node = src_loc.relativeToNodeIndex(node_off);
16831573
1684 var first_tok = tree.firstToken(node);1574 var first_tok = tree.firstToken(node);
1685 while (true) switch (token_tags[first_tok - 1]) {1575 while (true) switch (token_tags[first_tok - 1]) {
...@@ -1695,7 +1585,7 @@ pub const SrcLoc = struct {...@@ -1695,7 +1585,7 @@ pub const SrcLoc = struct {
1695 .token_offset_param => |token_off| {1585 .token_offset_param => |token_off| {
1696 const tree = try src_loc.file_scope.getTree(gpa);1586 const tree = try src_loc.file_scope.getTree(gpa);
1697 const token_tags = tree.tokens.items(.tag);1587 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];
1699 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));1589 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));
17001590
1701 var first_tok = tok_index;1591 var first_tok = tok_index;
...@@ -1713,13 +1603,13 @@ pub const SrcLoc = struct {...@@ -1713,13 +1603,13 @@ pub const SrcLoc = struct {
1713 .node_offset_anyframe_type => |node_off| {1603 .node_offset_anyframe_type => |node_off| {
1714 const tree = try src_loc.file_scope.getTree(gpa);1604 const tree = try src_loc.file_scope.getTree(gpa);
1715 const node_datas = tree.nodes.items(.data);1605 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);
1717 return tree.nodeToSpan(node_datas[parent_node].rhs);1607 return tree.nodeToSpan(node_datas[parent_node].rhs);
1718 },1608 },
17191609
1720 .node_offset_lib_name => |node_off| {1610 .node_offset_lib_name => |node_off| {
1721 const tree = try src_loc.file_scope.getTree(gpa);1611 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);
1723 var buf: [1]Ast.Node.Index = undefined;1613 var buf: [1]Ast.Node.Index = undefined;
1724 const full = tree.fullFnProto(&buf, parent_node).?;1614 const full = tree.fullFnProto(&buf, parent_node).?;
1725 const tok_index = full.lib_name.?;1615 const tok_index = full.lib_name.?;
...@@ -1730,21 +1620,21 @@ pub const SrcLoc = struct {...@@ -1730,21 +1620,21 @@ pub const SrcLoc = struct {
17301620
1731 .node_offset_array_type_len => |node_off| {1621 .node_offset_array_type_len => |node_off| {
1732 const tree = try src_loc.file_scope.getTree(gpa);1622 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
1735 const full = tree.fullArrayType(parent_node).?;1625 const full = tree.fullArrayType(parent_node).?;
1736 return tree.nodeToSpan(full.ast.elem_count);1626 return tree.nodeToSpan(full.ast.elem_count);
1737 },1627 },
1738 .node_offset_array_type_sentinel => |node_off| {1628 .node_offset_array_type_sentinel => |node_off| {
1739 const tree = try src_loc.file_scope.getTree(gpa);1629 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
1742 const full = tree.fullArrayType(parent_node).?;1632 const full = tree.fullArrayType(parent_node).?;
1743 return tree.nodeToSpan(full.ast.sentinel);1633 return tree.nodeToSpan(full.ast.sentinel);
1744 },1634 },
1745 .node_offset_array_type_elem => |node_off| {1635 .node_offset_array_type_elem => |node_off| {
1746 const tree = try src_loc.file_scope.getTree(gpa);1636 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
1749 const full = tree.fullArrayType(parent_node).?;1639 const full = tree.fullArrayType(parent_node).?;
1750 return tree.nodeToSpan(full.ast.elem_type);1640 return tree.nodeToSpan(full.ast.elem_type);
...@@ -1752,48 +1642,48 @@ pub const SrcLoc = struct {...@@ -1752,48 +1642,48 @@ pub const SrcLoc = struct {
1752 .node_offset_un_op => |node_off| {1642 .node_offset_un_op => |node_off| {
1753 const tree = try src_loc.file_scope.getTree(gpa);1643 const tree = try src_loc.file_scope.getTree(gpa);
1754 const node_datas = tree.nodes.items(.data);1644 const node_datas = tree.nodes.items(.data);
1755 const node = src_loc.declRelativeToNodeIndex(node_off);1645 const node = src_loc.relativeToNodeIndex(node_off);
17561646
1757 return tree.nodeToSpan(node_datas[node].lhs);1647 return tree.nodeToSpan(node_datas[node].lhs);
1758 },1648 },
1759 .node_offset_ptr_elem => |node_off| {1649 .node_offset_ptr_elem => |node_off| {
1760 const tree = try src_loc.file_scope.getTree(gpa);1650 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
1763 const full = tree.fullPtrType(parent_node).?;1653 const full = tree.fullPtrType(parent_node).?;
1764 return tree.nodeToSpan(full.ast.child_type);1654 return tree.nodeToSpan(full.ast.child_type);
1765 },1655 },
1766 .node_offset_ptr_sentinel => |node_off| {1656 .node_offset_ptr_sentinel => |node_off| {
1767 const tree = try src_loc.file_scope.getTree(gpa);1657 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
1770 const full = tree.fullPtrType(parent_node).?;1660 const full = tree.fullPtrType(parent_node).?;
1771 return tree.nodeToSpan(full.ast.sentinel);1661 return tree.nodeToSpan(full.ast.sentinel);
1772 },1662 },
1773 .node_offset_ptr_align => |node_off| {1663 .node_offset_ptr_align => |node_off| {
1774 const tree = try src_loc.file_scope.getTree(gpa);1664 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
1777 const full = tree.fullPtrType(parent_node).?;1667 const full = tree.fullPtrType(parent_node).?;
1778 return tree.nodeToSpan(full.ast.align_node);1668 return tree.nodeToSpan(full.ast.align_node);
1779 },1669 },
1780 .node_offset_ptr_addrspace => |node_off| {1670 .node_offset_ptr_addrspace => |node_off| {
1781 const tree = try src_loc.file_scope.getTree(gpa);1671 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
1784 const full = tree.fullPtrType(parent_node).?;1674 const full = tree.fullPtrType(parent_node).?;
1785 return tree.nodeToSpan(full.ast.addrspace_node);1675 return tree.nodeToSpan(full.ast.addrspace_node);
1786 },1676 },
1787 .node_offset_ptr_bitoffset => |node_off| {1677 .node_offset_ptr_bitoffset => |node_off| {
1788 const tree = try src_loc.file_scope.getTree(gpa);1678 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
1791 const full = tree.fullPtrType(parent_node).?;1681 const full = tree.fullPtrType(parent_node).?;
1792 return tree.nodeToSpan(full.ast.bit_range_start);1682 return tree.nodeToSpan(full.ast.bit_range_start);
1793 },1683 },
1794 .node_offset_ptr_hostsize => |node_off| {1684 .node_offset_ptr_hostsize => |node_off| {
1795 const tree = try src_loc.file_scope.getTree(gpa);1685 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
1798 const full = tree.fullPtrType(parent_node).?;1688 const full = tree.fullPtrType(parent_node).?;
1799 return tree.nodeToSpan(full.ast.bit_range_end);1689 return tree.nodeToSpan(full.ast.bit_range_end);
...@@ -1801,7 +1691,7 @@ pub const SrcLoc = struct {...@@ -1801,7 +1691,7 @@ pub const SrcLoc = struct {
1801 .node_offset_container_tag => |node_off| {1691 .node_offset_container_tag => |node_off| {
1802 const tree = try src_loc.file_scope.getTree(gpa);1692 const tree = try src_loc.file_scope.getTree(gpa);
1803 const node_tags = tree.nodes.items(.tag);1693 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
1806 switch (node_tags[parent_node]) {1696 switch (node_tags[parent_node]) {
1807 .container_decl_arg, .container_decl_arg_trailing => {1697 .container_decl_arg, .container_decl_arg_trailing => {
...@@ -1823,7 +1713,7 @@ pub const SrcLoc = struct {...@@ -1823,7 +1713,7 @@ pub const SrcLoc = struct {
1823 .node_offset_field_default => |node_off| {1713 .node_offset_field_default => |node_off| {
1824 const tree = try src_loc.file_scope.getTree(gpa);1714 const tree = try src_loc.file_scope.getTree(gpa);
1825 const node_tags = tree.nodes.items(.tag);1715 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
1828 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {1718 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {
1829 .container_field => tree.containerField(parent_node),1719 .container_field => tree.containerField(parent_node),
...@@ -1834,7 +1724,7 @@ pub const SrcLoc = struct {...@@ -1834,7 +1724,7 @@ pub const SrcLoc = struct {
1834 },1724 },
1835 .node_offset_init_ty => |node_off| {1725 .node_offset_init_ty => |node_off| {
1836 const tree = try src_loc.file_scope.getTree(gpa);1726 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
1839 var buf: [2]Ast.Node.Index = undefined;1729 var buf: [2]Ast.Node.Index = undefined;
1840 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|1730 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
...@@ -1847,7 +1737,7 @@ pub const SrcLoc = struct {...@@ -1847,7 +1737,7 @@ pub const SrcLoc = struct {
1847 const tree = try src_loc.file_scope.getTree(gpa);1737 const tree = try src_loc.file_scope.getTree(gpa);
1848 const node_tags = tree.nodes.items(.tag);1738 const node_tags = tree.nodes.items(.tag);
1849 const node_datas = tree.nodes.items(.data);1739 const node_datas = tree.nodes.items(.data);
1850 const node = src_loc.declRelativeToNodeIndex(node_off);1740 const node = src_loc.relativeToNodeIndex(node_off);
18511741
1852 switch (node_tags[node]) {1742 switch (node_tags[node]) {
1853 .assign => {1743 .assign => {
...@@ -1860,7 +1750,7 @@ pub const SrcLoc = struct {...@@ -1860,7 +1750,7 @@ pub const SrcLoc = struct {
1860 const tree = try src_loc.file_scope.getTree(gpa);1750 const tree = try src_loc.file_scope.getTree(gpa);
1861 const node_tags = tree.nodes.items(.tag);1751 const node_tags = tree.nodes.items(.tag);
1862 const node_datas = tree.nodes.items(.data);1752 const node_datas = tree.nodes.items(.data);
1863 const node = src_loc.declRelativeToNodeIndex(node_off);1753 const node = src_loc.relativeToNodeIndex(node_off);
18641754
1865 switch (node_tags[node]) {1755 switch (node_tags[node]) {
1866 .assign => {1756 .assign => {
...@@ -1871,7 +1761,7 @@ pub const SrcLoc = struct {...@@ -1871,7 +1761,7 @@ pub const SrcLoc = struct {
1871 },1761 },
1872 .node_offset_return_operand => |node_off| {1762 .node_offset_return_operand => |node_off| {
1873 const tree = try src_loc.file_scope.getTree(gpa);1763 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);
1875 const node_tags = tree.nodes.items(.tag);1765 const node_tags = tree.nodes.items(.tag);
1876 const node_datas = tree.nodes.items(.data);1766 const node_datas = tree.nodes.items(.data);
1877 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {1767 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {
...@@ -1879,29 +1769,629 @@ pub const SrcLoc = struct {...@@ -1879,29 +1769,629 @@ pub const SrcLoc = struct {
1879 }1769 }
1880 return tree.nodeToSpan(node);1770 return tree.nodeToSpan(node);
1881 },1771 },
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 },
1882 }1981 }
1883 }1982 }
1983};
18841984
1885 pub fn byteOffsetBuiltinCallArg(1985pub const LazySrcLoc = struct {
1886 src_loc: SrcLoc,1986 /// This instruction provides the source node locations are resolved relative to.
1887 gpa: Allocator,1987 /// It is a `declaration`, `struct_decl`, `union_decl`, `enum_decl`, or `opaque_decl`.
1888 node_off: i32,1988 /// This must be valid even if `relative` is an absolute value, since it is required to
1889 arg_index: u32,1989 /// determine the file which the `LazySrcLoc` refers to.
1890 ) !Span {1990 base_node_inst: InternPool.TrackedInst.Index,
1891 const tree = try src_loc.file_scope.getTree(gpa);1991 /// This field determines the source location relative to `base_node_inst`.
1892 const node_datas = tree.nodes.items(.data);1992 offset: Offset,
1893 const node_tags = tree.nodes.items(.tag);1993
1894 const node = src_loc.declRelativeToNodeIndex(node_off);1994 pub const Offset = union(enum) {
1895 const param = switch (node_tags[node]) {1995 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1896 .builtin_call_two, .builtin_call_two_comma => switch (arg_index) {1996 /// that all code paths which would need to resolve the source location are
1897 0 => node_datas[node].lhs,1997 /// unreachable. If you are debugging this tag incorrectly being this value,
1898 1 => node_datas[node].rhs,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,
1899 else => unreachable,2378 else => unreachable,
1900 },2379 },
1901 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + arg_index],
1902 else => unreachable,2380 else => unreachable,
1903 };2381 };
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 };
1905 }2395 }
1906};2396};
19072397
...@@ -1910,11 +2400,6 @@ pub const CompileError = error{...@@ -1910,11 +2400,6 @@ pub const CompileError = error{
1910 OutOfMemory,2400 OutOfMemory,
1911 /// When this is returned, the compile error for the failure has already been recorded.2401 /// When this is returned, the compile error for the failure has already been recorded.
1912 AnalysisFail,2402 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,
1918 /// A Type or Value was needed to be used during semantic analysis, but it was not available2403 /// A Type or Value was needed to be used during semantic analysis, but it was not available
1919 /// because the function is generic. This is only seen when analyzing the body of a param2404 /// because the function is generic. This is only seen when analyzing the body of a param
1920 /// instruction.2405 /// instruction.
...@@ -1950,6 +2435,7 @@ pub fn deinit(zcu: *Zcu) void {...@@ -1950,6 +2435,7 @@ pub fn deinit(zcu: *Zcu) void {
1950 value.destroy(zcu);2435 value.destroy(zcu);
1951 }2436 }
1952 zcu.import_table.deinit(gpa);2437 zcu.import_table.deinit(gpa);
2438 zcu.path_digest_map.deinit(gpa);
19532439
1954 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {2440 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
1955 gpa.free(path);2441 gpa.free(path);
...@@ -2114,26 +2600,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -2114,26 +2600,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
2114 const stat = try source_file.stat();2600 const stat = try source_file.stat();
21152601
2116 const want_local_cache = file.mod == mod.main_mod;2602 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;
2131 const hex_digest = hex: {2603 const hex_digest = hex: {
2132 var hex: Cache.HexDigest = undefined;2604 var hex: Cache.HexDigest = undefined;
2133 _ = std.fmt.bufPrint(2605 _ = std.fmt.bufPrint(
2134 &hex,2606 &hex,
2135 "{s}",2607 "{s}",
2136 .{std.fmt.fmtSliceHexLower(&bin_digest)},2608 .{std.fmt.fmtSliceHexLower(&file.path_digest)},
2137 ) catch unreachable;2609 ) catch unreachable;
2138 break :hex hex;2610 break :hex hex;
2139 };2611 };
...@@ -3023,7 +3495,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3023,7 +3495,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3023 }3495 }
3024 return error.AnalysisFail;3496 return error.AnalysisFail;
3025 },3497 },
3026 error.NeededSourceLocation => unreachable,
3027 error.GenericPoison => unreachable,3498 error.GenericPoison => unreachable,
3028 else => |e| {3499 else => |e| {
3029 decl.analysis = .sema_failure;3500 decl.analysis = .sema_failure;
...@@ -3031,7 +3502,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3031,7 +3502,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3031 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));3502 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
3032 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(3503 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
3033 mod.gpa,3504 mod.gpa,
3034 decl.srcLoc(mod),3505 decl.navSrcLoc(mod).upgrade(mod),
3035 "unable to analyze: {s}",3506 "unable to analyze: {s}",
3036 .{@errorName(e)},3507 .{@errorName(e)},
3037 ));3508 ));
...@@ -3205,7 +3676,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3205,7 +3676,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3205 decl_index,3676 decl_index,
3206 try Module.ErrorMsg.create(3677 try Module.ErrorMsg.create(
3207 gpa,3678 gpa,
3208 decl.srcLoc(zcu),3679 decl.navSrcLoc(zcu).upgrade(zcu),
3209 "invalid liveness: {s}",3680 "invalid liveness: {s}",
3210 .{@errorName(err)},3681 .{@errorName(err)},
3211 ),3682 ),
...@@ -3229,7 +3700,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3229,7 +3700,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3229 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);3700 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
3230 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(3701 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3231 gpa,3702 gpa,
3232 decl.srcLoc(zcu),3703 decl.navSrcLoc(zcu).upgrade(zcu),
3233 "unable to codegen: {s}",3704 "unable to codegen: {s}",
3234 .{@errorName(err)},3705 .{@errorName(err)},
3235 ));3706 ));
...@@ -3464,7 +3935,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3464,7 +3935,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
3464 });3935 });
3465 errdefer mod.destroyNamespace(new_namespace_index);3936 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);
3468 const new_decl = mod.declPtr(new_decl_index);3939 const new_decl = mod.declPtr(new_decl_index);
3469 errdefer @panic("TODO error handling");3940 errdefer @panic("TODO error handling");
34703941
...@@ -3611,7 +4082,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3611,7 +4082,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3611 var analysis_arena = std.heap.ArenaAllocator.init(gpa);4082 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3612 defer analysis_arena.deinit();4083 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);
3615 defer comptime_err_ret_trace.deinit();4086 defer comptime_err_ret_trace.deinit();
36164087
3617 var sema: Sema = .{4088 var sema: Sema = .{
...@@ -3641,11 +4112,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3641,11 +4112,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3641 var block_scope: Sema.Block = .{4112 var block_scope: Sema.Block = .{
3642 .parent = null,4113 .parent = null,
3643 .sema = &sema,4114 .sema = &sema,
3644 .src_decl = decl_index,
3645 .namespace = decl.src_namespace,4115 .namespace = decl.src_namespace,
3646 .instructions = .{},4116 .instructions = .{},
3647 .inlining = null,4117 .inlining = null,
3648 .is_comptime = true,4118 .is_comptime = true,
4119 .src_base_inst = decl.zir_decl_index.unwrap().?,
4120 .type_name_ctx = decl.name,
3649 };4121 };
3650 defer block_scope.instructions.deinit(gpa);4122 defer block_scope.instructions.deinit(gpa);
36514123
...@@ -3655,11 +4127,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3655,11 +4127,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3655 // We'll do some other bits with the Sema. Clear the type target index just4127 // We'll do some other bits with the Sema. Clear the type target index just
3656 // in case they analyze any type.4128 // in case they analyze any type.
3657 sema.builtin_type_target_index = .none;4129 sema.builtin_type_target_index = .none;
3658 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };4130 const align_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_align = 0 });
3659 const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };4131 const section_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_section = 0 });
3660 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };4132 const address_space_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_addrspace = 0 });
3661 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };4133 const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 });
3662 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };4134 const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 });
3663 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);4135 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);
3664 const decl_ty = decl_val.typeOf(mod);4136 const decl_ty = decl_val.typeOf(mod);
36654137
...@@ -3793,7 +4265,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3793,7 +4265,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3793 }4265 }
37944266
3795 if (decl.is_exported) {4267 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) });
3797 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});4269 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});
3798 // The scope needs to have the decl in it.4270 // The scope needs to have the decl in it.
3799 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);4271 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 {...@@ -3873,6 +4345,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
3873 keep_resolved_path = true; // It's now owned by import_table.4345 keep_resolved_path = true; // It's now owned by import_table.
3874 gop.value_ptr.* = builtin_file;4346 gop.value_ptr.* = builtin_file;
3875 try builtin_file.addReference(zcu.*, .{ .root = mod });4347 try builtin_file.addReference(zcu.*, .{ .root = mod });
4348 try zcu.path_digest_map.put(gpa, builtin_file.path_digest, {});
3876 return .{4349 return .{
3877 .file = builtin_file,4350 .file = builtin_file,
3878 .is_new = false,4351 .is_new = false,
...@@ -3900,8 +4373,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {...@@ -3900,8 +4373,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
3900 .status = .never_loaded,4373 .status = .never_loaded,
3901 .mod = mod,4374 .mod = mod,
3902 .root_decl = .none,4375 .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 },
3903 };4390 };
3904 try new_file.addReference(zcu.*, .{ .root = mod });4391 try new_file.addReference(zcu.*, .{ .root = mod });
4392 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
3905 return ImportFileResult{4393 return ImportFileResult{
3906 .file = new_file,4394 .file = new_file,
3907 .is_new = true,4395 .is_new = true,
...@@ -3910,23 +4398,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {...@@ -3910,23 +4398,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
3910}4398}
39114399
3912pub fn importFile(4400pub fn importFile(
3913 mod: *Module,4401 zcu: *Zcu,
3914 cur_file: *File,4402 cur_file: *File,
3915 import_string: []const u8,4403 import_string: []const u8,
3916) !ImportFileResult {4404) !ImportFileResult {
3917 if (std.mem.eql(u8, import_string, "std")) {4405 if (std.mem.eql(u8, import_string, "std")) {
3918 return mod.importPkg(mod.std_mod);4406 return zcu.importPkg(zcu.std_mod);
3919 }4407 }
3920 if (std.mem.eql(u8, import_string, "root")) {4408 if (std.mem.eql(u8, import_string, "root")) {
3921 return mod.importPkg(mod.root_mod);4409 return zcu.importPkg(zcu.root_mod);
3922 }4410 }
3923 if (cur_file.mod.deps.get(import_string)) |pkg| {4411 if (cur_file.mod.deps.get(import_string)) |pkg| {
3924 return mod.importPkg(pkg);4412 return zcu.importPkg(pkg);
3925 }4413 }
3926 if (!mem.endsWith(u8, import_string, ".zig")) {4414 if (!mem.endsWith(u8, import_string, ".zig")) {
3927 return error.ModuleNotFound;4415 return error.ModuleNotFound;
3928 }4416 }
3929 const gpa = mod.gpa;4417 const gpa = zcu.gpa;
39304418
3931 // The resolved path is used as the key in the import table, to detect if4419 // The resolved path is used as the key in the import table, to detect if
3932 // an import refers to the same as another, despite different relative paths4420 // an import refers to the same as another, despite different relative paths
...@@ -3942,8 +4430,8 @@ pub fn importFile(...@@ -3942,8 +4430,8 @@ pub fn importFile(
3942 var keep_resolved_path = false;4430 var keep_resolved_path = false;
3943 defer if (!keep_resolved_path) gpa.free(resolved_path);4431 defer if (!keep_resolved_path) gpa.free(resolved_path);
39444432
3945 const gop = try mod.import_table.getOrPut(gpa, resolved_path);4433 const gop = try zcu.import_table.getOrPut(gpa, resolved_path);
3946 errdefer _ = mod.import_table.pop();4434 errdefer _ = zcu.import_table.pop();
3947 if (gop.found_existing) return ImportFileResult{4435 if (gop.found_existing) return ImportFileResult{
3948 .file = gop.value_ptr.*,4436 .file = gop.value_ptr.*,
3949 .is_new = false,4437 .is_new = false,
...@@ -3988,7 +4476,22 @@ pub fn importFile(...@@ -3988,7 +4476,22 @@ pub fn importFile(
3988 .status = .never_loaded,4476 .status = .never_loaded,
3989 .mod = cur_file.mod,4477 .mod = cur_file.mod,
3990 .root_decl = .none,4478 .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 },
3991 };4493 };
4494 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
3992 return ImportFileResult{4495 return ImportFileResult{
3993 .file = new_file,4496 .file = new_file,
3994 .is_new = true,4497 .is_new = true,
...@@ -4255,12 +4758,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4255,12 +4758,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4255 const zir = namespace.file_scope.zir;4758 const zir = namespace.file_scope.zir;
4256 const ip = &zcu.intern_pool;4759 const ip = &zcu.intern_pool;
42574760
4258 const pl_node = zir.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node;4761 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
4259 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);4762 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
4260 const declaration = extra.data;4763 const declaration = extra.data;
42614764
4262 const line = iter.parent_decl.src_line + declaration.line_offset;4765 const line = iter.parent_decl.src_line + declaration.line_offset;
4263 const decl_node = iter.parent_decl.relativeToNodeIndex(pl_node.src_node);
42644766
4265 // Every Decl needs a name.4767 // Every Decl needs a name.
4266 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {4768 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...@@ -4348,14 +4850,13 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4348 const was_exported = decl.is_exported;4850 const was_exported = decl.is_exported;
4349 assert(decl.kind == kind); // ZIR tracking should preserve this4851 assert(decl.kind == kind); // ZIR tracking should preserve this
4350 decl.name = decl_name;4852 decl.name = decl_name;
4351 decl.src_node = decl_node;
4352 decl.src_line = line;4853 decl.src_line = line;
4353 decl.is_pub = declaration.flags.is_pub;4854 decl.is_pub = declaration.flags.is_pub;
4354 decl.is_exported = declaration.flags.is_export;4855 decl.is_exported = declaration.flags.is_export;
4355 break :decl_index .{ was_exported, decl_index };4856 break :decl_index .{ was_exported, decl_index };
4356 } else decl_index: {4857 } else decl_index: {
4357 // Create and set up a new Decl.4858 // 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);
4359 const new_decl = zcu.declPtr(new_decl_index);4860 const new_decl = zcu.declPtr(new_decl_index);
4360 new_decl.kind = kind;4861 new_decl.kind = kind;
4361 new_decl.name = decl_name;4862 new_decl.name = decl_name;
...@@ -4509,7 +5010,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4509,7 +5010,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45095010
4510 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));5011 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);
4513 defer comptime_err_ret_trace.deinit();5014 defer comptime_err_ret_trace.deinit();
45145015
4515 // In the case of a generic function instance, this is the type of the5016 // 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...@@ -4559,11 +5060,19 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4559 var inner_block: Sema.Block = .{5060 var inner_block: Sema.Block = .{
4560 .parent = null,5061 .parent = null,
4561 .sema = &sema,5062 .sema = &sema,
4562 .src_decl = decl_index,
4563 .namespace = decl.src_namespace,5063 .namespace = decl.src_namespace,
4564 .instructions = .{},5064 .instructions = .{},
4565 .inlining = null,5065 .inlining = null,
4566 .is_comptime = false,5066 .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,
4567 };5076 };
4568 defer inner_block.instructions.deinit(gpa);5077 defer inner_block.instructions.deinit(gpa);
45695078
...@@ -4605,7 +5114,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4605,7 +5114,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4605 runtime_param_index += 1;5114 runtime_param_index += 1;
46065115
4607 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {5116 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {
4608 error.NeededSourceLocation => unreachable,
4609 error.GenericPoison => unreachable,5117 error.GenericPoison => unreachable,
4610 error.ComptimeReturn => unreachable,5118 error.ComptimeReturn => unreachable,
4611 error.ComptimeBreak => unreachable,5119 error.ComptimeBreak => unreachable,
...@@ -4639,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4639,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46395147
4640 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {5148 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
4641 // TODO make these unreachable instead of @panic5149 // TODO make these unreachable instead of @panic
4642 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
4643 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),5150 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
4644 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),5151 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
4645 else => |e| return e,5152 else => |e| return e,
...@@ -4661,7 +5168,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4661,7 +5168,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4661 {5168 {
4662 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {5169 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
4663 // TODO make these unreachable instead of @panic5170 // TODO make these unreachable instead of @panic
4664 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
4665 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),5171 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
4666 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),5172 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
4667 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),5173 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),
...@@ -4682,8 +5188,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4682,8 +5188,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4682 // state to success, so that "unable to resolve inferred error set" errors5188 // state to success, so that "unable to resolve inferred error set" errors
4683 // can be emitted here.5189 // can be emitted here.
4684 if (sema.fn_ret_ty_ies) |ies| {5190 if (sema.fn_ret_ty_ies) |ies| {
4685 sema.resolveInferredErrorSetPtr(&inner_block, LazySrcLoc.nodeOffset(0), ies) catch |err| switch (err) {5191 sema.resolveInferredErrorSetPtr(&inner_block, .{
4686 error.NeededSourceLocation => unreachable,5192 .base_node_inst = inner_block.src_base_inst,
5193 .offset = LazySrcLoc.Offset.nodeOffset(0),
5194 }, ies) catch |err| switch (err) {
4687 error.GenericPoison => unreachable,5195 error.GenericPoison => unreachable,
4688 error.ComptimeReturn => unreachable,5196 error.ComptimeReturn => unreachable,
4689 error.ComptimeBreak => unreachable,5197 error.ComptimeBreak => unreachable,
...@@ -4707,7 +5215,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4707,7 +5215,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4707 // so that dependencies on the function body will now be satisfied rather than5215 // so that dependencies on the function body will now be satisfied rather than
4708 // result in circular dependency errors.5216 // result in circular dependency errors.
4709 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {5217 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {
4710 error.NeededSourceLocation => unreachable,
4711 error.GenericPoison => unreachable,5218 error.GenericPoison => unreachable,
4712 error.ComptimeReturn => unreachable,5219 error.ComptimeReturn => unreachable,
4713 error.ComptimeBreak => unreachable,5220 error.ComptimeBreak => unreachable,
...@@ -4724,7 +5231,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4724,7 +5231,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4724 // the backends.5231 // the backends.
4725 for (sema.types_to_resolve.keys()) |ty| {5232 for (sema.types_to_resolve.keys()) |ty| {
4726 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {5233 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {
4727 error.NeededSourceLocation => unreachable,
4728 error.GenericPoison => unreachable,5234 error.GenericPoison => unreachable,
4729 error.ComptimeReturn => unreachable,5235 error.ComptimeReturn => unreachable,
4730 error.ComptimeBreak => unreachable,5236 error.ComptimeBreak => unreachable,
...@@ -4752,17 +5258,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {...@@ -4752,17 +5258,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
4752 return mod.intern_pool.destroyNamespace(mod.gpa, index);5258 return mod.intern_pool.destroyNamespace(mod.gpa, index);
4753}5259}
47545260
4755pub fn allocateNewDecl(5261pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
4756 mod: *Module,5262 const gpa = zcu.gpa;
4757 namespace: Namespace.Index,5263 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
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, .{
4763 .name = undefined,5264 .name = undefined,
4764 .src_namespace = namespace,5265 .src_namespace = namespace,
4765 .src_node = src_node,
4766 .src_line = undefined,5266 .src_line = undefined,
4767 .has_tv = false,5267 .has_tv = false,
4768 .owns_tv = false,5268 .owns_tv = false,
...@@ -4777,10 +5277,10 @@ pub fn allocateNewDecl(...@@ -4777,10 +5277,10 @@ pub fn allocateNewDecl(
4777 .kind = .anon,5277 .kind = .anon,
4778 });5278 });
47795279
4780 if (mod.emit_h) |mod_emit_h| {5280 if (zcu.emit_h) |zcu_emit_h| {
4781 if (@intFromEnum(decl_index) >= mod_emit_h.allocated_emit_h.len) {5281 if (@intFromEnum(decl_index) >= zcu_emit_h.allocated_emit_h.len) {
4782 try mod_emit_h.allocated_emit_h.append(gpa, .{});5282 try zcu_emit_h.allocated_emit_h.append(gpa, .{});
4783 assert(@intFromEnum(decl_index) == mod_emit_h.allocated_emit_h.len);5283 assert(@intFromEnum(decl_index) == zcu_emit_h.allocated_emit_h.len);
4784 }5284 }
4785 }5285 }
47865286
...@@ -4874,376 +5374,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {...@@ -4874,376 +5374,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
4874 }5374 }
4875}5375}
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
5247/// Called from `Compilation.update`, after everything is done, just before5377/// Called from `Compilation.update`, after everything is done, just before
5248/// reporting compile errors. In this function we emit exported symbol collision5378/// reporting compile errors. In this function we emit exported symbol collision
5249/// errors and communicate exported symbols to the linker backend.5379/// errors and communicate exported symbols to the linker backend.
...@@ -5477,7 +5607,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {...@@ -5477,7 +5607,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
5477 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);5607 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
5478 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(5608 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
5479 gpa,5609 gpa,
5480 decl.srcLoc(zcu),5610 decl.navSrcLoc(zcu).upgrade(zcu),
5481 "unable to codegen: {s}",5611 "unable to codegen: {s}",
5482 .{@errorName(err)},5612 .{@errorName(err)},
5483 ));5613 ));
...@@ -5508,7 +5638,7 @@ fn reportRetryableFileError(...@@ -5508,7 +5638,7 @@ fn reportRetryableFileError(
5508 mod.gpa,5638 mod.gpa,
5509 .{5639 .{
5510 .file_scope = file,5640 .file_scope = file,
5511 .parent_decl_node = 0,5641 .base_node = 0,
5512 .lazy = .entire_file,5642 .lazy = .entire_file,
5513 },5643 },
5514 format,5644 format,
...@@ -6083,27 +6213,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func...@@ -6083,27 +6213,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func
6083 return mod.intern_pool.indexToKey(func_index).func;6213 return mod.intern_pool.indexToKey(func_index).func;
6084}6214}
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
6107pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {6216pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
6108 return mod.intern_pool.toEnum(E, val.toIntern());6217 return mod.intern_pool.toEnum(E, val.toIntern());
6109}6218}
src/RangeSet.zig+4-4
...@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;...@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;
7const Value = @import("Value.zig");7const Value = @import("Value.zig");
8const Module = @import("Module.zig");8const Module = @import("Module.zig");
9const RangeSet = @This();9const RangeSet = @This();
10const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;10const LazySrcLoc = @import("Module.zig").LazySrcLoc;
1111
12ranges: std.ArrayList(Range),12ranges: std.ArrayList(Range),
13module: *Module,13module: *Module,
...@@ -15,7 +15,7 @@ module: *Module,...@@ -15,7 +15,7 @@ module: *Module,
15pub const Range = struct {15pub const Range = struct {
16 first: InternPool.Index,16 first: InternPool.Index,
17 last: InternPool.Index,17 last: InternPool.Index,
18 src: SwitchProngSrc,18 src: LazySrcLoc,
19};19};
2020
21pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {21pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {
...@@ -33,8 +33,8 @@ pub fn add(...@@ -33,8 +33,8 @@ pub fn add(
33 self: *RangeSet,33 self: *RangeSet,
34 first: InternPool.Index,34 first: InternPool.Index,
35 last: InternPool.Index,35 last: InternPool.Index,
36 src: SwitchProngSrc,36 src: LazySrcLoc,
37) !?SwitchProngSrc {37) !?LazySrcLoc {
38 const mod = self.module;38 const mod = self.module;
39 const ip = &mod.intern_pool;39 const ip = &mod.intern_pool;
4040
src/Sema.zig+1789-1906
...@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},...@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},
16air_extra: std.ArrayListUnmanaged(u32) = .{},16air_extra: std.ArrayListUnmanaged(u32) = .{},
17/// Maps ZIR to AIR.17/// Maps ZIR to AIR.
18inst_map: InstMap = .{},18inst_map: InstMap = .{},
19/// When analyzing an inline function call, owner_decl is the Decl of the caller19/// 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`.
22owner_decl: *Decl,20owner_decl: *Decl,
23owner_decl_index: InternPool.DeclIndex,21owner_decl_index: InternPool.DeclIndex,
24/// For an inline or comptime function call, this will be the root parent function22/// For an inline or comptime function call, this will be the root parent function
...@@ -34,7 +32,7 @@ func_index: InternPool.Index,...@@ -34,7 +32,7 @@ func_index: InternPool.Index,
34func_is_naked: bool,32func_is_naked: bool,
35/// Used to restore the error return trace when returning a non-error from a function.33/// Used to restore the error return trace when returning a non-error from a function.
36error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none,34error_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),
38/// When semantic analysis needs to know the return type of the function whose body36/// When semantic analysis needs to know the return type of the function whose body
39/// is being analyzed, this `Type` should be used instead of going through `func`.37/// is being analyzed, this `Type` should be used instead of going through `func`.
40/// This will correctly handle the case of a comptime/inline function call of a38/// This will correctly handle the case of a comptime/inline function call of a
...@@ -65,9 +63,7 @@ generic_owner: InternPool.Index = .none,...@@ -65,9 +63,7 @@ generic_owner: InternPool.Index = .none,
65/// instantiation callsite so that compile errors on the parameter types of the63/// instantiation callsite so that compile errors on the parameter types of the
66/// instantiation can point back to the instantiation site in addition to the64/// instantiation can point back to the instantiation site in addition to the
67/// declaration site.65/// declaration site.
68generic_call_src: LazySrcLoc = .unneeded,66generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
69/// Corresponds to `generic_call_src`.
70generic_call_decl: InternPool.OptionalDeclIndex = .none,
71/// The key is types that must be fully resolved prior to machine code67/// The key is types that must be fully resolved prior to machine code
72/// generation pass. Types are added to this set when resolving them68/// generation pass. Types are added to this set when resolving them
73/// immediately could cause a dependency loop, but they do need to be resolved69/// immediately could cause a dependency loop, but they do need to be resolved
...@@ -131,7 +127,6 @@ const MaybeComptimeAlloc = struct {...@@ -131,7 +127,6 @@ const MaybeComptimeAlloc = struct {
131 /// If the instruction is one of these three tags, `src` may be `.unneeded`.127 /// If the instruction is one of these three tags, `src` may be `.unneeded`.
132 stores: std.MultiArrayList(struct {128 stores: std.MultiArrayList(struct {
133 inst: Air.Inst.Index,129 inst: Air.Inst.Index,
134 src_decl: InternPool.DeclIndex,
135 src: LazySrcLoc,130 src: LazySrcLoc,
136 }) = .{},131 }) = .{},
137};132};
...@@ -182,7 +177,7 @@ const Namespace = Module.Namespace;...@@ -182,7 +177,7 @@ const Namespace = Module.Namespace;
182const CompileError = Module.CompileError;177const CompileError = Module.CompileError;
183const SemaError = Module.SemaError;178const SemaError = Module.SemaError;
184const Decl = Module.Decl;179const Decl = Module.Decl;
185const LazySrcLoc = std.zig.LazySrcLoc;180const LazySrcLoc = Zcu.LazySrcLoc;
186const RangeSet = @import("RangeSet.zig");181const RangeSet = @import("RangeSet.zig");
187const target_util = @import("target.zig");182const target_util = @import("target.zig");
188const Package = @import("Package.zig");183const Package = @import("Package.zig");
...@@ -345,7 +340,6 @@ pub const Block = struct {...@@ -345,7 +340,6 @@ pub const Block = struct {
345 /// Shared among all child blocks.340 /// Shared among all child blocks.
346 sema: *Sema,341 sema: *Sema,
347 /// The namespace to use for lookups from this source block342 /// The namespace to use for lookups from this source block
348 /// When analyzing fields, this is different from src_decl.src_namespace.
349 namespace: InternPool.NamespaceIndex,343 namespace: InternPool.NamespaceIndex,
350 /// The AIR instructions generated for this block.344 /// The AIR instructions generated for this block.
351 instructions: std.ArrayListUnmanaged(Air.Inst.Index),345 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
...@@ -361,12 +355,8 @@ pub const Block = struct {...@@ -361,12 +355,8 @@ pub const Block = struct {
361 label: ?*Label = null,355 label: ?*Label = null,
362 inlining: ?*Inlining,356 inlining: ?*Inlining,
363 /// If runtime_index is not 0 then one of these is guaranteed to be non null.357 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
364 runtime_cond: ?Module.SrcLoc = null,358 runtime_cond: ?LazySrcLoc = null,
365 runtime_loop: ?Module.SrcLoc = null,359 runtime_loop: ?LazySrcLoc = 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,
370 /// Non zero if a non-inline loop or a runtime conditional have been encountered.360 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
371 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.361 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
372 runtime_index: Value.RuntimeIndex = .zero,362 runtime_index: Value.RuntimeIndex = .zero,
...@@ -395,13 +385,45 @@ pub const Block = struct {...@@ -395,13 +385,45 @@ pub const Block = struct {
395 /// `block` in order for codegen to match lexical scoping for debug vars.385 /// `block` in order for codegen to match lexical scoping for debug vars.
396 need_debug_scope: ?*bool = null,386 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
398 const ComptimeReason = union(enum) {422 const ComptimeReason = union(enum) {
399 c_import: struct {423 c_import: struct {
400 block: *Block,
401 src: LazySrcLoc,424 src: LazySrcLoc,
402 },425 },
403 comptime_ret_ty: struct {426 comptime_ret_ty: struct {
404 block: *Block,
405 func: Air.Inst.Ref,427 func: Air.Inst.Ref,
406 func_src: LazySrcLoc,428 func_src: LazySrcLoc,
407 return_ty: Type,429 return_ty: Type,
...@@ -413,27 +435,23 @@ pub const Block = struct {...@@ -413,27 +435,23 @@ pub const Block = struct {
413 const prefix = "expression is evaluated at comptime because ";435 const prefix = "expression is evaluated at comptime because ";
414 switch (cr) {436 switch (cr) {
415 .c_import => |ci| {437 .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", .{});
417 },439 },
418 .comptime_ret_ty => |rt| {440 .comptime_ret_ty => |rt| {
419 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {441 const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{
420 var src_loc = fn_decl.srcLoc(mod);442 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
421 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };443 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
422 break :blk src_loc;444 } else rt.func_src;
423 } else blk: {
424 const src_decl = mod.declPtr(rt.block.src_decl);
425 break :blk src_decl.toSrcLoc(rt.func_src, mod);
426 };
427 if (rt.return_ty.isGenericPoison()) {445 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", .{});
429 }447 }
430 try mod.errNoteNonLazy(448 try sema.errNote(
431 src_loc,449 ret_ty_src,
432 parent,450 parent,
433 prefix ++ "the function returns a comptime-only type '{}'",451 prefix ++ "the function returns a comptime-only type '{}'",
434 .{rt.return_ty.fmt(mod)},452 .{rt.return_ty.fmt(mod)},
435 );453 );
436 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);454 try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty);
437 },455 },
438 }456 }
439 }457 }
...@@ -497,7 +515,6 @@ pub const Block = struct {...@@ -497,7 +515,6 @@ pub const Block = struct {
497 return .{515 return .{
498 .parent = parent,516 .parent = parent,
499 .sema = parent.sema,517 .sema = parent.sema,
500 .src_decl = parent.src_decl,
501 .namespace = parent.namespace,518 .namespace = parent.namespace,
502 .instructions = .{},519 .instructions = .{},
503 .label = null,520 .label = null,
...@@ -513,6 +530,8 @@ pub const Block = struct {...@@ -513,6 +530,8 @@ pub const Block = struct {
513 .c_import_buf = parent.c_import_buf,530 .c_import_buf = parent.c_import_buf,
514 .error_return_trace_index = parent.error_return_trace_index,531 .error_return_trace_index = parent.error_return_trace_index,
515 .need_debug_scope = parent.need_debug_scope,532 .need_debug_scope = parent.need_debug_scope,
533 .src_base_inst = parent.src_base_inst,
534 .type_name_ctx = parent.type_name_ctx,
516 };535 };
517 }536 }
518537
...@@ -803,14 +822,6 @@ pub const Block = struct {...@@ -803,14 +822,6 @@ pub const Block = struct {
803 return result_index;822 return result_index;
804 }823 }
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
814 pub fn ownerModule(block: Block) *Package.Module {825 pub fn ownerModule(block: Block) *Package.Module {
815 const zcu = block.sema.mod;826 const zcu = block.sema.mod;
816 return zcu.namespacePtr(block.namespace).file_scope.mod;827 return zcu.namespacePtr(block.namespace).file_scope.mod;
...@@ -981,9 +992,16 @@ fn analyzeBodyInner(...@@ -981,9 +992,16 @@ fn analyzeBodyInner(
981 while (true) {992 while (true) {
982 crash_info.setBodyIndex(i);993 crash_info.setBodyIndex(i);
983 const inst = body[i];994 const inst = body[i];
984 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{995
985 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,996 // The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away.
986 });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
987 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {1005 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
988 // zig fmt: off1006 // zig fmt: off
989 .alloc => try sema.zirAlloc(block, inst),1007 .alloc => try sema.zirAlloc(block, inst),
...@@ -1225,7 +1243,7 @@ fn analyzeBodyInner(...@@ -1225,7 +1243,7 @@ fn analyzeBodyInner(
1225 .@"asm" => try sema.zirAsm( block, extended, false),1243 .@"asm" => try sema.zirAsm( block, extended, false),
1226 .asm_expr => try sema.zirAsm( block, extended, true),1244 .asm_expr => try sema.zirAsm( block, extended, true),
1227 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),1245 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),
1228 .compile_log => try sema.zirCompileLog( extended),1246 .compile_log => try sema.zirCompileLog( block, extended),
1229 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),1247 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),
1230 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),1248 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),
1231 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),1249 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
...@@ -1449,7 +1467,7 @@ fn analyzeBodyInner(...@@ -1449,7 +1467,7 @@ fn analyzeBodyInner(
1449 .check_comptime_control_flow => {1467 .check_comptime_control_flow => {
1450 if (!block.is_comptime) {1468 if (!block.is_comptime) {
1451 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;1469 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);
1453 const inline_block = inst_data.operand.toIndex().?;1471 const inline_block = inst_data.operand.toIndex().?;
14541472
1455 var check_block = block;1473 var check_block = block;
...@@ -1463,10 +1481,9 @@ fn analyzeBodyInner(...@@ -1463,10 +1481,9 @@ fn analyzeBodyInner(
1463 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {1481 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {
1464 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;1482 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
1465 const msg = msg: {1483 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", .{});
1467 errdefer msg.destroy(sema.gpa);1485 errdefer msg.destroy(sema.gpa);
14681486 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
1469 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
1470 break :msg msg;1487 break :msg msg;
1471 };1488 };
1472 return sema.failWithOwnedErrorMsg(block, msg);1489 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -1482,13 +1499,13 @@ fn analyzeBodyInner(...@@ -1482,13 +1499,13 @@ fn analyzeBodyInner(
1482 },1499 },
1483 .restore_err_ret_index_unconditional => {1500 .restore_err_ret_index_unconditional => {
1484 const un_node = datas[@intFromEnum(inst)].un_node;1501 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);
1486 i += 1;1503 i += 1;
1487 continue;1504 continue;
1488 },1505 },
1489 .restore_err_ret_index_fn_entry => {1506 .restore_err_ret_index_fn_entry => {
1490 const un_node = datas[@intFromEnum(inst)].un_node;1507 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);
1492 i += 1;1509 i += 1;
1493 continue;1510 continue;
1494 },1511 },
...@@ -1510,7 +1527,7 @@ fn analyzeBodyInner(...@@ -1510,7 +1527,7 @@ fn analyzeBodyInner(
1510 .repeat => {1527 .repeat => {
1511 if (block.is_comptime) {1528 if (block.is_comptime) {
1512 // Send comptime control flow back to the beginning of this block.1529 // 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);
1514 try sema.emitBackwardBranch(block, src);1531 try sema.emitBackwardBranch(block, src);
1515 i = 0;1532 i = 0;
1516 continue;1533 continue;
...@@ -1523,7 +1540,7 @@ fn analyzeBodyInner(...@@ -1523,7 +1540,7 @@ fn analyzeBodyInner(
1523 },1540 },
1524 .repeat_inline => {1541 .repeat_inline => {
1525 // Send comptime control flow back to the beginning of this block.1542 // 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);
1527 try sema.emitBackwardBranch(block, src);1544 try sema.emitBackwardBranch(block, src);
1528 i = 0;1545 i = 0;
1529 continue;1546 continue;
...@@ -1667,7 +1684,7 @@ fn analyzeBodyInner(...@@ -1667,7 +1684,7 @@ fn analyzeBodyInner(
1667 try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]);1684 try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]);
1668 block.instructions.items.len = block_index;1685 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);
1671 {1688 {
1672 // Destroy the ad-hoc block entry so that it does not interfere with1689 // Destroy the ad-hoc block entry so that it does not interfere with
1673 // the next iteration of comptime control flow, if any.1690 // the next iteration of comptime control flow, if any.
...@@ -1693,7 +1710,7 @@ fn analyzeBodyInner(...@@ -1693,7 +1710,7 @@ fn analyzeBodyInner(
1693 }1710 }
1694 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/82201711 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
1695 const inst_data = datas[@intFromEnum(inst)].pl_node;1712 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 });
1697 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);1714 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1698 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);1715 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1699 const else_body = sema.code.bodySlice(1716 const else_body = sema.code.bodySlice(
...@@ -1713,7 +1730,7 @@ fn analyzeBodyInner(...@@ -1713,7 +1730,7 @@ fn analyzeBodyInner(
1713 },1730 },
1714 .condbr_inline => blk: {1731 .condbr_inline => blk: {
1715 const inst_data = datas[@intFromEnum(inst)].pl_node;1732 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 });
1717 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);1734 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1718 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);1735 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1719 const else_body = sema.code.bodySlice(1736 const else_body = sema.code.bodySlice(
...@@ -1736,8 +1753,8 @@ fn analyzeBodyInner(...@@ -1736,8 +1753,8 @@ fn analyzeBodyInner(
1736 .@"try" => blk: {1753 .@"try" => blk: {
1737 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);1754 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
1738 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1755 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1739 const src = inst_data.src();1756 const src = block.nodeOffset(inst_data.src_node);
1740 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };1757 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1741 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);1758 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1742 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);1759 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
1743 const err_union = try sema.resolveInst(extra.data.operand);1760 const err_union = try sema.resolveInst(extra.data.operand);
...@@ -1762,8 +1779,8 @@ fn analyzeBodyInner(...@@ -1762,8 +1779,8 @@ fn analyzeBodyInner(
1762 .try_ptr => blk: {1779 .try_ptr => blk: {
1763 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);1780 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
1764 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1781 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1765 const src = inst_data.src();1782 const src = block.nodeOffset(inst_data.src_node);
1766 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };1783 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1767 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);1784 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1768 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);1785 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
1769 const operand = try sema.resolveInst(extra.data.operand);1786 const operand = try sema.resolveInst(extra.data.operand);
...@@ -1927,14 +1944,14 @@ fn resolveDestType(...@@ -1927,14 +1944,14 @@ fn resolveDestType(
1927 // Cast builtins use their result type as the destination type, but1944 // Cast builtins use their result type as the destination type, but
1928 // it could be an anytype argument, which we can't catch in AstGen.1945 // it could be an anytype argument, which we can't catch in AstGen.
1929 const msg = msg: {1946 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});
1931 errdefer msg.destroy(sema.gpa);1948 errdefer msg.destroy(sema.gpa);
1932 switch (sema.genericPoisonReason(zir_ref)) {1949 switch (sema.genericPoisonReason(block, zir_ref)) {
1933 .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}),1950 .anytype_param => |call_src| try sema.errNote(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", .{}),1951 .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
1935 .unknown => {},1952 .unknown => {},
1936 }1953 }
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", .{});
1938 break :msg msg;1955 break :msg msg;
1939 };1956 };
1940 return sema.failWithOwnedErrorMsg(block, msg);1957 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -1963,7 +1980,7 @@ const GenericPoisonReason = union(enum) {...@@ -1963,7 +1980,7 @@ const GenericPoisonReason = union(enum) {
19631980
1964/// Backtracks through ZIR instructions to determine the reason a generic poison1981/// Backtracks through ZIR instructions to determine the reason a generic poison
1965/// type was created. Used for error reporting.1982/// 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 {
1967 var cur = ref;1984 var cur = ref;
1968 while (true) {1985 while (true) {
1969 const inst = cur.toIndex() orelse return .unknown;1986 const inst = cur.toIndex() orelse return .unknown;
...@@ -1999,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {...@@ -1999,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
1999 cur = un_node.operand;2016 cur = un_node.operand;
2000 } else {2017 } else {
2001 // This must be an anyopaque pointer!2018 // This must be an anyopaque pointer!
2002 return .{ .anyopaque_ptr = un_node.src() };2019 return .{ .anyopaque_ptr = block.nodeOffset(un_node.src_node) };
2003 }2020 }
2004 },2021 },
2005 .call, .field_call => {2022 .call, .field_call => {
...@@ -2007,7 +2024,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {...@@ -2007,7 +2024,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
2007 // evaluating an `anytype` function parameter.2024 // evaluating an `anytype` function parameter.
2008 // TODO: better source location - function decl rather than call2025 // TODO: better source location - function decl rather than call
2009 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2026 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) };
2011 },2028 },
2012 else => return .unknown,2029 else => return .unknown,
2013 }2030 }
...@@ -2039,7 +2056,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)...@@ -2039,7 +2056,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
2039 var err_trace_block = block.makeSubBlock();2056 var err_trace_block = block.makeSubBlock();
2040 defer err_trace_block.instructions.deinit(gpa);2057 defer err_trace_block.instructions.deinit(gpa);
20412058
2042 const src: LazySrcLoc = .unneeded;2059 const src: LazySrcLoc = LazySrcLoc.unneeded;
20432060
2044 // var addrs: [err_return_trace_addr_count]usize = undefined;2061 // var addrs: [err_return_trace_addr_count]usize = undefined;
2045 const err_return_trace_addr_count = 32;2062 const err_return_trace_addr_count = 32;
...@@ -2200,9 +2217,9 @@ pub fn resolveFinalDeclValue(...@@ -2200,9 +2217,9 @@ pub fn resolveFinalDeclValue(
22002217
2201fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {2218fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
2202 const msg = msg: {2219 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", .{});
2204 errdefer msg.destroy(sema.gpa);2221 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
2207 if (reason.block_comptime_reason) |block_comptime_reason| {2224 if (reason.block_comptime_reason) |block_comptime_reason| {
2208 try block_comptime_reason.explain(sema, msg);2225 try block_comptime_reason.explain(sema, msg);
...@@ -2229,12 +2246,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T...@@ -2229,12 +2246,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T
2229fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {2246fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
2230 const mod = sema.mod;2247 const mod = sema.mod;
2231 const msg = msg: {2248 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 '{}'", .{
2233 non_optional_ty.fmt(mod),2250 non_optional_ty.fmt(mod),
2234 });2251 });
2235 errdefer msg.destroy(sema.gpa);2252 errdefer msg.destroy(sema.gpa);
2236 if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {2253 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'", .{});
2238 }2255 }
2239 try addDeclaredHereNote(sema, msg, non_optional_ty);2256 try addDeclaredHereNote(sema, msg, non_optional_ty);
2240 break :msg msg;2257 break :msg msg;
...@@ -2245,12 +2262,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non...@@ -2245,12 +2262,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
2245fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {2262fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2246 const mod = sema.mod;2263 const mod = sema.mod;
2247 const msg = msg: {2264 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", .{
2249 ty.fmt(mod),2266 ty.fmt(mod),
2250 });2267 });
2251 errdefer msg.destroy(sema.gpa);2268 errdefer msg.destroy(sema.gpa);
2252 if (ty.isSlice(mod)) {2269 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)});
2254 }2271 }
2255 break :msg msg;2272 break :msg msg;
2256 };2273 };
...@@ -2279,11 +2296,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2279,11 +2296,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2279 const zcu = sema.mod;2296 const zcu = sema.mod;
2280 if (int_ty.zigTypeTag(zcu) == .Vector) {2297 if (int_ty.zigTypeTag(zcu) == .Vector) {
2281 const msg = msg: {2298 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 '{}'", .{
2283 int_ty.fmt(zcu), val.fmtValue(zcu, sema),2300 int_ty.fmt(zcu), val.fmtValue(zcu, sema),
2284 });2301 });
2285 errdefer msg.destroy(sema.gpa);2302 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});
2287 break :msg msg;2304 break :msg msg;
2288 };2305 };
2289 return sema.failWithOwnedErrorMsg(block, msg);2306 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2296,15 +2313,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2296,15 +2313,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2296fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {2313fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
2297 const mod = sema.mod;2314 const mod = sema.mod;
2298 const msg = msg: {2315 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", .{});
2300 errdefer msg.destroy(sema.gpa);2317 errdefer msg.destroy(sema.gpa);
23012318
2302 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;2319 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;
2303 const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{2320 try sema.errNote(.{
2304 .index = field_index,2321 .base_node_inst = struct_type.zir_index.unwrap().?,
2305 .range = .value,2322 .offset = .{ .container_field_value = @intCast(field_index) },
2306 });2323 }, msg, "default value set here", .{});
2307 try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{});
2308 break :msg msg;2324 break :msg msg;
2309 };2325 };
2310 return sema.failWithOwnedErrorMsg(block, msg);2326 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2312,7 +2328,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS...@@ -2312,7 +2328,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
23122328
2313fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {2329fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
2314 const msg = msg: {2330 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", .{});
2316 errdefer msg.destroy(sema.gpa);2332 errdefer msg.destroy(sema.gpa);
2317 break :msg msg;2333 break :msg msg;
2318 };2334 };
...@@ -2333,9 +2349,9 @@ fn failWithInvalidFieldAccess(...@@ -2333,9 +2349,9 @@ fn failWithInvalidFieldAccess(
2333 const child_ty = inner_ty.optionalChild(mod);2349 const child_ty = inner_ty.optionalChild(mod);
2334 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;2350 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
2335 const msg = msg: {2351 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)});
2337 errdefer msg.destroy(sema.gpa);2353 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'", .{});
2339 break :msg msg;2355 break :msg msg;
2340 };2356 };
2341 return sema.failWithOwnedErrorMsg(block, msg);2357 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2343,9 +2359,9 @@ fn failWithInvalidFieldAccess(...@@ -2343,9 +2359,9 @@ fn failWithInvalidFieldAccess(
2343 const child_ty = inner_ty.errorUnionPayload(mod);2359 const child_ty = inner_ty.errorUnionPayload(mod);
2344 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;2360 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
2345 const msg = msg: {2361 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)});
2347 errdefer msg.destroy(sema.gpa);2363 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'", .{});
2349 break :msg msg;2365 break :msg msg;
2350 };2366 };
2351 return sema.failWithOwnedErrorMsg(block, msg);2367 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2378,11 +2394,11 @@ fn failWithComptimeErrorRetTrace(...@@ -2378,11 +2394,11 @@ fn failWithComptimeErrorRetTrace(
2378) CompileError {2394) CompileError {
2379 const mod = sema.mod;2395 const mod = sema.mod;
2380 const msg = msg: {2396 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)});
2382 errdefer msg.destroy(sema.gpa);2398 errdefer msg.destroy(sema.gpa);
23832399
2384 for (sema.comptime_err_ret_trace.items) |src_loc| {2400 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", .{});
2386 }2402 }
2387 break :msg msg;2403 break :msg msg;
2388 };2404 };
...@@ -2391,17 +2407,15 @@ fn failWithComptimeErrorRetTrace(...@@ -2391,17 +2407,15 @@ fn failWithComptimeErrorRetTrace(
23912407
2392/// We don't return a pointer to the new error note because the pointer2408/// We don't return a pointer to the new error note because the pointer
2393/// becomes invalid when you add another one.2409/// becomes invalid when you add another one.
2394fn errNote(2410pub fn errNote(
2395 sema: *Sema,2411 sema: *Sema,
2396 block: *Block,
2397 src: LazySrcLoc,2412 src: LazySrcLoc,
2398 parent: *Module.ErrorMsg,2413 parent: *Module.ErrorMsg,
2399 comptime format: []const u8,2414 comptime format: []const u8,
2400 args: anytype,2415 args: anytype,
2401) error{OutOfMemory}!void {2416) error{OutOfMemory}!void {
2402 const mod = sema.mod;2417 const zcu = sema.mod;
2403 const src_decl = mod.declPtr(block.src_decl);2418 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
2404 return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args);
2405}2419}
24062420
2407fn addFieldErrNote(2421fn addFieldErrNote(
...@@ -2413,52 +2427,23 @@ fn addFieldErrNote(...@@ -2413,52 +2427,23 @@ fn addFieldErrNote(
2413 args: anytype,2427 args: anytype,
2414) !void {2428) !void {
2415 @setCold(true);2429 @setCold(true);
2416 const mod = sema.mod;2430 const zcu = sema.mod;
2417 const decl_index = container_ty.getOwnerDecl(mod);2431 const type_src = container_ty.srcLocOrNull(zcu) orelse return;
2418 const decl = mod.declPtr(decl_index);2432 const field_src: LazySrcLoc = .{
24192433 .base_node_inst = type_src.base_node_inst,
2420 const field_src = blk: {2434 .offset = .{ .container_field_name = @intCast(field_index) },
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;
2447 };2435 };
2448 try mod.errNoteNonLazy(field_src, parent, format, args);2436 try sema.errNote(field_src, parent, format, args);
2449}2437}
24502438
2451pub fn errMsg(2439pub fn errMsg(
2452 sema: *Sema,2440 sema: *Sema,
2453 block: *Block,
2454 src: LazySrcLoc,2441 src: LazySrcLoc,
2455 comptime format: []const u8,2442 comptime format: []const u8,
2456 args: anytype,2443 args: anytype,
2457) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg {2444) Allocator.Error!*Module.ErrorMsg {
2458 const mod = sema.mod;2445 assert(src.offset != .unneeded);
2459 if (src == .unneeded) return error.NeededSourceLocation;2446 return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args);
2460 const src_decl = mod.declPtr(block.src_decl);
2461 return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args);
2462}2447}
24632448
2464pub fn fail(2449pub fn fail(
...@@ -2468,7 +2453,7 @@ pub fn fail(...@@ -2468,7 +2453,7 @@ pub fn fail(
2468 comptime format: []const u8,2453 comptime format: []const u8,
2469 args: anytype,2454 args: anytype,
2470) CompileError {2455) CompileError {
2471 const err_msg = try sema.errMsg(block, src, format, args);2456 const err_msg = try sema.errMsg(src, format, args);
2472 inline for (args) |arg| {2457 inline for (args) |arg| {
2473 if (@TypeOf(arg) == Type.Formatter) {2458 if (@TypeOf(arg) == Type.Formatter) {
2474 try addDeclaredHereNote(sema, err_msg, arg.data.ty);2459 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
...@@ -2502,7 +2487,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2502,7 +2487,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2502 var block_it = start_block;2487 var block_it = start_block;
2503 while (block_it.inlining) |inlining| {2488 while (block_it.inlining) |inlining| {
2504 try sema.errNote(2489 try sema.errNote(
2505 inlining.call_block,
2506 inlining.call_src,2490 inlining.call_src,
2507 err_msg,2491 err_msg,
2508 "called from here",2492 "called from here",
...@@ -2536,7 +2520,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2536,7 +2520,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2536 const decl = mod.declPtr(ref.referencer);2520 const decl = mod.declPtr(ref.referencer);
2537 try reference_stack.append(.{2521 try reference_stack.append(.{
2538 .decl = decl.name,2522 .decl = decl.name,
2539 .src_loc = decl.toSrcLoc(ref.src, mod),2523 .src_loc = ref.src.upgrade(mod),
2540 });2524 });
2541 }2525 }
2542 referenced_by = ref.referencer;2526 referenced_by = ref.referencer;
...@@ -2571,15 +2555,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2571,15 +2555,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2571/// Reference trace is preserved.2555/// Reference trace is preserved.
2572fn reparentOwnedErrorMsg(2556fn reparentOwnedErrorMsg(
2573 sema: *Sema,2557 sema: *Sema,
2574 block: *Block,
2575 src: LazySrcLoc,2558 src: LazySrcLoc,
2576 msg: *Module.ErrorMsg,2559 msg: *Module.ErrorMsg,
2577 comptime format: []const u8,2560 comptime format: []const u8,
2578 args: anytype,2561 args: anytype,
2579) !void {2562) !void {
2580 const mod = sema.mod;2563 const mod = sema.mod;
2581 const src_decl = mod.declPtr(block.src_decl);2564 const resolved_src = src.upgrade(mod);
2582 const resolved_src = src_decl.toSrcLoc(src, mod);
2583 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);2565 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25842566
2585 const orig_notes = msg.notes.len;2567 const orig_notes = msg.notes.len;
...@@ -2716,7 +2698,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2716,7 +2698,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2716 sema.code.nullTerminatedString(str),2698 sema.code.nullTerminatedString(str),
2717 .no_embedded_nulls,2699 .no_embedded_nulls,
2718 );2700 );
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?
2720 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });2702 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
2721 },2703 },
2722 .decl_ref => |str| capture: {2704 .decl_ref => |str| capture: {
...@@ -2725,7 +2707,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2725,7 +2707,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2725 sema.code.nullTerminatedString(str),2707 sema.code.nullTerminatedString(str),
2726 .no_embedded_nulls,2708 .no_embedded_nulls,
2727 );2709 );
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?
2729 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });2711 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
2730 },2712 },
2731 };2713 };
...@@ -2776,7 +2758,13 @@ fn zirStructDecl(...@@ -2776,7 +2758,13 @@ fn zirStructDecl(
2776 const ip = &mod.intern_pool;2758 const ip = &mod.intern_pool;
2777 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);2759 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
2778 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);2760 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
2780 var extra_index = extra.end;2768 var extra_index = extra.end;
27812769
2782 const captures_len = if (small.has_captures_len) blk: {2770 const captures_len = if (small.has_captures_len) blk: {
...@@ -2820,7 +2808,7 @@ fn zirStructDecl(...@@ -2820,7 +2808,7 @@ fn zirStructDecl(
2820 .any_aligned_fields = small.any_aligned_fields,2808 .any_aligned_fields = small.any_aligned_fields,
2821 .has_namespace = true or decls_len > 0, // TODO: see below2809 .has_namespace = true or decls_len > 0, // TODO: see below
2822 .key = .{ .declared = .{2810 .key = .{ .declared = .{
2823 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),2811 .zir_index = tracked_inst,
2824 .captures = captures,2812 .captures = captures,
2825 } },2813 } },
2826 };2814 };
...@@ -2835,11 +2823,11 @@ fn zirStructDecl(...@@ -2835,11 +2823,11 @@ fn zirStructDecl(
28352823
2836 const new_decl_index = try sema.createAnonymousDeclTypeNamed(2824 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2837 block,2825 block,
2838 src,
2839 Value.fromInterned(wip_ty.index),2826 Value.fromInterned(wip_ty.index),
2840 small.name_strategy,2827 small.name_strategy,
2841 "struct",2828 "struct",
2842 inst,2829 inst,
2830 extra.data.src_line,
2843 );2831 );
2844 mod.declPtr(new_decl_index).owns_tv = true;2832 mod.declPtr(new_decl_index).owns_tv = true;
2845 errdefer mod.abortAnonDecl(new_decl_index);2833 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -2872,42 +2860,26 @@ fn zirStructDecl(...@@ -2872,42 +2860,26 @@ fn zirStructDecl(
2872fn createAnonymousDeclTypeNamed(2860fn createAnonymousDeclTypeNamed(
2873 sema: *Sema,2861 sema: *Sema,
2874 block: *Block,2862 block: *Block,
2875 src: LazySrcLoc,
2876 val: Value,2863 val: Value,
2877 name_strategy: Zir.Inst.NameStrategy,2864 name_strategy: Zir.Inst.NameStrategy,
2878 anon_prefix: []const u8,2865 anon_prefix: []const u8,
2879 inst: ?Zir.Inst.Index,2866 inst: ?Zir.Inst.Index,
2867 src_line: u32,
2880) !InternPool.DeclIndex {2868) !InternPool.DeclIndex {
2881 const zcu = sema.mod;2869 const zcu = sema.mod;
2882 const ip = &zcu.intern_pool;2870 const ip = &zcu.intern_pool;
2883 const gpa = sema.gpa;2871 const gpa = sema.gpa;
2884 const namespace = block.namespace;2872 const namespace = block.namespace;
2885 const src_decl = zcu.declPtr(block.src_decl);2873 const new_decl_index = try zcu.allocateNewDecl(namespace);
2886 const src_node = src_decl.relativeToNodeIndex(src.node_offset.x);
2887 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);
2888 errdefer zcu.destroyDecl(new_decl_index);2874 errdefer zcu.destroyDecl(new_decl_index);
28892875
2890 switch (name_strategy) {2876 switch (name_strategy) {
2891 .anon => {2877 .anon => {}, // handled after switch
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 },
2905 .parent => {2878 .parent => {
2906 const name = zcu.declPtr(block.src_decl).name;2879 try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx);
2907 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2908 return new_decl_index;2880 return new_decl_index;
2909 },2881 },
2910 .func => {2882 .func => func_strat: {
2911 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip));2883 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip));
2912 const zir_tags = sema.code.instructions.items(.tag);2884 const zir_tags = sema.code.instructions.items(.tag);
29132885
...@@ -2915,7 +2887,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2915,7 +2887,7 @@ fn createAnonymousDeclTypeNamed(
2915 defer buf.deinit();2887 defer buf.deinit();
29162888
2917 const writer = buf.writer();2889 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
2920 var arg_i: usize = 0;2892 var arg_i: usize = 0;
2921 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {2893 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
...@@ -2926,8 +2898,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2926,8 +2898,7 @@ fn createAnonymousDeclTypeNamed(
2926 // If not then this is a struct type being returned from a non-generic2898 // If not then this is a struct type being returned from a non-generic
2927 // function and the name doesn't matter since it will later2899 // function and the name doesn't matter since it will later
2928 // result in a compile error.2900 // result in a compile error.
2929 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch2901 const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat
2930 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);
29312902
2932 if (arg_i != 0) try writer.writeByte(',');2903 if (arg_i != 0) try writer.writeByte(',');
29332904
...@@ -2950,7 +2921,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2950,7 +2921,7 @@ fn createAnonymousDeclTypeNamed(
29502921
2951 try writer.writeByte(')');2922 try writer.writeByte(')');
2952 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);2923 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);
2954 return new_decl_index;2925 return new_decl_index;
2955 },2926 },
2956 .dbg_var => {2927 .dbg_var => {
...@@ -2962,16 +2933,31 @@ fn createAnonymousDeclTypeNamed(...@@ -2962,16 +2933,31 @@ fn createAnonymousDeclTypeNamed(
2962 if (zir_data[i].str_op.operand != ref) continue;2933 if (zir_data[i].str_op.operand != ref) continue;
29632934
2964 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{2935 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),
2966 }, .no_embedded_nulls);2937 }, .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);
2968 return new_decl_index;2939 return new_decl_index;
2969 },2940 },
2970 else => {},2941 else => {},
2971 };2942 };
2972 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);2943 // fall through to anon strat
2973 },2944 },
2974 }2945 }
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;
2975}2961}
29762962
2977fn zirEnumDecl(2963fn zirEnumDecl(
...@@ -2990,8 +2976,9 @@ fn zirEnumDecl(...@@ -2990,8 +2976,9 @@ fn zirEnumDecl(
2990 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);2976 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
2991 var extra_index: usize = extra.end;2977 var extra_index: usize = extra.end;
29922978
2993 const src = extra.data.src();2979 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2994 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };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
2996 const tag_type_ref = if (small.has_tag_type) blk: {2983 const tag_type_ref = if (small.has_tag_type) blk: {
2997 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);2984 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
...@@ -3051,7 +3038,7 @@ fn zirEnumDecl(...@@ -3051,7 +3038,7 @@ fn zirEnumDecl(
3051 .explicit,3038 .explicit,
3052 .fields_len = fields_len,3039 .fields_len = fields_len,
3053 .key = .{ .declared = .{3040 .key = .{ .declared = .{
3054 .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst),3041 .zir_index = tracked_inst,
3055 .captures = captures,3042 .captures = captures,
3056 } },3043 } },
3057 };3044 };
...@@ -3071,11 +3058,11 @@ fn zirEnumDecl(...@@ -3071,11 +3058,11 @@ fn zirEnumDecl(
30713058
3072 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3059 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3073 block,3060 block,
3074 src,
3075 Value.fromInterned(wip_ty.index),3061 Value.fromInterned(wip_ty.index),
3076 small.name_strategy,3062 small.name_strategy,
3077 "enum",3063 "enum",
3078 inst,3064 inst,
3065 extra.data.src_line,
3079 );3066 );
3080 const new_decl = mod.declPtr(new_decl_index);3067 const new_decl = mod.declPtr(new_decl_index);
3081 new_decl.owns_tv = true;3068 new_decl.owns_tv = true;
...@@ -3132,11 +3119,12 @@ fn zirEnumDecl(...@@ -3132,11 +3119,12 @@ fn zirEnumDecl(
3132 var enum_block: Block = .{3119 var enum_block: Block = .{
3133 .parent = null,3120 .parent = null,
3134 .sema = sema,3121 .sema = sema,
3135 .src_decl = new_decl_index,
3136 .namespace = new_namespace_index.unwrap() orelse block.namespace,3122 .namespace = new_namespace_index.unwrap() orelse block.namespace,
3137 .instructions = .{},3123 .instructions = .{},
3138 .inlining = null,3124 .inlining = null,
3139 .is_comptime = true,3125 .is_comptime = true,
3126 .src_base_inst = tracked_inst,
3127 .type_name_ctx = new_decl.name,
3140 };3128 };
3141 defer enum_block.instructions.deinit(sema.gpa);3129 defer enum_block.instructions.deinit(sema.gpa);
31423130
...@@ -3145,9 +3133,9 @@ fn zirEnumDecl(...@@ -3145,9 +3133,9 @@ fn zirEnumDecl(
3145 }3133 }
31463134
3147 if (tag_type_ref != .none) {3135 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);
3149 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {3137 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)});
3151 }3139 }
3152 break :ty ty;3140 break :ty ty;
3153 } else if (fields_len == 0) {3141 } else if (fields_len == 0) {
...@@ -3184,36 +3172,33 @@ fn zirEnumDecl(...@@ -3184,36 +3172,33 @@ fn zirEnumDecl(
31843172
3185 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);3173 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
3187 const tag_overflow = if (has_tag_value) overflow: {3180 const tag_overflow = if (has_tag_value) overflow: {
3188 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);3181 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
3189 extra_index += 1;3182 extra_index += 1;
3190 const tag_inst = try sema.resolveInst(tag_val_ref);3183 const tag_inst = try sema.resolveInst(tag_val_ref);
3191 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {3184 last_tag_val = try sema.resolveConstDefinedValue(block, .{
3192 error.NeededSourceLocation => {3185 .base_node_inst = tracked_inst,
3193 const value_src = mod.fieldSrcLoc(new_decl_index, .{3186 .offset = .{ .container_field_name = field_i },
3194 .index = field_i,3187 }, tag_inst, .{
3195 .range = .value,3188 .needed_comptime_reason = "enum tag value must be comptime-known",
3196 }).lazy;3189 });
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 };
3204 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;3190 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;
3205 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);3191 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);
3206 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {3192 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
3207 assert(conflict.kind == .value); // AstGen validated names are unique3193 assert(conflict.kind == .value); // AstGen validated names are unique
3208 const value_src = mod.fieldSrcLoc(new_decl_index, .{3194 const other_field_src: LazySrcLoc = .{
3209 .index = field_i,3195 .base_node_inst = tracked_inst,
3210 .range = .value,3196 .offset = .{ .container_field_value = conflict.prev_field_idx },
3211 }).lazy;3197 };
3212 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3213 const msg = msg: {3198 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)});
3215 errdefer msg.destroy(gpa);3200 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", .{});
3217 break :msg msg;3202 break :msg msg;
3218 };3203 };
3219 return sema.failWithOwnedErrorMsg(block, msg);3204 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3228,12 +3213,14 @@ fn zirEnumDecl(...@@ -3228,12 +3213,14 @@ fn zirEnumDecl(
3228 if (overflow != null) break :overflow true;3213 if (overflow != null) break :overflow true;
3229 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {3214 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
3230 assert(conflict.kind == .value); // AstGen validated names are unique3215 assert(conflict.kind == .value); // AstGen validated names are unique
3231 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;3216 const other_field_src: LazySrcLoc = .{
3232 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;3217 .base_node_inst = tracked_inst,
3218 .offset = .{ .container_field_value = conflict.prev_field_idx },
3219 };
3233 const msg = msg: {3220 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)});
3235 errdefer msg.destroy(gpa);3222 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", .{});
3237 break :msg msg;3224 break :msg msg;
3238 };3225 };
3239 return sema.failWithOwnedErrorMsg(block, msg);3226 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3248,11 +3235,7 @@ fn zirEnumDecl(...@@ -3248,11 +3235,7 @@ fn zirEnumDecl(
3248 };3235 };
32493236
3250 if (tag_overflow) {3237 if (tag_overflow) {
3251 const value_src = mod.fieldSrcLoc(new_decl_index, .{3238 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{
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 '{}'", .{
3256 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),3239 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),
3257 });3240 });
3258 return sema.failWithOwnedErrorMsg(block, msg);3241 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3279,7 +3262,8 @@ fn zirUnionDecl(...@@ -3279,7 +3262,8 @@ fn zirUnionDecl(
3279 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);3262 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
3280 var extra_index: usize = extra.end;3263 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
3284 extra_index += @intFromBool(small.has_tag_type);3268 extra_index += @intFromBool(small.has_tag_type);
3285 const captures_len = if (small.has_captures_len) blk: {3269 const captures_len = if (small.has_captures_len) blk: {
...@@ -3327,7 +3311,7 @@ fn zirUnionDecl(...@@ -3327,7 +3311,7 @@ fn zirUnionDecl(
3327 .field_types = &.{}, // set later3311 .field_types = &.{}, // set later
3328 .field_aligns = &.{}, // set later3312 .field_aligns = &.{}, // set later
3329 .key = .{ .declared = .{3313 .key = .{ .declared = .{
3330 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),3314 .zir_index = tracked_inst,
3331 .captures = captures,3315 .captures = captures,
3332 } },3316 } },
3333 };3317 };
...@@ -3342,11 +3326,11 @@ fn zirUnionDecl(...@@ -3342,11 +3326,11 @@ fn zirUnionDecl(
33423326
3343 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3327 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3344 block,3328 block,
3345 src,
3346 Value.fromInterned(wip_ty.index),3329 Value.fromInterned(wip_ty.index),
3347 small.name_strategy,3330 small.name_strategy,
3348 "union",3331 "union",
3349 inst,3332 inst,
3333 extra.data.src_line,
3350 );3334 );
3351 mod.declPtr(new_decl_index).owns_tv = true;3335 mod.declPtr(new_decl_index).owns_tv = true;
3352 errdefer mod.abortAnonDecl(new_decl_index);3336 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -3394,7 +3378,8 @@ fn zirOpaqueDecl(...@@ -3394,7 +3378,8 @@ fn zirOpaqueDecl(
3394 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);3378 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
3395 var extra_index: usize = extra.end;3379 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
3399 const captures_len = if (small.has_captures_len) blk: {3384 const captures_len = if (small.has_captures_len) blk: {
3400 const captures_len = sema.code.extra[extra_index];3385 const captures_len = sema.code.extra[extra_index];
...@@ -3414,7 +3399,7 @@ fn zirOpaqueDecl(...@@ -3414,7 +3399,7 @@ fn zirOpaqueDecl(
3414 const opaque_init: InternPool.OpaqueTypeInit = .{3399 const opaque_init: InternPool.OpaqueTypeInit = .{
3415 .has_namespace = decls_len != 0,3400 .has_namespace = decls_len != 0,
3416 .key = .{ .declared = .{3401 .key = .{ .declared = .{
3417 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),3402 .zir_index = tracked_inst,
3418 .captures = captures,3403 .captures = captures,
3419 } },3404 } },
3420 };3405 };
...@@ -3430,11 +3415,11 @@ fn zirOpaqueDecl(...@@ -3430,11 +3415,11 @@ fn zirOpaqueDecl(
34303415
3431 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3416 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3432 block,3417 block,
3433 src,
3434 Value.fromInterned(wip_ty.index),3418 Value.fromInterned(wip_ty.index),
3435 small.name_strategy,3419 small.name_strategy,
3436 "opaque",3420 "opaque",
3437 inst,3421 inst,
3422 extra.data.src_line,
3438 );3423 );
3439 mod.declPtr(new_decl_index).owns_tv = true;3424 mod.declPtr(new_decl_index).owns_tv = true;
3440 errdefer mod.abortAnonDecl(new_decl_index);3425 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -3525,7 +3510,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -3525,7 +3510,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
35253510
3526 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;3511 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
3527 const operand = try sema.resolveInst(inst_data.operand);3512 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);
3529}3514}
35303515
3531fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {3516fn 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...@@ -3534,7 +3519,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
35343519
3535 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3520 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3536 const operand = try sema.resolveInst(inst_data.operand);3521 const operand = try sema.resolveInst(inst_data.operand);
3537 const src = inst_data.src();3522 const src = block.nodeOffset(inst_data.src_node);
35383523
3539 return sema.ensureResultUsed(block, sema.typeOf(operand), src);3524 return sema.ensureResultUsed(block, sema.typeOf(operand), src);
3540}3525}
...@@ -3551,19 +3536,19 @@ fn ensureResultUsed(...@@ -3551,19 +3536,19 @@ fn ensureResultUsed(
3551 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),3536 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
3552 .ErrorUnion => {3537 .ErrorUnion => {
3553 const msg = msg: {3538 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", .{});
3555 errdefer msg.destroy(sema.gpa);3540 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'", .{});
3557 break :msg msg;3542 break :msg msg;
3558 };3543 };
3559 return sema.failWithOwnedErrorMsg(block, msg);3544 return sema.failWithOwnedErrorMsg(block, msg);
3560 },3545 },
3561 else => {3546 else => {
3562 const msg = msg: {3547 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)});
3564 errdefer msg.destroy(sema.gpa);3549 errdefer msg.destroy(sema.gpa);
3565 try sema.errNote(block, src, msg, "all non-void values must be used", .{});3550 try sema.errNote(src, msg, "all non-void values must be used", .{});
3566 try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{});3551 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
3567 break :msg msg;3552 break :msg msg;
3568 };3553 };
3569 return sema.failWithOwnedErrorMsg(block, msg);3554 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3578,15 +3563,15 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3578,15 +3563,15 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3578 const mod = sema.mod;3563 const mod = sema.mod;
3579 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3564 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3580 const operand = try sema.resolveInst(inst_data.operand);3565 const operand = try sema.resolveInst(inst_data.operand);
3581 const src = inst_data.src();3566 const src = block.nodeOffset(inst_data.src_node);
3582 const operand_ty = sema.typeOf(operand);3567 const operand_ty = sema.typeOf(operand);
3583 switch (operand_ty.zigTypeTag(mod)) {3568 switch (operand_ty.zigTypeTag(mod)) {
3584 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),3569 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
3585 .ErrorUnion => {3570 .ErrorUnion => {
3586 const msg = msg: {3571 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", .{});
3588 errdefer msg.destroy(sema.gpa);3573 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'", .{});
3590 break :msg msg;3575 break :msg msg;
3591 };3576 };
3592 return sema.failWithOwnedErrorMsg(block, msg);3577 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3601,7 +3586,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index...@@ -3601,7 +3586,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
36013586
3602 const mod = sema.mod;3587 const mod = sema.mod;
3603 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3588 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);
3605 const operand = try sema.resolveInst(inst_data.operand);3590 const operand = try sema.resolveInst(inst_data.operand);
3606 const operand_ty = sema.typeOf(operand);3591 const operand_ty = sema.typeOf(operand);
3607 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)3592 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)
...@@ -3612,9 +3597,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index...@@ -3612,9 +3597,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
3612 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);3597 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);
3613 if (payload_ty != .Void and payload_ty != .NoReturn) {3598 if (payload_ty != .Void and payload_ty != .NoReturn) {
3614 const msg = msg: {3599 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", .{});
3616 errdefer msg.destroy(sema.gpa);3601 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 '|_|'", .{});
3618 break :msg msg;3603 break :msg msg;
3619 };3604 };
3620 return sema.failWithOwnedErrorMsg(block, msg);3605 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3626,7 +3611,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -3626,7 +3611,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
3626 defer tracy.end();3611 defer tracy.end();
36273612
3628 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3613 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);
3630 const object = try sema.resolveInst(inst_data.operand);3615 const object = try sema.resolveInst(inst_data.operand);
36313616
3632 return indexablePtrLen(sema, block, src, object);3617 return indexablePtrLen(sema, block, src, object);
...@@ -3668,8 +3653,8 @@ fn zirAllocExtended(...@@ -3668,8 +3653,8 @@ fn zirAllocExtended(
3668) CompileError!Air.Inst.Ref {3653) CompileError!Air.Inst.Ref {
3669 const gpa = sema.gpa;3654 const gpa = sema.gpa;
3670 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);3655 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3671 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };3656 const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node });
3672 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };3657 const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node });
3673 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);3658 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);
36743659
3675 var extra_index: usize = extra.end;3660 var extra_index: usize = extra.end;
...@@ -3745,7 +3730,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -3745,7 +3730,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
3745 defer tracy.end();3730 defer tracy.end();
37463731
3747 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3732 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 });
3749 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);3734 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
3750 return sema.analyzeComptimeAlloc(block, var_ty, .none);3735 return sema.analyzeComptimeAlloc(block, var_ty, .none);
3751}3736}
...@@ -3811,7 +3796,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3811,7 +3796,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3811 if (try sema.typeRequiresComptime(elem_ty)) {3796 if (try sema.typeRequiresComptime(elem_ty)) {
3812 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.3797 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
3813 // TODO: source location of runtime control flow3798 // 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 });
3815 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});3800 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});
3816 }3801 }
38173802
...@@ -3980,7 +3965,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -3980,7 +3965,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
3980 .ty = opt_ty.toIntern(),3965 .ty = opt_ty.toIntern(),
3981 .val = payload_val.toIntern(),3966 .val = payload_val.toIntern(),
3982 } });3967 } });
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);
3984 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();3969 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();
3985 },3970 },
3986 .eu_payload => ptr: {3971 .eu_payload => ptr: {
...@@ -3993,7 +3978,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -3993,7 +3978,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
3993 .ty = eu_ty.toIntern(),3978 .ty = eu_ty.toIntern(),
3994 .val = .{ .payload = payload_val.toIntern() },3979 .val = .{ .payload = payload_val.toIntern() },
3995 } });3980 } });
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);
3997 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();3982 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();
3998 },3983 },
3999 .field => |idx| ptr: {3984 .field => |idx| ptr: {
...@@ -4006,7 +3991,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4006,7 +3991,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4006 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);3991 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);
4007 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);3992 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);
4008 const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val);3993 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);
4010 }3995 }
4011 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();3996 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();
4012 },3997 },
...@@ -4028,14 +4013,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4028,14 +4013,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4028 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;4013 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
4029 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;4014 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
4030 const new_ptr = ptr_mapping.get(air_ptr_inst).?;4015 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())));
4032 },4017 },
4033 else => unreachable,4018 else => unreachable,
4034 }4019 }
4035 }4020 }
40364021
4037 // The value is finalized - load it!4022 // 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();
4039 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);4024 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);
4040}4025}
40414026
...@@ -4138,7 +4123,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -4138,7 +4123,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
4138 defer tracy.end();4123 defer tracy.end();
41394124
4140 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4125 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 });
4142 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);4127 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
4143 if (block.is_comptime) {4128 if (block.is_comptime) {
4144 return sema.analyzeComptimeAlloc(block, var_ty, .none);4129 return sema.analyzeComptimeAlloc(block, var_ty, .none);
...@@ -4161,7 +4146,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -4161,7 +4146,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
4161 defer tracy.end();4146 defer tracy.end();
41624147
4163 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4148 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 });
4165 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);4150 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
4166 if (block.is_comptime) {4151 if (block.is_comptime) {
4167 return sema.analyzeComptimeAlloc(block, var_ty, .none);4152 return sema.analyzeComptimeAlloc(block, var_ty, .none);
...@@ -4220,8 +4205,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4220,8 +4205,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4220 const mod = sema.mod;4205 const mod = sema.mod;
4221 const gpa = sema.gpa;4206 const gpa = sema.gpa;
4222 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4207 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4223 const src = inst_data.src();4208 const src = block.nodeOffset(inst_data.src_node);
4224 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };4209 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
4225 const ptr = try sema.resolveInst(inst_data.operand);4210 const ptr = try sema.resolveInst(inst_data.operand);
4226 const ptr_inst = ptr.toIndex().?;4211 const ptr_inst = ptr.toIndex().?;
4227 const target = mod.getTarget();4212 const target = mod.getTarget();
...@@ -4361,7 +4346,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4361,7 +4346,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4361 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4346 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4362 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);4347 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
4363 const args = sema.code.refSlice(extra.end, extra.data.operands_len);4348 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
4366 var len: Air.Inst.Ref = .none;4351 var len: Air.Inst.Ref = .none;
4367 var len_val: ?Value = null;4352 var len_val: ?Value = null;
...@@ -4384,20 +4369,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4384,20 +4369,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4384 .Int, .ComptimeInt => true,4369 .Int, .ComptimeInt => true,
4385 else => false,4370 else => false,
4386 };4371 };
4387 const arg_src: LazySrcLoc = .{ .for_input = .{4372 const arg_src = block.src(.{ .for_input = .{
4388 .for_node_offset = inst_data.src_node,4373 .for_node_offset = inst_data.src_node,
4389 .input_index = i,4374 .input_index = i,
4390 } };4375 } });
4391 const arg_len_uncoerced = if (is_int) object else l: {4376 const arg_len_uncoerced = if (is_int) object else l: {
4392 if (!object_ty.isIndexable(mod)) {4377 if (!object_ty.isIndexable(mod)) {
4393 // Instead of using checkIndexable we customize this error.4378 // Instead of using checkIndexable we customize this error.
4394 const msg = msg: {4379 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)});
4396 errdefer msg.destroy(sema.gpa);4381 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
4399 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {4384 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'", .{});
4401 }4386 }
44024387
4403 break :msg msg;4388 break :msg msg;
...@@ -4417,16 +4402,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4417,16 +4402,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4417 if (len_val) |v| {4402 if (len_val) |v| {
4418 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {4403 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {
4419 const msg = msg: {4404 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", .{});
4421 errdefer msg.destroy(gpa);4406 errdefer msg.destroy(gpa);
4422 const a_src: LazySrcLoc = .{ .for_input = .{4407 const a_src = block.src(.{ .for_input = .{
4423 .for_node_offset = inst_data.src_node,4408 .for_node_offset = inst_data.src_node,
4424 .input_index = len_idx,4409 .input_index = len_idx,
4425 } };4410 } });
4426 try sema.errNote(block, a_src, msg, "length {} here", .{4411 try sema.errNote(a_src, msg, "length {} here", .{
4427 v.fmtValue(sema.mod, sema),4412 v.fmtValue(sema.mod, sema),
4428 });4413 });
4429 try sema.errNote(block, arg_src, msg, "length {} here", .{4414 try sema.errNote(arg_src, msg, "length {} here", .{
4430 arg_val.fmtValue(sema.mod, sema),4415 arg_val.fmtValue(sema.mod, sema),
4431 });4416 });
4432 break :msg msg;4417 break :msg msg;
...@@ -4446,7 +4431,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4446,7 +4431,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44464431
4447 if (len == .none) {4432 if (len == .none) {
4448 const msg = msg: {4433 const msg = msg: {
4449 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});4434 const msg = try sema.errMsg(src, "unbounded for loop", .{});
4450 errdefer msg.destroy(gpa);4435 errdefer msg.destroy(gpa);
4451 for (args, 0..) |zir_arg, i_usize| {4436 for (args, 0..) |zir_arg, i_usize| {
4452 const i: u32 = @intCast(i_usize);4437 const i: u32 = @intCast(i_usize);
...@@ -4459,11 +4444,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4459,11 +4444,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4459 .Int, .ComptimeInt => continue,4444 .Int, .ComptimeInt => continue,
4460 else => {},4445 else => {},
4461 }4446 }
4462 const arg_src: LazySrcLoc = .{ .for_input = .{4447 const arg_src = block.src(.{ .for_input = .{
4463 .for_node_offset = inst_data.src_node,4448 .for_node_offset = inst_data.src_node,
4464 .input_index = i,4449 .input_index = i,
4465 } };4450 } });
4466 try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{4451 try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{
4467 object_ty.fmt(sema.mod),4452 object_ty.fmt(sema.mod),
4468 });4453 });
4469 }4454 }
...@@ -4504,16 +4489,16 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL...@@ -4504,16 +4489,16 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL
4504fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4489fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4505 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4490 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4506 const ptr = try sema.resolveInst(un_node.operand);4491 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));
4508}4493}
45094494
4510fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4495fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4511 const mod = sema.mod;4496 const mod = sema.mod;
4512 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4497 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);
4514 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;4499 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
4515 const uncoerced_val = try sema.resolveInst(extra.rhs);4500 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) {
4517 error.GenericPoison => return uncoerced_val,4502 error.GenericPoison => return uncoerced_val,
4518 else => |e| return e,4503 else => |e| return e,
4519 };4504 };
...@@ -4561,7 +4546,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -4561,7 +4546,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
4561fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {4546fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4562 const mod = sema.mod;4547 const mod = sema.mod;
4563 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;4548 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);
4565 // In case of GenericPoison, we don't actually have a type, so this will be4550 // In case of GenericPoison, we don't actually have a type, so this will be
4566 // treated as an untyped address-of operator.4551 // treated as an untyped address-of operator.
4567 const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) {4552 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...@@ -4575,9 +4560,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4575 if (ty_operand.isGenericPoison()) return;4560 if (ty_operand.isGenericPoison()) return;
4576 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {4561 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {
4577 return sema.failWithOwnedErrorMsg(block, msg: {4562 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)});
4579 errdefer msg.destroy(sema.gpa);4564 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", .{});
4581 break :msg msg;4566 break :msg msg;
4582 });4567 });
4583 }4568 }
...@@ -4590,9 +4575,9 @@ fn zirValidateArrayInitRefTy(...@@ -4590,9 +4575,9 @@ fn zirValidateArrayInitRefTy(
4590) CompileError!Air.Inst.Ref {4575) CompileError!Air.Inst.Ref {
4591 const mod = sema.mod;4576 const mod = sema.mod;
4592 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4577 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);
4594 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;4579 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) {
4596 error.GenericPoison => return .generic_poison_type,4581 error.GenericPoison => return .generic_poison_type,
4597 else => |e| return e,4582 else => |e| return e,
4598 };4583 };
...@@ -4632,8 +4617,8 @@ fn zirValidateArrayInitTy(...@@ -4632,8 +4617,8 @@ fn zirValidateArrayInitTy(
4632) CompileError!void {4617) CompileError!void {
4633 const mod = sema.mod;4618 const mod = sema.mod;
4634 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4619 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4635 const src = inst_data.src();4620 const src = block.nodeOffset(inst_data.src_node);
4636 const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = 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 });
4637 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;4622 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
4638 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {4623 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
4639 // It's okay for the type to be unknown: this will result in an anonymous array init.4624 // It's okay for the type to be unknown: this will result in an anonymous array init.
...@@ -4695,7 +4680,7 @@ fn zirValidateStructInitTy(...@@ -4695,7 +4680,7 @@ fn zirValidateStructInitTy(
4695) CompileError!void {4680) CompileError!void {
4696 const mod = sema.mod;4681 const mod = sema.mod;
4697 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4682 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);
4699 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {4684 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
4700 // It's okay for the type to be unknown: this will result in an anonymous struct init.4685 // It's okay for the type to be unknown: this will result in an anonymous struct init.
4701 error.GenericPoison => return,4686 error.GenericPoison => return,
...@@ -4720,7 +4705,7 @@ fn zirValidatePtrStructInit(...@@ -4720,7 +4705,7 @@ fn zirValidatePtrStructInit(
47204705
4721 const mod = sema.mod;4706 const mod = sema.mod;
4722 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4707 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);
4724 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);4709 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
4725 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);4710 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
4726 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;4711 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
...@@ -4759,7 +4744,6 @@ fn validateUnionInit(...@@ -4759,7 +4744,6 @@ fn validateUnionInit(
4759 if (instrs.len != 1) {4744 if (instrs.len != 1) {
4760 const msg = msg: {4745 const msg = msg: {
4761 const msg = try sema.errMsg(4746 const msg = try sema.errMsg(
4762 block,
4763 init_src,4747 init_src,
4764 "cannot initialize multiple union fields at once; unions can only have one active field",4748 "cannot initialize multiple union fields at once; unions can only have one active field",
4765 .{},4749 .{},
...@@ -4768,8 +4752,8 @@ fn validateUnionInit(...@@ -4768,8 +4752,8 @@ fn validateUnionInit(
47684752
4769 for (instrs[1..]) |inst| {4753 for (instrs[1..]) |inst| {
4770 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4754 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4771 const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };4755 const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node });
4772 try sema.errNote(block, inst_src, msg, "additional initializer here", .{});4756 try sema.errNote(inst_src, msg, "additional initializer here", .{});
4773 }4757 }
4774 try sema.addDeclaredHereNote(msg, union_ty);4758 try sema.addDeclaredHereNote(msg, union_ty);
4775 break :msg msg;4759 break :msg msg;
...@@ -4786,7 +4770,7 @@ fn validateUnionInit(...@@ -4786,7 +4770,7 @@ fn validateUnionInit(
47864770
4787 const field_ptr = instrs[0];4771 const field_ptr = instrs[0];
4788 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4772 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 });
4790 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4774 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4791 const field_name = try mod.intern_pool.getOrPutString(4775 const field_name = try mod.intern_pool.getOrPutString(
4792 gpa,4776 gpa,
...@@ -4895,15 +4879,15 @@ fn validateUnionInit(...@@ -4895,15 +4879,15 @@ fn validateUnionInit(
4895 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);4879 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
4896 return;4880 return;
4897 } else if (try sema.typeRequiresComptime(union_ty)) {4881 } 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), .{
4899 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",4883 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
4900 });4884 });
4901 }4885 }
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
4904 const new_tag = Air.internedToRef(tag_val.toIntern());4888 const new_tag = Air.internedToRef(tag_val.toIntern());
4905 const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);4889 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" store4890 try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
4907}4891}
49084892
4909fn validateStructInit(4893fn validateStructInit(
...@@ -4929,7 +4913,7 @@ fn validateStructInit(...@@ -4929,7 +4913,7 @@ fn validateStructInit(
49294913
4930 for (instrs, field_indices) |field_ptr, *field_index| {4914 for (instrs, field_indices) |field_ptr, *field_index| {
4931 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4915 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 });
4933 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4917 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4934 struct_ptr_zir_ref = field_ptr_extra.lhs;4918 struct_ptr_zir_ref = field_ptr_extra.lhs;
4935 const field_name = try ip.getOrPutString(4919 const field_name = try ip.getOrPutString(
...@@ -4966,18 +4950,18 @@ fn validateStructInit(...@@ -4966,18 +4950,18 @@ fn validateStructInit(
4966 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {4950 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
4967 const template = "missing tuple field with index {d}";4951 const template = "missing tuple field with index {d}";
4968 if (root_msg) |msg| {4952 if (root_msg) |msg| {
4969 try sema.errNote(block, init_src, msg, template, .{i});4953 try sema.errNote(init_src, msg, template, .{i});
4970 } else {4954 } else {
4971 root_msg = try sema.errMsg(block, init_src, template, .{i});4955 root_msg = try sema.errMsg(init_src, template, .{i});
4972 }4956 }
4973 continue;4957 continue;
4974 };4958 };
4975 const template = "missing struct field: {}";4959 const template = "missing struct field: {}";
4976 const args = .{field_name.fmt(ip)};4960 const args = .{field_name.fmt(ip)};
4977 if (root_msg) |msg| {4961 if (root_msg) |msg| {
4978 try sema.errNote(block, init_src, msg, template, args);4962 try sema.errNote(init_src, msg, template, args);
4979 } else {4963 } else {
4980 root_msg = try sema.errMsg(block, init_src, template, args);4964 root_msg = try sema.errMsg(init_src, template, args);
4981 }4965 }
4982 continue;4966 continue;
4983 }4967 }
...@@ -4992,16 +4976,7 @@ fn validateStructInit(...@@ -4992,16 +4976,7 @@ fn validateStructInit(
4992 }4976 }
49934977
4994 if (root_msg) |msg| {4978 if (root_msg) |msg| {
4995 if (mod.typeToStruct(struct_ty)) |struct_type| {4979 try sema.addDeclaredHereNote(msg, struct_ty);
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 }
5005 root_msg = null;4980 root_msg = null;
5006 return sema.failWithOwnedErrorMsg(block, msg);4981 return sema.failWithOwnedErrorMsg(block, msg);
5007 }4982 }
...@@ -5086,7 +5061,7 @@ fn validateStructInit(...@@ -5086,7 +5061,7 @@ fn validateStructInit(
5086 field_values[i] = val.toIntern();5061 field_values[i] = val.toIntern();
5087 } else if (require_comptime) {5062 } else if (require_comptime) {
5088 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;5063 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), .{
5090 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",5065 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
5091 });5066 });
5092 } else {5067 } else {
...@@ -5103,18 +5078,18 @@ fn validateStructInit(...@@ -5103,18 +5078,18 @@ fn validateStructInit(
5103 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {5078 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
5104 const template = "missing tuple field with index {d}";5079 const template = "missing tuple field with index {d}";
5105 if (root_msg) |msg| {5080 if (root_msg) |msg| {
5106 try sema.errNote(block, init_src, msg, template, .{i});5081 try sema.errNote(init_src, msg, template, .{i});
5107 } else {5082 } else {
5108 root_msg = try sema.errMsg(block, init_src, template, .{i});5083 root_msg = try sema.errMsg(init_src, template, .{i});
5109 }5084 }
5110 continue;5085 continue;
5111 };5086 };
5112 const template = "missing struct field: {}";5087 const template = "missing struct field: {}";
5113 const args = .{field_name.fmt(ip)};5088 const args = .{field_name.fmt(ip)};
5114 if (root_msg) |msg| {5089 if (root_msg) |msg| {
5115 try sema.errNote(block, init_src, msg, template, args);5090 try sema.errNote(init_src, msg, template, args);
5116 } else {5091 } else {
5117 root_msg = try sema.errMsg(block, init_src, template, args);5092 root_msg = try sema.errMsg(init_src, template, args);
5118 }5093 }
5119 continue;5094 continue;
5120 }5095 }
...@@ -5122,21 +5097,12 @@ fn validateStructInit(...@@ -5122,21 +5097,12 @@ fn validateStructInit(
5122 }5097 }
51235098
5124 if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) {5099 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", .{});5100 root_msg = try sema.errMsg(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", .{});5101 try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
5127 }5102 }
51285103
5129 if (root_msg) |msg| {5104 if (root_msg) |msg| {
5130 if (mod.typeToStruct(struct_ty)) |struct_type| {5105 try sema.addDeclaredHereNote(msg, struct_ty);
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 }
5140 root_msg = null;5106 root_msg = null;
5141 return sema.failWithOwnedErrorMsg(block, msg);5107 return sema.failWithOwnedErrorMsg(block, msg);
5142 }5108 }
...@@ -5210,7 +5176,7 @@ fn zirValidatePtrArrayInit(...@@ -5210,7 +5176,7 @@ fn zirValidatePtrArrayInit(
5210) CompileError!void {5176) CompileError!void {
5211 const mod = sema.mod;5177 const mod = sema.mod;
5212 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5178 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);
5214 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);5180 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
5215 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);5181 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
5216 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;5182 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
...@@ -5238,9 +5204,9 @@ fn zirValidatePtrArrayInit(...@@ -5238,9 +5204,9 @@ fn zirValidatePtrArrayInit(
5238 if (default_val == .unreachable_value) {5204 if (default_val == .unreachable_value) {
5239 const template = "missing tuple field with index {d}";5205 const template = "missing tuple field with index {d}";
5240 if (root_msg) |msg| {5206 if (root_msg) |msg| {
5241 try sema.errNote(block, init_src, msg, template, .{i});5207 try sema.errNote(init_src, msg, template, .{i});
5242 } else {5208 } else {
5243 root_msg = try sema.errMsg(block, init_src, template, .{i});5209 root_msg = try sema.errMsg(init_src, template, .{i});
5244 }5210 }
5245 continue;5211 continue;
5246 }5212 }
...@@ -5415,7 +5381,7 @@ fn zirValidatePtrArrayInit(...@@ -5415,7 +5381,7 @@ fn zirValidatePtrArrayInit(
5415fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5381fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5416 const mod = sema.mod;5382 const mod = sema.mod;
5417 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5383 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);
5419 const operand = try sema.resolveInst(inst_data.operand);5385 const operand = try sema.resolveInst(inst_data.operand);
5420 const operand_ty = sema.typeOf(operand);5386 const operand_ty = sema.typeOf(operand);
54215387
...@@ -5440,15 +5406,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -5440,15 +5406,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
5440 } else if (try sema.typeRequiresComptime(elem_ty)) {5406 } else if (try sema.typeRequiresComptime(elem_ty)) {
5441 const msg = msg: {5407 const msg = msg: {
5442 const msg = try sema.errMsg(5408 const msg = try sema.errMsg(
5443 block,
5444 src,5409 src,
5445 "values of type '{}' must be comptime-known, but operand value is runtime-known",5410 "values of type '{}' must be comptime-known, but operand value is runtime-known",
5446 .{elem_ty.fmt(mod)},5411 .{elem_ty.fmt(mod)},
5447 );5412 );
5448 errdefer msg.destroy(sema.gpa);5413 errdefer msg.destroy(sema.gpa);
54495414
5450 const src_decl = mod.declPtr(block.src_decl);5415 try sema.explainWhyTypeIsComptime(msg, src, elem_ty);
5451 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty);
5452 break :msg msg;5416 break :msg msg;
5453 };5417 };
5454 return sema.failWithOwnedErrorMsg(block, msg);5418 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5459,8 +5423,8 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5459,8 +5423,8 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
5459 const mod = sema.mod;5423 const mod = sema.mod;
5460 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5424 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5461 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;5425 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
5462 const src = inst_data.src();5426 const src = block.nodeOffset(inst_data.src_node);
5463 const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node);5427 const destructure_src = block.nodeOffset(extra.destructure_node);
5464 const operand = try sema.resolveInst(extra.operand);5428 const operand = try sema.resolveInst(extra.operand);
5465 const operand_ty = sema.typeOf(operand);5429 const operand_ty = sema.typeOf(operand);
54665430
...@@ -5472,21 +5436,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5472,21 +5436,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54725436
5473 if (!can_destructure) {5437 if (!can_destructure) {
5474 return sema.failWithOwnedErrorMsg(block, msg: {5438 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)});
5476 errdefer msg.destroy(sema.gpa);5440 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", .{});
5478 break :msg msg;5442 break :msg msg;
5479 });5443 });
5480 }5444 }
54815445
5482 if (operand_ty.arrayLen(mod) != extra.expect_len) {5446 if (operand_ty.arrayLen(mod) != extra.expect_len) {
5483 return sema.failWithOwnedErrorMsg(block, msg: {5447 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 {}", .{
5485 extra.expect_len,5449 extra.expect_len,
5486 operand_ty.arrayLen(mod),5450 operand_ty.arrayLen(mod),
5487 });5451 });
5488 errdefer msg.destroy(sema.gpa);5452 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", .{});
5490 break :msg msg;5454 break :msg msg;
5491 });5455 });
5492 }5456 }
...@@ -5521,24 +5485,24 @@ fn failWithBadMemberAccess(...@@ -5521,24 +5485,24 @@ fn failWithBadMemberAccess(
5521fn failWithBadStructFieldAccess(5485fn failWithBadStructFieldAccess(
5522 sema: *Sema,5486 sema: *Sema,
5523 block: *Block,5487 block: *Block,
5488 struct_ty: Type,
5524 struct_type: InternPool.LoadedStructType,5489 struct_type: InternPool.LoadedStructType,
5525 field_src: LazySrcLoc,5490 field_src: LazySrcLoc,
5526 field_name: InternPool.NullTerminatedString,5491 field_name: InternPool.NullTerminatedString,
5527) CompileError {5492) CompileError {
5528 const mod = sema.mod;5493 const zcu = sema.mod;
5529 const gpa = sema.gpa;5494 const gpa = sema.gpa;
5530 const decl = mod.declPtr(struct_type.decl.unwrap().?);5495 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5531 const fqn = try decl.fullyQualifiedName(mod);5496 const fqn = try decl.fullyQualifiedName(zcu);
55325497
5533 const msg = msg: {5498 const msg = msg: {
5534 const msg = try sema.errMsg(5499 const msg = try sema.errMsg(
5535 block,
5536 field_src,5500 field_src,
5537 "no field named '{}' in struct '{}'",5501 "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) },
5539 );5503 );
5540 errdefer msg.destroy(gpa);5504 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", .{});
5542 break :msg msg;5506 break :msg msg;
5543 };5507 };
5544 return sema.failWithOwnedErrorMsg(block, msg);5508 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5547,25 +5511,25 @@ fn failWithBadStructFieldAccess(...@@ -5547,25 +5511,25 @@ fn failWithBadStructFieldAccess(
5547fn failWithBadUnionFieldAccess(5511fn failWithBadUnionFieldAccess(
5548 sema: *Sema,5512 sema: *Sema,
5549 block: *Block,5513 block: *Block,
5514 union_ty: Type,
5550 union_obj: InternPool.LoadedUnionType,5515 union_obj: InternPool.LoadedUnionType,
5551 field_src: LazySrcLoc,5516 field_src: LazySrcLoc,
5552 field_name: InternPool.NullTerminatedString,5517 field_name: InternPool.NullTerminatedString,
5553) CompileError {5518) CompileError {
5554 const mod = sema.mod;5519 const zcu = sema.mod;
5555 const gpa = sema.gpa;5520 const gpa = sema.gpa;
55565521
5557 const decl = mod.declPtr(union_obj.decl);5522 const decl = zcu.declPtr(union_obj.decl);
5558 const fqn = try decl.fullyQualifiedName(mod);5523 const fqn = try decl.fullyQualifiedName(zcu);
55595524
5560 const msg = msg: {5525 const msg = msg: {
5561 const msg = try sema.errMsg(5526 const msg = try sema.errMsg(
5562 block,
5563 field_src,5527 field_src,
5564 "no field named '{}' in union '{}'",5528 "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) },
5566 );5530 );
5567 errdefer msg.destroy(gpa);5531 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", .{});
5569 break :msg msg;5533 break :msg msg;
5570 };5534 };
5571 return sema.failWithOwnedErrorMsg(block, msg);5535 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5573,16 +5537,15 @@ fn failWithBadUnionFieldAccess(...@@ -5573,16 +5537,15 @@ fn failWithBadUnionFieldAccess(
55735537
5574fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {5538fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
5575 const mod = sema.mod;5539 const mod = sema.mod;
5576 const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return;5540 const src_loc = decl_ty.srcLocOrNull(mod) orelse return;
5577 const category = switch (decl_ty.zigTypeTag(mod)) {5541 const category = switch (decl_ty.zigTypeTag(mod)) {
5578 .Union => "union",5542 .Union => "union",
5579 .Struct => "struct",5543 .Struct => "struct",
5580 .Enum => "enum",5544 .Enum => "enum",
5581 .Opaque => "opaque",5545 .Opaque => "opaque",
5582 .ErrorSet => "error set",
5583 else => unreachable,5546 else => unreachable,
5584 };5547 };
5585 try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category});5548 try sema.errNote(src_loc, parent, "{s} declared here", .{category});
5586}5549}
55875550
5588fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5551fn 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...@@ -5590,7 +5553,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
5590 defer tracy.end();5553 defer tracy.end();
55915554
5592 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5555 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);
5594 const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;5557 const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
5595 const ptr = try sema.resolveInst(bin.lhs);5558 const ptr = try sema.resolveInst(bin.lhs);
5596 const operand = try sema.resolveInst(bin.rhs);5559 const operand = try sema.resolveInst(bin.rhs);
...@@ -5672,7 +5635,7 @@ fn storeToInferredAllocComptime(...@@ -5672,7 +5635,7 @@ fn storeToInferredAllocComptime(
56725635
5673fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5636fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5674 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5637 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);
5676 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{5639 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{
5677 .needed_comptime_reason = "eval branch quota must be comptime-known",5640 .needed_comptime_reason = "eval branch quota must be comptime-known",
5678 }));5641 }));
...@@ -5687,7 +5650,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -5687,7 +5650,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
5687 const zir_tags = sema.code.instructions.items(.tag);5650 const zir_tags = sema.code.instructions.items(.tag);
5688 const zir_datas = sema.code.instructions.items(.data);5651 const zir_datas = sema.code.instructions.items(.data);
5689 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;5652 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
5690 const src = inst_data.src();5653 const src = block.nodeOffset(inst_data.src_node);
5691 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;5654 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
5692 const ptr = try sema.resolveInst(extra.lhs);5655 const ptr = try sema.resolveInst(extra.lhs);
5693 const operand = try sema.resolveInst(extra.rhs);5656 const operand = try sema.resolveInst(extra.rhs);
...@@ -5707,8 +5670,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -5707,8 +5670,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
5707 else => {},5670 else => {},
5708 };5671 };
57095672
5710 const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node };5673 const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
5711 const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };5674 const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node });
5712 const air_tag: Air.Inst.Tag = if (is_ret)5675 const air_tag: Air.Inst.Tag = if (is_ret)
5713 .ret_ptr5676 .ret_ptr
5714 else if (block.wantSafety())5677 else if (block.wantSafety())
...@@ -5821,8 +5784,8 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -5821,8 +5784,8 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
5821 defer tracy.end();5784 defer tracy.end();
58225785
5823 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5786 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5824 const src = inst_data.src();5787 const src = block.nodeOffset(inst_data.src_node);
5825 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5788 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
5826 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{5789 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
5827 .needed_comptime_reason = "compile error string must be comptime-known",5790 .needed_comptime_reason = "compile error string must be comptime-known",
5828 });5791 });
...@@ -5831,6 +5794,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -5831,6 +5794,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58315794
5832fn zirCompileLog(5795fn zirCompileLog(
5833 sema: *Sema,5796 sema: *Sema,
5797 block: *Block,
5834 extended: Zir.Inst.Extended.InstData,5798 extended: Zir.Inst.Extended.InstData,
5835) CompileError!Air.Inst.Ref {5799) CompileError!Air.Inst.Ref {
5836 const mod = sema.mod;5800 const mod = sema.mod;
...@@ -5863,20 +5827,21 @@ fn zirCompileLog(...@@ -5863,20 +5827,21 @@ fn zirCompileLog(
5863 else5827 else
5864 sema.owner_decl_index;5828 sema.owner_decl_index;
5865 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);5829 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5866 if (!gop.found_existing) {5830 if (!gop.found_existing) gop.value_ptr.* = .{
5867 gop.value_ptr.* = src_node;5831 .base_node_inst = block.src_base_inst,
5868 }5832 .node_offset = src_node,
5833 };
5869 return .void_value;5834 return .void_value;
5870}5835}
58715836
5872fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5837fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5838 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);
5875 const msg_inst = try sema.resolveInst(inst_data.operand);5840 const msg_inst = try sema.resolveInst(inst_data.operand);
58765841
5877 // `panicWithMsg` would perform this coercion for us, but we can get a better5842 // `panicWithMsg` would perform this coercion for us, but we can get a better
5878 // source location if we do it here.5843 // 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
5881 if (block.is_comptime) {5846 if (block.is_comptime) {
5882 return sema.fail(block, src, "encountered @panic at comptime", .{});5847 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...@@ -5886,7 +5851,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
58865851
5887fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5852fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5888 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;5853 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);
5890 if (block.is_comptime)5855 if (block.is_comptime)
5891 return sema.fail(block, src, "encountered @trap at comptime", .{});5856 return sema.fail(block, src, "encountered @trap at comptime", .{});
5892 _ = try block.addNoOp(.trap);5857 _ = try block.addNoOp(.trap);
...@@ -5898,7 +5863,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5898,7 +5863,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
58985863
5899 const mod = sema.mod;5864 const mod = sema.mod;
5900 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5865 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);
5902 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);5867 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
5903 const body = sema.code.bodySlice(extra.end, extra.data.body_len);5868 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
5904 const gpa = sema.gpa;5869 const gpa = sema.gpa;
...@@ -5933,7 +5898,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5933,7 +5898,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5933 var child_block = parent_block.makeSubBlock();5898 var child_block = parent_block.makeSubBlock();
5934 child_block.label = &label;5899 child_block.label = &label;
5935 child_block.runtime_cond = null;5900 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;
5937 child_block.runtime_index.increment();5902 child_block.runtime_index.increment();
5938 const merges = &child_block.label.?.merges;5903 const merges = &child_block.label.?.merges;
59395904
...@@ -5971,7 +5936,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5971,7 +5936,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5971 const comp = mod.comp;5936 const comp = mod.comp;
5972 const gpa = sema.gpa;5937 const gpa = sema.gpa;
5973 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5938 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);
5975 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);5940 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
5976 const body = sema.code.bodySlice(extra.end, extra.data.body_len);5941 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...@@ -5982,14 +5947,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5982 var c_import_buf = std.ArrayList(u8).init(gpa);5947 var c_import_buf = std.ArrayList(u8).init(gpa);
5983 defer c_import_buf.deinit();5948 defer c_import_buf.deinit();
59845949
5985 var comptime_reason: Block.ComptimeReason = .{ .c_import = .{5950 const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } };
5986 .block = parent_block,
5987 .src = src,
5988 } };
5989 var child_block: Block = .{5951 var child_block: Block = .{
5990 .parent = parent_block,5952 .parent = parent_block,
5991 .sema = sema,5953 .sema = sema,
5992 .src_decl = parent_block.src_decl,
5993 .namespace = parent_block.namespace,5954 .namespace = parent_block.namespace,
5994 .instructions = .{},5955 .instructions = .{},
5995 .inlining = parent_block.inlining,5956 .inlining = parent_block.inlining,
...@@ -5999,6 +5960,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5999,6 +5960,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5999 .runtime_cond = parent_block.runtime_cond,5960 .runtime_cond = parent_block.runtime_cond,
6000 .runtime_loop = parent_block.runtime_loop,5961 .runtime_loop = parent_block.runtime_loop,
6001 .runtime_index = parent_block.runtime_index,5962 .runtime_index = parent_block.runtime_index,
5963 .src_base_inst = parent_block.src_base_inst,
5964 .type_name_ctx = parent_block.type_name_ctx,
6002 };5965 };
6003 defer child_block.instructions.deinit(gpa);5966 defer child_block.instructions.deinit(gpa);
60045967
...@@ -6010,11 +5973,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -6010,11 +5973,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60105973
6011 if (c_import_res.errors.errorMessageCount() != 0) {5974 if (c_import_res.errors.errorMessageCount() != 0) {
6012 const msg = msg: {5975 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", .{});
6014 errdefer msg.destroy(gpa);5977 errdefer msg.destroy(gpa);
60155978
6016 if (!comp.config.link_libc)5979 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
6019 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);5982 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
6020 if (!gop.found_existing) {5983 if (!gop.found_existing) {
...@@ -6073,7 +6036,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -6073,7 +6036,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60736036
6074fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6037fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6075 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6038 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);
6077 return sema.failWithUseOfAsync(parent_block, src);6040 return sema.failWithUseOfAsync(parent_block, src);
6078}6041}
60796042
...@@ -6082,7 +6045,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6082,7 +6045,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6082 defer tracy.end();6045 defer tracy.end();
60836046
6084 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6047 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);
6086 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);6049 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
6087 const body = sema.code.bodySlice(extra.end, extra.data.body_len);6050 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
6088 const gpa = sema.gpa;6051 const gpa = sema.gpa;
...@@ -6109,7 +6072,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6109,7 +6072,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6109 var child_block: Block = .{6072 var child_block: Block = .{
6110 .parent = parent_block,6073 .parent = parent_block,
6111 .sema = sema,6074 .sema = sema,
6112 .src_decl = parent_block.src_decl,
6113 .namespace = parent_block.namespace,6075 .namespace = parent_block.namespace,
6114 .instructions = .{},6076 .instructions = .{},
6115 .label = &label,6077 .label = &label,
...@@ -6124,6 +6086,8 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6124,6 +6086,8 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6124 .runtime_loop = parent_block.runtime_loop,6086 .runtime_loop = parent_block.runtime_loop,
6125 .runtime_index = parent_block.runtime_index,6087 .runtime_index = parent_block.runtime_index,
6126 .error_return_trace_index = parent_block.error_return_trace_index,6088 .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,
6127 };6091 };
61286092
6129 defer child_block.instructions.deinit(gpa);6093 defer child_block.instructions.deinit(gpa);
...@@ -6318,14 +6282,13 @@ fn resolveAnalyzedBlock(...@@ -6318,14 +6282,13 @@ fn resolveAnalyzedBlock(
6318 const type_src = src; // TODO: better source location6282 const type_src = src; // TODO: better source location
6319 if (try sema.typeRequiresComptime(resolved_ty)) {6283 if (try sema.typeRequiresComptime(resolved_ty)) {
6320 const msg = msg: {6284 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)});
6322 errdefer msg.destroy(sema.gpa);6286 errdefer msg.destroy(sema.gpa);
63236287
6324 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;6288 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);6291 try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty);
6328 try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty);
63296292
6330 break :msg msg;6293 break :msg msg;
6331 };6294 };
...@@ -6417,9 +6380,9 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -6417,9 +6380,9 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
6417 const mod = sema.mod;6380 const mod = sema.mod;
6418 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6381 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6419 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;6382 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
6420 const src = inst_data.src();6383 const src = block.nodeOffset(inst_data.src_node);
6421 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6384 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6422 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6385 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
6423 const decl_name = try mod.intern_pool.getOrPutString(6386 const decl_name = try mod.intern_pool.getOrPutString(
6424 mod.gpa,6387 mod.gpa,
6425 sema.code.nullTerminatedString(extra.decl_name),6388 sema.code.nullTerminatedString(extra.decl_name),
...@@ -6433,13 +6396,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -6433,13 +6396,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
6433 break :index_blk maybe_index orelse6396 break :index_blk maybe_index orelse
6434 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);6397 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
6435 } else try sema.lookupIdentifier(block, operand_src, decl_name);6398 } else try sema.lookupIdentifier(block, operand_src, decl_name);
6436 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {6399 const options = try sema.resolveExportOptions(block, options_src, extra.options);
6437 error.NeededSourceLocation => {
6438 _ = try sema.resolveExportOptions(block, options_src, extra.options);
6439 unreachable;
6440 },
6441 else => |e| return e,
6442 };
6443 {6400 {
6444 try sema.ensureDeclAnalyzed(decl_index);6401 try sema.ensureDeclAnalyzed(decl_index);
6445 const exported_decl = mod.declPtr(decl_index);6402 const exported_decl = mod.declPtr(decl_index);
...@@ -6457,9 +6414,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6457,9 +6414,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6457 const mod = sema.mod;6414 const mod = sema.mod;
6458 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6415 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6459 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;6416 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
6460 const src = inst_data.src();6417 const src = block.nodeOffset(inst_data.src_node);
6461 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6418 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6462 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6419 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
6463 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{6420 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
6464 .needed_comptime_reason = "export target must be comptime-known",6421 .needed_comptime_reason = "export target must be comptime-known",
6465 });6422 });
...@@ -6475,7 +6432,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6475,7 +6432,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6475 .opts = options,6432 .opts = options,
6476 .src = src,6433 .src = src,
6477 .owner_decl = sema.owner_decl_index,6434 .owner_decl = sema.owner_decl_index,
6478 .src_decl = block.src_decl,
6479 .exported = .{ .value = operand.toIntern() },6435 .exported = .{ .value = operand.toIntern() },
6480 .status = .in_progress,6436 .status = .in_progress,
6481 });6437 });
...@@ -6500,11 +6456,10 @@ pub fn analyzeExport(...@@ -6500,11 +6456,10 @@ pub fn analyzeExport(
65006456
6501 if (!try sema.validateExternType(export_ty, .other)) {6457 if (!try sema.validateExternType(export_ty, .other)) {
6502 const msg = msg: {6458 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)});
6504 errdefer msg.destroy(gpa);6460 errdefer msg.destroy(gpa);
65056461
6506 const src_decl = mod.declPtr(block.src_decl);6462 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
6507 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
65086463
6509 try sema.addDeclaredHereNote(msg, export_ty);6464 try sema.addDeclaredHereNote(msg, export_ty);
6510 break :msg msg;6465 break :msg msg;
...@@ -6523,7 +6478,6 @@ pub fn analyzeExport(...@@ -6523,7 +6478,6 @@ pub fn analyzeExport(
6523 .opts = options,6478 .opts = options,
6524 .src = src,6479 .src = src,
6525 .owner_decl = sema.owner_decl_index,6480 .owner_decl = sema.owner_decl_index,
6526 .src_decl = block.src_decl,
6527 .exported = .{ .decl_index = exported_decl_index },6481 .exported = .{ .decl_index = exported_decl_index },
6528 .status = .in_progress,6482 .status = .in_progress,
6529 });6483 });
...@@ -6563,8 +6517,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {...@@ -6563,8 +6517,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {
6563fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6517fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
6564 const mod = sema.mod;6518 const mod = sema.mod;
6565 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6519 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6566 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };6520 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6567 const src = LazySrcLoc.nodeOffset(extra.node);6521 const src = block.nodeOffset(extra.node);
6568 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);6522 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
6569 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {6523 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {
6570 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{6524 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...@@ -6583,9 +6537,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65836537
6584 if (sema.prev_stack_alignment_src) |prev_src| {6538 if (sema.prev_stack_alignment_src) |prev_src| {
6585 const msg = msg: {6539 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", .{});
6587 errdefer msg.destroy(sema.gpa);6541 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", .{});
6589 break :msg msg;6543 break :msg msg;
6590 };6544 };
6591 return sema.failWithOwnedErrorMsg(block, msg);6545 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -6606,7 +6560,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -6606,7 +6560,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
6606 const mod = sema.mod;6560 const mod = sema.mod;
6607 const ip = &mod.intern_pool;6561 const ip = &mod.intern_pool;
6608 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6562 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);
6610 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{6564 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
6611 .needed_comptime_reason = "operand to @setCold must be comptime-known",6565 .needed_comptime_reason = "operand to @setCold must be comptime-known",
6612 });6566 });
...@@ -6616,7 +6570,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -6616,7 +6570,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66166570
6617fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6571fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
6618 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6572 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);
6620 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{6574 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
6621 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",6575 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
6622 });6576 });
...@@ -6624,7 +6578,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -6624,7 +6578,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
66246578
6625fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {6579fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
6626 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;6580 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);
6628 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{6582 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
6629 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",6583 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
6630 });6584 });
...@@ -6634,7 +6588,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co...@@ -6634,7 +6588,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
6634 if (block.is_comptime) return;6588 if (block.is_comptime) return;
66356589
6636 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6590 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);
6638 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{6592 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
6639 .needed_comptime_reason = "atomic order of @fence must be comptime-known",6593 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
6640 });6594 });
...@@ -6664,7 +6618,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6664,7 +6618,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
6664 if (label.zir_block == zir_block) {6618 if (label.zir_block == zir_block) {
6665 const br_ref = try start_block.addBr(label.merges.block_inst, operand);6619 const br_ref = try start_block.addBr(label.merges.block_inst, operand);
6666 const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node)6620 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)
6668 else6622 else
6669 null;6623 null;
6670 try label.merges.src_locs.append(sema.gpa, src_loc);6624 try label.merges.src_locs.append(sema.gpa, src_loc);
...@@ -6774,21 +6728,21 @@ fn addDbgVar(...@@ -6774,21 +6728,21 @@ fn addDbgVar(
6774fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6728fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6775 const mod = sema.mod;6729 const mod = sema.mod;
6776 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6730 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);
6778 const decl_name = try mod.intern_pool.getOrPutString(6732 const decl_name = try mod.intern_pool.getOrPutString(
6779 sema.gpa,6733 sema.gpa,
6780 inst_data.get(sema.code),6734 inst_data.get(sema.code),
6781 .no_embedded_nulls,6735 .no_embedded_nulls,
6782 );6736 );
6783 const decl_index = try sema.lookupIdentifier(block, src, decl_name);6737 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);
6785 return sema.analyzeDeclRef(decl_index);6739 return sema.analyzeDeclRef(decl_index);
6786}6740}
67876741
6788fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6742fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6789 const mod = sema.mod;6743 const mod = sema.mod;
6790 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6744 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);
6792 const decl_name = try mod.intern_pool.getOrPutString(6746 const decl_name = try mod.intern_pool.getOrPutString(
6793 sema.gpa,6747 sema.gpa,
6794 inst_data.get(sema.code),6748 inst_data.get(sema.code),
...@@ -6891,12 +6845,14 @@ fn lookupInNamespace(...@@ -6891,12 +6845,14 @@ fn lookupInNamespace(
6891 },6845 },
6892 else => {6846 else => {
6893 const msg = msg: {6847 const msg = msg: {
6894 const msg = try sema.errMsg(block, src, "ambiguous reference", .{});6848 const msg = try sema.errMsg(src, "ambiguous reference", .{});
6895 errdefer msg.destroy(gpa);6849 errdefer msg.destroy(gpa);
6896 for (candidates.items) |candidate_index| {6850 for (candidates.items) |candidate_index| {
6897 const candidate = mod.declPtr(candidate_index);6851 const candidate = mod.declPtr(candidate_index);
6898 const src_loc = candidate.srcLoc(mod);6852 try sema.errNote(.{
6899 try mod.errNoteNonLazy(src_loc, msg, "declared here", .{});6853 .base_node_inst = candidate.zir_decl_index.unwrap().?,
6854 .offset = LazySrcLoc.Offset.nodeOffset(0),
6855 }, msg, "declared here", .{});
6900 }6856 }
6901 break :msg msg;6857 break :msg msg;
6902 };6858 };
...@@ -6938,16 +6894,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6938,16 +6894,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6938 if (!block.ownerModule().error_tracing) return .none;6894 if (!block.ownerModule().error_tracing) return .none;
69396895
6940 const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {6896 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,
6942 else => |e| return e,6898 else => |e| return e,
6943 };6899 };
6944 sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) {6900 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,
6946 else => |e| return e,6902 else => |e| return e,
6947 };6903 };
6948 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);6904 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) {6905 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6950 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),6906 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
6951 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6907 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6952 error.OutOfMemory => |e| return e,6908 error.OutOfMemory => |e| return e,
6953 };6909 };
...@@ -7055,8 +7011,8 @@ fn zirCall(...@@ -7055,8 +7011,8 @@ fn zirCall(
70557011
7056 const mod = sema.mod;7012 const mod = sema.mod;
7057 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;7013 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 };7014 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
7059 const call_src = inst_data.src();7015 const call_src = block.nodeOffset(inst_data.src_node);
7060 const ExtraType = switch (kind) {7016 const ExtraType = switch (kind) {
7061 .direct => Zir.Inst.Call,7017 .direct => Zir.Inst.Call,
7062 .field => Zir.Inst.FieldCall,7018 .field => Zir.Inst.FieldCall,
...@@ -7077,7 +7033,7 @@ fn zirCall(...@@ -7077,7 +7033,7 @@ fn zirCall(
7077 sema.code.nullTerminatedString(extra.data.field_name_start),7033 sema.code.nullTerminatedString(extra.data.field_name_start),
7078 .no_embedded_nulls,7034 .no_embedded_nulls,
7079 );7035 );
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 });
7081 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);7037 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
7082 },7038 },
7083 };7039 };
...@@ -7187,11 +7143,11 @@ fn checkCallArgumentCount(...@@ -7187,11 +7143,11 @@ fn checkCallArgumentCount(
7187 opt_child.childType(mod).zigTypeTag(mod) == .Fn))7143 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
7188 {7144 {
7189 const msg = msg: {7145 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 '{}'", .{
7191 callee_ty.fmt(mod),7147 callee_ty.fmt(mod),
7192 });7148 });
7193 errdefer msg.destroy(sema.gpa);7149 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'", .{});
7195 break :msg msg;7151 break :msg msg;
7196 };7152 };
7197 return sema.failWithOwnedErrorMsg(block, msg);7153 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7217,7 +7173,6 @@ fn checkCallArgumentCount(...@@ -7217,7 +7173,6 @@ fn checkCallArgumentCount(
7217 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";7173 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
7218 const msg = msg: {7174 const msg = msg: {
7219 const msg = try sema.errMsg(7175 const msg = try sema.errMsg(
7220 block,
7221 func_src,7176 func_src,
7222 "{s}expected {s}{d} argument(s), found {d}",7177 "{s}expected {s}{d} argument(s), found {d}",
7223 .{7178 .{
...@@ -7229,7 +7184,12 @@ fn checkCallArgumentCount(...@@ -7229,7 +7184,12 @@ fn checkCallArgumentCount(
7229 );7184 );
7230 errdefer msg.destroy(sema.gpa);7185 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 }
7233 break :msg msg;7193 break :msg msg;
7234 };7194 };
7235 return sema.failWithOwnedErrorMsg(block, msg);7195 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7337,18 +7297,16 @@ const CallArgsInfo = union(enum) {...@@ -7337,18 +7297,16 @@ const CallArgsInfo = union(enum) {
7337 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {7297 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {
7338 return switch (cai) {7298 return switch (cai) {
7339 .resolved => |resolved| resolved.src,7299 .resolved => |resolved| resolved.src,
7340 .call_builtin => |call_builtin| .{ .call_arg = .{7300 .call_builtin => |call_builtin| block.src(.{ .call_arg = .{
7341 .decl = block.src_decl,
7342 .call_node_offset = call_builtin.call_node_offset,7301 .call_node_offset = call_builtin.call_node_offset,
7343 .arg_index = @intCast(arg_index),7302 .arg_index = @intCast(arg_index),
7344 } },7303 } }),
7345 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {7304 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {
7346 return zir_call.bound_arg_src;7305 return zir_call.bound_arg_src;
7347 } else .{ .call_arg = .{7306 } else block.src(.{ .call_arg = .{
7348 .decl = block.src_decl,
7349 .call_node_offset = zir_call.call_node_offset,7307 .call_node_offset = zir_call.call_node_offset,
7350 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),7308 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),
7351 } },7309 } }),
7352 };7310 };
7353 }7311 }
73547312
...@@ -7460,7 +7418,6 @@ const InlineCallSema = struct {...@@ -7460,7 +7418,6 @@ const InlineCallSema = struct {
7460 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,7418 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
7461 other_generic_owner: InternPool.Index,7419 other_generic_owner: InternPool.Index,
7462 other_generic_call_src: LazySrcLoc,7420 other_generic_call_src: LazySrcLoc,
7463 other_generic_call_decl: InternPool.OptionalDeclIndex,
74647421
7465 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not7422 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
7466 /// change that. The other parameters contain data for the callee Sema. The other modified7423 /// change that. The other parameters contain data for the callee Sema. The other modified
...@@ -7482,8 +7439,7 @@ const InlineCallSema = struct {...@@ -7482,8 +7439,7 @@ const InlineCallSema = struct {
7482 .other_inst_map = .{},7439 .other_inst_map = .{},
7483 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,7440 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,
7484 .other_generic_owner = .none,7441 .other_generic_owner = .none,
7485 .other_generic_call_src = .unneeded,7442 .other_generic_call_src = LazySrcLoc.unneeded,
7486 .other_generic_call_decl = .none,
7487 };7443 };
7488 }7444 }
74897445
...@@ -7530,7 +7486,6 @@ const InlineCallSema = struct {...@@ -7530,7 +7486,6 @@ const InlineCallSema = struct {
7530 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);7486 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);
7531 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);7487 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);
7532 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);7488 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);
7534 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);7489 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
7535 // zig fmt: on7490 // zig fmt: on
7536 }7491 }
...@@ -7562,14 +7517,16 @@ fn analyzeCall(...@@ -7562,14 +7517,16 @@ fn analyzeCall(
7562 const maybe_decl = try sema.funcDeclSrc(func);7517 const maybe_decl = try sema.funcDeclSrc(func);
7563 const msg = msg: {7518 const msg = msg: {
7564 const msg = try sema.errMsg(7519 const msg = try sema.errMsg(
7565 block,
7566 func_src,7520 func_src,
7567 "unable to call function with naked calling convention",7521 "unable to call function with naked calling convention",
7568 .{},7522 .{},
7569 );7523 );
7570 errdefer msg.destroy(sema.gpa);7524 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", .{});
7573 break :msg msg;7530 break :msg msg;
7574 };7531 };
7575 return sema.failWithOwnedErrorMsg(block, msg);7532 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7608,7 +7565,6 @@ fn analyzeCall(...@@ -7608,7 +7565,6 @@ fn analyzeCall(
7608 is_inline_call = ct;7565 is_inline_call = ct;
7609 if (ct) {7566 if (ct) {
7610 comptime_reason = &.{ .comptime_ret_ty = .{7567 comptime_reason = &.{ .comptime_ret_ty = .{
7611 .block = block,
7612 .func = func,7568 .func = func,
7613 .func_src = func_src,7569 .func_src = func_src,
7614 .return_ty = Type.fromInterned(func_ty_info.return_type),7570 .return_ty = Type.fromInterned(func_ty_info.return_type),
...@@ -7622,12 +7578,12 @@ fn analyzeCall(...@@ -7622,12 +7578,12 @@ fn analyzeCall(
76227578
7623 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {7579 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {
7624 const msg = msg: {7580 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)});
7626 errdefer msg.destroy(sema.gpa);7582 errdefer msg.destroy(sema.gpa);
76277583
7628 switch (operation) {7584 switch (operation) {
7629 .call, .@"@call", .@"@panic", .@"error return" => {},7585 .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", .{}),
7631 }7587 }
7632 break :msg msg;7588 break :msg msg;
7633 };7589 };
...@@ -7654,7 +7610,6 @@ fn analyzeCall(...@@ -7654,7 +7610,6 @@ fn analyzeCall(
7654 is_inline_call = true;7610 is_inline_call = true;
7655 is_comptime_call = true;7611 is_comptime_call = true;
7656 comptime_reason = &.{ .comptime_ret_ty = .{7612 comptime_reason = &.{ .comptime_ret_ty = .{
7657 .block = block,
7658 .func = func,7613 .func = func,
7659 .func_src = func_src,7614 .func_src = func_src,
7660 .return_ty = Type.fromInterned(func_ty_info.return_type),7615 .return_ty = Type.fromInterned(func_ty_info.return_type),
...@@ -7749,7 +7704,6 @@ fn analyzeCall(...@@ -7749,7 +7704,6 @@ fn analyzeCall(
7749 var child_block: Block = .{7704 var child_block: Block = .{
7750 .parent = null,7705 .parent = null,
7751 .sema = sema,7706 .sema = sema,
7752 .src_decl = module_fn.owner_decl,
7753 .namespace = fn_owner_decl.src_namespace,7707 .namespace = fn_owner_decl.src_namespace,
7754 .instructions = .{},7708 .instructions = .{},
7755 .label = null,7709 .label = null,
...@@ -7761,6 +7715,8 @@ fn analyzeCall(...@@ -7761,6 +7715,8 @@ fn analyzeCall(
7761 .runtime_cond = block.runtime_cond,7715 .runtime_cond = block.runtime_cond,
7762 .runtime_loop = block.runtime_loop,7716 .runtime_loop = block.runtime_loop,
7763 .runtime_index = block.runtime_index,7717 .runtime_index = block.runtime_index,
7718 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
7719 .type_name_ctx = fn_owner_decl.name,
7764 };7720 };
77657721
7766 const merges = &child_block.inlining.?.merges;7722 const merges = &child_block.inlining.?.merges;
...@@ -7834,7 +7790,7 @@ fn analyzeCall(...@@ -7834,7 +7790,7 @@ fn analyzeCall(
7834 var block_it = block;7790 var block_it = block;
7835 while (block_it.inlining) |parent_inlining| {7791 while (block_it.inlining) |parent_inlining| {
7836 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {7792 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", .{});
7838 return sema.failWithOwnedErrorMsg(null, err_msg);7794 return sema.failWithOwnedErrorMsg(null, err_msg);
7839 }7795 }
7840 block_it = parent_inlining.call_block;7796 block_it = parent_inlining.call_block;
...@@ -7849,7 +7805,7 @@ fn analyzeCall(...@@ -7849,7 +7805,7 @@ fn analyzeCall(
7849 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))7805 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))
7850 else7806 else
7851 try sema.resolveInst(fn_info.ret_ty_ref);7807 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 } };
7853 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);7809 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
7854 if (module_fn.analysis(ip).inferred_error_set) {7810 if (module_fn.analysis(ip).inferred_error_set) {
7855 // Create a fresh inferred error set type for inline/comptime calls.7811 // Create a fresh inferred error set type for inline/comptime calls.
...@@ -7920,7 +7876,7 @@ fn analyzeCall(...@@ -7920,7 +7876,7 @@ fn analyzeCall(
7920 };7876 };
79217877
7922 if (is_comptime_call) {7878 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);
7924 const result_interned = result_val.toIntern();7880 const result_interned = result_val.toIntern();
79257881
7926 // Transform ad-hoc inferred error set types into concrete error sets.7882 // Transform ad-hoc inferred error set types into concrete error sets.
...@@ -8081,7 +8037,7 @@ fn analyzeInlineCallArg(...@@ -8081,7 +8037,7 @@ fn analyzeInlineCallArg(
8081 // Evaluate the parameter type expression now that previous ones have8037 // Evaluate the parameter type expression now that previous ones have
8082 // been mapped, and coerce the corresponding argument to it.8038 // been mapped, and coerce the corresponding argument to it.
8083 const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;8039 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);
8085 const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index);8041 const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index);
8086 const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len);8042 const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len);
8087 const param_ty = param_ty: {8043 const param_ty = param_ty: {
...@@ -8261,7 +8217,6 @@ fn instantiateGenericCall(...@@ -8261,7 +8217,6 @@ fn instantiateGenericCall(
8261 .comptime_args = comptime_args,8217 .comptime_args = comptime_args,
8262 .generic_owner = generic_owner,8218 .generic_owner = generic_owner,
8263 .generic_call_src = call_src,8219 .generic_call_src = call_src,
8264 .generic_call_decl = block.src_decl.toOptional(),
8265 .branch_quota = sema.branch_quota,8220 .branch_quota = sema.branch_quota,
8266 .branch_count = sema.branch_count,8221 .branch_count = sema.branch_count,
8267 .comptime_err_ret_trace = sema.comptime_err_ret_trace,8222 .comptime_err_ret_trace = sema.comptime_err_ret_trace,
...@@ -8271,11 +8226,12 @@ fn instantiateGenericCall(...@@ -8271,11 +8226,12 @@ fn instantiateGenericCall(
8271 var child_block: Block = .{8226 var child_block: Block = .{
8272 .parent = null,8227 .parent = null,
8273 .sema = &child_sema,8228 .sema = &child_sema,
8274 .src_decl = generic_owner_func.owner_decl,
8275 .namespace = namespace_index,8229 .namespace = namespace_index,
8276 .instructions = .{},8230 .instructions = .{},
8277 .inlining = null,8231 .inlining = null,
8278 .is_comptime = true,8232 .is_comptime = true,
8233 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
8234 .type_name_ctx = fn_owner_decl.name,
8279 };8235 };
8280 defer child_block.instructions.deinit(gpa);8236 defer child_block.instructions.deinit(gpa);
82818237
...@@ -8306,22 +8262,23 @@ fn instantiateGenericCall(...@@ -8306,22 +8262,23 @@ fn instantiateGenericCall(
8306 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;8262 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;
8307 const prev_generic_owner = child_sema.generic_owner;8263 const prev_generic_owner = child_sema.generic_owner;
8308 const prev_generic_call_src = child_sema.generic_call_src;8264 const prev_generic_call_src = child_sema.generic_call_src;
8309 const prev_generic_call_decl = child_sema.generic_call_decl;
8310 child_block.params = .{};8265 child_block.params = .{};
8311 child_sema.no_partial_func_ty = true;8266 child_sema.no_partial_func_ty = true;
8312 child_sema.generic_owner = .none;8267 child_sema.generic_owner = .none;
8313 child_sema.generic_call_src = .unneeded;8268 child_sema.generic_call_src = LazySrcLoc.unneeded;
8314 child_sema.generic_call_decl = .none;
8315 defer {8269 defer {
8316 child_block.params = prev_params;8270 child_block.params = prev_params;
8317 child_sema.no_partial_func_ty = prev_no_partial_func_ty;8271 child_sema.no_partial_func_ty = prev_no_partial_func_ty;
8318 child_sema.generic_owner = prev_generic_owner;8272 child_sema.generic_owner = prev_generic_owner;
8319 child_sema.generic_call_src = prev_generic_call_src;8273 child_sema.generic_call_src = prev_generic_call_src;
8320 child_sema.generic_call_decl = prev_generic_call_decl;
8321 }8274 }
83228275
8323 const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst);8276 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 );
8325 },8282 },
8326 else => unreachable,8283 else => unreachable,
8327 }8284 }
...@@ -8353,14 +8310,14 @@ fn instantiateGenericCall(...@@ -8353,14 +8310,14 @@ fn instantiateGenericCall(
8353 .param_anytype_comptime,8310 .param_anytype_comptime,
8354 => return sema.failWithOwnedErrorMsg(block, msg: {8311 => return sema.failWithOwnedErrorMsg(block, msg: {
8355 const arg_src = args_info.argSrc(block, arg_index);8312 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", .{});
8357 errdefer msg.destroy(sema.gpa);8314 errdefer msg.destroy(sema.gpa);
8358 const param_src = switch (param_tag) {8315 const param_src = child_block.tokenOffset(switch (param_tag) {
8359 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),8316 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8360 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),8317 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
8361 else => unreachable,8318 else => unreachable,
8362 };8319 });
8363 try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{});8320 try child_sema.errNote(param_src, msg, "declared comptime here", .{});
8364 break :msg msg;8321 break :msg msg;
8365 }),8322 }),
83668323
...@@ -8368,16 +8325,15 @@ fn instantiateGenericCall(...@@ -8368,16 +8325,15 @@ fn instantiateGenericCall(
8368 .param_anytype,8325 .param_anytype,
8369 => return sema.failWithOwnedErrorMsg(block, msg: {8326 => return sema.failWithOwnedErrorMsg(block, msg: {
8370 const arg_src = args_info.argSrc(block, arg_index);8327 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", .{});
8372 errdefer msg.destroy(sema.gpa);8329 errdefer msg.destroy(sema.gpa);
8373 const param_src = switch (param_tag) {8330 const param_src = child_block.tokenOffset(switch (param_tag) {
8374 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),8331 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8375 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),8332 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
8376 else => unreachable,8333 else => unreachable,
8377 };8334 });
8378 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});8335 try child_sema.errNote(param_src, msg, "declared here", .{});
8379 const src_decl = mod.declPtr(block.src_decl);8336 try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty);
8380 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty);
8381 break :msg msg;8337 break :msg msg;
8382 }),8338 }),
83838339
...@@ -8414,12 +8370,12 @@ fn instantiateGenericCall(...@@ -8414,12 +8370,12 @@ fn instantiateGenericCall(
8414 // We've already handled parameters, so don't resolve the whole body. Instead, just8370 // We've already handled parameters, so don't resolve the whole body. Instead, just
8415 // do the instructions after the params (i.e. the func itself).8371 // do the instructions after the params (i.e. the func itself).
8416 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);8372 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
8419 const callee = mod.funcInfo(callee_index);8375 const callee = mod.funcInfo(callee_index);
8420 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);8376 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
8424 // Make a runtime call to the new function, making sure to omit the comptime args.8380 // Make a runtime call to the new function, making sure to omit the comptime args.
8425 const func_ty = Type.fromInterned(callee.ty);8381 const func_ty = Type.fromInterned(callee.ty);
...@@ -8501,7 +8457,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8501,7 +8457,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85018457
8502 const mod = sema.mod;8458 const mod = sema.mod;
8503 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8459 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 });
8505 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);8461 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
8506 if (child_type.zigTypeTag(mod) == .Opaque) {8462 if (child_type.zigTypeTag(mod) == .Opaque) {
8507 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});8463 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...@@ -8516,7 +8472,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8516fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8472fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8517 const mod = sema.mod;8473 const mod = sema.mod;
8518 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;8474 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) {
8520 // Since this is a ZIR instruction that returns a type, encountering8476 // Since this is a ZIR instruction that returns a type, encountering
8521 // generic poison should not result in a failed compilation, but the8477 // generic poison should not result in a failed compilation, but the
8522 // generic poison type. This prevents unnecessary failures when8478 // generic poison type. This prevents unnecessary failures when
...@@ -8539,7 +8495,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -8539,7 +8495,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
8539fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8495fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8540 const mod = sema.mod;8496 const mod = sema.mod;
8541 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8497 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) {
8543 error.GenericPoison => return .generic_poison_type,8499 error.GenericPoison => return .generic_poison_type,
8544 else => |e| return e,8500 else => |e| return e,
8545 };8501 };
...@@ -8557,7 +8513,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -8557,7 +8513,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
8557fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8513fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8558 const mod = sema.mod;8514 const mod = sema.mod;
8559 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8515 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);
8561 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {8517 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {
8562 error.GenericPoison => return .generic_poison_type,8518 error.GenericPoison => return .generic_poison_type,
8563 else => |e| return e,8519 else => |e| return e,
...@@ -8573,7 +8529,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -8573,7 +8529,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
8573fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8529fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8574 const mod = sema.mod;8530 const mod = sema.mod;
8575 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8531 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) {
8577 // Since this is a ZIR instruction that returns a type, encountering8533 // Since this is a ZIR instruction that returns a type, encountering
8578 // generic poison should not result in a failed compilation, but the8534 // generic poison should not result in a failed compilation, but the
8579 // generic poison type. This prevents unnecessary failures when8535 // generic poison type. This prevents unnecessary failures when
...@@ -8582,7 +8538,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8582,7 +8538,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8582 else => |e| return e,8538 else => |e| return e,
8583 };8539 };
8584 if (!vec_ty.isVector(mod)) {8540 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)});
8586 }8542 }
8587 return Air.internedToRef(vec_ty.childType(mod).toIntern());8543 return Air.internedToRef(vec_ty.childType(mod).toIntern());
8588}8544}
...@@ -8590,8 +8546,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8590,8 +8546,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8590fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8546fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8591 const mod = sema.mod;8547 const mod = sema.mod;
8592 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8548 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 };8549 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8594 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };8550 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
8595 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8551 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8596 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{8552 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
8597 .needed_comptime_reason = "vector length must be comptime-known",8553 .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...@@ -8611,8 +8567,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
86118567
8612 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8568 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8613 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8569 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 };8570 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8615 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };8571 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8616 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{8572 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
8617 .needed_comptime_reason = "array length must be comptime-known",8573 .needed_comptime_reason = "array length must be comptime-known",
8618 });8574 });
...@@ -8632,9 +8588,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -8632,9 +8588,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
86328588
8633 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8589 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8634 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;8590 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 };8591 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8636 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };8592 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
8637 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };8593 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8638 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{8594 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
8639 .needed_comptime_reason = "array length must be comptime-known",8595 .needed_comptime_reason = "array length must be comptime-known",
8640 });8596 });
...@@ -8669,10 +8625,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8669,10 +8625,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
86698625
8670 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8626 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8671 if (true) {8627 if (true) {
8672 return sema.failWithUseOfAsync(block, inst_data.src());8628 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
8673 }8629 }
8674 const mod = sema.mod;8630 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 });
8676 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);8632 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
8677 const anyframe_type = try mod.anyframeType(return_type);8633 const anyframe_type = try mod.anyframeType(return_type);
86788634
...@@ -8686,8 +8642,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8686,8 +8642,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8686 const mod = sema.mod;8642 const mod = sema.mod;
8687 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8643 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8688 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8644 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 };8645 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8690 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };8646 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
8691 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);8647 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
8692 const payload = try sema.resolveType(block, rhs_src, extra.rhs);8648 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...@@ -8739,8 +8695,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8739 const mod = sema.mod;8695 const mod = sema.mod;
8740 const ip = &mod.intern_pool;8696 const ip = &mod.intern_pool;
8741 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8697 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8742 const src = LazySrcLoc.nodeOffset(extra.node);8698 const src = block.nodeOffset(extra.node);
8743 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };8699 const operand_src = block.builtinCallArgSrc(extra.node, 0);
8744 const uncasted_operand = try sema.resolveInst(extra.operand);8700 const uncasted_operand = try sema.resolveInst(extra.operand);
8745 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);8701 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
8746 const err_int_ty = try mod.errorIntType();8702 const err_int_ty = try mod.errorIntType();
...@@ -8782,8 +8738,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8782,8 +8738,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87828738
8783 const mod = sema.mod;8739 const mod = sema.mod;
8784 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8740 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8785 const src = LazySrcLoc.nodeOffset(extra.node);8741 const src = block.nodeOffset(extra.node);
8786 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };8742 const operand_src = block.builtinCallArgSrc(extra.node, 0);
8787 const uncasted_operand = try sema.resolveInst(extra.operand);8743 const uncasted_operand = try sema.resolveInst(extra.operand);
8788 const err_int_ty = try mod.errorIntType();8744 const err_int_ty = try mod.errorIntType();
8789 const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);8745 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...@@ -8822,16 +8778,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8822 const ip = &mod.intern_pool;8778 const ip = &mod.intern_pool;
8823 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8779 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8824 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8780 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 };8781 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
8826 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };8782 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8827 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };8783 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
8828 const lhs = try sema.resolveInst(extra.lhs);8784 const lhs = try sema.resolveInst(extra.lhs);
8829 const rhs = try sema.resolveInst(extra.rhs);8785 const rhs = try sema.resolveInst(extra.rhs);
8830 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {8786 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {
8831 const msg = msg: {8787 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'", .{});
8833 errdefer msg.destroy(sema.gpa);8789 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", .{});
8835 break :msg msg;8791 break :msg msg;
8836 };8792 };
8837 return sema.failWithOwnedErrorMsg(block, msg);8793 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -8885,8 +8841,8 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8885,8 +8841,8 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8885fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8841fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8886 const mod = sema.mod;8842 const mod = sema.mod;
8887 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8843 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8888 const src = inst_data.src();8844 const src = block.nodeOffset(inst_data.src_node);
8889 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8845 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8890 const operand = try sema.resolveInst(inst_data.operand);8846 const operand = try sema.resolveInst(inst_data.operand);
8891 const operand_ty = sema.typeOf(operand);8847 const operand_ty = sema.typeOf(operand);
88928848
...@@ -8943,8 +8899,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8943,8 +8899,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8943 const mod = sema.mod;8899 const mod = sema.mod;
8944 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8900 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8945 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8901 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8946 const src = inst_data.src();8902 const src = block.nodeOffset(inst_data.src_node);
8947 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8903 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8948 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");8904 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
8949 const operand = try sema.resolveInst(extra.rhs);8905 const operand = try sema.resolveInst(extra.rhs);
89508906
...@@ -9012,7 +8968,7 @@ fn zirOptionalPayloadPtr(...@@ -9012,7 +8968,7 @@ fn zirOptionalPayloadPtr(
90128968
9013 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8969 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9014 const optional_ptr = try sema.resolveInst(inst_data.operand);8970 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
9017 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);8973 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);
9018}8974}
...@@ -9096,7 +9052,7 @@ fn zirOptionalPayload(...@@ -9096,7 +9052,7 @@ fn zirOptionalPayload(
90969052
9097 const mod = sema.mod;9053 const mod = sema.mod;
9098 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9054 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);
9100 const operand = try sema.resolveInst(inst_data.operand);9056 const operand = try sema.resolveInst(inst_data.operand);
9101 const operand_ty = sema.typeOf(operand);9057 const operand_ty = sema.typeOf(operand);
9102 const result_ty = switch (operand_ty.zigTypeTag(mod)) {9058 const result_ty = switch (operand_ty.zigTypeTag(mod)) {
...@@ -9148,7 +9104,7 @@ fn zirErrUnionPayload(...@@ -9148,7 +9104,7 @@ fn zirErrUnionPayload(
91489104
9149 const mod = sema.mod;9105 const mod = sema.mod;
9150 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9106 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);
9152 const operand = try sema.resolveInst(inst_data.operand);9108 const operand = try sema.resolveInst(inst_data.operand);
9153 const operand_src = src;9109 const operand_src = src;
9154 const err_union_ty = sema.typeOf(operand);9110 const err_union_ty = sema.typeOf(operand);
...@@ -9201,7 +9157,7 @@ fn zirErrUnionPayloadPtr(...@@ -9201,7 +9157,7 @@ fn zirErrUnionPayloadPtr(
92019157
9202 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9203 const operand = try sema.resolveInst(inst_data.operand);9159 const operand = try sema.resolveInst(inst_data.operand);
9204 const src = inst_data.src();9160 const src = block.nodeOffset(inst_data.src_node);
92059161
9206 return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false);9162 return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false);
9207}9163}
...@@ -9285,7 +9241,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -9285,7 +9241,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
9285 defer tracy.end();9241 defer tracy.end();
92869242
9287 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9243 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);
9289 const operand = try sema.resolveInst(inst_data.operand);9245 const operand = try sema.resolveInst(inst_data.operand);
9290 return sema.analyzeErrUnionCode(block, src, operand);9246 return sema.analyzeErrUnionCode(block, src, operand);
9291}9247}
...@@ -9318,7 +9274,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -9318,7 +9274,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
9318 defer tracy.end();9274 defer tracy.end();
93199275
9320 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9276 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);
9322 const operand = try sema.resolveInst(inst_data.operand);9278 const operand = try sema.resolveInst(inst_data.operand);
9323 return sema.analyzeErrUnionCodePtr(block, src, operand);9279 return sema.analyzeErrUnionCodePtr(block, src, operand);
9324}9280}
...@@ -9360,7 +9316,7 @@ fn zirFunc(...@@ -9360,7 +9316,7 @@ fn zirFunc(
9360 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;9316 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
9361 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);9317 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
9362 const target = sema.mod.getTarget();9318 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
9365 var extra_index = extra.end;9321 var extra_index = extra.end;
93669322
...@@ -9396,13 +9352,17 @@ fn zirFunc(...@@ -9396,13 +9352,17 @@ fn zirFunc(
9396 src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;9352 src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;
9397 }9353 }
93989354
9399 // If this instruction has a body it means it's the type of the `owner_decl`9355 // If this instruction has a body, then it's a function declaration, and we decide
9400 // otherwise it's a function type without a `callconv` attribute and should9356 // the callconv based on whether it is exported. Otherwise, the callconv defaults
9401 // never be `.C`.9357 // to `.Unspecified`.
9402 const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(block.src_decl).is_exported)9358 const cc: std.builtin.CallingConvention = if (has_body) cc: {
9403 .C9359 const fn_is_exported = if (sema.generic_owner != .none) exported: {
9404 else9360 const generic_owner_fn = mod.funcInfo(sema.generic_owner);
9405 .Unspecified;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
9407 return sema.funcCommon(9367 return sema.funcCommon(
9408 block,9368 block,
...@@ -9441,18 +9401,15 @@ fn resolveGenericBody(...@@ -9441,18 +9401,15 @@ fn resolveGenericBody(
9441 const prev_no_partial_func_type = sema.no_partial_func_ty;9401 const prev_no_partial_func_type = sema.no_partial_func_ty;
9442 const prev_generic_owner = sema.generic_owner;9402 const prev_generic_owner = sema.generic_owner;
9443 const prev_generic_call_src = sema.generic_call_src;9403 const prev_generic_call_src = sema.generic_call_src;
9444 const prev_generic_call_decl = sema.generic_call_decl;
9445 block.params = .{};9404 block.params = .{};
9446 sema.no_partial_func_ty = true;9405 sema.no_partial_func_ty = true;
9447 sema.generic_owner = .none;9406 sema.generic_owner = .none;
9448 sema.generic_call_src = .unneeded;9407 sema.generic_call_src = LazySrcLoc.unneeded;
9449 sema.generic_call_decl = .none;
9450 defer {9408 defer {
9451 block.params = prev_params;9409 block.params = prev_params;
9452 sema.no_partial_func_ty = prev_no_partial_func_type;9410 sema.no_partial_func_ty = prev_no_partial_func_type;
9453 sema.generic_owner = prev_generic_owner;9411 sema.generic_owner = prev_generic_owner;
9454 sema.generic_call_src = prev_generic_call_src;9412 sema.generic_call_src = prev_generic_call_src;
9455 sema.generic_call_decl = prev_generic_call_decl;
9456 }9413 }
94579414
9458 const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err;9415 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:...@@ -9562,9 +9519,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
95629519
9563 if (!callConvSupportsVarArgs(cc)) {9520 if (!callConvSupportsVarArgs(cc)) {
9564 const msg = msg: {9521 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)});
9566 errdefer msg.destroy(sema.gpa);9523 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{}});
9568 break :msg msg;9525 break :msg msg;
9569 };9526 };
9570 return sema.failWithOwnedErrorMsg(block, msg);9527 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -9604,9 +9561,9 @@ fn funcCommon(...@@ -9604,9 +9561,9 @@ fn funcCommon(
9604 const gpa = sema.gpa;9561 const gpa = sema.gpa;
9605 const target = mod.getTarget();9562 const target = mod.getTarget();
9606 const ip = &mod.intern_pool;9563 const ip = &mod.intern_pool;
9607 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };9564 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset });
9608 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };9565 const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset });
9609 const func_src = LazySrcLoc.nodeOffset(src_node_offset);9566 const func_src = block.nodeOffset(src_node_offset);
96109567
9611 var is_generic = bare_return_type.isGenericPoison() or9568 var is_generic = bare_return_type.isGenericPoison() or
9612 alignment == null or9569 alignment == null or
...@@ -9635,11 +9592,10 @@ fn funcCommon(...@@ -9635,11 +9592,10 @@ fn funcCommon(
9635 const index = std.math.cast(u5, i) orelse break :blk false;9592 const index = std.math.cast(u5, i) orelse break :blk false;
9636 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;9593 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
9637 };9594 };
9638 const param_src: LazySrcLoc = .{ .fn_proto_param = .{9595 const param_src = block.src(.{ .fn_proto_param = .{
9639 .decl = block.src_decl,
9640 .fn_proto_node_offset = src_node_offset,9596 .fn_proto_node_offset = src_node_offset,
9641 .param_index = @intCast(i),9597 .param_index = @intCast(i),
9642 } };9598 } });
9643 const requires_comptime = try sema.typeRequiresComptime(param_ty);9599 const requires_comptime = try sema.typeRequiresComptime(param_ty);
9644 if (param_is_comptime or requires_comptime) {9600 if (param_is_comptime or requires_comptime) {
9645 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error9601 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
...@@ -9660,13 +9616,12 @@ fn funcCommon(...@@ -9660,13 +9616,12 @@ fn funcCommon(
9660 }9616 }
9661 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {9617 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {
9662 const msg = msg: {9618 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}'", .{
9664 param_ty.fmt(mod), @tagName(cc_resolved),9620 param_ty.fmt(mod), @tagName(cc_resolved),
9665 });9621 });
9666 errdefer msg.destroy(sema.gpa);9622 errdefer msg.destroy(sema.gpa);
96679623
9668 const src_decl = mod.declPtr(block.src_decl);9624 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
9669 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty);
96709625
9671 try sema.addDeclaredHereNote(msg, param_ty);9626 try sema.addDeclaredHereNote(msg, param_ty);
9672 break :msg msg;9627 break :msg msg;
...@@ -9675,13 +9630,12 @@ fn funcCommon(...@@ -9675,13 +9630,12 @@ fn funcCommon(
9675 }9630 }
9676 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {9631 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {
9677 const msg = msg: {9632 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", .{
9679 param_ty.fmt(mod),9634 param_ty.fmt(mod),
9680 });9635 });
9681 errdefer msg.destroy(sema.gpa);9636 errdefer msg.destroy(sema.gpa);
96829637
9683 const src_decl = mod.declPtr(block.src_decl);9638 try sema.explainWhyTypeIsComptime(msg, param_src, param_ty);
9684 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty);
96859639
9686 try sema.addDeclaredHereNote(msg, param_ty);9640 try sema.addDeclaredHereNote(msg, param_ty);
9687 break :msg msg;9641 break :msg msg;
...@@ -9842,9 +9796,9 @@ fn funcCommon(...@@ -9842,9 +9796,9 @@ fn funcCommon(
9842 assert(section != .generic);9796 assert(section != .generic);
9843 assert(address_space != null);9797 assert(address_space != null);
9844 assert(!is_generic);9798 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(.{
9846 .node_offset_lib_name = src_node_offset,9800 .node_offset_lib_name = src_node_offset,
9847 }, lib_name);9801 }), lib_name);
9848 const func_index = try ip.getExternFunc(gpa, .{9802 const func_index = try ip.getExternFunc(gpa, .{
9849 .ty = func_ty,9803 .ty = func_ty,
9850 .decl = sema.owner_decl_index,9804 .decl = sema.owner_decl_index,
...@@ -9956,13 +9910,12 @@ fn finishFunc(...@@ -9956,13 +9910,12 @@ fn finishFunc(
9956 !try sema.validateExternType(return_type, .ret_ty))9910 !try sema.validateExternType(return_type, .ret_ty))
9957 {9911 {
9958 const msg = msg: {9912 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}'", .{
9960 return_type.fmt(mod), @tagName(cc_resolved),9914 return_type.fmt(mod), @tagName(cc_resolved),
9961 });9915 });
9962 errdefer msg.destroy(gpa);9916 errdefer msg.destroy(gpa);
99639917
9964 const src_decl = mod.declPtr(block.src_decl);9918 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty);
9965 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty);
99669919
9967 try sema.addDeclaredHereNote(msg, return_type);9920 try sema.addDeclaredHereNote(msg, return_type);
9968 break :msg msg;9921 break :msg msg;
...@@ -9978,12 +9931,11 @@ fn finishFunc(...@@ -9978,12 +9931,11 @@ fn finishFunc(
9978 } else break :comptime_check;9931 } else break :comptime_check;
99799932
9980 const msg = try sema.errMsg(9933 const msg = try sema.errMsg(
9981 block,
9982 ret_ty_src,9934 ret_ty_src,
9983 "function with comptime-only return type '{}' requires all parameters to be comptime",9935 "function with comptime-only return type '{}' requires all parameters to be comptime",
9984 .{return_type.fmt(mod)},9936 .{return_type.fmt(mod)},
9985 );9937 );
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
9988 const tags = sema.code.instructions.items(.tag);9940 const tags = sema.code.instructions.items(.tag);
9989 const data = sema.code.instructions.items(.data);9941 const data = sema.code.instructions.items(.data);
...@@ -9994,16 +9946,16 @@ fn finishFunc(...@@ -9994,16 +9946,16 @@ fn finishFunc(
9994 param_body[0..block.params.len],9946 param_body[0..block.params.len],
9995 ) |is_comptime, name_nts, param_index| {9947 ) |is_comptime, name_nts, param_index| {
9996 if (!is_comptime) {9948 if (!is_comptime) {
9997 const param_src = switch (tags[@intFromEnum(param_index)]) {9949 const param_src = block.tokenOffset(switch (tags[@intFromEnum(param_index)]) {
9998 .param => data[@intFromEnum(param_index)].pl_tok.src(),9950 .param => data[@intFromEnum(param_index)].pl_tok.src_tok,
9999 .param_anytype => data[@intFromEnum(param_index)].str_tok.src(),9951 .param_anytype => data[@intFromEnum(param_index)].str_tok.src_tok,
10000 else => unreachable,9952 else => unreachable,
10001 };9953 });
10002 const name = sema.code.nullTerminatedString(name_nts);9954 const name = sema.code.nullTerminatedString(name_nts);
10003 if (name.len != 0) {9955 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});
10005 } else {9957 } 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", .{});
10007 }9959 }
10008 }9960 }
10009 }9961 }
...@@ -10081,7 +10033,7 @@ fn zirParam(...@@ -10081,7 +10033,7 @@ fn zirParam(
10081 comptime_syntax: bool,10033 comptime_syntax: bool,
10082) CompileError!void {10034) CompileError!void {
10083 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;10035 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);
10085 const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);10037 const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
10086 const param_name: Zir.NullTerminatedString = extra.data.name;10038 const param_name: Zir.NullTerminatedString = extra.data.name;
10087 const body = sema.code.bodySlice(extra.end, extra.data.body_len);10039 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
...@@ -10093,18 +10045,15 @@ fn zirParam(...@@ -10093,18 +10045,15 @@ fn zirParam(
10093 const prev_no_partial_func_type = sema.no_partial_func_ty;10045 const prev_no_partial_func_type = sema.no_partial_func_ty;
10094 const prev_generic_owner = sema.generic_owner;10046 const prev_generic_owner = sema.generic_owner;
10095 const prev_generic_call_src = sema.generic_call_src;10047 const prev_generic_call_src = sema.generic_call_src;
10096 const prev_generic_call_decl = sema.generic_call_decl;
10097 block.params = .{};10048 block.params = .{};
10098 sema.no_partial_func_ty = true;10049 sema.no_partial_func_ty = true;
10099 sema.generic_owner = .none;10050 sema.generic_owner = .none;
10100 sema.generic_call_src = .unneeded;10051 sema.generic_call_src = LazySrcLoc.unneeded;
10101 sema.generic_call_decl = .none;
10102 defer {10052 defer {
10103 block.params = prev_params;10053 block.params = prev_params;
10104 sema.no_partial_func_ty = prev_no_partial_func_type;10054 sema.no_partial_func_ty = prev_no_partial_func_type;
10105 sema.generic_owner = prev_generic_owner;10055 sema.generic_owner = prev_generic_owner;
10106 sema.generic_call_src = prev_generic_call_src;10056 sema.generic_call_src = prev_generic_call_src;
10107 sema.generic_call_decl = prev_generic_call_decl;
10108 }10057 }
1010910058
10110 if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| {10059 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....@@ -10191,7 +10140,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
10191 defer tracy.end();10140 defer tracy.end();
1019210141
10193 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10142 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);
10195 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;10144 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
10196 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);10145 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);
10197}10146}
...@@ -10201,7 +10150,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -10201,7 +10150,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
10201 defer tracy.end();10150 defer tracy.end();
1020210151
10203 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10152 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);
10205 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;10154 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
10206 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true);10155 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true);
10207}10156}
...@@ -10246,7 +10195,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10246,7 +10195,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1024610195
10247 const zcu = sema.mod;10196 const zcu = sema.mod;
10248 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;10197 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);
10250 const operand = try sema.resolveInst(inst_data.operand);10199 const operand = try sema.resolveInst(inst_data.operand);
10251 const operand_ty = sema.typeOf(operand);10200 const operand_ty = sema.typeOf(operand);
10252 const ptr_ty = operand_ty.scalarType(zcu);10201 const ptr_ty = operand_ty.scalarType(zcu);
...@@ -10257,10 +10206,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10257,10 +10206,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10257 const pointee_ty = ptr_ty.childType(zcu);10206 const pointee_ty = ptr_ty.childType(zcu);
10258 if (try sema.typeRequiresComptime(ptr_ty)) {10207 if (try sema.typeRequiresComptime(ptr_ty)) {
10259 const msg = msg: {10208 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)});
10261 errdefer msg.destroy(sema.gpa);10210 errdefer msg.destroy(sema.gpa);
10262 const src_decl = zcu.declPtr(block.src_decl);10211 try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty);
10263 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty);
10264 break :msg msg;10212 break :msg msg;
10265 };10213 };
10266 return sema.failWithOwnedErrorMsg(block, msg);10214 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -10298,7 +10246,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10298,7 +10246,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10298 .storage = .{ .elems = new_elems },10246 .storage = .{ .elems = new_elems },
10299 } }));10247 } }));
10300 }10248 }
10301 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);10249 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src);
10302 try sema.validateRuntimeValue(block, ptr_src, operand);10250 try sema.validateRuntimeValue(block, ptr_src, operand);
10303 if (!is_vector) {10251 if (!is_vector) {
10304 return block.addUnOp(.int_from_ptr, operand);10252 return block.addUnOp(.int_from_ptr, operand);
...@@ -10320,8 +10268,8 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10320,8 +10268,8 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1032010268
10321 const mod = sema.mod;10269 const mod = sema.mod;
10322 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10270 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10323 const src = inst_data.src();10271 const src = block.nodeOffset(inst_data.src_node);
10324 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10272 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10325 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10273 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10326 const field_name = try mod.intern_pool.getOrPutString(10274 const field_name = try mod.intern_pool.getOrPutString(
10327 sema.gpa,10275 sema.gpa,
...@@ -10338,8 +10286,8 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10338,8 +10286,8 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1033810286
10339 const mod = sema.mod;10287 const mod = sema.mod;
10340 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10341 const src = inst_data.src();10289 const src = block.nodeOffset(inst_data.src_node);
10342 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10290 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10343 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10291 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10344 const field_name = try mod.intern_pool.getOrPutString(10292 const field_name = try mod.intern_pool.getOrPutString(
10345 sema.gpa,10293 sema.gpa,
...@@ -10356,8 +10304,8 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -10356,8 +10304,8 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1035610304
10357 const mod = sema.mod;10305 const mod = sema.mod;
10358 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10306 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10359 const src = inst_data.src();10307 const src = block.nodeOffset(inst_data.src_node);
10360 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };10308 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
10361 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10309 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10362 const field_name = try mod.intern_pool.getOrPutString(10310 const field_name = try mod.intern_pool.getOrPutString(
10363 sema.gpa,10311 sema.gpa,
...@@ -10381,8 +10329,8 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -10381,8 +10329,8 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
10381 defer tracy.end();10329 defer tracy.end();
1038210330
10383 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10331 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10384 const src = inst_data.src();10332 const src = block.nodeOffset(inst_data.src_node);
10385 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };10333 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
10386 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;10334 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
10387 const object = try sema.resolveInst(extra.lhs);10335 const object = try sema.resolveInst(extra.lhs);
10388 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{10336 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...@@ -10396,8 +10344,8 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
10396 defer tracy.end();10344 defer tracy.end();
1039710345
10398 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10346 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10399 const src = inst_data.src();10347 const src = block.nodeOffset(inst_data.src_node);
10400 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };10348 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
10401 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;10349 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
10402 const object_ptr = try sema.resolveInst(extra.lhs);10350 const object_ptr = try sema.resolveInst(extra.lhs);
10403 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{10351 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...@@ -10411,14 +10359,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10411 defer tracy.end();10359 defer tracy.end();
1041210360
10413 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10361 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10414 const src = inst_data.src();10362 const src = block.nodeOffset(inst_data.src_node);
10415 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10363 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10416 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10364 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1041710365
10418 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");10366 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
10419 const operand = try sema.resolveInst(extra.rhs);10367 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);
10422}10370}
1042310371
10424fn intCast(10372fn intCast(
...@@ -10581,8 +10529,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10581,8 +10529,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1058110529
10582 const mod = sema.mod;10530 const mod = sema.mod;
10583 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10531 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10584 const src = inst_data.src();10532 const src = block.nodeOffset(inst_data.src_node);
10585 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10533 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10586 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10534 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1058710535
10588 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");10536 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...@@ -10608,10 +10556,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1060810556
10609 .Enum => {10557 .Enum => {
10610 const msg = msg: {10558 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)});
10612 errdefer msg.destroy(sema.gpa);10560 errdefer msg.destroy(sema.gpa);
10613 switch (operand_ty.zigTypeTag(mod)) {10561 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)}),
10615 else => {},10563 else => {},
10616 }10564 }
1061710565
...@@ -10622,11 +10570,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10622,11 +10570,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1062210570
10623 .Pointer => {10571 .Pointer => {
10624 const msg = msg: {10572 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)});
10626 errdefer msg.destroy(sema.gpa);10574 errdefer msg.destroy(sema.gpa);
10627 switch (operand_ty.zigTypeTag(mod)) {10575 switch (operand_ty.zigTypeTag(mod)) {
10628 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),10576 .Int, .ComptimeInt => try sema.errNote(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)}),10577 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
10630 else => {},10578 else => {},
10631 }10579 }
1063210580
...@@ -10672,10 +10620,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10672,10 +10620,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1067210620
10673 .Enum => {10621 .Enum => {
10674 const msg = msg: {10622 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)});
10676 errdefer msg.destroy(sema.gpa);10624 errdefer msg.destroy(sema.gpa);
10677 switch (dest_ty.zigTypeTag(mod)) {10625 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)}),
10679 else => {},10627 else => {},
10680 }10628 }
1068110629
...@@ -10685,11 +10633,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10685,11 +10633,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10685 },10633 },
10686 .Pointer => {10634 .Pointer => {
10687 const msg = msg: {10635 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)});
10689 errdefer msg.destroy(sema.gpa);10637 errdefer msg.destroy(sema.gpa);
10690 switch (dest_ty.zigTypeTag(mod)) {10638 switch (dest_ty.zigTypeTag(mod)) {
10691 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr 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)}),
10692 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),10640 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
10693 else => {},10641 else => {},
10694 }10642 }
1069510643
...@@ -10715,7 +10663,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10715,7 +10663,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10715 .Vector,10663 .Vector,
10716 => {},10664 => {},
10717 }10665 }
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);
10719}10667}
1072010668
10721fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10669fn 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...@@ -10724,8 +10672,8 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1072410672
10725 const mod = sema.mod;10673 const mod = sema.mod;
10726 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10674 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10727 const src = inst_data.src();10675 const src = block.nodeOffset(inst_data.src_node);
10728 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10676 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10729 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10677 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1073010678
10731 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");10679 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...@@ -10778,7 +10726,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10778 if (dest_is_comptime_float) {10726 if (dest_is_comptime_float) {
10779 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{});10727 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{});
10780 }10728 }
10781 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);10729 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src);
1078210730
10783 const src_bits = operand_scalar_ty.floatBits(target);10731 const src_bits = operand_scalar_ty.floatBits(target);
10784 const dst_bits = dest_scalar_ty.floatBits(target);10732 const dst_bits = dest_scalar_ty.floatBits(target);
...@@ -10803,7 +10751,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10803,7 +10751,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10803 defer tracy.end();10751 defer tracy.end();
1080410752
10805 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10753 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);
10807 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10755 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10808 const array = try sema.resolveInst(extra.lhs);10756 const array = try sema.resolveInst(extra.lhs);
10809 const elem_index = try sema.resolveInst(extra.rhs);10757 const elem_index = try sema.resolveInst(extra.rhs);
...@@ -10815,8 +10763,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10815,8 +10763,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10815 defer tracy.end();10763 defer tracy.end();
1081610764
10817 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10765 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10818 const src = inst_data.src();10766 const src = block.nodeOffset(inst_data.src_node);
10819 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };10767 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
10820 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10768 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10821 const array = try sema.resolveInst(extra.lhs);10769 const array = try sema.resolveInst(extra.lhs);
10822 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10770 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
...@@ -10832,7 +10780,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10832,7 +10780,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10832 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;10780 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
10833 const array = try sema.resolveInst(inst_data.operand);10781 const array = try sema.resolveInst(inst_data.operand);
10834 const elem_index = try mod.intRef(Type.usize, inst_data.idx);10782 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);
10836}10784}
1083710785
10838fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10786fn 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...@@ -10841,20 +10789,20 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1084110789
10842 const mod = sema.mod;10790 const mod = sema.mod;
10843 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10791 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);
10845 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10793 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10846 const array_ptr = try sema.resolveInst(extra.lhs);10794 const array_ptr = try sema.resolveInst(extra.lhs);
10847 const elem_index = try sema.resolveInst(extra.rhs);10795 const elem_index = try sema.resolveInst(extra.rhs);
10848 const indexable_ty = sema.typeOf(array_ptr);10796 const indexable_ty = sema.typeOf(array_ptr);
10849 if (indexable_ty.zigTypeTag(mod) != .Pointer) {10797 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 });
10851 const msg = msg: {10799 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 '{}'", .{
10853 indexable_ty.fmt(mod),10801 indexable_ty.fmt(mod),
10854 });10802 });
10855 errdefer msg.destroy(sema.gpa);10803 errdefer msg.destroy(sema.gpa);
10856 if (indexable_ty.isIndexable(mod)) {10804 if (indexable_ty.isIndexable(mod)) {
10857 try sema.errNote(block, src, msg, "consider using '&' here", .{});10805 try sema.errNote(src, msg, "consider using '&' here", .{});
10858 }10806 }
10859 break :msg msg;10807 break :msg msg;
10860 };10808 };
...@@ -10868,8 +10816,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10868,8 +10816,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10868 defer tracy.end();10816 defer tracy.end();
1086910817
10870 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10818 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10871 const src = inst_data.src();10819 const src = block.nodeOffset(inst_data.src_node);
10872 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };10820 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
10873 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10821 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10874 const array_ptr = try sema.resolveInst(extra.lhs);10822 const array_ptr = try sema.resolveInst(extra.lhs);
10875 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10823 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
...@@ -10883,7 +10831,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -10883,7 +10831,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1088310831
10884 const mod = sema.mod;10832 const mod = sema.mod;
10885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10833 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);
10887 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;10835 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
10888 const array_ptr = try sema.resolveInst(extra.ptr);10836 const array_ptr = try sema.resolveInst(extra.ptr);
10889 const elem_index = try sema.mod.intRef(Type.usize, extra.index);10837 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!...@@ -10902,15 +10850,15 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10902 defer tracy.end();10850 defer tracy.end();
1090310851
10904 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10852 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);
10906 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;10854 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
10907 const array_ptr = try sema.resolveInst(extra.lhs);10855 const array_ptr = try sema.resolveInst(extra.lhs);
10908 const start = try sema.resolveInst(extra.start);10856 const start = try sema.resolveInst(extra.start);
10909 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10857 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10910 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10858 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10911 const end_src: LazySrcLoc = .{ .node_offset_slice_end = 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);
10914}10862}
1091510863
10916fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10864fn 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...@@ -10918,16 +10866,16 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10918 defer tracy.end();10866 defer tracy.end();
1091910867
10920 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10868 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);
10922 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;10870 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
10923 const array_ptr = try sema.resolveInst(extra.lhs);10871 const array_ptr = try sema.resolveInst(extra.lhs);
10924 const start = try sema.resolveInst(extra.start);10872 const start = try sema.resolveInst(extra.start);
10925 const end = try sema.resolveInst(extra.end);10873 const end = try sema.resolveInst(extra.end);
10926 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10874 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10927 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10875 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10928 const end_src: LazySrcLoc = .{ .node_offset_slice_end = 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);
10931}10879}
1093210880
10933fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10881fn 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...@@ -10935,16 +10883,16 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
10935 defer tracy.end();10883 defer tracy.end();
1093610884
10937 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10938 const src = inst_data.src();10886 const src = block.nodeOffset(inst_data.src_node);
10939 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };10887 const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
10940 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;10888 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
10941 const array_ptr = try sema.resolveInst(extra.lhs);10889 const array_ptr = try sema.resolveInst(extra.lhs);
10942 const start = try sema.resolveInst(extra.start);10890 const start = try sema.resolveInst(extra.start);
10943 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);10891 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);
10944 const sentinel = try sema.resolveInst(extra.sentinel);10892 const sentinel = try sema.resolveInst(extra.sentinel);
10945 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10893 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10946 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10894 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10947 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10895 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1094810896
10949 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);10897 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);
10950}10898}
...@@ -10954,19 +10902,19 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10954,19 +10902,19 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10954 defer tracy.end();10902 defer tracy.end();
1095510903
10956 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10904 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);
10958 const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;10906 const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
10959 const array_ptr = try sema.resolveInst(extra.lhs);10907 const array_ptr = try sema.resolveInst(extra.lhs);
10960 const start = try sema.resolveInst(extra.start);10908 const start = try sema.resolveInst(extra.start);
10961 const len = try sema.resolveInst(extra.len);10909 const len = try sema.resolveInst(extra.len);
10962 const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel);10910 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 };10911 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10964 const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset };10912 const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset });
10965 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10913 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
10966 const sentinel_src: LazySrcLoc = if (sentinel == .none)10914 const sentinel_src: LazySrcLoc = if (sentinel == .none)
10967 .unneeded10915 LazySrcLoc.unneeded
10968 else10916 else
10969 .{ .node_offset_slice_sentinel = inst_data.src_node };10917 block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1097010918
10971 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);10919 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);
10972}10920}
...@@ -11000,8 +10948,8 @@ const SwitchProngAnalysis = struct {...@@ -11000,8 +10948,8 @@ const SwitchProngAnalysis = struct {
11000 prong_type: enum { normal, special },10948 prong_type: enum { normal, special },
11001 prong_body: []const Zir.Inst.Index,10949 prong_body: []const Zir.Inst.Index,
11002 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,10950 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11003 /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field.10951 /// Must use the `switch_capture` field in `offset`.
11004 raw_capture_src: Module.SwitchProngSrc,10952 capture_src: LazySrcLoc,
11005 /// The set of all values which can reach this prong. May be undefined10953 /// The set of all values which can reach this prong. May be undefined
11006 /// if the prong is special or contains ranges.10954 /// if the prong is special or contains ranges.
11007 case_vals: []const Air.Inst.Ref,10955 case_vals: []const Air.Inst.Ref,
...@@ -11014,10 +10962,12 @@ const SwitchProngAnalysis = struct {...@@ -11014,10 +10962,12 @@ const SwitchProngAnalysis = struct {
11014 merges: *Block.Merges,10962 merges: *Block.Merges,
11015 ) CompileError!Air.Inst.Ref {10963 ) CompileError!Air.Inst.Ref {
11016 const sema = spa.sema;10964 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
11019 if (has_tag_capture) {10969 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);
11021 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);10971 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
11022 }10972 }
11023 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));10973 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
...@@ -11032,7 +10982,7 @@ const SwitchProngAnalysis = struct {...@@ -11032,7 +10982,7 @@ const SwitchProngAnalysis = struct {
11032 child_block,10982 child_block,
11033 capture == .by_ref,10983 capture == .by_ref,
11034 prong_type == .special,10984 prong_type == .special,
11035 raw_capture_src,10985 capture_src,
11036 case_vals,10986 case_vals,
11037 inline_case_capture,10987 inline_case_capture,
11038 );10988 );
...@@ -11058,8 +11008,8 @@ const SwitchProngAnalysis = struct {...@@ -11058,8 +11008,8 @@ const SwitchProngAnalysis = struct {
11058 prong_type: enum { normal, special },11008 prong_type: enum { normal, special },
11059 prong_body: []const Zir.Inst.Index,11009 prong_body: []const Zir.Inst.Index,
11060 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,11010 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11061 /// Must use the `scalar`, `special`, or `multi_capture` union field.11011 /// Must use the `switch_capture` field in `offset`.
11062 raw_capture_src: Module.SwitchProngSrc,11012 capture_src: LazySrcLoc,
11063 /// The set of all values which can reach this prong. May be undefined11013 /// The set of all values which can reach this prong. May be undefined
11064 /// if the prong is special or contains ranges.11014 /// if the prong is special or contains ranges.
11065 case_vals: []const Air.Inst.Ref,11015 case_vals: []const Air.Inst.Ref,
...@@ -11073,7 +11023,7 @@ const SwitchProngAnalysis = struct {...@@ -11073,7 +11023,7 @@ const SwitchProngAnalysis = struct {
11073 const sema = spa.sema;11023 const sema = spa.sema;
1107411024
11075 if (has_tag_capture) {11025 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);
11077 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);11027 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
11078 }11028 }
11079 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));11029 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
...@@ -11088,7 +11038,7 @@ const SwitchProngAnalysis = struct {...@@ -11088,7 +11038,7 @@ const SwitchProngAnalysis = struct {
11088 case_block,11038 case_block,
11089 capture == .by_ref,11039 capture == .by_ref,
11090 prong_type == .special,11040 prong_type == .special,
11091 raw_capture_src,11041 capture_src,
11092 case_vals,11042 case_vals,
11093 inline_case_capture,11043 inline_case_capture,
11094 );11044 );
...@@ -11109,23 +11059,18 @@ const SwitchProngAnalysis = struct {...@@ -11109,23 +11059,18 @@ const SwitchProngAnalysis = struct {
11109 fn analyzeTagCapture(11059 fn analyzeTagCapture(
11110 spa: SwitchProngAnalysis,11060 spa: SwitchProngAnalysis,
11111 block: *Block,11061 block: *Block,
11112 raw_capture_src: Module.SwitchProngSrc,11062 capture_src: LazySrcLoc,
11113 inline_case_capture: Air.Inst.Ref,11063 inline_case_capture: Air.Inst.Ref,
11114 ) CompileError!Air.Inst.Ref {11064 ) CompileError!Air.Inst.Ref {
11115 const sema = spa.sema;11065 const sema = spa.sema;
11116 const mod = sema.mod;11066 const mod = sema.mod;
11117 const operand_ty = sema.typeOf(spa.operand);11067 const operand_ty = sema.typeOf(spa.operand);
11118 if (operand_ty.zigTypeTag(mod) != .Union) {11068 if (operand_ty.zigTypeTag(mod) != .Union) {
11119 const zir_datas = sema.code.instructions.items(.data);11069 const tag_capture_src: LazySrcLoc = .{
11120 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;11070 .base_node_inst = capture_src.base_node_inst,
11121 const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) {11071 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
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,
11126 };11072 };
11127 const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none);11073 return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{
11128 return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{
11129 operand_ty.fmt(mod),11074 operand_ty.fmt(mod),
11130 });11075 });
11131 }11076 }
...@@ -11138,7 +11083,7 @@ const SwitchProngAnalysis = struct {...@@ -11138,7 +11083,7 @@ const SwitchProngAnalysis = struct {
11138 block: *Block,11083 block: *Block,
11139 capture_byref: bool,11084 capture_byref: bool,
11140 is_special_prong: bool,11085 is_special_prong: bool,
11141 raw_capture_src: Module.SwitchProngSrc,11086 capture_src: LazySrcLoc,
11142 case_vals: []const Air.Inst.Ref,11087 case_vals: []const Air.Inst.Ref,
11143 inline_case_capture: Air.Inst.Ref,11088 inline_case_capture: Air.Inst.Ref,
11144 ) CompileError!Air.Inst.Ref {11089 ) CompileError!Air.Inst.Ref {
...@@ -11151,10 +11096,10 @@ const SwitchProngAnalysis = struct {...@@ -11151,10 +11096,10 @@ const SwitchProngAnalysis = struct {
1115111096
11152 const operand_ty = sema.typeOf(spa.operand);11097 const operand_ty = sema.typeOf(spa.operand);
11153 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;11098 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
11156 if (inline_case_capture != .none) {11101 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;
11158 if (operand_ty.zigTypeTag(zcu) == .Union) {11103 if (operand_ty.zigTypeTag(zcu) == .Union) {
11159 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);11104 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
11160 const union_obj = zcu.typeToUnion(operand_ty).?;11105 const union_obj = zcu.typeToUnion(operand_ty).?;
...@@ -11195,7 +11140,7 @@ const SwitchProngAnalysis = struct {...@@ -11195,7 +11140,7 @@ const SwitchProngAnalysis = struct {
11195 .ErrorSet => if (spa.else_error_ty) |ty| {11140 .ErrorSet => if (spa.else_error_ty) |ty| {
11196 return sema.bitCast(block, ty, spa.operand, operand_src, null);11141 return sema.bitCast(block, ty, spa.operand, operand_src, null);
11197 } else {11142 } else {
11198 try block.addUnreachable(operand_src, false);11143 try sema.analyzeUnreachable(block, operand_src, false);
11199 return .unreachable_value;11144 return .unreachable_value;
11200 },11145 },
11201 else => return spa.operand,11146 else => return spa.operand,
...@@ -11205,14 +11150,14 @@ const SwitchProngAnalysis = struct {...@@ -11205,14 +11150,14 @@ const SwitchProngAnalysis = struct {
11205 switch (operand_ty.zigTypeTag(zcu)) {11150 switch (operand_ty.zigTypeTag(zcu)) {
11206 .Union => {11151 .Union => {
11207 const union_obj = zcu.typeToUnion(operand_ty).?;11152 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
11210 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;11155 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;
11211 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);11156 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1121211157
11213 const field_indices = try sema.arena.alloc(u32, case_vals.len);11158 const field_indices = try sema.arena.alloc(u32, case_vals.len);
11214 for (case_vals, field_indices) |item, *field_idx| {11159 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;
11216 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;11161 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;
11217 }11162 }
1121811163
...@@ -11232,27 +11177,22 @@ const SwitchProngAnalysis = struct {...@@ -11232,27 +11177,22 @@ const SwitchProngAnalysis = struct {
11232 }11177 }
1123311178
11234 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);11179 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11235 @memset(case_srcs, .unneeded);11180 for (case_srcs, 0..) |*case_src, i| {
1123611181 case_src.* = .{
11237 break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {11182 .base_node_inst = capture_src.base_node_inst,
11238 error.NeededSourceLocation => {11183 .offset = .{ .switch_case_item = .{
11239 // This must be a multi-prong so this must be a `multi_capture` src11184 .switch_node_offset = switch_node_offset,
11240 const multi_idx = raw_capture_src.multi_capture;11185 .case_idx = capture_src.offset.switch_capture.case_idx,
11241 const src_decl_ptr = zcu.declPtr(block.src_decl);11186 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11242 for (case_srcs, 0..) |*case_src, i| {11187 } },
11243 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };11188 };
11244 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11189 }
11245 }11190
11246 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11191 break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11247 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {11192 error.AnalysisFail => {
11248 error.AnalysisFail => {11193 const msg = sema.err orelse return error.AnalysisFail;
11249 const msg = sema.err orelse return error.AnalysisFail;11194 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11250 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});11195 return error.AnalysisFail;
11251 return error.AnalysisFail;
11252 },
11253 else => |e| return e,
11254 };
11255 unreachable;
11256 },11196 },
11257 else => |e| return e,11197 else => |e| return e,
11258 };11198 };
...@@ -11280,28 +11220,23 @@ const SwitchProngAnalysis = struct {...@@ -11280,28 +11220,23 @@ const SwitchProngAnalysis = struct {
11280 dummy.* = try zcu.undefRef(field_ptr_ty);11220 dummy.* = try zcu.undefRef(field_ptr_ty);
11281 }11221 }
11282 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);11222 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11283 @memset(case_srcs, .unneeded);11223 for (case_srcs, 0..) |*case_src, i| {
1128411224 case_src.* = .{
11285 break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {11225 .base_node_inst = capture_src.base_node_inst,
11286 error.NeededSourceLocation => {11226 .offset = .{ .switch_case_item = .{
11287 // This must be a multi-prong so this must be a `multi_capture` src11227 .switch_node_offset = switch_node_offset,
11288 const multi_idx = raw_capture_src.multi_capture;11228 .case_idx = capture_src.offset.switch_capture.case_idx,
11289 const src_decl_ptr = zcu.declPtr(block.src_decl);11229 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11290 for (case_srcs, 0..) |*case_src, i| {11230 } },
11291 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };11231 };
11292 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11232 }
11293 }11233
11294 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11234 break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11295 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {11235 error.AnalysisFail => {
11296 error.AnalysisFail => {11236 const msg = sema.err orelse return error.AnalysisFail;
11297 const msg = sema.err orelse return error.AnalysisFail;11237 try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{});
11298 try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{});11238 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11299 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});11239 return error.AnalysisFail;
11300 return error.AnalysisFail;
11301 },
11302 else => |e| return e,
11303 };
11304 unreachable;
11305 },11240 },
11306 else => |e| return e,11241 else => |e| return e,
11307 };11242 };
...@@ -11336,7 +11271,7 @@ const SwitchProngAnalysis = struct {...@@ -11336,7 +11271,7 @@ const SwitchProngAnalysis = struct {
11336 const first_non_imc = in_mem: {11271 const first_non_imc = in_mem: {
11337 for (field_indices, 0..) |field_idx, i| {11272 for (field_indices, 0..) |field_idx, i| {
11338 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11273 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)) {
11340 break :in_mem i;11275 break :in_mem i;
11341 }11276 }
11342 }11277 }
...@@ -11359,7 +11294,7 @@ const SwitchProngAnalysis = struct {...@@ -11359,7 +11294,7 @@ const SwitchProngAnalysis = struct {
11359 const next = first_non_imc + 1;11294 const next = first_non_imc + 1;
11360 for (field_indices[next..], next..) |field_idx, i| {11295 for (field_indices[next..], next..) |field_idx, i| {
11361 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11296 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)) {
11363 in_mem_coercible.unset(i);11298 in_mem_coercible.unset(i);
11364 }11299 }
11365 }11300 }
...@@ -11388,20 +11323,19 @@ const SwitchProngAnalysis = struct {...@@ -11388,20 +11323,19 @@ const SwitchProngAnalysis = struct {
11388 var coerce_block = block.makeSubBlock();11323 var coerce_block = block.makeSubBlock();
11389 defer coerce_block.instructions.deinit(sema.gpa);11324 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
11391 const field_idx = field_indices[idx];11335 const field_idx = field_indices[idx];
11392 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11336 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11393 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);11337 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) {11338 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
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 };
11405 _ = try coerce_block.addBr(capture_block_inst, coerced);11339 _ = try coerce_block.addBr(capture_block_inst, coerced);
1140611340
11407 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);11341 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
...@@ -11455,7 +11389,6 @@ const SwitchProngAnalysis = struct {...@@ -11455,7 +11389,6 @@ const SwitchProngAnalysis = struct {
11455 },11389 },
11456 .ErrorSet => {11390 .ErrorSet => {
11457 if (capture_byref) {11391 if (capture_byref) {
11458 const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none);
11459 return sema.fail(11392 return sema.fail(
11460 block,11393 block,
11461 capture_src,11394 capture_src,
...@@ -11465,7 +11398,7 @@ const SwitchProngAnalysis = struct {...@@ -11465,7 +11398,7 @@ const SwitchProngAnalysis = struct {
11465 }11398 }
1146611399
11467 if (case_vals.len == 1) {11400 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;
11469 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);11402 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);
11470 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);11403 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
11471 }11404 }
...@@ -11473,7 +11406,7 @@ const SwitchProngAnalysis = struct {...@@ -11473,7 +11406,7 @@ const SwitchProngAnalysis = struct {
11473 var names: InferredErrorSet.NameMap = .{};11406 var names: InferredErrorSet.NameMap = .{};
11474 try names.ensureUnusedCapacity(sema.arena, case_vals.len);11407 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
11475 for (case_vals) |err| {11408 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;
11477 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});11410 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});
11478 }11411 }
11479 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());11412 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());
...@@ -11527,10 +11460,10 @@ fn switchCond(...@@ -11527,10 +11460,10 @@ fn switchCond(
11527 try sema.resolveTypeFields(operand_ty);11460 try sema.resolveTypeFields(operand_ty);
11528 const enum_ty = operand_ty.unionTagType(mod) orelse {11461 const enum_ty = operand_ty.unionTagType(mod) orelse {
11529 const msg = msg: {11462 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", .{});
11531 errdefer msg.destroy(sema.gpa);11464 errdefer msg.destroy(sema.gpa);
11532 if (operand_ty.declSrcLocOrNull(mod)) |union_src| {11465 if (operand_ty.srcLocOrNull(mod)) |union_src| {
11533 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});11466 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
11534 }11467 }
11535 break :msg msg;11468 break :msg msg;
11536 };11469 };
...@@ -11554,7 +11487,7 @@ fn switchCond(...@@ -11554,7 +11487,7 @@ fn switchCond(
11554 }11487 }
11555}11488}
1155611489
11557const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);11490const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc);
1155811491
11559fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {11492fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
11560 const tracy = trace(@src());11493 const tracy = trace(@src());
...@@ -11563,13 +11496,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11563,13 +11496,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11563 const mod = sema.mod;11496 const mod = sema.mod;
11564 const gpa = sema.gpa;11497 const gpa = sema.gpa;
11565 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11498 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);
11567 const switch_src_node_offset = inst_data.src_node;11500 const switch_src_node_offset = inst_data.src_node;
11568 const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset };11501 const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset });
11569 const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset };11502 const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset });
11570 const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);11503 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 };11504 const main_operand_src = block.src(.{ .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 };11505 const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset });
1157311506
11574 const raw_operand_val = try sema.resolveInst(extra.data.operand);11507 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...@@ -11675,7 +11608,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11675 var child_block: Block = .{11608 var child_block: Block = .{
11676 .parent = block,11609 .parent = block,
11677 .sema = sema,11610 .sema = sema,
11678 .src_decl = block.src_decl,
11679 .namespace = block.namespace,11611 .namespace = block.namespace,
11680 .instructions = .{},11612 .instructions = .{},
11681 .label = &label,11613 .label = &label,
...@@ -11689,6 +11621,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11689,6 +11621,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11689 .runtime_index = block.runtime_index,11621 .runtime_index = block.runtime_index,
11690 .error_return_trace_index = block.error_return_trace_index,11622 .error_return_trace_index = block.error_return_trace_index,
11691 .want_safety = block.want_safety,11623 .want_safety = block.want_safety,
11624 .src_base_inst = block.src_base_inst,
11625 .type_name_ctx = block.type_name_ctx,
11692 };11626 };
11693 const merges = &child_block.label.?.merges;11627 const merges = &child_block.label.?.merges;
11694 defer child_block.instructions.deinit(gpa);11628 defer child_block.instructions.deinit(gpa);
...@@ -11755,6 +11689,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11755,6 +11689,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11755 try sema.switchCond(block, switch_operand_src, spa.operand),11689 try sema.switchCond(block, switch_operand_src, spa.operand),
11756 err_val,11690 err_val,
11757 operand_err_set_ty,11691 operand_err_set_ty,
11692 switch_src_node_offset,
11758 .{11693 .{
11759 .body = else_case.body,11694 .body = else_case.body,
11760 .end = else_case.end,11695 .end = else_case.end,
...@@ -11796,7 +11731,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11796,7 +11731,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1179611731
11797 var sub_block = child_block.makeSubBlock();11732 var sub_block = child_block.makeSubBlock();
11798 sub_block.runtime_loop = null;11733 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;
11800 sub_block.runtime_index.increment();11735 sub_block.runtime_index.increment();
11801 sub_block.need_debug_scope = null; // this body is emitted regardless11736 sub_block.need_debug_scope = null; // this body is emitted regardless
11802 defer sub_block.instructions.deinit(gpa);11737 defer sub_block.instructions.deinit(gpa);
...@@ -11871,10 +11806,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11871,10 +11806,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11871 const mod = sema.mod;11806 const mod = sema.mod;
11872 const gpa = sema.gpa;11807 const gpa = sema.gpa;
11873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11808 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);
11875 const src_node_offset = inst_data.src_node;11810 const src_node_offset = inst_data.src_node;
11876 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };11811 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
11877 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };11812 const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset });
11878 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);11813 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
1187911814
11880 const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: {11815 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...@@ -11941,7 +11876,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11941 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;11876 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
1194211877
11943 // Duplicate checking variables later also used for `inline else`.11878 // Duplicate checking variables later also used for `inline else`.
11944 var seen_enum_fields: []?Module.SwitchProngSrc = &.{};11879 var seen_enum_fields: []?LazySrcLoc = &.{};
11945 var seen_errors = SwitchErrorSet.init(gpa);11880 var seen_errors = SwitchErrorSet.init(gpa);
11946 var range_set = RangeSet.init(gpa, mod);11881 var range_set = RangeSet.init(gpa, mod);
11947 var true_count: u8 = 0;11882 var true_count: u8 = 0;
...@@ -11964,21 +11899,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11964,21 +11899,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11964 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {11899 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {
11965 const msg = msg: {11900 const msg = msg: {
11966 const msg = try sema.errMsg(11901 const msg = try sema.errMsg(
11967 block,
11968 src,11902 src,
11969 "'_' prong only allowed when switching on non-exhaustive enums",11903 "'_' prong only allowed when switching on non-exhaustive enums",
11970 .{},11904 .{},
11971 );11905 );
11972 errdefer msg.destroy(gpa);11906 errdefer msg.destroy(gpa);
11973 try sema.errNote(11907 try sema.errNote(
11974 block,
11975 special_prong_src,11908 special_prong_src,
11976 msg,11909 msg,
11977 "'_' prong here",11910 "'_' prong here",
11978 .{},11911 .{},
11979 );11912 );
11980 try sema.errNote(11913 try sema.errNote(
11981 block,
11982 src,11914 src,
11983 msg,11915 msg,
11984 "consider using 'else'",11916 "consider using 'else'",
...@@ -11993,7 +11925,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11993,7 +11925,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11993 switch (operand_ty.zigTypeTag(mod)) {11925 switch (operand_ty.zigTypeTag(mod)) {
11994 .Union => unreachable, // handled in `switchCond`11926 .Union => unreachable, // handled in `switchCond`
11995 .Enum => {11927 .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));
11997 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);11929 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);
11998 @memset(seen_enum_fields, null);11930 @memset(seen_enum_fields, null);
11999 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.11931 // `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...@@ -12013,8 +11945,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12013 &range_set,11945 &range_set,
12014 item_ref,11946 item_ref,
12015 operand_ty,11947 operand_ty,
12016 src_node_offset,11948 block.src(.{ .switch_case_item = .{
12017 .{ .scalar = scalar_i },11949 .switch_node_offset = src_node_offset,
11950 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
11951 .item_idx = .{ .kind = .single, .index = 0 },
11952 } }),
12018 ));11953 ));
12019 }11954 }
12020 }11955 }
...@@ -12038,8 +11973,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12038,8 +11973,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12038 &range_set,11973 &range_set,
12039 item_ref,11974 item_ref,
12040 operand_ty,11975 operand_ty,
12041 src_node_offset,11976 block.src(.{ .switch_case_item = .{
12042 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },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 } }),
12043 ));11981 ));
12044 }11982 }
1204511983
...@@ -12060,7 +11998,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12060,7 +11998,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12060 } else if (!all_tags_handled) {11998 } else if (!all_tags_handled) {
12061 const msg = msg: {11999 const msg = msg: {
12062 const msg = try sema.errMsg(12000 const msg = try sema.errMsg(
12063 block,
12064 src,12001 src,
12065 "switch must handle all possibilities",12002 "switch must handle all possibilities",
12066 .{},12003 .{},
...@@ -12078,8 +12015,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12078,8 +12015,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12078 .{field_name.fmt(&mod.intern_pool)},12015 .{field_name.fmt(&mod.intern_pool)},
12079 );12016 );
12080 }12017 }
12081 try mod.errNoteNonLazy(12018 try sema.errNote(
12082 operand_ty.declSrcLoc(mod),12019 operand_ty.srcLoc(mod),
12083 msg,12020 msg,
12084 "enum '{}' declared here",12021 "enum '{}' declared here",
12085 .{operand_ty.fmt(mod)},12022 .{operand_ty.fmt(mod)},
...@@ -12123,8 +12060,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12123,8 +12060,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12123 &range_set,12060 &range_set,
12124 item_ref,12061 item_ref,
12125 operand_ty,12062 operand_ty,
12126 src_node_offset,12063 block.src(.{ .switch_case_item = .{
12127 .{ .scalar = scalar_i },12064 .switch_node_offset = src_node_offset,
12065 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12066 .item_idx = .{ .kind = .single, .index = 0 },
12067 } }),
12128 ));12068 ));
12129 }12069 }
12130 }12070 }
...@@ -12147,8 +12087,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12147,8 +12087,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12147 &range_set,12087 &range_set,
12148 item_ref,12088 item_ref,
12149 operand_ty,12089 operand_ty,
12150 src_node_offset,12090 block.src(.{ .switch_case_item = .{
12151 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },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 } }),
12152 ));12095 ));
12153 }12096 }
1215412097
...@@ -12166,8 +12109,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12166,8 +12109,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12166 item_first,12109 item_first,
12167 item_last,12110 item_last,
12168 operand_ty,12111 operand_ty,
12169 src_node_offset,12112 block.src(.{ .switch_case_item = .{
12170 .{ .range = .{ .prong = multi_i, .item = range_i } },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 } }),
12171 );12117 );
12172 case_vals.appendAssumeCapacity(vals[0]);12118 case_vals.appendAssumeCapacity(vals[0]);
12173 case_vals.appendAssumeCapacity(vals[1]);12119 case_vals.appendAssumeCapacity(vals[1]);
...@@ -12218,8 +12164,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12218,8 +12164,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12218 &true_count,12164 &true_count,
12219 &false_count,12165 &false_count,
12220 item_ref,12166 item_ref,
12221 src_node_offset,12167 block.src(.{ .switch_case_item = .{
12222 .{ .scalar = scalar_i },12168 .switch_node_offset = src_node_offset,
12169 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12170 .item_idx = .{ .kind = .single, .index = 0 },
12171 } }),
12223 ));12172 ));
12224 }12173 }
12225 }12174 }
...@@ -12242,8 +12191,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12242,8 +12191,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12242 &true_count,12191 &true_count,
12243 &false_count,12192 &false_count,
12244 item_ref,12193 item_ref,
12245 src_node_offset,12194 block.src(.{ .switch_case_item = .{
12246 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },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 } }),
12247 ));12199 ));
12248 }12200 }
1224912201
...@@ -12301,8 +12253,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12301,8 +12253,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12301 &seen_values,12253 &seen_values,
12302 item_ref,12254 item_ref,
12303 operand_ty,12255 operand_ty,
12304 src_node_offset,12256 block.src(.{ .switch_case_item = .{
12305 .{ .scalar = scalar_i },12257 .switch_node_offset = src_node_offset,
12258 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12259 .item_idx = .{ .kind = .single, .index = 0 },
12260 } }),
12306 ));12261 ));
12307 }12262 }
12308 }12263 }
...@@ -12325,8 +12280,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12325,8 +12280,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12325 &seen_values,12280 &seen_values,
12326 item_ref,12281 item_ref,
12327 operand_ty,12282 operand_ty,
12328 src_node_offset,12283 block.src(.{ .switch_case_item = .{
12329 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },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 } }),
12330 ));12288 ));
12331 }12289 }
1233212290
...@@ -12382,7 +12340,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12382,7 +12340,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12382 var child_block: Block = .{12340 var child_block: Block = .{
12383 .parent = block,12341 .parent = block,
12384 .sema = sema,12342 .sema = sema,
12385 .src_decl = block.src_decl,
12386 .namespace = block.namespace,12343 .namespace = block.namespace,
12387 .instructions = .{},12344 .instructions = .{},
12388 .label = &label,12345 .label = &label,
...@@ -12396,6 +12353,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12396,6 +12353,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12396 .runtime_index = block.runtime_index,12353 .runtime_index = block.runtime_index,
12397 .want_safety = block.want_safety,12354 .want_safety = block.want_safety,
12398 .error_return_trace_index = block.error_return_trace_index,12355 .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,
12399 };12358 };
12400 const merges = &child_block.label.?.merges;12359 const merges = &child_block.label.?.merges;
12401 defer child_block.instructions.deinit(gpa);12360 defer child_block.instructions.deinit(gpa);
...@@ -12409,6 +12368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12409,6 +12368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12409 operand,12368 operand,
12410 operand_val,12369 operand_val,
12411 operand_ty,12370 operand_ty,
12371 src_node_offset,
12412 special,12372 special,
12413 case_vals,12373 case_vals,
12414 scalar_cases_len,12374 scalar_cases_len,
...@@ -12441,7 +12401,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12441,7 +12401,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12441 .special,12401 .special,
12442 special.body,12402 special.body,
12443 special.capture,12403 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 } }),
12445 undefined, // case_vals may be undefined for special prongs12408 undefined, // case_vals may be undefined for special prongs
12446 .none,12409 .none,
12447 false,12410 false,
...@@ -12508,9 +12471,9 @@ fn analyzeSwitchRuntimeBlock(...@@ -12508,9 +12471,9 @@ fn analyzeSwitchRuntimeBlock(
12508 union_originally: bool,12471 union_originally: bool,
12509 maybe_union_ty: Type,12472 maybe_union_ty: Type,
12510 err_set: bool,12473 err_set: bool,
12511 src_node_offset: i32,12474 switch_node_offset: i32,
12512 special_prong_src: LazySrcLoc,12475 special_prong_src: LazySrcLoc,
12513 seen_enum_fields: []?Module.SwitchProngSrc,12476 seen_enum_fields: []?LazySrcLoc,
12514 seen_errors: SwitchErrorSet,12477 seen_errors: SwitchErrorSet,
12515 range_set: RangeSet,12478 range_set: RangeSet,
12516 true_count: u8,12479 true_count: u8,
...@@ -12531,7 +12494,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12531,7 +12494,7 @@ fn analyzeSwitchRuntimeBlock(
1253112494
12532 var case_block = child_block.makeSubBlock();12495 var case_block = child_block.makeSubBlock();
12533 case_block.runtime_loop = null;12496 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;
12535 case_block.runtime_index.increment();12498 case_block.runtime_index.increment();
12536 case_block.need_debug_scope = null; // this body is emitted regardless12499 case_block.need_debug_scope = null; // this body is emitted regardless
12537 defer case_block.instructions.deinit(gpa);12500 defer case_block.instructions.deinit(gpa);
...@@ -12553,7 +12516,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12553,7 +12516,7 @@ fn analyzeSwitchRuntimeBlock(
12553 // `item` is already guaranteed to be constant known.12516 // `item` is already guaranteed to be constant known.
1255412517
12555 const analyze_body = if (union_originally) blk: {12518 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;
12557 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;12520 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
12558 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12521 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12559 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12522 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
...@@ -12567,7 +12530,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12567,7 +12530,10 @@ fn analyzeSwitchRuntimeBlock(
12567 .normal,12530 .normal,
12568 body,12531 body,
12569 info.capture,12532 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 } }),
12571 &.{item},12537 &.{item},
12572 if (info.is_inline) item else .none,12538 if (info.is_inline) item else .none,
12573 info.has_tag_capture,12539 info.has_tag_capture,
...@@ -12622,8 +12588,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12622,8 +12588,8 @@ fn analyzeSwitchRuntimeBlock(
12622 const item_first_ref = range_items[0];12588 const item_first_ref = range_items[0];
12623 const item_last_ref = range_items[1];12589 const item_last_ref = range_items[1];
1262412590
12625 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;12591 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
12626 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;12592 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;
1262712593
12628 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({12594 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
12629 // Previous validation has resolved any possible lazy values.12595 // Previous validation has resolved any possible lazy values.
...@@ -12639,17 +12605,11 @@ fn analyzeSwitchRuntimeBlock(...@@ -12639,17 +12605,11 @@ fn analyzeSwitchRuntimeBlock(
12639 case_block.instructions.shrinkRetainingCapacity(0);12605 case_block.instructions.shrinkRetainingCapacity(0);
12640 case_block.error_return_trace_index = child_block.error_return_trace_index;12606 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) {12608 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12643 error.NeededSourceLocation => {12609 .switch_node_offset = switch_node_offset,
12644 const case_src = Module.SwitchProngSrc{12610 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12645 .range = .{ .prong = multi_i, .item = range_i },12611 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12646 };12612 } }));
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 };
12653 emit_bb = true;12613 emit_bb = true;
1265412614
12655 try spa.analyzeProngRuntime(12615 try spa.analyzeProngRuntime(
...@@ -12657,7 +12617,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12657,7 +12617,10 @@ fn analyzeSwitchRuntimeBlock(
12657 .normal,12617 .normal,
12658 body,12618 body,
12659 info.capture,12619 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 } }),
12661 undefined, // case_vals may be undefined for ranges12624 undefined, // case_vals may be undefined for ranges
12662 item_ref,12625 item_ref,
12663 info.has_tag_capture,12626 info.has_tag_capture,
...@@ -12680,22 +12643,16 @@ fn analyzeSwitchRuntimeBlock(...@@ -12680,22 +12643,16 @@ fn analyzeSwitchRuntimeBlock(
12680 case_block.error_return_trace_index = child_block.error_return_trace_index;12643 case_block.error_return_trace_index = child_block.error_return_trace_index;
1268112644
12682 const analyze_body = if (union_originally) blk: {12645 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;
12684 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12647 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12685 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12648 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
12686 } else true;12649 } else true;
1268712650
12688 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {12651 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12689 error.NeededSourceLocation => {12652 .switch_node_offset = switch_node_offset,
12690 const case_src = Module.SwitchProngSrc{12653 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12691 .multi = .{ .prong = multi_i, .item = @intCast(item_i) },12654 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12692 };12655 } }));
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 };
12699 emit_bb = true;12656 emit_bb = true;
1270012657
12701 if (analyze_body) {12658 if (analyze_body) {
...@@ -12704,7 +12661,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12704,7 +12661,10 @@ fn analyzeSwitchRuntimeBlock(
12704 .normal,12661 .normal,
12705 body,12662 body,
12706 info.capture,12663 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 } }),
12708 &.{item},12668 &.{item},
12709 item,12669 item,
12710 info.has_tag_capture,12670 info.has_tag_capture,
...@@ -12734,7 +12694,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12734,7 +12694,7 @@ fn analyzeSwitchRuntimeBlock(
1273412694
12735 const analyze_body = if (union_originally)12695 const analyze_body = if (union_originally)
12736 for (items) |item| {12696 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;
12738 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12698 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12739 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;12699 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
12740 } else false12700 } else false
...@@ -12751,7 +12711,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12751,7 +12711,10 @@ fn analyzeSwitchRuntimeBlock(
12751 .normal,12711 .normal,
12752 body,12712 body,
12753 info.capture,12713 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 } }),
12755 items,12718 items,
12756 .none,12719 .none,
12757 false,12720 false,
...@@ -12835,7 +12798,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12835,7 +12798,10 @@ fn analyzeSwitchRuntimeBlock(
12835 .normal,12798 .normal,
12836 body,12799 body,
12837 info.capture,12800 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 } }),
12839 items,12805 items,
12840 .none,12806 .none,
12841 false,12807 false,
...@@ -12900,7 +12866,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12900,7 +12866,10 @@ fn analyzeSwitchRuntimeBlock(
12900 .special,12866 .special,
12901 special.body,12867 special.body,
12902 special.capture,12868 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 } }),
12904 &.{item_ref},12873 &.{item_ref},
12905 item_ref,12874 item_ref,
12906 special.has_tag_capture,12875 special.has_tag_capture,
...@@ -12945,7 +12914,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12945,7 +12914,10 @@ fn analyzeSwitchRuntimeBlock(
12945 .special,12914 .special,
12946 special.body,12915 special.body,
12947 special.capture,12916 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 } }),
12949 &.{item_ref},12921 &.{item_ref},
12950 item_ref,12922 item_ref,
12951 special.has_tag_capture,12923 special.has_tag_capture,
...@@ -12976,7 +12948,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12976,7 +12948,10 @@ fn analyzeSwitchRuntimeBlock(
12976 .special,12948 .special,
12977 special.body,12949 special.body,
12978 special.capture,12950 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 } }),
12980 &.{item_ref},12955 &.{item_ref},
12981 item_ref,12956 item_ref,
12982 special.has_tag_capture,12957 special.has_tag_capture,
...@@ -13004,7 +12979,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13004,7 +12979,10 @@ fn analyzeSwitchRuntimeBlock(
13004 .special,12979 .special,
13005 special.body,12980 special.body,
13006 special.capture,12981 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 } }),
13008 &.{.bool_true},12986 &.{.bool_true},
13009 .bool_true,12987 .bool_true,
13010 special.has_tag_capture,12988 special.has_tag_capture,
...@@ -13030,7 +13008,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13030,7 +13008,10 @@ fn analyzeSwitchRuntimeBlock(
13030 .special,13008 .special,
13031 special.body,13009 special.body,
13032 special.capture,13010 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 } }),
13034 &.{.bool_false},13015 &.{.bool_false},
13035 .bool_false,13016 .bool_false,
13036 special.has_tag_capture,13017 special.has_tag_capture,
...@@ -13080,7 +13061,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13080,7 +13061,10 @@ fn analyzeSwitchRuntimeBlock(
13080 .special,13061 .special,
13081 special.body,13062 special.body,
13082 special.capture,13063 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 } }),
13084 undefined, // case_vals may be undefined for special prongs13068 undefined, // case_vals may be undefined for special prongs
13085 .none,13069 .none,
13086 false,13070 false,
...@@ -13140,6 +13124,7 @@ fn resolveSwitchComptime(...@@ -13140,6 +13124,7 @@ fn resolveSwitchComptime(
13140 cond_operand: Air.Inst.Ref,13124 cond_operand: Air.Inst.Ref,
13141 operand_val: Value,13125 operand_val: Value,
13142 operand_ty: Type,13126 operand_ty: Type,
13127 switch_node_offset: i32,
13143 special: SpecialProng,13128 special: SpecialProng,
13144 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),13129 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),
13145 scalar_cases_len: u32,13130 scalar_cases_len: u32,
...@@ -13160,7 +13145,7 @@ fn resolveSwitchComptime(...@@ -13160,7 +13145,7 @@ fn resolveSwitchComptime(
13160 extra_index += info.body_len;13145 extra_index += info.body_len;
1316113146
13162 const item = case_vals.items[scalar_i];13147 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;
13164 if (operand_val.eql(item_val, operand_ty, sema.mod)) {13149 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
13165 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);13150 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
13166 return spa.resolveProngComptime(13151 return spa.resolveProngComptime(
...@@ -13168,7 +13153,10 @@ fn resolveSwitchComptime(...@@ -13168,7 +13153,10 @@ fn resolveSwitchComptime(
13168 .normal,13153 .normal,
13169 body,13154 body,
13170 info.capture,13155 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 } }),
13172 &.{item},13160 &.{item},
13173 if (info.is_inline) cond_operand else .none,13161 if (info.is_inline) cond_operand else .none,
13174 info.has_tag_capture,13162 info.has_tag_capture,
...@@ -13194,7 +13182,7 @@ fn resolveSwitchComptime(...@@ -13194,7 +13182,7 @@ fn resolveSwitchComptime(
1319413182
13195 for (items) |item| {13183 for (items) |item| {
13196 // Validation above ensured these will succeed.13184 // 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;
13198 if (operand_val.eql(item_val, operand_ty, sema.mod)) {13186 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
13199 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);13187 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
13200 return spa.resolveProngComptime(13188 return spa.resolveProngComptime(
...@@ -13202,7 +13190,10 @@ fn resolveSwitchComptime(...@@ -13202,7 +13190,10 @@ fn resolveSwitchComptime(
13202 .normal,13190 .normal,
13203 body,13191 body,
13204 info.capture,13192 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 } }),
13206 items,13197 items,
13207 if (info.is_inline) cond_operand else .none,13198 if (info.is_inline) cond_operand else .none,
13208 info.has_tag_capture,13199 info.has_tag_capture,
...@@ -13218,8 +13209,8 @@ fn resolveSwitchComptime(...@@ -13218,8 +13209,8 @@ fn resolveSwitchComptime(
13218 case_val_idx += 2;13209 case_val_idx += 2;
1321913210
13220 // Validation above ensured these will succeed.13211 // Validation above ensured these will succeed.
13221 const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable;13212 const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable;
13222 const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable;13213 const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable;
13223 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and13214 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
13224 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))13215 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
13225 {13216 {
...@@ -13229,7 +13220,10 @@ fn resolveSwitchComptime(...@@ -13229,7 +13220,10 @@ fn resolveSwitchComptime(
13229 .normal,13220 .normal,
13230 body,13221 body,
13231 info.capture,13222 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 } }),
13233 undefined, // case_vals may be undefined for ranges13227 undefined, // case_vals may be undefined for ranges
13234 if (info.is_inline) cond_operand else .none,13228 if (info.is_inline) cond_operand else .none,
13235 info.has_tag_capture,13229 info.has_tag_capture,
...@@ -13251,7 +13245,10 @@ fn resolveSwitchComptime(...@@ -13251,7 +13245,10 @@ fn resolveSwitchComptime(
13251 .special,13245 .special,
13252 special.body,13246 special.body,
13253 special.capture,13247 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 } }),
13255 undefined, // case_vals may be undefined for special prongs13252 undefined, // case_vals may be undefined for special prongs
13256 if (special.is_inline) cond_operand else .none,13253 if (special.is_inline) cond_operand else .none,
13257 special.has_tag_capture,13254 special.has_tag_capture,
...@@ -13337,36 +13334,19 @@ fn resolveSwitchItemVal(...@@ -13337,36 +13334,19 @@ fn resolveSwitchItemVal(
13337 item_ref: Zir.Inst.Ref,13334 item_ref: Zir.Inst.Ref,
13338 /// Coerce `item_ref` to this type.13335 /// Coerce `item_ref` to this type.
13339 coerce_ty: Type,13336 coerce_ty: Type,
13340 switch_node_offset: i32,13337 item_src: LazySrcLoc,
13341 switch_prong_src: Module.SwitchProngSrc,
13342 range_expand: Module.SwitchProngSrc.RangeExpand,
13343) CompileError!ResolvedSwitchItem {13338) CompileError!ResolvedSwitchItem {
13344 const mod = sema.mod;
13345 const uncoerced_item = try sema.resolveInst(item_ref);13339 const uncoerced_item = try sema.resolveInst(item_ref);
1334613340
13347 // Constructing a LazySrcLoc is costly because we only have the switch AST node.13341 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
13348 // Only if we know for sure we need to report a compile error do we resolve the13342 // Only if we know for sure we need to report a compile error do we resolve the
13349 // full source locations.13343 // full source locations.
1335013344
13351 const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) {13345 const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src);
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 };
1335913346
13360 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {13347 const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{
13361 error.NeededSourceLocation => {13348 .needed_comptime_reason = "switch prong values must be comptime-known",
13362 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);13349 });
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 };
1337013350
13371 const val = try sema.resolveLazyValue(maybe_lazy);13351 const val = try sema.resolveLazyValue(maybe_lazy);
13372 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {13352 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {
...@@ -13393,7 +13373,7 @@ fn validateErrSetSwitch(...@@ -13393,7 +13373,7 @@ fn validateErrSetSwitch(
13393 const ip = &mod.intern_pool;13373 const ip = &mod.intern_pool;
1339413374
13395 const src_node_offset = inst_data.src_node;13375 const src_node_offset = inst_data.src_node;
13396 const src = inst_data.src();13376 const src = block.nodeOffset(src_node_offset);
1339713377
13398 var extra_index: usize = else_case.end;13378 var extra_index: usize = else_case.end;
13399 {13379 {
...@@ -13409,8 +13389,11 @@ fn validateErrSetSwitch(...@@ -13409,8 +13389,11 @@ fn validateErrSetSwitch(
13409 seen_errors,13389 seen_errors,
13410 item_ref,13390 item_ref,
13411 operand_ty,13391 operand_ty,
13412 src_node_offset,13392 block.src(.{ .switch_case_item = .{
13413 .{ .scalar = scalar_i },13393 .switch_node_offset = src_node_offset,
13394 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13395 .item_idx = .{ .kind = .single, .index = 0 },
13396 } }),
13414 ));13397 ));
13415 }13398 }
13416 }13399 }
...@@ -13433,8 +13416,11 @@ fn validateErrSetSwitch(...@@ -13433,8 +13416,11 @@ fn validateErrSetSwitch(
13433 seen_errors,13416 seen_errors,
13434 item_ref,13417 item_ref,
13435 operand_ty,13418 operand_ty,
13436 src_node_offset,13419 block.src(.{ .switch_case_item = .{
13437 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },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 } }),
13438 ));13424 ));
13439 }13425 }
1344013426
...@@ -13463,7 +13449,6 @@ fn validateErrSetSwitch(...@@ -13463,7 +13449,6 @@ fn validateErrSetSwitch(
13463 if (!seen_errors.contains(error_name) and !has_else) {13449 if (!seen_errors.contains(error_name) and !has_else) {
13464 const msg = maybe_msg orelse blk: {13450 const msg = maybe_msg orelse blk: {
13465 maybe_msg = try sema.errMsg(13451 maybe_msg = try sema.errMsg(
13466 block,
13467 src,13452 src,
13468 "switch must handle all possibilities",13453 "switch must handle all possibilities",
13469 .{},13454 .{},
...@@ -13472,7 +13457,6 @@ fn validateErrSetSwitch(...@@ -13472,7 +13457,6 @@ fn validateErrSetSwitch(
13472 };13457 };
1347313458
13474 try sema.errNote(13459 try sema.errNote(
13475 block,
13476 src,13460 src,
13477 msg,13461 msg,
13478 "unhandled error value: 'error.{}'",13462 "unhandled error value: 'error.{}'",
...@@ -13550,18 +13534,24 @@ fn validateSwitchRange(...@@ -13550,18 +13534,24 @@ fn validateSwitchRange(
13550 first_ref: Zir.Inst.Ref,13534 first_ref: Zir.Inst.Ref,
13551 last_ref: Zir.Inst.Ref,13535 last_ref: Zir.Inst.Ref,
13552 operand_ty: Type,13536 operand_ty: Type,
13553 src_node_offset: i32,13537 item_src: LazySrcLoc,
13554 switch_prong_src: Module.SwitchProngSrc,
13555) CompileError![2]Air.Inst.Ref {13538) CompileError![2]Air.Inst.Ref {
13556 const mod = sema.mod;13539 const mod = sema.mod;
13557 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);13540 const first_src: LazySrcLoc = .{
13558 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);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);
13559 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {13550 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);13551 return sema.fail(block, item_src, "range start value is greater than the end value", .{});
13561 return sema.fail(block, src, "range start value is greater than the end value", .{});
13562 }13552 }
13563 const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src);13553 const maybe_prev_src = try range_set.add(first.val, last.val, item_src);
13564 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13554 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13565 return .{ first.ref, last.ref };13555 return .{ first.ref, last.ref };
13566}13556}
1356713557
...@@ -13571,36 +13561,34 @@ fn validateSwitchItemInt(...@@ -13571,36 +13561,34 @@ fn validateSwitchItemInt(
13571 range_set: *RangeSet,13561 range_set: *RangeSet,
13572 item_ref: Zir.Inst.Ref,13562 item_ref: Zir.Inst.Ref,
13573 operand_ty: Type,13563 operand_ty: Type,
13574 src_node_offset: i32,13564 item_src: LazySrcLoc,
13575 switch_prong_src: Module.SwitchProngSrc,
13576) CompileError!Air.Inst.Ref {13565) CompileError!Air.Inst.Ref {
13577 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13566 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13578 const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src);13567 const maybe_prev_src = try range_set.add(item.val, item.val, item_src);
13579 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13568 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13580 return item.ref;13569 return item.ref;
13581}13570}
1358213571
13583fn validateSwitchItemEnum(13572fn validateSwitchItemEnum(
13584 sema: *Sema,13573 sema: *Sema,
13585 block: *Block,13574 block: *Block,
13586 seen_fields: []?Module.SwitchProngSrc,13575 seen_fields: []?LazySrcLoc,
13587 range_set: *RangeSet,13576 range_set: *RangeSet,
13588 item_ref: Zir.Inst.Ref,13577 item_ref: Zir.Inst.Ref,
13589 operand_ty: Type,13578 operand_ty: Type,
13590 src_node_offset: i32,13579 item_src: LazySrcLoc,
13591 switch_prong_src: Module.SwitchProngSrc,
13592) CompileError!Air.Inst.Ref {13580) CompileError!Air.Inst.Ref {
13593 const ip = &sema.mod.intern_pool;13581 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);
13595 const int = ip.indexToKey(item.val).enum_tag.int;13583 const int = ip.indexToKey(item.val).enum_tag.int;
13596 const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse {13584 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);13585 const maybe_prev_src = try range_set.add(int, int, item_src);
13598 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13586 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13599 return item.ref;13587 return item.ref;
13600 };13588 };
13601 const maybe_prev_src = seen_fields[field_index];13589 const maybe_prev_src = seen_fields[field_index];
13602 seen_fields[field_index] = switch_prong_src;13590 seen_fields[field_index] = item_src;
13603 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13591 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13604 return item.ref;13592 return item.ref;
13605}13593}
1360613594
...@@ -13610,50 +13598,41 @@ fn validateSwitchItemError(...@@ -13610,50 +13598,41 @@ fn validateSwitchItemError(
13610 seen_errors: *SwitchErrorSet,13598 seen_errors: *SwitchErrorSet,
13611 item_ref: Zir.Inst.Ref,13599 item_ref: Zir.Inst.Ref,
13612 operand_ty: Type,13600 operand_ty: Type,
13613 src_node_offset: i32,13601 item_src: LazySrcLoc,
13614 switch_prong_src: Module.SwitchProngSrc,
13615) CompileError!Air.Inst.Ref {13602) CompileError!Air.Inst.Ref {
13616 const ip = &sema.mod.intern_pool;13603 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);
13618 const error_name = ip.indexToKey(item.val).err.name;13605 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|
13620 prev.value13607 prev.value
13621 else13608 else
13622 null;13609 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);
13624 return item.ref;13611 return item.ref;
13625}13612}
1362613613
13627fn validateSwitchDupe(13614fn validateSwitchDupe(
13628 sema: *Sema,13615 sema: *Sema,
13629 block: *Block,13616 block: *Block,
13630 maybe_prev_src: ?Module.SwitchProngSrc,13617 maybe_prev_src: ?LazySrcLoc,
13631 switch_prong_src: Module.SwitchProngSrc,13618 item_src: LazySrcLoc,
13632 src_node_offset: i32,
13633) CompileError!void {13619) CompileError!void {
13634 const prev_prong_src = maybe_prev_src orelse return;13620 const prev_item_src = maybe_prev_src orelse return;
13635 const mod = sema.mod;13621 return sema.failWithOwnedErrorMsg(block, msg: {
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: {
13640 const msg = try sema.errMsg(13622 const msg = try sema.errMsg(
13641 block,13623 item_src,
13642 src,
13643 "duplicate switch value",13624 "duplicate switch value",
13644 .{},13625 .{},
13645 );13626 );
13646 errdefer msg.destroy(sema.gpa);13627 errdefer msg.destroy(sema.gpa);
13647 try sema.errNote(13628 try sema.errNote(
13648 block,13629 prev_item_src,
13649 prev_src,
13650 msg,13630 msg,
13651 "previous value here",13631 "previous value here",
13652 .{},13632 .{},
13653 );13633 );
13654 break :msg msg;13634 break :msg msg;
13655 };13635 });
13656 return sema.failWithOwnedErrorMsg(block, msg);
13657}13636}
1365813637
13659fn validateSwitchItemBool(13638fn validateSwitchItemBool(
...@@ -13662,25 +13641,21 @@ fn validateSwitchItemBool(...@@ -13662,25 +13641,21 @@ fn validateSwitchItemBool(
13662 true_count: *u8,13641 true_count: *u8,
13663 false_count: *u8,13642 false_count: *u8,
13664 item_ref: Zir.Inst.Ref,13643 item_ref: Zir.Inst.Ref,
13665 src_node_offset: i32,13644 item_src: LazySrcLoc,
13666 switch_prong_src: Module.SwitchProngSrc,
13667) CompileError!Air.Inst.Ref {13645) CompileError!Air.Inst.Ref {
13668 const mod = sema.mod;13646 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src);
13669 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);
13670 if (Value.fromInterned(item.val).toBool()) {13647 if (Value.fromInterned(item.val).toBool()) {
13671 true_count.* += 1;13648 true_count.* += 1;
13672 } else {13649 } else {
13673 false_count.* += 1;13650 false_count.* += 1;
13674 }13651 }
13675 if (true_count.* > 1 or false_count.* > 1) {13652 if (true_count.* > 1 or false_count.* > 1) {
13676 const block_src_decl = sema.mod.declPtr(block.src_decl);13653 return sema.fail(block, item_src, "duplicate switch value", .{});
13677 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13678 return sema.fail(block, src, "duplicate switch value", .{});
13679 }13654 }
13680 return item.ref;13655 return item.ref;
13681}13656}
1368213657
13683const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc);13658const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc);
1368413659
13685fn validateSwitchItemSparse(13660fn validateSwitchItemSparse(
13686 sema: *Sema,13661 sema: *Sema,
...@@ -13688,12 +13663,11 @@ fn validateSwitchItemSparse(...@@ -13688,12 +13663,11 @@ fn validateSwitchItemSparse(
13688 seen_values: *ValueSrcMap,13663 seen_values: *ValueSrcMap,
13689 item_ref: Zir.Inst.Ref,13664 item_ref: Zir.Inst.Ref,
13690 operand_ty: Type,13665 operand_ty: Type,
13691 src_node_offset: i32,13666 item_src: LazySrcLoc,
13692 switch_prong_src: Module.SwitchProngSrc,
13693) CompileError!Air.Inst.Ref {13667) CompileError!Air.Inst.Ref {
13694 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13668 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13695 const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref;13669 const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref;
13696 try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset);13670 try sema.validateSwitchDupe(block, kv.value, item_src);
13697 unreachable;13671 unreachable;
13698}13672}
1369913673
...@@ -13707,19 +13681,17 @@ fn validateSwitchNoRange(...@@ -13707,19 +13681,17 @@ fn validateSwitchNoRange(
13707 if (ranges_len == 0)13681 if (ranges_len == 0)
13708 return;13682 return;
1370913683
13710 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };13684 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
13711 const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset };13685 const range_src = block.src(.{ .node_offset_switch_range = src_node_offset });
1371213686
13713 const msg = msg: {13687 const msg = msg: {
13714 const msg = try sema.errMsg(13688 const msg = try sema.errMsg(
13715 block,
13716 operand_src,13689 operand_src,
13717 "ranges not allowed when switching on type '{}'",13690 "ranges not allowed when switching on type '{}'",
13718 .{operand_ty.fmt(sema.mod)},13691 .{operand_ty.fmt(sema.mod)},
13719 );13692 );
13720 errdefer msg.destroy(sema.gpa);13693 errdefer msg.destroy(sema.gpa);
13721 try sema.errNote(13694 try sema.errNote(
13722 block,
13723 range_src,13695 range_src,
13724 msg,13696 msg,
13725 "range here",13697 "range here",
...@@ -13833,7 +13805,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I...@@ -13833,7 +13805,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
13833 }13805 }
13834 } else return;13806 } else return;
13835 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";13807 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
13838 if (try sema.resolveDefinedValue(block, src, operand)) |val| {13810 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
13839 if (val.getErrorName(sema.mod).unwrap()) |name| {13811 if (val.getErrorName(sema.mod).unwrap()) |name| {
...@@ -13846,8 +13818,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13846,8 +13818,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13846 const mod = sema.mod;13818 const mod = sema.mod;
13847 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13819 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13848 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13820 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 };13821 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13850 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };13822 const name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
13851 const ty = try sema.resolveType(block, ty_src, extra.lhs);13823 const ty = try sema.resolveType(block, ty_src, extra.lhs);
13852 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{13824 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
13853 .needed_comptime_reason = "field name must be comptime-known",13825 .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...@@ -13897,9 +13869,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13897 const mod = sema.mod;13869 const mod = sema.mod;
13898 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13870 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13899 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13871 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13900 const src = inst_data.src();13872 const src = block.nodeOffset(inst_data.src_node);
13901 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13873 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13902 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };13874 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
13903 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);13875 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
13904 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{13876 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
13905 .needed_comptime_reason = "decl name must be comptime-known",13877 .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....@@ -13929,7 +13901,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1392913901
13930 const mod = sema.mod;13902 const mod = sema.mod;
13931 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;13903 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);
13933 const operand = inst_data.get(sema.code);13905 const operand = inst_data.get(sema.code);
1393413906
13935 const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) {13907 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...@@ -13958,7 +13930,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1395813930
13959 const mod = sema.mod;13931 const mod = sema.mod;
13960 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;13932 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);
13962 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{13934 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
13963 .needed_comptime_reason = "file path name must be comptime-known",13935 .needed_comptime_reason = "file path name must be comptime-known",
13964 });13936 });
...@@ -13967,8 +13939,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13967,8 +13939,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13967 return sema.fail(block, operand_src, "file path name cannot be empty", .{});13939 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
13968 }13940 }
1396913941
13970 const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod);13942 const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) {
13971 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
13972 error.ImportOutsideModulePath => {13943 error.ImportOutsideModulePath => {
13973 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});13944 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
13974 },13945 },
...@@ -14009,9 +13980,9 @@ fn zirShl(...@@ -14009,9 +13980,9 @@ fn zirShl(
1400913980
14010 const mod = sema.mod;13981 const mod = sema.mod;
14011 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13982 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14012 const src = inst_data.src();13983 const src = block.nodeOffset(inst_data.src_node);
14013 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };13984 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14014 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };13985 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14015 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13986 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14016 const lhs = try sema.resolveInst(extra.lhs);13987 const lhs = try sema.resolveInst(extra.lhs);
14017 const rhs = try sema.resolveInst(extra.rhs);13988 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14179,9 +14150,9 @@ fn zirShr(...@@ -14179,9 +14150,9 @@ fn zirShr(
1417914150
14180 const mod = sema.mod;14151 const mod = sema.mod;
14181 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14152 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14182 const src = inst_data.src();14153 const src = block.nodeOffset(inst_data.src_node);
14183 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14154 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14184 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14155 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14185 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14156 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14186 const lhs = try sema.resolveInst(extra.lhs);14157 const lhs = try sema.resolveInst(extra.lhs);
14187 const rhs = try sema.resolveInst(extra.rhs);14158 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14314,9 +14285,9 @@ fn zirBitwise(...@@ -14314,9 +14285,9 @@ fn zirBitwise(
1431414285
14315 const mod = sema.mod;14286 const mod = sema.mod;
14316 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14287 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14317 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };14288 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
14318 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14289 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14319 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14290 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14320 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14291 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14321 const lhs = try sema.resolveInst(extra.lhs);14292 const lhs = try sema.resolveInst(extra.lhs);
14322 const rhs = try sema.resolveInst(extra.rhs);14293 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14368,8 +14339,8 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -14368,8 +14339,8 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1436814339
14369 const mod = sema.mod;14340 const mod = sema.mod;
14370 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;14341 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
14371 const src = inst_data.src();14342 const src = block.nodeOffset(inst_data.src_node);
14372 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };14343 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1437314344
14374 const operand = try sema.resolveInst(inst_data.operand);14345 const operand = try sema.resolveInst(inst_data.operand);
14375 const operand_type = sema.typeOf(operand);14346 const operand_type = sema.typeOf(operand);
...@@ -14415,7 +14386,7 @@ fn analyzeTupleCat(...@@ -14415,7 +14386,7 @@ fn analyzeTupleCat(
14415 const mod = sema.mod;14386 const mod = sema.mod;
14416 const lhs_ty = sema.typeOf(lhs);14387 const lhs_ty = sema.typeOf(lhs);
14417 const rhs_ty = sema.typeOf(rhs);14388 const rhs_ty = sema.typeOf(rhs);
14418 const src = LazySrcLoc.nodeOffset(src_node);14389 const src = block.nodeOffset(src_node);
1441914390
14420 const lhs_len = lhs_ty.structFieldCount(mod);14391 const lhs_len = lhs_ty.structFieldCount(mod);
14421 const rhs_len = rhs_ty.structFieldCount(mod);14392 const rhs_len = rhs_ty.structFieldCount(mod);
...@@ -14442,10 +14413,10 @@ fn analyzeTupleCat(...@@ -14442,10 +14413,10 @@ fn analyzeTupleCat(
14442 types[i] = lhs_ty.structFieldType(i, mod).toIntern();14413 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
14443 const default_val = lhs_ty.structFieldDefaultValue(i, mod);14414 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
14444 values[i] = default_val.toIntern();14415 values[i] = default_val.toIntern();
14445 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14416 const operand_src = block.src(.{ .array_cat_lhs = .{
14446 .array_cat_offset = src_node,14417 .array_cat_offset = src_node,
14447 .elem_index = i,14418 .elem_index = i,
14448 } };14419 } });
14449 if (default_val.toIntern() == .unreachable_value) {14420 if (default_val.toIntern() == .unreachable_value) {
14450 runtime_src = operand_src;14421 runtime_src = operand_src;
14451 values[i] = .none;14422 values[i] = .none;
...@@ -14456,10 +14427,10 @@ fn analyzeTupleCat(...@@ -14456,10 +14427,10 @@ fn analyzeTupleCat(
14456 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();14427 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
14457 const default_val = rhs_ty.structFieldDefaultValue(i, mod);14428 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
14458 values[i + lhs_len] = default_val.toIntern();14429 values[i + lhs_len] = default_val.toIntern();
14459 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14430 const operand_src = block.src(.{ .array_cat_rhs = .{
14460 .array_cat_offset = src_node,14431 .array_cat_offset = src_node,
14461 .elem_index = i,14432 .elem_index = i,
14462 } };14433 } });
14463 if (default_val.toIntern() == .unreachable_value) {14434 if (default_val.toIntern() == .unreachable_value) {
14464 runtime_src = operand_src;14435 runtime_src = operand_src;
14465 values[i + lhs_len] = .none;14436 values[i + lhs_len] = .none;
...@@ -14487,18 +14458,18 @@ fn analyzeTupleCat(...@@ -14487,18 +14458,18 @@ fn analyzeTupleCat(
14487 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);14458 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
14488 var i: u32 = 0;14459 var i: u32 = 0;
14489 while (i < lhs_len) : (i += 1) {14460 while (i < lhs_len) : (i += 1) {
14490 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14461 const operand_src = block.src(.{ .array_cat_lhs = .{
14491 .array_cat_offset = src_node,14462 .array_cat_offset = src_node,
14492 .elem_index = i,14463 .elem_index = i,
14493 } };14464 } });
14494 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);14465 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);
14495 }14466 }
14496 i = 0;14467 i = 0;
14497 while (i < rhs_len) : (i += 1) {14468 while (i < rhs_len) : (i += 1) {
14498 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14469 const operand_src = block.src(.{ .array_cat_rhs = .{
14499 .array_cat_offset = src_node,14470 .array_cat_offset = src_node,
14500 .elem_index = i,14471 .elem_index = i,
14501 } };14472 } });
14502 element_refs[i + lhs_len] =14473 element_refs[i + lhs_len] =
14503 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);14474 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
14504 }14475 }
...@@ -14517,7 +14488,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14517,7 +14488,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14517 const rhs = try sema.resolveInst(extra.rhs);14488 const rhs = try sema.resolveInst(extra.rhs);
14518 const lhs_ty = sema.typeOf(lhs);14489 const lhs_ty = sema.typeOf(lhs);
14519 const rhs_ty = sema.typeOf(rhs);14490 const rhs_ty = sema.typeOf(rhs);
14520 const src = inst_data.src();14491 const src = block.nodeOffset(inst_data.src_node);
1452114492
14522 const lhs_is_tuple = lhs_ty.isTuple(mod);14493 const lhs_is_tuple = lhs_ty.isTuple(mod);
14523 const rhs_is_tuple = rhs_ty.isTuple(mod);14494 const rhs_is_tuple = rhs_ty.isTuple(mod);
...@@ -14525,8 +14496,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14525,8 +14496,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14525 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);14496 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
14526 }14497 }
1452714498
14528 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14499 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14529 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14500 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1453014501
14531 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {14502 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
14532 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);14503 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...@@ -14638,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14638 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";14609 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
14639 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;14610 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
14640 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14611 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 = .{
14642 .array_cat_offset = inst_data.src_node,14613 .array_cat_offset = inst_data.src_node,
14643 .elem_index = elem_i,14614 .elem_index = elem_i,
14644 } };14615 } });
14645 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);14616 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
14646 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);14617 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
14647 element_vals[elem_i] = coerced_elem_val.toIntern();14618 element_vals[elem_i] = coerced_elem_val.toIntern();
...@@ -14651,10 +14622,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14651,10 +14622,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14651 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";14622 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
14652 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;14623 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
14653 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14624 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 = .{
14655 .array_cat_offset = inst_data.src_node,14626 .array_cat_offset = inst_data.src_node,
14656 .elem_index = @intCast(rhs_elem_i),14627 .elem_index = @intCast(rhs_elem_i),
14657 } };14628 } });
14658 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);14629 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
14659 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);14630 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
14660 element_vals[elem_i] = coerced_elem_val.toIntern();14631 element_vals[elem_i] = coerced_elem_val.toIntern();
...@@ -14683,10 +14654,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14683,10 +14654,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14683 while (elem_i < lhs_len) : (elem_i += 1) {14654 while (elem_i < lhs_len) : (elem_i += 1) {
14684 const elem_index = try mod.intRef(Type.usize, elem_i);14655 const elem_index = try mod.intRef(Type.usize, elem_i);
14685 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);14656 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 = .{
14687 .array_cat_offset = inst_data.src_node,14658 .array_cat_offset = inst_data.src_node,
14688 .elem_index = elem_i,14659 .elem_index = elem_i,
14689 } };14660 } });
14690 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);14661 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);
14691 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);14662 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
14692 }14663 }
...@@ -14695,10 +14666,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14695,10 +14666,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14695 const elem_index = try mod.intRef(Type.usize, elem_i);14666 const elem_index = try mod.intRef(Type.usize, elem_i);
14696 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);14667 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);
14697 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);14668 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 = .{
14699 .array_cat_offset = inst_data.src_node,14670 .array_cat_offset = inst_data.src_node,
14700 .elem_index = @intCast(rhs_elem_i),14671 .elem_index = @intCast(rhs_elem_i),
14701 } };14672 } });
14702 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);14673 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);
14703 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);14674 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
14704 }14675 }
...@@ -14717,20 +14688,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14717,20 +14688,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14717 var elem_i: u32 = 0;14688 var elem_i: u32 = 0;
14718 while (elem_i < lhs_len) : (elem_i += 1) {14689 while (elem_i < lhs_len) : (elem_i += 1) {
14719 const index = try mod.intRef(Type.usize, elem_i);14690 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 = .{
14721 .array_cat_offset = inst_data.src_node,14692 .array_cat_offset = inst_data.src_node,
14722 .elem_index = elem_i,14693 .elem_index = elem_i,
14723 } };14694 } });
14724 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);14695 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);
14725 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);14696 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
14726 }14697 }
14727 while (elem_i < result_len) : (elem_i += 1) {14698 while (elem_i < result_len) : (elem_i += 1) {
14728 const rhs_elem_i = elem_i - lhs_len;14699 const rhs_elem_i = elem_i - lhs_len;
14729 const index = try mod.intRef(Type.usize, rhs_elem_i);14700 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 = .{
14731 .array_cat_offset = inst_data.src_node,14702 .array_cat_offset = inst_data.src_node,
14732 .elem_index = @intCast(rhs_elem_i),14703 .elem_index = @intCast(rhs_elem_i),
14733 } };14704 } });
14734 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);14705 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);
14735 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);14706 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
14736 }14707 }
...@@ -14792,8 +14763,8 @@ fn analyzeTupleMul(...@@ -14792,8 +14763,8 @@ fn analyzeTupleMul(
14792) CompileError!Air.Inst.Ref {14763) CompileError!Air.Inst.Ref {
14793 const mod = sema.mod;14764 const mod = sema.mod;
14794 const operand_ty = sema.typeOf(operand);14765 const operand_ty = sema.typeOf(operand);
14795 const src = LazySrcLoc.nodeOffset(src_node);14766 const src = block.nodeOffset(src_node);
14796 const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node };14767 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });
1479714768
14798 const tuple_len = operand_ty.structFieldCount(mod);14769 const tuple_len = operand_ty.structFieldCount(mod);
14799 const final_len = std.math.mul(usize, tuple_len, factor) catch14770 const final_len = std.math.mul(usize, tuple_len, factor) catch
...@@ -14810,10 +14781,10 @@ fn analyzeTupleMul(...@@ -14810,10 +14781,10 @@ fn analyzeTupleMul(
14810 for (0..tuple_len) |i| {14781 for (0..tuple_len) |i| {
14811 types[i] = operand_ty.structFieldType(i, mod).toIntern();14782 types[i] = operand_ty.structFieldType(i, mod).toIntern();
14812 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();14783 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 = .{
14814 .array_cat_offset = src_node,14785 .array_cat_offset = src_node,
14815 .elem_index = @intCast(i),14786 .elem_index = @intCast(i),
14816 } };14787 } });
14817 if (values[i] == .unreachable_value) {14788 if (values[i] == .unreachable_value) {
14818 runtime_src = operand_src;14789 runtime_src = operand_src;
14819 values[i] = .none; // TODO don't treat unreachable_value as special14790 values[i] = .none; // TODO don't treat unreachable_value as special
...@@ -14845,10 +14816,10 @@ fn analyzeTupleMul(...@@ -14845,10 +14816,10 @@ fn analyzeTupleMul(
14845 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);14816 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
14846 var i: u32 = 0;14817 var i: u32 = 0;
14847 while (i < tuple_len) : (i += 1) {14818 while (i < tuple_len) : (i += 1) {
14848 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14819 const operand_src = block.src(.{ .array_cat_lhs = .{
14849 .array_cat_offset = src_node,14820 .array_cat_offset = src_node,
14850 .elem_index = i,14821 .elem_index = i,
14851 } };14822 } });
14852 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);14823 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);
14853 }14824 }
14854 i = 1;14825 i = 1;
...@@ -14868,10 +14839,10 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14868,10 +14839,10 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14868 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;14839 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
14869 const uncoerced_lhs = try sema.resolveInst(extra.lhs);14840 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
14870 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);14841 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);
14871 const src: LazySrcLoc = inst_data.src();14842 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
14872 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14843 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14873 const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node };14844 const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node });
14874 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14845 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1487514846
14876 const lhs, const lhs_ty = coerced_lhs: {14847 const lhs, const lhs_ty = coerced_lhs: {
14877 // If we have a result type, we might be able to do this more efficiently14848 // 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...@@ -14920,11 +14891,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14920 // Analyze the lhs first, to catch the case that someone tried to do exponentiation14891 // Analyze the lhs first, to catch the case that someone tried to do exponentiation
14921 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {14892 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {
14922 const msg = msg: {14893 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)});
14924 errdefer msg.destroy(sema.gpa);14895 errdefer msg.destroy(sema.gpa);
14925 switch (lhs_ty.zigTypeTag(mod)) {14896 switch (lhs_ty.zigTypeTag(mod)) {
14926 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {14897 .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", .{});
14928 },14899 },
14929 else => {},14900 else => {},
14930 }14901 }
...@@ -15038,9 +15009,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15038,9 +15009,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15038fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15009fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15039 const mod = sema.mod;15010 const mod = sema.mod;
15040 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;15011 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);
15042 const lhs_src = src;15013 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
15045 const rhs = try sema.resolveInst(inst_data.operand);15016 const rhs = try sema.resolveInst(inst_data.operand);
15046 const rhs_ty = sema.typeOf(rhs);15017 const rhs_ty = sema.typeOf(rhs);
...@@ -15070,9 +15041,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15070,9 +15041,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15070fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15041fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15071 const mod = sema.mod;15042 const mod = sema.mod;
15072 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;15043 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);
15074 const lhs_src = src;15045 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
15077 const rhs = try sema.resolveInst(inst_data.operand);15048 const rhs = try sema.resolveInst(inst_data.operand);
15078 const rhs_ty = sema.typeOf(rhs);15049 const rhs_ty = sema.typeOf(rhs);
...@@ -15098,9 +15069,9 @@ fn zirArithmetic(...@@ -15098,9 +15069,9 @@ fn zirArithmetic(
15098 defer tracy.end();15069 defer tracy.end();
1509915070
15100 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15101 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15072 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15102 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15073 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15103 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15074 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15104 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15075 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15105 const lhs = try sema.resolveInst(extra.lhs);15076 const lhs = try sema.resolveInst(extra.lhs);
15106 const rhs = try sema.resolveInst(extra.rhs);15077 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15111,9 +15082,9 @@ fn zirArithmetic(...@@ -15111,9 +15082,9 @@ fn zirArithmetic(
15111fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15082fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15112 const mod = sema.mod;15083 const mod = sema.mod;
15113 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15084 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15114 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15085 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15115 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15086 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15116 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15087 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15117 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15088 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15118 const lhs = try sema.resolveInst(extra.lhs);15089 const lhs = try sema.resolveInst(extra.lhs);
15119 const rhs = try sema.resolveInst(extra.rhs);15090 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15276,9 +15247,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15276,9 +15247,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15276fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15247fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15277 const mod = sema.mod;15248 const mod = sema.mod;
15278 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15249 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15279 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15250 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15280 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15251 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15281 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15252 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15282 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15253 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15283 const lhs = try sema.resolveInst(extra.lhs);15254 const lhs = try sema.resolveInst(extra.lhs);
15284 const rhs = try sema.resolveInst(extra.rhs);15255 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15441,9 +15412,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15441,9 +15412,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15441fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15412fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15442 const mod = sema.mod;15413 const mod = sema.mod;
15443 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15414 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15444 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15415 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15445 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15416 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15446 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15417 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15447 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15418 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15448 const lhs = try sema.resolveInst(extra.lhs);15419 const lhs = try sema.resolveInst(extra.lhs);
15449 const rhs = try sema.resolveInst(extra.rhs);15420 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15551,9 +15522,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15551,9 +15522,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15551fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15522fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15552 const mod = sema.mod;15523 const mod = sema.mod;
15553 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15524 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15554 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15525 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15555 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15526 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15556 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15527 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15557 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15528 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15558 const lhs = try sema.resolveInst(extra.lhs);15529 const lhs = try sema.resolveInst(extra.lhs);
15559 const rhs = try sema.resolveInst(extra.rhs);15530 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...@@ -15792,9 +15763,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
15792fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15763fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15793 const mod = sema.mod;15764 const mod = sema.mod;
15794 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15765 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15795 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15766 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15796 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15767 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15797 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15768 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15798 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15769 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15799 const lhs = try sema.resolveInst(extra.lhs);15770 const lhs = try sema.resolveInst(extra.lhs);
15800 const rhs = try sema.resolveInst(extra.rhs);15771 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15976,9 +15947,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr...@@ -15976,9 +15947,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
15976fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15947fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15977 const mod = sema.mod;15948 const mod = sema.mod;
15978 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15949 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15979 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15950 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15980 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15951 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15981 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15952 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15982 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15953 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15983 const lhs = try sema.resolveInst(extra.lhs);15954 const lhs = try sema.resolveInst(extra.lhs);
15984 const rhs = try sema.resolveInst(extra.rhs);15955 const rhs = try sema.resolveInst(extra.rhs);
...@@ -16071,9 +16042,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16071,9 +16042,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16071fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16042fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16072 const mod = sema.mod;16043 const mod = sema.mod;
16073 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;16044 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16074 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };16045 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16075 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };16046 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
16076 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };16047 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
16077 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;16048 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
16078 const lhs = try sema.resolveInst(extra.lhs);16049 const lhs = try sema.resolveInst(extra.lhs);
16079 const rhs = try sema.resolveInst(extra.rhs);16050 const rhs = try sema.resolveInst(extra.rhs);
...@@ -16173,10 +16144,10 @@ fn zirOverflowArithmetic(...@@ -16173,10 +16144,10 @@ fn zirOverflowArithmetic(
16173 defer tracy.end();16144 defer tracy.end();
1617416145
16175 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;16146 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 };16149 const lhs_src = block.builtinCallArgSrc(extra.node, 0);
16179 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };16150 const rhs_src = block.builtinCallArgSrc(extra.node, 1);
1618016151
16181 const uncasted_lhs = try sema.resolveInst(extra.lhs);16152 const uncasted_lhs = try sema.resolveInst(extra.lhs);
16182 const uncasted_rhs = try sema.resolveInst(extra.rhs);16153 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...@@ -16988,7 +16959,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In
16988 defer tracy.end();16959 defer tracy.end();
1698916960
16990 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;16961 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);
16992 const ptr_src = src; // TODO better source location16963 const ptr_src = src; // TODO better source location
16993 const ptr = try sema.resolveInst(inst_data.operand);16964 const ptr = try sema.resolveInst(inst_data.operand);
16994 return sema.analyzeLoad(block, src, ptr, ptr_src);16965 return sema.analyzeLoad(block, src, ptr, ptr_src);
...@@ -17004,8 +16975,8 @@ fn zirAsm(...@@ -17004,8 +16975,8 @@ fn zirAsm(
17004 defer tracy.end();16975 defer tracy.end();
1700516976
17006 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);16977 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
17007 const src = LazySrcLoc.nodeOffset(extra.data.src_node);16978 const src = block.nodeOffset(extra.data.src_node);
17008 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };16979 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
17009 const outputs_len: u5 = @truncate(extended.small);16980 const outputs_len: u5 = @truncate(extended.small);
17010 const inputs_len: u5 = @truncate(extended.small >> 5);16981 const inputs_len: u5 = @truncate(extended.small >> 5);
17011 const clobbers_len: u5 = @truncate(extended.small >> 10);16982 const clobbers_len: u5 = @truncate(extended.small >> 10);
...@@ -17178,9 +17149,9 @@ fn zirCmpEq(...@@ -17178,9 +17149,9 @@ fn zirCmpEq(
17178 const mod = sema.mod;17149 const mod = sema.mod;
17179 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;17150 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17180 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;17151 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17181 const src: LazySrcLoc = inst_data.src();17152 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17182 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };17153 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17183 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };17154 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
17184 const lhs = try sema.resolveInst(extra.lhs);17155 const lhs = try sema.resolveInst(extra.lhs);
17185 const rhs = try sema.resolveInst(extra.rhs);17156 const rhs = try sema.resolveInst(extra.rhs);
1718617157
...@@ -17259,9 +17230,9 @@ fn analyzeCmpUnionTag(...@@ -17259,9 +17230,9 @@ fn analyzeCmpUnionTag(
17259 try sema.resolveTypeFields(union_ty);17230 try sema.resolveTypeFields(union_ty);
17260 const union_tag_ty = union_ty.unionTagType(mod) orelse {17231 const union_tag_ty = union_ty.unionTagType(mod) orelse {
17261 const msg = msg: {17232 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", .{});
17263 errdefer msg.destroy(sema.gpa);17234 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)});
17265 break :msg msg;17236 break :msg msg;
17266 };17237 };
17267 return sema.failWithOwnedErrorMsg(block, msg);17238 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -17294,9 +17265,9 @@ fn zirCmp(...@@ -17294,9 +17265,9 @@ fn zirCmp(
1729417265
17295 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;17266 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17296 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;17267 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17297 const src: LazySrcLoc = inst_data.src();17268 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17298 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };17269 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17299 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };17270 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
17300 const lhs = try sema.resolveInst(extra.lhs);17271 const lhs = try sema.resolveInst(extra.lhs);
17301 const rhs = try sema.resolveInst(extra.rhs);17272 const rhs = try sema.resolveInst(extra.rhs);
17302 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);17273 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
...@@ -17438,7 +17409,7 @@ fn runtimeBoolCmp(...@@ -17438,7 +17409,7 @@ fn runtimeBoolCmp(
17438fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17409fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17439 const mod = sema.mod;17410 const mod = sema.mod;
17440 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17411 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);
17442 const ty = try sema.resolveType(block, operand_src, inst_data.operand);17413 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
17443 switch (ty.zigTypeTag(mod)) {17414 switch (ty.zigTypeTag(mod)) {
17444 .Fn,17415 .Fn,
...@@ -17481,7 +17452,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -17481,7 +17452,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
17481fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17452fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17482 const mod = sema.mod;17453 const mod = sema.mod;
17483 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17454 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);
17485 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);17456 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
17486 switch (operand_ty.zigTypeTag(mod)) {17457 switch (operand_ty.zigTypeTag(mod)) {
17487 .Fn,17458 .Fn,
...@@ -17525,7 +17496,7 @@ fn zirThis(...@@ -17525,7 +17496,7 @@ fn zirThis(
17525) CompileError!Air.Inst.Ref {17496) CompileError!Air.Inst.Ref {
17526 const mod = sema.mod;17497 const mod = sema.mod;
17527 const this_decl_index = mod.namespacePtr(block.namespace).decl_index;17498 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));
17529 return sema.analyzeDeclVal(block, src, this_decl_index);17500 return sema.analyzeDeclVal(block, src, this_decl_index);
17530}17501}
1753117502
...@@ -17535,7 +17506,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17535,7 +17506,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17535 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);17506 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);
1753617507
17537 const src_node: i32 = @bitCast(extended.operand);17508 const src_node: i32 = @bitCast(extended.operand);
17538 const src = LazySrcLoc.nodeOffset(src_node);17509 const src = block.nodeOffset(src_node);
1753917510
17540 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {17511 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {
17541 .@"comptime" => |index| return Air.internedToRef(index),17512 .@"comptime" => |index| return Air.internedToRef(index),
...@@ -17549,7 +17520,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17549,7 +17520,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17549 if (!block.is_typeof and sema.func_index == .none) {17520 if (!block.is_typeof and sema.func_index == .none) {
17550 const msg = msg: {17521 const msg = msg: {
17551 const name = name: {17522 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);
17553 const tree = file.getTree(sema.gpa) catch |err| {17525 const tree = file.getTree(sema.gpa) catch |err| {
17554 // In this case we emit a warning + a less precise source location.17526 // In this case we emit a warning + a less precise source location.
17555 log.warn("unable to load {s}: {s}", .{17527 log.warn("unable to load {s}: {s}", .{
...@@ -17557,15 +17529,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17557,15 +17529,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17557 });17529 });
17558 break :name null;17530 break :name null;
17559 };17531 };
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)));
17561 const token = tree.nodes.items(.main_token)[node];17533 const token = tree.nodes.items(.main_token)[node];
17562 break :name tree.tokenSlice(token);17534 break :name tree.tokenSlice(token);
17563 };17535 };
1756417536
17565 const msg = if (name) |some|17537 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})
17567 else17539 else
17568 try sema.errMsg(block, src, "variable not accessible outside function scope", .{});17540 try sema.errMsg(src, "variable not accessible outside function scope", .{});
17569 errdefer msg.destroy(sema.gpa);17541 errdefer msg.destroy(sema.gpa);
1757017542
17571 // TODO add "declared here" note17543 // TODO add "declared here" note
...@@ -17577,7 +17549,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17577,7 +17549,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17577 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {17549 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
17578 const msg = msg: {17550 const msg = msg: {
17579 const name = name: {17551 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);
17581 const tree = file.getTree(sema.gpa) catch |err| {17553 const tree = file.getTree(sema.gpa) catch |err| {
17582 // In this case we emit a warning + a less precise source location.17554 // In this case we emit a warning + a less precise source location.
17583 log.warn("unable to load {s}: {s}", .{17555 log.warn("unable to load {s}: {s}", .{
...@@ -17585,18 +17557,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17585,18 +17557,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17585 });17557 });
17586 break :name null;17558 break :name null;
17587 };17559 };
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)));
17589 const token = tree.nodes.items(.main_token)[node];17561 const token = tree.nodes.items(.main_token)[node];
17590 break :name tree.tokenSlice(token);17562 break :name tree.tokenSlice(token);
17591 };17563 };
1759217564
17593 const msg = if (name) |some|17565 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})
17595 else17567 else
17596 try sema.errMsg(block, src, "variable not accessible from inner function", .{});17568 try sema.errMsg(src, "variable not accessible from inner function", .{});
17597 errdefer msg.destroy(sema.gpa);17569 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
17601 // TODO add "declared here" note17573 // TODO add "declared here" note
17602 break :msg msg;17574 break :msg msg;
...@@ -17628,7 +17600,7 @@ fn zirFrameAddress(...@@ -17628,7 +17600,7 @@ fn zirFrameAddress(
17628 block: *Block,17600 block: *Block,
17629 extended: Zir.Inst.Extended.InstData,17601 extended: Zir.Inst.Extended.InstData,
17630) CompileError!Air.Inst.Ref {17602) CompileError!Air.Inst.Ref {
17631 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));17603 const src = block.nodeOffset(@bitCast(extended.operand));
17632 try sema.requireRuntimeBlock(block, src, null);17604 try sema.requireRuntimeBlock(block, src, null);
17633 return try block.addNoOp(.frame_addr);17605 return try block.addNoOp(.frame_addr);
17634}17606}
...@@ -17721,7 +17693,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17721,7 +17693,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17721 const gpa = sema.gpa;17693 const gpa = sema.gpa;
17722 const ip = &mod.intern_pool;17694 const ip = &mod.intern_pool;
17723 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17695 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);
17725 const ty = try sema.resolveType(block, src, inst_data.operand);17697 const ty = try sema.resolveType(block, src, inst_data.operand);
17726 const type_info_ty = try sema.getBuiltinType("Type");17698 const type_info_ty = try sema.getBuiltinType("Type");
17727 const type_info_tag_ty = type_info_ty.unionTagType(mod).?;17699 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...@@ -18884,7 +18856,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
18884 var child_block: Block = .{18856 var child_block: Block = .{
18885 .parent = block,18857 .parent = block,
18886 .sema = sema,18858 .sema = sema,
18887 .src_decl = block.src_decl,
18888 .namespace = block.namespace,18859 .namespace = block.namespace,
18889 .instructions = .{},18860 .instructions = .{},
18890 .inlining = block.inlining,18861 .inlining = block.inlining,
...@@ -18892,6 +18863,8 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18892,6 +18863,8 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
18892 .is_typeof = true,18863 .is_typeof = true,
18893 .want_safety = false,18864 .want_safety = false,
18894 .error_return_trace_index = block.error_return_trace_index,18865 .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,
18895 };18868 };
18896 defer child_block.instructions.deinit(sema.gpa);18869 defer child_block.instructions.deinit(sema.gpa);
1889718870
...@@ -18903,7 +18876,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18903,7 +18876,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1890318876
18904fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {18877fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18905 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;18878 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);
18907 const operand = try sema.resolveInst(inst_data.operand);18880 const operand = try sema.resolveInst(inst_data.operand);
18908 const operand_ty = sema.typeOf(operand);18881 const operand_ty = sema.typeOf(operand);
18909 const res_ty = try sema.log2IntType(block, operand_ty, src);18882 const res_ty = try sema.log2IntType(block, operand_ty, src);
...@@ -18956,13 +18929,12 @@ fn zirTypeofPeer(...@@ -18956,13 +18929,12 @@ fn zirTypeofPeer(
18956 defer tracy.end();18929 defer tracy.end();
1895718930
18958 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);18931 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);
18960 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);18933 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
1896118934
18962 var child_block: Block = .{18935 var child_block: Block = .{
18963 .parent = block,18936 .parent = block,
18964 .sema = sema,18937 .sema = sema,
18965 .src_decl = block.src_decl,
18966 .namespace = block.namespace,18938 .namespace = block.namespace,
18967 .instructions = .{},18939 .instructions = .{},
18968 .inlining = block.inlining,18940 .inlining = block.inlining,
...@@ -18971,6 +18943,8 @@ fn zirTypeofPeer(...@@ -18971,6 +18943,8 @@ fn zirTypeofPeer(
18971 .runtime_cond = block.runtime_cond,18943 .runtime_cond = block.runtime_cond,
18972 .runtime_loop = block.runtime_loop,18944 .runtime_loop = block.runtime_loop,
18973 .runtime_index = block.runtime_index,18945 .runtime_index = block.runtime_index,
18946 .src_base_inst = block.src_base_inst,
18947 .type_name_ctx = block.type_name_ctx,
18974 };18948 };
18975 defer child_block.instructions.deinit(sema.gpa);18949 defer child_block.instructions.deinit(sema.gpa);
18976 // Ignore the result, we only care about the instructions in `args`.18950 // 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...@@ -18995,8 +18969,8 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1899518969
18996 const mod = sema.mod;18970 const mod = sema.mod;
18997 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;18971 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
18998 const src = inst_data.src();18972 const src = block.nodeOffset(inst_data.src_node);
18999 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };18973 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
19000 const uncasted_operand = try sema.resolveInst(inst_data.operand);18974 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1900118975
19002 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);18976 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
...@@ -19027,8 +19001,8 @@ fn zirBoolBr(...@@ -19027,8 +19001,8 @@ fn zirBoolBr(
1902719001
19028 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);19002 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);
19029 const body = sema.code.bodySlice(extra.end, extra.data.body_len);19003 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19030 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };19004 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19031 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };19005 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1903219006
19033 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);19007 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);
1903419008
...@@ -19059,7 +19033,7 @@ fn zirBoolBr(...@@ -19059,7 +19033,7 @@ fn zirBoolBr(
1905919033
19060 var child_block = parent_block.makeSubBlock();19034 var child_block = parent_block.makeSubBlock();
19061 child_block.runtime_loop = null;19035 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;
19063 child_block.runtime_index.increment();19037 child_block.runtime_index.increment();
19064 defer child_block.instructions.deinit(gpa);19038 defer child_block.instructions.deinit(gpa);
1906519039
...@@ -19152,7 +19126,7 @@ fn zirIsNonNull(...@@ -19152,7 +19126,7 @@ fn zirIsNonNull(
19152 defer tracy.end();19126 defer tracy.end();
1915319127
19154 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19128 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);
19156 const operand = try sema.resolveInst(inst_data.operand);19130 const operand = try sema.resolveInst(inst_data.operand);
19157 try sema.checkNullableType(block, src, sema.typeOf(operand));19131 try sema.checkNullableType(block, src, sema.typeOf(operand));
19158 return sema.analyzeIsNull(block, src, operand, true);19132 return sema.analyzeIsNull(block, src, operand, true);
...@@ -19168,7 +19142,7 @@ fn zirIsNonNullPtr(...@@ -19168,7 +19142,7 @@ fn zirIsNonNullPtr(
1916819142
19169 const mod = sema.mod;19143 const mod = sema.mod;
19170 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19144 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);
19172 const ptr = try sema.resolveInst(inst_data.operand);19146 const ptr = try sema.resolveInst(inst_data.operand);
19173 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));19147 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
19174 if ((try sema.resolveValue(ptr)) == null) {19148 if ((try sema.resolveValue(ptr)) == null) {
...@@ -19193,7 +19167,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -19193,7 +19167,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
19193 defer tracy.end();19167 defer tracy.end();
1919419168
19195 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19169 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);
19197 const operand = try sema.resolveInst(inst_data.operand);19171 const operand = try sema.resolveInst(inst_data.operand);
19198 try sema.checkErrorType(block, src, sema.typeOf(operand));19172 try sema.checkErrorType(block, src, sema.typeOf(operand));
19199 return sema.analyzeIsNonErr(block, src, operand);19173 return sema.analyzeIsNonErr(block, src, operand);
...@@ -19205,7 +19179,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -19205,7 +19179,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1920519179
19206 const mod = sema.mod;19180 const mod = sema.mod;
19207 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19181 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);
19209 const ptr = try sema.resolveInst(inst_data.operand);19183 const ptr = try sema.resolveInst(inst_data.operand);
19210 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));19184 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));
19211 const loaded = try sema.analyzeLoad(block, src, ptr, src);19185 const loaded = try sema.analyzeLoad(block, src, ptr, src);
...@@ -19217,7 +19191,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -19217,7 +19191,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
19217 defer tracy.end();19191 defer tracy.end();
1921819192
19219 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19193 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);
19221 const operand = try sema.resolveInst(inst_data.operand);19195 const operand = try sema.resolveInst(inst_data.operand);
19222 return sema.analyzeIsNonErr(block, src, operand);19196 return sema.analyzeIsNonErr(block, src, operand);
19223}19197}
...@@ -19232,7 +19206,7 @@ fn zirCondbr(...@@ -19232,7 +19206,7 @@ fn zirCondbr(
1923219206
19233 const mod = sema.mod;19207 const mod = sema.mod;
19234 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19208 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 });
19236 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);19210 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1923719211
19238 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);19212 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
...@@ -19255,7 +19229,7 @@ fn zirCondbr(...@@ -19255,7 +19229,7 @@ fn zirCondbr(
19255 // instructions array in between using it for the then block and else block.19229 // instructions array in between using it for the then block and else block.
19256 var sub_block = parent_block.makeSubBlock();19230 var sub_block = parent_block.makeSubBlock();
19257 sub_block.runtime_loop = null;19231 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;
19259 sub_block.runtime_index.increment();19233 sub_block.runtime_index.increment();
19260 sub_block.need_debug_scope = null; // this body is emitted regardless19234 sub_block.need_debug_scope = null; // this body is emitted regardless
19261 defer sub_block.instructions.deinit(gpa);19235 defer sub_block.instructions.deinit(gpa);
...@@ -19299,8 +19273,8 @@ fn zirCondbr(...@@ -19299,8 +19273,8 @@ fn zirCondbr(
1929919273
19300fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19274fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19301 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19302 const src = inst_data.src();19276 const src = parent_block.nodeOffset(inst_data.src_node);
19303 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };19277 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19304 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);19278 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
19305 const body = sema.code.bodySlice(extra.end, extra.data.body_len);19279 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19306 const err_union = try sema.resolveInst(extra.data.operand);19280 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!...@@ -19346,8 +19320,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1934619320
19347fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19321fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19348 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19322 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19349 const src = inst_data.src();19323 const src = parent_block.nodeOffset(inst_data.src_node);
19350 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };19324 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19351 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);19325 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
19352 const body = sema.code.bodySlice(extra.end, extra.data.body_len);19326 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19353 const operand = try sema.resolveInst(extra.data.operand);19327 const operand = try sema.resolveInst(extra.data.operand);
...@@ -19437,12 +19411,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label...@@ -19437,12 +19411,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
19437 .block = .{19411 .block = .{
19438 .parent = block,19412 .parent = block,
19439 .sema = sema,19413 .sema = sema,
19440 .src_decl = block.src_decl,
19441 .namespace = block.namespace,19414 .namespace = block.namespace,
19442 .instructions = .{},19415 .instructions = .{},
19443 .label = &labeled_block.label,19416 .label = &labeled_block.label,
19444 .inlining = block.inlining,19417 .inlining = block.inlining,
19445 .is_comptime = block.is_comptime,19418 .is_comptime = block.is_comptime,
19419 .src_base_inst = block.src_base_inst,
19420 .type_name_ctx = block.type_name_ctx,
19446 },19421 },
19447 };19422 };
19448 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);19423 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,...@@ -19471,17 +19446,17 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, block_inst: Zir.Inst.Index,
1947119446
19472fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {19447fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
19473 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";19448 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
19476 if (block.is_comptime) {19451 if (block.is_comptime) {
19477 return sema.fail(block, src, "reached unreachable code", .{});19452 return sema.fail(block, src, "reached unreachable code", .{});
19478 }19453 }
19479 // TODO Add compile error for @optimizeFor occurring too late in a scope.19454 // 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) {
19481 error.AnalysisFail => {19456 error.AnalysisFail => {
19482 const msg = sema.err orelse return err;19457 const msg = sema.err orelse return err;
19483 if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err;19458 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", .{});
19485 return err;19460 return err;
19486 },19461 },
19487 else => |e| return e,19462 else => |e| return e,
...@@ -19495,13 +19470,13 @@ fn zirRetErrValue(...@@ -19495,13 +19470,13 @@ fn zirRetErrValue(
19495) CompileError!void {19470) CompileError!void {
19496 const mod = sema.mod;19471 const mod = sema.mod;
19497 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;19472 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
19473 const src = block.tokenOffset(inst_data.src_tok);
19498 const err_name = try mod.intern_pool.getOrPutString(19474 const err_name = try mod.intern_pool.getOrPutString(
19499 sema.gpa,19475 sema.gpa,
19500 inst_data.get(sema.code),19476 inst_data.get(sema.code),
19501 .no_embedded_nulls,19477 .no_embedded_nulls,
19502 );19478 );
19503 _ = try mod.getErrorValue(err_name);19479 _ = try mod.getErrorValue(err_name);
19504 const src = inst_data.src();
19505 // Return the error code from the function.19480 // Return the error code from the function.
19506 const error_set_type = try mod.singleErrorSetType(err_name);19481 const error_set_type = try mod.singleErrorSetType(err_name);
19507 const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{19482 const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{
...@@ -19521,38 +19496,38 @@ fn zirRetImplicit(...@@ -19521,38 +19496,38 @@ fn zirRetImplicit(
1952119496
19522 const mod = sema.mod;19497 const mod = sema.mod;
19523 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;19498 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);
19525 if (block.inlining == null and sema.func_is_naked) {19500 if (block.inlining == null and sema.func_is_naked) {
19526 assert(!block.is_comptime);19501 assert(!block.is_comptime);
19527 if (block.wantSafety()) {19502 if (block.wantSafety()) {
19528 // Calling a safety function from a naked function would not be legal.19503 // Calling a safety function from a naked function would not be legal.
19529 _ = try block.addNoOp(.trap);19504 _ = try block.addNoOp(.trap);
19530 } else {19505 } else {
19531 try block.addUnreachable(r_brace_src, false);19506 try sema.analyzeUnreachable(block, r_brace_src, false);
19532 }19507 }
19533 return;19508 return;
19534 }19509 }
1953519510
19536 const operand = try sema.resolveInst(inst_data.operand);19511 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 });
19538 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);19513 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
19539 if (base_tag == .NoReturn) {19514 if (base_tag == .NoReturn) {
19540 const msg = msg: {19515 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", .{
19542 sema.fn_ret_ty.fmt(mod),19517 sema.fn_ret_ty.fmt(mod),
19543 });19518 });
19544 errdefer msg.destroy(sema.gpa);19519 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", .{});
19546 break :msg msg;19521 break :msg msg;
19547 };19522 };
19548 return sema.failWithOwnedErrorMsg(block, msg);19523 return sema.failWithOwnedErrorMsg(block, msg);
19549 } else if (base_tag != .Void) {19524 } else if (base_tag != .Void) {
19550 const msg = msg: {19525 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", .{
19552 sema.fn_ret_ty.fmt(mod),19527 sema.fn_ret_ty.fmt(mod),
19553 });19528 });
19554 errdefer msg.destroy(sema.gpa);19529 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", .{});
19556 break :msg msg;19531 break :msg msg;
19557 };19532 };
19558 return sema.failWithOwnedErrorMsg(block, msg);19533 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -19567,9 +19542,9 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi...@@ -19567,9 +19542,9 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1956719542
19568 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19569 const operand = try sema.resolveInst(inst_data.operand);19544 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 }));
19573}19548}
1957419549
19575fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {19550fn 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...@@ -19577,12 +19552,12 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
19577 defer tracy.end();19552 defer tracy.end();
1957819553
19579 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19554 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);
19581 const ret_ptr = try sema.resolveInst(inst_data.operand);19556 const ret_ptr = try sema.resolveInst(inst_data.operand);
1958219557
19583 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {19558 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {
19584 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);19559 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 }));
19586 }19561 }
1958719562
19588 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {19563 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
...@@ -19676,7 +19651,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -19676,7 +19651,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1967619651
19677fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {19652fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
19678 const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;19653 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);
19680}19655}
1968119656
19682/// If `operand` is non-error (or is `none`), restores the error return trace to19657/// If `operand` is non-error (or is `none`), restores the error return trace to
...@@ -19795,9 +19770,7 @@ fn analyzeRet(...@@ -19795,9 +19770,7 @@ fn analyzeRet(
19795 inlining.comptime_result = operand;19770 inlining.comptime_result = operand;
1979619771
19797 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {19772 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19798 const src_decl = mod.declPtr(block.src_decl);19773 try sema.comptime_err_ret_trace.append(src);
19799 const src_loc = src_decl.toSrcLoc(src, mod);
19800 try sema.comptime_err_ret_trace.append(src_loc);
19801 }19774 }
19802 return error.ComptimeReturn;19775 return error.ComptimeReturn;
19803 }19776 }
...@@ -19811,10 +19784,10 @@ fn analyzeRet(...@@ -19811,10 +19784,10 @@ fn analyzeRet(
19811 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});19784 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});
19812 } else if (sema.func_is_naked) {19785 } else if (sema.func_is_naked) {
19813 const msg = msg: {19786 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", .{});
19815 errdefer msg.destroy(sema.gpa);19788 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", .{});
19818 break :msg msg;19791 break :msg msg;
19819 };19792 };
19820 return sema.failWithOwnedErrorMsg(block, msg);19793 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -19850,18 +19823,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19850,18 +19823,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19850 const mod = sema.mod;19823 const mod = sema.mod;
19851 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;19824 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
19852 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);19825 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 };19826 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
19854 const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node };19827 const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node });
19855 const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node };19828 const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node });
19856 const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node };19829 const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node });
19857 const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };19830 const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node });
19858 const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };19831 const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node });
1985919832
19860 const elem_ty = blk: {19833 const elem_ty = blk: {
19861 const air_inst = try sema.resolveInst(extra.data.elem_type);19834 const air_inst = try sema.resolveInst(extra.data.elem_type);
19862 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {19835 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
19863 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {19836 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", .{});
19865 }19838 }
19866 return err;19839 return err;
19867 };19840 };
...@@ -19953,11 +19926,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19953,11 +19926,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19953 } else if (inst_data.size == .C) {19926 } else if (inst_data.size == .C) {
19954 if (!try sema.validateExternType(elem_ty, .other)) {19927 if (!try sema.validateExternType(elem_ty, .other)) {
19955 const msg = msg: {19928 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)});
19957 errdefer msg.destroy(sema.gpa);19930 errdefer msg.destroy(sema.gpa);
1995819931
19959 const src_decl = mod.declPtr(block.src_decl);19932 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other);
19960 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other);
1996119933
19962 try sema.addDeclaredHereNote(msg, elem_ty);19934 try sema.addDeclaredHereNote(msg, elem_ty);
19963 break :msg msg;19935 break :msg msg;
...@@ -19971,10 +19943,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19971,10 +19943,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997119943
19972 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {19944 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {
19973 return sema.failWithOwnedErrorMsg(block, msg: {19945 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)});
19975 errdefer msg.destroy(sema.gpa);19947 errdefer msg.destroy(sema.gpa);
19976 const src_decl = mod.declPtr(block.src_decl);19948 try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty);
19977 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty);
19978 break :msg msg;19949 break :msg msg;
19979 });19950 });
19980 }19951 }
...@@ -20003,8 +19974,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -20003,8 +19974,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
20003 defer tracy.end();19974 defer tracy.end();
2000419975
20005 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19976 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20006 const src = inst_data.src();19977 const src = block.nodeOffset(inst_data.src_node);
20007 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };19978 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
20008 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);19979 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
20009 const mod = sema.mod;19980 const mod = sema.mod;
2001019981
...@@ -20023,7 +19994,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is...@@ -20023,7 +19994,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2002319994
20024 const mod = sema.mod;19995 const mod = sema.mod;
20025 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19996 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);
20027 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {19998 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
20028 // Generic poison means this is an untyped anonymous empty struct init19999 // Generic poison means this is an untyped anonymous empty struct init
20029 error.GenericPoison => return .empty_struct,20000 error.GenericPoison => return .empty_struct,
...@@ -20098,9 +20069,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com...@@ -20098,9 +20069,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
2009820069
20099fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20070fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20100 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20071 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 };20072 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20102 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };20073 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20103 const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };20074 const init_src = block.builtinCallArgSrc(inst_data.src_node, 2);
20104 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;20075 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
20105 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);20076 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
20106 if (union_ty.zigTypeTag(sema.mod) != .Union) {20077 if (union_ty.zigTypeTag(sema.mod) != .Union) {
...@@ -20155,7 +20126,7 @@ fn zirStructInit(...@@ -20155,7 +20126,7 @@ fn zirStructInit(
20155 const zir_datas = sema.code.instructions.items(.data);20126 const zir_datas = sema.code.instructions.items(.data);
20156 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;20127 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
20157 const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);20128 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
20160 const mod = sema.mod;20131 const mod = sema.mod;
20161 const ip = &mod.intern_pool;20132 const ip = &mod.intern_pool;
...@@ -20194,7 +20165,7 @@ fn zirStructInit(...@@ -20194,7 +20165,7 @@ fn zirStructInit(
20194 extra_index = item.end;20165 extra_index = item.end;
2019520166
20196 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20167 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 });
20198 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20169 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20199 const field_name = try ip.getOrPutString(20170 const field_name = try ip.getOrPutString(
20200 gpa,20171 gpa,
...@@ -20235,7 +20206,7 @@ fn zirStructInit(...@@ -20235,7 +20206,7 @@ fn zirStructInit(
20235 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);20206 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
2023620207
20237 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20208 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 });
20239 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20210 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20240 const field_name = try ip.getOrPutString(20211 const field_name = try ip.getOrPutString(
20241 gpa,20212 gpa,
...@@ -20249,7 +20220,7 @@ fn zirStructInit(...@@ -20249,7 +20220,7 @@ fn zirStructInit(
2024920220
20250 if (field_ty.zigTypeTag(mod) == .NoReturn) {20221 if (field_ty.zigTypeTag(mod) == .NoReturn) {
20251 return sema.failWithOwnedErrorMsg(block, msg: {20222 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", .{});
20253 errdefer msg.destroy(sema.gpa);20224 errdefer msg.destroy(sema.gpa);
2025420225
20255 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{20226 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{
...@@ -20327,16 +20298,12 @@ fn finishStructInit(...@@ -20327,16 +20298,12 @@ fn finishStructInit(
20327 for (0..anon_struct.types.len) |i| {20298 for (0..anon_struct.types.len) |i| {
20328 if (field_inits[i] != .none) {20299 if (field_inits[i] != .none) {
20329 // Coerce the init value to the field type.20300 // 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 } });
20330 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);20305 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) {20306 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
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 };
20340 continue;20307 continue;
20341 }20308 }
2034220309
...@@ -20346,18 +20313,18 @@ fn finishStructInit(...@@ -20346,18 +20313,18 @@ fn finishStructInit(
20346 if (anon_struct.names.len == 0) {20313 if (anon_struct.names.len == 0) {
20347 const template = "missing tuple field with index {d}";20314 const template = "missing tuple field with index {d}";
20348 if (root_msg) |msg| {20315 if (root_msg) |msg| {
20349 try sema.errNote(block, init_src, msg, template, .{i});20316 try sema.errNote(init_src, msg, template, .{i});
20350 } else {20317 } else {
20351 root_msg = try sema.errMsg(block, init_src, template, .{i});20318 root_msg = try sema.errMsg(init_src, template, .{i});
20352 }20319 }
20353 } else {20320 } else {
20354 const field_name = anon_struct.names.get(ip)[i];20321 const field_name = anon_struct.names.get(ip)[i];
20355 const template = "missing struct field: {}";20322 const template = "missing struct field: {}";
20356 const args = .{field_name.fmt(ip)};20323 const args = .{field_name.fmt(ip)};
20357 if (root_msg) |msg| {20324 if (root_msg) |msg| {
20358 try sema.errNote(block, init_src, msg, template, args);20325 try sema.errNote(init_src, msg, template, args);
20359 } else {20326 } else {
20360 root_msg = try sema.errMsg(block, init_src, template, args);20327 root_msg = try sema.errMsg(init_src, template, args);
20361 }20328 }
20362 }20329 }
20363 } else {20330 } else {
...@@ -20370,16 +20337,12 @@ fn finishStructInit(...@@ -20370,16 +20337,12 @@ fn finishStructInit(
20370 for (0..struct_type.field_types.len) |i| {20337 for (0..struct_type.field_types.len) |i| {
20371 if (field_inits[i] != .none) {20338 if (field_inits[i] != .none) {
20372 // Coerce the init value to the field type.20339 // 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 } });
20373 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);20344 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) {20345 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
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 };
20383 continue;20346 continue;
20384 }20347 }
2038520348
...@@ -20392,16 +20355,16 @@ fn finishStructInit(...@@ -20392,16 +20355,16 @@ fn finishStructInit(
20392 const template = "missing struct field: {}";20355 const template = "missing struct field: {}";
20393 const args = .{field_name.fmt(ip)};20356 const args = .{field_name.fmt(ip)};
20394 if (root_msg) |msg| {20357 if (root_msg) |msg| {
20395 try sema.errNote(block, init_src, msg, template, args);20358 try sema.errNote(init_src, msg, template, args);
20396 } else {20359 } else {
20397 root_msg = try sema.errMsg(block, init_src, template, args);20360 root_msg = try sema.errMsg(init_src, template, args);
20398 }20361 }
20399 } else {20362 } else {
20400 const template = "missing tuple field with index {d}";20363 const template = "missing tuple field with index {d}";
20401 if (root_msg) |msg| {20364 if (root_msg) |msg| {
20402 try sema.errNote(block, init_src, msg, template, .{i});20365 try sema.errNote(init_src, msg, template, .{i});
20403 } else {20366 } else {
20404 root_msg = try sema.errMsg(block, init_src, template, .{i});20367 root_msg = try sema.errMsg(init_src, template, .{i});
20405 }20368 }
20406 }20369 }
20407 } else {20370 } else {
...@@ -20413,16 +20376,7 @@ fn finishStructInit(...@@ -20413,16 +20376,7 @@ fn finishStructInit(
20413 }20376 }
2041420377
20415 if (root_msg) |msg| {20378 if (root_msg) |msg| {
20416 if (mod.typeToStruct(struct_ty)) |struct_type| {20379 try sema.addDeclaredHereNote(msg, struct_ty);
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 }
20426 root_msg = null;20380 root_msg = null;
20427 return sema.failWithOwnedErrorMsg(block, msg);20381 return sema.failWithOwnedErrorMsg(block, msg);
20428 }20382 }
...@@ -20449,9 +20403,10 @@ fn finishStructInit(...@@ -20449,9 +20403,10 @@ fn finishStructInit(
20449 };20403 };
2045020404
20451 if (try sema.typeRequiresComptime(struct_ty)) {20405 if (try sema.typeRequiresComptime(struct_ty)) {
20452 const decl = mod.declPtr(block.src_decl);20406 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
20453 const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index);20407 .init_node_offset = init_src.offset.node_offset.x,
20454 return sema.failWithNeededComptime(block, field_src, .{20408 .elem_index = @intCast(runtime_index),
20409 } }), .{
20455 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",20410 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
20456 });20411 });
20457 }20412 }
...@@ -20479,15 +20434,10 @@ fn finishStructInit(...@@ -20479,15 +20434,10 @@ fn finishStructInit(
20479 return sema.makePtrConst(block, alloc);20434 return sema.makePtrConst(block, alloc);
20480 }20435 }
2048120436
20482 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20437 try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{
20483 error.NeededSourceLocation => {20438 .init_node_offset = init_src.offset.node_offset.x,
20484 const decl = mod.declPtr(block.src_decl);20439 .elem_index = @intCast(runtime_index),
20485 const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index);20440 } }));
20486 try sema.requireRuntimeBlock(block, dest_src, field_src);
20487 unreachable;
20488 },
20489 else => |e| return e,
20490 };
20491 try sema.resolveStructFieldInits(struct_ty);20441 try sema.resolveStructFieldInits(struct_ty);
20492 try sema.queueFullTypeResolution(struct_ty);20442 try sema.queueFullTypeResolution(struct_ty);
20493 const struct_val = try block.addAggregateInit(struct_ty, field_inits);20443 const struct_val = try block.addAggregateInit(struct_ty, field_inits);
...@@ -20500,7 +20450,7 @@ fn zirStructInitAnon(...@@ -20500,7 +20450,7 @@ fn zirStructInitAnon(
20500 inst: Zir.Inst.Index,20450 inst: Zir.Inst.Index,
20501) CompileError!Air.Inst.Ref {20451) CompileError!Air.Inst.Ref {
20502 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20452 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);
20504 const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);20454 const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
20505 return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false);20455 return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false);
20506}20456}
...@@ -20555,9 +20505,11 @@ fn structInitAnon(...@@ -20555,9 +20505,11 @@ fn structInitAnon(
20555 field_ty.* = sema.typeOf(init).toIntern();20505 field_ty.* = sema.typeOf(init).toIntern();
20556 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {20506 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
20557 const msg = msg: {20507 const msg = msg: {
20558 const decl = mod.declPtr(block.src_decl);20508 const field_src = block.src(.{ .init_elem = .{
20559 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));20509 .init_node_offset = src.offset.node_offset.x,
20560 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});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", .{});
20561 errdefer msg.destroy(sema.gpa);20513 errdefer msg.destroy(sema.gpa);
2056220514
20563 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));20515 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
...@@ -20589,15 +20541,10 @@ fn structInitAnon(...@@ -20589,15 +20541,10 @@ fn structInitAnon(
20589 return sema.addConstantMaybeRef(tuple_val, is_ref);20541 return sema.addConstantMaybeRef(tuple_val, is_ref);
20590 };20542 };
2059120543
20592 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20544 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20593 error.NeededSourceLocation => {20545 .init_node_offset = src.offset.node_offset.x,
20594 const decl = mod.declPtr(block.src_decl);20546 .elem_index = @intCast(runtime_index),
20595 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);20547 } }));
20596 try sema.requireRuntimeBlock(block, src, field_src);
20597 unreachable;
20598 },
20599 else => |e| return e,
20600 };
2060120548
20602 if (is_ref) {20549 if (is_ref) {
20603 const target = mod.getTarget();20550 const target = mod.getTarget();
...@@ -20652,7 +20599,7 @@ fn zirArrayInit(...@@ -20652,7 +20599,7 @@ fn zirArrayInit(
20652 const mod = sema.mod;20599 const mod = sema.mod;
20653 const gpa = sema.gpa;20600 const gpa = sema.gpa;
20654 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20601 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
20657 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);20604 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
20658 const args = sema.code.refSlice(extra.end, extra.data.operands_len);20605 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
...@@ -20676,15 +20623,19 @@ fn zirArrayInit(...@@ -20676,15 +20623,19 @@ fn zirArrayInit(
20676 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);20623 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
20677 defer gpa.free(resolved_args);20624 defer gpa.free(resolved_args);
20678 for (resolved_args, 0..) |*dest, i| {20625 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 } });
20679 // Less inits than needed.20630 // Less inits than needed.
20680 if (i + 2 > args.len) if (is_tuple) {20631 if (i + 2 > args.len) if (is_tuple) {
20681 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();20632 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
20682 if (default_val == .unreachable_value) {20633 if (default_val == .unreachable_value) {
20683 const template = "missing tuple field with index {d}";20634 const template = "missing tuple field with index {d}";
20684 if (root_msg) |msg| {20635 if (root_msg) |msg| {
20685 try sema.errNote(block, src, msg, template, .{i});20636 try sema.errNote(src, msg, template, .{i});
20686 } else {20637 } else {
20687 root_msg = try sema.errMsg(block, src, template, .{i});20638 root_msg = try sema.errMsg(src, template, .{i});
20688 }20639 }
20689 } else {20640 } else {
20690 dest.* = Air.internedToRef(default_val);20641 dest.* = Air.internedToRef(default_val);
...@@ -20701,29 +20652,17 @@ fn zirArrayInit(...@@ -20701,29 +20652,17 @@ fn zirArrayInit(
20701 array_ty.structFieldType(i, mod)20652 array_ty.structFieldType(i, mod)
20702 else20653 else
20703 array_ty.elemType2(mod);20654 array_ty.elemType2(mod);
20704 dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {20655 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
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 };
20713 if (is_tuple) {20656 if (is_tuple) {
20714 if (array_ty.structFieldIsComptime(i, mod))20657 if (array_ty.structFieldIsComptime(i, mod))
20715 try sema.resolveStructFieldInits(array_ty);20658 try sema.resolveStructFieldInits(array_ty);
20716 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {20659 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
20717 const init_val = try sema.resolveValue(dest.*) orelse {20660 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);
20720 return sema.failWithNeededComptime(block, elem_src, .{20661 return sema.failWithNeededComptime(block, elem_src, .{
20721 .needed_comptime_reason = "value stored in comptime field must be comptime-known",20662 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
20722 });20663 });
20723 };20664 };
20724 if (!field_val.eql(init_val, elem_ty, mod)) {20665 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);
20727 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);20666 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
20728 }20667 }
20729 }20668 }
...@@ -20756,15 +20695,10 @@ fn zirArrayInit(...@@ -20756,15 +20695,10 @@ fn zirArrayInit(
20756 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);20695 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
20757 };20696 };
2075820697
20759 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20698 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20760 error.NeededSourceLocation => {20699 .init_node_offset = src.offset.node_offset.x,
20761 const decl = mod.declPtr(block.src_decl);20700 .elem_index = runtime_index,
20762 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);20701 } }));
20763 try sema.requireRuntimeBlock(block, src, elem_src);
20764 unreachable;
20765 },
20766 else => return err,
20767 };
20768 try sema.queueFullTypeResolution(array_ty);20702 try sema.queueFullTypeResolution(array_ty);
2076920703
20770 if (is_ref) {20704 if (is_ref) {
...@@ -20815,7 +20749,7 @@ fn zirArrayInitAnon(...@@ -20815,7 +20749,7 @@ fn zirArrayInitAnon(
20815 inst: Zir.Inst.Index,20749 inst: Zir.Inst.Index,
20816) CompileError!Air.Inst.Ref {20750) CompileError!Air.Inst.Ref {
20817 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20751 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);
20819 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);20753 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
20820 const operands = sema.code.refSlice(extra.end, extra.data.operands_len);20754 const operands = sema.code.refSlice(extra.end, extra.data.operands_len);
20821 return sema.arrayInitAnon(block, src, operands, false);20755 return sema.arrayInitAnon(block, src, operands, false);
...@@ -20843,7 +20777,7 @@ fn arrayInitAnon(...@@ -20843,7 +20777,7 @@ fn arrayInitAnon(
20843 types[i] = sema.typeOf(elem).toIntern();20777 types[i] = sema.typeOf(elem).toIntern();
20844 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {20778 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
20845 const msg = msg: {20779 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", .{});
20847 errdefer msg.destroy(gpa);20781 errdefer msg.destroy(gpa);
2084820782
20849 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));20783 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
...@@ -20914,8 +20848,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In...@@ -20914,8 +20848,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In
20914fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20848fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20915 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20849 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20916 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;20850 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 };20851 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20918 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };20852 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20919 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);20853 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
20920 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{20854 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
20921 .needed_comptime_reason = "field name must be comptime-known",20855 .needed_comptime_reason = "field name must be comptime-known",
...@@ -20928,8 +20862,8 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -20928,8 +20862,8 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
20928 const ip = &mod.intern_pool;20862 const ip = &mod.intern_pool;
20929 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20863 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20930 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;20864 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
20931 const ty_src = inst_data.src();20865 const ty_src = block.nodeOffset(inst_data.src_node);
20932 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };20866 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
20933 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {20867 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {
20934 // Since this is a ZIR instruction that returns a type, encountering20868 // Since this is a ZIR instruction that returns a type, encountering
20935 // generic poison should not result in a failed compilation, but the20869 // generic poison should not result in a failed compilation, but the
...@@ -20969,7 +20903,7 @@ fn fieldType(...@@ -20969,7 +20903,7 @@ fn fieldType(
20969 .struct_type => {20903 .struct_type => {
20970 const struct_type = ip.loadStructType(cur_ty.toIntern());20904 const struct_type = ip.loadStructType(cur_ty.toIntern());
20971 const field_index = struct_type.nameIndex(ip, field_name) orelse20905 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);
20973 const field_ty = struct_type.field_types.get(ip)[field_index];20907 const field_ty = struct_type.field_types.get(ip)[field_index];
20974 return Air.internedToRef(field_ty);20908 return Air.internedToRef(field_ty);
20975 },20909 },
...@@ -20978,7 +20912,7 @@ fn fieldType(...@@ -20978,7 +20912,7 @@ fn fieldType(
20978 .Union => {20912 .Union => {
20979 const union_obj = mod.typeToUnion(cur_ty).?;20913 const union_obj = mod.typeToUnion(cur_ty).?;
20980 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse20914 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);
20982 const field_ty = union_obj.field_types.get(ip)[field_index];20916 const field_ty = union_obj.field_types.get(ip)[field_index];
20983 return Air.internedToRef(field_ty);20917 return Air.internedToRef(field_ty);
20984 },20918 },
...@@ -21029,14 +20963,14 @@ fn zirFrame(...@@ -21029,14 +20963,14 @@ fn zirFrame(
21029 block: *Block,20963 block: *Block,
21030 extended: Zir.Inst.Extended.InstData,20964 extended: Zir.Inst.Extended.InstData,
21031) CompileError!Air.Inst.Ref {20965) CompileError!Air.Inst.Ref {
21032 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));20966 const src = block.nodeOffset(@bitCast(extended.operand));
21033 return sema.failWithUseOfAsync(block, src);20967 return sema.failWithUseOfAsync(block, src);
21034}20968}
2103520969
21036fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20970fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21037 const mod = sema.mod;20971 const mod = sema.mod;
21038 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;20972 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);
21040 const ty = try sema.resolveType(block, operand_src, inst_data.operand);20974 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
21041 if (ty.isNoReturn(mod)) {20975 if (ty.isNoReturn(mod)) {
21042 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)});20976 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...@@ -21051,7 +20985,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21051fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20985fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21052 const mod = sema.mod;20986 const mod = sema.mod;
21053 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;20987 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);
21055 const operand = try sema.resolveInst(inst_data.operand);20989 const operand = try sema.resolveInst(inst_data.operand);
21056 const operand_ty = sema.typeOf(operand);20990 const operand_ty = sema.typeOf(operand);
21057 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;20991 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
...@@ -21100,7 +21034,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -21100,7 +21034,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2110021034
21101fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21035fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21102 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21036 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);
21104 const uncoerced_operand = try sema.resolveInst(inst_data.operand);21038 const uncoerced_operand = try sema.resolveInst(inst_data.operand);
21105 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);21039 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);
2110621040
...@@ -21122,7 +21056,7 @@ fn zirAbs(...@@ -21122,7 +21056,7 @@ fn zirAbs(
21122 const mod = sema.mod;21056 const mod = sema.mod;
21123 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21057 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21124 const operand = try sema.resolveInst(inst_data.operand);21058 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);
21126 const operand_ty = sema.typeOf(operand);21060 const operand_ty = sema.typeOf(operand);
21127 const scalar_ty = operand_ty.scalarType(mod);21061 const scalar_ty = operand_ty.scalarType(mod);
2112821062
...@@ -21190,7 +21124,7 @@ fn zirUnaryMath(...@@ -21190,7 +21124,7 @@ fn zirUnaryMath(
21190 const mod = sema.mod;21124 const mod = sema.mod;
21191 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21125 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21192 const operand = try sema.resolveInst(inst_data.operand);21126 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);
21194 const operand_ty = sema.typeOf(operand);21128 const operand_ty = sema.typeOf(operand);
21195 const scalar_ty = operand_ty.scalarType(mod);21129 const scalar_ty = operand_ty.scalarType(mod);
2119621130
...@@ -21212,8 +21146,8 @@ fn zirUnaryMath(...@@ -21212,8 +21146,8 @@ fn zirUnaryMath(
2121221146
21213fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21147fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21214 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21148 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 };21149 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21216 const src = inst_data.src();21150 const src = block.nodeOffset(inst_data.src_node);
21217 const operand = try sema.resolveInst(inst_data.operand);21151 const operand = try sema.resolveInst(inst_data.operand);
21218 const operand_ty = sema.typeOf(operand);21152 const operand_ty = sema.typeOf(operand);
21219 const mod = sema.mod;21153 const mod = sema.mod;
...@@ -21222,7 +21156,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21222,7 +21156,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21222 try sema.resolveTypeLayout(operand_ty);21156 try sema.resolveTypeLayout(operand_ty);
21223 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {21157 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
21224 .EnumLiteral => {21158 .EnumLiteral => {
21225 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);21159 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined);
21226 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;21160 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
21227 return sema.addNullTerminatedStrLit(tag_name);21161 return sema.addNullTerminatedStrLit(tag_name);
21228 },21162 },
...@@ -21245,13 +21179,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21245,13 +21179,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21245 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);21179 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
21246 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {21180 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {
21247 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {21181 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
21248 const enum_decl = mod.declPtr(enum_decl_index);
21249 const msg = msg: {21182 const msg = msg: {
21250 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{21183 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{
21251 val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip),21184 val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip),
21252 });21185 });
21253 errdefer msg.destroy(sema.gpa);21186 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", .{});
21255 break :msg msg;21188 break :msg msg;
21256 };21189 };
21257 return sema.failWithOwnedErrorMsg(block, msg);21190 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -21281,11 +21214,23 @@ fn zirReify(...@@ -21281,11 +21214,23 @@ fn zirReify(
21281 const gpa = sema.gpa;21214 const gpa = sema.gpa;
21282 const ip = &mod.intern_pool;21215 const ip = &mod.intern_pool;
21283 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);21216 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
21284 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;21217 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
21285 const src = LazySrcLoc.nodeOffset(extra.node);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 };
21286 const type_info_ty = try sema.getBuiltinType("Type");21232 const type_info_ty = try sema.getBuiltinType("Type");
21287 const uncasted_operand = try sema.resolveInst(extra.operand);21233 const uncasted_operand = try sema.resolveInst(extra.operand);
21288 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
21289 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);21234 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
21290 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{21235 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
21291 .needed_comptime_reason = "operand to @Type must be comptime-known",21236 .needed_comptime_reason = "operand to @Type must be comptime-known",
...@@ -21438,11 +21383,10 @@ fn zirReify(...@@ -21438,11 +21383,10 @@ fn zirReify(
21438 } else if (ptr_size == .C) {21383 } else if (ptr_size == .C) {
21439 if (!try sema.validateExternType(elem_ty, .other)) {21384 if (!try sema.validateExternType(elem_ty, .other)) {
21440 const msg = msg: {21385 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)});
21442 errdefer msg.destroy(gpa);21387 errdefer msg.destroy(gpa);
2144321388
21444 const src_decl = mod.declPtr(block.src_decl);21389 try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other);
21445 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other);
2144621390
21447 try sema.addDeclaredHereNote(msg, elem_ty);21391 try sema.addDeclaredHereNote(msg, elem_ty);
21448 break :msg msg;21392 break :msg msg;
...@@ -21602,7 +21546,7 @@ fn zirReify(...@@ -21602,7 +21546,7 @@ fn zirReify(
21602 .needed_comptime_reason = "struct fields must be comptime-known",21546 .needed_comptime_reason = "struct fields must be comptime-known",
21603 });21547 });
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);
21606 },21550 },
21607 .Enum => {21551 .Enum => {
21608 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21552 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21631,7 +21575,7 @@ fn zirReify(...@@ -21631,7 +21575,7 @@ fn zirReify(
21631 .needed_comptime_reason = "enum fields must be comptime-known",21575 .needed_comptime_reason = "enum fields must be comptime-known",
21632 });21576 });
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);
21635 },21579 },
21636 .Opaque => {21580 .Opaque => {
21637 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21581 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21658,11 +21602,11 @@ fn zirReify(...@@ -21658,11 +21602,11 @@ fn zirReify(
2165821602
21659 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21603 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21660 block,21604 block,
21661 src,
21662 Value.fromInterned(wip_ty.index),21605 Value.fromInterned(wip_ty.index),
21663 name_strategy,21606 name_strategy,
21664 "opaque",21607 "opaque",
21665 inst,21608 inst,
21609 extra.src_line,
21666 );21610 );
21667 mod.declPtr(new_decl_index).owns_tv = true;21611 mod.declPtr(new_decl_index).owns_tv = true;
21668 errdefer mod.abortAnonDecl(new_decl_index);21612 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21699,7 +21643,7 @@ fn zirReify(...@@ -21699,7 +21643,7 @@ fn zirReify(
21699 .needed_comptime_reason = "union fields must be comptime-known",21643 .needed_comptime_reason = "union fields must be comptime-known",
21700 });21644 });
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);
21703 },21647 },
21704 .Fn => {21648 .Fn => {
21705 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21649 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21801,6 +21745,7 @@ fn reifyEnum(...@@ -21801,6 +21745,7 @@ fn reifyEnum(
21801 is_exhaustive: bool,21745 is_exhaustive: bool,
21802 fields_val: Value,21746 fields_val: Value,
21803 name_strategy: Zir.Inst.NameStrategy,21747 name_strategy: Zir.Inst.NameStrategy,
21748 src_line: u32,
21804) CompileError!Air.Inst.Ref {21749) CompileError!Air.Inst.Ref {
21805 const mod = sema.mod;21750 const mod = sema.mod;
21806 const gpa = sema.gpa;21751 const gpa = sema.gpa;
...@@ -21858,11 +21803,11 @@ fn reifyEnum(...@@ -21858,11 +21803,11 @@ fn reifyEnum(
2185821803
21859 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21804 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21860 block,21805 block,
21861 src,
21862 Value.fromInterned(wip_ty.index),21806 Value.fromInterned(wip_ty.index),
21863 name_strategy,21807 name_strategy,
21864 "enum",21808 "enum",
21865 inst,21809 inst,
21810 src_line,
21866 );21811 );
21867 mod.declPtr(new_decl_index).owns_tv = true;21812 mod.declPtr(new_decl_index).owns_tv = true;
21868 errdefer mod.abortAnonDecl(new_decl_index);21813 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21892,17 +21837,17 @@ fn reifyEnum(...@@ -21892,17 +21837,17 @@ fn reifyEnum(
21892 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {21837 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {
21893 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {21838 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {
21894 .name => msg: {21839 .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)});
21896 errdefer msg.destroy(gpa);21841 errdefer msg.destroy(gpa);
21897 _ = conflict.prev_field_idx; // TODO: this note is incorrect21842 _ = 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", .{});
21899 break :msg msg;21844 break :msg msg;
21900 },21845 },
21901 .value => msg: {21846 .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)});
21903 errdefer msg.destroy(gpa);21848 errdefer msg.destroy(gpa);
21904 _ = conflict.prev_field_idx; // TODO: this note is incorrect21849 _ = 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", .{});
21906 break :msg msg;21851 break :msg msg;
21907 },21852 },
21908 });21853 });
...@@ -21926,6 +21871,7 @@ fn reifyUnion(...@@ -21926,6 +21871,7 @@ fn reifyUnion(
21926 opt_tag_type_val: Value,21871 opt_tag_type_val: Value,
21927 fields_val: Value,21872 fields_val: Value,
21928 name_strategy: Zir.Inst.NameStrategy,21873 name_strategy: Zir.Inst.NameStrategy,
21874 src_line: u32,
21929) CompileError!Air.Inst.Ref {21875) CompileError!Air.Inst.Ref {
21930 const mod = sema.mod;21876 const mod = sema.mod;
21931 const gpa = sema.gpa;21877 const gpa = sema.gpa;
...@@ -22005,11 +21951,11 @@ fn reifyUnion(...@@ -22005,11 +21951,11 @@ fn reifyUnion(
2200521951
22006 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21952 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22007 block,21953 block,
22008 src,
22009 Value.fromInterned(wip_ty.index),21954 Value.fromInterned(wip_ty.index),
22010 name_strategy,21955 name_strategy,
22011 "union",21956 "union",
22012 inst,21957 inst,
21958 src_line,
22013 );21959 );
22014 mod.declPtr(new_decl_index).owns_tv = true;21960 mod.declPtr(new_decl_index).owns_tv = true;
22015 errdefer mod.abortAnonDecl(new_decl_index);21961 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -22061,7 +22007,7 @@ fn reifyUnion(...@@ -22061,7 +22007,7 @@ fn reifyUnion(
22061 }22007 }
2206222008
22063 if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: {22009 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", .{});
22065 errdefer msg.destroy(gpa);22011 errdefer msg.destroy(gpa);
22066 var it = seen_tags.iterator(.{ .kind = .unset });22012 var it = seen_tags.iterator(.{ .kind = .unset });
22067 while (it.next()) |enum_index| {22013 while (it.next()) |enum_index| {
...@@ -22105,7 +22051,7 @@ fn reifyUnion(...@@ -22105,7 +22051,7 @@ fn reifyUnion(
22105 }22051 }
22106 }22052 }
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);
22109 break :tag_ty .{ enum_tag_ty, false };22055 break :tag_ty .{ enum_tag_ty, false };
22110 };22056 };
22111 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error22057 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
...@@ -22114,7 +22060,7 @@ fn reifyUnion(...@@ -22114,7 +22060,7 @@ fn reifyUnion(
22114 const field_ty = Type.fromInterned(field_ty_ip);22060 const field_ty = Type.fromInterned(field_ty_ip);
22115 if (field_ty.zigTypeTag(mod) == .Opaque) {22061 if (field_ty.zigTypeTag(mod) == .Opaque) {
22116 return sema.failWithOwnedErrorMsg(block, msg: {22062 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", .{});
22118 errdefer msg.destroy(gpa);22064 errdefer msg.destroy(gpa);
2211922065
22120 try sema.addDeclaredHereNote(msg, field_ty);22066 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22123,22 +22069,20 @@ fn reifyUnion(...@@ -22123,22 +22069,20 @@ fn reifyUnion(
22123 }22069 }
22124 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {22070 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {
22125 return sema.failWithOwnedErrorMsg(block, msg: {22071 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)});
22127 errdefer msg.destroy(gpa);22073 errdefer msg.destroy(gpa);
2212822074
22129 const src_decl = mod.declPtr(block.src_decl);22075 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field);
22130 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field);
2213122076
22132 try sema.addDeclaredHereNote(msg, field_ty);22077 try sema.addDeclaredHereNote(msg, field_ty);
22133 break :msg msg;22078 break :msg msg;
22134 });22079 });
22135 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {22080 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
22136 return sema.failWithOwnedErrorMsg(block, msg: {22081 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)});
22138 errdefer msg.destroy(gpa);22083 errdefer msg.destroy(gpa);
2213922084
22140 const src_decl = mod.declPtr(block.src_decl);22085 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
22141 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2214222086
22143 try sema.addDeclaredHereNote(msg, field_ty);22087 try sema.addDeclaredHereNote(msg, field_ty);
22144 break :msg msg;22088 break :msg msg;
...@@ -22168,6 +22112,7 @@ fn reifyStruct(...@@ -22168,6 +22112,7 @@ fn reifyStruct(
22168 fields_val: Value,22112 fields_val: Value,
22169 name_strategy: Zir.Inst.NameStrategy,22113 name_strategy: Zir.Inst.NameStrategy,
22170 is_tuple: bool,22114 is_tuple: bool,
22115 src_line: u32,
22171) CompileError!Air.Inst.Ref {22116) CompileError!Air.Inst.Ref {
22172 const mod = sema.mod;22117 const mod = sema.mod;
22173 const gpa = sema.gpa;22118 const gpa = sema.gpa;
...@@ -22264,11 +22209,11 @@ fn reifyStruct(...@@ -22264,11 +22209,11 @@ fn reifyStruct(
2226422209
22265 const new_decl_index = try sema.createAnonymousDeclTypeNamed(22210 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22266 block,22211 block,
22267 src,
22268 Value.fromInterned(wip_ty.index),22212 Value.fromInterned(wip_ty.index),
22269 name_strategy,22213 name_strategy,
22270 "struct",22214 "struct",
22271 inst,22215 inst,
22216 src_line,
22272 );22217 );
22273 mod.declPtr(new_decl_index).owns_tv = true;22218 mod.declPtr(new_decl_index).owns_tv = true;
22274 errdefer mod.abortAnonDecl(new_decl_index);22219 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -22355,7 +22300,7 @@ fn reifyStruct(...@@ -22355,7 +22300,7 @@ fn reifyStruct(
2235522300
22356 if (field_ty.zigTypeTag(mod) == .Opaque) {22301 if (field_ty.zigTypeTag(mod) == .Opaque) {
22357 return sema.failWithOwnedErrorMsg(block, msg: {22302 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", .{});
22359 errdefer msg.destroy(gpa);22304 errdefer msg.destroy(gpa);
2236022305
22361 try sema.addDeclaredHereNote(msg, field_ty);22306 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22364,7 +22309,7 @@ fn reifyStruct(...@@ -22364,7 +22309,7 @@ fn reifyStruct(
22364 }22309 }
22365 if (field_ty.zigTypeTag(mod) == .NoReturn) {22310 if (field_ty.zigTypeTag(mod) == .NoReturn) {
22366 return sema.failWithOwnedErrorMsg(block, msg: {22311 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'", .{});
22368 errdefer msg.destroy(gpa);22313 errdefer msg.destroy(gpa);
2236922314
22370 try sema.addDeclaredHereNote(msg, field_ty);22315 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22373,22 +22318,20 @@ fn reifyStruct(...@@ -22373,22 +22318,20 @@ fn reifyStruct(
22373 }22318 }
22374 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {22319 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {
22375 return sema.failWithOwnedErrorMsg(block, msg: {22320 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)});
22377 errdefer msg.destroy(gpa);22322 errdefer msg.destroy(gpa);
2237822323
22379 const src_decl = sema.mod.declPtr(block.src_decl);22324 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field);
22380 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field);
2238122325
22382 try sema.addDeclaredHereNote(msg, field_ty);22326 try sema.addDeclaredHereNote(msg, field_ty);
22383 break :msg msg;22327 break :msg msg;
22384 });22328 });
22385 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {22329 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
22386 return sema.failWithOwnedErrorMsg(block, msg: {22330 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)});
22388 errdefer msg.destroy(gpa);22332 errdefer msg.destroy(gpa);
2238922333
22390 const src_decl = sema.mod.declPtr(block.src_decl);22334 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
22391 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2239222335
22393 try sema.addDeclaredHereNote(msg, field_ty);22336 try sema.addDeclaredHereNote(msg, field_ty);
22394 break :msg msg;22337 break :msg msg;
...@@ -22403,7 +22346,7 @@ fn reifyStruct(...@@ -22403,7 +22346,7 @@ fn reifyStruct(
22403 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {22346 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
22404 error.AnalysisFail => {22347 error.AnalysisFail => {
22405 const msg = sema.err orelse return err;22348 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", .{});
22407 return err;22350 return err;
22408 },22351 },
22409 else => return err,22352 else => return err,
...@@ -22434,22 +22377,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In...@@ -22434,22 +22377,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
22434}22377}
2243522378
22436fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22379fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22437 const mod = sema.mod;
22438 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22380 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22439 const src = LazySrcLoc.nodeOffset(extra.node);22381 const src = block.nodeOffset(extra.node);
22440 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22382 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
22441 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };22383 const ty_src = block.builtinCallArgSrc(extra.node, 1);
2244222384
22443 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);22385 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
22444 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);22386 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2244522387
22446 if (!try sema.validateExternType(arg_ty, .param_ty)) {22388 if (!try sema.validateExternType(arg_ty, .param_ty)) {
22447 const msg = msg: {22389 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)});
22449 errdefer msg.destroy(sema.gpa);22391 errdefer msg.destroy(sema.gpa);
2245022392
22451 const src_decl = sema.mod.declPtr(block.src_decl);22393 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
22452 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty);
2245322394
22454 try sema.addDeclaredHereNote(msg, arg_ty);22395 try sema.addDeclaredHereNote(msg, arg_ty);
22455 break :msg msg;22396 break :msg msg;
...@@ -22463,8 +22404,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -22463,8 +22404,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2246322404
22464fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22405fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22465 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;22406 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22466 const src = LazySrcLoc.nodeOffset(extra.node);22407 const src = block.nodeOffset(extra.node);
22467 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22408 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2246822409
22469 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);22410 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
22470 const va_list_ty = try sema.getBuiltinType("VaList");22411 const va_list_ty = try sema.getBuiltinType("VaList");
...@@ -22475,8 +22416,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -22475,8 +22416,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2247522416
22476fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22417fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22477 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;22418 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22478 const src = LazySrcLoc.nodeOffset(extra.node);22419 const src = block.nodeOffset(extra.node);
22479 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22420 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2248022421
22481 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);22422 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...@@ -22485,7 +22426,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
22485}22426}
2248622427
22487fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22428fn 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
22490 const va_list_ty = try sema.getBuiltinType("VaList");22431 const va_list_ty = try sema.getBuiltinType("VaList");
22491 try sema.requireRuntimeBlock(block, src, null);22432 try sema.requireRuntimeBlock(block, src, null);
...@@ -22500,7 +22441,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -22500,7 +22441,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
22500 const ip = &mod.intern_pool;22441 const ip = &mod.intern_pool;
2250122442
22502 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22443 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);
22504 const ty = try sema.resolveType(block, ty_src, inst_data.operand);22445 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2250522446
22506 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);22447 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...@@ -22509,22 +22450,22 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2250922450
22510fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22451fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22511 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22452 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);
22513 return sema.failWithUseOfAsync(block, src);22454 return sema.failWithUseOfAsync(block, src);
22514}22455}
2251522456
22516fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22457fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22517 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22458 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);
22519 return sema.failWithUseOfAsync(block, src);22460 return sema.failWithUseOfAsync(block, src);
22520}22461}
2252122462
22522fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22463fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22523 const mod = sema.mod;22464 const mod = sema.mod;
22524 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22465 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);
22526 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22467 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);
22528 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");22469 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
22529 const operand = try sema.resolveInst(extra.rhs);22470 const operand = try sema.resolveInst(extra.rhs);
22530 const operand_ty = sema.typeOf(operand);22471 const operand_ty = sema.typeOf(operand);
...@@ -22547,7 +22488,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22547,7 +22488,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22547 });22488 });
22548 }22489 }
2254922490
22550 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);22491 try sema.requireRuntimeBlock(block, src, operand_src);
22551 if (dest_scalar_ty.intInfo(mod).bits == 0) {22492 if (dest_scalar_ty.intInfo(mod).bits == 0) {
22552 if (!is_vector) {22493 if (!is_vector) {
22553 if (block.wantSafety()) {22494 if (block.wantSafety()) {
...@@ -22604,9 +22545,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22604,9 +22545,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22604fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22545fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22605 const mod = sema.mod;22546 const mod = sema.mod;
22606 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22547 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);
22608 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22549 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);
22610 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");22551 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
22611 const operand = try sema.resolveInst(extra.rhs);22552 const operand = try sema.resolveInst(extra.rhs);
22612 const operand_ty = sema.typeOf(operand);22553 const operand_ty = sema.typeOf(operand);
...@@ -22646,11 +22587,11 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22646,11 +22587,11 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22646fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22587fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22647 const mod = sema.mod;22588 const mod = sema.mod;
22648 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22589 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
22651 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22592 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);
22654 const operand_res = try sema.resolveInst(extra.rhs);22595 const operand_res = try sema.resolveInst(extra.rhs);
2265522596
22656 const uncoerced_operand_ty = sema.typeOf(operand_res);22597 const uncoerced_operand_ty = sema.typeOf(operand_res);
...@@ -22673,9 +22614,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22673,9 +22614,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2267322614
22674 if (ptr_ty.isSlice(mod)) {22615 if (ptr_ty.isSlice(mod)) {
22675 const msg = msg: {22616 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)});
22677 errdefer msg.destroy(sema.gpa);22618 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", .{});
22679 break :msg msg;22620 break :msg msg;
22680 };22621 };
22681 return sema.failWithOwnedErrorMsg(block, msg);22622 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -22700,11 +22641,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22700,11 +22641,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22700 }22641 }
22701 if (try sema.typeRequiresComptime(ptr_ty)) {22642 if (try sema.typeRequiresComptime(ptr_ty)) {
22702 return sema.failWithOwnedErrorMsg(block, msg: {22643 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)});
22704 errdefer msg.destroy(sema.gpa);22645 errdefer msg.destroy(sema.gpa);
2270522646
22706 const src_decl = mod.declPtr(block.src_decl);22647 try sema.explainWhyTypeIsComptime(msg, src, ptr_ty);
22707 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty);
22708 break :msg msg;22648 break :msg msg;
22709 });22649 });
22710 }22650 }
...@@ -22789,8 +22729,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -22789,8 +22729,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22789 const mod = sema.mod;22729 const mod = sema.mod;
22790 const ip = &mod.intern_pool;22730 const ip = &mod.intern_pool;
22791 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22731 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22792 const src = LazySrcLoc.nodeOffset(extra.node);22732 const src = block.nodeOffset(extra.node);
22793 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22733 const operand_src = block.builtinCallArgSrc(extra.node, 0);
22794 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");22734 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
22795 const operand = try sema.resolveInst(extra.rhs);22735 const operand = try sema.resolveInst(extra.rhs);
22796 const base_operand_ty = sema.typeOf(operand);22736 const base_operand_ty = sema.typeOf(operand);
...@@ -22810,12 +22750,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -22810,12 +22750,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22810 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())22750 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
22811 {22751 {
22812 return sema.failWithOwnedErrorMsg(block, msg: {22752 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", .{});
22814 errdefer msg.destroy(sema.gpa);22754 errdefer msg.destroy(sema.gpa);
22815 const dest_ty = base_dest_ty.errorUnionPayload(mod);22755 const dest_ty = base_dest_ty.errorUnionPayload(mod);
22816 const operand_ty = base_operand_ty.errorUnionPayload(mod);22756 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22817 try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});22757 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22818 try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});22758 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
22819 try addDeclaredHereNote(sema, msg, dest_ty);22759 try addDeclaredHereNote(sema, msg, dest_ty);
22820 try addDeclaredHereNote(sema, msg, operand_ty);22760 try addDeclaredHereNote(sema, msg, operand_ty);
22821 break :msg msg;22761 break :msg msg;
...@@ -22914,8 +22854,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa...@@ -22914,8 +22854,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
22914 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;22854 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
22915 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));22855 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
22916 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22856 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22917 const src = LazySrcLoc.nodeOffset(extra.node);22857 const src = block.nodeOffset(extra.node);
22918 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };22858 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
22919 const operand = try sema.resolveInst(extra.rhs);22859 const operand = try sema.resolveInst(extra.rhs);
22920 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());22860 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
22921 return sema.ptrCastFull(22861 return sema.ptrCastFull(
...@@ -22931,8 +22871,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa...@@ -22931,8 +22871,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2293122871
22932fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22872fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22933 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22934 const src = inst_data.src();22874 const src = block.nodeOffset(inst_data.src_node);
22935 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22875 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
22936 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22876 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22937 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");22877 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
22938 const operand = try sema.resolveInst(extra.rhs);22878 const operand = try sema.resolveInst(extra.rhs);
...@@ -23002,7 +22942,7 @@ fn ptrCastFull(...@@ -23002,7 +22942,7 @@ fn ptrCastFull(
23002 if (src_info.flags.size == .C) break :check_size;22942 if (src_info.flags.size == .C) break :check_size;
23003 if (dest_info.flags.size == .C) break :check_size;22943 if (dest_info.flags.size == .C) break :check_size;
23004 return sema.failWithOwnedErrorMsg(block, msg: {22944 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", .{
23006 pointerSizeString(src_info.flags.size),22946 pointerSizeString(src_info.flags.size),
23007 pointerSizeString(dest_info.flags.size),22947 pointerSizeString(dest_info.flags.size),
23008 });22948 });
...@@ -23011,9 +22951,9 @@ fn ptrCastFull(...@@ -23011,9 +22951,9 @@ fn ptrCastFull(
23011 (src_info.flags.size == .Slice or22951 (src_info.flags.size == .Slice or
23012 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))22952 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
23013 {22953 {
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", .{});
23015 } else {22955 } 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", .{});
23017 }22957 }
23018 break :msg msg;22958 break :msg msg;
23019 });22959 });
...@@ -23038,13 +22978,13 @@ fn ptrCastFull(...@@ -23038,13 +22978,13 @@ fn ptrCastFull(
23038 );22978 );
23039 if (imc_res == .ok) break :check_child;22979 if (imc_res == .ok) break :check_child;
23040 return sema.failWithOwnedErrorMsg(block, msg: {22980 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 '{}'", .{
23042 src_child.fmt(mod),22982 src_child.fmt(mod),
23043 dest_child.fmt(mod),22983 dest_child.fmt(mod),
23044 });22984 });
23045 errdefer msg.destroy(sema.gpa);22985 errdefer msg.destroy(sema.gpa);
23046 try imc_res.report(sema, block, src, msg);22986 try imc_res.report(sema, src, msg);
23047 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{});22987 try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{});
23048 break :msg msg;22988 break :msg msg;
23049 });22989 });
23050 }22990 }
...@@ -23066,41 +23006,41 @@ fn ptrCastFull(...@@ -23066,41 +23006,41 @@ fn ptrCastFull(
23066 }23006 }
23067 return sema.failWithOwnedErrorMsg(block, msg: {23007 return sema.failWithOwnedErrorMsg(block, msg: {
23068 const msg = if (src_info.sentinel == .none) blk: {23008 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", .{
23070 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),23010 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
23071 });23011 });
23072 } else blk: {23012 } 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 '{}'", .{
23074 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),23014 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),
23075 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),23015 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
23076 });23016 });
23077 };23017 };
23078 errdefer msg.destroy(sema.gpa);23018 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", .{});
23080 break :msg msg;23020 break :msg msg;
23081 });23021 });
23082 }23022 }
2308323023
23084 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {23024 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
23085 return sema.failWithOwnedErrorMsg(block, msg: {23025 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 '{}'", .{
23087 src_info.packed_offset.host_size,23027 src_info.packed_offset.host_size,
23088 dest_info.packed_offset.host_size,23028 dest_info.packed_offset.host_size,
23089 });23029 });
23090 errdefer msg.destroy(sema.gpa);23030 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", .{});
23092 break :msg msg;23032 break :msg msg;
23093 });23033 });
23094 }23034 }
2309523035
23096 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {23036 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
23097 return sema.failWithOwnedErrorMsg(block, msg: {23037 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 '{}'", .{
23099 src_info.packed_offset.bit_offset,23039 src_info.packed_offset.bit_offset,
23100 dest_info.packed_offset.bit_offset,23040 dest_info.packed_offset.bit_offset,
23101 });23041 });
23102 errdefer msg.destroy(sema.gpa);23042 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", .{});
23104 break :msg msg;23044 break :msg msg;
23105 });23045 });
23106 }23046 }
...@@ -23112,12 +23052,12 @@ fn ptrCastFull(...@@ -23112,12 +23052,12 @@ fn ptrCastFull(
23112 if (dest_allows_zero) break :check_allowzero;23052 if (dest_allows_zero) break :check_allowzero;
2311323053
23114 return sema.failWithOwnedErrorMsg(block, msg: {23054 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 '{}'", .{
23116 operand_ty.fmt(mod),23056 operand_ty.fmt(mod),
23117 dest_ty.fmt(mod),23057 dest_ty.fmt(mod),
23118 });23058 });
23119 errdefer msg.destroy(sema.gpa);23059 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", .{});
23121 break :msg msg;23061 break :msg msg;
23122 });23062 });
23123 }23063 }
...@@ -23138,15 +23078,15 @@ fn ptrCastFull(...@@ -23138,15 +23078,15 @@ fn ptrCastFull(
23138 if (!flags.align_cast) {23078 if (!flags.align_cast) {
23139 if (dest_align.compare(.gt, src_align)) {23079 if (dest_align.compare(.gt, src_align)) {
23140 return sema.failWithOwnedErrorMsg(block, msg: {23080 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});
23142 errdefer msg.destroy(sema.gpa);23082 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}'", .{
23144 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,23084 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,
23145 });23085 });
23146 try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{23086 try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{
23147 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,23087 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,
23148 });23088 });
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", .{});
23150 break :msg msg;23090 break :msg msg;
23151 });23091 });
23152 }23092 }
...@@ -23155,15 +23095,15 @@ fn ptrCastFull(...@@ -23155,15 +23095,15 @@ fn ptrCastFull(
23155 if (!flags.addrspace_cast) {23095 if (!flags.addrspace_cast) {
23156 if (src_info.flags.address_space != dest_info.flags.address_space) {23096 if (src_info.flags.address_space != dest_info.flags.address_space) {
23157 return sema.failWithOwnedErrorMsg(block, msg: {23097 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});
23159 errdefer msg.destroy(sema.gpa);23099 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}'", .{
23161 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),23101 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),
23162 });23102 });
23163 try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{23103 try sema.errNote(src, msg, "'{}' has address space '{s}'", .{
23164 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),23104 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),
23165 });23105 });
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", .{});
23167 break :msg msg;23107 break :msg msg;
23168 });23108 });
23169 }23109 }
...@@ -23171,9 +23111,9 @@ fn ptrCastFull(...@@ -23171,9 +23111,9 @@ fn ptrCastFull(
23171 // Some address space casts are always disallowed23111 // Some address space casts are always disallowed
23172 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {23112 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
23173 return sema.failWithOwnedErrorMsg(block, msg: {23113 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", .{});
23175 errdefer msg.destroy(sema.gpa);23115 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}'", .{
23177 @tagName(src_info.flags.address_space),23117 @tagName(src_info.flags.address_space),
23178 @tagName(dest_info.flags.address_space),23118 @tagName(dest_info.flags.address_space),
23179 });23119 });
...@@ -23185,9 +23125,9 @@ fn ptrCastFull(...@@ -23185,9 +23125,9 @@ fn ptrCastFull(
23185 if (!flags.const_cast) {23125 if (!flags.const_cast) {
23186 if (src_info.flags.is_const and !dest_info.flags.is_const) {23126 if (src_info.flags.is_const and !dest_info.flags.is_const) {
23187 return sema.failWithOwnedErrorMsg(block, msg: {23127 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});
23189 errdefer msg.destroy(sema.gpa);23129 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", .{});
23191 break :msg msg;23131 break :msg msg;
23192 });23132 });
23193 }23133 }
...@@ -23196,9 +23136,9 @@ fn ptrCastFull(...@@ -23196,9 +23136,9 @@ fn ptrCastFull(
23196 if (!flags.volatile_cast) {23136 if (!flags.volatile_cast) {
23197 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {23137 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
23198 return sema.failWithOwnedErrorMsg(block, msg: {23138 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});
23200 errdefer msg.destroy(sema.gpa);23140 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", .{});
23202 break :msg msg;23142 break :msg msg;
23203 });23143 });
23204 }23144 }
...@@ -23347,8 +23287,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -23347,8 +23287,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
23347 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;23287 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
23348 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));23288 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
23349 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;23289 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
23350 const src = LazySrcLoc.nodeOffset(extra.node);23290 const src = block.nodeOffset(extra.node);
23351 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };23291 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
23352 const operand = try sema.resolveInst(extra.operand);23292 const operand = try sema.resolveInst(extra.operand);
23353 const operand_ty = sema.typeOf(operand);23293 const operand_ty = sema.typeOf(operand);
23354 try sema.checkPtrOperand(block, operand_src, operand_ty);23294 try sema.checkPtrOperand(block, operand_src, operand_ty);
...@@ -23378,8 +23318,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -23378,8 +23318,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
23378fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23318fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23379 const mod = sema.mod;23319 const mod = sema.mod;
23380 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23320 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23381 const src = inst_data.src();23321 const src = block.nodeOffset(inst_data.src_node);
23382 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23322 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23383 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;23323 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
23384 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");23324 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
23385 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);23325 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...@@ -23417,16 +23357,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23417 if (operand_info.bits < dest_info.bits) {23357 if (operand_info.bits < dest_info.bits) {
23418 const msg = msg: {23358 const msg = msg: {
23419 const msg = try sema.errMsg(23359 const msg = try sema.errMsg(
23420 block,
23421 src,23360 src,
23422 "destination type '{}' has more bits than source type '{}'",23361 "destination type '{}' has more bits than source type '{}'",
23423 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },23362 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
23424 );23363 );
23425 errdefer msg.destroy(sema.gpa);23364 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", .{
23427 dest_info.bits,23366 dest_info.bits,
23428 });23367 });
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", .{
23430 operand_info.bits,23369 operand_info.bits,
23431 });23370 });
23432 break :msg msg;23371 break :msg msg;
...@@ -23468,8 +23407,8 @@ fn zirBitCount(...@@ -23468,8 +23407,8 @@ fn zirBitCount(
23468) CompileError!Air.Inst.Ref {23407) CompileError!Air.Inst.Ref {
23469 const mod = sema.mod;23408 const mod = sema.mod;
23470 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23409 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23471 const src = inst_data.src();23410 const src = block.nodeOffset(inst_data.src_node);
23472 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23411 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23473 const operand = try sema.resolveInst(inst_data.operand);23412 const operand = try sema.resolveInst(inst_data.operand);
23474 const operand_ty = sema.typeOf(operand);23413 const operand_ty = sema.typeOf(operand);
23475 _ = try sema.checkIntOrVector(block, operand, operand_src);23414 _ = try sema.checkIntOrVector(block, operand, operand_src);
...@@ -23522,8 +23461,8 @@ fn zirBitCount(...@@ -23522,8 +23461,8 @@ fn zirBitCount(
23522fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23461fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23523 const mod = sema.mod;23462 const mod = sema.mod;
23524 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23463 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23525 const src = inst_data.src();23464 const src = block.nodeOffset(inst_data.src_node);
23526 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23465 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23527 const operand = try sema.resolveInst(inst_data.operand);23466 const operand = try sema.resolveInst(inst_data.operand);
23528 const operand_ty = sema.typeOf(operand);23467 const operand_ty = sema.typeOf(operand);
23529 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);23468 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...@@ -23578,8 +23517,8 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2357823517
23579fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23518fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23580 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23519 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23581 const src = inst_data.src();23520 const src = block.nodeOffset(inst_data.src_node);
23582 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23521 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23583 const operand = try sema.resolveInst(inst_data.operand);23522 const operand = try sema.resolveInst(inst_data.operand);
23584 const operand_ty = sema.typeOf(operand);23523 const operand_ty = sema.typeOf(operand);
23585 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);23524 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...@@ -23637,9 +23576,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2363723576
23638fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {23577fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
23639 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23578 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23640 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };23579 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
23641 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };23580 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
23642 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };23581 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
23643 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;23582 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2364423583
23645 const ty = try sema.resolveType(block, lhs_src, extra.lhs);23584 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
...@@ -23752,14 +23691,13 @@ fn checkPtrOperand(...@@ -23752,14 +23691,13 @@ fn checkPtrOperand(
23752 .Fn => {23691 .Fn => {
23753 const msg = msg: {23692 const msg = msg: {
23754 const msg = try sema.errMsg(23693 const msg = try sema.errMsg(
23755 block,
23756 ty_src,23694 ty_src,
23757 "expected pointer, found '{}'",23695 "expected pointer, found '{}'",
23758 .{ty.fmt(mod)},23696 .{ty.fmt(mod)},
23759 );23697 );
23760 errdefer msg.destroy(sema.gpa);23698 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
23764 break :msg msg;23702 break :msg msg;
23765 };23703 };
...@@ -23784,14 +23722,13 @@ fn checkPtrType(...@@ -23784,14 +23722,13 @@ fn checkPtrType(
23784 .Fn => {23722 .Fn => {
23785 const msg = msg: {23723 const msg = msg: {
23786 const msg = try sema.errMsg(23724 const msg = try sema.errMsg(
23787 block,
23788 ty_src,23725 ty_src,
23789 "expected pointer type, found '{}'",23726 "expected pointer type, found '{}'",
23790 .{ty.fmt(mod)},23727 .{ty.fmt(mod)},
23791 );23728 );
23792 errdefer msg.destroy(sema.gpa);23729 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
23796 break :msg msg;23733 break :msg msg;
23797 };23734 };
...@@ -24045,26 +23982,26 @@ fn checkVectorizableBinaryOperands(...@@ -24045,26 +23982,26 @@ fn checkVectorizableBinaryOperands(
24045 const rhs_len = rhs_ty.arrayLen(mod);23982 const rhs_len = rhs_ty.arrayLen(mod);
24046 if (lhs_len != rhs_len) {23983 if (lhs_len != rhs_len) {
24047 const msg = msg: {23984 const msg = msg: {
24048 const msg = try sema.errMsg(block, src, "vector length mismatch", .{});23985 const msg = try sema.errMsg(src, "vector length mismatch", .{});
24049 errdefer msg.destroy(sema.gpa);23986 errdefer msg.destroy(sema.gpa);
24050 try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len});23987 try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len});
24051 try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len});23988 try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len});
24052 break :msg msg;23989 break :msg msg;
24053 };23990 };
24054 return sema.failWithOwnedErrorMsg(block, msg);23991 return sema.failWithOwnedErrorMsg(block, msg);
24055 }23992 }
24056 } else {23993 } else {
24057 const msg = msg: {23994 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 '{}'", .{
24059 lhs_ty.fmt(mod), rhs_ty.fmt(mod),23996 lhs_ty.fmt(mod), rhs_ty.fmt(mod),
24060 });23997 });
24061 errdefer msg.destroy(sema.gpa);23998 errdefer msg.destroy(sema.gpa);
24062 if (lhs_is_vector) {23999 if (lhs_is_vector) {
24063 try sema.errNote(block, lhs_src, msg, "vector here", .{});24000 try sema.errNote(lhs_src, msg, "vector here", .{});
24064 try sema.errNote(block, rhs_src, msg, "scalar here", .{});24001 try sema.errNote(rhs_src, msg, "scalar here", .{});
24065 } else {24002 } else {
24066 try sema.errNote(block, lhs_src, msg, "scalar here", .{});24003 try sema.errNote(lhs_src, msg, "scalar here", .{});
24067 try sema.errNote(block, rhs_src, msg, "vector here", .{});24004 try sema.errNote(rhs_src, msg, "vector here", .{});
24068 }24005 }
24069 break :msg msg;24006 break :msg msg;
24070 };24007 };
...@@ -24072,12 +24009,6 @@ fn checkVectorizableBinaryOperands(...@@ -24072,12 +24009,6 @@ fn checkVectorizableBinaryOperands(
24072 }24009 }
24073}24010}
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
24081fn resolveExportOptions(24012fn resolveExportOptions(
24082 sema: *Sema,24013 sema: *Sema,
24083 block: *Block,24014 block: *Block,
...@@ -24091,10 +24022,10 @@ fn resolveExportOptions(...@@ -24091,10 +24022,10 @@ fn resolveExportOptions(
24091 const air_ref = try sema.resolveInst(zir_ref);24022 const air_ref = try sema.resolveInst(zir_ref);
24092 const options = try sema.coerce(block, export_options_ty, air_ref, src);24023 const options = try sema.coerce(block, export_options_ty, air_ref, src);
2409324024
24094 const name_src = sema.maybeOptionsSrc(block, src, "name");24025 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24095 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");24026 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24096 const section_src = sema.maybeOptionsSrc(block, src, "section");24027 const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24097 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");24028 const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2409824029
24099 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);24030 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
24100 const name = try sema.toConstString(block, name_src, name_operand, .{24031 const name = try sema.toConstString(block, name_src, name_operand, .{
...@@ -24191,14 +24122,14 @@ fn zirCmpxchg(...@@ -24191,14 +24122,14 @@ fn zirCmpxchg(
24191 1 => .cmpxchg_strong,24122 1 => .cmpxchg_strong,
24192 else => unreachable,24123 else => unreachable,
24193 };24124 };
24194 const src = LazySrcLoc.nodeOffset(extra.node);24125 const src = block.nodeOffset(extra.node);
24195 // zig fmt: off24126 // zig fmt: off
24196 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };24127 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24197 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };24128 const ptr_src = block.builtinCallArgSrc(extra.node, 1);
24198 const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };24129 const expected_src = block.builtinCallArgSrc(extra.node, 2);
24199 const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };24130 const new_value_src = block.builtinCallArgSrc(extra.node, 3);
24200 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node };24131 const success_order_src = block.builtinCallArgSrc(extra.node, 4);
24201 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node };24132 const failure_order_src = block.builtinCallArgSrc(extra.node, 5);
24202 // zig fmt: on24133 // zig fmt: on
24203 const expected_value = try sema.resolveInst(extra.expected_value);24134 const expected_value = try sema.resolveInst(extra.expected_value);
24204 const elem_ty = sema.typeOf(expected_value);24135 const elem_ty = sema.typeOf(expected_value);
...@@ -24287,8 +24218,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -24287,8 +24218,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
24287 const mod = sema.mod;24218 const mod = sema.mod;
24288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24219 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24289 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;24220 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24290 const src = inst_data.src();24221 const src = block.nodeOffset(inst_data.src_node);
24291 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24222 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24292 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");24223 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2429324224
24294 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});24225 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...@@ -24309,15 +24240,15 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
24309 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());24240 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
24310 }24241 }
2431124242
24312 try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src);24243 try sema.requireRuntimeBlock(block, src, scalar_src);
24313 return block.addTyOp(.splat, dest_ty, scalar);24244 return block.addTyOp(.splat, dest_ty, scalar);
24314}24245}
2431524246
24316fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24247fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24317 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24248 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24318 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;24249 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 };24250 const op_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24320 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24251 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24321 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{24252 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
24322 .needed_comptime_reason = "@reduce operation must be comptime-known",24253 .needed_comptime_reason = "@reduce operation must be comptime-known",
24323 });24254 });
...@@ -24374,7 +24305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24374,7 +24305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24374 return Air.internedToRef(accum.toIntern());24305 return Air.internedToRef(accum.toIntern());
24375 }24306 }
2437624307
24377 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);24308 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src);
24378 return block.addInst(.{24309 return block.addInst(.{
24379 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,24310 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
24380 .data = .{ .reduce = .{24311 .data = .{ .reduce = .{
...@@ -24388,8 +24319,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -24388,8 +24319,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
24388 const mod = sema.mod;24319 const mod = sema.mod;
24389 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24320 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24390 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;24321 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 };24322 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24392 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24323 const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2439324324
24394 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24325 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24395 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);24326 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
...@@ -24424,9 +24355,9 @@ fn analyzeShuffle(...@@ -24424,9 +24355,9 @@ fn analyzeShuffle(
24424 mask_len: u32,24355 mask_len: u32,
24425) CompileError!Air.Inst.Ref {24356) CompileError!Air.Inst.Ref {
24426 const mod = sema.mod;24357 const mod = sema.mod;
24427 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node };24358 const a_src = block.builtinCallArgSrc(src_node, 1);
24428 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node };24359 const b_src = block.builtinCallArgSrc(src_node, 2);
24429 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node };24360 const mask_src = block.builtinCallArgSrc(src_node, 3);
24430 var a = a_arg;24361 var a = a_arg;
24431 var b = b_arg;24362 var b = b_arg;
2443224363
...@@ -24490,16 +24421,16 @@ fn analyzeShuffle(...@@ -24490,16 +24421,16 @@ fn analyzeShuffle(
24490 }24421 }
24491 if (unsigned >= operand_info[chosen][0]) {24422 if (unsigned >= operand_info[chosen][0]) {
24492 const msg = msg: {24423 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});
24494 errdefer msg.destroy(sema.gpa);24425 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 '{}'", .{
24497 unsigned,24428 unsigned,
24498 operand_info[chosen][2].fmt(sema.mod),24429 operand_info[chosen][2].fmt(sema.mod),
24499 });24430 });
2450024431
24501 if (chosen == 0) {24432 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", .{});
24503 }24434 }
2450424435
24505 break :msg msg;24436 break :msg msg;
...@@ -24577,11 +24508,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -24577,11 +24508,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
24577 const mod = sema.mod;24508 const mod = sema.mod;
24578 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;24509 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2457924510
24580 const src = LazySrcLoc.nodeOffset(extra.node);24511 const src = block.nodeOffset(extra.node);
24581 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };24512 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24582 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };24513 const pred_src = block.builtinCallArgSrc(extra.node, 1);
24583 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };24514 const a_src = block.builtinCallArgSrc(extra.node, 2);
24584 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };24515 const b_src = block.builtinCallArgSrc(extra.node, 3);
2458524516
24586 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24517 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24587 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);24518 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
...@@ -24668,9 +24599,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -24668,9 +24599,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
24668 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24599 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24669 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;24600 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
24670 // zig fmt: off24601 // zig fmt: off
24671 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24602 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24672 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24603 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24673 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24604 const order_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24674 // zig fmt: on24605 // zig fmt: on
24675 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24606 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24676 const uncasted_ptr = try sema.resolveInst(extra.ptr);24607 const uncasted_ptr = try sema.resolveInst(extra.ptr);
...@@ -24701,7 +24632,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -24701,7 +24632,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
24701 }24632 }
24702 }24633 }
2470324634
24704 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);24635 try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src);
24705 return block.addInst(.{24636 return block.addInst(.{
24706 .tag = .atomic_load,24637 .tag = .atomic_load,
24707 .data = .{ .atomic_load = .{24638 .data = .{ .atomic_load = .{
...@@ -24715,13 +24646,13 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -24715,13 +24646,13 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
24715 const mod = sema.mod;24646 const mod = sema.mod;
24716 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24647 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24717 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;24648 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);
24719 // zig fmt: off24650 // zig fmt: off
24720 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24651 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24721 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24652 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24722 const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24653 const op_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24723 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24654 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24724 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };24655 const order_src = block.builtinCallArgSrc(inst_data.src_node, 4);
24725 // zig fmt: on24656 // zig fmt: on
24726 const operand = try sema.resolveInst(extra.operand);24657 const operand = try sema.resolveInst(extra.operand);
24727 const elem_ty = sema.typeOf(operand);24658 const elem_ty = sema.typeOf(operand);
...@@ -24800,12 +24731,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -24800,12 +24731,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
24800fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {24731fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
24801 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24802 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;24733 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);
24804 // zig fmt: off24735 // zig fmt: off
24805 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24736 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24806 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24737 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24807 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24738 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24808 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24739 const order_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24809 // zig fmt: on24740 // zig fmt: on
24810 const operand = try sema.resolveInst(extra.operand);24741 const operand = try sema.resolveInst(extra.operand);
24811 const elem_ty = sema.typeOf(operand);24742 const elem_ty = sema.typeOf(operand);
...@@ -24836,11 +24767,11 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -24836,11 +24767,11 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
24836fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24767fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24837 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24768 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24838 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;24769 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 };24772 const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24842 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24773 const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24843 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24774 const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2484424775
24845 const addend = try sema.resolveInst(extra.addend);24776 const addend = try sema.resolveInst(extra.addend);
24846 const ty = sema.typeOf(addend);24777 const ty = sema.typeOf(addend);
...@@ -24903,10 +24834,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -24903,10 +24834,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2490324834
24904 const mod = sema.mod;24835 const mod = sema.mod;
24905 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24836 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 };24837 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24907 const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24838 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24908 const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24839 const args_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24909 const call_src = inst_data.src();24840 const call_src = block.nodeOffset(inst_data.src_node);
2491024841
24911 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;24842 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
24912 const func = try sema.resolveInst(extra.callee);24843 const func = try sema.resolveInst(extra.callee);
...@@ -25000,9 +24931,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25000,9 +24931,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25000 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;24931 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
25001 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));24932 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
25002 assert(!flags.ptr_cast);24933 assert(!flags.ptr_cast);
25003 const inst_src = extra.src();24934 const inst_src = block.nodeOffset(extra.src_node);
25004 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node };24935 const field_name_src = block.builtinCallArgSrc(extra.src_node, 0);
25005 const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node };24936 const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1);
2500624937
25007 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");24938 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");
25008 try sema.checkPtrType(block, inst_src, parent_ptr_ty, true);24939 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...@@ -25191,9 +25122,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte
25191 };25122 };
25192 if (ptr.byte_offset < byte_subtract) {25123 if (ptr.byte_offset < byte_subtract) {
25193 return sema.failWithOwnedErrorMsg(block, msg: {25124 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", .{});
25195 errdefer msg.destroy(sema.gpa);25126 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", .{});
25197 break :msg msg;25128 break :msg msg;
25198 });25129 });
25199 }25130 }
...@@ -25210,9 +25141,9 @@ fn zirMinMax(...@@ -25210,9 +25141,9 @@ fn zirMinMax(
25210) CompileError!Air.Inst.Ref {25141) CompileError!Air.Inst.Ref {
25211 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25142 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25212 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25143 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25213 const src = inst_data.src();25144 const src = block.nodeOffset(inst_data.src_node);
25214 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25145 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25215 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25146 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25216 const lhs = try sema.resolveInst(extra.lhs);25147 const lhs = try sema.resolveInst(extra.lhs);
25217 const rhs = try sema.resolveInst(extra.rhs);25148 const rhs = try sema.resolveInst(extra.rhs);
25218 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));25149 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
...@@ -25228,22 +25159,14 @@ fn zirMinMaxMulti(...@@ -25228,22 +25159,14 @@ fn zirMinMaxMulti(
25228) CompileError!Air.Inst.Ref {25159) CompileError!Air.Inst.Ref {
25229 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);25160 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
25230 const src_node = extra.data.src_node;25161 const src_node = extra.data.src_node;
25231 const src = LazySrcLoc.nodeOffset(src_node);25162 const src = block.nodeOffset(src_node);
25232 const operands = sema.code.refSlice(extra.end, extended.small);25163 const operands = sema.code.refSlice(extra.end, extended.small);
2523325164
25234 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);25165 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
25235 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);25166 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);
2523625167
25237 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {25168 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {
25238 op_src.* = switch (i) {25169 op_src.* = block.builtinCallArgSrc(src_node, @intCast(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 };
25247 air_ref.* = try sema.resolveInst(zir_ref);25170 air_ref.* = try sema.resolveInst(zir_ref);
25248 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));25171 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));
25249 }25172 }
...@@ -25511,9 +25434,9 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A...@@ -25511,9 +25434,9 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
25511fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {25434fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
25512 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25435 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25513 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25436 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25514 const src = inst_data.src();25437 const src = block.nodeOffset(inst_data.src_node);
25515 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25438 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25516 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25439 const src_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25517 const dest_ptr = try sema.resolveInst(extra.lhs);25440 const dest_ptr = try sema.resolveInst(extra.lhs);
25518 const src_ptr = try sema.resolveInst(extra.rhs);25441 const src_ptr = try sema.resolveInst(extra.rhs);
25519 const dest_ty = sema.typeOf(dest_ptr);25442 const dest_ty = sema.typeOf(dest_ptr);
...@@ -25529,12 +25452,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25529,12 +25452,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2552925452
25530 if (dest_len == .none and src_len == .none) {25453 if (dest_len == .none and src_len == .none) {
25531 const msg = msg: {25454 const msg = msg: {
25532 const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{});25455 const msg = try sema.errMsg(src, "unknown @memcpy length", .{});
25533 errdefer msg.destroy(sema.gpa);25456 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", .{
25535 dest_ty.fmt(sema.mod),25458 dest_ty.fmt(sema.mod),
25536 });25459 });
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", .{
25538 src_ty.fmt(sema.mod),25461 src_ty.fmt(sema.mod),
25539 });25462 });
25540 break :msg msg;25463 break :msg msg;
...@@ -25551,12 +25474,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25551,12 +25474,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25551 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {25474 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
25552 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {25475 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
25553 const msg = msg: {25476 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", .{});
25555 errdefer msg.destroy(sema.gpa);25478 errdefer msg.destroy(sema.gpa);
25556 try sema.errNote(block, dest_src, msg, "length {} here", .{25479 try sema.errNote(dest_src, msg, "length {} here", .{
25557 dest_len_val.fmtValue(sema.mod, sema),25480 dest_len_val.fmtValue(sema.mod, sema),
25558 });25481 });
25559 try sema.errNote(block, src_src, msg, "length {} here", .{25482 try sema.errNote(src_src, msg, "length {} here", .{
25560 src_len_val.fmtValue(sema.mod, sema),25483 src_len_val.fmtValue(sema.mod, sema),
25561 });25484 });
25562 break :msg msg;25485 break :msg msg;
...@@ -25664,7 +25587,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25664,7 +25587,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25664 } else if (dest_len == .none and len_val == null) {25587 } else if (dest_len == .none and len_val == null) {
25665 // Change the dest to a slice, since its type must have the length.25588 // Change the dest to a slice, since its type must have the length.
25666 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);25589 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);
25668 const new_src_ptr_ty = sema.typeOf(new_src_ptr);25591 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25669 if (new_src_ptr_ty.isSlice(mod)) {25592 if (new_src_ptr_ty.isSlice(mod)) {
25670 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);25593 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...@@ -25731,9 +25654,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25731 const ip = &mod.intern_pool;25654 const ip = &mod.intern_pool;
25732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25655 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25733 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25656 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25734 const src = inst_data.src();25657 const src = block.nodeOffset(inst_data.src_node);
25735 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25658 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25736 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25659 const value_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25737 const dest_ptr = try sema.resolveInst(extra.lhs);25660 const dest_ptr = try sema.resolveInst(extra.lhs);
25738 const uncoerced_elem = try sema.resolveInst(extra.rhs);25661 const uncoerced_elem = try sema.resolveInst(extra.rhs);
25739 const dest_ptr_ty = sema.typeOf(dest_ptr);25662 const dest_ptr_ty = sema.typeOf(dest_ptr);
...@@ -25755,9 +25678,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25755,9 +25678,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25755 .Many, .C => {},25678 .Many, .C => {},
25756 }25679 }
25757 return sema.failWithOwnedErrorMsg(block, msg: {25680 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", .{});
25759 errdefer msg.destroy(sema.gpa);25682 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", .{
25761 dest_ptr_ty.fmt(mod),25684 dest_ptr_ty.fmt(mod),
25762 });25685 });
25763 break :msg msg;25686 break :msg msg;
...@@ -25810,13 +25733,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25810,13 +25733,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2581025733
25811fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {25734fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
25812 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;25735 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);
25814 return sema.failWithUseOfAsync(block, src);25737 return sema.failWithUseOfAsync(block, src);
25815}25738}
2581625739
25817fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {25740fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
25818 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;25741 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);
25820 return sema.failWithUseOfAsync(block, src);25743 return sema.failWithUseOfAsync(block, src);
25821}25744}
2582225745
...@@ -25826,7 +25749,7 @@ fn zirAwait(...@@ -25826,7 +25749,7 @@ fn zirAwait(
25826 inst: Zir.Inst.Index,25749 inst: Zir.Inst.Index,
25827) CompileError!Air.Inst.Ref {25750) CompileError!Air.Inst.Ref {
25828 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;25751 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
25831 return sema.failWithUseOfAsync(block, src);25754 return sema.failWithUseOfAsync(block, src);
25832}25755}
...@@ -25837,7 +25760,7 @@ fn zirAwaitNosuspend(...@@ -25837,7 +25760,7 @@ fn zirAwaitNosuspend(
25837 extended: Zir.Inst.Extended.InstData,25760 extended: Zir.Inst.Extended.InstData,
25838) CompileError!Air.Inst.Ref {25761) CompileError!Air.Inst.Ref {
25839 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;25762 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
25842 return sema.failWithUseOfAsync(block, src);25765 return sema.failWithUseOfAsync(block, src);
25843}25766}
...@@ -25849,8 +25772,8 @@ fn zirVarExtended(...@@ -25849,8 +25772,8 @@ fn zirVarExtended(
25849) CompileError!Air.Inst.Ref {25772) CompileError!Air.Inst.Ref {
25850 const mod = sema.mod;25773 const mod = sema.mod;
25851 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);25774 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
25852 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };25775 const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 });
25853 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };25776 const init_src = block.src(.{ .node_offset_var_decl_init = 0 });
25854 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);25777 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);
2585525778
25856 var extra_index: usize = extra.end;25779 var extra_index: usize = extra.end;
...@@ -25915,11 +25838,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -25915,11 +25838,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
25915 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);25838 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
25916 const target = mod.getTarget();25839 const target = mod.getTarget();
2591725840
25918 const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node };25841 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
25919 const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node };25842 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
25920 const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node };25843 const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node });
25921 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };25844 const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node });
25922 const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };25845 const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
25923 const has_body = extra.data.body_len != 0;25846 const has_body = extra.data.body_len != 0;
2592425847
25925 var extra_index: usize = extra.end;25848 var extra_index: usize = extra.end;
...@@ -26146,7 +26069,7 @@ fn zirCUndef(...@@ -26146,7 +26069,7 @@ fn zirCUndef(
26146 extended: Zir.Inst.Extended.InstData,26069 extended: Zir.Inst.Extended.InstData,
26147) CompileError!Air.Inst.Ref {26070) CompileError!Air.Inst.Ref {
26148 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26071 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
26151 const name = try sema.resolveConstString(block, src, extra.operand, .{26074 const name = try sema.resolveConstString(block, src, extra.operand, .{
26152 .needed_comptime_reason = "name of macro being undefined must be comptime-known",26075 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
...@@ -26161,7 +26084,7 @@ fn zirCInclude(...@@ -26161,7 +26084,7 @@ fn zirCInclude(
26161 extended: Zir.Inst.Extended.InstData,26084 extended: Zir.Inst.Extended.InstData,
26162) CompileError!Air.Inst.Ref {26085) CompileError!Air.Inst.Ref {
26163 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26086 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
26166 const name = try sema.resolveConstString(block, src, extra.operand, .{26089 const name = try sema.resolveConstString(block, src, extra.operand, .{
26167 .needed_comptime_reason = "path being included must be comptime-known",26090 .needed_comptime_reason = "path being included must be comptime-known",
...@@ -26177,8 +26100,8 @@ fn zirCDefine(...@@ -26177,8 +26100,8 @@ fn zirCDefine(
26177) CompileError!Air.Inst.Ref {26100) CompileError!Air.Inst.Ref {
26178 const mod = sema.mod;26101 const mod = sema.mod;
26179 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26102 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26180 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26103 const name_src = block.builtinCallArgSrc(extra.node, 0);
26181 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26104 const val_src = block.builtinCallArgSrc(extra.node, 1);
2618226105
26183 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{26106 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
26184 .needed_comptime_reason = "name of macro being undefined must be comptime-known",26107 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
...@@ -26201,8 +26124,8 @@ fn zirWasmMemorySize(...@@ -26201,8 +26124,8 @@ fn zirWasmMemorySize(
26201 extended: Zir.Inst.Extended.InstData,26124 extended: Zir.Inst.Extended.InstData,
26202) CompileError!Air.Inst.Ref {26125) CompileError!Air.Inst.Ref {
26203 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26126 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26204 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26127 const index_src = block.builtinCallArgSrc(extra.node, 0);
26205 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26128 const builtin_src = block.nodeOffset(extra.node);
26206 const target = sema.mod.getTarget();26129 const target = sema.mod.getTarget();
26207 if (!target.isWasm()) {26130 if (!target.isWasm()) {
26208 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26131 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(...@@ -26227,9 +26150,9 @@ fn zirWasmMemoryGrow(
26227 extended: Zir.Inst.Extended.InstData,26150 extended: Zir.Inst.Extended.InstData,
26228) CompileError!Air.Inst.Ref {26151) CompileError!Air.Inst.Ref {
26229 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26152 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26230 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26153 const builtin_src = block.nodeOffset(extra.node);
26231 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26154 const index_src = block.builtinCallArgSrc(extra.node, 0);
26232 const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26155 const delta_src = block.builtinCallArgSrc(extra.node, 1);
26233 const target = sema.mod.getTarget();26156 const target = sema.mod.getTarget();
26234 if (!target.isWasm()) {26157 if (!target.isWasm()) {
26235 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26158 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(...@@ -26262,9 +26185,9 @@ fn resolvePrefetchOptions(
26262 const options_ty = try sema.getBuiltinType("PrefetchOptions");26185 const options_ty = try sema.getBuiltinType("PrefetchOptions");
26263 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);26186 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2626426187
26265 const rw_src = sema.maybeOptionsSrc(block, src, "rw");26188 const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26266 const locality_src = sema.maybeOptionsSrc(block, src, "locality");26189 const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26267 const cache_src = sema.maybeOptionsSrc(block, src, "cache");26190 const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2626826191
26269 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);26192 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
26270 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{26193 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
...@@ -26294,18 +26217,12 @@ fn zirPrefetch(...@@ -26294,18 +26217,12 @@ fn zirPrefetch(
26294 extended: Zir.Inst.Extended.InstData,26217 extended: Zir.Inst.Extended.InstData,
26295) CompileError!Air.Inst.Ref {26218) CompileError!Air.Inst.Ref {
26296 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26219 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26297 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26220 const ptr_src = block.builtinCallArgSrc(extra.node, 0);
26298 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26221 const opts_src = block.builtinCallArgSrc(extra.node, 1);
26299 const ptr = try sema.resolveInst(extra.lhs);26222 const ptr = try sema.resolveInst(extra.lhs);
26300 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));26223 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
2630126224
26302 const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {26225 const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26303 error.NeededSourceLocation => {
26304 _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26305 unreachable;
26306 },
26307 else => |e| return e,
26308 };
2630926226
26310 if (!block.is_comptime) {26227 if (!block.is_comptime) {
26311 _ = try block.addInst(.{26228 _ = try block.addInst(.{
...@@ -26340,10 +26257,10 @@ fn resolveExternOptions(...@@ -26340,10 +26257,10 @@ fn resolveExternOptions(
26340 const extern_options_ty = try sema.getBuiltinType("ExternOptions");26257 const extern_options_ty = try sema.getBuiltinType("ExternOptions");
26341 const options = try sema.coerce(block, extern_options_ty, options_inst, src);26258 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
2634226259
26343 const name_src = sema.maybeOptionsSrc(block, src, "name");26260 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26344 const library_src = sema.maybeOptionsSrc(block, src, "library");26261 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26345 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");26262 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26346 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");26263 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2634726264
26348 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);26265 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
26349 const name = try sema.toConstString(block, name_src, name_ref, .{26266 const name = try sema.toConstString(block, name_src, name_ref, .{
...@@ -26401,8 +26318,8 @@ fn zirBuiltinExtern(...@@ -26401,8 +26318,8 @@ fn zirBuiltinExtern(
26401 const mod = sema.mod;26318 const mod = sema.mod;
26402 const ip = &mod.intern_pool;26319 const ip = &mod.intern_pool;
26403 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26320 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26404 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26321 const ty_src = block.builtinCallArgSrc(extra.node, 0);
26405 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26322 const options_src = block.builtinCallArgSrc(extra.node, 1);
2640626323
26407 var ty = try sema.resolveType(block, ty_src, extra.lhs);26324 var ty = try sema.resolveType(block, ty_src, extra.lhs);
26408 if (!ty.isPtrAtRuntime(mod)) {26325 if (!ty.isPtrAtRuntime(mod)) {
...@@ -26410,29 +26327,22 @@ fn zirBuiltinExtern(...@@ -26410,29 +26327,22 @@ fn zirBuiltinExtern(
26410 }26327 }
26411 if (!try sema.validateExternType(ty, .other)) {26328 if (!try sema.validateExternType(ty, .other)) {
26412 const msg = msg: {26329 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)});
26414 errdefer msg.destroy(sema.gpa);26331 errdefer msg.destroy(sema.gpa);
26415 const src_decl = sema.mod.declPtr(block.src_decl);26332 try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other);
26416 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other);
26417 break :msg msg;26333 break :msg msg;
26418 };26334 };
26419 return sema.failWithOwnedErrorMsg(block, msg);26335 return sema.failWithOwnedErrorMsg(block, msg);
26420 }26336 }
2642126337
26422 const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {26338 const options = try sema.resolveExternOptions(block, options_src, extra.rhs);
26423 error.NeededSourceLocation => {
26424 _ = try sema.resolveExternOptions(block, options_src, extra.rhs);
26425 unreachable;
26426 },
26427 else => |e| return e,
26428 };
2642926339
26430 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {26340 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
26431 ty = try mod.optionalType(ty.toIntern());26341 ty = try mod.optionalType(ty.toIntern());
26432 }26342 }
26433 const ptr_info = ty.ptrInfo(mod);26343 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);
26436 errdefer mod.destroyDecl(new_decl_index);26346 errdefer mod.destroyDecl(new_decl_index);
26437 const new_decl = mod.declPtr(new_decl_index);26347 const new_decl = mod.declPtr(new_decl_index);
26438 try mod.initNewAnonDecl(26348 try mod.initNewAnonDecl(
...@@ -26482,8 +26392,8 @@ fn zirWorkItem(...@@ -26482,8 +26392,8 @@ fn zirWorkItem(
26482 zir_tag: Zir.Inst.Extended,26392 zir_tag: Zir.Inst.Extended,
26483) CompileError!Air.Inst.Ref {26393) CompileError!Air.Inst.Ref {
26484 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26394 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26485 const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26395 const dimension_src = block.builtinCallArgSrc(extra.node, 0);
26486 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26396 const builtin_src = block.nodeOffset(extra.node);
26487 const target = sema.mod.getTarget();26397 const target = sema.mod.getTarget();
2648826398
26489 switch (target.cpu.arch) {26399 switch (target.cpu.arch) {
...@@ -26524,11 +26434,11 @@ fn zirInComptime(...@@ -26524,11 +26434,11 @@ fn zirInComptime(
26524fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {26434fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
26525 if (block.is_comptime) {26435 if (block.is_comptime) {
26526 const msg = msg: {26436 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", .{});
26528 errdefer msg.destroy(sema.gpa);26438 errdefer msg.destroy(sema.gpa);
2652926439
26530 if (runtime_src) |some| {26440 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", .{});
26532 }26442 }
26533 if (block.comptime_reason) |some| {26443 if (block.comptime_reason) |some| {
26534 try some.explain(sema, msg);26444 try some.explain(sema, msg);
...@@ -26551,10 +26461,9 @@ fn validateVarType(...@@ -26551,10 +26461,9 @@ fn validateVarType(
26551 if (is_extern) {26461 if (is_extern) {
26552 if (!try sema.validateExternType(var_ty, .other)) {26462 if (!try sema.validateExternType(var_ty, .other)) {
26553 const msg = msg: {26463 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)});
26555 errdefer msg.destroy(sema.gpa);26465 errdefer msg.destroy(sema.gpa);
26556 const src_decl = mod.declPtr(block.src_decl);26466 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
26557 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other);
26558 break :msg msg;26467 break :msg msg;
26559 };26468 };
26560 return sema.failWithOwnedErrorMsg(block, msg);26469 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -26573,13 +26482,12 @@ fn validateVarType(...@@ -26573,13 +26482,12 @@ fn validateVarType(
26573 if (!try sema.typeRequiresComptime(var_ty)) return;26482 if (!try sema.typeRequiresComptime(var_ty)) return;
2657426483
26575 const msg = msg: {26484 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)});
26577 errdefer msg.destroy(sema.gpa);26486 errdefer msg.destroy(sema.gpa);
2657826487
26579 const src_decl = mod.declPtr(block.src_decl);26488 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
26580 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty);
26581 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {26489 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", .{});
26583 }26491 }
2658426492
26585 break :msg msg;26493 break :msg msg;
...@@ -26592,7 +26500,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);...@@ -26592,7 +26500,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
26592fn explainWhyTypeIsComptime(26500fn explainWhyTypeIsComptime(
26593 sema: *Sema,26501 sema: *Sema,
26594 msg: *Module.ErrorMsg,26502 msg: *Module.ErrorMsg,
26595 src_loc: Module.SrcLoc,26503 src_loc: LazySrcLoc,
26596 ty: Type,26504 ty: Type,
26597) CompileError!void {26505) CompileError!void {
26598 var type_set = TypeSet{};26506 var type_set = TypeSet{};
...@@ -26605,7 +26513,7 @@ fn explainWhyTypeIsComptime(...@@ -26605,7 +26513,7 @@ fn explainWhyTypeIsComptime(
26605fn explainWhyTypeIsComptimeInner(26513fn explainWhyTypeIsComptimeInner(
26606 sema: *Sema,26514 sema: *Sema,
26607 msg: *Module.ErrorMsg,26515 msg: *Module.ErrorMsg,
26608 src_loc: Module.SrcLoc,26516 src_loc: LazySrcLoc,
26609 ty: Type,26517 ty: Type,
26610 type_set: *TypeSet,26518 type_set: *TypeSet,
26611) CompileError!void {26519) CompileError!void {
...@@ -26623,13 +26531,13 @@ fn explainWhyTypeIsComptimeInner(...@@ -26623,13 +26531,13 @@ fn explainWhyTypeIsComptimeInner(
26623 => return,26531 => return,
2662426532
26625 .Fn => {26533 .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", .{
26627 ty.fmt(sema.mod),26535 ty.fmt(sema.mod),
26628 });26536 });
26629 },26537 },
2663026538
26631 .Type => {26539 .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", .{});
26633 },26541 },
2663426542
26635 .ComptimeFloat,26543 .ComptimeFloat,
...@@ -26641,7 +26549,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26641,7 +26549,7 @@ fn explainWhyTypeIsComptimeInner(
26641 => return,26549 => return,
2664226550
26643 .Opaque => {26551 .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)});
26645 },26553 },
2664626554
26647 .Array, .Vector => {26555 .Array, .Vector => {
...@@ -26652,14 +26560,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26652,14 +26560,14 @@ fn explainWhyTypeIsComptimeInner(
26652 if (elem_ty.zigTypeTag(mod) == .Fn) {26560 if (elem_ty.zigTypeTag(mod) == .Fn) {
26653 const fn_info = mod.typeToFunc(elem_ty).?;26561 const fn_info = mod.typeToFunc(elem_ty).?;
26654 if (fn_info.is_generic) {26562 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", .{});
26656 }26564 }
26657 switch (fn_info.cc) {26565 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", .{}),
26659 else => {},26567 else => {},
26660 }26568 }
26661 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {26569 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", .{});
26663 }26571 }
26664 return;26572 return;
26665 }26573 }
...@@ -26679,14 +26587,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26679,14 +26587,14 @@ fn explainWhyTypeIsComptimeInner(
26679 if (mod.typeToStruct(ty)) |struct_type| {26587 if (mod.typeToStruct(ty)) |struct_type| {
26680 for (0..struct_type.field_types.len) |i| {26588 for (0..struct_type.field_types.len) |i| {
26681 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);26589 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26682 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{26590 const field_src: LazySrcLoc = .{
26683 .index = i,26591 .base_node_inst = struct_type.zir_index.unwrap().?,
26684 .range = .type,26592 .offset = .{ .container_field_type = @intCast(i) },
26685 });26593 };
2668626594
26687 if (try sema.typeRequiresComptime(field_ty)) {26595 if (try sema.typeRequiresComptime(field_ty)) {
26688 try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});26596 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
26689 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);26597 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26690 }26598 }
26691 }26599 }
26692 }26600 }
...@@ -26699,14 +26607,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26699,14 +26607,14 @@ fn explainWhyTypeIsComptimeInner(
26699 if (mod.typeToUnion(ty)) |union_obj| {26607 if (mod.typeToUnion(ty)) |union_obj| {
26700 for (0..union_obj.field_types.len) |i| {26608 for (0..union_obj.field_types.len) |i| {
26701 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);26609 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26702 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{26610 const field_src: LazySrcLoc = .{
26703 .index = i,26611 .base_node_inst = union_obj.zir_index,
26704 .range = .type,26612 .offset = .{ .container_field_type = @intCast(i) },
26705 });26613 };
2670626614
26707 if (try sema.typeRequiresComptime(field_ty)) {26615 if (try sema.typeRequiresComptime(field_ty)) {
26708 try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});26616 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
26709 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);26617 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26710 }26618 }
26711 }26619 }
26712 }26620 }
...@@ -26796,7 +26704,7 @@ fn validateExternType(...@@ -26796,7 +26704,7 @@ fn validateExternType(
26796fn explainWhyTypeIsNotExtern(26704fn explainWhyTypeIsNotExtern(
26797 sema: *Sema,26705 sema: *Sema,
26798 msg: *Module.ErrorMsg,26706 msg: *Module.ErrorMsg,
26799 src_loc: Module.SrcLoc,26707 src_loc: LazySrcLoc,
26800 ty: Type,26708 ty: Type,
26801 position: ExternPosition,26709 position: ExternPosition,
26802) CompileError!void {26710) CompileError!void {
...@@ -26821,55 +26729,55 @@ fn explainWhyTypeIsNotExtern(...@@ -26821,55 +26729,55 @@ fn explainWhyTypeIsNotExtern(
2682126729
26822 .Pointer => {26730 .Pointer => {
26823 if (ty.isSlice(mod)) {26731 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", .{});
26825 } else {26733 } else {
26826 const pointee_ty = ty.childType(mod);26734 const pointee_ty = ty.childType(mod);
26827 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {26735 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'", .{});
26829 } else if (try sema.typeRequiresComptime(ty)) {26737 } 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)});
26831 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);26739 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
26832 }26740 }
26833 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);26741 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);
26834 }26742 }
26835 },26743 },
26836 .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),26744 .Void => try sema.errNote(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", .{}),26745 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
26838 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {26746 .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", .{});
26840 } else {26748 } 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", .{});
26842 },26750 },
26843 .Fn => {26751 .Fn => {
26844 if (position != .other) {26752 if (position != .other) {
26845 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});26753 try sema.errNote(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", .{});26754 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26847 return;26755 return;
26848 }26756 }
26849 switch (ty.fnCallingConvention(mod)) {26757 switch (ty.fnCallingConvention(mod)) {
26850 .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}),26758 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
26851 .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}),26759 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
26852 .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}),26760 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
26853 else => return,26761 else => return,
26854 }26762 }
26855 },26763 },
26856 .Enum => {26764 .Enum => {
26857 const tag_ty = ty.intTagType(mod);26765 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)});
26859 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);26767 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
26860 },26768 },
26861 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),26769 .Struct => try sema.errNote(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", .{}),26770 .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
26863 .Array => {26771 .Array => {
26864 if (position == .ret_ty) {26772 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", .{});
26866 } else if (position == .param_ty) {26774 } 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", .{});
26868 }26776 }
26869 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);26777 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
26870 },26778 },
26871 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),26779 .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", .{}),
26873 }26781 }
26874}26782}
2687526783
...@@ -26912,7 +26820,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {...@@ -26912,7 +26820,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
26912fn explainWhyTypeIsNotPacked(26820fn explainWhyTypeIsNotPacked(
26913 sema: *Sema,26821 sema: *Sema,
26914 msg: *Module.ErrorMsg,26822 msg: *Module.ErrorMsg,
26915 src_loc: Module.SrcLoc,26823 src_loc: LazySrcLoc,
26916 ty: Type,26824 ty: Type,
26917) CompileError!void {26825) CompileError!void {
26918 const mod = sema.mod;26826 const mod = sema.mod;
...@@ -26938,19 +26846,19 @@ fn explainWhyTypeIsNotPacked(...@@ -26938,19 +26846,19 @@ fn explainWhyTypeIsNotPacked(
26938 .AnyFrame,26846 .AnyFrame,
26939 .Optional,26847 .Optional,
26940 .Array,26848 .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", .{}),
26942 .Pointer => if (ty.isSlice(mod)) {26850 .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", .{});
26944 } else {26852 } 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", .{});
26946 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);26854 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
26947 },26855 },
26948 .Fn => {26856 .Fn => {
26949 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});26857 try sema.errNote(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", .{});26858 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26951 },26859 },
26952 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),26860 .Struct => try sema.errNote(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", .{}),26861 .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
26954 }26862 }
26955}26863}
2695626864
...@@ -27001,11 +26909,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP...@@ -27001,11 +26909,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
27001 const panic_messages_ty = try sema.getBuiltinType("panic_messages");26909 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
27002 const msg_decl_index = (sema.namespaceLookup(26910 const msg_decl_index = (sema.namespaceLookup(
27003 block,26911 block,
27004 .unneeded,26912 LazySrcLoc.unneeded,
27005 panic_messages_ty.getNamespaceIndex(mod),26913 panic_messages_ty.getNamespaceIndex(mod),
27006 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),26914 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
27007 ) catch |err| switch (err) {26915 ) 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"),
27009 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,26917 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
27010 error.OutOfMemory => |e| return e,26918 error.OutOfMemory => |e| return e,
27011 }).?;26919 }).?;
...@@ -27027,11 +26935,12 @@ fn addSafetyCheck(...@@ -27027,11 +26935,12 @@ fn addSafetyCheck(
27027 var fail_block: Block = .{26935 var fail_block: Block = .{
27028 .parent = parent_block,26936 .parent = parent_block,
27029 .sema = sema,26937 .sema = sema,
27030 .src_decl = parent_block.src_decl,
27031 .namespace = parent_block.namespace,26938 .namespace = parent_block.namespace,
27032 .instructions = .{},26939 .instructions = .{},
27033 .inlining = parent_block.inlining,26940 .inlining = parent_block.inlining,
27034 .is_comptime = false,26941 .is_comptime = false,
26942 .src_base_inst = parent_block.src_base_inst,
26943 .type_name_ctx = parent_block.type_name_ctx,
27035 };26944 };
2703626945
27037 defer fail_block.instructions.deinit(gpa);26946 defer fail_block.instructions.deinit(gpa);
...@@ -27135,11 +27044,12 @@ fn panicUnwrapError(...@@ -27135,11 +27044,12 @@ fn panicUnwrapError(
27135 var fail_block: Block = .{27044 var fail_block: Block = .{
27136 .parent = parent_block,27045 .parent = parent_block,
27137 .sema = sema,27046 .sema = sema,
27138 .src_decl = parent_block.src_decl,
27139 .namespace = parent_block.namespace,27047 .namespace = parent_block.namespace,
27140 .instructions = .{},27048 .instructions = .{},
27141 .inlining = parent_block.inlining,27049 .inlining = parent_block.inlining,
27142 .is_comptime = false,27050 .is_comptime = false,
27051 .src_base_inst = parent_block.src_base_inst,
27052 .type_name_ctx = parent_block.type_name_ctx,
27143 };27053 };
2714427054
27145 defer fail_block.instructions.deinit(gpa);27055 defer fail_block.instructions.deinit(gpa);
...@@ -27251,11 +27161,12 @@ fn safetyCheckFormatted(...@@ -27251,11 +27161,12 @@ fn safetyCheckFormatted(
27251 var fail_block: Block = .{27161 var fail_block: Block = .{
27252 .parent = parent_block,27162 .parent = parent_block,
27253 .sema = sema,27163 .sema = sema,
27254 .src_decl = parent_block.src_decl,
27255 .namespace = parent_block.namespace,27164 .namespace = parent_block.namespace,
27256 .instructions = .{},27165 .instructions = .{},
27257 .inlining = parent_block.inlining,27166 .inlining = parent_block.inlining,
27258 .is_comptime = false,27167 .is_comptime = false,
27168 .src_base_inst = parent_block.src_base_inst,
27169 .type_name_ctx = parent_block.type_name_ctx,
27259 };27170 };
2726027171
27261 defer fail_block.instructions.deinit(gpa);27172 defer fail_block.instructions.deinit(gpa);
...@@ -27279,13 +27190,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {...@@ -27279,13 +27190,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
27279 sema.branch_count += 1;27190 sema.branch_count += 1;
27280 if (sema.branch_count > sema.branch_quota) {27191 if (sema.branch_count > sema.branch_quota) {
27281 const msg = try sema.errMsg(27192 const msg = try sema.errMsg(
27282 block,
27283 src,27193 src,
27284 "evaluation exceeded {d} backwards branches",27194 "evaluation exceeded {d} backwards branches",
27285 .{sema.branch_quota},27195 .{sema.branch_quota},
27286 );27196 );
27287 try sema.errNote(27197 try sema.errNote(
27288 block,
27289 src,27198 src,
27290 msg,27199 msg,
27291 "use @setEvalBranchQuota() to raise the branch limit from {d}",27200 "use @setEvalBranchQuota() to raise the branch limit from {d}",
...@@ -27451,10 +27360,10 @@ fn fieldVal(...@@ -27451,10 +27360,10 @@ fn fieldVal(
27451 },27360 },
27452 else => {27361 else => {
27453 const msg = msg: {27362 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)});
27455 errdefer msg.destroy(sema.gpa);27364 errdefer msg.destroy(sema.gpa);
27456 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});27365 if (child_type.isSlice(mod)) try sema.errNote(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", .{});27366 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
27458 break :msg msg;27367 break :msg msg;
27459 };27368 };
27460 return sema.failWithOwnedErrorMsg(block, msg);27369 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -27612,7 +27521,7 @@ fn fieldPtr(...@@ -27612,7 +27521,7 @@ fn fieldPtr(
27612 }27521 }
27613 },27522 },
27614 .Type => {27523 .Type => {
27615 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);27524 _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined);
27616 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);27525 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
27617 const inner = if (is_pointer_to)27526 const inner = if (is_pointer_to)
27618 try sema.analyzeLoad(block, src, result, object_ptr_src)27527 try sema.analyzeLoad(block, src, result, object_ptr_src)
...@@ -27805,7 +27714,7 @@ fn fieldCallBind(...@@ -27805,7 +27714,7 @@ fn fieldCallBind(
27805 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse27714 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse
27806 break :found_decl null;27715 break :found_decl null;
2780727716
27808 try sema.addReferencedBy(block, src, decl_idx);27717 try sema.addReferencedBy(src, decl_idx);
27809 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);27718 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);
27810 const decl_type = sema.typeOf(decl_val);27719 const decl_type = sema.typeOf(decl_val);
27811 if (mod.typeToFunc(decl_type)) |func_type| f: {27720 if (mod.typeToFunc(decl_type)) |func_type| f: {
...@@ -27864,7 +27773,7 @@ fn fieldCallBind(...@@ -27864,7 +27773,7 @@ fn fieldCallBind(
27864 };27773 };
2786527774
27866 const msg = msg: {27775 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 '{}'", .{
27868 field_name.fmt(ip),27777 field_name.fmt(ip),
27869 concrete_ty.fmt(mod),27778 concrete_ty.fmt(mod),
27870 });27779 });
...@@ -27872,10 +27781,13 @@ fn fieldCallBind(...@@ -27872,10 +27781,13 @@ fn fieldCallBind(
27872 try sema.addDeclaredHereNote(msg, concrete_ty);27781 try sema.addDeclaredHereNote(msg, concrete_ty);
27873 if (found_decl) |decl_idx| {27782 if (found_decl) |decl_idx| {
27874 const decl = mod.declPtr(decl_idx);27783 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)});
27876 }27788 }
27877 if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {27789 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'", .{});
27879 }27791 }
27880 break :msg msg;27792 break :msg msg;
27881 };27793 };
...@@ -27933,11 +27845,14 @@ fn namespaceLookup(...@@ -27933,11 +27845,14 @@ fn namespaceLookup(
27933 const decl = mod.declPtr(decl_index);27845 const decl = mod.declPtr(decl_index);
27934 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {27846 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
27935 const msg = msg: {27847 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'", .{
27937 decl_name.fmt(&mod.intern_pool),27849 decl_name.fmt(&mod.intern_pool),
27938 });27850 });
27939 errdefer msg.destroy(gpa);27851 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", .{});
27941 break :msg msg;27856 break :msg msg;
27942 };27857 };
27943 return sema.failWithOwnedErrorMsg(block, msg);27858 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -27955,7 +27870,7 @@ fn namespaceLookupRef(...@@ -27955,7 +27870,7 @@ fn namespaceLookupRef(
27955 decl_name: InternPool.NullTerminatedString,27870 decl_name: InternPool.NullTerminatedString,
27956) CompileError!?Air.Inst.Ref {27871) CompileError!?Air.Inst.Ref {
27957 const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null;27872 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);
27959 return try sema.analyzeDeclRef(decl);27874 return try sema.analyzeDeclRef(decl);
27960}27875}
2796127876
...@@ -28002,7 +27917,7 @@ fn structFieldPtr(...@@ -28002,7 +27917,7 @@ fn structFieldPtr(
28002 const struct_type = mod.typeToStruct(struct_ty).?;27917 const struct_type = mod.typeToStruct(struct_ty).?;
2800327918
28004 const field_index = struct_type.nameIndex(ip, field_name) orelse27919 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
28007 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);27922 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
28008}27923}
...@@ -28117,7 +28032,7 @@ fn structFieldVal(...@@ -28117,7 +28032,7 @@ fn structFieldVal(
28117 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);28032 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);
2811828033
28119 const field_index = struct_type.nameIndex(ip, field_name) orelse28034 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);
28121 if (struct_type.fieldIsComptime(ip, field_index)) {28036 if (struct_type.fieldIsComptime(ip, field_index)) {
28122 try sema.resolveStructFieldInits(struct_ty);28037 try sema.resolveStructFieldInits(struct_ty);
28123 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);28038 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
...@@ -28270,7 +28185,7 @@ fn unionFieldPtr(...@@ -28270,7 +28185,7 @@ fn unionFieldPtr(
2827028185
28271 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {28186 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
28272 const msg = msg: {28187 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", .{});
28274 errdefer msg.destroy(sema.gpa);28189 errdefer msg.destroy(sema.gpa);
2827528190
28276 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{28191 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
...@@ -28303,7 +28218,7 @@ fn unionFieldPtr(...@@ -28303,7 +28218,7 @@ fn unionFieldPtr(
28303 const msg = msg: {28218 const msg = msg: {
28304 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;28219 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
28305 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);28220 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", .{
28307 field_name.fmt(ip),28222 field_name.fmt(ip),
28308 active_field_name.fmt(ip),28223 active_field_name.fmt(ip),
28309 });28224 });
...@@ -28371,7 +28286,7 @@ fn unionFieldVal(...@@ -28371,7 +28286,7 @@ fn unionFieldVal(
28371 const msg = msg: {28286 const msg = msg: {
28372 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;28287 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
28373 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);28288 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", .{
28375 field_name.fmt(ip), active_field_name.fmt(ip),28290 field_name.fmt(ip), active_field_name.fmt(ip),
28376 });28291 });
28377 errdefer msg.destroy(sema.gpa);28292 errdefer msg.destroy(sema.gpa);
...@@ -28594,15 +28509,13 @@ fn validateRuntimeElemAccess(...@@ -28594,15 +28509,13 @@ fn validateRuntimeElemAccess(
28594 if (try sema.typeRequiresComptime(elem_ty)) {28509 if (try sema.typeRequiresComptime(elem_ty)) {
28595 const msg = msg: {28510 const msg = msg: {
28596 const msg = try sema.errMsg(28511 const msg = try sema.errMsg(
28597 block,
28598 elem_index_src,28512 elem_index_src,
28599 "values of type '{}' must be comptime-known, but index value is runtime-known",28513 "values of type '{}' must be comptime-known, but index value is runtime-known",
28600 .{parent_ty.fmt(mod)},28514 .{parent_ty.fmt(mod)},
28601 );28515 );
28602 errdefer msg.destroy(sema.gpa);28516 errdefer msg.destroy(sema.gpa);
2860328517
28604 const src_decl = mod.declPtr(block.src_decl);28518 try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty);
28605 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty);
2860628519
28607 break :msg msg;28520 break :msg msg;
28608 };28521 };
...@@ -28990,21 +28903,18 @@ const CoerceOpts = struct {...@@ -28990,21 +28903,18 @@ const CoerceOpts = struct {
28990 func_inst: Air.Inst.Ref = .none,28903 func_inst: Air.Inst.Ref = .none,
28991 param_i: u32 = undefined,28904 param_i: u32 = undefined,
2899228905
28993 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {28906 fn get(info: @This(), sema: *Sema) !?LazySrcLoc {
28994 if (info.func_inst == .none) return null;28907 if (info.func_inst == .none) return null;
28995 const mod = sema.mod;28908 const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null;
28996 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;28909 return .{
28997 const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i);28910 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
28998 if (param_src == .node_offset_param) {28911 .offset = .{ .fn_proto_param_type = .{
28999 return Module.SrcLoc{28912 .fn_proto_node_offset = 0,
29000 .file_scope = fn_decl.getFileScope(mod),28913 .param_index = info.param_i,
29001 .parent_decl_node = fn_decl.src_node,28914 } },
29002 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),28915 };
29003 };
29004 }
29005 return fn_decl.toSrcLoc(param_src, mod);
29006 }28916 }
29007 } = .{},28917 } = .{ .func_inst = .none, .param_i = undefined },
29008};28918};
2900928919
29010fn coerceExtra(28920fn coerceExtra(
...@@ -29097,7 +29007,7 @@ fn coerceExtra(...@@ -29097,7 +29007,7 @@ fn coerceExtra(
2909729007
29098 // Function body to function pointer.29008 // Function body to function pointer.
29099 if (inst_ty.zigTypeTag(zcu) == .Fn) {29009 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);
29101 const fn_decl = fn_val.pointerDecl(zcu).?;29011 const fn_decl = fn_val.pointerDecl(zcu).?;
29102 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);29012 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
29103 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);29013 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
...@@ -29345,9 +29255,9 @@ fn coerceExtra(...@@ -29345,9 +29255,9 @@ fn coerceExtra(
29345 // pointer to tuple to slice29255 // pointer to tuple to slice
29346 if (!dest_info.flags.is_const) {29256 if (!dest_info.flags.is_const) {
29347 const err_msg = err_msg: {29257 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)});
29349 errdefer err_msg.destroy(sema.gpa);29259 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", .{});
29351 break :err_msg err_msg;29261 break :err_msg err_msg;
29352 };29262 };
29353 return sema.failWithOwnedErrorMsg(block, err_msg);29263 return sema.failWithOwnedErrorMsg(block, err_msg);
...@@ -29434,7 +29344,7 @@ fn coerceExtra(...@@ -29434,7 +29344,7 @@ fn coerceExtra(
29434 },29344 },
29435 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {29345 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {
29436 .ComptimeFloat => {29346 .ComptimeFloat => {
29437 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);29347 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
29438 const result_val = try val.floatCast(dest_ty, zcu);29348 const result_val = try val.floatCast(dest_ty, zcu);
29439 return Air.internedToRef(result_val.toIntern());29349 return Air.internedToRef(result_val.toIntern());
29440 },29350 },
...@@ -29493,7 +29403,7 @@ fn coerceExtra(...@@ -29493,7 +29403,7 @@ fn coerceExtra(
29493 .Enum => switch (inst_ty.zigTypeTag(zcu)) {29403 .Enum => switch (inst_ty.zigTypeTag(zcu)) {
29494 .EnumLiteral => {29404 .EnumLiteral => {
29495 // enum literal to enum29405 // 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);
29497 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;29407 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;
29498 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {29408 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
29499 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{29409 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{
...@@ -29627,54 +29537,58 @@ fn coerceExtra(...@@ -29627,54 +29537,58 @@ fn coerceExtra(
2962729537
29628 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {29538 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {
29629 const msg = msg: {29539 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", .{});
29631 errdefer msg.destroy(sema.gpa);29541 errdefer msg.destroy(sema.gpa);
2963229542
29633 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29543 const ret_ty_src: LazySrcLoc = .{
29634 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);29544 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29635 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{});29545 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29546 };
29547 try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{});
29636 break :msg msg;29548 break :msg msg;
29637 };29549 };
29638 return sema.failWithOwnedErrorMsg(block, msg);29550 return sema.failWithOwnedErrorMsg(block, msg);
29639 }29551 }
2964029552
29641 const msg = msg: {29553 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) });
29643 errdefer msg.destroy(sema.gpa);29555 errdefer msg.destroy(sema.gpa);
2964429556
29645 // E!T to T29557 // E!T to T
29646 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and29558 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and
29647 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)29559 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
29648 {29560 {
29649 try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{});29561 try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{});
29650 try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});29562 try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
29651 }29563 }
2965229564
29653 // ?T to T29565 // ?T to T
29654 if (inst_ty.zigTypeTag(zcu) == .Optional and29566 if (inst_ty.zigTypeTag(zcu) == .Optional and
29655 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)29567 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
29656 {29568 {
29657 try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{});29569 try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{});
29658 try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});29570 try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
29659 }29571 }
2966029572
29661 try in_memory_result.report(sema, block, inst_src, msg);29573 try in_memory_result.report(sema, inst_src, msg);
2966229574
29663 // Add notes about function return type29575 // Add notes about function return type
29664 if (opts.is_ret and29576 if (opts.is_ret and
29665 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)29577 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)
29666 {29578 {
29667 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29579 const ret_ty_src: LazySrcLoc = .{
29668 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);29580 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29581 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29582 };
29669 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {29583 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", .{});
29671 } else {29585 } 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", .{});
29673 }29587 }
29674 }29588 }
2967529589
29676 if (try opts.param_src.get(sema)) |param_src| {29590 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", .{});
29678 }29592 }
2967929593
29680 // TODO maybe add "cannot store an error in type '{}'" note29594 // TODO maybe add "cannot store an error in type '{}'" note
...@@ -29809,7 +29723,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -29809,7 +29723,7 @@ const InMemoryCoercionResult = union(enum) {
29809 return res;29723 return res;
29810 }29724 }
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 {
29813 const mod = sema.mod;29727 const mod = sema.mod;
29814 var cur = res;29728 var cur = res;
29815 while (true) switch (cur.*) {29729 while (true) switch (cur.*) {
...@@ -29820,93 +29734,93 @@ const InMemoryCoercionResult = union(enum) {...@@ -29820,93 +29734,93 @@ const InMemoryCoercionResult = union(enum) {
29820 break;29734 break;
29821 },29735 },
29822 .int_not_coercible => |int| {29736 .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", .{
29824 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,29738 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,
29825 });29739 });
29826 break;29740 break;
29827 },29741 },
29828 .error_union_payload => |pair| {29742 .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 '{}'", .{
29830 pair.actual.fmt(mod), pair.wanted.fmt(mod),29744 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29831 });29745 });
29832 cur = pair.child;29746 cur = pair.child;
29833 },29747 },
29834 .array_len => |lens| {29748 .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}", .{
29836 lens.actual, lens.wanted,29750 lens.actual, lens.wanted,
29837 });29751 });
29838 break;29752 break;
29839 },29753 },
29840 .array_sentinel => |sentinel| {29754 .array_sentinel => |sentinel| {
29841 if (sentinel.actual.toIntern() != .unreachable_value) {29755 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 '{}'", .{
29843 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),29757 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
29844 });29758 });
29845 } else {29759 } else {
29846 try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{29760 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{
29847 sentinel.wanted.fmtValue(mod, sema),29761 sentinel.wanted.fmtValue(mod, sema),
29848 });29762 });
29849 }29763 }
29850 break;29764 break;
29851 },29765 },
29852 .array_elem => |pair| {29766 .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 '{}'", .{
29854 pair.actual.fmt(mod), pair.wanted.fmt(mod),29768 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29855 });29769 });
29856 cur = pair.child;29770 cur = pair.child;
29857 },29771 },
29858 .vector_len => |lens| {29772 .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}", .{
29860 lens.actual, lens.wanted,29774 lens.actual, lens.wanted,
29861 });29775 });
29862 break;29776 break;
29863 },29777 },
29864 .vector_elem => |pair| {29778 .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 '{}'", .{
29866 pair.actual.fmt(mod), pair.wanted.fmt(mod),29780 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29867 });29781 });
29868 cur = pair.child;29782 cur = pair.child;
29869 },29783 },
29870 .optional_shape => |pair| {29784 .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 '{}'", .{
29872 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),29786 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),
29873 });29787 });
29874 break;29788 break;
29875 },29789 },
29876 .optional_child => |pair| {29790 .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 '{}'", .{
29878 pair.actual.fmt(mod), pair.wanted.fmt(mod),29792 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29879 });29793 });
29880 cur = pair.child;29794 cur = pair.child;
29881 },29795 },
29882 .from_anyerror => {29796 .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", .{});
29884 break;29798 break;
29885 },29799 },
29886 .missing_error => |missing_errors| {29800 .missing_error => |missing_errors| {
29887 for (missing_errors) |err| {29801 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)});
29889 }29803 }
29890 break;29804 break;
29891 },29805 },
29892 .fn_var_args => |wanted_var_args| {29806 .fn_var_args => |wanted_var_args| {
29893 if (wanted_var_args) {29807 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", .{});
29895 } else {29809 } 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", .{});
29897 }29811 }
29898 break;29812 break;
29899 },29813 },
29900 .fn_generic => |wanted_generic| {29814 .fn_generic => |wanted_generic| {
29901 if (wanted_generic) {29815 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", .{});
29903 } else {29817 } 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", .{});
29905 }29819 }
29906 break;29820 break;
29907 },29821 },
29908 .fn_param_count => |lens| {29822 .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", .{
29910 lens.actual, lens.wanted,29824 lens.actual, lens.wanted,
29911 });29825 });
29912 break;29826 break;
...@@ -29923,69 +29837,69 @@ const InMemoryCoercionResult = union(enum) {...@@ -29923,69 +29837,69 @@ const InMemoryCoercionResult = union(enum) {
29923 }29837 }
29924 }29838 }
29925 if (!actual_noalias) {29839 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});
29927 } else {29841 } 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});
29929 }29843 }
29930 break;29844 break;
29931 },29845 },
29932 .fn_param_comptime => |param| {29846 .fn_param_comptime => |param| {
29933 if (param.wanted) {29847 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});
29935 } else {29849 } 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});
29937 }29851 }
29938 break;29852 break;
29939 },29853 },
29940 .fn_param => |param| {29854 .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 '{}'", .{
29942 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),29856 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),
29943 });29857 });
29944 cur = param.child;29858 cur = param.child;
29945 },29859 },
29946 .fn_cc => |cc| {29860 .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) });
29948 break;29862 break;
29949 },29863 },
29950 .fn_return_type => |pair| {29864 .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 '{}'", .{
29952 pair.actual.fmt(mod), pair.wanted.fmt(mod),29866 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29953 });29867 });
29954 cur = pair.child;29868 cur = pair.child;
29955 },29869 },
29956 .ptr_child => |pair| {29870 .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 '{}'", .{
29958 pair.actual.fmt(mod), pair.wanted.fmt(mod),29872 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29959 });29873 });
29960 cur = pair.child;29874 cur = pair.child;
29961 },29875 },
29962 .ptr_addrspace => |@"addrspace"| {29876 .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) });
29964 break;29878 break;
29965 },29879 },
29966 .ptr_sentinel => |sentinel| {29880 .ptr_sentinel => |sentinel| {
29967 if (sentinel.actual.toIntern() != .unreachable_value) {29881 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 '{}'", .{
29969 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),29883 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
29970 });29884 });
29971 } else {29885 } else {
29972 try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{29886 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{
29973 sentinel.wanted.fmtValue(mod, sema),29887 sentinel.wanted.fmtValue(mod, sema),
29974 });29888 });
29975 }29889 }
29976 break;29890 break;
29977 },29891 },
29978 .ptr_size => |size| {29892 .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) });
29980 break;29894 break;
29981 },29895 },
29982 .ptr_qualifiers => |qualifiers| {29896 .ptr_qualifiers => |qualifiers| {
29983 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;29897 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;
29984 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;29898 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;
29985 if (!ok_const) {29899 if (!ok_const) {
29986 try sema.errNote(block, src, msg, "cast discards const qualifier", .{});29900 try sema.errNote(src, msg, "cast discards const qualifier", .{});
29987 } else if (!ok_volatile) {29901 } 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", .{});
29989 }29903 }
29990 break;29904 break;
29991 },29905 },
...@@ -29993,11 +29907,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -29993,11 +29907,11 @@ const InMemoryCoercionResult = union(enum) {
29993 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);29907 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);
29994 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);29908 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);
29995 if (actual_allow_zero and !wanted_allow_zero) {29909 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 '{}'", .{
29997 pair.actual.fmt(mod), pair.wanted.fmt(mod),29911 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29998 });29912 });
29999 } else {29913 } 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 '{}'", .{
30001 pair.actual.fmt(mod), pair.wanted.fmt(mod),29915 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30002 });29916 });
30003 }29917 }
...@@ -30005,34 +29919,34 @@ const InMemoryCoercionResult = union(enum) {...@@ -30005,34 +29919,34 @@ const InMemoryCoercionResult = union(enum) {
30005 },29919 },
30006 .ptr_bit_range => |bit_range| {29920 .ptr_bit_range => |bit_range| {
30007 if (bit_range.actual_host != bit_range.wanted_host) {29921 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 '{}'", .{
30009 bit_range.actual_host, bit_range.wanted_host,29923 bit_range.actual_host, bit_range.wanted_host,
30010 });29924 });
30011 }29925 }
30012 if (bit_range.actual_offset != bit_range.wanted_offset) {29926 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 '{}'", .{
30014 bit_range.actual_offset, bit_range.wanted_offset,29928 bit_range.actual_offset, bit_range.wanted_offset,
30015 });29929 });
30016 }29930 }
30017 break;29931 break;
30018 },29932 },
30019 .ptr_alignment => |pair| {29933 .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}'", .{
30021 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,29935 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,
30022 });29936 });
30023 break;29937 break;
30024 },29938 },
30025 .double_ptr_to_anyopaque => |pair| {29939 .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 '{}'", .{
30027 pair.actual.fmt(mod), pair.wanted.fmt(mod),29941 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30028 });29942 });
30029 break;29943 break;
30030 },29944 },
30031 .slice_to_anyopaque => |pair| {29945 .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 '{}'", .{
30033 pair.actual.fmt(mod), pair.wanted.fmt(mod),29947 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30034 });29948 });
30035 try sema.errNote(block, src, msg, "consider using '.ptr'", .{});29949 try sema.errNote(src, msg, "consider using '.ptr'", .{});
30036 break;29950 break;
30037 },29951 },
30038 };29952 };
...@@ -30646,7 +30560,7 @@ fn coerceVarArgParam(...@@ -30646,7 +30560,7 @@ fn coerceVarArgParam(
30646 .{},30560 .{},
30647 ),30561 ),
30648 .Fn => fn_ptr: {30562 .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);
30650 const fn_decl = fn_val.pointerDecl(mod).?;30564 const fn_decl = fn_val.pointerDecl(mod).?;
30651 break :fn_ptr try sema.analyzeDeclRef(fn_decl);30565 break :fn_ptr try sema.analyzeDeclRef(fn_decl);
30652 },30566 },
...@@ -30694,11 +30608,10 @@ fn coerceVarArgParam(...@@ -30694,11 +30608,10 @@ fn coerceVarArgParam(
30694 const coerced_ty = sema.typeOf(coerced);30608 const coerced_ty = sema.typeOf(coerced);
30695 if (!try sema.validateExternType(coerced_ty, .param_ty)) {30609 if (!try sema.validateExternType(coerced_ty, .param_ty)) {
30696 const msg = msg: {30610 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)});
30698 errdefer msg.destroy(sema.gpa);30612 errdefer msg.destroy(sema.gpa);
3069930613
30700 const src_decl = sema.mod.declPtr(block.src_decl);30614 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
30701 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty);
3070230615
30703 try sema.addDeclaredHereNote(msg, coerced_ty);30616 try sema.addDeclaredHereNote(msg, coerced_ty);
30704 break :msg msg;30617 break :msg msg;
...@@ -30858,7 +30771,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst....@@ -30858,7 +30771,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
30858 {30771 {
30859 try maybe_comptime_alloc.stores.append(sema.arena, .{30772 try maybe_comptime_alloc.stores.append(sema.arena, .{
30860 .inst = store_inst,30773 .inst = store_inst,
30861 .src_decl = block.src_decl,
30862 .src = store_src,30774 .src = store_src,
30863 });30775 });
30864 return;30776 return;
...@@ -30892,8 +30804,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt...@@ -30892,8 +30804,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt
3089230804
30893 try maybe_comptime_alloc.stores.append(sema.arena, .{30805 try maybe_comptime_alloc.stores.append(sema.arena, .{
30894 .inst = new_ptr_inst,30806 .inst = new_ptr_inst,
30895 .src_decl = block.src_decl,30807 .src = LazySrcLoc.unneeded,
30896 .src = .unneeded,
30897 });30808 });
30898 },30809 },
30899 .ptr_elem_ptr => {30810 .ptr_elem_ptr => {
...@@ -30916,10 +30827,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins...@@ -30916,10 +30827,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
30916 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;30827 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;
30917 // Since the alloc has been determined to be runtime, we must check that30828 // Since the alloc has been determined to be runtime, we must check that
30918 // all other stores to it are permitted to be runtime values.30829 // all other stores to it are permitted to be runtime values.
30919 const mod = sema.mod;
30920 const slice = maybe_comptime_alloc.stores.slice();30830 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| {30831 for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| {
30922 if (other_src == .unneeded) {30832 if (other_src.offset == .unneeded) {
30923 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {30833 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {
30924 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,30834 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,
30925 else => unreachable, // assertion failure30835 else => unreachable, // assertion failure
...@@ -30929,10 +30839,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins...@@ -30929,10 +30839,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
30929 const other_operand = other_data.rhs;30839 const other_operand = other_data.rhs;
30930 if (!sema.checkRuntimeValue(other_operand)) {30840 if (!sema.checkRuntimeValue(other_operand)) {
30931 return sema.failWithOwnedErrorMsg(block, msg: {30841 return sema.failWithOwnedErrorMsg(block, msg: {
30932 const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod);30842 const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{});
30933 const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{});
30934 errdefer msg.destroy(sema.gpa);30843 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", .{});
30936 break :msg msg;30845 break :msg msg;
30937 });30846 });
30938 }30847 }
...@@ -31194,11 +31103,11 @@ fn coerceEnumToUnion(...@@ -31194,11 +31103,11 @@ fn coerceEnumToUnion(
3119431103
31195 const tag_ty = union_ty.unionTagType(mod) orelse {31104 const tag_ty = union_ty.unionTagType(mod) orelse {
31196 const msg = msg: {31105 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 '{}'", .{
31198 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),31107 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
31199 });31108 });
31200 errdefer msg.destroy(sema.gpa);31109 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", .{});
31202 try sema.addDeclaredHereNote(msg, union_ty);31111 try sema.addDeclaredHereNote(msg, union_ty);
31203 break :msg msg;31112 break :msg msg;
31204 };31113 };
...@@ -31218,7 +31127,7 @@ fn coerceEnumToUnion(...@@ -31218,7 +31127,7 @@ fn coerceEnumToUnion(
31218 try sema.resolveTypeFields(field_ty);31127 try sema.resolveTypeFields(field_ty);
31219 if (field_ty.zigTypeTag(mod) == .NoReturn) {31128 if (field_ty.zigTypeTag(mod) == .NoReturn) {
31220 const msg = msg: {31129 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", .{});
31222 errdefer msg.destroy(sema.gpa);31131 errdefer msg.destroy(sema.gpa);
3122331132
31224 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31133 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
...@@ -31233,7 +31142,7 @@ fn coerceEnumToUnion(...@@ -31233,7 +31142,7 @@ fn coerceEnumToUnion(
31233 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {31142 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
31234 const msg = msg: {31143 const msg = msg: {
31235 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31144 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 '{}'", .{
31237 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),31146 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),
31238 field_ty.fmt(sema.mod), field_name.fmt(ip),31147 field_ty.fmt(sema.mod), field_name.fmt(ip),
31239 });31148 });
...@@ -31255,7 +31164,7 @@ fn coerceEnumToUnion(...@@ -31255,7 +31164,7 @@ fn coerceEnumToUnion(
3125531164
31256 if (tag_ty.isNonexhaustiveEnum(mod)) {31165 if (tag_ty.isNonexhaustiveEnum(mod)) {
31257 const msg = msg: {31166 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", .{
31259 union_ty.fmt(sema.mod),31168 union_ty.fmt(sema.mod),
31260 });31169 });
31261 errdefer msg.destroy(sema.gpa);31170 errdefer msg.destroy(sema.gpa);
...@@ -31273,7 +31182,6 @@ fn coerceEnumToUnion(...@@ -31273,7 +31182,6 @@ fn coerceEnumToUnion(
31273 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {31182 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
31274 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {31183 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
31275 const err_msg = msg orelse try sema.errMsg(31184 const err_msg = msg orelse try sema.errMsg(
31276 block,
31277 inst_src,31185 inst_src,
31278 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",31186 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
31279 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },31187 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
...@@ -31297,7 +31205,6 @@ fn coerceEnumToUnion(...@@ -31297,7 +31205,6 @@ fn coerceEnumToUnion(
3129731205
31298 const msg = msg: {31206 const msg = msg: {
31299 const msg = try sema.errMsg(31207 const msg = try sema.errMsg(
31300 block,
31301 inst_src,31208 inst_src,
31302 "runtime coercion from enum '{}' to union '{}' which has non-void fields",31209 "runtime coercion from enum '{}' to union '{}' which has non-void fields",
31303 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },31210 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
...@@ -31356,12 +31263,10 @@ fn coerceAnonStructToUnion(...@@ -31356,12 +31263,10 @@ fn coerceAnonStructToUnion(
31356 assert(field_count != 1);31263 assert(field_count != 1);
31357 const msg = msg: {31264 const msg = msg: {
31358 const msg = if (field_count > 1) try sema.errMsg(31265 const msg = if (field_count > 1) try sema.errMsg(
31359 block,
31360 inst_src,31266 inst_src,
31361 "cannot initialize multiple union fields at once; unions can only have one active field",31267 "cannot initialize multiple union fields at once; unions can only have one active field",
31362 .{},31268 .{},
31363 ) else try sema.errMsg(31269 ) else try sema.errMsg(
31364 block,
31365 inst_src,31270 inst_src,
31366 "union initializer must initialize one field",31271 "union initializer must initialize one field",
31367 .{},31272 .{},
...@@ -31438,12 +31343,12 @@ fn coerceArrayLike(...@@ -31438,12 +31343,12 @@ fn coerceArrayLike(
31438 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));31343 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
31439 if (dest_len != inst_len) {31344 if (dest_len != inst_len) {
31440 const msg = msg: {31345 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 '{}'", .{
31442 dest_ty.fmt(mod), inst_ty.fmt(mod),31347 dest_ty.fmt(mod), inst_ty.fmt(mod),
31443 });31348 });
31444 errdefer msg.destroy(sema.gpa);31349 errdefer msg.destroy(sema.gpa);
31445 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});31350 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31446 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});31351 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
31447 break :msg msg;31352 break :msg msg;
31448 };31353 };
31449 return sema.failWithOwnedErrorMsg(block, msg);31354 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -31525,12 +31430,12 @@ fn coerceTupleToArray(...@@ -31525,12 +31430,12 @@ fn coerceTupleToArray(
3152531430
31526 if (dest_len != inst_len) {31431 if (dest_len != inst_len) {
31527 const msg = msg: {31432 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 '{}'", .{
31529 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),31434 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
31530 });31435 });
31531 errdefer msg.destroy(sema.gpa);31436 errdefer msg.destroy(sema.gpa);
31532 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});31437 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31533 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});31438 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
31534 break :msg msg;31439 break :msg msg;
31535 };31440 };
31536 return sema.failWithOwnedErrorMsg(block, msg);31441 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -31701,9 +31606,9 @@ fn coerceTupleToStruct(...@@ -31701,9 +31606,9 @@ fn coerceTupleToStruct(
31701 const template = "missing struct field: {}";31606 const template = "missing struct field: {}";
31702 const args = .{field_name.fmt(ip)};31607 const args = .{field_name.fmt(ip)};
31703 if (root_msg) |msg| {31608 if (root_msg) |msg| {
31704 try sema.errNote(block, field_src, msg, template, args);31609 try sema.errNote(field_src, msg, template, args);
31705 } else {31610 } else {
31706 root_msg = try sema.errMsg(block, field_src, template, args);31611 root_msg = try sema.errMsg(field_src, template, args);
31707 }31612 }
31708 continue;31613 continue;
31709 }31614 }
...@@ -31839,18 +31744,18 @@ fn coerceTupleToTuple(...@@ -31839,18 +31744,18 @@ fn coerceTupleToTuple(
31839 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {31744 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
31840 const template = "missing tuple field: {d}";31745 const template = "missing tuple field: {d}";
31841 if (root_msg) |msg| {31746 if (root_msg) |msg| {
31842 try sema.errNote(block, field_src, msg, template, .{i});31747 try sema.errNote(field_src, msg, template, .{i});
31843 } else {31748 } else {
31844 root_msg = try sema.errMsg(block, field_src, template, .{i});31749 root_msg = try sema.errMsg(field_src, template, .{i});
31845 }31750 }
31846 continue;31751 continue;
31847 };31752 };
31848 const template = "missing struct field: {}";31753 const template = "missing struct field: {}";
31849 const args = .{field_name.fmt(ip)};31754 const args = .{field_name.fmt(ip)};
31850 if (root_msg) |msg| {31755 if (root_msg) |msg| {
31851 try sema.errNote(block, field_src, msg, template, args);31756 try sema.errNote(field_src, msg, template, args);
31852 } else {31757 } else {
31853 root_msg = try sema.errMsg(block, field_src, template, args);31758 root_msg = try sema.errMsg(field_src, template, args);
31854 }31759 }
31855 continue;31760 continue;
31856 }31761 }
...@@ -31884,7 +31789,7 @@ fn analyzeDeclVal(...@@ -31884,7 +31789,7 @@ fn analyzeDeclVal(
31884 src: LazySrcLoc,31789 src: LazySrcLoc,
31885 decl_index: InternPool.DeclIndex,31790 decl_index: InternPool.DeclIndex,
31886) CompileError!Air.Inst.Ref {31791) CompileError!Air.Inst.Ref {
31887 try sema.addReferencedBy(block, src, decl_index);31792 try sema.addReferencedBy(src, decl_index);
31888 if (sema.decl_val_table.get(decl_index)) |result| {31793 if (sema.decl_val_table.get(decl_index)) |result| {
31889 return result;31794 return result;
31890 }31795 }
...@@ -31900,21 +31805,14 @@ fn analyzeDeclVal(...@@ -31900,21 +31805,14 @@ fn analyzeDeclVal(
3190031805
31901fn addReferencedBy(31806fn addReferencedBy(
31902 sema: *Sema,31807 sema: *Sema,
31903 block: *Block,
31904 src: LazySrcLoc,31808 src: LazySrcLoc,
31905 decl_index: InternPool.DeclIndex,31809 decl_index: InternPool.DeclIndex,
31906) !void {31810) !void {
31907 if (sema.mod.comp.reference_trace == 0) return;31811 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 }
31916 try sema.mod.reference_table.put(sema.gpa, decl_index, .{31812 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,
31918 .src = src,31816 .src = src,
31919 });31817 });
31920}31818}
...@@ -31924,7 +31822,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile...@@ -31924,7 +31822,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
31924 const ip = &mod.intern_pool;31822 const ip = &mod.intern_pool;
31925 const decl = mod.declPtr(decl_index);31823 const decl = mod.declPtr(decl_index);
31926 if (decl.analysis == .in_progress) {31824 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", .{});
31928 return sema.failWithOwnedErrorMsg(null, msg);31829 return sema.failWithOwnedErrorMsg(null, msg);
31929 }31830 }
3193031831
...@@ -32419,10 +32320,9 @@ fn analyzeSlice(...@@ -32419,10 +32320,9 @@ fn analyzeSlice(
32419 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {32320 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
32420 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {32321 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
32421 const msg = msg: {32322 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, .{});
32423 errdefer msg.destroy(sema.gpa);32324 errdefer msg.destroy(sema.gpa);
32424 try sema.errNote(32325 try sema.errNote(
32425 block,
32426 start_src,32326 start_src,
32427 msg,32327 msg,
32428 "expected '{}', found '{}'",32328 "expected '{}', found '{}'",
...@@ -32436,10 +32336,9 @@ fn analyzeSlice(...@@ -32436,10 +32336,9 @@ fn analyzeSlice(
32436 return sema.failWithOwnedErrorMsg(block, msg);32336 return sema.failWithOwnedErrorMsg(block, msg);
32437 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {32337 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
32438 const msg = msg: {32338 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, .{});
32440 errdefer msg.destroy(sema.gpa);32340 errdefer msg.destroy(sema.gpa);
32441 try sema.errNote(32341 try sema.errNote(
32442 block,
32443 end_src,32342 end_src,
32444 msg,32343 msg,
32445 "expected '{}', found '{}'",32344 "expected '{}', found '{}'",
...@@ -32693,9 +32592,9 @@ fn analyzeSlice(...@@ -32693,9 +32592,9 @@ fn analyzeSlice(
3269332592
32694 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {32593 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
32695 const msg = msg: {32594 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", .{});
32697 errdefer msg.destroy(sema.gpa);32596 errdefer msg.destroy(sema.gpa);
32698 try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{32597 try sema.errNote(src, msg, "expected '{}', found '{}'", .{
32699 expected_sentinel.fmtValue(mod, sema),32598 expected_sentinel.fmtValue(mod, sema),
32700 actual_sentinel.fmtValue(mod, sema),32599 actual_sentinel.fmtValue(mod, sema),
32701 });32600 });
...@@ -33567,6 +33466,31 @@ const PeerResolveStrategy = enum {...@@ -33567,6 +33466,31 @@ const PeerResolveStrategy = enum {
33567 }33466 }
33568};33467};
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
33570const PeerResolveResult = union(enum) {33494const PeerResolveResult = union(enum) {
33571 /// The peer type resolution was successful, and resulted in the given type.33495 /// The peer type resolution was successful, and resulted in the given type.
33572 success: Type,33496 success: Type,
...@@ -33591,10 +33515,9 @@ const PeerResolveResult = union(enum) {...@@ -33591,10 +33515,9 @@ const PeerResolveResult = union(enum) {
33591 block: *Block,33515 block: *Block,
33592 src: LazySrcLoc,33516 src: LazySrcLoc,
33593 instructions: []const Air.Inst.Ref,33517 instructions: []const Air.Inst.Ref,
33594 candidate_srcs: Module.PeerTypeCandidateSrc,33518 candidate_srcs: PeerTypeCandidateSrc,
33595 ) !*Module.ErrorMsg {33519 ) !*Module.ErrorMsg {
33596 const mod = sema.mod;33520 const mod = sema.mod;
33597 const decl_ptr = mod.declPtr(block.src_decl);
3359833521
33599 var opt_msg: ?*Module.ErrorMsg = null;33522 var opt_msg: ?*Module.ErrorMsg = null;
33600 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);33523 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
...@@ -33622,9 +33545,9 @@ const PeerResolveResult = union(enum) {...@@ -33622,9 +33545,9 @@ const PeerResolveResult = union(enum) {
33622 const fmt = "struct field '{}' has conflicting types";33545 const fmt = "struct field '{}' has conflicting types";
33623 const args = .{field_error.field_name.fmt(&mod.intern_pool)};33546 const args = .{field_error.field_name.fmt(&mod.intern_pool)};
33624 if (opt_msg) |msg| {33547 if (opt_msg) |msg| {
33625 try sema.errNote(block, src, msg, fmt, args);33548 try sema.errNote(src, msg, fmt, args);
33626 } else {33549 } else {
33627 opt_msg = try sema.errMsg(block, src, fmt, args);33550 opt_msg = try sema.errMsg(src, fmt, args);
33628 }33551 }
3362933552
33630 // Continue on to child error33553 // Continue on to child error
...@@ -33646,8 +33569,8 @@ const PeerResolveResult = union(enum) {...@@ -33646,8 +33569,8 @@ const PeerResolveResult = union(enum) {
33646 peer_tys[conflict_idx[1]],33569 peer_tys[conflict_idx[1]],
33647 };33570 };
33648 const conflict_srcs: [2]?LazySrcLoc = .{33571 const conflict_srcs: [2]?LazySrcLoc = .{
33649 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]),33572 candidate_srcs.resolve(block, conflict_idx[0]),
33650 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]),33573 candidate_srcs.resolve(block, conflict_idx[1]),
33651 };33574 };
3365233575
33653 const fmt = "incompatible types: '{}' and '{}'";33576 const fmt = "incompatible types: '{}' and '{}'";
...@@ -33656,16 +33579,16 @@ const PeerResolveResult = union(enum) {...@@ -33656,16 +33579,16 @@ const PeerResolveResult = union(enum) {
33656 conflict_tys[1].fmt(mod),33579 conflict_tys[1].fmt(mod),
33657 };33580 };
33658 const msg = if (opt_msg) |msg| msg: {33581 const msg = if (opt_msg) |msg| msg: {
33659 try sema.errNote(block, src, msg, fmt, args);33582 try sema.errNote(src, msg, fmt, args);
33660 break :msg msg;33583 break :msg msg;
33661 } else msg: {33584 } else msg: {
33662 const msg = try sema.errMsg(block, src, fmt, args);33585 const msg = try sema.errMsg(src, fmt, args);
33663 opt_msg = msg;33586 opt_msg = msg;
33664 break :msg msg;33587 break :msg msg;
33665 };33588 };
3366633589
33667 if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});33590 if (conflict_srcs[0]) |src_loc| try sema.errNote(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)});33591 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
3366933592
33670 // No child error33593 // No child error
33671 break;33594 break;
...@@ -33680,7 +33603,7 @@ fn resolvePeerTypes(...@@ -33680,7 +33603,7 @@ fn resolvePeerTypes(
33680 block: *Block,33603 block: *Block,
33681 src: LazySrcLoc,33604 src: LazySrcLoc,
33682 instructions: []const Air.Inst.Ref,33605 instructions: []const Air.Inst.Ref,
33683 candidate_srcs: Module.PeerTypeCandidateSrc,33606 candidate_srcs: PeerTypeCandidateSrc,
33684) !Type {33607) !Type {
33685 switch (instructions.len) {33608 switch (instructions.len) {
33686 0 => return Type.noreturn,33609 0 => return Type.noreturn,
...@@ -35119,9 +35042,9 @@ pub fn resolveStructAlignment(...@@ -35119,9 +35042,9 @@ pub fn resolveStructAlignment(
35119}35042}
3512035043
35121fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {35044fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35122 const mod = sema.mod;35045 const zcu = sema.mod;
35123 const ip = &mod.intern_pool;35046 const ip = &zcu.intern_pool;
35124 const struct_type = mod.typeToStruct(ty) orelse return;35047 const struct_type = zcu.typeToStruct(ty) orelse return;
3512535048
35126 if (struct_type.haveLayout(ip))35049 if (struct_type.haveLayout(ip))
35127 return;35050 return;
...@@ -35129,16 +35052,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35129,16 +35052,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35129 try sema.resolveTypeFields(ty);35052 try sema.resolveTypeFields(ty);
3513035053
35131 if (struct_type.layout == .@"packed") {35054 if (struct_type.layout == .@"packed") {
35132 try semaBackingIntType(mod, struct_type);35055 try semaBackingIntType(zcu, struct_type);
35133 return;35056 return;
35134 }35057 }
3513535058
35136 if (struct_type.setLayoutWip(ip)) {35059 if (struct_type.setLayoutWip(ip)) {
35137 const msg = try Module.ErrorMsg.create(35060 const msg = try sema.errMsg(
35138 sema.gpa,35061 ty.srcLoc(zcu),
35139 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35140 "struct '{}' depends on itself",35062 "struct '{}' depends on itself",
35141 .{ty.fmt(mod)},35063 .{ty.fmt(zcu)},
35142 );35064 );
35143 return sema.failWithOwnedErrorMsg(null, msg);35065 return sema.failWithOwnedErrorMsg(null, msg);
35144 }35066 }
...@@ -35175,9 +35097,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35175,9 +35097,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35175 }35097 }
3517635098
35177 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {35099 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35178 const msg = try Module.ErrorMsg.create(35100 const msg = try sema.errMsg(
35179 sema.gpa,35101 ty.srcLoc(zcu),
35180 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35181 "struct layout depends on it having runtime bits",35102 "struct layout depends on it having runtime bits",
35182 .{},35103 .{},
35183 );35104 );
...@@ -35185,11 +35106,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35185,11 +35106,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35185 }35106 }
3518635107
35187 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and35108 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))))
35189 {35110 {
35190 const msg = try Module.ErrorMsg.create(35111 const msg = try sema.errMsg(
35191 sema.gpa,35112 ty.srcLoc(zcu),
35192 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35193 "struct layout depends on being pointer aligned",35113 "struct layout depends on being pointer aligned",
35194 .{},35114 .{},
35195 );35115 );
...@@ -35221,7 +35141,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35221,7 +35141,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35221 return a_align.compare(.gt, b_align);35141 return a_align.compare(.gt, b_align);
35222 }35142 }
35223 };35143 };
35224 if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) {35144 if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) {
35225 // TODO: don't handle tuples differently. This logic exists only because it35145 // TODO: don't handle tuples differently. This logic exists only because it
35226 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!35146 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!
35227 // Likewise, implement field reordering support in all the backends!35147 // Likewise, implement field reordering support in all the backends!
...@@ -35272,7 +35192,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35272,7 +35192,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35272 var analysis_arena = std.heap.ArenaAllocator.init(gpa);35192 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
35273 defer analysis_arena.deinit();35193 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);
35276 defer comptime_err_ret_trace.deinit();35196 defer comptime_err_ret_trace.deinit();
3527735197
35278 var sema: Sema = .{35198 var sema: Sema = .{
...@@ -35294,11 +35214,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35294,11 +35214,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35294 var block: Block = .{35214 var block: Block = .{
35295 .parent = null,35215 .parent = null,
35296 .sema = &sema,35216 .sema = &sema,
35297 .src_decl = decl_index,
35298 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,35217 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,
35299 .instructions = .{},35218 .instructions = .{},
35300 .inlining = null,35219 .inlining = null,
35301 .is_comptime = true,35220 .is_comptime = true,
35221 .src_base_inst = struct_type.zir_index.unwrap().?,
35222 .type_name_ctx = decl.name,
35302 };35223 };
35303 defer assert(block.instructions.items.len == 0);35224 defer assert(block.instructions.items.len == 0);
3530435225
...@@ -35331,7 +35252,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35331,7 +35252,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35331 const backing_int_body_len = zir.extra[extra_index];35252 const backing_int_body_len = zir.extra[extra_index];
35332 extra_index += 1;35253 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 };
35335 const backing_int_ty = blk: {35259 const backing_int_ty = blk: {
35336 if (backing_int_body_len == 0) {35260 if (backing_int_body_len == 0) {
35337 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);35261 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...@@ -35347,7 +35271,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35347 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();35271 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35348 } else {35272 } else {
35349 if (fields_bit_sum > std.math.maxInt(u16)) {35273 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});
35351 }35275 }
35352 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));35276 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
35353 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();35277 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
...@@ -35374,9 +35298,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {...@@ -35374,9 +35298,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
35374 const mod = sema.mod;35298 const mod = sema.mod;
35375 if (!ty.isIndexable(mod)) {35299 if (!ty.isIndexable(mod)) {
35376 const msg = msg: {35300 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)});
35378 errdefer msg.destroy(sema.gpa);35302 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", .{});
35380 break :msg msg;35304 break :msg msg;
35381 };35305 };
35382 return sema.failWithOwnedErrorMsg(block, msg);35306 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -35397,9 +35321,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void...@@ -35397,9 +35321,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
35397 }35321 }
35398 }35322 }
35399 const msg = msg: {35323 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)});
35401 errdefer msg.destroy(sema.gpa);35325 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", .{});
35403 break :msg msg;35327 break :msg msg;
35404 };35328 };
35405 return sema.failWithOwnedErrorMsg(block, msg);35329 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -35450,8 +35374,8 @@ pub fn resolveUnionAlignment(...@@ -35450,8 +35374,8 @@ pub fn resolveUnionAlignment(
3545035374
35451/// This logic must be kept in sync with `Module.getUnionLayout`.35375/// This logic must be kept in sync with `Module.getUnionLayout`.
35452fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {35376fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35453 const mod = sema.mod;35377 const zcu = sema.mod;
35454 const ip = &mod.intern_pool;35378 const ip = &zcu.intern_pool;
3545535379
35456 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));35380 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));
3545735381
...@@ -35461,11 +35385,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35461,11 +35385,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35461 switch (union_type.flagsPtr(ip).status) {35385 switch (union_type.flagsPtr(ip).status) {
35462 .none, .have_field_types => {},35386 .none, .have_field_types => {},
35463 .field_types_wip, .layout_wip => {35387 .field_types_wip, .layout_wip => {
35464 const msg = try Module.ErrorMsg.create(35388 const msg = try sema.errMsg(
35465 sema.gpa,35389 ty.srcLoc(zcu),
35466 mod.declPtr(union_type.decl).srcLoc(mod),
35467 "union '{}' depends on itself",35390 "union '{}' depends on itself",
35468 .{ty.fmt(mod)},35391 .{ty.fmt(zcu)},
35469 );35392 );
35470 return sema.failWithOwnedErrorMsg(null, msg);35393 return sema.failWithOwnedErrorMsg(null, msg);
35471 },35394 },
...@@ -35484,7 +35407,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35484,7 +35407,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35484 for (0..union_type.field_types.len) |field_index| {35407 for (0..union_type.field_types.len) |field_index| {
35485 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);35408 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
35489 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {35412 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
35490 error.AnalysisFail => {35413 error.AnalysisFail => {
...@@ -35526,7 +35449,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35526,7 +35449,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35526 } else {35449 } else {
35527 // {Payload, Tag}35450 // {Payload, Tag}
35528 size += max_size;35451 size += max_size;
35529 size = switch (mod.getTarget().ofmt) {35452 size = switch (zcu.getTarget().ofmt) {
35530 .c => max_align,35453 .c => max_align,
35531 else => tag_align,35454 else => tag_align,
35532 }.forward(size);35455 }.forward(size);
...@@ -35545,9 +35468,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35545,9 +35468,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35545 flags.status = .have_layout;35468 flags.status = .have_layout;
3554635469
35547 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {35470 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35548 const msg = try Module.ErrorMsg.create(35471 const msg = try sema.errMsg(
35549 sema.gpa,35472 ty.srcLoc(zcu),
35550 mod.declPtr(union_type.decl).srcLoc(mod),
35551 "union layout depends on it having runtime bits",35473 "union layout depends on it having runtime bits",
35552 .{},35474 .{},
35553 );35475 );
...@@ -35555,11 +35477,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35555,11 +35477,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35555 }35477 }
3555635478
35557 if (union_type.flagsPtr(ip).assumed_pointer_aligned and35479 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))))
35559 {35481 {
35560 const msg = try Module.ErrorMsg.create(35482 const msg = try sema.errMsg(
35561 sema.gpa,35483 ty.srcLoc(zcu),
35562 mod.declPtr(union_type.decl).srcLoc(mod),
35563 "union layout depends on being pointer aligned",35484 "union layout depends on being pointer aligned",
35564 .{},35485 .{},
35565 );35486 );
...@@ -35783,12 +35704,12 @@ pub fn resolveTypeFieldsStruct(...@@ -35783,12 +35704,12 @@ pub fn resolveTypeFieldsStruct(
35783 ty: InternPool.Index,35704 ty: InternPool.Index,
35784 struct_type: InternPool.LoadedStructType,35705 struct_type: InternPool.LoadedStructType,
35785) CompileError!void {35706) CompileError!void {
35786 const mod = sema.mod;35707 const zcu = sema.mod;
35787 const ip = &mod.intern_pool;35708 const ip = &zcu.intern_pool;
35788 // If there is no owner decl it means the struct has no fields.35709 // If there is no owner decl it means the struct has no fields.
35789 const owner_decl = struct_type.decl.unwrap() orelse return;35710 const owner_decl = struct_type.decl.unwrap() orelse return;
3579035711
35791 switch (mod.declPtr(owner_decl).analysis) {35712 switch (zcu.declPtr(owner_decl).analysis) {
35792 .file_failure,35713 .file_failure,
35793 .dependency_failure,35714 .dependency_failure,
35794 .sema_failure,35715 .sema_failure,
...@@ -35802,20 +35723,19 @@ pub fn resolveTypeFieldsStruct(...@@ -35802,20 +35723,19 @@ pub fn resolveTypeFieldsStruct(
35802 if (struct_type.haveFieldTypes(ip)) return;35723 if (struct_type.haveFieldTypes(ip)) return;
3580335724
35804 if (struct_type.setTypesWip(ip)) {35725 if (struct_type.setTypesWip(ip)) {
35805 const msg = try Module.ErrorMsg.create(35726 const msg = try sema.errMsg(
35806 sema.gpa,35727 Type.fromInterned(ty).srcLoc(zcu),
35807 mod.declPtr(owner_decl).srcLoc(mod),
35808 "struct '{}' depends on itself",35728 "struct '{}' depends on itself",
35809 .{Type.fromInterned(ty).fmt(mod)},35729 .{Type.fromInterned(ty).fmt(zcu)},
35810 );35730 );
35811 return sema.failWithOwnedErrorMsg(null, msg);35731 return sema.failWithOwnedErrorMsg(null, msg);
35812 }35732 }
35813 defer struct_type.clearTypesWip(ip);35733 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) {
35816 error.AnalysisFail => {35736 error.AnalysisFail => {
35817 if (mod.declPtr(owner_decl).analysis == .complete) {35737 if (zcu.declPtr(owner_decl).analysis == .complete) {
35818 mod.declPtr(owner_decl).analysis = .dependency_failure;35738 zcu.declPtr(owner_decl).analysis = .dependency_failure;
35819 }35739 }
35820 return error.AnalysisFail;35740 return error.AnalysisFail;
35821 },35741 },
...@@ -35824,9 +35744,9 @@ pub fn resolveTypeFieldsStruct(...@@ -35824,9 +35744,9 @@ pub fn resolveTypeFieldsStruct(
35824}35744}
3582535745
35826pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {35746pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35827 const mod = sema.mod;35747 const zcu = sema.mod;
35828 const ip = &mod.intern_pool;35748 const ip = &zcu.intern_pool;
35829 const struct_type = mod.typeToStruct(ty) orelse return;35749 const struct_type = zcu.typeToStruct(ty) orelse return;
35830 const owner_decl = struct_type.decl.unwrap() orelse return;35750 const owner_decl = struct_type.decl.unwrap() orelse return;
3583135751
35832 // Inits can start as resolved35752 // Inits can start as resolved
...@@ -35835,20 +35755,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {...@@ -35835,20 +35755,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35835 try sema.resolveStructLayout(ty);35755 try sema.resolveStructLayout(ty);
3583635756
35837 if (struct_type.setInitsWip(ip)) {35757 if (struct_type.setInitsWip(ip)) {
35838 const msg = try Module.ErrorMsg.create(35758 const msg = try sema.errMsg(
35839 sema.gpa,35759 ty.srcLoc(zcu),
35840 mod.declPtr(owner_decl).srcLoc(mod),
35841 "struct '{}' depends on itself",35760 "struct '{}' depends on itself",
35842 .{ty.fmt(mod)},35761 .{ty.fmt(zcu)},
35843 );35762 );
35844 return sema.failWithOwnedErrorMsg(null, msg);35763 return sema.failWithOwnedErrorMsg(null, msg);
35845 }35764 }
35846 defer struct_type.clearInitsWip(ip);35765 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) {
35849 error.AnalysisFail => {35768 error.AnalysisFail => {
35850 if (mod.declPtr(owner_decl).analysis == .complete) {35769 if (zcu.declPtr(owner_decl).analysis == .complete) {
35851 mod.declPtr(owner_decl).analysis = .dependency_failure;35770 zcu.declPtr(owner_decl).analysis = .dependency_failure;
35852 }35771 }
35853 return error.AnalysisFail;35772 return error.AnalysisFail;
35854 },35773 },
...@@ -35858,9 +35777,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {...@@ -35858,9 +35777,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35858}35777}
3585935778
35860pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {35779pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {
35861 const mod = sema.mod;35780 const zcu = sema.mod;
35862 const ip = &mod.intern_pool;35781 const ip = &zcu.intern_pool;
35863 const owner_decl = mod.declPtr(union_type.decl);35782 const owner_decl = zcu.declPtr(union_type.decl);
35864 switch (owner_decl.analysis) {35783 switch (owner_decl.analysis) {
35865 .file_failure,35784 .file_failure,
35866 .dependency_failure,35785 .dependency_failure,
...@@ -35874,11 +35793,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35874,11 +35793,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
35874 switch (union_type.flagsPtr(ip).status) {35793 switch (union_type.flagsPtr(ip).status) {
35875 .none => {},35794 .none => {},
35876 .field_types_wip => {35795 .field_types_wip => {
35877 const msg = try Module.ErrorMsg.create(35796 const msg = try sema.errMsg(
35878 sema.gpa,35797 ty.srcLoc(zcu),
35879 owner_decl.srcLoc(mod),
35880 "union '{}' depends on itself",35798 "union '{}' depends on itself",
35881 .{ty.fmt(mod)},35799 .{ty.fmt(zcu)},
35882 );35800 );
35883 return sema.failWithOwnedErrorMsg(null, msg);35801 return sema.failWithOwnedErrorMsg(null, msg);
35884 },35802 },
...@@ -35892,7 +35810,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35892,7 +35810,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589235810
35893 union_type.flagsPtr(ip).status = .field_types_wip;35811 union_type.flagsPtr(ip).status = .field_types_wip;
35894 errdefer union_type.flagsPtr(ip).status = .none;35812 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) {
35896 error.AnalysisFail => {35814 error.AnalysisFail => {
35897 if (owner_decl.analysis == .complete) {35815 if (owner_decl.analysis == .complete) {
35898 owner_decl.analysis = .dependency_failure;35816 owner_decl.analysis = .dependency_failure;
...@@ -35942,10 +35860,13 @@ fn resolveInferredErrorSet(...@@ -35942,10 +35860,13 @@ fn resolveInferredErrorSet(
35942 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {35860 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {
35943 if (ies_func_info.is_generic) {35861 if (ies_func_info.is_generic) {
35944 const msg = msg: {35862 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", .{});
35946 errdefer msg.destroy(sema.gpa);35864 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", .{});
35949 break :msg msg;35870 break :msg msg;
35950 };35871 };
35951 return sema.failWithOwnedErrorMsg(block, msg);35872 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -36126,7 +36047,7 @@ fn semaStructFields(...@@ -36126,7 +36047,7 @@ fn semaStructFields(
36126 },36047 },
36127 };36048 };
3612836049
36129 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);36050 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36130 defer comptime_err_ret_trace.deinit();36051 defer comptime_err_ret_trace.deinit();
3613136052
36132 var sema: Sema = .{36053 var sema: Sema = .{
...@@ -36148,11 +36069,12 @@ fn semaStructFields(...@@ -36148,11 +36069,12 @@ fn semaStructFields(
36148 var block_scope: Block = .{36069 var block_scope: Block = .{
36149 .parent = null,36070 .parent = null,
36150 .sema = &sema,36071 .sema = &sema,
36151 .src_decl = decl_index,
36152 .namespace = namespace_index,36072 .namespace = namespace_index,
36153 .instructions = .{},36073 .instructions = .{},
36154 .inlining = null,36074 .inlining = null,
36155 .is_comptime = true,36075 .is_comptime = true,
36076 .src_base_inst = struct_type.zir_index.unwrap().?,
36077 .type_name_ctx = decl.name,
36156 };36078 };
36157 defer assert(block_scope.instructions.items.len == 0);36079 defer assert(block_scope.instructions.items.len == 0);
3615836080
...@@ -36231,35 +36153,19 @@ fn semaStructFields(...@@ -36231,35 +36153,19 @@ fn semaStructFields(
36231 // so that init values may depend on type layout.36153 // so that init values may depend on type layout.
3623236154
36233 for (fields, 0..) |zir_field, field_i| {36155 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 };
36234 const field_ty: Type = ty: {36160 const field_ty: Type = ty: {
36235 if (zir_field.type_ref != .none) {36161 if (zir_field.type_ref != .none) {
36236 break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) {36162 break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
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 };
36247 }36163 }
36248 assert(zir_field.type_body_len != 0);36164 assert(zir_field.type_body_len != 0);
36249 const body = zir.bodySlice(extra_index, zir_field.type_body_len);36165 const body = zir.bodySlice(extra_index, zir_field.type_body_len);
36250 extra_index += body.len;36166 extra_index += body.len;
36251 const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);36167 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) {36168 break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
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 };
36263 };36169 };
36264 if (field_ty.isGenericPoison()) {36170 if (field_ty.isGenericPoison()) {
36265 return error.GenericPoison;36171 return error.GenericPoison;
...@@ -36269,11 +36175,7 @@ fn semaStructFields(...@@ -36269,11 +36175,7 @@ fn semaStructFields(
3626936175
36270 if (field_ty.zigTypeTag(mod) == .Opaque) {36176 if (field_ty.zigTypeTag(mod) == .Opaque) {
36271 const msg = msg: {36177 const msg = msg: {
36272 const ty_src = mod.fieldSrcLoc(decl_index, .{36178 const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
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", .{});
36277 errdefer msg.destroy(sema.gpa);36179 errdefer msg.destroy(sema.gpa);
3627836180
36279 try sema.addDeclaredHereNote(msg, field_ty);36181 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36283,11 +36185,7 @@ fn semaStructFields(...@@ -36283,11 +36185,7 @@ fn semaStructFields(
36283 }36185 }
36284 if (field_ty.zigTypeTag(mod) == .NoReturn) {36186 if (field_ty.zigTypeTag(mod) == .NoReturn) {
36285 const msg = msg: {36187 const msg = msg: {
36286 const ty_src = mod.fieldSrcLoc(decl_index, .{36188 const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{});
36287 .index = field_i,
36288 .range = .type,
36289 }).lazy;
36290 const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{});
36291 errdefer msg.destroy(sema.gpa);36189 errdefer msg.destroy(sema.gpa);
3629236190
36293 try sema.addDeclaredHereNote(msg, field_ty);36191 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36298,11 +36196,7 @@ fn semaStructFields(...@@ -36298,11 +36196,7 @@ fn semaStructFields(
36298 switch (struct_type.layout) {36196 switch (struct_type.layout) {
36299 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {36197 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {
36300 const msg = msg: {36198 const msg = msg: {
36301 const ty_src = mod.fieldSrcLoc(decl_index, .{36199 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
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)});
36306 errdefer msg.destroy(sema.gpa);36200 errdefer msg.destroy(sema.gpa);
3630736201
36308 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);36202 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);
...@@ -36314,11 +36208,7 @@ fn semaStructFields(...@@ -36314,11 +36208,7 @@ fn semaStructFields(
36314 },36208 },
36315 .@"packed" => if (!try sema.validatePackedType(field_ty)) {36209 .@"packed" => if (!try sema.validatePackedType(field_ty)) {
36316 const msg = msg: {36210 const msg = msg: {
36317 const ty_src = mod.fieldSrcLoc(decl_index, .{36211 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
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)});
36322 errdefer msg.destroy(sema.gpa);36212 errdefer msg.destroy(sema.gpa);
3632336213
36324 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);36214 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
...@@ -36335,17 +36225,11 @@ fn semaStructFields(...@@ -36335,17 +36225,11 @@ fn semaStructFields(
36335 const body = zir.bodySlice(extra_index, zir_field.align_body_len);36225 const body = zir.bodySlice(extra_index, zir_field.align_body_len);
36336 extra_index += body.len;36226 extra_index += body.len;
36337 const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);36227 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) {36228 const align_src: LazySrcLoc = .{
36339 error.NeededSourceLocation => {36229 .base_node_inst = struct_type.zir_index.unwrap().?,
36340 const align_src = mod.fieldSrcLoc(decl_index, .{36230 .offset = .{ .container_field_align = @intCast(field_i) },
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,
36348 };36231 };
36232 const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
36349 struct_type.field_aligns.get(ip)[field_i] = field_align;36233 struct_type.field_aligns.get(ip)[field_i] = field_align;
36350 }36234 }
3635136235
...@@ -36374,7 +36258,7 @@ fn semaStructFieldInits(...@@ -36374,7 +36258,7 @@ fn semaStructFieldInits(
36374 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);36258 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
36375 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);36259 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);
36378 defer comptime_err_ret_trace.deinit();36262 defer comptime_err_ret_trace.deinit();
3637936263
36380 var sema: Sema = .{36264 var sema: Sema = .{
...@@ -36396,11 +36280,12 @@ fn semaStructFieldInits(...@@ -36396,11 +36280,12 @@ fn semaStructFieldInits(
36396 var block_scope: Block = .{36280 var block_scope: Block = .{
36397 .parent = null,36281 .parent = null,
36398 .sema = &sema,36282 .sema = &sema,
36399 .src_decl = decl_index,
36400 .namespace = namespace_index,36283 .namespace = namespace_index,
36401 .instructions = .{},36284 .instructions = .{},
36402 .inlining = null,36285 .inlining = null,
36403 .is_comptime = true,36286 .is_comptime = true,
36287 .src_base_inst = struct_type.zir_index.unwrap().?,
36288 .type_name_ctx = decl.name,
36404 };36289 };
36405 defer assert(block_scope.instructions.items.len == 0);36290 defer assert(block_scope.instructions.items.len == 0);
3640636291
...@@ -36474,33 +36359,20 @@ fn semaStructFieldInits(...@@ -36474,33 +36359,20 @@ fn semaStructFieldInits(
36474 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});36359 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
36475 sema.inst_map.putAssumeCapacity(zir_index, type_ref);36360 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
3647636361
36477 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);36362 const init_src: LazySrcLoc = .{
36478 const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) {36363 .base_node_inst = struct_type.zir_index.unwrap().?,
36479 error.NeededSourceLocation => {36364 .offset = .{ .container_field_value = @intCast(field_i) },
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,
36488 };36365 };
36489 const default_val = (try sema.resolveValue(coerced)) orelse {36366
36490 const init_src = mod.fieldSrcLoc(decl_index, .{36367 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36491 .index = field_i,36368 const coerced = try sema.coerce(&block_scope, field_ty, init, init_src);
36492 .range = .value,36369 const default_val = try sema.resolveValue(coerced) orelse {
36493 }).lazy;
36494 return sema.failWithNeededComptime(&block_scope, init_src, .{36370 return sema.failWithNeededComptime(&block_scope, init_src, .{
36495 .needed_comptime_reason = "struct field default value must be comptime-known",36371 .needed_comptime_reason = "struct field default value must be comptime-known",
36496 });36372 });
36497 };36373 };
3649836374
36499 if (default_val.canMutateComptimeVarState(mod)) {36375 if (default_val.canMutateComptimeVarState(mod)) {
36500 const init_src = mod.fieldSrcLoc(decl_index, .{
36501 .index = field_i,
36502 .range = .value,
36503 }).lazy;
36504 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});36376 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});
36505 }36377 }
36506 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();36378 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...@@ -36520,9 +36392,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36520 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;36392 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
36521 assert(extended.opcode == .union_decl);36393 assert(extended.opcode == .union_decl);
36522 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);36394 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
36523 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;36395 const extra = zir.extraData(Zir.Inst.UnionDecl, extended.operand);
3652436396 var extra_index: usize = extra.end;
36525 const src = LazySrcLoc.nodeOffset(0);
3652636397
36527 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {36398 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
36528 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);36399 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...@@ -36562,7 +36433,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3656236433
36563 const decl = mod.declPtr(decl_index);36434 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);
36566 defer comptime_err_ret_trace.deinit();36437 defer comptime_err_ret_trace.deinit();
3656736438
36568 var sema: Sema = .{36439 var sema: Sema = .{
...@@ -36584,14 +36455,17 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36584,14 +36455,17 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36584 var block_scope: Block = .{36455 var block_scope: Block = .{
36585 .parent = null,36456 .parent = null,
36586 .sema = &sema,36457 .sema = &sema,
36587 .src_decl = decl_index,
36588 .namespace = union_type.namespace.unwrap().?,36458 .namespace = union_type.namespace.unwrap().?,
36589 .instructions = .{},36459 .instructions = .{},
36590 .inlining = null,36460 .inlining = null,
36591 .is_comptime = true,36461 .is_comptime = true,
36462 .src_base_inst = union_type.zir_index,
36463 .type_name_ctx = decl.name,
36592 };36464 };
36593 defer assert(block_scope.instructions.items.len == 0);36465 defer assert(block_scope.instructions.items.len == 0);
3659436466
36467 const src = block_scope.nodeOffset(0);
36468
36595 if (body.len != 0) {36469 if (body.len != 0) {
36596 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);36470 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);
36597 }36471 }
...@@ -36601,7 +36475,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36601,7 +36475,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36601 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};36475 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};
36602 var explicit_tags_seen: []bool = &.{};36476 var explicit_tags_seen: []bool = &.{};
36603 if (tag_type_ref != .none) {36477 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 };
36605 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);36482 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);
36606 if (small.auto_enum_tag) {36483 if (small.auto_enum_tag) {
36607 // The provided type is an integer type and we must construct the enum tag type here.36484 // 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...@@ -36614,9 +36491,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36614 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);36491 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);
36615 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {36492 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
36616 const msg = msg: {36493 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", .{});
36618 errdefer msg.destroy(sema.gpa);36495 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}", .{
36620 int_tag_ty.fmt(mod),36497 int_tag_ty.fmt(mod),
36621 fields_len - 1,36498 fields_len - 1,
36622 });36499 });
...@@ -36701,19 +36578,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36701,19 +36578,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36701 break :blk try sema.resolveInst(tag_ref);36578 break :blk try sema.resolveInst(tag_ref);
36702 } else .none;36579 } 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
36704 if (enum_field_vals.capacity() > 0) {36598 if (enum_field_vals.capacity() > 0) {
36705 const enum_tag_val = if (tag_ref != .none) blk: {36599 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) {36600 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);
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 };
36717 last_tag_val = val;36601 last_tag_val = val;
3671836602
36719 break :blk val;36603 break :blk val;
...@@ -36728,12 +36612,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36728,12 +36612,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36728 };36612 };
36729 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());36613 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());
36730 if (gop.found_existing) {36614 if (gop.found_existing) {
36731 const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy;36615 const other_value_src: LazySrcLoc = .{
36732 const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy;36616 .base_node_inst = union_type.zir_index,
36617 .offset = .{ .container_field_value = @intCast(gop.index) },
36618 };
36733 const msg = msg: {36619 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)});
36735 errdefer msg.destroy(gpa);36621 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", .{});
36737 break :msg msg;36623 break :msg msg;
36738 };36624 };
36739 return sema.failWithOwnedErrorMsg(&block_scope, msg);36625 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36751,17 +36637,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36751,17 +36637,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36751 else if (field_type_ref == .none)36637 else if (field_type_ref == .none)
36752 Type.noreturn36638 Type.noreturn
36753 else36639 else
36754 sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) {36640 try sema.resolveType(&block_scope, type_src, field_type_ref);
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 };
3676536641
36766 if (field_ty.isGenericPoison()) {36642 if (field_ty.isGenericPoison()) {
36767 return error.GenericPoison;36643 return error.GenericPoison;
...@@ -36770,11 +36646,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36770,11 +36646,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36770 if (explicit_tags_seen.len > 0) {36646 if (explicit_tags_seen.len > 0) {
36771 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);36647 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36772 const enum_index = tag_info.nameIndex(ip, field_name) orelse {36648 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
36773 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36649 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
36774 .index = field_i,
36775 .range = .name,
36776 }).lazy;
36777 return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
36778 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),36650 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
36779 });36651 });
36780 };36652 };
...@@ -36787,17 +36659,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36787,17 +36659,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36787 // Enforce the enum fields and the union fields being in the same order.36659 // Enforce the enum fields and the union fields being in the same order.
36788 if (enum_index != field_i) {36660 if (enum_index != field_i) {
36789 const msg = msg: {36661 const msg = msg: {
36790 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36662 const enum_field_src: LazySrcLoc = .{
36791 .index = field_i,36663 .base_node_inst = tag_info.zir_index.unwrap().?,
36792 .range = .name,36664 .offset = .{ .container_field_name = enum_index },
36793 }).lazy;36665 };
36794 const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy;36666 const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{
36795 const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{
36796 field_name.fmt(ip),36667 field_name.fmt(ip),
36797 });36668 });
36798 errdefer msg.destroy(sema.gpa);36669 errdefer msg.destroy(sema.gpa);
36799 const decl_ptr = mod.declPtr(tag_info.decl);36670 try sema.errNote(enum_field_src, msg, "enum field here", .{});
36800 try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{});
36801 break :msg msg;36671 break :msg msg;
36802 };36672 };
36803 return sema.failWithOwnedErrorMsg(&block_scope, msg);36673 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36806,11 +36676,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36806,11 +36676,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3680636676
36807 if (field_ty.zigTypeTag(mod) == .Opaque) {36677 if (field_ty.zigTypeTag(mod) == .Opaque) {
36808 const msg = msg: {36678 const msg = msg: {
36809 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36679 const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
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", .{});
36814 errdefer msg.destroy(sema.gpa);36680 errdefer msg.destroy(sema.gpa);
3681536681
36816 try sema.addDeclaredHereNote(msg, field_ty);36682 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36823,14 +36689,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36823,14 +36689,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36823 !try sema.validateExternType(field_ty, .union_field))36689 !try sema.validateExternType(field_ty, .union_field))
36824 {36690 {
36825 const msg = msg: {36691 const msg = msg: {
36826 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36692 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
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)});
36831 errdefer msg.destroy(sema.gpa);36693 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
36835 try sema.addDeclaredHereNote(msg, field_ty);36697 try sema.addDeclaredHereNote(msg, field_ty);
36836 break :msg msg;36698 break :msg msg;
...@@ -36838,14 +36700,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36838,14 +36700,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36838 return sema.failWithOwnedErrorMsg(&block_scope, msg);36700 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36839 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {36701 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
36840 const msg = msg: {36702 const msg = msg: {
36841 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36703 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
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)});
36846 errdefer msg.destroy(sema.gpa);36704 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
36850 try sema.addDeclaredHereNote(msg, field_ty);36708 try sema.addDeclaredHereNote(msg, field_ty);
36851 break :msg msg;36709 break :msg msg;
...@@ -36857,17 +36715,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36857,17 +36715,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3685736715
36858 if (small.any_aligned_fields) {36716 if (small.any_aligned_fields) {
36859 field_aligns.appendAssumeCapacity(if (align_ref != .none)36717 field_aligns.appendAssumeCapacity(if (align_ref != .none)
36860 sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {36718 try sema.resolveAlign(&block_scope, align_src, align_ref)
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 }
36871 else36719 else
36872 .none);36720 .none);
36873 } else {36721 } else {
...@@ -36882,7 +36730,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36882,7 +36730,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36882 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);36730 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36883 if (tag_info.names.len > fields_len) {36731 if (tag_info.names.len > fields_len) {
36884 const msg = msg: {36732 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", .{});
36886 errdefer msg.destroy(sema.gpa);36734 errdefer msg.destroy(sema.gpa);
3688736735
36888 for (tag_info.names.get(ip), 0..) |field_name, field_index| {36736 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...@@ -36897,10 +36745,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36897 return sema.failWithOwnedErrorMsg(&block_scope, msg);36745 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36898 }36746 }
36899 } else if (enum_field_vals.count() > 0) {36747 } 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);
36901 union_type.tagTypePtr(ip).* = enum_ty;36749 union_type.tagTypePtr(ip).* = enum_ty;
36902 } else {36750 } 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);
36904 union_type.tagTypePtr(ip).* = enum_ty;36752 union_type.tagTypePtr(ip).* = enum_ty;
36905 }36753 }
36906}36754}
...@@ -36918,13 +36766,13 @@ fn generateUnionTagTypeNumbered(...@@ -36918,13 +36766,13 @@ fn generateUnionTagTypeNumbered(
36918 enum_field_names: []const InternPool.NullTerminatedString,36766 enum_field_names: []const InternPool.NullTerminatedString,
36919 enum_field_vals: []const InternPool.Index,36767 enum_field_vals: []const InternPool.Index,
36920 union_owner_decl: *Module.Decl,36768 union_owner_decl: *Module.Decl,
36769 src_line: u32,
36921) !InternPool.Index {36770) !InternPool.Index {
36922 const mod = sema.mod;36771 const mod = sema.mod;
36923 const gpa = sema.gpa;36772 const gpa = sema.gpa;
36924 const ip = &mod.intern_pool;36773 const ip = &mod.intern_pool;
3692536774
36926 const src_decl = mod.declPtr(block.src_decl);36775 const new_decl_index = try mod.allocateNewDecl(block.namespace);
36927 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36928 errdefer mod.destroyDecl(new_decl_index);36776 errdefer mod.destroyDecl(new_decl_index);
36929 const fqn = try union_owner_decl.fullyQualifiedName(mod);36777 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36930 const name = try ip.getOrPutStringFmt(36778 const name = try ip.getOrPutStringFmt(
...@@ -36935,7 +36783,7 @@ fn generateUnionTagTypeNumbered(...@@ -36935,7 +36783,7 @@ fn generateUnionTagTypeNumbered(
36935 );36783 );
36936 try mod.initNewAnonDecl(36784 try mod.initNewAnonDecl(
36937 new_decl_index,36785 new_decl_index,
36938 src_decl.src_line,36786 src_line,
36939 Value.@"unreachable",36787 Value.@"unreachable",
36940 name,36788 name,
36941 );36789 );
...@@ -36968,6 +36816,7 @@ fn generateUnionTagTypeSimple(...@@ -36968,6 +36816,7 @@ fn generateUnionTagTypeSimple(
36968 block: *Block,36816 block: *Block,
36969 enum_field_names: []const InternPool.NullTerminatedString,36817 enum_field_names: []const InternPool.NullTerminatedString,
36970 union_owner_decl: *Module.Decl,36818 union_owner_decl: *Module.Decl,
36819 src_line: u32,
36971) !InternPool.Index {36820) !InternPool.Index {
36972 const mod = sema.mod;36821 const mod = sema.mod;
36973 const ip = &mod.intern_pool;36822 const ip = &mod.intern_pool;
...@@ -36975,8 +36824,7 @@ fn generateUnionTagTypeSimple(...@@ -36975,8 +36824,7 @@ fn generateUnionTagTypeSimple(
3697536824
36976 const new_decl_index = new_decl_index: {36825 const new_decl_index = new_decl_index: {
36977 const fqn = try union_owner_decl.fullyQualifiedName(mod);36826 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36978 const src_decl = mod.declPtr(block.src_decl);36827 const new_decl_index = try mod.allocateNewDecl(block.namespace);
36979 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36980 errdefer mod.destroyDecl(new_decl_index);36828 errdefer mod.destroyDecl(new_decl_index);
36981 const name = try ip.getOrPutStringFmt(36829 const name = try ip.getOrPutStringFmt(
36982 gpa,36830 gpa,
...@@ -36986,7 +36834,7 @@ fn generateUnionTagTypeSimple(...@@ -36986,7 +36834,7 @@ fn generateUnionTagTypeSimple(
36986 );36834 );
36987 try mod.initNewAnonDecl(36835 try mod.initNewAnonDecl(
36988 new_decl_index,36836 new_decl_index,
36989 src_decl.src_line,36837 src_line,
36990 Value.@"unreachable",36838 Value.@"unreachable",
36991 name,36839 name,
36992 );36840 );
...@@ -37016,19 +36864,33 @@ fn generateUnionTagTypeSimple(...@@ -37016,19 +36864,33 @@ fn generateUnionTagTypeSimple(
37016}36864}
3701736865
37018fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {36866fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37019 const gpa = sema.gpa;36867 const zcu = sema.mod;
37020 const src = LazySrcLoc.nodeOffset(0);
3702136868
37022 var block: Block = .{36869 var block: Block = .{
37023 .parent = null,36870 .parent = null,
37024 .sema = sema,36871 .sema = sema,
37025 .src_decl = sema.owner_decl_index,
37026 .namespace = sema.owner_decl.src_namespace,36872 .namespace = sema.owner_decl.src_namespace,
37027 .instructions = .{},36873 .instructions = .{},
37028 .inlining = null,36874 .inlining = null,
37029 .is_comptime = true,36875 .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,
37030 };36890 };
37031 defer block.instructions.deinit(gpa);36891 defer block.instructions.deinit(sema.gpa);
36892
36893 const src = block.nodeOffset(0);
3703236894
37033 const decl_index = try getBuiltinDecl(sema, &block, name);36895 const decl_index = try getBuiltinDecl(sema, &block, name);
37034 return sema.analyzeDeclVal(&block, src, decl_index);36896 return sema.analyzeDeclVal(&block, src, decl_index);
...@@ -37037,7 +36899,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {...@@ -37037,7 +36899,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37037fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {36899fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
37038 const gpa = sema.gpa;36900 const gpa = sema.gpa;
3703936901
37040 const src = LazySrcLoc.nodeOffset(0);36902 const src = block.nodeOffset(0);
3704136903
37042 const mod = sema.mod;36904 const mod = sema.mod;
37043 const ip = &mod.intern_pool;36905 const ip = &mod.intern_pool;
...@@ -37064,19 +36926,34 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int...@@ -37064,19 +36926,34 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
37064}36926}
3706536927
37066fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {36928fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36929 const zcu = sema.mod;
37067 const ty_inst = try sema.getBuiltin(name);36930 const ty_inst = try sema.getBuiltin(name);
3706836931
37069 var block: Block = .{36932 var block: Block = .{
37070 .parent = null,36933 .parent = null,
37071 .sema = sema,36934 .sema = sema,
37072 .src_decl = sema.owner_decl_index,
37073 .namespace = sema.owner_decl.src_namespace,36935 .namespace = sema.owner_decl.src_namespace,
37074 .instructions = .{},36936 .instructions = .{},
37075 .inlining = null,36937 .inlining = null,
37076 .is_comptime = true,36938 .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,
37077 };36953 };
37078 defer block.instructions.deinit(sema.gpa);36954 defer block.instructions.deinit(sema.gpa);
37079 const src = LazySrcLoc.nodeOffset(0);36955
36956 const src = block.nodeOffset(0);
3708036957
37081 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {36958 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {
37082 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),36959 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),
...@@ -37092,12 +36969,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -37092,12 +36969,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
37092/// that the types are already resolved.36969/// that the types are already resolved.
37093/// TODO assert the return value matches `ty.onePossibleValue`36970/// TODO assert the return value matches `ty.onePossibleValue`
37094pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {36971pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37095 const mod = sema.mod;36972 const zcu = sema.mod;
37096 const ip = &mod.intern_pool;36973 const ip = &zcu.intern_pool;
37097 return switch (ty.toIntern()) {36974 return switch (ty.toIntern()) {
37098 .u0_type,36975 .u0_type,
37099 .i0_type,36976 .i0_type,
37100 => try mod.intValue(ty, 0),36977 => try zcu.intValue(ty, 0),
37101 .u1_type,36978 .u1_type,
37102 .u8_type,36979 .u8_type,
37103 .i8_type,36980 .i8_type,
...@@ -37160,7 +37037,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37160,7 +37037,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37160 .anyframe_type => unreachable,37037 .anyframe_type => unreachable,
37161 .null_type => Value.null,37038 .null_type => Value.null,
37162 .undefined_type => Value.undef,37039 .undefined_type => Value.undef,
37163 .optional_noreturn_type => try mod.nullValue(ty),37040 .optional_noreturn_type => try zcu.nullValue(ty),
37164 .generic_poison_type => error.GenericPoison,37041 .generic_poison_type => error.GenericPoison,
37165 .empty_struct_type => Value.empty_struct,37042 .empty_struct_type => Value.empty_struct,
37166 // values, not types37043 // values, not types
...@@ -37274,13 +37151,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37274,13 +37151,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37274 => switch (ip.indexToKey(ty.toIntern())) {37151 => switch (ip.indexToKey(ty.toIntern())) {
37275 inline .array_type, .vector_type => |seq_type, seq_tag| {37152 inline .array_type, .vector_type => |seq_type, seq_tag| {
37276 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;37153 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 = .{
37278 .ty = ty.toIntern(),37155 .ty = ty.toIntern(),
37279 .storage = .{ .elems = &.{} },37156 .storage = .{ .elems = &.{} },
37280 } })));37157 } })));
3728137158
37282 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {37159 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 = .{
37284 .ty = ty.toIntern(),37161 .ty = ty.toIntern(),
37285 .storage = .{ .repeated_elem = opv.toIntern() },37162 .storage = .{ .repeated_elem = opv.toIntern() },
37286 } })));37163 } })));
...@@ -37295,7 +37172,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37295,7 +37172,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37295 if (struct_type.field_types.len == 0) {37172 if (struct_type.field_types.len == 0) {
37296 // In this case the struct has no fields at all and37173 // In this case the struct has no fields at all and
37297 // therefore has one possible value.37174 // therefore has one possible value.
37298 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37175 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37299 .ty = ty.toIntern(),37176 .ty = ty.toIntern(),
37300 .storage = .{ .elems = &.{} },37177 .storage = .{ .elems = &.{} },
37301 } })));37178 } })));
...@@ -37312,12 +37189,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37312,12 +37189,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37312 continue;37189 continue;
37313 }37190 }
37314 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);37191 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
37315 if (field_ty.eql(ty, mod)) {37192 if (field_ty.eql(ty, zcu)) {
37316 const msg = try Module.ErrorMsg.create(37193 const msg = try sema.errMsg(
37317 sema.gpa,37194 ty.srcLoc(zcu),
37318 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
37319 "struct '{}' depends on itself",37195 "struct '{}' depends on itself",
37320 .{ty.fmt(mod)},37196 .{ty.fmt(zcu)},
37321 );37197 );
37322 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});37198 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
37323 return sema.failWithOwnedErrorMsg(null, msg);37199 return sema.failWithOwnedErrorMsg(null, msg);
...@@ -37329,7 +37205,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37329,7 +37205,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3732937205
37330 // In this case the struct has no runtime-known fields and37206 // In this case the struct has no runtime-known fields and
37331 // therefore has one possible value.37207 // therefore has one possible value.
37332 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37208 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37333 .ty = ty.toIntern(),37209 .ty = ty.toIntern(),
37334 .storage = .{ .elems = field_vals },37210 .storage = .{ .elems = field_vals },
37335 } })));37211 } })));
...@@ -37342,7 +37218,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37342,7 +37218,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37342 // In this case the struct has all comptime-known fields and37218 // In this case the struct has all comptime-known fields and
37343 // therefore has one possible value.37219 // therefore has one possible value.
37344 // TODO: write something like getCoercedInts to avoid needing to dupe37220 // 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 = .{
37346 .ty = ty.toIntern(),37222 .ty = ty.toIntern(),
37347 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },37223 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
37348 } })));37224 } })));
...@@ -37354,23 +37230,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37354,23 +37230,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37354 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse37230 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
37355 return null;37231 return null;
37356 if (union_obj.field_types.len == 0) {37232 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() });
37358 return Value.fromInterned(only);37234 return Value.fromInterned(only);
37359 }37235 }
37360 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);37236 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
37361 if (only_field_ty.eql(ty, mod)) {37237 if (only_field_ty.eql(ty, zcu)) {
37362 const msg = try Module.ErrorMsg.create(37238 const msg = try sema.errMsg(
37363 sema.gpa,37239 ty.srcLoc(zcu),
37364 mod.declPtr(union_obj.decl).srcLoc(mod),
37365 "union '{}' depends on itself",37240 "union '{}' depends on itself",
37366 .{ty.fmt(mod)},37241 .{ty.fmt(zcu)},
37367 );37242 );
37368 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});37243 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});
37369 return sema.failWithOwnedErrorMsg(null, msg);37244 return sema.failWithOwnedErrorMsg(null, msg);
37370 }37245 }
37371 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse37246 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
37372 return null;37247 return null;
37373 const only = try mod.intern(.{ .un = .{37248 const only = try zcu.intern(.{ .un = .{
37374 .ty = ty.toIntern(),37249 .ty = ty.toIntern(),
37375 .tag = tag_val.toIntern(),37250 .tag = tag_val.toIntern(),
37376 .val = val_val.toIntern(),37251 .val = val_val.toIntern(),
...@@ -37385,7 +37260,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37385,7 +37260,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37385 if (enum_type.tag_ty == .comptime_int_type) return null;37260 if (enum_type.tag_ty == .comptime_int_type) return null;
3738637261
37387 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {37262 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 = .{
37389 .ty = ty.toIntern(),37264 .ty = ty.toIntern(),
37390 .int = int_opv.toIntern(),37265 .int = int_opv.toIntern(),
37391 } });37266 } });
...@@ -37395,18 +37270,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37395,18 +37270,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37395 return null;37270 return null;
37396 },37271 },
37397 .auto, .explicit => {37272 .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
37400 return Value.fromInterned(switch (enum_type.names.len) {37275 return Value.fromInterned(switch (enum_type.names.len) {
37401 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),37276 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }),
37402 1 => try mod.intern(.{ .enum_tag = .{37277 1 => try zcu.intern(.{ .enum_tag = .{
37403 .ty = ty.toIntern(),37278 .ty = ty.toIntern(),
37404 .int = if (enum_type.values.len == 0)37279 .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()
37406 else37281 else
37407 try mod.intern_pool.getCoercedInts(37282 try zcu.intern_pool.getCoercedInts(
37408 mod.gpa,37283 zcu.gpa,
37409 mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,37284 zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
37410 enum_type.tag_ty,37285 enum_type.tag_ty,
37411 ),37286 ),
37412 } }),37287 } }),
...@@ -37744,7 +37619,7 @@ fn unionFieldIndex(...@@ -37744,7 +37619,7 @@ fn unionFieldIndex(
37744 try sema.resolveTypeFields(union_ty);37619 try sema.resolveTypeFields(union_ty);
37745 const union_obj = mod.typeToUnion(union_ty).?;37620 const union_obj = mod.typeToUnion(union_ty).?;
37746 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse37621 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);
37748 return @intCast(field_index);37623 return @intCast(field_index);
37749}37624}
3775037625
...@@ -37763,7 +37638,7 @@ fn structFieldIndex(...@@ -37763,7 +37638,7 @@ fn structFieldIndex(
37763 } else {37638 } else {
37764 const struct_type = mod.typeToStruct(struct_ty).?;37639 const struct_type = mod.typeToStruct(struct_ty).?;
37765 return struct_type.nameIndex(ip, field_name) orelse37640 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);
37767 }37642 }
37768}37643}
3776937644
...@@ -38535,9 +38410,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {...@@ -38535,9 +38410,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {
38535fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {38410fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {
38536 if (sema.checkRuntimeValue(val)) return;38411 if (sema.checkRuntimeValue(val)) return;
38537 return sema.failWithOwnedErrorMsg(block, msg: {38412 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", .{});
38539 errdefer msg.destroy(sema.gpa);38414 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", .{});
38541 break :msg msg;38416 break :msg msg;
38542 });38417 });
38543}38418}
...@@ -38628,6 +38503,14 @@ fn maybeDerefSliceAsArray(...@@ -38628,6 +38503,14 @@ fn maybeDerefSliceAsArray(
38628 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);38503 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);
38629}38504}
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
38631pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;38514pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
38632pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;38515pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
3863338516
src/Sema/comptime_ptr_access.zig+6-5
...@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(...@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(
1025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {1025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {
1026 if (block.runtime_cond) |cond_src| {1026 if (block.runtime_cond) |cond_src| {
1027 const msg = msg: {1027 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", .{});
1029 errdefer msg.destroy(sema.gpa);1029 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", .{});
1031 break :msg msg;1031 break :msg msg;
1032 };1032 };
1033 return sema.failWithOwnedErrorMsg(block, msg);1033 return sema.failWithOwnedErrorMsg(block, msg);
1034 }1034 }
1035 if (block.runtime_loop) |loop_src| {1035 if (block.runtime_loop) |loop_src| {
1036 const msg = msg: {1036 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", .{});
1038 errdefer msg.destroy(sema.gpa);1038 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", .{});
1040 break :msg msg;1040 break :msg msg;
1041 };1041 };
1042 return sema.failWithOwnedErrorMsg(block, msg);1042 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -1048,7 +1048,6 @@ fn checkComptimeVarStore(...@@ -1048,7 +1048,6 @@ fn checkComptimeVarStore(
1048const std = @import("std");1048const std = @import("std");
1049const assert = std.debug.assert;1049const assert = std.debug.assert;
1050const Allocator = std.mem.Allocator;1050const Allocator = std.mem.Allocator;
1051const LazySrcLoc = std.zig.LazySrcLoc;
10521051
1053const InternPool = @import("../InternPool.zig");1052const InternPool = @import("../InternPool.zig");
1054const ComptimeAllocIndex = InternPool.ComptimeAllocIndex;1053const ComptimeAllocIndex = InternPool.ComptimeAllocIndex;
...@@ -1057,3 +1056,5 @@ const Block = Sema.Block;...@@ -1057,3 +1056,5 @@ const Block = Sema.Block;
1057const MutableValue = @import("../mutable_value.zig").MutableValue;1056const MutableValue = @import("../mutable_value.zig").MutableValue;
1058const Type = @import("../type.zig").Type;1057const Type = @import("../type.zig").Type;
1059const Value = @import("../Value.zig");1058const 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....@@ -4014,7 +4014,6 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu) Allocator.
4014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {4014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {
4015 error.OutOfMemory => |e| return e,4015 error.OutOfMemory => |e| return e,
4016 error.AnalysisFail,4016 error.AnalysisFail,
4017 error.NeededSourceLocation,
4018 error.GenericPoison,4017 error.GenericPoison,
4019 error.ComptimeReturn,4018 error.ComptimeReturn,
4020 error.ComptimeBreak,4019 error.ComptimeBreak,
src/arch/wasm/CodeGen.zig+2-3
...@@ -16,7 +16,6 @@ const Decl = Module.Decl;...@@ -16,7 +16,6 @@ const Decl = Module.Decl;
16const Type = @import("../../type.zig").Type;16const Type = @import("../../type.zig").Type;
17const Value = @import("../../Value.zig");17const Value = @import("../../Value.zig");
18const Compilation = @import("../../Compilation.zig");18const Compilation = @import("../../Compilation.zig");
19const LazySrcLoc = std.zig.LazySrcLoc;
20const link = @import("../../link.zig");19const link = @import("../../link.zig");
21const Air = @import("../../Air.zig");20const Air = @import("../../Air.zig");
22const Liveness = @import("../../Liveness.zig");21const Liveness = @import("../../Liveness.zig");
...@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {...@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
766/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
767fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
768 const mod = func.bin_file.base.comp.module.?;767 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);
770 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);769 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
771 return error.CodegenFail;770 return error.CodegenFail;
772}771}
...@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(...@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(
3123 }3122 }
31243123
3125 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;3124 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));
3127 switch (res) {3126 switch (res) {
3128 .ok => {},3127 .ok => {},
3129 .fail => |em| {3128 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;258 const zcu = comp.module.?;
259 const gpa = comp.gpa;259 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);
261 return error.EmitFail;261 return error.EmitFail;
262}262}
263263
src/codegen/c.zig+1-2
...@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;...@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;
13const C = link.File.C;13const C = link.File.C;
14const Decl = Zcu.Decl;14const Decl = Zcu.Decl;
15const trace = @import("../tracy.zig").trace;15const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = std.zig.LazySrcLoc;
17const Air = @import("../Air.zig");16const Air = @import("../Air.zig");
18const Liveness = @import("../Liveness.zig");17const Liveness = @import("../Liveness.zig");
19const InternPool = @import("../InternPool.zig");18const InternPool = @import("../InternPool.zig");
...@@ -638,7 +637,7 @@ pub const DeclGen = struct {...@@ -638,7 +637,7 @@ pub const DeclGen = struct {
638 const zcu = dg.zcu;637 const zcu = dg.zcu;
639 const decl_index = dg.pass.decl;638 const decl_index = dg.pass.decl;
640 const decl = zcu.declPtr(decl_index);639 const decl = zcu.declPtr(decl_index);
641 const src_loc = decl.srcLoc(zcu);640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);
642 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
643 return error.AnalysisFail;642 return error.AnalysisFail;
644 }643 }
src/codegen/c/Type.zig+1-1
...@@ -2581,8 +2581,8 @@ pub const AlignAs = packed struct {...@@ -2581,8 +2581,8 @@ pub const AlignAs = packed struct {
2581const Alignment = @import("../../InternPool.zig").Alignment;2581const Alignment = @import("../../InternPool.zig").Alignment;
2582const assert = std.debug.assert;2582const assert = std.debug.assert;
2583const CType = @This();2583const CType = @This();
2584const DeclIndex = std.zig.DeclIndex;
2585const Module = @import("../../Package/Module.zig");2584const Module = @import("../../Package/Module.zig");
2586const std = @import("std");2585const std = @import("std");
2587const Type = @import("../../type.zig").Type;2586const Type = @import("../../type.zig").Type;
2588const Zcu = @import("../../Module.zig");2587const 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");...@@ -22,7 +22,6 @@ const Air = @import("../Air.zig");
22const Liveness = @import("../Liveness.zig");22const Liveness = @import("../Liveness.zig");
23const Value = @import("../Value.zig");23const Value = @import("../Value.zig");
24const Type = @import("../type.zig").Type;24const Type = @import("../type.zig").Type;
25const LazySrcLoc = std.zig.LazySrcLoc;
26const x86_64_abi = @import("../arch/x86_64/abi.zig");25const x86_64_abi = @import("../arch/x86_64/abi.zig");
27const wasm_c_abi = @import("../arch/wasm/abi.zig");26const wasm_c_abi = @import("../arch/wasm/abi.zig");
28const aarch64_c_abi = @import("../arch/aarch64/abi.zig");27const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
...@@ -2067,7 +2066,7 @@ pub const Object = struct {...@@ -2067,7 +2066,7 @@ pub const Object = struct {
2067 try o.builder.metadataString(name),2066 try o.builder.metadataString(name),
2068 file,2067 file,
2069 scope,2068 scope,
2070 owner_decl.src_node + 1, // Line2069 owner_decl.src_line + 1, // Line
2071 try o.lowerDebugType(int_ty),2070 try o.lowerDebugType(int_ty),
2072 ty.abiSize(mod) * 8,2071 ty.abiSize(mod) * 8,
2073 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,2072 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
...@@ -2237,7 +2236,7 @@ pub const Object = struct {...@@ -2237,7 +2236,7 @@ pub const Object = struct {
2237 try o.builder.metadataString(name),2236 try o.builder.metadataString(name),
2238 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),2237 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
2239 try o.namespaceToDebugScope(owner_decl.src_namespace),2238 try o.namespaceToDebugScope(owner_decl.src_namespace),
2240 owner_decl.src_node + 1, // Line2239 owner_decl.src_line + 1, // Line
2241 .none, // Underlying type2240 .none, // Underlying type
2242 0, // Size2241 0, // Size
2243 0, // Align2242 0, // Align
...@@ -4729,7 +4728,7 @@ pub const DeclGen = struct {...@@ -4729,7 +4728,7 @@ pub const DeclGen = struct {
4729 const o = dg.object;4728 const o = dg.object;
4730 const gpa = o.gpa;4729 const gpa = o.gpa;
4731 const mod = o.module;4730 const mod = o.module;
4732 const src_loc = dg.decl.srcLoc(mod);4731 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);
4733 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);4732 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
4734 return error.CodegenFail;4733 return error.CodegenFail;
4735 }4734 }
src/codegen/spirv.zig+2-3
...@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");...@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");
9const Decl = Module.Decl;9const Decl = Module.Decl;
10const Type = @import("../type.zig").Type;10const Type = @import("../type.zig").Type;
11const Value = @import("../Value.zig");11const Value = @import("../Value.zig");
12const LazySrcLoc = std.zig.LazySrcLoc;
13const Air = @import("../Air.zig");12const Air = @import("../Air.zig");
14const Liveness = @import("../Liveness.zig");13const Liveness = @import("../Liveness.zig");
15const InternPool = @import("../InternPool.zig");14const InternPool = @import("../InternPool.zig");
...@@ -414,7 +413,7 @@ const DeclGen = struct {...@@ -414,7 +413,7 @@ const DeclGen = struct {
414 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {413 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
415 @setCold(true);414 @setCold(true);
416 const mod = self.module;415 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);
418 assert(self.error_msg == null);417 assert(self.error_msg == null);
419 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);418 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
420 return error.CodegenFail;419 return error.CodegenFail;
...@@ -6438,7 +6437,7 @@ const DeclGen = struct {...@@ -6438,7 +6437,7 @@ const DeclGen = struct {
6438 // TODO: Translate proper error locations.6437 // TODO: Translate proper error locations.
6439 assert(as.errors.items.len != 0);6438 assert(as.errors.items.len != 0);
6440 assert(self.error_msg == null);6439 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);
6442 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});6441 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6443 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);6442 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;...@@ -10,6 +10,7 @@ const native_os = builtin.os.tag;
1010
11const Module = @import("Module.zig");11const Module = @import("Module.zig");
12const Sema = @import("Sema.zig");12const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");
13const Zir = std.zig.Zir;14const Zir = std.zig.Zir;
14const Decl = Module.Decl;15const Decl = Module.Decl;
1516
...@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {...@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {
76 const stderr = io.getStdErr().writer();77 const stderr = io.getStdErr().writer();
77 const block: *Sema.Block = anal.block;78 const block: *Sema.Block = anal.block;
78 const mod = anal.sema.mod;79 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
81 try stderr.writeAll("Analyzing ");83 try stderr.writeAll("Analyzing ");
82 try writeFullyQualifiedDeclWithFile(mod, block_src_decl, stderr);84 try writeFilePath(file, stderr);
83 try stderr.writeAll("\n");85 try stderr.writeAll("\n");
8486
85 print_zir.renderInstructionContext(87 print_zir.renderInstructionContext(
86 allocator,88 allocator,
87 anal.body,89 anal.body,
88 anal.body_index,90 anal.body_index,
89 mod.namespacePtr(block.namespace).file_scope,91 file,
90 block_src_decl.src_node,92 src_base_node,
91 6, // indent93 6, // indent
92 stderr,94 stderr,
93 ) catch |err| switch (err) {95 ) catch |err| switch (err) {
...@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {...@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {
95 else => |e| return e,97 else => |e| return e,
96 };98 };
97 try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");99 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);
99 try stderr.writeAll("\n\n");101 try stderr.writeAll("\n\n");
100102
101 var parent = anal.parent;103 var parent = anal.parent;
102 while (parent) |curr| {104 while (parent) |curr| {
103 fba.reset();105 fba.reset();
104 try stderr.writeAll(" in ");106 try stderr.writeAll(" in ");
105 const curr_block_src_decl = mod.declPtr(curr.block.src_decl);107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);
106 try writeFullyQualifiedDeclWithFile(mod, curr_block_src_decl, stderr);108 try writeFilePath(cur_block_file, stderr);
107 try stderr.writeAll("\n > ");109 try stderr.writeAll("\n > ");
108 print_zir.renderSingleInstruction(110 print_zir.renderSingleInstruction(
109 allocator,111 allocator,
110 curr.body[curr.body_index],112 curr.body[curr.body_index],
111 mod.namespacePtr(curr.block.namespace).file_scope,113 cur_block_file,
112 curr_block_src_decl.src_node,114 cur_block_src_base_node,
113 6, // indent115 6, // indent
114 stderr,116 stderr,
115 ) catch |err| switch (err) {117 ) catch |err| switch (err) {
...@@ -138,12 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {...@@ -138,12 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
138 try writer.writeAll(file.sub_file_path);140 try writer.writeAll(file.sub_file_path);
139}141}
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
147pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {143pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
148 PanicSwitch.preDispatch();144 PanicSwitch.preDispatch();
149 @setCold(true);145 @setCold(true);
src/link/Coff.zig+6-6
...@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:...@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11441144
1145 const res = try codegen.generateFunction(1145 const res = try codegen.generateFunction(
1146 &self.base,1146 &self.base,
1147 decl.srcLoc(mod),1147 decl.navSrcLoc(mod).upgrade(mod),
1148 func_index,1148 func_index,
1149 air,1149 air,
1150 liveness,1150 liveness,
...@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd...@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1182 defer gpa.free(sym_name);1182 defer gpa.free(sym_name);
1183 const ty = val.typeOf(mod);1183 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))) {
1185 .ok => |atom_index| atom_index,1185 .ok => |atom_index| atom_index,
1186 .fail => |em| {1186 .fail => |em| {
1187 decl.analysis = .codegen_failure;1187 decl.analysis = .codegen_failure;
...@@ -1272,7 +1272,7 @@ pub fn updateDecl(...@@ -1272,7 +1272,7 @@ pub fn updateDecl(
1272 defer code_buffer.deinit();1272 defer code_buffer.deinit();
12731273
1274 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1274 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, .{
1276 .parent_atom_index = atom.getSymbolIndex().?,1276 .parent_atom_index = atom.getSymbolIndex().?,
1277 });1277 });
1278 const code = switch (res) {1278 const code = switch (res) {
...@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(...@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(
1313 const atom = self.getAtomPtr(atom_index);1313 const atom = self.getAtomPtr(atom_index);
1314 const local_sym_index = atom.getSymbolIndex().?;1314 const local_sym_index = atom.getSymbolIndex().?;
13151315
1316 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1316 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1317 mod.declPtr(owner_decl).srcLoc(mod)1317 src.upgrade(mod)
1318 else1318 else
1319 Module.SrcLoc{1319 Module.SrcLoc{
1320 .file_scope = undefined,1320 .file_scope = undefined,
1321 .parent_decl_node = undefined,1321 .base_node = undefined,
1322 .lazy = .unneeded,1322 .lazy = .unneeded,
1323 };1323 };
1324 const res = try codegen.generateLazySymbol(1324 const res = try codegen.generateLazySymbol(
src/link/Elf/ZigObject.zig+8-8
...@@ -1074,7 +1074,7 @@ pub fn updateFunc(...@@ -1074,7 +1074,7 @@ pub fn updateFunc(
1074 const res = if (decl_state) |*ds|1074 const res = if (decl_state) |*ds|
1075 try codegen.generateFunction(1075 try codegen.generateFunction(
1076 &elf_file.base,1076 &elf_file.base,
1077 decl.srcLoc(mod),1077 decl.navSrcLoc(mod).upgrade(mod),
1078 func_index,1078 func_index,
1079 air,1079 air,
1080 liveness,1080 liveness,
...@@ -1084,7 +1084,7 @@ pub fn updateFunc(...@@ -1084,7 +1084,7 @@ pub fn updateFunc(
1084 else1084 else
1085 try codegen.generateFunction(1085 try codegen.generateFunction(
1086 &elf_file.base,1086 &elf_file.base,
1087 decl.srcLoc(mod),1087 decl.navSrcLoc(mod).upgrade(mod),
1088 func_index,1088 func_index,
1089 air,1089 air,
1090 liveness,1090 liveness,
...@@ -1158,13 +1158,13 @@ pub fn updateDecl(...@@ -1158,13 +1158,13 @@ pub fn updateDecl(
1158 // TODO implement .debug_info for global variables1158 // TODO implement .debug_info for global variables
1159 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1159 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1160 const res = if (decl_state) |*ds|1160 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, .{
1162 .dwarf = ds,1162 .dwarf = ds,
1163 }, .{1163 }, .{
1164 .parent_atom_index = sym_index,1164 .parent_atom_index = sym_index,
1165 })1165 })
1166 else1166 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, .{
1168 .parent_atom_index = sym_index,1168 .parent_atom_index = sym_index,
1169 });1169 });
11701170
...@@ -1221,12 +1221,12 @@ fn updateLazySymbol(...@@ -1221,12 +1221,12 @@ fn updateLazySymbol(
1221 break :blk try self.strtab.insert(gpa, name);1221 break :blk try self.strtab.insert(gpa, name);
1222 };1222 };
12231223
1224 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1224 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1225 mod.declPtr(owner_decl).srcLoc(mod)1225 src.upgrade(mod)
1226 else1226 else
1227 Module.SrcLoc{1227 Module.SrcLoc{
1228 .file_scope = undefined,1228 .file_scope = undefined,
1229 .parent_decl_node = undefined,1229 .base_node = undefined,
1230 .lazy = .unneeded,1230 .lazy = .unneeded,
1231 };1231 };
1232 const res = try codegen.generateLazySymbol(1232 const res = try codegen.generateLazySymbol(
...@@ -1306,7 +1306,7 @@ pub fn lowerUnnamedConst(...@@ -1306,7 +1306,7 @@ pub fn lowerUnnamedConst(
1306 val,1306 val,
1307 ty.abiAlignment(mod),1307 ty.abiAlignment(mod),
1308 elf_file.zig_data_rel_ro_section_index.?,1308 elf_file.zig_data_rel_ro_section_index.?,
1309 decl.srcLoc(mod),1309 decl.navSrcLoc(mod).upgrade(mod),
1310 )) {1310 )) {
1311 .ok => |sym_index| sym_index,1311 .ok => |sym_index| sym_index,
1312 .fail => |em| {1312 .fail => |em| {
src/link/MachO/ZigObject.zig+6-6
...@@ -682,7 +682,7 @@ pub fn updateFunc(...@@ -682,7 +682,7 @@ pub fn updateFunc(
682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683 const res = try codegen.generateFunction(683 const res = try codegen.generateFunction(
684 &macho_file.base,684 &macho_file.base,
685 decl.srcLoc(mod),685 decl.navSrcLoc(mod).upgrade(mod),
686 func_index,686 func_index,
687 air,687 air,
688 liveness,688 liveness,
...@@ -756,7 +756,7 @@ pub fn updateDecl(...@@ -756,7 +756,7 @@ pub fn updateDecl(
756756
757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
758 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;758 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, .{
760 .parent_atom_index = sym_index,760 .parent_atom_index = sym_index,
761 });761 });
762762
...@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(...@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(
1104 val,1104 val,
1105 val.typeOf(mod).abiAlignment(mod),1105 val.typeOf(mod).abiAlignment(mod),
1106 macho_file.zig_const_sect_index.?,1106 macho_file.zig_const_sect_index.?,
1107 decl.srcLoc(mod),1107 decl.navSrcLoc(mod).upgrade(mod),
1108 )) {1108 )) {
1109 .ok => |sym_index| sym_index,1109 .ok => |sym_index| sym_index,
1110 .fail => |em| {1110 .fail => |em| {
...@@ -1294,12 +1294,12 @@ fn updateLazySymbol(...@@ -1294,12 +1294,12 @@ fn updateLazySymbol(
1294 break :blk try self.strtab.insert(gpa, name);1294 break :blk try self.strtab.insert(gpa, name);
1295 };1295 };
12961296
1297 const src = if (lazy_sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1297 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|
1298 mod.declPtr(owner_decl).srcLoc(mod)1298 src.upgrade(mod)
1299 else1299 else
1300 Module.SrcLoc{1300 Module.SrcLoc{
1301 .file_scope = undefined,1301 .file_scope = undefined,
1302 .parent_decl_node = undefined,1302 .base_node = undefined,
1303 .lazy = .unneeded,1303 .lazy = .unneeded,
1304 };1304 };
1305 const res = try codegen.generateLazySymbol(1305 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:...@@ -433,7 +433,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
433433
434 const res = try codegen.generateFunction(434 const res = try codegen.generateFunction(
435 &self.base,435 &self.base,
436 decl.srcLoc(mod),436 decl.navSrcLoc(mod).upgrade(mod),
437 func_index,437 func_index,
438 air,438 air,
439 liveness,439 liveness,
...@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn...@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
499 };499 };
500 self.syms.items[info.sym_index.?] = sym;500 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, .{
503 .none = {},503 .none = {},
504 }, .{504 }, .{
505 .parent_atom_index = new_atom_idx,505 .parent_atom_index = new_atom_idx,
...@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)...@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
538 defer code_buffer.deinit();538 defer code_buffer.deinit();
539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
540 // TODO we need the symbol index for symbol in the table of locals for the containing atom540 // 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 = {} }, .{
542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
543 });543 });
544 const code = switch (res) {544 const code = switch (res) {
...@@ -1020,7 +1020,7 @@ fn addDeclExports(...@@ -1020,7 +1020,7 @@ fn addDeclExports(
1020 {1020 {
1021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(1021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
1022 gpa,1022 gpa,
1023 mod.declPtr(decl_index).srcLoc(mod),1023 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),
1024 "plan9 does not support extra sections",1024 "plan9 does not support extra sections",
1025 .{},1025 .{},
1026 ));1026 ));
...@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind...@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
1212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;1212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12131213
1214 // generate the code1214 // generate the code
1215 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1215 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1216 mod.declPtr(owner_decl).srcLoc(mod)1216 src.upgrade(mod)
1217 else1217 else
1218 Module.SrcLoc{1218 Module.SrcLoc{
1219 .file_scope = undefined,1219 .file_scope = undefined,
1220 .parent_decl_node = undefined,1220 .base_node = undefined,
1221 .lazy = .unneeded,1221 .lazy = .unneeded,
1222 };1222 };
1223 const res = try codegen.generateLazySymbol(1223 const res = try codegen.generateLazySymbol(
src/link/Wasm/ZigObject.zig+15-5
...@@ -269,7 +269,7 @@ pub fn updateDecl(...@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270 const res = try codegen.generateSymbol(270 const res = try codegen.generateSymbol(
271 &wasm_file.base,271 &wasm_file.base,
272 decl.srcLoc(mod),272 decl.navSrcLoc(mod).upgrade(mod),
273 val,273 val,
274 &code_writer,274 &code_writer,
275 .none,275 .none,
...@@ -308,7 +308,7 @@ pub fn updateFunc(...@@ -308,7 +308,7 @@ pub fn updateFunc(
308 defer code_writer.deinit();308 defer code_writer.deinit();
309 const result = try codegen.generateFunction(309 const result = try codegen.generateFunction(
310 &wasm_file.base,310 &wasm_file.base,
311 decl.srcLoc(mod),311 decl.navSrcLoc(mod).upgrade(mod),
312 func_index,312 func_index,
313 air,313 air,
314 liveness,314 liveness,
...@@ -484,7 +484,17 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d...@@ -484,7 +484,17 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
484 });484 });
485 defer gpa.free(name);485 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))) {
488 .ok => |atom_index| {498 .ok => |atom_index| {
489 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
490 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
...@@ -867,7 +877,7 @@ pub fn updateExports(...@@ -867,7 +877,7 @@ pub fn updateExports(
867 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {877 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
868 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(878 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
869 gpa,879 gpa,
870 decl.srcLoc(mod),880 decl.navSrcLoc(mod).upgrade(mod),
871 "Unimplemented: ExportOptions.section '{s}'",881 "Unimplemented: ExportOptions.section '{s}'",
872 .{section},882 .{section},
873 ));883 ));
...@@ -900,7 +910,7 @@ pub fn updateExports(...@@ -900,7 +910,7 @@ pub fn updateExports(
900 .link_once => {910 .link_once => {
901 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(911 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
902 gpa,912 gpa,
903 decl.srcLoc(mod),913 decl.navSrcLoc(mod).upgrade(mod),
904 "Unimplemented: LinkOnce",914 "Unimplemented: LinkOnce",
905 .{},915 .{},
906 ));916 ));
src/main.zig+3
...@@ -5966,6 +5966,7 @@ fn cmdAstCheck(...@@ -5966,6 +5966,7 @@ fn cmdAstCheck(
5966 .zir = undefined,5966 .zir = undefined,
5967 .mod = undefined,5967 .mod = undefined,
5968 .root_decl = .none,5968 .root_decl = .none,
5969 .path_digest = undefined,
5969 };5970 };
5970 if (zig_source_file) |file_name| {5971 if (zig_source_file) |file_name| {
5971 var f = fs.cwd().openFile(file_name, .{}) catch |err| {5972 var f = fs.cwd().openFile(file_name, .{}) catch |err| {
...@@ -6284,6 +6285,7 @@ fn cmdDumpZir(...@@ -6284,6 +6285,7 @@ fn cmdDumpZir(
6284 .zir = try Module.loadZirCache(gpa, f),6285 .zir = try Module.loadZirCache(gpa, f),
6285 .mod = undefined,6286 .mod = undefined,
6286 .root_decl = .none,6287 .root_decl = .none,
6288 .path_digest = undefined,
6287 };6289 };
6288 defer file.zir.deinit(gpa);6290 defer file.zir.deinit(gpa);
62896291
...@@ -6354,6 +6356,7 @@ fn cmdChangelist(...@@ -6354,6 +6356,7 @@ fn cmdChangelist(
6354 .zir = undefined,6356 .zir = undefined,
6355 .mod = undefined,6357 .mod = undefined,
6356 .root_decl = .none,6358 .root_decl = .none,
6359 .path_digest = undefined,
6357 };6360 };
63586361
6359 file.mod = try Package.Module.createLimited(arena, .{6362 file.mod = try Package.Module.createLimited(arena, .{
src/print_value.zig+1-1
...@@ -32,7 +32,7 @@ pub fn format(...@@ -32,7 +32,7 @@ pub fn format(
32 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {32 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {
33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
34 error.ComptimeBreak, error.ComptimeReturn => unreachable,34 error.ComptimeBreak, error.ComptimeReturn => unreachable,
35 error.AnalysisFail, error.NeededSourceLocation => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully35 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
36 else => |e| return e,36 else => |e| return e,
37 };37 };
38}38}
src/print_zir.zig+162-157
...@@ -6,8 +6,9 @@ const Ast = std.zig.Ast;...@@ -6,8 +6,9 @@ const Ast = std.zig.Ast;
6const InternPool = @import("InternPool.zig");6const InternPool = @import("InternPool.zig");
77
8const Zir = std.zig.Zir;8const Zir = std.zig.Zir;
9const Module = @import("Module.zig");9const Zcu = @import("Module.zig");
10const LazySrcLoc = std.zig.LazySrcLoc;10const Module = Zcu;
11const LazySrcLoc = Zcu.LazySrcLoc;
1112
12/// Write human-readable, debug formatted ZIR code to a file.13/// Write human-readable, debug formatted ZIR code to a file.
13pub fn renderAsTextToFile(14pub fn renderAsTextToFile(
...@@ -47,12 +48,11 @@ pub fn renderAsTextToFile(...@@ -47,12 +48,11 @@ pub fn renderAsTextToFile(
47 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);48 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
48 extra_index = item.end;49 extra_index = item.end;
4950
50 const src: LazySrcLoc = .{ .token_abs = item.data.token };
51 const import_path = scope_file.zir.nullTerminatedString(item.data.name);51 const import_path = scope_file.zir.nullTerminatedString(item.data.name);
52 try stream.print(" @import(\"{}\") ", .{52 try stream.print(" @import(\"{}\") ", .{
53 std.zig.fmtEscapes(import_path),53 std.zig.fmtEscapes(import_path),
54 });54 });
55 try writer.writeSrc(stream, src);55 try writer.writeSrcTokAbs(stream, item.data.token);
56 try stream.writeAll("\n");56 try stream.writeAll("\n");
57 }57 }
58 }58 }
...@@ -187,7 +187,7 @@ const Writer = struct {...@@ -187,7 +187,7 @@ const Writer = struct {
187 } = .{},187 } = .{},
188188
189 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {189 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)));
191 }191 }
192192
193 fn writeInstToStream(193 fn writeInstToStream(
...@@ -569,7 +569,6 @@ const Writer = struct {...@@ -569,7 +569,6 @@ const Writer = struct {
569 .wasm_memory_size,569 .wasm_memory_size,
570 .int_from_error,570 .int_from_error,
571 .error_from_int,571 .error_from_int,
572 .reify,
573 .c_va_copy,572 .c_va_copy,
574 .c_va_end,573 .c_va_end,
575 .work_item_id,574 .work_item_id,
...@@ -577,10 +576,20 @@ const Writer = struct {...@@ -577,10 +576,20 @@ const Writer = struct {
577 .work_group_id,576 .work_group_id,
578 => {577 => {
579 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;578 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
580 const src = LazySrcLoc.nodeOffset(inst_data.node);
581 try self.writeInstRef(stream, inst_data.operand);579 try self.writeInstRef(stream, inst_data.operand);
582 try stream.writeAll(")) ");580 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);
584 },593 },
585594
586 .builtin_extern,595 .builtin_extern,
...@@ -591,12 +600,11 @@ const Writer = struct {...@@ -591,12 +600,11 @@ const Writer = struct {
591 .c_va_arg,600 .c_va_arg,
592 => {601 => {
593 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;602 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
594 const src = LazySrcLoc.nodeOffset(inst_data.node);
595 try self.writeInstRef(stream, inst_data.lhs);603 try self.writeInstRef(stream, inst_data.lhs);
596 try stream.writeAll(", ");604 try stream.writeAll(", ");
597 try self.writeInstRef(stream, inst_data.rhs);605 try self.writeInstRef(stream, inst_data.rhs);
598 try stream.writeAll(")) ");606 try stream.writeAll(")) ");
599 try self.writeSrc(stream, src);607 try self.writeSrcNode(stream, inst_data.node);
600 },608 },
601609
602 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),610 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
...@@ -611,9 +619,8 @@ const Writer = struct {...@@ -611,9 +619,8 @@ const Writer = struct {
611 }619 }
612620
613 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {621 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
614 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
615 try stream.writeAll(")) ");622 try stream.writeAll(")) ");
616 try self.writeSrc(stream, src);623 try self.writeSrcNode(stream, @bitCast(extended.operand));
617 }624 }
618625
619 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {626 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -630,7 +637,7 @@ const Writer = struct {...@@ -630,7 +637,7 @@ const Writer = struct {
630 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;637 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
631 try self.writeInstRef(stream, inst_data.operand);638 try self.writeInstRef(stream, inst_data.operand);
632 try stream.writeAll(") ");639 try stream.writeAll(") ");
633 try self.writeSrc(stream, inst_data.src());640 try self.writeSrcNode(stream, inst_data.src_node);
634 }641 }
635642
636 fn writeUnTok(643 fn writeUnTok(
...@@ -641,7 +648,7 @@ const Writer = struct {...@@ -641,7 +648,7 @@ const Writer = struct {
641 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;648 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
642 try self.writeInstRef(stream, inst_data.operand);649 try self.writeInstRef(stream, inst_data.operand);
643 try stream.writeAll(") ");650 try stream.writeAll(") ");
644 try self.writeSrc(stream, inst_data.src());651 try self.writeSrcTok(stream, inst_data.src_tok);
645 }652 }
646653
647 fn writeValidateDestructure(654 fn writeValidateDestructure(
...@@ -653,9 +660,9 @@ const Writer = struct {...@@ -653,9 +660,9 @@ const Writer = struct {
653 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;660 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
654 try self.writeInstRef(stream, extra.operand);661 try self.writeInstRef(stream, extra.operand);
655 try stream.print(", {d}) (destructure=", .{extra.expect_len});662 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);
657 try stream.writeAll(") ");664 try stream.writeAll(") ");
658 try self.writeSrc(stream, inst_data.src());665 try self.writeSrcNode(stream, inst_data.src_node);
659 }666 }
660667
661 fn writeValidateArrayInitTy(668 fn writeValidateArrayInitTy(
...@@ -667,7 +674,7 @@ const Writer = struct {...@@ -667,7 +674,7 @@ const Writer = struct {
667 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;674 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
668 try self.writeInstRef(stream, extra.ty);675 try self.writeInstRef(stream, extra.ty);
669 try stream.print(", {d}) ", .{extra.init_count});676 try stream.print(", {d}) ", .{extra.init_count});
670 try self.writeSrc(stream, inst_data.src());677 try self.writeSrcNode(stream, inst_data.src_node);
671 }678 }
672679
673 fn writeArrayTypeSentinel(680 fn writeArrayTypeSentinel(
...@@ -683,7 +690,7 @@ const Writer = struct {...@@ -683,7 +690,7 @@ const Writer = struct {
683 try stream.writeAll(", ");690 try stream.writeAll(", ");
684 try self.writeInstRef(stream, extra.elem_type);691 try self.writeInstRef(stream, extra.elem_type);
685 try stream.writeAll(") ");692 try stream.writeAll(") ");
686 try self.writeSrc(stream, inst_data.src());693 try self.writeSrcNode(stream, inst_data.src_node);
687 }694 }
688695
689 fn writePtrType(696 fn writePtrType(
...@@ -728,7 +735,7 @@ const Writer = struct {...@@ -728,7 +735,7 @@ const Writer = struct {
728 try stream.writeAll(")");735 try stream.writeAll(")");
729 }736 }
730 try stream.writeAll(") ");737 try stream.writeAll(") ");
731 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.data.src_node));738 try self.writeSrcNode(stream, extra.data.src_node);
732 }739 }
733740
734 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {741 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -763,11 +770,10 @@ const Writer = struct {...@@ -763,11 +770,10 @@ const Writer = struct {
763 fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {770 fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
764 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;771 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
765 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;772 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
766 const src = inst_data.src();
767 const number = extra.get();773 const number = extra.get();
768 // TODO improve std.format to be able to print f128 values774 // TODO improve std.format to be able to print f128 values
769 try stream.print("{d}) ", .{@as(f64, @floatCast(number))});775 try stream.print("{d}) ", .{@as(f64, @floatCast(number))});
770 try self.writeSrc(stream, src);776 try self.writeSrcNode(stream, inst_data.src_node);
771 }777 }
772778
773 fn writeStr(779 fn writeStr(
...@@ -787,7 +793,7 @@ const Writer = struct {...@@ -787,7 +793,7 @@ const Writer = struct {
787 try stream.writeAll(", ");793 try stream.writeAll(", ");
788 try self.writeInstRef(stream, extra.start);794 try self.writeInstRef(stream, extra.start);
789 try stream.writeAll(") ");795 try stream.writeAll(") ");
790 try self.writeSrc(stream, inst_data.src());796 try self.writeSrcNode(stream, inst_data.src_node);
791 }797 }
792798
793 fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {799 fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -799,7 +805,7 @@ const Writer = struct {...@@ -799,7 +805,7 @@ const Writer = struct {
799 try stream.writeAll(", ");805 try stream.writeAll(", ");
800 try self.writeInstRef(stream, extra.end);806 try self.writeInstRef(stream, extra.end);
801 try stream.writeAll(") ");807 try stream.writeAll(") ");
802 try self.writeSrc(stream, inst_data.src());808 try self.writeSrcNode(stream, inst_data.src_node);
803 }809 }
804810
805 fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {811 fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -813,7 +819,7 @@ const Writer = struct {...@@ -813,7 +819,7 @@ const Writer = struct {
813 try stream.writeAll(", ");819 try stream.writeAll(", ");
814 try self.writeInstRef(stream, extra.sentinel);820 try self.writeInstRef(stream, extra.sentinel);
815 try stream.writeAll(") ");821 try stream.writeAll(") ");
816 try self.writeSrc(stream, inst_data.src());822 try self.writeSrcNode(stream, inst_data.src_node);
817 }823 }
818824
819 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {825 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -829,7 +835,7 @@ const Writer = struct {...@@ -829,7 +835,7 @@ const Writer = struct {
829 try self.writeInstRef(stream, extra.sentinel);835 try self.writeInstRef(stream, extra.sentinel);
830 }836 }
831 try stream.writeAll(") ");837 try stream.writeAll(") ");
832 try self.writeSrc(stream, inst_data.src());838 try self.writeSrcNode(stream, inst_data.src_node);
833 }839 }
834840
835 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {841 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -841,7 +847,7 @@ const Writer = struct {...@@ -841,7 +847,7 @@ const Writer = struct {
841 try stream.writeAll(", ");847 try stream.writeAll(", ");
842 try self.writeInstRef(stream, extra.init);848 try self.writeInstRef(stream, extra.init);
843 try stream.writeAll(") ");849 try stream.writeAll(") ");
844 try self.writeSrc(stream, inst_data.src());850 try self.writeSrcNode(stream, inst_data.src_node);
845 }851 }
846852
847 fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {853 fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -855,7 +861,7 @@ const Writer = struct {...@@ -855,7 +861,7 @@ const Writer = struct {
855 try stream.writeAll(", ");861 try stream.writeAll(", ");
856 try self.writeInstRef(stream, extra.mask);862 try self.writeInstRef(stream, extra.mask);
857 try stream.writeAll(") ");863 try stream.writeAll(") ");
858 try self.writeSrc(stream, inst_data.src());864 try self.writeSrcNode(stream, inst_data.src_node);
859 }865 }
860866
861 fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {867 fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
...@@ -868,7 +874,7 @@ const Writer = struct {...@@ -868,7 +874,7 @@ const Writer = struct {
868 try stream.writeAll(", ");874 try stream.writeAll(", ");
869 try self.writeInstRef(stream, extra.b);875 try self.writeInstRef(stream, extra.b);
870 try stream.writeAll(") ");876 try stream.writeAll(") ");
871 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));877 try self.writeSrcNode(stream, extra.node);
872 }878 }
873879
874 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {880 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -880,7 +886,7 @@ const Writer = struct {...@@ -880,7 +886,7 @@ const Writer = struct {
880 try stream.writeAll(", ");886 try stream.writeAll(", ");
881 try self.writeInstRef(stream, extra.addend);887 try self.writeInstRef(stream, extra.addend);
882 try stream.writeAll(") ");888 try stream.writeAll(") ");
883 try self.writeSrc(stream, inst_data.src());889 try self.writeSrcNode(stream, inst_data.src_node);
884 }890 }
885891
886 fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {892 fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -896,7 +902,7 @@ const Writer = struct {...@@ -896,7 +902,7 @@ const Writer = struct {
896 try stream.writeAll(", ");902 try stream.writeAll(", ");
897 try self.writeInstRef(stream, extra.args);903 try self.writeInstRef(stream, extra.args);
898 try stream.writeAll(") ");904 try stream.writeAll(") ");
899 try self.writeSrc(stream, inst_data.src());905 try self.writeSrcNode(stream, inst_data.src_node);
900 }906 }
901907
902 fn writeFieldParentPtr(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {908 fn writeFieldParentPtr(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
...@@ -913,7 +919,7 @@ const Writer = struct {...@@ -913,7 +919,7 @@ const Writer = struct {
913 try stream.writeAll(", ");919 try stream.writeAll(", ");
914 try self.writeInstRef(stream, extra.field_ptr);920 try self.writeInstRef(stream, extra.field_ptr);
915 try stream.writeAll(") ");921 try stream.writeAll(") ");
916 try self.writeSrc(stream, extra.src());922 try self.writeSrcNode(stream, extra.src_node);
917 }923 }
918924
919 fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {925 fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
...@@ -926,7 +932,7 @@ const Writer = struct {...@@ -926,7 +932,7 @@ const Writer = struct {
926 try stream.writeAll(", ");932 try stream.writeAll(", ");
927 try self.writeInstRef(stream, extra.args);933 try self.writeInstRef(stream, extra.args);
928 try stream.writeAll(") ");934 try stream.writeAll(") ");
929 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));935 try self.writeSrcNode(stream, extra.node);
930 }936 }
931937
932 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {938 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -944,7 +950,7 @@ const Writer = struct {...@@ -944,7 +950,7 @@ const Writer = struct {
944 }950 }
945 try self.writeBracedBody(stream, body);951 try self.writeBracedBody(stream, body);
946 try stream.writeAll(") ");952 try stream.writeAll(") ");
947 try self.writeSrc(stream, inst_data.src());953 try self.writeSrcTok(stream, inst_data.src_tok);
948 }954 }
949955
950 fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {956 fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -954,7 +960,7 @@ const Writer = struct {...@@ -954,7 +960,7 @@ const Writer = struct {
954 try stream.writeAll(", ");960 try stream.writeAll(", ");
955 try self.writeInstRef(stream, extra.rhs);961 try self.writeInstRef(stream, extra.rhs);
956 try stream.writeAll(") ");962 try stream.writeAll(") ");
957 try self.writeSrc(stream, inst_data.src());963 try self.writeSrcNode(stream, inst_data.src_node);
958 }964 }
959965
960 fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {966 fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -967,7 +973,7 @@ const Writer = struct {...@@ -967,7 +973,7 @@ const Writer = struct {
967 try self.writeInstRef(stream, arg);973 try self.writeInstRef(stream, arg);
968 }974 }
969 try stream.writeAll("}) ");975 try stream.writeAll("}) ");
970 try self.writeSrc(stream, inst_data.src());976 try self.writeSrcNode(stream, inst_data.src_node);
971 }977 }
972978
973 fn writeArrayMul(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {979 fn writeArrayMul(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -979,7 +985,7 @@ const Writer = struct {...@@ -979,7 +985,7 @@ const Writer = struct {
979 try stream.writeAll(", ");985 try stream.writeAll(", ");
980 try self.writeInstRef(stream, extra.rhs);986 try self.writeInstRef(stream, extra.rhs);
981 try stream.writeAll(") ");987 try stream.writeAll(") ");
982 try self.writeSrc(stream, inst_data.src());988 try self.writeSrcNode(stream, inst_data.src_node);
983 }989 }
984990
985 fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {991 fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -994,7 +1000,7 @@ const Writer = struct {...@@ -994,7 +1000,7 @@ const Writer = struct {
9941000
995 try self.writeInstRef(stream, extra.ptr);1001 try self.writeInstRef(stream, extra.ptr);
996 try stream.print(", {d}) ", .{extra.index});1002 try stream.print(", {d}) ", .{extra.index});
997 try self.writeSrc(stream, inst_data.src());1003 try self.writeSrcNode(stream, inst_data.src_node);
998 }1004 }
9991005
1000 fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1006 fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1006,7 +1012,7 @@ const Writer = struct {...@@ -1006,7 +1012,7 @@ const Writer = struct {
1006 try stream.print(", {p}, ", .{std.zig.fmtId(decl_name)});1012 try stream.print(", {p}, ", .{std.zig.fmtId(decl_name)});
1007 try self.writeInstRef(stream, extra.options);1013 try self.writeInstRef(stream, extra.options);
1008 try stream.writeAll(") ");1014 try stream.writeAll(") ");
1009 try self.writeSrc(stream, inst_data.src());1015 try self.writeSrcNode(stream, inst_data.src_node);
1010 }1016 }
10111017
1012 fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1018 fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1017,7 +1023,7 @@ const Writer = struct {...@@ -1017,7 +1023,7 @@ const Writer = struct {
1017 try stream.writeAll(", ");1023 try stream.writeAll(", ");
1018 try self.writeInstRef(stream, extra.options);1024 try self.writeInstRef(stream, extra.options);
1019 try stream.writeAll(") ");1025 try stream.writeAll(") ");
1020 try self.writeSrc(stream, inst_data.src());1026 try self.writeSrcNode(stream, inst_data.src_node);
1021 }1027 }
10221028
1023 fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1029 fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1027,7 +1033,7 @@ const Writer = struct {...@@ -1027,7 +1033,7 @@ const Writer = struct {
1027 try self.writeInstRef(stream, extra.ptr_ty);1033 try self.writeInstRef(stream, extra.ptr_ty);
1028 try stream.writeAll(", ");1034 try stream.writeAll(", ");
1029 try stream.print(", {}) ", .{extra.elem_count});1035 try stream.print(", {}) ", .{extra.elem_count});
1030 try self.writeSrc(stream, inst_data.src());1036 try self.writeSrcNode(stream, inst_data.src_node);
1031 }1037 }
10321038
1033 fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1039 fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1051,12 +1057,11 @@ const Writer = struct {...@@ -1051,12 +1057,11 @@ const Writer = struct {
1051 try stream.writeAll("]");1057 try stream.writeAll("]");
1052 }1058 }
1053 try stream.writeAll(") ");1059 try stream.writeAll(") ");
1054 try self.writeSrc(stream, inst_data.src());1060 try self.writeSrcNode(stream, inst_data.src_node);
1055 }1061 }
10561062
1057 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1063 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1058 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;1064 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
1059 const src = LazySrcLoc.nodeOffset(extra.node);
10601065
1061 try self.writeInstRef(stream, extra.ptr);1066 try self.writeInstRef(stream, extra.ptr);
1062 try stream.writeAll(", ");1067 try stream.writeAll(", ");
...@@ -1068,14 +1073,13 @@ const Writer = struct {...@@ -1068,14 +1073,13 @@ const Writer = struct {
1068 try stream.writeAll(", ");1073 try stream.writeAll(", ");
1069 try self.writeInstRef(stream, extra.failure_order);1074 try self.writeInstRef(stream, extra.failure_order);
1070 try stream.writeAll(") ");1075 try stream.writeAll(") ");
1071 try self.writeSrc(stream, src);1076 try self.writeSrcNode(stream, extra.node);
1072 }1077 }
10731078
1074 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1079 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1075 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;1080 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
1076 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1081 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1077 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1082 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1078 const src = LazySrcLoc.nodeOffset(extra.node);
1079 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");1083 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
1080 if (flags.align_cast) try stream.writeAll("align_cast, ");1084 if (flags.align_cast) try stream.writeAll("align_cast, ");
1081 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");1085 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");
...@@ -1085,19 +1089,18 @@ const Writer = struct {...@@ -1085,19 +1089,18 @@ const Writer = struct {
1085 try stream.writeAll(", ");1089 try stream.writeAll(", ");
1086 try self.writeInstRef(stream, extra.rhs);1090 try self.writeInstRef(stream, extra.rhs);
1087 try stream.writeAll(")) ");1091 try stream.writeAll(")) ");
1088 try self.writeSrc(stream, src);1092 try self.writeSrcNode(stream, extra.node);
1089 }1093 }
10901094
1091 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1095 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1092 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;1096 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
1093 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1097 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1094 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;1098 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1095 const src = LazySrcLoc.nodeOffset(extra.node);
1096 if (flags.const_cast) try stream.writeAll("const_cast, ");1099 if (flags.const_cast) try stream.writeAll("const_cast, ");
1097 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");1100 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
1098 try self.writeInstRef(stream, extra.operand);1101 try self.writeInstRef(stream, extra.operand);
1099 try stream.writeAll(")) ");1102 try stream.writeAll(")) ");
1100 try self.writeSrc(stream, src);1103 try self.writeSrcNode(stream, extra.node);
1101 }1104 }
11021105
1103 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1106 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1110,7 +1113,7 @@ const Writer = struct {...@@ -1110,7 +1113,7 @@ const Writer = struct {
1110 try stream.writeAll(", ");1113 try stream.writeAll(", ");
1111 try self.writeInstRef(stream, extra.ordering);1114 try self.writeInstRef(stream, extra.ordering);
1112 try stream.writeAll(") ");1115 try stream.writeAll(") ");
1113 try self.writeSrc(stream, inst_data.src());1116 try self.writeSrcNode(stream, inst_data.src_node);
1114 }1117 }
11151118
1116 fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1119 fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1123,7 +1126,7 @@ const Writer = struct {...@@ -1123,7 +1126,7 @@ const Writer = struct {
1123 try stream.writeAll(", ");1126 try stream.writeAll(", ");
1124 try self.writeInstRef(stream, extra.ordering);1127 try self.writeInstRef(stream, extra.ordering);
1125 try stream.writeAll(") ");1128 try stream.writeAll(") ");
1126 try self.writeSrc(stream, inst_data.src());1129 try self.writeSrcNode(stream, inst_data.src_node);
1127 }1130 }
11281131
1129 fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1132 fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1138,7 +1141,7 @@ const Writer = struct {...@@ -1138,7 +1141,7 @@ const Writer = struct {
1138 try stream.writeAll(", ");1141 try stream.writeAll(", ");
1139 try self.writeInstRef(stream, extra.ordering);1142 try self.writeInstRef(stream, extra.ordering);
1140 try stream.writeAll(") ");1143 try stream.writeAll(") ");
1141 try self.writeSrc(stream, inst_data.src());1144 try self.writeSrcNode(stream, inst_data.src_node);
1142 }1145 }
11431146
1144 fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1147 fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1159,7 +1162,7 @@ const Writer = struct {...@@ -1159,7 +1162,7 @@ const Writer = struct {
1159 try stream.writeAll("]");1162 try stream.writeAll("]");
1160 }1163 }
1161 try stream.writeAll(") ");1164 try stream.writeAll(") ");
1162 try self.writeSrc(stream, inst_data.src());1165 try self.writeSrcNode(stream, inst_data.src_node);
1163 }1166 }
11641167
1165 fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1168 fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1168,7 +1171,7 @@ const Writer = struct {...@@ -1168,7 +1171,7 @@ const Writer = struct {
1168 try self.writeInstRef(stream, extra.container_type);1171 try self.writeInstRef(stream, extra.container_type);
1169 const field_name = self.code.nullTerminatedString(extra.name_start);1172 const field_name = self.code.nullTerminatedString(extra.name_start);
1170 try stream.print(", {s}) ", .{field_name});1173 try stream.print(", {s}) ", .{field_name});
1171 try self.writeSrc(stream, inst_data.src());1174 try self.writeSrcNode(stream, inst_data.src_node);
1172 }1175 }
11731176
1174 fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1177 fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1178,12 +1181,11 @@ const Writer = struct {...@@ -1178,12 +1181,11 @@ const Writer = struct {
1178 try stream.writeAll(", ");1181 try stream.writeAll(", ");
1179 try self.writeInstRef(stream, extra.field_name);1182 try self.writeInstRef(stream, extra.field_name);
1180 try stream.writeAll(") ");1183 try stream.writeAll(") ");
1181 try self.writeSrc(stream, inst_data.src());1184 try self.writeSrcNode(stream, inst_data.src_node);
1182 }1185 }
11831186
1184 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1187 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1185 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);1188 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
1186 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1187 const operands = self.code.refSlice(extra.end, extended.small);1189 const operands = self.code.refSlice(extra.end, extended.small);
11881190
1189 for (operands, 0..) |operand, i| {1191 for (operands, 0..) |operand, i| {
...@@ -1191,7 +1193,7 @@ const Writer = struct {...@@ -1191,7 +1193,7 @@ const Writer = struct {
1191 try self.writeInstRef(stream, operand);1193 try self.writeInstRef(stream, operand);
1192 }1194 }
1193 try stream.writeAll(")) ");1195 try stream.writeAll(")) ");
1194 try self.writeSrc(stream, src);1196 try self.writeSrcNode(stream, extra.data.src_node);
1195 }1197 }
11961198
1197 fn writeInstNode(1199 fn writeInstNode(
...@@ -1202,7 +1204,7 @@ const Writer = struct {...@@ -1202,7 +1204,7 @@ const Writer = struct {
1202 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;1204 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
1203 try self.writeInstIndex(stream, inst_data.inst);1205 try self.writeInstIndex(stream, inst_data.inst);
1204 try stream.writeAll(") ");1206 try stream.writeAll(") ");
1205 try self.writeSrc(stream, inst_data.src());1207 try self.writeSrcNode(stream, inst_data.src_node);
1206 }1208 }
12071209
1208 fn writeAsm(1210 fn writeAsm(
...@@ -1212,7 +1214,6 @@ const Writer = struct {...@@ -1212,7 +1214,6 @@ const Writer = struct {
1212 tmpl_is_expr: bool,1214 tmpl_is_expr: bool,
1213 ) !void {1215 ) !void {
1214 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);1216 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
1215 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1216 const outputs_len = @as(u5, @truncate(extended.small));1217 const outputs_len = @as(u5, @truncate(extended.small));
1217 const inputs_len = @as(u5, @truncate(extended.small >> 5));1218 const inputs_len = @as(u5, @truncate(extended.small >> 5));
1218 const clobbers_len = @as(u5, @truncate(extended.small >> 10));1219 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
...@@ -1283,18 +1284,17 @@ const Writer = struct {...@@ -1283,18 +1284,17 @@ const Writer = struct {
1283 }1284 }
1284 }1285 }
1285 try stream.writeAll(")) ");1286 try stream.writeAll(")) ");
1286 try self.writeSrc(stream, src);1287 try self.writeSrcNode(stream, extra.data.src_node);
1287 }1288 }
12881289
1289 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1290 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1290 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1291 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1291 const src = LazySrcLoc.nodeOffset(extra.node);
12921292
1293 try self.writeInstRef(stream, extra.lhs);1293 try self.writeInstRef(stream, extra.lhs);
1294 try stream.writeAll(", ");1294 try stream.writeAll(", ");
1295 try self.writeInstRef(stream, extra.rhs);1295 try self.writeInstRef(stream, extra.rhs);
1296 try stream.writeAll(")) ");1296 try stream.writeAll(")) ");
1297 try self.writeSrc(stream, src);1297 try self.writeSrcNode(stream, extra.node);
1298 }1298 }
12991299
1300 fn writeCall(1300 fn writeCall(
...@@ -1347,13 +1347,13 @@ const Writer = struct {...@@ -1347,13 +1347,13 @@ const Writer = struct {
1347 }1347 }
13481348
1349 try stream.writeAll("]) ");1349 try stream.writeAll("]) ");
1350 try self.writeSrc(stream, inst_data.src());1350 try self.writeSrcNode(stream, inst_data.src_node);
1351 }1351 }
13521352
1353 fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1353 fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1354 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1354 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1355 try self.writePlNodeBlockWithoutSrc(stream, inst);1355 try self.writePlNodeBlockWithoutSrc(stream, inst);
1356 try self.writeSrc(stream, inst_data.src());1356 try self.writeSrcNode(stream, inst_data.src_node);
1357 }1357 }
13581358
1359 fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1359 fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1375,7 +1375,7 @@ const Writer = struct {...@@ -1375,7 +1375,7 @@ const Writer = struct {
1375 try stream.writeAll(", ");1375 try stream.writeAll(", ");
1376 try self.writeBracedBody(stream, else_body);1376 try self.writeBracedBody(stream, else_body);
1377 try stream.writeAll(") ");1377 try stream.writeAll(") ");
1378 try self.writeSrc(stream, inst_data.src());1378 try self.writeSrcNode(stream, inst_data.src_node);
1379 }1379 }
13801380
1381 fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1381 fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1386,13 +1386,18 @@ const Writer = struct {...@@ -1386,13 +1386,18 @@ const Writer = struct {
1386 try stream.writeAll(", ");1386 try stream.writeAll(", ");
1387 try self.writeBracedBody(stream, body);1387 try self.writeBracedBody(stream, body);
1388 try stream.writeAll(") ");1388 try stream.writeAll(") ");
1389 try self.writeSrc(stream, inst_data.src());1389 try self.writeSrcNode(stream, inst_data.src_node);
1390 }1390 }
13911391
1392 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1392 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
1395 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);1395 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
1396 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1401 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1397 extra.data.fields_hash_0,1402 extra.data.fields_hash_0,
1398 extra.data.fields_hash_1,1403 extra.data.fields_hash_1,
...@@ -1465,10 +1470,6 @@ const Writer = struct {...@@ -1465,10 +1470,6 @@ const Writer = struct {
1465 if (decls_len == 0) {1470 if (decls_len == 0) {
1466 try stream.writeAll("{}, ");1471 try stream.writeAll("{}, ");
1467 } else {1472 } 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
1472 try stream.writeAll("{\n");1473 try stream.writeAll("{\n");
1473 self.indent += 2;1474 self.indent += 2;
1474 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1475 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1479,7 +1480,7 @@ const Writer = struct {...@@ -1479,7 +1480,7 @@ const Writer = struct {
1479 }1480 }
14801481
1481 if (fields_len == 0) {1482 if (fields_len == 0) {
1482 try stream.writeAll("{}, {})");1483 try stream.writeAll("{}, {}) ");
1483 } else {1484 } else {
1484 const bits_per_field = 4;1485 const bits_per_field = 4;
1485 const fields_per_u32 = 32 / bits_per_field;1486 const fields_per_u32 = 32 / bits_per_field;
...@@ -1546,8 +1547,6 @@ const Writer = struct {...@@ -1546,8 +1547,6 @@ const Writer = struct {
1546 }1547 }
1547 }1548 }
15481549
1549 const prev_parent_decl_node = self.parent_decl_node;
1550 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1551 try stream.writeAll("{\n");1550 try stream.writeAll("{\n");
1552 self.indent += 2;1551 self.indent += 2;
15531552
...@@ -1595,18 +1594,22 @@ const Writer = struct {...@@ -1595,18 +1594,22 @@ const Writer = struct {
1595 try stream.writeAll(",\n");1594 try stream.writeAll(",\n");
1596 }1595 }
15971596
1598 self.parent_decl_node = prev_parent_decl_node;
1599 self.indent -= 2;1597 self.indent -= 2;
1600 try stream.writeByteNTimes(' ', self.indent);1598 try stream.writeByteNTimes(' ', self.indent);
1601 try stream.writeAll("})");1599 try stream.writeAll("}) ");
1602 }1600 }
1603 try self.writeSrcNode(stream, extra.data.src_node);1601 try self.writeSrcNode(stream, 0);
1604 }1602 }
16051603
1606 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1604 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1607 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));1605 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
16081606
1609 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);1607 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
1610 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1613 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1611 extra.data.fields_hash_0,1614 extra.data.fields_hash_0,
1612 extra.data.fields_hash_1,1615 extra.data.fields_hash_1,
...@@ -1670,10 +1673,6 @@ const Writer = struct {...@@ -1670,10 +1673,6 @@ const Writer = struct {
1670 if (decls_len == 0) {1673 if (decls_len == 0) {
1671 try stream.writeAll("{}");1674 try stream.writeAll("{}");
1672 } else {1675 } 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
1677 try stream.writeAll("{\n");1676 try stream.writeAll("{\n");
1678 self.indent += 2;1677 self.indent += 2;
1679 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1678 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1689,8 +1688,8 @@ const Writer = struct {...@@ -1689,8 +1688,8 @@ const Writer = struct {
1689 }1688 }
16901689
1691 if (fields_len == 0) {1690 if (fields_len == 0) {
1692 try stream.writeAll("})");1691 try stream.writeAll("}) ");
1693 try self.writeSrcNode(stream, extra.data.src_node);1692 try self.writeSrcNode(stream, 0);
1694 return;1693 return;
1695 }1694 }
1696 try stream.writeAll(", ");1695 try stream.writeAll(", ");
...@@ -1698,8 +1697,6 @@ const Writer = struct {...@@ -1698,8 +1697,6 @@ const Writer = struct {
1698 const body = self.code.bodySlice(extra_index, body_len);1697 const body = self.code.bodySlice(extra_index, body_len);
1699 extra_index += body.len;1698 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);
1703 try self.writeBracedDecl(stream, body);1700 try self.writeBracedDecl(stream, body);
1704 try stream.writeAll(", {\n");1701 try stream.writeAll(", {\n");
17051702
...@@ -1763,17 +1760,21 @@ const Writer = struct {...@@ -1763,17 +1760,21 @@ const Writer = struct {
1763 try stream.writeAll(",\n");1760 try stream.writeAll(",\n");
1764 }1761 }
17651762
1766 self.parent_decl_node = prev_parent_decl_node;
1767 self.indent -= 2;1763 self.indent -= 2;
1768 try stream.writeByteNTimes(' ', self.indent);1764 try stream.writeByteNTimes(' ', self.indent);
1769 try stream.writeAll("})");1765 try stream.writeAll("}) ");
1770 try self.writeSrcNode(stream, extra.data.src_node);1766 try self.writeSrcNode(stream, 0);
1771 }1767 }
17721768
1773 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1769 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1774 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));1770 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17751771
1776 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);1772 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
1777 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1778 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1778 extra.data.fields_hash_0,1779 extra.data.fields_hash_0,
1779 extra.data.fields_hash_1,1780 extra.data.fields_hash_1,
...@@ -1835,10 +1836,6 @@ const Writer = struct {...@@ -1835,10 +1836,6 @@ const Writer = struct {
1835 if (decls_len == 0) {1836 if (decls_len == 0) {
1836 try stream.writeAll("{}, ");1837 try stream.writeAll("{}, ");
1837 } else {1838 } 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
1842 try stream.writeAll("{\n");1839 try stream.writeAll("{\n");
1843 self.indent += 2;1840 self.indent += 2;
1844 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1841 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1856,12 +1853,9 @@ const Writer = struct {...@@ -1856,12 +1853,9 @@ const Writer = struct {
1856 const body = self.code.bodySlice(extra_index, body_len);1853 const body = self.code.bodySlice(extra_index, body_len);
1857 extra_index += body.len;1854 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);
1861 try self.writeBracedDecl(stream, body);1856 try self.writeBracedDecl(stream, body);
1862 if (fields_len == 0) {1857 if (fields_len == 0) {
1863 try stream.writeAll(", {})");1858 try stream.writeAll(", {}) ");
1864 self.parent_decl_node = prev_parent_decl_node;
1865 } else {1859 } else {
1866 try stream.writeAll(", {\n");1860 try stream.writeAll(", {\n");
18671861
...@@ -1900,12 +1894,11 @@ const Writer = struct {...@@ -1900,12 +1894,11 @@ const Writer = struct {
1900 }1894 }
1901 try stream.writeAll(",\n");1895 try stream.writeAll(",\n");
1902 }1896 }
1903 self.parent_decl_node = prev_parent_decl_node;
1904 self.indent -= 2;1897 self.indent -= 2;
1905 try stream.writeByteNTimes(' ', self.indent);1898 try stream.writeByteNTimes(' ', self.indent);
1906 try stream.writeAll("})");1899 try stream.writeAll("}) ");
1907 }1900 }
1908 try self.writeSrcNode(stream, extra.data.src_node);1901 try self.writeSrcNode(stream, 0);
1909 }1902 }
19101903
1911 fn writeOpaqueDecl(1904 fn writeOpaqueDecl(
...@@ -1915,6 +1908,11 @@ const Writer = struct {...@@ -1915,6 +1908,11 @@ const Writer = struct {
1915 ) !void {1908 ) !void {
1916 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));1909 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
1917 const extra = self.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);1910 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
1918 var extra_index: usize = extra.end;1916 var extra_index: usize = extra.end;
19191917
1920 const captures_len = if (small.has_captures_len) blk: {1918 const captures_len = if (small.has_captures_len) blk: {
...@@ -1946,20 +1944,16 @@ const Writer = struct {...@@ -1946,20 +1944,16 @@ const Writer = struct {
1946 }1944 }
19471945
1948 if (decls_len == 0) {1946 if (decls_len == 0) {
1949 try stream.writeAll("{})");1947 try stream.writeAll("{}) ");
1950 } else {1948 } 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
1955 try stream.writeAll("{\n");1949 try stream.writeAll("{\n");
1956 self.indent += 2;1950 self.indent += 2;
1957 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1951 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
1958 self.indent -= 2;1952 self.indent -= 2;
1959 try stream.writeByteNTimes(' ', self.indent);1953 try stream.writeByteNTimes(' ', self.indent);
1960 try stream.writeAll("})");1954 try stream.writeAll("}) ");
1961 }1955 }
1962 try self.writeSrcNode(stream, extra.data.src_node);1956 try self.writeSrcNode(stream, 0);
1963 }1957 }
19641958
1965 fn writeErrorSetDecl(1959 fn writeErrorSetDecl(
...@@ -1988,7 +1982,7 @@ const Writer = struct {...@@ -1988,7 +1982,7 @@ const Writer = struct {
1988 try stream.writeByteNTimes(' ', self.indent);1982 try stream.writeByteNTimes(' ', self.indent);
1989 try stream.writeAll("}) ");1983 try stream.writeAll("}) ");
19901984
1991 try self.writeSrc(stream, inst_data.src());1985 try self.writeSrcNode(stream, inst_data.src_node);
1992 }1986 }
19931987
1994 fn writeSwitchBlockErrUnion(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1988 fn writeSwitchBlockErrUnion(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2125,7 +2119,7 @@ const Writer = struct {...@@ -2125,7 +2119,7 @@ const Writer = struct {
2125 self.indent -= 2;2119 self.indent -= 2;
21262120
2127 try stream.writeAll(") ");2121 try stream.writeAll(") ");
2128 try self.writeSrc(stream, inst_data.src());2122 try self.writeSrcNode(stream, inst_data.src_node);
2129 }2123 }
21302124
2131 fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2125 fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2255,7 +2249,7 @@ const Writer = struct {...@@ -2255,7 +2249,7 @@ const Writer = struct {
2255 self.indent -= 2;2249 self.indent -= 2;
22562250
2257 try stream.writeAll(") ");2251 try stream.writeAll(") ");
2258 try self.writeSrc(stream, inst_data.src());2252 try self.writeSrcNode(stream, inst_data.src_node);
2259 }2253 }
22602254
2261 fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2255 fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2264,7 +2258,7 @@ const Writer = struct {...@@ -2264,7 +2258,7 @@ const Writer = struct {
2264 const name = self.code.nullTerminatedString(extra.field_name_start);2258 const name = self.code.nullTerminatedString(extra.field_name_start);
2265 try self.writeInstRef(stream, extra.lhs);2259 try self.writeInstRef(stream, extra.lhs);
2266 try stream.print(", \"{}\") ", .{std.zig.fmtEscapes(name)});2260 try stream.print(", \"{}\") ", .{std.zig.fmtEscapes(name)});
2267 try self.writeSrc(stream, inst_data.src());2261 try self.writeSrcNode(stream, inst_data.src_node);
2268 }2262 }
22692263
2270 fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2264 fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2274,7 +2268,7 @@ const Writer = struct {...@@ -2274,7 +2268,7 @@ const Writer = struct {
2274 try stream.writeAll(", ");2268 try stream.writeAll(", ");
2275 try self.writeInstRef(stream, extra.field_name);2269 try self.writeInstRef(stream, extra.field_name);
2276 try stream.writeAll(") ");2270 try stream.writeAll(") ");
2277 try self.writeSrc(stream, inst_data.src());2271 try self.writeSrcNode(stream, inst_data.src_node);
2278 }2272 }
22792273
2280 fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2274 fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2284,7 +2278,7 @@ const Writer = struct {...@@ -2284,7 +2278,7 @@ const Writer = struct {
2284 try stream.writeAll(", ");2278 try stream.writeAll(", ");
2285 try self.writeInstRef(stream, extra.operand);2279 try self.writeInstRef(stream, extra.operand);
2286 try stream.writeAll(") ");2280 try stream.writeAll(") ");
2287 try self.writeSrc(stream, inst_data.src());2281 try self.writeSrcNode(stream, inst_data.src_node);
2288 }2282 }
22892283
2290 fn writeNode(2284 fn writeNode(
...@@ -2293,9 +2287,8 @@ const Writer = struct {...@@ -2293,9 +2287,8 @@ const Writer = struct {
2293 inst: Zir.Inst.Index,2287 inst: Zir.Inst.Index,
2294 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {2288 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2295 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;2289 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
2296 const src = LazySrcLoc.nodeOffset(src_node);
2297 try stream.writeAll(") ");2290 try stream.writeAll(") ");
2298 try self.writeSrc(stream, src);2291 try self.writeSrcNode(stream, src_node);
2299 }2292 }
23002293
2301 fn writeStrTok(2294 fn writeStrTok(
...@@ -2306,7 +2299,7 @@ const Writer = struct {...@@ -2306,7 +2299,7 @@ const Writer = struct {
2306 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;2299 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
2307 const str = inst_data.get(self.code);2300 const str = inst_data.get(self.code);
2308 try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)});2301 try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)});
2309 try self.writeSrc(stream, inst_data.src());2302 try self.writeSrcTok(stream, inst_data.src_tok);
2310 }2303 }
23112304
2312 fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2305 fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2323,7 +2316,6 @@ const Writer = struct {...@@ -2323,7 +2316,6 @@ const Writer = struct {
2323 inferred_error_set: bool,2316 inferred_error_set: bool,
2324 ) !void {2317 ) !void {
2325 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2318 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2326 const src = inst_data.src();
2327 const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index);2319 const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index);
23282320
2329 var extra_index = extra.end;2321 var extra_index = extra.end;
...@@ -2370,7 +2362,7 @@ const Writer = struct {...@@ -2370,7 +2362,7 @@ const Writer = struct {
2370 ret_ty_body,2362 ret_ty_body,
23712363
2372 body,2364 body,
2373 src,2365 inst_data.src_node,
2374 src_locs,2366 src_locs,
2375 0,2367 0,
2376 );2368 );
...@@ -2379,7 +2371,6 @@ const Writer = struct {...@@ -2379,7 +2371,6 @@ const Writer = struct {
2379 fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2371 fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2380 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2372 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2381 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);2373 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
2382 const src = inst_data.src();
23832374
2384 var extra_index: usize = extra.end;2375 var extra_index: usize = extra.end;
2385 var align_ref: Zir.Inst.Ref = .none;2376 var align_ref: Zir.Inst.Ref = .none;
...@@ -2476,7 +2467,7 @@ const Writer = struct {...@@ -2476,7 +2467,7 @@ const Writer = struct {
2476 ret_ty_ref,2467 ret_ty_ref,
2477 ret_ty_body,2468 ret_ty_body,
2478 body,2469 body,
2479 src,2470 inst_data.src_node,
2480 src_locs,2471 src_locs,
2481 noalias_bits,2472 noalias_bits,
2482 );2473 );
...@@ -2515,7 +2506,6 @@ const Writer = struct {...@@ -2515,7 +2506,6 @@ const Writer = struct {
2515 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2506 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2516 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);2507 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2517 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));2508 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
2518 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
25192509
2520 var extra_index: usize = extra.end;2510 var extra_index: usize = extra.end;
2521 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {2511 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
...@@ -2533,7 +2523,7 @@ const Writer = struct {...@@ -2533,7 +2523,7 @@ const Writer = struct {
2533 try self.writeOptionalInstRef(stream, ",ty=", type_inst);2523 try self.writeOptionalInstRef(stream, ",ty=", type_inst);
2534 try self.writeOptionalInstRef(stream, ",align=", align_inst);2524 try self.writeOptionalInstRef(stream, ",align=", align_inst);
2535 try stream.writeAll(")) ");2525 try stream.writeAll(")) ");
2536 try self.writeSrc(stream, src);2526 try self.writeSrcNode(stream, extra.data.src_node);
2537 }2527 }
25382528
2539 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2529 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
...@@ -2557,7 +2547,7 @@ const Writer = struct {...@@ -2557,7 +2547,7 @@ const Writer = struct {
2557 try stream.writeAll(", ");2547 try stream.writeAll(", ");
2558 try self.writeBracedBody(stream, body);2548 try self.writeBracedBody(stream, body);
2559 try stream.writeAll(") ");2549 try stream.writeAll(") ");
2560 try self.writeSrc(stream, inst_data.src());2550 try self.writeSrcNode(stream, inst_data.src_node);
2561 }2551 }
25622552
2563 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2553 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2567,7 +2557,7 @@ const Writer = struct {...@@ -2567,7 +2557,7 @@ const Writer = struct {
2567 .unsigned => 'u',2557 .unsigned => 'u',
2568 };2558 };
2569 try stream.print("{c}{d}) ", .{ prefix, int_type.bit_count });2559 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);
2571 }2561 }
25722562
2573 fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2563 fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2585,7 +2575,7 @@ const Writer = struct {...@@ -2585,7 +2575,7 @@ const Writer = struct {
2585 try self.writeInstRef(stream, extra.operand);2575 try self.writeInstRef(stream, extra.operand);
25862576
2587 try stream.writeAll(") ");2577 try stream.writeAll(") ");
2588 try self.writeSrc(stream, extra.src());2578 try self.writeSrcNode(stream, extra.src_node);
2589 }2579 }
25902580
2591 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2581 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2611,7 +2601,7 @@ const Writer = struct {...@@ -2611,7 +2601,7 @@ const Writer = struct {
2611 try self.writeInstRef(stream, arg);2601 try self.writeInstRef(stream, arg);
2612 }2602 }
2613 try stream.writeAll("}) ");2603 try stream.writeAll("}) ");
2614 try self.writeSrc(stream, inst_data.src());2604 try self.writeSrcNode(stream, inst_data.src_node);
2615 }2605 }
26162606
2617 fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2607 fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2626,7 +2616,7 @@ const Writer = struct {...@@ -2626,7 +2616,7 @@ const Writer = struct {
2626 try self.writeInstRef(stream, arg);2616 try self.writeInstRef(stream, arg);
2627 }2617 }
2628 try stream.writeAll("}) ");2618 try stream.writeAll("}) ");
2629 try self.writeSrc(stream, inst_data.src());2619 try self.writeSrcNode(stream, inst_data.src_node);
2630 }2620 }
26312621
2632 fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2622 fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2646,13 +2636,13 @@ const Writer = struct {...@@ -2646,13 +2636,13 @@ const Writer = struct {
2646 try self.writeInstRef(stream, elem);2636 try self.writeInstRef(stream, elem);
2647 }2637 }
2648 try stream.writeAll("}) ");2638 try stream.writeAll("}) ");
2649 try self.writeSrc(stream, inst_data.src());2639 try self.writeSrcNode(stream, inst_data.src_node);
2650 }2640 }
26512641
2652 fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2642 fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2653 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";2643 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
2654 try stream.writeAll(") ");2644 try stream.writeAll(") ");
2655 try self.writeSrc(stream, inst_data.src());2645 try self.writeSrcNode(stream, inst_data.src_node);
2656 }2646 }
26572647
2658 fn writeFuncCommon(2648 fn writeFuncCommon(
...@@ -2673,7 +2663,7 @@ const Writer = struct {...@@ -2673,7 +2663,7 @@ const Writer = struct {
2673 ret_ty_ref: Zir.Inst.Ref,2663 ret_ty_ref: Zir.Inst.Ref,
2674 ret_ty_body: []const Zir.Inst.Index,2664 ret_ty_body: []const Zir.Inst.Index,
2675 body: []const Zir.Inst.Index,2665 body: []const Zir.Inst.Index,
2676 src: LazySrcLoc,2666 src_node: i32,
2677 src_locs: Zir.Inst.Func.SrcLocs,2667 src_locs: Zir.Inst.Func.SrcLocs,
2678 noalias_bits: u32,2668 noalias_bits: u32,
2679 ) !void {2669 ) !void {
...@@ -2700,7 +2690,7 @@ const Writer = struct {...@@ -2700,7 +2690,7 @@ const Writer = struct {
2700 src_locs.rbrace_line + 1, @as(u16, @truncate(src_locs.columns >> 16)) + 1,2690 src_locs.rbrace_line + 1, @as(u16, @truncate(src_locs.columns >> 16)) + 1,
2701 });2691 });
2702 }2692 }
2703 try self.writeSrc(stream, src);2693 try self.writeSrcNode(stream, src_node);
2704 }2694 }
27052695
2706 fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2696 fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2729,11 +2719,16 @@ const Writer = struct {...@@ -2729,11 +2719,16 @@ const Writer = struct {
2729 }2719 }
27302720
2731 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2721 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;
2733 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);2723 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);
2734 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {2724 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {
2735 break :dc @enumFromInt(self.code.extra[extra.end]);2725 break :dc @enumFromInt(self.code.extra[extra.end]);
2736 } else null;2726 } 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
2737 if (extra.data.flags.is_pub) try stream.writeAll("pub ");2732 if (extra.data.flags.is_pub) try stream.writeAll("pub ");
2738 if (extra.data.flags.is_export) try stream.writeAll("export ");2733 if (extra.data.flags.is_export) try stream.writeAll("export ");
2739 switch (extra.data.name) {2734 switch (extra.data.name) {
...@@ -2757,10 +2752,6 @@ const Writer = struct {...@@ -2757,10 +2752,6 @@ const Writer = struct {
2757 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });2752 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });
27582753
2759 {2754 {
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
2764 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);2755 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);
27652756
2766 try stream.writeAll(" value=");2757 try stream.writeAll(" value=");
...@@ -2783,13 +2774,12 @@ const Writer = struct {...@@ -2783,13 +2774,12 @@ const Writer = struct {
2783 }2774 }
27842775
2785 try stream.writeAll(") ");2776 try stream.writeAll(") ");
2786 try self.writeSrc(stream, inst_data.src());2777 try self.writeSrcNode(stream, 0);
2787 }2778 }
27882779
2789 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2780 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2790 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
2791 try stream.print("{d})) ", .{extended.small});2781 try stream.print("{d})) ", .{extended.small});
2792 try self.writeSrc(stream, src);2782 try self.writeSrcNode(stream, @bitCast(extended.operand));
2793 }2783 }
27942784
2795 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {2785 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
...@@ -2865,29 +2855,44 @@ const Writer = struct {...@@ -2865,29 +2855,44 @@ const Writer = struct {
2865 try stream.writeAll(name);2855 try stream.writeAll(name);
2866 }2856 }
28672857
2868 fn writeSrc(self: *Writer, stream: anytype, src: LazySrcLoc) !void {2858 fn writeSrcNode(self: *Writer, stream: anytype, src_node: i32) !void {
2869 if (self.file.tree_loaded) {2859 if (!self.file.tree_loaded) return;
2870 const tree = self.file.tree;2860 const tree = self.file.tree;
2871 const src_loc: Module.SrcLoc = .{2861 const abs_node = self.relativeToNodeIndex(src_node);
2872 .file_scope = self.file,2862 const src_span = tree.nodeToSpan(abs_node);
2873 .parent_decl_node = self.parent_decl_node,2863 const start = self.line_col_cursor.find(tree.source, src_span.start);
2874 .lazy = src,2864 const end = self.line_col_cursor.find(tree.source, src_span.end);
2875 };2865 try stream.print("node_offset:{d}:{d} to :{d}:{d}", .{
2876 const src_span = src_loc.span(self.gpa) catch unreachable;2866 start.line + 1, start.column + 1,
2877 const start = self.line_col_cursor.find(tree.source, src_span.start);2867 end.line + 1, end.column + 1,
2878 const end = self.line_col_cursor.find(tree.source, src_span.end);2868 });
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 }
2884 }2869 }
28852870
2886 fn writeSrcNode(self: *Writer, stream: anytype, src_node: ?i32) !void {2871 fn writeSrcTok(self: *Writer, stream: anytype, src_tok: u32) !void {
2887 const node_offset = src_node orelse return;2872 if (!self.file.tree_loaded) return;
2888 const src = LazySrcLoc.nodeOffset(node_offset);2873 const tree = self.file.tree;
2889 try stream.writeAll(" ");2874 const abs_tok = tree.firstToken(self.parent_decl_node) + src_tok;
2890 return self.writeSrc(stream, src);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 });
2891 }2896 }
28922897
2893 fn writeBracedDecl(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {2898 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 {...@@ -3317,15 +3317,6 @@ pub const Type = struct {
3317 }3317 }
3318 }3318 }
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
3329 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {3320 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
3330 return ty.getOwnerDeclOrNull(mod) orelse unreachable;3321 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
3331 }3322 }
...@@ -3341,6 +3332,26 @@ pub const Type = struct {...@@ -3341,6 +3332,26 @@ pub const Type = struct {
3341 };3332 };
3342 }3333 }
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
3344 pub fn isGenericPoison(ty: Type) bool {3355 pub fn isGenericPoison(ty: Type) bool {
3345 return ty.toIntern() == .generic_poison_type;3356 return ty.toIntern() == .generic_poison_type;
3346 }3357 }
test/cases/compile_errors/enum_value_already_taken.zig+1-1
...@@ -15,4 +15,4 @@ export fn entry() void {...@@ -15,4 +15,4 @@ export fn entry() void {
15// target=native15// target=native
16//16//
17// :6:9: error: enum tag value 60 already taken17// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here18// :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 {...@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
6// backend=stage26// backend=stage2
7// target=native7// target=native
8//8//
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 {...@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
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 {...@@ -19,5 +19,5 @@ comptime {
19// target=native19// target=native
20//20//
21// :5:30: error: comptime parameters not allowed in function with calling convention 'C'21// :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'
23// :1:15: error: comptime parameters not allowed in function with calling convention 'C'23// :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 {...@@ -27,9 +27,9 @@ export fn h() void {
27// target=native27// target=native
28//28//
29// :9:16: error: missing struct field: x29// :9:16: error: missing struct field: x
30// :1:11: note: struct 'tmp.A' declared here30// :1:11: note: struct declared here
31// :18:16: error: missing tuple field with index 131// :18:16: error: missing tuple field with index 1
32// :16:11: note: struct declared here32// :16:11: note: struct declared here
33// :22:16: error: missing tuple field with index 033// :22:16: error: missing tuple field with index 0
34// :22:16: note: missing tuple field with index 134// :22:16: note: missing tuple field with index 1
35// :16:11: note: struct 'tmp.B' declared here35// :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 {...@@ -14,5 +14,5 @@ comptime {
14// target=native14// target=native
15//15//
16// :5:17: error: missing struct field: b16// :5:17: error: missing struct field: b
17// :1:11: note: struct 'tmp.S' declared here17// :1:11: note: struct declared here
18// :9:15: note: called from here18// :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 {...@@ -17,5 +17,5 @@ pub export fn entr2() void {
17// backend=stage217// backend=stage2
18// target=native18// target=native
19//19//
20// :4:9: error: range start value is greater than the end value20// :4:10: error: range start value is greater than the end value
21// :11:9: error: range start value is greater than the end value21// :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 {...@@ -14,5 +14,5 @@ export fn entry() void {
14// backend=stage214// backend=stage2
15// target=native15// target=native
16//16//
17// :6:5: error: enum tag value 60 already taken17// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here18// :4:9: note: other occurrence here