mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Support generating docs for packages too
This commit is contained in:
parent
e5a0509380
commit
d8d517d6f9
2 changed files with 41 additions and 18 deletions
|
@ -376,12 +376,6 @@ fn start_phase<'a>(
|
||||||
state.cached_types.lock().contains_key(&module_id)
|
state.cached_types.lock().contains_key(&module_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let exposed_module_ids = state
|
|
||||||
.platform_data
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| data.exposed_modules)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
BuildTask::CanonicalizeAndConstrain {
|
BuildTask::CanonicalizeAndConstrain {
|
||||||
parsed,
|
parsed,
|
||||||
dep_idents,
|
dep_idents,
|
||||||
|
@ -390,7 +384,7 @@ fn start_phase<'a>(
|
||||||
aliases,
|
aliases,
|
||||||
abilities_store,
|
abilities_store,
|
||||||
skip_constraint_gen,
|
skip_constraint_gen,
|
||||||
exposed_module_ids,
|
exposed_module_ids: state.exposed_modules,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +925,6 @@ struct PlatformData<'a> {
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
provides: &'a [(Loc<ExposedName<'a>>, Loc<TypedIdent<'a>>)],
|
provides: &'a [(Loc<ExposedName<'a>>, Loc<TypedIdent<'a>>)],
|
||||||
is_prebuilt: bool,
|
is_prebuilt: bool,
|
||||||
exposed_modules: &'a [ModuleId],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -971,6 +964,10 @@ struct State<'a> {
|
||||||
pub platform_path: PlatformPath<'a>,
|
pub platform_path: PlatformPath<'a>,
|
||||||
pub target_info: TargetInfo,
|
pub target_info: TargetInfo,
|
||||||
|
|
||||||
|
/// Note: only packages and platforms actually expose any modules;
|
||||||
|
/// for all others, this will be empty.
|
||||||
|
pub exposed_modules: &'a [ModuleId],
|
||||||
|
|
||||||
pub module_cache: ModuleCache<'a>,
|
pub module_cache: ModuleCache<'a>,
|
||||||
pub dependencies: Dependencies<'a>,
|
pub dependencies: Dependencies<'a>,
|
||||||
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
|
@ -1055,6 +1052,7 @@ impl<'a> State<'a> {
|
||||||
procedures: MutMap::default(),
|
procedures: MutMap::default(),
|
||||||
toplevel_expects: ToplevelExpects::default(),
|
toplevel_expects: ToplevelExpects::default(),
|
||||||
exposed_to_host: ExposedToHost::default(),
|
exposed_to_host: ExposedToHost::default(),
|
||||||
|
exposed_modules: &[],
|
||||||
exposed_types,
|
exposed_types,
|
||||||
arc_modules,
|
arc_modules,
|
||||||
arc_shorthands,
|
arc_shorthands,
|
||||||
|
@ -2445,8 +2443,14 @@ fn update<'a>(
|
||||||
state.platform_path = PlatformPath::Valid(to_platform);
|
state.platform_path = PlatformPath::Valid(to_platform);
|
||||||
}
|
}
|
||||||
Package {
|
Package {
|
||||||
config_shorthand, ..
|
config_shorthand,
|
||||||
|
exposes_ids,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
|
if header.is_root_module {
|
||||||
|
state.exposed_modules = exposes_ids;
|
||||||
|
}
|
||||||
|
|
||||||
work.extend(state.dependencies.notify_package(config_shorthand));
|
work.extend(state.dependencies.notify_package(config_shorthand));
|
||||||
}
|
}
|
||||||
Platform {
|
Platform {
|
||||||
|
@ -2484,9 +2488,12 @@ fn update<'a>(
|
||||||
module_id: header.module_id,
|
module_id: header.module_id,
|
||||||
provides,
|
provides,
|
||||||
is_prebuilt,
|
is_prebuilt,
|
||||||
exposed_modules: exposes_ids,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if header.is_root_module {
|
||||||
|
state.exposed_modules = exposes_ids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Builtin { .. } | Interface { .. } => {
|
Builtin { .. } | Interface { .. } => {
|
||||||
if header.is_root_module {
|
if header.is_root_module {
|
||||||
|
@ -3521,8 +3528,12 @@ fn load_package_from_disk<'a>(
|
||||||
},
|
},
|
||||||
parser_state,
|
parser_state,
|
||||||
)) => {
|
)) => {
|
||||||
let exposes_ids =
|
let exposes_ids = get_exposes_ids(
|
||||||
get_exposes_ids(&header, arena, &module_ids, &ident_ids_by_module);
|
&header.exposes.item.items,
|
||||||
|
arena,
|
||||||
|
&module_ids,
|
||||||
|
&ident_ids_by_module,
|
||||||
|
);
|
||||||
|
|
||||||
// make a `platform` module that ultimately exposes `main` to the host
|
// make a `platform` module that ultimately exposes `main` to the host
|
||||||
let (_, _, platform_module_msg) = build_platform_header(
|
let (_, _, platform_module_msg) = build_platform_header(
|
||||||
|
@ -3555,20 +3566,19 @@ fn load_package_from_disk<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exposes_ids<'a>(
|
fn get_exposes_ids<'a>(
|
||||||
header: &PlatformHeader<'a>,
|
entries: &'a [Loc<Spaced<'a, roc_parse::header::ModuleName<'a>>>],
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
module_ids: &Arc<Mutex<PackageModuleIds<'a>>>,
|
module_ids: &Arc<Mutex<PackageModuleIds<'a>>>,
|
||||||
ident_ids_by_module: &Arc<Mutex<IdentIdsByModule>>,
|
ident_ids_by_module: &Arc<Mutex<IdentIdsByModule>>,
|
||||||
) -> bumpalo::collections::Vec<'a, ModuleId> {
|
) -> bumpalo::collections::Vec<'a, ModuleId> {
|
||||||
let mut exposes_ids =
|
let mut exposes_ids = bumpalo::collections::Vec::with_capacity_in(entries.len(), arena);
|
||||||
bumpalo::collections::Vec::with_capacity_in(header.exposes.item.items.len(), arena);
|
|
||||||
{
|
{
|
||||||
// Lock just long enough to perform the minimal operations necessary.
|
// Lock just long enough to perform the minimal operations necessary.
|
||||||
let mut module_ids = (**module_ids).lock();
|
let mut module_ids = (**module_ids).lock();
|
||||||
let mut ident_ids_by_module = (**ident_ids_by_module).lock();
|
let mut ident_ids_by_module = (**ident_ids_by_module).lock();
|
||||||
|
|
||||||
// TODO can we "iterate unspaced" instead of calling unspace here?
|
// TODO can we "iterate unspaced" instead of calling unspace here?
|
||||||
for entry in unspace(arena, header.exposes.item.items) {
|
for entry in unspace(arena, entries) {
|
||||||
let module_id =
|
let module_id =
|
||||||
module_ids.get_or_insert(&PQModuleName::Unqualified(entry.value.as_str().into()));
|
module_ids.get_or_insert(&PQModuleName::Unqualified(entry.value.as_str().into()));
|
||||||
|
|
||||||
|
@ -4111,7 +4121,12 @@ fn parse_header<'a>(
|
||||||
},
|
},
|
||||||
parse_state,
|
parse_state,
|
||||||
)) => {
|
)) => {
|
||||||
let exposes_ids = get_exposes_ids(&header, arena, &module_ids, &ident_ids_by_module);
|
let exposes_ids = get_exposes_ids(
|
||||||
|
&header.exposes.item.items,
|
||||||
|
arena,
|
||||||
|
&module_ids,
|
||||||
|
&ident_ids_by_module,
|
||||||
|
);
|
||||||
|
|
||||||
let (module_id, _, header) = build_platform_header(
|
let (module_id, _, header) = build_platform_header(
|
||||||
arena,
|
arena,
|
||||||
|
@ -5120,10 +5135,17 @@ fn build_package_header<'a>(
|
||||||
arena,
|
arena,
|
||||||
);
|
);
|
||||||
let packages = unspace(arena, header.packages.item.items);
|
let packages = unspace(arena, header.packages.item.items);
|
||||||
|
let exposes_ids = get_exposes_ids(
|
||||||
|
&header.exposes.item.items,
|
||||||
|
arena,
|
||||||
|
&module_ids,
|
||||||
|
&ident_ids_by_module,
|
||||||
|
);
|
||||||
let header_type = HeaderType::Package {
|
let header_type = HeaderType::Package {
|
||||||
// A config_shorthand of "" should be fine
|
// A config_shorthand of "" should be fine
|
||||||
config_shorthand: opt_shorthand.unwrap_or_default(),
|
config_shorthand: opt_shorthand.unwrap_or_default(),
|
||||||
exposes: exposes.into_bump_slice(),
|
exposes: exposes.into_bump_slice(),
|
||||||
|
exposes_ids: exposes_ids.into_bump_slice(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let info = HeaderInfo {
|
let info = HeaderInfo {
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub enum HeaderType<'a> {
|
||||||
/// usually something other than `pf`
|
/// usually something other than `pf`
|
||||||
config_shorthand: &'a str,
|
config_shorthand: &'a str,
|
||||||
exposes: &'a [Loc<ModuleName<'a>>],
|
exposes: &'a [Loc<ModuleName<'a>>],
|
||||||
|
exposes_ids: &'a [ModuleId],
|
||||||
},
|
},
|
||||||
Platform {
|
Platform {
|
||||||
opt_app_module_id: Option<ModuleId>,
|
opt_app_module_id: Option<ModuleId>,
|
||||||
|
@ -54,7 +55,7 @@ pub enum HeaderType<'a> {
|
||||||
requires: &'a [Loc<TypedIdent<'a>>],
|
requires: &'a [Loc<TypedIdent<'a>>],
|
||||||
requires_types: &'a [Loc<UppercaseIdent<'a>>],
|
requires_types: &'a [Loc<UppercaseIdent<'a>>],
|
||||||
exposes: &'a [Loc<ModuleName<'a>>],
|
exposes: &'a [Loc<ModuleName<'a>>],
|
||||||
exposes_ids: &'a [roc_module::symbol::ModuleId],
|
exposes_ids: &'a [ModuleId],
|
||||||
|
|
||||||
/// usually `pf`
|
/// usually `pf`
|
||||||
config_shorthand: &'a str,
|
config_shorthand: &'a str,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue