Skip to content

Commit

Permalink
misc: fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Oct 27, 2020
1 parent 7b50951 commit 6747bbc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions crates/mun_hir/src/name_resolution/path_resolution.rs
Expand Up @@ -70,8 +70,8 @@ impl PackageDefs {
}

/// Resolves the specified `path` from within the specified `module`. Also returns whether or
/// not an additions to the PackageDef would change the result. This is useful when resolving
/// all imports.
/// not additions to the `PackageDef` would change the result or whether a fixed point has been
/// reached. This is useful when resolving all imports.
pub(super) fn resolve_path_with_fixedpoint(
&self,
db: &dyn DefDatabase,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl PackageDefs {
}
.into(),
Visibility::Public,
))
)),
};

for (i, segment) in segments {
Expand Down
11 changes: 5 additions & 6 deletions crates/mun_hir/src/package_defs.rs
@@ -1,11 +1,10 @@
mod collector;

use crate::ids::PackageId;
use crate::item_scope::ItemScope;
use crate::module_tree::ModuleTree;
use crate::{arena::map::ArenaMap, module_tree::LocalModuleId, DefDatabase};
use std::ops::Index;
use std::sync::Arc;
use crate::{
arena::map::ArenaMap, ids::PackageId, item_scope::ItemScope, module_tree::LocalModuleId,
module_tree::ModuleTree, DefDatabase,
};
use std::{ops::Index, sync::Arc};

/// Contains all top-level definitions for a package.
#[derive(Debug, PartialEq, Eq)]
Expand Down
34 changes: 18 additions & 16 deletions crates/mun_hir/src/package_defs/collector.rs
@@ -1,15 +1,15 @@
use super::PackageDefs;
use crate::arena::map::ArenaMap;
use crate::ids::{
FunctionLoc, Intern, ItemDefinitionId, ModuleId, PackageId, StructLoc, TypeAliasLoc,
use crate::{
arena::map::ArenaMap,
ids::{FunctionLoc, Intern, ItemDefinitionId, ModuleId, PackageId, StructLoc, TypeAliasLoc},
item_scope::ItemScope,
item_tree::{
Function, ItemTree, ItemTreeId, LocalItemTreeId, ModItem, Struct, StructDefKind, TypeAlias,
},
module_tree::{LocalModuleId, ModuleTree},
visibility::RawVisibility,
DefDatabase, FileId, Name, PerNs, Visibility,
};
use crate::item_scope::ItemScope;
use crate::item_tree::{
Function, ItemTree, ItemTreeId, LocalItemTreeId, ModItem, Struct, StructDefKind, TypeAlias,
};
use crate::module_tree::{LocalModuleId, ModuleTree};
use crate::visibility::RawVisibility;
use crate::{DefDatabase, FileId, Name, PerNs, Visibility};
use std::sync::Arc;

pub(super) fn collect(db: &dyn DefDatabase, package_id: PackageId) -> PackageDefs {
Expand All @@ -23,21 +23,22 @@ pub(super) fn collect(db: &dyn DefDatabase, package_id: PackageId) -> PackageDef
collector.finish()
}

/// A helper struct to collect all definitions for all modules in a package.
struct DefCollector<'db> {
db: &'db dyn DefDatabase,
package_id: PackageId,
modules: ArenaMap<LocalModuleId, ItemScope>,
module_tree: Arc<ModuleTree>,
}

impl<'t> DefCollector<'t> {
impl<'db> DefCollector<'db> {
/// Collects all information and stores it in the instance
fn collect(&mut self) {
// Collect all definitions in each module
let module_tree = self.module_tree.clone();

fn collect_modules_recursive<'t>(
collector: &mut DefCollector<'t>,
fn collect_modules_recursive(
collector: &mut DefCollector,
module_id: LocalModuleId,
parent: Option<(Name, LocalModuleId)>,
) {
Expand All @@ -48,13 +49,14 @@ impl<'t> DefCollector<'t> {
let module_data = &collector.module_tree[module_id];
if let Some(file_id) = module_data.file {
let item_tree = collector.db.item_tree(file_id);
ModCollector {
let mut mod_collector = ModCollector {
def_collector: collector,
module_id,
file_id,
item_tree: &item_tree,
}
.collect(item_tree.top_level_items());
};

mod_collector.collect(item_tree.top_level_items());
}

// Insert this module into the scope of the parent
Expand Down

0 comments on commit 6747bbc

Please sign in to comment.