mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
Merge branch 'trunk' into morphic-static-strings
This commit is contained in:
commit
d7d85e3862
9 changed files with 193 additions and 71 deletions
|
@ -36,6 +36,7 @@ pub struct ModuleOutput {
|
|||
pub problems: Vec<Problem>,
|
||||
pub ident_ids: IdentIds,
|
||||
pub references: MutSet<Symbol>,
|
||||
pub scope: Scope,
|
||||
}
|
||||
|
||||
// TODO trim these down
|
||||
|
@ -309,6 +310,7 @@ where
|
|||
}
|
||||
|
||||
Ok(ModuleOutput {
|
||||
scope,
|
||||
aliases,
|
||||
rigid_variables,
|
||||
declarations,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use roc_collections::all::{ImMap, MutSet};
|
||||
use roc_collections::all::{MutSet, SendMap};
|
||||
use roc_module::ident::{Ident, Lowercase};
|
||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||
use roc_problem::can::RuntimeError;
|
||||
|
@ -10,14 +10,14 @@ use roc_types::types::{Alias, Type};
|
|||
pub struct Scope {
|
||||
/// All the identifiers in scope, mapped to were they were defined and
|
||||
/// the Symbol they resolve to.
|
||||
idents: ImMap<Ident, (Symbol, Region)>,
|
||||
idents: SendMap<Ident, (Symbol, Region)>,
|
||||
|
||||
/// A cache of all the symbols in scope. This makes lookups much
|
||||
/// faster when checking for unused defs and unused arguments.
|
||||
symbols: ImMap<Symbol, Region>,
|
||||
symbols: SendMap<Symbol, Region>,
|
||||
|
||||
/// The type aliases currently in scope
|
||||
aliases: ImMap<Symbol, Alias>,
|
||||
aliases: SendMap<Symbol, Alias>,
|
||||
|
||||
/// The current module being processed. This will be used to turn
|
||||
/// unqualified idents into Symbols.
|
||||
|
@ -28,7 +28,7 @@ impl Scope {
|
|||
pub fn new(home: ModuleId, var_store: &mut VarStore) -> Scope {
|
||||
use roc_types::solved_types::{BuiltinAlias, FreeVars};
|
||||
let solved_aliases = roc_types::builtin_aliases::aliases();
|
||||
let mut aliases = ImMap::default();
|
||||
let mut aliases = SendMap::default();
|
||||
|
||||
for (symbol, builtin_alias) in solved_aliases {
|
||||
let BuiltinAlias { region, vars, typ } = builtin_alias;
|
||||
|
@ -58,7 +58,7 @@ impl Scope {
|
|||
Scope {
|
||||
home,
|
||||
idents: Symbol::default_in_scope(),
|
||||
symbols: ImMap::default(),
|
||||
symbols: SendMap::default(),
|
||||
aliases,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expr::constrain_decls;
|
||||
use roc_builtins::std::StdLib;
|
||||
use roc_can::constraint::{Constraint, LetConstraint};
|
||||
use roc_can::module::ModuleOutput;
|
||||
use roc_can::def::Declaration;
|
||||
use roc_collections::all::{MutMap, MutSet, SendMap};
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::{Located, Region};
|
||||
|
@ -22,16 +22,18 @@ pub struct ConstrainedModule {
|
|||
pub constraint: Constraint,
|
||||
}
|
||||
|
||||
pub fn constrain_module(module: &ModuleOutput, home: ModuleId) -> Constraint {
|
||||
pub fn constrain_module(
|
||||
aliases: &MutMap<Symbol, Alias>,
|
||||
declarations: &[Declaration],
|
||||
home: ModuleId,
|
||||
) -> Constraint {
|
||||
let mut send_aliases = SendMap::default();
|
||||
|
||||
for (symbol, alias) in module.aliases.iter() {
|
||||
for (symbol, alias) in aliases.iter() {
|
||||
send_aliases.insert(*symbol, alias.clone());
|
||||
}
|
||||
|
||||
let decls = &module.declarations;
|
||||
|
||||
constrain_decls(home, decls)
|
||||
constrain_decls(home, declarations)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use crate::docs::DocEntry::DetatchedDoc;
|
||||
use crate::docs::TypeAnnotation::{Apply, BoundVariable, Record, TagUnion};
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_can::scope::Scope;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_module::ident::ModuleName;
|
||||
use roc_module::symbol::IdentIds;
|
||||
use roc_module::symbol::{IdentIds, Interns, ModuleId};
|
||||
use roc_parse::ast;
|
||||
use roc_parse::ast::CommentOrNewline;
|
||||
use roc_parse::ast::{AssignedField, Def};
|
||||
|
@ -10,18 +12,19 @@ use roc_region::all::Located;
|
|||
|
||||
// Documentation generation requirements
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct Documentation {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub docs: String,
|
||||
pub modules: Vec<ModuleDocumentation>,
|
||||
pub modules: Vec<(MutMap<ModuleId, ModuleDocumentation>, Interns)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct ModuleDocumentation {
|
||||
pub name: String,
|
||||
pub entries: Vec<DocEntry>,
|
||||
pub scope: Scope,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -75,19 +78,21 @@ pub struct Tag {
|
|||
}
|
||||
|
||||
pub fn generate_module_docs<'a>(
|
||||
scope: Scope,
|
||||
module_name: ModuleName,
|
||||
exposed_ident_ids: &'a IdentIds,
|
||||
ident_ids: &'a IdentIds,
|
||||
parsed_defs: &'a [Located<ast::Def<'a>>],
|
||||
) -> ModuleDocumentation {
|
||||
let (entries, _) =
|
||||
parsed_defs
|
||||
.iter()
|
||||
.fold((vec![], None), |(acc, maybe_comments_after), def| {
|
||||
generate_entry_doc(exposed_ident_ids, acc, maybe_comments_after, &def.value)
|
||||
generate_entry_doc(ident_ids, acc, maybe_comments_after, &def.value)
|
||||
});
|
||||
|
||||
ModuleDocumentation {
|
||||
name: module_name.as_str().to_string(),
|
||||
scope,
|
||||
entries,
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +122,7 @@ fn detatched_docs_from_comments_and_new_lines<'a>(
|
|||
}
|
||||
|
||||
fn generate_entry_doc<'a>(
|
||||
exposed_ident_ids: &'a IdentIds,
|
||||
ident_ids: &'a IdentIds,
|
||||
mut acc: Vec<DocEntry>,
|
||||
before_comments_or_new_lines: Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
||||
def: &'a ast::Def<'a>,
|
||||
|
@ -135,13 +140,13 @@ fn generate_entry_doc<'a>(
|
|||
acc.push(DetatchedDoc(detatched_doc));
|
||||
}
|
||||
|
||||
generate_entry_doc(exposed_ident_ids, acc, Some(comments_or_new_lines), sub_def)
|
||||
generate_entry_doc(ident_ids, acc, Some(comments_or_new_lines), sub_def)
|
||||
}
|
||||
|
||||
Def::SpaceAfter(sub_def, comments_or_new_lines) => {
|
||||
let (new_acc, _) =
|
||||
// If there are comments before, attach to this definition
|
||||
generate_entry_doc(exposed_ident_ids, acc, before_comments_or_new_lines, sub_def);
|
||||
generate_entry_doc(ident_ids, acc, before_comments_or_new_lines, sub_def);
|
||||
|
||||
// Comments after a definition are attached to the next definition
|
||||
(new_acc, Some(comments_or_new_lines))
|
||||
|
@ -150,7 +155,7 @@ fn generate_entry_doc<'a>(
|
|||
Def::Annotation(loc_pattern, _loc_ann) => match loc_pattern.value {
|
||||
Pattern::Identifier(identifier) => {
|
||||
// Check if the definition is exposed
|
||||
if exposed_ident_ids
|
||||
if ident_ids
|
||||
.get_id(&InlinableString::from(identifier))
|
||||
.is_some()
|
||||
{
|
||||
|
@ -170,7 +175,7 @@ fn generate_entry_doc<'a>(
|
|||
Def::AnnotatedBody { ann_pattern, .. } => match ann_pattern.value {
|
||||
Pattern::Identifier(identifier) => {
|
||||
// Check if the definition is exposed
|
||||
if exposed_ident_ids
|
||||
if ident_ids
|
||||
.get_id(&InlinableString::from(identifier))
|
||||
.is_some()
|
||||
{
|
||||
|
|
|
@ -3512,9 +3512,14 @@ fn fabricate_effects_module<'a>(
|
|||
problems: can_env.problems,
|
||||
ident_ids: can_env.ident_ids,
|
||||
references: MutSet::default(),
|
||||
scope,
|
||||
};
|
||||
|
||||
let constraint = constrain_module(&module_output, module_id);
|
||||
let constraint = constrain_module(
|
||||
&module_output.aliases,
|
||||
&module_output.declarations,
|
||||
module_id,
|
||||
);
|
||||
|
||||
let module = Module {
|
||||
module_id,
|
||||
|
@ -3531,6 +3536,7 @@ fn fabricate_effects_module<'a>(
|
|||
let module_docs = ModuleDocumentation {
|
||||
name: String::from(name),
|
||||
entries: Vec::new(),
|
||||
scope: module_output.scope,
|
||||
};
|
||||
|
||||
let constrained_module = ConstrainedModule {
|
||||
|
@ -3612,18 +3618,6 @@ where
|
|||
..
|
||||
} = parsed;
|
||||
|
||||
// Generate documentation information
|
||||
// TODO: store timing information?
|
||||
let module_docs = match module_name {
|
||||
ModuleNameEnum::PkgConfig => None,
|
||||
ModuleNameEnum::App(_) => None,
|
||||
ModuleNameEnum::Interface(name) => Some(crate::docs::generate_module_docs(
|
||||
name.as_str().into(),
|
||||
&exposed_ident_ids,
|
||||
&parsed_defs,
|
||||
)),
|
||||
};
|
||||
|
||||
let mut var_store = VarStore::default();
|
||||
let canonicalized = canonicalize_module_defs(
|
||||
&arena,
|
||||
|
@ -3644,7 +3638,24 @@ where
|
|||
|
||||
match canonicalized {
|
||||
Ok(module_output) => {
|
||||
let constraint = constrain_module(&module_output, module_id);
|
||||
// Generate documentation information
|
||||
// TODO: store timing information?
|
||||
let module_docs = match module_name {
|
||||
ModuleNameEnum::PkgConfig => None,
|
||||
ModuleNameEnum::App(_) => None,
|
||||
ModuleNameEnum::Interface(name) => Some(crate::docs::generate_module_docs(
|
||||
module_output.scope,
|
||||
name.as_str().into(),
|
||||
&module_output.ident_ids,
|
||||
&parsed_defs,
|
||||
)),
|
||||
};
|
||||
|
||||
let constraint = constrain_module(
|
||||
&module_output.aliases,
|
||||
&module_output.declarations,
|
||||
module_id,
|
||||
);
|
||||
|
||||
let module = Module {
|
||||
module_id,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::ident::Ident;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_collections::all::{default_hasher, ImMap, MutMap};
|
||||
use roc_collections::all::{default_hasher, MutMap, SendMap};
|
||||
use roc_region::all::Region;
|
||||
use std::collections::HashMap;
|
||||
use std::{fmt, u32};
|
||||
|
@ -711,8 +711,8 @@ macro_rules! define_builtins {
|
|||
/// and what symbols they should resolve to.
|
||||
///
|
||||
/// This is for type aliases like `Int` and `Str` and such.
|
||||
pub fn default_in_scope() -> ImMap<Ident, (Symbol, Region)> {
|
||||
let mut scope = ImMap::default();
|
||||
pub fn default_in_scope() -> SendMap<Ident, (Symbol, Region)> {
|
||||
let mut scope = SendMap::default();
|
||||
|
||||
$(
|
||||
$(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue