Skip to content

Commit 214b33b

Browse files
Rollup merge of rust-lang#106385 - compiler-errors:new-solver-flag, r=jackh726
Split `-Zchalk` flag into `-Ztrait-solver=(classic|chalk|next)` flag We'll eventually need a way to select more than chalk + not-chalk. Does this need an MCP since it's touching a `-Z` flag? Or perhaps I should preserve `-Zchalk` for the time being... maybe I could make it a warning to use that flag? cc `@rust-lang/types` r? types
2 parents c686f43 + 8b0f43b commit 214b33b

39 files changed

+78
-48
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+
/// Classic trait solver in `rustc_trait_selection::traits::select`
560+
Classic,
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

+16-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 (`classic`, `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,18 @@ mod parse {
880882
}
881883
}
882884

885+
pub(crate) fn parse_trait_solver(slot: &mut TraitSolver, v: Option<&str>) -> bool {
886+
match v {
887+
Some("classic") => *slot = TraitSolver::Classic,
888+
Some("chalk") => *slot = TraitSolver::Chalk,
889+
Some("next") => *slot = TraitSolver::Next,
890+
// default trait solver is subject to change..
891+
Some("default") => *slot = TraitSolver::Classic,
892+
_ => return false,
893+
}
894+
true
895+
}
896+
883897
pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
884898
if v.is_some() {
885899
let mut bool_arg = None;
@@ -1249,8 +1263,6 @@ options! {
12491263
"instrument control-flow architecture protection"),
12501264
cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
12511265
"the codegen unit partitioning strategy to use"),
1252-
chalk: bool = (false, parse_bool, [TRACKED],
1253-
"enable the experimental Chalk-based trait solving engine"),
12541266
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
12551267
"the backend to use"),
12561268
combine_cgu: bool = (false, parse_bool, [TRACKED],
@@ -1609,6 +1621,8 @@ options! {
16091621
"for every macro invocation, print its name and arguments (default: no)"),
16101622
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
16111623
"tracks where in rustc a diagnostic was emitted"),
1624+
trait_solver: TraitSolver = (TraitSolver::Classic, parse_trait_solver, [TRACKED],
1625+
"specify the trait solver mode used by rustc (default: classic)"),
16121626
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
16131627
// alongside query results and changes to translation options can affect diagnostics - so
16141628
// 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::Classic => 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::Classic => 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
}

src/test/rustdoc-ui/z-help.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
-Z branch-protection=val -- set options for branch target identification and pointer authentication on AArch64
99
-Z cf-protection=val -- instrument control-flow architecture protection
1010
-Z cgu-partitioning-strategy=val -- the codegen unit partitioning strategy to use
11-
-Z chalk=val -- enable the experimental Chalk-based trait solving engine
1211
-Z codegen-backend=val -- the backend to use
1312
-Z combine-cgu=val -- combine CGUs into a single one
1413
-Z crate-attr=val -- inject the given attribute in the crate
@@ -175,6 +174,7 @@
175174
-Z tls-model=val -- choose the TLS model to use (`rustc --print tls-models` for details)
176175
-Z trace-macros=val -- for every macro invocation, print its name and arguments (default: no)
177176
-Z track-diagnostics=val -- tracks where in rustc a diagnostic was emitted
177+
-Z trait-solver=val -- specify the trait solver mode used by rustc (default: classic)
178178
-Z translate-additional-ftl=val -- additional fluent translation to preferentially use (for testing translation)
179179
-Z translate-directionality-markers=val -- emit directionality isolation markers in translated diagnostics
180180
-Z translate-lang=val -- language identifier for diagnostic output

src/test/ui/chalkify/arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
fn main() {
55
1 + 2;

src/test/ui/chalkify/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
fn main() {
55
assert_eq!(1, 1);

src/test/ui/chalkify/basic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo {}
55

src/test/ui/chalkify/bugs/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-fail
22
// known-bug: unknown
3-
// compile-flags: -Z chalk --edition=2021
3+
// compile-flags: -Z trait-solver=chalk --edition=2021
44

55
fn main() -> () {}
66

src/test/ui/chalkify/builtin-copy-clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
// Test that `Clone` is correctly implemented for builtin types.
55

src/test/ui/chalkify/chalk_initial_program.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z chalk
1+
// compile-flags: -Z trait-solver=chalk
22

33
trait Foo { }
44

src/test/ui/chalkify/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z chalk
1+
// compile-flags: -Z trait-solver=chalk
22

33
fn main() -> () {
44
let t = || {};

src/test/ui/chalkify/generic_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z chalk
1+
// compile-flags: -Z trait-solver=chalk
22

33
trait Foo { }
44

src/test/ui/chalkify/impl_wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z chalk
1+
// compile-flags: -Z trait-solver=chalk
22

33
trait Foo: Sized { }
44

src/test/ui/chalkify/impl_wf_2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Split out of impl_wf.rs to work around rust aborting compilation early
22

3-
// compile-flags: -Z chalk
3+
// compile-flags: -Z trait-solver=chalk
44

55
trait Foo: Sized { }
66

src/test/ui/chalkify/inherent_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55

src/test/ui/chalkify/inherent_impl_min.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55

src/test/ui/chalkify/lower_env1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
#![allow(dead_code)]
55

src/test/ui/chalkify/lower_env2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
#![allow(dead_code)]
55

src/test/ui/chalkify/lower_env3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
#![allow(dead_code)]
55

src/test/ui/chalkify/lower_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55

src/test/ui/chalkify/lower_struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
struct Foo<'a, T> where Box<T>: Clone {
55
_x: std::marker::PhantomData<&'a T>,

src/test/ui/chalkify/lower_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Bar { }
55

src/test/ui/chalkify/lower_trait_higher_rank.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo<F: ?Sized> where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8
55
{

src/test/ui/chalkify/lower_trait_where_clause.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
use std::borrow::Borrow;
55

src/test/ui/chalkify/println.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
fn main() {
55
println!("hello");

src/test/ui/chalkify/projection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55

src/test/ui/chalkify/recursive_where_clause_on_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// FIXME(chalk): should fail, see comments
22
// check-fail
3-
// compile-flags: -Z chalk
3+
// compile-flags: -Z trait-solver=chalk
44

55
#![feature(trivial_bounds)]
66

src/test/ui/chalkify/super_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55
trait Bar: Foo { }

src/test/ui/chalkify/trait-objects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
use std::fmt::Display;
55

src/test/ui/chalkify/trait_implied_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z chalk
2+
// compile-flags: -Z trait-solver=chalk
33

44
trait Foo { }
55
trait Bar<U> where U: Foo { }

0 commit comments

Comments
 (0)