Skip to content

Lowering unnamed fields and anonymous adt - #115367

Merged
bors merged 8 commits into
rust-lang:masterfrom
frank-king:feature/unnamed-fields-hir
Feb 12, 2024
Merged

Lowering unnamed fields and anonymous adt#115367
bors merged 8 commits into
rust-lang:masterfrom
frank-king:feature/unnamed-fields-hir

Conversation

@frank-king

@frank-kingfrank-king commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

This implements #49804.

Goals:

  • lowering anonymous ADTs from AST to HIR
  • generating definitions of anonymous ADTs
  • uniqueness check of the unnamed fields
  • field projection of anonymous ADTs
  • #[repr(C)] check of the anonymous ADTs

Non-Goals (will be in the next PRs)

  • capturing generic params for the anonymous ADTs from the parent ADT
  • pattern matching of anonymous ADTs
  • structural expressions of anonymous ADTs
  • rustdoc support of anonymous ADTs

@rustbot

Copy link
Copy Markdown
Collaborator

r? @cjgillot

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

@rustbotrustbot 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. 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 Aug 30, 2023
@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from c0f0f46 to d9347eeCompareAugust 30, 2023 01:34
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbotrustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Sep 2, 2023
@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from 424439f to fa89812CompareSeptember 2, 2023 14:55
@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from fa89812 to 3440d65CompareSeptember 3, 2023 12:05
@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from 3440d65 to 1df9b8aCompareSeptember 4, 2023 01:31
@rust-log-analyzer

This comment has been minimized.

Comment threadcompiler/rustc_ast_lowering/src/lib.rs Outdated
Comment threadcompiler/rustc_ast_lowering/src/lib.rs Outdated
Comment threadcompiler/rustc_ast_lowering/src/lib.rs Outdated
Comment threadcompiler/rustc_hir/src/definitions.rs Outdated
Comment threadcompiler/rustc_ast_lowering/src/lib.rs
Comment threadcompiler/rustc_trait_selection/src/traits/select/mod.rs Outdated
Comment threadcompiler/rustc_middle/src/ty/context.rs
Comment threadcompiler/rustc_hir_analysis/src/astconv/mod.rs Outdated
Comment threadcompiler/rustc_mir_dataflow/src/value_analysis.rs Outdated
Comment threadcompiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs Outdated
@bors

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from 2b57f9f to a8b76fcCompareDecember 14, 2023 14:32
@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch from a8b76fc to 043ed32CompareDecember 20, 2023 15:21
@bors

This comment was marked as resolved.

@frank-king
frank-kingforce-pushed the feature/unnamed-fields-hir branch 3 times, most recently from 3dce559 to bf6482bCompareJanuary 6, 2024 10:26
@bors
bors merged commit bdc1592 into rust-lang:masterFeb 12, 2024
@rustbotrustbot added this to the 1.78.0 milestone Feb 12, 2024
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (bdc1592): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

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

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
6.1%[0.3%, 20.7%]9
Improvements ✅
(primary)
-1.1%[-1.1%, -1.1%]1
Improvements ✅
(secondary)
-0.3%[-0.3%, -0.3%]1
All ❌✅ (primary)-1.1%[-1.1%, -1.1%]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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-2.0%[-2.0%, -2.0%]1
Improvements ✅
(secondary)
-5.3%[-5.3%, -5.3%]1
All ❌✅ (primary)-2.0%[-2.0%, -2.0%]1

Cycles

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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
6.9%[2.7%, 13.8%]6
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.1%[-3.2%, -3.1%]3
All ❌✅ (primary)--0

Binary size

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

Bootstrap: 661.706s -> 662.09s (0.06%)
Artifact size: 308.30 MiB -> 308.34 MiB (0.01%)

@Kobzol

Copy link
Copy Markdown
Member

There seems to be a big regression here on this benchmark, which has a struct with many fields.

Should this have affected performance of non-anonymous fields?

@frank-king

Copy link
Copy Markdown
ContributorAuthor

