Skip to content

Commit 5ff4928

Browse files
authored
Report syntetic read in priv_raw_file_content (#6799)
1 parent 9e0fea7 commit 5ff4928

File tree

1 file changed

+11
-4
lines changed
  • crates/cairo-lang-filesystem/src

1 file changed

+11
-4
lines changed

crates/cairo-lang-filesystem/src/db.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55

66
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
77
use cairo_lang_utils::{LookupIntern, Upcast};
8+
use salsa::Durability;
89
use semver::Version;
910
use serde::{Deserialize, Serialize};
1011
use smol_str::{SmolStr, ToSmolStr};
@@ -313,10 +314,16 @@ fn crate_config(db: &dyn FilesGroup, crt: CrateId) -> Option<CrateConfiguration>
313314

314315
fn priv_raw_file_content(db: &dyn FilesGroup, file: FileId) -> Option<Arc<str>> {
315316
match file.lookup_intern(db) {
316-
FileLongId::OnDisk(path) => match fs::read_to_string(path) {
317-
Ok(content) => Some(content.into()),
318-
Err(_) => None,
319-
},
317+
FileLongId::OnDisk(path) => {
318+
// This does not result in performance cost due to OS caching and the fact that salsa
319+
// will re-execute only this single query if the file content did not change.
320+
db.salsa_runtime().report_synthetic_read(Durability::LOW);
321+
322+
match fs::read_to_string(path) {
323+
Ok(content) => Some(content.into()),
324+
Err(_) => None,
325+
}
326+
}
320327
FileLongId::Virtual(virt) => Some(virt.content),
321328
FileLongId::External(external_id) => Some(db.ext_as_virtual(external_id).content),
322329
}

0 commit comments

Comments
 (0)