From 6dc2e2e7be173b6c315b2ff605b900d827c47ac9 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 18 Jul 2024 14:06:20 +0100 Subject: [PATCH] naming fixes --- crates/red_knot_module_resolver/src/db.rs | 4 ++-- .../red_knot_module_resolver/src/resolver.rs | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/crates/red_knot_module_resolver/src/db.rs b/crates/red_knot_module_resolver/src/db.rs index a1fa85a8218b75..327a2036a0ca1c 100644 --- a/crates/red_knot_module_resolver/src/db.rs +++ b/crates/red_knot_module_resolver/src/db.rs @@ -2,14 +2,14 @@ use ruff_db::Upcast; use crate::resolver::{ editable_install_resolution_paths, file_to_module, internal::ModuleNameIngredient, - resolve_module_query, resolve_module_resolution_settings, + module_resolution_settings, resolve_module_query, }; use crate::typeshed::parse_typeshed_versions; #[salsa::jar(db=Db)] pub struct Jar( ModuleNameIngredient<'_>, - resolve_module_resolution_settings, + module_resolution_settings, editable_install_resolution_paths, resolve_module_query, file_to_module, diff --git a/crates/red_knot_module_resolver/src/resolver.rs b/crates/red_knot_module_resolver/src/resolver.rs index 95da575eccf971..ffff1e36be14e6 100644 --- a/crates/red_knot_module_resolver/src/resolver.rs +++ b/crates/red_knot_module_resolver/src/resolver.rs @@ -102,16 +102,8 @@ pub(crate) fn file_to_module(db: &dyn Db, file: File) -> Option { /// /// This method also implements the typing spec's [module resolution order]. /// -/// TODO(Alex): this method does multiple `.unwrap()` calls when it should really return an error. -/// Each `.unwrap()` call is a point where we're validating a setting that the user would pass -/// and transforming it into an internal representation for a validated path. -/// Rather than panicking if a path fails to validate, we should display an error message to the user -/// and exit the process with a nonzero exit code. -/// This validation should probably be done outside of Salsa? -/// /// [module resolution order]: https://typing.readthedocs.io/en/latest/spec/distributing.html#import-resolution-ordering -#[salsa::tracked(return_ref)] -pub(crate) fn resolve_module_resolution_settings( +fn try_resolve_module_resolution_settings( db: &dyn Db, ) -> Result { let program = Program::get(db.upcast()); @@ -185,9 +177,11 @@ pub(crate) fn resolve_module_resolution_settings( }) } -fn module_resolution_settings(db: &dyn Db) -> &ModuleResolutionSettings { - // TODO proper error handling if this Salsa query returns an error: - resolve_module_resolution_settings(db).as_ref().unwrap() +#[salsa::tracked(return_ref)] +pub(crate) fn module_resolution_settings(db: &dyn Db) -> ModuleResolutionSettings { + // TODO proper error handling if this Salsa query returns an error + // rather than panicking if a path fails to validate + try_resolve_module_resolution_settings(db).unwrap() } /// Collect all dynamic search paths: