diff --git a/crates/compiler/can/src/def.rs b/crates/compiler/can/src/def.rs index c9b389cee1..8d67e40c0f 100644 --- a/crates/compiler/can/src/def.rs +++ b/crates/compiler/can/src/def.rs @@ -10,7 +10,6 @@ use crate::annotation::IntroducedVariables; use crate::annotation::OwnedNamedOrAble; use crate::derive; use crate::env::Env; -use crate::expr::AccessorData; use crate::expr::AnnotatedMark; use crate::expr::ClosureData; use crate::expr::Declarations; @@ -2255,36 +2254,6 @@ fn canonicalize_pending_body<'a>( (loc_can_expr, def_references) } - // Turn f = .foo into f = \rcd -[f]-> rcd.foo - ( - Pattern::Identifier(defined_symbol) - | Pattern::AbilityMemberSpecialization { - ident: defined_symbol, - .. - }, - ast::Expr::RecordAccessorFunction(field), - ) => { - let (loc_can_expr, can_output) = ( - Loc::at( - loc_expr.region, - Accessor(AccessorData { - name: *defined_symbol, - function_var: var_store.fresh(), - record_var: var_store.fresh(), - ext_var: var_store.fresh(), - closure_var: var_store.fresh(), - field_var: var_store.fresh(), - field: (*field).into(), - }), - ), - Output::default(), - ); - let def_references = DefReferences::Value(can_output.references.clone()); - output.union(can_output); - - (loc_can_expr, def_references) - } - _ => { let (loc_can_expr, can_output) = canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); diff --git a/crates/compiler/test_gen/src/gen_records.rs b/crates/compiler/test_gen/src/gen_records.rs index e0d25d553f..1c5c710f60 100644 --- a/crates/compiler/test_gen/src/gen_records.rs +++ b/crates/compiler/test_gen/src/gen_records.rs @@ -1092,3 +1092,22 @@ fn update_record_that_is_a_thunk_single_field() { RocStr ); } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn toplevel_accessor_fn_thunk() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [main] to "./platform" + + ra = .field + + main = + ra { field : 15u8 } + "# + ), + 15u8, + u8 + ) +} diff --git a/crates/compiler/test_mono/generated/toplevel_accessor_fn_thunk.txt b/crates/compiler/test_mono/generated/toplevel_accessor_fn_thunk.txt new file mode 100644 index 0000000000..96e66c2592 --- /dev/null +++ b/crates/compiler/test_mono/generated/toplevel_accessor_fn_thunk.txt @@ -0,0 +1,12 @@ +procedure Test.1 (): + let Test.6 : {} = Struct {}; + ret Test.6; + +procedure Test.2 (Test.7): + ret Test.7; + +procedure Test.0 (): + let Test.9 : U8 = 15i64; + let Test.4 : {} = CallByName Test.1; + let Test.3 : U8 = CallByName Test.2 Test.9; + ret Test.3; diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index 03ddfc0d88..aa4dfb6023 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -2082,3 +2082,17 @@ fn anonymous_closure_lifted_to_named_issue_2403() { "# ) } + +#[mono_test] +fn toplevel_accessor_fn_thunk() { + indoc!( + r#" + app "test" provides [main] to "./platform" + + ra = .field + + main = + ra { field : 15u8 } + "# + ) +} diff --git a/crates/compiler/types/src/subs.rs b/crates/compiler/types/src/subs.rs index 4b189c0b26..975d33195b 100644 --- a/crates/compiler/types/src/subs.rs +++ b/crates/compiler/types/src/subs.rs @@ -2135,6 +2135,8 @@ impl Subs { is_inhabited(self, var) } + /// Is the ground constructor (in the layout-determination sense) of this type a function? + /// That is, is this a function modulo aliases and opaques? pub fn is_function(&self, mut var: Variable) -> bool { loop { match self.get_content_without_compacting(var) {