Skip to content

Commit

Permalink
address a few remaining comments from Vineeth that I missed before
Browse files Browse the repository at this point in the history
  • Loading branch information
brmataptos committed Nov 27, 2024
1 parent 982d07c commit 44baaf0
Show file tree
Hide file tree
Showing 53 changed files with 154 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! Lambda lifting rewrites lambda expressions into construction
//! of *closures*. A closure refers to a function and contains a partial list
//! of arguments for that function, essentially currying it. We use the
//! `EarlyBind` operation to construct a closure from a function and set of arguemnts,
//! `EarlyBind` operation to construct a closure from a function and set of arguments,
//! which must be the first `k` arguments to the function argument list.
//!
//! ```ignore
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<'a> LambdaLifter<'a> {
// If final `args` match `lambda_params`, and all other args are simple, then returns
// the simple prefix of `args`.
fn get_args_if_simple<'b>(
lambda_params: &Vec<Parameter>,
lambda_params: &[Parameter],
args: &'b [Exp],
) -> Option<Vec<&'b Exp>> {
if lambda_params.len() <= args.len() {
Expand Down Expand Up @@ -313,13 +313,14 @@ impl<'a> LambdaLifter<'a> {
None
}

// Only allow simple expressions which cannot vary or abort
fn exp_is_simple(fn_exp: &Exp) -> bool {
// Only allow simple expressions which are not too expensive for now.
// TODO(LAMBDA): see if more compelx expresisons would be useful.
fn exp_is_simple(exp: &Exp) -> bool {
use ExpData::*;
match fn_exp.as_ref() {
Call(_, Operation::EarlyBind, args) => args.iter().all(|exp| Self::exp_is_simple(exp)),
match exp.as_ref() {
Call(_, Operation::EarlyBind, args) => args.iter().all(Self::exp_is_simple),
Call(_, op, args) => {
op.is_ok_to_remove_from_code() && args.iter().all(|exp| Self::exp_is_simple(exp))
op.is_ok_to_remove_from_code() && args.iter().all(Self::exp_is_simple)
},
Sequence(_, exp_vec) => {
if let [exp] = &exp_vec[..] {
Expand Down Expand Up @@ -658,7 +659,7 @@ impl<'a> ExpRewriterFunctions for LambdaLifter<'a> {
env.error(
&loc,
// TODO(LAMBDA)
"Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall."
"Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call."
);
return None;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,19 @@ module 0xcafe::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/basic.move:10:16
10 │ map(x, |y| y + c)
│ ^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/basic.move:15:16
15 │ map(x, |x| x + c)
│ ^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/basic.move:20:16
20 │ map(x, |x| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ module 0xcafe::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/modify.move:13:16
13 │ map(x, |y| {
Expand All @@ -513,7 +513,7 @@ error: Currently, lambda expressions must explicitly declare `move` capture of f
16 │ │ })
│ ╰─────────^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/modify.move:20:16
20 │ map(x, |y| {
Expand All @@ -523,7 +523,7 @@ error: Currently, lambda expressions must explicitly declare `move` capture of f
23 │ │ })
│ ╰─────────^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/modify.move:28:16
28 │ map(x, |y| {
Expand All @@ -533,7 +533,7 @@ error: Currently, lambda expressions must explicitly declare `move` capture of f
31 │ │ })
│ ╰─────────^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/modify.move:36:16
36 │ map(x, |y| {
Expand All @@ -543,7 +543,7 @@ error: Currently, lambda expressions must explicitly declare `move` capture of f
39 │ │ })
│ ╰─────────^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/modify.move:44:16
44 │ map(x, |y| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ module 0xcafe::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/nested.move:15:42
15 │ map1(x, |y| (map2((y - c as u8), |y| y + (c as u8)) as u64))
│ ^^^^^^^^^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/nested.move:15:17
15 │ map1(x, |y| (map2((y - c as u8), |y| y + (c as u8)) as u64))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module 0xcafe::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda-lifting/pattern.move:15:23
15 │ consume(s, x, |S{x}, _y| { let y = x; x + y})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,19 +1045,19 @@ module 0xc0ffee::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/break_continue_in_lambda.move:40:22
40 │ brk2(| | break);
│ ^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/break_continue_in_lambda.move:41:8
41 │ brk2(| | while (true) { break });
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/break_continue_in_lambda.move:42:8
42 │ brk2(| | while (true) { continue });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991.move:8:21
8 │ assert!(foo(|x, _| x, |_, y| y, 10, 100) == 110, 0);
│ ^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991.move:8:31
8 │ assert!(foo(|x, _| x, |_, y| y, 10, 100) == 110, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991_noparam.move:8:21
8 │ assert!(foo(|_, _| 3, |_, _| 10, 10, 100) == 13, 0);
│ ^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991_noparam.move:8:31
8 │ assert!(foo(|_, _| 3, |_, _| 10, 10, 100) == 13, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991_noparam2.move:8:21
8 │ assert!(foo(|_| 3, |_| 10, 10, 100) == 13, 0);
│ ^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991_noparam2.move:8:28
8 │ assert!(foo(|_| 3, |_| 10, 10, 100) == 13, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,25 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991a.move:10:21
10 │ assert!(foo(|x, _| x, |_, y| y,
│ ^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991a.move:10:31
10 │ assert!(foo(|x, _| x, |_, y| y,
│ ^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991a.move:11:6
11 │ |a, _b| a, |_c, d| d,
│ ^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991a.move:11:17
11 │ |a, _b| a, |_c, d| d,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991b.move:8:21
8 │ assert!(foo(|_, y| y,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/bug_10991c.move:8:21
8 │ assert!(foo(|_, y, _, q| y + q,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3267,7 +3267,7 @@ module 0x42::test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/dotdot_valid.move:181:22
181 │ lambda_param(|S2(x, ..)| x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ warning: Unused parameter `f`. Consider removing or prefixing with an underscore
3 │ fun foo(f: |&u64|) {
│ ^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/eq_inline.move:7:13
7 │ foo(|v| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/eval_ignored_param.move:10:14
10 │ let r = foo(|x, _, z| x*z, |_, y, _| y, 1, 10, 100, 1000);
│ ^^^^^^^^^^^^^

error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/eval_ignored_param.move:10:29
10 │ let r = foo(|x, _, z| x*z, |_, y, _| y, 1, 10, 100, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ module 0x42::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/generic_calls.move:47:17
47 │ inlined(|s| s.id(), s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/generics.move:16:26
16 │ foreach<u64>(&v, |e| sum = sum + *e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ module 0x42::m {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/inline_fun_in_spec.move:19:28
19 │ spec { assert exec(|y| y > 0, x); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ module 0x42::Test {


Diagnostics:
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline functioncall.
error: Currently, lambda expressions must explicitly declare `move` capture of free variables, except when appearing as an argument to an inline function call.
┌─ tests/lambda/inline-parity/inlining1.move:8:13
8 │ foo(|_| 3, 10)
Expand Down
Loading

0 comments on commit 44baaf0

Please sign in to comment.