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

add missing potential_query_instability for keys and values in hashmap #120485

Merged

Conversation

chenyukang
Copy link
Member

From #120435 (comment),

These API are also returning iterator, so we need add potential_query_instability for them?

@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2024

r? @michaelwoerister

(rustbot has picked a reviewer for you, use r? to override)

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 30, 2024
@chenyukang
Copy link
Member Author

link #84447 #89558

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @chenyukang!

That's a great catch about the missing query instability attributes on the HashMap methods. That was definitely a bug.

I've left a few comments below where it should not be too hard to fix the problem in a cleaner way.

@@ -267,6 +267,7 @@ impl CguReuseTracker {

fn check_expected_reuse(&self, sess: &Session) {
if let Some(ref data) = self.data {
#[allow(rustc::potential_query_instability)]
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
Copy link
Member

Choose a reason for hiding this comment

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

We can fix this properly by using UnordMap instead of FxHashMap for the actual_reuse and expected_reuse fields in TrackerData. That has the to_sorted_stable_ord method that does exactly what we want.

@@ -403,6 +403,7 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
let mut result = items.clone();

for cgu in cgus {
#[allow(rustc::potential_query_instability)]
Copy link
Member

Choose a reason for hiding this comment

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

Can you try turning the items field in CodegenUnit into an FxIndexMap. That should make iteration stable (if the collection is built in a deterministic order). An UnordMap would be even better, but I suspect that that would be more work.

@@ -682,6 +682,7 @@ fn link_dwarf_object<'a>(
}

// Input rlibs contain .o/.dwo files from dependencies.
#[allow(rustc::potential_query_instability)]
let input_rlibs = cg_results
.crate_info
.used_crate_source
Copy link
Member

Choose a reason for hiding this comment

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

Can you turn the used_crate_source field into an UnordMap? Then you should be able to do this:

// Input rlibs contain .o/.dwo files from dependencies.
let input_rlibs = cg_results
    .crate_info
    .used_crate_source
    .items()
    .filter_map(|(_, csource)| csource.rlib.as_ref())
    .map(|(path, _)| path)
    .into_sorted_stable_ord();

@@ -1950,6 +1950,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let len = remaining_fields.len();

#[allow(rustc::potential_query_instability)]
Copy link
Member

Choose a reason for hiding this comment

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

It should be straightforward to make remaining_fields and UnordMap.

@chenyukang
Copy link
Member Author

chenyukang commented Jan 30, 2024

Thanks for the PR, @chenyukang!

That's a great catch about the missing query instability attributes on the HashMap methods. That was definitely a bug.

I've left a few comments below where it should not be too hard to fix the problem in a cleaner way.

There was an issue to track these kinds of cleanups:
#84447

I may create a separate PR to clean up those replacements?

@michaelwoerister
Copy link
Member

This is also closely related: rust-lang/compiler-team#533

It is where the unord collections were proposed. They've been implemented meanwhile and are quite mature (although it seems that UnordMap misses fn keys(&self) -> UnordItems<&K, impl Iterator<Item = &K>> for example).

I may create a separate PR to clean up those replacements?

Sure, you can r? @michaelwoerister on that. Let me know if you plan to do any further changes to this PR, otherwise I'm happy to approve it.

@chenyukang
Copy link
Member Author

Ok, please approve this one, I may work on cleanups in the weekend.

@michaelwoerister
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 30, 2024

📌 Commit ad526d8 has been approved by michaelwoerister

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 Jan 30, 2024
Comment on lines -329 to +331
debug!(
"is_lint_group(lint_name={:?}, lint_groups={:?})",
lint_name,
self.lint_groups.keys().collect::<Vec<_>>()
);
#[allow(rustc::potential_query_instability)]
let lint_groups = self.lint_groups.keys().collect::<Vec<_>>();
debug!("is_lint_group(lint_name={:?}, lint_groups={:?})", lint_name, lint_groups);
Copy link
Contributor

@klensy klensy Jan 30, 2024

Choose a reason for hiding this comment

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

Will collect things on release now, instead of debug only, next one too. cfg(debug_assertions)?

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right, I will clean this up when I replace HashMap.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 30, 2024
…llaumeGomez

Rollup of 11 pull requests

Successful merges:

 - rust-lang#117906 (Improve display of crate name when hovered)
 - rust-lang#118533 (Suppress unhelpful diagnostics for unresolved top level attributes)
 - rust-lang#120293 (Deduplicate more sized errors on call exprs)
 - rust-lang#120295 (Remove `raw_os_nonzero` feature.)
 - rust-lang#120310 (adapt test for v0 symbol mangling)
 - rust-lang#120342 (Remove various `has_errors` or `err_count` uses)
 - rust-lang#120434 (Revert outdated version of "Add the wasm32-wasi-preview2 target")
 - rust-lang#120445 (Fix some `Arc` allocator leaks)
 - rust-lang#120475 (Improve error message when `cargo build` is used to build the compiler)
 - rust-lang#120476 (Remove some unnecessary check logic for lang items in HIR typeck)
 - rust-lang#120485 (add missing potential_query_instability for keys and values in hashmap)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 27bc496 into rust-lang:master Jan 30, 2024
11 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 30, 2024
Rollup merge of rust-lang#120485 - chenyukang:yukang-add-query-instability-check, r=michaelwoerister

add missing potential_query_instability for keys and values in hashmap

From rust-lang#120435 (comment),

These API are also returning iterator, so we need add `potential_query_instability` for them?
@rustbot rustbot added this to the 1.77.0 milestone Jan 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
…=<try>

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 12, 2024
…=<try>

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2024
…=<try>

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2024
…=<try>

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2024
…=michaelwoerister

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 15, 2024
…=michaelwoerister

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang#120485 (comment)

r? `@michaelwoerister`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 16, 2024
…oerister

Clean up potential_query_instability with FxIndexMap and UnordMap

From rust-lang/rust#120485 (comment)

r? `@michaelwoerister`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-libs Relevant to the library 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