|
1 | 1 | use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
2 | 2 | use crate::middle::lang_items::DropInPlaceFnLangItem;
|
3 |
| -use crate::traits; |
4 | 3 | use crate::ty::print::{FmtPrinter, Printer};
|
5 | 4 | use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
|
| 5 | +use rustc_data_structures::AtomicRef; |
6 | 6 | use rustc_hir::def::Namespace;
|
7 | 7 | use rustc_hir::def_id::{CrateNum, DefId};
|
8 | 8 | use rustc_macros::HashStable;
|
9 |
| -use rustc_target::spec::abi::Abi; |
10 | 9 |
|
11 | 10 | use std::fmt;
|
12 | 11 |
|
@@ -263,45 +262,7 @@ impl<'tcx> Instance<'tcx> {
|
263 | 262 | def_id: DefId,
|
264 | 263 | substs: SubstsRef<'tcx>,
|
265 | 264 | ) -> Option<Instance<'tcx>> {
|
266 |
| - debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); |
267 |
| - let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { |
268 |
| - debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env); |
269 |
| - let item = tcx.associated_item(def_id); |
270 |
| - resolve_associated_item(tcx, &item, param_env, trait_def_id, substs) |
271 |
| - } else { |
272 |
| - let ty = tcx.type_of(def_id); |
273 |
| - let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, &ty); |
274 |
| - |
275 |
| - let def = match item_type.kind { |
276 |
| - ty::FnDef(..) |
277 |
| - if { |
278 |
| - let f = item_type.fn_sig(tcx); |
279 |
| - f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic |
280 |
| - } => |
281 |
| - { |
282 |
| - debug!(" => intrinsic"); |
283 |
| - ty::InstanceDef::Intrinsic(def_id) |
284 |
| - } |
285 |
| - _ => { |
286 |
| - if Some(def_id) == tcx.lang_items().drop_in_place_fn() { |
287 |
| - let ty = substs.type_at(0); |
288 |
| - if ty.needs_drop(tcx, param_env.with_reveal_all()) { |
289 |
| - debug!(" => nontrivial drop glue"); |
290 |
| - ty::InstanceDef::DropGlue(def_id, Some(ty)) |
291 |
| - } else { |
292 |
| - debug!(" => trivial drop glue"); |
293 |
| - ty::InstanceDef::DropGlue(def_id, None) |
294 |
| - } |
295 |
| - } else { |
296 |
| - debug!(" => free item"); |
297 |
| - ty::InstanceDef::Item(def_id) |
298 |
| - } |
299 |
| - } |
300 |
| - }; |
301 |
| - Some(Instance { def: def, substs: substs }) |
302 |
| - }; |
303 |
| - debug!("resolve(def_id={:?}, substs={:?}) = {:?}", def_id, substs, result); |
304 |
| - result |
| 265 | + (*RESOLVE_INSTANCE)(tcx, param_env, def_id, substs) |
305 | 266 | }
|
306 | 267 |
|
307 | 268 | pub fn resolve_for_fn_ptr(
|
@@ -398,88 +359,6 @@ impl<'tcx> Instance<'tcx> {
|
398 | 359 | }
|
399 | 360 | }
|
400 | 361 |
|
401 |
| -fn resolve_associated_item<'tcx>( |
402 |
| - tcx: TyCtxt<'tcx>, |
403 |
| - trait_item: &ty::AssocItem, |
404 |
| - param_env: ty::ParamEnv<'tcx>, |
405 |
| - trait_id: DefId, |
406 |
| - rcvr_substs: SubstsRef<'tcx>, |
407 |
| -) -> Option<Instance<'tcx>> { |
408 |
| - let def_id = trait_item.def_id; |
409 |
| - debug!( |
410 |
| - "resolve_associated_item(trait_item={:?}, \ |
411 |
| - param_env={:?}, \ |
412 |
| - trait_id={:?}, \ |
413 |
| - rcvr_substs={:?})", |
414 |
| - def_id, param_env, trait_id, rcvr_substs |
415 |
| - ); |
416 |
| - |
417 |
| - let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); |
418 |
| - let vtbl = tcx.codegen_fulfill_obligation((param_env, ty::Binder::bind(trait_ref))); |
419 |
| - |
420 |
| - // Now that we know which impl is being used, we can dispatch to |
421 |
| - // the actual function: |
422 |
| - match vtbl { |
423 |
| - traits::VtableImpl(impl_data) => { |
424 |
| - let (def_id, substs) = |
425 |
| - traits::find_associated_item(tcx, param_env, trait_item, rcvr_substs, &impl_data); |
426 |
| - |
427 |
| - let resolved_item = tcx.associated_item(def_id); |
428 |
| - |
429 |
| - // Since this is a trait item, we need to see if the item is either a trait default item |
430 |
| - // or a specialization because we can't resolve those unless we can `Reveal::All`. |
431 |
| - // NOTE: This should be kept in sync with the similar code in |
432 |
| - // `rustc::traits::project::assemble_candidates_from_impls()`. |
433 |
| - let eligible = if !resolved_item.defaultness.is_default() { |
434 |
| - true |
435 |
| - } else if param_env.reveal == traits::Reveal::All { |
436 |
| - !trait_ref.needs_subst() |
437 |
| - } else { |
438 |
| - false |
439 |
| - }; |
440 |
| - |
441 |
| - if !eligible { |
442 |
| - return None; |
443 |
| - } |
444 |
| - |
445 |
| - let substs = tcx.erase_regions(&substs); |
446 |
| - Some(ty::Instance::new(def_id, substs)) |
447 |
| - } |
448 |
| - traits::VtableGenerator(generator_data) => Some(Instance { |
449 |
| - def: ty::InstanceDef::Item(generator_data.generator_def_id), |
450 |
| - substs: generator_data.substs, |
451 |
| - }), |
452 |
| - traits::VtableClosure(closure_data) => { |
453 |
| - let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap(); |
454 |
| - Some(Instance::resolve_closure( |
455 |
| - tcx, |
456 |
| - closure_data.closure_def_id, |
457 |
| - closure_data.substs, |
458 |
| - trait_closure_kind, |
459 |
| - )) |
460 |
| - } |
461 |
| - traits::VtableFnPointer(ref data) => Some(Instance { |
462 |
| - def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty), |
463 |
| - substs: rcvr_substs, |
464 |
| - }), |
465 |
| - traits::VtableObject(ref data) => { |
466 |
| - let index = traits::get_vtable_index_of_object_method(tcx, data, def_id); |
467 |
| - Some(Instance { def: ty::InstanceDef::Virtual(def_id, index), substs: rcvr_substs }) |
468 |
| - } |
469 |
| - traits::VtableBuiltin(..) => { |
470 |
| - if tcx.lang_items().clone_trait().is_some() { |
471 |
| - Some(Instance { |
472 |
| - def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()), |
473 |
| - substs: rcvr_substs, |
474 |
| - }) |
475 |
| - } else { |
476 |
| - None |
477 |
| - } |
478 |
| - } |
479 |
| - traits::VtableAutoImpl(..) | traits::VtableParam(..) | traits::VtableTraitAlias(..) => None, |
480 |
| - } |
481 |
| -} |
482 |
| - |
483 | 362 | fn needs_fn_once_adapter_shim(
|
484 | 363 | actual_closure_kind: ty::ClosureKind,
|
485 | 364 | trait_closure_kind: ty::ClosureKind,
|
@@ -512,3 +391,21 @@ fn needs_fn_once_adapter_shim(
|
512 | 391 | (ty::ClosureKind::FnMut, _) | (ty::ClosureKind::FnOnce, _) => Err(()),
|
513 | 392 | }
|
514 | 393 | }
|
| 394 | + |
| 395 | +fn resolve_instance_default( |
| 396 | + _tcx: TyCtxt<'tcx>, |
| 397 | + _param_env: ty::ParamEnv<'tcx>, |
| 398 | + _def_id: DefId, |
| 399 | + _substs: SubstsRef<'tcx>, |
| 400 | +) -> Option<Instance<'tcx>> { |
| 401 | + unimplemented!() |
| 402 | +} |
| 403 | + |
| 404 | +pub static RESOLVE_INSTANCE: AtomicRef< |
| 405 | + for<'tcx> fn( |
| 406 | + TyCtxt<'tcx>, |
| 407 | + ty::ParamEnv<'tcx>, |
| 408 | + DefId, |
| 409 | + SubstsRef<'tcx>, |
| 410 | + ) -> Option<Instance<'tcx>>, |
| 411 | +> = AtomicRef::new(&(resolve_instance_default as _)); |
0 commit comments