This PR adds a formatting step to documentable code blocks which also
removes user comments. So something like
```rust
pub struct Hello { \n\n
// hello, a comment good sir
my_field : u32, // another unwanted comment
// oops this is a comment
my_other_field: u32 ,
}
```
will get formatting and have its comments removed only for the main code
block show casing the `struct`.
Along the way, I found a small problem in `sway_parse` in `item_struct`.
Looks like the parser was looking for the `struct` keyword first instead
of the `pub` keyword. I just added a `let` binding for the visibility
keyword before we check for `struct`.
Before this fix the error message for doc comments before a dep was out
of place and was "Expected an item."
This was fixed by peeking for one or more `DocComment` followed by a
`DepToken` and returning an error in that case. This ensures that no
`DocComment` is consumed and can therefore be consumed later on while
parsing `Annotated<ItemKind>`.
Closes#3116
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: João Matos <joao@tritao.eu>
Closes https://github.com/FuelLabs/sway/issues/3155
This is needed due to `mem2reg` and some unclear semantics around
initialized registers being passed as ref/mut ref. Besides, it's a good
idea to restrict `asm` blocks as much as possible to avoid weird
unwanted behavior.
<img width="883" alt="image"
src="https://user-images.githubusercontent.com/59666792/199332120-974d1821-680e-43a1-922d-1a32d491b3cd.png">
* I also removed the `disallow_opcodes` check because the parser takes
care of that now. The parser only allows legal opcodes in `asm` blocks.
* Finally, I update the parser to accept the correct storage opcodes
with `fuel-core 0.13` and updates all the tests.
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Fixes https://github.com/FuelLabs/sway/issues/1436.
This PR first removes the need for `~` in `~Foo::bar` by first delaying
the interpretation of `Foo::Bar` (associated call, free function call,
or enum variant construction?) until type checking. This is achieved
with `ExprKind::AmbiguousPathExpression`. During type checking, we ask
whether `Foo` (and any prefixes) is a module, or an enum. If it's
neither, we attempt type checking as an associated function call.
Otherwise, we continue as if we had a `ExpressionKind::DelineatedPath`.
Once `~` is made redundant, it's then also removed from the language and
so also from tests, examples, and the standard library.
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
- Introduce a new control flow op `LoadLabel` which reads an address
from the data section.
- Convert `JI`, `JNZI`, `JNEI` and `MoveAddress` to use `LoadLabel` and
`JMP` or `JNE` when required.
- Introduce a `BLOB` instruction which is for testing purposes only, and
efficiently & conveniently inserts a raft of `NOOP`s into the binary.
This PR achieves a couple of related things.
1. All compiler errors are moved into the common `sway-error` crate. The
`Handler` type is now also moved there, and now uses `CompileError`
instead of `ParseError`. That's also the main goal, to generalize
`Handler` to all sorts of errors, which will help solve
https://github.com/FuelLabs/sway/issues/2734 soon.
2. Using 1, we can now also emit `LexError`s into the `Handler`, so this
enables lexer recovery.
3. Lexer recovery is added for e.g., `42y8`, which fixes
https://github.com/FuelLabs/sway/issues/2865.
4. Lexer recovery is added for `'abc'` char literals, which fixes
https://github.com/FuelLabs/sway/issues/2864. The AST supports them, but
the rest of the compiler does not, so this will be useful later on, but
was good for recovery framework testing.
5. Lexer recovery is added for mismatched open/close delimiters, e.g.,
`fn foo() { )`.
6. Lexer recovery is added for unexpected closing delimiters, e.g., `fn
foo() }`.
7. Lexer recovery is added for unclosed delimiters.
8. Parser recovery is added for `let x =`, which fixes
https://github.com/FuelLabs/sway/issues/2815.
9. Misc lexer refactoring and simplifications are made.
Fixes https://github.com/FuelLabs/sway/issues/2948.
Now it's possible to write `foo.bar::<Baz>()`.
The parser will also do recovery for `foo.field::<Args>`.
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Closes https://github.com/FuelLabs/sway/issues/2884
Main changes:
1. Disallowing `rvrt`, `ret`, and `retd` in `asm` blocks.
2. Remove all checks that look for the opcodes above.
3. Add `__revert` intrinsic and make its type `Unknown` for now. It will
be `Never` in the future.
4. Add an IR instruction `revert` with no type. There are still some
things that should be ironed out related to that.
Also closes https://github.com/FuelLabs/sway/issues/2822.
https://github.com/FuelLabs/sway/issues/2876 is not fixed yet though.
This is related to the issues mentioned in (4) above.
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Some drive-by work made to get a better understanding for
https://github.com/FuelLabs/sway/issues/2815 (doesn't fix the issue,
yet) and other possible lexer improvements.
A bug around lexing of integers specified in octal, was also fixed.
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>