Generate asserts to help LLVM

This commit is contained in:
Markus Westerlind 2020-03-03 00:03:18 +01:00
parent 9320f34bd4
commit af88b698c2

View File

@ -930,6 +930,16 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
rust!(self.out, "// {:?}", production);
// Pop each of the symbols and their associated states.
if production.symbols.len() > 1 {
// By asserting that there are enough elements to pop before popping multiple elements
// we may help LLVM to optimize better since it does not need to generate panic
// branches for each unwrap
rust!(
self.out,
"assert!(symbols.len() >= {});",
production.symbols.len()
);
}
for (index, symbol) in production.symbols.iter().enumerate().rev() {
let name = self.variant_name_for_symbol(symbol);
rust!(