Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Dec 26, 2024
1 parent 09c9c57 commit cfd7b77
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/ast/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl<'a> AstWorkspace<'a> {
None
}

pub fn get_owning_module_or_self(&self, fs_node_id: FsNodeId) -> FsNodeId {
self.get_owning_module(fs_node_id).unwrap_or(fs_node_id)
}

pub fn get_mut(&mut self, id: FsNodeId) -> Option<&mut AstFile> {
self.files.get_mut(&id)
}
Expand Down
4 changes: 1 addition & 3 deletions src/resolve/function_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub fn resolve_function_bodies(
while let Some(job) = ctx.jobs.pop_front() {
match job {
FuncJob::Regular(physical_file_id, ast_function_index, resolved_function_ref) => {
let module_file_id = ast_workspace
.get_owning_module(physical_file_id)
.unwrap_or(physical_file_id);
let module_file_id = ast_workspace.get_owning_module_or_self(physical_file_id);

let function_haystack = ctx
.function_haystacks
Expand Down
4 changes: 1 addition & 3 deletions src/resolve/function_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ pub fn create_function_heads<'a>(
options: &BuildOptions,
) -> Result<(), ResolveError> {
for (physical_file_id, file) in ast_workspace.files.iter() {
let module_file_id = ast_workspace
.get_owning_module(*physical_file_id)
.unwrap_or(*physical_file_id);
let module_file_id = ast_workspace.get_owning_module_or_self(*physical_file_id);

for (function_i, function) in file.functions.iter().enumerate() {
let name = ResolvedName::new(module_file_id, &Name::plain(&function.head.name));
Expand Down
4 changes: 1 addition & 3 deletions src/resolve/global_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub fn resolve_global_variables(
let constraints = CurrentConstraints::new_empty(ctx.implementations);

for (physical_file_id, file) in ast_workspace.files.iter() {
let module_file_id = ast_workspace
.get_owning_module(*physical_file_id)
.unwrap_or(*physical_file_id);
let module_file_id = ast_workspace.get_owning_module_or_self(*physical_file_id);

for global in file.global_variables.iter() {
let type_ctx = ResolveTypeCtx::new(
Expand Down
5 changes: 1 addition & 4 deletions src/resolve/helper_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub fn resolve_helper_expressions(
ast_workspace: &AstWorkspace,
) -> Result<(), ResolveError> {
for (physical_file_id, file) in ast_workspace.files.iter() {
let module_file_id = ast_workspace
.get_owning_module(*physical_file_id)
.unwrap_or(*physical_file_id);

let module_file_id = ast_workspace.get_owning_module_or_self(*physical_file_id);
let settings = &ast_workspace.settings[file.settings.unwrap_or_default().0];

// NOTE: This module should already have a function haystack
Expand Down
4 changes: 1 addition & 3 deletions src/resolve/type_definition/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ pub fn prepare_type_jobs(
let mut type_jobs = Vec::with_capacity(ast_workspace.files.len());

for (physical_file_id, file) in ast_workspace.files.iter() {
let module_fs_node_id = ast_workspace
.get_owning_module(*physical_file_id)
.unwrap_or(*physical_file_id);
let module_fs_node_id = ast_workspace.get_owning_module_or_self(*physical_file_id);

let mut job = TypeJob {
physical_file_id: *physical_file_id,
Expand Down
4 changes: 1 addition & 3 deletions src/resolve/type_definition/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ pub fn resolve_type_jobs(
.get(&job.physical_file_id)
.expect("valid ast file");

let module_file_id = ast_workspace
.get_owning_module(job.physical_file_id)
.unwrap_or(job.physical_file_id);
let module_file_id = ast_workspace.get_owning_module_or_self(job.physical_file_id);

for (trait_ref, user_trait) in job.traits.iter().zip(file.traits.iter()) {
resolve_trait(
Expand Down

0 comments on commit cfd7b77

Please sign in to comment.