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 /// 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 /// Mutex and the query is marked volatile, to make sure the cached state is
/// thrown away when input facts change. /// thrown away when input facts change.
#[salsa::invoke(crate::ty::traits::solver_query)] #[salsa::invoke(crate::ty::traits::trait_solver_query)]
#[salsa::volatile] #[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)] #[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk_ir::TypeId) -> Arc<chalk_rust_ir::AssociatedTyDatum>; 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)] #[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>; fn impl_datum(&self, krate: Crate, impl_id: chalk_ir::ImplId) -> Arc<chalk_rust_ir::ImplDatum>;
#[salsa::invoke(crate::ty::traits::solve_query)] #[salsa::invoke(crate::ty::traits::trait_solve_query)]
fn solve( fn trait_solve(
&self, &self,
krate: Crate, krate: Crate,
goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>, 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, callable_item_sig, generic_defaults_query, generic_predicates_query, type_for_def,
type_for_field, TypableDef, 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 /// 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 /// 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 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 { match &solution {
Solution::Unique(vars) => { Solution::Unique(vars) => {

View file

@ -29,8 +29,8 @@ use test_utils::tested_by;
use super::{ use super::{
autoderef, lower, method_resolution, op, primitive, autoderef, lower, method_resolution, op, primitive,
traits::{Guidance, Obligation, ProjectionPredicate, Solution}, traits::{Guidance, Obligation, ProjectionPredicate, Solution},
ApplicationTy, CallableDef, Environment, InEnvironment, ProjectionTy, Substs, TraitRef, Ty, ApplicationTy, CallableDef, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef,
TypableDef, TypeCtor, Ty, TypableDef, TypeCtor,
}; };
use crate::{ use crate::{
adt::VariantDef, adt::VariantDef,
@ -170,7 +170,7 @@ struct InferenceContext<'a, D: HirDatabase> {
body: Arc<Body>, body: Arc<Body>,
resolver: Resolver, resolver: Resolver,
var_unification_table: InPlaceUnificationTable<TypeVarId>, var_unification_table: InPlaceUnificationTable<TypeVarId>,
trait_env: Arc<Environment>, trait_env: Arc<TraitEnvironment>,
obligations: Vec<Obligation>, obligations: Vec<Obligation>,
method_resolutions: FxHashMap<ExprId, Function>, method_resolutions: FxHashMap<ExprId, Function>,
field_resolutions: FxHashMap<ExprId, StructField>, 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 in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone());
let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); let canonicalized = self.canonicalizer().canonicalize_obligation(in_env);
let solution = 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 { match solution {
Some(Solution::Unique(substs)) => { 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) 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 let predicates = resolver
.where_predicates_in_scope() .where_predicates_in_scope()
.map(|pred| { .map(|pred| {
@ -326,7 +329,7 @@ pub(crate) fn trait_env(db: &impl HirDatabase, resolver: &Resolver) -> Arc<super
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Arc::new(super::Environment { predicates }) Arc::new(super::TraitEnvironment { predicates })
} }
/// Resolve the where clause(s) of an item with generics. /// Resolve the where clause(s) of an item with generics.

View file

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

View file

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

View file

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