aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-10-31 08:43:20 +0000
committerSeivan Heidari <[email protected]>2019-10-31 08:43:20 +0000
commit8edda0e7b164009d6c03bb3d4be603fb38ad2e2a (patch)
tree744cf81075d394e2f9c06afb07642a2601800dda /crates/ra_hir/src/ty
parent49562d36b97ddde34cf7585a8c2e8f232519b657 (diff)
parentd067afb064a7fa67b172abf561b7d80740cd6f18 (diff)
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs3
-rw-r--r--crates/ra_hir/src/ty/infer.rs8
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs3
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs5
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs23
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs15
-rw-r--r--crates/ra_hir/src/ty/primitive.rs22
-rw-r--r--crates/ra_hir/src/ty/traits.rs6
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs157
10 files changed, 124 insertions, 124 deletions
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index 02492ca14..3645ee831 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -5,10 +5,11 @@
5 5
6use std::iter::successors; 6use std::iter::successors;
7 7
8use hir_expand::name;
8use log::{info, warn}; 9use log::{info, warn};
9 10
10use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; 11use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk};
11use crate::{db::HirDatabase, name, HasGenericParams, Resolver}; 12use crate::{db::HirDatabase, HasGenericParams, Resolver};
12 13
13const AUTODEREF_RECURSION_LIMIT: usize = 10; 14const AUTODEREF_RECURSION_LIMIT: usize = 10;
14 15
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index ebaff998e..6694467a3 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -21,6 +21,11 @@ use std::sync::Arc;
21use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; 21use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
22use rustc_hash::FxHashMap; 22use rustc_hash::FxHashMap;
23 23
24use hir_def::{
25 path::known,
26 type_ref::{Mutability, TypeRef},
27};
28use hir_expand::name;
24use ra_arena::map::ArenaMap; 29use ra_arena::map::ArenaMap;
25use ra_prof::profile; 30use ra_prof::profile;
26use test_utils::tested_by; 31use test_utils::tested_by;
@@ -37,11 +42,8 @@ use crate::{
37 db::HirDatabase, 42 db::HirDatabase,
38 diagnostics::DiagnosticSink, 43 diagnostics::DiagnosticSink,
39 expr::{BindingAnnotation, Body, ExprId, PatId}, 44 expr::{BindingAnnotation, Body, ExprId, PatId},
40 name,
41 path::known,
42 resolve::{Resolver, TypeNs}, 45 resolve::{Resolver, TypeNs},
43 ty::infer::diagnostics::InferenceDiagnostic, 46 ty::infer::diagnostics::InferenceDiagnostic,
44 type_ref::{Mutability, TypeRef},
45 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, 47 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField,
46}; 48};
47 49
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index 0429a9866..6ea135126 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -14,8 +14,7 @@ use crate::{
14 lang_item::LangItemTarget, 14 lang_item::LangItemTarget,
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, 16 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk},
17 type_ref::Mutability, 17 Adt, Mutability,
18 Adt,
19}; 18};
20 19
21impl<'a, D: HirDatabase> InferenceContext<'a, D> { 20impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index f8807c742..fed52df39 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -3,14 +3,15 @@
3use std::iter::{repeat, repeat_with}; 3use std::iter::{repeat, repeat_with};
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::path::{GenericArg, GenericArgs};
7use hir_expand::name;
8
6use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; 9use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
7use crate::{ 10use crate::{
8 db::HirDatabase, 11 db::HirDatabase,
9 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 12 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
10 generics::{GenericParams, HasGenericParams}, 13 generics::{GenericParams, HasGenericParams},
11 name,
12 nameres::Namespace, 14 nameres::Namespace,
13 path::{GenericArg, GenericArgs},
14 ty::{ 15 ty::{
15 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, 16 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation,
16 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 17 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index db979353a..77aa35ce1 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -1,5 +1,7 @@
1//! Path expression resolution. 1//! Path expression resolution.
2 2
3use hir_def::path::PathSegment;
4
3use super::{ExprOrPatId, InferenceContext, TraitRef}; 5use super::{ExprOrPatId, InferenceContext, TraitRef};
4use crate::{ 6use crate::{
5 db::HirDatabase, 7 db::HirDatabase,
@@ -131,7 +133,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
131 fn resolve_trait_assoc_item( 133 fn resolve_trait_assoc_item(
132 &mut self, 134 &mut self,
133 trait_ref: TraitRef, 135 trait_ref: TraitRef,
134 segment: &crate::path::PathSegment, 136 segment: &PathSegment,
135 id: ExprOrPatId, 137 id: ExprOrPatId,
136 ) -> Option<(ValueNs, Option<Substs>)> { 138 ) -> Option<(ValueNs, Option<Substs>)> {
137 let trait_ = trait_ref.trait_; 139 let trait_ = trait_ref.trait_;
@@ -170,7 +172,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
170 fn resolve_ty_assoc_item( 172 fn resolve_ty_assoc_item(
171 &mut self, 173 &mut self,
172 ty: Ty, 174 ty: Ty,
173 segment: &crate::path::PathSegment, 175 segment: &PathSegment,
174 id: ExprOrPatId, 176 id: ExprOrPatId,
175 ) -> Option<(ValueNs, Option<Substs>)> { 177 ) -> Option<(ValueNs, Option<Substs>)> {
176 if let Ty::Unknown = ty { 178 if let Ty::Unknown = ty {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 366556134..dd7cd979f 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -8,6 +8,12 @@
8use std::iter; 8use std::iter;
9use std::sync::Arc; 9use std::sync::Arc;
10 10
11use hir_def::{
12 builtin_type::BuiltinType,
13 path::{GenericArg, PathSegment},
14 type_ref::{TypeBound, TypeRef},
15};
16
11use super::{ 17use super::{
12 FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 18 FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
13 TypeWalk, 19 TypeWalk,
@@ -18,13 +24,14 @@ use crate::{
18 generics::HasGenericParams, 24 generics::HasGenericParams,
19 generics::{GenericDef, WherePredicate}, 25 generics::{GenericDef, WherePredicate},
20 nameres::Namespace, 26 nameres::Namespace,
21 path::{GenericArg, PathSegment},
22 resolve::{Resolver, TypeNs}, 27 resolve::{Resolver, TypeNs},
23 ty::Adt, 28 ty::{
24 type_ref::{TypeBound, TypeRef}, 29 primitive::{FloatTy, IntTy},
30 Adt,
31 },
25 util::make_mut_slice, 32 util::make_mut_slice,
26 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, 33 Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
27 Trait, TypeAlias, Union, 34 TypeAlias, Union,
28}; 35};
29 36
30impl Ty { 37impl Ty {
@@ -640,8 +647,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty {
640 BuiltinType::Char => TypeCtor::Char, 647 BuiltinType::Char => TypeCtor::Char,
641 BuiltinType::Bool => TypeCtor::Bool, 648 BuiltinType::Bool => TypeCtor::Bool,
642 BuiltinType::Str => TypeCtor::Str, 649 BuiltinType::Str => TypeCtor::Str,
643 BuiltinType::Int(ty) => TypeCtor::Int(ty.into()), 650 BuiltinType::Int { signedness, bitness } => {
644 BuiltinType::Float(ty) => TypeCtor::Float(ty.into()), 651 TypeCtor::Int(IntTy { signedness, bitness }.into())
652 }
653 BuiltinType::Float { bitness } => TypeCtor::Float(FloatTy { bitness }.into()),
645 }) 654 })
646} 655}
647 656
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index ad2ab560d..eb69344f6 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -5,18 +5,17 @@
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use hir_def::CrateModuleId;
8use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
9 10
10use super::{autoderef, lower, Canonical, InEnvironment, TraitEnvironment, TraitRef}; 11use super::{autoderef, lower, Canonical, InEnvironment, TraitEnvironment, TraitRef};
11use crate::{ 12use crate::{
12 db::HirDatabase, 13 db::HirDatabase,
13 impl_block::{ImplBlock, ImplId}, 14 impl_block::{ImplBlock, ImplId},
14 nameres::CrateModuleId,
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, 16 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy},
17 ty::{Ty, TypeCtor}, 17 ty::{Ty, TypeCtor},
18 type_ref::Mutability, 18 AssocItem, Crate, Function, Module, Mutability, Name, Trait,
19 AssocItem, Crate, Function, Module, Name, Trait,
20}; 19};
21 20
22/// This is used as a key for indexing impls. 21/// This is used as a key for indexing impls.
@@ -50,7 +49,7 @@ impl CrateImplBlocks {
50 let fingerprint = TyFingerprint::for_impl(ty); 49 let fingerprint = TyFingerprint::for_impl(ty);
51 fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flat_map(|i| i.iter()).map( 50 fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flat_map(|i| i.iter()).map(
52 move |(module_id, impl_id)| { 51 move |(module_id, impl_id)| {
53 let module = Module { krate: self.krate, module_id: *module_id }; 52 let module = Module::new(self.krate, *module_id);
54 ImplBlock::from_id(module, *impl_id) 53 ImplBlock::from_id(module, *impl_id)
55 }, 54 },
56 ) 55 )
@@ -62,7 +61,7 @@ impl CrateImplBlocks {
62 ) -> impl Iterator<Item = ImplBlock> + 'a { 61 ) -> impl Iterator<Item = ImplBlock> + 'a {
63 self.impls_by_trait.get(&tr).into_iter().flat_map(|i| i.iter()).map( 62 self.impls_by_trait.get(&tr).into_iter().flat_map(|i| i.iter()).map(
64 move |(module_id, impl_id)| { 63 move |(module_id, impl_id)| {
65 let module = Module { krate: self.krate, module_id: *module_id }; 64 let module = Module::new(self.krate, *module_id);
66 ImplBlock::from_id(module, *impl_id) 65 ImplBlock::from_id(module, *impl_id)
67 }, 66 },
68 ) 67 )
@@ -71,7 +70,7 @@ impl CrateImplBlocks {
71 pub fn all_impls<'a>(&'a self) -> impl Iterator<Item = ImplBlock> + 'a { 70 pub fn all_impls<'a>(&'a self) -> impl Iterator<Item = ImplBlock> + 'a {
72 self.impls.values().chain(self.impls_by_trait.values()).flat_map(|i| i.iter()).map( 71 self.impls.values().chain(self.impls_by_trait.values()).flat_map(|i| i.iter()).map(
73 move |(module_id, impl_id)| { 72 move |(module_id, impl_id)| {
74 let module = Module { krate: self.krate, module_id: *module_id }; 73 let module = Module::new(self.krate, *module_id);
75 ImplBlock::from_id(module, *impl_id) 74 ImplBlock::from_id(module, *impl_id)
76 }, 75 },
77 ) 76 )
@@ -90,14 +89,14 @@ impl CrateImplBlocks {
90 self.impls_by_trait 89 self.impls_by_trait
91 .entry(tr.trait_) 90 .entry(tr.trait_)
92 .or_insert_with(Vec::new) 91 .or_insert_with(Vec::new)
93 .push((module.module_id, impl_id)); 92 .push((module.id.module_id, impl_id));
94 } 93 }
95 } else { 94 } else {
96 if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { 95 if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) {
97 self.impls 96 self.impls
98 .entry(target_ty_fp) 97 .entry(target_ty_fp)
99 .or_insert_with(Vec::new) 98 .or_insert_with(Vec::new)
100 .push((module.module_id, impl_id)); 99 .push((module.id.module_id, impl_id));
101 } 100 }
102 } 101 }
103 } 102 }
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs
index 8966f9d1d..1749752f1 100644
--- a/crates/ra_hir/src/ty/primitive.rs
+++ b/crates/ra_hir/src/ty/primitive.rs
@@ -2,27 +2,7 @@
2 2
3use std::fmt; 3use std::fmt;
4 4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] 5pub use hir_def::builtin_type::{FloatBitness, IntBitness, Signedness};
6pub enum Signedness {
7 Signed,
8 Unsigned,
9}
10
11#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
12pub enum IntBitness {
13 Xsize,
14 X8,
15 X16,
16 X32,
17 X64,
18 X128,
19}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
22pub enum FloatBitness {
23 X32,
24 X64,
25}
26 6
27#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] 7#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
28pub enum UncertainIntTy { 8pub enum UncertainIntTy {
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 0cb5c3798..4f1eab150 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -1,7 +1,7 @@
1//! Trait solving using Chalk. 1//! Trait solving using Chalk.
2use std::sync::{Arc, Mutex}; 2use std::sync::{Arc, Mutex};
3 3
4use chalk_ir::cast::Cast; 4use chalk_ir::{cast::Cast, family::ChalkIr};
5use log::debug; 5use log::debug;
6use ra_db::salsa; 6use ra_db::salsa;
7use ra_prof::profile; 7use ra_prof::profile;
@@ -33,7 +33,7 @@ impl TraitSolver {
33 fn solve( 33 fn solve(
34 &self, 34 &self,
35 db: &impl HirDatabase, 35 db: &impl HirDatabase,
36 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal>>, 36 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<ChalkIr>>>,
37 ) -> Option<chalk_solve::Solution> { 37 ) -> Option<chalk_solve::Solution> {
38 let context = ChalkContext { db, krate: self.krate }; 38 let context = ChalkContext { db, krate: self.krate };
39 debug!("solve goal: {:?}", goal); 39 debug!("solve goal: {:?}", goal);
@@ -196,7 +196,7 @@ pub(crate) fn trait_solve_query(
196} 196}
197 197
198fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -> Solution { 198fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -> Solution {
199 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution>| { 199 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<ChalkIr>>| {
200 let value = subst 200 let value = subst
201 .value 201 .value
202 .parameters 202 .parameters
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 00aaf65d9..39ef92182 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -4,11 +4,13 @@ use std::sync::Arc;
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{ 6use chalk_ir::{
7 cast::Cast, Identifier, ImplId, Parameter, PlaceholderIndex, TypeId, TypeKindId, TypeName, 7 cast::Cast, family::ChalkIr, Identifier, ImplId, Parameter, PlaceholderIndex, TypeId,
8 UniverseIndex, 8 TypeKindId, TypeName, UniverseIndex,
9}; 9};
10use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; 10use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum};
11 11
12use hir_expand::name;
13
12use ra_db::salsa::{InternId, InternKey}; 14use ra_db::salsa::{InternId, InternKey};
13 15
14use super::{Canonical, ChalkContext, Impl, Obligation}; 16use super::{Canonical, ChalkContext, Impl, Obligation};
@@ -38,8 +40,8 @@ where
38} 40}
39 41
40impl ToChalk for Ty { 42impl ToChalk for Ty {
41 type Chalk = chalk_ir::Ty; 43 type Chalk = chalk_ir::Ty<ChalkIr>;
42 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty { 44 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty<ChalkIr> {
43 match self { 45 match self {
44 Ty::Apply(apply_ty) => { 46 Ty::Apply(apply_ty) => {
45 let name = match apply_ty.ctor { 47 let name = match apply_ty.ctor {
@@ -62,21 +64,19 @@ impl ToChalk for Ty {
62 chalk_ir::ProjectionTy { associated_ty_id, parameters }.cast() 64 chalk_ir::ProjectionTy { associated_ty_id, parameters }.cast()
63 } 65 }
64 Ty::Param { idx, .. } => { 66 Ty::Param { idx, .. } => {
65 PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty() 67 PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty::<ChalkIr>()
66 } 68 }
67 Ty::Bound(idx) => chalk_ir::Ty::BoundVar(idx as usize), 69 Ty::Bound(idx) => chalk_ir::Ty::BoundVar(idx as usize),
68 Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), 70 Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
69 // FIXME this is clearly incorrect, but probably not too incorrect 71 // FIXME use Chalk's Dyn/Opaque once the bugs with that are fixed
70 // and I'm not sure what to actually do with Ty::Unknown
71 // maybe an alternative would be `for<T> T`? (meaningless in rust, but expressible in chalk's Ty)
72 //
73 // FIXME also dyn and impl Trait are currently handled like Unknown because Chalk doesn't have them yet
74 Ty::Unknown | Ty::Dyn(_) | Ty::Opaque(_) => { 72 Ty::Unknown | Ty::Dyn(_) | Ty::Opaque(_) => {
75 PlaceholderIndex { ui: UniverseIndex::ROOT, idx: usize::max_value() }.to_ty() 73 let parameters = Vec::new();
74 let name = TypeName::Error;
75 chalk_ir::ApplicationTy { name, parameters }.cast()
76 } 76 }
77 } 77 }
78 } 78 }
79 fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty) -> Self { 79 fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<ChalkIr>) -> Self {
80 match chalk { 80 match chalk {
81 chalk_ir::Ty::Apply(apply_ty) => { 81 chalk_ir::Ty::Apply(apply_ty) => {
82 // FIXME this is kind of hacky due to the fact that 82 // FIXME this is kind of hacky due to the fact that
@@ -92,6 +92,7 @@ impl ToChalk for Ty {
92 let parameters = from_chalk(db, apply_ty.parameters); 92 let parameters = from_chalk(db, apply_ty.parameters);
93 Ty::Apply(ApplicationTy { ctor, parameters }) 93 Ty::Apply(ApplicationTy { ctor, parameters })
94 } 94 }
95 TypeName::Error => Ty::Unknown,
95 // FIXME handle TypeKindId::Trait/Type here 96 // FIXME handle TypeKindId::Trait/Type here
96 TypeName::TypeKindId(_) => unimplemented!(), 97 TypeName::TypeKindId(_) => unimplemented!(),
97 TypeName::Placeholder(idx) => { 98 TypeName::Placeholder(idx) => {
@@ -108,18 +109,30 @@ impl ToChalk for Ty {
108 chalk_ir::Ty::ForAll(_) => unimplemented!(), 109 chalk_ir::Ty::ForAll(_) => unimplemented!(),
109 chalk_ir::Ty::BoundVar(idx) => Ty::Bound(idx as u32), 110 chalk_ir::Ty::BoundVar(idx) => Ty::Bound(idx as u32),
110 chalk_ir::Ty::InferenceVar(_iv) => Ty::Unknown, 111 chalk_ir::Ty::InferenceVar(_iv) => Ty::Unknown,
112 chalk_ir::Ty::Dyn(where_clauses) => {
113 assert_eq!(where_clauses.binders.len(), 1);
114 let predicates =
115 where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect();
116 Ty::Dyn(predicates)
117 }
118 chalk_ir::Ty::Opaque(where_clauses) => {
119 assert_eq!(where_clauses.binders.len(), 1);
120 let predicates =
121 where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect();
122 Ty::Opaque(predicates)
123 }
111 } 124 }
112 } 125 }
113} 126}
114 127
115impl ToChalk for Substs { 128impl ToChalk for Substs {
116 type Chalk = Vec<chalk_ir::Parameter>; 129 type Chalk = Vec<chalk_ir::Parameter<ChalkIr>>;
117 130
118 fn to_chalk(self, db: &impl HirDatabase) -> Vec<Parameter> { 131 fn to_chalk(self, db: &impl HirDatabase) -> Vec<Parameter<ChalkIr>> {
119 self.iter().map(|ty| ty.clone().to_chalk(db).cast()).collect() 132 self.iter().map(|ty| ty.clone().to_chalk(db).cast()).collect()
120 } 133 }
121 134
122 fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter>) -> Substs { 135 fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter<ChalkIr>>) -> Substs {
123 let tys = parameters 136 let tys = parameters
124 .into_iter() 137 .into_iter()
125 .map(|p| match p { 138 .map(|p| match p {
@@ -132,15 +145,15 @@ impl ToChalk for Substs {
132} 145}
133 146
134impl ToChalk for TraitRef { 147impl ToChalk for TraitRef {
135 type Chalk = chalk_ir::TraitRef; 148 type Chalk = chalk_ir::TraitRef<ChalkIr>;
136 149
137 fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef { 150 fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef<ChalkIr> {
138 let trait_id = self.trait_.to_chalk(db); 151 let trait_id = self.trait_.to_chalk(db);
139 let parameters = self.substs.to_chalk(db); 152 let parameters = self.substs.to_chalk(db);
140 chalk_ir::TraitRef { trait_id, parameters } 153 chalk_ir::TraitRef { trait_id, parameters }
141 } 154 }
142 155
143 fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef) -> Self { 156 fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef<ChalkIr>) -> Self {
144 let trait_ = from_chalk(db, trait_ref.trait_id); 157 let trait_ = from_chalk(db, trait_ref.trait_id);
145 let substs = from_chalk(db, trait_ref.parameters); 158 let substs = from_chalk(db, trait_ref.parameters);
146 TraitRef { trait_, substs } 159 TraitRef { trait_, substs }
@@ -151,11 +164,11 @@ impl ToChalk for Trait {
151 type Chalk = chalk_ir::TraitId; 164 type Chalk = chalk_ir::TraitId;
152 165
153 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId { 166 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId {
154 self.id.into() 167 chalk_ir::TraitId(id_to_chalk(self.id))
155 } 168 }
156 169
157 fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> Trait { 170 fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> Trait {
158 Trait { id: trait_id.into() } 171 Trait { id: id_from_chalk(trait_id.0) }
159 } 172 }
160} 173}
161 174
@@ -187,18 +200,18 @@ impl ToChalk for TypeAlias {
187 type Chalk = chalk_ir::TypeId; 200 type Chalk = chalk_ir::TypeId;
188 201
189 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId { 202 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId {
190 self.id.into() 203 chalk_ir::TypeId(id_to_chalk(self.id))
191 } 204 }
192 205
193 fn from_chalk(_db: &impl HirDatabase, impl_id: chalk_ir::TypeId) -> TypeAlias { 206 fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAlias {
194 TypeAlias { id: impl_id.into() } 207 TypeAlias { id: id_from_chalk(type_alias_id.0) }
195 } 208 }
196} 209}
197 210
198impl ToChalk for GenericPredicate { 211impl ToChalk for GenericPredicate {
199 type Chalk = chalk_ir::QuantifiedWhereClause; 212 type Chalk = chalk_ir::QuantifiedWhereClause<ChalkIr>;
200 213
201 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::QuantifiedWhereClause { 214 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::QuantifiedWhereClause<ChalkIr> {
202 match self { 215 match self {
203 GenericPredicate::Implemented(trait_ref) => { 216 GenericPredicate::Implemented(trait_ref) => {
204 make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) 217 make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0)
@@ -221,25 +234,40 @@ impl ToChalk for GenericPredicate {
221 } 234 }
222 235
223 fn from_chalk( 236 fn from_chalk(
224 _db: &impl HirDatabase, 237 db: &impl HirDatabase,
225 _where_clause: chalk_ir::QuantifiedWhereClause, 238 where_clause: chalk_ir::QuantifiedWhereClause<ChalkIr>,
226 ) -> GenericPredicate { 239 ) -> GenericPredicate {
227 // This should never need to be called 240 match where_clause.value {
228 unimplemented!() 241 chalk_ir::WhereClause::Implemented(tr) => {
242 if tr.trait_id == UNKNOWN_TRAIT {
243 // FIXME we need an Error enum on the Chalk side to avoid this
244 return GenericPredicate::Error;
245 }
246 GenericPredicate::Implemented(from_chalk(db, tr))
247 }
248 chalk_ir::WhereClause::ProjectionEq(projection_eq) => {
249 let projection_ty = from_chalk(db, projection_eq.projection);
250 let ty = from_chalk(db, projection_eq.ty);
251 GenericPredicate::Projection(super::ProjectionPredicate { projection_ty, ty })
252 }
253 }
229 } 254 }
230} 255}
231 256
232impl ToChalk for ProjectionTy { 257impl ToChalk for ProjectionTy {
233 type Chalk = chalk_ir::ProjectionTy; 258 type Chalk = chalk_ir::ProjectionTy<ChalkIr>;
234 259
235 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::ProjectionTy { 260 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::ProjectionTy<ChalkIr> {
236 chalk_ir::ProjectionTy { 261 chalk_ir::ProjectionTy {
237 associated_ty_id: self.associated_ty.to_chalk(db), 262 associated_ty_id: self.associated_ty.to_chalk(db),
238 parameters: self.parameters.to_chalk(db), 263 parameters: self.parameters.to_chalk(db),
239 } 264 }
240 } 265 }
241 266
242 fn from_chalk(db: &impl HirDatabase, projection_ty: chalk_ir::ProjectionTy) -> ProjectionTy { 267 fn from_chalk(
268 db: &impl HirDatabase,
269 projection_ty: chalk_ir::ProjectionTy<ChalkIr>,
270 ) -> ProjectionTy {
243 ProjectionTy { 271 ProjectionTy {
244 associated_ty: from_chalk(db, projection_ty.associated_ty_id), 272 associated_ty: from_chalk(db, projection_ty.associated_ty_id),
245 parameters: from_chalk(db, projection_ty.parameters), 273 parameters: from_chalk(db, projection_ty.parameters),
@@ -248,31 +276,31 @@ impl ToChalk for ProjectionTy {
248} 276}
249 277
250impl ToChalk for super::ProjectionPredicate { 278impl ToChalk for super::ProjectionPredicate {
251 type Chalk = chalk_ir::Normalize; 279 type Chalk = chalk_ir::Normalize<ChalkIr>;
252 280
253 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize { 281 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize<ChalkIr> {
254 chalk_ir::Normalize { 282 chalk_ir::Normalize {
255 projection: self.projection_ty.to_chalk(db), 283 projection: self.projection_ty.to_chalk(db),
256 ty: self.ty.to_chalk(db), 284 ty: self.ty.to_chalk(db),
257 } 285 }
258 } 286 }
259 287
260 fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize) -> Self { 288 fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize<ChalkIr>) -> Self {
261 unimplemented!() 289 unimplemented!()
262 } 290 }
263} 291}
264 292
265impl ToChalk for Obligation { 293impl ToChalk for Obligation {
266 type Chalk = chalk_ir::DomainGoal; 294 type Chalk = chalk_ir::DomainGoal<ChalkIr>;
267 295
268 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::DomainGoal { 296 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::DomainGoal<ChalkIr> {
269 match self { 297 match self {
270 Obligation::Trait(tr) => tr.to_chalk(db).cast(), 298 Obligation::Trait(tr) => tr.to_chalk(db).cast(),
271 Obligation::Projection(pr) => pr.to_chalk(db).cast(), 299 Obligation::Projection(pr) => pr.to_chalk(db).cast(),
272 } 300 }
273 } 301 }
274 302
275 fn from_chalk(_db: &impl HirDatabase, _goal: chalk_ir::DomainGoal) -> Self { 303 fn from_chalk(_db: &impl HirDatabase, _goal: chalk_ir::DomainGoal<ChalkIr>) -> Self {
276 unimplemented!() 304 unimplemented!()
277 } 305 }
278} 306}
@@ -296,16 +324,16 @@ where
296} 324}
297 325
298impl ToChalk for Arc<super::TraitEnvironment> { 326impl ToChalk for Arc<super::TraitEnvironment> {
299 type Chalk = Arc<chalk_ir::Environment>; 327 type Chalk = chalk_ir::Environment<ChalkIr>;
300 328
301 fn to_chalk(self, db: &impl HirDatabase) -> Arc<chalk_ir::Environment> { 329 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Environment<ChalkIr> {
302 let mut clauses = Vec::new(); 330 let mut clauses = Vec::new();
303 for pred in &self.predicates { 331 for pred in &self.predicates {
304 if pred.is_error() { 332 if pred.is_error() {
305 // for env, we just ignore errors 333 // for env, we just ignore errors
306 continue; 334 continue;
307 } 335 }
308 let program_clause: chalk_ir::ProgramClause = pred.clone().to_chalk(db).cast(); 336 let program_clause: chalk_ir::ProgramClause<ChalkIr> = pred.clone().to_chalk(db).cast();
309 clauses.push(program_clause.into_from_env_clause()); 337 clauses.push(program_clause.into_from_env_clause());
310 } 338 }
311 chalk_ir::Environment::new().add_clauses(clauses) 339 chalk_ir::Environment::new().add_clauses(clauses)
@@ -313,13 +341,16 @@ impl ToChalk for Arc<super::TraitEnvironment> {
313 341
314 fn from_chalk( 342 fn from_chalk(
315 _db: &impl HirDatabase, 343 _db: &impl HirDatabase,
316 _env: Arc<chalk_ir::Environment>, 344 _env: chalk_ir::Environment<ChalkIr>,
317 ) -> Arc<super::TraitEnvironment> { 345 ) -> Arc<super::TraitEnvironment> {
318 unimplemented!() 346 unimplemented!()
319 } 347 }
320} 348}
321 349
322impl<T: ToChalk> ToChalk for super::InEnvironment<T> { 350impl<T: ToChalk> ToChalk for super::InEnvironment<T>
351where
352 T::Chalk: chalk_ir::family::HasTypeFamily<TypeFamily = ChalkIr>,
353{
323 type Chalk = chalk_ir::InEnvironment<T::Chalk>; 354 type Chalk = chalk_ir::InEnvironment<T::Chalk>;
324 355
325 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { 356 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> {
@@ -351,7 +382,7 @@ fn convert_where_clauses(
351 db: &impl HirDatabase, 382 db: &impl HirDatabase,
352 def: GenericDef, 383 def: GenericDef,
353 substs: &Substs, 384 substs: &Substs,
354) -> Vec<chalk_ir::QuantifiedWhereClause> { 385) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> {
355 let generic_predicates = db.generic_predicates(def); 386 let generic_predicates = db.generic_predicates(def);
356 let mut result = Vec::with_capacity(generic_predicates.len()); 387 let mut result = Vec::with_capacity(generic_predicates.len());
357 for pred in generic_predicates.iter() { 388 for pred in generic_predicates.iter() {
@@ -384,7 +415,7 @@ where
384 fn impls_for_trait( 415 fn impls_for_trait(
385 &self, 416 &self,
386 trait_id: chalk_ir::TraitId, 417 trait_id: chalk_ir::TraitId,
387 parameters: &[Parameter], 418 parameters: &[Parameter<ChalkIr>],
388 ) -> Vec<ImplId> { 419 ) -> Vec<ImplId> {
389 debug!("impls_for_trait {:?}", trait_id); 420 debug!("impls_for_trait {:?}", trait_id);
390 if trait_id == UNKNOWN_TRAIT { 421 if trait_id == UNKNOWN_TRAIT {
@@ -430,13 +461,13 @@ where
430 } 461 }
431 fn split_projection<'p>( 462 fn split_projection<'p>(
432 &self, 463 &self,
433 projection: &'p chalk_ir::ProjectionTy, 464 projection: &'p chalk_ir::ProjectionTy<ChalkIr>,
434 ) -> (Arc<AssociatedTyDatum>, &'p [Parameter], &'p [Parameter]) { 465 ) -> (Arc<AssociatedTyDatum>, &'p [Parameter<ChalkIr>], &'p [Parameter<ChalkIr>]) {
435 debug!("split_projection {:?}", projection); 466 debug!("split_projection {:?}", projection);
436 // we don't support GATs, so I think this should always be correct currently 467 // we don't support GATs, so I think this should always be correct currently
437 (self.db.associated_ty_data(projection.associated_ty_id), &projection.parameters, &[]) 468 (self.db.associated_ty_data(projection.associated_ty_id), &projection.parameters, &[])
438 } 469 }
439 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause> { 470 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> {
440 vec![] 471 vec![]
441 } 472 }
442 fn local_impls_to_coherence_check( 473 fn local_impls_to_coherence_check(
@@ -508,7 +539,7 @@ pub(crate) fn trait_datum_query(
508 let trait_ref = trait_.trait_ref(db).subst(&bound_vars).to_chalk(db); 539 let trait_ref = trait_.trait_ref(db).subst(&bound_vars).to_chalk(db);
509 let flags = chalk_rust_ir::TraitFlags { 540 let flags = chalk_rust_ir::TraitFlags {
510 auto: trait_.is_auto(db), 541 auto: trait_.is_auto(db),
511 upstream: trait_.module(db).krate(db) != Some(krate), 542 upstream: trait_.module(db).krate() != krate,
512 non_enumerable: true, 543 non_enumerable: true,
513 // FIXME set these flags correctly 544 // FIXME set these flags correctly
514 marker: false, 545 marker: false,
@@ -596,7 +627,7 @@ fn impl_block_datum(
596 .target_trait_ref(db) 627 .target_trait_ref(db)
597 .expect("FIXME handle unresolved impl block trait ref") 628 .expect("FIXME handle unresolved impl block trait ref")
598 .subst(&bound_vars); 629 .subst(&bound_vars);
599 let impl_type = if impl_block.module().krate(db) == Some(krate) { 630 let impl_type = if impl_block.module().krate() == krate {
600 chalk_rust_ir::ImplType::Local 631 chalk_rust_ir::ImplType::Local
601 } else { 632 } else {
602 chalk_rust_ir::ImplType::External 633 chalk_rust_ir::ImplType::External
@@ -705,7 +736,7 @@ fn closure_fn_trait_impl_datum(
705 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), 736 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
706 }; 737 };
707 738
708 let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?; 739 let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?;
709 740
710 let output_ty_value = chalk_rust_ir::AssociatedTyValue { 741 let output_ty_value = chalk_rust_ir::AssociatedTyValue {
711 associated_ty_id: output_ty_id.to_chalk(db), 742 associated_ty_id: output_ty_id.to_chalk(db),
@@ -746,30 +777,6 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId {
746 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } 777 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() }
747} 778}
748 779
749impl From<chalk_ir::TraitId> for crate::ids::TraitId {
750 fn from(trait_id: chalk_ir::TraitId) -> Self {
751 id_from_chalk(trait_id.0)
752 }
753}
754
755impl From<crate::ids::TraitId> for chalk_ir::TraitId {
756 fn from(trait_id: crate::ids::TraitId) -> Self {
757 chalk_ir::TraitId(id_to_chalk(trait_id))
758 }
759}
760
761impl From<chalk_ir::TypeId> for crate::ids::TypeAliasId {
762 fn from(type_id: chalk_ir::TypeId) -> Self {
763 id_from_chalk(type_id.0)
764 }
765}
766
767impl From<crate::ids::TypeAliasId> for chalk_ir::TypeId {
768 fn from(type_id: crate::ids::TypeAliasId) -> Self {
769 chalk_ir::TypeId(id_to_chalk(type_id))
770 }
771}
772
773impl From<chalk_ir::StructId> for crate::ids::TypeCtorId { 780impl From<chalk_ir::StructId> for crate::ids::TypeCtorId {
774 fn from(struct_id: chalk_ir::StructId) -> Self { 781 fn from(struct_id: chalk_ir::StructId) -> Self {
775 id_from_chalk(struct_id.0) 782 id_from_chalk(struct_id.0)