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

Implement the unsafe-fields RFC. #132915

Merged
merged 1 commit into from
Nov 23, 2024
Merged

Conversation

veluca93
Copy link
Contributor

@veluca93 veluca93 commented Nov 11, 2024

@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 Nov 11, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 11, 2024

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 11, 2024

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

Copy link
Member

@jswrenn jswrenn 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 implementing this! Here's a first round of comments. :-)

compiler/rustc_feature/src/unstable.rs Outdated Show resolved Hide resolved
compiler/rustc_metadata/src/rmeta/encoder.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/check_unsafety.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/check_unsafety.rs Outdated Show resolved Hide resolved
@rustbot rustbot 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 11, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

compiler/rustc_feature/src/unstable.rs Outdated Show resolved Hide resolved
@veluca93 veluca93 force-pushed the unsafe-fields branch 2 times, most recently from ff9aee3 to db32d80 Compare November 11, 2024 23:33
@jswrenn
Copy link
Member

jswrenn commented Nov 12, 2024

@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 Nov 12, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 12, 2024
Draft implementation of unsafe-fields.

RFC: rust-lang/rfcs#3458

Tracking:

- rust-lang#132922

r? jswrenn
@bors
Copy link
Contributor

bors commented Nov 12, 2024

⌛ Trying commit db32d80 with merge ce25ffa...

@bors
Copy link
Contributor

bors commented Nov 12, 2024

☀️ Try build successful - checks-actions
Build commit: ce25ffa (ce25ffa95be3a8577d9d1ff09eafe449df2dcfc3)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ce25ffa): comparison URL.

Overall result: ❌✅ regressions and improvements - 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-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
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.7%)

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)
1.8% [1.8%, 1.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.1% [-3.1%, -3.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-3.1%, 1.8%] 2

Cycles

Results (secondary 1.7%)

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)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.2%, secondary 0.3%)

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.2% [0.0%, 0.5%] 128
Regressions ❌
(secondary)
0.3% [0.0%, 0.5%] 29
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.0%, 0.5%] 128

Bootstrap: 787.726s -> 783.8s (-0.50%)
Artifact size: 335.35 MiB -> 335.31 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 12, 2024
@jswrenn
Copy link
Member

jswrenn commented Nov 19, 2024

The UI testing checklist I'd like to see completed before we merge this:

  • if feature(unsafe_fields):
    • the 'incomplete features' warning is emitted
    • unsafe can be applied to the fields of struct-like variant fields of structs, enums and unions
      • the unsafe field's type must be Copy or ManuallyDrop
    • unsafe cannot be applied to tuple-like struct fields
    • unsafe cannot be applied to tuple-like enum fields
  • if not feature(unsafe_fields), even in cfg'd-out code:
    • unsafe cannot be applied to the fields of struct-like struct fields
    • unsafe cannot be applied to the fields of struct-like enum fields
    • unsafe cannot be applied to the fields of struct-like (i.e., all) unions
  • even if not feature(unsafe_fields):
    • initializing, destructuring, referencing, reading, and writing the unsafe fields of a struct/enum/union can only occur in an unsafe context (see these tests as a rough point of reference)
    • initializing, destructuring, referencing, reading, and writing the safe fields of a struct/enum/union (even one that that has other unsafe fields) does not require unsafe

@traviscross traviscross added the F-unsafe_fields `#![feature(unsafe_fields)]` label Nov 20, 2024
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 21, 2024
@bors
Copy link
Contributor

bors commented Nov 21, 2024

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

Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

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

This is looking pretty good. Be sure to update the commit message, too! It's no longer a draft implementation — it's just an implementation. :-)

tests/ui/feature-gates/feature-gate-unsafe_fields.rs Outdated Show resolved Hide resolved
tests/ui/unsafe-fields.rs Show resolved Hide resolved
tests/ui/unsafe-fields.rs Show resolved Hide resolved
tests/ui/unsafe-fields.rs Show resolved Hide resolved
@rustbot rustbot 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 21, 2024
@rust-log-analyzer

This comment has been minimized.

@veluca93 veluca93 changed the title Draft implementation of unsafe-fields. Implement the unsafe-fields RFC. Nov 21, 2024
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Generally looks okay. I've got some minor comments about style and code deduplication.

compiler/rustc_parse/src/parser/item.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/check_unsafety.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/check_unsafety.rs Outdated Show resolved Hide resolved
compiler/rustc_metadata/src/rmeta/encoder.rs Show resolved Hide resolved
compiler/rustc_hir_analysis/src/check/check.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/check/check.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/check/check.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/check/check.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/check/check.rs Outdated Show resolved Hide resolved
@jswrenn
Copy link
Member

jswrenn commented Nov 22, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Nov 22, 2024

📌 Commit 9022bb2 has been approved by jswrenn

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 22, 2024
@bors
Copy link
Contributor

bors commented Nov 23, 2024

⌛ Testing commit 9022bb2 with merge 6e1c11591fc7e98015f8e793a15c8faf0bda67f1...

@bors
Copy link
Contributor

bors commented Nov 23, 2024

☀️ Test successful - checks-actions
Approved by: jswrenn
Pushing 6e1c115 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 23, 2024
@bors bors merged commit 6e1c115 into rust-lang:master Nov 23, 2024
7 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Nov 23, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6e1c115): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -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
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.8%, secondary -2.4%)

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)
2.3% [1.4%, 3.1%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
-2.4% [-4.6%, -1.2%] 3
All ❌✅ (primary) 0.8% [-2.1%, 3.1%] 3

Cycles

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

Binary size

Results (primary 0.2%, secondary 0.3%)

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.2% [0.0%, 0.5%] 129
Regressions ❌
(secondary)
0.3% [0.0%, 0.5%] 31
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.0%, 0.5%] 129

Bootstrap: 797.021s -> 795.784s (-0.16%)
Artifact size: 336.26 MiB -> 336.31 MiB (0.02%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-unsafe_fields `#![feature(unsafe_fields)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants