@@ -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
- CodeMapping , CodeOrigin , CrateId , CrateLongId , Directory , FileId , FileLongId , FlagId ,
17
- FlagLongId , VirtualFile ,
16
+ BlobId , BlobLongId , CodeMapping , CodeOrigin , CrateId , CrateLongId , Directory , FileId ,
17
+ FileLongId , FlagId , FlagLongId , VirtualFile ,
18
18
} ;
19
19
use crate :: span:: { FileSummary , TextOffset , TextSpan , TextWidth } ;
20
20
@@ -50,11 +50,12 @@ pub struct CrateConfiguration {
50
50
/// The root directory of the crate.
51
51
pub root : Directory ,
52
52
pub settings : CrateSettings ,
53
+ pub cache_file : Option < BlobId > ,
53
54
}
54
55
impl CrateConfiguration {
55
56
/// Returns a new configuration.
56
57
pub fn default_for_root ( root : Directory ) -> Self {
57
- Self { root, settings : CrateSettings :: default ( ) }
58
+ Self { root, settings : CrateSettings :: default ( ) , cache_file : None }
58
59
}
59
60
}
60
61
@@ -182,6 +183,8 @@ pub trait FilesGroup: ExternalFiles {
182
183
#[ salsa:: interned]
183
184
fn intern_file ( & self , file : FileLongId ) -> FileId ;
184
185
#[ salsa:: interned]
186
+ fn intern_blob ( & self , blob : BlobLongId ) -> BlobId ;
187
+ #[ salsa:: interned]
185
188
fn intern_flag ( & self , flag : FlagLongId ) -> FlagId ;
186
189
187
190
/// Main input of the project. Lists all the crates configurations.
@@ -215,6 +218,8 @@ pub trait FilesGroup: ExternalFiles {
215
218
fn file_content ( & self , file_id : FileId ) -> Option < Arc < str > > ;
216
219
fn file_summary ( & self , file_id : FileId ) -> Option < Arc < FileSummary > > ;
217
220
221
+ /// Query for the blob content.
222
+ fn blob_content ( & self , blob_id : BlobId ) -> Option < Arc < [ u8 ] > > ;
218
223
/// Query to get a compilation flag by its ID.
219
224
fn get_flag ( & self , id : FlagId ) -> Option < Arc < Flag > > ;
220
225
}
@@ -244,6 +249,7 @@ pub fn init_dev_corelib(db: &mut (dyn FilesGroup + 'static), core_lib_dir: PathB
244
249
coupons : true ,
245
250
} ,
246
251
} ,
252
+ cache_file : None ,
247
253
} ) ,
248
254
) ;
249
255
}
@@ -302,13 +308,17 @@ fn crates(db: &dyn FilesGroup) -> Vec<CrateId> {
302
308
fn crate_config ( db : & dyn FilesGroup , crt : CrateId ) -> Option < CrateConfiguration > {
303
309
match crt. lookup_intern ( db) {
304
310
CrateLongId :: Real { .. } => db. crate_configs ( ) . get ( & crt) . cloned ( ) ,
305
- CrateLongId :: Virtual { name : _, file_id, settings } => Some ( CrateConfiguration {
306
- root : Directory :: Virtual {
307
- files : BTreeMap :: from ( [ ( "lib.cairo" . into ( ) , file_id) ] ) ,
308
- dirs : Default :: default ( ) ,
309
- } ,
310
- settings : toml:: from_str ( & settings) . expect ( "Failed to parse virtual crate settings." ) ,
311
- } ) ,
311
+ CrateLongId :: Virtual { name : _, file_id, settings, cache_file } => {
312
+ Some ( CrateConfiguration {
313
+ root : Directory :: Virtual {
314
+ files : BTreeMap :: from ( [ ( "lib.cairo" . into ( ) , file_id) ] ) ,
315
+ dirs : Default :: default ( ) ,
316
+ } ,
317
+ settings : toml:: from_str ( & settings)
318
+ . expect ( "Failed to parse virtual crate settings." ) ,
319
+ cache_file,
320
+ } )
321
+ }
312
322
}
313
323
}
314
324
@@ -348,6 +358,22 @@ fn get_flag(db: &dyn FilesGroup, id: FlagId) -> Option<Arc<Flag>> {
348
358
db. flags ( ) . get ( & id) . cloned ( )
349
359
}
350
360
361
+ fn blob_content ( db : & dyn FilesGroup , blob : BlobId ) -> Option < Arc < [ u8 ] > > {
362
+ match blob. lookup_intern ( db) {
363
+ BlobLongId :: OnDisk ( path) => {
364
+ // This does not result in performance cost due to OS caching and the fact that salsa
365
+ // will re-execute only this single query if the file content did not change.
366
+ db. salsa_runtime ( ) . report_synthetic_read ( Durability :: LOW ) ;
367
+
368
+ match fs:: read ( path) {
369
+ Ok ( content) => Some ( content. into ( ) ) ,
370
+ Err ( _) => None ,
371
+ }
372
+ }
373
+ BlobLongId :: Virtual ( content) => Some ( content) ,
374
+ }
375
+ }
376
+
351
377
/// Returns the location of the originating user code.
352
378
pub fn get_originating_location (
353
379
db : & dyn FilesGroup ,
0 commit comments