Some renamings for clarity

This commit is contained in:
Florian Diebold 2019-07-09 21:34:23 +02:00
parent c4e2e36e4c
commit 0a20770f46
9 changed files with 28 additions and 25 deletions

View file

@ -189,9 +189,9 @@ pub trait HirDatabase: DefDatabase + AstDatabase {
/// because Chalk does its own internal caching, the solver is wrapped in a
/// Mutex and the query is marked volatile, to make sure the cached state is
/// thrown away when input facts change.
#[salsa::invoke(crate::ty::traits::solver_query)]
#[salsa::invoke(crate::ty::traits::trait_solver_query)]
#[salsa::volatile]
fn solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>;
fn trait_solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>;
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk_ir::TypeId) -> Arc<chalk_rust_ir::AssociatedTyDatum>;
@ -213,8 +213,8 @@ pub trait HirDatabase: DefDatabase + AstDatabase {
#[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)]
fn impl_datum(&self, krate: Crate, impl_id: chalk_ir::ImplId) -> Arc<chalk_rust_ir::ImplDatum>;
#[salsa::invoke(crate::ty::traits::solve_query)]
fn solve(
#[salsa::invoke(crate::ty::traits::trait_solve_query)]
fn trait_solve(
&self,
krate: Crate,
goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>,

View file

@ -26,7 +26,7 @@ pub(crate) use lower::{
callable_item_sig, generic_defaults_query, generic_predicates_query, type_for_def,
type_for_field, TypableDef,
};
pub(crate) use traits::{Environment, InEnvironment, Obligation, ProjectionPredicate};
pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
/// A type constructor or type name: this might be something like the primitive
/// type `bool`, a struct like `Vec`, or things like function pointers or

View file

@ -68,7 +68,7 @@ fn deref_by_trait(
let canonical = super::Canonical { num_vars: 1 + ty.num_vars, value: in_env };
let solution = db.solve(krate, canonical)?;
let solution = db.trait_solve(krate, canonical)?;
match &solution {
Solution::Unique(vars) => {

View file

@ -29,8 +29,8 @@ use test_utils::tested_by;
use super::{
autoderef, lower, method_resolution, op, primitive,
traits::{Guidance, Obligation, ProjectionPredicate, Solution},
ApplicationTy, CallableDef, Environment, InEnvironment, ProjectionTy, Substs, TraitRef, Ty,
TypableDef, TypeCtor,
ApplicationTy, CallableDef, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef,
Ty, TypableDef, TypeCtor,
};
use crate::{
adt::VariantDef,
@ -170,7 +170,7 @@ struct InferenceContext<'a, D: HirDatabase> {
body: Arc<Body>,
resolver: Resolver,
var_unification_table: InPlaceUnificationTable<TypeVarId>,
trait_env: Arc<Environment>,
trait_env: Arc<TraitEnvironment>,
obligations: Vec<Obligation>,
method_resolutions: FxHashMap<ExprId, Function>,
field_resolutions: FxHashMap<ExprId, StructField>,
@ -345,7 +345,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone());
let canonicalized = self.canonicalizer().canonicalize_obligation(in_env);
let solution =
self.db.solve(self.resolver.krate().unwrap(), canonicalized.value.clone());
self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone());
match solution {
Some(Solution::Unique(substs)) => {

View file

@ -317,7 +317,10 @@ pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty {
Ty::from_hir(db, &resolver, type_ref)
}
pub(crate) fn trait_env(db: &impl HirDatabase, resolver: &Resolver) -> Arc<super::Environment> {
pub(crate) fn trait_env(
db: &impl HirDatabase,
resolver: &Resolver,
) -> Arc<super::TraitEnvironment> {
let predicates = resolver
.where_predicates_in_scope()
.map(|pred| {
@ -326,7 +329,7 @@ pub(crate) fn trait_env(db: &impl HirDatabase, resolver: &Resolver) -> Arc<super
})
.collect::<Vec<_>>();
Arc::new(super::Environment { predicates })
Arc::new(super::TraitEnvironment { predicates })
}
/// Resolve the where clause(s) of an item with generics.

View file

@ -7,7 +7,7 @@ use std::sync::Arc;
use arrayvec::ArrayVec;
use rustc_hash::FxHashMap;
use super::{autoderef, lower, Canonical, Environment, InEnvironment, TraitRef};
use super::{autoderef, lower, Canonical, InEnvironment, TraitEnvironment, TraitRef};
use crate::{
generics::HasGenericParams,
impl_block::{ImplBlock, ImplId, ImplItem},
@ -214,7 +214,7 @@ fn iterate_trait_method_candidates<T>(
if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
if !known_implemented {
let goal = generic_implements_goal(db, env.clone(), t, ty.clone());
if db.solve(krate, goal).is_none() {
if db.trait_solve(krate, goal).is_none() {
continue 'traits;
}
}
@ -283,7 +283,7 @@ impl Ty {
/// for all other parameters, to query Chalk with it.
fn generic_implements_goal(
db: &impl HirDatabase,
env: Arc<Environment>,
env: Arc<TraitEnvironment>,
trait_: Trait,
self_ty: Canonical<Ty>,
) -> Canonical<InEnvironment<super::Obligation>> {

View file

@ -27,7 +27,7 @@ struct ChalkContext<'a, DB> {
krate: Crate,
}
pub(crate) fn solver_query(_db: &impl HirDatabase, _krate: Crate) -> Arc<Mutex<Solver>> {
pub(crate) fn trait_solver_query(_db: &impl HirDatabase, _krate: Crate) -> Arc<Mutex<Solver>> {
// krate parameter is just so we cache a unique solver per crate
let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE };
debug!("Creating new solver for crate {:?}", _krate);
@ -60,7 +60,7 @@ fn solve(
goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal>>,
) -> Option<chalk_solve::Solution> {
let context = ChalkContext { db, krate };
let solver = db.solver(krate);
let solver = db.trait_solver(krate);
debug!("solve goal: {:?}", goal);
let solution = solver.lock().solve_with_fuel(&context, goal, Some(1000));
debug!("solve({:?}) => {:?}", goal, solution);
@ -73,19 +73,19 @@ fn solve(
/// ```
/// we assume that `T: Default`.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Environment {
pub struct TraitEnvironment {
pub predicates: Vec<GenericPredicate>,
}
/// Something (usually a goal), along with an environment.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct InEnvironment<T> {
pub environment: Arc<Environment>,
pub environment: Arc<TraitEnvironment>,
pub value: T,
}
impl<T> InEnvironment<T> {
pub fn new(environment: Arc<Environment>, value: T) -> InEnvironment<T> {
pub fn new(environment: Arc<TraitEnvironment>, value: T) -> InEnvironment<T> {
InEnvironment { environment, value }
}
}
@ -117,12 +117,12 @@ pub struct ProjectionPredicate {
}
/// Solve a trait goal using Chalk.
pub(crate) fn solve_query(
pub(crate) fn trait_solve_query(
db: &impl HirDatabase,
krate: Crate,
trait_ref: Canonical<InEnvironment<Obligation>>,
) -> Option<Solution> {
let _p = profile("solve_query");
let _p = profile("trait_solve_query");
let canonical = trait_ref.to_chalk(db).cast();
// We currently don't deal with universes (I think / hope they're not yet
// relevant for our use cases?)

View file

@ -266,7 +266,7 @@ where
}
}
impl ToChalk for Arc<super::Environment> {
impl ToChalk for Arc<super::TraitEnvironment> {
type Chalk = Arc<chalk_ir::Environment>;
fn to_chalk(self, db: &impl HirDatabase) -> Arc<chalk_ir::Environment> {
@ -289,7 +289,7 @@ impl ToChalk for Arc<super::Environment> {
fn from_chalk(
_db: &impl HirDatabase,
_env: Arc<chalk_ir::Environment>,
) -> Arc<super::Environment> {
) -> Arc<super::TraitEnvironment> {
unimplemented!()
}
}

View file

@ -302,7 +302,7 @@ impl RootDatabase {
hir::db::TraitDatumQuery
hir::db::StructDatumQuery
hir::db::ImplDatumQuery
hir::db::SolveQuery
hir::db::TraitSolveQuery
];
acc.sort_by_key(|it| std::cmp::Reverse(it.1));
acc