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

const fn support (e.g. for constructors) #493

Closed
tarcieri opened this issue Jan 5, 2023 · 2 comments · Fixed by #494
Closed

const fn support (e.g. for constructors) #493

tarcieri opened this issue Jan 5, 2023 · 2 comments · Fixed by #494

Comments

@tarcieri
Copy link
Contributor

tarcieri commented Jan 5, 2023

From scalar.rs:

XXX This is pub(crate) so we can write literal constants. If const fns were stable, we could
make the Scalar constructors const fns and use those instead.

This now possible after the MSRV bump.

I wouldn't consider it a release blocker though. Functions can always be made const fn later.

@tarcieri
Copy link
Contributor Author

tarcieri commented Jan 5, 2023

Offhand the only constructor Scalar that seems immediately applicable for a const fn constructor is Scalar::from_bits.

All of the others use reduce which creates a backend-specific UnpackedScalar. We can't make the SIMD backends const fn (yet, see rust-lang/miri#1912).

With a simpler canonicalization check that does a simple conditional subtract (#384), Scalar::from_canonical_bytes could almost be made const fn, but since we made it return CtOption that alone makes const fn support no longer possible.

@tarcieri
Copy link
Contributor Author

tarcieri commented Jan 5, 2023

It turns out Scalar::from_bits is already const fn.

#494 expands const fn everywhere possible I could find.

Another possibility is a pub(crate) const fn new_unchecked method but that's hardly better than the status quo.

@rozbb rozbb closed this as completed in #494 Jan 6, 2023
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 a pull request may close this issue.

1 participant