Skip to content

Commit 74a9293

Browse files
committed
Address comments
1 parent 0a6fa34 commit 74a9293

File tree

10 files changed

+28
-37
lines changed

10 files changed

+28
-37
lines changed

creusot-contracts/src/invariant.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ impl<T> UserInv for T {
4444
}
4545
}
4646

47-
impl UserInv for i32 {
48-
#[predicate]
49-
#[open]
50-
fn user_inv(self) -> bool {
51-
pearlite! { self@ > 0 }
52-
}
53-
}
54-
5547
impl<'a, T: Invariant + ?Sized> Invariant for &'a T {
5648
#[predicate]
5749
#[open]

creusot/src/backend/clone_map.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,7 @@ impl<'tcx> CloneInfo {
210210
}
211211

212212
impl<'tcx> CloneMap<'tcx> {
213-
pub(crate) fn new(tcx: TyCtxt<'tcx>, self_id: DefId, clone_level: CloneLevel) -> Self {
214-
Self::new_with_tid(tcx, TransId::Item(self_id), clone_level)
215-
}
216-
217-
pub(crate) fn new_with_tid(
218-
tcx: TyCtxt<'tcx>,
219-
self_id: TransId,
220-
clone_level: CloneLevel,
221-
) -> Self {
213+
pub(crate) fn new(tcx: TyCtxt<'tcx>, self_id: TransId, clone_level: CloneLevel) -> Self {
222214
let mut names = IndexMap::new();
223215

224216
let self_id = match self_id {
@@ -233,7 +225,7 @@ impl<'tcx> CloneMap<'tcx> {
233225

234226
CloneNode::new(tcx, (self_id, subst)).erase_regions(tcx)
235227
}
236-
TransId::TyInv(inv_kind) => CloneNode::TyInv(inv_kind.to_ty(tcx)),
228+
TransId::TyInv(inv_kind) => CloneNode::TyInv(inv_kind.to_skeleton_ty(tcx)),
237229
};
238230

239231
debug!("cloning self: {:?}", self_id);
@@ -295,8 +287,7 @@ impl<'tcx> CloneMap<'tcx> {
295287
};
296288
}
297289

298-
let base = if let CloneNode::TyInv(ty) = key {
299-
let inv_kind = TyInvKind::from_ty(ty);
290+
let base = if let Some(inv_kind) = key.ty_inv_kind() {
300291
Symbol::intern(&*inv_module_name(self.tcx, inv_kind))
301292
} else {
302293
let did = key.did().unwrap().0;
@@ -457,7 +448,7 @@ impl<'tcx> CloneMap<'tcx> {
457448
}
458449

459450
let inv_kind = TyInvKind::from_ty(ty);
460-
if let CloneNode::TyInv(self_ty) = self.self_id && TyInvKind::from_ty(self_ty) == inv_kind {
451+
if self.self_id.ty_inv_kind().is_some_and(|self_kind| self_kind == inv_kind) {
461452
return;
462453
}
463454

creusot/src/backend/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'tcx> Why3Generator<'tcx> {
2828
let param_env = self.param_env(def_id);
2929
let span = self.def_span(def_id);
3030
let res = from_ty_const(&mut self.ctx, constant, param_env, span);
31-
let mut names = CloneMap::new(self.tcx, def_id, CloneLevel::Body);
31+
let mut names = CloneMap::new(self.tcx, def_id.into(), CloneLevel::Body);
3232
let res = res.to_why(self, &mut names, &LocalDecls::new());
3333
let sig = signature_of(self, &mut names, def_id);
3434
let mut decls: Vec<_> = closure_generic_decls(self.tcx, def_id).collect();

creusot/src/backend/dependency.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
util::{self, ItemType},
1010
};
1111

12-
use super::ty_inv;
12+
use super::ty_inv::{self, TyInvKind};
1313

1414
/// Dependencies between items and the resolution logic to find the 'monomorphic' forms accounting
1515
/// for various Creusot hacks like the handling of closures.
@@ -57,6 +57,14 @@ impl<'tcx> Dependency<'tcx> {
5757
}
5858
}
5959

60+
pub(crate) fn ty_inv_kind(self) -> Option<TyInvKind> {
61+
if let Dependency::TyInv(ty) = self {
62+
Some(TyInvKind::from_ty(ty))
63+
} else {
64+
None
65+
}
66+
}
67+
6068
pub(crate) fn is_inv(&self) -> bool {
6169
matches!(self, Dependency::TyInv(_))
6270
}

creusot/src/backend/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn interface_for<'tcx>(
2121
def_id: DefId,
2222
) -> (Module, CloneSummary<'tcx>) {
2323
debug!("interface_for: {def_id:?}");
24-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Stub);
24+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Stub);
2525
let mut sig = signature_of(ctx, &mut names, def_id);
2626

2727
sig.contract.variant = Vec::new();

creusot/src/backend/logic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn builtin_body<'tcx>(
6565
ctx: &mut Why3Generator<'tcx>,
6666
def_id: DefId,
6767
) -> (Module, CloneSummary<'tcx>) {
68-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Stub);
68+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Stub);
6969
let mut sig = signature_of(ctx, &mut names, def_id);
7070
let (val_args, val_binders) = binders_to_args(ctx, sig.args);
7171
sig.args = val_binders;
@@ -133,7 +133,7 @@ pub(crate) fn val_decl<'tcx>(
133133
}
134134

135135
fn body_module<'tcx>(ctx: &mut Why3Generator<'tcx>, def_id: DefId) -> (Module, CloneSummary<'tcx>) {
136-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Stub);
136+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Stub);
137137

138138
let mut sig = signature_of(ctx, &mut names, def_id);
139139
let mut val_sig = sig.clone();
@@ -198,7 +198,7 @@ fn body_module<'tcx>(ctx: &mut Why3Generator<'tcx>, def_id: DefId) -> (Module, C
198198
}
199199

200200
pub(crate) fn stub_module(ctx: &mut Why3Generator, def_id: DefId) -> Module {
201-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Stub);
201+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Stub);
202202
let mut sig = signature_of(ctx, &mut names, def_id);
203203

204204
if util::is_predicate(ctx.tcx, def_id) {
@@ -225,7 +225,7 @@ fn proof_module(ctx: &mut Why3Generator, def_id: DefId) -> Option<Module> {
225225
return None;
226226
}
227227

228-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Body);
228+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Body);
229229

230230
let mut sig = signature_of(ctx, &mut names, def_id);
231231

creusot/src/backend/program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use why3::{
3737
use super::signature::sig_to_why3;
3838

3939
fn closure_ty<'tcx>(ctx: &mut Why3Generator<'tcx>, def_id: DefId) -> Module {
40-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Body);
40+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Body);
4141
let mut decls = Vec::new();
4242

4343
let TyKind::Closure(_, subst) = ctx.tcx.type_of(def_id).subst_identity().kind() else { unreachable!() };
@@ -152,7 +152,7 @@ pub(crate) fn translate_function<'tcx, 'sess>(
152152
def_id: DefId,
153153
) -> Option<Module> {
154154
let tcx = ctx.tcx;
155-
let mut names = CloneMap::new(tcx, def_id, CloneLevel::Body);
155+
let mut names = CloneMap::new(tcx, def_id.into(), CloneLevel::Body);
156156

157157
let body_ids = collect_body_ids(ctx, def_id)?;
158158
let body = to_why(ctx, &mut names, body_ids[0]);

creusot/src/backend/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn lower_impl<'tcx>(ctx: &mut Why3Generator<'tcx>, def_id: DefId) ->
1616
let tcx = ctx.tcx;
1717
let data = ctx.trait_impl(def_id).clone();
1818

19-
let mut names = CloneMap::new(ctx.tcx, def_id, CloneLevel::Body);
19+
let mut names = CloneMap::new(ctx.tcx, def_id.into(), CloneLevel::Body);
2020

2121
let mut impl_decls = Vec::new();
2222
for refn in &data.refinements {
@@ -41,7 +41,7 @@ impl<'tcx> Why3Generator<'tcx> {
4141
pub(crate) fn translate_assoc_ty(&mut self, def_id: DefId) -> (Module, CloneSummary<'tcx>) {
4242
assert_eq!(util::item_type(self.tcx, def_id), ItemType::AssocTy);
4343

44-
let mut names = CloneMap::new(self.tcx, def_id, CloneLevel::Interface);
44+
let mut names = CloneMap::new(self.tcx, def_id.into(), CloneLevel::Interface);
4545

4646
let mut decls: Vec<_> = all_generic_decls_for(self.tcx, def_id).collect();
4747
let name = item_name(self.tcx, def_id, Namespace::TypeNS);

creusot/src/backend/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub(crate) fn translate_tydecl(
291291
return None;
292292
}
293293

294-
let mut names = CloneMap::new(ctx.tcx, repr, CloneLevel::Stub);
294+
let mut names = CloneMap::new(ctx.tcx, repr.into(), CloneLevel::Stub);
295295

296296
let name = module_name(ctx.tcx, repr);
297297
let span = ctx.def_span(repr);
@@ -432,7 +432,7 @@ pub(crate) fn translate_accessor(
432432

433433
let substs = InternalSubsts::identity_for_item(ctx.tcx, adt_did);
434434
let repr = ctx.representative_type(adt_did);
435-
let mut names = CloneMap::new(ctx.tcx, repr, CloneLevel::Stub);
435+
let mut names = CloneMap::new(ctx.tcx, repr.into(), CloneLevel::Stub);
436436

437437
// UGLY hack to ensure that we don't explicitly use/clone the members of a binding group
438438
let bg = ctx.binding_group(repr).clone();

creusot/src/backend/ty_inv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl TyInvKind {
3838
}
3939
}
4040

41-
pub(crate) fn to_ty<'tcx>(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
41+
pub(crate) fn to_skeleton_ty<'tcx>(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
4242
match self {
4343
TyInvKind::Trivial => tcx.mk_ty_param(0, Symbol::intern("T")),
4444
TyInvKind::Borrow => {
@@ -82,7 +82,7 @@ pub(crate) fn build_inv_module<'tcx>(
8282
ctx: &mut Why3Generator<'tcx>,
8383
inv_kind: TyInvKind,
8484
) -> (Module, CloneSummary<'tcx>) {
85-
let mut names = CloneMap::new_with_tid(ctx.tcx, TransId::TyInv(inv_kind), CloneLevel::Stub);
85+
let mut names = CloneMap::new(ctx.tcx, TransId::TyInv(inv_kind), CloneLevel::Stub);
8686
let generics = inv_kind.generics(ctx.tcx);
8787
let inv_axiom = build_inv_axiom(ctx, &mut names, inv_kind);
8888

@@ -119,7 +119,7 @@ fn build_inv_axiom<'tcx>(
119119
let param_env =
120120
if let TyInvKind::Adt(did) = inv_kind { ctx.param_env(did) } else { ParamEnv::empty() };
121121

122-
let ty = inv_kind.to_ty(ctx.tcx);
122+
let ty = inv_kind.to_skeleton_ty(ctx.tcx);
123123
let lhs: Exp = Exp::impure_qvar(names.ty_inv(ty)).app_to(Exp::pure_var("self".into()));
124124
let rhs = if TyInvKind::Trivial == inv_kind {
125125
Exp::mk_true()

0 commit comments

Comments
 (0)