## Description
This PR introduces `string slices`.
The basic usage is at `test/src/ir_generation/tests/str_slice.sw`:
```sway
let a: str = "ABC";
```
Before this PR `a` would be of type `str[3]`, a string array.
Now both `string slices` and `string arrays` exist. This PR contains a
new intrinsic that converts from string literals to arrays.
```sway
let a: str = "ABC";
let b: str[3] = __to_str_array("ABC");
```
Runtime conversions can be done using
```sway
let a = "abcd";
let b: str[4] = a.try_as_str_array().unwrap();
let c = from_str_array(b);
```
string slices to string arrays can fail, so they return
`Option<str[N]>`; and because of this `try_as_str_array` lives in `std`.
The inverse, `from_str_array` only fails if `alloc` fails and lives in
`core`.
At this PR `string slices` are forbidden at `configurable`, `storage`,
`const`, and main arguments and returns. The reason for these
limitations is the internal structure of `string slices` having a `ptr`.
The optimized IR for initializing the slice is:
```
v0 = const string<3> "abc"
v1 = ptr_to_int v0 to u64, !2
v2 = get_local ptr { u64, u64 }, __anon_0, !2
v3 = const u64 0
v4 = get_elem_ptr v2, ptr u64, v3
store v1 to v4, !2
v5 = const u64 1
v6 = get_elem_ptr v2, ptr u64, v5
v7 = const u64 3
store v7 to v6, !2
v8 = get_local ptr slice, __anon_1, !2
mem_copy_bytes v8, v2, 16
```
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
## Description
Change AssetId from alias to struct. Allows implementing of methods.
Also moved the helper functions into the struct as methods.
## 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: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: Braqzen <103777923+Braqzen@users.noreply.github.com>
## Description
Implements Hash trait for builtin types and for some std lib types.
This is required to have a proper hashing that does not change in case
the internal memory representation of type changes.
Current hashing functions are hashing the types in memory directly, as
this representation might change in future versions of the VM and
compiler we want to have a more reliable way of getting hashes that
won't change in future versions of the compiler and std lib.
Replaces use of sha256 function with Hasher in storage_map and
storage_vec.
Adds intrinsic __check_str_type.
__check_str_type returns an error at compile time in case the provided
generic type is not a str.
This is used to guarantee that `Hasher` `write_str` is not called with
non str types.
Closes#3835.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## Description
related to #4946.
Directly using `/latest` instead of exact versioning does not work for
some reason. To unblock bump PRs (one waiting, #4945) this PR disables
link checks at links which uses exact latest versions. We should find a
way to point to `latest` without using an exact version.
This pull request is an upgrade to a `fuel-core 0.20.1` release.
The biggest changes coming from this new release is a rework of how
AssetId is structured to support [granular asset
minting](https://github.com/FuelLabs/fuel-specs/pull/491). This means a
contract can mint and burn multiple AssetId's, and the ContractId !=
AssetId.
---------
Co-authored-by: bitzoic <bitzoic.eth@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
Co-authored-by: Sophie <sophiedankel@gmail.com>
## Description
This PR removes unused keys in sway reference so that warnings do not
appear while searching for std after creating a new project with `forc
init`.
Closes#4709
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
## Description
- Introduce three distinguished new error messages on const shadowing as
defined in #4587:
- Variables shadowing constants.
- Constants shadowing variables.
- Constants shadowing constants, _item-style_ and _sequentially_.
- _Item-style_ and _sequential shadowing_ are added as an explicit
concept to the `TypeCheckContext`. This follows the same pattern that we
have in passing _ABI mode_ and _disallow functions_ contextual
information. Basically, the parts of the semantic analysis lower in the
chain need contextual information available and deducible in the upper
parts of the chain. In this case, the deduction is simple - as soon as
we are within a function body, we apply _sequential shadowing_. (Note
that this simple approach will not work if we ever introduce types local
to functions. But this is not an issues. In that case we will need to
redefine the const shadowing within functions in general, and also by
that time I assume we will have the graph collections which will allow
us different approach :-))
- Clean up of redundant error messages as defined in #4799.
Closes#4587, #4799
## 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.
- [ ] 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.
## Description
Style guide example is blocking new releases because it tries to use an
unpublished version of std
## 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.
## Description
closes#4595.
unblocks #4525.
Once #4596 is fixed we can remove std declarations in each manifest file
with a single patch statement in the workspace level manifest file. That
will also open the way to re-enable the disabled member (reentrancy) as
the example depends on sway-lib and sway-lib depends on latest released
std. So without the patch table it is not useable.
follow-up: #4596.
## Description
Since predicates are now gas-metered and allow backwards jumps, this
lifts the restriction so loops can be used in predicates. Fix#4521
## 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.
## 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.
## 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>
## 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>
## Description
fixes#4424closes#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>
## 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.
## Description
resolves#2740closes#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>
## 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.
## 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>
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`.
## Summary
More information can be found in #2443 .
Notes for PR:
- The review is meant to take place using `mdbook` so check out the main
`README.md` to see how to run it in the browser
- This book is incomplete however there are a lot of pages so the idea
is to PR this into the repo soon so that subsequent reviews are smaller
- No CI added until the book is ready to replace the current book
- Ideally reviews are split between multiple people because there is a
lot of content
Closes#2443
## Pages Reviewed
@matt-user : Program Types -> Functions, Misc
Co-authored-by: Bikem <bengisuozaydin@gmail.com>
Co-authored-by: Matt <54373384+matt-user@users.noreply.github.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: bing <bingcicle@proton.me>
Co-authored-by: Mitch Martin <111294749+mitch-fuel@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Luiz Felipe Bolsoni Gomes <8636507+LuizAsFight@users.noreply.github.com>
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>