mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge pull request #604 from rtfeldman/merge-docs-into-load-file
Merge docs into load file
This commit is contained in:
commit
c982f968c2
5 changed files with 53 additions and 1553 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -614,6 +614,7 @@ dependencies = [
|
||||||
name = "docs"
|
name = "docs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
"handlebars",
|
"handlebars",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::docs::ModuleDocumentation;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use crossbeam::channel::{bounded, Sender};
|
use crossbeam::channel::{bounded, Sender};
|
||||||
use crossbeam::deque::{Injector, Stealer, Worker};
|
use crossbeam::deque::{Injector, Stealer, Worker};
|
||||||
|
@ -202,6 +203,7 @@ struct ModuleCache<'a> {
|
||||||
typechecked: MutMap<ModuleId, TypeCheckedModule<'a>>,
|
typechecked: MutMap<ModuleId, TypeCheckedModule<'a>>,
|
||||||
found_specializations: MutMap<ModuleId, FoundSpecializationsModule<'a>>,
|
found_specializations: MutMap<ModuleId, FoundSpecializationsModule<'a>>,
|
||||||
external_specializations_requested: MutMap<ModuleId, ExternalSpecializations>,
|
external_specializations_requested: MutMap<ModuleId, ExternalSpecializations>,
|
||||||
|
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) -> BuildTask<'a> {
|
fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) -> BuildTask<'a> {
|
||||||
|
@ -378,6 +380,7 @@ pub struct LoadedModule {
|
||||||
pub exposed_to_host: MutMap<Symbol, Variable>,
|
pub exposed_to_host: MutMap<Symbol, Variable>,
|
||||||
pub src: Box<str>,
|
pub src: Box<str>,
|
||||||
pub timings: MutMap<ModuleId, ModuleTiming>,
|
pub timings: MutMap<ModuleId, ModuleTiming>,
|
||||||
|
pub documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -458,6 +461,7 @@ enum Msg<'a> {
|
||||||
problems: Vec<roc_problem::can::Problem>,
|
problems: Vec<roc_problem::can::Problem>,
|
||||||
var_store: VarStore,
|
var_store: VarStore,
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
|
module_docs: ModuleDocumentation,
|
||||||
},
|
},
|
||||||
SolvedTypes {
|
SolvedTypes {
|
||||||
src: &'a str,
|
src: &'a str,
|
||||||
|
@ -471,6 +475,7 @@ enum Msg<'a> {
|
||||||
FinishedAllTypeChecking {
|
FinishedAllTypeChecking {
|
||||||
solved_subs: Solved<Subs>,
|
solved_subs: Solved<Subs>,
|
||||||
exposed_vars_by_symbol: Vec<(Symbol, Variable)>,
|
exposed_vars_by_symbol: Vec<(Symbol, Variable)>,
|
||||||
|
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||||
src: &'a str,
|
src: &'a str,
|
||||||
},
|
},
|
||||||
FoundSpecializations {
|
FoundSpecializations {
|
||||||
|
@ -1096,6 +1101,7 @@ where
|
||||||
Msg::FinishedAllTypeChecking {
|
Msg::FinishedAllTypeChecking {
|
||||||
solved_subs,
|
solved_subs,
|
||||||
exposed_vars_by_symbol,
|
exposed_vars_by_symbol,
|
||||||
|
documentation,
|
||||||
src,
|
src,
|
||||||
} => {
|
} => {
|
||||||
// We're done! There should be no more messages pending.
|
// We're done! There should be no more messages pending.
|
||||||
|
@ -1112,6 +1118,7 @@ where
|
||||||
state,
|
state,
|
||||||
solved_subs,
|
solved_subs,
|
||||||
exposed_vars_by_symbol,
|
exposed_vars_by_symbol,
|
||||||
|
documentation,
|
||||||
src,
|
src,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
@ -1228,11 +1235,17 @@ fn update<'a>(
|
||||||
problems,
|
problems,
|
||||||
var_store,
|
var_store,
|
||||||
module_timing,
|
module_timing,
|
||||||
|
module_docs,
|
||||||
} => {
|
} => {
|
||||||
log!("generated constraints for {:?}", module.module_id);
|
log!("generated constraints for {:?}", module.module_id);
|
||||||
let module_id = module.module_id;
|
let module_id = module.module_id;
|
||||||
state.can_problems.extend(problems);
|
state.can_problems.extend(problems);
|
||||||
|
|
||||||
|
state
|
||||||
|
.module_cache
|
||||||
|
.documentation
|
||||||
|
.insert(module_id, module_docs);
|
||||||
|
|
||||||
let constrained_module = ConstrainedModule {
|
let constrained_module = ConstrainedModule {
|
||||||
module,
|
module,
|
||||||
constraint,
|
constraint,
|
||||||
|
@ -1243,6 +1256,7 @@ fn update<'a>(
|
||||||
var_store,
|
var_store,
|
||||||
imported_modules,
|
imported_modules,
|
||||||
};
|
};
|
||||||
|
|
||||||
state
|
state
|
||||||
.module_cache
|
.module_cache
|
||||||
.constrained
|
.constrained
|
||||||
|
@ -1288,10 +1302,18 @@ fn update<'a>(
|
||||||
|
|
||||||
state.timings.insert(module_id, module_timing);
|
state.timings.insert(module_id, module_timing);
|
||||||
|
|
||||||
|
let documentation = {
|
||||||
|
let mut empty = MutMap::default();
|
||||||
|
std::mem::swap(&mut empty, &mut state.module_cache.documentation);
|
||||||
|
|
||||||
|
empty
|
||||||
|
};
|
||||||
|
|
||||||
msg_tx
|
msg_tx
|
||||||
.send(Msg::FinishedAllTypeChecking {
|
.send(Msg::FinishedAllTypeChecking {
|
||||||
solved_subs,
|
solved_subs,
|
||||||
exposed_vars_by_symbol: solved_module.exposed_vars_by_symbol,
|
exposed_vars_by_symbol: solved_module.exposed_vars_by_symbol,
|
||||||
|
documentation,
|
||||||
src,
|
src,
|
||||||
})
|
})
|
||||||
.map_err(|_| LoadingProblem::MsgChannelDied)?;
|
.map_err(|_| LoadingProblem::MsgChannelDied)?;
|
||||||
|
@ -1514,6 +1536,7 @@ fn finish<'a>(
|
||||||
state: State<'a>,
|
state: State<'a>,
|
||||||
solved: Solved<Subs>,
|
solved: Solved<Subs>,
|
||||||
exposed_vars_by_symbol: Vec<(Symbol, Variable)>,
|
exposed_vars_by_symbol: Vec<(Symbol, Variable)>,
|
||||||
|
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||||
src: &'a str,
|
src: &'a str,
|
||||||
) -> LoadedModule {
|
) -> LoadedModule {
|
||||||
let module_ids = Arc::try_unwrap(state.arc_modules)
|
let module_ids = Arc::try_unwrap(state.arc_modules)
|
||||||
|
@ -1535,6 +1558,7 @@ fn finish<'a>(
|
||||||
exposed_to_host: exposed_vars_by_symbol.into_iter().collect(),
|
exposed_to_host: exposed_vars_by_symbol.into_iter().collect(),
|
||||||
src: src.into(),
|
src: src.into(),
|
||||||
timings: state.timings,
|
timings: state.timings,
|
||||||
|
documentation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,6 +2018,15 @@ fn parse_and_constrain<'a>(
|
||||||
// immediately afterward (for the beginning of canonicalization).
|
// immediately afterward (for the beginning of canonicalization).
|
||||||
let parse_end = SystemTime::now();
|
let parse_end = SystemTime::now();
|
||||||
let module_id = header.module_id;
|
let module_id = header.module_id;
|
||||||
|
|
||||||
|
// Generate documentation information
|
||||||
|
// TODO: store timing information?
|
||||||
|
let module_docs = crate::docs::generate_module_docs(
|
||||||
|
header.module_name,
|
||||||
|
&header.exposed_ident_ids,
|
||||||
|
&parsed_defs,
|
||||||
|
);
|
||||||
|
|
||||||
let mut var_store = VarStore::default();
|
let mut var_store = VarStore::default();
|
||||||
let canonicalized = canonicalize_module_defs(
|
let canonicalized = canonicalize_module_defs(
|
||||||
&arena,
|
&arena,
|
||||||
|
@ -2070,6 +2103,7 @@ fn parse_and_constrain<'a>(
|
||||||
problems,
|
problems,
|
||||||
var_store,
|
var_store,
|
||||||
module_timing,
|
module_timing,
|
||||||
|
module_docs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ pulldown-cmark = { version = "0.8", default-features = false }
|
||||||
roc_load = { path = "../compiler/load" }
|
roc_load = { path = "../compiler/load" }
|
||||||
roc_builtins = { path = "../compiler/builtins" }
|
roc_builtins = { path = "../compiler/builtins" }
|
||||||
roc_collections = { path = "../compiler/collections" }
|
roc_collections = { path = "../compiler/collections" }
|
||||||
|
bumpalo = { version = "3.2", features = ["collections"] }
|
||||||
|
|
|
@ -8,6 +8,7 @@ extern crate serde_json;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
extern crate roc_load;
|
extern crate roc_load;
|
||||||
|
use bumpalo::Bump;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ pub struct TemplateLinkEntry {
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let std_lib = roc_builtins::std::standard_stdlib();
|
let std_lib = roc_builtins::std::standard_stdlib();
|
||||||
let subs_by_module = MutMap::default();
|
let subs_by_module = MutMap::default();
|
||||||
|
let arena = Bump::new();
|
||||||
|
|
||||||
let src_dir = Path::new("../compiler/builtins/docs");
|
let src_dir = Path::new("../compiler/builtins/docs");
|
||||||
let files = vec![
|
let files = vec![
|
||||||
PathBuf::from(r"../compiler/builtins/docs/Bool.roc"),
|
PathBuf::from(r"../compiler/builtins/docs/Bool.roc"),
|
||||||
|
@ -59,9 +62,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
// Load each file is files vector
|
// Load each file is files vector
|
||||||
for filename in files {
|
for filename in files {
|
||||||
let loaded = roc_load::docs::load(filename, &std_lib, src_dir, subs_by_module.clone())
|
let mut loaded = roc_load::file::load_and_typecheck(
|
||||||
.expect("TODO gracefully handle load failing");
|
&arena,
|
||||||
modules_docs.push(loaded.module_docs);
|
filename,
|
||||||
|
std_lib.clone(),
|
||||||
|
src_dir,
|
||||||
|
subs_by_module.clone(),
|
||||||
|
)
|
||||||
|
.expect("TODO gracefully handle load failing");
|
||||||
|
modules_docs.extend(loaded.documentation.drain().map(|x| x.1));
|
||||||
}
|
}
|
||||||
|
|
||||||
let package = roc_load::docs::Documentation {
|
let package = roc_load::docs::Documentation {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue