mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-13 23:28:46 +00:00
![]() ## Description This PR is part of https://github.com/FuelLabs/sway/issues/5110 and introduces two new intrinsic: `__slice` and `__elem_at`. `__slice` allows the creation of slices by slicing arrays or other slices. Whilst `__elem_at` returns a reference to an item inside the slice or the array. ## Out of bounds checks These intrinsic will not generate any runtime checks, these must be done manually, when and where appropriate; but they do a complete static analysis of all indices, to avoid runtime buffer overflows, when possible. That means that at runtime, it is possible to do a buffer overflow when reading/writing, which is an "undefined behaviour" as to what will happen. ## Empty Array This PR also solves a problem with empty arrays. Before empty arrays such as `let a = []` were being type-checked as `[Never; 0]`, which means that any code after them was being marked as dead. Now we correctly type check them as `[Unknown; 0]` and return a more friendly error. ``` 4 | 5 | // Empty array 6 | let a = []; | ^^ Type must be known at this point 7 | } | ____ ``` ## Check of constants inside fns This PR also solves a problem with not checking `const` expressions inside `fns`. We, for example, do not allow slices in constants, but we were only checking globals. Now we check constants also inside functions, methods etc... ## Small improvements for our e2e We can now `dbg` inside our e2e harness and get results like the ones below. One needs to include the lib `test/src/e2e_vm_tests/utils` and cal `something.dbg()` or `something.dbgln()`. There is no magic, and structs/enums will need to manually implement the `Dbg` trait. This is only to facilitate the debugging of our e2e tests.  ## 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). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] 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. |
||
---|---|---|
.. | ||
src | ||
theme | ||
.gitignore | ||
book.toml | ||
README.md |
The Sway Reference
Setup
If you wish contribute to this reference: