-
Notifications
You must be signed in to change notification settings - Fork 488
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
Improve associated constant item CTFE timing section #1147
Conversation
@RalfJung pointed out in a [comment] that the previous phrasing of the sentence can read like it is giving guarantees about free constant definitions always undergoing CTFE, even when unused. That seems to be how the compiler behaves right now, but it's unclear whether it's intentional. Be more precise and don't talk about free constants at all. [comment]: rust-lang#1120 (comment)
If you want to help with this, I think the first step is to contact the lang team (e.g. in their Zulip stream) -- I am not sure if an RFC is even required; possibly an FCP (final comment period) is enough to turn this current implementation fact into a stable guarantee. |
src/items/associated-items.md
Outdated
Unlike [free] constants, associated constant definitions undergo | ||
[constant evaluation] only when referenced. | ||
Associated constant definitions undergo [constant evaluation] only when | ||
referenced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And only after monomorphization. Nothing is actually done on generic constants, even if we could attempt it nowadays
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the example a bit bigger, but makes the reason why constants don't immediately undergo CTFE more conspicuous. When there is computation in the definition that use generic parameters, there is not enough information to fully evaluate the definition eagerly. I made it a `compile_fail` example so the run button on the page gives reader useful outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Update books ## nomicon 3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03 2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900 - Fix a small typo in exception-safety.md (rust-lang/nomicon#341) - Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336) - Fix a syntax error in leaking.md (rust-lang/nomicon#335) ## reference 6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05 2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800 - Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154) - Mention std::is_aarch64_feature_detected (rust-lang/reference#1061) - Fix link to the Bastion of the Turbofish (rust-lang/reference#1161) - Improve associated constant item CTFE timing section (rust-lang/reference#1147) - document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098) - Update patterns allowed in @ patterns (rust-lang/reference#1158) ## book 6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab 2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500 - Snapshot of ch18 for nostarch - Remove mention of destructuring references as that's not covered currently - Add note that exhaustiveness checking doesn't extend to match guards - Change match guard example to actually be unexpressable with patterns alone - Corrected listing number from 9-10 to 9-13 - Remove duplicate paragraph after No Starch related changes ## rustc-dev-guide 3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706 2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500 - Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298) - Triage some date references (rust-lang/rustc-dev-guide#1293) - mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)
Update books ## nomicon 3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03 2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900 - Fix a small typo in exception-safety.md (rust-lang/nomicon#341) - Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336) - Fix a syntax error in leaking.md (rust-lang/nomicon#335) ## reference 6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05 2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800 - Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154) - Mention std::is_aarch64_feature_detected (rust-lang/reference#1061) - Fix link to the Bastion of the Turbofish (rust-lang/reference#1161) - Improve associated constant item CTFE timing section (rust-lang/reference#1147) - document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098) - Update patterns allowed in @ patterns (rust-lang/reference#1158) ## book 6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab 2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500 - Snapshot of ch18 for nostarch - Remove mention of destructuring references as that's not covered currently - Add note that exhaustiveness checking doesn't extend to match guards - Change match guard example to actually be unexpressable with patterns alone - Corrected listing number from 9-10 to 9-13 - Remove duplicate paragraph after No Starch related changes ## rustc-dev-guide 3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706 2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500 - Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298) - Triage some date references (rust-lang/rustc-dev-guide#1293) - mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)
Update books ## nomicon 3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03 2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900 - Fix a small typo in exception-safety.md (rust-lang/nomicon#341) - Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336) - Fix a syntax error in leaking.md (rust-lang/nomicon#335) ## reference 6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05 2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800 - Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154) - Mention std::is_aarch64_feature_detected (rust-lang/reference#1061) - Fix link to the Bastion of the Turbofish (rust-lang/reference#1161) - Improve associated constant item CTFE timing section (rust-lang/reference#1147) - document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098) - Update patterns allowed in @ patterns (rust-lang/reference#1158) ## book 6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab 2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500 - Snapshot of ch18 for nostarch - Remove mention of destructuring references as that's not covered currently - Add note that exhaustiveness checking doesn't extend to match guards - Change match guard example to actually be unexpressable with patterns alone - Corrected listing number from 9-10 to 9-13 - Remove duplicate paragraph after No Starch related changes ## rustc-dev-guide 3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706 2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500 - Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298) - Triage some date references (rust-lang/rustc-dev-guide#1293) - mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)
@RalfJung pointed out in a comment that the previous phrasing of the
sentence can read like it is giving guarantees about free constant
definitions always undergoing CTFE, even when unused. That seems to be
how the compiler behaves right now, but it's unclear whether it's
intentional.
Be more precise and don't talk about free constants at all.
Related to this, I'm not sure if rust-lang/rust#89006
stabilized the fact that unamed constants (in contrast to named but unused free constants) always undergo CTFE. It's part
of the issue, and it's used in the release notes to demo the feature, so I had assumed that it does. Going through the RFC and the issue though, it does not state it explicitly, so it's possible that nothing with regards to when CTFE is guaranteed to happen was actually stabilized.
I'm fairly new to the language overall, but maybe it's time that I try to write an RFC about the whens of CTFE?