-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Support enum variants in offset_of! #114208
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred in diagnostic error codes Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 This PR changes Stable MIR cc @oli-obk, @celinval, @spastorino |
cc @thomcc as the RFC author. |
This comment has been minimized.
This comment has been minimized.
For MIR we are using |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #114614) made this pull request unmergeable. Please resolve the merge conflicts. |
So once this is merged, the syntax to get the offset of the Also I dislike the rule of "last part must be field". I think we should rather specify it as "field must follow enum variant". Otherwise people may try |
I've wondered about possible syntaxes. It seems here we have an exception from the rule of having to import the variant via Personally I think it's okay to not be required to do |
Musing on syntax: Would it be worth having some syntactic distinction between variant parts and field parts? After all, Spitballing, (Dunno that this would be necessary, though. Just EDIT: Oh, you mentioned this in the OP. Dunno how to choose here. I started a zulip thread to try to think about things more: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/.60offset_of!.60.20Syntax/near/384555143 I agree with @est31 that we don't need to type-qualify things, though, same as how field access in general isn't type-qualified. |
Some discussion w.r.t. syntax on Zulip: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/.60offset_of!.60.20Syntax My proposed bikeshed color:
|
I'm personally not a fan of So we either use |
Yeah, that basically only works in MIR because of the In anything that would go in surface-like Rust, I don't think we can make that so cleanly. Any use of |
Yeah, doing offset_of!(Type, comma-separated list of field or Variant::field) would probably minimize the implementation effort, be perfectly clear and fit into { |
The feature is unstable, so can we pick something and then bikeshed the stable syntax separately? |
I stand corrected, paths don't accept |
I don't think that |
@est31 I agree. When I checked it in the playground, it didn't work. Trying other options brought up the The nice thing is that ideally we want a With that said, I'd be totally OK with unstably merging any syntax that makes it work and handling the other stuff later. |
I agree with @the8472 in #114208 (comment) -- let's get this landed in nightly under a feature gate, and continue the syntax picking conversation on zulip. I would vote for picking something as simple as possible in the macro that's consistent with (I have some compiler code comments, but feel free to do or ignore those depending on the advice of the actual compiler reviewers here.) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@wesleywiser @est31 This is now rebased and review comments are resolved. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (146dafa): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 635.994s -> 638.45s (0.39%) |
80: Automated pull from upstream `master` r=tshepang a=github-actions[bot] This PR pulls the following changes from the upstream repository: * rust-lang/rust#117498 * rust-lang/rust#117488 * rust-lang/rust#117441 * rust-lang/rust#117373 * rust-lang/rust#117298 * rust-lang/rust#117029 * rust-lang/rust#117289 * rust-lang/rust#117307 * rust-lang/rust#114208 * rust-lang/rust#117482 * rust-lang/rust#117475 * rust-lang/rust#117401 * rust-lang/rust#117397 * rust-lang/rust#115626 * rust-lang/rust#117436 * rust-lang/rust#115356 * rust-lang/rust#117422 * rust-lang/rust#116692 Co-authored-by: David CARLIER <devnexen@gmail.com> Co-authored-by: Taiki Endo <te316e89@gmail.com> Co-authored-by: ltdk <usr@ltdk.xyz> Co-authored-by: Ryan Mehri <ryan.mehri1@gmail.com>
Update to the latest Rust toolchain (2023-11-06). The relevant changes are: - rust-lang/rust#117507: this required changing the import of `Span` from `rustc_span::source_map::Span` to `rustc_span::Span`. - rust-lang/rust#114208: this changed the data field for the `OffsetOf` variant of `NullOp` from `List<FieldIdx>` to `List<(VariantIdx, FieldIdx)>`, which required updating the relevant code in `rvalue.rs`. - rust-lang/rust#115626: the unchecked shift operators have been separated from the `unchecked_math` feature, so this required changing the feature annotation in `tests/ui/should-panic-attribute/unexpected-failures/test.rs` - Some rustc change (not sure which one) result in a line in `tests/coverage/unreachable/variant/main.rs` getting optimized out. To maintain what this test is testing, I changed the `match` to make it a bit less-prone to optimization. - A change in `cargo` (rust-lang/cargo#12779) resulted in an update to Kani's workspace `Cargo.toml` when `cargo add` is executed inside `tests/script-based-pre/build-cache-bin`. This is apparently intended behavior, so I had to make the `exclude` in the `Cargo.toml` more specific to make sure this doesn't happen (I tried using a glob, but that didn't work, apparently because of rust-lang/cargo#6009. Resolves #2848 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
…trochenkov Remove option_payload_ptr; redundant to offset_of The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (rust-lang#114208). This PR removes it in order to dogfood offset_of (as suggested at rust-lang#106655 (comment)). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
This MR implements support for navigating through enum variants in
offset_of!
, placing the enum variant name in the second argument tooffset_of!
. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things likeAlternatively, a syntactic distinction could be made between variants and fields (e.g.
field::Variant.field
) but I'm not convinced this would be helpful.RFC 3308 # Enum Support
Tracking Issue #106655.