Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few cleanups and minor improvements for the lexer #53289

Merged
merged 1 commit into from
Aug 16, 2018

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Aug 12, 2018

  • improve readability by adjusting the formatting of some function signatures and adding some newlines
  • reorder some functions for easier reading
  • remove redundant 'static in consts
  • remove some explicit returns
  • read directly to a String in gather_comments_and_literals
  • change unwrap_or! (macro) to unwrap_or (function)
  • move an assert!ion from try_next_token (called in a loop) to try_real_token after all calls to try_next_token
  • #[inline] some one-liner functions
  • assign directly from an if-else expression
  • refactor a match to map_or
  • add a token::is_irrelevant function to detect tokens that are not "real"

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2018
Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @ljedrz!

I left some comments where I think that things should stay as they are.

fn read_block_comment(rdr: &mut StringReader,
code_to_the_left: bool,
comments: &mut Vec<Comment>) {
fn read_block_comment(rdr: &mut StringReader, code_to_the_left: bool, comments: &mut Vec<Comment>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous version is actually more readable.

}

assert!(self.fatal_errs.is_empty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep the assertion in try_next_token() since it's also called from other places.

}
_ => break,
}
while t.tok.is_irrelevant() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, I'd rather keep the previous version. It's not immediately clear what is_irrelevant() means and the token might be "relevant" in other contexts, so pulling it into a method of Token could be confusing.

@ljedrz
Copy link
Contributor Author

ljedrz commented Aug 13, 2018

Thanks, comments addressed.

@ljedrz
Copy link
Contributor Author

ljedrz commented Aug 13, 2018

@michaelwoerister are you sure about that assert, though? I only found it (within the compiler) used in next_token and try_real_token; I could always add it to next_token too (though I'm not sure it's needed due to unwrap_or_abort).

@michaelwoerister
Copy link
Member

I'd rather stay on the safe side here. An assertion like this is practically free as far as runtime performance goes.

@ljedrz
Copy link
Contributor Author

ljedrz commented Aug 13, 2018

@michaelwoerister ah, that's true; that check is trivial.

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 13, 2018

📌 Commit 40d9bd0 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Aug 13, 2018
…ister

A few cleanups and minor improvements for the lexer

- improve readability by adjusting the formatting of some function signatures and adding some newlines
- reorder some functions for easier reading
- remove redundant `'static` in `const`s
- remove some explicit `return`s
- read directly to a `String` in `gather_comments_and_literals`
- change `unwrap_or!` (macro) to `unwrap_or` (function)
- move an `assert!`ion from `try_next_token` (called in a loop) to `try_real_token` after all calls to `try_next_token`
- `#[inline]` some one-liner functions
- assign directly from an `if-else` expression
- refactor a `match` to `map_or`
- add a `token::is_irrelevant` function to detect tokens that are not "`real`"
@bors
Copy link
Contributor

bors commented Aug 16, 2018

⌛ Testing commit 40d9bd0 with merge 6c712b1...

bors added a commit that referenced this pull request Aug 16, 2018
A few cleanups and minor improvements for the lexer

- improve readability by adjusting the formatting of some function signatures and adding some newlines
- reorder some functions for easier reading
- remove redundant `'static` in `const`s
- remove some explicit `return`s
- read directly to a `String` in `gather_comments_and_literals`
- change `unwrap_or!` (macro) to `unwrap_or` (function)
- move an `assert!`ion from `try_next_token` (called in a loop) to `try_real_token` after all calls to `try_next_token`
- `#[inline]` some one-liner functions
- assign directly from an `if-else` expression
- refactor a `match` to `map_or`
- add a `token::is_irrelevant` function to detect tokens that are not "`real`"
@bors
Copy link
Contributor

bors commented Aug 16, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing 6c712b1 to master...

@bors bors merged commit 40d9bd0 into rust-lang:master Aug 16, 2018
@ljedrz ljedrz deleted the improve_lexer branch August 16, 2018 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants