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

Some const { } asserts for #128200 #128465

Merged
merged 2 commits into from
Aug 8, 2024
Merged

Some const { } asserts for #128200 #128465

merged 2 commits into from
Aug 8, 2024

Conversation

GrigorenkoPV
Copy link
Contributor

The correctness of code in #128200 relies on an array being sorted (so that it can be used in binary search later), which is currently enforced with // tidy-alphabetical (and characters being written in \u{XXXX} form), as well as lack of duplicate entries with conflicting keys, which is not currently enforced.

This PR changes it to using a const{ } assertion (and also checks for duplicate entries). Sadly, we cannot use the recently-stabilized is_sorted_by_key here, because it is not const (but it would not allow us to check for uniqueness anyways). Instead, let's write a manual loop.

Alternative approach (perfect hash function): #128463

r? @ghost

@rustbot rustbot added 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. labels Jul 31, 2024
@GrigorenkoPV
Copy link
Contributor Author

r? estebank

@GrigorenkoPV GrigorenkoPV marked this pull request as ready for review August 6, 2024 06:27
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
rustc_errors: use perfect hashing for character replacements

The correctness of code in rust-lang#128200 relies on an array being sorted (so that it can be used in binary search later), which is currently enforced with `// tidy-alphabetical` (and characters being written in `\u{XXXX}` form), as well as lack of duplicate entries with conflicting keys, which is not currently enforced.

A const assert or a test can be added checking that (implemented in rust-lang#128465).

But this PR tries to use [perfect hashing](https://en.wikipedia.org/wiki/Perfect_hash_function) instead.

The performance implications are unclear. Asymptotically it's faster, but in reality we should just benchmark. Plus if there are no significant performance wins, this entire things is probably not even worse the additional dependencies it brings.

UPD: funnily enough, there's a PR optimizing the binary search implementation (rust-lang#128254) in the queue right now. So I guess we have to wait until that is merged too before benchmarking this.
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, wither with the additional check or not

Comment on lines +2621 to +2622
"The OUTPUT_REPLACEMENTS array must be sorted (for binary search to work) \
and must contain no duplicate entries"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add another check for assert_neq!(OUTPUT_REPLACEMENTS[i - 1].0, OUTPUT_REPLACEMENTS[i].0) too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is already < and not <=

@estebank
Copy link
Contributor

estebank commented Aug 8, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2024

📌 Commit 15982b2 has been approved by estebank

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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 8, 2024
Some `const { }` asserts for rust-lang#128200

The correctness of code in rust-lang#128200 relies on an array being sorted (so that it can be used in binary search later), which is currently enforced with `// tidy-alphabetical` (and characters being written in `\u{XXXX}` form), as well as lack of duplicate entries with conflicting keys, which is not currently enforced.

This PR changes it to using a `const{ }` assertion (and also checks for duplicate entries). Sadly, we cannot use the recently-stabilized `is_sorted_by_key` here, because it is not const (but it would not allow us to check for uniqueness anyways). Instead, let's write a manual loop.

Alternative approach (perfect hash function): rust-lang#128463

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 8, 2024
…iaskrgr

Rollup of 2 pull requests

Successful merges:

 - rust-lang#128465 (Some `const { }` asserts for rust-lang#128200 )
 - rust-lang#128795 (Update E0517 message to reflect RFC 2195.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Aug 8, 2024

⌛ Testing commit 15982b2 with merge d3a3939...

@bors
Copy link
Contributor

bors commented Aug 8, 2024

☀️ Test successful - checks-actions
Approved by: estebank
Pushing d3a3939 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 8, 2024
@bors bors merged commit d3a3939 into rust-lang:master Aug 8, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 8, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d3a3939): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (primary -0.1%, secondary -0.0%)

This 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.

mean range count
Regressions ❌
(primary)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-3.4% [-3.4%, -3.4%] 1
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) -0.1% [-3.4%, 3.1%] 2

Cycles

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

Binary size

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

Bootstrap: 762.874s -> 760.03s (-0.37%)
Artifact size: 337.10 MiB -> 337.08 MiB (-0.00%)

@GrigorenkoPV GrigorenkoPV deleted the 128200 branch August 10, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants