Merge pull request #4645 from roc-lang/i4606

Do not bind accessors in toplevel thunks to their thunks' names
This commit is contained in:
Ayaz 2022-12-02 11:46:00 -06:00 committed by GitHub
commit 1beb00f490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 31 deletions

View File

@ -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);

View File

@ -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
)
}

View File

@ -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;

View File

@ -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 }
"#
)
}

View File

@ -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) {