Open
Conversation
Collaborator
|
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri HIR ty lowering was modified cc @fmease |
Collaborator
|
|
This comment has been minimized.
This comment has been minimized.
fe3fa8b to
f5f42d1
Compare
Collaborator
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This is a rewrite of #146307 by using a lang item instead of a custom
TyKind. We still need ahir::TyKind::FieldOfvariant, because resolving the field name cannot be done before HIR construction. The advantage of doing it this way is that we don't need to make any changes to types after HIR (including symbol mangling). At the very beginning of this feature implementation, I tried to do it using a lang item, but then quickly abandoned the approach, because at that time I was still intending to support nested fields.Here is a range-diff between the two PRs
Add Field Representing Types (FRTs)
This PR implements the first step of the field projection lang experiment (Tracking Issue: #145383). Field representing types (FRTs) are a new kind of type. They can be named through the use of the
field_of!macro with the first argument being the type and the second the name of the field (or variant and field in the case of an enum). No nested fields are supported.FRTs natively implement the
Fieldtrait that's also added in this PR. It exposes information about the field such as the type of the field, the type of the base (i.e. the type that contains the field) and the offset within that base type. Only fields of non-packed structs are supported, fields of enums an unions have unique types for each field, but those do not implement theFieldtrait.This PR was created in collaboration with @dingxiangfei2009, it wouldn't have been possible without him, so huge thanks for mentoring me!
I updated my library solution for field projections to use the FRTs from
coreinstead of creating my own using the hash of the name of the field. See the Rust-for-Linux/field-projectionlang-experimentbranch.API added to
core::fieldAlong with a perma-unstable type that the compiler uses in the expansion of the macro:
Explanation of Field Representing Types (FRTs)
FRTs are used for compile-time & trait-level reflection for fields of structs & tuples. Each struct & tuple has a unique compiler-generated type nameable through the
field_of!macro. This type natively contains information about the field such as the outermost container, type of the field and its offset. Users may implement additional traits on these types in order to record custom information (for example a crate may define aPinnableFieldtrait that records whether the field is structurally pinned).They are the foundation of field projections, a general operation that's generic over the fields of a struct. This genericism needs to be expressible in the trait system. FRTs make this possible, since an operation generic over fields can just be a function with a generic parameter
F: Field.Note
The approach of field projections has changed considerably since this PR was opened. In the end we might not need FRTs, so this API is highly experimental.
FRTs should act as though they were defined as
struct MyStruct_my_field<StructGenerics>;next to the struct. So it should be local to the crate defining the struct so that one can implement any trait for the FRT from that crate. TheFieldtraits should be implemented by the compiler & populated with correct information (unsafecode needs to be able to rely on them being correct).TODOs
There are some
FIXME(FRTs)scattered around the code:field_of!can be improvedtests/ui/field_representing_types/nonexistent.rstests/ui/field_representing_types/non-struct.rstests/ui/field_representing_types/offset.rstests/ui/field_representing_types/not-field-if-packed.rstests/ui/field_representing_types/invalid.rscompiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rsr? @oli-obk