use VecSet for exposed_symbols

This commit is contained in:
Folkert 2022-04-17 20:23:29 +02:00
parent 39aa112fd5
commit 304b7fd569
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
4 changed files with 17 additions and 12 deletions

View File

@ -4,7 +4,7 @@ use crate::env::Env;
use crate::expr::{ClosureData, Expr, Recursive};
use crate::pattern::Pattern;
use crate::scope::Scope;
use roc_collections::all::{MutSet, SendMap};
use roc_collections::all::{SendMap, VecSet};
use roc_module::called_via::CalledVia;
use roc_module::ident::TagName;
use roc_module::symbol::Symbol;
@ -39,7 +39,7 @@ pub(crate) fn build_effect_builtins(
scope: &mut Scope,
effect_symbol: Symbol,
var_store: &mut VarStore,
exposed_symbols: &mut MutSet<Symbol>,
exposed_symbols: &mut VecSet<Symbol>,
declarations: &mut Vec<Declaration>,
generated_functions: HostedGeneratedFunctions,
) {

View File

@ -23,7 +23,7 @@ use roc_types::types::{Alias, AliasKind, Type};
pub struct Module {
pub module_id: ModuleId,
pub exposed_imports: MutMap<Symbol, Variable>,
pub exposed_symbols: MutSet<Symbol>,
pub exposed_symbols: VecSet<Symbol>,
pub referenced_values: VecSet<Symbol>,
pub referenced_types: VecSet<Symbol>,
/// all aliases. `bool` indicates whether it is exposed
@ -89,7 +89,7 @@ pub fn canonicalize_module_defs<'a>(
dep_idents: &'a MutMap<ModuleId, IdentIds>,
aliases: MutMap<Symbol, Alias>,
exposed_imports: MutMap<Ident, (Symbol, Region)>,
exposed_symbols: &MutSet<Symbol>,
exposed_symbols: &VecSet<Symbol>,
var_store: &mut VarStore,
) -> Result<ModuleOutput, RuntimeError> {
let mut can_exposed_imports = MutMap::default();
@ -319,7 +319,7 @@ pub fn canonicalize_module_defs<'a>(
generated_functions,
}) = hosted_info
{
let mut exposed_symbols = MutSet::default();
let mut exposed_symbols = VecSet::default();
// NOTE this currently builds all functions, not just the ones that the user requested
crate::effect_module::build_effect_builtins(

View File

@ -235,6 +235,12 @@ impl<T> Default for VecSet<T> {
}
impl<T: PartialEq> VecSet<T> {
pub fn with_capacity(capacity: usize) -> Self {
Self {
elements: Vec::with_capacity(capacity),
}
}
pub fn insert(&mut self, value: T) -> bool {
if self.elements.contains(&value) {
true

View File

@ -9,7 +9,7 @@ use roc_can::abilities::AbilitiesStore;
use roc_can::constraint::{Constraint as ConstraintSoa, Constraints};
use roc_can::def::Declaration;
use roc_can::module::{canonicalize_module_defs, Module};
use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet};
use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet, VecSet};
use roc_constrain::module::{
constrain_builtin_imports, constrain_module, ExposedByModule, ExposedForModule,
ExposedModuleTypes,
@ -40,7 +40,7 @@ use roc_types::solved_types::Solved;
use roc_types::subs::{Subs, VarStore, Variable};
use roc_types::types::{Alias, AliasCommon, TypeExtension};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{HashMap, HashSet};
use std::collections::{HashMap, };
use std::io;
use std::iter;
use std::ops::ControlFlow;
@ -605,7 +605,7 @@ struct State<'a> {
pub declarations_by_id: MutMap<ModuleId, Vec<Declaration>>,
pub exposed_symbols_by_module: MutMap<ModuleId, MutSet<Symbol>>,
pub exposed_symbols_by_module: MutMap<ModuleId, VecSet<Symbol>>,
pub timings: MutMap<ModuleId, ModuleTiming>,
@ -749,7 +749,7 @@ enum BuildTask<'a> {
parsed: ParsedModule<'a>,
module_ids: ModuleIds,
dep_idents: MutMap<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>,
exposed_symbols: VecSet<Symbol>,
aliases: MutMap<Symbol, Alias>,
},
Solve {
@ -1680,8 +1680,7 @@ fn update<'a>(
}
// This was a dependency. Write it down and keep processing messages.
let mut exposed_symbols: MutSet<Symbol> =
HashSet::with_capacity_and_hasher(header.exposes.len(), default_hasher());
let mut exposed_symbols: VecSet<Symbol> = VecSet::with_capacity(header.exposes.len());
// TODO can we avoid this loop by storing them as a Set in Header to begin with?
for symbol in header.exposes.iter() {
@ -3399,7 +3398,7 @@ fn canonicalize_and_constrain<'a>(
arena: &'a Bump,
module_ids: &ModuleIds,
dep_idents: MutMap<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>,
exposed_symbols: VecSet<Symbol>,
aliases: MutMap<Symbol, Alias>,
parsed: ParsedModule<'a>,
) -> Result<Msg<'a>, LoadingProblem<'a>> {