## Description
This PR is part of https://github.com/FuelLabs/sway/pull/4794 and
implements more operators for u256:
- [x] sub
- [x] mul
- [x] div
- [x] comparisions
- [x] mod
## 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: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
## Description
This PR is part of https://github.com/FuelLabs/sway/pull/4794. It
implements support for u256 add operators.
The IR generated is a vanilla `add` operator as any other integer.
```rust
script {
entry fn main() -> u256, !1 {
entry():
v0 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !2
v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !3
v2 = call add_0(v0, v1), !4
ret u256 v2
}
}
```
This will then be transformed by `miscdemotion` pass to something like:
```rust
script {
entry fn main() -> u256 {
local u256 __wide_lhs
local mut u256 __wide_result
local u256 __wide_rhs
entry():
v0 = get_local ptr u256, __wide_lhs, !0
v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !0
store v1 to v0, !0
v2 = get_local ptr u256, __wide_rhs, !0
v3 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !0
store v3 to v2, !0
v4 = get_local ptr u256, __wide_result, !0
wide add v0, v2 to v4, !0
v5 = load v4, !0
ret u256 v5
}
}
```
Mind the `wide add` here. It is a Fuel specific operation, giving space
to other targets to implement this differently.
## 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
In Rust, when implementing traits the type `Self` is used instead of the
concrete type. This provides a more flexible and generic API design and
it promotes code reusability and simplifies the creation of fluent
interfaces. The same has now been done for Sway.
## 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).
- [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: bitzoic <bitzoic.eth@gmail.com>
## Description
This does two things.
1. Integer types no longer automatically cast to each other. Methods
such as `as_u64` and `try_as_u8` have been introduced to require the
user to explicit the cast.
Warnings about casts losing precision have been removed as they are no
longer possible.
2. Numeric literals (such as `32` without further qualifications) no
longer immediately decay to a `u64` and we instead attempt to type them
as `TypeInfo::Numeric` as far as possible to allow their usage with any
integer type.
Numeric intrinsics unify arguments with the numeric type to enforce
their constraints.
Numeric values are forced to decay to `u64` when resolving methods or
traits.
This change is a prerequisite to move our representation of
sub-byte-sized values to a different memory representation, as numeric
types need to be distinct if we are ever to treat them differently.
Fixes#3470
## 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
Looked for the le function for a while being realizing the weird
formatting was hiding it. The newline for the impls are also unnecessary
## 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.
- [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.
## Description
Closes https://github.com/FuelLabs/sway/issues/4711.
This PR fixes the problem when initializing a constant unsigned integer
using "bitwise not". Main issue was that at `ops.sw` the bitwise
operator was implemented using `AsmFunctions`, which are ignored in
const eval.
I have created a new `__not` intrinsic which now works (almost) as
expected. We still have two issues surrounding this "const eval":
1 - All integers are `u64`, so inside the `const eval`, we do not have
enough context to correct do the bitwise. That is why `Not` for u8, u16
and u32 do a `__and` afterwards;
2 - `bool` is not using the new intrinsic, so it does not support
`bool`.
## 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: IGI-111 <igi-111@protonmail.com>
fixes#4646
## Description
This PR fixes the linked issue by introducing overflow/underflow checks
in the `Add`, `Mul`, `Sub` stdlib traits implementations for the `u8`,
`u16` and `u32` types.
## 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 PR cleans up stdlib warnings that have accumulated.
## 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#4626
## Checklist
- [x] 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).
- [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.
---------
Co-authored-by: Marcos Henrich <marcoshenrich@gmail.com>
## Description
This change introduces `__mod`, `__shl` and `__shr` intrinsics for use
with integer operations to remove the asm block based implementations in
core and enable us to support const evaluation of integer expressions in
most cases, notably when specifying values like `1 << 32`.
## 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 adds a field to `StorageKey` that is unique among storage fields.
It aims to alleviate the problem created by having multiple zero sized
fields inside of a storage struct, which are, by necessity, living in
the same slot.
It allows `StorageMap` (which itself is zero-sized) to address its own
values on a unique address map instead of colliding with adjacent
`StorageMap`s.
This is a breaking change because it will generate different IR
for the same code.
Fixes https://github.com/FuelLabs/sway/issues/4524
Fixes https://github.com/FuelLabs/sway/issues/4523
## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
This change mainly adds checks to enforce the new module privacy rules
and supporting changes for it.
Changes include updating std and core to use
public modules, updating the parser to allow the use of the `pub mod`
syntax and adding an error type for private modules.
This change is implemented behind a `--experimental-private-modules`
experimental flag and not enabled by default.
It implements part of https://github.com/FuelLabs/sway/issues/4446, the
`pub use` syntax is yet to be implemented.
## 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
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>
## Description
This PR introduces `StorageHandle` to the `core` as an **experimental**
feature. `StorageHandle` is a descriptor of a location in storage
containing two fields:
1. A key pointing to a storage slot `s`.
2. An offset pointing to a particular word in `s` or in its subsequent
slots. This offset is new and is not described in the RFC. I will
rectify that shortly.
The standard library introduces helper methods `read`, `try_read`, and
`write` to `StorageHandle` that allow reading from and writing to the
location pointed to by the handle. `try_read` returns an `Option`
wrapping the data while `read` automatically internally unwraps the data
and could panic.
The summary of this change is as follows:
* New struct `core::experimental::storage::StorageHandle`
* New storage library `std::experimental::storage::*` that should
eventually replace `std::storage::*`. This new library mirrors the old
one to the extent possible and introduces the helper methods for
`StorageHandle`. Other data structures such as `StorageVec` and
`StorageBytes` will be introduced in a separate PR.
* Add an experimental flag `--experimental-storage` to `forc` that
enables all the required code in the compiler to support `StorageHandle`
as described in the https://github.com/FuelLabs/sway-rfcs/pull/23.
* Type checking phases assumes the existence of `StorageHandle` and
monomorphizes it as needed.
* Storage accesses now always return `StorageHandle` and storage
reassignment are no longer relevant.
* IR gen handles storage accesses by "filling" the key and the offset in
an aggregate representing the `StorageHandle`. The key and the offset
are statically determined based on the index of the storage variable in
the `storage` block and the field accessed, if applicable.
* Storage initializers are now handled based on the new model
* The new approach packs struct fields by default but does not pack
across storage variables. This offers the most amount of flexibility.
This is a deviation from the RFC which I will update shortly.
* To implement `StorageMap` and other dynamic storage data structures,
we now write `impl StorageHandle<StorageMap<K, V>>` instead of `impl
StorageMap<K, V>` directly. Also, note that the `get` method now returns
a `StorageHandle` instead of the actual data. To get the actual data,
`read()` or `try_read()` should be called on the resulting handle. This
is needed for multiple reasons including proper support for nested
dynamic storage types. Rust also does the same, in a way (where `get`
actually returns ` &` which happens to coerce to the real data in
certain places).
* I added various tests but they're not comprehensive. Some tests on my
list:
* Extensive tests for storage maps in structs (which now work!)
* Extensive tests for storage accesses with various types and struct
layouts
I still need to figure out how to do nested dynamic storage types with
this approach. The stuff I have in `map_in_map_access` in
`test_projects/experimental_storage/src/main.sw` is just an attempt but
not ergonomic at all of course.
## Checklist
- [ ] 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.
- [ ] 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.
## Description
With these changes we will have DCA warnings for function parameters.
This PR also fixes tests that have unused function parameters.
## Checklist
- [ ] 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: Mohammad Fawaz <mohammadfawaz89@gmail.com>
## Description
This PR introduces a way more generalized way to store heap types into
storage as discussed
[here](https://github.com/FuelLabs/sway/issues/4013) with the
`StorableSlice` trait. The current implementation of the `store` and
`get` functions do not support heap types. With the use of `raw_slice`
any heap types may now be stored.
This PR unlocks https://github.com/FuelLabs/sway-libs/issues/40 which is
required for a number of other issues.
With the introduction of the `StorableSlice` trait, the `StorageBytes`
have been refactored to use it.
This trait could be used to convert a `Vec` to a `StorageVec` in an
efficient manner in another PR. While `Vec` already has the ability to
convert to a `raw_slice`, `Storage_Vec` stores each element using a
unique key created by hashing the index of that element i.e.
sha256(index) in a more linked-list like fashion. This would need to be
changed if this functionality is desired.
**NOTE:** A `from_raw_slice` function has been added to the `Bytes` type
to enable the refactor. This should be removed and replaced once
https://github.com/FuelLabs/sway/pull/3882 is resolved and also uses the
`len_bytes` function introduced in that PR.
## 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: bitzoic <cameron.carstens@fuel.sh>
## 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.
## 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.
This PR fixes the bug described in #3891 by adding `ops` to the prelude
in `core`. This change is congruent with Rust's approach as well.
This is a _breaking change_---if any users have any traits manually
implemented for which core already has an existing implementation, this
will now create an error. A rightful one, IMO, but a breaking change
nonetheless.
A few of the tests were written in a way that is not compatible with
this change---so this PR rewrites these. The only one of note is that a
old `should_pass/language/trait_override_bug` test was refactored to a
new `should_fail/redefine_method_from_core` test.
This PR also refactors the trait finding algorithm in
`check_if_trait_constraints_are_satisfied_for_type` to reduce it from
O(n^2) to O(n).
Closes#3891
Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
Copies the documentation from
https://doc.rust-lang.org/std/primitive.never.html.
Copies the link above to the possible extend. Rust has more use cases to
the Never type than Sway currently has, so the sections were not
included in the
docstring as they are not applicable to the Sway Never type.
Co-authored-by: João Matos <joao@tritao.eu>
Re-enables test diverge_in_op_not.
In rust
```
let b = {
return 5;
}[0];
```
Gives error: `cannot index into a value of type !`
While:
```
let b = {
return 5;
[true, false]
}[0];
```
No longer gives an error.
This shows us that rust compiler uses the implicit return of a block
that deterministically aborts to compile the rest of the code.
The behavior of `TyCodeBlock::type_check` was changed to as rust do and
apply the implicit return when possible even when block
deterministically aborts. When a block deterministically aborts and no
implicit return is used then the block return type is assigned to Never
enum.
Now similar to rust the following code:
```
let b = {
return 5;
}[0];
```
Gives the error: `No method named "index" found for type "Never".`
Closes#2881Closes#3061
Adds changes done by @emilyaherbert.
Empty match arms are ok for types that have no valid constructor.
[2b52de9](2b52de98fd)
Closes https://github.com/FuelLabs/sway/issues/1679
Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
The current `core::num` name is not well aligned with types like `b256`
which are not numeric types.
In addition, in Rust, methods like `min(), `max()` and `bits()` are in
the `primitives` module.
Closes#2777
This PR is a minimal cut of https://github.com/FuelLabs/sway/pull/3251
that just implements the bare minimum required to fix
https://github.com/FuelLabs/fuels-ts/issues/467:
- A new type `raw_slice` and support for returning it from scripts.
- Support for conversion between `raw_slice` and `Vec`.
```rs
script;
fn main() -> raw_slice {
// Create a vec
let vec = Vec::new();
vec.push(42);
vec.push(1337);
// Return it
vec.as_slice()
}
```
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Closes https://github.com/FuelLabs/sway/issues/3155
This is needed due to `mem2reg` and some unclear semantics around
initialized registers being passed as ref/mut ref. Besides, it's a good
idea to restrict `asm` blocks as much as possible to avoid weird
unwanted behavior.
<img width="883" alt="image"
src="https://user-images.githubusercontent.com/59666792/199332120-974d1821-680e-43a1-922d-1a32d491b3cd.png">
* I also removed the `disallow_opcodes` check because the parser takes
care of that now. The parser only allows legal opcodes in `asm` blocks.
* Finally, I update the parser to accept the correct storage opcodes
with `fuel-core 0.13` and updates all the tests.
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
This PR:
- Adds `__ptr_add<T>(ptr: raw_ptr, count: u64)` (which basically does
`ptr + __size_of::<T>() * count`) and its sub counterpart to be used in
pointer offset calculations.
- Makes `std::alloc::*` and `raw_ptr::*` have type arguments and work in
increments of `size_of::<T>()` instead of bytes.
- Removes test `fixing_generic_type` which was broken instead of
maintaining it. This test was created to reproduce an issue I was having
a few months ago. Fixing this allowed other things to be built so there
are other tests that touch this case.
Fixes https://github.com/FuelLabs/sway/issues/1436.
This PR first removes the need for `~` in `~Foo::bar` by first delaying
the interpretation of `Foo::Bar` (associated call, free function call,
or enum variant construction?) until type checking. This is achieved
with `ExprKind::AmbiguousPathExpression`. During type checking, we ask
whether `Foo` (and any prefixes) is a module, or an enum. If it's
neither, we attempt type checking as an associated function call.
Otherwise, we continue as if we had a `ExpressionKind::DelineatedPath`.
Once `~` is made redundant, it's then also removed from the language and
so also from tests, examples, and the standard library.
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
With this change, `core` and `std` should stop providing a convenient
way to access pointers as `u64`s.
While this might seem limiting, with `alloc()` returning `raw_ptr`s that
have `add()` and `sub()`, all usages of `.addr()` could be refactored.
(If not there's still `asm(r1: ptr) { r1: u64 }` of course.)
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
This PR:
- Introduces the `raw_ptr` type.
- Changes RawVec's `ptr` field from `u64` to `raw_ptr`.
- Disallows returning `raw_ptr`s (and aggregate types that contain it)
from being returned from `main()` fns.

---
Note to @sezna:
On our meeting we discussed `checks.rs`, which led me to this
implementation:
090a4d1a4d
That didn't work because `raw_ptr`s are converted to
`sway_ir::irtype::Type::Uint(64)`s so there wasn't a way to
differentiate them. I've reverted that and went with this instead:
fc6bf34084
Co-authored-by: Andrew Cann <shum@canndrew.org>
Co-authored-by: tyshkor <tyshko1@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Simon <46566889+simonr0204@users.noreply.github.com>
* feat: add left and right shift for b256
* style: fmt
* fix: rename helper functions
* merge cleanup
* fix: update type of other to u64
* test: add first shifting assertions
* fix: cleanup & refactor shifting functions
* test: get initial tests passing
* feat: draft impl add for b256
* test: add first test for impl add for b256
* rename functions
* test: cleanup
* bugfix: WIP
* progress
* refactor: add loop version of lsh
* fix: use ifs for now until vec lands
* test: fix tests
* cleanup
* cleanup: rsh_with_carry
* feat: impl right shift
* test: add tests for right shift
* cleanup
* fmt
* cleanup: remove unused const FLAG
* refactor: remove asm from shifting funcs
* cleanup: remove some consts from constants.sw
* feat: add impl b256 to num module
* test: fix all usage of ZERO const in tests
* fix: update example project to use new b256::min()
* style: fmt
* fix: fix comments
* style: fmt examples
* Revert "fix: fix comments"
This reverts commit 65e7176a4e.
* docs: fix comment for b256::max()
* fix: update intrinsics
* fmt