mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Revert "Mark introduced variables"
This reverts commit 02038ea8bf525021f05061e4296749b01a4b9346.
This commit is contained in:
parent
23bbe0863b
commit
cc507f3abd
2 changed files with 26 additions and 52 deletions
|
@ -125,7 +125,7 @@ impl IntroducedVariables {
|
||||||
self.inferred.push(var);
|
self.inferred.push(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_lambda_set(&mut self, var: Variable) {
|
fn insert_lambda_set(&mut self, var: Variable) {
|
||||||
self.debug_assert_not_already_present(var);
|
self.debug_assert_not_already_present(var);
|
||||||
self.lambda_sets.push(var);
|
self.lambda_sets.push(var);
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,13 +167,11 @@ fn build_effect_always(
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut introduced_variables = IntroducedVariables::default();
|
|
||||||
|
|
||||||
// \value -> $Effect \{} -> value
|
// \value -> $Effect \{} -> value
|
||||||
let (function_var, always_closure) = {
|
let (function_var, always_closure) = {
|
||||||
// `$Effect \{} -> value`
|
// `$Effect \{} -> value`
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let body = Expr::OpaqueRef {
|
let body = Expr::OpaqueRef {
|
||||||
opaque_var: var_store.fresh(),
|
opaque_var: var_store.fresh(),
|
||||||
name: effect_symbol,
|
name: effect_symbol,
|
||||||
|
@ -204,6 +202,8 @@ fn build_effect_always(
|
||||||
(function_var, closure)
|
(function_var, closure)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut introduced_variables = IntroducedVariables::default();
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
// Effect.always : a -> Effect a
|
// Effect.always : a -> Effect a
|
||||||
let var_a = var_store.fresh();
|
let var_a = var_store.fresh();
|
||||||
|
@ -327,8 +327,6 @@ fn build_effect_map(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut introduced_variables = IntroducedVariables::default();
|
|
||||||
|
|
||||||
// \{} -> mapper (thunk {})
|
// \{} -> mapper (thunk {})
|
||||||
let inner_closure = {
|
let inner_closure = {
|
||||||
let arguments = vec![(
|
let arguments = vec![(
|
||||||
|
@ -354,7 +352,7 @@ fn build_effect_map(
|
||||||
|
|
||||||
// \$Effect thunk, mapper
|
// \$Effect thunk, mapper
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let arguments = vec![
|
let arguments = vec![
|
||||||
(
|
(
|
||||||
var_store.fresh(),
|
var_store.fresh(),
|
||||||
|
@ -378,7 +376,7 @@ fn build_effect_map(
|
||||||
|
|
||||||
// `$Effect \{} -> (mapper (thunk {}))`
|
// `$Effect \{} -> (mapper (thunk {}))`
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let body = Expr::OpaqueRef {
|
let body = Expr::OpaqueRef {
|
||||||
opaque_var: var_store.fresh(),
|
opaque_var: var_store.fresh(),
|
||||||
name: effect_symbol,
|
name: effect_symbol,
|
||||||
|
@ -401,6 +399,8 @@ fn build_effect_map(
|
||||||
loc_body: Box::new(Loc::at_zero(body)),
|
loc_body: Box::new(Loc::at_zero(body)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut introduced_variables = IntroducedVariables::default();
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
// Effect.map : Effect a, (a -> b) -> Effect b
|
// Effect.map : Effect a, (a -> b) -> Effect b
|
||||||
let var_a = var_store.fresh();
|
let var_a = var_store.fresh();
|
||||||
|
@ -534,10 +534,8 @@ fn build_effect_after(
|
||||||
Expr::Call(Box::new(boxed), arguments, CalledVia::Space)
|
Expr::Call(Box::new(boxed), arguments, CalledVia::Space)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut introduced_variables = IntroducedVariables::default();
|
|
||||||
|
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, &mut introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
|
|
||||||
let arguments = vec![
|
let arguments = vec![
|
||||||
(
|
(
|
||||||
|
@ -573,6 +571,8 @@ fn build_effect_after(
|
||||||
loc_body: Box::new(Loc::at_zero(to_effect_call)),
|
loc_body: Box::new(Loc::at_zero(to_effect_call)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut introduced_variables = IntroducedVariables::default();
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
let var_a = var_store.fresh();
|
let var_a = var_store.fresh();
|
||||||
let var_b = var_store.fresh();
|
let var_b = var_store.fresh();
|
||||||
|
@ -643,7 +643,6 @@ fn wrap_in_effect_thunk(
|
||||||
closure_name: Symbol,
|
closure_name: Symbol,
|
||||||
captured_symbols: Vec<Symbol>,
|
captured_symbols: Vec<Symbol>,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let captured_symbols: Vec<_> = captured_symbols
|
let captured_symbols: Vec<_> = captured_symbols
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -673,7 +672,7 @@ fn wrap_in_effect_thunk(
|
||||||
|
|
||||||
// `$Effect \{} -> value`
|
// `$Effect \{} -> value`
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
Expr::OpaqueRef {
|
Expr::OpaqueRef {
|
||||||
opaque_var: var_store.fresh(),
|
opaque_var: var_store.fresh(),
|
||||||
name: effect_symbol,
|
name: effect_symbol,
|
||||||
|
@ -690,14 +689,13 @@ fn force_effect(
|
||||||
effect_symbol: Symbol,
|
effect_symbol: Symbol,
|
||||||
thunk_symbol: Symbol,
|
thunk_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let whole_var = var_store.fresh();
|
let whole_var = var_store.fresh();
|
||||||
|
|
||||||
let thunk_var = var_store.fresh();
|
let thunk_var = var_store.fresh();
|
||||||
|
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let pattern = Pattern::UnwrappedOpaque {
|
let pattern = Pattern::UnwrappedOpaque {
|
||||||
whole_var,
|
whole_var,
|
||||||
opaque: effect_symbol,
|
opaque: effect_symbol,
|
||||||
|
@ -813,17 +811,8 @@ fn build_effect_forever(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut introduced_variables = IntroducedVariables::default();
|
let body =
|
||||||
|
build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store);
|
||||||
let body = build_effect_forever_body(
|
|
||||||
env,
|
|
||||||
scope,
|
|
||||||
effect_symbol,
|
|
||||||
forever_symbol,
|
|
||||||
effect,
|
|
||||||
var_store,
|
|
||||||
&mut introduced_variables,
|
|
||||||
);
|
|
||||||
|
|
||||||
let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))];
|
let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))];
|
||||||
|
|
||||||
|
@ -840,6 +829,8 @@ fn build_effect_forever(
|
||||||
loc_body: Box::new(Loc::at_zero(body)),
|
loc_body: Box::new(Loc::at_zero(body)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut introduced_variables = IntroducedVariables::default();
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
let var_a = var_store.fresh();
|
let var_a = var_store.fresh();
|
||||||
let var_b = var_store.fresh();
|
let var_b = var_store.fresh();
|
||||||
|
@ -903,7 +894,6 @@ fn build_effect_forever_body(
|
||||||
forever_symbol: Symbol,
|
forever_symbol: Symbol,
|
||||||
effect: Symbol,
|
effect: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let closure_name = {
|
let closure_name = {
|
||||||
scope
|
scope
|
||||||
|
@ -923,7 +913,6 @@ fn build_effect_forever_body(
|
||||||
forever_symbol,
|
forever_symbol,
|
||||||
effect,
|
effect,
|
||||||
var_store,
|
var_store,
|
||||||
introduced_variables,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let captured_symbols = vec![effect];
|
let captured_symbols = vec![effect];
|
||||||
|
@ -933,7 +922,6 @@ fn build_effect_forever_body(
|
||||||
closure_name,
|
closure_name,
|
||||||
captured_symbols,
|
captured_symbols,
|
||||||
var_store,
|
var_store,
|
||||||
introduced_variables,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +932,6 @@ fn build_effect_forever_inner_body(
|
||||||
forever_symbol: Symbol,
|
forever_symbol: Symbol,
|
||||||
effect: Symbol,
|
effect: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let thunk1_symbol = {
|
let thunk1_symbol = {
|
||||||
scope
|
scope
|
||||||
|
@ -975,7 +962,7 @@ fn build_effect_forever_inner_body(
|
||||||
let thunk_var = var_store.fresh();
|
let thunk_var = var_store.fresh();
|
||||||
|
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let pattern = Pattern::UnwrappedOpaque {
|
let pattern = Pattern::UnwrappedOpaque {
|
||||||
whole_var,
|
whole_var,
|
||||||
opaque: effect_symbol,
|
opaque: effect_symbol,
|
||||||
|
@ -1043,7 +1030,6 @@ fn build_effect_forever_inner_body(
|
||||||
effect_symbol,
|
effect_symbol,
|
||||||
thunk2_symbol,
|
thunk2_symbol,
|
||||||
var_store,
|
var_store,
|
||||||
introduced_variables,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
Expr::LetNonRec(
|
Expr::LetNonRec(
|
||||||
|
@ -1067,8 +1053,6 @@ fn build_effect_loop(
|
||||||
let state_symbol = new_symbol!(scope, env, "state");
|
let state_symbol = new_symbol!(scope, env, "state");
|
||||||
let step_symbol = new_symbol!(scope, env, "step");
|
let step_symbol = new_symbol!(scope, env, "step");
|
||||||
|
|
||||||
let mut introduced_variables = IntroducedVariables::default();
|
|
||||||
|
|
||||||
let body = build_effect_loop_body(
|
let body = build_effect_loop_body(
|
||||||
env,
|
env,
|
||||||
scope,
|
scope,
|
||||||
|
@ -1077,7 +1061,6 @@ fn build_effect_loop(
|
||||||
state_symbol,
|
state_symbol,
|
||||||
step_symbol,
|
step_symbol,
|
||||||
var_store,
|
var_store,
|
||||||
&mut introduced_variables,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let arguments = vec![
|
let arguments = vec![
|
||||||
|
@ -1104,6 +1087,8 @@ fn build_effect_loop(
|
||||||
loc_body: Box::new(Loc::at_zero(body)),
|
loc_body: Box::new(Loc::at_zero(body)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut introduced_variables = IntroducedVariables::default();
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
let var_a = var_store.fresh();
|
let var_a = var_store.fresh();
|
||||||
let var_b = var_store.fresh();
|
let var_b = var_store.fresh();
|
||||||
|
@ -1202,7 +1187,6 @@ fn build_effect_loop_body(
|
||||||
state_symbol: Symbol,
|
state_symbol: Symbol,
|
||||||
step_symbol: Symbol,
|
step_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let closure_name = {
|
let closure_name = {
|
||||||
scope
|
scope
|
||||||
|
@ -1223,7 +1207,6 @@ fn build_effect_loop_body(
|
||||||
state_symbol,
|
state_symbol,
|
||||||
step_symbol,
|
step_symbol,
|
||||||
var_store,
|
var_store,
|
||||||
introduced_variables,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let captured_symbols = vec![state_symbol, step_symbol];
|
let captured_symbols = vec![state_symbol, step_symbol];
|
||||||
|
@ -1233,7 +1216,6 @@ fn build_effect_loop_body(
|
||||||
closure_name,
|
closure_name,
|
||||||
captured_symbols,
|
captured_symbols,
|
||||||
var_store,
|
var_store,
|
||||||
introduced_variables,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1267,7 +1249,6 @@ fn build_effect_loop_inner_body(
|
||||||
state_symbol: Symbol,
|
state_symbol: Symbol,
|
||||||
step_symbol: Symbol,
|
step_symbol: Symbol,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let thunk1_symbol = new_symbol!(scope, env, "thunk3");
|
let thunk1_symbol = new_symbol!(scope, env, "thunk3");
|
||||||
let thunk2_symbol = new_symbol!(scope, env, "thunk4");
|
let thunk2_symbol = new_symbol!(scope, env, "thunk4");
|
||||||
|
@ -1282,7 +1263,7 @@ fn build_effect_loop_inner_body(
|
||||||
let thunk_var = var_store.fresh();
|
let thunk_var = var_store.fresh();
|
||||||
|
|
||||||
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
let (specialized_def_type, type_arguments, lambda_set_variables) =
|
||||||
build_fresh_opaque_variables(var_store, introduced_variables);
|
build_fresh_opaque_variables(var_store);
|
||||||
let pattern = Pattern::UnwrappedOpaque {
|
let pattern = Pattern::UnwrappedOpaque {
|
||||||
whole_var,
|
whole_var,
|
||||||
opaque: effect_symbol,
|
opaque: effect_symbol,
|
||||||
|
@ -1352,13 +1333,7 @@ fn build_effect_loop_inner_body(
|
||||||
// $Effect thunk2 = loop effect
|
// $Effect thunk2 = loop effect
|
||||||
// thunk2 {}
|
// thunk2 {}
|
||||||
// ```
|
// ```
|
||||||
let force_thunk2 = force_effect(
|
let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store);
|
||||||
loop_new_state_step,
|
|
||||||
effect_symbol,
|
|
||||||
thunk2_symbol,
|
|
||||||
var_store,
|
|
||||||
introduced_variables,
|
|
||||||
);
|
|
||||||
|
|
||||||
let step_branch = {
|
let step_branch = {
|
||||||
let step_tag_name = TagName::Global("Step".into());
|
let step_tag_name = TagName::Global("Step".into());
|
||||||
|
@ -1602,7 +1577,7 @@ fn build_effect_opaque(
|
||||||
introduced_variables: &mut IntroducedVariables,
|
introduced_variables: &mut IntroducedVariables,
|
||||||
) -> Type {
|
) -> Type {
|
||||||
let closure_var = var_store.fresh();
|
let closure_var = var_store.fresh();
|
||||||
introduced_variables.insert_lambda_set(closure_var);
|
introduced_variables.insert_wildcard(Loc::at_zero(closure_var));
|
||||||
|
|
||||||
let actual = Type::Function(
|
let actual = Type::Function(
|
||||||
vec![Type::EmptyRec],
|
vec![Type::EmptyRec],
|
||||||
|
@ -1621,14 +1596,13 @@ fn build_effect_opaque(
|
||||||
|
|
||||||
fn build_fresh_opaque_variables(
|
fn build_fresh_opaque_variables(
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
|
||||||
) -> (Box<Type>, Vec<(Lowercase, Type)>, Vec<LambdaSet>) {
|
) -> (Box<Type>, Vec<(Lowercase, Type)>, Vec<LambdaSet>) {
|
||||||
let a_var = var_store.fresh();
|
|
||||||
let closure_var = var_store.fresh();
|
let closure_var = var_store.fresh();
|
||||||
|
|
||||||
introduced_variables.insert_named("a".into(), Loc::at_zero(a_var));
|
// NB: if there are bugs, check whether not introducing variables is a problem!
|
||||||
introduced_variables.insert_lambda_set(closure_var);
|
// introduced_variables.insert_wildcard(Loc::at_zero(closure_var));
|
||||||
|
|
||||||
|
let a_var = var_store.fresh();
|
||||||
let actual = Type::Function(
|
let actual = Type::Function(
|
||||||
vec![Type::EmptyRec],
|
vec![Type::EmptyRec],
|
||||||
Box::new(Type::Variable(closure_var)),
|
Box::new(Type::Variable(closure_var)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue