Skip to content

Make traits_in_crate and impls_in_crate proper queries. #129478

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

Closed
wants to merge 3 commits into from

Conversation

xonx4l
Copy link

@xonx4l xonx4l commented Aug 23, 2024

Issue -: #95092.

This PR introduces impls_in_crate as a query, maintaining current sorting behavior while setting the stage for future optimizations.

Benefits -:

  1. Centralized impl collection.
  2. Potential for better caching and incremental compilation.
  3. Groundwork for future performance improvements.

Sorting is kept within the query for now to minimize changes. It Maintains existing behaviour while introducing the new query.

@rustbot
Copy link
Collaborator

rustbot commented Aug 23, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Aug 23, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#13 2.714 Building wheels for collected packages: reuse
#13 2.715   Building wheel for reuse (pyproject.toml): started
#13 2.964   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 2.965   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#13 2.965   Stored in directory: /tmp/pip-ephem-wheel-cache-o0ati48c/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#13 2.968 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#13 3.370 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#13 3.370 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#13 3.901 Collecting virtualenv
#13 3.901 Collecting virtualenv
#13 3.939   Downloading virtualenv-20.26.3-py3-none-any.whl (5.7 MB)
#13 4.019      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.7/5.7 MB 72.9 MB/s eta 0:00:00
#13 4.076 Collecting filelock<4,>=3.12.2
#13 4.079   Downloading filelock-3.15.4-py3-none-any.whl (16 kB)
#13 4.110 Collecting platformdirs<5,>=3.9.1
#13 4.117   Downloading platformdirs-4.2.2-py3-none-any.whl (18 kB)
#13 4.137 Collecting distlib<1,>=0.3.7
#13 4.148      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 93.4 MB/s eta 0:00:00
#13 4.148      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 93.4 MB/s eta 0:00:00
#13 4.229 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 4.417 Successfully installed distlib-0.3.8 filelock-3.15.4 platformdirs-4.2.2 virtualenv-20.26.3
#13 DONE 4.5s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      212928 kB
DirectMap2M:    10272768 kB
DirectMap1G:     8388608 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://ci-artifacts.rust-lang.org/rustc-builds-alt/a60a9e567a7319b33619f6551dc29522c6f58687/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
extracting /checkout/obj/build/cache/llvm-a60a9e567a7319b33619f6551dc29522c6f58687-true/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm
---
   Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
    Finished `release` profile [optimized] target(s) in 29.28s
##[endgroup]
fmt check
Diff in /checkout/compiler/rustc_metadata/src/rmeta/encoder.rs:2011:
                     .push((impl_def_id.index, simplified_self_ty));
         }
