Skip to content

Commit 51c781f

Browse files
committed
Upgrade chalk to 0.28.0
1 parent 5f67571 commit 51c781f

File tree

5 files changed

+103
-47
lines changed

5 files changed

+103
-47
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.27.0"
430+
version = "0.28.0"
431431
source = "registry+https://github.com/rust-lang/crates.io-index"
432-
checksum = "d5444ff2a211fe2a863e44d16a368c3d8a314d489de21b8eeb6879f14dd5d4a8"
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.27.0"
442+
version = "0.28.0"
443443
source = "registry+https://github.com/rust-lang/crates.io-index"
444-
checksum = "5b8ba5b42db32c9c92deec8baf6821628b1234eaa296c48dff39cecbce3c0271"
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.27.0"
455+
version = "0.28.0"
456456
source = "registry+https://github.com/rust-lang/crates.io-index"
457-
checksum = "e39c3db1dd4abfaa7658faaa62e5fe998a982a592b710bd971fad5b6adfcfdef"
457+
checksum = "2135d844688dc920e3ece3012c5d3d4f06e26986fe38bc041bc98f0e7a9f4e2b"
458458
dependencies = [
459459
"chalk-derive",
460460
"lazy_static",
461461
]
462462

463463
[[package]]
464464
name = "chalk-solve"
465-
version = "0.27.0"
465+
version = "0.28.0"
466466
source = "registry+https://github.com/rust-lang/crates.io-index"
467-
checksum = "a673abe3077adc25f8ee0894198aed494a5bb0ce50ee993900d0ee1a44e1948a"
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.27.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.27.0"
16-
chalk-solve = "0.27.0"
17-
chalk-engine = "0.27.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-25
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::fmt;
1818
use std::sync::Arc;
1919

2020
use crate::chalk::lowering::{self, LowerInto};
21-
use rustc_hir::Unsafety;
21+
use rustc_ast::ast;
2222

2323
pub struct RustIrDatabase<'tcx> {
2424
pub(crate) interner: RustInterner<'tcx>,
@@ -247,14 +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-
sig: chalk_ir::FnSig {
251-
abi: sig.abi(),
252-
safety: match sig.unsafety() {
253-
Unsafety::Normal => chalk_ir::Safety::Safe,
254-
Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
255-
},
256-
variadic: sig.c_variadic(),
257-
},
250+
sig: sig.lower_into(&self.interner),
258251
binders: chalk_ir::Binders::new(binders, bound),
259252
})
260253
}
@@ -329,21 +322,75 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
329322
fn impl_provided_for(
330323
&self,
331324
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
332-
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
325+
app_ty: &chalk_ir::ApplicationTy<RustInterner<'tcx>>,
333326
) -> bool {
327+
use chalk_ir::Scalar::*;
328+
use chalk_ir::TypeName::*;
329+
334330
let trait_def_id = auto_trait_id.0;
335-
let adt_def = adt_id.0;
336331
let all_impls = self.interner.tcx.all_impls(trait_def_id);
337332
for impl_def_id in all_impls {
338333
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
339334
let self_ty = trait_ref.self_ty();
340-
match *self_ty.kind() {
341-
ty::Adt(impl_adt_def, _) => {
342-
if impl_adt_def == adt_def {
343-
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,
344375
}
345376
}
346-
_ => {}
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;
347394
}
348395
}
349396
false
@@ -418,16 +465,18 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
418465
well_known_trait: chalk_solve::rust_ir::WellKnownTrait,
419466
) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
420467
use chalk_solve::rust_ir::WellKnownTrait::*;
468+
let lang_items = self.interner.tcx.lang_items();
421469
let def_id = match well_known_trait {
422-
Sized => self.interner.tcx.lang_items().sized_trait(),
423-
Copy => self.interner.tcx.lang_items().copy_trait(),
424-
Clone => self.interner.tcx.lang_items().clone_trait(),
425-
Drop => self.interner.tcx.lang_items().drop_trait(),
426-
Fn => self.interner.tcx.lang_items().fn_trait(),
427-
FnMut => self.interner.tcx.lang_items().fn_mut_trait(),
428-
FnOnce => self.interner.tcx.lang_items().fn_once_trait(),
429-
Unsize => self.interner.tcx.lang_items().unsize_trait(),
430-
Unpin => self.interner.tcx.lang_items().unpin_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(),
431480
};
432481
def_id.map(chalk_ir::TraitId)
433482
}

compiler/rustc_traits/src/chalk/lowering.rs

+17-10
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,14 +341,7 @@ 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),
343-
sig: chalk_ir::FnSig {
344-
abi: sig.abi(),
345-
safety: match sig.unsafety() {
346-
rustc_hir::Unsafety::Normal => chalk_ir::Safety::Safe,
347-
rustc_hir::Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
348-
},
349-
variadic: sig.c_variadic(),
350-
},
344+
sig: sig.lower_into(interner),
351345
substitution: chalk_ir::Substitution::from_iter(
352346
interner,
353347
inputs_and_outputs.iter().map(|ty| {
@@ -721,6 +715,19 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
721715
}
722716
}
723717

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+
724731
/// To collect bound vars, we have to do two passes. In the first pass, we
725732
/// collect all `BoundRegion`s and `ty::Bound`s. In the second pass, we then
726733
/// replace `BrNamed` into `BrAnon`. The two separate passes are important,

0 commit comments

Comments
 (0)