Commit graph

517 commits

Author SHA1 Message Date
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
Cameron Carstens
da05b9d5b3
Reference Sway-Libs, Sway-Standards, and Sway-Applications In Sway Book (#5944)
## Description

Previously the Sway book did not have any sections on Sway-Libs,
Sway-Standards, or Sway-Applications and was sparsely mentioned.
Sections for each repository have been added with a brief overview of
what they contain. Links to any app, standard, or library have also been
provided.

Any use of the sway-libs repository has been replaced with the
[Sway-Libs book](https://fuellabs.github.io/sway-libs/book/index.html).
This should eventually be replaced with a doc hub link when it has been
integrated and the same for Sway-Apps and Sway-Libs.

Closes #5780 

## 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).
- [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: K1-R1 <77465250+K1-R1@users.noreply.github.com>
2024-05-08 13:00:50 +00:00
João Matos
d6da909e78
Adds documentation about the compiler internals. (#5937)
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-05-08 04:37:41 +00:00
Sarah Schwartz
476e07a659
docs: fix typos (#5959) 2024-05-03 10:54:11 -05:00
Sarah Schwartz
2949f46211
docs: rewrite introduction (#5956)
Rewrites the docs introduction to be more friendly to beginners
2024-05-03 08:25:03 -06:00
Igor Rončević
daee1c247c
Dereferencing as reassignment target (#5923)
## Description

This PR implements dereferencing in reassignment targets, as defined in
[references](https://github.com/FuelLabs/sway-rfcs/blob/ironcev/amend-references/files/0010-references.sw).
The overall effort related to references is tracked in
https://github.com/FuelLabs/sway/issues/5063.

Up to now, it was only possible to read the values references refer to.
This PR allows values to be written over `&mut` references. In other
words, any `*<expression that results in &mut>`is now an l-values and
can be used in left-hand sides (LHS) of assignments. In most of the
cases, the `<expression>` will very likely be just a reference variable,
but any expression that results in `&mut` is allowed and supported.
E.g.;

```Sway
*mut_ref_to_u64 = 42;

*if condition { &mut x } else { &mut y } = 42;

*max_mut(&mut x, &mut y) = 42;
```

Additionally, the PR:
- fixes #5736 by properly replacing decls in reassignment LHSs.
- fixes #5737 by properly substituting types in reassignment LHSs.
- fixes #5920 by properly connecting expressions in array indices to the
DCA graph.
- fixes #5922 by type-cheking the array indices in reassignment LHSs and
forcing them to be `u64`.
- improves misplaced and misleading error messages when assigning to
constants and other items (see demo below).
- improves error message when assigning to immutable variables by
pointing to variable declaration.
- improves error message when expression cannot be assigned to by
pointing to the problematic part of the expression. Since Sway is more
restrictive here then Rust, the restrictions, without being explained,
could cause confusion. That's why special attention was given to point
to the exact issue and explain what is actually supported in Sway (see
demo below).
- reduces number of expected warnings in references E2E tests that were
previously set high because of DCA issues that are fixed in the
meantime.

The PR also brings additional analysis and checks to IR optimizations.
Among other things, it explicitly points out the cases in which a
potential usage of a symbol cannot be deterministically confirmed or
denied. In this PR properly reacting for such cases is done in some
optimizations. Rolling it out fully will be done in a follow up PR
#5924. More advanced escape analysis will be done later on, as a part of
allocating values on the heap in case of referencing.

This PR implements only dereferencing in LHS. Support for referenced
elements in the element based access (without dereferencing) will be
done in a separate step as an ongoing work on implementing #5063.

Closes #5736, #5737, #5920, #5922.

## Demo

Before:
![Assignment to constant -
Before](e6b29d31-8e29-4ffa-acfe-a844ac50887b)

![Assignment to decl -
Before](ef5f025e-3dcc-4cb0-b52f-d735e2ee451e)

After:
![Assignment to constant -
After](f3dfdbd9-2123-4a96-98a7-b3c7a3f3e7f9)

![Assignment to decl -
After](ae765d61-41b2-478c-96c0-d476604deec6)

Expression cannot be assigned to:

![Expression cannot be assigned
to](384d0bb7-34a1-446a-acd5-6c8f66dc4ed5)

## 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-04-30 18:39:07 +02:00
IGI-111
b495d0df69
Bump to v0.56.0 (#5919)
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-04-26 05:46:45 +04: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
Cameron Carstens
dbdcd62c8b
Simplify Asset Transfer and Mint Functions (#5891)
## Description

There are currently multiple functions for the same functionality:

Transfer:
- `transfer()`
- `force_transfer_to_contract()`
- `transfer_to_address()`

Mint:
- `mint()`
- `mint_to()`
- `mint_to_contract()`
- `mint_to_address()`

This be reduced to just `transfer()`, `mint()`, `mint_to()`. Specific
functions for separately minting and transferring to contracts and
addresses are legacy code left over from before the `Identity` type was
introduced and now only adds additional complexity.

## Changes:

- `force_transfer_to_contract()` is now private
- `transfer_to_address()` is now private
- `mint_to_contract()` removed
- `mint_to_address()` removed
- Removed newlines in inline docs for better `forc doc` compatibility
- Updated `burn()` inline docs

## Breaking Changes:

- `force_transfer_to_contract()` is now private
- `transfer_to_address()` is now private
- `mint_to_contract()` removed
- `mint_to_address()` removed

## Closes

- Closes #5773 

## 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-04-25 18:39:21 +04:00
Call Delegation
e12d985cd8
docs: Wallet Example Clarification (#5878)
## Description
https://forum.fuel.network/t/module-wallet-abi-could-not-be-found/5116
Nick asked for clarification in the wallet example based on this inquiry
in the forum.

TLDR:
It is unclear to the user that, when copying the example into their own
Sway project, these are two separate projects and require a dependency
declaration inside the `forc.toml` file.

## 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)
- [ ] 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).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-04-19 14:43:53 +00:00
Cameron Carstens
11f9c0ebf7
Use GM opcode to fetch the base_asset_id (#5806)
## Description

The Base asset ID is no longer a constant. It is now stored in memory
and retrieved using the `GM` opcode. More information can be found
[here](https://github.com/FuelLabs/fuel-specs/blob/master/src/fuel-vm/instruction-set.md#gm-get-metadata).

## Breaking Changes

- The `BASE_ASSET_ID` constant has been removed.
- `AssetId::base_asset_id()` is now `AssetId::base()`.

## 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-04-19 12:43:49 +00:00
Sophie Dankel
3c85388555
Update docs on how to disable LSP (#5877)
## Description

To be merged after
https://github.com/FuelLabs/sway-vscode-plugin/pull/180

## 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: Joshua Batty <joshpbatty@gmail.com>
2024-04-18 23:53:03 +00:00