Move try_to_bits from Const to Valtree#136130
Move try_to_bits from Const to Valtree#136130FedericoBruzzone wants to merge 1 commit intorust-lang:masterfrom
try_to_bits from Const to Valtree#136130Conversation
|
Some changes occurred in compiler/rustc_sanitizers cc @rust-lang/project-exploit-mitigations, @rcvalle |
This comment has been minimized.
This comment has been minimized.
b53347c to
312a32f
Compare
lukas-code
left a comment
There was a problem hiding this comment.
IMO we should eventually add a proper type for type-level const values rather that use a tuple of (Ty, ValTree) everywhere, but this PR is already an improvement :)
312a32f to
23ed79b
Compare
Currently, I introduced the proper type ( |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
23ed79b to
9783e80
Compare
| struct ValTreeAndTy<'tcx> { | ||
| valtree: ty::ValTree<'tcx>, | ||
| ty: Ty<'tcx>, | ||
| } |
There was a problem hiding this comment.
cc @BoxyUwU this is a practical type we could use in more places, and implement methods like try_to_bits directly on, to avoid having to pass the type separately
There was a problem hiding this comment.
Ah yeah sorry this was intended to be follow up work from the original PR that removed Ty from ty::Const but it just didn't wind up happening 👍
There was a problem hiding this comment.
I have a branch that implements this PR's approach more globally (master...lukas-code:rust:typed-valtree), will send PR soon.
There was a problem hiding this comment.
I will look at that PR as soon as possible.
|
Closed in favor of #136180 |
Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes rust-lang#131102 supercedes rust-lang#136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
Rollup merge of rust-lang#136180 - lukas-code:typed-valtree, r=oli-obk Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes rust-lang#131102 supercedes rust-lang#136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes rust-lang/rust#131102 supercedes rust-lang/rust#136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes rust-lang/rust#131102 supercedes rust-lang/rust#136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes rust-lang/rust#131102 supercedes rust-lang/rust#136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
This PR is a follow-up to #135158
What's in this PR?
try_to_bits: Transitioned fromConsttoValtree.validate_const_with_value: Renamed toextract_valtree_and_tyfor better clarity.Benefits
Valtreeavoids the need to re-evaluate aConst, improving efficiency where this re-evaluation was previously performed. For instance, in:TooGenericvariant toLayoutErrorand emitUnknown#135158).r? @lukas-code @oli-obk