Skip to content

Commit

Permalink
Merge pull request #525 from Marwes/symbol_type
Browse files Browse the repository at this point in the history
perf: Move the symbol mismatch panic into a colder path
  • Loading branch information
Marwes committed May 2, 2020
2 parents 29a4bea + e932f81 commit 672716e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 98 deletions.
2 changes: 1 addition & 1 deletion lalrpop/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Generator<'grammar> {
depth: u32,
}

const MAX_DEPTH: u32 = 10000;
const MAX_DEPTH: u32 = 7000;

impl<'grammar> Generator<'grammar> {
fn nonterminal(&mut self, nt: NonterminalString) -> Option<ParseTree> {
Expand Down
7 changes: 6 additions & 1 deletion lalrpop/src/lr1/codegen/parse_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,11 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
}

fn emit_downcast_fns(&mut self) -> io::Result<()> {
rust!(self.out, "#[inline(never)]");
rust!(self.out, "fn {}symbol_type_mismatch() -> ! {{", self.prefix);
rust!(self.out, "panic!(\"symbol type mismatch\")");
rust!(self.out, "}}");

for (ty, name) in self.custom.variants.clone() {
self.emit_downcast_fn(&name, ty)?;
}
Expand Down Expand Up @@ -1224,7 +1229,7 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
self.prefix,
self.prefix
);
rust!(self.out, "_ => panic!(\"symbol type mismatch\")");
rust!(self.out, "_ => {}symbol_type_mismatch()", self.prefix);
rust!(self.out, "}}");

rust!(self.out, "}}");
Expand Down
Loading

0 comments on commit 672716e

Please sign in to comment.