Skip to content

Commit

Permalink
stage2: Rename Value.compare to compareAll, etc.
Browse files Browse the repository at this point in the history
These functions have a very error-prone API. They are essentially
`all(cmp(op, ...))` but that's not reflected in the name.

This renames these functions to `compareAllAgainstZero...` etc.
for clarity and fixes >20 locations where the predicate was
incorrect.

In the future, the scalar `compare` should probably be split off
from the vector comparison. Rank-polymorphic programming is great,
but a proper implementation in Zig would decouple comparison and
reduction, which then needs a way to fuse ops at comptime.
  • Loading branch information
topolarity committed Nov 2, 2022
1 parent b0be3e2 commit acab0a2
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 96 deletions.
6 changes: 3 additions & 3 deletions src/RangeSet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub fn add(
src: SwitchProngSrc,
) !?SwitchProngSrc {
for (self.ranges.items) |range| {
if (last.compare(.gte, range.first, ty, self.module) and
first.compare(.lte, range.last, ty, self.module))
if (last.compareAll(.gte, range.first, ty, self.module) and
first.compareAll(.lte, range.last, ty, self.module))
{
return range.src; // They overlap.
}
Expand All @@ -53,7 +53,7 @@ const LessThanContext = struct { ty: Type, module: *Module };

/// Assumes a and b do not overlap
fn lessThan(ctx: LessThanContext, a: Range, b: Range) bool {
return a.first.compare(.lt, b.first, ctx.ty, ctx.module);
return a.first.compareAll(.lt, b.first, ctx.ty, ctx.module);
}

pub fn spans(self: *RangeSet, first: Value, last: Value, ty: Type) !bool {
Expand Down
Loading

0 comments on commit acab0a2

Please sign in to comment.