## Description
This PR implements `Display` and `DisplayWithEngines` for some more
types to help with debugging.
## 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.
## Description
This PR is part of https://github.com/FuelLabs/sway/issues/5727.
Fix the issue of trying to solve expressions that were typed as
`ErrorRecovery` inside `const_eval`.
## 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.
## 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.
## 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.
## Description
Switching from `std::sync::RwLock` to `parking_lot::RwLock` is giving us
a 10% further performance increase.
before: `13.459551958s`
after: `12.125325542s`
## 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.
## 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.
## Description
This PR:
- removes the redundant calls to `compile_declarations` function and the
function itself. The function was used in early versions of Sway, but
the way we compile items to IR has changed: functions are compiled at
call site, and structs and enums are inlined at instantiation site. In
the end, the function was only compiling constants, but that was already
done in the dedicated `compile_constants` calls.
- removes the `inline_main` optimization which was aggressively inlining
the whole program into `main` function. This was a necessity in early
versions of Sway and is not used anymore.
## 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.
## 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.
## 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>
## Description
Fixes#5940.
This PR deals with the situation where the same name is imported by
multiple star imports, e.g.,
```
// a.sw
struct X = ...
// b.sw
struct X = ...
// main.sw
use a::*;
use b::*;
```
So far we have resolved this name clash by letting the latter import
shadow the former, which is incorrect.
The correct behavior is to allow the import without error, but to report
an error if the unqualified name (i.e., `X`) is used (qualified names
`a::X` and `b::X` are legal)`. This PR fixes this problem.
Note that if `X` is imported multiple times, but each time is bound to
the same entity (e.g., because it is imported both through
`core:;prelude` and `core::codec`), then this should not cause an error.
Note also that there is a problem with the implicit imports from the
core and std preludes, which in some cases causes the implementation to
think that a name is bound to multiple different entities, even though
the entities are actually the same. As a workaround anytime a name is
imported from either `std` or `core` when it is already imported from
`std` or `core`, the new binding replaces the old one instead of being
added as a new binding.
Unfortunately this workaround means that it is not currently possible to
redefine and use a name that exists in `std` or `core`, e.g., to create
a specialized version of `assert_eq` as is done in one of our tests. To
use such a redefinition one must use a qualified name for the entity,
which seems like an acceptable workaround. (Note that this only applies
if the redefined entity is imported using a star import - if imported
using an item import (`use a::X;`), then there is no issue).
Once #3487 is implemented this workaround should no longer be necessary.
## 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: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
Bumps fuel-core to v0.26.0, for some reason sway-core was failing and
needed a blanket implementation for `Vec<T: PartialEqWithEngines>`
## Description
Using the same performance test as in #5976 and #5978, this change gives
a further 21.33% performance improvement.
Before: Elapsed time: `14.653166459s`
After: Elapsed time: `11.527667375s`
## Description
The [`im` docs](https://docs.rs/im/latest/im/) state that the
performance of `HashMap` is similar to that found in `std` but the
`ImOrd` is between 2-3x slower than `BTreeMap`. Changing submodules from
using `im::OrdMap` to using `im::HashMap` is giving us a nice
performance win.
I tried compiling the libraries project from fluid protocol as a test,
it has 19 seperate libraries. This change gives us a 21.25% speed
increase.
Before: Elapsed time: `27.968193458s`
After: Elapsed time: `22.02603425s`
Running the compile benchmark in LSP is showing a 29% improvement.
Before: Elapsed time: `3.8328s`
After: Elapsed time: `2.7086s`
---------
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## 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.
## 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.
## 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>
## 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>
## 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.
## Description
Fixes#5912, #5713 .
Item imports with aliases `use x::y as z` have so far been represented
using two maps:
- A synonyms map mapping `y` to the type declaration of `x::y`.
- An alias map mapping `z` to `y`.
This is confusing, since `y` is not actually bound by this import, and
unsurprisingly has lead to a bug because of a name capture (see #5713).
This PR eliminates the alias mapping, and changes the synonyms map to
map `z` to the type declaration of `x::y`.
## 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.
## Description
Fixes#5913 .
Name resolution for imports and top-level items in module currently
happens at the module level, in part by traversing the submodules of the
current module.
This PR moves name resolution to the root of the module structure.
This refactoring is needed to enable fixes to the following issues:
- #5713 : The resolved type declaration must be understood in the
context of the declaring module rather than in the context of the
importing module, which means that name resolution must happen across
the module structure.
- #5498 : The modules from which items are imported are currently
introduced as submodules to the importing module (in addition to their
absolute location in the module hierarchy). To remove those submodules
the name resolution algorithm needs access to the full module hierarchy,
which it can get by having access to the root of the hierarchy.
## 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: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## 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:


After:


Expression cannot be assigned to:

## 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.
## 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: toofooboo <cmaker@foxmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## 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.
## Description
Fixes#5911 .
So far all imported items in a module have been collected in single map,
with a flag in each value indicating whether it was the result of a
glob/star import or an item import (this distinction matters because
item imports shadow glob imports).
This PR splits the map in two: One for glob imports and one for item
imports. This simplifies name resolution, and eliminates the
`GlobImport` flag.
When another module imports all reexported items the logic is now
slightly more complex, but this will be resolved once the excessive
cloning of namespaces, modules and typed declarations are eliminated.
## 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.
## Description
We now do the return type unification before doing the second pass of
arguments type checking in method application type checking.
Doing the unification sooner fixes the problem we were having while
doing:
```
let mut bytes = Bytes::new();
bytes.push(1_u64.try_into().unwrap());
```
With the unification sooner we will unify the return of unwarp with the
type annotation of the push argument before we do the type checking of
`1_u64.try_into()`. By the time we do `1_u64.try_into()` we will already
have the type parameter `U` unified with u8.
Fixes#5802.
## 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.
## Description
When using trait constraints a blanket implementation is added for the
trait constraint generic parameter.
This changes avoid the generation of other implementations from the type
parameter generic implementation.
Fixes#5873
## 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.
## 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>
The new encoding can handle functions with pointer arguments.
So this change reverts #4899. That PR also added a test which now passes
without the forced inlining.
Also see #2819, which first introduced this hack.
## Description
Adds DCE before running other optimizations on the backend.
Running DCE before other optimizations reduces compile time in compolabs
project from over 40 minutes to 76 seconds.
Fixes#5769
## 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)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
This PR:
- closes#5803 by providing the proper error message that `mut` is not
implemented in pattern matching. Support for `ref`, `mut`, and `ref mut`
in pattern matching will be done later as a part of support for
references in pattern matching.
- closes#5846 by checking if aliased type can be matched.
- provides `Diagnostic` for the `Unimplemented` error and removes the
`UnimplementedWithHelp` error.
- differentiates between unimplemented features and features that are
actually semantically not supported. Previously, `Unimplemented` error
was used for both which emitted misleading errors in `match` expressions
and trait implementations.
Closes#5803, #5846.
# Demo
Before:

After:

Diagnostic for `Unimplemented` error:

## 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.
- [ ] 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.
## Description
DCA warnings were missing when methods call return in some places.
Changes e2e test runner to use file checker in tests with category runs.
Fixes https://github.com/FuelLabs/sway/issues/5666
## 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).
- [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>
## Description
When a fully qualified path was used inside a library using a type
within the same file the symbol would not be found.
Fixes#5826
## 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: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## Description
ReplaceDecls for method application was calling replace_decls twice for
FunctionDecl. This was visiting function declarations as a binary tree,
doing replace decls twice per FunctionDecl.
With these changes, we merge both decl mappings before calling
replace_decls once instead of twice.
The performance dropped from over 2min(did not wait for test to finish)
to 7 seconds in the mega example. With --experimental-new-encoding and
--release.
## 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.
## Description
Partially addresses https://github.com/FuelLabs/sway/issues/5781.
This reduces the problem of millions of TyFunctionDecl being created.
For more details see: https://github.com/FuelLabs/sway/pull/5782
## 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.
## Description
This PR improves fix a problem when a type cannot be auto-impled and
improve error messages for this case.
This can be seen on `tests/types/contracts/type_inside_enum` in the Rust
SDK repo.
```
Running `target/debug/forc build --path /home/xunilrj/github/fuels-rs/packages/fuels --experimental-new-encoding`
thread 'main' panicked at sway-ir/src/constant.rs:172:14:
Enums are aggregates.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
Given that this PR also improve implementation of arrays for `AbiEncode`
and `AbiDecode`, the entry function is actually generated. But in case
of error, it will fail like:
```
error
--> /home/xunilrj/.forc/git/checkouts/std-9be0d6062747ea7/5645f10143243e1fd64a55002cd5c09730636ece/sway-lib-core/src/codec.sw:2192:8
|
2190 |
2191 | pub trait AbiDecode {
2192 | fn abi_decode(ref mut buffer: BufferReader) -> Self;
| ^^^^^^^^^^ No method named "abi_decode" found for type "SomeEnum".
2193 | }
|
____
error
--> <autogenerated>:5:61
|
3 |
4 | let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
5 | let result_arr_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_arr_inside_enum(args.0));
| ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
6 | __contract_ret(result_arr_inside_enum.ptr(), result_arr_inside_enum.len::<u8>());
7 | }
|
____
error
--> <autogenerated>:24:61
|
22 |
23 | let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
24 | let result_str_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_str_inside_enum(args.0));
| ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
25 | __contract_ret(result_str_inside_enum.ptr(), result_str_inside_enum.len::<u8>());
26 | }
|
____
error: Could not generate the entry method because one of the arguments does not implement AbiEncode/AbiDecode
____
Aborting due to 4 errors.
Error: Failed to compile type_inside_enum
````
## 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.
## Description
Partially addresses https://github.com/FuelLabs/sway/issues/5781.
This reduces the time spent retrieving items in slabs.
For more details see: https://github.com/FuelLabs/sway/pull/5782
## 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.
- [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>
## Description
Partially fixes https://github.com/FuelLabs/sway/issues/5781.
This reduces the problem of millions of `TypeInfo`s being created.
For more details see: https://github.com/FuelLabs/sway/pull/5782
## 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>
## Description
This PR unifies the codepaths in trait map and name resolution code so
they can work for both parsed and typed declarations.
It does this by introducing wrapper types for the output of resolving of
names.
This is an intermediate step to being able to use this code on the new
symbol resolving pass.
While this adds a little bit of minor bloat to the code, I think it's an
acceptable further step to be able to do re-use the code in steps before
type-checking.
## 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>