Skip to content

Commit

Permalink
Add fast path for subtyping checks
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Jul 22, 2020
1 parent c754e5f commit 4e7209e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pikelet/src/lang/core/semantics.rs
Expand Up @@ -503,7 +503,7 @@ pub fn read_back_value(
}

/// Check that one elimination is equal to another elimination.
pub fn is_equal_elim(
pub fn is_equal_spine(
globals: &Globals,
local_size: LocalSize,
(head0, spine0): (&Head, &[Elim]),
Expand Down Expand Up @@ -546,9 +546,25 @@ pub fn is_subtype(
value0: &Value,
value1: &Value,
) -> bool {
match (value0.force(globals), value1.force(globals)) {
match (value0, value1) {
(Value::Stuck(head0, spine0), Value::Stuck(head1, spine1)) => {
is_equal_elim(globals, local_size, (head0, spine0), (head1, spine1))
is_equal_spine(globals, local_size, (head0, spine0), (head1, spine1))
}
(Value::Unstuck(head0, spine0, value0), Value::Unstuck(head1, spine1, value1)) => {
if is_equal_spine(globals, local_size, (head0, spine0), (head1, spine1)) {
// No need to force computation if the spines are the same!
return true;
}

let value0 = value0.force(globals);
let value1 = value1.force(globals);
is_subtype(globals, local_size, value0, value1)
}
(Value::Unstuck(_, _, value0), value1) => {
is_subtype(globals, local_size, value0.force(globals), value1)
}
(value0, Value::Unstuck(_, _, value1)) => {
is_subtype(globals, local_size, value0, value1.force(globals))
}

(Value::Universe(level0), Value::Universe(level1)) => level0 <= level1,
Expand Down

0 comments on commit 4e7209e

Please sign in to comment.