Skip to content

Commit

Permalink
Bump chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Apr 8, 2024
1 parent a82e028 commit 8078c3d
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 88 deletions.
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ arrayvec = "0.7.4"
bitflags = "2.4.1"
cargo_metadata = "0.18.1"
camino = "1.1.6"
chalk-solve = { version = "0.96.0", default-features = false }
chalk-ir = "0.96.0"
chalk-recursive = { version = "0.96.0", default-features = false }
chalk-derive = "0.96.0"
chalk-solve = { version = "0.97.0", default-features = false }
chalk-ir = "0.97.0"
chalk-recursive = { version = "0.97.0", default-features = false }
chalk-derive = "0.97.0"
command-group = "2.0.1"
crossbeam-channel = "0.5.8"
dissimilar = "1.0.7"
Expand Down
28 changes: 19 additions & 9 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ use crate::{
primitive, to_assoc_type_id,
utils::{self, detect_variant_from_bytes, generics, ClosureSubst},
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Const, ConstScalar, ConstValue,
DomainGoal, FnAbi, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives,
MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar,
Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyExt, WhereClause,
DomainGoal, FnAbi, GenericArg, GenericArgData, ImplTraitId, Interner, Lifetime, LifetimeData,
LifetimeOutlives, MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
QuantifiedWhereClause, Scalar, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty,
TyExt, WhereClause,
};

pub trait HirWrite: fmt::Write {
Expand Down Expand Up @@ -1367,8 +1368,8 @@ fn hir_fmt_generics(
return true;
}
}
if parameter.lifetime(Interner).map(|it| it.data(Interner))
== Some(&crate::LifetimeData::Static)
if let Some(crate::LifetimeData::Static | crate::LifetimeData::Error) =
parameter.lifetime(Interner).map(|it| it.data(Interner))
{
return true;
}
Expand Down Expand Up @@ -1403,10 +1404,18 @@ fn hir_fmt_generics(
write!(f, ", ")?;
}
first = false;
if f.display_target.is_source_code()
&& generic_arg.ty(Interner).map(|ty| ty.kind(Interner)) == Some(&TyKind::Error)
{
write!(f, "_")?;
if f.display_target.is_source_code() {
match generic_arg.data(Interner) {
GenericArgData::Lifetime(l)
if matches!(l.data(Interner), LifetimeData::Error) =>
{
write!(f, "'_")
}
GenericArgData::Ty(t) if matches!(t.kind(Interner), TyKind::Error) => {
write!(f, "_")
}
_ => generic_arg.hir_fmt(f),
}?
} else {
generic_arg.hir_fmt(f)?;
}
Expand Down Expand Up @@ -1729,6 +1738,7 @@ impl HirDisplay for LifetimeData {
Ok(())
}
LifetimeData::Static => write!(f, "'static"),
LifetimeData::Error => write!(f, "'{{error}}"),
LifetimeData::Erased => Ok(()),
LifetimeData::Phantom(_, _) => Ok(()),
}
Expand Down
4 changes: 1 addition & 3 deletions crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,6 @@ has_interner!(ImplTraits);

#[derive(PartialEq, Eq, Debug, Hash)]
pub struct ImplTrait {
// FIXME: Should be Arc<[QuantifiedWhereClause]>, but the HasInterner impl for Arc is missing a
// ?Sized bound
pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>,
}

Expand All @@ -624,7 +622,7 @@ pub fn static_lifetime() -> Lifetime {
}

pub fn error_lifetime() -> Lifetime {
LifetimeData::Static.intern(Interner)
LifetimeData::Error.intern(Interner)
}

pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
Expand Down
81 changes: 44 additions & 37 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ use crate::{
},
AliasEq, AliasTy, Binders, BoundVar, CallableSig, Const, ConstScalar, DebruijnIndex, DynTy,
FnAbi, FnPointer, FnSig, FnSubst, ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime,
LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder,
TyKind, WhereClause,
LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProgramClause, ProjectionTy,
QuantifiedWhereClause, QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef,
TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
};

#[derive(Debug)]
Expand Down Expand Up @@ -1052,11 +1052,11 @@ impl<'a> TyLoweringContext<'a> {
self_ty: Ty,
ignore_bindings: bool,
) -> impl Iterator<Item = QuantifiedWhereClause> + 'a {
let mut bindings = None;
let trait_ref = match bound.as_ref() {
let mut trait_ref = None;
let clause = match bound.as_ref() {
TypeBound::Path(path, TraitBoundModifier::None) => {
bindings = self.lower_trait_ref_from_path(path, Some(self_ty));
bindings
trait_ref = self.lower_trait_ref_from_path(path, Some(self_ty));
trait_ref
.clone()
.filter(|tr| {
// ignore `T: Drop` or `T: Destruct` bounds.
Expand Down Expand Up @@ -1092,8 +1092,8 @@ impl<'a> TyLoweringContext<'a> {
}
TypeBound::ForLifetime(_, path) => {
// FIXME Don't silently drop the hrtb lifetimes here
bindings = self.lower_trait_ref_from_path(path, Some(self_ty));
bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
trait_ref = self.lower_trait_ref_from_path(path, Some(self_ty));
trait_ref.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
}
TypeBound::Lifetime(l) => {
let lifetime = self.lower_lifetime(l);
Expand All @@ -1104,8 +1104,8 @@ impl<'a> TyLoweringContext<'a> {
}
TypeBound::Error => None,
};
trait_ref.into_iter().chain(
bindings
clause.into_iter().chain(
trait_ref
.into_iter()
.filter(move |_| !ignore_bindings)
.flat_map(move |tr| self.assoc_type_bindings_from_type_bound(bound, tr)),
Expand Down Expand Up @@ -1624,10 +1624,14 @@ pub(crate) fn generic_predicates_for_param_query(

let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
let implicitly_sized_predicates =
if let Some(implicitly_sized_predicates) =
implicitly_sized_clauses(db, param_id.parent, &explicitly_unsized_tys, &subst, &resolver)
.map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p)));
predicates.extend(implicitly_sized_predicates);
{
predicates.extend(
implicitly_sized_predicates
.map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))),
);
}
predicates.into()
}

Expand Down Expand Up @@ -1685,24 +1689,23 @@ pub(crate) fn trait_environment_query(
let substs = TyBuilder::placeholder_subst(db, trait_id);
let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
let pred = WhereClause::Implemented(trait_ref);
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(Interner);
clauses.push(program_clause.into_from_env_clause(Interner));
clauses.push(pred.cast::<ProgramClause>(Interner).into_from_env_clause(Interner));
}

let subst = generics(db.upcast(), def).placeholder_subst(db);
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
let implicitly_sized_clauses =
implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver).map(|pred| {
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(Interner);
program_clause.into_from_env_clause(Interner)
});
clauses.extend(implicitly_sized_clauses);

let krate = def.module(db.upcast()).krate();
if let Some(implicitly_sized_clauses) =
implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver)
{
clauses.extend(
implicitly_sized_clauses
.map(|pred| pred.cast::<ProgramClause>(Interner).into_from_env_clause(Interner)),
);
}

let env = chalk_ir::Environment::new(Interner).add_clauses(Interner, clauses);

TraitEnvironment::new(krate, None, traits_in_scope.into_boxed_slice(), env)
TraitEnvironment::new(resolver.krate(), None, traits_in_scope.into_boxed_slice(), env)
}

/// Resolve the where clause(s) of an item with generics.
Expand Down Expand Up @@ -1730,10 +1733,14 @@ pub(crate) fn generic_predicates_query(

let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
let implicitly_sized_predicates =
if let Some(implicitly_sized_predicates) =
implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver)
.map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p)));
predicates.extend(implicitly_sized_predicates);
{
predicates.extend(
implicitly_sized_predicates
.map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))),
);
}
predicates.into()
}

Expand All @@ -1745,24 +1752,24 @@ fn implicitly_sized_clauses<'a>(
explicitly_unsized_tys: &'a FxHashSet<Ty>,
substitution: &'a Substitution,
resolver: &Resolver,
) -> impl Iterator<Item = WhereClause> + 'a {
) -> Option<impl Iterator<Item = WhereClause> + 'a> {
let is_trait_def = matches!(def, GenericDefId::TraitId(..));
let generic_args = &substitution.as_slice(Interner)[is_trait_def as usize..];
let sized_trait = db
.lang_item(resolver.krate(), LangItem::Sized)
.and_then(|lang_item| lang_item.as_trait().map(to_chalk_trait_id));

sized_trait.into_iter().flat_map(move |sized_trait| {
let implicitly_sized_tys = generic_args
sized_trait.map(move |sized_trait| {
generic_args
.iter()
.filter_map(|generic_arg| generic_arg.ty(Interner))
.filter(move |&self_ty| !explicitly_unsized_tys.contains(self_ty));
implicitly_sized_tys.map(move |self_ty| {
WhereClause::Implemented(TraitRef {
trait_id: sized_trait,
substitution: Substitution::from1(Interner, self_ty.clone()),
.filter(move |&self_ty| !explicitly_unsized_tys.contains(self_ty))
.map(move |self_ty| {
WhereClause::Implemented(TraitRef {
trait_id: sized_trait,
substitution: Substitution::from1(Interner, self_ty.clone()),
})
})
})
})
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/tests/display_source_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn render_dyn_for_ty() {
trait Foo<'a> {}
fn foo(foo: &dyn for<'a> Foo<'a>) {}
// ^^^ &dyn Foo<'static>
// ^^^ &dyn Foo<'{error}>
"#,
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/tests/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ fn var_args() {
#[lang = "va_list"]
pub struct VaListImpl<'f>;
fn my_fn(foo: ...) {}
//^^^ VaListImpl<'static>
//^^^ VaListImpl<'{error}>
"#,
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,13 +896,13 @@ fn flush(&self) {
"#,
expect![[r#"
123..127 'self': &Mutex<T>
150..152 '{}': MutexGuard<'static, T>
150..152 '{}': MutexGuard<'{error}, T>
234..238 'self': &{unknown}
240..290 '{ ...()); }': ()
250..251 'w': &Mutex<BufWriter>
276..287 '*(w.lock())': BufWriter
278..279 'w': &Mutex<BufWriter>
278..286 'w.lock()': MutexGuard<'static, BufWriter>
278..286 'w.lock()': MutexGuard<'{error}, BufWriter>
"#]],
);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,15 +3092,15 @@ fn main() {
389..394 'boxed': Box<Foo<i32>>
389..406 'boxed....nner()': &i32
416..421 'good1': &i32
424..438 'Foo::get_inner': fn get_inner<i32, 'static>(&Box<Foo<i32>>) -> &i32
424..438 'Foo::get_inner': fn get_inner<i32, '{error}>(&Box<Foo<i32>>) -> &i32
424..446 'Foo::g...boxed)': &i32
439..445 '&boxed': &Box<Foo<i32>>
440..445 'boxed': Box<Foo<i32>>
457..461 'bad2': &Foo<i32>
464..469 'boxed': Box<Foo<i32>>
464..480 'boxed....self()': &Foo<i32>
490..495 'good2': &Foo<i32>
498..511 'Foo::get_self': fn get_self<i32, 'static>(&Box<Foo<i32>>) -> &Foo<i32>
498..511 'Foo::get_self': fn get_self<i32, '{error}>(&Box<Foo<i32>>) -> &Foo<i32>
498..519 'Foo::g...boxed)': &Foo<i32>
512..518 '&boxed': &Box<Foo<i32>>
513..518 'boxed': Box<Foo<i32>>
Expand Down Expand Up @@ -3659,7 +3659,7 @@ fn main() {
let are = "are";
let count = 10;
builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'static>
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'{error}>
}
"#,
);
Expand Down
16 changes: 8 additions & 8 deletions crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ fn weird_bounds() {
r#"
//- minicore: sized
trait Trait {}
fn test(
fn test<'lifetime>(
a: impl Trait + 'lifetime,
b: impl 'lifetime,
c: impl (Trait),
Expand All @@ -1612,13 +1612,13 @@ fn test(
) {}
"#,
expect![[r#"
28..29 'a': impl Trait + 'static
59..60 'b': impl 'static
82..83 'c': impl Trait
103..104 'd': impl 'static
128..129 'e': impl ?Sized
148..149 'f': impl Trait + ?Sized
173..175 '{}': ()
39..40 'a': impl Trait + 'lifetime
70..71 'b': impl 'lifetime
93..94 'c': impl Trait
114..115 'd': impl 'lifetime
139..140 'e': impl ?Sized
159..160 'f': impl Trait + ?Sized
184..186 '{}': ()
"#]],
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5617,7 +5617,7 @@ fn func<T: Debug>(i: Struct<'_, T>) {
fun_name(i);
}
fn $0fun_name(i: Struct<'static, T>) {
fn $0fun_name(i: Struct<'_, T>) {
foo(i);
}
"#,
Expand Down
Loading

0 comments on commit 8078c3d

Please sign in to comment.