aboutsummaryrefslogtreecommitdiff
path: root/src/RangeSet.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-06-15 16:10:53 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2024-07-07 22:59:52 -0400
commit525f341f33af9b8aad53931fd5511f00a82cb090 (patch)
treecec3280498c1122858580946ac5e31f8feb807ce /src/RangeSet.zig
parent8f20e81b8816aadd8ceb1b04bd3727cc1d124464 (diff)
downloadzig-525f341f33af9b8aad53931fd5511f00a82cb090.tar.gz
zig-525f341f33af9b8aad53931fd5511f00a82cb090.zip
Zcu: introduce `PerThread` and pass to all the functions
Diffstat (limited to 'src/RangeSet.zig')
-rw-r--r--src/RangeSet.zig32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/RangeSet.zig b/src/RangeSet.zig
index 01d9157767..b174f8e3b5 100644
--- a/src/RangeSet.zig
+++ b/src/RangeSet.zig
@@ -6,13 +6,11 @@ const InternPool = @import("InternPool.zig");
const Type = @import("Type.zig");
const Value = @import("Value.zig");
const Zcu = @import("Zcu.zig");
-/// Deprecated.
-const Module = Zcu;
const RangeSet = @This();
const LazySrcLoc = Zcu.LazySrcLoc;
+pt: Zcu.PerThread,
ranges: std.ArrayList(Range),
-module: *Module,
pub const Range = struct {
first: InternPool.Index,
@@ -20,10 +18,10 @@ pub const Range = struct {
src: LazySrcLoc,
};
-pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {
+pub fn init(allocator: std.mem.Allocator, pt: Zcu.PerThread) RangeSet {
return .{
+ .pt = pt,
.ranges = std.ArrayList(Range).init(allocator),
- .module = module,
};
}
@@ -37,8 +35,8 @@ pub fn add(
last: InternPool.Index,
src: LazySrcLoc,
) !?LazySrcLoc {
- const mod = self.module;
- const ip = &mod.intern_pool;
+ const pt = self.pt;
+ const ip = &pt.zcu.intern_pool;
const ty = ip.typeOf(first);
assert(ty == ip.typeOf(last));
@@ -47,8 +45,8 @@ pub fn add(
assert(ty == ip.typeOf(range.first));
assert(ty == ip.typeOf(range.last));
- if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), mod) and
- Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), mod))
+ if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), pt) and
+ Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), pt))
{
return range.src; // They overlap.
}
@@ -63,20 +61,20 @@ pub fn add(
}
/// Assumes a and b do not overlap
-fn lessThan(mod: *Module, a: Range, b: Range) bool {
- const ty = Type.fromInterned(mod.intern_pool.typeOf(a.first));
- return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, mod);
+fn lessThan(pt: Zcu.PerThread, a: Range, b: Range) bool {
+ const ty = Type.fromInterned(pt.zcu.intern_pool.typeOf(a.first));
+ return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, pt);
}
pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {
- const mod = self.module;
- const ip = &mod.intern_pool;
+ const pt = self.pt;
+ const ip = &pt.zcu.intern_pool;
assert(ip.typeOf(first) == ip.typeOf(last));
if (self.ranges.items.len == 0)
return false;
- std.mem.sort(Range, self.ranges.items, mod, lessThan);
+ std.mem.sort(Range, self.ranges.items, pt, lessThan);
if (self.ranges.items[0].first != first or
self.ranges.items[self.ranges.items.len - 1].last != last)
@@ -95,10 +93,10 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !
const prev = self.ranges.items[i];
// prev.last + 1 == cur.first
- try counter.copy(Value.fromInterned(prev.last).toBigInt(&space, mod));
+ try counter.copy(Value.fromInterned(prev.last).toBigInt(&space, pt));
try counter.addScalar(&counter, 1);
- const cur_start_int = Value.fromInterned(cur.first).toBigInt(&space, mod);
+ const cur_start_int = Value.fromInterned(cur.first).toBigInt(&space, pt);
if (!cur_start_int.eql(counter.toConst())) {
return false;
}