This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
forked from move-language/move
Destroy vectors with elements #368
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
language/tools/move-mv-llvm-compiler/tests/rbpf-tests/vec-destroy.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// use-stdlib | ||
|
||
// Testing that the runtime can destroy vectors | ||
// with non-zero number of elements. | ||
// | ||
// At time of writing the compiler does not always | ||
// generate vector destructor calls. The particular | ||
// pattern here, with make returning a vector, | ||
// does generate destructor calls. | ||
|
||
module 0x2::tests { | ||
use 0x1::vector; | ||
|
||
fun make<T>(elt: T) : vector<T> { | ||
let v: vector<T> = vector::empty(); | ||
vector::push_back(&mut v, elt); | ||
v | ||
} | ||
|
||
fun make2<T>(elt1: T, elt2: T) : vector<T> { | ||
let v: vector<T> = vector::empty(); | ||
vector::push_back(&mut v, elt1); | ||
vector::push_back(&mut v, elt2); | ||
v | ||
} | ||
|
||
public fun test_bool() { | ||
make(true); | ||
} | ||
|
||
public fun test_u8() { | ||
make(1_u8); | ||
} | ||
|
||
public fun test_u16() { | ||
make(1_u16); | ||
} | ||
|
||
public fun test_u32() { | ||
make(1_u32); | ||
} | ||
|
||
public fun test_u64() { | ||
make(1_u64); | ||
} | ||
|
||
public fun test_u128() { | ||
make(1_u128); | ||
} | ||
|
||
public fun test_u256() { | ||
make(1_u256); | ||
} | ||
|
||
public fun test_vec_u8() { | ||
make(make2(1_u256, 2)); | ||
} | ||
|
||
public fun test_vec_vec_u8() { | ||
make(make(make2(1_u256, 2))); | ||
} | ||
|
||
struct S1 has drop { | ||
} | ||
|
||
public fun test_struct1() { | ||
make(make2(S1 { }, S1 { })); | ||
} | ||
|
||
struct S2 has drop { | ||
f1: vector<u8>, | ||
f2: bool, | ||
f3: vector<S3>, | ||
} | ||
|
||
struct S3 has drop { | ||
f1: vector<S1>, | ||
} | ||
|
||
public fun test_struct2() { | ||
make(make2( | ||
S2 { | ||
f1: make(1), | ||
f2: true, | ||
f3: make(S3 { | ||
f1: make(S1 { }), | ||
}), | ||
}, | ||
S2 { | ||
f1: make(2), | ||
f2: true, | ||
f3: make(S3 { | ||
f1: make(S1 { }), | ||
}), | ||
} | ||
)); | ||
} | ||
} | ||
|
||
script { | ||
use 0x2::tests; | ||
|
||
fun main() { | ||
tests::test_bool(); | ||
tests::test_u8(); | ||
tests::test_u16(); | ||
tests::test_u32(); | ||
tests::test_u64(); | ||
tests::test_u128(); | ||
tests::test_u256(); | ||
tests::test_vec_u8(); | ||
tests::test_vec_vec_u8(); | ||
tests::test_struct1(); | ||
tests::test_struct2(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a flag that will help switch between leak vs. drop. that'd be easier to test i guess. maybe as a separate patch if you think this is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can do that separately.