Cleanup after #7227

This commit is contained in:
JRI98 2024-11-18 11:04:07 +00:00
parent 64cd70c1da
commit a18232bd8b
No known key found for this signature in database
GPG key ID: F83B29916FF13F24
11 changed files with 12 additions and 331 deletions

View file

@ -62,7 +62,6 @@ fn print_declarations_help<'a>(
toplevel_function(c, f, symbol, function_def, &body.value)
}
DeclarationTag::Expectation => todo!(),
DeclarationTag::ExpectationFx => todo!(),
DeclarationTag::Destructure(_) => todo!(),
DeclarationTag::MutualRecursion { .. } => {
// the defs will be printed next

View file

@ -342,7 +342,6 @@ pub enum Declaration {
DeclareRec(Vec<Def>, IllegalCycleMark),
Builtin(Def),
Expects(ExpectsOrDbgs),
ExpectsFx(ExpectsOrDbgs),
/// If we know a cycle is illegal during canonicalization.
/// Otherwise we will try to detect this during solving; see [`IllegalCycleMark`].
InvalidCycle(Vec<CycleEntry>),
@ -357,7 +356,6 @@ impl Declaration {
InvalidCycle { .. } => 0,
Builtin(_) => 0,
Expects(_) => 0,
ExpectsFx(_) => 0,
}
}
@ -373,7 +371,7 @@ impl Declaration {
&cycles.first().unwrap().expr_region,
&cycles.last().unwrap().expr_region,
),
Declaration::Expects(expects) | Declaration::ExpectsFx(expects) => Region::span_across(
Declaration::Expects(expects) => Region::span_across(
expects.regions.first().unwrap(),
expects.regions.last().unwrap(),
),
@ -2835,10 +2833,6 @@ fn decl_to_let(decl: Declaration, loc_ret: Loc<Expr>) -> Loc<Expr> {
loc_ret
}
Declaration::ExpectsFx(expects) => {
// Expects should only be added to top-level decls, not to let-exprs!
unreachable!("{:?}", &expects)
}
}
}

View file

@ -3241,12 +3241,6 @@ impl Declarations {
collector.visit_expr(&loc_expr.value, loc_expr.region, var);
}
ExpectationFx => {
let loc_expr =
toplevel_expect_to_inline_expect_fx(self.expressions[index].clone());
collector.visit_expr(&loc_expr.value, loc_expr.region, var);
}
}
}
@ -3265,7 +3259,6 @@ roc_error_macros::assert_sizeof_default!(DeclarationTag, 8);
pub enum DeclarationTag {
Value,
Expectation,
ExpectationFx,
Function(Index<Loc<FunctionDef>>),
Recursive(Index<Loc<FunctionDef>>),
TailRecursive(Index<Loc<FunctionDef>>),
@ -3283,7 +3276,7 @@ impl DeclarationTag {
match self {
Function(_) | Recursive(_) | TailRecursive(_) => 1,
Value => 1,
Expectation | ExpectationFx => 1,
Expectation => 1,
Destructure(_) => 1,
MutualRecursion { length, .. } => length as usize + 1,
}
@ -3484,15 +3477,7 @@ pub(crate) fn get_lookup_symbols(expr: &Expr) -> Vec<ExpectLookup> {
/// This is supposed to happen just before monomorphization:
/// all type errors and such are generated from the user source,
/// but this transformation means that we don't need special codegen for toplevel expects
pub fn toplevel_expect_to_inline_expect_pure(loc_expr: Loc<Expr>) -> Loc<Expr> {
toplevel_expect_to_inline_expect_help(loc_expr, false)
}
pub fn toplevel_expect_to_inline_expect_fx(loc_expr: Loc<Expr>) -> Loc<Expr> {
toplevel_expect_to_inline_expect_help(loc_expr, true)
}
fn toplevel_expect_to_inline_expect_help(mut loc_expr: Loc<Expr>, has_effects: bool) -> Loc<Expr> {
pub fn toplevel_expect_to_inline_expect_pure(mut loc_expr: Loc<Expr>) -> Loc<Expr> {
enum StoredDef {
NonRecursive(Region, Box<Def>),
Recursive(Region, Vec<Def>, IllegalCycleMark),
@ -3530,7 +3515,6 @@ fn toplevel_expect_to_inline_expect_help(mut loc_expr: Loc<Expr>, has_effects: b
}
let expect_region = loc_expr.region;
assert!(!has_effects);
let expect = Expr::Expect {
loc_condition: Box::new(loc_expr),
loc_continuation: Box::new(Loc::at_zero(Expr::EmptyRecord)),

View file

@ -609,7 +609,6 @@ pub fn canonicalize_module_defs<'a>(
// the declarations of this group will be treaded individually by later iterations
}
Expectation => { /* ignore */ }
ExpectationFx => { /* ignore */ }
}
}
@ -747,14 +746,6 @@ pub fn canonicalize_module_defs<'a>(
&mut fix_closures_closure_captures,
);
}
ExpectationFx => {
let loc_expr = &mut declarations.expressions[index];
fix_values_captured_in_closure_expr(
&mut loc_expr.value,
&mut fix_closures_no_capture_symbols,
&mut fix_closures_closure_captures,
);
}
}
}

View file

@ -107,7 +107,7 @@ pub fn walk_decls<V: Visitor>(visitor: &mut V, decls: &Declarations) {
annotation: decls.annotations[index].as_ref(),
}
}
Expectation | ExpectationFx => {
Expectation => {
let loc_condition = &decls.expressions[index];
DeclarationInfo::Expectation { loc_condition }

View file

@ -2738,34 +2738,6 @@ pub fn constrain_decls(
expected,
);
constraint = constraints.let_constraint(
[],
[],
[],
expect_constraint,
constraint,
Generalizable(false),
)
}
ExpectationFx => {
let loc_expr = &declarations.expressions[index];
let bool_type = constraints.push_variable(Variable::BOOL);
let expected = constraints.push_expected_type(Expected::ForReason(
Reason::ExpectCondition,
bool_type,
loc_expr.region,
));
let expect_constraint = constrain_expr(
types,
constraints,
&mut env,
loc_expr.region,
&loc_expr.value,
expected,
);
constraint = constraints.let_constraint(
[],
[],

View file

@ -2657,7 +2657,7 @@ fn update<'a>(
let subs = solved_subs.into_inner();
if !toplevel_expects.pure.is_empty() || !toplevel_expects.fx.is_empty() {
if !toplevel_expects.pure.is_empty() {
state.toplevel_expects.insert(module_id, toplevel_expects);
}
@ -6010,78 +6010,6 @@ fn build_pending_specializations<'a>(
toplevel_expects.pure.insert(symbol, region);
procs_base.partial_procs.insert(symbol, proc);
}
ExpectationFx => {
// skip expectations if we're not going to run them
if !build_expects {
continue;
}
// mark this symbol as a top-level thunk before any other work on the procs
module_thunks.push(symbol);
let expr_var = Variable::EMPTY_RECORD;
let is_host_exposed = true;
// If this is an exposed symbol, we need to
// register it as such. Otherwise, since it
// never gets called by Roc code, it will never
// get specialized!
if is_host_exposed {
let layout_result =
layout_cache.raw_from_var(mono_env.arena, expr_var, mono_env.subs);
// cannot specialize when e.g. main's type contains type variables
if let Err(e) = layout_result {
match e {
LayoutProblem::Erroneous => {
let message = "top level function has erroneous type";
procs_base.runtime_errors.insert(symbol, message);
continue;
}
LayoutProblem::UnresolvedTypeVar(v) => {
let message = format!(
"top level function has unresolved type variable {v:?}"
);
procs_base
.runtime_errors
.insert(symbol, mono_env.arena.alloc(message));
continue;
}
}
}
procs_base.host_specializations.insert_host_exposed(
mono_env.subs,
LambdaName::no_niche(symbol),
None,
expr_var,
);
}
let body = roc_can::expr::toplevel_expect_to_inline_expect_fx(body);
let proc = PartialProc {
annotation: expr_var,
// This is a 0-arity thunk, so it has no arguments.
pattern_symbols: &[],
// This is a top-level definition, so it cannot capture anything
captured_symbols: CapturedSymbols::None,
body: body.value,
body_var: expr_var,
// This is a 0-arity thunk, so it cannot be recursive
is_self_recursive: false,
};
// extend the region of the expect expression with the region of the preceding
// comment, so it is shown in failure/panic messages
let name_region = declarations.symbols[index].region;
let expr_region = declarations.expressions[index].region;
let region = Region::span_across(&name_region, &expr_region);
toplevel_expects.fx.insert(symbol, region);
procs_base.partial_procs.insert(symbol, proc);
}
}
}

View file

@ -167,7 +167,6 @@ pub(crate) struct LateSpecializationsModule<'a> {
#[derive(Debug, Default)]
pub struct ToplevelExpects {
pub pure: VecMap<Symbol, Region>,
pub fx: VecMap<Symbol, Region>,
}
#[derive(Debug)]

View file

@ -359,10 +359,6 @@ fn expect_types(mut loaded_module: LoadedModule, mut expected_types: HashMap<&st
// at least at the moment this does not happen
panic!("Unexpected expectation in module declarations");
}
ExpectationFx => {
// at least at the moment this does not happen
panic!("Unexpected expectation in module declarations");
}
};
}
@ -462,7 +458,7 @@ fn module_with_deps() {
def_count += 1;
}
MutualRecursion { .. } => { /* do nothing, not a def */ }
Expectation | ExpectationFx => { /* do nothing, not a def */ }
Expectation => { /* do nothing, not a def */ }
}
}

View file

@ -101,7 +101,7 @@ impl<'a> LowerParams<'a> {
self.lower_expr(&mut decls.expressions[index].value);
}
Destructure(_) | Expectation | ExpectationFx => {
Destructure(_) | Expectation => {
self.lower_expr(&mut decls.expressions[index].value);
}
MutualRecursion { .. } => {}