@@ -54,10 +54,10 @@ use rustc_type_ir::{
5454 AliasTyKind , TypeFoldable ,
5555 inherent:: { AdtDef , IntoKind , Region as _, SliceLike , Ty as _} ,
5656} ;
57+ use salsa:: Update ;
5758use span:: Edition ;
5859use stdx:: never;
5960use thin_vec:: ThinVec ;
60- use triomphe:: Arc ;
6161
6262use crate :: {
6363 ImplTraitId , IncorrectGenericsLenKind , PathLoweringDiagnostic , TargetFeatures ,
@@ -95,7 +95,7 @@ use cast::{CastCheck, CastError};
9595pub ( crate ) use closure:: analysis:: { CaptureKind , CapturedItem , CapturedItemWithoutTy } ;
9696
9797/// The entry point of type inference.
98- pub ( crate ) fn infer_query ( db : & dyn HirDatabase , def : DefWithBodyId ) -> Arc < InferenceResult < ' _ > > {
98+ fn infer_query ( db : & dyn HirDatabase , def : DefWithBodyId ) -> InferenceResult < ' _ > {
9999 let _p = tracing:: info_span!( "infer_query" ) . entered ( ) ;
100100 let resolver = def. resolver ( db) ;
101101 let body = db. body ( def) ;
@@ -159,17 +159,14 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
159159
160160 ctx. handle_opaque_type_uses ( ) ;
161161
162- Arc :: new ( ctx. resolve_all ( ) )
162+ ctx. resolve_all ( )
163163}
164164
165- pub ( crate ) fn infer_cycle_result (
166- db : & dyn HirDatabase ,
167- _: DefWithBodyId ,
168- ) -> Arc < InferenceResult < ' _ > > {
169- Arc :: new ( InferenceResult {
165+ fn infer_cycle_result ( db : & dyn HirDatabase , _: DefWithBodyId ) -> InferenceResult < ' _ > {
166+ InferenceResult {
170167 has_errors : true ,
171168 ..InferenceResult :: new ( Ty :: new_error ( DbInterner :: new_no_crate ( db) , ErrorGuaranteed ) )
172- } )
169+ }
173170}
174171
175172/// Binding modes inferred for patterns.
@@ -199,7 +196,7 @@ pub enum InferenceTyDiagnosticSource {
199196 Signature ,
200197}
201198
202- #[ derive( Debug , PartialEq , Eq , Clone ) ]
199+ #[ derive( Debug , PartialEq , Eq , Clone , Update ) ]
203200pub enum InferenceDiagnostic < ' db > {
204201 NoSuchField {
205202 field : ExprOrPatId ,
@@ -293,7 +290,7 @@ pub enum InferenceDiagnostic<'db> {
293290}
294291
295292/// A mismatch between an expected and an inferred type.
296- #[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
293+ #[ derive( Clone , PartialEq , Eq , Debug , Hash , Update ) ]
297294pub struct TypeMismatch < ' db > {
298295 pub expected : Ty < ' db > ,
299296 pub actual : Ty < ' db > ,
@@ -339,7 +336,7 @@ pub struct TypeMismatch<'db> {
339336/// At some point, of course, `Box` should move out of the compiler, in which
340337/// case this is analogous to transforming a struct. E.g., Box<[i32; 4]> ->
341338/// Box<[i32]> is an `Adjust::Unsize` with the target `Box<[i32]>`.
342- #[ derive( Clone , Debug , PartialEq , Eq , Hash , TypeVisitable , TypeFoldable ) ]
339+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , TypeVisitable , TypeFoldable , Update ) ]
343340pub struct Adjustment < ' db > {
344341 #[ type_visitable( ignore) ]
345342 #[ type_foldable( identity) ]
@@ -476,9 +473,10 @@ pub enum PointerCast {
476473/// When you add a field that stores types (including `Substitution` and the like), don't forget
477474/// `resolve_completely()`'ing them in `InferenceContext::resolve_all()`. Inference variables must
478475/// not appear in the final inference result.
479- #[ derive( Clone , PartialEq , Eq , Debug ) ]
476+ #[ derive( Clone , PartialEq , Eq , Debug , Update ) ]
480477pub struct InferenceResult < ' db > {
481478 /// For each method call expr, records the function it resolves to.
479+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* expr id is technically update */ ) ) ) ]
482480 method_resolutions : FxHashMap < ExprId , ( FunctionId , GenericArgs < ' db > ) > ,
483481 /// For each field access expr, records the field it resolves to.
484482 field_resolutions : FxHashMap < ExprId , Either < FieldId , TupleFieldId > > ,
@@ -491,13 +489,17 @@ pub struct InferenceResult<'db> {
491489 /// that which allows us to resolve a [`TupleFieldId`]s type.
492490 tuple_field_access_types : FxHashMap < TupleId , Tys < ' db > > ,
493491
492+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* expr id is technically update */ ) ) ) ]
494493 pub ( crate ) type_of_expr : ArenaMap < ExprId , Ty < ' db > > ,
495494 /// For each pattern record the type it resolves to.
496495 ///
497496 /// **Note**: When a pattern type is resolved it may still contain
498497 /// unresolved or missing subpatterns or subpatterns of mismatched types.
498+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* pat id is technically update */ ) ) ) ]
499499 pub ( crate ) type_of_pat : ArenaMap < PatId , Ty < ' db > > ,
500+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* binding id is technically update */ ) ) ) ]
500501 pub ( crate ) type_of_binding : ArenaMap < BindingId , Ty < ' db > > ,
502+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* type ref id is technically update */ ) ) ) ]
501503 pub ( crate ) type_of_type_placeholder : FxHashMap < TypeRefId , Ty < ' db > > ,
502504 pub ( crate ) type_of_opaque : FxHashMap < InternedOpaqueTyId , Ty < ' db > > ,
503505
@@ -508,14 +510,17 @@ pub struct InferenceResult<'db> {
508510 // Which will then mark this field.
509511 pub ( crate ) has_errors : bool ,
510512 /// During inference this field is empty and [`InferenceContext::diagnostics`] is filled instead.
513+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* thinvec is technically update */ ) ) ) ]
511514 diagnostics : ThinVec < InferenceDiagnostic < ' db > > ,
512515
513516 /// Interned `Error` type to return references to.
514517 // FIXME: Remove this.
515518 error_ty : Ty < ' db > ,
516519
520+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* expr id is technically update */ ) ) ) ]
517521 pub ( crate ) expr_adjustments : FxHashMap < ExprId , Box < [ Adjustment < ' db > ] > > ,
518522 /// Stores the types which were implicitly dereferenced in pattern binding modes.
523+ #[ update( unsafe ( with( crate :: utils:: unsafe_update_eq /* pat id is technically update */ ) ) ) ]
519524 pub ( crate ) pat_adjustments : FxHashMap < PatId , Vec < Ty < ' db > > > ,
520525 /// Stores the binding mode (`ref` in `let ref x = 2`) of bindings.
521526 ///
@@ -539,6 +544,14 @@ pub struct InferenceResult<'db> {
539544 pub ( crate ) coercion_casts : FxHashSet < ExprId > ,
540545}
541546
547+ #[ salsa:: tracked]
548+ impl < ' db > InferenceResult < ' db > {
549+ #[ salsa:: tracked( returns( ref) , cycle_result = infer_cycle_result) ]
550+ pub fn for_body ( db : & ' db dyn HirDatabase , def : DefWithBodyId ) -> InferenceResult < ' db > {
551+ infer_query ( db, def)
552+ }
553+ }
554+
542555impl < ' db > InferenceResult < ' db > {
543556 fn new ( error_ty : Ty < ' db > ) -> Self {
544557 Self {
0 commit comments