Skip to content

Commit bc0615d

Browse files
committed
Address code review
1 parent 993ab43 commit bc0615d

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

crates/oak_db/src/package.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Package {
9393
/// parses it. Lazy and tracked so we only pay the read and the R-parse
9494
/// for packages whose imports actually get resolved. Parsing every
9595
/// installed package's `NAMESPACE` eagerly would dominate the cost of
96-
/// scanning a library with hundreds of packages, so we defer it.
96+
/// scanning a library with hundreds of packages, so we defer it (#1265).
9797
///
9898
/// A missing or unparseable `NAMESPACE` yields an empty `Namespace`.
9999
#[salsa::tracked(returns(ref))]
@@ -114,19 +114,17 @@ impl Package {
114114
};
115115

116116
let namespace_path = dir.join("NAMESPACE");
117-
let text = match fs::read_to_string(namespace_path.as_std_path()) {
118-
Ok(text) => text,
117+
match fs::read_to_string(namespace_path.as_std_path()) {
118+
Ok(text) => Namespace::parse(&text).log_err().unwrap_or_default(),
119119
// A package needn't ship a `NAMESPACE`, so absence is the normal
120120
// case and stays quiet. A file that exists but can't be read is
121121
// logged so the failure isn't silently read as "no namespace".
122-
Err(err) if err.kind() == io::ErrorKind::NotFound => return Namespace::default(),
122+
Err(err) if err.kind() == io::ErrorKind::NotFound => Namespace::default(),
123123
Err(err) => {
124124
log::error!("Failed to read `{namespace_path}`: {err:?}");
125-
return Namespace::default();
125+
Namespace::default()
126126
},
127-
};
128-
129-
Namespace::parse(&text).log_err().unwrap_or_default()
127+
}
130128
}
131129

132130
/// The package's `Version:`, parsed lazily from `DESCRIPTION`. `None`
@@ -171,17 +169,16 @@ impl Package {
171169
report_untracked_if_zero(db, self.description_revision(db));
172170

173171
let path = self.description_path(db).as_path()?;
174-
let text = match fs::read_to_string(path.as_std_path()) {
175-
Ok(text) => text,
172+
match fs::read_to_string(path.as_std_path()) {
173+
Ok(text) => Description::parse(&text).log_err(),
176174
// A missing `DESCRIPTION` is the normal "gone after a rescan" case
177175
// and stays quiet. A file that exists but can't be read is logged
178176
// rather than silently treated as absent.
179-
Err(err) if err.kind() == io::ErrorKind::NotFound => return None,
177+
Err(err) if err.kind() == io::ErrorKind::NotFound => None,
180178
Err(err) => {
181179
log::error!("Failed to read `{path}`: {err:?}");
182-
return None;
180+
None
183181
},
184-
};
185-
Description::parse(&text).log_err()
182+
}
186183
}
187184
}

crates/oak_scan/src/packages.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ pub(crate) struct PackageEntry {
5656
/// `NAMESPACE` is only stat'd here, never read or parsed. The lazy
5757
/// [`oak_db::Package::namespace`] query does the parse. `DESCRIPTION` is read
5858
/// and parsed because the walk needs the `Package:` name (the workspace
59-
/// directory name isn't authoritative) and the `Collate:` order to sort
59+
/// directory name isn't authoritative, unlike an installed package's folder
60+
/// name) and the `Collate:` order to sort
6061
/// `R/*.R`. The parsed `collation` only orders this walk's files. It isn't
6162
/// pushed to salsa. [`oak_db::Package::version`] and
6263
/// [`oak_db::Package::collation`] re-read `DESCRIPTION` lazily off the

0 commit comments

Comments
 (0)