Skip to content

Fix all compilation errors#11612

Merged
dhruvmanila merged 2 commits intodhruv/parser-phase-2from
dhruv/compile
May 30, 2024
Merged

Fix all compilation errors#11612
dhruvmanila merged 2 commits intodhruv/parser-phase-2from
dhruv/compile

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented May 30, 2024

Summary

This PR fixes all the compilation error as raised by clippy. It doesn't look at the tests. Apart from that it also does the following:

  • Expose a lex method which creates the Lexer object. This is used in the benchmark crate. Ideally, we shouldn't expose the lexer and in the future we should move the lexer benchmark in the parser crate
  • Update the parser reference in red_knot crate
  • Change all references of &[LexResult] to &Tokens
  • Add CommentRanges to the LinterResult as it's required after the linter run. The Program is consumed because it requires an owned ParseError

@codspeed-hq
Copy link

codspeed-hq bot commented May 30, 2024

CodSpeed Performance Report

Merging #11612 will not alter performance

Comparing dhruv/compile (39a9845) with dhruv/compile (b422554)

Summary

✅ 30 untouched benchmarks

Comment on lines +209 to +211
pycodestyle::rules::syntax_error(&mut diagnostics, &parse_error, locator);
error = Some(parse_error);
CommentRanges::default()
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if it makes sense to consume the Program and include CommentRanges to LinterResult. I'm thinking of just cloning the ParseError here, it shouldn't affect performance at all.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we could do that too. Or you could consider adding a take_errors method to Program.


let program =
ruff_python_parser::parse_unchecked_source(source_kind.source_code(), source_type);
ruff_python_parser::parse_unchecked_source(transformed.source_code(), source_type);
Copy link
Member Author

Choose a reason for hiding this comment

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

Um, this is actually a bug. Sorry, it's difficult to separate all this changes very carefully

Comment on lines +1872 to +1876
/// Create a new [`Lexer`] for the given source code and [`Mode`].
pub fn lex(source: &str, mode: Mode) -> Lexer {
Lexer::new(source, mode, TextSize::default())
}

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to expose the lexer because the benchmark crate requires it.

Comment on lines 24 to 26
fn tokenize_reverse(&self) -> Vec<SimpleToken> {
let program = parse_module(self.source).expect("Input to be a valid Python program");
let program = parse_unchecked(self.source, Mode::Module);
BackwardsTokenizer::new(self.source, self.range, program.comment_ranges()).collect()
Copy link
Member Author

Choose a reason for hiding this comment

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

We're only interested in the comment ranges and the source can contain syntax errors.

Comment on lines 263 to 265
pub fn tokens(&self, contents: &str) -> Result<String, Error> {
let program = ruff_python_parser::parse_module(contents)?;
let program = parse_unchecked(contents, Mode::Module);

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just maintaining the existing behavior where the playground displays the token stream even if it contains syntax errors.

@dhruvmanila dhruvmanila marked this pull request as ready for review May 30, 2024 10:34
@dhruvmanila dhruvmanila requested a review from MichaReiser as a code owner May 30, 2024 10:34
Base automatically changed from dhruv/bugfixes to dhruv/parser-phase-2 May 30, 2024 10:52
Comment on lines +209 to +211
pycodestyle::rules::syntax_error(&mut diagnostics, &parse_error, locator);
error = Some(parse_error);
CommentRanges::default()
Copy link
Member

Choose a reason for hiding this comment

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

Yeah we could do that too. Or you could consider adding a take_errors method to Program.

@dhruvmanila dhruvmanila merged commit d55bfcc into dhruv/parser-phase-2 May 30, 2024
@dhruvmanila dhruvmanila deleted the dhruv/compile branch May 30, 2024 11:14
dhruvmanila added a commit that referenced this pull request May 31, 2024
## Summary

This PR fixes all the compilation error as raised by `clippy`. It
doesn't look at the tests. Apart from that it also does the following:

* Expose a `lex` method which creates the `Lexer` object. This is used
in the benchmark crate. Ideally, we shouldn't expose the lexer and in
the future we should move the lexer benchmark in the parser crate
* Update the parser reference in `red_knot` crate 
* Change all references of `&[LexResult]` to `&Tokens`
* Add `CommentRanges` to the `LinterResult` as it's required after the
linter run. The `Program` is consumed because it requires an owned
`ParseError`
dhruvmanila added a commit that referenced this pull request Jun 3, 2024
This PR fixes all the compilation error as raised by `clippy`. It
doesn't look at the tests. Apart from that it also does the following:

* Expose a `lex` method which creates the `Lexer` object. This is used
in the benchmark crate. Ideally, we shouldn't expose the lexer and in
the future we should move the lexer benchmark in the parser crate
* Update the parser reference in `red_knot` crate
* Change all references of `&[LexResult]` to `&Tokens`
* Add `CommentRanges` to the `LinterResult` as it's required after the
linter run. The `Program` is consumed because it requires an owned
`ParseError`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants