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![
315315 return buffer.toOwnedSlice();
316316}
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
318691const std = @import("std.zig");
319692const tokenizer = @import("zig/tokenizer.zig");
320693const assert = std.debug.assert;
src/InternPool.zig+2-21
......@@ -383,27 +383,8 @@ pub const RuntimeIndex = enum(u32) {
383383 }
384384};
385385
386pub const DeclIndex = enum(u32) {
387 _,
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};
386pub const DeclIndex = std.zig.DeclIndex;
387pub const OptionalDeclIndex = std.zig.OptionalDeclIndex;
407388
408389pub const NamespaceIndex = enum(u32) {
409390 _,
src/Module.zig+96-446
......@@ -13,6 +13,7 @@ const BigIntConst = std.math.big.int.Const;
1313const BigIntMutable = std.math.big.int.Mutable;
1414const Target = std.Target;
1515const Ast = std.zig.Ast;
16const LazySrcLoc = std.zig.LazySrcLoc;
1617
1718/// Deprecated, use `Zcu`.
1819const Module = Zcu;
......@@ -664,6 +665,101 @@ pub const Decl = struct {
664665 if (decl.alignment != .none) return decl.alignment;
665666 return decl.ty.abiAlignment(zcu);
666667 }
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 }
667763};
668764
669765/// This state is attached to every Decl when Module emit_h is non-null.
......@@ -1951,452 +2047,6 @@ pub const SrcLoc = struct {
19512047 }
19522048};
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
24002050pub const SemaError = error{ OutOfMemory, AnalysisFail };
24012051pub const CompileError = error{
24022052 OutOfMemory,
src/Sema.zig+39-39
......@@ -156,7 +156,7 @@ const CompileError = Module.CompileError;
156156const SemaError = Module.SemaError;
157157const Decl = Module.Decl;
158158const CaptureScope = Module.CaptureScope;
159const LazySrcLoc = Module.LazySrcLoc;
159const LazySrcLoc = std.zig.LazySrcLoc;
160160const RangeSet = @import("RangeSet.zig");
161161const target_util = @import("target.zig");
162162const Package = @import("Package.zig");
......@@ -397,7 +397,7 @@ pub const Block = struct {
397397 break :blk src_loc;
398398 } else blk: {
399399 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);
401401 };
402402 if (rt.return_ty.isGenericPoison()) {
403403 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
......@@ -2421,7 +2421,7 @@ fn errNote(
24212421) error{OutOfMemory}!void {
24222422 const mod = sema.mod;
24232423 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);
24252425}
24262426
24272427fn addFieldErrNote(
......@@ -2478,7 +2478,7 @@ fn errMsg(
24782478 const mod = sema.mod;
24792479 if (src == .unneeded) return error.NeededSourceLocation;
24802480 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);
24822482}
24832483
24842484pub fn fail(
......@@ -2556,7 +2556,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg)
25562556 const decl = mod.declPtr(ref.referencer);
25572557 try reference_stack.append(.{
25582558 .decl = decl.name,
2559 .src_loc = ref.src.toSrcLoc(decl, mod),
2559 .src_loc = decl.toSrcLoc(ref.src, mod),
25602560 });
25612561 }
25622562 referenced_by = ref.referencer;
......@@ -2599,7 +2599,7 @@ fn reparentOwnedErrorMsg(
25992599) !void {
26002600 const mod = sema.mod;
26012601 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);
26032603 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
26042604
26052605 const orig_notes = msg.notes.len;
......@@ -5252,7 +5252,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
52525252 errdefer msg.destroy(sema.gpa);
52535253
52545254 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);
52565256 break :msg msg;
52575257 };
52585258 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5716,7 +5716,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
57165716 var child_block = parent_block.makeSubBlock();
57175717 child_block.label = &label;
57185718 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);
57205720 child_block.runtime_index.increment();
57215721 const merges = &child_block.label.?.merges;
57225722
......@@ -6058,7 +6058,7 @@ fn analyzeBlockBody(
60586058 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
60596059
60606060 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
60636063 break :msg msg;
60646064 };
......@@ -6213,7 +6213,7 @@ pub fn analyzeExport(
62136213 errdefer msg.destroy(gpa);
62146214
62156215 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
62186218 try sema.addDeclaredHereNote(msg, exported_decl.ty);
62196219 break :msg msg;
......@@ -8082,7 +8082,7 @@ fn instantiateGenericCall(
80828082 };
80838083 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});
80848084 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);
80868086 break :msg msg;
80878087 }),
80888088
......@@ -9387,7 +9387,7 @@ fn funcCommon(
93879387 errdefer msg.destroy(sema.gpa);
93889388
93899389 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
93929392 try sema.addDeclaredHereNote(msg, param_ty);
93939393 break :msg msg;
......@@ -9402,7 +9402,7 @@ fn funcCommon(
94029402 errdefer msg.destroy(sema.gpa);
94039403
94049404 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
94079407 try sema.addDeclaredHereNote(msg, param_ty);
94089408 break :msg msg;
......@@ -9671,7 +9671,7 @@ fn finishFunc(
96719671 errdefer msg.destroy(gpa);
96729672
96739673 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
96769676 try sema.addDeclaredHereNote(msg, return_type);
96779677 break :msg msg;
......@@ -9692,7 +9692,7 @@ fn finishFunc(
96929692 "function with comptime-only return type '{}' requires all parameters to be comptime",
96939693 .{return_type.fmt(mod)},
96949694 );
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
96979697 const tags = sema.code.instructions.items(.tag);
96989698 const data = sema.code.instructions.items(.data);
......@@ -9965,7 +9965,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
99659965 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(mod)});
99669966 errdefer msg.destroy(sema.gpa);
99679967 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);
99699969 break :msg msg;
99709970 };
99719971 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -11492,7 +11492,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1149211492
1149311493 var sub_block = child_block.makeSubBlock();
1149411494 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);
1149611496 sub_block.runtime_index.increment();
1149711497 defer sub_block.instructions.deinit(gpa);
1149811498
......@@ -12227,7 +12227,7 @@ fn analyzeSwitchRuntimeBlock(
1222712227
1222812228 var case_block = child_block.makeSubBlock();
1222912229 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);
1223112231 case_block.runtime_index.increment();
1223212232 defer case_block.instructions.deinit(gpa);
1223312233
......@@ -13663,7 +13663,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1366313663 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
1366413664 }
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);
1366713667 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
1366813668 error.ImportOutsideModulePath => {
1366913669 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
......@@ -18766,7 +18766,7 @@ fn zirBoolBr(
1876618766
1876718767 var child_block = parent_block.makeSubBlock();
1876818768 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);
1877018770 child_block.runtime_index.increment();
1877118771 defer child_block.instructions.deinit(gpa);
1877218772
......@@ -18963,7 +18963,7 @@ fn zirCondbr(
1896318963 // instructions array in between using it for the then block and else block.
1896418964 var sub_block = parent_block.makeSubBlock();
1896518965 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);
1896718967 sub_block.runtime_index.increment();
1896818968 defer sub_block.instructions.deinit(gpa);
1896918969
......@@ -19503,7 +19503,7 @@ fn analyzeRet(
1950319503
1950419504 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
1950519505 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);
1950719507 try sema.comptime_err_ret_trace.append(src_loc);
1950819508 }
1950919509 return error.ComptimeReturn;
......@@ -19660,7 +19660,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1966019660 errdefer msg.destroy(sema.gpa);
1966119661
1966219662 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
1966519665 try sema.addDeclaredHereNote(msg, elem_ty);
1966619666 break :msg msg;
......@@ -21128,7 +21128,7 @@ fn zirReify(
2112821128 errdefer msg.destroy(gpa);
2112921129
2113021130 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
2113321133 try sema.addDeclaredHereNote(msg, elem_ty);
2113421134 break :msg msg;
......@@ -21572,7 +21572,7 @@ fn zirReify(
2157221572 errdefer msg.destroy(gpa);
2157321573
2157421574 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
2157721577 try sema.addDeclaredHereNote(msg, field_ty);
2157821578 break :msg msg;
......@@ -21584,7 +21584,7 @@ fn zirReify(
2158421584 errdefer msg.destroy(gpa);
2158521585
2158621586 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
2158921589 try sema.addDeclaredHereNote(msg, field_ty);
2159021590 break :msg msg;
......@@ -21939,7 +21939,7 @@ fn reifyStruct(
2193921939 errdefer msg.destroy(gpa);
2194021940
2194121941 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
2194421944 try sema.addDeclaredHereNote(msg, field_ty);
2194521945 break :msg msg;
......@@ -21951,7 +21951,7 @@ fn reifyStruct(
2195121951 errdefer msg.destroy(gpa);
2195221952
2195321953 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
2195621956 try sema.addDeclaredHereNote(msg, field_ty);
2195721957 break :msg msg;
......@@ -22018,7 +22018,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2201822018 errdefer msg.destroy(sema.gpa);
2201922019
2202022020 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
2202322023 try sema.addDeclaredHereNote(msg, arg_ty);
2202422024 break :msg msg;
......@@ -25859,7 +25859,7 @@ fn zirBuiltinExtern(
2585925859 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
2586025860 errdefer msg.destroy(sema.gpa);
2586125861 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);
2586325863 break :msg msg;
2586425864 };
2586525865 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -26003,7 +26003,7 @@ fn validateVarType(
2600326003 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
2600426004 errdefer msg.destroy(sema.gpa);
2600526005 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);
2600726007 break :msg msg;
2600826008 };
2600926009 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -26026,7 +26026,7 @@ fn validateVarType(
2602626026 errdefer msg.destroy(sema.gpa);
2602726027
2602826028 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);
2603026030 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
2603126031 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2603226032 }
......@@ -28093,7 +28093,7 @@ fn validateRuntimeElemAccess(
2809328093 errdefer msg.destroy(sema.gpa);
2809428094
2809528095 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
2809828098 break :msg msg;
2809928099 };
......@@ -28492,7 +28492,7 @@ const CoerceOpts = struct {
2849228492 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
2849328493 };
2849428494 }
28495 return param_src.toSrcLoc(fn_decl, mod);
28495 return fn_decl.toSrcLoc(param_src, mod);
2849628496 }
2849728497 } = .{},
2849828498};
......@@ -29110,7 +29110,7 @@ fn coerceExtra(
2911029110
2911129111 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
2911229112 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", .{});
2911429114 break :msg msg;
2911529115 };
2911629116 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -29145,9 +29145,9 @@ fn coerceExtra(
2914529145 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
2914629146 const src_decl = mod.funcOwnerDeclPtr(sema.func_index);
2914729147 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", .{});
2914929149 } 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", .{});
2915129151 }
2915229152 }
2915329153
......@@ -30165,7 +30165,7 @@ fn coerceVarArgParam(
3016530165 errdefer msg.destroy(sema.gpa);
3016630166
3016730167 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
3017030170 try sema.addDeclaredHereNote(msg, coerced_ty);
3017130171 break :msg msg;
......@@ -37180,7 +37180,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3718037180 });
3718137181 errdefer msg.destroy(sema.gpa);
3718237182 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", .{});
3718437184 break :msg msg;
3718537185 };
3718637186 return sema.failWithOwnedErrorMsg(&block_scope, msg);
src/Zir.zig+1-1
......@@ -22,7 +22,7 @@ const Ast = std.zig.Ast;
2222const InternPool = @import("InternPool.zig");
2323const Zir = @This();
2424const Module = @import("Module.zig");
25const LazySrcLoc = Module.LazySrcLoc;
25const LazySrcLoc = std.zig.LazySrcLoc;
2626
2727instructions: std.MultiArrayList(Inst).Slice,
2828/// 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;
1616const Type = @import("../../type.zig").Type;
1717const Value = @import("../../Value.zig");
1818const Compilation = @import("../../Compilation.zig");
19const LazySrcLoc = Module.LazySrcLoc;
19const LazySrcLoc = std.zig.LazySrcLoc;
2020const link = @import("../../link.zig");
2121const TypedValue = @import("../../TypedValue.zig");
2222const Air = @import("../../Air.zig");
......@@ -767,8 +767,7 @@ pub fn deinit(func: *CodeGen) void {
767767/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
768768fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
769769 const mod = func.bin_file.base.comp.module.?;
770 const src = LazySrcLoc.nodeOffset(0);
771 const src_loc = src.toSrcLoc(func.decl, mod);
770 const src_loc = func.decl.srcLoc(mod);
772771 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
773772 return error.CodegenFail;
774773}
src/codegen/c.zig+2-3
......@@ -13,7 +13,7 @@ const TypedValue = @import("../TypedValue.zig");
1313const C = link.File.C;
1414const Decl = Module.Decl;
1515const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = Module.LazySrcLoc;
16const LazySrcLoc = std.zig.LazySrcLoc;
1717const Air = @import("../Air.zig");
1818const Liveness = @import("../Liveness.zig");
1919const InternPool = @import("../InternPool.zig");
......@@ -570,8 +570,7 @@ pub const DeclGen = struct {
570570 const mod = dg.module;
571571 const decl_index = dg.pass.decl;
572572 const decl = mod.declPtr(decl_index);
573 const src = LazySrcLoc.nodeOffset(0);
574 const src_loc = src.toSrcLoc(decl, mod);
573 const src_loc = decl.srcLoc(mod);
575574 dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args);
576575 return error.AnalysisFail;
577576 }
src/codegen/llvm.zig+2-2
......@@ -23,7 +23,7 @@ const Air = @import("../Air.zig");
2323const Liveness = @import("../Liveness.zig");
2424const Value = @import("../Value.zig");
2525const Type = @import("../type.zig").Type;
26const LazySrcLoc = Module.LazySrcLoc;
26const LazySrcLoc = std.zig.LazySrcLoc;
2727const x86_64_abi = @import("../arch/x86_64/abi.zig");
2828const wasm_c_abi = @import("../arch/wasm/abi.zig");
2929const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
......@@ -4686,7 +4686,7 @@ pub const DeclGen = struct {
46864686 const o = dg.object;
46874687 const gpa = o.gpa;
46884688 const mod = o.module;
4689 const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(dg.decl, mod);
4689 const src_loc = dg.decl.srcLoc(mod);
46904690 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
46914691 return error.CodegenFail;
46924692 }
src/codegen/spirv.zig+3-5
......@@ -8,7 +8,7 @@ const Module = @import("../Module.zig");
88const Decl = Module.Decl;
99const Type = @import("../type.zig").Type;
1010const Value = @import("../Value.zig");
11const LazySrcLoc = Module.LazySrcLoc;
11const LazySrcLoc = std.zig.LazySrcLoc;
1212const Air = @import("../Air.zig");
1313const Zir = @import("../Zir.zig");
1414const Liveness = @import("../Liveness.zig");
......@@ -413,8 +413,7 @@ const DeclGen = struct {
413413 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
414414 @setCold(true);
415415 const mod = self.module;
416 const src = LazySrcLoc.nodeOffset(0);
417 const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index), mod);
416 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
418417 assert(self.error_msg == null);
419418 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
420419 return error.CodegenFail;
......@@ -5270,8 +5269,7 @@ const DeclGen = struct {
52705269 // TODO: Translate proper error locations.
52715270 assert(as.errors.items.len != 0);
52725271 assert(self.error_msg == null);
5273 const loc = LazySrcLoc.nodeOffset(0);
5274 const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index), mod);
5272 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
52755273 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
52765274 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");
77
88const Zir = @import("Zir.zig");
99const Module = @import("Module.zig");
10const LazySrcLoc = Module.LazySrcLoc;
10const LazySrcLoc = std.zig.LazySrcLoc;
1111
1212/// Write human-readable, debug formatted ZIR code to a file.
1313pub fn renderAsTextToFile(