diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 345bb0853e..2b45a14f32 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -20,7 +20,7 @@ use roc_types::types::Alias; pub struct Module { pub module_id: ModuleId, pub exposed_imports: MutMap, - pub exposed_symbols: MutSet, + pub exposed_symbols: Vec, pub references: MutSet, pub aliases: MutMap, pub rigid_variables: MutMap, @@ -50,7 +50,7 @@ pub fn canonicalize_module_defs<'a, F>( dep_idents: MutMap, aliases: MutMap, exposed_imports: MutMap, - exposed_symbols: &MutSet, + exposed_symbols: &Vec, var_store: &mut VarStore, look_up_builtin: F, ) -> Result @@ -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); } diff --git a/compiler/load/src/effect_module.rs b/compiler/load/src/effect_module.rs index 5dab90a4f8..81be7ecf60 100644 --- a/compiler/load/src/effect_module.rs +++ b/compiler/load/src/effect_module.rs @@ -48,7 +48,7 @@ pub fn build_effect_builtins( scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, - exposed_symbols: &mut MutSet, + exposed_symbols: &mut Vec, declarations: &mut Vec, ) { 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)); } } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index e306b7cbd7..8e9533102f 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -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::>(); let mut aliases = MutMap::default(); @@ -621,7 +623,7 @@ pub struct LoadedModule { pub type_problems: MutMap>, pub declarations_by_id: MutMap>, pub exposed_to_host: MutMap, - pub exposed_aliases: MutMap, + pub exposed_values: Vec, pub header_sources: MutMap)>, pub sources: MutMap)>, pub timings: MutMap, @@ -764,7 +766,7 @@ enum Msg<'a> { FinishedAllTypeChecking { solved_subs: Solved, exposed_vars_by_symbol: MutMap, - exposed_aliases_by_symbol: MutMap, + exposed_values: Vec, documentation: MutMap, }, FoundSpecializations { @@ -972,7 +974,7 @@ enum BuildTask<'a> { parsed: ParsedModule<'a>, module_ids: ModuleIds, dep_idents: MutMap, - exposed_symbols: MutSet, + exposed_symbols: Vec, aliases: MutMap, }, 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, - exposed_aliases_by_symbol: MutMap, + exposed_values: Vec, exposed_vars_by_symbol: MutMap, documentation: MutMap, ) -> 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::>(), 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 = { - let mut exposed_symbols = MutSet::default(); + let exposed_symbols: Vec = { + 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, - exposed_symbols: MutSet, + exposed_symbols: Vec, aliases: MutMap, parsed: ParsedModule<'a>, look_up_builtins: F, diff --git a/compiler/solve/src/module.rs b/compiler/solve/src/module.rs index f888e2208e..f921b20709 100644 --- a/compiler/solve/src/module.rs +++ b/compiler/solve/src/module.rs @@ -11,6 +11,7 @@ use roc_types::types::Alias; pub struct SolvedModule { pub solved_types: MutMap, pub aliases: MutMap, + pub exposed_symbols: Vec, pub exposed_vars_by_symbol: MutMap, pub problems: Vec, } diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 05cb4aba02..7973bd23dd 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -63,23 +63,12 @@ pub fn generate(filenames: Vec, 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::>(); - let mut exposed_aliases = loaded_module - .exposed_aliases - .iter() - .map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string()) - .collect::>(); - - 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