From 7e104ea4a885c8fd6f348a0d7d30911fe49d91e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 22 Jun 2020 14:18:10 +0300 Subject: Bump chalk --- crates/ra_hir_ty/src/traits/chalk.rs | 86 ++++++++++++++++++++++----- crates/ra_hir_ty/src/traits/chalk/interner.rs | 1 + crates/ra_hir_ty/src/traits/chalk/mapping.rs | 9 ++- 3 files changed, 80 insertions(+), 16 deletions(-) (limited to 'crates/ra_hir_ty/src/traits') diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 2f35d6d49..8ef4941c0 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -48,6 +48,9 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn adt_datum(&self, struct_id: AdtId) -> Arc { self.db.struct_datum(self.krate, struct_id) } + fn adt_repr(&self, _struct_id: AdtId) -> rust_ir::AdtRepr { + unreachable!() + } fn impl_datum(&self, impl_id: ImplId) -> Arc { self.db.impl_datum(self.krate, impl_id) } @@ -128,8 +131,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { well_known_trait: rust_ir::WellKnownTrait, ) -> Option> { let lang_attr = lang_attr_from_well_known_trait(well_known_trait); - let lang_items = self.db.crate_lang_items(self.krate); - let trait_ = match lang_items.target(lang_attr) { + let trait_ = match self.db.lang_item(self.krate, lang_attr.into()) { Some(LangItemTarget::TraitId(trait_)) => trait_, _ => return None, }; @@ -186,6 +188,39 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { // FIXME: implement actual object safety true } + + fn closure_kind( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> rust_ir::ClosureKind { + // FIXME: implement closure support + unimplemented!() + } + fn closure_inputs_and_output( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Binders> { + // FIXME: implement closure support + unimplemented!() + } + fn closure_upvars( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Binders> { + // FIXME: implement closure support + unimplemented!() + } + fn closure_fn_substitution( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Substitution { + // FIXME: implement closure support + unimplemented!() + } } pub(crate) fn program_clauses_for_chalk_env_query( @@ -250,7 +285,7 @@ pub(crate) fn trait_datum_query( upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, non_enumerable: true, coinductive: false, // only relevant for Chalk testing - // FIXME set these flags correctly + // FIXME: set these flags correctly marker: false, fundamental: false, }; @@ -272,20 +307,28 @@ pub(crate) fn trait_datum_query( fn well_known_trait_from_lang_attr(name: &str) -> Option { Some(match name { - "sized" => WellKnownTrait::SizedTrait, - "copy" => WellKnownTrait::CopyTrait, - "clone" => WellKnownTrait::CloneTrait, - "drop" => WellKnownTrait::DropTrait, + "sized" => WellKnownTrait::Sized, + "copy" => WellKnownTrait::Copy, + "clone" => WellKnownTrait::Clone, + "drop" => WellKnownTrait::Drop, + "fn_once" => WellKnownTrait::FnOnce, + "fn_mut" => WellKnownTrait::FnMut, + "fn" => WellKnownTrait::Fn, + "unsize" => WellKnownTrait::Unsize, _ => return None, }) } fn lang_attr_from_well_known_trait(attr: WellKnownTrait) -> &'static str { match attr { - WellKnownTrait::SizedTrait => "sized", - WellKnownTrait::CopyTrait => "copy", - WellKnownTrait::CloneTrait => "clone", - WellKnownTrait::DropTrait => "drop", + WellKnownTrait::Sized => "sized", + WellKnownTrait::Copy => "copy", + WellKnownTrait::Clone => "clone", + WellKnownTrait::Drop => "drop", + WellKnownTrait::FnOnce => "fn_once", + WellKnownTrait::FnMut => "fn_mut", + WellKnownTrait::Fn => "fn", + WellKnownTrait::Unsize => "unsize", } } @@ -309,8 +352,9 @@ pub(crate) fn struct_datum_query( .unwrap_or_else(Vec::new); let flags = rust_ir::AdtFlags { upstream, - // FIXME set fundamental flag correctly + // FIXME set fundamental and phantom_data flags correctly fundamental: false, + phantom_data: false, }; let struct_datum_bound = rust_ir::AdtDatumBound { fields: Vec::new(), // FIXME add fields (only relevant for auto traits) @@ -448,11 +492,23 @@ pub(crate) fn fn_def_datum_query( let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); let bound = rust_ir::FnDefDatumBound { // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway - argument_types: sig.value.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), - return_type: sig.value.ret().clone().to_chalk(db), + inputs_and_output: make_binders( + rust_ir::FnDefInputsAndOutputDatum { + argument_types: sig + .value + .params() + .iter() + .map(|ty| ty.clone().to_chalk(db)) + .collect(), + return_type: sig.value.ret().clone().to_chalk(db), + } + .shifted_in(&Interner), + 0, + ), where_clauses, }; - let datum = FnDefDatum { id: fn_def_id, binders: make_binders(bound, sig.num_binders) }; + let datum = + FnDefDatum { id: fn_def_id, binders: make_binders(bound, sig.num_binders), abi: () }; Arc::new(datum) } diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 56aab640c..15426b022 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs @@ -42,6 +42,7 @@ impl chalk_ir::interner::Interner for Interner { type DefId = InternId; type InternedAdtId = crate::TypeCtorId; type Identifier = TypeAliasId; + type FnAbi = (); fn debug_adt_id(type_kind_id: AdtId, fmt: &mut fmt::Formatter<'_>) -> Option { tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 18e5c9c16..ac82ea831 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -65,7 +65,10 @@ impl ToChalk for Ty { &Interner, predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), ); - let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) }; + let bounded_ty = chalk_ir::DynTy { + bounds: make_binders(where_clauses, 1), + lifetime: LIFETIME_PLACEHOLDER.to_lifetime(&Interner), + }; chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) } Ty::Opaque(opaque_ty) => { @@ -319,6 +322,10 @@ impl ToChalk for TypeCtor { // this should not be reached, since we don't represent TypeName::Error with TypeCtor unreachable!() } + TypeName::Closure(_) => { + // FIXME: implement closure support + unreachable!() + } } } } -- cgit v1.2.3