mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-04 18:58:20 +00:00
set new encoding as true by default and allow it to be disabled (#5915)
## Description This PR sets the "new encoding" (from now on will be called "encoding v1") as the default. We can still disable it using `no_encoding_v1`, which switches back to "encoding v0". Actions that needs to be done after this being merged will exist in https://github.com/FuelLabs/sway/issues/5727 New features - ABI Super traits; - AbiEncode buffer dynamic sizing; Bugs Fixed - `ContractCall` intrinsic interaction effect was not set correctly; Fixing warnings and error messages - Better error message when core-lib is not available for scripts/contracts/predicates; - Better error message when main inputs/outputs are unknown or error types; - Better error message when main inputs/outputs do not implement AbiEncode/AbiDecode; - Don't warn impurity attributes on the "__entry" fn; - Don't warn CEI on the "__entry" fn. Our CEI analysis, currently, does not recognize `Never`. This means it does not realize it is impossible to call two contract functions; Test Disabled (needs to be enabled again in the future) - should_pass/language/name_resolution_after_monomorphization - should_pass/language/shadowing/shadowed_glob_imports - should_pass/language/name_resolution_inside_intrinsics - sdk-harness/external_proxy test is not working. I am assuming it is the LDC bug that is already fixed on version 0.25. What is happening is that the literal "double_value" has the correct length, but some random data. Which makes the method selector fails. Only after we call LDC. The proxy contract is working. Test generating more warnings than before - should_pass/dca/contract/superabi_contract_calls What happens here is that when we implement a trait for `Contract`, we actually generate two functions: one prefixed `__contract_entry` that is called by the method selector; and another one normal, that can be called freely. So, if the trait method is never called manually, it is marked as dead. - should_pass/dca/contract/abi_fn_params I actually think the new warning is correct and nothing here needs to be done. Test with fewer warnings than before - should_pass/dca/unused_fields auto-impl is making all fields being used. so no dead code warnings are being generated. We need to fix this. Changes to std-lib - Functions that return data about call context changed the semantic. `first_param` and `second_param` return the value as the VM sees them. We now have `called_method` and `called_args`. This means that we can change the protocol later and still keep these four functions always working and with meaningful names. - - predicate_data also was updated to use encoding v1 protocol. ICE - increase_buffer_if_needed implementation is a little bit strange because does not work as a method inside `Buffer`. For some reason, it is generating an ICE. I need to create an issue so we can fix, and improve the implementation here. - `Buffer` used by AbiEncode needs a `push_bytes` so we can be more efficient when encoding Bytes and others. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers.
This commit is contained in:
parent
dbdcd62c8b
commit
1aec319e31
961 changed files with 13581 additions and 908 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -353,7 +353,7 @@ jobs:
|
|||
toolchain: ${{ env.RUST_VERSION }}
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Cargo Run E2E Tests (EVM)
|
||||
run: cargo run --locked --release --bin test -- --target evm --locked
|
||||
run: cargo run --locked --release --bin test -- --target evm --locked --no-encoding-v1
|
||||
|
||||
cargo-run-e2e-test-midenvm:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -365,7 +365,7 @@ jobs:
|
|||
toolchain: ${{ env.RUST_VERSION }}
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Cargo Run E2E Tests (EVM)
|
||||
run: cargo run --locked --release --bin test -- --target midenvm --locked
|
||||
run: cargo run --locked --release --bin test -- --target midenvm --locked --no-encoding-v1
|
||||
|
||||
# TODO: Remove this upon merging std tests with the rest of the E2E tests.
|
||||
cargo-test-lib-std:
|
||||
|
|
|
@ -1,268 +1,281 @@
|
|||
[[package]]
|
||||
name = 'annotation_style'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "annotation_style"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'annotations'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "annotations"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'arrays'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "arrays"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'assertions'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "assertions"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'asset_operations'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "asset_operations"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'associated-consts'
|
||||
source = 'member'
|
||||
name = "associated-consts"
|
||||
source = "member"
|
||||
dependencies = ["std git+https://github.com/fuellabs/sway?tag=v0.55.0#60ea55e692f4f70730b500735e13c29df2ac727e"]
|
||||
|
||||
[[package]]
|
||||
name = 'booleans'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "booleans"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'bytes'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "bytes"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'call'
|
||||
source = 'member'
|
||||
name = "call"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
'contract_interface',
|
||||
'std',
|
||||
"contract_interface",
|
||||
"std path+from-root-0F28276288D2432C",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = 'call_data'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "call_data"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'comments'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "comments"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'constants'
|
||||
source = 'member'
|
||||
name = "constants"
|
||||
source = "member"
|
||||
|
||||
[[package]]
|
||||
name = 'contract_interface'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "contract_interface"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'control_flow'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "control_flow"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'core'
|
||||
source = 'path+from-root-0F28276288D2432C'
|
||||
name = "core"
|
||||
source = "path+from-root-0F28276288D2432C"
|
||||
|
||||
[[package]]
|
||||
name = 'counter'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "core"
|
||||
source = "path+from-root-6074AE318B2A365C"
|
||||
|
||||
[[package]]
|
||||
name = 'empty_storage_init'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "counter"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'enum-advanced'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "empty_storage_init"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'enum_style'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "enum-advanced"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'enums'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "enum_style"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'fizzbuzz'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "enums"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'functions'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "fizzbuzz"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'getters'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "functions"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'hashing'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "getters"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'interface'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "hashing"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'intermediate_variables'
|
||||
source = 'member'
|
||||
name = "interface"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "intermediate_variables"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
'core',
|
||||
'std',
|
||||
"core path+from-root-0F28276288D2432C",
|
||||
"std path+from-root-0F28276288D2432C",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = 'letter_casing'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "letter_casing"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'logging'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "logging"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'my_lib'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "my_lib"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'my_library'
|
||||
source = 'member'
|
||||
name = "my_library"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
'my_other_library',
|
||||
'std',
|
||||
"my_other_library",
|
||||
"std path+from-root-0F28276288D2432C",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = 'my_other_library'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "my_other_library"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = 'namespace'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'numerics'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'ownership'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'pattern_matching'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'reading_writing_to_storage'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'simple_predicate'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'simple_script'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'std'
|
||||
source = 'path+from-root-0F28276288D2432C'
|
||||
dependencies = ['core']
|
||||
|
||||
[[package]]
|
||||
name = 'storage_init'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'storage_map'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'storage_vec'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'store_get'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'string_issue'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'strings'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'struct_shorthand'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'structs'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'tuples'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'unused_variables'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'variables'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
|
||||
[[package]]
|
||||
name = 'wallet'
|
||||
source = 'member'
|
||||
name = "namespace"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
'interface',
|
||||
'std',
|
||||
"core path+from-root-0F28276288D2432C",
|
||||
"std path+from-root-0F28276288D2432C",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = 'wallet_example'
|
||||
source = 'member'
|
||||
dependencies = ['std']
|
||||
name = "numerics"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "ownership"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "pattern_matching"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "reading_writing_to_storage"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "simple_predicate"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "simple_script"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "std"
|
||||
source = "git+https://github.com/fuellabs/sway?tag=v0.55.0#60ea55e692f4f70730b500735e13c29df2ac727e"
|
||||
dependencies = ["core path+from-root-6074AE318B2A365C"]
|
||||
|
||||
[[package]]
|
||||
name = "std"
|
||||
source = "path+from-root-0F28276288D2432C"
|
||||
dependencies = ["core path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "storage_init"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "storage_map"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "storage_vec"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "store_get"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "string_issue"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "strings"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "struct_shorthand"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "structs"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "tuples"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "unused_variables"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "variables"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
||||
[[package]]
|
||||
name = "wallet"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
"interface",
|
||||
"std path+from-root-0F28276288D2432C",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wallet_example"
|
||||
source = "member"
|
||||
dependencies = ["std path+from-root-0F28276288D2432C"]
|
||||
|
|
|
@ -3,6 +3,5 @@ authors = ["Fuel Labs <contact@fuel.sh>"]
|
|||
entry = "lib.sw"
|
||||
license = "Apache-2.0"
|
||||
name = "associated-consts"
|
||||
implicit-std = false
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "namespace"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
std = { path = "../../../../../../sway-lib-std" }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
library;
|
||||
|
||||
/* External declarations
|
||||
// ANCHOR: address
|
||||
pub struct Address {
|
||||
bits: b256,
|
||||
|
@ -16,6 +17,8 @@ pub enum Identity {
|
|||
ContractId: ContractId,
|
||||
}
|
||||
// ANCHOR_END: identity
|
||||
*/
|
||||
|
||||
fn address_cast() {
|
||||
// ANCHOR: address_cast
|
||||
let variable1 = 0x000000000000000000000000000000000000000000000000000000000000002A;
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
[[package]]
|
||||
name = "abi_supertraits"
|
||||
source = "member"
|
||||
|
||||
[[package]]
|
||||
name = "advanced_storage_variables"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "array"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "asm_return_tuple_pointer"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "basic_storage_variables"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "break_and_continue"
|
||||
|
@ -30,16 +38,23 @@ dependencies = ["core"]
|
|||
[[package]]
|
||||
name = "cei_analysis"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "configurable_constants"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "converting_types"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
|
@ -48,7 +63,10 @@ source = "path+from-root-70EE78029FACCEF1"
|
|||
[[package]]
|
||||
name = "counter"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enums"
|
||||
|
@ -57,72 +75,114 @@ source = "member"
|
|||
[[package]]
|
||||
name = "fizzbuzz"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashing"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "identity"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "liquidity_pool"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "match_expressions"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "methods_and_associated_functions"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "msg_sender"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mut_ref_params"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native_asset"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nested_storage_variables"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ownership"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "result"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signatures"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "std"
|
||||
|
@ -132,22 +192,34 @@ dependencies = ["core"]
|
|||
[[package]]
|
||||
name = "storage_example"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "storage_map"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "storage_vec"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "struct_storage_variables"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structs"
|
||||
|
@ -160,22 +232,32 @@ source = "member"
|
|||
[[package]]
|
||||
name = "type_aliases"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vec"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wallet_abi"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wallet_contract_caller_script"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
"wallet_abi",
|
||||
]
|
||||
|
@ -184,6 +266,7 @@ dependencies = [
|
|||
name = "wallet_smart_contract"
|
||||
source = "member"
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
"wallet_abi",
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# in the Sway repo, where each example is a package member of the workspace.
|
||||
[workspace]
|
||||
members = [
|
||||
"abi_supertraits",
|
||||
# "abi_supertraits",
|
||||
"advanced_storage_variables",
|
||||
"arrays",
|
||||
"methods_and_associated_functions",
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[project]
|
||||
authors = ["Fuel Labs <contact@fuel.sh>"]
|
||||
entry = "main.sw"
|
||||
implicit-std = false
|
||||
license = "Apache-2.0"
|
||||
name = "abi_supertraits"
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "advanced_storage_variables"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "array"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "asm_return_tuple_pointer"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "basic_storage_variables"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "cei_analysis"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -6,3 +6,4 @@ license = "Apache-2.0"
|
|||
name = "configurable_constants"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "converting_types"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "counter"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "fizzbuzz"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "hashing"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "identity"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "liquidity_pool"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "match_expressions"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "methods_and_associated_functions"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "msg_sender"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "callee"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../sway-lib-core" }
|
||||
std = { path = "../../../sway-lib-std/" }
|
||||
|
|
|
@ -6,6 +6,7 @@ license = "Apache-2.0"
|
|||
name = "caller"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../sway-lib-core" }
|
||||
std = { path = "../../../sway-lib-std/" }
|
||||
|
||||
[contract-dependencies]
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "native_asset"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "nested_storage_variables"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "option"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "ownership"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "mut_ref_params"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "result"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "signatures"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "storage_example"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "storage_map"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "storage_namespace"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "storage_vec"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "struct_storage_variables"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "type_aliases"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "vec"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "wallet_abi"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
|
|
|
@ -5,5 +5,6 @@ license = "Apache-2.0"
|
|||
name = "wallet_contract_caller_script"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
wallet_abi = { path = "../wallet_abi" }
|
||||
|
|
|
@ -5,5 +5,6 @@ license = "Apache-2.0"
|
|||
name = "wallet_smart_contract"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../sway-lib-core" }
|
||||
std = { path = "../../sway-lib-std" }
|
||||
wallet_abi = { path = "../wallet_abi" }
|
||||
|
|
|
@ -2829,14 +2829,18 @@ mod test {
|
|||
let build_plan = setup_build_plan();
|
||||
let result = build_plan.visualize(Some("some-prefix::".to_string()));
|
||||
let re = Regex::new(r#"digraph \{
|
||||
0 \[ label = "test_contract" shape = box URL = "some-prefix::/[[:ascii:]]+/test_contract/Forc.toml"\]
|
||||
1 \[ label = "test_lib" shape = box URL = "some-prefix::/[[:ascii:]]+/test_lib/Forc.toml"\]
|
||||
2 \[ label = "test_script" shape = box URL = "some-prefix::/[[:ascii:]]+/test_script/Forc.toml"\]
|
||||
2 -> 1 \[ \]
|
||||
2 -> 0 \[ \]
|
||||
0 -> 1 \[ \]
|
||||
0 \[ label = "core" shape = box URL = "some-prefix::[[:ascii:]]+/sway-lib-core/Forc.toml"\]
|
||||
1 \[ label = "test_contract" shape = box URL = "some-prefix::/[[:ascii:]]+/test_contract/Forc.toml"\]
|
||||
2 \[ label = "test_lib" shape = box URL = "some-prefix::/[[:ascii:]]+/test_lib/Forc.toml"\]
|
||||
3 \[ label = "test_script" shape = box URL = "some-prefix::/[[:ascii:]]+/test_script/Forc.toml"\]
|
||||
3 -> 2 \[ \]
|
||||
3 -> 0 \[ \]
|
||||
3 -> 1 \[ \]
|
||||
1 -> 2 \[ \]
|
||||
1 -> 0 \[ \]
|
||||
\}
|
||||
"#).unwrap();
|
||||
dbg!(&result);
|
||||
assert!(!re.find(result.as_str()).unwrap().is_empty());
|
||||
}
|
||||
|
||||
|
@ -2845,12 +2849,15 @@ mod test {
|
|||
let build_plan = setup_build_plan();
|
||||
let result = build_plan.visualize(None);
|
||||
let expected = r#"digraph {
|
||||
0 [ label = "test_contract" shape = box ]
|
||||
1 [ label = "test_lib" shape = box ]
|
||||
2 [ label = "test_script" shape = box ]
|
||||
2 -> 1 [ ]
|
||||
2 -> 0 [ ]
|
||||
0 -> 1 [ ]
|
||||
0 [ label = "core" shape = box ]
|
||||
1 [ label = "test_contract" shape = box ]
|
||||
2 [ label = "test_lib" shape = box ]
|
||||
3 [ label = "test_script" shape = box ]
|
||||
3 -> 2 [ ]
|
||||
3 -> 0 [ ]
|
||||
3 -> 1 [ ]
|
||||
1 -> 2 [ ]
|
||||
1 -> 0 [ ]
|
||||
}
|
||||
"#;
|
||||
assert_eq!(expected, result);
|
||||
|
|
|
@ -81,6 +81,7 @@ pub struct Command {
|
|||
#[clap(long, verbatim_doc_comment, name = "JSON_FILE_PATH")]
|
||||
pub override_storage_slots: Option<String>,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ pub struct Command {
|
|||
#[clap(long)]
|
||||
pub args: Option<Vec<String>>,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ fn build_opts_from_cmd(cmd: &cmd::Deploy) -> pkg::BuildOpts {
|
|||
tests: false,
|
||||
member_filter: pkg::MemberFilter::only_contracts(),
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ fn build_opts_from_cmd(cmd: &cmd::Run) -> pkg::BuildOpts {
|
|||
tests: false,
|
||||
member_filter: pkg::MemberFilter::only_scripts(),
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ pub struct Command {
|
|||
#[cfg(test)]
|
||||
pub(crate) doc_path: Option<String>,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn main() -> Result<()> {
|
|||
&build_instructions,
|
||||
&get_doc_dir,
|
||||
sway_core::ExperimentalFlags {
|
||||
new_encoding: build_instructions.experimental_new_encoding,
|
||||
new_encoding: !build_instructions.no_encoding_v1,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ fn test_impl_traits_default() {
|
|||
assert_search_js(
|
||||
&doc_path,
|
||||
&expect![[r#"
|
||||
var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"fn.ok_str_eq.html","module_info":["core","ops"],"name":"ok_str_eq","preview":"","type_name":"function"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"},{"html_filename":"struct.Buffer.html","module_info":["core","codec"],"name":"Buffer","preview":"","type_name":"struct"},{"html_filename":"struct.BufferReader.html","module_info":["core","codec"],"name":"BufferReader","preview":"","type_name":"struct"},{"html_filename":"trait.AbiDecode.html","module_info":["core","codec"],"name":"AbiDecode","preview":"","type_name":"trait"},{"html_filename":"trait.AbiEncode.html","module_info":["core","codec"],"name":"AbiEncode","preview":"","type_name":"trait"},{"html_filename":"fn.encode.html","module_info":["core","codec"],"name":"encode","preview":"","type_name":"function"},{"html_filename":"fn.abi_decode.html","module_info":["core","codec"],"name":"abi_decode","preview":"","type_name":"function"},{"html_filename":"fn.contract_call.html","module_info":["core","codec"],"name":"contract_call","preview":"","type_name":"function"},{"html_filename":"fn.decode_script_data.html","module_info":["core","codec"],"name":"decode_script_data","preview":"","type_name":"function"},{"html_filename":"fn.decode_predicate_data.html","module_info":["core","codec"],"name":"decode_predicate_data","preview":"","type_name":"function"},{"html_filename":"fn.decode_first_param.html","module_info":["core","codec"],"name":"decode_first_param","preview":"","type_name":"function"},{"html_filename":"fn.decode_second_param.html","module_info":["core","codec"],"name":"decode_second_param","preview":"","type_name":"function"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
|
||||
var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"fn.ok_str_eq.html","module_info":["core","ops"],"name":"ok_str_eq","preview":"","type_name":"function"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"},{"html_filename":"struct.Buffer.html","module_info":["core","codec"],"name":"Buffer","preview":"","type_name":"struct"},{"html_filename":"struct.BufferReader.html","module_info":["core","codec"],"name":"BufferReader","preview":"","type_name":"struct"},{"html_filename":"trait.AbiDecode.html","module_info":["core","codec"],"name":"AbiDecode","preview":"","type_name":"trait"},{"html_filename":"trait.AbiEncode.html","module_info":["core","codec"],"name":"AbiEncode","preview":"","type_name":"trait"},{"html_filename":"fn.encode.html","module_info":["core","codec"],"name":"encode","preview":"","type_name":"function"},{"html_filename":"fn.abi_decode.html","module_info":["core","codec"],"name":"abi_decode","preview":"","type_name":"function"},{"html_filename":"fn.contract_call.html","module_info":["core","codec"],"name":"contract_call","preview":"","type_name":"function"},{"html_filename":"fn.decode_script_data.html","module_info":["core","codec"],"name":"decode_script_data","preview":"","type_name":"function"},{"html_filename":"fn.decode_predicate_data.html","module_info":["core","codec"],"name":"decode_predicate_data","preview":"","type_name":"function"},{"html_filename":"fn.decode_predicate_data_by_index.html","module_info":["core","codec"],"name":"decode_predicate_data_by_index","preview":"","type_name":"function"},{"html_filename":"fn.decode_first_param.html","module_info":["core","codec"],"name":"decode_first_param","preview":"","type_name":"function"},{"html_filename":"fn.decode_second_param.html","module_info":["core","codec"],"name":"decode_second_param","preview":"","type_name":"function"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
|
||||
"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=SEARCH_INDEX);"#]],
|
||||
);
|
||||
assert_file_tree(
|
||||
|
@ -56,6 +56,7 @@ fn test_impl_traits_default() {
|
|||
"core/codec/fn.abi_decode.html",
|
||||
"core/codec/fn.contract_call.html",
|
||||
"core/codec/fn.decode_predicate_data.html",
|
||||
"core/codec/fn.decode_predicate_data_by_index.html",
|
||||
"core/codec/fn.decode_first_param.html",
|
||||
"core/codec/fn.decode_script_data.html",
|
||||
"core/codec/fn.decode_second_param.html",
|
||||
|
|
|
@ -33,9 +33,9 @@ pub struct Command {
|
|||
#[clap(long)]
|
||||
pub tests: bool,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
/// Experimental flag for the "new encoding" feature
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn exec(command: Command) -> ForcResult<()> {
|
||||
|
|
|
@ -45,9 +45,9 @@ pub struct Command {
|
|||
#[clap(long)]
|
||||
pub ipfs_node: Option<IPFSNode>,
|
||||
|
||||
/// Set of experimental flags
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn exec(command: Command) -> ForcResult<()> {
|
||||
|
|
|
@ -29,9 +29,9 @@ pub struct Command {
|
|||
#[clap(flatten)]
|
||||
pub salt: Salt,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
/// Experimental flag for the "new encoding" feature
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
|
||||
|
|
|
@ -26,9 +26,9 @@ pub struct Command {
|
|||
#[clap(flatten)]
|
||||
pub build_profile: BuildProfile,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
/// Experimental flag for the "new encoding" feature
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
|
||||
|
|
|
@ -50,9 +50,9 @@ pub struct Command {
|
|||
/// threads available in your system.
|
||||
pub test_threads: Option<usize>,
|
||||
|
||||
/// Disable the "new encoding" feature
|
||||
#[clap(long)]
|
||||
/// Experimental flag for the "new encoding" feature
|
||||
pub experimental_new_encoding: bool,
|
||||
pub no_encoding_v1: bool,
|
||||
}
|
||||
|
||||
/// The set of options provided for controlling output of a test.
|
||||
|
@ -232,7 +232,7 @@ fn opts_from_cmd(cmd: Command) -> forc_test::TestOpts {
|
|||
debug_outfile: cmd.build.output.debug_file,
|
||||
build_target: cmd.build.build_target,
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ fn opts_from_cmd(cmd: BuildCommand) -> pkg::BuildOpts {
|
|||
tests: cmd.tests,
|
||||
member_filter: Default::default(),
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyP
|
|||
locked,
|
||||
disable_tests,
|
||||
ipfs_node,
|
||||
experimental_new_encoding,
|
||||
no_encoding_v1,
|
||||
} = command;
|
||||
|
||||
let this_dir = if let Some(ref path) = path {
|
||||
|
@ -45,7 +45,7 @@ pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyP
|
|||
engines,
|
||||
None,
|
||||
ExperimentalFlags {
|
||||
new_encoding: experimental_new_encoding,
|
||||
new_encoding: !no_encoding_v1,
|
||||
},
|
||||
)?;
|
||||
let (res, handler) = v
|
||||
|
|
|
@ -80,7 +80,7 @@ fn build_opts_from_cmd(cmd: &ContractIdCommand) -> pkg::BuildOpts {
|
|||
tests: false,
|
||||
member_filter: pkg::MemberFilter::only_contracts(),
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ fn build_opts_from_cmd(cmd: PredicateRootCommand) -> pkg::BuildOpts {
|
|||
tests: false,
|
||||
member_filter: pkg::MemberFilter::only_predicates(),
|
||||
experimental: ExperimentalFlags {
|
||||
new_encoding: cmd.experimental_new_encoding,
|
||||
new_encoding: !cmd.no_encoding_v1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,9 +244,13 @@ pub(crate) fn compile_constant_expression_to_constant(
|
|||
// Special case functions because the span in `const_expr` is to the inlined function
|
||||
// definition, rather than the actual call site.
|
||||
ty::TyExpressionVariant::FunctionApplication { call_path, .. } => {
|
||||
Err(CompileError::NonConstantDeclValue {
|
||||
span: call_path.span(),
|
||||
})
|
||||
let span = call_path.span();
|
||||
let span = if span == Span::dummy() {
|
||||
const_expr.span.clone()
|
||||
} else {
|
||||
span
|
||||
};
|
||||
Err(CompileError::NonConstantDeclValue { span })
|
||||
}
|
||||
_otherwise => Err(CompileError::NonConstantDeclValue {
|
||||
span: const_expr.span.clone(),
|
||||
|
|
|
@ -95,12 +95,15 @@ pub(crate) fn check_function_purity(
|
|||
});
|
||||
};
|
||||
let warn = |span, purity: Purity| {
|
||||
handler.emit_warn(CompileWarning {
|
||||
warning_content: Warning::DeadStorageDeclarationForFunction {
|
||||
unneeded_attrib: purity.to_attribute_syntax(),
|
||||
},
|
||||
span,
|
||||
});
|
||||
// Do not warn on generated code
|
||||
if span != Span::dummy() {
|
||||
handler.emit_warn(CompileWarning {
|
||||
warning_content: Warning::DeadStorageDeclarationForFunction {
|
||||
unneeded_attrib: purity.to_attribute_syntax(),
|
||||
},
|
||||
span,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
match (attributed_purity, reads, writes) {
|
||||
|
|
|
@ -44,6 +44,18 @@ fn get_type_not_allowed_error(
|
|||
})
|
||||
}
|
||||
|
||||
fn check_no_ref_main(engines: &Engines, handler: &Handler, main_function: &DeclId<TyFunctionDecl>) {
|
||||
let main_function = engines.de().get_function(main_function);
|
||||
for param in &main_function.parameters {
|
||||
if param.is_reference && param.is_mutable {
|
||||
handler.emit_err(CompileError::RefMutableNotAllowedInMain {
|
||||
param_name: param.name.clone(),
|
||||
span: param.name.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TyProgram {
|
||||
/// Validate the root module given the expected program kind.
|
||||
pub fn validate_root(
|
||||
|
@ -237,7 +249,11 @@ impl TyProgram {
|
|||
|
||||
TyProgramKind::Contract {
|
||||
entry_function: if experimental.new_encoding {
|
||||
assert!(entries.len() == 1);
|
||||
if entries.len() != 1 {
|
||||
return Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}));
|
||||
}
|
||||
Some(entries[0])
|
||||
} else {
|
||||
None
|
||||
|
@ -276,8 +292,15 @@ impl TyProgram {
|
|||
return Err(last_error.unwrap());
|
||||
}
|
||||
|
||||
// check if no ref mut arguments passed to a `main()` in a `script` or `predicate`.
|
||||
check_no_ref_main(engines, handler, &mains[0]);
|
||||
|
||||
let (entry_fn_id, main_fn_id) = if experimental.new_encoding {
|
||||
assert!(entries.len() == 1);
|
||||
if entries.len() != 1 {
|
||||
return Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}));
|
||||
}
|
||||
(entries[0], mains[0])
|
||||
} else {
|
||||
assert!(entries.is_empty());
|
||||
|
@ -318,8 +341,15 @@ impl TyProgram {
|
|||
return Err(last_error.unwrap());
|
||||
}
|
||||
|
||||
// check if no ref mut arguments passed to a `main()` in a `script` or `predicate`.
|
||||
check_no_ref_main(engines, handler, &mains[0]);
|
||||
|
||||
let (entry_fn_id, main_fn_id) = if experimental.new_encoding {
|
||||
assert!(entries.len() == 1);
|
||||
if entries.len() != 1 {
|
||||
return Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}));
|
||||
}
|
||||
(entries[0], mains[0])
|
||||
} else {
|
||||
assert!(entries.is_empty());
|
||||
|
@ -380,23 +410,6 @@ impl TyProgram {
|
|||
}
|
||||
};
|
||||
|
||||
// check if no ref mut arguments passed to a `main()` in a `script` or `predicate`.
|
||||
match &typed_program_kind {
|
||||
TyProgramKind::Script { main_function, .. }
|
||||
| TyProgramKind::Predicate { main_function, .. } => {
|
||||
let main_function = decl_engine.get_function(main_function);
|
||||
for param in &main_function.parameters {
|
||||
if param.is_reference && param.is_mutable {
|
||||
handler.emit_err(CompileError::RefMutableNotAllowedInMain {
|
||||
param_name: param.name.clone(),
|
||||
span: param.name.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
//configurables and constant cannot be str slice
|
||||
for c in configurables.iter() {
|
||||
if let Some(error) = get_type_not_allowed_error(
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::{
|
|||
semantic_analysis::TypeCheckContext,
|
||||
Engines, TypeId, TypeInfo, TypeParameter,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use sway_error::{
|
||||
error::CompileError,
|
||||
handler::{ErrorEmitted, Handler},
|
||||
|
@ -186,31 +185,39 @@ where
|
|||
code
|
||||
}
|
||||
|
||||
fn generate_abi_decode_struct_body(&self, engines: &Engines, decl: &TyStructDecl) -> String {
|
||||
fn generate_abi_decode_struct_body(
|
||||
&self,
|
||||
engines: &Engines,
|
||||
decl: &TyStructDecl,
|
||||
) -> Option<String> {
|
||||
let mut code = String::new();
|
||||
for f in decl.fields.iter() {
|
||||
code.push_str(&format!(
|
||||
"{field_name}: buffer.decode::<{field_type_name}>(),",
|
||||
field_name = f.name.as_str(),
|
||||
field_type_name = Self::generate_type(engines, f.type_argument.type_id),
|
||||
field_type_name = Self::generate_type(engines, f.type_argument.type_id)?,
|
||||
));
|
||||
}
|
||||
|
||||
format!("Self {{ {code} }}")
|
||||
Some(format!("Self {{ {code} }}"))
|
||||
}
|
||||
|
||||
fn generate_abi_decode_enum_body(&self, engines: &Engines, decl: &TyEnumDecl) -> String {
|
||||
fn generate_abi_decode_enum_body(
|
||||
&self,
|
||||
engines: &Engines,
|
||||
decl: &TyEnumDecl,
|
||||
) -> Option<String> {
|
||||
let enum_name = decl.call_path.suffix.as_str();
|
||||
let arms = decl.variants.iter()
|
||||
.map(|x| {
|
||||
let name = x.name.as_str();
|
||||
match &*engines.te().get(x.type_argument.type_id) {
|
||||
Some(match &*engines.te().get(x.type_argument.type_id) {
|
||||
// unit
|
||||
TypeInfo::Tuple(fiels) if fiels.is_empty() => {
|
||||
format!("{} => {}::{}, \n", x.tag, enum_name, name)
|
||||
},
|
||||
_ => {
|
||||
let variant_type_name = Self::generate_type(engines, x.type_argument.type_id);
|
||||
let variant_type_name = Self::generate_type(engines, x.type_argument.type_id)?;
|
||||
format!("{tag_value} => {enum_name}::{variant_name}(buffer.decode::<{variant_type}>()), \n",
|
||||
tag_value = x.tag,
|
||||
enum_name = enum_name,
|
||||
|
@ -218,19 +225,23 @@ where
|
|||
variant_type = variant_type_name
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect::<String>();
|
||||
.collect::<Option<String>>()?;
|
||||
|
||||
use std::fmt::Write;
|
||||
let mut code = String::new();
|
||||
writeln!(&mut code, "let variant: u64 = buffer.decode::<u64>();").unwrap();
|
||||
writeln!(&mut code, "match variant {{ {arms} _ => __revert(0), }}").unwrap();
|
||||
|
||||
code
|
||||
Some(code)
|
||||
}
|
||||
|
||||
fn generate_abi_encode_enum_body(&self, engines: &Engines, decl: &TyEnumDecl) -> String {
|
||||
if decl.variants.is_empty() {
|
||||
return "".into();
|
||||
}
|
||||
|
||||
let enum_name = decl.call_path.suffix.as_str();
|
||||
let arms = decl
|
||||
.variants
|
||||
|
@ -391,10 +402,10 @@ where
|
|||
&mut self,
|
||||
engines: &Engines,
|
||||
decl: &TyDecl,
|
||||
) -> (Option<TyAstNode>, Option<TyAstNode>) {
|
||||
) -> Option<(Option<TyAstNode>, Option<TyAstNode>)> {
|
||||
if matches!(self.ctx.namespace.root().module.read(engines, |m| m.name.clone()).as_ref(), Some(x) if x.as_str() == "core")
|
||||
{
|
||||
return (None, None);
|
||||
return Some((None, None));
|
||||
}
|
||||
|
||||
let implementing_for_decl_ref = decl.get_struct_decl_ref().unwrap();
|
||||
|
@ -415,22 +426,22 @@ where
|
|||
let abi_decode_code = self.generate_abi_decode_code(
|
||||
struct_decl.name(),
|
||||
&struct_decl.type_parameters,
|
||||
abi_decode_body,
|
||||
abi_decode_body?,
|
||||
);
|
||||
let abi_decode_node =
|
||||
self.parse_impl_trait_to_ty_ast_node(engines, module_id, &abi_decode_code);
|
||||
|
||||
(abi_encode_node.ok(), abi_decode_node.ok())
|
||||
Some((abi_encode_node.ok(), abi_decode_node.ok()))
|
||||
}
|
||||
|
||||
fn auto_impl_enum(
|
||||
&mut self,
|
||||
engines: &Engines,
|
||||
decl: &TyDecl,
|
||||
) -> (Option<TyAstNode>, Option<TyAstNode>) {
|
||||
) -> Option<(Option<TyAstNode>, Option<TyAstNode>)> {
|
||||
if matches!(self.ctx.namespace.root().module.read(engines, |m| m.name.clone()).as_ref(), Some(x) if x.as_str() == "core")
|
||||
{
|
||||
return (None, None);
|
||||
return Some((None, None));
|
||||
}
|
||||
|
||||
let enum_decl_ref = decl.get_enum_decl_ref().unwrap();
|
||||
|
@ -451,12 +462,12 @@ where
|
|||
let abi_decode_code = self.generate_abi_decode_code(
|
||||
enum_decl.name(),
|
||||
&enum_decl.type_parameters,
|
||||
abi_decode_body,
|
||||
abi_decode_body?,
|
||||
);
|
||||
let abi_decode_node =
|
||||
self.parse_impl_trait_to_ty_ast_node(engines, module_id, &abi_decode_code);
|
||||
|
||||
(abi_encode_node.ok(), abi_decode_node.ok())
|
||||
Some((abi_encode_node.ok(), abi_decode_node.ok()))
|
||||
}
|
||||
|
||||
pub fn generate(
|
||||
|
@ -465,14 +476,14 @@ where
|
|||
decl: &ty::TyDecl,
|
||||
) -> (Option<TyAstNode>, Option<TyAstNode>) {
|
||||
match decl {
|
||||
TyDecl::StructDecl(_) => self.auto_impl_struct(engines, decl),
|
||||
TyDecl::EnumDecl(_) => self.auto_impl_enum(engines, decl),
|
||||
TyDecl::StructDecl(_) => self.auto_impl_struct(engines, decl).unwrap_or((None, None)),
|
||||
TyDecl::EnumDecl(_) => self.auto_impl_enum(engines, decl).unwrap_or((None, None)),
|
||||
_ => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_type(engines: &Engines, type_id: TypeId) -> String {
|
||||
match &*engines.te().get(type_id) {
|
||||
fn generate_type(engines: &Engines, type_id: TypeId) -> Option<String> {
|
||||
let name = match &*engines.te().get(type_id) {
|
||||
TypeInfo::UnknownGeneric { name, .. } => name.to_string(),
|
||||
TypeInfo::Placeholder(type_param) => type_param.name_ident.to_string(),
|
||||
TypeInfo::StringSlice => "str".into(),
|
||||
|
@ -492,12 +503,12 @@ where
|
|||
} => call_path.call_path.suffix.to_string(),
|
||||
TypeInfo::Tuple(fields) => {
|
||||
if fields.is_empty() {
|
||||
return "()".into();
|
||||
return Some("()".into());
|
||||
}
|
||||
let field_strs = fields
|
||||
.iter()
|
||||
.map(|field| Self::generate_type(engines, field.type_id))
|
||||
.collect::<Vec<_>>();
|
||||
.collect::<Option<Vec<String>>>()?;
|
||||
format!("({},)", field_strs.join(", "))
|
||||
}
|
||||
TypeInfo::B256 => "b256".into(),
|
||||
|
@ -508,6 +519,7 @@ where
|
|||
.type_parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_id))
|
||||
.collect::<Option<Vec<String>>>()?
|
||||
.join(", ");
|
||||
|
||||
let type_parameters = if !type_parameters.is_empty() {
|
||||
|
@ -525,6 +537,7 @@ where
|
|||
.type_parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_id))
|
||||
.collect::<Option<Vec<String>>>()?
|
||||
.join(", ");
|
||||
|
||||
let type_parameters = if !type_parameters.is_empty() {
|
||||
|
@ -538,15 +551,17 @@ where
|
|||
TypeInfo::Array(elem_ty, count) => {
|
||||
format!(
|
||||
"[{}; {}]",
|
||||
Self::generate_type(engines, elem_ty.type_id),
|
||||
Self::generate_type(engines, elem_ty.type_id)?,
|
||||
count.val()
|
||||
)
|
||||
}
|
||||
TypeInfo::RawUntypedPtr => "raw_ptr".into(),
|
||||
TypeInfo::RawUntypedSlice => "raw_slice".into(),
|
||||
TypeInfo::Alias { name, .. } => name.to_string(),
|
||||
_ => todo!(),
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(name)
|
||||
}
|
||||
|
||||
pub(crate) fn generate_contract_entry(
|
||||
|
@ -575,13 +590,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let args_types = itertools::intersperse(
|
||||
decl.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id)),
|
||||
", ".into(),
|
||||
)
|
||||
.collect::<String>();
|
||||
let Some(args_types) = decl
|
||||
.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id))
|
||||
.collect::<Option<Vec<String>>>()
|
||||
else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
let args_types = itertools::intersperse(args_types, ", ".into()).collect::<String>();
|
||||
|
||||
let args_types = if args_types.is_empty() {
|
||||
"()".into()
|
||||
|
@ -598,7 +618,12 @@ where
|
|||
)
|
||||
.collect::<String>();
|
||||
|
||||
let return_type = Self::generate_type(engines, decl.return_type.type_id);
|
||||
let Some(return_type) = Self::generate_type(engines, decl.return_type.type_id) else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
|
||||
let method_name = decl.name.as_str();
|
||||
|
||||
|
@ -626,7 +651,13 @@ where
|
|||
|
||||
let fallback = if let Some(fallback_fn) = fallback_fn {
|
||||
let fallback_fn = engines.de().get(&fallback_fn);
|
||||
let return_type = Self::generate_type(engines, fallback_fn.return_type.type_id);
|
||||
let Some(return_type) = Self::generate_type(engines, fallback_fn.return_type.type_id)
|
||||
else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
let method_name = fallback_fn.name.as_str();
|
||||
|
||||
format!("let result: raw_slice = encode::<{return_type}>({method_name}()); __contract_ret(result.ptr(), result.len::<u8>());")
|
||||
|
@ -649,8 +680,9 @@ where
|
|||
match entry_fn {
|
||||
Ok(entry_fn) => Ok(entry_fn),
|
||||
Err(gen_handler) => {
|
||||
handler.append(gen_handler);
|
||||
Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
Self::check_impl_is_missing(handler, &gen_handler);
|
||||
Self::check_core_is_missing(handler, &gen_handler);
|
||||
Err(gen_handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}))
|
||||
}
|
||||
|
@ -665,13 +697,18 @@ where
|
|||
) -> Result<TyAstNode, ErrorEmitted> {
|
||||
let module_id = decl.span.source_id().map(|sid| sid.module_id());
|
||||
|
||||
let args_types = itertools::intersperse(
|
||||
decl.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id)),
|
||||
", ".into(),
|
||||
)
|
||||
.collect::<String>();
|
||||
let Some(args_types) = decl
|
||||
.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id))
|
||||
.collect::<Option<Vec<String>>>()
|
||||
else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
let args_types = itertools::intersperse(args_types, ", ".into()).collect::<String>();
|
||||
|
||||
let expanded_args = itertools::intersperse(
|
||||
decl.parameters
|
||||
|
@ -700,14 +737,47 @@ where
|
|||
match entry_fn {
|
||||
Ok(entry_fn) => Ok(entry_fn),
|
||||
Err(gen_handler) => {
|
||||
handler.append(gen_handler);
|
||||
Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
Self::check_impl_is_missing(handler, &gen_handler);
|
||||
Self::check_core_is_missing(handler, &gen_handler);
|
||||
Err(gen_handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check core is missing and give a more user-friendly error message.
|
||||
fn check_core_is_missing(handler: &Handler, gen_handler: &Handler) {
|
||||
let encode_not_found = gen_handler
|
||||
.find_error(|x| matches!(x, CompileError::SymbolNotFound { .. }))
|
||||
.is_some();
|
||||
if encode_not_found {
|
||||
handler.emit_err(CompileError::CouldNotGenerateEntryMissingCore {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Check cannot encode or decode type
|
||||
fn check_impl_is_missing(handler: &Handler, gen_handler: &Handler) {
|
||||
let constraint_not_satisfied = gen_handler.find_error(|x| {
|
||||
matches!(x, CompileError::TraitConstraintNotSatisfied { trait_name, .. }
|
||||
if trait_name == "AbiEncode" || trait_name == "AbiDecode" && {
|
||||
true
|
||||
})
|
||||
});
|
||||
if let Some(constraint_not_satisfied) = constraint_not_satisfied {
|
||||
let ty = match constraint_not_satisfied {
|
||||
CompileError::TraitConstraintNotSatisfied { ty, .. } => ty,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
handler.emit_err(CompileError::CouldNotGenerateEntryMissingImpl {
|
||||
ty,
|
||||
span: Span::dummy(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn generate_script_entry(
|
||||
&mut self,
|
||||
engines: &Engines,
|
||||
|
@ -716,14 +786,18 @@ where
|
|||
) -> Result<TyAstNode, ErrorEmitted> {
|
||||
let module_id = decl.span.source_id().map(|sid| sid.module_id());
|
||||
|
||||
let args_types = itertools::intersperse(
|
||||
decl.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id)),
|
||||
", ".into(),
|
||||
)
|
||||
.collect::<String>();
|
||||
|
||||
let Some(args_types) = decl
|
||||
.parameters
|
||||
.iter()
|
||||
.map(|x| Self::generate_type(engines, x.type_argument.type_id))
|
||||
.collect::<Option<Vec<String>>>()
|
||||
else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
let args_types = itertools::intersperse(args_types, ", ".into()).collect::<String>();
|
||||
let args_types = if args_types.is_empty() {
|
||||
"()".into()
|
||||
} else {
|
||||
|
@ -739,7 +813,12 @@ where
|
|||
)
|
||||
.collect::<String>();
|
||||
|
||||
let return_type = Self::generate_type(engines, decl.return_type.type_id);
|
||||
let Some(return_type) = Self::generate_type(engines, decl.return_type.type_id) else {
|
||||
let err = handler.emit_err(CompileError::UnknownType {
|
||||
span: Span::dummy(),
|
||||
});
|
||||
return Err(err);
|
||||
};
|
||||
|
||||
let code = if args_types == "()" {
|
||||
format!(
|
||||
|
@ -764,8 +843,9 @@ where
|
|||
match entry_fn {
|
||||
Ok(entry_fn) => Ok(entry_fn),
|
||||
Err(gen_handler) => {
|
||||
handler.append(gen_handler);
|
||||
Err(handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
Self::check_core_is_missing(handler, &gen_handler);
|
||||
Self::check_impl_is_missing(handler, &gen_handler);
|
||||
Err(gen_handler.emit_err(CompileError::CouldNotGenerateEntry {
|
||||
span: Span::dummy(),
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -278,20 +278,12 @@ impl TyDecl {
|
|||
Err(err) => return Ok(ty::TyDecl::ErrorRecovery(span, err)),
|
||||
};
|
||||
|
||||
// if this ImplTrait implements a trait and not an ABI,
|
||||
// we insert its methods into the context
|
||||
// otherwise, if it implements an ABI,
|
||||
// we insert its methods with a prefix
|
||||
let emp_vec = vec![];
|
||||
let impl_trait_items = if let Ok(ty::TyDecl::TraitDecl { .. }) =
|
||||
ctx.namespace().resolve_call_path_typed(
|
||||
&Handler::default(),
|
||||
engines,
|
||||
&impl_trait.trait_name,
|
||||
ctx.self_type(),
|
||||
) {
|
||||
&impl_trait.items
|
||||
} else {
|
||||
// Insert prefixed symbols when implementing_for is Contract
|
||||
let is_contract = engines
|
||||
.te()
|
||||
.get(impl_trait.implementing_for.type_id)
|
||||
.is_contract();
|
||||
if is_contract {
|
||||
for i in &impl_trait.items {
|
||||
if let ty::TyTraitItem::Fn(f) = i {
|
||||
let decl = engines.de().get(f.id());
|
||||
|
@ -314,8 +306,22 @@ impl TyDecl {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&emp_vec
|
||||
// Choose which items are going to be visible depending if this is an abi impl
|
||||
// or trait impl
|
||||
let t = ctx.namespace().resolve_call_path_typed(
|
||||
&Handler::default(),
|
||||
engines,
|
||||
&impl_trait.trait_name,
|
||||
ctx.self_type(),
|
||||
);
|
||||
|
||||
let empty_vec = vec![];
|
||||
let impl_trait_items = if let Ok(ty::TyDecl::TraitDecl { .. }) = t {
|
||||
&impl_trait.items
|
||||
} else {
|
||||
&empty_vec
|
||||
};
|
||||
|
||||
ctx.insert_trait_implementation(
|
||||
|
|
|
@ -84,6 +84,10 @@ fn analyze_contract(engines: &Engines, ast_nodes: &[ty::TyAstNode]) -> Vec<Compi
|
|||
let decl_engine = engines.de();
|
||||
let mut warnings: Vec<CompileWarning> = vec![];
|
||||
for fn_decl in contract_entry_points(decl_engine, ast_nodes) {
|
||||
// no need to analyze the entry fn
|
||||
if fn_decl.name.as_str() == "__entry" {
|
||||
continue;
|
||||
}
|
||||
analyze_code_block(engines, &fn_decl.body, &fn_decl.name, &mut warnings);
|
||||
}
|
||||
warnings
|
||||
|
@ -608,10 +612,12 @@ fn effects_of_intrinsic(intr: &sway_ast::Intrinsic) -> HashSet<Effect> {
|
|||
StateClear | StateStoreWord | StateStoreQuad => HashSet::from([Effect::StorageWrite]),
|
||||
StateLoadWord | StateLoadQuad => HashSet::from([Effect::StorageRead]),
|
||||
Smo => HashSet::from([Effect::OutputMessage]),
|
||||
ContractCall => HashSet::from([Effect::Interaction]),
|
||||
Revert | JmpMem | IsReferenceType | IsStrArray | SizeOfType | SizeOfVal | SizeOfStr
|
||||
| ContractCall | ContractRet | AssertIsStrArray | ToStrArray | Eq | Gt | Lt | Gtf
|
||||
| AddrOf | Log | Add | Sub | Mul | Div | And | Or | Xor | Mod | Rsh | Lsh | PtrAdd
|
||||
| PtrSub | Not => HashSet::new(),
|
||||
| ContractRet | AssertIsStrArray | ToStrArray | Eq | Gt | Lt | Gtf | AddrOf | Log | Add
|
||||
| Sub | Mul | Div | And | Or | Xor | Mod | Rsh | Lsh | PtrAdd | PtrSub | Not => {
|
||||
HashSet::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,22 +329,24 @@ impl ty::TyModule {
|
|||
(TreeType::Predicate, true) => {
|
||||
let mut fn_generator =
|
||||
auto_impl::EncodingAutoImplContext::new(&mut ctx).unwrap();
|
||||
let node = fn_generator.generate_predicate_entry(
|
||||
if let Ok(node) = fn_generator.generate_predicate_entry(
|
||||
engines,
|
||||
main_decl.as_ref().unwrap(),
|
||||
handler,
|
||||
)?;
|
||||
all_nodes.push(node)
|
||||
) {
|
||||
all_nodes.push(node)
|
||||
}
|
||||
}
|
||||
(TreeType::Script, true) => {
|
||||
let mut fn_generator =
|
||||
auto_impl::EncodingAutoImplContext::new(&mut ctx).unwrap();
|
||||
let node = fn_generator.generate_script_entry(
|
||||
if let Ok(node) = fn_generator.generate_script_entry(
|
||||
engines,
|
||||
main_decl.as_ref().unwrap(),
|
||||
handler,
|
||||
)?;
|
||||
all_nodes.push(node)
|
||||
) {
|
||||
all_nodes.push(node)
|
||||
}
|
||||
}
|
||||
(TreeType::Contract, _) => {
|
||||
// collect all contract methods
|
||||
|
@ -357,14 +359,15 @@ impl ty::TyModule {
|
|||
|
||||
let mut fn_generator =
|
||||
auto_impl::EncodingAutoImplContext::new(&mut ctx).unwrap();
|
||||
let node = fn_generator.generate_contract_entry(
|
||||
if let Ok(node) = fn_generator.generate_contract_entry(
|
||||
engines,
|
||||
parsed.span.source_id().map(|x| x.module_id()),
|
||||
&contract_fns,
|
||||
fallback_fn,
|
||||
handler,
|
||||
)?;
|
||||
all_nodes.push(node)
|
||||
) {
|
||||
all_nodes.push(node)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -1164,6 +1164,10 @@ impl TypeInfo {
|
|||
matches!(self, TypeInfo::Array(_, _))
|
||||
}
|
||||
|
||||
pub fn is_contract(&self) -> bool {
|
||||
matches!(self, TypeInfo::Contract)
|
||||
}
|
||||
|
||||
pub fn is_struct(&self) -> bool {
|
||||
matches!(self, TypeInfo::Struct(_))
|
||||
}
|
||||
|
|
|
@ -887,8 +887,12 @@ pub enum CompileError {
|
|||
FallbackFnsAreContractOnly { span: Span },
|
||||
#[error("Fallback functions cannot have parameters")]
|
||||
FallbackFnsCannotHaveParameters { span: Span },
|
||||
#[error("Could not generate the entry method because one of the arguments does not implement AbiEncode/AbiDecode")]
|
||||
#[error("Could not generate the entry method. See errors above for more details.")]
|
||||
CouldNotGenerateEntry { span: Span },
|
||||
#[error("Missing `core` in dependencies.")]
|
||||
CouldNotGenerateEntryMissingCore { span: Span },
|
||||
#[error("Type \"{ty}\" does not implement AbiEncode or AbiDecode.")]
|
||||
CouldNotGenerateEntryMissingImpl { ty: String, span: Span },
|
||||
}
|
||||
|
||||
impl std::convert::From<TypeError> for CompileError {
|
||||
|
@ -1092,6 +1096,8 @@ impl Spanned for CompileError {
|
|||
FallbackFnsAreContractOnly { span } => span.clone(),
|
||||
FallbackFnsCannotHaveParameters { span } => span.clone(),
|
||||
CouldNotGenerateEntry { span } => span.clone(),
|
||||
CouldNotGenerateEntryMissingCore { span } => span.clone(),
|
||||
CouldNotGenerateEntryMissingImpl { span, .. } => span.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@ impl Handler {
|
|||
!self.inner.borrow().errors.is_empty()
|
||||
}
|
||||
|
||||
pub fn find_error(&self, f: impl FnMut(&&CompileError) -> bool) -> Option<CompileError> {
|
||||
self.inner.borrow().errors.iter().find(f).cloned()
|
||||
}
|
||||
|
||||
pub fn has_warnings(&self) -> bool {
|
||||
!self.inner.borrow().warnings.is_empty()
|
||||
}
|
||||
|
|
|
@ -8,6 +8,36 @@ pub struct Buffer {
|
|||
size: u64,
|
||||
}
|
||||
|
||||
enum IncreaseBuffer {
|
||||
None: (),
|
||||
NewBuffer: (raw_ptr, u64), // ptr, capacity
|
||||
}
|
||||
|
||||
fn increase_buffer_if_needed(
|
||||
current_ptr: raw_ptr,
|
||||
current_cap: u64,
|
||||
needed_capacity: u64,
|
||||
) -> IncreaseBuffer {
|
||||
if current_cap <= needed_capacity {
|
||||
// smallest buffer that is a multiple of the current one
|
||||
// that fits the needed capacity
|
||||
let factor = needed_capacity / current_cap;
|
||||
let new_cap = current_cap * (factor + 1);
|
||||
let new_ptr = asm(
|
||||
current_ptr: current_ptr,
|
||||
current_cap: current_cap,
|
||||
new_cap: new_cap,
|
||||
) {
|
||||
aloc new_cap;
|
||||
mcp hp current_ptr current_cap;
|
||||
hp: raw_ptr
|
||||
};
|
||||
IncreaseBuffer::NewBuffer((new_ptr, new_cap))
|
||||
} else {
|
||||
IncreaseBuffer::None
|
||||
}
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
pub fn new() -> Self {
|
||||
let cap = 1024;
|
||||
|
@ -21,30 +51,44 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Push a byte into the buffer, increasing its size
|
||||
/// when needed.
|
||||
pub fn push_byte(ref mut self, val: u8) {
|
||||
let count = 1;
|
||||
if self.cap >= self.size + count {
|
||||
let ptr = self.buffer.add::<u8>(self.size);
|
||||
asm(ptr: ptr, val: val) {
|
||||
sb ptr val i0;
|
||||
};
|
||||
self.size += count;
|
||||
} else {
|
||||
__revert(123456789);
|
||||
let count = 1u64;
|
||||
|
||||
match increase_buffer_if_needed(self.buffer, self.cap, self.size + count) {
|
||||
IncreaseBuffer::None => {},
|
||||
IncreaseBuffer::NewBuffer((new_buffer, new_cap)) => {
|
||||
self.buffer = new_buffer;
|
||||
self.cap = new_cap;
|
||||
}
|
||||
}
|
||||
|
||||
let ptr = self.buffer.add::<u8>(self.size);
|
||||
asm(ptr: ptr, val: val) {
|
||||
sb ptr val i0;
|
||||
};
|
||||
self.size += count;
|
||||
}
|
||||
|
||||
/// Push a u64 into the buffer, increasing its size
|
||||
/// when needed.
|
||||
pub fn push_u64(ref mut self, val: u64) {
|
||||
let count = 8;
|
||||
if self.cap >= self.size + count {
|
||||
let ptr = self.buffer.add::<u8>(self.size);
|
||||
asm(ptr: ptr, val: val) {
|
||||
sw ptr val i0;
|
||||
};
|
||||
self.size += count;
|
||||
} else {
|
||||
__revert(123456789);
|
||||
let count = 8u64;
|
||||
|
||||
match increase_buffer_if_needed(self.buffer, self.cap, self.size + count) {
|
||||
IncreaseBuffer::None => {},
|
||||
IncreaseBuffer::NewBuffer((new_buffer, new_cap)) => {
|
||||
self.buffer = new_buffer;
|
||||
self.cap = new_cap;
|
||||
}
|
||||
}
|
||||
|
||||
let ptr = self.buffer.add::<u8>(self.size);
|
||||
asm(ptr: ptr, val: val) {
|
||||
sw ptr val i0;
|
||||
};
|
||||
self.size += count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +155,10 @@ impl BufferReader {
|
|||
gm r1 i3; // GET_VERIFYING_PREDICATE
|
||||
r1: u64
|
||||
};
|
||||
Self::from_predicate_data_by_index(predicate_index)
|
||||
}
|
||||
|
||||
pub fn from_predicate_data_by_index(predicate_index: u64) -> BufferReader {
|
||||
match __gtf::<u8>(predicate_index, 0x200) { // GTF_INPUT_TYPE
|
||||
0u8 => {
|
||||
let ptr = __gtf::<raw_ptr>(predicate_index, 0x20C); // INPUT_COIN_PREDICATE_DATA
|
||||
|
@ -1222,6 +1270,13 @@ impl AbiEncode for raw_slice {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> AbiEncode for [T; 0]
|
||||
where
|
||||
T: AbiEncode,
|
||||
{
|
||||
fn abi_encode(self, ref mut _buffer: Buffer) {}
|
||||
}
|
||||
|
||||
// BEGIN ARRAY_ENCODE
|
||||
impl<T> AbiEncode for [T; 1]
|
||||
where
|
||||
|
@ -5570,6 +5625,14 @@ where
|
|||
T::abi_decode(buffer)
|
||||
}
|
||||
|
||||
pub fn decode_predicate_data_by_index<T>(index: u64) -> T
|
||||
where
|
||||
T: AbiDecode,
|
||||
{
|
||||
let mut buffer = BufferReader::from_predicate_data_by_index(index);
|
||||
T::abi_decode(buffer)
|
||||
}
|
||||
|
||||
pub fn decode_first_param<T>() -> T
|
||||
where
|
||||
T: AbiDecode,
|
||||
|
|
|
@ -115,19 +115,23 @@ pub fn first_param() -> u64 {
|
|||
/// assert(param != 0);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn second_param<T>() -> T {
|
||||
if __size_of::<T>() == 1 {
|
||||
let v = frame_ptr().add::<u64>(SECOND_PARAMETER_OFFSET).read::<u64>();
|
||||
return asm(v: v) {
|
||||
v: T
|
||||
};
|
||||
}
|
||||
pub fn second_param() -> u64 {
|
||||
frame_ptr().add::<u64>(SECOND_PARAMETER_OFFSET).read()
|
||||
}
|
||||
|
||||
if !is_reference_type::<T>() {
|
||||
frame_ptr().add::<u64>(SECOND_PARAMETER_OFFSET).read::<T>()
|
||||
} else {
|
||||
frame_ptr().add::<u64>(SECOND_PARAMETER_OFFSET).read::<raw_ptr>().read::<T>()
|
||||
}
|
||||
/// Get the called method name from the current call frame.
|
||||
pub fn called_method() -> str {
|
||||
use core::codec::decode_first_param;
|
||||
decode_first_param::<str>()
|
||||
}
|
||||
|
||||
/// Get the called arguments from the current call frame.
|
||||
pub fn called_args<T>() -> T
|
||||
where
|
||||
T: AbiDecode,
|
||||
{
|
||||
use core::codec::decode_second_param;
|
||||
decode_second_param::<T>()
|
||||
}
|
||||
|
||||
// Accessing arbitrary call frames by pointer
|
||||
|
|
|
@ -255,11 +255,12 @@ pub fn input_predicate_data_pointer(index: u64) -> Option<raw_ptr> {
|
|||
/// assert(input_predicate_data == 100);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn input_predicate_data<T>(index: u64) -> T {
|
||||
match input_predicate_data_pointer(index) {
|
||||
Some(d) => d.read::<T>(),
|
||||
None => revert(0),
|
||||
}
|
||||
pub fn input_predicate_data<T>(index: u64) -> T
|
||||
where
|
||||
T: AbiDecode,
|
||||
{
|
||||
use core::codec::decode_predicate_data_by_index;
|
||||
decode_predicate_data_by_index::<T>(index)
|
||||
}
|
||||
|
||||
/// Gets the AssetId of the input at `index`.
|
||||
|
|
|
@ -82,7 +82,7 @@ pub(crate) async fn deploy_contract(file_name: &str, run_config: &RunConfig) ->
|
|||
true => BuildProfile::RELEASE.to_string(),
|
||||
false => BuildProfile::DEBUG.to_string(),
|
||||
},
|
||||
experimental_new_encoding: run_config.experimental.new_encoding,
|
||||
no_encoding_v1: !dbg!(run_config.experimental.new_encoding),
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
|
@ -125,7 +125,7 @@ pub(crate) async fn runs_on_node(
|
|||
},
|
||||
contract: Some(contracts),
|
||||
signing_key: Some(SecretKey::from_str(SECRET_KEY).unwrap()),
|
||||
experimental_new_encoding: run_config.experimental.new_encoding,
|
||||
no_encoding_v1: !run_config.experimental.new_encoding,
|
||||
..Default::default()
|
||||
};
|
||||
run(command).await.map(|ran_scripts| {
|
||||
|
|
|
@ -628,7 +628,7 @@ pub async fn run(filter_config: &FilterConfig, run_config: &RunConfig) -> Result
|
|||
// Be mindful that this can explode exponentially the number of tests
|
||||
// that run because one expansion expands on top of another
|
||||
let mut tests = tests;
|
||||
let expansions = ["new_encoding"];
|
||||
let expansions: [&str; 0] = [];
|
||||
for expansion in expansions {
|
||||
tests = tests
|
||||
.into_iter()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
category = "run"
|
||||
expected_result = { action = "revert", value = 0 }
|
||||
expected_result_new_encoding = { action = "revert", value = 0 }
|
||||
validate_abi = false
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
[[package]]
|
||||
name = 'array_oob'
|
||||
source = 'member'
|
||||
name = "array_oob"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
source = "path+from-root-B7F3BB0330F243C2"
|
||||
|
|
|
@ -4,3 +4,6 @@ license = "Apache-2.0"
|
|||
name = "array_oob"
|
||||
entry = "main.sw"
|
||||
implicit-std = false
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
script;
|
||||
|
||||
enum Result<T, E> {
|
||||
Ok: T,
|
||||
Err: E,
|
||||
}
|
||||
|
||||
// should return 5
|
||||
fn main() -> u64 {
|
||||
let result_a = Result::Ok::<u64, bool>(5u64);
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
[[package]]
|
||||
name = 'configurables_are_not_const'
|
||||
source = 'member'
|
||||
name = "configurables_are_not_const"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
source = "path+from-root-96EE05F4B3FB2E76"
|
||||
|
|
|
@ -4,3 +4,6 @@ entry = "main.sw"
|
|||
implicit-std = false
|
||||
license = "Apache-2.0"
|
||||
name = "configurables_are_not_const"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
[[package]]
|
||||
name = 'configurables_in_lib'
|
||||
source = 'member'
|
||||
name = "configurables_in_lib"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
source = "path+from-root-D4FAD531EAB9796D"
|
||||
|
|
|
@ -4,3 +4,6 @@ entry = "main.sw"
|
|||
implicit-std = false
|
||||
license = "Apache-2.0"
|
||||
name = "configurables_in_lib"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
[[package]]
|
||||
name = "const-instead-of-let"
|
||||
source = "member"
|
||||
dependencies = ["std"]
|
||||
dependencies = [
|
||||
"core",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
|
|
|
@ -5,4 +5,5 @@ license = "Apache-2.0"
|
|||
name = "const-instead-of-let"
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
std = { path = "../../../reduced_std_libs/sway-lib-std-assert" }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
category = "fail"
|
||||
|
||||
# check: $()error
|
||||
# check: const-instead-of-let/src/main.sw:13:38
|
||||
# check: const-instead-of-let/src/main.sw:13
|
||||
# check: $()const INVALID_CONST = contract_1.foo();
|
||||
# nextln: $()Could not evaluate initializer to a const declaration.
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
[[package]]
|
||||
name = 'const_eval_bad_struct'
|
||||
source = 'member'
|
||||
name = "const_eval_bad_struct"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
source = "path+from-root-37642B35B36048FC"
|
||||
|
|
|
@ -6,3 +6,4 @@ name = "const_eval_bad_struct"
|
|||
implicit-std = false
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
[[package]]
|
||||
name = 'const_eval_bad_struct_with_return'
|
||||
source = 'member'
|
||||
name = "const_eval_bad_struct_with_return"
|
||||
source = "member"
|
||||
dependencies = ["core"]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
source = "path+from-root-154BF654D5BA1912"
|
||||
|
|
|
@ -4,3 +4,6 @@ entry = "main.sw"
|
|||
license = "Apache-2.0"
|
||||
name = "const_eval_bad_struct_with_return"
|
||||
implicit-std = false
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../../../../../../sway-lib-core" }
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue