Skip to content

Compiletest should set RUST_SAVE_ANALYSIS_CONFIG for run-pass tests #96928

Closed as not planned

Description

@jyn514

#96777 was necessary because a test used both -Zsave-analysis and run-pass. That generated an untracked save-analysis-temp file in the root directory. That behavior is not great - we shouldn't do that even if the test is marked run-pass. We can avoid it by passing --out-dir config.build_base in compiletest:

match output_file {
TargetLocation::ThisFile(path) => {
rustc.arg("-o").arg(path);
}
TargetLocation::ThisDirectory(path) => {
if is_rustdoc {
// `rustdoc` uses `-o` for the output directory.
rustc.arg("-o").arg(path);
} else {
rustc.arg("--out-dir").arg(path);
}
}
}

We should also investigate why this wasn't caught by CI - it makes the source directory read only, which should have prevented this being merged.

@rustbot label +E-easy +A-testsuite +E-mentor

Activity

  1. added
    A-testsuiteArea: The testsuite used to check the correctness of rustc
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on May 10, 2022
  2. jyn514 commented on May 10, 2022

    @jyn514
    MemberAuthor

    We should also investigate why this wasn't caught by CI - it makes the source directory read only, which should have prevented this being merged.

    I think it might run x.py from a working directory other than the source root.

  3. kingdido999 commented on May 12, 2022

    @kingdido999

    @rustbot claim

  4. lionellloh commented on May 25, 2022

    @lionellloh
    Contributor

    @kingdido999 are you still working on it?

  5. lionellloh commented on May 30, 2022

    @lionellloh
    Contributor

    @rustbot claim

  6. lionellloh commented on May 30, 2022

    @lionellloh
    Contributor

    Hey @jyn514, thanks for offering to mentor!

    Some questions -

    What is the difference between check-pass and run-pass?

    That generated an untracked save-analysis-temp file in the root directory.

    What is the best way to repro this?

  7. jyn514 commented on May 30, 2022

    @jyn514
    MemberAuthor

    @lionellloh "the difference between cargo check and cargo run" - the first just runs rustc --emit metadata while the second actually generates a binary and runs it. The reason it causes trouble here is because save-analysis uses --out-dir to determine where to put the generated JSON file, and defaults to the working directory if it isn't passed.

    What is the best way to repro this?

    Change any existing UI test with -Z save-analysis and check-pass to be run-pass instead.

  8. lionellloh commented on May 30, 2022

    @lionellloh
    Contributor

    @jyn514

    Qq regarding dev efficiency:
    I managed to repro the issue by running ./x.py test src/test/ui/const-generics/const-argument-non-static-lifetime.rs and changing check-pass to be run-pass.

    The command ran for 10 minutes. I deleted the save-analysis-temp folder after the repro, made my patch and tried to run again. I realised the tests were ignored this time. I deleted the build folder so that the tests may not be ignored, but it seems like that causes the test to run for a pretty long time again. I wonder if that is avoidable?

    One more n00b qn:
    I am a little curious how // [full] run-pass is parsed. They seem like comments to me. Why does changing it change anything?

  9. jyn514 commented on May 30, 2022

    @jyn514
    MemberAuthor

    @lionellloh touch src/test/ui/const-generics/const-argument-non-static-lifetime.rs should work and be quite fast.

  10. jyn514 commented on May 30, 2022

    @jyn514
    MemberAuthor

    I think there's also a force-rerun flag or something like that.

  11. 14 remaining items

  12. removed their assignment
    on Nov 27, 2022
  13. azadnn commented on Jan 12, 2023

    @azadnn

    @rustbot claim

  14. azadnn commented on Jan 12, 2023

    @azadnn

    Hi @jyn514,
    I have spent some time looking at this issue and I can see that, as you indicated above, the (only) likely solution is to set the RUST_SAVE_ANALYSIS_CONFIG environment variable. This is because rustc_save_analysis is always called with config=None as can be seen here:

    sess.time("save_analysis", || {
    save::process_crate(
    tcx,
    crate_name,
    compiler.input(),
    None,
    DumpHandler::new(compiler.output_dir().as_deref(), crate_name),
    )
    });

    I see an example of the RUST_SAVE_ANALYSIS_CONFIG env variable though output_file is null here:

    rust/src/bootstrap/builder.rs

    Lines 1795 to 1801 in 40ba0e8

    rustflags.arg("-Zsave-analysis");
    cargo.env(
    "RUST_SAVE_ANALYSIS_CONFIG",
    "{\"output_file\": null,\"full_docs\": false,\
    \"pub_only\": true,\"reachable_only\": false,\
    \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}",
    );

    My observation is that when run-pass tests are run, output_file matches TargetLocation::ThisFile(path) which is where I propose to set the environment variable:
    match output_file {
    TargetLocation::ThisFile(path) => {
    rustc.arg("-o").arg(path);
    }

    I should post a PR soon

  15. added
    A-save-analysisArea: saving results of analyses such as inference and borrowck results to a file.
    on Jan 13, 2023
  16. added a commit that references this issue on Jan 29, 2023
    b2032e4
  17. added a commit that references this issue on Jan 30, 2023
    0b9209d
  18. jyn514 commented on Feb 19, 2023

    @jyn514
    MemberAuthor

    Save-analysis has been removed from the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-save-analysisArea: saving results of analyses such as inference and borrowck results to a file.A-testsuiteArea: The testsuite used to check the correctness of rustcE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions