-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use only ty::Unevaluated<'tcx, ()> in type system #98588
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
Changes from all commits
a4bbb8d
2554fa1
a7735cd
0726265
372c4fd
bea0a6d
db9a2d2
29c0364
ba00189
6af8fb7
d77248e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,26 +25,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |||||
constant: &mir::Constant<'tcx>, | ||||||
) -> Result<ConstValue<'tcx>, ErrorHandled> { | ||||||
let ct = self.monomorphize(constant.literal); | ||||||
let ct = match ct { | ||||||
mir::ConstantKind::Ty(ct) => ct, | ||||||
let uv = match ct { | ||||||
mir::ConstantKind::Ty(ct) => match ct.kind() { | ||||||
ty::ConstKind::Unevaluated(uv) => uv.expand(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we can still have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that seems wrong? the constant should be evaluated in maybe we should return an rust/compiler/rustc_trait_selection/src/traits/query/normalize.rs Lines 327 to 328 in 4045ce6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also not clear to me why we would want to error here if we can't evaluate yet, this is called all the time during typecheck, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, the normalize query isn't used during typeck, it's only used afterwards. i guess it's fine to keep this for now 🤷 will be easier to fix this once your pr has landed |
||||||
ty::ConstKind::Value(val) => { | ||||||
return Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val))); | ||||||
} | ||||||
err => span_bug!( | ||||||
constant.span, | ||||||
"encountered bad ConstKind after monomorphizing: {:?}", | ||||||
err | ||||||
), | ||||||
}, | ||||||
mir::ConstantKind::Unevaluated(uv, _) => uv, | ||||||
mir::ConstantKind::Val(val, _) => return Ok(val), | ||||||
}; | ||||||
match ct.kind() { | ||||||
ty::ConstKind::Unevaluated(ct) => self | ||||||
.cx | ||||||
.tcx() | ||||||
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None) | ||||||
.map_err(|err| { | ||||||
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered"); | ||||||
err | ||||||
}), | ||||||
ty::ConstKind::Value(val) => Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val))), | ||||||
err => span_bug!( | ||||||
constant.span, | ||||||
"encountered bad ConstKind after monomorphizing: {:?}", | ||||||
err | ||||||
), | ||||||
} | ||||||
|
||||||
self.cx.tcx().const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).map_err(|err| { | ||||||
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered"); | ||||||
err | ||||||
}) | ||||||
b-naber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
/// process constant containing SIMD shuffle indices | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,8 +564,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
throw_inval!(AlreadyReported(reported)) | ||
} | ||
ty::ConstKind::Unevaluated(uv) => { | ||
// NOTE: We evaluate to a `ValTree` here as a check to ensure | ||
// we're working with valid constants, even though we never need it. | ||
let instance = self.resolve(uv.def, uv.substs)?; | ||
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into()) | ||
let cid = GlobalId { instance, promoted: None }; | ||
let _valtree = self | ||
.tcx | ||
.eval_to_valtree(self.param_env.and(cid))? | ||
.unwrap_or_else(|| bug!("unable to create ValTree for {:?}", uv)); | ||
|
||
Comment on lines
+567
to
+575
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a strange check. Why would CTFE care whether the constant is a valid valtree? What if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this is specifically for But then IMO it would make most sense to have a function that evaluates a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I will do that in #104317 |
||
Ok(self.eval_to_allocation(cid)?.into()) | ||
} | ||
ty::ConstKind::Bound(..) | ty::ConstKind::Infer(..) => { | ||
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c) | ||
|
@@ -586,6 +594,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
match val { | ||
mir::ConstantKind::Ty(ct) => self.const_to_op(*ct, layout), | ||
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout), | ||
mir::ConstantKind::Unevaluated(uv, _) => { | ||
let instance = self.resolve(uv.def, uv.substs)?; | ||
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into()) | ||
} | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.