Skip to content

Commit

Permalink
address PR 15365 comments as of 11/26
Browse files Browse the repository at this point in the history
  • Loading branch information
brmataptos committed Nov 27, 2024
1 parent c9dfd1b commit 3c02ba1
Show file tree
Hide file tree
Showing 12 changed files with 6,684 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,7 @@ impl<'a> ExpRewriterFunctions for LambdaLifter<'a> {
// param_index_mapping = for each free var which is a Parameter from the enclosing function,
// a mapping from index there to index in the params list; other free vars are
// substituted automatically by using the same symbol for the param
let Some((mut params, mut closure_args, param_index_mapping)) =
self.get_params_for_freevars()
else {
return None;
};
let (mut params, mut closure_args, param_index_mapping) = self.get_params_for_freevars()?;

// Some(ExpData::Invalid(env.clone_node(id)).into_exp());
// Add lambda args. For dealing with patterns in lambdas (`|S{..}|e`) we need
Expand Down Expand Up @@ -764,7 +760,7 @@ impl<'a> ExpRewriterFunctions for LambdaLifter<'a> {
env.error(
&loc,
// TODO(LAMBDA)
"Lambdas expressions with `store` ability currently may only be a simple call to an existing `public` function. This lambda expression requires defining a `public` helper function, which might affect module upgradeability and is not yet supported."
"The body of a lambdas expression with `store` ability currently must be a simple call to an existing `public` function, with lambda params the same as the *final* arguments to the function call."
);
return None;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,64 @@

Diagnostics:
warning: Unused parameter `f`. Consider removing or prefixing with an underscore: `_f`
┌─ tests/checking/inlining/function_name_shadowing.move:8:28
8 │ public inline fun quux(f:|u64, u64|u64, a: u64, b: u64): u64 {
│ ^
┌─ tests/checking/inlining/function_name_shadowing.move:20:28
20 │ public inline fun quux(f:|u64, u64|u64, g:|u64|u64, i:|u8|u8, a: u64, b: u64): u64 {
│ ^

warning: Unused parameter `g`. Consider removing or prefixing with an underscore: `_g`
┌─ tests/checking/inlining/function_name_shadowing.move:20:45
20 │ public inline fun quux(f:|u64, u64|u64, g:|u64|u64, i:|u8|u8, a: u64, b: u64): u64 {
│ ^

warning: Unused parameter `i`. Consider removing or prefixing with an underscore: `_i`
┌─ tests/checking/inlining/function_name_shadowing.move:20:57
20 │ public inline fun quux(f:|u64, u64|u64, g:|u64|u64, i:|u8|u8, a: u64, b: u64): u64 {
│ ^

// -- Model dump before bytecode pipeline
module 0x42::OtherModule {
public fun g(a: u64,b: u64): u64 {
Add<u64>(a, b)
}
public fun h(a: u64,b: u64): u64 {
Add<u64>(Mul<u64>(2, a), b)
}
} // end 0x42::OtherModule
module 0x42::Test {
use 0x42::OtherModule::{g}; // resolved as: 0x42::OtherModule
public fun f(a: u64,b: u64): u64 {
Mul<u64>(a, b)
}
public inline fun quux(f: |(u64, u64)|u64,a: u64,b: u64): u64 {
Test::f(a, b)
public inline fun quux(f: |(u64, u64)|u64,g: |u64|u64,i: |u8|u8,a: u64,b: u64): u64 {
Mul<u64>(Mul<u64>(Test::f(a, b), OtherModule::g(a, b)), OtherModule::h(a, b))
}
public fun test_shadowing(): u64 {
Test::f(10, 2)
Mul<u64>(Mul<u64>(Test::f(10, 2), OtherModule::g(10, 2)), OtherModule::h(10, 2))
}
} // end 0x42::Test

// -- Sourcified model before bytecode pipeline
module 0x42::OtherModule {
public fun g(a: u64, b: u64): u64 {
a + b
}
public fun h(a: u64, b: u64): u64 {
2 * a + b
}
}
module 0x42::Test {
use 0x42::OtherModule;
public fun f(a: u64, b: u64): u64 {
a * b
}
public inline fun quux(f: |(u64, u64)|u64, a: u64, b: u64): u64 {
f(a, b)
public inline fun quux(f: |(u64, u64)|u64, g: |u64|u64, i: |u8|u8, a: u64, b: u64): u64 {
f(a, b) * OtherModule::g(a, b) * OtherModule::h(a, b)
}
public fun test_shadowing(): u64 {
f(10, 2)
f(10, 2) * OtherModule::g(10, 2) * OtherModule::h(10, 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
//# publish
module 0x42::OtherModule {
public fun g(a: u64, b: u64): u64 {
a + b
}

public fun h(a: u64, b: u64): u64 {
2 * a + b
}
}

//# publish
module 0x42::Test {
use 0x42::OtherModule::g;

public fun f(a: u64, b: u64): u64 {
a * b
}

public inline fun quux(f:|u64, u64|u64, a: u64, b: u64): u64 {
f(a, b)
public inline fun quux(f:|u64, u64|u64, g:|u64|u64, i:|u8|u8, a: u64, b: u64): u64 {
use 0x42::OtherModule::h;
f(a, b) * g(a, b) * h(a, b)
}

public fun test_shadowing(): u64 {
quux(|a, b| a - b, 10, 2)
quux(|a, b| a - b, |a| a + 2, |b| 255u8-b, 10, 2)
}
}

Expand Down
Loading

0 comments on commit 3c02ba1

Please sign in to comment.