@@ -13,8 +13,8 @@ use smol_str::{SmolStr, ToSmolStr};
13
13
use crate :: cfg:: CfgSet ;
14
14
use crate :: flag:: Flag ;
15
15
use crate :: ids:: {
16
- BlobId , BlobLongId , CodeMapping , CodeOrigin , CrateId , CrateLongId , Directory , FileId ,
17
- FileInput , FileLongId , FlagId , FlagLongId , VirtualFile ,
16
+ BlobId , BlobLongId , CodeMapping , CodeOrigin , CrateId , CrateInput , CrateLongId , Directory ,
17
+ DirectoryInput , FileId , FileInput , FileLongId , FlagId , FlagLongId , VirtualFile ,
18
18
} ;
19
19
use crate :: span:: { FileSummary , TextOffset , TextSpan , TextWidth } ;
20
20
@@ -44,8 +44,28 @@ impl From<CrateIdentifier> for SmolStr {
44
44
}
45
45
}
46
46
47
- /// A configuration per crate.
47
+ /// Same as `CrateConfiguration` but without interning the root directory.
48
+ /// This is used to avoid the need to intern the file id inside salsa database inputs.
48
49
#[ derive( Clone , Debug , PartialEq , Eq ) ]
50
+ pub struct CrateConfigurationInput {
51
+ pub root : DirectoryInput ,
52
+ pub settings : CrateSettings ,
53
+ pub cache_file : Option < BlobLongId > ,
54
+ }
55
+
56
+ impl CrateConfigurationInput {
57
+ /// Converts the input into an [`CrateConfiguration`].
58
+ pub fn into_crate_configuration ( self , db : & dyn FilesGroup ) -> CrateConfiguration {
59
+ CrateConfiguration {
60
+ root : self . root . into_directory ( db) ,
61
+ settings : self . settings ,
62
+ cache_file : self . cache_file . map ( |blob_long_id| blob_long_id. intern ( db) ) ,
63
+ }
64
+ }
65
+ }
66
+
67
+ /// A configuration per crate.
68
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
49
69
pub struct CrateConfiguration {
50
70
/// The root directory of the crate.
51
71
pub root : Directory ,
@@ -57,10 +77,19 @@ impl CrateConfiguration {
57
77
pub fn default_for_root ( root : Directory ) -> Self {
58
78
Self { root, settings : CrateSettings :: default ( ) , cache_file : None }
59
79
}
80
+
81
+ /// Converts the configuration into an [`CrateConfigurationInput`].
82
+ pub fn into_crate_configuration_input ( self , db : & dyn FilesGroup ) -> CrateConfigurationInput {
83
+ CrateConfigurationInput {
84
+ root : self . root . into_directory_input ( db) ,
85
+ settings : self . settings ,
86
+ cache_file : self . cache_file . map ( |blob_id| blob_id. lookup_intern ( db) ) ,
87
+ }
88
+ }
60
89
}
61
90
62
91
/// Same as `CrateConfiguration` but without the root directory.
63
- #[ derive( Clone , Debug , Default , Hash , PartialEq , Eq , Serialize , Deserialize ) ]
92
+ #[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize , Hash ) ]
64
93
pub struct CrateSettings {
65
94
/// The name reflecting how the crate is referred to in the Cairo code e.g. `use crate_name::`.
66
95
/// If set to [`None`] then [`CrateIdentifier`] key will be used as a name.
@@ -137,7 +166,7 @@ impl Edition {
137
166
}
138
167
139
168
/// The settings for a dependency.
140
- #[ derive( Clone , Debug , Default , Hash , PartialEq , Eq , Serialize , Deserialize ) ]
169
+ #[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize , Hash ) ]
141
170
pub struct DependencySettings {
142
171
/// A unique string allowing identifying different copies of the same dependency
143
172
/// in the compilation unit.
@@ -192,7 +221,7 @@ pub trait FilesGroup: ExternalFiles {
192
221
193
222
/// Main input of the project. Lists all the crates configurations.
194
223
#[ salsa:: input]
195
- fn crate_configs_input ( & self ) -> Arc < OrderedHashMap < CrateLongId , CrateConfiguration > > ;
224
+ fn crate_configs_input ( & self ) -> Arc < OrderedHashMap < CrateInput , CrateConfigurationInput > > ;
196
225
197
226
/// Interned version of `crate_configs_input`.
198
227
fn crate_configs ( & self ) -> Arc < OrderedHashMap < CrateId , CrateConfiguration > > ;
@@ -238,6 +267,12 @@ pub trait FilesGroup: ExternalFiles {
238
267
239
268
/// Create an input file from an interned file id.
240
269
fn file_input ( & self , file_id : FileId ) -> FileInput ;
270
+
271
+ /// Create an input crate from an interned crate id.
272
+ fn crate_input ( & self , crt : CrateId ) -> CrateInput ;
273
+
274
+ /// Create an input crate configuration from a [`CrateConfiguration`].
275
+ fn crate_configuration_input ( & self , config : CrateConfiguration ) -> CrateConfigurationInput ;
241
276
}
242
277
243
278
pub fn init_files_group ( db : & mut ( dyn FilesGroup + ' static ) ) {
@@ -263,7 +298,12 @@ pub fn crate_configs(db: &dyn FilesGroup) -> Arc<OrderedHashMap<CrateId, CrateCo
263
298
let inp = db. crate_configs_input ( ) ;
264
299
Arc :: new (
265
300
inp. iter ( )
266
- . map ( |( crate_id, config) | ( crate_id. clone ( ) . intern ( db) , config. clone ( ) ) )
301
+ . map ( |( crate_input, config) | {
302
+ (
303
+ crate_input. clone ( ) . into_crate_long_id ( db) . intern ( db) ,
304
+ config. clone ( ) . into_crate_configuration ( db) ,
305
+ )
306
+ } )
267
307
. collect ( ) ,
268
308
)
269
309
}
@@ -277,6 +317,17 @@ fn file_input(db: &dyn FilesGroup, file_id: FileId) -> FileInput {
277
317
file_id. lookup_intern ( db) . into_file_input ( db)
278
318
}
279
319
320
+ fn crate_input ( db : & dyn FilesGroup , crt : CrateId ) -> CrateInput {
321
+ crt. lookup_intern ( db) . into_crate_input ( db)
322
+ }
323
+
324
+ fn crate_configuration_input (
325
+ db : & dyn FilesGroup ,
326
+ config : CrateConfiguration ,
327
+ ) -> CrateConfigurationInput {
328
+ config. clone ( ) . into_crate_configuration_input ( db)
329
+ }
330
+
280
331
pub fn init_dev_corelib ( db : & mut ( dyn FilesGroup + ' static ) , core_lib_dir : PathBuf ) {
281
332
db. set_crate_config (
282
333
CrateId :: core ( db) ,
@@ -313,10 +364,10 @@ pub trait FilesGroupEx: FilesGroup {
313
364
}
314
365
/// Sets the root directory of the crate. None value removes the crate.
315
366
fn set_crate_config ( & mut self , crt : CrateId , root : Option < CrateConfiguration > ) {
316
- let crt = self . lookup_intern_crate ( crt) ;
367
+ let crt = self . crate_input ( crt) ;
317
368
let mut crate_configs = self . crate_configs_input ( ) . as_ref ( ) . clone ( ) ;
318
369
match root {
319
- Some ( root) => crate_configs. insert ( crt, root) ,
370
+ Some ( root) => crate_configs. insert ( crt, self . crate_configuration_input ( root) ) ,
320
371
None => crate_configs. swap_remove ( & crt) ,
321
372
} ;
322
373
self . set_crate_configs_input ( Arc :: new ( crate_configs) ) ;
@@ -398,19 +449,7 @@ fn get_flag(db: &dyn FilesGroup, id: FlagId) -> Option<Arc<Flag>> {
398
449
}
399
450
400
451
fn blob_content ( db : & dyn FilesGroup , blob : BlobId ) -> Option < Arc < [ u8 ] > > {
401
- match blob. lookup_intern ( db) {
402
- BlobLongId :: OnDisk ( path) => {
403
- // This does not result in performance cost due to OS caching and the fact that salsa
404
- // will re-execute only this single query if the file content did not change.
405
- db. salsa_runtime ( ) . report_synthetic_read ( Durability :: LOW ) ;
406
-
407
- match fs:: read ( path) {
408
- Ok ( content) => Some ( content. into ( ) ) ,
409
- Err ( _) => None ,
410
- }
411
- }
412
- BlobLongId :: Virtual ( content) => Some ( content) ,
413
- }
452
+ blob. lookup_intern ( db) . content ( db)
414
453
}
415
454
416
455
/// Returns the location of the originating user code.
0 commit comments