Skip to content

Commit 02fa3f0

Browse files
authored
Merge pull request #1586 from Nadrieril/impl-implied-outlives
Keep inherent impl headers around, they add implied bounds
2 parents 7f093eb + ebc2763 commit 02fa3f0

15 files changed

Lines changed: 84 additions & 7 deletions

File tree

‎charon-ml/src/CharonVersion.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* This is an automatically generated file, generated from `charon/Cargo.toml`. *)
22
(* To re-generate this file, rune `make` in the root directory *)
3-
let supported_charon_version = "0.1.304"
3+
let supported_charon_version = "0.1.305"

‎charon-ml/src/generated/Generated_GAst.ml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ and fun_source =
262262
| NormalFun (** A normal function. *)
263263
| AdtConstructorFun
264264
(** A synthetic function representing an ADT constructor. *)
265+
| InherentImplFun of ty
266+
(** A method in an inherent implementation.
267+
268+
Fields:
269+
- [self_ty]: The self type of the impl block. *)
265270
| TraitDefaultFun of trait_decl_ref * trait_method_id
266271
(** A default method in a trait declaration.
267272

‎charon-ml/src/generated/Generated_OfJson.ml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,6 +3046,9 @@ and fun_source_of_json (ctx : of_json_ctx) (js : json) :
30463046
(match js with
30473047
| `String "Normal" -> Ok NormalFun
30483048
| `String "AdtConstructor" -> Ok AdtConstructorFun
3049+
| `Assoc [ ("InherentImpl", `Assoc [ ("self_ty", self_ty) ]) ] ->
3050+
let* self_ty = ty_of_json ctx self_ty in
3051+
Ok (InherentImplFun self_ty)
30493052
| `Assoc
30503053
[
30513054
( "TraitDefault",

‎charon-ml/src/generated/Generated_OfPostcard.ml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,20 +2511,23 @@ and fun_source_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
25112511
| 0 -> Ok NormalFun
25122512
| 1 -> Ok AdtConstructorFun
25132513
| 2 ->
2514+
let* self_ty = ty_of_postcard ctx st in
2515+
Ok (InherentImplFun self_ty)
2516+
| 3 ->
25142517
let* trait_ref = trait_decl_ref_of_postcard ctx st in
25152518
let* item_id = trait_method_id_of_postcard ctx st in
25162519
Ok (TraitDefaultFun (trait_ref, item_id))
2517-
| 3 ->
2520+
| 4 ->
25182521
let* impl_ref = trait_impl_ref_of_postcard ctx st in
25192522
let* trait_ref = trait_decl_ref_of_postcard ctx st in
25202523
let* item_id = trait_method_id_of_postcard ctx st in
25212524
let* reuses_default = bool_of_postcard ctx st in
25222525
Ok (TraitImplFun (impl_ref, trait_ref, item_id, reuses_default))
2523-
| 4 -> Ok VTableShimFun
2524-
| 5 ->
2526+
| 5 -> Ok VTableShimFun
2527+
| 6 ->
25252528
let* _0 = global_decl_ref_of_postcard ctx st in
25262529
Ok (GlobalInitializerFun _0)
2527-
| 6 ->
2530+
| 7 ->
25282531
let* dispatcher = fun_decl_ref_of_postcard ctx st in
25292532
Ok (TargetDependentFun dispatcher)
25302533
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))

‎charon/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charon/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tracing = { version = "0.1", features = ["max_level_trace"] }
2828

2929
[package]
3030
name = "charon"
31-
version = "0.1.304"
31+
version = "0.1.305"
3232
authors.workspace = true
3333
edition.workspace = true
3434
license.workspace = true

‎charon/src/ast/items/fun_decl.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub enum FunSource {
5656
Normal,
5757
/// A synthetic function representing an ADT constructor.
5858
AdtConstructor,
59+
/// A method in an inherent implementation.
60+
InherentImpl {
61+
/// The self type of the impl block.
62+
self_ty: Ty,
63+
},
5964
/// A default method in a trait declaration.
6065
TraitDefault {
6166
/// The trait declaration this item belongs to.

‎charon/src/bin/charon-driver/hax/types/traits.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ impl<'tcx> AssocItem<'tcx> {
8080
}
8181
ty::AssocContainer::InherentImpl => AssocItemContainer::InherentImplContainer {
8282
impl_id: container_id.sinto(s),
83+
self_ty: inst_binder(
84+
tcx,
85+
s.typing_env(),
86+
Some(container_args),
87+
tcx.type_of(container_id),
88+
)
89+
.sinto(s),
8390
},
8491
};
8592
let name = match item.opt_name() {
@@ -152,6 +159,8 @@ pub enum AssocItemContainer<'tcx> {
152159
},
153160
InherentImplContainer {
154161
impl_id: DefId,
162+
/// The self type instantiated with this associated item's arguments.
163+
self_ty: Ty<'tcx>,
155164
},
156165
}
157166

‎charon/src/bin/charon-driver/translate/translate_items.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ impl<'tcx> ItemTransCtx<'tcx, '_> {
512512
})
513513
} else if matches!(def.kind(), hax::FullDefKind::Ctor(_)) {
514514
FunSource::AdtConstructor
515+
} else if let hax::FullDefKind::AssocFn(f) = def.kind()
516+
&& let hax::AssocItemContainer::InherentImplContainer { self_ty, .. } =
517+
&f.associated_item().container
518+
{
519+
FunSource::InherentImpl {
520+
self_ty: self.translate_ty(span, self_ty)?,
521+
}
515522
} else {
516523
match self.get_trait_item_source(span, def)? {
517524
None => FunSource::Normal,

‎charon/src/transform/add_missing_info/add_implied_outlives.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ impl TransformPass for Transform {
222222
for fun_decl in &mut ctx.translated.fun_decls {
223223
let mut visitor = OutlivesGatherer::new(&mut fun_decl.generics, type_decls);
224224
visitor.visit(&mut fun_decl.signature);
225+
if let FunSource::InherentImpl { self_ty } = &mut fun_decl.src {
226+
// The inherent impl header contributes to the implied bounds even if that type is
227+
// not mentioned in the signature.
228+
visitor.visit(self_ty);
229+
}
225230
visitor.finish();
226231
}
227232

0 commit comments

Comments
 (0)