-
Notifications
You must be signed in to change notification settings - Fork 69
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
Change ty::Const
to a "value tree" representation
#323
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. |
I've previously talked about how this is the interpretation const generics want, and I'm now conceding that making it explicit in the representation (as opposed to lazily decoding it from the miri representation) is a good way to sidestep accidentally ending up with not-typesystem-friendly constants in types, even if other uses of We also probably want to also have some compact encoding for @rustbot second |
ty::Const
to an integer tree representationty::Const
to a "value" tree representation
ty::Const
to a "value" tree representationty::Const
to a "value tree" representation
Proposal
Currently
ty::Const
has multiple ways of representing the same value, which by itself isn't bad, but we actually do represent the same value in different ways. This breaks the invariant in the compiler that if interned things are equal, their interned address is the same. This is very visible when you have two constants representing a pointer value. Const generic functions that are generic over pointer values can arbitrarily cause linker errors, because code defining the generic function may compute a different symbol than the code calling the generic function.ty::Const
'sval
field is of typeConstKind
, whoseValue
variant contains aConstValue
. ThisConstValue
will be replaced byThis change will shrink the size of
ConstValue
from its current 32 bytes to 24 bytes.A value of struct, tuple or array type will be represented as a
Node
, where all the fields or elements are again encoded asConstValue
. Only integers, bools andchar
are allowed asLeaf
values.A value of enum type will be represented as a
Node
where thevariant
field is set to the active enum variant's index and the enum variant's fields are encoded just like struct fields.A pointer is represented as a
Node
with a single child, so(42,)
and&42
are represented exactly the same, only the type at thety::Const
level will differ. While we could have a separatePointer(&'tcx ConstValue<'tcx>)
variant, there's little use in making this explicit and not having it will reduce code duplication everwhere where the difference is not relevant without affecting the places where the difference is relevant.A lossy conversion from
mir::Const
toty::Const
will be introduced. It will be used for pretty printingmir::Const
during mir dumps. This way we only have to support pretty printingty::Const
, which is trivial to pretty print.mir::Const
will be changed to just become the oldConstValue::ByRef
representation in case ofConstKind::Value
. We can likely also remove other variants from the newmir::ConstKind
- I beliveInfer
,Bound
andPlaceHolder
are only used in typeck and irrelevant for MIR.Extensions and alternative designs are elaborated in https://hackmd.io/YmDjIsUsRrC6SiQzkl3Gew
Mentors or Reviewers
Process
The main points of the Major Change Process is as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: