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

Engine: F*: open modules providing trait impls #676

Merged
merged 2 commits into from
May 22, 2024
Merged

Conversation

W95Psp
Copy link
Collaborator

@W95Psp W95Psp commented May 16, 2024

The PR fixes 667.

Consider the following Rust module:

mod trait_definition {
    pub trait MyTrait {
        fn my_method(self);
    }
}
mod define_type {
    pub struct MyType;
}
mod impl_type {
    impl super::trait_definition::MyTrait for super::define_type::MyType {
        fn my_method(self) {}
    }
}
mod use_type {
    fn some_function(x: super::define_type::MyType) {
        use super::trait_definition::MyTrait;
        x.my_method()
    }
}

The point here is that the type MyType, the trait MyTrait, the impl of MyTrait for MyType and the call to my_method are in four different modules.

Thus, in the module use_type, the module impl_type is never explicitly mentioned: in F* this results in the module impl_type to not be loaded at all by F*, which in turn, implies that the instance (the impl) is not in scope. Thus, the F* mechanism for resolving the instance of the typeclass MyTrait fails.

With this PR, extracting this crate, you will get the following for module use_type:

module Use_type
#set-options "--fuel 0 --ifuel 1 --z3rlimit 15"
open Core
open FStar.Mul

let _ =
  (* This module has implicit dependencies, here we make them explicit. *)
  (* The implicit dependencies arise from typeclasses instances. *)
  let open Impl_type in
  ()

let some_function (x: Define_type.t_MyType) : unit = Trait_definition.f_my_method x

@W95Psp W95Psp force-pushed the fix-667 branch 2 times, most recently from 528c7ee to f7193f6 Compare May 16, 2024 08:09
@W95Psp W95Psp added this pull request to the merge queue May 22, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2024
W95Psp added a commit to cryspen/libcrux that referenced this pull request May 22, 2024
@W95Psp
Copy link
Collaborator Author

W95Psp commented May 22, 2024

This PR fails due to Kyber extraction that changes slightly: cryspen/libcrux#288

franziskuskiefer added a commit to cryspen/libcrux that referenced this pull request May 22, 2024
@franziskuskiefer franziskuskiefer added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit acae1cf May 22, 2024
13 checks passed
@franziskuskiefer franziskuskiefer deleted the fix-667 branch May 22, 2024 18:54
W95Psp added a commit to cryspen/libcrux that referenced this pull request May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

F*: typeclass instances not found because not in scope
3 participants