Skip to content

Commit b59dec6

Browse files
committed
Use typed exposed item targets
1 parent d66ca78 commit b59dec6

15 files changed

Lines changed: 522 additions & 219 deletions

File tree

src/base/CommonEnv.zig

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,29 @@ pub fn addExposedById(self: *CommonEnv, gpa: std.mem.Allocator, ident_idx: Ident
197197
return try self.exposed_items.addExposedById(gpa, @bitCast(ident_idx));
198198
}
199199

200-
/// Retrieves the node index associated with an exposed identifier.
201-
pub fn getNodeIndexById(self: *const CommonEnv, allocator: std.mem.Allocator, ident_idx: Ident.Idx) ?u32 {
202-
return self.exposed_items.getNodeIndexById(allocator, @bitCast(ident_idx));
200+
/// Retrieves the explicit target associated with an exposed identifier.
201+
pub fn getExposedTargetById(self: *const CommonEnv, allocator: std.mem.Allocator, ident_idx: Ident.Idx) ?collections.ExposedItemTarget {
202+
return self.exposed_items.getTargetById(allocator, @bitCast(ident_idx));
203203
}
204204

205-
/// Associates a node index with an exposed identifier.
206-
pub fn setNodeIndexById(self: *CommonEnv, gpa: std.mem.Allocator, ident_idx: Ident.Idx, node_idx: u32) Allocator.Error!void {
207-
return try self.exposed_items.setNodeIndexById(gpa, @bitCast(ident_idx), node_idx);
205+
/// Retrieves the value definition node associated with an exposed identifier.
206+
pub fn getValueNodeIndexById(self: *const CommonEnv, allocator: std.mem.Allocator, ident_idx: Ident.Idx) ?u32 {
207+
return self.exposed_items.getValueNodeIndexById(allocator, @bitCast(ident_idx));
208+
}
209+
210+
/// Retrieves the type declaration node associated with an exposed identifier.
211+
pub fn getTypeNodeIndexById(self: *const CommonEnv, allocator: std.mem.Allocator, ident_idx: Ident.Idx) ?u32 {
212+
return self.exposed_items.getTypeNodeIndexById(allocator, @bitCast(ident_idx));
213+
}
214+
215+
/// Associates a value definition node index with an exposed identifier.
216+
pub fn setValueNodeIndexById(self: *CommonEnv, gpa: std.mem.Allocator, ident_idx: Ident.Idx, node_idx: u32) Allocator.Error!void {
217+
return try self.exposed_items.setValueNodeIndexById(gpa, @bitCast(ident_idx), node_idx);
218+
}
219+
220+
/// Associates a type declaration node index with an exposed identifier.
221+
pub fn setTypeNodeIndexById(self: *CommonEnv, gpa: std.mem.Allocator, ident_idx: Ident.Idx, node_idx: u32) Allocator.Error!void {
222+
return try self.exposed_items.setTypeNodeIndexById(gpa, @bitCast(ident_idx), node_idx);
208223
}
209224

210225
/// Get region info for a given region

src/build/builtin_compiler/main.zig

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,31 @@ fn expectBuiltinIdent(env: *const ModuleEnv, text: []const u8) base.Ident.Idx {
215215
}
216216

217217
fn installBuiltinNodeIndices(gpa: Allocator, env: *ModuleEnv, indices: BuiltinIndices) !void {
218-
try env.common.setNodeIndexById(gpa, indices.bool_ident, @intCast(@intFromEnum(indices.bool_type)));
219-
try env.common.setNodeIndexById(gpa, indices.try_ident, @intCast(@intFromEnum(indices.try_type)));
220-
try env.common.setNodeIndexById(gpa, indices.dict_ident, @intCast(@intFromEnum(indices.dict_type)));
221-
try env.common.setNodeIndexById(gpa, indices.set_ident, @intCast(@intFromEnum(indices.set_type)));
222-
try env.common.setNodeIndexById(gpa, indices.str_ident, @intCast(@intFromEnum(indices.str_type)));
223-
try env.common.setNodeIndexById(gpa, indices.hasher_ident, @intCast(@intFromEnum(indices.hasher_type)));
224-
try env.common.setNodeIndexById(gpa, indices.iter_ident, @intCast(@intFromEnum(indices.iter_type)));
225-
try env.common.setNodeIndexById(gpa, indices.stream_ident, @intCast(@intFromEnum(indices.stream_type)));
226-
try env.common.setNodeIndexById(gpa, indices.list_ident, @intCast(@intFromEnum(indices.list_type)));
227-
try env.common.setNodeIndexById(gpa, indices.box_ident, @intCast(@intFromEnum(indices.box_type)));
228-
try env.common.setNodeIndexById(gpa, indices.utf8_problem_ident, @intCast(@intFromEnum(indices.utf8_problem_type)));
229-
try env.common.setNodeIndexById(gpa, indices.u8_ident, @intCast(@intFromEnum(indices.u8_type)));
230-
try env.common.setNodeIndexById(gpa, indices.i8_ident, @intCast(@intFromEnum(indices.i8_type)));
231-
try env.common.setNodeIndexById(gpa, indices.u16_ident, @intCast(@intFromEnum(indices.u16_type)));
232-
try env.common.setNodeIndexById(gpa, indices.i16_ident, @intCast(@intFromEnum(indices.i16_type)));
233-
try env.common.setNodeIndexById(gpa, indices.u32_ident, @intCast(@intFromEnum(indices.u32_type)));
234-
try env.common.setNodeIndexById(gpa, indices.i32_ident, @intCast(@intFromEnum(indices.i32_type)));
235-
try env.common.setNodeIndexById(gpa, indices.u64_ident, @intCast(@intFromEnum(indices.u64_type)));
236-
try env.common.setNodeIndexById(gpa, indices.i64_ident, @intCast(@intFromEnum(indices.i64_type)));
237-
try env.common.setNodeIndexById(gpa, indices.u128_ident, @intCast(@intFromEnum(indices.u128_type)));
238-
try env.common.setNodeIndexById(gpa, indices.i128_ident, @intCast(@intFromEnum(indices.i128_type)));
239-
try env.common.setNodeIndexById(gpa, indices.dec_ident, @intCast(@intFromEnum(indices.dec_type)));
240-
try env.common.setNodeIndexById(gpa, indices.f32_ident, @intCast(@intFromEnum(indices.f32_type)));
241-
try env.common.setNodeIndexById(gpa, indices.f64_ident, @intCast(@intFromEnum(indices.f64_type)));
242-
try env.common.setNodeIndexById(gpa, indices.numeral_ident, @intCast(@intFromEnum(indices.numeral_type)));
218+
try env.common.setTypeNodeIndexById(gpa, indices.bool_ident, @intCast(@intFromEnum(indices.bool_type)));
219+
try env.common.setTypeNodeIndexById(gpa, indices.try_ident, @intCast(@intFromEnum(indices.try_type)));
220+
try env.common.setTypeNodeIndexById(gpa, indices.dict_ident, @intCast(@intFromEnum(indices.dict_type)));
221+
try env.common.setTypeNodeIndexById(gpa, indices.set_ident, @intCast(@intFromEnum(indices.set_type)));
222+
try env.common.setTypeNodeIndexById(gpa, indices.str_ident, @intCast(@intFromEnum(indices.str_type)));
223+
try env.common.setTypeNodeIndexById(gpa, indices.hasher_ident, @intCast(@intFromEnum(indices.hasher_type)));
224+
try env.common.setTypeNodeIndexById(gpa, indices.iter_ident, @intCast(@intFromEnum(indices.iter_type)));
225+
try env.common.setTypeNodeIndexById(gpa, indices.stream_ident, @intCast(@intFromEnum(indices.stream_type)));
226+
try env.common.setTypeNodeIndexById(gpa, indices.list_ident, @intCast(@intFromEnum(indices.list_type)));
227+
try env.common.setTypeNodeIndexById(gpa, indices.box_ident, @intCast(@intFromEnum(indices.box_type)));
228+
try env.common.setTypeNodeIndexById(gpa, indices.utf8_problem_ident, @intCast(@intFromEnum(indices.utf8_problem_type)));
229+
try env.common.setTypeNodeIndexById(gpa, indices.u8_ident, @intCast(@intFromEnum(indices.u8_type)));
230+
try env.common.setTypeNodeIndexById(gpa, indices.i8_ident, @intCast(@intFromEnum(indices.i8_type)));
231+
try env.common.setTypeNodeIndexById(gpa, indices.u16_ident, @intCast(@intFromEnum(indices.u16_type)));
232+
try env.common.setTypeNodeIndexById(gpa, indices.i16_ident, @intCast(@intFromEnum(indices.i16_type)));
233+
try env.common.setTypeNodeIndexById(gpa, indices.u32_ident, @intCast(@intFromEnum(indices.u32_type)));
234+
try env.common.setTypeNodeIndexById(gpa, indices.i32_ident, @intCast(@intFromEnum(indices.i32_type)));
235+
try env.common.setTypeNodeIndexById(gpa, indices.u64_ident, @intCast(@intFromEnum(indices.u64_type)));
236+
try env.common.setTypeNodeIndexById(gpa, indices.i64_ident, @intCast(@intFromEnum(indices.i64_type)));
237+
try env.common.setTypeNodeIndexById(gpa, indices.u128_ident, @intCast(@intFromEnum(indices.u128_type)));
238+
try env.common.setTypeNodeIndexById(gpa, indices.i128_ident, @intCast(@intFromEnum(indices.i128_type)));
239+
try env.common.setTypeNodeIndexById(gpa, indices.dec_ident, @intCast(@intFromEnum(indices.dec_type)));
240+
try env.common.setTypeNodeIndexById(gpa, indices.f32_ident, @intCast(@intFromEnum(indices.f32_type)));
241+
try env.common.setTypeNodeIndexById(gpa, indices.f64_ident, @intCast(@intFromEnum(indices.f64_type)));
242+
try env.common.setTypeNodeIndexById(gpa, indices.numeral_ident, @intCast(@intFromEnum(indices.numeral_type)));
243243
}
244244

245245
/// Validates that BuiltinIndices contains all nominal type declarations in the Builtin module.

0 commit comments

Comments
 (0)