-
Notifications
You must be signed in to change notification settings - Fork 14k
Inherent const impl #148434
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
Inherent const impl #148434
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to the CTFE machinery Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Changes to the size of AST and/or HIR nodes. cc @nnethercote |
This comment has been minimized.
This comment has been minimized.
1cc41b4 to
d780ac6
Compare
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.
Looks good to me, including from the side of the lang experiment, as the lang champion.
| fn should_encode_constness(def_kind: DefKind) -> bool { | ||
| match def_kind { | ||
| DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(_, CtorKind::Fn) => true, | ||
| DefKind::Fn | ||
| | DefKind::AssocFn | ||
| | DefKind::Closure | ||
| | DefKind::Ctor(_, CtorKind::Fn) | ||
| | DefKind::Impl { of_trait: false } => true, |
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.
I see something asymmetric here, and this is something we might want to address either here or some time later.
We only encode impl methods' constness for trait impls and those are inherited from the impl, but is it not better to just look at the parent and only encode constness once? Since we're going with the whole-trait whole-impl approach anyways.
In the other direction, we should not encode const impl also and have all the assocs encode their constness.
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.
Looking into this I realized we encode even NotConst in metadata. So all functions get the value encoded, even if we could just encode it if Maybe or Always and treat the lack of a value as NotConst
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.
I will look into this metadata encoding thing later
| return Some(true); | ||
| } | ||
| if ALL_QUALS.iter().any(|&qual| token.is_keyword(qual)) { | ||
| // Ok, we found a legal keyword, keep looking for `impl` | ||
| return None; | ||
| } | ||
| Some(false) | ||
| }); | ||
| if let Some(ret) = action { | ||
| return ret; |
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.
wonder if using ControlFlow here would be more clearer
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.
not by much. Tho I would love it if I could ? away a Break(T) in a function that returns T
| if let Some(of_trait) = of_trait.as_deref() { | ||
| result.push_str(format_constness_right(of_trait.constness)); | ||
| result.push_str(format_constness_right(*constness)); |
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.
are we not going to format impl const Tr to const impl Tr? Feels like it should be placed at the earlier places now.
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.
Happy to go all the way in one PR, just wanted to change as little as possible
tests/ui/traits/const-traits/const-impl-inherent-double-const.fixed
Outdated
Show resolved
Hide resolved
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (cb034f2): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -1.0%, secondary -0.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 473.413s -> 473.703s (0.06%) |
|
☔ The latest upstream changes (presumably #139558) made this pull request unmergeable. Please resolve the merge conflicts. |
|
No idea why I'm happy to land this, and I am happy to do the followup rustdoc work (making rustdoc think of each method as const and inheriting the const stability, etc) |
d780ac6 to
7e3ccca
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
7e3ccca to
b41c2a2
Compare
|
Hopefully there is no conflict... @bors r+ |
|
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 7c2c3c0 (parent) -> 6159a44 (this PR) Test differencesShow 310 test diffsStage 0
Stage 1
Stage 2
(and 196 additional test diffs) Additionally, 14 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 6159a44067ebce42b38f062cc7df267a1348e092 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (6159a44): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 3.0%, secondary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.7%, secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 474.558s -> 473.45s (-0.23%) |
Avoid encoding non-constness or non-asyncness in metadata r? `@fee1-dead` Let's see if we can get any benefit (even just metadata size) from not encoding the common case. Inspired by #148434 (comment)
|
perf triage:
@rustbot label: +perf-regression-triaged |
Some constifications are annoying because we need to repeat
T: Traitbounds from an impl block on the individual constifiedconst fns asT: [const] Trait. We've brainstormed solutions before, and one would be to have separateconst implblocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along.Also interacts with the discussion around
impl const Trait for Typevsconst impl Trait for Type, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme).r? @fee1-dead
cc @traviscross @rust-lang/project-const-traits