Commit graph

2324 commits

Author SHA1 Message Date
João Matos
f4b155f337
Split processing of impl methods in two phases (part 1). (#4890)
## Description

This PR mainly refactors existing code around type checking and
processing of functions.

[Split type checking and namespace insertion for parameters and type
parameters](327deace24)

[Split processing of functions in two
phases.](e3cf148f3f)

I've split this up from the rest of the PR for fixing impl methods
calling to make it easier to review (also made it easier for me to find
and fix some regressions).

I also threw in another round of clippy fixes that my Rust toolchain was
complaining about.

## 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.
2023-08-07 23:40:09 +01:00
Vaivaswatha N
b6c95b5de7
Bugfixes on enabling simplify-cfg at the end of optimizer pipeline (#4903) 2023-08-07 15:53:08 +02:00
Joshua Batty
227cb2b264
Refactor parse_project to return a result. (#4922)
## Description
This PR refactors the `parse_project` method to return a result instead
of writing to internal types in place. This helps to seperate the
parsing and writing logic into seperate phases, useful for future work
where we execute parsing on seperate threads.

I've also tried to clean up the `Session` interface at the same time.
2023-08-07 21:20:08 +10:00
Daniel Frederico Lins Leite
943c67cb1a
u256 more operations (#4904)
## Description

This PR is part of https://github.com/FuelLabs/sway/pull/4794 and
implements more operators for u256:
- [x] sub
- [x] mul
- [x] div
- [x] comparisions
- [x] mod

## 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: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
2023-08-07 10:35:06 +02:00
Kaya Gökalp
36da3cfb91
feat: enable providing main arguments to a script with forc-run (#4603)
## Description

closes #3439.

This PR adds `--args` flag and encoding capabilities to `forc-run` so
that users can provide inputs to main function of the script they are
running.
2023-08-04 14:41:33 -07:00
IGI-111
d8cf611840
Bump to v0.43.2 (#4907) 2023-08-03 18:23:32 +02:00
IGI-111
923157bcf1
Use buildjet runner for gh-pages workflow (#4902)
The regular runner runs out of memory at this point, switching to this
one should solve this problem.
2023-08-03 12:16:25 +01:00
Daniel Frederico Lins Leite
390b945e65
u256 add operator (#4896)
## Description

This PR is part of https://github.com/FuelLabs/sway/pull/4794. It
implements support for u256 add operators.

The IR generated is a vanilla `add` operator as any other integer.

```rust
script {
    entry fn main() -> u256, !1 {
        entry():
        v0 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !2
        v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !3
        v2 = call add_0(v0, v1), !4
        ret u256 v2
    }
}
```

This will then be transformed by `miscdemotion` pass to something like:

```rust
script {
    entry fn main() -> u256 {
         local u256 __wide_lhs
         local mut u256 __wide_result
         local u256 __wide_rhs
 
        entry():       
         v0 = get_local ptr u256, __wide_lhs, !0
         v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !0
         store v1 to v0, !0
         v2 = get_local ptr u256, __wide_rhs, !0
         v3 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !0
         store v3 to v2, !0
         v4 = get_local ptr u256, __wide_result, !0
         wide add v0, v2 to v4, !0
         v5 = load v4, !0
         ret u256 v5
    }
}
```

Mind the `wide add` here. It is a Fuel specific operation, giving space
to other targets to implement this differently.


## 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.
2023-08-02 21:47:26 +00:00
IGI-111
3efc60e22b
Bump to v0.43.0 (#4897) 2023-08-02 22:57:10 +02:00
Vaivaswatha N
1cb1a46bcd
Workaround: Do not inline functions that have pointer args (#4899)
This reverts the inliner change that was done in #4823.

Without this, when sharing stack data across contract boundaries, we end
up with an illegal access.

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2023-08-02 19:07:32 +02:00
Marcos Henrich
1799db80c1
Fixes replace_decls issue with nested and multiple types. (#4889)
## Description

When a single method uses multiple trait implementation errors are
thrown by the compiler similar issue occurs when a method requires a
trait implementation and then calls another method that requires another
implementation of the same trait.

This PR fixes both issues by filtering traits to be replaced by the
arguments type used and trait method self type, and by gathering decl
mapping of nested methods.

Fixes #4852

## 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.
2023-08-02 18:42:43 +02:00
Igor Rončević
6015013c8b
Support multi-span errors and warnings (#4892)
## Description

A new `Diagnostic` type is introduced for detail description of compile
errors and warnings. The change is backward compatible. The existing
`CompileWarning`s and `CompileError`s will continue render as they had
before.

The `Diagnostic` is formed out of a:
- _Level_: Error or Warning.
- _Code_: Unique error or warning code. Placeholder for future. Not used
at the moment.
- _Reason_: Short description of the diagnostic, not related to a
specific error/warning. Answers the question "Why is this an
error/warning?" E.g., Because - "Constants cannot be shadowed".
- _Issue_: Short description of the concrete case that the compiler has
found. E.g., "Variable "X" shadows imported constant with the same name"
- _Hints_: Detailed description of the diagnostic placed in the source
code.
- _Help_: Additional friendly information that helps understanding and
solving the issue, but which is not related to a place in code.

![07C Constant shadowing - Alias - After 02 -
Terminology](50c639a1-43f5-4bc2-afa2-5717652f0172)

The `Diagnostic`s are defined imperatively in code right now, pretty
much the sam way we do `CompilWarning`s at the moment. Development of a
proc-macro that should make de definitions declarative is out of scope
of #21.

## Known Limitations

The `annotate-snippets` library has a bug and a missing functionality
for which I opened issues:

- Wrong display of line numbers when using folding of lines of code.
This issue is fixed but there is no patch release provided:
https://github.com/rust-lang/annotate-snippets-rs/issues/52#issuecomment-1657829040
- No possibility to remove the "note:" prefix as shown on the image
above: https://github.com/rust-lang/annotate-snippets-rs/issues/59

These two issues are not blocking. Proposal is to wait for the official
support in the library, or contribute or in the worst case make a
workaround in our code.

## Demo (Before and After)

### Errors
![07A Constant shadowing - Alias -
Before](5d67c5e5-d456-4762-b7c7-6fcf7340d6b3)

![07C Constant shadowing - Alias - After
02](02691b39-3d08-4776-ba93-5ffeca4546ed)

### Warnings
![06A NonScreamingSnakeCaseConstName -
Before](c27279d4-0e6c-4d05-9b00-da7121bb60ad)

![06B NonScreamingSnakeCaseConstName -
After](483044f3-f190-4506-9e9e-2d03d70cb3f2)

Closes #21

## 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.
- [ ] 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.
2023-08-02 10:50:52 +02:00
IGI-111
f48268ea5e
More error handling refactoring (#4895)
## Description
This changes addresses the issues introduced in #4878

The `error_emitted` pattern is replaced by a scoping method on `Handler`
that collects errors within a closure and will error out if new erros
are introduced.

All instances of introducing `ErrorEmitted` as a literal value have now
been replaced by passing arround the receipt of the error emission
through the error representing values. Some types from the AST had to be
moved to `sway-types` to avoid circular dependencies introduced by this
change.

This also repairs some of the discrepancies to emitted warnings
introduced in #4878, as well as rename some of the `Handler` methods.

Fixes #4885
Fixes #4886

## 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.
2023-08-01 16:12:53 +01:00
Joshua Batty
0341a7ed3c
refactor did_* lsp notifications to log errors in server module (#4894)
## Description
This PR just bubbles up any errors to be logged in the server module
rather that in the `did_change` `did_open` or `did_save` methods. Also
made the resync temp folder with workspace logic it's own method on
`sync`.
2023-07-31 21:21:58 -05:00
João Matos
670281d3fb
Another round of fixing warnings. (#4888) 2023-07-31 15:30:52 +00:00
Daniel Frederico Lins Leite
ad856d2851
Support for u256 constants (#4887)
## Description

This PR is part of https://github.com/FuelLabs/sway/pull/4794. It
implements the bare minimum to support `u256` constants across the
stack.

They are represented in sway in hex literals with `u256` suffixes. Hex
without suffix will still be `b256`, for backward compatibility until we
implement `u256` completely. Then we can decide what to do.

There are multiple places in the code that will fail if the literal does
not fit in u64. This will be fixed later in a specific PR for big u256.
Some places have temporary `unwrap()`, that will be removed later. I can
try to remove them now, if necessary.

I am leaving all documentation updates for when everything is
implemented.

## 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: Anton Trunov <anton.a.trunov@gmail.com>
2023-07-31 15:22:01 +01:00
IGI-111
f5f8566e8c
Refactor compiler error handling (#4878)
## Description

Change error handling to use `Handler` instead of the macro based
`CompileResult`.

Fix #2734

## 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.
2023-07-29 15:19:59 +00:00
Sophie Dankel
492870bb9f
Custom on_enter LSP method (#4876)
## Description

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

Moves the on_enter capabilities to a custom LSP method that simply
returns the edits to the client, rather than directly applying the edits
as part of did_change.

With this approach, there is still some lag if you hit enter many times,
but it seems to be working better than before.

## 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).
- [ ] 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.
2023-07-28 09:56:17 -07:00
Anton Trunov
d2c1f03548
SuperABIs for ABIs (#4272) 2023-07-27 08:45:50 +04:00
andrewvious
eb49be8597
Update CallPath<T> impl of Display (#4873)
## Description
avoids the extra `String` alloc from `to_string()`.
Closes #2225

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
2023-07-26 23:34:42 +02:00
Mitchell Mackert
2bb072496d
chore: remove unused keys from examples under sway repo reference (#4854)
## Description

This PR removes unused keys in sway reference so that warnings do not
appear while searching for std after creating a new project with `forc
init`.

Closes #4709 
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
2023-07-26 16:11:36 +00:00
Cameron Carstens
660abd9acd
Use the Self annotation in implementation blocks (#4871)
## Description

In Rust, when implementing traits the type `Self` is used instead of the
concrete type. This provides a more flexible and generic API design and
it promotes code reusability and simplifies the creation of fluent
interfaces. The same has now been done for Sway.

## 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).
- [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: bitzoic <bitzoic.eth@gmail.com>
2023-07-26 15:02:07 +00:00
Joshua Batty
cab7e33271
Assign correct type_defs to struct field and function param names (#4858)
## Description

closes #4857
2023-07-25 10:34:30 +00:00
Joshua Batty
a1d56228e3
assign correct semantics to struct expression name accounting for Self (#4860)
## Description

closes #4859
2023-07-25 10:08:48 +00:00
Joshua Batty
5670deae64
temp remove publish_diagnostics_dead_code_warning test (#4856)
## Description

Temporarily removing the `publish_diagnostics_dead_code_warning` test so
it unblocks our CI until I can work out how to fix it. See #4855
2023-07-25 12:45:51 +04:00
Hannes Karppila
f744dbb1bb
Update fuel-core to 0.19 (#4718)
Updates fuel-core, fuel-vm, and other fuel-* and fuels-rs dependencies
to versions corresponding to fuel-core 0.19 release.

---------

Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
2023-07-25 02:42:25 +01:00
João Matos
96047463a0
Fix clippy warnings introduced recently. (#4853)
These have been introduced in
b33b63c108.

## Description
2023-07-24 14:39:59 +00:00
JC
b19174afcf
Correct usage of terms "ABI" and "JSON ABI" (#4847)
This PR clears up usage of terms "ABI" (our actual ABI) and "JSON ABI"
(the JSON representation of our ABI).

What we really actually have here is the "Rust ABI" but we can drop the
"Rust" and just call it "ABI".

Other ABIs would be the "TypeScript ABI" generated by fuels-ts, and the
"GraphQL ABI" I'm planning to work on.
2023-07-24 11:16:08 +00:00
Kaya Gökalp
c3d75e73ea
feat: forc-deploy suggests creating a new wallet if the wallet is missing (#4827)
## Description
closes #4754.

If the default path does not contain any wallet, forc-deploy
automatically suggests creating a new one via forc-wallet:

```console
Could not find a wallet at "/Users/kayagokalp/.fuel/wallets/.wallet", would you like to create a new one? [y/N]: y
Please enter a password to encrypt this private key: 
Please confirm your password: 
Wallet created successfully.
```
At this step a new window opens with your mnemonic just like
forc-wallet's new flow. User pres enter:
```console
Please provide the password of your encrypted wallet vault at "/Users/kayagokalp/.fuel/wallets/.wallet":
Do you accept to sign this transaction with fuel13pudgkhq9pmsj3s2nwxmsmydqnau3lcpn5m70jrg5mrw0dlc3r8qz6pjdk? [y/N]: y
```

User is asked for their password again, to prevent this I need to cut
another release to forc-wallet which is currently blocked. So I will fix
that in a follow-up PR.
2023-07-23 08:01:54 +00:00
Anton Trunov
5e04dfa989
Make ABI impl methods part of contract interface (#4843)
Fixes #4841

## Description


## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2023-07-21 14:09:27 +02:00
Joshua Batty
b33b63c108
Collect module kind span for ParseModule (#4822)
## Description
This PR replaces collecting the dummy spans for the module kind token
with the span of the module kind.

These were introduced in #4232. This was causing an issue in the
language server where we were unable to debug parsed tokens as warnings
if the span was all 0's.

closes #4809
2023-07-21 11:38:12 +03:00
Vaivaswatha N
5318edd06e
Don't force inliner in case of ref type function args (#4823)
This was required previously, but after the IR refactoring (#4336), this
is no longer required, and actually worsens things.

Fixes #4747. For the two tests mentioned there, (both based on
https://github.com/hashcloak/fuel-crypto/) the compile time now comes
down from
1. 30m -> 16s
2. 180m -> 31s

Also fixes two bugs uncovered:
1. Bug in DCE - Fixes #4763.
(1b512b87d2)
2. Bug in interaction b/w asm gen and reg alloc spiller
(7a404967e7).

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2023-07-21 09:52:16 +05:30
IGI-111
303a7a3acf
Numeric type inference (#4829)
## Description

This does two things.

1. Integer types no longer automatically cast to each other. Methods
such as `as_u64` and `try_as_u8` have been introduced to require the
user to explicit the cast.
Warnings about casts losing precision have been removed as they are no
longer possible.

2. Numeric literals (such as `32` without further qualifications) no
longer immediately decay to a `u64` and we instead attempt to type them
as `TypeInfo::Numeric` as far as possible to allow their usage with any
integer type.
Numeric intrinsics unify arguments with the numeric type to enforce
their constraints.
Numeric values are forced to decay to `u64` when resolving methods or
traits.

This change is a prerequisite to move our representation of
sub-byte-sized values to a different memory representation, as numeric
types need to be distinct if we are ever to treat them differently.

Fixes #3470

## 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: Joshua Batty <joshpbatty@gmail.com>
2023-07-21 04:37:13 +02:00
Anton Trunov
55dd65463a
Show compiler error messages for unit tests that do not compile (#4840)
Fixes #4839

## 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).
- [ ] 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.
2023-07-21 08:58:32 +10:00
Marcos Henrich
686f5e0527
Fixes generic trait methods not found. (#4807)
## Description

The issue this commit solves is the method not found error thrown when
we try to use generic traits.

This issue was fixed by calling `insert_trait_implementation_for_type`
while resolving
tuples and arrays, we also call `insert_trait_implementation_for_type`
as
a fail-safe when a method is not found.

 Fixes #4806
 Unblocks #4701

## 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: Anton Trunov <anton.a.trunov@gmail.com>
2023-07-20 13:11:32 +00:00
Kaya Gökalp
99f4a80016
ci: bump nightly rust version to 2023-04-01 (#4825)
## Description
Unused dependency check is failing as nightly version that we use for
that step is too old for fuels-program v0.44 dependency which is being
added in a separate PR. (failing PR: #4771)
2023-07-20 12:24:14 +02:00
Cameron Carstens
5d27e25779
Remove dependency on external library for Ownership example (#4832)
## Description

It was noted that in the case of a breaking change to the std-lib, the
external Ownership library would need to be updated, which depended on
the std-lib creating a circular dependency.

The external library has been removed from the example and a skeleton of
its implementation has been added with a link to the actual
implementation.

## 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: bitzoic <bitzoic.eth@gmail.com>
2023-07-19 14:59:30 +00:00
Igor Rončević
cdf825a595
Give more helpful error when shadowing constants (#4819)
## Description

- Introduce three distinguished new error messages on const shadowing as
defined in #4587:
  - Variables shadowing constants.
  - Constants shadowing variables.
  - Constants shadowing constants, _item-style_ and _sequentially_.
- _Item-style_ and _sequential shadowing_ are added as an explicit
concept to the `TypeCheckContext`. This follows the same pattern that we
have in passing _ABI mode_ and _disallow functions_ contextual
information. Basically, the parts of the semantic analysis lower in the
chain need contextual information available and deducible in the upper
parts of the chain. In this case, the deduction is simple - as soon as
we are within a function body, we apply _sequential shadowing_. (Note
that this simple approach will not work if we ever introduce types local
to functions. But this is not an issues. In that case we will need to
redefine the const shadowing within functions in general, and also by
that time I assume we will have the graph collections which will allow
us different approach :-))
- Clean up of redundant error messages as defined in  #4799.

Closes #4587, #4799

## 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.
- [ ] 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.
2023-07-19 12:10:57 +02:00
Kaya Gökalp
1870dee0bf
chore: add forc-pkg codeowner (#4808)
## Description

We will be fixing #4709, but the one thing more important than fixing it
might be ensuring that it does not happen again. Until we have the
bandwidth to introduce nice CLI testing suite I am adding myself as code
owner to forc-pkg. Since forc-pkg lives between the compiler and forc,
it is seeing lots of traffic and I will try to make sure nothing changes
in terms of user experience during those changes. Feel free to close
this, if you feel like we might have a better way of ensuring this
before we got the CLI testing suite ready.
2023-07-18 18:53:14 +00:00
Cameron Carstens
9195d633f3
Update Sway Book and ownership example to use ownership library and src-5 standard (#4751)
## Description

The Sway Book's ownership example and documentation is outdated and does
not include the ownership library. It now links to the SRC-5 Ownership
standard, ownership library, and includes additional examples.

## 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: bitzoic <bitzoic.eth@gmail.com>
Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com>
2023-07-18 18:21:28 +00:00
SwayStar123
55fbbbab29
Delete experimental.sw (#4811)
This used to house storagekey, but that since has been moved to storage

## Description


## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] 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.
2023-07-18 22:20:34 +05:30
Vaivaswatha N
01ee3cb891
Use relatives jumps (#4804)
## Description

Switch the compiler to use relative jumps instead of absolute jumps.

1. The function `relocate_control_flow` is now removed. It used to move
basic blocks around in case absolute addresses crossed the easily
addressable boundary. The code movement can then avoid having to load
the address to a register and using indirect jumps. This is unlikely to
happen with relative jumps. But if it does, the existing algorithm
wouldn't work anyway. So we can add a new one when required later.
2. In the case of function call jumps, we use `$pc` to save the return
address for the callee. This is a bit inefficient as it involves 3 extra
computations: `$$reta = ($pc - $is) / 4 + offset_to_return_point`. We
could change this to the following: Since we already have a common
return point for every function, compute the relative offset from that
point to the callee return point statically and use that. We don't have
the infrastructure to do that right now, but it shouldn't be too
difficult an extension.

Fixes #4443
2023-07-18 16:03:21 +00:00
Joshua Batty
62f9857eea
Collect storage keyword and assign type_def to storage fields (#4810)
## Description
The storage tests in the language server were removed in #4464. That PR
also removed the ability for the language server to access the `storage`
token and assign correct type definition to storage fields. This PR adds
all that functionality back in.

closes #4641
closes #4482
2023-07-18 19:39:16 +04:00
Kaya Gökalp
8600ccec85
chore: bump rust version to 1.71 (#4805)
## Description

Rust v1.71 is
[released](https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html). This
PR bumps rust version used in CI and fixes warnings returned from
clippy's new version.
2023-07-17 23:07:13 +00:00
Braqzen
7d774907c7
Sway Ref: Style guide unused variables (#4660) 2023-07-17 22:41:38 +00:00
Sophie Dankel
6b50f9d8ec
Add documentation for LSP with different IDEs (#4801)
## Description

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

Screenshots:

![Screenshot 2023-07-14 at 2 10 47
PM](aa2bd354-98ed-4254-b69e-c1a8b38ffea6)
![Screenshot 2023-07-14 at 2 10 57
PM](f565af29-3360-4c90-a4da-fa294c80b386)
![Screenshot 2023-07-14 at 2 11 02
PM](6853fa8d-2595-4fd9-8510-7dae20dcff48)
![Screenshot 2023-07-14 at 2 11 12
PM](6517793c-6fcf-4829-8c29-32fd4489e324)


## 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).
- [ ] 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>
2023-07-17 19:26:08 +00:00
SwayStar123
55cb4087c6
Improve flag library functionality (#4793)
## Description
- Changes `disable_panic_on_overflow()` function to return the flags set
prior to calling the function
- Adds a `set_flags` function that simply sets the given value to the
flag register
- Changed u64 `overflowing_add` and `overflowing_mul` to use the new
functions
- Adds equivalent functions for unsafe-math flag aswell
- Additional documentation for all functions in the library

closes #4355 

## 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.
- [ ] 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>
2023-07-17 17:14:34 +05:30
Anton Trunov
0614787e50
stdlib: remove decompose function for u256 (#4802)
The `From` trait already lets one to decompose a `u256` into four 64-bit
words. Also, there is no `compose` for `u256` (unlike `b256`, which has
both at the moment).

## Description


## 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).
- [ ] 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.
2023-07-17 06:21:35 +02:00
Anton Trunov
13ed81b6bf
Improve error message when contract calls its own method (#4791)
close #1491

We add ABI methods to the namespace (this is going to be useful for the
super-ABI feature) and filter out same contract method calls during
method application typechecking, instead of not adding ABI methods to
the namespace and providing a bit confusing error message like `No
method named "method1" found for type "contract".`

## Description


## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2023-07-13 20:53:48 +04:00
Daniel Frederico Lins Leite
7036a2cfe9
constcombine pass optimizing unary and binary operators (#4780)
## Description

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

This PR does NOT change the IR generation for expressions. Instead, it
implements constant folding for unary and binary operators. The idea is
that IR generation will be kept simple and stable, and all optimizations
are pushed onto the opt passes.

To better test this, this PR also changes some implementation details on
IR generation tests:

1 - `filecheck` directives are now collected and tested in groups. This
allows a new "::check-ir-optimized::", that can be configured with the
passes you want to test, or just fallback to "o1".

2 - `filechecker` explanations are now pretty-printed, and can be
printed when `verbose=true`. This allows the test to be checked more
easily.


![image](75d0f628-b271-458d-8c33-7d4d47af789a)

![image](9591a3d5-b0b4-4623-8a7c-1a34f5f96a99)

`breaking` label because of this change:
https://github.com/FuelLabs/sway/pull/4780/files#diff-b40fc3999876b0ff447de112b508250c7d0e7993f9023db29ddce8590d9b2286L5

## 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: Anton Trunov <anton.a.trunov@gmail.com>
2023-07-13 15:42:52 +01:00