-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add StableOrd trait as proposed in MCP 533. #105175
Conversation
The StableOrd trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.
r? @nagisa (rustbot has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 3a58309 with merge e29ec0eb30603d64bdf1c7521883db1abae44331... |
Why is the trait unsafe? Can it cause memory unsafety in the rustc process itself? |
I made it unsafe because the trait is giving a guarantee that the compiler has no way to check, either at compile time or via a runtime check and the consequences of getting it wrong are pretty severe. An error here can result in the kinds of miscompilations that we've seen in incremental compilation in the past. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (e29ec0eb30603d64bdf1c7521883db1abae44331): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
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.
r=me
@@ -140,7 +140,7 @@ impl stable_hasher::StableHasherResult for Fingerprint { | |||
} | |||
} | |||
|
|||
impl_stable_hash_via_hash!(Fingerprint); | |||
impl_stable_ord_and_stable_hash_via_hash!(Fingerprint); |
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.
Naming nit: are there any other Stable*
traits? Could this be impl_stable_via_hash
or something?
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 renamed the macro to impl_stable_traits_for_trivial_type!()
.
⌛ Testing commit 56aacb2 with merge 46f1f6f6123083f3ebf4544b45988e2c25cb9209... |
💥 Test timed out |
Timeout while updating crates.io index. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9db224f): comparison URL. Overall result: ❌✅ regressions and improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
…t, r=nagisa Add StableOrd trait as proposed in MCP 533. The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order. See rust-lang/compiler-team#533 for more information.
…elwoerister Un-unsafe the `StableOrd` trait Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc. [Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler). cc [MCP 533](rust-lang/compiler-team#533), rust-lang#105175, `@michaelwoerister` r? `@Nilstrieb`
…woerister Un-unsafe the `StableOrd` trait Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc. [Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler). cc [MCP 533](rust-lang/compiler-team#533), rust-lang#105175, `@michaelwoerister` r? `@Nilstrieb`
The
StableOrd
trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.See rust-lang/compiler-team#533 for more information.