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 in constant expressions #86

Closed
kvark opened this issue Mar 19, 2018 · 9 comments
Closed

Use in constant expressions #86

kvark opened this issue Mar 19, 2018 · 9 comments
Labels

Comments

@kvark
Copy link
Member

@kvark kvark commented Mar 19, 2018

It would be useful to be able to use SmallVec in constants (long shot - having BigInt with associated constants for ONE, ZERO, etc). This would require exposing SmallVecData enum. Any concerns/objections?

@gnzlbg
Copy link

@gnzlbg gnzlbg commented Mar 22, 2018

I think this is generally desired, but the only issue blocking this right now are the current limitations of const fn.

@kvark
Copy link
Member Author

@kvark kvark commented Mar 26, 2018

@gnzlbg well, I was thinking if it's possible to provide this ability without const fn. I.e. if SmallVecData is exposed, the user could provide it manually.

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Mar 27, 2018

Unfortunately, that would also require making the fields of SmallVec public, which would break the encapsulation necessary for memory safety. I think the only way we can do this soundly is with const fn.

@gnzlbg
Copy link

@gnzlbg gnzlbg commented Apr 6, 2018

@kvark

I was thinking if it's possible to provide this ability without const fn

Ah, I see. The answer is that it is not possible to do this "right" without const fn. A solution could be hacked, but that's not really worth doing.

Also, what are you trying to do? This sounds a lot of like XY.

@kvark
Copy link
Member Author

@kvark kvark commented Apr 6, 2018

@gnzlbg I looked at num-traits crate, and it has quite a few interfaces that should have been const values in the first place. The blocker to convert those is having BigInt as one of the implementations, and it's based on heap allocation. So I was thinking if it's possible to convert BigInt to use SmallVec and have that one supporting constant initialization...

@gnzlbg
Copy link

@gnzlbg gnzlbg commented Apr 6, 2018

The blocker to convert those is having BigInt as one of the implementations, and it's based on heap allocation. So I was thinking if it's possible to convert BigInt to use SmallVec and have that one supporting constant initialization...

I see. I don't think that's going to be possible for the time being :/


Offtopic: Which APIs do you mean? Most of the APIs in num-traits can't be const fn because they are implemented as trait methods, which aren't allowed to be const either. Was your idea to make some of these APIs be associated consts instead?

@kvark
Copy link
Member Author

@kvark kvark commented Apr 6, 2018

@gnzlbg

  • whole Bounded
  • the whole FloatConst thing
  • Zero::zero()
  • One::one()
  • Float::{nan(), infinity(), neg_infinity(), neg_zero(), min_value(), min_positive_value(), max_value(), epsilon()}
@gnzlbg
Copy link

@gnzlbg gnzlbg commented Apr 6, 2018

That's what I thought. Yeah it makes sense to make those associated const, but for that one would need to add const fn constructors for BigNum as you mentioned. Allowing dynamic memory allocation inside const fn would be enough to allow that, and this is something that miri can already do. There is no need to change the implementation to SmallVec for that. Pinging @oli-obk

(this issue should be closed and that should be discussed somewhere else)

@kvark kvark closed this Apr 6, 2018
@oli-obk
Copy link

@oli-obk oli-obk commented Apr 6, 2018

I fully agree that we should not modify SmallVec. I definitely plan to push for making most of Vec const fn in 2019, so SmallVec would be trivial after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.