-    
+
+
         for id in tcx.hir().items() {
             let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
Diff in /checkout/compiler/rustc_hir_analysis/src/lib.rs:150:
     hir_wf_check::provide(providers);
     *providers = Providers {
     *providers = Providers {
         impls_in_crate: |tcx, cnum| {
-            assert_eq!(cnum , LOCAL_CRATE);
+            assert_eq!(cnum, LOCAL_CRATE);
             let mut impls = Vec::new();
             for id in tcx.hir().items() {
-                if let Defkind::Impl = tcx.def_kind(id.owner_id){
+                if let Defkind::Impl = tcx.def_kind(id.owner_id) {
                     let def_id = id.owner_id.to_def_id();
                     let simplified_self_ty = if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
                         Some(fast_reject::simplify_type(
Diff in /checkout/compiler/rustc_hir_analysis/src/lib.rs:160:
                             tcx,
                             trait_ref.self_ty(),
                             TreatParams::AsInfer,
+                        ))
                     } else {
                         None
                     };
                     };
fmt error: Running `fmt: checked 5510 files
"/checkout/obj/build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/find_use.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/mod.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/region_errors.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/var_name.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/region_name.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/move_errors.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs" "/checkout/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs" "/checkout/compiler/rustc_borrowck/src/dataflow.rs" "/checkout/compiler/rustc_lint_defs/src/builtin.rs" "/checkout/compiler/rustc_lint_defs/src/lib.rs" "/checkout/compiler/rustc_query_impl/src/profiling_support.rs" "/checkout/compiler/rustc_query_impl/src/lib.rs" "/checkout/compiler/rustc_query_impl/src/plumbing.rs" "/checkout/compiler/rustc_metadata/src/errors.rs" "/checkout/compiler/rustc_metadata/src/locator.rs" "/checkout/compiler/rustc_metadata/src/native_libs.rs" "/checkout/compiler/rustc_metadata/src/foreign_modules.rs" "/checkout/compiler/rustc_metadata/src/rmeta/table.rs" "/checkout/compiler/rustc_metadata/src/rmeta/decoder.rs" "/checkout/compiler/rustc_metadata/src/rmeta/encoder.rs" "/checkout/compiler/rustc_metadata/src/rmeta/mod.rs" "/checkout/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs" "/checkout/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs" "/checkout/compiler/rustc_metadata/src/lib.rs" "/checkout/compiler/rustc_metadata/src/creader.rs" "/checkout/compiler/rustc_metadata/src/dependency_format.rs" "/checkout/compiler/rustc_metadata/src/fs.rs" "/checkout/compiler/rustc_ast_passes/src/node_count.rs" "/checkout/compiler/rustc_ast_passes/src/errors.rs" "/checkout/compiler/rustc_ast_passes/src/feature_gate.rs" "/checkout/compiler/rustc_ast_passes/src/lib.rs" "/checkout/compiler/rustc_ast_passes/src/show_span.rs" "/checkout/compiler/rustc_ast_passes/src/ast_validation.rs" "/checkout/compiler/rustc_fs_util/src/lib.rs" "/checkout/compiler/rustc_ast_ir/src/lib.rs" "/checkout/compiler/rustc_ast_ir/src/visit.rs" "/checkout/compiler/rustc_target/src/spec/crt_objects.rs" "/checkout/compiler/rustc_target/src/spec/mod.rs" "/checkout/compiler/rustc_target/src/spec/tests/tests_impl.rs" "/checkout/compiler/rustc_target/src/spec/base/aix.rs" "/checkout/compiler/rustc_target/src/spec/base/windows_gnu.rs" "/checkout/compiler/rustc_target/src/spec/base/fuchsia.rs" "/checkout/compiler/rustc_target/src/spec/base/xtensa.rs" "/checkout/compiler/rustc_target/src/spec/base/hermit.rs" "/checkout/compiler/rustc_target/src/spec/base/avr_gnu.rs" "/checkout/compiler/rustc_target/src/spec/base/teeos.rs" "/checkout/compiler/rustc_target/src/spec/base/netbsd.rs" "/checkout/compiler/rustc_target/src/spec/base/illumos.rs" "/checkout/compiler/rustc_target/src/spec/base/apple/mod.rs" "/checkout/compiler/rustc_target/src/spec/base/apple/tests.rs" "/checkout/compiler/rustc_target/src/spec/base/hurd.rs" "/checkout/compiler/rustc_target/src/spec/base/mod.rs" "/checkout/compiler/rustc_target/src/spec/base/dragonfly.rs" "/checkout/compiler/rustc_target/src/spec/base/hurd_gnu.rs" "/checkout/compiler/rustc_target/src/spec/base/linux_ohos.rs" "/checkout/compiler/rustc_target/src/spec/base/nto_qnx.rs" "/checkout/compiler/rustc_target/src/spec/base/android.rs" "/checkout/compiler/rustc_target/src/spec/base/windows_uwp_msvc.rs" "/checkout/compiler/rustc_borrowck/src/places_conflict.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
  local time: Fri Aug 23 19:00:36 UTC 2024
  network time: Fri, 23 Aug 2024 19:00:36 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@compiler-errors
Copy link
Member

The title doesn't seem to reflect what is actually implemented in this PR: traits_in_crate is not referenced anywhere in the code.

@xonx4l
Copy link
Author

xonx4l commented Aug 24, 2024

@compiler-errors I wrote that in reference to the issue and that's why I specified what implemented in pr note .

@compiler-errors
Copy link
Member

Why not just change the title of the PR?

Also, please run the formatter (./x.py fmt) and squash the commit history -- this doesn't need to be 3 commits for a 3 file change.

r? @cjgillot since you're mentoring this issue, though I'm happy to review it if you're busy.

@rustbot rustbot assigned cjgillot and unassigned michaelwoerister Aug 24, 2024
@cjgillot
Copy link
Contributor

Preliminary questions:

  • this PR adds a new query, but does not use it anywhere, why?
  • you say you keep sorting to preserve existing behaviour, but there is no such behaviour, could you elaborate?

@xonx4l
Copy link
Author

xonx4l commented Aug 25, 2024

Regarding sorting to preserve existing behavior I made an assumption about existing sorting behavior but after reviewing the code more carefully, I see that there isn't an existing sorting behavior for impls_in_crate that needs to be preserved.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2024
@alex-semenyuk
Copy link
Member

alex-semenyuk commented Sep 25, 2024

@xonx4l
From wg-triage. Are you interested in proceeding with this PR? There are some comments and some failed pipelines

@alex-semenyuk
Copy link
Member

@xonx4l
From wg-triage. Closed this PR due to inactivity. Feel free to reopen or raised new one. Thanks for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants