Commit graph

1324 commits

Author SHA1 Message Date
Daniel Frederico Lins Leite
e82c72be30
Only check non-parent monomorphization args (#6549)
## Description

This PR fixes https://github.com/FuelLabs/sway/issues/6384

The performance improvement is probably coming from just aggregating
spans when there is an error.

## Checklist

- [x] 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)
- [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.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-09-18 00:45:11 +00:00
Marcos Henrich
520bfe9168
Fixes panic error on decl_to_type_info. (#6552)
## Description

Doing an unwrap without checking if the value was none was causing a
panic. Fixed by throwing an error so we can also see the previous
errors.

Fixes #6330

## 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: Joshua Batty <joshpbatty@gmail.com>
2024-09-17 20:09:55 +00:00
Marcos Henrich
a073a95f6b
Fixes OOB in type_check_analyze of ImplTrait. (#6551)
## Description

An unused line of code threw an OOB panic because of a parser error.
Removing the unused line of code fixes the issue.

Fixes #6331

## 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: Joshua Batty <joshpbatty@gmail.com>
2024-09-17 12:04:13 +00:00
Marcos Henrich
db748659ba
Fixes unreachable on invalid cfg attribute arg. (#6553)
## Description

We now throw an error that enforces cfg arg to be a valid one.

Fixes #6326

## 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.
2024-09-17 21:40:18 +10:00
Daniel Frederico Lins Leite
fa3dafaa81
Remove subs type optimization causing find method issues (#6532)
## Description

This PR fixes https://github.com/FuelLabs/sway/issues/6491

## Checklist

- [x] 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)
- [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.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-09-12 05:52:04 +02:00
Daniel Frederico Lins Leite
439f9359e9
fix second pass of method application arguments (#6526)
## Description

This PR fixes https://github.com/FuelLabs/sway/issues/6487.

## 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.
2024-09-11 12:55:14 +00:00
Sophie Dankel
7d574a9279
fix: forc-test log decoding in libraries (#6518)
## Description

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

## Checklist

- [x] 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)
- [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.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-09-11 11:25:40 +10:00
Kaya Gökalp
31a1d6f983
chore: bump to v0.63.5 (#6508)
## Description

Bumps repo to v0.63.5
2024-09-06 18:31:11 +00:00
Igor Rončević
6fdc598755
Emit unreachable arm warning for OR match arms (#6505)
## Description

This PR fixes #6388. If a whole OR match arm is unreachable a warning
will be emitted like in this case:

```Sway
match v {
    1 => (),
    2 => (),
    1 | 2 => (), <<<--- Warning emitted here.
    _ => (),
};
```

The PR strictly fixes the issue reported in #6388. It does not fix a
previously known, more general issue, described in #5097 where we expect
warnings to be emitted also on individual elements of an OR arm, even if
the whole arm is reachable. E.g.:

```Sway
match v {
    1 => (),
    2 => (),
    1 | 3 => (), <<<--- Warning should be emitted here that `1` is not reachable.
    2 | 4 => (), <<<--- Warning should be emitted here that `2` is not reachable.
    _ => (),
};
```

Fixing this issue requires more invasive restructuring of the
propagation of the collected witness information and will be done in a
separate PR.

Closes #6388.

## 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.
2024-09-06 15:21:23 +02:00
Marcos Henrich
9132ca8ac8
Fixes mismatched types in ABI cast. (#6489)
## Description

ABI cast generates TypeInfo::ContractCaller which contains an address
that is an expression. While doing the first and second code block
passes we would obtain different expressions because of first passes
optimizations.

This PR disables first pass optimizations while type checking address
expression so there aren't any mismatched types.

## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-09-06 09:05:10 +01:00
IGI-111
2538442a67
Bump to v0.63.4 (#6503) 2024-09-05 20:30:44 +02:00
Marcos Henrich
cd95cdccbc
Fixes ABI alias metadata types. (#6494)
## Description

Before this push, using an alias in a contract would produce an ABI with
two distinct metadata types for tuples: one for `(_,_)` and another for
`(u64,u64)`.

With this change, aliases are bypassed and we only produce metadata for
the string type of the inner alias type. If alias is `(u64, u64)` we
will produce a metadatatype for `(_,_)`.

Fixes #6488

## 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>
2024-09-05 00:58:58 +00:00
Igor Rončević
e220ecab1e
Implement __contract_ret as diverging and retd as terminator (#6486)
## Description

This PR implements the `__contract_ret` as a diverging (returning `!`)
and accordingly the FuelVM `retd` instruction as being a terminator.
This strict semantics is needed in the #6351 which introduces strict(er)
verification of IR invariants.

## 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.
2024-09-04 10:56:27 -07:00
Marcos Henrich
a81c42eb18
Adds function return type unification. (#6490)
## Description

The function return type unification was missing, leading to generic
functions not being resolved based on the return type.

## 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: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-09-04 13:16:47 +02:00
Marcos Henrich
253330df2e
Fixes impl self duplicated missing error. (#6493)
## Description

While inserting trait implementations into the trait map we now compare
the implementing type_id without matching UnkownGenerics trait
constraints. Matching the trait constraints was causing a missing error.

Fixes #6381

## Checklist

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

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-09-04 00:58:48 +01:00
Igor Rončević
1bda0e8c98
Support FuelVM wqxx instructions in ASM blocks (#6484)
## Description

This PR adds support for FuelVM `wqxx` instructions in ASM blocks. Some
of those instructions were up to now partially supported in IR and ASM
generation but not in ASM blocks. The immediate motivation for adding
support for these instructions is the need for `wqml` instruction in the
new implementation of `u256::pow()`.

Additionally, the PR adds expressive diagnostics for
`UnrecognizedOpCode` parsing error.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-08-30 14:22:52 +02:00
Joshua Batty
f55c81cce6
Bump to v0.63.3 (#6483) 2024-08-28 23:57:55 -07:00
Marcos Henrich
40efa4687a
Reduces memory footprint of collecting unifications. (#6479)
## Description
As shown in https://fuellabs.github.io/sway-performance-dashboard/ #6461
introduced a bigger memory footprint.

Lexical scope has a shared OrdMap called
`symbols_unique_while_collecting_unifications` that was never cleared.
With this commit, it is cleared on each code block along with the clear
of collected unifications.

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

Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-08-28 23:39:02 +00:00
IGI-111
a9e83955bc
Bump to v0.63.2 (#6476) 2024-08-28 23:06:10 +02:00
Daniel Frederico Lins Leite
98877f836d
check if all required generic arguments are valid (#6462)
## Description

This PR fixes https://github.com/FuelLabs/sway/issues/6383,
https://github.com/FuelLabs/sway/issues/6390 and
https://github.com/FuelLabs/sway/issues/6385.

## 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.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-08-28 19:16:12 +00:00
Marcos Henrich
4698d37b91
Fixes Numeric type propagation (#6461)
## Description

To fix the Numeric type propagation we now do the type checking of code
blocks twice, first to collect all the unification and second to unify
the types of a previous namespace with the variable declarations types
of the current namespace.

This change incurs a performance drop in the compilation time. The
benchmark `compile` takes 25% more time to run.

This can be improved significantly by using LexicalScopes instead of
cloning the whole namespace on each scope.

Fixes #6371


## 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>
2024-08-28 18:57:19 +00:00
Marcos Henrich
4fc554c69e
Improves TraitMap performance. (#6471)
## Description

By using im::Vector inside TypeMap we avoid cloning everything when
cloning namespaces.

Improves TraitMap not to traverse all entries.

These changes incur a performance **increase** in the compilation time.
The benchmark compile takes 40% less time to run.

Fixes #6470.

## 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).
- [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>
2024-08-28 11:24:41 -07:00
Daniel Frederico Lins Leite
9403cd0aa8
Better error array numerics (#6420)
## Description

This PR fixes: https://github.com/FuelLabs/sway/issues/6376

The issue is that we use the first element of the array as its element
type. This can be problematic as the first element is not "concrete".
For example, when it is `Numeric`.

Now we iterate the array elements, search for the first "good" element,
and use its type as the array type. This means:
1 - if the type is concrete, we use it;
2 - if the type is `Numeric`, we keep searching for something better;

This allows consistent arrays, but where the concrete types are at the
end.

```sway
let a = [1, 2u8]; <- we will choose u8
let a = [None, Some(1), Some(2u8)]; <- we will choose Option<u8>, instead of Option<T>
```

## snapshot tests

This PR also brings an experiment. Now when an "e2e" test has a file
`snapshot.toml` it will run as `cargo insta` snapshot tests. These tests
can be run as normal: `cargo r -p test`, and in two new ways:

```
> cargo t -p test
> cargo insta test
```

Snapshots can be reviewed using normal "cargo insta" workflow.

The secret lies in https://github.com/LukasKalbertodt/libtest-mimic. **I
also want to suggest that all our tests migrate to this model**, where
we could just use "cargo test" normally. Apart from that, I opted to use
the `forc` executable, which means tests will run in parallel. In the
future, if we want to poke compiler internals, we can expose them using
flags, or create a special binary to fit our needs.

`snapshot.toml` is still empty because I have no idea to what put there
at the moment. My initial idea was to configure what ends up into
snapshots (multiple runs, compiler flags, script/contract calls) etc...
But for the moment, empty is enough.

## 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>
2024-08-26 13:28:25 +00:00
jjcnn
df5d19481f
Parse error on illegal statement (#6443)
## Description

Fixes #6327 .

When encountering an illegal statement the parser does not report an
error, but simply adds an error node to the parse tree. This error node
is transformed to AST error nodes, and the error goes unhandled until IR
generation. However, during IR generation the constant evaluator assumes
that no error nodes exist, which causes a panic in the compiler.

This PR changes the constant evaluator so that it now fails nicely when
encountering an error node.

It is possible to fix the problem in the parser instead, but I can't
find an easy way to do it that still allows for error recovery.

## 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>
2024-08-26 12:37:31 +00:00
João Matos
bb049669f0
Fix trait-related type inference propagation bug (#6455)
## Description

Trait methods end up passing an extra type parameter related to self.

What was happening is that we ended up creating a placeholder of a
placeholder in some cases, which threw the type inferencing system off.

The fix is to avoid creating a new type for a given type parameter if
its already a placeholder.

Fixes https://github.com/FuelLabs/sway/issues/6372.

## 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-08-24 00:29:16 +00:00
Marcos Henrich
4f08020bb7
Fixes panic on unwrapping in type_check_trait_implementation. (#6434)
## Description

This PR fixes panic on unwrapping by only performing the required
behavior with the unwrapped value when it is available.

Fixes #6336

## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-08-23 04:20:47 +00:00
jjcnn
ddad3aacd7
No limit on the depth of the return path analysis (#6435)
## Description

Fixes #6369.

The return path analysis performs a breadth-first traversal of the
control flow graph to determine whether every path returns a value.

So far the traversal has been limited to 50 iterations of the outer
while loop, meaning that if the graph has a depth of more than 50 there
are paths that would not be checked. The limit was introduced to ensure
that that the analysis terminated.

This PR removes this limit. Termination is ensured by keeping track of
which nodes have already been visited so that they are not visited
again.


## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-20 06:54:26 +00:00
Kaya Gökalp
169f91ae0a
Bump version to 0.63.1 (#6438)
## Description

Bumps version to 0.63.1
2024-08-19 20:34:40 +00:00
Sophie Dankel
da9b323070
chore: bump to 0.63.0 (#6421)
## Description

To be merged after https://github.com/FuelLabs/sway/pull/6250

## 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: Brandon Kite <brandonkite92@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-08-19 18:37:36 +02:00
Igor Rončević
7731c6b128
Fix scwq instruction and "phantom" error in purity checks (#6432)
## Description

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

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

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

Closes #6320.
Closes #6431.

## Demo

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

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

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

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

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

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

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-08-19 14:18:02 +00:00
Daniel Frederico Lins Leite
a82e954c17
Better checks at type_check_analyze (#6410)
## Description

Fix https://github.com/FuelLabs/sway/issues/6342 and
https://github.com/FuelLabs/sway/issues/6370.

https://github.com/FuelLabs/sway/issues/6342 occurs because when the
type checker unifies `Numeric` with an unsigned integer, it never checks
if the original literal actually fits into the new "unified" type.

https://github.com/FuelLabs/sway/issues/6370 happens because we never go
back to the array and check if every item actually is valid.

This PR is now doing these two tests at `type_check_analyze`.

## 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-08-16 01:19:07 +00:00
Joshua Batty
886c0b8c1b
Implement Typed Module Caching (#6280)
## Description
This PR implements a typed module caching system for the compiler when
interacted with from the language server. The main goal is to improve
performance by caching typed modules and reusing them when possible,
reducing unnecessary recompilation.

## Key Changes
- Introduced `CowCache` for efficient, thread-safe caching with
copy-on-write semantics
- Implemented typed module caching in the `QueryEngine`
- Updated `ServerState` and `Session` to utilize the new caching system


## Performance Improvements
These changes show promising performance improvements in processing
didChange events, particularly for larger projects. Here are some
benchmarks using the FUSD libraries Sway project (19 Sway files):

| Build | Before | After | Improvement |
|-------|--------|-------|-------------|
| Debug | 448.25ms | 123.73ms | 72.4% faster |
| Release | 103.83ms | 53.59ms | 48.4% faster |

These improvements should lead to a more responsive development
experience, especially when making frequent small changes.

closes #6228
improves: https://github.com/FuelLabs/sway-vscode-plugin/issues/172

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-08-15 22:05:57 +00:00
Marcos Henrich
25060f4f38
Updates JSON ABI, LDC, BSIZ, BLDD and ED19. (#6254)
## Description

Updates all the dependencies for the current release.

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

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

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

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

## Checklist

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

---------

Co-authored-by: Vaivaswatha Nagaraj <vaivaswatha.nagaraj@fuel.sh>
Co-authored-by: Kaya Gokalp <kayagokalp123@gmail.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-15 18:21:44 +01:00
João Matos
1c275bc800
Implement mutability checks for references to aggregate type fields. (#6415)
Fixes https://github.com/FuelLabs/sway/issues/6368.

## Description

Implements mutability checks for references to aggregate type fields.

## 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-08-15 05:45:48 +00:00
João Matos
798c0e24dc
Fix impl self node order dependency pass key collision issue. (#6407)
## Description

This fixes a key collision issue that happened in the node dependency
pass while handling `impl self` nodes with multiple blocks.

See the following example for a simple example of the problem:

```rust
struct A {}

impl A {   //dependency of this impl is overwritten by the next impl
    fn a() {}
    fn b() {}
}

impl A {   //this will overwrite the dependency for the previous impl
    fn ab() {}
}
```

Fixes the problem by introducing a `,` while joining the names for the
key.

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


## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-15 15:31:39 +10:00
João Matos
4c2c384302
Filter ABI supertrait methods from contract entry generation (#6402)
## Description

This PR filters out ABI supertrait methods from being considered for
contract function entry generation.

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

## 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-08-14 16:35:07 +00:00
IGI-111
273bc14789
Fix broken documentation link (#6400)
## Description

Closes #6392

## Checklist

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

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-09 10:32:37 +01:00
Igor Rončević
589d3b9f81
ASM blocks handling: inlining, DCE, ASM returns without return register (#6404)
## Description

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

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

Closes #6332.
Closes #6354.

## Bytecode size changes

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

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

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

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

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

</details>

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-08-08 08:30:15 +00:00
Marcos Henrich
2332025661
Fixes unreachable macro crashing compiler. (#6362)
## Description

In case of a bad input given to the lexer, it is possible to generate an
AST with invalid ImplItem tuples.

This fix replaces the unreachable macro with an CompileError::Internal.
This allows the user to see the lexer errors and fix them which will
also address the new errors.

Fixes #6339.

## 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: João Matos <joao@tritao.eu>
2024-08-07 23:23:48 +00:00
IGI-111
a6f1ebe3ab
Add error for duplicate struct field initialization (#6401)
## Description

Fixes #6378

## Checklist

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

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-07 19:30:51 +00:00
Daniel Frederico Lins Leite
d5aa2d6da6
fix size of configurable buffer for enums (#6366)
## Description

This PR fixes an issue where the encoded bytes for enums were not big
enough for the biggest variant.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] 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.

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-08-07 20:53:25 +02:00
Marcos Henrich
cd0213a47b
Fixes crash on encode_buffer_append with wrong args. (#6365)
## Description
When encode_buffer_append was called with a wrong number of args an
array OOB panic was thrown.

With this fix we throw a CompileError::IntrinsicIncorrectNumArgs in case
the intrinsic encode_buffer_append is called with more or less than the
expected 2 arguments.

Fixes #6337

## 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: João Matos <joao@tritao.eu>
2024-08-07 13:49:29 +00:00
Marcos Henrich
a906afaae2
Fixes assert in type_check_encode_buffer_empty. (#6364)
## Description

Assert in type_check_encode_buffer_empty was causing the compiler to
crash.

We now throw a CompileError to avoid crashing.

Fixes #6338.

## 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.
2024-08-07 13:22:06 +00:00
Daniel Frederico Lins Leite
afd6a6709e
Slice/Array intrinsics: __slice and __elem_at (#6282)
## Description

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

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

## Out of bounds checks

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

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

## Empty Array

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

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

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

## Check of constants inside fns

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

## Small improvements for our e2e

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

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


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


## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
2024-08-07 02:00:09 -07:00
João Matos
159f049adb
Introduce a new symbol resolving pass (#5809)
## Description

This PR implements a new AST resolution approach that resolves symbols
using the information from the collection context.

To achieve this, we introduce a new `ResolveSymbols` trait and
`SymbolResolveContext` context type.

Parsed nodes now contain a `resolved_call_path_binding:
Option<TypeBinding<ResolvedCallPath<ParsedDeclId<...>>>>`, which contain
the resolved call path binding that references the `ParsedDeclId`
relative to the resolved name. This field is resolved by the new
`resolve_symbols` pass, which mutates the `resolved_call_path_binding`
as it walks through the nodes.

Most of the name lookups are implemented in the new
`SymbolResolveTypeBinding` which is equivalent to the existing
`TypeCheckTypeBinding` (to be removed once everything is migrated in the
type checker).

The only exception right now are `DelineatedPath` and
`AmbiguousPathExpression` which are not being fully resolved yet (though
there is a draft PR right now with some of this ongoing work).

Also to note there are a handful of unused functions in the context that
will be used in the next PRs.

These are the main commits:

[Implement
Declaration::TraitFn.](8da322351f)

[Implement decl_engine_parsed_decl and
get_parsed_decl.](dd6f5e6974)

[Fix lexical scope id calculation on
creation.](e16d996325)

[Add symbol resolve
context.](e9356cc429)

[Collect nodes inside each function body and keep a reference to their
lexical
scope](e327345ef3)

[Resolve alias declarations when resolving struct
symbols.](2c8dc647d9)

Partially closes #5379.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-08-06 08:18:57 -07:00
Igor Rončević
24e7ebfcea
Additionally test associated constants (#6349)
## Description

This PR strengthens existing and adds new tests for associated
constants. This extended test coverage revealed the following existing
issues: #6310, #6348, #6345, #6346, #6343, #6344.

It also pointed out that we are missing rules for a contract
implementing several ABIs with overlapping interface surfaces, where
constants can also be overlapping: #6306.

All the issues are linked to tests via TODOs in code that is commented
out. We will address the issues in separate PRs. With this PR, we want
to first have tests in place.

Additionally, the PR:
- cleans up dead code that become obsolete when `TyConfigurableDecl` was
introduced in #6058.
- deletes some redundant tests for constants.
- groups some tests to reduce test compilation and execution time and
provides guidelines for such groupings in the testing README.md.

## 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.
2024-08-02 09:00:48 +10:00
Igor Rončević
508554547f
Forbid configurables in pattern matching and shadowing (#6289)
## Description

This PR:
- emits errors when configurables clash with global constants of the
same name
- forbids shadowing configurables with local constants or variables
- forbids matching against configurables in pattern matching

Before #6058, it was just the flag `is_configurable` in `TyConstantDecl`
that marked constants as configurables. The first two points were
implemented for `TyConstantDecl` and, thus, worked both for constants
and for configurables. When introducing `TyConfigurableDecl` we forgot
to extend those checks to cover the new type declaration.

The third point fixes a bug that allowed matching against configurables,
although they are not compile-time constants.
Originally, matching was done against the configured value, which was
treated as a constant, even if changed during the deployment.

After introducing `TyConfigurableDecl`, because of a bug, configurables
were treated as pattern variable declarations.

This PR brings back the original shadowing behavior and forbids matching
against configurables in pattern matching.

Forbidding configurables in pattern matching can cause confusion,
knowing that regular constants can be matched against. A special
consideration was given to explain to developers why this is the case.

## Breaking Changes

There were two releases in between. Theoretically but unlikely, it could
be that some code appeared that e.g., shadows configurables. In such a
case, the change in this PR will be breaking and cause compiler errors.

## Demo

![Constant of the same name as configurable already
exists](https://github.com/user-attachments/assets/caa84d32-f661-414c-b2e8-869ae2c2d297)

![Configurables cannot be shadowed -
Variable](https://github.com/user-attachments/assets/e95675fa-6754-4e33-bb15-ff923dcb5eba)

![Configurables cannot be matched
against](https://github.com/user-attachments/assets/aebd6462-d254-484b-abaf-45a3ce7ef263)

## 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.
2024-07-22 22:31:28 +10:00
jjcnn
de853614a2
Make module name mandatory and private (#6271)
## Description

Partial fix of #5498 .

So far the `name` field in `namespace::Module` has been public and of
type `Option<Ident>`. This makes little sense, since the name of a
module should always have a value, and should retain that value once it
is set. This PR fixes this problem.

The `visibility` and `span` fields have also been made private.
`visibility` can be read-only, but there is a single instance in which
the `span` field must be set later, so I have added a setter for that
field too.


## 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>
2024-07-20 08:51:13 +10:00
IGI-111
e9cdaacaf1
Remove support for namespace attribute (#6279)
## Description
Namespace annotation is no longer supported and has been replaced by
namespacing syntax.


## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-07-19 13:53:59 +02:00
IGI-111
efda0397c7
Bump to v0.62.0 (#6276) 2024-07-18 09:13:09 +10:00