1
1
//! Compute the binary representation of a type
2
2
3
- use std:: sync:: Arc ;
4
-
5
3
use base_db:: CrateId ;
6
4
use chalk_ir:: { AdtId , TyKind } ;
7
5
use hir_def:: {
@@ -31,19 +29,19 @@ mod adt;
31
29
mod target;
32
30
33
31
struct LayoutCx < ' a > {
34
- db : & ' a dyn HirDatabase ,
35
32
krate : CrateId ,
33
+ target : & ' a TargetDataLayout ,
36
34
}
37
35
38
- impl LayoutCalculator for LayoutCx < ' _ > {
39
- type TargetDataLayoutRef = Arc < TargetDataLayout > ;
36
+ impl < ' a > LayoutCalculator for LayoutCx < ' a > {
37
+ type TargetDataLayoutRef = & ' a TargetDataLayout ;
40
38
41
39
fn delay_bug ( & self , txt : & str ) {
42
40
never ! ( "{}" , txt) ;
43
41
}
44
42
45
- fn current_data_layout ( & self ) -> Arc < TargetDataLayout > {
46
- self . db . target_data_layout ( self . krate )
43
+ fn current_data_layout ( & self ) -> & ' a TargetDataLayout {
44
+ self . target
47
45
}
48
46
}
49
47
@@ -56,7 +54,8 @@ fn scalar(dl: &TargetDataLayout, value: Primitive) -> Layout {
56
54
}
57
55
58
56
pub fn layout_of_ty ( db : & dyn HirDatabase , ty : & Ty , krate : CrateId ) -> Result < Layout , LayoutError > {
59
- let cx = LayoutCx { db, krate } ;
57
+ let Some ( target) = db. target_data_layout ( krate) else { return Err ( LayoutError :: TargetLayoutNotAvailable ) } ;
58
+ let cx = LayoutCx { krate, target : & target } ;
60
59
let dl = & * cx. current_data_layout ( ) ;
61
60
Ok ( match ty. kind ( Interner ) {
62
61
TyKind :: Adt ( AdtId ( def) , subst) => db. layout_of_adt ( * def, subst. clone ( ) ) ?,
0 commit comments