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

Experiment with nightly const-trait-impl #358

Closed
wcampbell0x2a opened this issue Aug 27, 2023 · 1 comment
Closed

Experiment with nightly const-trait-impl #358

wcampbell0x2a opened this issue Aug 27, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@wcampbell0x2a
Copy link
Collaborator

wcampbell0x2a commented Aug 27, 2023

Previous Issue

@wcampbell0x2a it could call all those trait methods at compile time if possible and/or optimize them out: ![image](https://user-images.githubusercontent.com/108802164/235850935-15d0a95c-5733-48ac-8dc2-fb14f52ebbfc.png) see [feature const-trait-impl](https://doc.rust-lang.org/beta/unstable-book/language-features/const-trait-impl.html)

I'm not sure how #[inline] interacts with this. I'm guessing if the call can't be optimized out at compile time, it inlines. It could also be the case that constness is only relevant to the crate where it is defined.
See the last line here (which I used on some From impls lately):

None: The compiler will decide itself if the function should be inlined. This will depend on factors such as the optimization level and the size of the function. Non-generic functions will never be inlined across crate boundaries unless link-time optimization is used; generic functions might be.

#[inline]: This suggests that the function should be inlined, including across crate boundaries.

Then again, I might have mixed this up (even non-const stuff can get computed at compile time), so if someone wants to go at this, it's probably best to first try to put #[inline] on those trait methods and compare asm outputs.
Edit: I quickly tried adding #[inline] to all the reads and writes in impls::primitives, it didn't inline (and I wouldn't use inline(always)).

Originally posted by @hecatia-elegua in #308 (comment)

@wcampbell0x2a
Copy link
Collaborator Author

I don't see this as a possible advantage for the time being, and not interesting in maintaining a nightly only feature set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant