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

Split -Zchalk flag into -Ztrait-solver=(classic|chalk|next) flag #106385

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::interface::parse_cfgspecs;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
use rustc_session::config::rustc_optgroups;
use rustc_session::config::TraitSolver;
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
use rustc_session::config::{
BranchProtection, Externs, OomStrategy, OutputType, OutputTypes, PAuthKey, PacRet,
Expand Down Expand Up @@ -722,7 +723,6 @@ fn test_unstable_options_tracking_hash() {
pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
})
);
tracked!(chalk, true);
tracked!(codegen_backend, Some("abc".to_string()));
tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(debug_info_for_profiling, true);
Expand Down Expand Up @@ -792,6 +792,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(thinlto, Some(true));
tracked!(thir_unsafeck, true);
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
tracked!(trait_solver, TraitSolver::Chalk);
tracked!(translate_remapped_path_to_local_path, false);
tracked!(trap_unreachable, Some(false));
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,16 @@ pub enum PrintRequest {
SplitDebuginfo,
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum TraitSolver {
/// Classic trait solver in `rustc_trait_selection::traits::select`
Classic,
/// Chalk trait solver
Chalk,
/// Experimental trait solver in `rustc_trait_selection::solve`
Next,
}

pub enum Input {
/// Load source code from a file.
File(PathBuf),
Expand Down Expand Up @@ -2761,7 +2771,7 @@ pub(crate) mod dep_tracking {
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel,
OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SplitDwarfKind,
SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
};
use crate::lint;
use crate::options::WasiExecModel;
Expand Down Expand Up @@ -2861,6 +2871,7 @@ pub(crate) mod dep_tracking {
BranchProtection,
OomStrategy,
LanguageIdentifier,
TraitSolver,
);

impl<T1, T2> DepTrackingHash for (T1, T2)
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ mod desc {
"`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
pub const parse_unpretty: &str = "`string` or `string=string`";
pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
pub const parse_trait_solver: &str =
"one of the supported solver modes (`classic`, `chalk`, or `next`)";
pub const parse_lto: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
pub const parse_linker_plugin_lto: &str =
Expand Down Expand Up @@ -880,6 +882,18 @@ mod parse {
}
}

pub(crate) fn parse_trait_solver(slot: &mut TraitSolver, v: Option<&str>) -> bool {
match v {
Some("classic") => *slot = TraitSolver::Classic,
Some("chalk") => *slot = TraitSolver::Chalk,
Some("next") => *slot = TraitSolver::Next,
// default trait solver is subject to change..
Some("default") => *slot = TraitSolver::Classic,
_ => return false,
}
true
}

pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
if v.is_some() {
let mut bool_arg = None;
Expand Down Expand Up @@ -1249,8 +1263,6 @@ options! {
"instrument control-flow architecture protection"),
cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
"the codegen unit partitioning strategy to use"),
chalk: bool = (false, parse_bool, [TRACKED],
"enable the experimental Chalk-based trait solving engine"),
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
"the backend to use"),
combine_cgu: bool = (false, parse_bool, [TRACKED],
Expand Down Expand Up @@ -1609,6 +1621,8 @@ options! {
"for every macro invocation, print its name and arguments (default: no)"),
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
"tracks where in rustc a diagnostic was emitted"),
trait_solver: TraitSolver = (TraitSolver::Classic, parse_trait_solver, [TRACKED],
"specify the trait solver mode used by rustc (default: classic)"),
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
// alongside query results and changes to translation options can affect diagnostics - so
// translation options should be tracked.
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Debug;

use super::TraitEngine;
use super::{ChalkFulfillmentContext, FulfillmentContext};
use crate::solve::FulfillmentCtxt as NextFulfillmentCtxt;
use crate::traits::NormalizeExt;
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand All @@ -20,6 +21,7 @@ use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config::TraitSolver;
use rustc_span::Span;

pub trait TraitEngineExt<'tcx> {
Expand All @@ -29,18 +31,18 @@ pub trait TraitEngineExt<'tcx> {

impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> Box<Self> {
if tcx.sess.opts.unstable_opts.chalk {
Box::new(ChalkFulfillmentContext::new())
} else {
Box::new(FulfillmentContext::new())
match tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Classic => Box::new(FulfillmentContext::new()),
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new()),
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
}
}

fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self> {
if tcx.sess.opts.unstable_opts.chalk {
Box::new(ChalkFulfillmentContext::new_in_snapshot())
} else {
Box::new(FulfillmentContext::new_in_snapshot())
match tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Classic => Box::new(FulfillmentContext::new_in_snapshot()),
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new_in_snapshot()),
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use rustc_middle::ty::{
self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable,
TypeVisitable,
};
use rustc_session::config::TraitSolver;
use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -1167,7 +1168,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}

ty::PredicateKind::WellFormed(ty) => {
if !self.tcx.sess.opts.unstable_opts.chalk {
if self.tcx.sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
Copy link
Contributor

Choose a reason for hiding this comment

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

the new solver can also error for WellFormed by themselves

// WF predicates cannot themselves make
// errors. They can only block due to
// ambiguity; otherwise, they always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_middle::ty::{
self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::DefId;

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

// FIXME: Chalk

if !self.tcx().sess.opts.unstable_opts.chalk {
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
nested.push(obligation.with(
self.tcx(),
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)),
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
use rustc_session::config::TraitSolver;
use rustc_trait_selection::traits;

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

if tcx.sess.opts.unstable_opts.chalk {
if tcx.sess.opts.unstable_opts.trait_solver == TraitSolver::Chalk {
let environment = well_formed_types_in_env(tcx, def_id);
predicates.extend(environment);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/z-help.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
-Z branch-protection=val -- set options for branch target identification and pointer authentication on AArch64
-Z cf-protection=val -- instrument control-flow architecture protection
-Z cgu-partitioning-strategy=val -- the codegen unit partitioning strategy to use
-Z chalk=val -- enable the experimental Chalk-based trait solving engine
-Z codegen-backend=val -- the backend to use
-Z combine-cgu=val -- combine CGUs into a single one
-Z crate-attr=val -- inject the given attribute in the crate
Expand Down Expand Up @@ -175,6 +174,7 @@
-Z tls-model=val -- choose the TLS model to use (`rustc --print tls-models` for details)
-Z trace-macros=val -- for every macro invocation, print its name and arguments (default: no)
-Z track-diagnostics=val -- tracks where in rustc a diagnostic was emitted
-Z trait-solver=val -- specify the trait solver mode used by rustc (default: classic)
-Z translate-additional-ftl=val -- additional fluent translation to preferentially use (for testing translation)
-Z translate-directionality-markers=val -- emit directionality isolation markers in translated diagnostics
-Z translate-lang=val -- language identifier for diagnostic output
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

fn main() {
1 + 2;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/assert.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

fn main() {
assert_eq!(1, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo {}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/bugs/async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-fail
// known-bug: unknown
// compile-flags: -Z chalk --edition=2021
// compile-flags: -Z trait-solver=chalk --edition=2021

fn main() -> () {}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/builtin-copy-clone.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/chalk_initial_program.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/closure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

fn main() -> () {
let t = || {};
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/generic_impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/impl_wf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo: Sized { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/impl_wf_2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Split out of impl_wf.rs to work around rust aborting compilation early

// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo: Sized { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/inherent_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/inherent_impl_min.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_env1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

#![allow(dead_code)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_env2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

#![allow(dead_code)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_env3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

#![allow(dead_code)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

struct Foo<'a, T> where Box<T>: Clone {
_x: std::marker::PhantomData<&'a T>,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_trait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Bar { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_trait_higher_rank.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo<F: ?Sized> where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/lower_trait_where_clause.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

use std::borrow::Borrow;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/println.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

fn main() {
println!("hello");
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/projection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/recursive_where_clause_on_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME(chalk): should fail, see comments
// check-fail
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

#![feature(trivial_bounds)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/super_trait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }
trait Bar: Foo { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/trait-objects.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

use std::fmt::Display;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/trait_implied_bound.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z chalk
// compile-flags: -Z trait-solver=chalk

trait Foo { }
trait Bar<U> where U: Foo { }
Expand Down
Loading