Skip to content

Commit

Permalink
Remove DCHECK from sort comparison function
Browse files Browse the repository at this point in the history
Summary:
Our implementation of `std::sort()` (and other functions that take a
`Compare` object) does some sanity checks on the provided predicate, including
calling `comp(a, a)` and asserting that it's false. This was tripping a
`JIT_DCHECK()` in this comparison function. Remove it from the predicate and do
a separate pass to ensure uniqueness after sorting.

Reviewed By: alexmalyshev

Differential Revision: D56479803

fbshipit-source-id: e877d08d2f51271fd668fe1308e34aa571b1652b
  • Loading branch information
swtaarrs authored and facebook-github-bot committed Apr 23, 2024
1 parent 8b9c46f commit bc0227e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cinderx/Jit/hir/hir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ void DeoptBase::sortLiveRegs() {
live_regs_.begin(),
live_regs_.end(),
[](const RegState& a, const RegState& b) {
JIT_DCHECK(a.reg != b.reg, "Same register should not be live twice");
return a.reg->id() < b.reg->id();
});

if (kPyDebug) {
// Check for uniqueness after sorting rather than inside the predicate
// passed to std::sort(), in case sort() performs extra comparisons to
// sanity-check our predicate.
auto it = std::adjacent_find(
live_regs_.begin(),
live_regs_.end(),
[](const RegState& a, const RegState& b) { return a.reg == b.reg; });
JIT_DCHECK(it == live_regs_.end(), "Register {} is live twice", *it->reg);
}
}

void Phi::setArgs(const std::unordered_map<BasicBlock*, Register*>& args) {
Expand Down

0 comments on commit bc0227e

Please sign in to comment.