Commit graph

502 commits

Author SHA1 Message Date
Kaya Gökalp
db8ba0bb6c
fix: deployment estimation deferred to sdk (#6212) 2024-07-03 20:39:09 +10:00
IGI-111
d86bb86369
Bump to v0.61.1 (#6207) 2024-07-02 23:03:30 +02:00
Kaya Gökalp
012244df84
chore: bump fuels-rs to v0.64.0, fuel-core to v0.28.0 (#6187)
## Description

Bumps fuel-rs to v0.64.0 to support fuel-core v0.28.0. No need to cut a
release for now, as we probably want to bump to v0.30.0. That is blocked
for now as sdk v0.65.0 is not released yet.
2024-06-27 13:55:21 +00:00
João Matos
0b79759e2c
Fix Clippy warnings. (#6183)
## Description

Fixes Clippy warnings after updating to the latest stable Rust toolchain
(1.79).

## 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.
- [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-26 23:20:42 +00:00
João Matos
3993f253fb
Cleanup DeclRef references from TypeInfo::Enum and TypeInfo::Struct (#6178)
## Description

This cleans up `DeclRef` references from `TypeInfo::Enum` and
`TypeInfo::Struct`, which both will allows us to long-term get rid of
the unnecessary and unperformant `DeclRef` abstraction. I'm touching
this to allow subsequent usage of `ResolvedDeclaration` in its place in
a future PR, so decided to go ahead and do this cleanup while at it.

## 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.
- [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-25 22:48:50 +00:00
Sophie Dankel
c186d93155
fix: fix panic in forc-debug (#6165)
## Description

https://app.warp.dev/block/iedebqr2dgZIuM5N0ZNlkU



## 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-21 18:11:55 +00:00
IGI-111
4b4fb53eb2
Bump to v0.61.0 (#6144) 2024-06-19 15:40:51 +04:00
tsinghuacoder
7278b6e04b
chore: fix some comments (#6139)
## Description


fix some comments


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

Signed-off-by: tsinghuacoder <tsinghuacoder@icloud.com>
2024-06-18 13:54:15 +04:00
Daniel Frederico Lins Leite
ba0d2d7e90
Faster access for configurables (#6058)
## Description

This PR revamps how configurables are accessed when encoding v1 is used.
Any changes for configurables with encoding v0 should be treated as
bugs.

After encoding V1 was merged, every single time you accessed a
configurable, we would "decode it". Apart from obvious performance
problems, this also introduced semantic problems: two different
references, would not point to the same memory address, which is
something one would expect from sway syntax.

This was addressed in four steps:

1 - Configurable lowering to IR now comes with more data, The IR below
is for a simple `u8` configurable named `U8`.

```
U8 = config u8, abi_decode_in_place_50, 0x01, !15
```

1.1 - config name comes from the configurable itself (before it was
auto-named as `c0`, `c1` etc...);
1.2 - config type correctly follows the configurable type (after
encoding v1, it was always byte slice);
1.3 - there is a new decode function that will be called to initialize
this configurable (more details below);
1.4 - at last, we have the encoded bytes of the configurable value.

2 - This PR also splits `TyConfigurableDecl` from `TyConstantDecl`, and
`ConfigurabletExpression` from `ConfigurableExpressions`.

This is needed because we now compile `ConfigurableExpression` to a new
IR instruction called `get_config`, which is similar to `get_local`. So
a reference to a `configurable` will be compiled into:

```
v0 = get_config ptr bool, BOOL, !261
v1 = load v0
```

3 - Given that `config`s are not writeable, and there is no way to set
their value in IR, this is done when we lower IR to ASM, more
specifically we are using a new ASM section called "globals", which are
the writeable counterpart of the read-only data section.

The physical difference is that the read-only data section is appended
at the end of the final binary which puts all the data sections outside
of the writeable memory; To circumvent this and enable some globals to
be writeable, we need to allocate them in the stack (the only writeable
memory inside FuelVM). So, as soon as possible we allocate space for all
globals with `cfei`, but we do not initialize them in any way, shape or
form. We cannot expect their value to be zero!

In one of our tests, this is the allocation that is generated:

```
cfei i190                               ; stack space for globals
```

After this, for each `config`, the following virtual ASM is appended to
the prologue (before the `__entry` fn).

```
addr $$arg0 data_0                      ; ptr to ANOTHER_U8 default value
addi $$arg1 $zero i1                    ; length of ANOTHER_U8 default value
addi $$arg2 $ssp i0                     ; ptr to global ANOTHER_U8 stack address
mova $$reta .72
fncall .0                               ; decode ANOTHER_U8
.72
```

There are two interesting parts here:

3.1 - There is a new `addr` virtual ASM opcode that returns the address
of an item in the data section, in this case, it is the `config` encoded
bytes.
3.2 - The address where the `config` lives in runtime is calculated at
compile time and it is represented as `addi $$arg2 $ssp i0`. In this
case, the first `config` is at `$ssp + 0`. The second one will packed
after the first, and so on. They are NOT aligned.

The final FuelVM bytecode is as packed as one could expect:

```
0x00000018 CFEI 0xbe                       ;; [145, 0, 0, 190]                      <- allocate globals at the stack
0x0000001c ADDI R58 R63 0x0                ;; [80, 235, 240, 0]              <- initialize the first config
0x00000020 ADDI R57 $zero 0x1              ;; [80, 228, 0, 1]
0x00000024 ADDI R56 $ssp 0x0               ;; [80, 224, 64, 0]
0x00000028 SUB R62 $pc $is                 ;; [32, 248, 51, 0]
0x0000002c SRLI R62 R62 0x2                ;; [88, 251, 224, 2]
0x00000030 ADDI R62 R62 0x4                ;; [80, 251, 224, 4]
0x00000034 JMPF $zero 0x19b                ;; [116, 0, 1, 155]
0x00000038 ADDI R58 R63 0x8                ;; [80, 235, 240, 8]              <- initialize the second config
0x0000003c ADDI R57 $zero 0x3              ;; [80, 228, 0, 3]
0x00000040 ADDI R56 $ssp 0x1               ;; [80, 224, 64, 1]
0x00000044 SUB R62 $pc $is                 ;; [32, 248, 51, 0]
0x00000048 SRLI R62 R62 0x2                ;; [88, 251, 224, 2]
0x0000004c ADDI R62 R62 0x4                ;; [80, 251, 224, 4]
0x00000050 JMPF $zero 0x1d8 
```

# Major code changes

1 - I had to split Constant and Configurable. This happened in both AST
and the typed tree.
2 - I completely removed `Configurable` and a possible IR value. As a
matter of fact, configurables do not exist in IR. We do have the concept
of `config`, which only exists in two forms: the `config` declaration,
and the `get_config` instruction.
3 - I moved the folder "programs" to inside "fuel" because they were not
being used for other targets. I have also move the abstraction of
targets away from them to the function
`compile_ir_context_to_finalized_asm`. So the lowering from IR to asm is
generic on the target as before, but the intermediary data are specific
to each target.

The only "leak" is `InstructionSet`, which still is a `enum` with a
variant for each target. I have changed this as this PR does not need
it. But I think would make sense for its parent structure
`FinalizedAsm`, to be target ignorant.
4 - I have also improved bytecode printing as shown above. Not we print
the FuelVM instruction, registers and arguments, together with the
binary in a more readable form. Together with absolute address.
5 - Up until now, all the compilation of `sway` to IR was done from the
entry function. Any code not reachable from here would not be in the
final binary. That was also true for how the suffix "_0", "_1" etc...
was inserted. They were chosen as these functions were being called.

This created a problem because the configurable initialization was not
necessarily also called in normal sway code. For this, I started to also
use the `config` decode fn field as entry functions. To avoid these two
generating colliding suffixes, I move the shared code into
`CompiledFunctionCache`. This "cache" is something that we should
revisit soon, but I left it untouched for now.

## Internal Debugging

We have some very hard to debug algorithms. I tend to leave some
commented code when I find a good place and a good "print" that helps to
debug these parts. For example:

```
// Uncomment to debug what this optimization is doing
```

We may want to find a better solution for this. Maybe a combination of
cargo feature and environment variable that prints these debugging
snippets.

I am fine with removing them for now, but I think they would be very
helpful, not only for debug, but also for snapshot tests in the future.

## Binary Size

Since the introduction of encoding v1 for configurable, the binary size
of
`test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts`
has exploded. Before it was around 5k, and skyrocketed to 14k. This PR
alleviates this a little bit, and brings it back to 10k.


![image](aff42e77-bbcc-499d-89fc-eafec8fcebd8)

## 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.
2024-06-11 13:28:47 +04:00
Sophie Dankel
f342f52381
feat: Add primitive types to forc-doc (#6032)
## Description

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

Adds a new "Primitive" type in the sidebar and to the search bar. The
descriptions are hard coded since there is nowhere to parse the
documentation from. The list of primitives is also hardcoded, so we will
need to update forc-doc if/when new primitives are added to the
language.

Primitives will be documented show up in the side bar for any package
that has implementations for a primitive. This is why it currently shows
up for both std and core.

Side bar nav:
![May-27-2024
16-54-34](30efc6d9-43d3-455b-baac-5daf7b19955f)

Search bar:
![May-27-2024
16-54-53](9e988c12-f84d-4012-bd88-a646514841ce)

## 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: Joshua Batty <joshpbatty@gmail.com>
2024-05-29 09:40:10 +10:00
Sophie Dankel
9d03fbd352
chore: Improve the error message for unresolved manifest reference (#6061)
## Description

Updates the error message to be more helpful when `forc build` is run
and the Forc.toml contains an invalid reference (i.e. bad git
branch/tag/rev). Also updates `forc-fmt` to use `println_error` for
consistent error display with the rest of forc.
2024-05-27 18:43:05 -07:00
cui fliter
e4088e0c58
chore: fix some comments (#5989)
## Description

Fixes some comments and panic messages grammatically.

Signed-off-by: cuishuang <imcusg@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
2024-05-23 19:57:34 +00: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
Vaivaswatha N
7ee627c4a7
Optimization pipeline: switch order of fndedup and inlining (#6024)
Without function deduplication, the heuristic that we have for inlining
"if a function is called only once, inline it" isn't good enough because
identical functions, after they're combined into one will have multiple
callers, which wouldn't be so without fndedup.

---------

Co-authored-by: Sophie <sophiedankel@gmail.com>
2024-05-22 17:16:49 +02:00
Sophie Dankel
f9a72da094
fix: add forc-doc impls for enums and fix sidebar (#6020)
## Description

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

Makes trait & inherent implementations show up for enums now: 

![image](58308fb6-2807-44cd-aa4a-6f4ee314ceac)

And makes the sidebar include links to the impls:

![image](55d9b17e-66dc-4f32-b1d8-325011eaef6f)


## 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-05-18 22:34:40 -07:00
IGI-111
d9985d8111
Bump to v0.59.0 (#6030) 2024-05-17 11:29:22 +00:00
Kaya Gökalp
0f1bdef8a4
chore: use fuels-rs v0.62.0, fuel-abi-types v0.5.0 (#6027)
## Description

Bumps:

1. fuels-rs v0.62.0
2. forc-wallet to v0.7.1
3. fuels-abi-types to v0.5.0

In the process I had to adjust forc-run to use new encoding api from the
sdk as well.
2024-05-16 18:02:41 -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
Sophie Dankel
d4f0c12c85
feat: Add implementations to forc-doc (#6017)
## Description

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

Also tweaked the CSS to make:
- the subheaders inside of implementations smaller than the impl header
- the colors a little less stark
- the impl toggle blocks open by default (same as crates.io)

Discovered two issues, relating to enums and the sidebar, which I'll
solve separately: https://github.com/FuelLabs/sway/issues/6018


![image](907f59c9-8555-4f0f-9ab2-353d4c17fa12)

## 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-05-15 16:23:53 -07:00
Kaya Gökalp
79b56517ba
feat: point --testnet flag to latest testnet instead of devnet (#6019)
## Description

Changes the target of `--testnet` flag to testnet instead of devnet.
Also fixes some missing from end point url conversions for target
resolving.

---------

Co-authored-by: Sophie <sophiedankel@gmail.com>
2024-05-16 09:02:39 +10:00
IGI-111
3c86abb400
Update clap and deps to latest version (#5994)
## Description

Update clap and deps to latest version

## 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-05-14 15:35:01 +04: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
Kaya Gökalp
b0af33479b
feat: fee estimation for forc-deploy and point --testnet to devnet (#5990)
## Description

Estimation is hard to test as it is dependent on the network
configuration but this is nearly the same thing we have been doing for
scripts.

1. `--testnet` points to devnet.
2. For the new `max_fee` requirement, adds an estimation phase with dry
runing the transaction
3. Various consts are pointed to relevant devnet endpoints.

Most visible outcome is that `forc-deploy --testnet` can deploy to
devnet without any other flags etc.

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-05-13 14:04:17 -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
Daniel Frederico Lins Leite
a7d35d3f09
Encoding v1 for Configurables (#5942)
## Description

This PR uses `AbiEncode` on configurables.  We can imagine that 

```sway
configurable {
    SOMETHING: u64 = 1
}

fn main() -> u64 {
    SOMETHING
}
```

will be desugared into

```sway
configurable {
    SOMETHING: slice = encode(1)
}

fn main() -> u64 {
    abi_decode(SOMETHING)
}
```

To allow this, now the whole `encode` function and all trait impls run
inside `const_eval`. To make this work, three new intrinsic were
implemented: `EncodeBufferEmpty`, `EncodeBufferAppend`, and
`EncodeBufferAsRawSlice`.

`EncodeBufferEmpty` creates an empty "encoding buffer", which is
composed of a pointer to the buffer, the buffer capacity, and how many
bytes were written already.

`EncodeBufferAppend` appends any primitive data types to the buffer.
This intrinsic does not mutate its argument, it returns a new "encoding
buffer". If no reallocation is needed, the pointer and the capacity stay
the same.

`EncodeBufferAsRawSlice` returns a slice with is composed of the buffer
pointer and its length (not the capacity).

### Errors

Some constant expressions cannot live inside the data section because
their encoding depends on some instance value, for example: string
slices, Vecs, Sttrings, Bytes etc... For these we now we return an error
in these cases, like

```
  error
            --> /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw:33:5
             |
          31 | 
          32 |     C6: str[4] = __to_str_array("fuel"),
          33 |     C6_2: str = "fuel as str",
             |     ^^^^ This code cannot be evaluated to a configurable because its size is not always limited.
          34 |     C7: [u64; 4] = [1, 2, 3, 4],
          35 |     
             |
          ____
```

## Future TODOs

This PR adds two more tasks to
https://github.com/FuelLabs/sway/issues/5727:

- Enable sdk-harness tests that were ignore. SDK needs to update
configurable encoding.
- Correctly error when a type with custom impl for AbiEncode is used in
configurables
- avoid decoding on each use

## 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: Igor Rončević <ironcev@hotmail.com>
2024-05-12 18:22:46 +01:00
Kaya Gökalp
85b9d9755b
feat: take dynamic asset id into account with forc-client (#5987)
## Description
Base asset ids are dynamic for the newer fuel-core versions. This PR
adds capability to query that and use it for forc-client transactions.
Also adds a flag `max-fee` which is required to be set for newer
versions of fuel-core.
2024-05-11 08:45:57 +10:00
Kaya Gökalp
fc4007dcdd
chore: bump to fuel-core v0.26.0 (#5981)
## Description

Bumps fuel-core to v0.26.0, for some reason sway-core was failing and
needed a blanket implementation for `Vec<T: PartialEqWithEngines>`
2024-05-10 11:11:13 +01:00
Joshua Batty
0c094706bf
Refactor forc-doc into a lib and add tests folder (#5971)
## Description
Just some cleaning up to make it easier to have a dedicated tests folder
with specific sway project fixtures. Similar to how sway-lsp is set up.

## 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 00:47:13 +00: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
Joshua Batty
b7a87f34a4
Code quality pass on forc doc (#5962) 2024-05-06 22:14:34 +00:00
Vaivaswatha N
20b8ff062e
Fixes to accessing the data section during bytecode gen (#5927)
## Description

This PR fixes a bunch of issues we had in generating access to the data
section. It also fixes #5876.

Reverts #5918.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-05-06 04:20:45 +00:00
João Matos
1fd9e4772a
Cleanup duplicated data from ty::TyDecl (#5751)
## Description

This PR cleans up the `ty::TyDecl` struct by removing fields for
duplicated data that we already have access through the engines. Have
not measured the true impact of this, but should have a noticeable
performance and especially memory improvement.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-05-06 03:23:39 +00:00
Joshua Batty
297de57a67
Larger clippy::pedantic and code quality pass on whole repo (#5945)
## Description
There's still a ton more to do but going to open this to get merged to
avoid conflicts. We can possibly add in some of these rules into CI in a
future PR.

## 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-04 14:00:56 -07:00
Kaya Gökalp
80c39d97c5
chore: use rust-sdk v0.58.0 (#5933) 2024-04-29 08:26:44 +00: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
João Matos
e8e6d3aa3a
Refactor read and write access to namespace modules. (#5868)
## Description

This PR prepares existing code that deals with (mutable) access to
namespace modules to work with an upcoming PR that introduces a module
ID for optimization purposes.

It also refactors the ABI code to pass engines around, which is
necessary for the same PR.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] 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>
2024-04-19 10:25:46 +04:00
Joshua Batty
60ea55e692
chore: bump to v0.55.0 (#5872)
## Description

waiting on #5871
2024-04-18 09:47:57 +02:00
IGI-111
d90cbc8419
Bump to v0.54.0 (#5853) 2024-04-13 04:03:01 +04:00
Kaya Gökalp
1f0d8563b6
chore: bump fuel-core to 0.24.2, fuel-vm to 0.48.0, sdk to 0.57.0 (#5844)
## Description

Updates fuel dependencies:

1. fuel-core to 0.24.2
2. fuel-vm to 0.48.0
3.  sdk to 0.57.0
2024-04-13 09:15:12 +10:00
Joshua Batty
b30f0e83d3
chore: bump to v0.53.0 (#5831)
## Description
Bump repo to 0.53.0

waiting on #5813

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-04-11 11:15:06 +00:00
Kaya Gökalp
3c2647cf36
chore: bump sdk to v0.56, fuel-core to 0.23.0, fuel-vm to 0.47.1 (#5759)
## Description

Update rust sdk to v0.56, fuel-core to v0.23.0 and fuel-vm to v0.47.1
2024-04-10 23:58:59 +00:00
César D. Rodas
bc2e603cbf
Add support for fig completions (#5669)
## Description

This fixes https://github.com/FuelLabs/sway/issues/5474

This is the first part of #5612, which will be split into several
smaller PRs


## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-04-04 14:39:14 -04:00
Kaya Gökalp
c1ea517f05
chore: bump to v0.52.1 (#5822)
## Description

Bump repo to 0.52.1
2024-04-03 12:57:19 +04:00
IGI-111
98d8f4cadb
Bump to v0.52.0 (#5791) 2024-03-27 13:22:13 +04:00
great9
fe77e1ab24
fix typo to beta-5 (#5731)
## Description
Typo fix. It should say beta-5

## 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: phiberdev <phiberdev@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-03-15 05:39:57 +00:00
huajin tong
089416fa24
remove repetitive words (#5699)
## 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] 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.

Signed-off-by: thirdkeyword <fliterdashen@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-03-14 23:45:20 +00:00
Vaivaswatha N
ddc420c439
Initial DWARF debug symbols output code. (#5521)
This PR adds support to express line number mapping from assembly to
source using DWARF object files. Since there are offset details that are
specific to the Fuel ISA, I'm using the existing `SourceMap` that's
already being built, rather than generating directly from the
instructions.

An important point to note is that DWARF uses line-col to express
positions rather than an absolute offset-from-start format. To avoid
computing line-col from absolute positions (which requires re-reading
the source files), I'm changing the source position format everywhere to
line-col. This also simplifies our code at many places (for example, in
`forc-debug`). The only exception is the `addr2line` tool, where the use
of absolute positions is in a function that seemed quite complex to me
to attempt changes. So I have, temporarily, added code to compute
absolute positions from line-col information and then reuse the existing
functions. This is inefficient, but I think that's _okay_ since it's a
standalone tool and the whole thing runs just once for every command
invocation.

The DWARF information is written to a file specified by the `-g` flag
and can be verified using `llvm-dwarfdump --debug-line ./test.obj`. If
the argument to the `-g` flag is a filename that ends with `.json`, then
the existing JSON format is written out, otherwise it's a DWARF object
in an ELF container.

---------

Co-authored-by: Joao Matos <joao@tritao.eu>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-03-14 12:08:07 +05:30