Skip to content

Commit b302f69

Browse files
committed
Update chalk to 0.27 and adapt to chalk changes.
1 parent f514965 commit b302f69

File tree

11 files changed

+113
-41
lines changed

11 files changed

+113
-41
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir_def/src/item_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ pub struct TypeAlias {
592592
pub bounds: Box<[TypeBound]>,
593593
pub generic_params: GenericParamsId,
594594
pub type_ref: Option<TypeRef>,
595+
pub is_extern: bool,
595596
pub ast_id: FileAstId<ast::TypeAlias>,
596597
}
597598

crates/hir_def/src/item_tree/lower.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ impl Ctx {
364364
generic_params,
365365
type_ref,
366366
ast_id,
367+
is_extern: false,
367368
};
368369
Some(id(self.data().type_aliases.alloc(res)))
369370
}
@@ -558,8 +559,9 @@ impl Ctx {
558559
statik.into()
559560
}
560561
ast::ExternItem::TypeAlias(ty) => {
561-
let id = self.lower_type_alias(&ty)?;
562-
id.into()
562+
let foreign_ty = self.lower_type_alias(&ty)?;
563+
self.data().type_aliases[foreign_ty.index].is_extern = true;
564+
foreign_ty.into()
563565
}
564566
ast::ExternItem::MacroCall(_) => return None,
565567
};

crates/hir_def/src/item_tree/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn smoke() {
236236
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
237237
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) }
238238
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
239-
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
239+
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, is_extern: false, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
240240
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
241241
> Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<syntax::ast::generated::nodes::Const>(9) }
242242
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]

crates/hir_ty/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ ena = "0.14.0"
1717
log = "0.4.8"
1818
rustc-hash = "1.1.0"
1919
scoped-tls = "1"
20-
chalk-solve = { version = "0.25.0" }
21-
chalk-ir = { version = "0.25.0" }
22-
chalk-recursive = { version = "0.25.0" }
20+
chalk-solve = { version = "0.27.0" }
21+
chalk-ir = { version = "0.27.0" }
22+
chalk-recursive = { version = "0.27.0" }
2323

2424
stdx = { path = "../stdx", version = "0.0.0" }
2525
hir_def = { path = "../hir_def", version = "0.0.0" }

