commit dd402f6d83071535fffac055fabe72ebcb0db994 (tree)
parent 5e1db5e47800a8e9bb1d8d11f07b0023bd8e49ef
Author: mlugg <mlugg@mlugg.co.uk>
Date: Thu, 19 Oct 2023 16:56:20 -0700
AstGen: omit make_ptr_const for resolve_inferred_alloc
After the previous commit, these make_ptr_const ZIR instructions are
redundant.
Diffstat:
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/AstGen.zig b/src/AstGen.zig
@@ -3123,10 +3123,10 @@ fn varDecl(
if (nodeMayAppendToErrorTrace(tree, var_decl.ast.init_node))
_ = try gz.addSaveErrRetIndex(.{ .if_of_error_type = init_inst });
- if (resolve_inferred_alloc != .none) {
+ const const_ptr = if (resolve_inferred_alloc != .none) p: {
_ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
- }
- const const_ptr = try gz.addUnNode(.make_ptr_const, var_ptr, node);
+ break :p var_ptr;
+ } else try gz.addUnNode(.make_ptr_const, var_ptr, node);
try gz.addDbgVar(.dbg_var_ptr, ident_name, const_ptr);
@@ -3533,7 +3533,9 @@ fn assignDestructureMaybeDecls(
else => unreachable,
};
// If the alloc was const, make it const.
- const var_ptr = if (is_const) make_const: {
+ const var_ptr = if (is_const and full.ast.type_node != 0) make_const: {
+ // Note that we don't do this if type_node == 0 since `resolve_inferred_alloc`
+ // handles it for us.
break :make_const try gz.addUnNode(.make_ptr_const, raw_ptr, node);
} else raw_ptr;
const name_token = full.ast.mut_token + 1;
diff --git a/src/Zir.zig b/src/Zir.zig
@@ -997,8 +997,9 @@ pub const Inst = struct {
/// is the allocation that needs to have its type inferred.
/// Uses the `un_node` field. The AST node is the var decl.
resolve_inferred_alloc,
- /// Turns a pointer coming from an `alloc`, `alloc_inferred`, `alloc_inferred_comptime` or
- /// `Extended.alloc` into a constant version of the same pointer.
+ /// Turns a pointer coming from an `alloc` or `Extended.alloc` into a constant
+ /// version of the same pointer. For inferred allocations this is instead implicitly
+ /// handled by the `resolve_inferred_alloc` instruction.
/// Uses the `un_node` union field.
make_ptr_const,