Commit graph

278 commits

Author SHA1 Message Date
Mohammad Fawaz
32b5b142b5
Bump to v0.21.0 (#2651)
Bump to v0.21.0

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2022-08-29 22:02:51 -04:00
Kaya Gökalp
f7b346eb47
fix: ForwardSlash span collection (#2625) 2022-08-25 20:13:53 +00:00
Nick Furfaro
1484aee162
Add missing gtf support to compiler (#2613)
fix: add missing gtf support to compiler
2022-08-23 12:35:35 -06:00
Mohammad Fawaz
6a8116fcee
Bump to v0.20.2 (#2584)
Bump to v0.20.2
2022-08-18 23:40:55 -04:00
Mohammad Fawaz
21887f4b32
Bump to v0.20.1 (#2578)
* Add forc client metadata to Cargo.toml

* bump to v0.21.1
2022-08-18 15:02:14 -07:00
Emily Herbert
fc3a05d87d
Bump to v0.20.0 (#2565)
* bump to v0.20.0

* run cargo update and update forc-client

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-08-18 15:25:28 -04:00
JC
74b239be87
Annotate TypeFields (#2528)
* Annotate TypeFields

* Fix fmt-v2 issues

* Actually fix fmt-v2

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
2022-08-16 13:36:48 +00:00
Andrew Cann
f8c5d57dbc
break and continue are not items (#2536)
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-08-16 00:04:20 +00:00
Mazdak Farrokhzad
42148b36fe
Fix support for parser recovery (#2527)
* add initial parser recovery support

* parser: recover on 'pub $item'

* parser: add recovery tests

* cargo clippy

* parser recovery: make test compile

* cargo clippy

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-08-14 13:13:33 -07:00
João Matos
47f2db9bf1
Add pointers to IR and implement mutable parameters. (#2363)
* Add pointers to IR and implement mutable parameters.

So this PR does a few different things:

- Adds first-class pointer type in the IR
- Changes the type of get_ptr IR instruction to return a pointer
- Updates the IR verifier to deal with this
- Allows Sway to parse mutable function parameters
- Updates IR generation to generate a pointer for mutable parameters

This means Sway code like `fn mut_prim(mut b: u32)` now generates the
following IR:

```rust
fn mut_prim_0(b !8: mut ptr u64) -> (), !9
```

And functions can take a pointer, like the result of `get_ptr`:

```rust
        v2 = get_ptr mut ptr u64 b, ptr u64, 0, !4
        v3 = call mut_prim_0(v2), !5
```

Struct mutable parameters are also now working, where previously only
mut self parameters were working.

Part of https://github.com/FuelLabs/sway/issues/1188.

* Add ref keyword for mutable parameters.

* Address PR feedback.

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
2022-08-13 05:22:46 +00:00
JC
91a2b43dd2
Add Outer DocComment Parsing (#2516)
* Add DocComment parsing

* review changes

* review changes

* fixed a random bug

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
2022-08-12 16:03:27 -07:00
Kaya Gökalp
87e0a488cf
Fix new clippy lints (with rust version 1.63) (#2518) 2022-08-11 19:13:33 +00:00
Mazdak Farrokhzad
c7113d3ed2
Misc cleanups in the parser (#2480)
* misc cleanups in the parser

* fix bug in peek_delimiter

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
2022-08-10 08:01:33 -07:00
Mohammad Fawaz
6808861389
Bump to v0.19.2 (#2481)
bump to v0.19.2
2022-08-08 15:47:20 -06:00
Mazdak Farrokhzad
09d67871a9
Moves out the AST definitions from sway_parse into sway_ast (#2438)
* misc minor improvements to CFA

* split out sway_ast from sway_parse

* cargo clippy
2022-08-03 17:06:32 +00:00
Mohammad Fawaz
1202e790c1
Bump to v0.19.1 (#2437)
Bump to v0.19.1
2022-08-01 11:11:46 -04:00
Kaya Gökalp
8673f73a20
Additional checks for unnecessary visibility qualifier (ABI definitions, ABI impls and trait impls) (#2432) 2022-08-01 02:11:16 +00:00
Vaivaswatha N
22859f34f7
Provide intrinsic __addr_of. (#2371)
Closes #2281 (see discussion on design choices).
2022-07-28 06:15:17 -04:00
Mohammad Fawaz
5c716e1ba5
Bump to v0.19.0 (#2393)
Bump to v0.19.0
2022-07-27 20:00:33 -04:00
mitchmindtree
91a60a6600
Fix lexing of multiline comments to include the trailing '/' (#2359)
* Fix lexing of multiline comments to include the trailing '/'

Previously, both the implementation and the test missed the trailing
slash during lexing. This fixes both, closes #2355 and unblocks #2311.

* Add missing slash to sway-fmt-v2 comment test
2022-07-22 16:13:29 +10:00
Mohammad Fawaz
bd8f8fea13
Fix Span end for unclosed multiline comments and unclosed string literals (#2354) 2022-07-21 07:05:22 -04:00
Mohammad Fawaz
9efe316f78
Add a new __gtf intrinsic (#2315)
* Add int_to_ptr IR instruction

* Simplify codegen for int_to_ptr

* Update a few more things and add a test

* Add a new __gtf intrinsic

* Add a simple test

* Use int_to_ptr to generate asm for __gtf

* Add an ir_generation test

* Update sway-ir/src/verify.rs

Co-authored-by: Toby Hutton <toby@grusly.com>

* Addressing some comments

* Update test/src/e2e_vm_tests/test_programs/should_pass/language/gtf_intrinsic/src/main.sw

Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>

* Update sway-core/src/asm_generation/from_ir.rs

Co-authored-by: Toby Hutton <toby@grusly.com>

* Update sway-ir/src/parser.rs

Co-authored-by: Toby Hutton <toby@grusly.com>

* rename the test.. the old name was wrong

* Updating type checking of gtf to only expect u64s

* fmt

Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
2022-07-19 04:51:00 -04:00
Mohammad Fawaz
3bd8eaf4a0
Bump to v0.18.1 (#2304)
bump to v0.18.1
2022-07-11 23:23:17 -04:00
João Matos
f588d8a078
Check for unnecessary visibility qualifier in trait items. (#2276)
This introduces a new check for unnecessary visibility qualifiers
when defining trait items.

For code like:

```
trait A {} {
    pub fn f(self) -> bool {
        false
    }
}
```

We now emit:

```
error
 --> main.sw:4:5
  |
2 |
3 | trait A {} {
4 |     pub fn f(self) -> bool {
  |     ^^^ Unnecessary visibility qualifier.
5 |         false
6 |     }
  |
____
```

Also adds some tests for both trait interface and method blocks.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-07-11 18:28:40 +00:00
Chris O'Brien
c89f3029f5
Adds ItemFn formatting to sway-fmt-v2 (#2173)
* wip: item_fn handling

* wip fn_item fmt

* more wip pieces of ItemFn

* update item_fn with Ty and write

* updated statement with Ty and write

* update path and pattern with write

* update and add test

* update tests, add spans to expr and trait, and update where clause

* update literal with write

* fix has_where_clause and update_where_clause
2022-07-11 23:36:48 +10:00
Mohammad Fawaz
ada0d294a6
Bump to v0.18.0 (#2268) 2022-07-08 19:12:28 -04:00
Mohammad Fawaz
b161e82103
Make storage initializers required, just like local variables (#2278) 2022-07-08 17:27:40 -04:00
Mohammad Fawaz
7740b0085a
Some code golf (#2271) 2022-07-08 17:18:22 -04:00
Matt
aadca68708
feat: struct destructuring (#2243)
* test: struct destructuring

* feat: add print statements for debugging

* debugging: add print

* Add Forc.lock.

* Add descriptions.

* fix: remove println! statements

* chore: update to latest version

* feat: add not working Pattern:Struct branch to match

* fix: identation in oracle json

* feat: create pattern if field has none

* refactor: remove debug prints

* fix: warnings

* test: type annotations for destructure

* fix: handle type annotations

* chore: run formatter

* fix: remove test cargo toml

* fix: destructure test case

* test: nested struct destructuring

* docs: add struct destructuring

* refactor: fix formatting

* fix: formatting

* refactor examples

* fix: formatting

* fix: remove mention of deleted file

* test: nested tuple in struct and vis versa

* docs: add nested tuple in struct and vis versa to examples

* fix: formatting

* fix: formatting

* fix: formatting

* fix: formatting

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-07-08 07:58:12 +00:00
Braqzen
40deb203a2
Add the SMO opcode to sway-core (#2178)
* Added SMO opcode
2022-07-04 15:42:12 +01:00
Mohammad Fawaz
b81bcd9652
Bump to v0.17.0 (#2174)
* bump to 0.17.0

* Also run cargo update
2022-07-01 15:12:20 -04:00
Mohammad Fawaz
2e89868a82
break and continue (#2112) 2022-07-01 12:07:18 +00:00
mitchmindtree
7c45838bc2
Add lex_commented and CommentedTokenStream to sway_parse (#2123)
* Add `CommentedTokenStream` to `sway_parse`

This doesn't yet collect any comments, but adds the necessary structure
and attempts to preserve the original API and behaviour where possible.

Collecting of comments to be added in a follow-up commit.

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

* Add Spanned impl for CommentedTokenTree. Add comment lexing test.

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
2022-06-30 07:09:18 +00:00
Vaivaswatha N
753639c1a6
Introduce __eq intrinsic (#2100)
* Introduce `__eq` intrinsic

* Lower to `Instruction::Cmp` instead of to assembly in IRGen

* Refactor intrinsics to all have arg and type arg vectors
2022-06-29 16:04:39 +00:00
João Matos
19586172e4
Improve reserved keywords checking and add support for raw identifiers. (#2066)
Add support for raw identifiers and improve reserved keywords checking.

This commit deals with the usage and checking of reserved keywords
as identifiers, for code like:

```
fn main() {
    let mut mut = 0;
}

It introduces a new error that checks if an identifier is a reserved
keyword:

```
error
 --> /main.sw:4:13
  |
2 |
3 | fn main() {
4 |     let mut mut = 0;
  |             ^^^ Identifiers cannot be a reserved keyword.
5 | }
  |
____
```

There was an existing issue in the standard library, which
has a library/module named `storage`.

Instead of working around this by renaming it to something else,
an alternative solution with raw identifiers is implemented.

This raw identifier feature is implemented at the lexer level,
and allows you to use keywords as identifiers in places that
generally wouldn't be allowed.

Rust and a bunch of other modern languages also provide this escape
hatch, and it seemed the simplest solution for me to handle the issue.

It activates by declaring an identifier prefixed with `r#`, just like
Rust.

The complexity on the codebase to support this feature is pretty
minimal, but if there any objections to this, I can easily remove it,
but some other solution to the issue above will need to be figured out.

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

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-06-27 13:18:57 -04:00
Mohammad Fawaz
7920330d34
Bump to v0.16.2 (#2105)
* bump to v0.16.2

* Fix one test not pointing to local std
2022-06-24 15:02:08 -04:00
Chris O'Brien
755ff6a5e2
Adds attribute handling to sway-fmt-v2 (#2061)
* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos
2022-06-22 00:03:39 +00:00
rakita
649bbbb517
comby-rust (#2065)
* comby-rust

* Fix clippy warning

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-06-21 18:08:38 -05:00
João Matos
4b77e83a6d
Improve struct patterns with new warnings and rest pattern support. (#2032)
* Improve struct patterns with new warnings and rest pattern support.

This commit improves a couple aspects of handling of struct patterns.

First of all, it adds semantic checking (with a new warning) when
patterns are missing usage of all fields:

```
error
  --> src/main.sw:15:9
   |
13 |
14 |     let z = match p {
15 |         Point { x } => { x },
   |         ^^^^^^^^^^^ Pattern does not mention field: y
16 |     };
   |
____
```

Then it adds support for rest pattern, "..", which can be used as the
last token in a pattern to not have to specify all the struct fields.

The semantic AST model was updated to support modeling this pattern,
and further type checking was added to the code.

There is also a new warning for when the rest pattern doesn't appear as
the last location, or when it appears multiple times:

```
error
  --> src/main.sw:17:20
   |
15 |
16 |     let z = match p {
17 |         Point { x, .., .. } => { x },
|                    ^^ Unexpected rest token, must be at the end of
pattern.
18 |     };
   |
____
```

And lastly, tests were added to cover the changes and new functionality.

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

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-06-20 19:07:26 -04:00
Mohammad Fawaz
dcf22453ae
Bump to v0.16.1 (#2037)
Bump to 0.16.1
2022-06-17 23:03:40 +03:00
Mohammad Fawaz
458724ecf7
Improve span for missing tokens at the end of a scope (#1973)
improve span for missing tokens at the end of a scope
2022-06-16 22:54:05 +00:00
Mohammad Fawaz
948f7aba42
Bump to v0.16.0 (#1998)
bump to 0.16.0
2022-06-16 13:30:17 -04:00
Mohammad Fawaz
ba30e8e5cc
Allow self to be mutable (#1956)
* Allow self to be mutable

* assign to self directly

* fix lock files
2022-06-16 02:47:16 +00:00
Mohammad Fawaz
eab07e48bc
Bump to v0.15.2 (#1920) 2022-06-09 14:37:56 -04:00
Emily Herbert
3afc08d66e
Use the Spanned trait everywhere (#1881)
* Use Spanned everywhere.

* clippy
2022-06-06 21:27:31 -05:00
Mohammad Fawaz
a34b4b99fc
bump to 0.15.1 (#1871) 2022-06-06 13:45:20 -04:00
Mohammad Fawaz
ee7822c411
bump to v0.15.0 (#1835) 2022-06-06 11:45:18 -04:00
Emily Herbert
6dada08959
Make tuple annotation more specific (#1774)
* Make tuple annotation more specific.

* Documentation

* update
2022-06-02 09:08:41 -05:00
Mohammad Fawaz
60c626cf48
bump to 0.14.5 (#1793) 2022-06-01 16:19:51 -04:00
Mohammad Fawaz
443f42c95b
Eliminating the need for new() to use StorageMap (#1776) 2022-06-01 07:34:30 -04:00