Remove WithOptconstParam.
This commit is contained in:
parent
0e017fc94a
commit
b275d2c30b
68 changed files with 335 additions and 960 deletions
|
@ -296,12 +296,12 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
|
|||
}
|
||||
|
||||
let cid = key.value;
|
||||
let def = cid.instance.def.with_opt_param();
|
||||
let is_static = tcx.is_static(def.did);
|
||||
let def = cid.instance.def.def_id();
|
||||
let is_static = tcx.is_static(def);
|
||||
|
||||
let mut ecx = InterpCx::new(
|
||||
tcx,
|
||||
tcx.def_span(def.did),
|
||||
tcx.def_span(def),
|
||||
key.param_env,
|
||||
// Statics (and promoteds inside statics) may access other statics, because unlike consts
|
||||
// they do not have to behave "as if" they were evaluated at runtime.
|
||||
|
|
|
@ -375,9 +375,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
|
||||
match instance {
|
||||
ty::InstanceDef::Item(def) => {
|
||||
if ecx.tcx.is_ctfe_mir_available(def.did) {
|
||||
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
|
||||
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
|
||||
if ecx.tcx.is_ctfe_mir_available(def) {
|
||||
Ok(ecx.tcx.mir_for_ctfe(def))
|
||||
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
|
||||
let guar = ecx.tcx.sess.delay_span_bug(
|
||||
rustc_span::DUMMY_SP,
|
||||
"This is likely a const item that is missing from its impl",
|
||||
|
@ -386,7 +386,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
} else {
|
||||
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
|
||||
// so this should be unreachable.
|
||||
let path = ecx.tcx.def_path_str(def.did);
|
||||
let path = ecx.tcx.def_path_str(def);
|
||||
bug!("trying to call extern function `{path}` at compile-time");
|
||||
}
|
||||
}
|
||||
|
@ -410,9 +410,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
// Execution might have wandered off into other crates, so we cannot do a stability-
|
||||
// sensitive check here. But we can at least rule out functions that are not const
|
||||
// at all.
|
||||
if !ecx.tcx.is_const_fn_raw(def.did) {
|
||||
if !ecx.tcx.is_const_fn_raw(def) {
|
||||
// allow calling functions inside a trait marked with #[const_trait].
|
||||
if !ecx.tcx.is_const_default_method(def.did) {
|
||||
if !ecx.tcx.is_const_default_method(def) {
|
||||
// We certainly do *not* want to actually call the fn
|
||||
// though, so be sure we return here.
|
||||
throw_unsup_format!("calling non-const function `{}`", instance)
|
||||
|
|
|
@ -461,10 +461,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
instance: ty::InstanceDef<'tcx>,
|
||||
promoted: Option<mir::Promoted>,
|
||||
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
|
||||
let def = instance.with_opt_param();
|
||||
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
|
||||
let body = if let Some(promoted) = promoted {
|
||||
&self.tcx.promoted_mir_opt_const_arg(def)[promoted]
|
||||
let def = instance.def_id();
|
||||
&self.tcx.promoted_mir(def)[promoted]
|
||||
} else {
|
||||
M::load_mir(self, instance)?
|
||||
};
|
||||
|
@ -502,13 +502,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
/// The `substs` are assumed to already be in our interpreter "universe" (param_env).
|
||||
pub(super) fn resolve(
|
||||
&self,
|
||||
def: ty::WithOptConstParam<DefId>,
|
||||
def: DefId,
|
||||
substs: SubstsRef<'tcx>,
|
||||
) -> InterpResult<'tcx, ty::Instance<'tcx>> {
|
||||
trace!("resolve: {:?}, {:#?}", def, substs);
|
||||
trace!("param_env: {:#?}", self.param_env);
|
||||
trace!("substs: {:#?}", substs);
|
||||
match ty::Instance::resolve_opt_const_arg(*self.tcx, self.param_env, def, substs) {
|
||||
match ty::Instance::resolve(*self.tcx, self.param_env, def, substs) {
|
||||
Ok(Some(instance)) => Ok(instance),
|
||||
Ok(None) => throw_inval!(TooGeneric),
|
||||
|
||||
|
|
|
@ -83,8 +83,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
(fn_val, self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?, false)
|
||||
}
|
||||
ty::FnDef(def_id, substs) => {
|
||||
let instance =
|
||||
self.resolve(ty::WithOptConstParam::unknown(def_id), substs)?;
|
||||
let instance = self.resolve(def_id, substs)?;
|
||||
(
|
||||
FnVal::Instance(instance),
|
||||
self.fn_abi_of_instance(instance, extra_args)?,
|
||||
|
|
|
@ -36,7 +36,7 @@ where
|
|||
ty::Closure(def_id, substs)
|
||||
| ty::Generator(def_id, substs, ..)
|
||||
| ty::FnDef(def_id, substs) => {
|
||||
let instance = ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id));
|
||||
let instance = ty::InstanceDef::Item(def_id);
|
||||
let unused_params = self.tcx.unused_generic_params(instance);
|
||||
for (index, subst) in substs.into_iter().enumerate() {
|
||||
let index = index
|
||||
|
|
|
@ -874,7 +874,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
debug!("Resolving ({:?}) -> {:?}", callee, instance);
|
||||
if let Ok(Some(func)) = instance {
|
||||
if let InstanceDef::Item(def) = func.def {
|
||||
callee = def.did;
|
||||
callee = def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -364,9 +364,8 @@ where
|
|||
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
|
||||
|
||||
// Don't peek inside trait associated constants.
|
||||
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
|
||||
assert_eq!(def.const_param_did, None, "expected associated const: {def:?}");
|
||||
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def.did);
|
||||
if promoted.is_none() && cx.tcx.trait_of_item(def).is_none() {
|
||||
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
|
||||
|
||||
if !Q::in_qualifs(&qualifs) {
|
||||
return false;
|
||||
|
|
|
@ -828,7 +828,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) -> Body<'tcx> {
|
||||
let def = self.source.source.with_opt_param();
|
||||
let def = self.source.source.def_id();
|
||||
let mut rvalue = {
|
||||
let promoted = &mut self.promoted;
|
||||
let promoted_id = Promoted::new(next_promoted_id);
|
||||
|
@ -836,7 +836,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
let mut promoted_operand = |ty, span| {
|
||||
promoted.span = span;
|
||||
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
|
||||
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did));
|
||||
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def));
|
||||
let uneval = mir::UnevaluatedConst { def, substs, promoted: Some(promoted_id) };
|
||||
|
||||
Operand::Constant(Box::new(Constant {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue