Skip to content

Commit 3ffd78e

Browse files
committed
Remove from_dec_literal too
1 parent 3e537fb commit 3ffd78e

File tree

13 files changed

+9
-119
lines changed

13 files changed

+9
-119
lines changed

src/base/Ident.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const CompactWriter = collections.CompactWriter;
1616

1717
const Ident = @This();
1818

19-
/// Method name for parsing decimals from digit lists - used by numeric literal type checking
20-
pub const FROM_DEC_DIGITS_METHOD_NAME = "from_dec_digits";
2119
/// Method name for addition - used by + operator desugaring
2220
pub const PLUS_METHOD_NAME = "plus";
2321
/// Method name for negation - used by unary - operator desugaring

src/build/builtin_compiler/main.zig

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,6 @@ fn replaceStrIsEmptyWithLowLevel(env: *ModuleEnv) !std.ArrayList(CIR.Def.Idx) {
196196
}
197197
}
198198

199-
// from_dec_digits (Dec, F32, F64 only)
200-
const dec_types = [_][]const u8{ "Dec", "F32", "F64" };
201-
for (dec_types) |num_type| {
202-
var buf: [256]u8 = undefined;
203-
204-
// from_dec_digits
205-
const from_dec_digits = try std.fmt.bufPrint(&buf, "Builtin.Num.{s}.from_dec_digits", .{num_type});
206-
if (env.common.findIdent(from_dec_digits)) |ident| {
207-
try low_level_map.put(ident, .num_from_dec_digits);
208-
}
209-
}
210-
211199
// from_numeral (all numeric types)
212200
for (numeric_types) |num_type| {
213201
var buf: [256]u8 = undefined;

src/build/roc/Builtin.roc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ Builtin :: [].{
352352
div_trunc_by : Dec, Dec -> Dec
353353
rem_by : Dec, Dec -> Dec
354354

355-
from_dec_digits : (List(U8), List(U8)) -> Try(Dec, [OutOfRange])
356355
from_numeral : Numeral -> Try(Dec, [InvalidNumeral(Str)])
357356
}
358357

@@ -373,7 +372,6 @@ Builtin :: [].{
373372
div_trunc_by : F32, F32 -> F32
374373
rem_by : F32, F32 -> F32
375374

376-
from_dec_digits : (List(U8), List(U8)) -> Try(F32, [OutOfRange])
377375
from_numeral : Numeral -> Try(F32, [InvalidNumeral(Str)])
378376
}
379377

@@ -394,7 +392,6 @@ Builtin :: [].{
394392
div_trunc_by : F64, F64 -> F64
395393
rem_by : F64, F64 -> F64
396394

397-
from_dec_digits : (List(U8), List(U8)) -> Try(F64, [OutOfRange])
398395
from_numeral : Numeral -> Try(F64, [InvalidNumeral(Str)])
399396
}
400397
}

src/canonicalize/Expression.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ pub const Expr = union(enum) {
438438
num_rem_by, // All numeric types
439439

440440
// Numeric parsing operations
441-
num_from_dec_digits, // Parse (List(U8), List(U8)) -> Try(num, [OutOfRange])
442441
num_from_numeral, // Parse Numeral -> Try(num, [InvalidNumeral(Str)])
443442
};
444443

src/canonicalize/ModuleEnv.zig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ evaluation_order: ?*DependencyGraph.EvaluationOrder,
132132
// Cached well-known identifiers for type checking
133133
// (These are interned once during init to avoid repeated string comparisons during type checking)
134134

135-
/// Interned identifier for "from_dec_digits" - used for decimal literal type checking
136-
from_dec_digits_ident: Ident.Idx,
135+
/// Padding for removed from_dec_digits_ident field (maintains struct layout for serialization)
136+
_padding_removed_from_dec_digits: u32 = 0,
137+
137138
/// Interned identifier for "Try" - used for numeric literal type checking
138139
try_ident: Ident.Idx,
139140
/// Interned identifier for "OutOfRange" - used for numeric literal type checking
@@ -231,7 +232,6 @@ pub fn init(gpa: std.mem.Allocator, source: []const u8) std.mem.Allocator.Error!
231232
var common = try CommonEnv.init(gpa, source);
232233

233234
// Intern well-known identifiers once during initialization for fast type checking
234-
const from_dec_digits_ident = try common.insertIdent(gpa, Ident.for_text(Ident.FROM_DEC_DIGITS_METHOD_NAME));
235235
const try_ident = try common.insertIdent(gpa, Ident.for_text("Try"));
236236
const out_of_range_ident = try common.insertIdent(gpa, Ident.for_text("OutOfRange"));
237237
const builtin_module_ident = try common.insertIdent(gpa, Ident.for_text("Builtin"));
@@ -281,7 +281,6 @@ pub fn init(gpa: std.mem.Allocator, source: []const u8) std.mem.Allocator.Error!
281281
.diagnostics = CIR.Diagnostic.Span{ .span = base.DataSpan{ .start = 0, .len = 0 } },
282282
.store = try NodeStore.initCapacity(gpa, 10_000), // Default node store capacity
283283
.evaluation_order = null, // Will be set after canonicalization completes
284-
.from_dec_digits_ident = from_dec_digits_ident,
285284
.try_ident = try_ident,
286285
.out_of_range_ident = out_of_range_ident,
287286
.builtin_module_ident = builtin_module_ident,
@@ -1718,7 +1717,7 @@ pub const Serialized = extern struct {
17181717
store: NodeStore.Serialized,
17191718
module_kind: ModuleKind.Serialized,
17201719
evaluation_order_reserved: u64, // Reserved space for evaluation_order field (required for in-place deserialization cast)
1721-
from_dec_digits_ident_reserved: u32, // Reserved space for from_dec_digits_ident field (interned during deserialization)
1720+
_padding_removed_from_dec_digits: u32 = 0, // Padding for removed from_dec_digits_ident field (maintains struct layout)
17221721
try_ident_reserved: u32, // Reserved space for try_ident field (interned during deserialization)
17231722
out_of_range_ident_reserved: u32, // Reserved space for out_of_range_ident field (interned during deserialization)
17241723
builtin_module_ident_reserved: u32, // Reserved space for builtin_module_ident field (interned during deserialization)
@@ -1772,7 +1771,6 @@ pub const Serialized = extern struct {
17721771
self.module_name = .{ 0, 0 };
17731772
self.module_name_idx_reserved = 0;
17741773
self.evaluation_order_reserved = 0;
1775-
self.from_dec_digits_ident_reserved = 0;
17761774
self.try_ident_reserved = 0;
17771775
self.out_of_range_ident_reserved = 0;
17781776
self.builtin_module_ident_reserved = 0;
@@ -1828,7 +1826,6 @@ pub const Serialized = extern struct {
18281826
.store = self.store.deserialize(offset, gpa).*,
18291827
.evaluation_order = null, // Not serialized, will be recomputed if needed
18301828
// Well-known identifiers for type checking - look them up in the deserialized common env
1831-
.from_dec_digits_ident = common.findIdent(Ident.FROM_DEC_DIGITS_METHOD_NAME) orelse unreachable,
18321829
.try_ident = common.findIdent("Try") orelse unreachable,
18331830
.out_of_range_ident = common.findIdent("OutOfRange") orelse unreachable,
18341831
.builtin_module_ident = common.findIdent("Builtin") orelse unreachable,

src/check/test/TestEnv.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fn loadCompiledModule(gpa: std.mem.Allocator, bin_data: []const u8, module_name:
8585
.diagnostics = serialized_ptr.diagnostics,
8686
.store = serialized_ptr.store.deserialize(@as(i64, @intCast(base_ptr)), gpa).*,
8787
.evaluation_order = null,
88-
.from_dec_digits_ident = common.findIdent(base.Ident.FROM_DEC_DIGITS_METHOD_NAME) orelse unreachable,
8988
.try_ident = common.findIdent("Try") orelse unreachable,
9089
.out_of_range_ident = common.findIdent("OutOfRange") orelse unreachable,
9190
.builtin_module_ident = common.findIdent("Builtin") orelse unreachable,

src/check/unify.zig

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,85 +1116,6 @@ const Unifier = struct {
11161116
self.merge(vars, vars.b.desc.content);
11171117
}
11181118

1119-
/// Check if a nominal type has a from_dec_digits method by unifying its signature
1120-
/// with the expected type: (List(U8), List(U8)) -> Try(Self, [OutOfRange])
1121-
/// Returns true if unification succeeds, false otherwise.
1122-
fn nominalTypeHasFromDecDigits(
1123-
self: *Self,
1124-
nominal_type: NominalType,
1125-
) Error!bool {
1126-
const method_var = try self.getNominalMethodVar(nominal_type, self.module_env.from_dec_digits_ident) orelse return false;
1127-
const resolved = self.types_store.resolveVar(method_var);
1128-
1129-
const func = switch (resolved.desc.content) {
1130-
.structure => |structure| switch (structure) {
1131-
.fn_pure => structure.fn_pure,
1132-
.fn_effectful => structure.fn_effectful,
1133-
.fn_unbound => structure.fn_unbound,
1134-
else => return false,
1135-
},
1136-
else => return false,
1137-
};
1138-
1139-
const ret_desc = self.types_store.resolveVar(func.ret);
1140-
const ret_nominal = switch (ret_desc.desc.content) {
1141-
.structure => |structure| switch (structure) {
1142-
.nominal_type => structure.nominal_type,
1143-
else => return false,
1144-
},
1145-
else => return false,
1146-
};
1147-
if (!self.isBuiltinTryNominal(ret_nominal)) return false;
1148-
const ret_args = self.types_store.sliceVars(ret_nominal.vars.nonempty);
1149-
if (ret_args.len < 3) return false;
1150-
1151-
const args_slice = self.types_store.sliceVars(func.args);
1152-
if (args_slice.len != 1) return false;
1153-
1154-
const before_ident = self.module_env.common.findIdent("before_dot") orelse return false;
1155-
const after_ident = self.module_env.common.findIdent("after_dot") orelse return false;
1156-
1157-
const record_desc = self.types_store.resolveVar(args_slice[0]);
1158-
const record = switch (record_desc.desc.content) {
1159-
.structure => |structure| switch (structure) {
1160-
.record => structure.record,
1161-
else => return false,
1162-
},
1163-
else => return false,
1164-
};
1165-
1166-
if (record.fields.len() != 2) return false;
1167-
const fields_slice = self.types_store.getRecordFieldsSlice(record.fields);
1168-
const names = fields_slice.items(.name);
1169-
const vars = fields_slice.items(.var_);
1170-
1171-
var before_idx: ?usize = null;
1172-
var after_idx: ?usize = null;
1173-
for (names, 0..) |name, idx| {
1174-
if (name == before_ident) {
1175-
before_idx = idx;
1176-
} else if (name == after_ident) {
1177-
after_idx = idx;
1178-
}
1179-
}
1180-
1181-
if (before_idx == null or after_idx == null) return false;
1182-
1183-
const list_u8_first = try self.createListU8Var();
1184-
const list_u8_second = try self.createListU8Var();
1185-
1186-
self.unifyGuarded(vars[before_idx.?], list_u8_first) catch return false;
1187-
self.unifyGuarded(vars[after_idx.?], list_u8_second) catch return false;
1188-
1189-
const self_ret_var = try self.createNominalInstanceVar(nominal_type);
1190-
self.unifyGuarded(ret_args[1], self_ret_var) catch return false;
1191-
1192-
const try_error_var = try self.createOutOfRangeTagUnion();
1193-
self.unifyGuarded(ret_args[2], try_error_var) catch return false;
1194-
1195-
return true;
1196-
}
1197-
11981119
fn getNominalMethodVar(
11991120
self: *Self,
12001121
nominal_type: NominalType,

src/compile/test/module_env_test.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ test "ModuleEnv.Serialized roundtrip" {
102102
.diagnostics = deserialized_ptr.diagnostics,
103103
.store = deserialized_ptr.store.deserialize(@as(i64, @intCast(@intFromPtr(buffer.ptr))), deser_alloc).*,
104104
.evaluation_order = null,
105-
.from_dec_digits_ident = common.findIdent(Ident.FROM_DEC_DIGITS_METHOD_NAME) orelse unreachable,
106105
.try_ident = common.findIdent("Try") orelse unreachable,
107106
.out_of_range_ident = common.findIdent("OutOfRange") orelse unreachable,
108107
.builtin_module_ident = common.findIdent("Builtin") orelse unreachable,
@@ -128,9 +127,9 @@ test "ModuleEnv.Serialized roundtrip" {
128127

129128
// Verify original data before serialization was correct
130129
// initCIRFields inserts the module name ("TestModule") into the interner, so we have 3 total: hello, world, TestModule
131-
// ModuleEnv.init() also interns 18 well-known identifiers: from_dec_digits, Try, OutOfRange, Builtin, plus, minus, times, div_by, div_trunc_by, rem_by, negate, not, is_lt, is_lte, is_gt, is_gte, is_eq, is_ne
130+
// ModuleEnv.init() also interns 17 well-known identifiers: Try, OutOfRange, Builtin, plus, minus, times, div_by, div_trunc_by, rem_by, negate, not, is_lt, is_lte, is_gt, is_gte, is_eq, is_ne
132131
// Plus 13 numeric type identifiers: Num.U8, Num.I8, Num.U16, Num.I16, Num.U32, Num.I32, Num.U64, Num.I64, Num.U128, Num.I128, Num.F32, Num.F64, Num.Dec
133-
try testing.expectEqual(@as(u32, 34), original.common.idents.interner.entry_count);
132+
try testing.expectEqual(@as(u32, 33), original.common.idents.interner.entry_count);
134133
try testing.expectEqualStrings("hello", original.getIdent(hello_idx));
135134
try testing.expectEqualStrings("world", original.getIdent(world_idx));
136135

@@ -139,8 +138,8 @@ test "ModuleEnv.Serialized roundtrip" {
139138
try testing.expectEqual(@as(usize, 2), original.imports.imports.len()); // Should have 2 unique imports
140139

141140
// First verify that the CommonEnv data was preserved after deserialization
142-
// Should have same 34 identifiers as original: hello, world, TestModule + 18 well-known identifiers + 13 numeric type identifiers from ModuleEnv.init()
143-
try testing.expectEqual(@as(u32, 34), env.common.idents.interner.entry_count);
141+
// Should have same 33 identifiers as original: hello, world, TestModule + 17 well-known identifiers + 13 numeric type identifiers from ModuleEnv.init()
142+
try testing.expectEqual(@as(u32, 33), env.common.idents.interner.entry_count);
144143

145144
try testing.expectEqual(@as(usize, 1), env.common.exposed_items.count());
146145
try testing.expectEqual(@as(?u16, 42), env.common.exposed_items.getNodeIndexById(gpa, @as(u32, @bitCast(hello_idx))));

src/eval/builtin_loading.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub fn loadCompiledModule(gpa: std.mem.Allocator, bin_data: []const u8, module_n
7979
.evaluation_order = null,
8080
// Well-known identifiers for type checking - look them up in the deserialized common env
8181
// These must exist in the Builtin module which defines them
82-
.from_dec_digits_ident = common.findIdent(Ident.FROM_DEC_DIGITS_METHOD_NAME) orelse unreachable,
8382
.try_ident = common.findIdent("Try") orelse unreachable,
8483
.out_of_range_ident = common.findIdent("OutOfRange") orelse unreachable,
8584
.builtin_module_ident = common.findIdent("Builtin") orelse unreachable,

src/eval/interpreter.zig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,11 +3191,6 @@ pub const Interpreter = struct {
31913191
out.is_initialized = true;
31923192
return out;
31933193
},
3194-
.num_from_dec_digits => {
3195-
// num.from_dec_digits : (List(U8), List(U8)) -> Try(num, [OutOfRange])
3196-
self.triggerCrash("num_from_dec_digits not yet implemented", false, roc_ops);
3197-
return error.Crash;
3198-
},
31993194
.num_from_numeral => {
32003195
// num.from_numeral : Numeral -> Try(num, [InvalidNumeral(Str)])
32013196
// Numeral is { is_negative: Bool, digits_before_pt: List(U8), digits_after_pt: List(U8) }

0 commit comments

Comments
 (0)