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

Use implicit parameters in the generated code #333

Merged
merged 27 commits into from
Sep 9, 2024
Merged

Use implicit parameters in the generated code #333

merged 27 commits into from
Sep 9, 2024

Conversation

sonmarcho
Copy link
Member

The generated code now uses implicit type and const generic parameters.

For instance, the following code:

pub fn choose<'a, T>(b: bool, x: &'a mut T, y: &'a mut T) -> &'a mut T {
    if b {
        x
    } else {
        y
    }
}

now extracts to (the type T is now implicit):

def choose
  {T : Type} (b : Bool) (x : T) (y : T) :
  Result (T × (T → Result (T × T)))
  :=
  if b
  then let back := fun ret => Result.ok (ret, y)
       Result.ok (x, back)
  else let back := fun ret => Result.ok (x, ret)
       Result.ok (y, back)

The rule we are using is that any type or const generic parameter is implicit if it is referred by the trait clauses or the input values. Importantly, we ignore the output value. This means that the type parameter in Vec::new is still explicit, because it can't be inferred from the inputs:

def Vec.new (α : Type u): Vec α := ...

@sonmarcho sonmarcho marked this pull request as ready for review September 9, 2024 14:16
@sonmarcho sonmarcho merged commit a5f5bf6 into main Sep 9, 2024
10 checks passed
@sonmarcho sonmarcho deleted the son/implicit branch September 9, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant