@@ -23,10 +23,10 @@ mod pat;
23
23
mod path;
24
24
pub ( crate ) mod unify;
25
25
26
- use std:: { cell:: OnceCell , convert:: identity, iter, ops:: Index } ;
26
+ use std:: { cell:: OnceCell , convert:: identity, iter, ops:: Index , sync :: LazyLock } ;
27
27
28
28
use chalk_ir:: {
29
- DebruijnIndex , Mutability , Safety , Scalar , TyKind , TypeFlags , Variance ,
29
+ DebruijnIndex , Mutability , Safety , TyKind , TypeFlags , Variance ,
30
30
cast:: Cast ,
31
31
fold:: TypeFoldable ,
32
32
interner:: HasInterner ,
@@ -195,6 +195,10 @@ pub enum InferenceTyDiagnosticSource {
195
195
Signature ,
196
196
}
197
197
198
+ pub ( crate ) static ERROR_TY : LazyLock < Ty > = LazyLock :: new ( || TyKind :: Error . intern ( Interner ) ) ;
199
+ pub ( crate ) static UNIT_TY : LazyLock < Ty > =
200
+ LazyLock :: new ( || TyKind :: Tuple ( 0 , Substitution :: empty ( Interner ) ) . intern ( Interner ) ) ;
201
+
198
202
#[ derive( Debug ) ]
199
203
pub ( crate ) struct TypeError ;
200
204
pub ( crate ) type InferResult < T > = Result < InferOk < T > , TypeError > ;
@@ -299,24 +303,6 @@ pub struct TypeMismatch {
299
303
pub actual : Ty ,
300
304
}
301
305
302
- #[ derive( Clone , PartialEq , Eq , Debug ) ]
303
- struct InternedStandardTypes {
304
- unknown : Ty ,
305
- bool_ : Ty ,
306
- unit : Ty ,
307
- never : Ty ,
308
- }
309
-
310
- impl Default for InternedStandardTypes {
311
- fn default ( ) -> Self {
312
- InternedStandardTypes {
313
- unknown : TyKind :: Error . intern ( Interner ) ,
314
- bool_ : TyKind :: Scalar ( Scalar :: Bool ) . intern ( Interner ) ,
315
- unit : TyKind :: Tuple ( 0 , Substitution :: empty ( Interner ) ) . intern ( Interner ) ,
316
- never : TyKind :: Never . intern ( Interner ) ,
317
- }
318
- }
319
- }
320
306
/// Represents coercing a value to a different type of value.
321
307
///
322
308
/// We transform values by following a number of `Adjust` steps in order.
@@ -475,8 +461,6 @@ pub struct InferenceResult {
475
461
// Which will then mark this field.
476
462
pub ( crate ) has_errors : bool ,
477
463
/// Interned common types to return references to.
478
- // FIXME: Move this into `InferenceContext`
479
- standard_types : InternedStandardTypes ,
480
464
/// Stores the types which were implicitly dereferenced in pattern binding modes.
481
465
pub pat_adjustments : FxHashMap < PatId , Vec < Ty > > ,
482
466
/// Stores the binding mode (`ref` in `let ref x = 2`) of bindings.
@@ -564,31 +548,31 @@ impl Index<ExprId> for InferenceResult {
564
548
type Output = Ty ;
565
549
566
550
fn index ( & self , expr : ExprId ) -> & Ty {
567
- self . type_of_expr . get ( expr) . unwrap_or ( & self . standard_types . unknown )
551
+ self . type_of_expr . get ( expr) . unwrap_or_else ( || & ERROR_TY )
568
552
}
569
553
}
570
554
571
555
impl Index < PatId > for InferenceResult {
572
556
type Output = Ty ;
573
557
574
558
fn index ( & self , pat : PatId ) -> & Ty {
575
- self . type_of_pat . get ( pat) . unwrap_or ( & self . standard_types . unknown )
559
+ self . type_of_pat . get ( pat) . unwrap_or_else ( || & ERROR_TY )
576
560
}
577
561
}
578
562
579
563
impl Index < ExprOrPatId > for InferenceResult {
580
564
type Output = Ty ;
581
565
582
566
fn index ( & self , id : ExprOrPatId ) -> & Ty {
583
- self . type_of_expr_or_pat ( id) . unwrap_or ( & self . standard_types . unknown )
567
+ self . type_of_expr_or_pat ( id) . unwrap_or_else ( || & ERROR_TY )
584
568
}
585
569
}
586
570
587
571
impl Index < BindingId > for InferenceResult {
588
572
type Output = Ty ;
589
573
590
574
fn index ( & self , b : BindingId ) -> & Ty {
591
- self . type_of_binding . get ( b) . unwrap_or ( & self . standard_types . unknown )
575
+ self . type_of_binding . get ( b) . unwrap_or_else ( || & ERROR_TY )
592
576
}
593
577
}
594
578
@@ -767,7 +751,6 @@ impl<'db> InferenceContext<'db> {
767
751
type_of_for_iterator,
768
752
type_mismatches,
769
753
has_errors,
770
- standard_types : _,
771
754
pat_adjustments,
772
755
binding_modes : _,
773
756
expr_adjustments,
@@ -1022,7 +1005,7 @@ impl<'db> InferenceContext<'db> {
1022
1005
return_ty
1023
1006
}
1024
1007
}
1025
- None => self . result . standard_types . unit . clone ( ) ,
1008
+ None => UNIT_TY . clone ( ) ,
1026
1009
} ;
1027
1010
1028
1011
self . return_ty = self . normalize_associated_types_in ( return_ty) ;
@@ -1400,7 +1383,7 @@ impl<'db> InferenceContext<'db> {
1400
1383
}
1401
1384
1402
1385
fn err_ty ( & self ) -> Ty {
1403
- self . result . standard_types . unknown . clone ( )
1386
+ TyKind :: Error . intern ( Interner )
1404
1387
}
1405
1388
1406
1389
fn make_body_lifetime ( & mut self , lifetime_ref : LifetimeRefId ) -> Lifetime {
0 commit comments