Skip to content

Commit

Permalink
feat: Location information in extension inference error (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
croyzor authored Aug 29, 2023
1 parent 550df7f commit b58b582
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ pub enum InferExtensionError {
/// The incompatible solution that we found was already there
actual: ExtensionSet,
},
#[error("Solved extensions {expected} at {expected_loc:?} and {actual} at {actual_loc:?} should be equal.")]
/// A version of the above with info about which nodes failed to unify
MismatchedConcreteWithLocations {
/// Where the solution we want to insert came from
expected_loc: (Node, Direction),
/// The solution we were trying to insert for this meta
expected: ExtensionSet,
/// Which node we're trying to add a solution for
actual_loc: (Node, Direction),
/// The incompatible solution that we found was already there
actual: ExtensionSet,
},
/// A variable went unsolved that wasn't related to a parameter
#[error("Unsolved variable at location {:?}", location)]
Unsolved {
Expand Down Expand Up @@ -314,7 +326,10 @@ impl UnificationContext {
}
}

/// Try to turn mismatches into `ExtensionError` when possible
/// When trying to unify two metas, check if they both correspond to
/// different ends of the same wire. If so, return an `ExtensionError`.
/// Otherwise check whether they both correspond to *some* location on the
/// graph and include that info the otherwise generic `MismatchedConcrete`.
fn report_mismatch(
&self,
m1: Meta,
Expand Down Expand Up @@ -375,10 +390,19 @@ impl UnificationContext {
} else {
None
};
err.unwrap_or(InferExtensionError::MismatchedConcrete {
expected: rs1,
actual: rs2,
})
if let (Some(loc1), Some(loc2)) = (loc1, loc2) {
err.unwrap_or(InferExtensionError::MismatchedConcreteWithLocations {
expected_loc: *loc1,
expected: rs1,
actual_loc: *loc2,
actual: rs2,
})
} else {
err.unwrap_or(InferExtensionError::MismatchedConcrete {
expected: rs1,
actual: rs2,
})
}
}

/// Take a group of equal metas and merge them into a new, single meta.
Expand Down

0 comments on commit b58b582

Please sign in to comment.