Skip to content

Commit 4002968

Browse files
authored
Fix asserts when dispatch excluded targets with pending compilation (reactorlabs#1211)
* Fix asserts when dispatch excluded targets with pending compilation
1 parent 2678933 commit 4002968

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

rir/src/api.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ SEXP pirCompile(SEXP what, const Context& assumptions, const std::string& name,
330330
auto body = BODY(cls);
331331
auto dt = DispatchTable::unpack(body);
332332
if (dt->contains(c->context())) {
333-
auto other = dt->dispatch(c->context());
333+
// Dispatch also to versions with pending compilation
334+
// since we're not evaluating
335+
auto other = dt->dispatch(c->context(), false);
334336
assert(other != dt->baseline());
335337
assert(other->context() == c->context());
336338
if (other->body()->isCompiled())

rir/src/runtime/Code.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ struct Code : public RirRuntimeObject<Code, CODE_MAGIC> {
107107
return lazyCompile();
108108
}
109109

110-
bool isCompiled() const {
111-
return kind == Kind::Native && *lazyCodeHandle_ != '\0' &&
112-
nativeCode_ != nullptr;
113-
}
110+
bool isCompiled() const { return kind == Kind::Native && nativeCode_; }
114111
// For Kind::Native there is an in-between state when the Code is already
115112
// placed in a Function but its code handle isn't yet filled by the
116113
// finalizer of PirJitLLVM. We need to prevent such instances from being

rir/src/runtime/DispatchTable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct DispatchTable
4040
return f;
4141
}
4242

43-
Function* dispatch(Context a) const {
43+
Function* dispatch(Context a, bool ignorePending = true) const {
4444
if (!a.smaller(userDefinedContext_)) {
4545
#ifdef DEBUG_DISPATCH
4646
std::cout << "DISPATCH trying: " << a
@@ -56,7 +56,7 @@ struct DispatchTable
5656
#endif
5757
auto e = get(i);
5858
if (a.smaller(e->context()) && !e->disabled() &&
59-
!e->pendingCompilation())
59+
(ignorePending || !e->pendingCompilation()))
6060
return e;
6161
}
6262
return baseline();

0 commit comments

Comments
 (0)