Commit graph

231 commits

Author SHA1 Message Date
IGI-111
d90cbc8419
Bump to v0.54.0 (#5853) 2024-04-13 04:03:01 +04:00
Joshua Batty
b30f0e83d3
chore: bump to v0.53.0 (#5831)
## Description
Bump repo to 0.53.0

waiting on #5813

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2024-04-11 11:15:06 +00:00
Daniel Frederico Lins Leite
89e5708402
Fix and improve errors when the entry fns cannot be generated (#5824)
## Description

This PR improves fix a problem when a type cannot be auto-impled and
improve error messages for this case.

This can be seen on `tests/types/contracts/type_inside_enum` in the Rust
SDK repo.
```
     Running `target/debug/forc build --path /home/xunilrj/github/fuels-rs/packages/fuels --experimental-new-encoding`
thread 'main' panicked at sway-ir/src/constant.rs:172:14:
Enums are aggregates.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Given that this PR also improve implementation of arrays for `AbiEncode`
and `AbiDecode`, the entry function is actually generated. But in case
of error, it will fail like:

```
error
    --> /home/xunilrj/.forc/git/checkouts/std-9be0d6062747ea7/5645f10143243e1fd64a55002cd5c09730636ece/sway-lib-core/src/codec.sw:2192:8
     |
2190 | 
2191 | pub trait AbiDecode {
2192 |     fn abi_decode(ref mut buffer: BufferReader) -> Self;
     |        ^^^^^^^^^^ No method named "abi_decode" found for type "SomeEnum".
2193 | }
     |
____

error
 --> <autogenerated>:5:61
  |
3 | 
4 |                     let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
5 |                     let result_arr_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_arr_inside_enum(args.0));
  |                                                             ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
6 |                     __contract_ret(result_arr_inside_enum.ptr(), result_arr_inside_enum.len::<u8>());
7 |                 }
  |
____

error
  --> <autogenerated>:24:61
   |
22 | 
23 |                     let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
24 |                     let result_str_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_str_inside_enum(args.0));
   |                                                             ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
25 |                     __contract_ret(result_str_inside_enum.ptr(), result_str_inside_enum.len::<u8>());
26 |                 }
   |
____

error: Could not generate the entry method because one of the arguments does not implement AbiEncode/AbiDecode
____

  Aborting due to 4 errors.
Error: Failed to compile type_inside_enum
````


## Checklist

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

Bump repo to 0.52.1
2024-04-03 12:57:19 +04:00
IGI-111
98d8f4cadb
Bump to v0.52.0 (#5791) 2024-03-27 13:22:13 +04:00
Igor Rončević
f8e40eb678
References to mutable values (#5688)
## Description

This PR implements references to mutable values, `&mut T`, as defined in
[references](https://github.com/FuelLabs/sway-rfcs/blob/ironcev/amend-references/files/0010-references.sw).
The overall effort related to references is tracked in #5063.

References to mutable values:
- can be created using `&mut`
- can be used in type system wherever a type is expected
- coerce to references (`&mut T` -> `&T`) and thus can be used wherever
"regular" references are expected
- can be passed to and returned from functions

The last point is a step in direction of replacing `ref mut` function
parameters with either `&` or `&mut`.

References to mutable values cannot be taken on constants and immutable
variables (see errors below). (Note that we slightly departure from the
Rust counterparts here. Rust allows `&mut` on constants but issues a
warning.)

Additionally, the PR implements `Diagnostic` for the
`ConflictingImplsForTraitAndType` and shows the already existing,
conflicting implementation of the trait.

## Demo

For more demos, see the tests in this PR.

```Sway
let mut x = 123u32;
let r_m_x: &mut u32 = &mut x;

fn fun(p: &mut T) -> &mut T { ... }

impl Foo for &mut &mut T { ... }

type RefMutRefMut = &mut &mut u64;
```
![References to mutable values cannot reference
constants](207a859b-4876-4320-9e65-57b37093f384)

![Trait is already implemented for
type](4c10902e-ffce-40bb-b9f5-2e9c0e971fcf)

## 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.
2024-03-11 12:39:44 +00:00
Igor Rončević
3426dd12b6
Fix type check and inference issues in references, structs, and enums (#5643)
## Description

This PR:
- fixes #5559, #5597, and #5492 by removing the `TypeInfo::Unknown` and
providing the required contextual information to type checking of
referencing, dereferencing, `if`, and `match` expressions respectively.
The contextual information provided is taken from the
`ctx.type_annotation()` but always adapted according to the semantics of
the type-checked expression.
- fixes #5583 and #5581 by combining the contextual information coming
from the `ctx.type_annotation()` with the one coming from the enum and
struct instantiation and declaration.
- fixes #5598 by forcing the name-based and not structure-based
identity. In other words, two enums or structs are considered equal only
if they whole `call_path`s are equal. Up to now, we were expecting only
the enum or struct _names_ to be equal, which was treating types with
same names and structures (variants or fields) as equal although they
were defined in different modules.

The PR also introduces parsing of references to mutable values (`&mut
T`). Since this addition does not overlap with the above bug fixes, it
was left as is, and can be fully ignored during the review. Other
changes related to references to mutable values are removed from the
code from type-checking onward to make this PR only fixing the issues.
Continuation on references to mutable values will be done in a separate
PR.

Closes #5559, #5597, #5492, #5583, #5581, #5598.

## 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.
2024-02-23 15:20:46 +00:00
IGI-111
d1e8f019c1
Revert to cc 1.0.83 and bump to 0.51.1 (#5649)
cc version 1.0.86 has a bug that blocks our cross compilation pipeline
https://github.com/rust-lang/cc-rs/issues/964
2024-02-23 08:59:26 +03:00
IGI-111
694457da6a
Bump to v0.51.0 (#5647) 2024-02-22 19:12:42 +00:00
Marcos Henrich
b32d0e0ae4
Implements the Never ! types as a TypeInfo bottom type. (#5602)
## Description

We now parse the `!` as a TypeInfo::Never, and remove the usage of empty
enums as Never type in our code.

This commit removes completely the DeterministicallyAborts and
TypeCheckUnificationContext.

The DeterministicallyAborts can be removed because the Never TypeInfo is
now propagated using the type checker. Code blocks that return, break,
continue, or call an expression that returns Never, are marked as Never.

Partially fixes #5562.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-02-20 05:44:38 +04:00
Sudhakar Verma
cdb82e2d9f
swayfmt: fix indentation after where in fn (#5468) (#5578)
## Description
This is a small fix to match the indentation for opening brace after a
where clause is seen. This should fix #5468

cc: @Braqzen 

The change is near trivial.
## 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.

Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2024-02-13 22:57:34 +00:00
Marcos Henrich
80be608517
Implements Iterator trait and for loops. (#5557)
## Description

This implements an Iterator trait in std-lib, and adds iter() to Vec.
This also adds parsing and desugaring of for loops.

```
    for pattern in iterator {
        code_block
    }
```
 is desugared into:
```
    let mut iterable = iterator;
    while true {
        let value_opt = iterable.next();
        if value_opt.is_none() {
             break;
        }
        let value = value_opt.unwrap();
        code_block
    }
```

This also adds for loops documentation to the control flow docs.

We still have to fix this issues:
 -  #5567
 -  #5568
 -  #5570
 -  #5571

Closes #145

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-02-08 18:26:24 +00:00
IGI-111
11231184a0
Bump to v0.50.0 (#5564) 2024-02-07 18:19:09 +04:00
Igor Rončević
8320c1ba12
Struct field privacy (#5508)
## Description

This PR makes struct fields private by default and introduces explicit
public struct fields:

```
pub struct Struct {
    pub public_field: u8,
    private_field: u8,    
}
```

Private fields can be accessed only withing the module in which their
struct is declared.

Error messages are properly orchestrated so that no conflicting or
duplicated messages are emitted. Since the change is a breaking change,
relevant suggestion on how to fix the particular issue are given.

To avoid an abrupt breaking change, the errors are temporarily turned
into warnings. These warnings will become errors in the upcoming
versions of Sway. The demo section below demonstrate how the errors will
look like, and how a one warning equivalent looks now.

Standard library structs like `Vec` or `String`, are adapted where
needed by adding the `pub` keyword to the fields that are accessed
outside of the struct declaration module. Some of these fields should
very likely remain public, but some, like e.g., `RawBytes::ptr` or
`Vec::buf` should be private. Adjusting the standard library to properly
utilize private fields is out of scope of this PR and will be done
separately. I expect breaking changes in the STD once we start modeling
structs keeping encapsulation in mind.

In addition, the PR:
- migrates
[annotate_snippets](https://github.com/rust-lang/annotate-snippets-rs)
crate to its latest version (breaking changes)
- removes a redundant non-existing field error and orchestrates
non-existing field error with privacy errors
- replaces an invalid and misleading error when accessing fields on
storage elements that are not structs

Closes #4692.

## Known limitations

There is an issue in displaying multi-line code snippets, which is
independent of these changes, but wasn't apparent before. The issue is
visible in the demo section below, where the struct bodies are sometimes
not fully shown, and they should be. This issue is reported in #5499 and
will be solved in a separate PR.

## Demo (an excerpt 😄)

### Private struct field is inaccessible

![Private struct field is
inaccessible](8ac07c2b-8135-470b-ad7a-820a4934f232)

![Private struct field is
inaccessible](ca944a7a-e6c4-4b6f-97f1-18000e649452)

### Struct cannot be instantiated

![Struct cannot be instantiated due to inaccessible private
fields](05993416-91d6-4f58-8fd6-8c35c23595f8)

![Struct cannot be instantiated due to inaccessible private
fields](655c17df-a520-45a0-8af4-f1e424ddf085)

### Struct pattern must ignore inaccessible private fields

![Struct pattern must ignore inaccessible private
fields](90396d14-de63-4b08-9f22-e260f406542d)

### Struct pattern has missing fields

![Struct pattern has missing
fields](0ddf44e8-7598-461a-b85b-48006670b0ca)

### Errors temporarily turned into warnings

![Error turned into
warning](ba235248-740f-4fd2-b1fa-29fc35ee8c84)

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-01-30 17:15:24 +04:00
Kaya Gökalp
2ac7030570
chore: bump version to 0.49.1 (#5495)
## Description
Bumps version to 0.49.1.
2024-01-19 21:29:31 +03:00
Kaya Gökalp
a17fbf3e7d
chore: bump to v0.49.0 (#5452)
## Description
Bumps repo to 0.49.0, made this a major one after some thought as we
longer support beta-4 as tooling with this release.
Also ran `cargo update` as this is a breaking change

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2024-01-18 04:42:23 +03:00
Igor Rončević
bae4be893f
Add references to Sway (#5406)
## Description

This PR brings
[references](https://github.com/FuelLabs/sway-rfcs/blob/ironcev/amend-references/files/0010-references.sw)
to the language. The overall effort is tracked in #5063.

In the below description, when talking about references we mean `&T`
references - references to immutable values. `&mut T` will be
implemented in upcoming PRs.

The PR implements the following features:
- References exist in the type system and can be declared, aliased,
dereferenced using `*` operator, etc.
- Reference expressions (referencing) are fully supported on all
expressions including the nonsensical one like e.g. `&return;`
- Semantic analysis and checks are implemented for the current
functionality.
- References can be embedded in aggregates.
- References can reference parts of aggreagates.
- References can be passed to and returned from ASM blocks.
- References can be passed to and returned from functions.
- References can be mutable: `let mut r_x = &x`
- Impls can be implemented for non-generic reference types.
- Traits can be implemented for non-generic reference types.
- References work with generics, means `&T` works as expected.
- References can reference references.
- References can be dereferenced using the `*` operator.
- Dereference expressions (dereferencing) are fully supported on all
expressions including the nonsensical one like e.g. `*&return;`

Known limitations:
- When declaring references on references, currently a space (' ') is
mandatory between two ampersands. E.g., `&&a` emits error and must be
written as `& &a`. Extending parser to support, e.g., arbitrary
`&&...&&a` will be done in upcoming PRs.
- Referencing function parameters for copy types works but not with 100%
proper semantics (creates a copy of the parameter).

On the IR level, references are pointers stored as `u64` and do not
exist as a separate concept. They play well with all the existing IR
optimizations.

Since `core::ops::Eq` and `__addr_of()` are still not implemented for
references, checking for equality in tests is done by converting
references to `raw_ptr`s and checking raw pointers. This is essentially
fine and will one day be turned into converting references to typed
pointers which are tests we will anyhow want to have.

Next steps are listed in #5063.

The documentation will be done in a separate PR and provided separately
once feature is considered ready for public usage.

There are several todos in code marked as `TODO-IG`. They will be
resolved in upcoming PRs.

# Demo

For extensive demos of implemented features, see the tests in this PR.

An example of a semantic check:

![Expression cannot be
dereferenced](0d1a3576-3725-4a70-abf2-e5e11625f429)

## 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.
2024-01-05 09:08:36 +11:00
César D. Rodas
61c260c10c
Run forc fmt on std-lib (#5404)
## Description

Run `forc fmt` on the std-lib

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-01-03 11:41:32 -03:00
César D. Rodas
d3533713ca
Improve forc-fmt to format std lib and core (#5410)
## Description

Changes needed to build #5404 and #5405 

## Improvements
1. Use byte-offset instead of chars offset
2. Enhanced `asm` formatting

## Better output when tests fail


![image](9b884167-a242-4a81-8858-5eff7e9bb7c1)


## 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: Cesar Rodas <cesar@Cesars-MacBook-Pro-2.local>
2023-12-21 23:57:27 +00:00
IGI-111
6886ef050c
Fix release Dockerfile and bump to v0.48.1 (#5370) 2023-12-06 10:37:39 +00:00
Joshua Batty
e451140ce0
Bump to v0.48.0 (#5275)
Co-authored-by: Kaya Gokalp <kayagokalp123@gmail.com>
2023-12-06 17:48:58 +11:00
hal3e
fc17c39e83
feat!: add transaction policies support (#5281)
## Description
co-developed with: @IGI-111 and @xgreenx

This PR adds support for transaction policies. 

What was done:
- bump `fuel-vm` to `0.43.1`
- bump `fuels-rs` to `0.53.0`
- update the `std-lib` to handle new `GTF` codes and the transaction
policies
- update all test

BREAKING CHANGE:
- removed `TxParameters` in favor of `TxPolicies`
- changed `gtf` opcodes 
- removed `Mint` from `forc-tx` and cli

## 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.
- [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: green <xgreenx9999@gmail.com>
Co-authored-by: Elvis <elvisdedic@outlook.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: xunilrj <xunilrj@hotmail.com>
Co-authored-by: Vaivaswatha Nagaraj <vaivaswatha.nagaraj@fuel.sh>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2023-12-06 03:19:54 +04:00
César D. Rodas
f85144062d
Improve comments in-between doc-comments and functions/methods (#5364)
## Description

This was discovered while adding tests for #2790, #2497. This is a
regression from #4185

## 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-12-06 06:13:16 +11:00
Cesar
18bf4930a1
Improve inline arguments formatting (#5283)
## Description

Improve breaking method calls into multiple lines following Rust rules.

A two parts method call is never broken into multiple lines, longer
chains are broken if they are long enough (counting their arguments).

## 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-11-15 23:32:25 -08:00
IGI-111
34265301c6
Bump to v0.47.0 (#5257) 2023-11-06 11:04:34 +04:00
Chris-san
c32934b9c2
bug: Update swayfmt::Config & remove partial implementations (#5193)
Closes #3472 

What this does:
- Removes use of `Config` options that were partially implemented
- Fixes the default implementations for `Config`. This removes the match
arms in the implementations of the `CurlyBrace` trait and just handles
the default, eg `ItemBraceStyle::SameLineWhere`
- Adds tests for items with `where` clauses, ie `ItemImpl`,
`ItemStruct`, `ItemTrait`, which weren't being tested thoroughly enough
- Updates to code quality in the `Config`, and documentation for the
default config's options
2023-10-31 20:39:19 -07:00
Cesar
d9de68d4c5
Attempt to break long expressions into multiple lines (#5207)
Fixes #3474

## Description

Breaks long expressions (focusing into chained methods calls but will
cover all expressions) into multiple lines

## 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-10-27 22:12:48 -03:00
Joshua Batty
b69ea4f790
refactor: Move dir helpers from forc-util to sway-utils (#5224)
## Description
This PR just moves the dir helpers that were in `forc-util` to
`sway-utils`. I need access to these methods in an upcoming PR and
having them in `forc-util` introduces a mind field of circular
dependencies.
2023-10-25 02:38:50 +00:00
Chris-san
53fd58dd96
Fix formatting of abi & trait function signatures (#5186)
Closes #4285 

What this does:
- Adds the necessary information in `Shape` for `FnSignature`'s `Format`
implementation, to always format as a `Function`. This bug occurred
because `FnSignature` always inherited the parent type's `ExprKind`,
meaning it will format correctly so long as the parent type (`ItemFn`)
exists. Otherwise it will default to the normal format.
- Adds tests for `ItemAbi` & `ItemTrait`
- Removes an unnecessary indentation from `ItemImpl`

---------

Co-authored-by: Chris O'Brien <obrchr96@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2023-10-12 22:29:06 +00:00
Chris-san
0eaa61ae37
Remove List options from the formatter (#5183)
Closes #2135 

What this does:
The formatter's config is basically a snapshot of `rustfmt`'s, but our
formatter does not make use of the list tactics that `rustfmt` does.
This just removes the unused code since we handle it a different way.
2023-10-12 04:05:08 +00:00
Cesar
bf08373dcd
Fix new lines into empty implementation (#5176)
Fixes #5060 

## Description

Empty implementations have a bug with new lines



## 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-10-11 21:05:10 -05:00
Chris-san
5406057297
bug: Fix formatting for ItemTraitItem and Annotated<T> (#5182)
Closes #5179 

- Centralizes the use case of `ItemTraitItem`'s format method
- Fixes indentation problems around `Annotated<T>`
- Adds a `write_ident_into_buffer` method which checks if the buffer is
already indented
- Adds documentation for methods the interact with the indentation of
the formatter to avoid confusion on what they actually do
2023-10-11 01:22:51 -03:00
Cesar
f12d5d431e
Fix fmt whitespaces between comments and doc comments (#5178)
This is part of #5052

## Description

There was a bug in the formatter whenever a comment as followed by a
doc-comment, this was due the `insert_after_span` was not allowed to
return a negative offset (due types constraints). But sometimes this
function should let their callee know to remove some bytes.

## 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-10-09 23:00:06 +00:00
Chris-san
2289b14b83
Refactor use of destructive methods in swayfmt (#5148)
Closes #3473 
Removes use of `.pop` used directly on the end formatted `String`.
Better prioritizes order of operations, and writing into buffers to
achieve the same result.
2023-10-10 09:11:05 +11:00
Kaya Gökalp
512a3386f8
Bump to v0.46.1 (#5149)
## Description
Bumps version to 0.46.1.
2023-09-28 23:42:04 +03:00
Marcos Henrich
d61fc362c4
Implements associated types (#5048)
## Description

Implements associated types parsing.

Adds associated types to trait map.

Modifies resolve_symbol to handle associated types.

Support was added for type ascription, methods parameters, method return
types, and function parameters.

It is still missing fully qualified paths, and checking associated types
name conflicts.

It is also missing updating the documentation.

Closes #4487
Closes #610

## Checklist

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

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
2023-09-19 19:14:41 +01:00
IGI-111
e75f14b036
Bump to v0.46.0 (#5120) 2023-09-14 19:31:19 +02:00
Brandon
cff0b1b3a2
SwayFmt: remove {} around single imports (#5109)
## Description
Closes #4944

1. `swayfmt/src/items/item_use/mod.rs`
Added logic to detect if there is only one import in `item_use`. If
there is only one import then no braces are applied. Else apply braces
and formatting logic.

3. `swayfmt/src/items/item_use/tests.rs`
Added test case for single imports with braces.

Co-authored-by: Anton Trunov <anton.a.trunov@gmail.com>
2023-09-12 09:52:25 -05:00
Daniel Frederico Lins Leite
f88bbf42d9
String slices (#4996)
## Description

This PR introduces `string slices`.

The basic usage is at `test/src/ir_generation/tests/str_slice.sw`:

```sway
let a: str = "ABC";
```

Before this PR `a` would be of type `str[3]`, a string array.

Now both `string slices` and `string arrays` exist. This PR contains a
new intrinsic that converts from string literals to arrays.

```sway
let a: str = "ABC";
let b: str[3] = __to_str_array("ABC");
```

Runtime conversions can be done using 

```sway
let a = "abcd";
let b: str[4] = a.try_as_str_array().unwrap();
let c = from_str_array(b);
```

string slices to string arrays can fail, so they return
`Option<str[N]>`; and because of this `try_as_str_array` lives in `std`.
The inverse, `from_str_array` only fails if `alloc` fails and lives in
`core`.

At this PR `string slices` are forbidden at `configurable`, `storage`,
`const`, and main arguments and returns. The reason for these
limitations is the internal structure of `string slices` having a `ptr`.

The optimized IR for initializing the slice is:

```
v0 = const string<3> "abc"
v1 = ptr_to_int v0 to u64, !2
v2 = get_local ptr { u64, u64 }, __anon_0, !2
v3 = const u64 0
v4 = get_elem_ptr v2, ptr u64, v3
store v1 to v4, !2

v5 = const u64 1
v6 = get_elem_ptr v2, ptr u64, v5
v7 = const u64 3
store v7 to v6, !2

v8 = get_local ptr slice, __anon_1, !2
mem_copy_bytes v8, v2, 16
```

## 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-09-11 13:24:41 +00:00
andrewvious
1d0b9a5bd7
Fixed formatting of Module doc comments (#5101)
## Description
Closes #5058
2023-09-08 15:06:27 -05:00
Cesar
675d1347c2
[1645] Enhanced PackageManifest parsing (#5038)
## Description

Fixes #1645 by checking if there are any duplicate keys in sections. Any
duplication of keys will generate a parsing error that will bubble up to
the final user with some context on how to fix it.

The following `Forc.toml` file will fail:

```
[project]
authors = ["Cesar"]
entry = "main.sw"
license = "Apache-2.0"
name = "invalid"

[dependencies]
foo = "bar"
foo = "xxx"
```

The error that will be bubble up to the CLI output reads as follow:

```
Error: failed to parse manifest: duplicate 'foo' for key `dependencies` at line 7 column 1.
```
2023-08-30 15:17:58 +10:00
Sophie Dankel
0c045be329
Fix panic in forc-fmt with special chars (#5014)
## Description

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

## 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-08-29 08:28:57 +10:00
Kaya Gökalp
869200aab9
chore: change rust version used by CI to v1.72.0 (#5043)
## Description

Changes rust version CI uses to v1.72.0 and nightly to 2023-08-27
2023-08-28 11:36:55 +00:00
Sophie Dankel
985e055854
Fix forc-fmt panic when lexing fails (#5011)
## Description

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

Now instead of a panic, the user sees this: 

<img width="836" alt="image"
src="2da2e075-8a10-4ed4-8892-1c95cc42af63">

With debug logging they can see the compiler error, or they can simply
run the compiler.

## 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-08-25 10:11:23 +00:00
Kaya Gökalp
92dc9f361a
Bump to v0.45.0 (#5026)
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-08-25 12:13:44 +03:00
Daniel Frederico Lins Leite
2919d44c7e
Fail formatting if there are syntax error nodes (#5015)
## Description

This PR complements https://github.com/FuelLabs/sway/issues/4912. 

We currently do not allow file with syntax errors to be formatted, but
if the `fmt` was called with AST with syntax errors, it would "eat" all
error spans.

Now the whole formatting will fail with a more decent error message.

## 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-08-24 23:57:58 +00:00
Sophie Dankel
a7da1f2c94
Fix fmt panic for const inside trait (#5009)
## Description

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

The panic happened because the formatter was adding two `;`s after a
constant declaration inside of a trait.

I'm working toward the goal of making it so the formatter never panics,
even for sway files that do not compile.

I made it so, when a sway file does not compile, it does not cause the
formatter to panic. Now it prints an error message and returns that it
did not format anything with exit code 0.

I'm checking in this simple bash script that runs the formatter against
every sway project in the repo. Fixing this bug brought the # of panics
from ~35 down to 23.

I verified that the CI step that checks the formatting of sway docs is
still working.

## 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-08-25 09:29:02 +10:00
Sophie Dankel
baaae4dd20
Fix forc-fmt extra space before scoped block (#5007)
## Description

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

## 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-08-23 22:12:00 +00:00
Daniel Frederico Lins Leite
122fb0b646
Parser recovery inside trait/abi (#4979)
## Description

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

The trick part of this PR is that `TraitItems` were being parsed as
`(TraitItem, SemicolonToken)`. The problem is that to recover from an
error we call the `error` method of the `Parser` trait. And it is very
hard to come up with a generic implementation for the tuple. Which type
of tuple do we call its `error` method, and how do we return a valid
tuple in all cases? Impossible.

So that is why I moved the `SemicolonToken` to inside the `TraitItem`.
Another benefit is that we can recover from missing semicolons with nice
error messages.

## 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-23 14:32:02 +00:00
Daniel Frederico Lins Leite
771865cd30
parser recovery at item level (#4964)
## Description

Closes https://github.com/FuelLabs/sway/issues/4910.
Closes https://github.com/FuelLabs/sway/issues/4909.
Closes https://github.com/FuelLabs/sway/issues/4908

The trait `Parse` now contains a do-nothing `error` function that
returns the error variant for that item, if it has one. This allows
generic parsing functions like `Vec`, `Annotated` etc... to be able to
recover and continue if desired.

Now the parser continues even if strange things at the item level.


![image](5ce00e01-5eb5-48db-b163-f3245cb6e5fe)

## 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-18 10:19:09 +01:00