Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine) Fix generic type constraints naming bug. #1182

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions engine/lib/ast_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ module Make (F : Features.T) = struct
((enabled, s) : bool * (string, string) Hashtbl.t) gc =
match gc with
| GCType { goal; name } when enabled ->
let data = "i" ^ Int.to_string (Hashtbl.length s) in
let _ = Hashtbl.add s ~key:name ~data in
GCType { goal; name = data }
let new_name =
Hashtbl.find_or_add s name ~default:(fun () ->
"i" ^ Int.to_string (Hashtbl.length s))
in
GCType { goal; name = new_name }
| _ -> super#visit_generic_constraint (enabled, s) gc

method! visit_trait_item (_, s) = super#visit_trait_item (true, s)
Expand Down
30 changes: 30 additions & 0 deletions test-harness/src/snapshots/toolchain__generics into-fstar.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ type t_Defaults (v_T: Type0) (v_N: usize) = | Defaults : t_Array v_T v_N -> t_De

let f (_: t_Defaults Prims.unit (sz 2)) : Prims.unit = ()
'''
"Generics.Impl_generics.fst" = '''
module Generics.Impl_generics
#set-options "--fuel 0 --ifuel 1 --z3rlimit 15"
open Core
open FStar.Mul

type t_Test = | Test : t_Test

let impl__Test__set_alpn_protocols
(#v_S #impl_995885649_: Type0)
(#[FStar.Tactics.Typeclasses.tcresolve ()] i2: Core.Convert.t_AsRef v_S string)
(#[FStar.Tactics.Typeclasses.tcresolve ()]
i3:
Core.Iter.Traits.Collect.t_IntoIterator impl_995885649_)
(self: t_Test)
(v__protocols: impl_995885649_)
: Core.Result.t_Result Prims.unit Prims.unit =
Core.Result.Result_Ok (() <: Prims.unit) <: Core.Result.t_Result Prims.unit Prims.unit

let impl__Test__set_ciphersuites
(#v_S #impl_995885649_: Type0)
(#[FStar.Tactics.Typeclasses.tcresolve ()] i2: Core.Convert.t_AsRef v_S string)
(#[FStar.Tactics.Typeclasses.tcresolve ()]
i3:
Core.Iter.Traits.Collect.t_IntoIterator impl_995885649_)
(self: t_Test)
(ciphers: impl_995885649_)
: Core.Result.t_Result Prims.unit Prims.unit =
Core.Result.Result_Ok (() <: Prims.unit) <: Core.Result.t_Result Prims.unit Prims.unit
'''
"Generics.fst" = '''
module Generics
#set-options "--fuel 0 --ifuel 1 --z3rlimit 15"
Expand Down
21 changes: 21 additions & 0 deletions tests/generics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,24 @@ mod defaults_generics {
struct Defaults<T = (), const N: usize = 2>([T; N]);
fn f(_: Defaults) {}
}

/// See https://github.com/hacspec/hax/issues/1176
mod impl_generics {
struct Test();

impl Test {
fn set_ciphersuites<S>(&self, ciphers: impl IntoIterator<Item = S>) -> Result<(), ()>
where
S: AsRef<str>,
{
Ok(())
}

fn set_alpn_protocols<S>(&self, _protocols: impl IntoIterator<Item = S>) -> Result<(), ()>
where
S: AsRef<str>,
{
Ok(())
}
}
}
Loading