The query find_field seems to be inefficient and affects FnCtxt::check_field for tuple fields as well.

Is this problem serious? I'm going to do some refactoring work on this query (to implement struct patterns and struct expressions of unnamed fields), but I'm afraid I won't have much time till next week.

@Kobzol

Copy link
Copy Markdown
Member

It would be nice to improve it eventually, it's probably not that rare to have structs with many fields, e.g. generated by macros. But there's no immediate rush :)

@Kobzol

Copy link
Copy Markdown
Member

Oh, I only now noticed that it's a tuple struct. Yeah, so tuple structs with many fields are probably quite rare. In any case, if you find any wins here in the future, that would be great!

@frank-king

Copy link
Copy Markdown
ContributorAuthor

No problem, I'll look into this benchmark in the next step of implementation.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 14, 2024
find_field does not need to be a query.
The current implementation is quadratic in the number of nested fields.
r? `@davidtwco` as you reviewed rust-lang#115367Fixesrust-lang#121755
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 14, 2024
find_field does not need to be a query.
The current implementation is quadratic in the number of nested fields.
r? `@davidtwco` as you reviewed rust-lang#115367Fixesrust-lang#121755
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Jul 16, 2024
find_field does not need to be a query.
The current implementation is quadratic in the number of nested fields.
r? `@davidtwco` as you reviewed rust-lang/rust#115367Fixesrust-lang/rust#121755
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 11, 2024
…s, r=wesleywiser
Retire the `unnamed_fields` feature for now
`#![feature(unnamed_fields)]` was implemented in part in rust-lang#115131 and rust-lang#115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.
However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.
Fixesrust-lang#117942Fixesrust-lang#121161Fixesrust-lang#121263Fixesrust-lang#121299Fixesrust-lang#121722Fixesrust-lang#121799Fixesrust-lang#126969Fixesrust-lang#131041
Tracking:
* rust-lang#49804
[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: rust-lang#49804 (comment)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 11, 2024
…s, r=wesleywiser
Retire the `unnamed_fields` feature for now
`#![feature(unnamed_fields)]` was implemented in part in rust-lang#115131 and rust-lang#115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.
However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.
Fixesrust-lang#117942Fixesrust-lang#121161Fixesrust-lang#121263Fixesrust-lang#121299Fixesrust-lang#121722Fixesrust-lang#121799Fixesrust-lang#126969Fixesrust-lang#131041
Tracking:
* rust-lang#49804
[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: rust-lang#49804 (comment)
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 18, 2024
…s, r=wesleywiser
Retire the `unnamed_fields` feature for now
`#![feature(unnamed_fields)]` was implemented in part in rust-lang#115131 and rust-lang#115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.
However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.
Fixesrust-lang#117942Fixesrust-lang#121161Fixesrust-lang#121263Fixesrust-lang#121299Fixesrust-lang#121722Fixesrust-lang#121799Fixesrust-lang#126969Fixesrust-lang#131041
Tracking:
* rust-lang#49804
[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: rust-lang#49804 (comment)
nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 8, 2024
Empty idents are also disambiguated. This was added in rust-lang#115367.
nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 13, 2024
Empty idents are also disambiguated. This was added in rust-lang#115367.
@petrochenkovpetrochenkov mentioned this pull request Nov 13, 2024
nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 14, 2024
It was added in rust-lang#115367 for anonymous ADTs. Those changes were then
reverted in rust-lang#131045, but `empty_disambiguator` was left behind, perhaps
by mistake. It seems to be unnecessary.
rust-borsBot pushed a commit that referenced this pull request Feb 27, 2026
…eywiser
Retire the `unnamed_fields` feature for now
`#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.
However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.
Fixes#117942Fixes#121161Fixes#121263Fixes#121299Fixes#121722Fixes#121799Fixes#126969Fixes#131041
Tracking:
* #49804
[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: #49804 (comment)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.perf-regressionPerformance regression.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@frank-king@rustbot@rust-log-analyzer@bors@cjgillot@davidtwco@rust-timer@Kobzol@ytmimi