authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-26 20:35:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-26 21:35:30-07:00
logf7143e18e368eb89763e9d813b8b7c9c96dd1bd3
treecf1ee7be89d5f632ef865f2ff3900c48150d08e2
parent4e2570baafb587c679ee0fc5e113ddeb36522a5d

move Zcu.LazySrcLoc to std.zig.LazySrcLoc

Part of an effort to ship more of the compiler in source form.

10 files changed, 521 insertions(+), 521 deletions(-)

lib/std/zig.zig+373
...@@ -315,6 +315,379 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![...@@ -315,6 +315,379 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![
315 return buffer.toOwnedSlice();315 return buffer.toOwnedSlice();
316}316}
317317
318pub const DeclIndex = enum(u32) {
319 _,
320
321 pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
322 return @enumFromInt(@intFromEnum(i));
323 }
324};
325
326pub const OptionalDeclIndex = enum(u32) {
327 none = std.math.maxInt(u32),
328 _,
329
330 pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
331 return @enumFromInt(@intFromEnum(oi orelse return .none));
332 }
333
334 pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
335 if (oi == .none) return null;
336 return @enumFromInt(@intFromEnum(oi));
337 }
338};
339
340/// Resolving a source location into a byte offset may require doing work
341/// that we would rather not do unless the error actually occurs.
342/// Therefore we need a data structure that contains the information necessary
343/// to lazily produce a `SrcLoc` as required.
344/// Most of the offsets in this data structure are relative to the containing Decl.
345/// This makes the source location resolve properly even when a Decl gets
346/// shifted up or down in the file, as long as the Decl's contents itself
347/// do not change.
348pub const LazySrcLoc = union(enum) {
349 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
350 /// that all code paths which would need to resolve the source location are
351 /// unreachable. If you are debugging this tag incorrectly being this value,
352 /// look into using reverse-continue with a memory watchpoint to see where the
353 /// value is being set to this tag.
354 unneeded,
355 /// Means the source location points to an entire file; not any particular
356 /// location within the file. `file_scope` union field will be active.
357 entire_file,
358 /// The source location points to a byte offset within a source file,
359 /// offset from 0. The source file is determined contextually.
360 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
361 byte_abs: u32,
362 /// The source location points to a token within a source file,
363 /// offset from 0. The source file is determined contextually.
364 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
365 token_abs: u32,
366 /// The source location points to an AST node within a source file,
367 /// offset from 0. The source file is determined contextually.
368 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
369 node_abs: u32,
370 /// The source location points to a byte offset within a source file,
371 /// offset from the byte offset of the Decl within the file.
372 /// The Decl is determined contextually.
373 byte_offset: u32,
374 /// This data is the offset into the token list from the Decl token.
375 /// The Decl is determined contextually.
376 token_offset: u32,
377 /// The source location points to an AST node, which is this value offset
378 /// from its containing Decl node AST index.
379 /// The Decl is determined contextually.
380 node_offset: TracedOffset,
381 /// The source location points to the main token of an AST node, found
382 /// by taking this AST node index offset from the containing Decl AST node.
383 /// The Decl is determined contextually.
384 node_offset_main_token: i32,
385 /// The source location points to the beginning of a struct initializer.
386 /// The Decl is determined contextually.
387 node_offset_initializer: i32,
388 /// The source location points to a variable declaration type expression,
389 /// found by taking this AST node index offset from the containing
390 /// Decl AST node, which points to a variable declaration AST node. Next, navigate
391 /// to the type expression.
392 /// The Decl is determined contextually.
393 node_offset_var_decl_ty: i32,
394 /// The source location points to the alignment expression of a var decl.
395 /// The Decl is determined contextually.
396 node_offset_var_decl_align: i32,
397 /// The source location points to the linksection expression of a var decl.
398 /// The Decl is determined contextually.
399 node_offset_var_decl_section: i32,
400 /// The source location points to the addrspace expression of a var decl.
401 /// The Decl is determined contextually.
402 node_offset_var_decl_addrspace: i32,
403 /// The source location points to the initializer of a var decl.
404 /// The Decl is determined contextually.
405 node_offset_var_decl_init: i32,
406 /// The source location points to the first parameter of a builtin
407 /// function call, found by taking this AST node index offset from the containing
408 /// Decl AST node, which points to a builtin call AST node. Next, navigate
409 /// to the first parameter.
410 /// The Decl is determined contextually.
411 node_offset_builtin_call_arg0: i32,
412 /// Same as `node_offset_builtin_call_arg0` except arg index 1.
413 node_offset_builtin_call_arg1: i32,
414 node_offset_builtin_call_arg2: i32,
415 node_offset_builtin_call_arg3: i32,
416 node_offset_builtin_call_arg4: i32,
417 node_offset_builtin_call_arg5: i32,
418 /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls
419 /// to pointer cast builtins.
420 node_offset_ptrcast_operand: i32,
421 /// The source location points to the index expression of an array access
422 /// expression, found by taking this AST node index offset from the containing
423 /// Decl AST node, which points to an array access AST node. Next, navigate
424 /// to the index expression.
425 /// The Decl is determined contextually.
426 node_offset_array_access_index: i32,
427 /// The source location points to the LHS of a slice expression
428 /// expression, found by taking this AST node index offset from the containing
429 /// Decl AST node, which points to a slice AST node. Next, navigate
430 /// to the sentinel expression.
431 /// The Decl is determined contextually.
432 node_offset_slice_ptr: i32,
433 /// The source location points to start expression of a slice expression
434 /// expression, found by taking this AST node index offset from the containing
435 /// Decl AST node, which points to a slice AST node. Next, navigate
436 /// to the sentinel expression.
437 /// The Decl is determined contextually.
438 node_offset_slice_start: i32,
439 /// The source location points to the end expression of a slice
440 /// expression, found by taking this AST node index offset from the containing
441 /// Decl AST node, which points to a slice AST node. Next, navigate
442 /// to the sentinel expression.
443 /// The Decl is determined contextually.
444 node_offset_slice_end: i32,
445 /// The source location points to the sentinel expression of a slice
446 /// expression, found by taking this AST node index offset from the containing
447 /// Decl AST node, which points to a slice AST node. Next, navigate
448 /// to the sentinel expression.
449 /// The Decl is determined contextually.
450 node_offset_slice_sentinel: i32,
451 /// The source location points to the callee expression of a function
452 /// call expression, found by taking this AST node index offset from the containing
453 /// Decl AST node, which points to a function call AST node. Next, navigate
454 /// to the callee expression.
455 /// The Decl is determined contextually.
456 node_offset_call_func: i32,
457 /// The payload is offset from the containing Decl AST node.
458 /// The source location points to the field name of:
459 /// * a field access expression (`a.b`), or
460 /// * the callee of a method call (`a.b()`)
461 /// The Decl is determined contextually.
462 node_offset_field_name: i32,
463 /// The payload is offset from the containing Decl AST node.
464 /// The source location points to the field name of the operand ("b" node)
465 /// of a field initialization expression (`.a = b`)
466 /// The Decl is determined contextually.
467 node_offset_field_name_init: i32,
468 /// The source location points to the pointer of a pointer deref expression,
469 /// found by taking this AST node index offset from the containing
470 /// Decl AST node, which points to a pointer deref AST node. Next, navigate
471 /// to the pointer expression.
472 /// The Decl is determined contextually.
473 node_offset_deref_ptr: i32,
474 /// The source location points to the assembly source code of an inline assembly
475 /// expression, found by taking this AST node index offset from the containing
476 /// Decl AST node, which points to inline assembly AST node. Next, navigate
477 /// to the asm template source code.
478 /// The Decl is determined contextually.
479 node_offset_asm_source: i32,
480 /// The source location points to the return type of an inline assembly
481 /// expression, found by taking this AST node index offset from the containing
482 /// Decl AST node, which points to inline assembly AST node. Next, navigate
483 /// to the return type expression.
484 /// The Decl is determined contextually.
485 node_offset_asm_ret_ty: i32,
486 /// The source location points to the condition expression of an if
487 /// expression, found by taking this AST node index offset from the containing
488 /// Decl AST node, which points to an if expression AST node. Next, navigate
489 /// to the condition expression.
490 /// The Decl is determined contextually.
491 node_offset_if_cond: i32,
492 /// The source location points to a binary expression, such as `a + b`, found
493 /// by taking this AST node index offset from the containing Decl AST node.
494 /// The Decl is determined contextually.
495 node_offset_bin_op: i32,
496 /// The source location points to the LHS of a binary expression, found
497 /// by taking this AST node index offset from the containing Decl AST node,
498 /// which points to a binary expression AST node. Next, navigate to the LHS.
499 /// The Decl is determined contextually.
500 node_offset_bin_lhs: i32,
501 /// The source location points to the RHS of a binary expression, found
502 /// by taking this AST node index offset from the containing Decl AST node,
503 /// which points to a binary expression AST node. Next, navigate to the RHS.
504 /// The Decl is determined contextually.
505 node_offset_bin_rhs: i32,
506 /// The source location points to the operand of a switch expression, found
507 /// by taking this AST node index offset from the containing Decl AST node,
508 /// which points to a switch expression AST node. Next, navigate to the operand.
509 /// The Decl is determined contextually.
510 node_offset_switch_operand: i32,
511 /// The source location points to the else/`_` prong of a switch expression, found
512 /// by taking this AST node index offset from the containing Decl AST node,
513 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
514 /// The Decl is determined contextually.
515 node_offset_switch_special_prong: i32,
516 /// The source location points to all the ranges of a switch expression, found
517 /// by taking this AST node index offset from the containing Decl AST node,
518 /// which points to a switch expression AST node. Next, navigate to any of the
519 /// range nodes. The error applies to all of them.
520 /// The Decl is determined contextually.
521 node_offset_switch_range: i32,
522 /// The source location points to the capture of a switch_prong.
523 /// The Decl is determined contextually.
524 node_offset_switch_prong_capture: i32,
525 /// The source location points to the tag capture of a switch_prong.
526 /// The Decl is determined contextually.
527 node_offset_switch_prong_tag_capture: i32,
528 /// The source location points to the align expr of a function type
529 /// expression, found by taking this AST node index offset from the containing
530 /// Decl AST node, which points to a function type AST node. Next, navigate to
531 /// the calling convention node.
532 /// The Decl is determined contextually.
533 node_offset_fn_type_align: i32,
534 /// The source location points to the addrspace expr of a function type
535 /// expression, found by taking this AST node index offset from the containing
536 /// Decl AST node, which points to a function type AST node. Next, navigate to
537 /// the calling convention node.
538 /// The Decl is determined contextually.
539 node_offset_fn_type_addrspace: i32,
540 /// The source location points to the linksection expr of a function type
541 /// expression, found by taking this AST node index offset from the containing
542 /// Decl AST node, which points to a function type AST node. Next, navigate to
543 /// the calling convention node.
544 /// The Decl is determined contextually.
545 node_offset_fn_type_section: i32,
546 /// The source location points to the calling convention of a function type
547 /// expression, found by taking this AST node index offset from the containing
548 /// Decl AST node, which points to a function type AST node. Next, navigate to
549 /// the calling convention node.
550 /// The Decl is determined contextually.
551 node_offset_fn_type_cc: i32,
552 /// The source location points to the return type of a function type
553 /// expression, found by taking this AST node index offset from the containing
554 /// Decl AST node, which points to a function type AST node. Next, navigate to
555 /// the return type node.
556 /// The Decl is determined contextually.
557 node_offset_fn_type_ret_ty: i32,
558 node_offset_param: i32,
559 token_offset_param: i32,
560 /// The source location points to the type expression of an `anyframe->T`
561 /// expression, found by taking this AST node index offset from the containing
562 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
563 /// to the type expression.
564 /// The Decl is determined contextually.
565 node_offset_anyframe_type: i32,
566 /// The source location points to the string literal of `extern "foo"`, found
567 /// by taking this AST node index offset from the containing
568 /// Decl AST node, which points to a function prototype or variable declaration
569 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
570 /// The Decl is determined contextually.
571 node_offset_lib_name: i32,
572 /// The source location points to the len expression of an `[N:S]T`
573 /// expression, found by taking this AST node index offset from the containing
574 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
575 /// to the len expression.
576 /// The Decl is determined contextually.
577 node_offset_array_type_len: i32,
578 /// The source location points to the sentinel expression of an `[N:S]T`
579 /// expression, found by taking this AST node index offset from the containing
580 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
581 /// to the sentinel expression.
582 /// The Decl is determined contextually.
583 node_offset_array_type_sentinel: i32,
584 /// The source location points to the elem expression of an `[N:S]T`
585 /// expression, found by taking this AST node index offset from the containing
586 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
587 /// to the elem expression.
588 /// The Decl is determined contextually.
589 node_offset_array_type_elem: i32,
590 /// The source location points to the operand of an unary expression.
591 /// The Decl is determined contextually.
592 node_offset_un_op: i32,
593 /// The source location points to the elem type of a pointer.
594 /// The Decl is determined contextually.
595 node_offset_ptr_elem: i32,
596 /// The source location points to the sentinel of a pointer.
597 /// The Decl is determined contextually.
598 node_offset_ptr_sentinel: i32,
599 /// The source location points to the align expr of a pointer.
600 /// The Decl is determined contextually.
601 node_offset_ptr_align: i32,
602 /// The source location points to the addrspace expr of a pointer.
603 /// The Decl is determined contextually.
604 node_offset_ptr_addrspace: i32,
605 /// The source location points to the bit-offset of a pointer.
606 /// The Decl is determined contextually.
607 node_offset_ptr_bitoffset: i32,
608 /// The source location points to the host size of a pointer.
609 /// The Decl is determined contextually.
610 node_offset_ptr_hostsize: i32,
611 /// The source location points to the tag type of an union or an enum.
612 /// The Decl is determined contextually.
613 node_offset_container_tag: i32,
614 /// The source location points to the default value of a field.
615 /// The Decl is determined contextually.
616 node_offset_field_default: i32,
617 /// The source location points to the type of an array or struct initializer.
618 /// The Decl is determined contextually.
619 node_offset_init_ty: i32,
620 /// The source location points to the LHS of an assignment.
621 /// The Decl is determined contextually.
622 node_offset_store_ptr: i32,
623 /// The source location points to the RHS of an assignment.
624 /// The Decl is determined contextually.
625 node_offset_store_operand: i32,
626 /// The source location points to the operand of a `return` statement, or
627 /// the `return` itself if there is no explicit operand.
628 /// The Decl is determined contextually.
629 node_offset_return_operand: i32,
630 /// The source location points to a for loop input.
631 /// The Decl is determined contextually.
632 for_input: struct {
633 /// Points to the for loop AST node.
634 for_node_offset: i32,
635 /// Picks one of the inputs from the condition.
636 input_index: u32,
637 },
638 /// The source location points to one of the captures of a for loop, found
639 /// by taking this AST node index offset from the containing
640 /// Decl AST node, which points to one of the input nodes of a for loop.
641 /// Next, navigate to the corresponding capture.
642 /// The Decl is determined contextually.
643 for_capture_from_input: i32,
644 /// The source location points to the argument node of a function call.
645 call_arg: struct {
646 decl: DeclIndex,
647 /// Points to the function call AST node.
648 call_node_offset: i32,
649 /// The index of the argument the source location points to.
650 arg_index: u32,
651 },
652 fn_proto_param: struct {
653 decl: DeclIndex,
654 /// Points to the function prototype AST node.
655 fn_proto_node_offset: i32,
656 /// The index of the parameter the source location points to.
657 param_index: u32,
658 },
659 array_cat_lhs: ArrayCat,
660 array_cat_rhs: ArrayCat,
661
662 const ArrayCat = struct {
663 /// Points to the array concat AST node.
664 array_cat_offset: i32,
665 /// The index of the element the source location points to.
666 elem_index: u32,
667 };
668
669 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
670
671 noinline fn nodeOffsetDebug(node_offset: i32) LazySrcLoc {
672 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
673 result.node_offset.trace.addAddr(@returnAddress(), "init");
674 return result;
675 }
676
677 fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {
678 return .{ .node_offset = .{ .x = node_offset } };
679 }
680
681 /// This wraps a simple integer in debug builds so that later on we can find out
682 /// where in semantic analysis the value got set.
683 pub const TracedOffset = struct {
684 x: i32,
685 trace: std.debug.Trace = .{},
686
687 const want_tracing = false;
688 };
689};
690
318const std = @import("std.zig");691const std = @import("std.zig");
319const tokenizer = @import("zig/tokenizer.zig");692const tokenizer = @import("zig/tokenizer.zig");
320const assert = std.debug.assert;693const assert = std.debug.assert;
src/InternPool.zig+2-21
...@@ -383,27 +383,8 @@ pub const RuntimeIndex = enum(u32) {...@@ -383,27 +383,8 @@ pub const RuntimeIndex = enum(u32) {
383 }383 }
384};384};
385385
386pub const DeclIndex = enum(u32) {386pub const DeclIndex = std.zig.DeclIndex;
387 _,387pub const OptionalDeclIndex = std.zig.OptionalDeclIndex;
388
389 pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
390 return @enumFromInt(@intFromEnum(i));
391 }
392};
393
394pub const OptionalDeclIndex = enum(u32) {
395 none = std.math.maxInt(u32),
396 _,
397
398 pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
399 return @enumFromInt(@intFromEnum(oi orelse return .none));
400 }
401
402 pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
403 if (oi == .none) return null;
404 return @enumFromInt(@intFromEnum(oi));
405 }
406};
407388
408pub const NamespaceIndex = enum(u32) {389pub const NamespaceIndex = enum(u32) {
409 _,390 _,
src/Module.zig+96-446
...@@ -13,6 +13,7 @@ const BigIntConst = std.math.big.int.Const;...@@ -13,6 +13,7 @@ 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;
1617
17/// Deprecated, use `Zcu`.18/// Deprecated, use `Zcu`.
18const Module = Zcu;19const Module = Zcu;
...@@ -664,6 +665,101 @@ pub const Decl = struct {...@@ -664,6 +665,101 @@ pub const Decl = struct {
664 if (decl.alignment != .none) return decl.alignment;665 if (decl.alignment != .none) return decl.alignment;
665 return decl.ty.abiAlignment(zcu);666 return decl.ty.abiAlignment(zcu);
666 }667 }
668
669 /// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
670 pub fn toSrcLoc(decl: *Decl, lazy: LazySrcLoc, mod: *Module) SrcLoc {
671 return switch (lazy) {
672 .unneeded,
673 .entire_file,
674 .byte_abs,
675 .token_abs,
676 .node_abs,
677 => .{
678 .file_scope = decl.getFileScope(mod),
679 .parent_decl_node = 0,
680 .lazy = lazy,
681 },
682
683 .byte_offset,
684 .token_offset,
685 .node_offset,
686 .node_offset_main_token,
687 .node_offset_initializer,
688 .node_offset_var_decl_ty,
689 .node_offset_var_decl_align,
690 .node_offset_var_decl_section,
691 .node_offset_var_decl_addrspace,
692 .node_offset_var_decl_init,
693 .node_offset_builtin_call_arg0,
694 .node_offset_builtin_call_arg1,
695 .node_offset_builtin_call_arg2,
696 .node_offset_builtin_call_arg3,
697 .node_offset_builtin_call_arg4,
698 .node_offset_builtin_call_arg5,
699 .node_offset_ptrcast_operand,
700 .node_offset_array_access_index,
701 .node_offset_slice_ptr,
702 .node_offset_slice_start,
703 .node_offset_slice_end,
704 .node_offset_slice_sentinel,
705 .node_offset_call_func,
706 .node_offset_field_name,
707 .node_offset_field_name_init,
708 .node_offset_deref_ptr,
709 .node_offset_asm_source,
710 .node_offset_asm_ret_ty,
711 .node_offset_if_cond,
712 .node_offset_bin_op,
713 .node_offset_bin_lhs,
714 .node_offset_bin_rhs,
715 .node_offset_switch_operand,
716 .node_offset_switch_special_prong,
717 .node_offset_switch_range,
718 .node_offset_switch_prong_capture,
719 .node_offset_switch_prong_tag_capture,
720 .node_offset_fn_type_align,
721 .node_offset_fn_type_addrspace,
722 .node_offset_fn_type_section,
723 .node_offset_fn_type_cc,
724 .node_offset_fn_type_ret_ty,
725 .node_offset_param,
726 .token_offset_param,
727 .node_offset_anyframe_type,
728 .node_offset_lib_name,
729 .node_offset_array_type_len,
730 .node_offset_array_type_sentinel,
731 .node_offset_array_type_elem,
732 .node_offset_un_op,
733 .node_offset_ptr_elem,
734 .node_offset_ptr_sentinel,
735 .node_offset_ptr_align,
736 .node_offset_ptr_addrspace,
737 .node_offset_ptr_bitoffset,
738 .node_offset_ptr_hostsize,
739 .node_offset_container_tag,
740 .node_offset_field_default,
741 .node_offset_init_ty,
742 .node_offset_store_ptr,
743 .node_offset_store_operand,
744 .node_offset_return_operand,
745 .for_input,
746 .for_capture_from_input,
747 .array_cat_lhs,
748 .array_cat_rhs,
749 => .{
750 .file_scope = decl.getFileScope(mod),
751 .parent_decl_node = decl.src_node,
752 .lazy = lazy,
753 },
754 inline .call_arg,
755 .fn_proto_param,
756 => |x| .{
757 .file_scope = decl.getFileScope(mod),
758 .parent_decl_node = mod.declPtr(x.decl).src_node,
759 .lazy = lazy,
760 },
761 };
762 }
667};763};
668764
669/// This state is attached to every Decl when Module emit_h is non-null.765/// This state is attached to every Decl when Module emit_h is non-null.
...@@ -1951,452 +2047,6 @@ pub const SrcLoc = struct {...@@ -1951,452 +2047,6 @@ pub const SrcLoc = struct {
1951 }2047 }
1952};2048};
19532049
1954/// This wraps a simple integer in debug builds so that later on we can find out
1955/// where in semantic analysis the value got set.
1956const TracedOffset = struct {
1957 x: i32,
1958 trace: std.debug.Trace = .{},
1959
1960 const want_tracing = build_options.value_tracing;
1961};
1962
1963/// Resolving a source location into a byte offset may require doing work
1964/// that we would rather not do unless the error actually occurs.
1965/// Therefore we need a data structure that contains the information necessary
1966/// to lazily produce a `SrcLoc` as required.
1967/// Most of the offsets in this data structure are relative to the containing Decl.
1968/// This makes the source location resolve properly even when a Decl gets
1969/// shifted up or down in the file, as long as the Decl's contents itself
1970/// do not change.
1971pub const LazySrcLoc = union(enum) {
1972 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1973 /// that all code paths which would need to resolve the source location are
1974 /// unreachable. If you are debugging this tag incorrectly being this value,
1975 /// look into using reverse-continue with a memory watchpoint to see where the
1976 /// value is being set to this tag.
1977 unneeded,
1978 /// Means the source location points to an entire file; not any particular
1979 /// location within the file. `file_scope` union field will be active.
1980 entire_file,
1981 /// The source location points to a byte offset within a source file,
1982 /// offset from 0. The source file is determined contextually.
1983 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1984 byte_abs: u32,
1985 /// The source location points to a token within a source file,
1986 /// offset from 0. The source file is determined contextually.
1987 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1988 token_abs: u32,
1989 /// The source location points to an AST node within a source file,
1990 /// offset from 0. The source file is determined contextually.
1991 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1992 node_abs: u32,
1993 /// The source location points to a byte offset within a source file,
1994 /// offset from the byte offset of the Decl within the file.
1995 /// The Decl is determined contextually.
1996 byte_offset: u32,
1997 /// This data is the offset into the token list from the Decl token.
1998 /// The Decl is determined contextually.
1999 token_offset: u32,
2000 /// The source location points to an AST node, which is this value offset
2001 /// from its containing Decl node AST index.
2002 /// The Decl is determined contextually.
2003 node_offset: TracedOffset,
2004 /// The source location points to the main token of an AST node, found
2005 /// by taking this AST node index offset from the containing Decl AST node.
2006 /// The Decl is determined contextually.
2007 node_offset_main_token: i32,
2008 /// The source location points to the beginning of a struct initializer.
2009 /// The Decl is determined contextually.
2010 node_offset_initializer: i32,
2011 /// The source location points to a variable declaration type expression,
2012 /// found by taking this AST node index offset from the containing
2013 /// Decl AST node, which points to a variable declaration AST node. Next, navigate
2014 /// to the type expression.
2015 /// The Decl is determined contextually.
2016 node_offset_var_decl_ty: i32,
2017 /// The source location points to the alignment expression of a var decl.
2018 /// The Decl is determined contextually.
2019 node_offset_var_decl_align: i32,
2020 /// The source location points to the linksection expression of a var decl.
2021 /// The Decl is determined contextually.
2022 node_offset_var_decl_section: i32,
2023 /// The source location points to the addrspace expression of a var decl.
2024 /// The Decl is determined contextually.
2025 node_offset_var_decl_addrspace: i32,
2026 /// The source location points to the initializer of a var decl.
2027 /// The Decl is determined contextually.
2028 node_offset_var_decl_init: i32,
2029 /// The source location points to the first parameter of a builtin
2030 /// function call, found by taking this AST node index offset from the containing
2031 /// Decl AST node, which points to a builtin call AST node. Next, navigate
2032 /// to the first parameter.
2033 /// The Decl is determined contextually.
2034 node_offset_builtin_call_arg0: i32,
2035 /// Same as `node_offset_builtin_call_arg0` except arg index 1.
2036 node_offset_builtin_call_arg1: i32,
2037 node_offset_builtin_call_arg2: i32,
2038 node_offset_builtin_call_arg3: i32,
2039 node_offset_builtin_call_arg4: i32,
2040 node_offset_builtin_call_arg5: i32,
2041 /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls
2042 /// to pointer cast builtins.
2043 node_offset_ptrcast_operand: i32,
2044 /// The source location points to the index expression of an array access
2045 /// expression, found by taking this AST node index offset from the containing
2046 /// Decl AST node, which points to an array access AST node. Next, navigate
2047 /// to the index expression.
2048 /// The Decl is determined contextually.
2049 node_offset_array_access_index: i32,
2050 /// The source location points to the LHS of a slice expression
2051 /// expression, found by taking this AST node index offset from the containing
2052 /// Decl AST node, which points to a slice AST node. Next, navigate
2053 /// to the sentinel expression.
2054 /// The Decl is determined contextually.
2055 node_offset_slice_ptr: i32,
2056 /// The source location points to start expression of a slice expression
2057 /// expression, found by taking this AST node index offset from the containing
2058 /// Decl AST node, which points to a slice AST node. Next, navigate
2059 /// to the sentinel expression.
2060 /// The Decl is determined contextually.
2061 node_offset_slice_start: i32,
2062 /// The source location points to the end expression of a slice
2063 /// expression, found by taking this AST node index offset from the containing
2064 /// Decl AST node, which points to a slice AST node. Next, navigate
2065 /// to the sentinel expression.
2066 /// The Decl is determined contextually.
2067 node_offset_slice_end: i32,
2068 /// The source location points to the sentinel expression of a slice
2069 /// expression, found by taking this AST node index offset from the containing
2070 /// Decl AST node, which points to a slice AST node. Next, navigate
2071 /// to the sentinel expression.
2072 /// The Decl is determined contextually.
2073 node_offset_slice_sentinel: i32,
2074 /// The source location points to the callee expression of a function
2075 /// call expression, found by taking this AST node index offset from the containing
2076 /// Decl AST node, which points to a function call AST node. Next, navigate
2077 /// to the callee expression.
2078 /// The Decl is determined contextually.
2079 node_offset_call_func: i32,
2080 /// The payload is offset from the containing Decl AST node.
2081 /// The source location points to the field name of:
2082 /// * a field access expression (`a.b`), or
2083 /// * the callee of a method call (`a.b()`)
2084 /// The Decl is determined contextually.
2085 node_offset_field_name: i32,
2086 /// The payload is offset from the containing Decl AST node.
2087 /// The source location points to the field name of the operand ("b" node)
2088 /// of a field initialization expression (`.a = b`)
2089 /// The Decl is determined contextually.
2090 node_offset_field_name_init: i32,
2091 /// The source location points to the pointer of a pointer deref expression,
2092 /// found by taking this AST node index offset from the containing
2093 /// Decl AST node, which points to a pointer deref AST node. Next, navigate
2094 /// to the pointer expression.
2095 /// The Decl is determined contextually.
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 /// Decl AST node, which points to inline assembly AST node. Next, navigate
2100 /// to the asm template source code.
2101 /// The Decl is determined contextually.
2102 node_offset_asm_source: i32,
2103 /// The source location points to the return type of an inline assembly
2104 /// expression, found by taking this AST node index offset from the containing
2105 /// Decl AST node, which points to inline assembly AST node. Next, navigate
2106 /// to the return type expression.
2107 /// The Decl is determined contextually.
2108 node_offset_asm_ret_ty: i32,
2109 /// The source location points to the condition expression of an if
2110 /// expression, found by taking this AST node index offset from the containing
2111 /// Decl AST node, which points to an if expression AST node. Next, navigate
2112 /// to the condition expression.
2113 /// The Decl is determined contextually.
2114 node_offset_if_cond: i32,
2115 /// The source location points to a binary expression, such as `a + b`, found
2116 /// by taking this AST node index offset from the containing Decl AST node.
2117 /// The Decl is determined contextually.
2118 node_offset_bin_op: i32,
2119 /// The source location points to the LHS of a binary expression, found
2120 /// by taking this AST node index offset from the containing Decl AST node,
2121 /// which points to a binary expression AST node. Next, navigate to the LHS.
2122 /// The Decl is determined contextually.
2123 node_offset_bin_lhs: i32,
2124 /// The source location points to the RHS of a binary expression, found
2125 /// by taking this AST node index offset from the containing Decl AST node,
2126 /// which points to a binary expression AST node. Next, navigate to the RHS.
2127 /// The Decl is determined contextually.
2128 node_offset_bin_rhs: i32,
2129 /// The source location points to the operand of a switch expression, found
2130 /// by taking this AST node index offset from the containing Decl AST node,
2131 /// which points to a switch expression AST node. Next, navigate to the operand.
2132 /// The Decl is determined contextually.
2133 node_offset_switch_operand: i32,
2134 /// The source location points to the else/`_` prong of a switch expression, found
2135 /// by taking this AST node index offset from the containing Decl AST node,
2136 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
2137 /// The Decl is determined contextually.
2138 node_offset_switch_special_prong: i32,
2139 /// The source location points to all the ranges of a switch expression, found
2140 /// by taking this AST node index offset from the containing Decl AST node,
2141 /// which points to a switch expression AST node. Next, navigate to any of the
2142 /// range nodes. The error applies to all of them.
2143 /// The Decl is determined contextually.
2144 node_offset_switch_range: i32,
2145 /// The source location points to the capture of a switch_prong.
2146 /// The Decl is determined contextually.
2147 node_offset_switch_prong_capture: i32,
2148 /// The source location points to the tag capture of a switch_prong.
2149 /// The Decl is determined contextually.
2150 node_offset_switch_prong_tag_capture: i32,
2151 /// The source location points to the align expr of a function type
2152 /// expression, found by taking this AST node index offset from the containing
2153 /// Decl AST node, which points to a function type AST node. Next, navigate to
2154 /// the calling convention node.
2155 /// The Decl is determined contextually.
2156 node_offset_fn_type_align: i32,
2157 /// The source location points to the addrspace expr of a function type
2158 /// expression, found by taking this AST node index offset from the containing
2159 /// Decl AST node, which points to a function type AST node. Next, navigate to
2160 /// the calling convention node.
2161 /// The Decl is determined contextually.
2162 node_offset_fn_type_addrspace: i32,
2163 /// The source location points to the linksection expr of a function type
2164 /// expression, found by taking this AST node index offset from the containing
2165 /// Decl AST node, which points to a function type AST node. Next, navigate to
2166 /// the calling convention node.
2167 /// The Decl is determined contextually.
2168 node_offset_fn_type_section: i32,
2169 /// The source location points to the calling convention of a function type
2170 /// expression, found by taking this AST node index offset from the containing
2171 /// Decl AST node, which points to a function type AST node. Next, navigate to
2172 /// the calling convention node.
2173 /// The Decl is determined contextually.
2174 node_offset_fn_type_cc: i32,
2175 /// The source location points to the return type of a function type
2176 /// expression, found by taking this AST node index offset from the containing
2177 /// Decl AST node, which points to a function type AST node. Next, navigate to
2178 /// the return type node.
2179 /// The Decl is determined contextually.
2180 node_offset_fn_type_ret_ty: i32,
2181 node_offset_param: i32,
2182 token_offset_param: i32,
2183 /// The source location points to the type expression of an `anyframe->T`
2184 /// expression, found by taking this AST node index offset from the containing
2185 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
2186 /// to the type expression.
2187 /// The Decl is determined contextually.
2188 node_offset_anyframe_type: i32,
2189 /// The source location points to the string literal of `extern "foo"`, found
2190 /// by taking this AST node index offset from the containing
2191 /// Decl AST node, which points to a function prototype or variable declaration
2192 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
2193 /// The Decl is determined contextually.
2194 node_offset_lib_name: i32,
2195 /// The source location points to the len expression of an `[N:S]T`
2196 /// expression, found by taking this AST node index offset from the containing
2197 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2198 /// to the len expression.
2199 /// The Decl is determined contextually.
2200 node_offset_array_type_len: i32,
2201 /// The source location points to the sentinel expression of an `[N:S]T`
2202 /// expression, found by taking this AST node index offset from the containing
2203 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2204 /// to the sentinel expression.
2205 /// The Decl is determined contextually.
2206 node_offset_array_type_sentinel: i32,
2207 /// The source location points to the elem expression of an `[N:S]T`
2208 /// expression, found by taking this AST node index offset from the containing
2209 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2210 /// to the elem expression.
2211 /// The Decl is determined contextually.
2212 node_offset_array_type_elem: i32,
2213 /// The source location points to the operand of an unary expression.
2214 /// The Decl is determined contextually.
2215 node_offset_un_op: i32,
2216 /// The source location points to the elem type of a pointer.
2217 /// The Decl is determined contextually.
2218 node_offset_ptr_elem: i32,
2219 /// The source location points to the sentinel of a pointer.
2220 /// The Decl is determined contextually.
2221 node_offset_ptr_sentinel: i32,
2222 /// The source location points to the align expr of a pointer.
2223 /// The Decl is determined contextually.
2224 node_offset_ptr_align: i32,
2225 /// The source location points to the addrspace expr of a pointer.
2226 /// The Decl is determined contextually.
2227 node_offset_ptr_addrspace: i32,
2228 /// The source location points to the bit-offset of a pointer.
2229 /// The Decl is determined contextually.
2230 node_offset_ptr_bitoffset: i32,
2231 /// The source location points to the host size of a pointer.
2232 /// The Decl is determined contextually.
2233 node_offset_ptr_hostsize: i32,
2234 /// The source location points to the tag type of an union or an enum.
2235 /// The Decl is determined contextually.
2236 node_offset_container_tag: i32,
2237 /// The source location points to the default value of a field.
2238 /// The Decl is determined contextually.
2239 node_offset_field_default: i32,
2240 /// The source location points to the type of an array or struct initializer.
2241 /// The Decl is determined contextually.
2242 node_offset_init_ty: i32,
2243 /// The source location points to the LHS of an assignment.
2244 /// The Decl is determined contextually.
2245 node_offset_store_ptr: i32,
2246 /// The source location points to the RHS of an assignment.
2247 /// The Decl is determined contextually.
2248 node_offset_store_operand: i32,
2249 /// The source location points to the operand of a `return` statement, or
2250 /// the `return` itself if there is no explicit operand.
2251 /// The Decl is determined contextually.
2252 node_offset_return_operand: i32,
2253 /// The source location points to a for loop input.
2254 /// The Decl is determined contextually.
2255 for_input: struct {
2256 /// Points to the for loop AST node.
2257 for_node_offset: i32,
2258 /// Picks one of the inputs from the condition.
2259 input_index: u32,
2260 },
2261 /// The source location points to one of the captures of a for loop, found
2262 /// by taking this AST node index offset from the containing
2263 /// Decl AST node, which points to one of the input nodes of a for loop.
2264 /// Next, navigate to the corresponding capture.
2265 /// The Decl is determined contextually.
2266 for_capture_from_input: i32,
2267 /// The source location points to the argument node of a function call.
2268 call_arg: struct {
2269 decl: Decl.Index,
2270 /// Points to the function call AST node.
2271 call_node_offset: i32,
2272 /// The index of the argument the source location points to.
2273 arg_index: u32,
2274 },
2275 fn_proto_param: struct {
2276 decl: Decl.Index,
2277 /// Points to the function prototype AST node.
2278 fn_proto_node_offset: i32,
2279 /// The index of the parameter the source location points to.
2280 param_index: u32,
2281 },
2282 array_cat_lhs: ArrayCat,
2283 array_cat_rhs: ArrayCat,
2284
2285 const ArrayCat = struct {
2286 /// Points to the array concat AST node.
2287 array_cat_offset: i32,
2288 /// The index of the element the source location points to.
2289 elem_index: u32,
2290 };
2291
2292 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
2293
2294 noinline fn nodeOffsetDebug(node_offset: i32) LazySrcLoc {
2295 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
2296 result.node_offset.trace.addAddr(@returnAddress(), "init");
2297 return result;
2298 }
2299
2300 fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {
2301 return .{ .node_offset = .{ .x = node_offset } };
2302 }
2303
2304 /// Upgrade to a `SrcLoc` based on the `Decl` provided.
2305 pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl, mod: *Module) SrcLoc {
2306 return switch (lazy) {
2307 .unneeded,
2308 .entire_file,
2309 .byte_abs,
2310 .token_abs,
2311 .node_abs,
2312 => .{
2313 .file_scope = decl.getFileScope(mod),
2314 .parent_decl_node = 0,
2315 .lazy = lazy,
2316 },
2317
2318 .byte_offset,
2319 .token_offset,
2320 .node_offset,
2321 .node_offset_main_token,
2322 .node_offset_initializer,
2323 .node_offset_var_decl_ty,
2324 .node_offset_var_decl_align,
2325 .node_offset_var_decl_section,
2326 .node_offset_var_decl_addrspace,
2327 .node_offset_var_decl_init,
2328 .node_offset_builtin_call_arg0,
2329 .node_offset_builtin_call_arg1,
2330 .node_offset_builtin_call_arg2,
2331 .node_offset_builtin_call_arg3,
2332 .node_offset_builtin_call_arg4,
2333 .node_offset_builtin_call_arg5,
2334 .node_offset_ptrcast_operand,
2335 .node_offset_array_access_index,
2336 .node_offset_slice_ptr,
2337 .node_offset_slice_start,
2338 .node_offset_slice_end,
2339 .node_offset_slice_sentinel,
2340 .node_offset_call_func,
2341 .node_offset_field_name,
2342 .node_offset_field_name_init,
2343 .node_offset_deref_ptr,
2344 .node_offset_asm_source,
2345 .node_offset_asm_ret_ty,
2346 .node_offset_if_cond,
2347 .node_offset_bin_op,
2348 .node_offset_bin_lhs,
2349 .node_offset_bin_rhs,
2350 .node_offset_switch_operand,
2351 .node_offset_switch_special_prong,
2352 .node_offset_switch_range,
2353 .node_offset_switch_prong_capture,
2354 .node_offset_switch_prong_tag_capture,
2355 .node_offset_fn_type_align,
2356 .node_offset_fn_type_addrspace,
2357 .node_offset_fn_type_section,
2358 .node_offset_fn_type_cc,
2359 .node_offset_fn_type_ret_ty,
2360 .node_offset_param,
2361 .token_offset_param,
2362 .node_offset_anyframe_type,
2363 .node_offset_lib_name,
2364 .node_offset_array_type_len,
2365 .node_offset_array_type_sentinel,
2366 .node_offset_array_type_elem,
2367 .node_offset_un_op,
2368 .node_offset_ptr_elem,
2369 .node_offset_ptr_sentinel,
2370 .node_offset_ptr_align,
2371 .node_offset_ptr_addrspace,
2372 .node_offset_ptr_bitoffset,
2373 .node_offset_ptr_hostsize,
2374 .node_offset_container_tag,
2375 .node_offset_field_default,
2376 .node_offset_init_ty,
2377 .node_offset_store_ptr,
2378 .node_offset_store_operand,
2379 .node_offset_return_operand,
2380 .for_input,
2381 .for_capture_from_input,
2382 .array_cat_lhs,
2383 .array_cat_rhs,
2384 => .{
2385 .file_scope = decl.getFileScope(mod),
2386 .parent_decl_node = decl.src_node,
2387 .lazy = lazy,
2388 },
2389 inline .call_arg,
2390 .fn_proto_param,
2391 => |x| .{
2392 .file_scope = decl.getFileScope(mod),
2393 .parent_decl_node = mod.declPtr(x.decl).src_node,
2394 .lazy = lazy,
2395 },
2396 };
2397 }
2398};
2399
2400pub const SemaError = error{ OutOfMemory, AnalysisFail };2050pub const SemaError = error{ OutOfMemory, AnalysisFail };
2401pub const CompileError = error{2051pub const CompileError = error{
2402 OutOfMemory,2052 OutOfMemory,
src/Sema.zig+39-39
...@@ -156,7 +156,7 @@ const CompileError = Module.CompileError;...@@ -156,7 +156,7 @@ const CompileError = Module.CompileError;
156const SemaError = Module.SemaError;156const SemaError = Module.SemaError;
157const Decl = Module.Decl;157const Decl = Module.Decl;
158const CaptureScope = Module.CaptureScope;158const CaptureScope = Module.CaptureScope;
159const LazySrcLoc = Module.LazySrcLoc;159const LazySrcLoc = std.zig.LazySrcLoc;
160const RangeSet = @import("RangeSet.zig");160const RangeSet = @import("RangeSet.zig");
161const target_util = @import("target.zig");161const target_util = @import("target.zig");
162const Package = @import("Package.zig");162const Package = @import("Package.zig");
...@@ -397,7 +397,7 @@ pub const Block = struct {...@@ -397,7 +397,7 @@ pub const Block = struct {
397 break :blk src_loc;397 break :blk src_loc;
398 } else blk: {398 } else blk: {
399 const src_decl = mod.declPtr(rt.block.src_decl);399 const src_decl = mod.declPtr(rt.block.src_decl);
400 break :blk rt.func_src.toSrcLoc(src_decl, mod);400 break :blk src_decl.toSrcLoc(rt.func_src, mod);
401 };401 };
402 if (rt.return_ty.isGenericPoison()) {402 if (rt.return_ty.isGenericPoison()) {
403 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});403 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
...@@ -2421,7 +2421,7 @@ fn errNote(...@@ -2421,7 +2421,7 @@ fn errNote(
2421) error{OutOfMemory}!void {2421) error{OutOfMemory}!void {
2422 const mod = sema.mod;2422 const mod = sema.mod;
2423 const src_decl = mod.declPtr(block.src_decl);2423 const src_decl = mod.declPtr(block.src_decl);
2424 return mod.errNoteNonLazy(src.toSrcLoc(src_decl, mod), parent, format, args);2424 return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args);
2425}2425}
24262426
2427fn addFieldErrNote(2427fn addFieldErrNote(
...@@ -2478,7 +2478,7 @@ fn errMsg(...@@ -2478,7 +2478,7 @@ fn errMsg(
2478 const mod = sema.mod;2478 const mod = sema.mod;
2479 if (src == .unneeded) return error.NeededSourceLocation;2479 if (src == .unneeded) return error.NeededSourceLocation;
2480 const src_decl = mod.declPtr(block.src_decl);2480 const src_decl = mod.declPtr(block.src_decl);
2481 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(src_decl, mod), format, args);2481 return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args);
2482}2482}
24832483
2484pub fn fail(2484pub fn fail(
...@@ -2556,7 +2556,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg)...@@ -2556,7 +2556,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg)
2556 const decl = mod.declPtr(ref.referencer);2556 const decl = mod.declPtr(ref.referencer);
2557 try reference_stack.append(.{2557 try reference_stack.append(.{
2558 .decl = decl.name,2558 .decl = decl.name,
2559 .src_loc = ref.src.toSrcLoc(decl, mod),2559 .src_loc = decl.toSrcLoc(ref.src, mod),
2560 });2560 });
2561 }2561 }
2562 referenced_by = ref.referencer;2562 referenced_by = ref.referencer;
...@@ -2599,7 +2599,7 @@ fn reparentOwnedErrorMsg(...@@ -2599,7 +2599,7 @@ fn reparentOwnedErrorMsg(
2599) !void {2599) !void {
2600 const mod = sema.mod;2600 const mod = sema.mod;
2601 const src_decl = mod.declPtr(block.src_decl);2601 const src_decl = mod.declPtr(block.src_decl);
2602 const resolved_src = src.toSrcLoc(src_decl, mod);2602 const resolved_src = src_decl.toSrcLoc(src, mod);
2603 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);2603 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
26042604
2605 const orig_notes = msg.notes.len;2605 const orig_notes = msg.notes.len;
...@@ -5252,7 +5252,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -5252,7 +5252,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
5252 errdefer msg.destroy(sema.gpa);5252 errdefer msg.destroy(sema.gpa);
52535253
5254 const src_decl = mod.declPtr(block.src_decl);5254 const src_decl = mod.declPtr(block.src_decl);
5255 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);5255 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty);
5256 break :msg msg;5256 break :msg msg;
5257 };5257 };
5258 return sema.failWithOwnedErrorMsg(block, msg);5258 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5716,7 +5716,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5716,7 +5716,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5716 var child_block = parent_block.makeSubBlock();5716 var child_block = parent_block.makeSubBlock();
5717 child_block.label = &label;5717 child_block.label = &label;
5718 child_block.runtime_cond = null;5718 child_block.runtime_cond = null;
5719 child_block.runtime_loop = src.toSrcLoc(mod.declPtr(child_block.src_decl), mod);5719 child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod);
5720 child_block.runtime_index.increment();5720 child_block.runtime_index.increment();
5721 const merges = &child_block.label.?.merges;5721 const merges = &child_block.label.?.merges;
57225722
...@@ -6058,7 +6058,7 @@ fn analyzeBlockBody(...@@ -6058,7 +6058,7 @@ fn analyzeBlockBody(
6058 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});6058 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
60596059
6060 const child_src_decl = mod.declPtr(child_block.src_decl);6060 const child_src_decl = mod.declPtr(child_block.src_decl);
6061 try sema.explainWhyTypeIsComptime(msg, type_src.toSrcLoc(child_src_decl, mod), resolved_ty);6061 try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty);
60626062
6063 break :msg msg;6063 break :msg msg;
6064 };6064 };
...@@ -6213,7 +6213,7 @@ pub fn analyzeExport(...@@ -6213,7 +6213,7 @@ pub fn analyzeExport(
6213 errdefer msg.destroy(gpa);6213 errdefer msg.destroy(gpa);
62146214
6215 const src_decl = mod.declPtr(block.src_decl);6215 const src_decl = mod.declPtr(block.src_decl);
6216 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other);6216 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), exported_decl.ty, .other);
62176217
6218 try sema.addDeclaredHereNote(msg, exported_decl.ty);6218 try sema.addDeclaredHereNote(msg, exported_decl.ty);
6219 break :msg msg;6219 break :msg msg;
...@@ -8082,7 +8082,7 @@ fn instantiateGenericCall(...@@ -8082,7 +8082,7 @@ fn instantiateGenericCall(
8082 };8082 };
8083 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});8083 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});
8084 const src_decl = mod.declPtr(block.src_decl);8084 const src_decl = mod.declPtr(block.src_decl);
8085 try sema.explainWhyTypeIsComptime(msg, arg_src.toSrcLoc(src_decl, mod), arg_ty);8085 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty);
8086 break :msg msg;8086 break :msg msg;
8087 }),8087 }),
80888088
...@@ -9387,7 +9387,7 @@ fn funcCommon(...@@ -9387,7 +9387,7 @@ fn funcCommon(
9387 errdefer msg.destroy(sema.gpa);9387 errdefer msg.destroy(sema.gpa);
93889388
9389 const src_decl = mod.declPtr(block.src_decl);9389 const src_decl = mod.declPtr(block.src_decl);
9390 try sema.explainWhyTypeIsNotExtern(msg, param_src.toSrcLoc(src_decl, mod), param_ty, .param_ty);9390 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty);
93919391
9392 try sema.addDeclaredHereNote(msg, param_ty);9392 try sema.addDeclaredHereNote(msg, param_ty);
9393 break :msg msg;9393 break :msg msg;
...@@ -9402,7 +9402,7 @@ fn funcCommon(...@@ -9402,7 +9402,7 @@ fn funcCommon(
9402 errdefer msg.destroy(sema.gpa);9402 errdefer msg.destroy(sema.gpa);
94039403
9404 const src_decl = mod.declPtr(block.src_decl);9404 const src_decl = mod.declPtr(block.src_decl);
9405 try sema.explainWhyTypeIsComptime(msg, param_src.toSrcLoc(src_decl, mod), param_ty);9405 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty);
94069406
9407 try sema.addDeclaredHereNote(msg, param_ty);9407 try sema.addDeclaredHereNote(msg, param_ty);
9408 break :msg msg;9408 break :msg msg;
...@@ -9671,7 +9671,7 @@ fn finishFunc(...@@ -9671,7 +9671,7 @@ fn finishFunc(
9671 errdefer msg.destroy(gpa);9671 errdefer msg.destroy(gpa);
96729672
9673 const src_decl = mod.declPtr(block.src_decl);9673 const src_decl = mod.declPtr(block.src_decl);
9674 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty);9674 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty);
96759675
9676 try sema.addDeclaredHereNote(msg, return_type);9676 try sema.addDeclaredHereNote(msg, return_type);
9677 break :msg msg;9677 break :msg msg;
...@@ -9692,7 +9692,7 @@ fn finishFunc(...@@ -9692,7 +9692,7 @@ fn finishFunc(
9692 "function with comptime-only return type '{}' requires all parameters to be comptime",9692 "function with comptime-only return type '{}' requires all parameters to be comptime",
9693 .{return_type.fmt(mod)},9693 .{return_type.fmt(mod)},
9694 );9694 );
9695 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type);9695 try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type);
96969696
9697 const tags = sema.code.instructions.items(.tag);9697 const tags = sema.code.instructions.items(.tag);
9698 const data = sema.code.instructions.items(.data);9698 const data = sema.code.instructions.items(.data);
...@@ -9965,7 +9965,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -9965,7 +9965,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
9965 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(mod)});9965 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(mod)});
9966 errdefer msg.destroy(sema.gpa);9966 errdefer msg.destroy(sema.gpa);
9967 const src_decl = mod.declPtr(block.src_decl);9967 const src_decl = mod.declPtr(block.src_decl);
9968 try sema.explainWhyTypeIsComptime(msg, ptr_src.toSrcLoc(src_decl, mod), pointee_ty);9968 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, mod), pointee_ty);
9969 break :msg msg;9969 break :msg msg;
9970 };9970 };
9971 return sema.failWithOwnedErrorMsg(block, msg);9971 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -11492,7 +11492,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11492,7 +11492,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1149211492
11493 var sub_block = child_block.makeSubBlock();11493 var sub_block = child_block.makeSubBlock();
11494 sub_block.runtime_loop = null;11494 sub_block.runtime_loop = null;
11495 sub_block.runtime_cond = main_operand_src.toSrcLoc(mod.declPtr(child_block.src_decl), mod);11495 sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod);
11496 sub_block.runtime_index.increment();11496 sub_block.runtime_index.increment();
11497 defer sub_block.instructions.deinit(gpa);11497 defer sub_block.instructions.deinit(gpa);
1149811498
...@@ -12227,7 +12227,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12227,7 +12227,7 @@ fn analyzeSwitchRuntimeBlock(
1222712227
12228 var case_block = child_block.makeSubBlock();12228 var case_block = child_block.makeSubBlock();
12229 case_block.runtime_loop = null;12229 case_block.runtime_loop = null;
12230 case_block.runtime_cond = operand_src.toSrcLoc(mod.declPtr(child_block.src_decl), mod);12230 case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod);
12231 case_block.runtime_index.increment();12231 case_block.runtime_index.increment();
12232 defer case_block.instructions.deinit(gpa);12232 defer case_block.instructions.deinit(gpa);
1223312233
...@@ -13663,7 +13663,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13663,7 +13663,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13663 return sema.fail(block, operand_src, "file path name cannot be empty", .{});13663 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
13664 }13664 }
1366513665
13666 const src_loc = operand_src.toSrcLoc(mod.declPtr(block.src_decl), mod);13666 const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod);
13667 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {13667 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
13668 error.ImportOutsideModulePath => {13668 error.ImportOutsideModulePath => {
13669 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});13669 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
...@@ -18766,7 +18766,7 @@ fn zirBoolBr(...@@ -18766,7 +18766,7 @@ fn zirBoolBr(
1876618766
18767 var child_block = parent_block.makeSubBlock();18767 var child_block = parent_block.makeSubBlock();
18768 child_block.runtime_loop = null;18768 child_block.runtime_loop = null;
18769 child_block.runtime_cond = lhs_src.toSrcLoc(mod.declPtr(child_block.src_decl), mod);18769 child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod);
18770 child_block.runtime_index.increment();18770 child_block.runtime_index.increment();
18771 defer child_block.instructions.deinit(gpa);18771 defer child_block.instructions.deinit(gpa);
1877218772
...@@ -18963,7 +18963,7 @@ fn zirCondbr(...@@ -18963,7 +18963,7 @@ fn zirCondbr(
18963 // instructions array in between using it for the then block and else block.18963 // instructions array in between using it for the then block and else block.
18964 var sub_block = parent_block.makeSubBlock();18964 var sub_block = parent_block.makeSubBlock();
18965 sub_block.runtime_loop = null;18965 sub_block.runtime_loop = null;
18966 sub_block.runtime_cond = cond_src.toSrcLoc(mod.declPtr(parent_block.src_decl), mod);18966 sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod);
18967 sub_block.runtime_index.increment();18967 sub_block.runtime_index.increment();
18968 defer sub_block.instructions.deinit(gpa);18968 defer sub_block.instructions.deinit(gpa);
1896918969
...@@ -19503,7 +19503,7 @@ fn analyzeRet(...@@ -19503,7 +19503,7 @@ fn analyzeRet(
1950319503
19504 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {19504 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19505 const src_decl = mod.declPtr(block.src_decl);19505 const src_decl = mod.declPtr(block.src_decl);
19506 const src_loc = src.toSrcLoc(src_decl, mod);19506 const src_loc = src_decl.toSrcLoc(src, mod);
19507 try sema.comptime_err_ret_trace.append(src_loc);19507 try sema.comptime_err_ret_trace.append(src_loc);
19508 }19508 }
19509 return error.ComptimeReturn;19509 return error.ComptimeReturn;
...@@ -19660,7 +19660,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19660,7 +19660,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19660 errdefer msg.destroy(sema.gpa);19660 errdefer msg.destroy(sema.gpa);
1966119661
19662 const src_decl = mod.declPtr(block.src_decl);19662 const src_decl = mod.declPtr(block.src_decl);
19663 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other);19663 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other);
1966419664
19665 try sema.addDeclaredHereNote(msg, elem_ty);19665 try sema.addDeclaredHereNote(msg, elem_ty);
19666 break :msg msg;19666 break :msg msg;
...@@ -21128,7 +21128,7 @@ fn zirReify(...@@ -21128,7 +21128,7 @@ fn zirReify(
21128 errdefer msg.destroy(gpa);21128 errdefer msg.destroy(gpa);
2112921129
21130 const src_decl = mod.declPtr(block.src_decl);21130 const src_decl = mod.declPtr(block.src_decl);
21131 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), elem_ty, .other);21131 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other);
2113221132
21133 try sema.addDeclaredHereNote(msg, elem_ty);21133 try sema.addDeclaredHereNote(msg, elem_ty);
21134 break :msg msg;21134 break :msg msg;
...@@ -21572,7 +21572,7 @@ fn zirReify(...@@ -21572,7 +21572,7 @@ fn zirReify(
21572 errdefer msg.destroy(gpa);21572 errdefer msg.destroy(gpa);
2157321573
21574 const src_decl = mod.declPtr(block.src_decl);21574 const src_decl = mod.declPtr(block.src_decl);
21575 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .union_field);21575 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field);
2157621576
21577 try sema.addDeclaredHereNote(msg, field_ty);21577 try sema.addDeclaredHereNote(msg, field_ty);
21578 break :msg msg;21578 break :msg msg;
...@@ -21584,7 +21584,7 @@ fn zirReify(...@@ -21584,7 +21584,7 @@ fn zirReify(
21584 errdefer msg.destroy(gpa);21584 errdefer msg.destroy(gpa);
2158521585
21586 const src_decl = mod.declPtr(block.src_decl);21586 const src_decl = mod.declPtr(block.src_decl);
21587 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty);21587 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2158821588
21589 try sema.addDeclaredHereNote(msg, field_ty);21589 try sema.addDeclaredHereNote(msg, field_ty);
21590 break :msg msg;21590 break :msg msg;
...@@ -21939,7 +21939,7 @@ fn reifyStruct(...@@ -21939,7 +21939,7 @@ fn reifyStruct(
21939 errdefer msg.destroy(gpa);21939 errdefer msg.destroy(gpa);
2194021940
21941 const src_decl = sema.mod.declPtr(block.src_decl);21941 const src_decl = sema.mod.declPtr(block.src_decl);
21942 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .struct_field);21942 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field);
2194321943
21944 try sema.addDeclaredHereNote(msg, field_ty);21944 try sema.addDeclaredHereNote(msg, field_ty);
21945 break :msg msg;21945 break :msg msg;
...@@ -21951,7 +21951,7 @@ fn reifyStruct(...@@ -21951,7 +21951,7 @@ fn reifyStruct(
21951 errdefer msg.destroy(gpa);21951 errdefer msg.destroy(gpa);
2195221952
21953 const src_decl = sema.mod.declPtr(block.src_decl);21953 const src_decl = sema.mod.declPtr(block.src_decl);
21954 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty);21954 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2195521955
21956 try sema.addDeclaredHereNote(msg, field_ty);21956 try sema.addDeclaredHereNote(msg, field_ty);
21957 break :msg msg;21957 break :msg msg;
...@@ -22018,7 +22018,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -22018,7 +22018,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
22018 errdefer msg.destroy(sema.gpa);22018 errdefer msg.destroy(sema.gpa);
2201922019
22020 const src_decl = sema.mod.declPtr(block.src_decl);22020 const src_decl = sema.mod.declPtr(block.src_decl);
22021 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), arg_ty, .param_ty);22021 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty);
2202222022
22023 try sema.addDeclaredHereNote(msg, arg_ty);22023 try sema.addDeclaredHereNote(msg, arg_ty);
22024 break :msg msg;22024 break :msg msg;
...@@ -25859,7 +25859,7 @@ fn zirBuiltinExtern(...@@ -25859,7 +25859,7 @@ fn zirBuiltinExtern(
25859 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});25859 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
25860 errdefer msg.destroy(sema.gpa);25860 errdefer msg.destroy(sema.gpa);
25861 const src_decl = sema.mod.declPtr(block.src_decl);25861 const src_decl = sema.mod.declPtr(block.src_decl);
25862 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other);25862 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other);
25863 break :msg msg;25863 break :msg msg;
25864 };25864 };
25865 return sema.failWithOwnedErrorMsg(block, msg);25865 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -26003,7 +26003,7 @@ fn validateVarType(...@@ -26003,7 +26003,7 @@ fn validateVarType(
26003 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});26003 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
26004 errdefer msg.destroy(sema.gpa);26004 errdefer msg.destroy(sema.gpa);
26005 const src_decl = mod.declPtr(block.src_decl);26005 const src_decl = mod.declPtr(block.src_decl);
26006 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other);26006 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other);
26007 break :msg msg;26007 break :msg msg;
26008 };26008 };
26009 return sema.failWithOwnedErrorMsg(block, msg);26009 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -26026,7 +26026,7 @@ fn validateVarType(...@@ -26026,7 +26026,7 @@ fn validateVarType(
26026 errdefer msg.destroy(sema.gpa);26026 errdefer msg.destroy(sema.gpa);
2602726027
26028 const src_decl = mod.declPtr(block.src_decl);26028 const src_decl = mod.declPtr(block.src_decl);
26029 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), var_ty);26029 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty);
26030 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {26030 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26031 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});26031 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
26032 }26032 }
...@@ -28093,7 +28093,7 @@ fn validateRuntimeElemAccess(...@@ -28093,7 +28093,7 @@ fn validateRuntimeElemAccess(
28093 errdefer msg.destroy(sema.gpa);28093 errdefer msg.destroy(sema.gpa);
2809428094
28095 const src_decl = mod.declPtr(block.src_decl);28095 const src_decl = mod.declPtr(block.src_decl);
28096 try sema.explainWhyTypeIsComptime(msg, parent_src.toSrcLoc(src_decl, mod), parent_ty);28096 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty);
2809728097
28098 break :msg msg;28098 break :msg msg;
28099 };28099 };
...@@ -28492,7 +28492,7 @@ const CoerceOpts = struct {...@@ -28492,7 +28492,7 @@ const CoerceOpts = struct {
28492 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),28492 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
28493 };28493 };
28494 }28494 }
28495 return param_src.toSrcLoc(fn_decl, mod);28495 return fn_decl.toSrcLoc(param_src, mod);
28496 }28496 }
28497 } = .{},28497 } = .{},
28498};28498};
...@@ -29110,7 +29110,7 @@ fn coerceExtra(...@@ -29110,7 +29110,7 @@ fn coerceExtra(
2911029110
29111 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29111 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29112 const src_decl = mod.funcOwnerDeclPtr(sema.func_index);29112 const src_decl = mod.funcOwnerDeclPtr(sema.func_index);
29113 try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{});29113 try mod.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, mod), msg, "'noreturn' declared here", .{});
29114 break :msg msg;29114 break :msg msg;
29115 };29115 };
29116 return sema.failWithOwnedErrorMsg(block, msg);29116 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -29145,9 +29145,9 @@ fn coerceExtra(...@@ -29145,9 +29145,9 @@ fn coerceExtra(
29145 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29145 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29146 const src_decl = mod.funcOwnerDeclPtr(sema.func_index);29146 const src_decl = mod.funcOwnerDeclPtr(sema.func_index);
29147 if (inst_ty.isError(mod) and !dest_ty.isError(mod)) {29147 if (inst_ty.isError(mod) and !dest_ty.isError(mod)) {
29148 try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function cannot return an error", .{});29148 try mod.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, mod), msg, "function cannot return an error", .{});
29149 } else {29149 } else {
29150 try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function return type declared here", .{});29150 try mod.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, mod), msg, "function return type declared here", .{});
29151 }29151 }
29152 }29152 }
2915329153
...@@ -30165,7 +30165,7 @@ fn coerceVarArgParam(...@@ -30165,7 +30165,7 @@ fn coerceVarArgParam(
30165 errdefer msg.destroy(sema.gpa);30165 errdefer msg.destroy(sema.gpa);
3016630166
30167 const src_decl = sema.mod.declPtr(block.src_decl);30167 const src_decl = sema.mod.declPtr(block.src_decl);
30168 try sema.explainWhyTypeIsNotExtern(msg, inst_src.toSrcLoc(src_decl, mod), coerced_ty, .param_ty);30168 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty);
3016930169
30170 try sema.addDeclaredHereNote(msg, coerced_ty);30170 try sema.addDeclaredHereNote(msg, coerced_ty);
30171 break :msg msg;30171 break :msg msg;
...@@ -37180,7 +37180,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un...@@ -37180,7 +37180,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
37180 });37180 });
37181 errdefer msg.destroy(sema.gpa);37181 errdefer msg.destroy(sema.gpa);
37182 const decl_ptr = mod.declPtr(tag_info.decl);37182 const decl_ptr = mod.declPtr(tag_info.decl);
37183 try mod.errNoteNonLazy(enum_field_src.toSrcLoc(decl_ptr, mod), msg, "enum field here", .{});37183 try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{});
37184 break :msg msg;37184 break :msg msg;
37185 };37185 };
37186 return sema.failWithOwnedErrorMsg(&block_scope, msg);37186 return sema.failWithOwnedErrorMsg(&block_scope, msg);
src/Zir.zig+1-1
...@@ -22,7 +22,7 @@ const Ast = std.zig.Ast;...@@ -22,7 +22,7 @@ const Ast = std.zig.Ast;
22const InternPool = @import("InternPool.zig");22const InternPool = @import("InternPool.zig");
23const Zir = @This();23const Zir = @This();
24const Module = @import("Module.zig");24const Module = @import("Module.zig");
25const LazySrcLoc = Module.LazySrcLoc;25const LazySrcLoc = std.zig.LazySrcLoc;
2626
27instructions: std.MultiArrayList(Inst).Slice,27instructions: std.MultiArrayList(Inst).Slice,
28/// In order to store references to strings in fewer bytes, we copy all28/// In order to store references to strings in fewer bytes, we copy all
src/arch/wasm/CodeGen.zig+2-3
...@@ -16,7 +16,7 @@ const Decl = Module.Decl;...@@ -16,7 +16,7 @@ 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 = Module.LazySrcLoc;19const LazySrcLoc = std.zig.LazySrcLoc;
20const link = @import("../../link.zig");20const link = @import("../../link.zig");
21const TypedValue = @import("../../TypedValue.zig");21const TypedValue = @import("../../TypedValue.zig");
22const Air = @import("../../Air.zig");22const Air = @import("../../Air.zig");
...@@ -767,8 +767,7 @@ pub fn deinit(func: *CodeGen) void {...@@ -767,8 +767,7 @@ pub fn deinit(func: *CodeGen) void {
767/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig767/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
768fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {768fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
769 const mod = func.bin_file.base.comp.module.?;769 const mod = func.bin_file.base.comp.module.?;
770 const src = LazySrcLoc.nodeOffset(0);770 const src_loc = func.decl.srcLoc(mod);
771 const src_loc = src.toSrcLoc(func.decl, mod);
772 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);771 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
773 return error.CodegenFail;772 return error.CodegenFail;
774}773}
src/codegen/c.zig+2-3
...@@ -13,7 +13,7 @@ const TypedValue = @import("../TypedValue.zig");...@@ -13,7 +13,7 @@ const TypedValue = @import("../TypedValue.zig");
13const C = link.File.C;13const C = link.File.C;
14const Decl = Module.Decl;14const Decl = Module.Decl;
15const trace = @import("../tracy.zig").trace;15const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = Module.LazySrcLoc;16const LazySrcLoc = std.zig.LazySrcLoc;
17const Air = @import("../Air.zig");17const Air = @import("../Air.zig");
18const Liveness = @import("../Liveness.zig");18const Liveness = @import("../Liveness.zig");
19const InternPool = @import("../InternPool.zig");19const InternPool = @import("../InternPool.zig");
...@@ -570,8 +570,7 @@ pub const DeclGen = struct {...@@ -570,8 +570,7 @@ pub const DeclGen = struct {
570 const mod = dg.module;570 const mod = dg.module;
571 const decl_index = dg.pass.decl;571 const decl_index = dg.pass.decl;
572 const decl = mod.declPtr(decl_index);572 const decl = mod.declPtr(decl_index);
573 const src = LazySrcLoc.nodeOffset(0);573 const src_loc = decl.srcLoc(mod);
574 const src_loc = src.toSrcLoc(decl, mod);
575 dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args);574 dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args);
576 return error.AnalysisFail;575 return error.AnalysisFail;
577 }576 }
src/codegen/llvm.zig+2-2
...@@ -23,7 +23,7 @@ const Air = @import("../Air.zig");...@@ -23,7 +23,7 @@ const Air = @import("../Air.zig");
23const Liveness = @import("../Liveness.zig");23const Liveness = @import("../Liveness.zig");
24const Value = @import("../Value.zig");24const Value = @import("../Value.zig");
25const Type = @import("../type.zig").Type;25const Type = @import("../type.zig").Type;
26const LazySrcLoc = Module.LazySrcLoc;26const LazySrcLoc = std.zig.LazySrcLoc;
27const x86_64_abi = @import("../arch/x86_64/abi.zig");27const x86_64_abi = @import("../arch/x86_64/abi.zig");
28const wasm_c_abi = @import("../arch/wasm/abi.zig");28const wasm_c_abi = @import("../arch/wasm/abi.zig");
29const aarch64_c_abi = @import("../arch/aarch64/abi.zig");29const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
...@@ -4686,7 +4686,7 @@ pub const DeclGen = struct {...@@ -4686,7 +4686,7 @@ pub const DeclGen = struct {
4686 const o = dg.object;4686 const o = dg.object;
4687 const gpa = o.gpa;4687 const gpa = o.gpa;
4688 const mod = o.module;4688 const mod = o.module;
4689 const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(dg.decl, mod);4689 const src_loc = dg.decl.srcLoc(mod);
4690 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);4690 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
4691 return error.CodegenFail;4691 return error.CodegenFail;
4692 }4692 }
src/codegen/spirv.zig+3-5
...@@ -8,7 +8,7 @@ const Module = @import("../Module.zig");...@@ -8,7 +8,7 @@ const Module = @import("../Module.zig");
8const Decl = Module.Decl;8const Decl = Module.Decl;
9const Type = @import("../type.zig").Type;9const Type = @import("../type.zig").Type;
10const Value = @import("../Value.zig");10const Value = @import("../Value.zig");
11const LazySrcLoc = Module.LazySrcLoc;11const LazySrcLoc = std.zig.LazySrcLoc;
12const Air = @import("../Air.zig");12const Air = @import("../Air.zig");
13const Zir = @import("../Zir.zig");13const Zir = @import("../Zir.zig");
14const Liveness = @import("../Liveness.zig");14const Liveness = @import("../Liveness.zig");
...@@ -413,8 +413,7 @@ const DeclGen = struct {...@@ -413,8 +413,7 @@ const DeclGen = struct {
413 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 {
414 @setCold(true);414 @setCold(true);
415 const mod = self.module;415 const mod = self.module;
416 const src = LazySrcLoc.nodeOffset(0);416 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
417 const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index), 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;
...@@ -5270,8 +5269,7 @@ const DeclGen = struct {...@@ -5270,8 +5269,7 @@ const DeclGen = struct {
5270 // TODO: Translate proper error locations.5269 // TODO: Translate proper error locations.
5271 assert(as.errors.items.len != 0);5270 assert(as.errors.items.len != 0);
5272 assert(self.error_msg == null);5271 assert(self.error_msg == null);
5273 const loc = LazySrcLoc.nodeOffset(0);5272 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
5274 const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index), mod);
5275 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});5273 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
5276 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);5274 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);
52775275
src/print_zir.zig+1-1
...@@ -7,7 +7,7 @@ const InternPool = @import("InternPool.zig");...@@ -7,7 +7,7 @@ const InternPool = @import("InternPool.zig");
77
8const Zir = @import("Zir.zig");8const Zir = @import("Zir.zig");
9const Module = @import("Module.zig");9const Module = @import("Module.zig");
10const LazySrcLoc = Module.LazySrcLoc;10const LazySrcLoc = std.zig.LazySrcLoc;
1111
12/// Write human-readable, debug formatted ZIR code to a file.12/// Write human-readable, debug formatted ZIR code to a file.
13pub fn renderAsTextToFile(13pub fn renderAsTextToFile(