Skip to content

Commit 475d82a

Browse files
committed
Remove ParamTypeMapper and stop relaying TypeBuilder
1 parent 26dbb9d commit 475d82a

5 files changed

Lines changed: 4 additions & 56 deletions

File tree

src/analyze.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ impl<'tcx> Analyzer<'tcx> {
243243
def_id: DefId,
244244
generic_args: mir_ty::GenericArgsRef<'tcx>,
245245
) -> Option<rty::RefinedType> {
246-
let type_builder = TypeBuilder::new(self.tcx, def_id);
247-
248246
let deferred_ty = match self.defs.get(&def_id)? {
249247
DefTy::Concrete(rty) => {
248+
let type_builder = TypeBuilder::new(self.tcx, def_id);
249+
250250
let mut def_ty = rty.clone();
251251
def_ty.instantiate_ty_params(
252252
generic_args
@@ -266,9 +266,7 @@ impl<'tcx> Analyzer<'tcx> {
266266
}
267267

268268
let mut analyzer = self.local_def_analyzer(def_id.as_local()?);
269-
analyzer
270-
.type_builder(type_builder)
271-
.generic_args(generic_args);
269+
analyzer.generic_args(generic_args);
272270

273271
let expected = analyzer.expected_ty();
274272
deferred_ty_cache

src/analyze/basic_block.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
983983
self
984984
}
985985

986-
pub fn type_builder(&mut self, type_builder: TypeBuilder<'tcx>) -> &mut Self {
987-
self.type_builder = type_builder;
988-
self
989-
}
990-
991986
pub fn run(&mut self, expected: &BasicBlockType) {
992987
let span = tracing::info_span!("bb", bb = ?self.basic_block);
993988
let _guard = span.enter();

src/analyze/crate_.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
7676

7777
// check polymorphic function def by replacing type params with some opaque type
7878
// (and this is no-op if the function is mono)
79-
let type_builder = TypeBuilder::new(self.tcx, local_def_id.to_def_id());
8079
let mut expected = expected.clone();
8180
let subst = rty::TypeParamSubst::new(
8281
expected
@@ -89,7 +88,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
8988
let generic_args = self.placeholder_generic_args(*local_def_id);
9089
self.ctx
9190
.local_def_analyzer(*local_def_id)
92-
.type_builder(type_builder)
9391
.generic_args(generic_args)
9492
.run(&expected);
9593
}

src/analyze/local_def.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
533533
.basic_block_analyzer(self.local_def_id, bb)
534534
.body(self.body.clone())
535535
.drop_points(drop_points)
536-
.type_builder(self.type_builder.clone())
537536
.run(&rty);
538537
}
539538
}
@@ -650,11 +649,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
650649
}
651650
}
652651

653-
pub fn type_builder(&mut self, type_builder: TypeBuilder<'tcx>) -> &mut Self {
654-
self.type_builder = type_builder;
655-
self
656-
}
657-
658652
pub fn generic_args(&mut self, generic_args: mir_ty::GenericArgsRef<'tcx>) -> &mut Self {
659653
self.body =
660654
mir_ty::EarlyBinder::bind(self.body.clone()).instantiate(self.tcx, generic_args);

src/refine/template.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,6 @@ where
5959
}
6060
}
6161

62-
trait ParamTypeMapper {
63-
fn map_param_ty(&self, ty: rty::ParamType) -> rty::Type<rty::Closed>;
64-
}
65-
66-
impl<F> ParamTypeMapper for F
67-
where
68-
F: Fn(rty::ParamType) -> rty::Type<rty::Closed>,
69-
{
70-
fn map_param_ty(&self, ty: rty::ParamType) -> rty::Type<rty::Closed> {
71-
self(ty)
72-
}
73-
}
74-
7562
/// Translates [`mir_ty::Ty`] to [`rty::Type`].
7663
///
7764
/// This struct implements a translation from Rust MIR types to Thrust types.
@@ -87,9 +74,6 @@ pub struct TypeBuilder<'tcx> {
8774
/// mapped when we translate a [`mir_ty::ParamTy`] to [`rty::ParamType`].
8875
/// See [`rty::TypeParamIdx`] for more details.
8976
param_idx_mapping: HashMap<u32, rty::TypeParamIdx>,
90-
/// Optionally also want to further map rty::ParamType to other rty::Type before generating
91-
/// templates. This is no-op by default.
92-
param_type_mapper: std::rc::Rc<dyn ParamTypeMapper>,
9377
}
9478

9579
impl<'tcx> TypeBuilder<'tcx> {
@@ -109,25 +93,15 @@ impl<'tcx> TypeBuilder<'tcx> {
10993
Self {
11094
tcx,
11195
param_idx_mapping,
112-
param_type_mapper: std::rc::Rc::new(|ty: rty::ParamType| ty.into()),
11396
}
11497
}
11598

116-
pub fn with_param_mapper<F>(mut self, mapper: F) -> Self
117-
where
118-
F: Fn(rty::ParamType) -> rty::Type<rty::Closed> + 'static,
119-
{
120-
self.param_type_mapper = std::rc::Rc::new(mapper);
121-
self
122-
}
123-
12499
fn translate_param_type(&self, ty: &mir_ty::ParamTy) -> rty::Type<rty::Closed> {
125100
let index = *self
126101
.param_idx_mapping
127102
.get(&ty.index)
128103
.expect("unknown type param idx");
129-
let param_ty = rty::ParamType::new(index);
130-
self.param_type_mapper.map_param_ty(param_ty)
104+
rty::ParamType::new(index).into()
131105
}
132106

133107
// TODO: consolidate two impls
@@ -400,17 +374,6 @@ impl<'tcx, 'a, R> FunctionTemplateTypeBuilder<'tcx, 'a, R> {
400374
self.ret_rty = Some(rty);
401375
self
402376
}
403-
404-
pub fn would_contain_template(&self) -> bool {
405-
if self.param_tys.is_empty() {
406-
return self.ret_rty.is_none();
407-
}
408-
409-
let last_param_idx = rty::FunctionParamIdx::from(self.param_tys.len() - 1);
410-
let param_annotated =
411-
self.param_refinement.is_some() || self.param_rtys.contains_key(&last_param_idx);
412-
self.ret_rty.is_none() || !param_annotated
413-
}
414377
}
415378

416379
impl<'tcx, 'a, R> FunctionTemplateTypeBuilder<'tcx, 'a, R>

0 commit comments

Comments
 (0)