Skip to content

Basic canonicalize_expr of idents with tests #7806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f492e8b
Basic canonicalize_expr of idents with tests
gamebox May 23, 2025
94eaaac
BROKEN: CanIR re-design rough draft
gamebox May 23, 2025
317e78b
STILL BREAKING - Can Statements
gamebox May 24, 2025
b3319c0
STILL BREAKING: Fill out more Can IR nodes
gamebox May 24, 2025
99fe1d3
Fixed
gamebox May 27, 2025
41c6ca8
Fix lints
gamebox May 27, 2025
db3ee64
Address feedback
gamebox May 28, 2025
30bcd46
WIP compiles again
lukewilliamboswell Jun 7, 2025
845ea3c
WIP compiles again
lukewilliamboswell Jun 7, 2025
d1dce66
Merge remote-tracking branch 'remote/main' into canonicalize-start
lukewilliamboswell Jun 7, 2025
a968750
remove DataSpan file
lukewilliamboswell Jun 7, 2025
05ac3d5
use base.Scratch for Parse.IR.scratch_statements
lukewilliamboswell Jun 7, 2025
fce2fc1
use base.Scratch for scratch_tokens in Parse IR
lukewilliamboswell Jun 7, 2025
5421f3d
use base.Scratch for scratch_exprs
lukewilliamboswell Jun 7, 2025
d0675bc
use base.Scratch for Parse scratch_patterns, make Scratch top dry
lukewilliamboswell Jun 7, 2025
9021a29
use base.Scratch in Parser scratch_record_fields
lukewilliamboswell Jun 7, 2025
1ed7e2a
use base.Scratch in Parser scratch_pattern_record_fields
lukewilliamboswell Jun 7, 2025
e719727
use base.Scratch in Parser scratch_when_branches
lukewilliamboswell Jun 7, 2025
c169efe
use base.Scratch in Parser scratch_type_annos
lukewilliamboswell Jun 7, 2025
0b1c2ed
use base.Scratch in Parser scratch_anno_record_fields
lukewilliamboswell Jun 7, 2025
6ad1ec1
use base.Scratch in Parser scratch_exposed_items
lukewilliamboswell Jun 7, 2025
250bed2
use base.Scratch in Parser scratch_where_clauses
lukewilliamboswell Jun 7, 2025
295e63b
use common base.DataSpan
lukewilliamboswell Jun 7, 2025
122ccdc
fix uppercase name for Scratch.zig import
lukewilliamboswell Jun 7, 2025
964d892
rename Self to IR, add some comments
lukewilliamboswell Jun 8, 2025
586f565
try start on Can for Ints
lukewilliamboswell Jun 8, 2025
3808c6a
WIP use snapshots for Can
lukewilliamboswell Jun 8, 2025
a261525
WIP implement more Can placeholders
lukewilliamboswell Jun 8, 2025
5620297
add lots of new snapshots to test Can
lukewilliamboswell Jun 8, 2025
6c500da
fix bug with env in Can, implement more sexprs for snapshots
lukewilliamboswell Jun 8, 2025
2a0b566
add more Can SExpr, format type vars using #
lukewilliamboswell Jun 8, 2025
c40abe4
fix add and get of type vars in Can Nodes
lukewilliamboswell Jun 8, 2025
4d7870e
cleanup toSExpr for Can Expr's
lukewilliamboswell Jun 8, 2025
c80aeab
fix typos, rename expr snapshot folder
lukewilliamboswell Jun 8, 2025
ba96581
implement Can for call expressions, and simple strings
lukewilliamboswell Jun 9, 2025
e4b9a79
implement psuedo-builtin Str.concat for string interpolation
lukewilliamboswell Jun 9, 2025
6662c99
simplify SExpr for Can Expr's
lukewilliamboswell Jun 9, 2025
abf7cc5
implement basic Defs and canonicalize_file
lukewilliamboswell Jun 9, 2025
ed13222
improve Can IR, thread region diagnostics through
lukewilliamboswell Jun 9, 2025
203a22d
Merge remote-tracking branch 'remote/main' into canonicalize-start
lukewilliamboswell Jun 9, 2025
9818ceb
refactor Node and NodeStore in Can into separate files
lukewilliamboswell Jun 9, 2025
c79f525
Refactor Can.IR -> CIR
lukewilliamboswell Jun 9, 2025
dc1b145
rename Can IR -> CIR, remove unused `PendingValueDef`
lukewilliamboswell Jun 9, 2025
72778ca
rename CIR.Expr.RuntimeError and continue refactor to CIR
lukewilliamboswell Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/base/DataSpan.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
start: u32,
len: u32,
54 changes: 54 additions & 0 deletions src/base/Scratch.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const std = @import("std");
const exitOnOom = @import("../collections/utils.zig").exitOnOom;
const DataSpan = @import("./DataSpan.zig");

pub fn Scratch(comptime T: type) type {
return struct {
items: std.ArrayListUnmanaged(T),

const Self = @This();
const ArrayList = std.ArrayListUnmanaged(T);

pub fn init(gpa: std.mem.Allocator) Self {
const items = ArrayList.initCapacity(gpa, std.math.ceilPowerOfTwoAssert(usize, 64)) catch |e| exitOnOom(e);
return .{
.items = items,
};
}

pub fn deinit(self: *Self, gpa: std.mem.Allocator) void {
self.items.deinit(gpa);
}

/// Returns the start position for a new Span of whereClauseIdxs in scratch
pub fn top(self: *Self) u32 {
return @as(u32, @intCast(self.items.len));
}

/// Places a new WhereClauseIdx in the scratch. Will panic on OOM.
pub fn append(self: *Self, gpa: std.mem.Allocator, idx: T) void {
self.items.append(gpa, idx) catch |err| exitOnOom(err);
}

/// Creates a new span starting at start. Moves the items from scratch
/// to extra_data as appropriate.
pub fn spanFromStart(self: *Self, start: u32, gpa: std.mem.Allocator, data: *std.ArrayListUnmanaged(u32)) DataSpan {
const end = self.items.len;
defer self.items.shrinkRetainingCapacity(start);
var i = @as(usize, @intCast(start));
const data_start = @as(u32, @intCast(data.items.len));
while (i < end) {
data.append(gpa, self.items[i].id) catch |err| exitOnOom(err);
i += 1;
}
return .{ .span = .{ .start = data_start, .len = @as(u32, @intCast(end)) - start } };
}

/// Clears any WhereClauseIds added to scratch from start until the end.
/// Should be used wherever the scratch items will not be used,
/// as in when parsing fails.
pub fn clearFrom(self: *Self, start: u32) void {
self.items.shrinkRetainingCapacity(start);
}
};
}
2 changes: 1 addition & 1 deletion src/base/module_work.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn ModuleWork(comptime Work: type) type {
items.appendAssumeCapacity(.{
.package_idx = can_irs.getPackageIdx(work_idx),
.module_idx = can_irs.getModuleIdx(work_idx),
.work = Work.init(can_irs.getWork(work_idx).env),
.work = Work.init(&can_irs.getWork(work_idx).env),
});
}

Expand Down
Loading
Loading