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

Replace pointer address checks in the parser #103700

Conversation

Noratrieb
Copy link
Member

The parser used to check the address of the P<Expr> to determine whether a method it called had changed the value. This is undesirable for serveral reasons:

  • The P::map function allows changes while still maintaining address stability, which could break this code (although it isn't a problem right now)
  • Replacing it with a boolean flag is really simple
  • This is a Rust parser and I don't like casting pointers to integers in my Rust parser
  • I really dont.

r? @compiler-errors because he told me to fix it after i made fun of it

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2022
The parser used to check the address of the `P<Expr>` to determine
whether a method it called had changed the value. This is undesirable
for serveral reasons:

- The `P::map` function allows changes while still maintaining address
  stability, which could break this code (although it isn't a problem
  right now)
- Replacing it with a boolean flag is really simple
- This is a Rust parser and I don't like casting pointers to integers in
  my Rust parser
- I really dont.
@Noratrieb Noratrieb force-pushed the no-pointer-casts-in-my-parser-thank-you branch from ca624b1 to 1a043b2 Compare October 28, 2022 19:07
&mut self,
mut e: P<Expr>,
lo: Span,
) -> PResult<'a, (P<Expr>, bool)> {
Copy link
Member

Choose a reason for hiding this comment

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

maybe a (doc) comment describing what this bool means would be nice,,

Copy link
Member

Choose a reason for hiding this comment

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

galaxy brain: enum ParseDotOrCall { Changed(P<Expr>), Unchanged(P<Expr>) } 😅

but a bool is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

enum ParseDotOrCall {
  Changed(P<Expr>),
  Unchanged(P<Expr>),
  CheckTheAddressJustToBeSure(P<Expr>),
}

@compiler-errors
Copy link
Member

Just being extra defensive, this maybe could use a perf run... But I will rollup- if it ends up with no results.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 28, 2022
@bors
Copy link
Contributor

bors commented Oct 28, 2022

⌛ Trying commit 1a043b2 with merge 75b17f6d708e321f05dd86ccae511d29ff954d97...

@compiler-errors
Copy link
Member

anyways r=me once this perf run comes back clean, if it doesn't then i'll give a look at the results.

@bors delegate+

@bors
Copy link
Contributor

bors commented Oct 28, 2022

✌️ @Nilstrieb can now approve this pull request

@@ -998,13 +999,14 @@ impl<'a> Parser<'a> {
continue;
Copy link
Member

Choose a reason for hiding this comment

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

You forgot a changed_expr on the previous line.

Copy link
Member

@compiler-errors compiler-errors Oct 28, 2022

Choose a reason for hiding this comment

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

Add the corresponding UI test please:

fn main() {
    (1,) as (i32,) .0
    //~^ ERROR cast cannot be followed by a field access
}

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I feel like changed is redundant with the check on line 836:

if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) || changed {

Why did we need changed in the first place??

Copy link
Member

Choose a reason for hiding this comment

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

Status update, as far as I can tell: we don't

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 like this

@compiler-errors
Copy link
Member

@bors delegate-

@bors
Copy link
Contributor

bors commented Oct 28, 2022

☀️ Try build successful - checks-actions
Build commit: 75b17f6d708e321f05dd86ccae511d29ff954d97 (75b17f6d708e321f05dd86ccae511d29ff954d97)

@rust-timer
Copy link
Collaborator

Queued 75b17f6d708e321f05dd86ccae511d29ff954d97 with parent 77e7b74, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (75b17f6d708e321f05dd86ccae511d29ff954d97): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [0.7%, 0.7%] 1

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-4.3%, -3.4%] 3
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2022
@compiler-errors
Copy link
Member

(probably noise)

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 1, 2022
@Noratrieb
Copy link
Member Author

I forgot about one location the body and it turns out this location is very nested and non-trivial. I'm sure it can be fixed, but that's too much effort for me right. If anyone wants to pick it up, feel free.

@Noratrieb Noratrieb closed this Nov 4, 2022
@Noratrieb Noratrieb deleted the no-pointer-casts-in-my-parser-thank-you branch December 23, 2022 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants