cranelift-isle: Do fewer term lookups (#5232)

While checking the call graph of extractors during semantic validation,
save `TermId` instead of `Sym`. The types are both just integer indexes,
but the `TermId` is more useful here. Saving it avoids needing to check
for failed map lookups twice, which simplifies the implementation.
This commit is contained in:
Jamey Sharp
2022-11-09 11:24:38 -08:00
committed by GitHub
parent 065ce74591
commit 33a192556e

View File

@@ -1323,21 +1323,20 @@ impl TermEnv {
let mut callees = BTreeSet::new(); let mut callees = BTreeSet::new();
template.terms(&mut |pos, t| { template.terms(&mut |pos, t| {
let t = tyenv.intern_mut(t); let sym = tyenv.intern_mut(t);
callees.insert(t); if let Some(term) = self.term_map.get(&sym) {
callees.insert(term);
if !self.term_map.contains_key(&t) { } else {
tyenv.report_error( tyenv.report_error(
pos, pos,
format!( format!(
"`{}` extractor definition references unknown term `{}`", "`{}` extractor definition references unknown term `{}`",
ext.term.0, ext.term.0, t.0
tyenv.syms[t.index()]
), ),
); );
} }
}); });
extractor_call_graph.insert(sym, callees); extractor_call_graph.insert(term, callees);
let termdata = &mut self.terms[term.index()]; let termdata = &mut self.terms[term.index()];
match &mut termdata.kind { match &mut termdata.kind {
@@ -1400,23 +1399,13 @@ impl TermEnv {
})); }));
} }
} else { } else {
let term = match self.term_map.get(&caller) { let pos = match &self.terms[caller.index()].kind {
Some(t) => t,
None => {
// Some other error must have already been recorded
// if we don't have the caller's term data.
assert!(!tyenv.errors.is_empty());
continue 'outer;
}
};
let pos = match &self.terms[term.index()].kind {
TermKind::Decl { TermKind::Decl {
extractor_kind: Some(ExtractorKind::InternalExtractor { template }), extractor_kind: Some(ExtractorKind::InternalExtractor { template }),
.. ..
} => template.pos(), } => template.pos(),
_ => { _ => {
// Again, there must have already been errors // There must have already been errors recorded.
// recorded.
assert!(!tyenv.errors.is_empty()); assert!(!tyenv.errors.is_empty());
continue 'outer; continue 'outer;
} }