From b735a59a347802e6c3d61aa661ea6a93ef4da72d Mon Sep 17 00:00:00 2001 From: "Brian R. Murphy" <132495859+brmataptos@users.noreply.github.com> Date: Fri, 13 Sep 2024 19:57:29 -0700 Subject: [PATCH] Fix v1 test input /resources_invalid.move to match v2 test input, and add 2 other variants of the test. --- .../checking/inlining/resources_valid.exp | 29 +++++++++++++++++++ .../checking/inlining/resources_valid.move | 24 +++++++++++++++ .../inlining/resources_valid_noacquires.exp | 12 ++++++++ .../inlining/resources_valid_noacquires.move | 24 +++++++++++++++ .../move_check/inlining/resources_invalid.exp | 6 ---- .../inlining/resources_invalid.move | 2 +- .../move_check/inlining/resources_valid.move | 24 +++++++++++++++ .../inlining/resources_valid_noacquires.exp | 6 ++++ .../inlining/resources_valid_noacquires.move | 24 +++++++++++++++ 9 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.exp create mode 100644 third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.move create mode 100644 third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.exp create mode 100644 third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.move create mode 100644 third_party/move/move-compiler/tests/move_check/inlining/resources_valid.move create mode 100644 third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.exp create mode 100644 third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.move diff --git a/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.exp b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.exp new file mode 100644 index 00000000000000..cf71f9d1297c0b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.exp @@ -0,0 +1,29 @@ +// -- Model dump before bytecode pipeline +module 0x42::objects { + struct ReaderRef { + addr: address, + } + public fun get_addr(ref: &objects::ReaderRef<#0>): address { + select objects::ReaderRef.addr<&objects::ReaderRef>(ref) + } + public inline fun reader(ref: &objects::ReaderRef<#0>): � { + BorrowGlobal(Immutable)(objects::get_addr(ref)) + } +} // end 0x42::objects +module 0x42::token { + use 0x42::objects as obj; // resolved as: 0x42::objects + struct Token { + val: u64, + } + public fun get_value(ref: &objects::ReaderRef): u64 + acquires token::Token(*) + { + select token::Token.val<&token::Token>({ + let (ref: &objects::ReaderRef): (&objects::ReaderRef) = Tuple(ref); + BorrowGlobal(Immutable)(objects::get_addr(ref)) + }) + } +} // end 0x42::token + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.move b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.move new file mode 100644 index 00000000000000..37f2720a95b556 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid.move @@ -0,0 +1,24 @@ +module 0x42::objects { + + struct ReaderRef has store { + addr: address + } + + public fun get_addr(ref: &ReaderRef): address { + ref.addr + } + + public inline fun reader(ref: &ReaderRef): &T { + borrow_global(get_addr(ref)) + } +} + +module 0x42::token { + use 0x42::objects as obj; + + struct Token has key { val: u64 } + + public fun get_value(ref: &obj::ReaderRef): u64 acquires Token { + obj::reader(ref).val + } +} diff --git a/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.exp b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.exp new file mode 100644 index 00000000000000..040117f39fb1f3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.exp @@ -0,0 +1,12 @@ + +Diagnostics: +error: missing acquires annotation for `Token` + ┌─ tests/checking/inlining/resources_valid_noacquires.move:21:16 + │ +12 │ borrow_global(get_addr(ref)) + │ ------------------------------- acquired here + · +21 │ public fun get_value(ref: &obj::ReaderRef): u64 { + │ ^^^^^^^^^ +22 │ obj::reader(ref).val + │ ---------------- from a call inlined at this callsite diff --git a/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.move b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.move new file mode 100644 index 00000000000000..895bc3ec908894 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/inlining/resources_valid_noacquires.move @@ -0,0 +1,24 @@ +module 0x42::objects { + + struct ReaderRef has store { + addr: address + } + + public fun get_addr(ref: &ReaderRef): address { + ref.addr + } + + public inline fun reader(ref: &ReaderRef): &T { + borrow_global(get_addr(ref)) + } +} + +module 0x42::token { + use 0x42::objects as obj; + + struct Token has key { val: u64 } + + public fun get_value(ref: &obj::ReaderRef): u64 { + obj::reader(ref).val + } +} diff --git a/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.exp b/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.exp index 3f5913f49b2afd..092be903a7ac47 100644 --- a/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.exp +++ b/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.exp @@ -1,9 +1,3 @@ -error[E04020]: missing acquires annotation - ┌─ tests/move_check/inlining/resources_invalid.move:8:9 - │ -8 │ borrow_global(ref.addr) - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ The call acquires '0x42::token::Token', but the 'acquires' list for the current function 'get_value` does not contain this type. It must be present in the calling context's acquires list - error[E14002]: Inlined code invalid in this context ┌─ tests/move_check/inlining/resources_invalid.move:8:26 │ diff --git a/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.move b/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.move index 3445aa71d15d91..0ed28eded5c713 100644 --- a/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.move +++ b/third_party/move/move-compiler/tests/move_check/inlining/resources_invalid.move @@ -14,7 +14,7 @@ module 0x42::token { struct Token has key { val: u64 } - public fun get_value(ref: &obj::ReaderRef): u64 { + public fun get_value(ref: &obj::ReaderRef): u64 acquires Token { obj::reader(ref).val } } diff --git a/third_party/move/move-compiler/tests/move_check/inlining/resources_valid.move b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid.move new file mode 100644 index 00000000000000..37f2720a95b556 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid.move @@ -0,0 +1,24 @@ +module 0x42::objects { + + struct ReaderRef has store { + addr: address + } + + public fun get_addr(ref: &ReaderRef): address { + ref.addr + } + + public inline fun reader(ref: &ReaderRef): &T { + borrow_global(get_addr(ref)) + } +} + +module 0x42::token { + use 0x42::objects as obj; + + struct Token has key { val: u64 } + + public fun get_value(ref: &obj::ReaderRef): u64 acquires Token { + obj::reader(ref).val + } +} diff --git a/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.exp b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.exp new file mode 100644 index 00000000000000..3829891a72e2b4 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.exp @@ -0,0 +1,6 @@ +error[E04020]: missing acquires annotation + ┌─ tests/move_check/inlining/resources_valid_noacquires.move:12:9 + │ +12 │ borrow_global(get_addr(ref)) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The call acquires '0x42::token::Token', but the 'acquires' list for the current function 'get_value` does not contain this type. It must be present in the calling context's acquires list + diff --git a/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.move b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.move new file mode 100644 index 00000000000000..895bc3ec908894 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/inlining/resources_valid_noacquires.move @@ -0,0 +1,24 @@ +module 0x42::objects { + + struct ReaderRef has store { + addr: address + } + + public fun get_addr(ref: &ReaderRef): address { + ref.addr + } + + public inline fun reader(ref: &ReaderRef): &T { + borrow_global(get_addr(ref)) + } +} + +module 0x42::token { + use 0x42::objects as obj; + + struct Token has key { val: u64 } + + public fun get_value(ref: &obj::ReaderRef): u64 { + obj::reader(ref).val + } +}