From 1fabc3fa3e8d400c64634692d545ae91a0b85064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 10 Jan 2019 18:54:40 +0900 Subject: [PATCH] debug_assert! instead of assert! This reduces binary size --- ecmascript/parser/src/lexer/input.rs | 2 +- ecmascript/parser/src/lexer/mod.rs | 10 +++++----- ecmascript/parser/src/lexer/number.rs | 2 +- ecmascript/parser/src/parser/expr/mod.rs | 6 +++--- ecmascript/parser/src/parser/expr/ops.rs | 2 +- ecmascript/parser/src/parser/input.rs | 2 +- ecmascript/parser/src/parser/jsx/mod.rs | 2 +- ecmascript/parser/src/parser/macros.rs | 4 ++-- ecmascript/parser/src/parser/typescript.rs | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ecmascript/parser/src/lexer/input.rs b/ecmascript/parser/src/lexer/input.rs index 4e144cf42d9..fe57b05f2ea 100644 --- a/ecmascript/parser/src/lexer/input.rs +++ b/ecmascript/parser/src/lexer/input.rs @@ -61,7 +61,7 @@ impl<'a> Input for SourceFileInput<'a> { } fn slice(&mut self, start: BytePos, end: BytePos) -> &str { - assert!(start <= end, "Cannot slice {:?}..{:?}", start, end); + debug_assert!(start <= end, "Cannot slice {:?}..{:?}", start, end); let s = self.orig; let start_idx = (start - self.fm.start_pos).0 as usize; diff --git a/ecmascript/parser/src/lexer/mod.rs b/ecmascript/parser/src/lexer/mod.rs index d67e04f1c7c..33241194eb9 100644 --- a/ecmascript/parser/src/lexer/mod.rs +++ b/ecmascript/parser/src/lexer/mod.rs @@ -283,7 +283,7 @@ impl<'a, I: Input> Lexer<'a, I> { /// `#` fn read_token_number_sign(&mut self) -> LexResult> { - assert!(self.cur().is_some()); + debug_assert!(self.cur().is_some()); let start = self.input.cur_pos(); @@ -458,7 +458,7 @@ impl<'a, I: Input> Lexer<'a, I> { } fn read_token_lt_gt(&mut self) -> LexResult> { - assert!(self.cur() == Some('<') || self.cur() == Some('>')); + debug_assert!(self.cur() == Some('<') || self.cur() == Some('>')); let start = self.cur_pos(); let c = self.cur().unwrap(); @@ -506,7 +506,7 @@ impl<'a, I: Input> Lexer<'a, I> { /// See https://tc39.github.io/ecma262/#sec-names-and-keywords fn read_ident_or_keyword(&mut self) -> LexResult { - assert!(self.cur().is_some()); + debug_assert!(self.cur().is_some()); let start = self.cur_pos(); let (word, has_escape) = self.read_word_as_str()?; @@ -534,7 +534,7 @@ impl<'a, I: Input> Lexer<'a, I> { /// returns (word, has_escape) fn read_word_as_str(&mut self) -> LexResult<(JsWord, bool)> { - assert!(self.cur().is_some()); + debug_assert!(self.cur().is_some()); let mut has_escape = false; let mut word = String::new(); @@ -637,7 +637,7 @@ impl<'a, I: Input> Lexer<'a, I> { /// See https://tc39.github.io/ecma262/#sec-literals-string-literals fn read_str_lit(&mut self) -> LexResult { - assert!(self.cur() == Some('\'') || self.cur() == Some('"')); + debug_assert!(self.cur() == Some('\'') || self.cur() == Some('"')); let start = self.cur_pos(); let quote = self.cur().unwrap(); self.bump(); // '"' diff --git a/ecmascript/parser/src/lexer/number.rs b/ecmascript/parser/src/lexer/number.rs index 376ad3dfb07..474f8bdea4d 100644 --- a/ecmascript/parser/src/lexer/number.rs +++ b/ecmascript/parser/src/lexer/number.rs @@ -10,7 +10,7 @@ use std::fmt::Display; impl<'a, I: Input> Lexer<'a, I> { /// Reads an integer, octal integer, or floating-point number pub(super) fn read_number(&mut self, starts_with_dot: bool) -> LexResult { - assert!(self.cur().is_some()); + debug_assert!(self.cur().is_some()); if starts_with_dot { debug_assert_eq!( self.cur(), diff --git a/ecmascript/parser/src/parser/expr/mod.rs b/ecmascript/parser/src/parser/expr/mod.rs index 4517f6b8f1c..6ca6fb04666 100644 --- a/ecmascript/parser/src/parser/expr/mod.rs +++ b/ecmascript/parser/src/parser/expr/mod.rs @@ -548,7 +548,7 @@ impl<'a, I: Input> Parser<'a, I> { expr, })); } else { - assert!(expr_or_spreads.len() >= 2); + debug_assert!(expr_or_spreads.len() >= 2); let mut exprs = Vec::with_capacity(expr_or_spreads.len()); for expr in expr_or_spreads { @@ -560,7 +560,7 @@ impl<'a, I: Input> Parser<'a, I> { ExprOrSpread { expr, .. } => exprs.push(expr), } } - assert!(exprs.len() >= 2); + debug_assert!(exprs.len() >= 2); // span of sequence expression should not include '(', ')' let seq_expr = box Expr::Seq(SeqExpr { @@ -1091,7 +1091,7 @@ impl<'a, I: Input> Parser<'a, I> { let start = cur_pos!(); assert_and_bump!("yield"); - assert!(self.ctx().in_generator); + debug_assert!(self.ctx().in_generator); // Spec says // YieldExpression cannot be used within the FormalParameters of a generator diff --git a/ecmascript/parser/src/parser/expr/ops.rs b/ecmascript/parser/src/parser/expr/ops.rs index 30435754ac2..53c3bd3b749 100644 --- a/ecmascript/parser/src/parser/expr/ops.rs +++ b/ecmascript/parser/src/parser/expr/ops.rs @@ -206,7 +206,7 @@ impl<'a, I: Input> Parser<'a, I> { let start = cur_pos!(); assert_and_bump!("await"); - assert!(self.ctx().in_async); + debug_assert!(self.ctx().in_async); if is!('*') { syntax_error!(SyntaxError::AwaitStar); diff --git a/ecmascript/parser/src/parser/input.rs b/ecmascript/parser/src/parser/input.rs index f900f7f055e..1df3390c673 100644 --- a/ecmascript/parser/src/parser/input.rs +++ b/ecmascript/parser/src/parser/input.rs @@ -63,7 +63,7 @@ impl<'a, I: Input> ParserInput<'a, I> { } pub fn peek(&mut self) -> Option<&Token> { - assert!( + debug_assert!( self.cur.is_some(), "parser should not call peek() without knowing current token" ); diff --git a/ecmascript/parser/src/parser/jsx/mod.rs b/ecmascript/parser/src/parser/jsx/mod.rs index 7230b15ea42..f9adde780f6 100644 --- a/ecmascript/parser/src/parser/jsx/mod.rs +++ b/ecmascript/parser/src/parser/jsx/mod.rs @@ -368,7 +368,7 @@ impl<'a, I: Input> Parser<'a, I> { pub(super) fn parse_jsx_text(&mut self) -> PResult<'a, JSXText> { debug_assert!(self.input.syntax().jsx()); - assert!({ + debug_assert!({ match *cur!(false)? { Token::JSXText { .. } => true, _ => false, diff --git a/ecmascript/parser/src/parser/macros.rs b/ecmascript/parser/src/parser/macros.rs index 5367f7edfe8..85c1b118ba1 100644 --- a/ecmascript/parser/src/parser/macros.rs +++ b/ecmascript/parser/src/parser/macros.rs @@ -211,7 +211,7 @@ macro_rules! cur { macro_rules! peek { ($p:expr) => {{ - assert!( + debug_assert!( $p.input.knows_cur(), "parser should not call peek() without knowing current token. Current token is {:?}", @@ -236,7 +236,7 @@ Current token is {:?}", macro_rules! bump { ($p:expr) => {{ - assert!( + debug_assert!( $p.input.knows_cur(), "parser should not call bump() without knowing current token" ); diff --git a/ecmascript/parser/src/parser/typescript.rs b/ecmascript/parser/src/parser/typescript.rs index 5914b12bb00..b5926cde482 100644 --- a/ecmascript/parser/src/parser/typescript.rs +++ b/ecmascript/parser/src/parser/typescript.rs @@ -591,7 +591,7 @@ impl<'a, I: Input> Parser<'a, I> { debug_assert!(self.input.syntax().typescript()); // Need to set `state.inType` so that we don't parse JSX in a type context. - assert!(self.ctx().in_type); + debug_assert!(self.ctx().in_type); let start = cur_pos!();