authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-19 16:56:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-21 21:38:41-04:00
logdd402f6d83071535fffac055fabe72ebcb0db994
tree4e3f74cec7d55c84c070a16dfd5b27502df969f9
parent5e1db5e47800a8e9bb1d8d11f07b0023bd8e49ef

AstGen: omit make_ptr_const for resolve_inferred_alloc

After the previous commit, these make_ptr_const ZIR instructions are redundant.

2 files changed, 9 insertions(+), 6 deletions(-)

src/AstGen.zig+6-4
...@@ -3123,10 +3123,10 @@ fn varDecl(...@@ -3123,10 +3123,10 @@ fn varDecl(
3123 if (nodeMayAppendToErrorTrace(tree, var_decl.ast.init_node))3123 if (nodeMayAppendToErrorTrace(tree, var_decl.ast.init_node))
3124 _ = try gz.addSaveErrRetIndex(.{ .if_of_error_type = init_inst });3124 _ = try gz.addSaveErrRetIndex(.{ .if_of_error_type = init_inst });
31253125
3126 if (resolve_inferred_alloc != .none) {3126 const const_ptr = if (resolve_inferred_alloc != .none) p: {
3127 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);3127 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
3128 }3128 break :p var_ptr;
3129 const const_ptr = try gz.addUnNode(.make_ptr_const, var_ptr, node);3129 } else try gz.addUnNode(.make_ptr_const, var_ptr, node);
31303130
3131 try gz.addDbgVar(.dbg_var_ptr, ident_name, const_ptr);3131 try gz.addDbgVar(.dbg_var_ptr, ident_name, const_ptr);
31323132
...@@ -3533,7 +3533,9 @@ fn assignDestructureMaybeDecls(...@@ -3533,7 +3533,9 @@ fn assignDestructureMaybeDecls(
3533 else => unreachable,3533 else => unreachable,
3534 };3534 };
3535 // If the alloc was const, make it const.3535 // If the alloc was const, make it const.
3536 const var_ptr = if (is_const) make_const: {3536 const var_ptr = if (is_const and full.ast.type_node != 0) make_const: {
3537 // Note that we don't do this if type_node == 0 since `resolve_inferred_alloc`
3538 // handles it for us.
3537 break :make_const try gz.addUnNode(.make_ptr_const, raw_ptr, node);3539 break :make_const try gz.addUnNode(.make_ptr_const, raw_ptr, node);
3538 } else raw_ptr;3540 } else raw_ptr;
3539 const name_token = full.ast.mut_token + 1;3541 const name_token = full.ast.mut_token + 1;
src/Zir.zig+3-2
...@@ -997,8 +997,9 @@ pub const Inst = struct {...@@ -997,8 +997,9 @@ pub const Inst = struct {
997 /// is the allocation that needs to have its type inferred.997 /// is the allocation that needs to have its type inferred.
998 /// Uses the `un_node` field. The AST node is the var decl.998 /// Uses the `un_node` field. The AST node is the var decl.
999 resolve_inferred_alloc,999 resolve_inferred_alloc,
1000 /// Turns a pointer coming from an `alloc`, `alloc_inferred`, `alloc_inferred_comptime` or1000 /// Turns a pointer coming from an `alloc` or `Extended.alloc` into a constant
1001 /// `Extended.alloc` into a constant version of the same pointer.1001 /// version of the same pointer. For inferred allocations this is instead implicitly
1002 /// handled by the `resolve_inferred_alloc` instruction.
1002 /// Uses the `un_node` union field.1003 /// Uses the `un_node` union field.
1003 make_ptr_const,1004 make_ptr_const,
10041005