Commit graph

517 commits

Author SHA1 Message Date
IGI-111
ce9ce93ea8
Fix --finalized-asm output and docs (#4510)
## Description

This change does three things.

First it repairs the output of the `--finalize-asm` build option so it
actually outputs readable asm.

Second it updates the documentation on build profiles and in all
occurences of `--print-finalize-asm` to use the new flag, use the
correct names of build profile options and adds documentation for the
new flags. Fixes #4481

Third, it lets the deserialization of the flags to use default values
when the flags for a certain build profile are not all defined, so users
can define a new build profile to tweak a small number of options and
get the least surprising behavior.

## 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-05-01 02:07:37 +02:00
IGI-111
6a3fba19d4
Add Option and Result variants in prelude (#4504)
## Description

This also handles ambiguities in cases where a lone ident is either a
variable or a variant; or a variable declaration or an enum scrutinee.

Fix #4480

## 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-04-28 09:58:54 +00:00
Call Delegation
af5f536101
Added to msg_sender to prelude and removed from swayfiles (#4483)
## Description
Fixes #4478

## 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: Kin Chan <calldelegation@calldelegation.local>
2023-04-27 17:05:37 -04:00
sarahschwartz
384646c991
fix broken installation url, typo (#4488)
close #4379
2023-04-25 01:05:46 +00:00
Mohammad Fawaz
1db8385158
Replace old storage API with the new one explained in the StorageKey RFC (#4464)
## Description
Implement https://github.com/FuelLabs/sway-rfcs/pull/23

Closes https://github.com/FuelLabs/sway/issues/3419 (technically via the
RFC)
Closes https://github.com/FuelLabs/sway/issues/3202
Closes https://github.com/FuelLabs/sway/issues/3043
Closes https://github.com/FuelLabs/sway/issues/2639
Closes https://github.com/FuelLabs/sway/issues/2465
Closes https://github.com/FuelLabs/sway/issues/4304

This is a big one but mostly removes stuff. It's hard to review but the
summary of changes below should be sufficient. Most of the changes here
are things that I just had to do to make CI pass.

- Removed the `--experimental-storage` flag and made its
[behavior](https://github.com/FuelLabs/sway/pull/4297) the default. Also
removed everything that was required for the previous storage APIs in
favour of the new ones.
- Break down the `std::storage` into multiple submodules:
 - `storage_key` implements the API for `std::core::StorageKey`
- `storage_api` implements the free functions `read` (previously `get`),
`write` (previously `store`), and `clear`.
- 4 more modules for the dynamic storage types which now use the new
`StorageKey` API.
- `#[storage(write)]` now allows reading from storage as well. This is
needed because the way we pack structs in storage now requires that we
sometimes read from storage first if we were to write a portion of a
slot.
- Removed the "storage only types" checks and the corresponding tests.
- Removed the `__get_storage_key` intrinsic and the `get_storage_key` IR
instruction and all corresponding tests. Also removed the `state_index`
metadata as it is no longer required.
- Added tests and example to showcase nested storage maps and nested
storage vectors.

## 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-04-21 07:36:40 -04:00
Call Delegation
3ffd038ae4
Adding subsection on address and contract types (#4479)
## Description
Closes #2704

## 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.
- [ ] 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: Kin Chan <calldelegation@calldelegation.local>
2023-04-20 18:09:38 -04:00
Kaya Gökalp
ebdbbfe2dd
feat: exit with 101 from forc-test if there are failing tests (#4463)
## Description
closes #4462.

With this PR we exit from `forc test` with 101 exit status, if there are
failing unit tests. If `forc test` execution itself fails we exit with
1. This is useful especially in CIs as the return status can be checked
to better understand what is happening.

## 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).
- [ ] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
2023-04-19 22:48:37 +00:00
Kaya Gökalp
35fe3248c3
feat: workspace level patch table added (#4086)
## Description
closes #3958.

This is a handy feature for tests with workspaces. We were already
supporting a `patch` table feature for packages. This PR adds the same
feature for workspaces. Basically we can patch every instance of a
package with a different version. One main motivation behind this can be
patching the standard library while working with an unreleased version
of `forc`. With this feature we can pin the `std` version for the whole
workspace so that all members in the workspace depending on `std` would
depend on master version of the `std`.
2023-04-19 13:03:45 +03:00
IGI-111
30f869a3a8
Implement OR match pattern (#4348)
## Description

Allow users to specify match patters such as:

```sway
let x = 1;
match x {
  0 | 1 => true,
  _ => false
}
```

We also check that all patterns in a disjunction declare the same set of
variables (not doing so is an error).

Fix https://github.com/FuelLabs/sway/issues/769

This requires a change in the pattern matching analysis to remove the
assumption that a specialized matrix of a vector pattern is always a
vector, which is now no longer true because or patterns can generate
multiple branches and therefore multiple rows.

## 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-04-18 22:08:17 +00:00
Mohammad Yasir
800089eb62
Updated the sway.js file by adding mod and type in keyword (#4427)
## Description
fixes #4424 
closes #4424 


## Checklist

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

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-04-12 22:39:45 +00:00
Kaya Gökalp
91ed9817bf
feat: parallel unit test runners (#4395)
## Description
closes #3953

This PR adds parallel test runners to improve our test execution times
by utilizing the fact that each test is actually completely separate
from each other. Also a flag `--test-threads` added to `forc-test` to
manually control number of thread used for execution.

Simple benchmarks taken from my local system with m1 max can be seen in
below: (
*Each config is executed 10 times)*
| Num Threads      | Average Time |
| ----------- | ----------- |
| 1      | 1.019   ms  |
| 2   | 938 ms        |
| 4   | 883 ms        |


As it can be seen speed-ups aren't great as this includes building as
well which is done with single thread. So I tested just building with
tests enabled on the same project (which is sway-lib-std btw) which
takes 810ms (again averaged 10 times). So after I normalize the results
above with this data
| Num Threads      | Average Time |
| ----------- | ----------- |
| 1      | 209    ms |
| 2   | 128 ms       |
| 4   | 73 ms         |

Speed-ups are more visible with more complex tests with increased number
of tests.
2023-04-05 22:57:07 +00:00
João Matos
92ecf7f4a3
Implement associated consts for traits (#4301)
## Description

This is the last step to getting associated consts to work.

First it refactors the existing const support to use a newly-introduced
`ConstantExpression` instead of relying on `VariableExpression` like
we've been doing previously.

Then it adds IR generation for associated constants and enables the
relevant tests.

[Add ConstantExpression and IR generation
support.](3d2e62598f)

[Update ConstantExpression constant before IR
generation.](4ec7ebe807)

[Add IR generation for associated
consts.](67386a874e)

Then there also some commits adding some new documentation:

[Add traits documentation to the
reference.](afda9026a0)

[Add some documentation about associated consts to the
book.](6845ddc166)

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

## 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-04-05 13:20:17 +00:00
Kaya Gökalp
8e30dc2a5b
feat: add forc contract-id and forc predicate-id commands (#4338)
## Description
Adds `forc contract-id` and `forc predicate-id` commands for contract id and predicate root detection.

closes #3444.
2023-04-04 02:19:41 +00:00
Camila
5731920fae
streamline installation steps (#4380)
## Description
The current installation steps have rust and rustup dependencies at the
bottom of the page, and its not clear to the user that they need it in
order to install fuelup. This PR moves those instructions to the top of
the page to make it intuitive.

## Checklist

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

Co-authored-by: Camila Ramos <camiinthisthang@Camilas-MacBook-Pro-3.local>
2023-04-01 21:37:34 +00:00
bing
00ba771319
docs: remove missing feature regarding configurables (#4317)
## Description

https://github.com/FuelLabs/sway/issues/2647 has been resolved.

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
2023-03-21 15:27:50 +11:00
sarahschwartz
48f0aba358
direct to fuel book quickstart (#4313)
This PR redirects users on the quickstart page to the Fuel book
developer quickstart
2023-03-20 09:20:20 -06:00
bing
032cd3b3b7
refactor: deprecate ConfigTimeConstants (#4298)
## Description

Closes #3681 

I meant to tackle #3077 first, but tackling #3681 first cleans up a lot
of the code needed to make #3077 easier.

This PR is mostly cleanup:
- Completely removes usage of `ConfigTimeConstant` everywhere (in
forc-pkg, sway-core, sway-type)
- **(BREAKING)** Completely removes support for `[constants]` table in
the manifest, which was using the `ConfigTimeConstant` struct. This
change is breaking for app devs ([open
issue](https://github.com/FuelLabs/sway-applications/issues/375)) and
from a [quick
search](https://github.com/FuelLabs/sway-applications/search?l=TOML&q=%5Bconstants%5D)
on our sway-applications repo, there's a number of manifests still using
the old version of configuration time constants.

Consequentially, the above change also allowed us to cut down on other
constructs like `ConstInjectMap` within forc-pkg, since the only thing
we need to inject now are const CONTRACT_IDs - this cuts down quite a
bit of now-redundant code.

- As a result of the removal of `ConfigTimeConstant`, a few tests using
that feature were also deleted.
- Also updated the `configurable` example to be known as
`configurable_constants` instead of `config_time_constant`.


**This PR does not:**
- Fix the manual creation of `CONTRACT_ID` const. To create the const,
we still undergo manual parsing and type-checking and finally inserting
into a `SymbolMap` manually. This will be handled in a separate PR to
tackle #3077

Other than removal of a lot of code to do with CTC, the main change here
that allows contract dependencies to still work here is instead of
relying on the `ConstInjectMap` which we used to inject both constants
and contract dependencies, there is now only a single contract ID value
that we require (this is abstracted as `ContractIdConst`) to inject into
the contract for tests.

## 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-03-17 01:15:55 +00:00
Kaya Gökalp
f4cffba1c4
feat: multi contract calls in unit tests for contracts (#4156)
## Description
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

### Follow-ups
- #4161
- ~#4162~
 
## 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: Kaya Gokalp <kayagokalp@fuel.sh>
2023-03-16 10:01:16 +00:00
Mohammad Fawaz
2ffb034eb8
Implementing basic type aliases (#4151) 2023-03-16 00:58:30 +00:00
Kaya Gökalp
1a2d323e9c
docs: quick-start section move the --node-url explanation under the example (#4279)
## Description
closes #4278.

Simple documentation fix, in quick start section we were explaining the
`--node-url` before giving an example that uses it. I moved the
explanation under the example.
2023-03-15 09:30:02 +00:00
Vaivaswatha N
b48cabd14e
More intrinsics and const_eval (#4260)
## Description
New intrinsics and constant evaluations supported by this PR can be seen
in the additions to
[const_inits](https://github.com/FuelLabs/sway/compare/vaivaswatha/const_eval_407?expand=1#diff-5886ff784ee10cb93be850eba9966c80d539bf6c08eaeb7d286183494690c610)
test.

 Closes #407.

## 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-03-10 16:12:54 +00:00
AndrésF
63382365bd
doc: Adding annotations support on highlight.js (#4186)
## Description

resolves #2740
closes #4157

> In order to give a better highlighting I picked the "meta" scope as
seen in [highlight.js
docs](https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html)
> 
> The ["Mode"
](https://highlightjs.readthedocs.io/en/latest/language-guide.html) I've
added provides the html class: _hljs-meta_ however, the result is a
white color for annotation (like plain text) and not a blue color as
requested in the issue.
> 
> The solution I've found for this is to add an additional css file to
specify custom behavior for the desired class. I haven't added this file
because I think it's out of scope.


## Checklist

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

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-03-10 15:24:50 +00:00
Mohammad Fawaz
b33463d3f9
Bump to fuels v0.37 and add a test and docs for configurable blocks (#4255)
## Description
Closes #4206 

Three main changes: 
* Add new configuration-time constants tests to `sdk-harness`. This is
important to make sure there are no regression in the backend.
* Add a new example for `configurable`
* Document `configurable`
* Had to bump to `fuels 0.37` to be able to update `configurable`
variables from the SDK.

## 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-03-10 09:59:59 +11:00
IGI-111
0eaa3a6da9
Standardized module structure (#4232)
## Description

Implement RFC 0006, fix #4191.

Remove the `dep` reseved keyword in favor of `mod`.

Change path resolution for submodules to use an adjascent file at the
root and a folder named after the current module in other cases.

Remove the need for an argument to `library`, the LSP now points to
empty spans at the top of module files.

The library names are now determined by the file name, or the package
name at the top level.

## 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-03-09 19:14:52 +11:00
Mohammad Fawaz
cfb5d48bfc
New example for methods and associated functions (#4226)
## Description
Closes #4223

Basically just showing that associated methods do actually work.

## 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).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2023-03-07 09:02:20 +11:00
Akash S M
0125b3851f
Update the invalid link to Developer Quickstart Guide in the Sway Docs. (#4216) 2023-03-03 21:22:26 +00:00
Mohammad Fawaz
22195ba404
Fix broken link and missing summary item for the "Attributes" chapter (#4214)
## Description


## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
2023-03-03 16:29:06 +00:00
Marcos Henrich
829cb7cd7f
Adds documentation for Sway attributes. (#4203)
## Description
Adds Documentation for allow, doc, inline, payable, storage, and test
attributes.

Closes #3302
Closes #4114

## 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.

---------

Co-authored-by: João Matos <joao@tritao.eu>
2023-03-02 15:06:57 +00:00
Chris O'Brien
ed15a08a1b
Add std docs to the sway book (#4204)
## Description
Adds a link to the `std` docs in the standard library section of the
sway book & links the source code in the root docstring of the `std`
library itself.

![Screenshot from 2023-02-28
10-44-52](https://user-images.githubusercontent.com/57543709/221920234-b08548e9-70fc-45f6-a02b-5620a4e64913.png)


## Checklist

- [x] I have linked to any relevant issues. #4200 
- [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-28 18:15:35 -05:00
Camila
a1cacd6e19
add Result to blockchain types (#3894)
Added the Result type to the same page where Identity, ContractId, and
Address are covered. Definition was taken from standard library repo -
https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/result.sw

---------

Co-authored-by: Camila Ramos <camiinthisthang@Camilas-MacBook-Pro-3.local>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-23 23:18:46 +11:00
Vishwa Mehta
d9131a9a9c
Add usage docs for Salt feature (#4132)
## Description

Added usage docs for `--salt` and `--random-salt` flags

---------

Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-23 03:06:22 +03:00
Camila
6e5262a3eb
Update match examples (#4107)
## Description
Updated match examples to be more intuitive and helpful for the reader,
replacing function and variable names like foo, bar, etc.

## 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.

---------

Co-authored-by: Camila Ramos <camiinthisthang@Camilas-MacBook-Pro-3.local>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-21 13:32:38 -05:00
mitchmindtree
af634d6a1a
Update Sway book section on forc-wallet for changes in v0.2.0 (#4146)
## Description

See the detailed release notes for `forc-wallet` v0.2.0 here:

https://github.com/FuelLabs/forc-wallet/releases/tag/v0.2.0

Related: https://github.com/FuelLabs/forc-wallet/issues/87.

## 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-21 18:43:56 +11:00
Vishwa Mehta
a0202af80b
Add Google Analytics ID to book.toml (#4121)
## Description

mdBook lets you track traffic on your generated website or docs simply
by adding the tracking ID to the `book.toml` file.

This PR adds the Google Analytics tracking ID to `book.toml` for Sway
Book.

---------

Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-20 13:37:44 +00:00
Kaya Gökalp
88776b8ab3
doc: updated docs with missing supported workspace commands (#4122)
## Description
closes #4102.

Tiny doc PR adding missing essential commands that now supports
workspaces

## 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.
2023-02-18 02:59:58 +00:00
Anton Trunov
8ce36000d3
Supertraits for ABIs (#3992)
## Description

Please see the issue #3798.

## 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.

## Tasks

- [x] check the supertrait(s) for the ABI is implemented
- [x] fail with an error when a supertrait for ABI is not implemented
- [x] check that ABI implementation methods can use its supertrait's
methods (the one that are defined at the ABI _declaration_ site)
- [x] check that the supertrait's methods can be used in the actual
contract methods
- [x] check that methods in supertraits are not be available externally
(i.e. they're not actually contract methods)
- [x] implement that Ownable example
- [x] formatter tests
- [x] add new section in the Sway docs illustrating this language
feature

---------

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-16 10:38:14 -05:00
Vishwa Mehta
fac37d310e
beta-3 updates (#4068)
## Description

Ongoing PR for beta-3 changes in the Sway repo:
1. Made minor changes in the Sway quickstart for beta-3

---------

Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
2023-02-13 14:57:43 -05:00
Vishwa Mehta
ed60928f21
Update installation.md for beta-3 (#4039) 2023-02-12 16:40:11 +00:00
Harsh Ghodkar
7669954789
Update links in libraries.md (#4044)
## Description
Some links leading towards sway libraries were broken and not pointing
towards the official repo. Fixed those.

## 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: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-12 14:33:33 +00: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
Riley
b80283f131
Remove reentrancy library (#3698)
## Overview

Closes #3217, migrates the reentrancy library to Sway-libs.

> Notice: Awaiting merge and version bump from Sway-libs ([relevant pull
request](https://github.com/FuelLabs/sway-libs/pull/70)).

## Changes

- remove reentrancy library
- remove reentrancy tests
- modifies documentation to point to new reentrancy guard url
- modifies imports of `std::reentrancy::` to `sway_libs::reentrancy`

---------

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-02-07 09:15:29 -05:00
Mitchell Mackert
4eb4edd17a
Update sway book README (#3983)
Closes #3981

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-02-07 10:34:49 +11:00
Chris O'Brien
880c22f243
Add forc doc to CI documenter (#3977) 2023-02-03 04:22:48 -06:00
Vishwa Mehta
37583c4821
Update link to Fuel Spec book (#3969) 2023-02-02 08:36:37 -05:00
Braqzen
4131a16927
Add logging::log & assert::assert_eq to prelude.sw (#3916) 2023-01-29 14:28:06 -07:00
Camila
d5c9326b4d
update installation instructions, add link to forum (#3890) 2023-01-28 08:18:14 +00:00
Mohammad Fawaz
0a3beae92e
Update std::storage::get and std::storage::StorageMap::get to return an Option (#3862)
API change:
Previous:
```rust
pub fn get<T>(key: b256) -> T;
pub fn get(self, key: K) -> V;
```
Now:
```rust
pub fn get<T>(key: b256) -> Option<T>;
pub fn get(self, key: K) -> Option<V>;
```
`Option::None` indicates that the storage slot requested in not
available.

- Updated all storage intrinsics to return a `bool` except for
`__state_load_word` because it already returns the value loaded. The
`bool` returned represents the previous state of the storage slots as
described in the specs. I was not able to update `__state_load_word` to
return both the value loaded and the `bool` unfortunately because I hit
various hiccups along the way, particularly in IR/codegen.
- Updated `get` and `StorageMap::get` in the standard library to return
an `Option` based on the Boolean mentioned above. In the copy type case,
I had to use `asm` blocks instead of `__state_load_word` until we're
able to return a struct from an intrinsic.
- I did not update `store` and `StorageMap::insert` to return an
`Option`, for now, because that would involve an extra storage read to
return the previous value, if available. We can think about whether this
is worth it at some point.
- I added `unwrap` and `unwrap_or` where it makes sense in `StoargeVec`.
- Update various docs, examples, and tests.

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

I will open separate issues for updating `__state_load_word` and
thinking about making `store` and `insert` also return an `Option`.
2023-01-24 14:00:17 +00:00
Vishwa Mehta
a0ef103c58
Fix bug in "Advanced Calls" section in Sway book (#3874)
Bug:
The example script in the [Advanced
Calls](https://fuellabs.github.io/sway/v0.33.1/book/blockchain-development/calling_contracts.html#advanced-calls)
section of the Sway Book uses `amount` to specify the asset amount to
send with the function call.

Error:
`Unrecognized contract ABI method parameter "amount". The only available
parameters are "gas", "coins", and "asset_id"`

Solution:
Replaced keyword `amount` with the expected keyword `coins`.

Fixes issue #3834

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
2023-01-24 12:51:55 +00: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
Vishwa Mehta
313f6b6ea9
Add additional sections under Libraries (#3786)
Added the following additional info under the `Libraries` page in the
Sway Book:

- External and Internal Libraries distinction with examples for
importing them
- Brief description of Sway Libraries with various sway-libs currently
available for code reuse

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: “vish” <“vishwa.mehta30@gmail.com”>
2023-01-23 03:51:37 +00:00