Revert "wip canonical builtins in modules"

This reverts commit e1935a1e9f0c7ea1ffefe5f2f4f07f2c7666363b.
This commit is contained in:
Richard Feldman 2020-04-30 20:31:45 -04:00
parent a1750567ff
commit 072cf4e844
4 changed files with 26 additions and 63 deletions

View file

@ -1,27 +1,13 @@
use crate::def::{Declaration, Def};
use crate::expr::{Expr, Recursive};
use roc_collections::all::{MutMap, MutSet, SendMap};
use crate::def::Def;
use crate::expr::Expr;
use crate::expr::Recursive;
use roc_collections::all::SendMap;
use roc_module::ident::TagName;
use roc_module::symbol::{ModuleId, Symbol};
use roc_module::symbol::Symbol;
use roc_parse::operator::CalledVia;
use roc_region::all::{Located, Region};
use roc_types::subs::{VarStore, Variable};
fn exposed_symbols() -> MutMap<ModuleId, MutSet<Symbol>> {
let mut all = MutMap::default(); // TODO use with_capacity_and_hasher here
all.insert(ModuleId::LIST, {
let mut set = MutSet::default(); // TODO use with_capacity_and_hasher here
set.insert(Symbol::LIST_GET);
set.insert(Symbol::LIST_FIRST);
set
});
all
}
/// Some builtins cannot be constructed in code gen alone, and need to be defined
/// as separate Roc defs. For example, List.get has this type:
///
@ -39,24 +25,16 @@ fn exposed_symbols() -> MutMap<ModuleId, MutSet<Symbol>> {
/// delegates to the compiler-internal List.getUnsafe function to do the actual
/// lookup (if the bounds check passed). That internal function is hardcoded in code gen,
/// which works fine because it doesn't involve any open tag unions.
pub fn declarations_by_id() -> MutMap<ModuleId, Vec<Declaration>> {
let var_store = VarStore::default();
let mut decls = MutMap::default(); // TODO use with_capacity_and_hasher here
decls.insert(
ModuleId::LIST,
vec![
list_get(&var_store),
list_first(&var_store),
int_div(&var_store),
],
);
decls
pub fn builtin_defs(var_store: &VarStore) -> Vec<Def> {
vec![
list_get(var_store),
list_first(var_store),
int_div(var_store),
]
}
/// List.get : List elem, Int -> Result elem [ OutOfBounds ]*
fn list_get(var_store: &VarStore) -> Declaration {
fn list_get(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
defn(
@ -127,7 +105,7 @@ fn list_get(var_store: &VarStore) -> Declaration {
}
/// Int.div : Int, Int -> Result Int [ DivByZero ]*
fn int_div(var_store: &VarStore) -> Declaration {
fn int_div(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
use crate::pattern::Pattern::*;
@ -196,17 +174,17 @@ fn int_div(var_store: &VarStore) -> Declaration {
Box::new((no_region(body), var_store.fresh())),
);
Declare(Def {
Def {
loc_pattern: no_region(Identifier(Symbol::INT_DIV)),
loc_expr: no_region(expr),
expr_var: var_store.fresh(),
pattern_vars: SendMap::default(),
annotation: None,
})
}
}
/// List.first : List elem -> Result elem [ ListWasEmpty ]*
fn list_first(var_store: &VarStore) -> Declaration {
fn list_first(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
defn(
@ -298,7 +276,7 @@ fn call(symbol: Symbol, args: Vec<Expr>, var_store: &VarStore) -> Expr {
}
#[inline(always)]
fn defn(fn_name: Symbol, args: Vec<Symbol>, var_store: &VarStore, body: Expr) -> Declaration {
fn defn(fn_name: Symbol, args: Vec<Symbol>, var_store: &VarStore, body: Expr) -> Def {
use crate::expr::Expr::*;
use crate::pattern::Pattern::*;
@ -315,11 +293,11 @@ fn defn(fn_name: Symbol, args: Vec<Symbol>, var_store: &VarStore, body: Expr) ->
Box::new((no_region(body), var_store.fresh())),
);
Declaration::Declare(Def {
Def {
loc_pattern: no_region(Identifier(fn_name)),
loc_expr: no_region(expr),
expr_var: var_store.fresh(),
pattern_vars: SendMap::default(),
annotation: None,
})
}
}