Only render exposed values

This commit is contained in:
Chadtech 2021-06-27 20:24:05 -04:00
parent 80a1ca698f
commit 38ef2a915a
5 changed files with 80 additions and 74 deletions

View File

@ -20,7 +20,7 @@ use roc_types::types::Alias;
pub struct Module {
pub module_id: ModuleId,
pub exposed_imports: MutMap<Symbol, Variable>,
pub exposed_symbols: MutSet<Symbol>,
pub exposed_symbols: Vec<Symbol>,
pub references: MutSet<Symbol>,
pub aliases: MutMap<Symbol, Alias>,
pub rigid_variables: MutMap<Variable, Lowercase>,
@ -50,7 +50,7 @@ pub fn canonicalize_module_defs<'a, F>(
dep_idents: MutMap<ModuleId, IdentIds>,
aliases: MutMap<Symbol, Alias>,
exposed_imports: MutMap<Ident, (Symbol, Region)>,
exposed_symbols: &MutSet<Symbol>,
exposed_symbols: &Vec<Symbol>,
var_store: &mut VarStore,
look_up_builtin: F,
) -> Result<ModuleOutput, RuntimeError>
@ -203,7 +203,11 @@ where
// we can see if there were any
// exposed symbols which did not have
// corresponding defs.
exposed_but_not_defined.remove(symbol);
if let Some(index) =
exposed_but_not_defined.iter().position(|s| *s == *symbol)
{
exposed_but_not_defined.remove(index);
}
}
}
}
@ -216,7 +220,11 @@ where
// we can see if there were any
// exposed symbols which did not have
// corresponding defs.
exposed_but_not_defined.remove(symbol);
if let Some(index) =
exposed_but_not_defined.iter().position(|s| *s == *symbol)
{
exposed_but_not_defined.remove(index);
}
}
}
}
@ -244,7 +252,9 @@ where
// we can see if there were any
// exposed symbols which did not have
// corresponding defs.
exposed_but_not_defined.remove(&symbol);
if let Some(index) = exposed_but_not_defined.iter().position(|s| *s == symbol) {
exposed_but_not_defined.remove(index);
}
aliases.insert(symbol, alias);
}

View File

@ -48,7 +48,7 @@ pub fn build_effect_builtins(
scope: &mut Scope,
effect_symbol: Symbol,
var_store: &mut VarStore,
exposed_symbols: &mut MutSet<Symbol>,
exposed_symbols: &mut Vec<Symbol>,
declarations: &mut Vec<Declaration>,
) {
for (_, f) in BUILTIN_EFFECT_FUNCTIONS.iter() {
@ -60,7 +60,7 @@ pub fn build_effect_builtins(
var_store,
);
exposed_symbols.insert(symbol);
exposed_symbols.push(symbol);
declarations.push(Declaration::Declare(def));
}
}

View File

@ -487,7 +487,9 @@ fn start_phase<'a>(
let exposed_symbols = state
.exposed_symbols_by_module
.remove(&module_id)
.expect("Could not find listener ID in exposed_symbols_by_module");
.expect("Could not find listener ID in exposed_symbols_by_module")
.into_iter()
.collect::<Vec<Symbol>>();
let mut aliases = MutMap::default();
@ -621,7 +623,7 @@ pub struct LoadedModule {
pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
pub declarations_by_id: MutMap<ModuleId, Vec<Declaration>>,
pub exposed_to_host: MutMap<Symbol, Variable>,
pub exposed_aliases: MutMap<Symbol, Alias>,
pub exposed_values: Vec<Symbol>,
pub header_sources: MutMap<ModuleId, (PathBuf, Box<str>)>,
pub sources: MutMap<ModuleId, (PathBuf, Box<str>)>,
pub timings: MutMap<ModuleId, ModuleTiming>,
@ -764,7 +766,7 @@ enum Msg<'a> {
FinishedAllTypeChecking {
solved_subs: Solved<Subs>,
exposed_vars_by_symbol: MutMap<Symbol, Variable>,
exposed_aliases_by_symbol: MutMap<Symbol, Alias>,
exposed_values: Vec<Symbol>,
documentation: MutMap<ModuleId, ModuleDocumentation>,
},
FoundSpecializations {
@ -972,7 +974,7 @@ enum BuildTask<'a> {
parsed: ParsedModule<'a>,
module_ids: ModuleIds,
dep_idents: MutMap<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>,
exposed_symbols: Vec<Symbol>,
aliases: MutMap<Symbol, Alias>,
},
Solve {
@ -1512,7 +1514,7 @@ where
Msg::FinishedAllTypeChecking {
solved_subs,
exposed_vars_by_symbol,
exposed_aliases_by_symbol,
exposed_values,
documentation,
} => {
// We're done! There should be no more messages pending.
@ -1528,7 +1530,7 @@ where
return Ok(LoadResult::TypeChecked(finish(
state,
solved_subs,
exposed_aliases_by_symbol,
exposed_values,
exposed_vars_by_symbol,
documentation,
)));
@ -1943,7 +1945,7 @@ fn update<'a>(
.send(Msg::FinishedAllTypeChecking {
solved_subs,
exposed_vars_by_symbol: solved_module.exposed_vars_by_symbol,
exposed_aliases_by_symbol: solved_module.aliases,
exposed_values: solved_module.exposed_symbols,
documentation,
})
.map_err(|_| LoadingProblem::MsgChannelDied)?;
@ -2268,7 +2270,7 @@ fn finish_specialization(
fn finish(
state: State,
solved: Solved<Subs>,
exposed_aliases_by_symbol: MutMap<Symbol, Alias>,
exposed_values: Vec<Symbol>,
exposed_vars_by_symbol: MutMap<Symbol, Variable>,
documentation: MutMap<ModuleId, ModuleDocumentation>,
) -> LoadedModule {
@ -2303,8 +2305,8 @@ fn finish(
can_problems: state.module_cache.can_problems,
type_problems: state.module_cache.type_problems,
declarations_by_id: state.declarations_by_id,
exposed_values,
exposed_to_host: exposed_vars_by_symbol.into_iter().collect(),
exposed_aliases: exposed_aliases_by_symbol,
header_sources,
sources,
timings: state.timings,
@ -3297,6 +3299,7 @@ fn run_solve<'a>(
let solved_module = SolvedModule {
exposed_vars_by_symbol,
exposed_symbols: exposed_symbols.into_iter().collect::<Vec<_>>(),
solved_types,
problems,
aliases: solved_env.aliases,
@ -3500,8 +3503,8 @@ fn fabricate_effects_module<'a>(
let mut declarations = Vec::new();
let exposed_symbols: MutSet<Symbol> = {
let mut exposed_symbols = MutSet::default();
let exposed_symbols: Vec<Symbol> = {
let mut exposed_symbols = Vec::new();
{
for (ident, ann) in effect_entries {
@ -3534,7 +3537,7 @@ fn fabricate_effects_module<'a>(
annotation,
);
exposed_symbols.insert(symbol);
exposed_symbols.push(symbol);
declarations.push(Declaration::Declare(def));
}
@ -3648,7 +3651,7 @@ fn canonicalize_and_constrain<'a, F>(
arena: &'a Bump,
module_ids: &ModuleIds,
dep_idents: MutMap<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>,
exposed_symbols: Vec<Symbol>,
aliases: MutMap<Symbol, Alias>,
parsed: ParsedModule<'a>,
look_up_builtins: F,

View File

@ -11,6 +11,7 @@ use roc_types::types::Alias;
pub struct SolvedModule {
pub solved_types: MutMap<Symbol, SolvedType>,
pub aliases: MutMap<Symbol, Alias>,
pub exposed_symbols: Vec<Symbol>,
pub exposed_vars_by_symbol: MutMap<Symbol, Variable>,
pub problems: Vec<solve::TypeError>,
}

View File

@ -63,23 +63,12 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
// Write each package's module docs html file
for loaded_module in package.modules.iter_mut() {
let mut exposed_values = loaded_module
.exposed_to_host
let exports = loaded_module
.exposed_values
.iter()
.map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string())
.map(|symbol| symbol.ident_string(&loaded_module.interns).to_string())
.collect::<Vec<String>>();
let mut exposed_aliases = loaded_module
.exposed_aliases
.iter()
.map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string())
.collect::<Vec<String>>();
let mut exports = Vec::new();
exports.append(&mut exposed_values);
exports.append(&mut exposed_aliases);
for module in loaded_module.documentation.values_mut() {
let module_dir = build_dir.join(module.name.replace(".", "/").as_str());
@ -122,61 +111,64 @@ fn render_main_content(
);
for entry in &module.entries {
let mut should_render_entry = true;
if let DocDef(def) = entry {
if !exposed_values.contains(&def.name) {
break;
}
// We dont want to render entries that arent exposed
should_render_entry = exposed_values.contains(&def.name);
}
match entry {
DocEntry::DocDef(doc_def) => {
let mut href = String::new();
href.push('#');
href.push_str(doc_def.name.as_str());
if should_render_entry {
match entry {
DocEntry::DocDef(doc_def) => {
let mut href = String::new();
href.push('#');
href.push_str(doc_def.name.as_str());
let name = doc_def.name.as_str();
let name = doc_def.name.as_str();
let mut content = String::new();
let mut content = String::new();
content.push_str(html_node("a", vec![("href", href.as_str())], name).as_str());
content.push_str(html_node("a", vec![("href", href.as_str())], name).as_str());
for type_var in &doc_def.type_vars {
content.push(' ');
content.push_str(type_var.as_str());
}
for type_var in &doc_def.type_vars {
content.push(' ');
content.push_str(type_var.as_str());
}
let type_ann = &doc_def.type_annotation;
let type_ann = &doc_def.type_annotation;
match type_ann {
TypeAnnotation::NoTypeAnn => {}
_ => {
content.push_str(" : ");
match type_ann {
TypeAnnotation::NoTypeAnn => {}
_ => {
content.push_str(" : ");
}
}
type_annotation_to_html(0, &mut content, &type_ann);
buf.push_str(
html_node(
"h3",
vec![("id", name), ("class", "entry-name")],
content.as_str(),
)
.as_str(),
);
if let Some(docs) = &doc_def.docs {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
}
type_annotation_to_html(0, &mut content, &type_ann);
buf.push_str(
html_node(
"h3",
vec![("id", name), ("class", "entry-name")],
content.as_str(),
)
.as_str(),
);
if let Some(docs) = &doc_def.docs {
DocEntry::DetachedDoc(docs) => {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
}
DocEntry::DetachedDoc(docs) => {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
};
};
}
}
buf