Skip to content

Commit a4974fa

Browse files
Split -Zchalk flag into -Ztrait-solver=(stock|chalk|next) flag
1 parent df75643 commit a4974fa

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::interface::parse_cfgspecs;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
66
use rustc_session::config::rustc_optgroups;
7+
use rustc_session::config::TraitSolver;
78
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
89
use rustc_session::config::{
910
BranchProtection, Externs, OomStrategy, OutputType, OutputTypes, PAuthKey, PacRet,
@@ -722,7 +723,6 @@ fn test_unstable_options_tracking_hash() {
722723
pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
723724
})
724725
);
725-
tracked!(chalk, true);
726726
tracked!(codegen_backend, Some("abc".to_string()));
727727
tracked!(crate_attr, vec!["abc".to_string()]);
728728
tracked!(debug_info_for_profiling, true);
@@ -792,6 +792,7 @@ fn test_unstable_options_tracking_hash() {
792792
tracked!(thinlto, Some(true));
793793
tracked!(thir_unsafeck, true);
794794
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
795+
tracked!(trait_solver, TraitSolver::Chalk);
795796
tracked!(translate_remapped_path_to_local_path, false);
796797
tracked!(trap_unreachable, Some(false));
797798
tracked!(treat_err_as_bug, NonZeroUsize::new(1));

compiler/rustc_session/src/config.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,16 @@ pub enum PrintRequest {
554554
SplitDebuginfo,
555555
}
556556

557+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
558+
pub enum TraitSolver {
559+
/// Stock trait solver in `rustc_trait_selection::traits::select`
560+
Stock,
561+
/// Chalk trait solver
562+
Chalk,
563+
/// Experimental trait solver in `rustc_trait_selection::solve`
564+
Next,
565+
}
566+
557567
pub enum Input {
558568
/// Load source code from a file.
559569
File(PathBuf),
@@ -2761,7 +2771,7 @@ pub(crate) mod dep_tracking {
27612771
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
27622772
InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel,
27632773
OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SplitDwarfKind,
2764-
SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
2774+
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
27652775
};
27662776
use crate::lint;
27672777
use crate::options::WasiExecModel;
@@ -2861,6 +2871,7 @@ pub(crate) mod dep_tracking {
28612871
BranchProtection,
28622872
OomStrategy,
28632873
LanguageIdentifier,
2874+
TraitSolver,
28642875
);
28652876

28662877
impl<T1, T2> DepTrackingHash for (T1, T2)

compiler/rustc_session/src/options.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ mod desc {
382382
"`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
383383
pub const parse_unpretty: &str = "`string` or `string=string`";
384384
pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
385+
pub const parse_trait_solver: &str =
386+
"one of the supported solver modes (`stock`, `chalk`, or `next`)";
385387
pub const parse_lto: &str =
386388
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
387389
pub const parse_linker_plugin_lto: &str =
@@ -880,6 +882,16 @@ mod parse {
880882
}
881883
}
882884

885+
pub(crate) fn parse_trait_solver(slot: &mut TraitSolver, v: Option<&str>) -> bool {
886+
match v {
887+
Some("stock") => *slot = TraitSolver::Stock,
888+
Some("chalk") => *slot = TraitSolver::Chalk,
889+
Some("next") => *slot = TraitSolver::Next,
890+
_ => return false,
891+
}
892+
true
893+
}
894+
883895
pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
884896
if v.is_some() {
885897
let mut bool_arg = None;
@@ -1249,8 +1261,6 @@ options! {
12491261
"instrument control-flow architecture protection"),
12501262
cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
12511263
"the codegen unit partitioning strategy to use"),
1252-
chalk: bool = (false, parse_bool, [TRACKED],
1253-
"enable the experimental Chalk-based trait solving engine"),
12541264
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
12551265
"the backend to use"),
12561266
combine_cgu: bool = (false, parse_bool, [TRACKED],
@@ -1609,6 +1619,8 @@ options! {
16091619
"for every macro invocation, print its name and arguments (default: no)"),
16101620
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
16111621
"tracks where in rustc a diagnostic was emitted"),
1622+
trait_solver: TraitSolver = (TraitSolver::Stock, parse_trait_solver, [TRACKED],
1623+
"specify the trait solver mode used by rustc (default: stock)"),
16121624
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
16131625
// alongside query results and changes to translation options can affect diagnostics - so
16141626
// translation options should be tracked.

compiler/rustc_trait_selection/src/traits/engine.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Debug;
33

44
use super::TraitEngine;
55
use super::{ChalkFulfillmentContext, FulfillmentContext};
6+
use crate::solve::FulfillmentCtxt as NextFulfillmentCtxt;
67
use crate::traits::NormalizeExt;
78
use rustc_data_structures::fx::FxIndexSet;
89
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -20,6 +21,7 @@ use rustc_middle::ty::error::TypeError;
2021
use rustc_middle::ty::ToPredicate;
2122
use rustc_middle::ty::TypeFoldable;
2223
use rustc_middle::ty::{self, Ty, TyCtxt};
24+
use rustc_session::config::TraitSolver;
2325
use rustc_span::Span;
2426

2527
pub trait TraitEngineExt<'tcx> {
@@ -29,18 +31,18 @@ pub trait TraitEngineExt<'tcx> {
2931

3032
impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
3133
fn new(tcx: TyCtxt<'tcx>) -> Box<Self> {
32-
if tcx.sess.opts.unstable_opts.chalk {
33-
Box::new(ChalkFulfillmentContext::new())
34-
} else {
35-
Box::new(FulfillmentContext::new())
34+
match tcx.sess.opts.unstable_opts.trait_solver {
35+
TraitSolver::Stock => Box::new(FulfillmentContext::new()),
36+
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new()),
37+
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
3638
}
3739
}
3840

3941
fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self> {
40-
if tcx.sess.opts.unstable_opts.chalk {
41-
Box::new(ChalkFulfillmentContext::new_in_snapshot())
42-
} else {
43-
Box::new(FulfillmentContext::new_in_snapshot())
42+
match tcx.sess.opts.unstable_opts.trait_solver {
43+
TraitSolver::Stock => Box::new(FulfillmentContext::new_in_snapshot()),
44+
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new_in_snapshot()),
45+
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
4446
}
4547
}
4648
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use rustc_middle::ty::{
4040
self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable,
4141
TypeVisitable,
4242
};
43+
use rustc_session::config::TraitSolver;
4344
use rustc_session::Limit;
4445
use rustc_span::def_id::LOCAL_CRATE;
4546
use rustc_span::symbol::sym;
@@ -1167,7 +1168,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11671168
}
11681169

11691170
ty::PredicateKind::WellFormed(ty) => {
1170-
if !self.tcx.sess.opts.unstable_opts.chalk {
1171+
if self.tcx.sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
11711172
// WF predicates cannot themselves make
11721173
// errors. They can only block due to
11731174
// ambiguity; otherwise, they always

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::ty::{
1515
self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
1616
ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt,
1717
};
18+
use rustc_session::config::TraitSolver;
1819
use rustc_span::def_id::DefId;
1920

2021
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
@@ -767,8 +768,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
767768
debug!(?closure_def_id, ?trait_ref, ?nested, "confirm closure candidate obligations");
768769

769770
// FIXME: Chalk
770-
771-
if !self.tcx().sess.opts.unstable_opts.chalk {
771+
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
772772
nested.push(obligation.with(
773773
self.tcx(),
774774
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)),

compiler/rustc_ty_utils/src/ty.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
33
use rustc_hir::def_id::DefId;
44
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
5+
use rustc_session::config::TraitSolver;
56
use rustc_trait_selection::traits;
67

78
fn sized_constraint_for_ty<'tcx>(
@@ -121,7 +122,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
121122
// are any errors at that point, so outside of type inference you can be
122123
// sure that this will succeed without errors anyway.
123124

124-
if tcx.sess.opts.unstable_opts.chalk {
125+
if tcx.sess.opts.unstable_opts.trait_solver == TraitSolver::Chalk {
125126
let environment = well_formed_types_in_env(tcx, def_id);
126127
predicates.extend(environment);
127128
}

0 commit comments

Comments
 (0)