Skip to content

Commit fdf13b8

Browse files
committed
change: store the def_id of the corresponding function in TypeBuilder
1 parent e855440 commit fdf13b8

5 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/analyze.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,16 @@ impl<'tcx> Analyzer<'tcx> {
547547
&mut self,
548548
local_def_id: LocalDefId,
549549
bb: BasicBlock,
550+
owner_fn_id: DefId
550551
) -> basic_block::Analyzer<'tcx, '_> {
551-
basic_block::Analyzer::new(self, local_def_id, bb)
552+
basic_block::Analyzer::new(self, local_def_id, bb, owner_fn_id)
552553
}
553554

554-
pub fn type_builder(&self, def_ids: DefIdCache<'tcx>, def_id: DefId) -> TypeBuilder<'tcx> {
555+
pub fn type_builder(&self, def_ids: DefIdCache<'tcx>, owner_fn_id: DefId) -> TypeBuilder<'tcx> {
555556
TypeBuilder::new(
556557
self.tcx,
557558
def_ids,
558-
def_id,
559+
owner_fn_id,
559560
self.type_params.clone(),
560561
self.system.clone(),
561562
)

src/analyze/basic_block.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,14 +1166,15 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
11661166
ctx: &'ctx mut analyze::Analyzer<'tcx>,
11671167
local_def_id: LocalDefId,
11681168
basic_block: BasicBlock,
1169+
owner_fn_id: DefId,
11691170
) -> Self {
11701171
let tcx = ctx.tcx;
11711172
let drop_points = DropPoints::default();
11721173
let body = Cow::Borrowed(tcx.optimized_mir(local_def_id.to_def_id()));
11731174
let env = ctx.new_env();
11741175
let local_decls = body.local_decls.clone();
11751176
let prophecy_vars = Default::default();
1176-
let type_builder = ctx.type_builder(ctx.def_ids(), local_def_id.to_def_id());
1177+
let type_builder = ctx.type_builder(ctx.def_ids(), owner_fn_id);
11771178
Self {
11781179
ctx,
11791180
tcx,

src/analyze/crate_.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
179179
let arg = match param.kind {
180180
mir_ty::GenericParamDefKind::Type { .. } => {
181181
if constrained_params.contains(&param.index) {
182-
mir_ty::Ty::new_param(self.tcx, param.index, param.name).into()
182+
let new_param =
183+
mir_ty::Ty::new_param(self.tcx, param.index, param.name).into();
184+
tracing::debug!(
185+
"replace the cosnstrained param {:#?} with the new param {:#?}.",
186+
param,
187+
new_param
188+
);
189+
new_param
183190
} else {
184191
self.tcx.types.i32.into()
185192
}

src/analyze/local_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
865865
let rty = self.ctx.basic_block_ty(self.local_def_id, bb).clone();
866866
let drop_points = self.drop_points[&bb].clone();
867867
self.ctx
868-
.basic_block_analyzer(self.local_def_id, bb)
868+
.basic_block_analyzer(self.local_def_id, bb, self.body.source.def_id())
869869
.body(self.body.clone())
870870
.drop_points(drop_points)
871871
.run(&rty);

src/refine/template.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
pub struct TypeBuilder<'tcx> {
7474
tcx: mir_ty::TyCtxt<'tcx>,
7575
def_ids: DefIdCache<'tcx>,
76-
def_id: DefId,
76+
owner_fn_id: DefId,
7777
typing_env: mir_ty::TypingEnv<'tcx>,
7878
type_params: Rc<RefCell<TypeParamMap>>,
7979
system: Rc<RefCell<chc::System>>,
@@ -83,15 +83,16 @@ impl<'tcx> TypeBuilder<'tcx> {
8383
pub fn new(
8484
tcx: mir_ty::TyCtxt<'tcx>,
8585
def_ids: DefIdCache<'tcx>,
86-
def_id: DefId,
86+
owner_fn_id: DefId,
8787
type_params: Rc<RefCell<TypeParamMap>>,
8888
system: Rc<RefCell<chc::System>>,
8989
) -> Self {
90-
let typing_env = mir_ty::TypingEnv::post_analysis(tcx, def_id);
90+
tracing::debug!("TypeBuilder is created for {owner_fn_id:?}.");
91+
let typing_env = mir_ty::TypingEnv::post_analysis(tcx, owner_fn_id);
9192
Self {
9293
tcx,
9394
def_ids,
94-
def_id,
95+
owner_fn_id,
9596
typing_env,
9697
type_params,
9798
system,
@@ -101,16 +102,29 @@ impl<'tcx> TypeBuilder<'tcx> {
101102
fn translate_param_type(&self, ty: &mir_ty::ParamTy) -> rty::Type<rty::Closed> {
102103
let mut type_params = self.type_params.borrow_mut();
103104
let index = type_params
104-
.entry(TypeParam::GenericType(self.def_id, ty.index))
105-
.or_insert_with(|| self.system.borrow_mut().new_forall_sort());
105+
.entry(TypeParam::GenericType(self.owner_fn_id, ty.index))
106+
.or_insert_with(|| {
107+
let idx = self.system.borrow_mut().new_forall_sort();
108+
tracing::debug!(
109+
"issue the new ForallSortIdx {} for ParamTy {:?} at {:?}.",
110+
idx,
111+
ty,
112+
self.owner_fn_id
113+
);
114+
idx
115+
});
106116
rty::ParamType::new(*index).into()
107117
}
108118

109119
fn translate_alias_type(&self, ty: &mir_ty::AliasTy) -> rty::Type<rty::Closed> {
110120
let mut type_params = self.type_params.borrow_mut();
111121
let index = type_params
112122
.entry(TypeParam::AssocType(ty.def_id))
113-
.or_insert_with(|| self.system.borrow_mut().new_forall_sort());
123+
.or_insert_with(|| {
124+
let idx = self.system.borrow_mut().new_forall_sort();
125+
tracing::debug!("issue the new ForallSortIdx {} for AliasTy {:#?}.", idx, ty);
126+
idx
127+
});
114128
rty::ParamType::new(*index).into()
115129
}
116130

0 commit comments

Comments
 (0)