From a2050ba12d4c717478ec9da176090de1609e8b07 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 8 Jun 2023 19:23:24 +0100 Subject: [PATCH] add -Z flag --- compiler/rustc_session/src/options.rs | 2 ++ .../rustc_trait_selection/src/solve/eval_ctxt.rs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3d9f0a4e268..edf95949d32 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1436,6 +1436,8 @@ options! { "output statistics about monomorphization collection"), dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED], "the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"), + dump_solver_proof_tree: bool = (false, parse_bool, [UNTRACKED], + "dump a proof tree for every goal evaluated by the new trait solver"), dwarf_version: Option = (None, parse_opt_number, [TRACKED], "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), dylib_lto: bool = (false, parse_bool, [UNTRACKED], diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs index 6aff9e45cb4..7ac1ef19bbc 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs @@ -147,13 +147,21 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> { var_values: CanonicalVarValues::dummy(), nested_goals: NestedGoals::new(), tainted: Ok(()), - inspect: Box::new(DebugSolver::new()), + inspect: match self.tcx.sess.opts.unstable_opts.dump_solver_proof_tree { + true => Box::new(DebugSolver::new()), + false => Box::new(()), + }, }; let result = ecx.evaluate_goal(IsNormalizesToHack::No, goal); - let tree = match ecx.inspect.into_debug_solver() { + let tcx = ecx.tcx(); + match ecx.inspect.into_debug_solver() { Some(tree) => match Box::leak(tree) { - DebugSolver::GoalEvaluation(tree) => tree, + DebugSolver::GoalEvaluation(tree) => { + if tcx.sess.opts.unstable_opts.dump_solver_proof_tree { + println!("{:?}", tree); + } + } _ => unreachable!("unable to convert to `DebugSolver::GoalEvaluation`"), }, _ => unreachable!("unable to convert to `DebugSolver::GoalEvaluation`"),