Skip to content

Commit 4496a8f

Browse files
Replace arena parameter with analyser in getAllTypesWithHandles
1 parent 85e33ee commit 4496a8f

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/analysis.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,18 +3683,19 @@ pub const Type = struct {
36833683

36843684
/// Resolves possible types of a type (single for all except either)
36853685
/// Drops duplicates
3686-
pub fn getAllTypesWithHandles(ty: Type, arena: std.mem.Allocator) error{OutOfMemory}![]const Type {
3686+
pub fn getAllTypesWithHandles(ty: Type, analyser: *Analyser) error{OutOfMemory}![]const Type {
36873687
var all_types: ArraySet = .empty;
3688-
try ty.getAllTypesWithHandlesArraySet(arena, &all_types);
3688+
try ty.getAllTypesWithHandlesArraySet(analyser, &all_types);
36893689
return all_types.keys();
36903690
}
36913691

3692-
pub fn getAllTypesWithHandlesArraySet(ty: Type, arena: std.mem.Allocator, all_types: *ArraySet) !void {
3692+
pub fn getAllTypesWithHandlesArraySet(ty: Type, analyser: *Analyser, all_types: *ArraySet) !void {
3693+
const arena = analyser.arena;
36933694
switch (ty.data) {
36943695
.either => |entries| {
36953696
for (entries) |entry| {
36963697
const entry_ty: Type = .{ .data = entry.type_data, .is_type_val = ty.is_type_val };
3697-
try entry_ty.getAllTypesWithHandlesArraySet(arena, all_types);
3698+
try entry_ty.getAllTypesWithHandlesArraySet(analyser, all_types);
36983699
}
36993700
},
37003701
else => try all_types.put(arena, ty, {}),
@@ -6103,7 +6104,7 @@ pub fn getSymbolFieldAccesses(
61036104
if (try analyser.getFieldAccessType(handle, source_index, held_loc)) |ty| {
61046105
const container_handle = try analyser.resolveDerefType(ty) orelse ty;
61056106

6106-
const container_handle_nodes = try container_handle.getAllTypesWithHandles(arena);
6107+
const container_handle_nodes = try container_handle.getAllTypesWithHandles(analyser);
61076108

61086109
for (container_handle_nodes) |t| {
61096110
try decls_with_handles.append(arena, (try t.lookupSymbol(analyser, name)) orelse continue);

src/features/completions.zig

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ fn collectContainerNodes(
15131513
.identifier_token_index => |token| token,
15141514
.expr_node_index => |node| {
15151515
if (try builder.analyser.resolveTypeOfNode(.of(node, handle))) |ty| {
1516-
try ty.getAllTypesWithHandlesArraySet(builder.arena, &types_with_handles);
1516+
try ty.getAllTypesWithHandlesArraySet(builder.analyser, &types_with_handles);
15171517
}
15181518
return types_with_handles.keys();
15191519
},
@@ -1533,7 +1533,7 @@ fn collectContainerNodes(
15331533
const var_decl = handle.tree.fullVarDecl(nodes[1]).?;
15341534
if (nodes[0].toOptional() == var_decl.ast.type_node) {
15351535
if (try builder.analyser.resolveTypeOfNode(.of(nodes[0], handle))) |ty| {
1536-
try ty.getAllTypesWithHandlesArraySet(builder.arena, &types_with_handles);
1536+
try ty.getAllTypesWithHandlesArraySet(builder.analyser, &types_with_handles);
15371537
return types_with_handles.keys();
15381538
}
15391539
}
@@ -1579,7 +1579,7 @@ fn collectBuiltinContainerNodes(
15791579
dot_context.fn_arg_index,
15801580
handle.tree.source[loc.start..loc.end],
15811581
)) |ty| {
1582-
try ty.getAllTypesWithHandlesArraySet(builder.arena, types_with_handles);
1582+
try ty.getAllTypesWithHandlesArraySet(builder.analyser, types_with_handles);
15831583
}
15841584
}
15851585

@@ -1591,13 +1591,12 @@ fn collectVarAccessContainerNodes(
15911591
types_with_handles: *Analyser.Type.ArraySet,
15921592
) error{OutOfMemory}!void {
15931593
const analyser = builder.analyser;
1594-
const arena = builder.arena;
15951594

15961595
const symbol_decl = try analyser.lookupSymbolGlobal(handle, handle.tree.source[loc.start..loc.end], loc.end) orelse return;
15971596
const result = try symbol_decl.resolveType(analyser) orelse return;
15981597
const type_expr = try analyser.resolveDerefType(result) orelse result;
15991598
if (!type_expr.isFunc()) {
1600-
try type_expr.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1599+
try type_expr.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16011600
return;
16021601
}
16031602

@@ -1606,13 +1605,13 @@ fn collectVarAccessContainerNodes(
16061605
if (dot_context.likely == .enum_comparison or dot_context.need_ret_type) { // => we need f()'s return type
16071606
var node_type = try analyser.resolveReturnType(type_expr) orelse return;
16081607
if (try analyser.resolveUnwrapErrorUnionType(node_type, .payload)) |unwrapped| node_type = unwrapped;
1609-
try node_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1608+
try node_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16101609
return;
16111610
}
16121611
const param_index = dot_context.fn_arg_index;
16131612
if (param_index >= info.parameters.len) return;
16141613
const param_type = info.parameters[param_index].type;
1615-
try param_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1614+
try param_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16161615
}
16171616

16181617
fn collectFieldAccessContainerNodes(
@@ -1634,12 +1633,12 @@ fn collectFieldAccessContainerNodes(
16341633
const container = try analyser.resolveDerefType(result) orelse result;
16351634
if (try analyser.resolveUnwrapErrorUnionType(container, .payload)) |unwrapped| {
16361635
if (unwrapped.isEnumType() or unwrapped.isUnionType()) {
1637-
try unwrapped.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1636+
try unwrapped.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16381637
return;
16391638
}
16401639
}
16411640
// if (dot_context.likely == .enum_literal and !(container.isEnumType() or container.isUnionType())) return;
1642-
try container.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1641+
try container.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16431642
return;
16441643
};
16451644
const name = offsets.locToSlice(handle.tree.source, name_loc);
@@ -1651,7 +1650,7 @@ fn collectFieldAccessContainerNodes(
16511650
if (try analyser.resolveOptionalUnwrap(node_type)) |unwrapped| node_type = unwrapped;
16521651
}
16531652
if (!node_type.isFunc()) {
1654-
try node_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1653+
try node_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16551654
continue;
16561655
}
16571656

@@ -1660,7 +1659,7 @@ fn collectFieldAccessContainerNodes(
16601659
if (dot_context.need_ret_type) { // => we need f()'s return type
16611660
node_type = try analyser.resolveReturnType(node_type) orelse continue;
16621661
if (try analyser.resolveUnwrapErrorUnionType(node_type, .payload)) |unwrapped| node_type = unwrapped;
1663-
try node_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1662+
try node_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16641663
continue;
16651664
}
16661665
// don't have the luxury of referencing an `Ast.full.Call`
@@ -1683,7 +1682,7 @@ fn collectFieldAccessContainerNodes(
16831682
const param_index = dot_context.fn_arg_index + additional_index;
16841683
if (param_index >= params.len) continue;
16851684
const param_type = params[param_index].type;
1686-
try param_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1685+
try param_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
16871686
}
16881687
}
16891688

@@ -1695,7 +1694,6 @@ fn collectEnumLiteralContainerNodes(
16951694
types_with_handles: *Analyser.Type.ArraySet,
16961695
) error{OutOfMemory}!void {
16971696
const analyser = builder.analyser;
1698-
const arena = builder.arena;
16991697
const alleged_field_name = offsets.locToSlice(handle.tree.source, offsets.identifierIndexToLoc(handle.tree.source, loc.start + 1, .name));
17001698
const dot_index = offsets.sourceIndexToTokenIndex(handle.tree, loc.start).pickPreferred(&.{.period}, &handle.tree) orelse return;
17011699
const el_dot_context = getSwitchOrStructInitContext(handle.tree, dot_index, nodes) orelse return;
@@ -1706,7 +1704,7 @@ fn collectEnumLiteralContainerNodes(
17061704
var member_type = try member_decl.resolveType(analyser) orelse continue;
17071705
// Unwrap `x{ .fld_w_opt_type =`
17081706
if (try analyser.resolveOptionalUnwrap(member_type)) |unwrapped| member_type = unwrapped;
1709-
try member_type.getAllTypesWithHandlesArraySet(arena, types_with_handles);
1707+
try member_type.getAllTypesWithHandlesArraySet(analyser, types_with_handles);
17101708
}
17111709
}
17121710

@@ -1730,5 +1728,5 @@ fn collectKeywordFnContainerNodes(
17301728
}
17311729
};
17321730
const ty = try builder.analyser.instanceStdBuiltinType(builtin_type_name) orelse return;
1733-
try ty.getAllTypesWithHandlesArraySet(builder.arena, types_with_handles);
1731+
try ty.getAllTypesWithHandlesArraySet(builder.analyser, types_with_handles);
17341732
}

0 commit comments

Comments
 (0)