mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
cleanup
This commit is contained in:
parent
992575051a
commit
b1fe5659a4
4 changed files with 13 additions and 38 deletions
|
@ -1,6 +1,5 @@
|
||||||
use crate::annotation::IntroducedVariables;
|
use crate::annotation::IntroducedVariables;
|
||||||
use crate::def::{Declaration, Def};
|
use crate::def::{Declaration, Def};
|
||||||
use crate::env::Env;
|
|
||||||
use crate::expr::{ClosureData, Expr, Recursive};
|
use crate::expr::{ClosureData, Expr, Recursive};
|
||||||
use crate::pattern::Pattern;
|
use crate::pattern::Pattern;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
|
@ -35,7 +34,6 @@ pub(crate) struct HostedGeneratedFunctions {
|
||||||
/// For this alias we implement the functions specified in HostedGeneratedFunctions with the
|
/// For this alias we implement the functions specified in HostedGeneratedFunctions with the
|
||||||
/// standard implementation.
|
/// standard implementation.
|
||||||
pub(crate) fn build_effect_builtins(
|
pub(crate) fn build_effect_builtins(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
|
@ -45,7 +43,7 @@ pub(crate) fn build_effect_builtins(
|
||||||
) {
|
) {
|
||||||
macro_rules! helper {
|
macro_rules! helper {
|
||||||
($f:expr) => {{
|
($f:expr) => {{
|
||||||
let (symbol, def) = $f(env, scope, effect_symbol, var_store);
|
let (symbol, def) = $f(scope, effect_symbol, var_store);
|
||||||
|
|
||||||
// make the outside world know this symbol exists
|
// make the outside world know this symbol exists
|
||||||
exposed_symbols.insert(symbol);
|
exposed_symbols.insert(symbol);
|
||||||
|
@ -92,13 +90,12 @@ pub(crate) fn build_effect_builtins(
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! new_symbol {
|
macro_rules! new_symbol {
|
||||||
($scope:expr, $env:expr, $name:expr) => {{
|
($scope:expr, $name:expr) => {{
|
||||||
$scope.introduce($name.into(), Region::zero()).unwrap()
|
$scope.introduce($name.into(), Region::zero()).unwrap()
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_always(
|
fn build_effect_always(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
|
@ -224,7 +221,6 @@ fn build_effect_always(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_map(
|
fn build_effect_map(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
|
@ -418,7 +414,6 @@ fn build_effect_map(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_after(
|
fn build_effect_after(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
|
@ -667,7 +662,6 @@ fn force_effect(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_forever(
|
fn build_effect_forever(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
|
@ -724,8 +718,7 @@ fn build_effect_forever(
|
||||||
|
|
||||||
let effect = { scope.introduce("effect".into(), Region::zero()).unwrap() };
|
let effect = { scope.introduce("effect".into(), Region::zero()).unwrap() };
|
||||||
|
|
||||||
let body =
|
let body = build_effect_forever_body(scope, effect_symbol, forever_symbol, effect, var_store);
|
||||||
build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store);
|
|
||||||
|
|
||||||
let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))];
|
let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))];
|
||||||
|
|
||||||
|
@ -801,7 +794,6 @@ fn build_effect_forever(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_forever_body(
|
fn build_effect_forever_body(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
forever_symbol: Symbol,
|
forever_symbol: Symbol,
|
||||||
|
@ -814,14 +806,8 @@ fn build_effect_forever_body(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let inner_body = build_effect_forever_inner_body(
|
let inner_body =
|
||||||
env,
|
build_effect_forever_inner_body(scope, effect_symbol, forever_symbol, effect, var_store);
|
||||||
scope,
|
|
||||||
effect_symbol,
|
|
||||||
forever_symbol,
|
|
||||||
effect,
|
|
||||||
var_store,
|
|
||||||
);
|
|
||||||
|
|
||||||
let captured_symbols = vec![effect];
|
let captured_symbols = vec![effect];
|
||||||
wrap_in_effect_thunk(
|
wrap_in_effect_thunk(
|
||||||
|
@ -834,7 +820,6 @@ fn build_effect_forever_body(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_forever_inner_body(
|
fn build_effect_forever_inner_body(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
forever_symbol: Symbol,
|
forever_symbol: Symbol,
|
||||||
|
@ -934,17 +919,15 @@ fn build_effect_forever_inner_body(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_loop(
|
fn build_effect_loop(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
) -> (Symbol, Def) {
|
) -> (Symbol, Def) {
|
||||||
let loop_symbol = new_symbol!(scope, env, "loop");
|
let loop_symbol = new_symbol!(scope, "loop");
|
||||||
let state_symbol = new_symbol!(scope, env, "state");
|
let state_symbol = new_symbol!(scope, "state");
|
||||||
let step_symbol = new_symbol!(scope, env, "step");
|
let step_symbol = new_symbol!(scope, "step");
|
||||||
|
|
||||||
let body = build_effect_loop_body(
|
let body = build_effect_loop_body(
|
||||||
env,
|
|
||||||
scope,
|
scope,
|
||||||
effect_symbol,
|
effect_symbol,
|
||||||
loop_symbol,
|
loop_symbol,
|
||||||
|
@ -1070,7 +1053,6 @@ fn build_effect_loop(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_loop_body(
|
fn build_effect_loop_body(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
loop_symbol: Symbol,
|
loop_symbol: Symbol,
|
||||||
|
@ -1085,7 +1067,6 @@ fn build_effect_loop_body(
|
||||||
};
|
};
|
||||||
|
|
||||||
let inner_body = build_effect_loop_inner_body(
|
let inner_body = build_effect_loop_inner_body(
|
||||||
env,
|
|
||||||
scope,
|
scope,
|
||||||
effect_symbol,
|
effect_symbol,
|
||||||
loop_symbol,
|
loop_symbol,
|
||||||
|
@ -1127,7 +1108,6 @@ fn applied_tag_pattern(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_effect_loop_inner_body(
|
fn build_effect_loop_inner_body(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
loop_symbol: Symbol,
|
loop_symbol: Symbol,
|
||||||
|
@ -1135,11 +1115,11 @@ fn build_effect_loop_inner_body(
|
||||||
step_symbol: Symbol,
|
step_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let thunk1_symbol = new_symbol!(scope, env, "thunk3");
|
let thunk1_symbol = new_symbol!(scope, "thunk3");
|
||||||
let thunk2_symbol = new_symbol!(scope, env, "thunk4");
|
let thunk2_symbol = new_symbol!(scope, "thunk4");
|
||||||
|
|
||||||
let new_state_symbol = new_symbol!(scope, env, "newState");
|
let new_state_symbol = new_symbol!(scope, "newState");
|
||||||
let done_symbol = new_symbol!(scope, env, "done");
|
let done_symbol = new_symbol!(scope, "done");
|
||||||
|
|
||||||
// Effect thunk1 = step state
|
// Effect thunk1 = step state
|
||||||
let thunk_from_effect = {
|
let thunk_from_effect = {
|
||||||
|
@ -1262,7 +1242,6 @@ fn build_effect_loop_inner_body(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_host_exposed_def(
|
pub fn build_host_exposed_def(
|
||||||
env: &mut Env,
|
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
ident: &str,
|
ident: &str,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::procedure::References;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use roc_collections::{MutMap, VecSet};
|
use roc_collections::{MutMap, VecSet};
|
||||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||||
use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{ IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_problem::can::{Problem, RuntimeError};
|
use roc_problem::can::{Problem, RuntimeError};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
|
||||||
|
|
|
@ -407,7 +407,6 @@ pub fn canonicalize_expr<'a>(
|
||||||
fields,
|
fields,
|
||||||
update: loc_update,
|
update: loc_update,
|
||||||
} => {
|
} => {
|
||||||
dbg!(&loc_update);
|
|
||||||
let (can_update, update_out) =
|
let (can_update, update_out) =
|
||||||
canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value);
|
canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value);
|
||||||
if let Var(symbol) = &can_update.value {
|
if let Var(symbol) = &can_update.value {
|
||||||
|
@ -438,7 +437,6 @@ pub fn canonicalize_expr<'a>(
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dbg!(&can_update.value);
|
|
||||||
// only (optionally qualified) variables can be updated, not arbitrary expressions
|
// only (optionally qualified) variables can be updated, not arbitrary expressions
|
||||||
|
|
||||||
let error = roc_problem::can::RuntimeError::InvalidRecordUpdate {
|
let error = roc_problem::can::RuntimeError::InvalidRecordUpdate {
|
||||||
|
|
|
@ -362,7 +362,6 @@ pub fn canonicalize_module_defs<'a>(
|
||||||
|
|
||||||
// NOTE this currently builds all functions, not just the ones that the user requested
|
// NOTE this currently builds all functions, not just the ones that the user requested
|
||||||
crate::effect_module::build_effect_builtins(
|
crate::effect_module::build_effect_builtins(
|
||||||
&mut env,
|
|
||||||
&mut scope,
|
&mut scope,
|
||||||
effect_symbol,
|
effect_symbol,
|
||||||
var_store,
|
var_store,
|
||||||
|
@ -417,7 +416,6 @@ pub fn canonicalize_module_defs<'a>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let hosted_def = crate::effect_module::build_host_exposed_def(
|
let hosted_def = crate::effect_module::build_host_exposed_def(
|
||||||
&mut env,
|
|
||||||
&mut scope,
|
&mut scope,
|
||||||
*symbol,
|
*symbol,
|
||||||
&ident,
|
&ident,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue