Commit graph

15 commits

Author SHA1 Message Date
SwayStar123
a5d9d2835f
Merge std and core libraries (#6729)
## Description
Merges the two libraries. They were initially separate to separate the
core logic and fuel vm specific functionality, but that separation is no
longer maintained so having a merged library is better.

Closes #6708

## 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.

---------

Co-authored-by: Sophie <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
2025-03-12 23:52:38 +01:00
Daniel Frederico Lins Leite
1aec319e31
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.
2024-04-25 20:37:50 +04:00
Mohammad Fawaz
1db8385158
Replace old storage API with the new one explained in the StorageKey RFC (#4464)
## Description
Implement https://github.com/FuelLabs/sway-rfcs/pull/23

Closes https://github.com/FuelLabs/sway/issues/3419 (technically via the
RFC)
Closes https://github.com/FuelLabs/sway/issues/3202
Closes https://github.com/FuelLabs/sway/issues/3043
Closes https://github.com/FuelLabs/sway/issues/2639
Closes https://github.com/FuelLabs/sway/issues/2465
Closes https://github.com/FuelLabs/sway/issues/4304

This is a big one but mostly removes stuff. It's hard to review but the
summary of changes below should be sufficient. Most of the changes here
are things that I just had to do to make CI pass.

- Removed the `--experimental-storage` flag and made its
[behavior](https://github.com/FuelLabs/sway/pull/4297) the default. Also
removed everything that was required for the previous storage APIs in
favour of the new ones.
- Break down the `std::storage` into multiple submodules:
 - `storage_key` implements the API for `std::core::StorageKey`
- `storage_api` implements the free functions `read` (previously `get`),
`write` (previously `store`), and `clear`.
- 4 more modules for the dynamic storage types which now use the new
`StorageKey` API.
- `#[storage(write)]` now allows reading from storage as well. This is
needed because the way we pack structs in storage now requires that we
sometimes read from storage first if we were to write a portion of a
slot.
- Removed the "storage only types" checks and the corresponding tests.
- Removed the `__get_storage_key` intrinsic and the `get_storage_key` IR
instruction and all corresponding tests. Also removed the `state_index`
metadata as it is no longer required.
- Added tests and example to showcase nested storage maps and nested
storage vectors.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] 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).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-04-21 07:36:40 -04:00
mitchmindtree
4ffa867b3d
refactor: Move the examples workspace manifest into examples directory. Use it in CI. (#4145)
## Description

This moves the examples workspace manifest introduced in #4118 into the
`examples/` directory and cleans it up a bit.

We also now integrate the examples workspace into CI, making the old
`examples-checker` script redundant. This old script is also removed as
a part of this PR.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] 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).
- [x] I have requested a review from the relevant team or maintainers.
2023-02-21 11:15:29 +11:00
Mohammad Fawaz
0a3beae92e
Update std::storage::get and std::storage::StorageMap::get to return an Option (#3862)
API change:
Previous:
```rust
pub fn get<T>(key: b256) -> T;
pub fn get(self, key: K) -> V;
```
Now:
```rust
pub fn get<T>(key: b256) -> Option<T>;
pub fn get(self, key: K) -> Option<V>;
```
`Option::None` indicates that the storage slot requested in not
available.

- Updated all storage intrinsics to return a `bool` except for
`__state_load_word` because it already returns the value loaded. The
`bool` returned represents the previous state of the storage slots as
described in the specs. I was not able to update `__state_load_word` to
return both the value loaded and the `bool` unfortunately because I hit
various hiccups along the way, particularly in IR/codegen.
- Updated `get` and `StorageMap::get` in the standard library to return
an `Option` based on the Boolean mentioned above. In the copy type case,
I had to use `asm` blocks instead of `__state_load_word` until we're
able to return a struct from an intrinsic.
- I did not update `store` and `StorageMap::insert` to return an
`Option`, for now, because that would involve an extra storage read to
return the previous value, if available. We can think about whether this
is worth it at some point.
- I added `unwrap` and `unwrap_or` where it makes sense in `StoargeVec`.
- Update various docs, examples, and tests.

Closes https://github.com/FuelLabs/sway/issues/3318

I will open separate issues for updating `__state_load_word` and
thinking about making `store` and `insert` also return an `Option`.
2023-01-24 14:00:17 +00:00
Mohammad Fawaz
d613be1f8f
Update lock files for all examples (#3307) 2022-11-06 20:29:02 -05:00
Mohammad Fawaz
cfecaf4c40
Generic trait From<T> in the standard library (#3241)
Closes #1078 

* New trait `From<T>` in a new library called `convert.rs`
* Most changes are trivial
* Added `From` to the prelude
* Had to modify `from()` in `U128`, `U256`, and `B512` to take a tuple
of components instead of multiple arguments to conform to the trait.
This is a breaking change of course.
* Updating lock files for all the examples.
2022-11-02 15:41:06 +00:00
Mohammad Fawaz
734ed89951
Minor enhancements to the Sway Book (#2741) 2022-09-07 22:39:03 -04:00
Chris O'Brien
3c83178581
Replace old formatter with new formatter (#2669)
* update plugin and swayfmt toml, remove old formatter

* update config to formatter for consistency

* wip fix lsp formatting

* more merge conflicts

* update dependencies to 22.1

* remove files that made it back in from merge

* comment out function in LSP that uses formatter

* format examples and remove debug printlns

* Merge #2669 (swayfmt replacement PR) with `master` including newline formatting fixes (#2698)

* refactor: forc-deploy requires wallet address and accepts signature (#2629)

* Add the `CopyTypes` trait to `DeclarationId` (#2682)

Co-authored-by: Toby Hutton <toby@grusly.com>

* fix: Unformatted comment spans add extra newline (#2692)

* newline handler checks for existing newlines before inserting new ones

* stability test added

* newline-comment handler interaction test added

* review suggestion

* feat: add basic comment context formatting (#2697)

* feat: add comment context formatting

* test: enhance newline-comment handler interaction test

* Apply suggestions from code review

Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>

Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>

* Update `examples/` for recent swayfmt-v2 patches

Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>

* change name to swayfmt, kashira

* add swayfmt file

* sort toml dependencies

* fix excess newlines in format_context

* test on examples

Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-09-02 11:40:00 -05:00
Nick Furfaro
f1632e5437
Furnic/revert b256 add (#1961)
* feat: Implement Add for b256

* modify: make U128 functions public

* feat: add b256_ops module to stdlib

* docs: add comments

* reorganize: move b256_ops tests to e2e harness

* test: stuff

* refactor: cleanup unneeded mut variables

* feat: add core-utils lib

* fixup

* refactor: use new lib for compostion

* chore: fix manifest project name

* refactor: rename module to compose

* cleanup

* refactor: rename to core_utils

* fixup

* chore: rename new lib and update manifests

* test: fix last assert

* docs: add module level docs

* fixup

* chore: remove and rebuild for lock files

* fixup

* test: cleanup

* chore: rebuild basic_predicate

* chore: rebuild

* fix: restore test project

* fix: add oracle file

* chore: rebuild sdk-harness tests

* Revert "Implement Add for b256 (#1707)"

This reverts commit 560ca4b4c6.

* chore: rebuild lockfiles
2022-06-13 16:05:16 -05:00
Toby Hutton
9fd4bb8434
Add checks to IR verification for invalid storage operations. (#1716)
Each instruction within a function is inspected and if storage
operations are found they are confirmed to match the function `storage`
attribute annotation.
2022-06-11 16:06:01 +10:00
Nick Furfaro
560ca4b4c6
Implement Add for b256 (#1707)
* feat: Implement Add for b256

* modify: make U128 functions public

* feat: add b256_ops module to stdlib

* docs: add comments

* reorganize: move b256_ops tests to e2e harness

* test: stuff

* refactor: cleanup unneeded mut variables

* feat: add core-utils lib

* fixup

* refactor: use new lib for compostion

* chore: fix manifest project name

* refactor: rename module to compose

* cleanup

* refactor: rename to core_utils

* fixup

* chore: rename new lib and update manifests

* test: fix last assert

* docs: add module level docs

* fixup

* chore: remove and rebuild for lock files

* fixup

* test: cleanup

* chore: rebuild basic_predicate

* chore: rebuild

* fix: restore test project

* fix: add oracle file

* chore: rebuild sdk-harness tests
2022-06-10 18:24:27 -07:00
mitchmindtree
fb4bc7a8ef
Disambiguate path dependencies using the ID of the package at the path root (#1790)
* Disambiguate `path` dependencies using the parent package ID

Implements and closes #1789.

TODO:

- [x] Disambiguate `path` dependencies using parent package ID.
- [ ] Impl `Display` and `FromStr` for `PinnedId` to convert it to and
  from hex for path source string in lock file.
- [ ] Address #1637 now to reduce this PR adding even more noise in the
  lock file `dependencies` lists.
- [ ] Refactor `fetch_deps` slightly to better accomodate new `Root`
  source variant.
- [ ] Update lock files of all examples and tests in repository.

* Swap `ToString` impls for `Display`. Add `PinnedId` impls.

Also removes the `lock::source_from_str/source_to_string` impls in
favour of implementing `Display` and `FromStr` for `SourcePinned`.

* Only disambiguate pkg lock dependencies if the name requires it

Closes #1637.

* Update new add_deps function for changes applied to pin_pkg

* Fix path dependency disambiguation using a path root rather than parent

Improves path dependency disambiguation by using the ID of the package
that is the root of the subgraph of path dependencies.

* Update `examples` forc lock files for path disambiguation changes

* Update E2E test forc lock files for path disambiguation changes

* Update stdlib test lock files for path dependency disambiguation changes

* Update new lock files introduced since previous rebase
2022-06-08 16:14:48 +10:00
John Adler
6a938534f3
Check examples formatting in CI (#1384)
* Make build-all-examples also check formatting.

* Install forc-fmt in CI.

* fmt examples

* Remove duplicate CI steps.

* Revert "Remove duplicate CI steps."

This reverts commit 8cbaaf1c43.

* Install forc-fmt prior to all build-all-examples.
2022-04-24 06:37:09 -04:00
Nick
bb264a6569
Expanding storage documentation (#1228)
* Expanding storage documentation

- Adding a small section on working with storage by-hand
- Adding work-around methods for storing b256 values

* Update storage.md

Small nit.

* Update docs/src/blockchain-development/storage.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/blockchain-development/storage.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/blockchain-development/storage.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update storage.md

* Update storage.md

* Update storage.md

Complex type note.

* Update comment.

* add to examples, cleanup storage comments

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Nicholas Dodson <nick@Nicholass-MacBook-Pro.local>
2022-04-14 16:38:56 -07:00