Skip to content

Commit

Permalink
add AbilitySet::MAXIMAL_FUNCTIONS and use it in some function type …
Browse files Browse the repository at this point in the history
…constraints to avoid reducing set of function type abilities when unifying types
  • Loading branch information
brmataptos committed Nov 22, 2024
1 parent 96b04a6 commit 14473ed
Show file tree
Hide file tree
Showing 29 changed files with 688 additions and 171 deletions.
4 changes: 3 additions & 1 deletion third_party/move/move-binary-format/src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,10 @@ impl AbilitySet {
| (Ability::Key as u8),
);
pub const EMPTY: Self = Self(0);
/// Base abilities for all `Functions`
/// Minimal abilities for all `Functions`
pub const FUNCTIONS: AbilitySet = Self(Ability::Drop as u8);
/// Maximal abilities for all `Functions`. This is used for UB when joining types.
pub const MAXIMAL_FUNCTIONS: AbilitySet = Self::PUBLIC_FUNCTIONS;
/// Abilities for `Bool`, `U8`, `U64`, `U128`, and `Address`
pub const PRIMITIVES: AbilitySet =
Self((Ability::Copy as u8) | (Ability::Drop as u8) | (Ability::Store as u8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<'a> LambdaLifter<'a> {
// functions (courtesy of #12317)
let mut param_index_mapping = BTreeMap::new();
let mut params = vec![];

for (used_param_count, (param, var_info)) in
mem::take(&mut self.free_params).into_iter().enumerate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|(u64, integer)|u64` to a function which expects argument of type `|(u64, vector<u8>)|u64`
error: cannot pass `|(u64, integer)|u64 with copy+drop+store` to a function which expects argument of type `|(u64, vector<u8>)|u64`
┌─ tests/checking/inlining/lambda_cast_err.move:7:53
7 │ vector::fold(gas_schedule_blob, (0 as u64), |sum, addend| sum + (addend as u64))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|u64|u64` to a function which expects argument of type `|u64|`
error: cannot pass `|u64|u64 with copy+drop+store` to a function which expects argument of type `|u64|`
┌─ tests/checking/inlining/lambda_param_mismatch.move:12:33
12 │ vector::for_each(input, |item| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ error: cannot pass `u256` to a function which expects argument of type `bool`
32 │ wrongly_typed_callee(1, 1) // Wrongly typed function application
│ ^

error: cannot pass `|num|bool` to a function which expects argument of type `|num|num`
error: cannot pass `|num|bool with copy+drop+store` to a function which expects argument of type `|num|num`
┌─ tests/checking/specs/expressions_err.move:37:36
37 │ wrongly_typed_fun_arg_callee(|x| false) // Wrongly typed function argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ error: cannot use `()` with an operator which expects a value of type `u64`
56 │ i = i + action(XVector::borrow(v, i)); // expected to have wrong result type
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot return `u64` from a function with result type `|integer|`
error: cannot return `u64` from a function with result type `|integer| with copy+drop+store`
┌─ tests/checking/typing/lambda.move:61:9
61 │ x(1) // expected to be not a function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ error: cannot use `()` with an operator which expects a value of type `u64`
56 │ i = i + action(XVector::borrow(v, i)); // expected to have wrong result type
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot return `u64` from a function with result type `|integer|`
error: cannot return `u64` from a function with result type `|integer| with copy+drop+store`
┌─ tests/checking/typing/lambda_typed.move:61:9
61 │ x(1) // expected to be not a function
Expand All @@ -30,7 +30,7 @@ error: cannot use `&u64` with an operator which expects a value of type `integer
67 │ foreach(&v, |e: &u64| sum = sum + e) // expected to cannot infer type
│ ^

error: cannot pass `|&u64|u64` to a function which expects argument of type `|&u64|`
error: cannot pass `|&u64|u64 with copy+drop+store` to a function which expects argument of type `|&u64|`
┌─ tests/checking/typing/lambda_typed.move:73:21
73 │ foreach(&v, |e: &u64| { sum = sum + *e; *e }) // expected to have wrong result type of lambda
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|(u64, integer)|u64` to a function which expects argument of type `|(u64, vector<u8>)|u64`
error: cannot pass `|(u64, integer)|u64 with copy+drop+store` to a function which expects argument of type `|(u64, vector<u8>)|u64`
┌─ tests/lambda/inline-parity/lambda_cast_err.move:26:52
26 │ vector_fold(gas_schedule_blob, (0 as u64), |sum, addend| sum + (addend as u64))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|(u64, integer)|u64` to a function which expects argument of type `|(u64, vector<u8>)|u64`
error: cannot pass `|(u64, integer)|u64 with copy+drop+store` to a function which expects argument of type `|(u64, vector<u8>)|u64`
┌─ tests/lambda/inline-parity/lambda_cast_err.move:26:52
26 │ vector_fold(gas_schedule_blob, (0 as u64), |sum, addend| sum + (addend as u64))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|u64|u64` to a function which expects argument of type `|u64|`
error: cannot pass `|u64|u64 with copy+drop+store` to a function which expects argument of type `|u64|`
┌─ tests/lambda/inline-parity/lambda_param_mismatch.move:20:32
20 │ vector_for_each(input, |item| {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: cannot pass `|u64|u64` to a function which expects argument of type `|u64|`
error: cannot pass `|u64|u64 with copy+drop+store` to a function which expects argument of type `|u64|`
┌─ tests/lambda/inline-parity/lambda_param_mismatch.move:20:32
20 │ vector_for_each(input, |item| {
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-compiler-v2/tests/lambda/lambda.exp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ error: cannot use `()` with an operator which expects a value of type `u64`
56 │ i = i + action(XVector::borrow(v, i)); // expected to have wrong result type
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot return `u64` from a function with result type `|integer|`
error: cannot return `u64` from a function with result type `|integer| with copy+drop+store`
┌─ tests/lambda/lambda.move:61:9
61 │ x(1) // expected to be not a function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ error: cannot use `()` with an operator which expects a value of type `u64`
56 │ i = i + action(XVector::borrow(v, i)); // expected to have wrong result type
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot return `u64` from a function with result type `|integer|`
error: cannot return `u64` from a function with result type `|integer| with copy+drop+store`
┌─ tests/lambda/lambda.move:61:9
61 │ x(1) // expected to be not a function
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-compiler-v2/tests/lambda/lambda3.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand Down
22 changes: 11 additions & 11 deletions third_party/move/move-compiler-v2/tests/lambda/lambda3.lambda.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -13,7 +13,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -24,7 +24,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -35,7 +35,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -46,7 +46,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -57,7 +57,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -68,7 +68,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -79,7 +79,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -90,7 +90,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -101,7 +101,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand All @@ -112,7 +112,7 @@ module 0x8675309::M {
module 0x8675309::M {
public fun lambda_not_allowed() {
{
let _x: |u64|u64 = |i: u64| Add<u64>(i, 1);
let _x: |u64|u64 with copy+drop+store = |i: u64| Add<u64>(i, 1);
Tuple()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module 0x42::test {
}
private fun choose_function1(key: u64,x: u64): u64 {
{
let f: |u64|u64 = if Eq<u64>(key, 0) {
let f: |u64|u64 with copy+drop = if Eq<u64>(key, 0) {
mod2::double
} else {
if Eq<u64>(key, 1) {
Expand Down Expand Up @@ -64,24 +64,24 @@ module 0x42::test {
} else {
if Eq<u64>(key, 11) {
{
let g: |(u64, u64)|u64:copy+drop = move|(x: u64, y: u64): (u64, u64)| mod3::multiply(x, y) with copy, drop;
let g: |(u64, u64)|u64 with copy+drop+store = move|(x: u64, y: u64): (u64, u64)| mod3::multiply(x, y) with copy, drop;
move|x: u64| (g)(x, 11)
}
} else {
if Eq<u64>(key, 12) {
{
let h: |u64|u64:copy+drop = move|x: u64| mod3::multiply(x, 12) with copy, drop;
let h: |u64|u64 with copy+drop+store = move|x: u64| mod3::multiply(x, 12) with copy, drop;
move|x: u64| (h)(x) with copy, drop
}
} else {
if Eq<u64>(key, 14) {
{
let i: |u64|u64 = move|x: u64| test::multiply3(2, x, 2);
let i: |u64|u64 with copy+drop+store = move|x: u64| test::multiply3(2, x, 2);
move|z: u64| (i)(z)
}
} else {
{
let i: |(u64, u64)|u64 = move|(x: u64, y: u64): (u64, u64)| {
let i: |(u64, u64)|u64 with copy+drop+store = move|(x: u64, y: u64): (u64, u64)| {
let q: u64 = Sub<u64>(y, 1);
mod3::multiply(x, Add<u64>(q, 1))
};
Expand Down
Loading

0 comments on commit 14473ed

Please sign in to comment.