|
1 |
| -use rustc_middle::traits; |
| 1 | +use rustc_index::vec::IndexVec; |
| 2 | +use rustc_middle::{traits, mir}; |
2 | 3 | use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
3 |
| -use rustc_middle::ty::{self, Ty, TyCtxt}; |
| 4 | +use rustc_middle::ty::{self, Ty, TyCtxt, Instance}; |
| 5 | +use rustc_middle::ty::query::Providers; |
| 6 | +use rustc_span::DUMMY_SP; |
4 | 7 |
|
5 | 8 | pub mod collector;
|
6 | 9 | pub mod partitioning;
|
7 | 10 |
|
| 11 | +pub fn provide(providers: &mut Providers<'_>) { |
| 12 | + providers.custom_intrinsic_mirgen = |_, _| { None }; |
| 13 | + providers.custom_intrinsic_mir = custom_intrinsic_mir; |
| 14 | +} |
| 15 | + |
| 16 | +fn custom_intrinsic_mir<'tcx>(tcx: TyCtxt<'tcx>, |
| 17 | + instance: Instance<'tcx>) |
| 18 | + -> Option<&'tcx mir::BodyAndCache<'tcx>> |
| 19 | +{ |
| 20 | + let mirgen = tcx.custom_intrinsic_mirgen(instance.def_id())?; |
| 21 | + |
| 22 | + let ty = instance.monomorphic_ty(tcx); |
| 23 | + let sig = ty.fn_sig(tcx); |
| 24 | + let sig = tcx.normalize_erasing_late_bound_regions( |
| 25 | + ty::ParamEnv::reveal_all(), |
| 26 | + &sig, |
| 27 | + ); |
| 28 | + |
| 29 | + // no var arg calls, so we can skip monomorphizing extra arguments. |
| 30 | + assert!(!sig.c_variadic); |
| 31 | + |
| 32 | + let source_scope_local_data = mir::ClearCrossCrate::Clear; |
| 33 | + let source_scope = mir::SourceScopeData { |
| 34 | + span: DUMMY_SP, |
| 35 | + parent_scope: None, |
| 36 | + local_data: source_scope_local_data, |
| 37 | + }; |
| 38 | + let source_info = mir::SourceInfo { |
| 39 | + span: DUMMY_SP, |
| 40 | + scope: mir::OUTERMOST_SOURCE_SCOPE, |
| 41 | + }; |
| 42 | + |
| 43 | + let mut source_scopes = IndexVec::new(); |
| 44 | + source_scopes.push(source_scope.clone()); |
| 45 | + |
| 46 | + let ret_decl = mir::LocalDecl::new_return_place(sig.output(), DUMMY_SP); |
| 47 | + let mut local_decls = IndexVec::from_elem_n(ret_decl, 1); |
| 48 | + for &arg in sig.inputs().iter() { |
| 49 | + local_decls.push(mir::LocalDecl { |
| 50 | + mutability: mir::Mutability::Mut, |
| 51 | + local_info: mir::LocalInfo::Other, |
| 52 | + ty: arg, |
| 53 | + source_info, |
| 54 | + internal: false, |
| 55 | + user_ty: mir::UserTypeProjections::none(), |
| 56 | + is_block_tail: None, |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + let gen = mir::Body::new(IndexVec::new(), |
| 61 | + source_scopes, |
| 62 | + local_decls, |
| 63 | + Default::default(), |
| 64 | + sig.inputs().len(), |
| 65 | + Vec::new(), |
| 66 | + source_scope.span, |
| 67 | + Vec::new(), |
| 68 | + None); |
| 69 | + let mut gen = mir::BodyAndCache::new(gen); |
| 70 | + |
| 71 | + mirgen.mirgen_simple_intrinsic(tcx, instance, &mut gen); |
| 72 | + gen.ensure_predecessors(); |
| 73 | + |
| 74 | + Some(tcx.arena.alloc(gen)) |
| 75 | +} |
| 76 | + |
8 | 77 | pub fn custom_coerce_unsize_info<'tcx>(
|
9 | 78 | tcx: TyCtxt<'tcx>,
|
10 | 79 | source_ty: Ty<'tcx>,
|
|
0 commit comments