Skip to content

Conversation

@clementblaudeau
Copy link
Contributor

This PR adds support for const parameters on functions and traits. They are represented as normal parameters.

/// Test def site
fn f<const N1: usize>(x : usize) -> usize {
    N1 + x + 1 
}

/// Test call site
fn test() -> usize { 
    f::<1>(1) 
    + f::<{ if true { 1 } else { 1 / 0 } }>(2)
}
--  Test def site
def Playground.f (N1 : usize) (x : usize) : RustM usize := do
  ((← (N1 +? x)) +? (1 : usize))

--  Test call site
def Playground.test (_ : Rust_primitives.Hax.Tuple0) : RustM usize := do
  ((← (Playground.f ((1 : usize)) (1 : usize)))
    +? (← (Playground.f ((1 : usize)) (2 : usize))))

Open this code snippet in the playground

This adds a necessary step towards the support of arrays with non integer-literal size (#1713). During the work on this PR, the issue #1796 was uncovered, which explains the 2 added negative tests.

@clementblaudeau clementblaudeau requested a review from a team as a code owner December 3, 2025 19:12
@clementblaudeau clementblaudeau linked an issue Dec 3, 2025 that may be closed by this pull request
@W95Psp W95Psp requested a review from abentkamp December 11, 2025 13:02
Copy link
Contributor

@abentkamp abentkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented in #1796, issue #1796 could quite easily be fixed. But I think we can merge this PR first.

@abentkamp abentkamp added this pull request to the merge queue Dec 11, 2025
Merged via the queue into main with commit 63551dd Dec 11, 2025
17 of 18 checks passed
@abentkamp abentkamp deleted the lean-const-parameters branch December 11, 2025 14:05
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.

[Lean] Add support for constant generic parameters

2 participants