about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-25 12:22:05 +0000
committerbors <bors@rust-lang.org>2020-09-25 12:22:05 +0000
commitb984ef6797ff17faa2b1e0ebb54b78de1491e5fd (patch)
tree2812f06573f5567dcc49358359d16326cb98dccd /compiler
parent521d8d8a2236a239e3327336844ed5948857ea31 (diff)
parent51c781f6138ec541c9e3dff30e8d049027075e79 (diff)
downloadrust-b984ef6797ff17faa2b1e0ebb54b78de1491e5fd.tar.gz
rust-b984ef6797ff17faa2b1e0ebb54b78de1491e5fd.zip
Auto merge of #77152 - vandenheuvel:update_chalk_further, r=jackh726
Update chalk to 0.28.0
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_middle/Cargo.toml2
-rw-r--r--compiler/rustc_traits/Cargo.toml6
-rw-r--r--compiler/rustc_traits/src/chalk/db.rs96
-rw-r--r--compiler/rustc_traits/src/chalk/lowering.rs26
4 files changed, 96 insertions, 34 deletions
diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml
index a5a860a38b3..5136e2743cd 100644
--- a/compiler/rustc_middle/Cargo.toml
+++ b/compiler/rustc_middle/Cargo.toml
@@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index" }
 rustc_serialize = { path = "../rustc_serialize" }
 rustc_ast = { path = "../rustc_ast" }
 rustc_span = { path = "../rustc_span" }
-chalk-ir = "0.21.0"
+chalk-ir = "0.28.0"
 smallvec = { version = "1.0", features = ["union", "may_dangle"] }
 measureme = "0.7.1"
 rustc_session = { path = "../rustc_session" }
diff --git a/compiler/rustc_traits/Cargo.toml b/compiler/rustc_traits/Cargo.toml
index 3571ff17f31..369d003eb22 100644
--- a/compiler/rustc_traits/Cargo.toml
+++ b/compiler/rustc_traits/Cargo.toml
@@ -12,9 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
 rustc_index = { path = "../rustc_index" }
 rustc_ast = { path = "../rustc_ast" }
 rustc_span = { path = "../rustc_span" }
-chalk-ir = "0.21.0"
-chalk-solve = "0.21.0"
-chalk-engine = "0.21.0"
+chalk-ir = "0.28.0"
+chalk-solve = "0.28.0"
+chalk-engine = "0.28.0"
 smallvec = { version = "1.0", features = ["union", "may_dangle"] }
 rustc_infer = { path = "../rustc_infer" }
 rustc_trait_selection = { path = "../rustc_trait_selection" }
diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs
index 2fad54013ad..828ee6dea62 100644
--- a/compiler/rustc_traits/src/chalk/db.rs
+++ b/compiler/rustc_traits/src/chalk/db.rs
@@ -11,7 +11,6 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
 use rustc_middle::ty::{self, AssocItemContainer, AssocKind, TyCtxt, TypeFoldable};
 
 use rustc_hir::def_id::DefId;
-use rustc_hir::Unsafety;
 
 use rustc_span::symbol::sym;
 
@@ -19,6 +18,7 @@ use std::fmt;
 use std::sync::Arc;
 
 use crate::chalk::lowering::{self, LowerInto};
+use rustc_ast::ast;
 
 pub struct RustIrDatabase<'tcx> {
     pub(crate) interner: RustInterner<'tcx>,
@@ -247,12 +247,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
         };
         Arc::new(chalk_solve::rust_ir::FnDefDatum {
             id: fn_def_id,
-            abi: sig.abi(),
-            safety: match sig.unsafety() {
-                Unsafety::Normal => chalk_ir::Safety::Safe,
-                Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
-            },
-            variadic: sig.c_variadic(),
+            sig: sig.lower_into(&self.interner),
             binders: chalk_ir::Binders::new(binders, bound),
         })
     }
@@ -327,21 +322,75 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
     fn impl_provided_for(
         &self,
         auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
-        adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
+        app_ty: &chalk_ir::ApplicationTy<RustInterner<'tcx>>,
     ) -> bool {
+        use chalk_ir::Scalar::*;
+        use chalk_ir::TypeName::*;
+
         let trait_def_id = auto_trait_id.0;
-        let adt_def = adt_id.0;
         let all_impls = self.interner.tcx.all_impls(trait_def_id);
         for impl_def_id in all_impls {
             let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
             let self_ty = trait_ref.self_ty();
-            match *self_ty.kind() {
-                ty::Adt(impl_adt_def, _) => {
-                    if impl_adt_def == adt_def {
-                        return true;
+            let provides = match (self_ty.kind(), app_ty.name) {
+                (&ty::Adt(impl_adt_def, ..), Adt(id)) => impl_adt_def.did == id.0.did,
+                (_, AssociatedType(_ty_id)) => {
+                    // FIXME(chalk): See https://github.com/rust-lang/rust/pull/77152#discussion_r494484774
+                    false
+                }
+                (ty::Bool, Scalar(Bool)) => true,
+                (ty::Char, Scalar(Char)) => true,
+                (ty::Int(ty1), Scalar(Int(ty2))) => match (ty1, ty2) {
+                    (ast::IntTy::Isize, chalk_ir::IntTy::Isize)
+                    | (ast::IntTy::I8, chalk_ir::IntTy::I8)
+                    | (ast::IntTy::I16, chalk_ir::IntTy::I16)
+                    | (ast::IntTy::I32, chalk_ir::IntTy::I32)
+                    | (ast::IntTy::I64, chalk_ir::IntTy::I64)
+                    | (ast::IntTy::I128, chalk_ir::IntTy::I128) => true,
+                    _ => false,
+                },
+                (ty::Uint(ty1), Scalar(Uint(ty2))) => match (ty1, ty2) {
+                    (ast::UintTy::Usize, chalk_ir::UintTy::Usize)
+                    | (ast::UintTy::U8, chalk_ir::UintTy::U8)
+                    | (ast::UintTy::U16, chalk_ir::UintTy::U16)
+                    | (ast::UintTy::U32, chalk_ir::UintTy::U32)
+                    | (ast::UintTy::U64, chalk_ir::UintTy::U64)
+                    | (ast::UintTy::U128, chalk_ir::UintTy::U128) => true,
+                    _ => false,
+                },
+                (ty::Float(ty1), Scalar(Float(ty2))) => match (ty1, ty2) {
+                    (ast::FloatTy::F32, chalk_ir::FloatTy::F32)
+                    | (ast::FloatTy::F64, chalk_ir::FloatTy::F64) => true,
+                    _ => false,
+                },
+                (&ty::Tuple(..), Tuple(..)) => true,
+                (&ty::Array(..), Array) => true,
+                (&ty::Slice(..), Slice) => true,
+                (&ty::RawPtr(type_and_mut), Raw(mutability)) => {
+                    match (type_and_mut.mutbl, mutability) {
+                        (ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
+                        (ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
+                        (ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
+                        (ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
                     }
                 }
-                _ => {}
+                (&ty::Ref(.., mutability1), Ref(mutability2)) => match (mutability1, mutability2) {
+                    (ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
+                    (ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
+                    (ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
+                    (ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
+                },
+                (&ty::Opaque(def_id, ..), OpaqueType(opaque_ty_id)) => def_id == opaque_ty_id.0,
+                (&ty::FnDef(def_id, ..), FnDef(fn_def_id)) => def_id == fn_def_id.0,
+                (&ty::Str, Str) => true,
+                (&ty::Never, Never) => true,
+                (&ty::Closure(def_id, ..), Closure(closure_id)) => def_id == closure_id.0,
+                (&ty::Foreign(def_id), Foreign(foreign_def_id)) => def_id == foreign_def_id.0,
+                (&ty::Error(..), Error) => false,
+                _ => false,
+            };
+            if provides {
+                return true;
             }
         }
         false
@@ -416,15 +465,18 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
         well_known_trait: chalk_solve::rust_ir::WellKnownTrait,
     ) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
         use chalk_solve::rust_ir::WellKnownTrait::*;
+        let lang_items = self.interner.tcx.lang_items();
         let def_id = match well_known_trait {
-            Sized => self.interner.tcx.lang_items().sized_trait(),
-            Copy => self.interner.tcx.lang_items().copy_trait(),
-            Clone => self.interner.tcx.lang_items().clone_trait(),
-            Drop => self.interner.tcx.lang_items().drop_trait(),
-            Fn => self.interner.tcx.lang_items().fn_trait(),
-            FnMut => self.interner.tcx.lang_items().fn_mut_trait(),
-            FnOnce => self.interner.tcx.lang_items().fn_once_trait(),
-            Unsize => self.interner.tcx.lang_items().unsize_trait(),
+            Sized => lang_items.sized_trait(),
+            Copy => lang_items.copy_trait(),
+            Clone => lang_items.clone_trait(),
+            Drop => lang_items.drop_trait(),
+            Fn => lang_items.fn_trait(),
+            FnMut => lang_items.fn_mut_trait(),
+            FnOnce => lang_items.fn_once_trait(),
+            Unsize => lang_items.unsize_trait(),
+            Unpin => lang_items.unpin_trait(),
+            CoerceUnsized => lang_items.coerce_unsized_trait(),
         };
         def_id.map(chalk_ir::TraitId)
     }
diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs
index 650404e8ca6..1e1841a57f8 100644
--- a/compiler/rustc_traits/src/chalk/lowering.rs
+++ b/compiler/rustc_traits/src/chalk/lowering.rs
@@ -39,6 +39,8 @@ use rustc_middle::ty::{
 };
 use rustc_span::def_id::DefId;
 
+use chalk_ir::{FnSig, ForeignDefId};
+use rustc_hir::Unsafety;
 use std::collections::btree_map::{BTreeMap, Entry};
 
 /// Essentially an `Into` with a `&RustInterner` parameter
@@ -269,8 +271,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
                 ast::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
             },
             Adt(def, substs) => apply(struct_ty(def.did), substs.lower_into(interner)),
-            // FIXME(chalk): lower Foreign
-            Foreign(def_id) => apply(chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(def_id)), empty()),
+            Foreign(def_id) => apply(chalk_ir::TypeName::Foreign(ForeignDefId(def_id)), empty()),
             Str => apply(chalk_ir::TypeName::Str, empty()),
             Array(ty, len) => {
                 let value = match len.val {
@@ -340,18 +341,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
                     collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
                 TyData::Function(chalk_ir::FnPointer {
                     num_binders: binders.len(interner),
+                    sig: sig.lower_into(interner),
                     substitution: chalk_ir::Substitution::from_iter(
                         interner,
                         inputs_and_outputs.iter().map(|ty| {
                             chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
                         }),
                     ),
-                    abi: sig.abi(),
-                    safety: match sig.unsafety() {
-                        rustc_hir::Unsafety::Normal => chalk_ir::Safety::Safe,
-                        rustc_hir::Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
-                    },
-                    variadic: sig.c_variadic(),
                 })
                 .intern(interner)
             }
@@ -480,6 +476,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
                     substs: application_ty.substitution.lower_into(interner),
                     item_def_id: assoc_ty.0,
                 }),
+                chalk_ir::TypeName::Foreign(def_id) => ty::Foreign(def_id.0),
                 chalk_ir::TypeName::Error => unimplemented!(),
             },
             TyData::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
@@ -718,6 +715,19 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
     }
 }
 
+impl<'tcx> LowerInto<'tcx, chalk_ir::FnSig<RustInterner<'tcx>>> for ty::Binder<ty::FnSig<'tcx>> {
+    fn lower_into(self, _interner: &RustInterner<'_>) -> FnSig<RustInterner<'tcx>> {
+        chalk_ir::FnSig {
+            abi: self.abi(),
+            safety: match self.unsafety() {
+                Unsafety::Normal => chalk_ir::Safety::Safe,
+                Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
+            },
+            variadic: self.c_variadic(),
+        }
+    }
+}
+
 /// To collect bound vars, we have to do two passes. In the first pass, we
 /// collect all `BoundRegion`s and `ty::Bound`s. In the second pass, we then
 /// replace `BrNamed` into `BrAnon`. The two separate passes are important,