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

Merge PatKind::Path into PatKind::Expr #134248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Dec 13, 2024

Follow-up to #134228

We always had a duplication where Paths could be represented as PatKind::Path or PatKind::Lit(ExprKind::Path). We had to handle both everywhere, and still do after #134228, so I'm removing it now.

@rustbot
Copy link
Collaborator

rustbot commented Dec 13, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 13, 2024
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the patkind-path-removal branch from 7cee193 to eb60270 Compare December 13, 2024 09:20
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the patkind-path-removal branch from eb60270 to a29a302 Compare December 13, 2024 10:20
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the patkind-path-removal branch 2 times, most recently from 40adfed to 25dae36 Compare December 18, 2024 10:13
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 18, 2024
…ler-errors

Forbid overwriting types in typeck

While trying to figure out some type setting logic in rust-lang#134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care.

Best reviewed commit by commit.

No behaviour change is intended.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 19, 2024
…ler-errors

Forbid overwriting types in typeck

While trying to figure out some type setting logic in rust-lang#134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care.

Best reviewed commit by commit.

No behaviour change is intended.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2024
Rollup merge of rust-lang#134474 - oli-obk:push-yomnkntvzlxw, r=compiler-errors

Forbid overwriting types in typeck

While trying to figure out some type setting logic in rust-lang#134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care.

Best reviewed commit by commit.

No behaviour change is intended.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 20, 2024
Forbid overwriting types in typeck

While trying to figure out some type setting logic in rust-lang/rust#134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care.

Best reviewed commit by commit.

No behaviour change is intended.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Dec 23, 2024
Forbid overwriting types in typeck

While trying to figure out some type setting logic in rust-lang/rust#134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care.

Best reviewed commit by commit.

No behaviour change is intended.
@bors
Copy link
Contributor

bors commented Dec 26, 2024

☔ The latest upstream changes (presumably #134788) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk force-pushed the patkind-path-removal branch 2 times, most recently from 2f05ee6 to 1be4ad1 Compare January 7, 2025 10:07
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the patkind-path-removal branch from 1be4ad1 to 2269e1f Compare January 7, 2025 10:19
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 7, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2025
Merge `PatKind::Path` into `PatKind::Lit`

Follow-up to rust-lang#134228

We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now. subsequently we can also nuke `visit_pattern_type_pattern`
@bors
Copy link
Contributor

bors commented Jan 7, 2025

⌛ Trying commit 2269e1f with merge 801e8e4...

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 20, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 20, 2025

😅 finally. Ready for review as I have nothing more to add on the code side. Best reviewed commit by commit

@oli-obk oli-obk changed the title Merge PatKind::Path into PatKind::Lit Merge PatKind::Path into PatKind::Expr Jan 23, 2025
Comment on lines 688 to 690
PatKind::Expr(ref expression) => {
try_visit!(walk_pat_expr(visitor, pattern.hir_id, pattern.span, expression))
}
Copy link
Member

Choose a reason for hiding this comment

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

So this is kind of sketchy. It means that overriding visit_pat_expr wont' actually visit any PatKind::Expr. I haven't looked to see if any existing hir visitors would be incorrect now but at the very least it seems like unexpected behaviour.

It also seems like to some extent jankyness around hir visitors and patterns is pre-existing, we store PatExpr in PatKind::Range which means that overriding the visit_pat function won't actually visit the patterns in range patterns. Again I don't really know if there's any existing hir visitors which are buggy because of this but it feels unexpected and like it could cause issues.

If it's possible to keep PatKind::Expr as containing a PatExpr for now that would mean that this PR wouldn't make anything worse here. I could imagine that potentially having performance implications though from now having more nodes in the HIR, more HirIds and generally Pat being larger as path exprs now go through a layer of indirection through a PatExpr.

Can probably figure out other solutions if that doesn't work out perf wise, though if that doesn't work out it's probably worth figuring out how to also make visit_pat visit all patterns as it wouldn't surprise me if they wind up being similar solutions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

visit the patterns in range patterns

there are no patterns within range patterns. you can't do a..5

Copy link
Member

@BoxyUwU BoxyUwU Jan 23, 2025

Choose a reason for hiding this comment

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

Right it's a PatExpr but that's still a pattern no? Just because we don't support all pattern syntax there doesn't make it not a pattern 🤔

edit: Maybe that's just not a good intuition and it's fine for visit_pat to not visit that stuff though, the important thing is the visit_pat_expr stuff I think since its a new change

Copy link
Member

Choose a reason for hiding this comment

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

141c3ba#diff-ffa196a0614fce5117ac525b8da3cbf210e21efa6f743b2ec2b7eb3d8ea38a76R331-R333 I assume this change is a manifestation of the fact that by storing an PatExprKind, visitors which are doing something "obviously right" overriding visit_pat_expr now no longer actually visit all pat exprs

this definitely makes me feel like this is something that could be hit in practice so should probably be worked around somehow

@oli-obk oli-obk force-pushed the patkind-path-removal branch from d327296 to fd47152 Compare January 23, 2025 09:50
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 23, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 23, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 23, 2025
Merge `PatKind::Path` into `PatKind::Expr`

Follow-up to rust-lang#134228

We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now.
@bors
Copy link
Contributor

bors commented Jan 23, 2025

⌛ Trying commit fd47152 with merge 78fe09469938ee57fbc1e1dc8e20855ef0609ae0...

Comment on lines +74 to +81
let expr = hir::PatExpr { hir_id: pat_hir_id, span, kind };
let expr = self.arena.alloc(expr);
return hir::Pat {
hir_id: self.next_id(),
kind: hir::PatKind::Expr(expr),
span,
default_binding_modes: true,
};
Copy link
Contributor Author

@oli-obk oli-obk Jan 23, 2025

Choose a reason for hiding this comment

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

Fishy HirId swap, but I can't remember why this is the right soluation. If I do it differently we end up not being able to handle assoc consts anymore

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 23, 2025

💔 Test failed - checks-actions

@bors bors 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 Jan 23, 2025
@oli-obk oli-obk force-pushed the patkind-path-removal branch from fd47152 to dbf867b Compare January 23, 2025 13:37
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 23, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 23, 2025

⌛ Trying commit dbf867b with merge a5bd41a...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 23, 2025
Merge `PatKind::Path` into `PatKind::Expr`

Follow-up to rust-lang#134228

We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now.
@bors
Copy link
Contributor

bors commented Jan 23, 2025

☀️ Try build successful - checks-actions
Build commit: a5bd41a (a5bd41a49f2a00ea177a196fca62d6568cc9d37b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a5bd41a): comparison URL.

Overall result: ❌ regressions - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.1%, 0.4%] 8
Regressions ❌
(secondary)
0.3% [0.1%, 0.5%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.1%, 0.4%] 8

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 778.767s -> 774.185s (-0.59%)
Artifact size: 325.93 MiB -> 325.92 MiB (-0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 23, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 23, 2025

No diffs in query executions, so it's all about incremental caching being more expensive due to the extra node, which is unavoidable, but also very small. We can always revisit in the future, but more robust code trumps perf for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.

7 participants