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 flag for enabling global cache usage for proof trees and printing proof trees on error #113296

Merged
merged 5 commits into from
Jul 5, 2023

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Jul 3, 2023

This adds a few new things:

  • -Zdump-solver-proof-tree=always/never/on-error
    • always/never were previosuly specifiable by whether the flag exists or not, th new flag is on_error which reruns obligations of fulfillment and selection errors with proof tree generation enabled and prints them out
  • -Zdump-solver-proof-tree-uses-cache
    • allows forcing global cache to be used or unused for all generated proof trees, global cache is enabled by default for always so that it accurately represents what happend. This flag currently would affect misc uses of GenerateProofTree::Yes which will be added in the future for things like diagnostics logic and rustdoc's auto_trait file. We can fix this when we start using proof tree generation for those use cases if it's desirable.

I also changed the output to go straight to stdout instead of going through debug! so that -Zdump-solver-proof-tree can be adequately used on nightly not just a locally built toolchain.

The idea for on-error is that it should hopefully make it easier to quickly figure out "why doesnt this code compile"- you just pass in -Zdump-solver-proof-tree=on-error and you'll only get proof trees you care about.


r? @lcnr @compiler-errors

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 3, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@BoxyUwU BoxyUwU changed the title add flag for disabling global cache for proof trees and printing proof trees on error add flag for enabling global cache usage for proof trees and printing proof trees on error Jul 3, 2023
@BoxyUwU BoxyUwU force-pushed the proof_trees_on_error branch 2 times, most recently from 90d171d to 96049a8 Compare July 3, 2023 19:56
@BoxyUwU BoxyUwU force-pushed the proof_trees_on_error branch from 96049a8 to 040aa58 Compare July 3, 2023 20:00
@@ -3499,3 +3513,16 @@ pub enum DefIdOrName {
DefId(DefId),
Name(&'static str),
}

pub fn dump_proof_tree<'tcx>(o: &Obligation<'tcx, ty::Predicate<'tcx>>, infcx: &InferCtxt<'tcx>) {
Copy link
Member

Choose a reason for hiding this comment

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

Noting that since this happens during error reporting, there may have been inference done in between when the goal was registered in the fulfillment context and now, but it's probably fine, since the proof tree will probably still explain why something failed pretty clearly.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh that's actually kind of unfortunate

compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_trait_selection/src/solve/eval_ctxt.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@lcnr lcnr 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 after review

compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/config.rs Outdated Show resolved Hide resolved
"dump a proof tree for every goal evaluated by the new trait solver. If the flag is specified without any options after it
then it defaults to `always`. If the flag is not specified at all it defaults to `on-request`."),
dump_solver_proof_tree_use_cache: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
"determines whether proof tree generation uses the global cache"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"determines whether proof tree generation uses the global cache"),
"determines whether dumping proof trees should disable the global cache"),

this flag should not affect general proof tree generation, only the proof trees which should get dumped

Copy link
Member Author

Choose a reason for hiding this comment

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

that's.... not how the code works. the flag does cause us to use or not use the global cache during proof tree creation. It's not a step done when we dump the proof tree to edit all the "GLOBAL CACHE HIT" to actual proof trees. Implementing it that way sounds trickier than what was done in this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

from the description:

This flag currently would affect misc uses of GenerateProofTree::Yes which will be added in the future for things like diagnostics logic and rustdoc's auto_trait file. We can fix this when we start using proof tree generation for those use cases if it's desirable.

When -Zdump-solver-proof-tree-use-cache=no/yes is set it acts on every call to evaluate_goal with GenerateProofTree::Yes and also to all proof trees generated by -Zdump-solver-proof-tree=always

Copy link
Contributor

Choose a reason for hiding this comment

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

my thought was that setting this to true does/will not prevent diagnostics and auto trait computation from disabling the cache, so this only affects trait solving when we construct a tree for "proof tree dumping"

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally that's how it would work but right now it wouldn't if you implemented auto_trait/diagnostics by callign evalaute_goal with GenerateProofTree::Yes(UseGlobalCache::No).

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but that would completely ignore this compile flag

compiler/rustc_trait_selection/src/solve/inspect.rs Outdated Show resolved Hide resolved
compiler/rustc_trait_selection/src/solve/inspect.rs Outdated Show resolved Hide resolved
@BoxyUwU BoxyUwU force-pushed the proof_trees_on_error branch from 5bed20b to 284b614 Compare July 4, 2023 13:56
@lcnr
Copy link
Contributor

lcnr commented Jul 4, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 4, 2023

📌 Commit 284b614 has been approved by lcnr

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 Jul 4, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 4, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#113192 (`assemble_candidates_after_normalizing_self_ty` docs)
 - rust-lang#113251 (Use scoped-tls for SMIR to  map between TyCtxt and SMIR datastructures)
 - rust-lang#113282 (Update platform-support.md to improve ARM target descriptions)
 - rust-lang#113296 (add flag for enabling global cache usage for proof trees and printing proof trees on error)
 - rust-lang#113324 (implement `ConstEvaluatable` goals in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 494e67c into rust-lang:master Jul 5, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jul 5, 2023
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants