Skip to content

Implement unstable trait impl #140399

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

Merged
merged 8 commits into from
Jul 17, 2025
Merged

Implement unstable trait impl #140399

merged 8 commits into from
Jul 17, 2025

Conversation

tiif
Copy link
Member

@tiif tiif commented Apr 28, 2025

This PR allows marking impls of stable trait with stable type as unstable.

Approach

In std/core, an impl can be marked as unstable by annotating it with #[unstable_feature_bound(feat_name)]. This will add a ClauseKind::Unstable_Feature(feat_name) to the list of predicates in predicates_of .

When an unstable impl's function is called, we will first iterate through all the goals in param_env to check if there is any ClauseKind::UnstableFeature(feat_name) in param_env.

The existence of ClauseKind::Unstable_Feature(feat_name) in param_env means an#[unstable_feature_bound(feat_name)] is present at the call site of the function, so we allow the check to succeed in this case.

If ClauseKind::UnstableFeature(feat_name) does not exist in param_env, we will still allow the check to succeed for either of the cases below:

  1. The feature is enabled through #[feature(feat_name)] outside of std / core.
  2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not.

For the rest of the case, it will fail with ambiguity.

Limitation

In this PR, we do not support:

  1. using items that need #[unstable_feature_bound] within stable APIs
  2. annotate main function with #[unstable_feature_bound]
  3. annotate #[unstable_feature_bound] on items other than free function and impl

Acknowledgement

The design and mentoring are done by @BoxyUwU

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 28, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU self-assigned this May 27, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 10, 2025

☔ The latest upstream changes (presumably #142299) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Jul 15, 2025

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a

rust-bors bot added a commit that referenced this pull request Jul 15, 2025
[Perf] Remove call to hir_attrs in predicates_of

<!-- homu-ignore:start -->
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r? <reviewer name>
-->
<!-- homu-ignore:end -->

Test how much regression we still have if we remove the call to ``hir_attrs`` in ``predicates_of`` for #140399

r? ghost
@lcnr
Copy link
Contributor

lcnr commented Jul 16, 2025

looks like the cost is from just the new PredicateKind 🤔

While I think changing Predicate and Clause to be like GenericArg (as in, a tagged pointer and storing different predicate/clause kinds in separate interned list), would likely improve perf and reduce the impact of adding new variants, I don't think we should block this PR on that.

Unless you want to try something to reduce the perf impact, r=me

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 16, 2025

@bors r=lcnr rollup=never

I would really like to get this perf back but also supporting stability of impls seems quite important so I would prefer to land this then experiment with perf changes afterwards 🤔

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit e331de1 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 16, 2025

@bors r=lcnr,BoxyUwU

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit e331de1 has been approved by lcnr,BoxyUwU

It is now in the queue for this repository.

@tiif
Copy link
Member Author

tiif commented Jul 16, 2025

I am happy to send a follow-up PR to try more stuff to claw back the perf

Thanks for all the reviews ❤️

@bors
Copy link
Collaborator

bors commented Jul 17, 2025

⌛ Testing commit e331de1 with merge 014bd82...

@bors
Copy link
Collaborator

bors commented Jul 17, 2025

☀️ Test successful - checks-actions
Approved by: lcnr,BoxyUwU
Pushing 014bd82 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 17, 2025
@bors bors merged commit 014bd82 into rust-lang:master Jul 17, 2025
12 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 17, 2025
Copy link
Contributor

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 fd2eb39 (parent) -> 014bd82 (this PR)

Test differences

Show 292 test diffs

Stage 1

  • errors::verify_passes_abi_invalid_attribute_125: pass -> [missing] (J0)
  • errors::verify_passes_abi_of_123: pass -> [missing] (J0)
  • errors::verify_passes_abi_of_124: [missing] -> pass (J0)
  • errors::verify_passes_align_should_be_repr_align_176: pass -> [missing] (J0)
  • errors::verify_passes_attr_application_enum_138: pass -> [missing] (J0)
  • errors::verify_passes_attr_application_enum_139: [missing] -> pass (J0)
  • errors::verify_passes_attr_application_struct_139: pass -> [missing] (J0)
  • errors::verify_passes_attr_application_struct_enum_union_141: pass -> [missing] (J0)
  • errors::verify_passes_attr_application_struct_enum_union_142: [missing] -> pass (J0)
  • errors::verify_passes_attr_application_struct_union_141: [missing] -> pass (J0)
  • errors::verify_passes_attr_only_in_functions_129: pass -> [missing] (J0)
  • errors::verify_passes_attr_only_in_functions_130: [missing] -> pass (J0)
  • errors::verify_passes_cannot_stabilize_deprecated_145: pass -> [missing] (J0)
  • errors::verify_passes_cannot_stabilize_deprecated_146: [missing] -> pass (J0)
  • errors::verify_passes_collapse_debuginfo_106: pass -> [missing] (J0)
  • errors::verify_passes_collapse_debuginfo_107: [missing] -> pass (J0)
  • errors::verify_passes_coroutine_on_non_closure_91: pass -> [missing] (J0)
  • errors::verify_passes_coroutine_on_non_closure_92: [missing] -> pass (J0)
  • errors::verify_passes_deprecated_94: pass -> [missing] (J0)
  • errors::verify_passes_deprecated_95: [missing] -> pass (J0)
  • errors::verify_passes_deprecated_attribute_143: pass -> [missing] (J0)
  • errors::verify_passes_extern_main_131: pass -> [missing] (J0)
  • errors::verify_passes_extern_main_132: [missing] -> pass (J0)
  • errors::verify_passes_feature_previously_declared_129: [missing] -> pass (J0)
  • errors::verify_passes_implied_feature_not_exist_152: pass -> [missing] (J0)
  • errors::verify_passes_incorrect_crate_type_134: [missing] -> pass (J0)
  • errors::verify_passes_incorrect_target_132: pass -> [missing] (J0)
  • errors::verify_passes_ineffective_unstable_impl_164: [missing] -> pass (J0)
  • errors::verify_passes_inline_ignored_for_exported_136: pass -> [missing] (J0)
  • errors::verify_passes_inline_ignored_for_exported_137: [missing] -> pass (J0)
  • errors::verify_passes_invalid_macro_export_arguments_98: pass -> [missing] (J0)
  • errors::verify_passes_lang_item_fn_with_track_caller_113: [missing] -> pass (J0)
  • errors::verify_passes_layout_abi_118: [missing] -> pass (J0)
  • errors::verify_passes_layout_align_118: pass -> [missing] (J0)
  • errors::verify_passes_layout_homogeneous_aggregate_121: [missing] -> pass (J0)
  • errors::verify_passes_layout_invalid_attribute_122: pass -> [missing] (J0)
  • errors::verify_passes_layout_invalid_attribute_123: [missing] -> pass (J0)
  • errors::verify_passes_link_ordinal_90: [missing] -> pass (J0)
  • errors::verify_passes_macro_export_96: pass -> [missing] (J0)
  • errors::verify_passes_macro_export_97: [missing] -> pass (J0)
  • errors::verify_passes_macro_export_on_decl_macro_97: pass -> [missing] (J0)
  • errors::verify_passes_macro_use_95: pass -> [missing] (J0)
  • errors::verify_passes_macro_use_96: [missing] -> pass (J0)
  • errors::verify_passes_may_dangle_101: pass -> [missing] (J0)
  • errors::verify_passes_missing_const_stab_attr_149: [missing] -> pass (J0)
  • errors::verify_passes_missing_panic_handler_110: [missing] -> pass (J0)
  • errors::verify_passes_missing_stability_attr_148: [missing] -> pass (J0)
  • errors::verify_passes_non_exported_macro_invalid_attrs_100: pass -> [missing] (J0)
  • errors::verify_passes_non_exported_macro_invalid_attrs_101: [missing] -> pass (J0)
  • errors::verify_passes_repr_align_should_be_align_176: [missing] -> pass (J0)
  • errors::verify_passes_rustc_const_stable_indirect_pairing_166: pass -> [missing] (J0)
  • errors::verify_passes_rustc_force_inline_87: pass -> [missing] (J0)
  • errors::verify_passes_rustc_force_inline_88: [missing] -> pass (J0)
  • errors::verify_passes_rustc_lint_opt_ty_104: pass -> [missing] (J0)
  • errors::verify_passes_rustc_pub_transparent_86: pass -> [missing] (J0)
  • errors::verify_passes_rustc_std_internal_symbol_86: [missing] -> pass (J0)
  • errors::verify_passes_stability_promotable_93: pass -> [missing] (J0)
  • errors::verify_passes_stability_promotable_94: [missing] -> pass (J0)
  • errors::verify_passes_trait_impl_const_stable_149: pass -> [missing] (J0)
  • errors::verify_passes_transparent_incompatible_142: pass -> [missing] (J0)
  • errors::verify_passes_unexportable_adt_with_private_fields_174: pass -> [missing] (J0)
  • errors::verify_passes_unexportable_adt_with_private_fields_175: [missing] -> pass (J0)
  • errors::verify_passes_unexportable_fn_abi_171: [missing] -> pass (J0)
  • errors::verify_passes_unexportable_generic_fn_169: pass -> [missing] (J0)
  • errors::verify_passes_unexportable_generic_fn_170: [missing] -> pass (J0)
  • errors::verify_passes_unexportable_type_in_interface_172: pass -> [missing] (J0)
  • errors::verify_passes_unexportable_type_repr_171: pass -> [missing] (J0)
  • errors::verify_passes_unknown_external_lang_item_109: [missing] -> pass (J0)
  • errors::verify_passes_unknown_feature_alias_151: pass -> [missing] (J0)
  • errors::verify_passes_unknown_feature_alias_152: [missing] -> pass (J0)
  • errors::verify_passes_unnecessary_partial_stable_feature_162: pass -> [missing] (J0)
  • errors::verify_passes_unnecessary_stable_feature_162: [missing] -> pass (J0)
  • errors::verify_passes_unsupported_attributes_in_where_167: pass -> [missing] (J0)
  • errors::verify_passes_unused_assign_passed_164: pass -> [missing] (J0)
  • errors::verify_passes_unused_assign_passed_165: [missing] -> pass (J0)
  • errors::verify_passes_unused_capture_maybe_capture_ref_159: pass -> [missing] (J0)
  • errors::verify_passes_unused_multiple_104: [missing] -> pass (J0)
  • errors::verify_passes_unused_var_assigned_only_161: [missing] -> pass (J0)
  • errors::verify_passes_useless_assignment_135: [missing] -> pass (J0)
  • errors::verify_passes_useless_stability_144: pass -> [missing] (J0)
  • session_diagnostics::verify_attr_parsing_link_ordinal_out_of_range_41: [missing] -> pass (J0)
  • session_diagnostics::verify_attr_parsing_naked_functions_incompatible_attribute_39: pass -> [missing] (J0)
  • session_diagnostics::verify_attr_parsing_naked_functions_incompatible_attribute_40: [missing] -> pass (J0)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-multiple-symbol.rs: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-require-bound.rs#pass: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-exact-symbol.rs#pass: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable-impl-assoc-type.rs#pass: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable-impl-multiple-symbol.rs: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable_feature_bound_free_fn.rs#fail: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable_feature_bound_incompatible_stability.rs: [missing] -> pass (J2)
  • [ui] tests/ui/unstable-feature-bound/unstable_feature_bound_multi_attr.rs: [missing] -> pass (J2)

Stage 2

  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-exact-symbol.rs#pass: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-multiple-symbol.rs: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-require-bound.rs#fail: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-cross-crate-require-bound.rs#pass: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-feature-exact-symbol.rs#fail: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-impl-assoc-type.rs#fail: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable-impl-cannot-use-feature.rs#pass: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable_feature_bound_free_fn.rs#fail: [missing] -> pass (J1)
  • [ui] tests/ui/unstable-feature-bound/unstable_impl_codegen.rs: [missing] -> pass (J1)

(and 140 additional test diffs)

Additionally, 52 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 014bd8290f084c714995205a9116e6c035419ae6 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. tidy: 127.7s -> 65.9s (-48.4%)
  2. x86_64-apple-2: 4059.0s -> 5853.5s (44.2%)
  3. pr-check-2: 2212.3s -> 2835.3s (28.2%)
  4. dist-x86_64-apple: 9792.9s -> 11486.7s (17.3%)
  5. i686-gnu-1: 7170.0s -> 8367.1s (16.7%)
  6. dist-apple-various: 7290.3s -> 6080.5s (-16.6%)
  7. pr-check-1: 1513.0s -> 1729.0s (14.3%)
  8. i686-gnu-2: 5500.1s -> 6153.6s (11.9%)
  9. i686-gnu-nopt-1: 7156.4s -> 7991.9s (11.7%)
  10. x86_64-apple-1: 7540.6s -> 8354.2s (10.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (014bd82): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 0.8%] 65
Regressions ❌
(secondary)
0.4% [0.1%, 1.3%] 60
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.3%, 0.8%] 67

Max RSS (memory usage)

Results (secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [1.8%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-6.0%, -1.2%] 5
All ❌✅ (primary) - - 0

Cycles

Results (primary 2.3%, secondary 0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
2.7% [2.0%, 3.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-3.8%, -3.8%] 1
All ❌✅ (primary) 2.3% [2.3%, 2.3%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 467.109s -> 462.752s (-0.93%)
Artifact size: 374.84 MiB -> 374.69 MiB (-0.04%)

@Kobzol
Copy link
Member

Kobzol commented Jul 17, 2025

The perf regressions were deemed to be acceptable for the time being, to avoid delaying this feature. Interestingly this was a solid win on bootstrap time, maybe because of some refactoring/restructuring of code?

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 17, 2025
@lqd
Copy link
Member

lqd commented Jul 17, 2025

It’s just that bootstrap times are more unstable on the new benchmark machine.

@Kobzol
Copy link
Member

Kobzol commented Jul 17, 2025

Really? I haven't seen that large swings recently. Usually it's ~2.5s at most (https://perf.rust-lang.org/bootstrap.html), so 4.5s seemed like it could be an actual change to me. But it could also be noise ofc, as you say, doesn't really matter.

@lqd
Copy link
Member

lqd commented Jul 17, 2025

I've seen a few 3s+ in the last few days, and here's a 5% swing, +25s, -25s, from a couple days back, so there may be some more noise than before.

@Kobzol
Copy link
Member

Kobzol commented Jul 17, 2025

Hmm, unattended upgrades or anything similar doesn't seem to be it, per logs. I wonder if it might have been datadog, that seems like the only thing that consumes a bunch of CPU there.

@tiif tiif deleted the unstable_impl branch July 17, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.