Commit graph

478 commits

Author SHA1 Message Date
Yash Jagtap
8fe2bd6ed2
fix: typos cleanup (#6799)
## Description
fixed 3 typos

## Checklist

- [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 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.
2025-01-06 11:38:00 +11:00
Matt
cf7b6664b5
docs: add sway memory model (#6775)
## Description
Developers get confused by Sway's memory model as it is different from
Rust's. So I added this to the docs.

closes https://app.asana.com/0/1207924201336629/1208429018056446

## Checklist

- [x] I have linked to any relevant issues.
- [ ] 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).
- [ ] 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.
- 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-12-20 10:47:39 -06:00
zees-dev
519f208a05
Forc.toml metadata support (#6728)
# Description
Adds support for `metadata` as `[project.metadata]` or
`[workspace.metadata]` in `Forc.toml` of value `toml::Value`

- Addresses:
22bf3936a3/text/rfcs/0006-metadata-in-forc-manifest.md (reference-level-explanation)
- Resolves: https://github.com/FuelLabs/sway/issues/2180

## Linked examples of usage
- https://github.com/FuelLabs/example-forc-plugins/pull/1

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-11-19 16:48:32 +13:00
Kaya Gökalp
8073fab0b6
docs: remove dead links to sway-libs/fixed-point (#6689)
## Description
closes #6636.
closes #6631.

As of https://github.com/FuelLabs/sway-libs/pull/278
sway-libs/fixed-point library is deprecated and removed completely from
sway-libs repo. We should not link it from our book as well.
2024-11-03 23:39:54 -08:00
0x77
7e499fe24d
[docs] Update ::call_frames::ContractId to ::contract_id::ContractId in Native Assets Documentation (#6141)
## Description
The syntax `std::call_frames::ContractId` has been updated in the latest
version of Sway. The new syntax is `std::contract_id::ContractId`. To
ensure the documentation is accurate and consistent with the latest
version, this update is necessary.

## Reason for Change:
- The `std::call_frames::ContractId` syntax has been deprecated or
modified in the latest version of Sway.
- Using the latest `std::contract_id::ContractId` syntax ensures the
documentation is accurate and helps developers avoid using outdated
syntax.

## Reference
#5867 

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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).
- [ ] I have requested a review from the relevant team or maintainers.

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-10-28 14:48:26 +01:00
mcisb
cbfd9621d0
style: update troubleshooting.md (#6632)
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-10-16 10:02:56 +11:00
Sophie Dankel
98d821b6ed
add new target to forc (#6621)
## Description


## 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: Alfie John <alfie@alfie.wtf>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-10-14 21:00:25 -07:00
Kaya Gökalp
b465e19284
fix: pin forc-deploy to use 100kb blob size by default (#6616)
## Description

Pins forc-deploy chunk sizes to 100kb to fix errors while deploying
chunked contracts. To unblock an ecosystem project, the PR is marked
critical.
2024-10-07 05:10:36 -07:00
Kaya Gökalp
347c83473a
feat: add blob deployments for scripts and predicates (#6607)
## Description

This PR adds support for deploying executables, namely predicates and
scripts. Before this PR executing `forc-deploy` on a script or predicate
was an hard error. With this PR we are enabling the deployment of them
via converting them to a loader which loads the original bytecode
deployed as a blob.

The loader binaries are serialized to disk under `out` folder for both
predicates and scripts. For predicates we also save the root of the
loader additionally. Every output related to generated `loader` is
suffixed with `-loader` so that it can be distinguished easily.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-10-06 17:12:36 +11:00
Cameron Carstens
f14af85025
Update single and multi asset example in docs hub (#6594)
## Description

The single and multi asset examples in the docs hub do not use the
latest versions of the SRC3 and SRC20 standard. This has been updated to
follow the specifications.

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-09-29 10:16:31 +02:00
Samuel Moelius
c55ad21e3e
Fix "Testing with Rust / Writing Tests" example (#5539)
## Description

The harnes.rs code that currently appears in the book seems to be out of
date (it doesn't compile).

The proposed code was copied from the [`sway-test-rs`
template](1fee545237/templates/sway-test-rs/template/tests/harness.rs (L1-L36)).

(The Sway tutorial is very good, BTW.)

## 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).
- [ ] 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: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-09-10 09:48:27 +10:00
Sophie Dankel
507870a386
docs: Add build script to test templates (#6510)
## Description

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

Adds a build script to the test templates that runs prior to the tests
when `cargo test` is run. This makes it so users who copy this template
don't have to run `forc build` prior to `cargo test`

## 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: K1-R1 <77465250+K1-R1@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-09-09 18:41:38 +00:00
Joshua Batty
050ee9dbe2
Add find all references feature to the language server. (#6512)
## Description
closes #5961 

See video below for how it's used. 


https://github.com/user-attachments/assets/4b758abb-bd4e-4f37-89ba-cff42a3b82e5


## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-09-09 17:45:24 +00:00
Sophie Dankel
e85dffc157
docs: Update debugging_with_cli.md (#6472)
## Description

Updating the docs to use the script from
`forc-plugins/forc-debug/examples/example_tx.json`

## 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-08-27 18:28:14 -07:00
Igor Rončević
7731c6b128
Fix scwq instruction and "phantom" error in purity checks (#6432)
## Description

This PR fixes #6320 and #6431 by:
- properly treating the `scwq` instruction in purity check as a storage
writing instruction.
- not emitting purity issues for `__entry` functions.

Additionally, the PR:
- removes purity checks from the type-checking phase. Those checks were:
  - redundant. The same checks were also done at the IR side.
- incomplete. The checks were covering only the function and method
calls, not other kinds of storage access (e.g., intrinsics).
- inaccurate. The checks were relying on `#[storage]` attributes, which
do not necessary represent actual storage access patterns.
- extends `MetadataManager` to be able to store more then one `Span` per
`MetadataIndex`. E.g., for a function, we can now store the span of the
whole function declaration, but in addition, also the span pointing only
to the function name.
- removes two different and overlapping storage access mismatch errors
and introduces one expressive diagnostics that points to the exact
storage access violations inside of a function (see demo below).

Note that having the purity tests at the IR level means that no purity
errors will be reported on non-used functions. This was already the case
before, since the complete set of tests was done at the IR level, and
only two tests (inaccurately) at the type-checking phase, where errors
would be reported even for the non-used functions. The purity guaranty
is given for all the compiled code.

Closes #6320.
Closes #6431.

## Demo

Before, we had two different error messages, rendered potentially
several times per access violation.

![Before 01 - Storage attribute access
mismatch](https://github.com/user-attachments/assets/1207b640-2742-4cee-afa9-da9cfc743e2c)

![Before 02 - Function performs storage
read](https://github.com/user-attachments/assets/284f9a65-fc6c-4318-ab83-5beab730b4d3)

Now, we have only one error message that points to the access violations
and explains them.

![After 01 - Pure function cannot access
storage](https://github.com/user-attachments/assets/87f69493-efd2-4230-bd52-95f0ea1c6fd8)

![After 02 - Pure function cannot access
storage](https://github.com/user-attachments/assets/2fd3ff3b-5738-4e46-99f9-417c4be8520d)

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [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.
2024-08-19 14:18:02 +00:00
Joshua Batty
7dc3e2d745
Fix broken forc command docs (#6424)
## Description
I noticed that the command section for forc in the documentation was
only showing headings and no information about the commands themselves.
See below.

![Screenshot 2024-08-19 at 10 47
48 AM](https://github.com/user-attachments/assets/ee5c00d3-97f2-445a-b1c7-203144bf2d13)

This was due to back ticks being placed around the heading in #5369.
I've removed these ticks and added the commands to the list of accepted
words.

Also there were a lot of commands being missed due to their no longer
being subcommands, this logic has been updated and all the forc commands
are now being parsed.

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-08-19 15:49:28 +02:00
Kaya Gökalp
d003a5f5a8
feat: Implement ldc based automatic contract chunking with auto split and loader generation (#6250)
## Description

This PR adds chunk deployment based on LDC. Contracts larger than 100 kb
size, is split into chunks and chunks are deployed as `blobs`. Out of
these blobs we create a loader contract, which loads all the blobs using
`LDC` opcode.

One important thing is that this feature works nicely with the proxy
feature introduced in #6069, so a large contract, with proxy can be
deployed directly. Large contract will be split into chunks, chunks will
get deployed, loader will get get generated and deployed, after all
these a proxy contract is deployed and pointed to the loader contract
deployed.

Simple chunked deploy, chunked deployment re routing the call, chunked
deployment behind a proxy re routes the call is tested.

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-16 23:47:54 -07:00
Marcos Henrich
25060f4f38
Updates JSON ABI, LDC, BSIZ, BLDD and ED19. (#6254)
## Description

Updates all the dependencies for the current release.

Implements the fuel ABI generation changes proposed in
https://github.com/FuelLabs/fuel-specs/pull/599.

Removes the flag `--json-abi-with-callpaths` and the behavior is as if
it were true. We removed the flag because it is unsafe to produce JSON
ABIs without callpaths, so we shouldn't allow it.

Includes the LDC, BSIZ, BLDD and ED19 changes
from:https://github.com/FuelLabs/sway/pull/6409.

Fixes https://github.com/FuelLabs/sway/issues/5954
Fixes https://github.com/FuelLabs/sway/issues/5151

## Checklist

- [x] I have linked to any relevant issues.
- [x] 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)
- [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: Vaivaswatha Nagaraj <vaivaswatha.nagaraj@fuel.sh>
Co-authored-by: Kaya Gokalp <kayagokalp123@gmail.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-15 18:21:44 +01:00
Luis Gustavo Búrigo Alexandre
9b87126927
Allow forc deploy to submit transaction without waiting for commit confirmation (#6294)
## Description
The current `forc deploy` command is designed to submit and await for
transaction finalization as much this is a common use case, for delayed
transactions, were transaction are submitted but can take time a lot of
time to be included and finalized. For this use cases I have implement a
suggestion `--submit-only` this will follow the current flow, but only
submit the transaction.

### Example use case for delayed transactions
In Bako Safe, as it is a multisig, it is necessary to have signatures
from multiple accounts before sending the transaction to the network. To
work together with forc deploy, a GraphQL Proxy has been developed that
works with the Fuel provider to allow sending the transaction to our
protocol.

```zsh
forc deploy --node-url 'https://api.bako.global/v1/graphql' --default-signer --submit-only
```

## Changes
- [x] Add a new deploy params `--submit-only`
- [x] Create a branch on the code to verify if the param is provided
- [x] Abstract create artifacts to a single function to avoid code
repetition
- [x] Modified transaction submission to allow for immediate submission
when the `submit_only` command is provided
- [x] Implemented tests for the new command


## Checklist
- [ ] I have linked to any relevant issues.
- [ ] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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 Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
2024-08-14 03:57:36 -07:00
Igor Rončević
589d3b9f81
ASM blocks handling: inlining, DCE, ASM returns without return register (#6404)
## Description

This PR fixes #6332 and #6354 by:
- including number of instructions in ASM blocks when calculating
overall number of instructions for function inlining.
- properly lowering ASM blocks that return unit, `()`, without return
register to returning `$zero` in the ASM.

Additionally, the PR:
- removes dead ASM blocks (that do not have side-effects) in the DCE
pass.
- prints ASM blocks that return `()` without a register as `-> ()` to
make it consistent with functions.
- emits a warning if an ASM block is empty.
- adds expressive diagnostic for `UninitializedAsmRegShadowsItem`
warning and extends the warning for constants and configurables.
- removes obsolete `NamespaceAttributeDeprecated` warning and its empty
tests.
- harmonizes and defines guidelines for ASM instruction comments.

Closes #6332.
Closes #6354.

## Bytecode size changes

Changes in the `fn-inline` and `dce` optimizations had a minimal impact
on the bytcode sizes of the `should_pass` test programs. Out of 455
tests, only 13 tests changed sizes. 8 tests got a size increase of 0.8%
in average, while 5 tests got size decrease of 3.0% in average.

The real-world
[compolabs-orderbook](https://github.com/compolabs/orderbook-contract)
contract got a minimal size decrease of 0.16%.

<details>
  <summary>Click here for the numbers</summary>

Test | Before | After | Decrease | Percentage
-- | -- | -- | -- | --
empty_fields_in_storage_struct | 28384 | 28456 | -72 | -0.25
language/deprecated_attribute | 224 | 208 | 16 | 7.14
language/duplicated_storage_keys | 224 | 208 | 16 | 7.14
language/references/dereferencing_operator_dot_on_structs | 124920 |
125272 | -352 | -0.28
language/references/dereferencing_operator_dot_on_tuples | 124920 |
125272 | -352 | -0.28
language/references/dereferencing_operator_index | 92376 | 92344 | 32 |
0.03
language/references/dereferencing_operator_star | 151152 | 151536 | -384
| -0.25
language/references/impl_reference_types | 7840 | 7776 | 64 | 0.81

language/references/reassigning_via_references_passed_and_returned_to_and_from_functions
| 39008 | 39184 | -176 | -0.45
language/references/reassigning_via_references_to_expressions | 36920 |
37064 | -144 | -0.39
language/references/reassigning_via_references_to_values | 13952 | 13936
| 16 | 0.11
stdlib/storage_vec_insert | 8480 | 8552 | -72 | -0.85
stdlib/vec_byte_remove | 1904 | 1976 | -72 | -3.78

</details>

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [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.
2024-08-08 08:30:15 +00:00
Sophie Dankel
93656fe5f6
docs: Update docs for forc-client (#6403)
## Description

Apply @bitzoic 's comments from
https://github.com/FuelLabs/sway/pull/6069

## 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-08-07 21:19:50 +05:30
Kaya Gökalp
5d796fb3c2
feat: create and deploy a reference proxy contract for contracts with [proxy] enabled (#6069)
## Description
Part of #6068. 

This PR adds couple of things:

1. A default proxy contract implementation taken from [sway
standards](https://github.com/FuelLabs/sway-standards/blob/master/standards/src/src14.sw).
2. Infra for creating, building and deploying the reference
implementation for proxy contracts.
3. Deployment procedure such that proxy contract is deployed while
working on a contract which enables the `[proxy]` in its forc.toml. In a
way that it is owned by the deployer and the target initially points to
implementation contract.
4. Infra for making a contract call into the already deployed proxy
contracts to update their targets.
5. Adds a `Building` text to the all forc build invocations to better
inform the user about what forc is doing behind the scenes.
6. Removes duplicate forc-wallet password prompts which was very
frustrating for the users. Now forc-wallet deployment path only asks for
password once.
7. Refactors around how secret_key is selected based on user input
8. Updated docs around forc-client
9. Docs around how to use the proxy feature

## How this works
If the user does not have a proxy table in their forc.toml, nothing
changes, same old deployment procedure is followed. Only difference is
that this PR improves the ux by removing the need of providing the
password multiple times.

If the user has a contract with a proxy table but without an address
like:

```TOML
[project]
authors = ["kaya"]
entry = "main.sw"
license = "Apache-2.0"
name = "impl-contract"

[dependencies]

[proxy]
enabled = true
```
Forc automatically creates a proxy contract based on the reference
implementation at
[SRC14](61fd4ad8f6). Sets its
target to the implementation contract, whichever contract enabled the
proxy and the owner to the deployer (signing account of the
transaction).

If the user has a contract with a proxy table and an address specified
like:

```TOML
[project]
authors = ["kaya"]
entry = "main.sw"
license = "Apache-2.0"
name = "impl-contract"

[dependencies]

[proxy]
enabled = true
address = "........."
```
Forc automatically makes a set target conract call to update the proxy
contract's target. Pointing it to the newly deployed impl contract which
defines the proxy table.

Generated proxy contract abi and bins are stored at
`~/.forc/.generated_proxy_contracts/project_name` for housekeeping.
2024-08-07 10:41:44 +00:00
Daniel Frederico Lins Leite
afd6a6709e
Slice/Array intrinsics: __slice and __elem_at (#6282)
## Description

This PR is part of https://github.com/FuelLabs/sway/issues/5110 and
introduces two new intrinsic: `__slice` and `__elem_at`.

`__slice` allows the creation of slices by slicing arrays or other
slices. Whilst `__elem_at` returns a reference to an item inside the
slice or the array.

## Out of bounds checks

These intrinsic will not generate any runtime checks, these must be done
manually, when and where appropriate; but they do a complete static
analysis of all indices, to avoid runtime buffer overflows, when
possible.

That means that at runtime, it is possible to do a buffer overflow when
reading/writing, which is an "undefined behaviour" as to what will
happen.

## Empty Array

This PR also solves a problem with empty arrays. Before empty arrays
such as `let a = []` were being type-checked as `[Never; 0]`, which
means that any code after them was being marked as dead.

Now we correctly type check them as `[Unknown; 0]` and return a more
friendly error.

```
          4 |
          5 |     // Empty array
          6 |     let a = [];
            |             ^^ Type must be known at this point
          7 | }
            |
          ____
```

## Check of constants inside fns

This PR also solves a problem with not checking `const` expressions
inside `fns`. We, for example, do not allow slices in constants, but we
were only checking globals. Now we check constants also inside
functions, methods etc...

## Small improvements for our e2e

We can now `dbg` inside our e2e harness and get results like the ones
below. One needs to include the lib `test/src/e2e_vm_tests/utils` and
cal `something.dbg()` or `something.dbgln()`. There is no magic, and
structs/enums will need to manually implement the `Dbg` trait.

This is only to facilitate the debugging of our e2e tests.


![image](https://github.com/user-attachments/assets/2f25c50e-b7b3-4199-8bf4-699473919e6c)


## 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-08-07 02:00:09 -07:00
osrm
33134f888e
chore: correction typos index.md (#6303) 2024-07-30 05:42:44 +02:00
dima-safin-2025
ec01af49c8
fix: update the document link for Manual Storage Management. (#6301)
## Description

related https://github.com/FuelLabs/sway/issues/6300


## 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).
- [ ] 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.
- [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: K1-R1 <77465250+K1-R1@users.noreply.github.com>
2024-07-26 21:26:20 +02:00
IGI-111
d31334d1d1
Add documentation about Undefined Behavior (#6302)
## Description

Add a section in the docs to list known UB.

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-07-26 18:26:03 +02:00
Oleg
fe89d16a4a
Update index.md (#6267)
Update

## Description


## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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: IGI-111 <igi-111@protonmail.com>
2024-07-16 02:36:14 +00:00
Call Delegation
ebc2ee6bf5
docs: Add Core Library to introduction section of the Sway book (#6193)
## Description
https://fuellabs.slack.com/archives/C031TTYJM60/p1719402172570099

## Checklist

- [ ] 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] 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.
- [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: IGI-111 <igi-111@protonmail.com>
2024-07-15 01:23:08 -07:00
Olexandr Radovenchyk
f43342b3d8
Update index.md (#6261)
Error correction

## Description


## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-07-11 18:16:31 +02:00
IGI-111
d86bb86369
Bump to v0.61.1 (#6207) 2024-07-02 23:03:30 +02:00
Madhur Dixit
10052d9b9a
Counter Example Doc Update (#6164)
## Description
Linked the building and deployment doc and added the commands to enable
developers in quickly building and deploying the contracts

### Motivation
To enable new developers to quickly deploy contracts from templates

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-06-24 10:38:36 -07:00
IGI-111
4b4fb53eb2
Bump to v0.61.0 (#6144) 2024-06-19 15:40:51 +04:00
Marcos Henrich
e30497caaa
Storage name based slots and namespaces. (#6064)
## Description
With this change storage keys will have a hash based on:

`sha256("storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>"`
or a given key.

A key can be provided by using the `in` keyword in a storage field as
such:
```
storage {
    a in 0x02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae: u64
}
```
Or by using a const expression:
```
const C1 = 0x02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae;
storage {
    a in C1: u64
}
```

StorageKey.field_id is now based on:

`sha256("storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>.<struct_field_name1>.<struct_field_name2>")`

Nested storage namespaces such as the following are now supported.
```
storage {
    my_namespace1 {
        my_namespace2 {
            b:u64 = 1,
        }
    }
}
```

A deprecated warning is now thrown when the attribute `#[namespace(ns)]`
is used.

A warning is thrown when storage fields use the same storage slot key.
The warning looks like this:
```
          Two storage fields are using the same storage key.
          First field: storage::ns1.f3
          Second field: storage::ns2.f4
          Key: 5F4C20CE4BD128E5393A4C2B82007DAC795FA0006D01ACF8DB4C42632BC680CA 
```

This PR does not include yet the necessary documentation updates.
Created dev-rel documentation request:
https://github.com/FuelLabs/devrel-requests/issues/14

## Checklist

- [ ] I have linked to any relevant issues.
- [x] 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).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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: IGI-111 <igi-111@protonmail.com>
2024-06-18 16:03:39 +04:00
Cameron Carstens
2984831f5f
Add primitive conversions submodules to the prelude (#6105)
## Description

As part of https://github.com/FuelLabs/sway/pull/6087, it was revealed
that the current `use std::primitive_conversions::*;` line in the
prelude does not import anything which a developer can use. To use any
of the submodules in the primitive conversions library, users would need
to import the individual submodule regardless of the prelude.

This PR adds the submodules as an import to the prelude to stay
consistent with the original intent. Both the core's and std-lib's
primitive conversions modules are imported. Conversions between
primitive types should not require additional imports.

Example before:
```sway
use std::primitive_conversions::u32::*;

fn foo() {
    let my_u8 = 1_u8;
    let my_u16 = 1_u16;
    let my_u64 = 1_u64;

    let u32_1 = u32::from(my_u8);
    let u32_2 = u32::from(my_u16);
    let u32_3 = u32::try_from(my_u64);
}
```

Example after:
```sway
fn foo() {
    let my_u8 = 1_u8;
    let my_u16 = 1_u16;
    let my_u64 = 1_u64;

    let u32_1 = u32::from(my_u8);
    let u32_2 = u32::from(my_u16);
    let u32_3 = u32::try_from(my_u64);
}
```

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

Dependent on https://github.com/FuelLabs/sway/pull/6087

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-06-11 05:13:39 +04:00
Sophie Dankel
3f99163eaa
fix: remove Forc.lock files from template projects (#6101)
## Description

These projects are used as templates in `forc template` and having the
lock files as part of the template could cause issues. The lock file
should be generated on the fly by forc.

## 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-06-07 12:56:09 -07:00
Cameron Carstens
5389aa85c0
Add examples on how to import storage types to the book (#6051)
## Description

A [recent issue on the
forum](https://forum.fuel.network/t/no-method-push-found/5342)
demonstrated the lack of examples on how to import storage types to the
book. Specifically, they require the glob operator to be used properly.
A note on this has been added.

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-05-27 12:04:44 +08:00
IGI-111
2f0392ee35
Bump to v0.60.0 (#6049)
Co-authored-by: João Matos <joao@tritao.eu>
2024-05-22 19:34:47 +02:00
Cameron Carstens
954a81b626
Introduce Self::zero and self::is_zero() for 13 types (#5973)
## Description

Introduces the following functions to be implemented:
- `zero()`
- `is_zero()`

This falls inline with what we see in [Rust's Zero
Trait](https://docs.rs/num/latest/num/traits/trait.Zero.html), making
the language feel and look more like Rust.

This PR also deprecates the following:
- `ZERO_B256` -> `b256::zero()`
- `ZERO_U256` -> `u256::zero()`

To define a `u256` or `b256` zero address, the following should be used:

```sway
let zero_b256 = b256::zero();
let zero_u256 = u256::zero();
```

A common use of the `ZERO_B256` was to define the zero addresses and
contract id`:
```sway
let zero_address = Address::from(ZERO_B256);
let zero_contract = ContractId::from(ZERO_B25);
```
The following is now possible:
```sway
let zero_address = Address::zero();
let zero_contract = ContractId::zero();
```

The following types now implement the `Zero` trait:

- `u8`
- `u16`
- `u32`
- `u64`
- `u256`
- `b256`
- `SubId`
- `AssetId`
- `ContractId`
- `Address`
- `EvmAddress`
- `U128`
- `B512`

Closes #5830 

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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: K1-R1 <77465250+K1-R1@users.noreply.github.com>
2024-05-22 14:13:15 +04:00
IGI-111
d9985d8111
Bump to v0.59.0 (#6030) 2024-05-17 11:29:22 +00:00
Nick
2ec4332c55
Remove frontend section from Sway docs. (#5743)
Remove frontend docs, this section is no longer needed.

## Description

Remove the frontend docs. This section is no longer needed.

---------

Co-authored-by: JoshuaBatty <joshpbatty@gmail.com>
2024-05-16 21:47:32 -07:00
Igor Rončević
8c999fa252
Improve IR printing CLI in forc (#6025)
## Description

This PR:
- implements detailed control over printing of IR:
  - initial IR
- IR after choosen optimization steps, with option to print only the
steps that have actually modified the IR
  - final IR
- improves printed IRs by removing the confusing empty modules printed
for every external library dependency.
- harmonizes names and descriptions of the optimization passes. The
proposed convention is documented in the
_sway-ir/src/optimize/README.md_ file.
- harmonizes help comments of the shared compiler options (consistent
separation between option title and additional info, wording, etc.)

## Demo

```
'Print initial and final IR together with IR after each optimization step.
--ir all

'Print initial and final IR together with IR after each optimization step that has modified the IR.
--ir all modified

'Print only the final IR.
--ir final

'Print the IR after every "dce", "sroa", and "inline" optimization step.
--ir dce sroa inline

'Print the IR after every "dce", "sroa", and "inline" optimization step that has modified the IR.
--ir dce sroa inline modified
```

## Breaking Changes

### CLI

Instead of the existing `--ir` option without parameters we now have the
same CLI option but with parameters. The existing `--ir` is equivalent
to the new `--ir final`.

### Build Profile

Instead of the existing `print-ir` of type bool, we now have the same
`print-ir` build profile option with parameters. E.g.:

```
print-ir = { initial = true, final = false, modified = true, passes = ["dce", "sroa"]}
```

## Checklist

- [ ] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.
2024-05-17 10:42:00 +10:00
Cameron Carstens
235380328a
Add ContractId::this() documentation to book (#6008)
## Description

There is no documentation on how to get the `ContractId` of a contract
in an internal context. This has been added.

Closes #6001 

## Checklist

- [x] I have linked to any relevant issues.
- [ ] 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).
- [ ] 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.
- [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: K1-R1 <77465250+K1-R1@users.noreply.github.com>
2024-05-16 10:07:33 +00:00
Kaya Gökalp
cd76c648e4
feat: add log decoding capabilities to show decoded log values for forc-test (#5812)
## Description

This PR adds log decoding capabilities to forc, so that it can be used
for showing actual decoded, human readable values at forc-test output.

For the following unit test:

```sway
script;

fn main() {}

#[test]
fn test_fn() {
	let a = 10;
	log(a);
	let b = 30;
	log(b);
	assert_eq(a, 10)
}
```
Logs are:


```console
forc test --logs --experimental-new-encoding
  Finished debug [unoptimized + fuel] target(s) in 5.14s
      Bytecode hash: 0x562b471bae4323b806a1b2829014ef7078a5b9406a076a54cf0b2f1a61cb49f8
   Running 1 test, filtered 0 tests
      test test_fn ... ok (33.875µs, 200 gas)
Decoded log value: 10, log rb: 0
Decoded log value: 30, log rb: 1
Raw logs:
[{"LogData":{"data":"000000000000000a","digest":"8d85f8467240628a94819b26bee26e3a9b2804334c63482deacec8d64ab4e1e7","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10336,"len":8,"pc":10784,"ptr":67107840,"ra":0,"rb":0}},{"LogData":{"data":"000000000000001e","digest":"48a97e421546f8d4cae1cf88c51a459a8c10a88442eed63643dd263cef880c1c","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10336,"len":8,"pc":11048,"ptr":67106816,"ra":0,"rb":1}}]
   Result: OK. 1 passed. 0 failed. Finished in 33.875µs.
```

Also this PR fixes a bug in test suite which causes test suite to omit
the encoding information passed into forc-test from `unit_tests_pass`
tests. And adds log decode testing capabilities to the test suite.

Next up is adding actual variable names instead of log id so that
decoded log values will show as, this is left to a future PR

`Decoded log: ( a = 10 )`
`Decoded log: ( b = 30 )`
2024-05-14 23:53:57 -07:00
Kaya Gökalp
9579dd2f77
chore: bump to v0.58.0 (#6003)
## Description
Bumps sway repo to 0.58.0.
2024-05-13 16:44:55 -07:00
Igor Rončević
fa62d82d8a
Improve ASM printing CLI in forc (#5997)
## Description

This PR simplifies and gives more control ove printing the ASM. It's a
first step in harmonizing printing options for ASM and IR, where the
goal is to be able to print arbitrary optimization passes in IR.

This PR:
- replaces two existing, verbose and unintuitive to discover, ASM
printing CLI options with a single `--asm`, same as the single `--ir`
option.
- improves printed ASM by removing the confusing empty programs printed
for every external library dependency.
- harmonizes printed virtual and allocated abstract ASM to have the
same-looking comments and structure.

Additionally, the PR fixes the bug in the
`PassManager::insert_after_each` helper function, where passes were not
inserted within groups. This is a preparation step for the changes
needed for improving the `--ir` CLI option.

## Demo

```
--asm all               'Prints virtual, allocated, and final ASM.
--asm final             'Prints only the final ASM.
--asm allocated final   'Prints the allocated and the final ASM.
```

## Breaking Changes

### CLI

Instead of existing `--intermediate-asm` and `--finalized-asm` options
we now have a single `--asm` CLI option with parameters. The existing
options should be replaced:

| Current | New |
| - | - |
|`--intermediate-asm`|`--asm abstract`|
|`--finalized-asm`|`--asm final`|
|`--intermediate-asm --finalized-asm`|`--asm all`|

### Build Profile

Instead of existing `print-intermediate-asm` and `print-finalized-asm`
options we now have a single `print-asm` CLI option with parameters.
E.g.:

```
print-asm = { virtual = true, allocated = true, final = true }
```


## Checklist

- [ ] 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).
- [ ] 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.
- [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.
2024-05-13 13:51:23 +01:00
IGI-111
b939c0be73
Bump to v0.57.0 (#5993) 2024-05-13 08:19:45 +01:00
IGI-111
58944ae5f9
Rework book intro (#5972)
## Description

Rewrote much of the book introduction to better explain the vision for
Sway, how it compares to both Solidity and Rust, address some of the
misconceptions in it and generally make it more appealing to people who
are just discovering Sway.



## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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>
Co-authored-by: João Matos <joao@tritao.eu>
2024-05-09 22:46:29 +02:00
Sophie Dankel
f8e8d356be
ci: fixing typos programmatically (#5975)
## Description

Adds a CI check for typos and fixes all* typos in code, comments, and
docs.

*found by [typos-cli](https://github.com/crate-ci/typos)

`typos` doesn't catch everything, but it seems to work better than
codespell and cargo-spellcheck (fewer false positives).

## 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-05-09 10:21:32 +10:00
IGI-111
4a63b41de1
Bump to v0.56.1 (#5974) 2024-05-08 22:26:41 +00:00
Sarah Schwartz
474d654c9d
docs: add external code doc (#5840)
## Description

This PR adds a page for external code execution in the Sway book.

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-05-08 20:23:42 +01:00