Skip to content

Commit b984ef6

Browse files
committed
Auto merge of #77152 - vandenheuvel:update_chalk_further, r=jackh726
Update chalk to 0.28.0
2 parents 521d8d8 + 51c781f commit b984ef6

File tree

5 files changed

+104
-42
lines changed

5 files changed

+104
-42
lines changed

Cargo.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ dependencies = [
427427

428428
[[package]]
429429
name = "chalk-derive"
430-
version = "0.21.0"
430+
version = "0.28.0"
431431
source = "registry+https://github.com/rust-lang/crates.io-index"
432-
checksum = "c1df0dbb57d74b4acd20f20fa66ab2acd09776b79eaeb9d8f947b2f3e01c40bf"
432+
checksum = "8c85b013e2dc1b46ac4a279f54e62e55556a8c4d859f7b7c4e340a9b1d013640"
433433
dependencies = [
434434
"proc-macro2",
435435
"quote",
@@ -439,9 +439,9 @@ dependencies = [
439439

440440
[[package]]
441441
name = "chalk-engine"
442-
version = "0.21.0"
442+
version = "0.28.0"
443443
source = "registry+https://github.com/rust-lang/crates.io-index"
444-
checksum = "fb7c65a13f32f02aba8f1d9a37f206af615f77ac564624b81a4c593c6c1735b9"
444+
checksum = "2a499f81860f6eadfe0c76c5bb606cd2df701939d5a596ed3724c7db04aec14b"
445445
dependencies = [
446446
"chalk-derive",
447447
"chalk-ir",
@@ -452,19 +452,19 @@ dependencies = [
452452

453453
[[package]]
454454
name = "chalk-ir"
455-
version = "0.21.0"
455+
version = "0.28.0"
456456
source = "registry+https://github.com/rust-lang/crates.io-index"
457-
checksum = "44361a25dbdb1dc428f56ad7a3c21ba9ca12f3225c26a47919ff6fcb10a583d4"
457+
checksum = "2135d844688dc920e3ece3012c5d3d4f06e26986fe38bc041bc98f0e7a9f4e2b"
458458
dependencies = [
459459
"chalk-derive",
460460
"lazy_static",
461461
]
462462

463463
[[package]]
464464
name = "chalk-solve"
465-
version = "0.21.0"
465+
version = "0.28.0"
466466
source = "registry+https://github.com/rust-lang/crates.io-index"
467-
checksum = "a886da37a0dc457057d86f78f026f7a09c6d8088aa13f4f4127fdb8dc80119a3"
467+
checksum = "bc69e4e94ffd4b39f1a865824b431bb82a7b4c8f14a0ba3d461cd86e56a590ac"
468468
dependencies = [
469469
"chalk-derive",
470470
"chalk-ir",

compiler/rustc_middle/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index" }
2626
rustc_serialize = { path = "../rustc_serialize" }
2727
rustc_ast = { path = "../rustc_ast" }
2828
rustc_span = { path = "../rustc_span" }
29-
chalk-ir = "0.21.0"
29+
chalk-ir = "0.28.0"
3030
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3131
measureme = "0.7.1"
3232
rustc_session = { path = "../rustc_session" }

compiler/rustc_traits/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
1212
rustc_index = { path = "../rustc_index" }
1313
rustc_ast = { path = "../rustc_ast" }
1414
rustc_span = { path = "../rustc_span" }
15-
chalk-ir = "0.21.0"
16-
chalk-solve = "0.21.0"
17-
chalk-engine = "0.21.0"
15+
chalk-ir = "0.28.0"
16+
chalk-solve = "0.28.0"
17+
chalk-engine = "0.28.0"
1818
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
1919
rustc_infer = { path = "../rustc_infer" }
2020
rustc_trait_selection = { path = "../rustc_trait_selection" }

compiler/rustc_traits/src/chalk/db.rs

+74-22
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
1111
use rustc_middle::ty::{self, AssocItemContainer, AssocKind, TyCtxt, TypeFoldable};
1212

1313
use rustc_hir::def_id::DefId;
14-
use rustc_hir::Unsafety;
1514

1615
use rustc_span::symbol::sym;
1716

1817
use std::fmt;
1918
use std::sync::Arc;
2019

2120
use crate::chalk::lowering::{self, LowerInto};
21+
use rustc_ast::ast;
2222

2323
pub struct RustIrDatabase<'tcx> {
2424
pub(crate) interner: RustInterner<'tcx>,
@@ -247,12 +247,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
247247
};
248248
Arc::new(chalk_solve::rust_ir::FnDefDatum {
249249
id: fn_def_id,
250-
abi: sig.abi(),
251-
safety: match sig.unsafety() {
252-
Unsafety::Normal => chalk_ir::Safety::Safe,
253-
Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
254-
},
255-
variadic: sig.c_variadic(),
250+
sig: sig.lower_into(&self.interner),
256251
binders: chalk_ir::Binders::new(binders, bound),
257252
})
258253
}
@@ -327,21 +322,75 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
327322
fn impl_provided_for(
328323
&self,
329324
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
330-
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
325+
app_ty: &chalk_ir::ApplicationTy<RustInterner<'tcx>>,
331326
) -> bool {
327+
use chalk_ir::Scalar::*;
328+
use chalk_ir::TypeName::*;
329+
332330
let trait_def_id = auto_trait_id.0;
333-
let adt_def = adt_id.0;
334331
let all_impls = self.interner.tcx.all_impls(trait_def_id);
335332
for impl_def_id in all_impls {
336333
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
337334
let self_ty = trait_ref.self_ty();
338-
match *self_ty.kind() {
339-
ty::Adt(impl_adt_def, _) => {
340-
if impl_adt_def == adt_def {
341-
return true;
335+
let provides = match (self_ty.kind(), app_ty.name) {
336+
(&ty::Adt(impl_adt_def, ..), Adt(id)) => impl_adt_def.did == id.0.did,
337+
(_, AssociatedType(_ty_id)) => {
338+
// FIXME(chalk): See https://github.com/rust-lang/rust/pull/77152#discussion_r494484774
339+
false
340+
}
341+
(ty::Bool, Scalar(Bool)) => true,
342+
(ty::Char, Scalar(Char)) => true,
343+
(ty::Int(ty1), Scalar(Int(ty2))) => match (ty1, ty2) {
344+
(ast::IntTy::Isize, chalk_ir::IntTy::Isize)
345+
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
346+
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
347+
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
348+
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
349+
| (ast::IntTy::I128, chalk_ir::IntTy::I128) => true,
350+
_ => false,
351+
},
352+
(ty::Uint(ty1), Scalar(Uint(ty2))) => match (ty1, ty2) {
353+
(ast::UintTy::Usize, chalk_ir::UintTy::Usize)
354+
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
355+
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
356+
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
357+
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
358+
| (ast::UintTy::U128, chalk_ir::UintTy::U128) => true,
359+
_ => false,
360+
},
361+
(ty::Float(ty1), Scalar(Float(ty2))) => match (ty1, ty2) {
362+
(ast::FloatTy::F32, chalk_ir::FloatTy::F32)
363+
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64) => true,
364+
_ => false,
365+
},
366+
(&ty::Tuple(..), Tuple(..)) => true,
367+
(&ty::Array(..), Array) => true,
368+
(&ty::Slice(..), Slice) => true,
369+
(&ty::RawPtr(type_and_mut), Raw(mutability)) => {
370+
match (type_and_mut.mutbl, mutability) {
371+
(ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
372+
(ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
373+
(ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
374+
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
342375
}
343376
}
344-
_ => {}
377+
(&ty::Ref(.., mutability1), Ref(mutability2)) => match (mutability1, mutability2) {
378+
(ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
379+
(ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
380+
(ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
381+
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
382+
},
383+
(&ty::Opaque(def_id, ..), OpaqueType(opaque_ty_id)) => def_id == opaque_ty_id.0,
384+
(&ty::FnDef(def_id, ..), FnDef(fn_def_id)) => def_id == fn_def_id.0,
385+
(&ty::Str, Str) => true,
386+
(&ty::Never, Never) => true,
387+
(&ty::Closure(def_id, ..), Closure(closure_id)) => def_id == closure_id.0,
388+
(&ty::Foreign(def_id), Foreign(foreign_def_id)) => def_id == foreign_def_id.0,
389+
(&ty::Error(..), Error) => false,
390+
_ => false,
391+
};
392+
if provides {
393+
return true;
345394
}
346395
}
347396
false
@@ -416,15 +465,18 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
416465
well_known_trait: chalk_solve::rust_ir::WellKnownTrait,
417466
) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
418467
use chalk_solve::rust_ir::WellKnownTrait::*;
468+
let lang_items = self.interner.tcx.lang_items();
419469
let def_id = match well_known_trait {
420-
Sized => self.interner.tcx.lang_items().sized_trait(),
421-
Copy => self.interner.tcx.lang_items().copy_trait(),
422-
Clone => self.interner.tcx.lang_items().clone_trait(),
423-
Drop => self.interner.tcx.lang_items().drop_trait(),
424-
Fn => self.interner.tcx.lang_items().fn_trait(),
425-
FnMut => self.interner.tcx.lang_items().fn_mut_trait(),
426-
FnOnce => self.interner.tcx.lang_items().fn_once_trait(),
427-
Unsize => self.interner.tcx.lang_items().unsize_trait(),
470+
Sized => lang_items.sized_trait(),
471+
Copy => lang_items.copy_trait(),
472+
Clone => lang_items.clone_trait(),
473+
Drop => lang_items.drop_trait(),
474+
Fn => lang_items.fn_trait(),
475+
FnMut => lang_items.fn_mut_trait(),
476+
FnOnce => lang_items.fn_once_trait(),
477+
Unsize => lang_items.unsize_trait(),
478+
Unpin => lang_items.unpin_trait(),
479+
CoerceUnsized => lang_items.coerce_unsized_trait(),
428480
};
429481
def_id.map(chalk_ir::TraitId)
430482
}

compiler/rustc_traits/src/chalk/lowering.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ use rustc_middle::ty::{
3939
};
4040
use rustc_span::def_id::DefId;
4141

42+
use chalk_ir::{FnSig, ForeignDefId};
43+
use rustc_hir::Unsafety;
4244
use std::collections::btree_map::{BTreeMap, Entry};
4345

4446
/// Essentially an `Into` with a `&RustInterner` parameter
@@ -269,8 +271,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
269271
ast::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
270272
},
271273
Adt(def, substs) => apply(struct_ty(def.did), substs.lower_into(interner)),
272-
// FIXME(chalk): lower Foreign
273-
Foreign(def_id) => apply(chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(def_id)), empty()),
274+
Foreign(def_id) => apply(chalk_ir::TypeName::Foreign(ForeignDefId(def_id)), empty()),
274275
Str => apply(chalk_ir::TypeName::Str, empty()),
275276
Array(ty, len) => {
276277
let value = match len.val {
@@ -340,18 +341,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
340341
collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
341342
TyData::Function(chalk_ir::FnPointer {
342343
num_binders: binders.len(interner),
344+
sig: sig.lower_into(interner),
343345
substitution: chalk_ir::Substitution::from_iter(
344346
interner,
345347
inputs_and_outputs.iter().map(|ty| {
346348
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
347349
}),
348350
),
349-
abi: sig.abi(),
350-
safety: match sig.unsafety() {
351-
rustc_hir::Unsafety::Normal => chalk_ir::Safety::Safe,
352-
rustc_hir::Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
353-
},
354-
variadic: sig.c_variadic(),
355351
})
356352
.intern(interner)
357353
}
@@ -480,6 +476,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
480476
substs: application_ty.substitution.lower_into(interner),
481477
item_def_id: assoc_ty.0,
482478
}),
479+
chalk_ir::TypeName::Foreign(def_id) => ty::Foreign(def_id.0),
483480
chalk_ir::TypeName::Error => unimplemented!(),
484481
},
485482
TyData::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
@@ -718,6 +715,19 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
718715
}
719716
}
720717

718+
impl<'tcx> LowerInto<'tcx, chalk_ir::FnSig<RustInterner<'tcx>>> for ty::Binder<ty::FnSig<'tcx>> {
719+
fn lower_into(self, _interner: &RustInterner<'_>) -> FnSig<RustInterner<'tcx>> {
720+
chalk_ir::FnSig {
721+
abi: self.abi(),
722+
safety: match self.unsafety() {
723+
Unsafety::Normal => chalk_ir::Safety::Safe,
724+
Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
725+
},
726+
variadic: self.c_variadic(),
727+
}
728+
}
729+
}
730+
721731
/// To collect bound vars, we have to do two passes. In the first pass, we
722732
/// collect all `BoundRegion`s and `ty::Bound`s. In the second pass, we then
723733
/// replace `BrNamed` into `BrAnon`. The two separate passes are important,

0 commit comments

Comments
 (0)