Commit graph

502 commits

Author SHA1 Message Date
bing
ec65188a42
fix(fmt): forc-fmt check (#4147)
## Description

Fixes the same issue found here:
https://github.com/FuelLabs/sway/pull/4038#discussion_r1105153934, but
missed out in other locations. This has caused new PRs to not fail on
`forc-fmt --check` even if they contained formatting violations, see:
https://github.com/FuelLabs/sway/pull/4129

## 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).
- [x] I have requested a review from the relevant team or maintainers.
2023-02-21 10:13:18 +00:00
Mohammad Fawaz
f05ecaf2de
Bump to v0.35.2 (#4123) 2023-02-17 15:08:34 -08:00
mitchmindtree
8fdc452fff
feat: Add salt flag to forc deploy, maturity flag to deploy and run (#4116)
## Description

This allows for specifying a `--salt` for the top-level contract member
when running `forc deploy`. Right now, we only enable this for
*packages*, and not for workspaces with more than one package due to
some ambiguities that arise (see comment note in code). I'll open an
issue to track relaxing this constraint a little. Edit: opened
https://github.com/FuelLabs/sway/issues/4117.

I noticed we also had no way of specifying maturity, so have added a
`--maturity` flag for this as well.

These flags are shared with the `forc-tx` crate in order to try and
provide some consistency (in help output and flag representation) across
our CLI tooling.

Ideally we'd like to ship this feature in the Sway release that ends up
in the fuelup beta-3 toolchain - otherwise users following the
quick-start guide will be unable to re-deploy the same contract to the
network as it will already exist - they'll need to be able to provide a
salt.

## 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-02-17 19:36:27 +00:00
mitchmindtree
729f8b3bf8
forc-tx: Improve error handling using thiserror. Fix panic!ing version/help output. (#4085)
## Description

This introduces a `Command::parse` constructor that emulates the
behaviour of the `clap` parse constructor in order to provide a more
consistent clap-like CLI experience. For context, we cannot use the
generated `parse` command due to limitations in clap's ability to handle
trailing subcommands as mentioned in #3804.

We switch to using `thiserror` in the library in order to allow for
handling error cases (necessary for the new `parse` constructor) and to
provide cleaner, more detailed error cause traces.

The help and version output no longer panic, and now behave like regular
clap applications. Closes #3886.

Also adds an example command invocation to the end of the `--help`
output.

## 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-02-17 13:25:15 +08:00
bing
080543ef16
bug(fmt): do not iteratively call forc-fmt over members on the root dir (#4038)
## Description

closes #4027

This is a fix for the formatter being called to format multiple times.

This implements the suggested changes described in the issue, and
refactors some of the code:

- `format_file()` is now renamed to `write_file_formatted()`, since all
it does is write to a file.
- Extract logic of formatting a single file into `format_file()`. This
means its reusable at 3 levels: formatting a single file, formatting a
package and formatting a workspace.
- Handles formatting by workspace vs package - formatting a workspace is
handled slightly differently. Formatting a package has no changes - it
still works the same. However, for workspaces, we want to format all
files at the root, then find for each subdirectories (inclusively), all
the nested directories with a manifest inside. If it exists, we are
interested in formatting it. If the subdirectory happens to have a
`swayfmt.toml` inside it, we will prioritize that configuration file.
Generally, we should prefer member config > workspace config > default.
This nuance is [explained in a
comment](https://github.com/FuelLabs/sway/pull/4038/files#diff-bf9b5d7023fff817f83ae31bd01e66d2788178a0705a2c638ce79d7990cc374aR190-R193).
- Extract logic of formatting a manifest into `format_manifest()`

It's faster by quite a bit, with some good ol' primitive testing:


![image](https://user-images.githubusercontent.com/25565268/218050071-b6b5eb7f-9d82-4293-9321-996376a46a82.png)

new (fmt.sh):
```
for i in `seq 1 13`; do
  ./forc-fmt --path AMM
done
```

The above `forc-fmt` is built on `--release` and I moved it to the sway
apps repo for testing. Looped it 13 times because that's the no. of
projects in sway-applications.

old (fmt-old.sh):
```
for i in `seq 1 13`; do
  forc fmt --path AMM
done
```

This one is just the current formatter.

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

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
2023-02-16 10:40:34 +08:00
Mohammad Fawaz
1f9debfaf9
Bump to v0.35.1 (#4088)
Co-authored-by: João Matos <joao@tritao.eu>
2023-02-15 16:56:49 -05:00
Emily Herbert
30cdb10b6a
Introduce DeclRef and remove excessive clones to DeclId (#4037)
## Description

This PR is a subset of #3744. It introduces `DeclRef`, which is a smart
wrapper type around `DeclId` and contains additional information aside
from the `DeclId`. This allows us to make `DeclId` a copy type and
remove excessive clones of `DeclId` and `DeclRef`.

This PR is a subset of #3744, so while not explicitly necessary right
now on `master`, there will be additional fields added to `DeclRef` in
#3744.

In detail, this PR:
1. Changes `DeclId` to a copy type defined as:
    ```rust
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
    pub struct DeclId(usize);
    ```
2. Creates a new `DeclRef` type which is a handle to a use of a
declaration: (there will be more fields added to this in #3744)
    ```rust
    /// A reference to the use of a declaration.
    #[derive(Debug, Clone)]
    struct DeclRef {
        /// The name of the declaration.
        name: Ident,
        /// The index into the [DeclEngine].
        id: DeclId,
        /// The [Span] of the entire declaration.
        decl_span: Span,
    }
    ```
3. Changes the definition of the `TyDeclaration::FunctionDeclaration`
variant to contain additional fields: (there will be more fields added
to this in #3744)
    ```rust
        FunctionDeclaration {
            name: Ident,
            decl_id: DeclId,
            decl_span: Span,
        },
    ```
4. Changes the definiton of the
`TyExpressionVariant::FunctionApplication` variant to contain a
`DeclRef` instead of just the previous `DeclId`. The
`TyExpressionVariant::FunctionApplication` variant gets a `DeclRef`
because `DeclRef` is a handle to a declaration _usage_, while the
`TyDeclaration::FunctionDeclaration` variant does not get a `DeclRef`
because it is simply an AST node for the function declaration. This
distinction will be more clear/necessary in #3744.
5. Changes the `DeclEngine` API to take `&T where ...`, allowing us to
remove more unnecessary instances of `.clone()`.

## Checklist

- [x] I have linked to any relevant issues.
- [ ] 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.

---------

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2023-02-14 14:24:47 +11:00
IGI-111
3f3fe47b21
Add tokens for generic custom type fields (#4066)
## Description
Collect LSP tokens for fields of enums, structs and storage field
annotations by refactoring the `TypeId` handling to use `TypeArgument`
and collect name spans.

Fix #4052
Fix #4051 

## 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-02-13 11:34:17 +01:00
IGI-111
77cbe63cad
Add tokens for function parameters, return types and type ascriptions (#4042)
## Description

This adds LSP tokens with proper definitions inside type ascriptions for
variable and const declarations, function parameter type definitions and
function return type definitions.

To this end it refactors the definition handling to use `TypeArgument`s
instead of raw `TypeId`s.

Fix #3616 
Fix #4030 

## 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: João Matos <joao@tritao.eu>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-12 16:26:44 +00:00
Chris O'Brien
c7ff7653b0
Fix reference formatting in forc doc (#4041)
## Description
Changes `&` to `ref` in method formatting. 
Closes #4022
2023-02-12 00:55:44 +00:00
Kaya Gökalp
4d5fea688f
feat: only build relevant members for forc-client operations (#4008)
## Description

closes #3329.

This PR filters unrelevant member nodes for `forc-client` operations in
workspaces. `forc deploy` only builds contracts and `forc run` only
builds scripts. This is done by adding a filtering capability to
`forc-pkg`.

## 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-02-10 14:02:01 +03:00
mitchmindtree
220325d601
Add a forc-submit plugin command for submitting txs to a given node (#3885)
Closes #3875.
2023-02-10 13:08:06 +03:00
João Matos
b6f19a3be7
Bump to v0.35.0 (#4024)
## Description

Bump to `v0.35.0` for a new release.

## 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-02-08 10:38:48 +00:00
Brandon Kite
67b37ce4cc
Fuel Core v0.17.0 Upgrade (#3961) 2023-02-08 20:01:12 +11:00
João Matos
69d4dbb84b
Fix DCA for generic functions (#3878)
Closes https://github.com/FuelLabs/sway/issues/3671.

There were a bunch of different fixes necessary to fix this one, which
are separated into individual commits to make it easier to review. The
main gist is that the DCA now keeps track of functions by their
signature instead of just their name and when encountering monomorphized
functions in the DCA engine, we now look for their counterpart fully
generic version and link the two together.

Previously:


![bug](https://user-images.githubusercontent.com/602268/216972881-65b9a7c3-083e-44ff-9a5b-cc310bb19146.png)

Now:


![bug3](https://user-images.githubusercontent.com/602268/216972937-c6be0909-9349-4fd4-9d33-f9dcaca93767.png)
2023-02-07 13:18:19 +00:00
Marcos Henrich
3fbad7b5f0
Changes struct and enum declarations to contain a call path. (#3900)
With these changes `TyStructDeclaration` and `TyEnumDeclaration` now
have a call path instead of a name.

This is required before changing the JSON ABI to use enum and struct
types with call paths instead of only names which can be duplicate.

This also fixes #418 by changing `Unifier` to compare `CallPath`'s
instead of `Ident`'s for enums and structs.

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

---------

Co-authored-by: João Matos <joao@tritao.eu>
2023-02-03 11:41:40 +00:00
Mohammad Fawaz
f5867dcb28
Bump to v0.34.0 (#3943)
~~Waiting on https://github.com/FuelLabs/sway/pull/3942~~
2023-02-01 06:39:13 -05:00
Mitchell Mackert
ea4d4b4378
Change expect messages to Result in forc doc (#3691)
Work in progress, implementing `anyhow::Result` and handling `expect` &
`unwrap` where necessary

Closes #3655
2023-01-31 16:09:46 +00:00
mitchmindtree
bc700d5afd
Refactor forc-client in preparation for new forc submit command (#3941)
This is a small refactor of the `forc-client` crate in anticipation of
including the new `forc submit` command (see #3885) as a new binary
output for the crate.

This PR inverts the forc-client module hierarchy to follow `forc`'s
layout a little more closely.

It also refactors the command types in order to better share sets of
clap arguments between different commands with the aim of reducing code
duplication and providing a more uniform experience across all official
forc commands/plugins. This will be improved further once the `forc
submit` command is included, allowing us to share some of the networking
arguments too.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-31 21:55:45 +11:00
Chris O'Brien
f6616ed2b2
Fix handling of empty documents (#3930)
Closes #3923 

The name here is slightly misleading. This does clean up how we handle
it to a degree, but mostly due to a conflict of what is considered
documentable. We don't have html rendering for `ImplTrait`s just yet,
and because they were considered documentable but not handled we were
getting a panic.

While working this out, I found another bug: #3929

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-30 03:46:48 -06:00
bing
ce75cc93ef
feat(fmt): allow a single file for --path (#3858)
Allows you to format a single file with defaults for `Formatter` and
`BuildConfig`.

Usage: `forc fmt --path my_file.sw`
2023-01-27 10:16:51 +08:00
Nick Furfaro
ed1bc39c67
Run cargo clippy --fix in the sway repo (#3903)
Co-authored-by: Sophie <sophiedankel@gmail.com>
2023-01-26 16:05:13 -05:00
Chris O'Brien
0419c19237
feat: Adds Markdown formatting to item previews in forc doc (#3869)
Closes #3868 

Adds markdown support and a few layers of logic to figure out where a
preview should end.
![Screen Shot 2023-01-23 at 5 18 57
PM](https://user-images.githubusercontent.com/57543709/214174091-74ea5fae-9ea4-435d-b4e5-16ccf5ce2ecd.png)

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-25 17:46:30 +08:00
Chris O'Brien
1e384ca019
chore: change type of module_info field on RenderedDocument to ModuleInfo (#3846)
Closes #3845
2023-01-25 16:57:45 +11:00
Kaya Gökalp
76606cd930
feat: inject contract id into the namespace for tests automatically (#3729)
closes #3673.

## About this PR

This PR adds `CONTRACT_ID` injection while building contracts with `forc
build --test`. `CONTRACT_ID` is the id of the contract without the tests
added. To find out that id, we first compile the contract without tests
enabled.

The rough outline of stuff happening here:

1. We iterate over `BuildPlan` members to find out contracts and collect
their contract id into an injection map. In this step only the contracts
are built. To determine contract id we need to compile the contract
without tests. Since we also need the bytecode of the contract without
tests, we are collecting them as we come across them while iterating
over members.
2. With the injection map build and execute all the tests, so basically
after first step we are just doing the old `forc-test` behaviour.

So basically I added a pre-processing step for contract id collection
for those members that require it (contracts).

This enables the following test structure:

```rust
let caller = abi(MyContract, CONTRACT_ID);
let result = caller.test_function {}();
assert(result == true)
```
2023-01-24 10:32:04 +00:00
Chris O'Brien
86c02c27ef
Add docstring previews to index files (#3848)
Closes #3820 

I've added a limit of 200 characters so that anything longer would be 75
characters with an ellipsis (not pictured):
![Screen Shot 2023-01-20 at 7 16 37
PM](https://user-images.githubusercontent.com/57543709/213831623-27c5ed84-9f4e-4efe-8d2a-1c7789ca4dc0.png)
2023-01-23 16:25:01 +00:00
Kaya Gökalp
c13dcfb7b8
feat: forc-fmt workspace support (#3851)
closes #3781.
2023-01-23 10:01:56 +08:00
Mitchell Mackert
d1506d9277
Fixed self in trait methods (#3832)
Closes #3805
2023-01-20 23:13:28 -06:00
Kaya Gökalp
097fa69c1f
Add a flag to print Log and LogData receipts emitted from tests (#3808)
closes #3807.

- Moved `Log` and `LogData` formatting code from `forc-client` to
`forc-util` as `forc-test` needs it too.
- Added `--logs` and `--pretty-print` flags to `forc-test`
2023-01-19 10:37:58 +00:00
Chris O'Brien
6319f8e7ec
Add index file navigation to forc doc (#3778)
Closes #3658 
Closes #3170 
Closes #3660 

Updated video using `std`:


https://user-images.githubusercontent.com/57543709/213319718-c8dd9d40-a29b-4598-8db5-89c8d6a5a837.mov

Here's what the files look like, the only difference to rust is that
they create a folder for the parent module as where we omit it. This
will likely need to change once we have support for workspaces.
![Screen Shot 2023-01-17 at 7 51 32
PM](https://user-images.githubusercontent.com/57543709/213061699-12ac1b3a-3e2e-4469-8f63-737549564b91.png)

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-19 05:14:28 +00:00
Kaya Gökalp
f18197f0c0
Introduce a way to inject items into project namespaces through forc-pkg (#3770)
This PR, refactor the `BuildPlan` generation a little to be able to
re-use some of the parts from other crates that requires to create
`BuildPlan` from build opts.

On top of that this PR also introduces a way to inject list of items
into the namespace of any member of the workspace.

This is done to unblock #3729

closes #3763.
2023-01-18 11:27:52 +00:00
Mohammad Fawaz
0122a1c700
Bump to v0.33.1 (#3806) 2023-01-18 06:00:31 -05:00
mitchmindtree
7c3331d6fe
Add a forc-tx plugin purely for constructing TXs from CLI (#3582)
This crate allows for constructing arbitrary transactions from the
command line. The constructed `forc_tx::Transaction` can be converted to
a `fuel_tx::Transaction` using the `TryFrom` implementation.

The key difference between the `forc_tx::Transaction` type differs in
that it accepts *paths* for fields like `bytecode`, `storage_slots`,
`predicate_data`, etc. These are loaded during the
`fuel_tx::Transaction`'s `try_from` constructor.

Addresses https://github.com/FuelLabs/sway/issues/3491.

Verbose Example
---------------

The following isn't a valid transaction, but shows what it looks like to
specify arguments including multiple inputs and outputs.

```console
forc tx create \
    --bytecode ./my-contract/out/debug/my-contract.bin \
    --storage-slots ./my-contract/out/debug/my-contract-storage_slots.json \
    --gas-limit 100 \
    --gas-price 0 \
    --maturity 0 \
    --witness ADFD \
    --witness DFDA \
    input coin \
        --utxo-id 0 \
        --output-ix 0 \
        --owner 0x0000000000000000000000000000000000000000000000000000000000000000 \
        --amount 100 \
        --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \
        --tx-ptr 89ACBDEFBDEF \
        --witness-ix 0 \
        --maturity 0 \
        --predicate ./my-predicate/out/debug/my-predicate.bin \
        --predicate-data ./my-predicate.dat \
    input contract \
        --utxo-id 1 \
        --output-ix 1 \
        --balance-root 0x0000000000000000000000000000000000000000000000000000000000000000 \
        --state-root 0x0000000000000000000000000000000000000000000000000000000000000000 \
        --tx-ptr 89ACBDEFBDEF \
        --contract-id 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC \
    input message \
        --msg-id 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB \
        --sender 0x1111111111111111111111111111111111111111111111111111111111111111 \
        --recipient 0x2222222222222222222222222222222222222222222222222222222222222222 \
        --amount 1 \
        --nonce 1234 \
        --witness-ix 1 \
        --msg-data ./message.dat \
        --predicate ./my-predicate2/out/debug/my-predicate2.bin \
        --predicate-data ./my-predicate2.dat \
    output coin \
        --to 0x2222222222222222222222222222222222222222222222222222222222222222 \
        --amount 100 \
        --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \
    output contract \
        --input-ix 1 \
        --balance-root 0x0000000000000000000000000000000000000000000000000000000000000000 \
        --state-root 0x0000000000000000000000000000000000000000000000000000000000000000 \
    output message \
        --recipient 0x2222222222222222222222222222222222222222222222222222222222222222 \
        --amount 100 \
    output change \
        --to 0x2222222222222222222222222222222222222222222222222222222222222222 \
        --amount 100 \
        --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \
    output variable \
        --to 0x2222222222222222222222222222222222222222222222222222222222222222 \
        --amount 100 \
        --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \
    output contract-created \
        --contract-id 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC \
        --state-root 0x0000000000000000000000000000000000000000000000000000000000000000
```

The output of this command dumps the entire `fuel_tx::Transaction`
serialized to JSON to stdout. A `-o tx.json` argument can be provided
(before the transaction type) to write the tx to a file instead.

Follow-up
---------

- Currently, the CLI is a bit unwieldy due to requiring a custom
`try_parse` constructor which is required to parse multiple trailing
input/output subcommands. This is necessary because clap doesn't appear
to allow multiple trailing subcommands by default. We should see if it's
possible to manually implement clap's Subcommand for some custom type in
a manner that allows us the same behaviour but without breaking clap's
generated CLI.
- Possibly add forc-aware defaults, i.e. infer unambiguous defaults for
bytecode, storage slots, etc from the project within the current or
parent directory.
- Base `forc-run`, `forc-deploy` transaction construction on components
from `forc-tx`.
- Add CI tests for `forc tx` command that actually constructs and
submits a transaction to a node. This might be a lot easier to write
once we have something like a `forc submit` command that allows
submitting a transaction from the command line.

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-18 13:45:42 +11:00
João Matos
28899f8e5c
Bootstrap the EVM backend. (#3685)
This bootstraps the EVM backend via the following:

- [x] Add build target support. This is implemented as a `--build-target
/ --target` CLI flag in Forc.
- [x] Allow for multiple asm builders The existing architecture was
refactored to be trait-based, and the code was split into two
directories, for `fuel` and `evm` backends.
- [x] Add minimal EVM assembly output. 
- [x] Add `evm` target testing support.
- [x] Implement EVM smart contract memory loader
- [x] Implement basic Solidity ABI generation
2023-01-13 19:10:20 +00:00
Emily Herbert
b44d8ba1a1
Improve the declaration engine API (#3757)
The goal of this PR is to reduce code bloat. So it does a number of
things, although there are _no functional changes_.

1. Change the canonical code name from "declaration engine" to "decl
engine", including renaming `DeclarationEngine` to `DeclEngine`,
`DeclarationId` to `DeclId`, and `DeclarationWrapper` to `DeclWrapper`.
"`Declaration`" is a lot of syllables to say all the time haha 😅
2. Rename the `DeclEngine::look_up_decl_id` method to `DeclEngine::get`
and rename the `DeclEngine::replace_decl_id` method to
`DeclEngine::replace`.
3. Rename the `DeclEngine::insert` method to
`DeclEngine::insert_wrapper`.
4. Add a new `DeclEngine::insert` method with type param `T:
Into<DeclWrapper>` and add traits for `From<DeclWrapper>` for different
declarations. Replace and remove the dedicated "`insert`" methods with
the generic `DeclEngine::insert` method.

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2023-01-11 15:02:22 -05:00
Kaya Gökalp
970565901d
Exclude tests from ParseTree after parsing if they are not enabled (#3684)
closes #3622.
closes #3586.

unblocks #3673.

## About this PR

After parsing, I added a check to remove tests from `AstTree` if tests
are not enabled. Since all the other checks are done after this
exclusion of tests, this PR also prevents warnings and errors coming
from test functions to be emitted while using `forc build`. They are
still visible with `forc test` as they should be.
2023-01-05 22:58:48 +00:00
Mohammad Fawaz
2b2b4b117c
Bump to v0.33.0 (#3703)
Also ran `cargo update`
2023-01-05 15:27:38 -05:00
Chris O'Brien
aa54dba7bd
Adds interface for generating links between items & modules (#3647)
A redesign of `module_prefix`. This PR introduces the `ModuleInfo`
struct with methods for auto generating paths for use in the rendering
process.

Closes #3646
2023-01-04 18:25:19 +00:00
Joshua Batty
b21009e17d
Return the lexing stage produced by sway_parse from forc-pkg::check() (#3675)
Previous to this PR, `forc_pkg::check()` would only return the
`ParseProgram` and `TyProgram` AST's. In the language server, we now
also need access to the initial lexing stage produced by `sway_parse` in
order to get access to the sway keyword tokens.

This PR now returns the lexing stage of a program along with the parsed
and typed stages.

closes #3524
2023-01-03 16:39:23 -08:00
Emily Herbert
978de4dd80
Remove the global DeclarationEngine (#3411)
This PR removes the global `DeclarationEngine` in favor of keeping a
local copy in the `TypeCheckContext`.

This PR is pretty big... there aren't any additional things added other
than what I """ had to add """ in order to complete this task. At a high
level:

- This PR introduces the `Engines` struct, which has two fields
`type_engine: &TypeEngine` and `declaration_engine: &DeclarationEngine`.
- For most/many of the traits introduced in #3353, this PR changes these
traits to take a `Engines` instead of a `&TypeEngine`

Closes #2063

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-12-22 12:43:03 +11:00
Chris O'Brien
985cea2300
Add context to documentable items & cleanup workspace (#3607)
This PR vastly increases readability of `forc doc`. It makes sure to
evaluate all item context during the `descriptor` phase now, and remove
all unnecessary newtype structs and enums. It also adds the basic item
context for Sway `structs`, `storage`, `traits`, `abi` and `enums`.

There are some issues that I've stumbled upon during this, here are some
screenshots:

1. Enum variant type spans are really just spans of the entire variant,
not the type itself. #3634
![Screenshot from 2022-12-16
23-45-47](https://user-images.githubusercontent.com/57543709/208227540-cb6f3c71-f95e-4a82-89fe-6b5e095aa1ad.png)
2. Methods on `abi` and `traits` also have this same issue, the span of
the return type for functions that don't have a return type I assumed
would be `()` (unit type) but as you can see it's just giving me the
span of the entire function signature. #3635
![Screenshot from 2022-12-16
23-46-04](https://user-images.githubusercontent.com/57543709/208227538-a445bb41-e5ff-4e0d-8a85-c4bda3346418.png)
3. Less important but just an eyes sore, normal comments get removed
during formatting but it seems that doc comments do not which I guess
makes sense because they are really attributes under the hood. This
problem should go away once I add links to everything since I will have
to change how we go about formatting.
![Screenshot from 2022-12-16
23-46-22](https://user-images.githubusercontent.com/57543709/208227537-91ed6a0c-6cfa-4ea7-b3fe-0105907be4fb.png)
![Screenshot from 2022-12-16
23-45-57](https://user-images.githubusercontent.com/57543709/208227539-5081b8b7-325d-4979-b429-6c4f07fbca59.png)
2022-12-21 13:26:22 +11:00
Anton Trunov
211667cde8
Add #[payable] annotation to ABI methods (#3450)
## Description

The lack of this annotation implies the method is non-payable. When
calling an ABI method that is non-payable, the compiler must emit an
error if the amount of coins to forward is not guaranteed to be zero.

The compiler also emits an error if the method signature and the method
implementation have different `#[payable]` annotations.

## Assumptions

Currently, the analysis of non-zero coins is very simple and only checks
if the special `coins:` contract call parameter is the zero `u64`
literal directly or can be reached through a chain of variable/constant
definitions.

## Tests

- [x] Must fail when scripts call non-payable methods with non-zero
coins as a literal
- [x] Must fail when scripts call non-payable methods with non-zero
coins as a constant
- [x] Must fail when scripts call non-payable methods with non-zero
coins as a variable definition
- [x] Must fail when contracts call non-payable methods with non-zero
coins
- [x] Must fail when there is an extra `#[payable]` annotation in method
implementation (not mentioned in its signature)
- [x] Must fail when the `#[payable]` annotation in method
implementation is missing (but mentioned in its signature)

close #1608

## TODOs

- [x] Fix `#[payable]` annotations for the standard library
- [x] Fix the empty parens issue for formatting attributes: #3451
- [x] Parser should allow us write annotations like so: `#[storage(read,
write), payable]`: #3452
- [x] Refactor `#[payable]` annotations in this PR in the style above
- [x] Add more complex formatter unit tests with `payable`
- [x] As pointed out by @mohammadfawaz, the SDK can bypass payable
annotations and one option would be to add function attributes to the
[JSON ABI
schema](https://fuellabs.github.io/fuel-specs/master/protocol/abi/json_abi_format.html)
and process it in the SDK (see these issues:
https://github.com/FuelLabs/fuel-specs/issues/446 and
https://github.com/FuelLabs/fuels-rs/issues/742)
- [x] Bump `fuels-rs`'s version

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2022-12-19 14:26:16 +00:00
Mohammad Fawaz
b9996f1346
Bump to v0.32.2 (#3618)
Mainly to get
efd4518b6d
out as per the SDK team's request.
2022-12-15 22:04:28 -05:00
Emily Herbert
581b44ed12
Update repo in response to clippy update (#3611)
Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-12-16 09:34:16 +11:00
Anton Trunov
5b35baa4cf
Allow comma-separated annotations: #[ann1, ann2, ...] (#3469)
close #3452
close #3475
2022-12-15 09:53:45 +04:00
Mohammad Fawaz
50c1b6c858
Bump to v0.32.1 (#3606)
Mainly to include https://github.com/FuelLabs/sway/pull/3605 so that we
can publish correctly.
2022-12-14 21:59:46 -05:00
Mohammad Fawaz
9f02b5a0b9
Update location of sway.js in forc-doc (#3605)
Looks like `cargo publish` requires that `sway.js` live inside the
`forc-doc` directory. Otherwise, the file is not found. I'm simply
moving `sway.js` to `forc-doc/src/assets` and updating the code to point
to that location instead.
2022-12-15 02:45:07 +00:00
Mohammad Fawaz
5bd25b8611
Bump to v0.32.0 (#3602)
- Bump to `v0.32.0`
- Run `cargo update`
- Bump `fuel-core` CI to `0.15.1` since `cargo update` updated `the
`fuel-core` version in `Cargo.lock`.
2022-12-14 16:42:16 -05:00
Mohammad Fawaz
22a150537a
Fix CI failure by running cargo update and bumping fuel-core (#3581)
This unfortunately happened because I made a non-breaking release in
`fuels-rs` that was in fact breaking. The breaking was non-breaking from
the point of view of the user, but it was breaking from the point of
view of the sway repo.
- Had to run `cargo update` to update the `fuels-rs` version
- Had to bump `fuel-core` to `0.15` due to some transitive dependencies
and conflicting types.
2022-12-13 15:19:47 +11:00
João Matos
10e098c71f
Fix DCA warnings for impl trait methods. (#3427)
We now connect the edge of methods referenced in function call
expressions to the edge of the corresponding node of the implemented
trait method.

For this FunctionDeclaration was extended to keep track of the
implementing type where it is declared.

Also previously we were not correctly connecting edges in
`add_edge_from_entry` due to the function using `self.entry_points`
which is only computed as the last stage of the DCA process. Fix this by
deferring these edge node indices and only making the connection after
they are computed.

Aditionally now we use an `IdentUnique` to keep track of functions in
the CFG namespace which helps disambiguate functions shadowing each
other.

Closes https://github.com/FuelLabs/sway/issues/3067.
2022-12-12 03:22:18 +00:00