crates/hir_ty/src/display.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ impl HirDisplay for ApplicationTy {
380380
write!(f, ">")?;
381381
}
382382
}
383+
TypeCtor::ForeignType(type_alias) => {
384+
let type_alias = f.db.type_alias_data(type_alias);
385+
write!(f, "{}", type_alias.name)?;
386+
if self.parameters.len() > 0 {
387+
write!(f, "<")?;
388+
f.write_joined(&*self.parameters.0, ", ")?;
389+
write!(f, ">")?;
390+
}
391+
}
383392
TypeCtor::OpaqueType(opaque_ty_id) => {
384393
match opaque_ty_id {
385394
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {

crates/hir_ty/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ pub enum TypeCtor {
134134
/// representing the Future::Output type.
135135
OpaqueType(OpaqueTyId),
136136

137+
/// Represents a foreign type declared in external blocks.
138+
ForeignType(TypeAliasId),
139+
137140
/// The type of a specific closure.
138141
///
139142
/// The closure signature is stored in a `FnPtr` type in the first type
@@ -168,6 +171,10 @@ impl TypeCtor {
168171
let generic_params = generics(db.upcast(), type_alias.into());
169172
generic_params.len()
170173
}
174+
TypeCtor::ForeignType(type_alias) => {
175+
let generic_params = generics(db.upcast(), type_alias.into());
176+
generic_params.len()
177+
}
171178
TypeCtor::OpaqueType(opaque_ty_id) => {
172179
match opaque_ty_id {
173180
OpaqueTyId::ReturnTypeImplTrait(func, _) => {
@@ -204,6 +211,9 @@ impl TypeCtor {
204211
TypeCtor::AssociatedType(type_alias) => {
205212
Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate)
206213
}
214+
TypeCtor::ForeignType(type_alias) => {
215+
Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate)
216+
}
207217
TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id {
208218
OpaqueTyId::ReturnTypeImplTrait(func, _) => {
209219
Some(func.lookup(db.upcast()).module(db.upcast()).krate)
@@ -231,6 +241,7 @@ impl TypeCtor {
231241
TypeCtor::Adt(adt) => Some(adt.into()),
232242
TypeCtor::FnDef(callable) => Some(callable.into()),
233243
TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
244+
TypeCtor::ForeignType(type_alias) => Some(type_alias.into()),
234245
TypeCtor::OpaqueType(_impl_trait_id) => None,
235246
}
236247
}

crates/hir_ty/src/traits/chalk.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use crate::{
2323
ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
2424
};
2525
use mapping::{
26-
convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
26+
convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsAssocType,
27+
TypeAliasAsValue,
2728
};
2829

2930
pub use self::interner::*;
@@ -340,7 +341,7 @@ pub(crate) fn associated_ty_data_query(
340341
id: AssocTypeId,
341342
) -> Arc<AssociatedTyDatum> {
342343
debug!("associated_ty_data {:?}", id);
343-
let type_alias: TypeAliasId = from_chalk(db, id);
344+
let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(db, id).0;
344345
let trait_ = match type_alias.lookup(db.upcast()).container {
345346
AssocContainerId::TraitId(t) => t,
346347
_ => panic!("associated type not in trait"),
@@ -394,8 +395,10 @@ pub(crate) fn trait_datum_query(
394395
fundamental: false,
395396
};
396397
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
397-
let associated_ty_ids =
398-
trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect();
398+
let associated_ty_ids = trait_data
399+
.associated_types()
400+
.map(|type_alias| TypeAliasAsAssocType(type_alias).to_chalk(db))
401+
.collect();
399402
let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses };
400403
let well_known =
401404
lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
@@ -433,6 +436,7 @@ fn lang_attr_from_well_known_trait(attr: WellKnownTrait) -> &'static str {
433436
WellKnownTrait::FnMut => "fn_mut",
434437
WellKnownTrait::Fn => "fn",
435438
WellKnownTrait::Unsize => "unsize",
439+
WellKnownTrait::Unpin => "unpin",
436440
}
437441
}
438442

@@ -576,7 +580,7 @@ fn type_alias_associated_ty_value(
576580
let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) };
577581
let value = rust_ir::AssociatedTyValue {
578582
impl_id: impl_id.to_chalk(db),
579-
associated_ty_id: assoc_ty.to_chalk(db),
583+
associated_ty_id: TypeAliasAsAssocType(assoc_ty).to_chalk(db),
580584
value: make_binders(value_bound, ty.num_binders),
581585
};
582586
Arc::new(value)
@@ -611,9 +615,11 @@ pub(crate) fn fn_def_datum_query(
611615
};
612616
let datum = FnDefDatum {
613617
id: fn_def_id,
614-
abi: (),
615-
safety: chalk_ir::Safety::Safe,
616-
variadic: sig.value.is_varargs,
618+
sig: chalk_ir::FnSig {
619+
abi: (),
620+
safety: chalk_ir::Safety::Safe,
621+
variadic: sig.value.is_varargs,
622+
},
617623
binders: make_binders(bound, sig.num_binders),
618624
};
619625
Arc::new(datum)

crates/hir_ty/src/traits/chalk/interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Interner;
1212

1313
pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
1414
pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
15+
pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
1516
pub type TraitId = chalk_ir::TraitId<Interner>;
1617
pub type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
1718
pub type AdtId = chalk_ir::AdtId<Interner>;

crates/hir_ty/src/traits/chalk/mapping.rs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ impl ToChalk for Ty {
3434
let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner);
3535
chalk_ir::TyData::Function(chalk_ir::FnPointer {
3636
num_binders: 0,
37-
abi: (),
38-
safety: chalk_ir::Safety::Safe,
39-
variadic: is_varargs,
37+
sig: chalk_ir::FnSig {
38+
abi: (),
39+
safety: chalk_ir::Safety::Safe,
40+
variadic: is_varargs,
41+
},
4042
substitution,
4143
})
4244
.intern(&Interner)
@@ -48,7 +50,7 @@ impl ToChalk for Ty {
4850
}
4951
},
5052
Ty::Projection(proj_ty) => {
51-
let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
53+
let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db);
5254
let substitution = proj_ty.parameters.to_chalk(db);
5355
chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
5456
associated_ty_id,
@@ -114,7 +116,8 @@ impl ToChalk for Ty {
114116
Ty::Placeholder(db.lookup_intern_type_param_id(interned_id))
115117
}
116118
chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => {
117-
let associated_ty = from_chalk(db, proj.associated_ty_id);
119+
let associated_ty =
120+
from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0;
118121
let parameters = from_chalk(db, proj.substitution);
119122
Ty::Projection(ProjectionTy { associated_ty, parameters })
120123
}
@@ -125,7 +128,7 @@ impl ToChalk for Ty {
125128
}
126129
chalk_ir::TyData::Function(chalk_ir::FnPointer {
127130
num_binders,
128-
variadic,
131+
sig: chalk_ir::FnSig { variadic, .. },
129132
substitution,
130133
..
131134
}) => {
@@ -290,15 +293,22 @@ impl ToChalk for TypeCtor {
290293
fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> {
291294
match self {
292295
TypeCtor::AssociatedType(type_alias) => {
293-
let type_id = type_alias.to_chalk(db);
294-
TypeName::AssociatedType(type_id)
296+
let assoc_type = TypeAliasAsAssocType(type_alias);
297+
let assoc_type_id = assoc_type.to_chalk(db);
298+
TypeName::AssociatedType(assoc_type_id)
295299
}
296300

297301
TypeCtor::OpaqueType(impl_trait_id) => {
298302
let id = impl_trait_id.to_chalk(db);
299303
TypeName::OpaqueType(id)
300304
}
301305

306+
TypeCtor::ForeignType(type_alias) => {
307+
let foreign_type = TypeAliasAsForeignType(type_alias);
308+
let foreign_type_id = foreign_type.to_chalk(db);
309+
TypeName::Foreign(foreign_type_id)
310+
}
311+
302312
TypeCtor::Bool => TypeName::Scalar(Scalar::Bool),
303313
TypeCtor::Char => TypeName::Scalar(Scalar::Char),
304314
TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)),
@@ -339,7 +349,9 @@ impl ToChalk for TypeCtor {
339349
fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor {
340350
match type_name {
341351
TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0),
342-
TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)),
352+
TypeName::AssociatedType(type_id) => {
353+
TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0)
354+
}
343355
TypeName::OpaqueType(opaque_type_id) => {
344356
TypeCtor::OpaqueType(from_chalk(db, opaque_type_id))
345357
}
@@ -379,6 +391,10 @@ impl ToChalk for TypeCtor {
379391
TypeCtor::Closure { def, expr }
380392
}
381393

394+
TypeName::Foreign(foreign_def_id) => {
395+
TypeCtor::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
396+
}
397+
382398
TypeName::Error => {
383399
// this should not be reached, since we don't represent TypeName::Error with TypeCtor
384400
unreachable!()
@@ -488,15 +504,31 @@ impl ToChalk for CallableDefId {
488504
}
489505
}
490506

491-
impl ToChalk for TypeAliasId {
507+
pub struct TypeAliasAsAssocType(pub TypeAliasId);
508+
509+
impl ToChalk for TypeAliasAsAssocType {
492510
type Chalk = AssocTypeId;
493511

494512
fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId {
495-
chalk_ir::AssocTypeId(self.as_intern_id())
513+
chalk_ir::AssocTypeId(self.0.as_intern_id())
514+
}
515+
516+
fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType {
517+
TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0))
518+
}
519+
}
520+
521+
pub struct TypeAliasAsForeignType(pub TypeAliasId);
522+
523+
impl ToChalk for TypeAliasAsForeignType {
524+
type Chalk = ForeignDefId;
525+
526+
fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId {
527+
chalk_ir::ForeignDefId(self.0.as_intern_id())
496528
}
497529

498-
fn from_chalk(_db: &dyn HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId {
499-
InternKey::from_intern_id(type_alias_id.0)
530+
fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType {
531+
TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0))
500532
}
501533
}
502534

@@ -580,7 +612,7 @@ impl ToChalk for ProjectionTy {
580612

581613
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
582614
chalk_ir::ProjectionTy {
583-
associated_ty_id: self.associated_ty.to_chalk(db),
615+
associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db),
584616
substitution: self.parameters.to_chalk(db),
585617
}
586618
}
@@ -590,7 +622,11 @@ impl ToChalk for ProjectionTy {
590622
projection_ty: chalk_ir::ProjectionTy<Interner>,
591623
) -> ProjectionTy {
592624
ProjectionTy {
593-
associated_ty: from_chalk(db, projection_ty.associated_ty_id),
625+
associated_ty: from_chalk::<TypeAliasAsAssocType, _>(
626+
db,
627+
projection_ty.associated_ty_id,
628+
)
629+
.0,
594630
parameters: from_chalk(db, projection_ty.substitution),
595631
}
596632
}
@@ -789,7 +825,8 @@ pub(super) fn generic_predicate_to_inline_bound(
789825
let alias_eq_bound = rust_ir::AliasEqBound {
790826
value: proj.ty.clone().to_chalk(db),
791827
trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
792-
associated_ty_id: proj.projection_ty.associated_ty.to_chalk(db),
828+
associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty)
829+
.to_chalk(db),
793830
parameters: Vec::new(), // FIXME we don't support generic associated types yet
794831
};
795832
Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound))

0 commit comments

Comments
 (0)