Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead Code Analysis suspiciously slow (up to 28x slower than type_check) particularly for std #1952

Closed
mitchmindtree opened this issue Jun 13, 2022 · 8 comments · Fixed by #2159
Labels
ci compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request language server LSP server

Comments

@mitchmindtree
Copy link
Contributor

I've noticed the E2E tests and stdlib tests have been progressively getting slower and slower as we add new APIs to std.

This is particularly problematic for sway-lsp. @JoshuaBatty is in the process of updating sway-lsp to use compile_to_ast, however the current state of things (taking multiple seconds just for std) is unfeasible for the kind of feedback a user would normally expect in an IDE environment.

To work out what's going on, I added some basic time-stamping between all of the major compiler phases to see where most time was being spent. You can see the exact approach in this commit.

Here is the output of forc build --path examples/counter with forc built in debug:

$ cargo run --bin forc -- build --path examples/counter
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/forc build --path examples/counter`
Parsing: 1.06626ms
Type Check: 1.344043ms
Dead Code Analysis: 294.733µs
Return Path Analysis: 146.552µs
  Compiled library "core_utils".
Parsing: 12.502972ms
Type Check: 75.687842ms
Dead Code Analysis: 113.27732ms
Return Path Analysis: 4.030499ms
  Compiled library "core".
Parsing: 26.412109ms
Type Check: 159.818236ms
Dead Code Analysis: 4.463190539s
Return Path Analysis: 9.589824ms
  Compiled library "std".
Parsing: 566.406µs
Type Check: 861.018µs
Dead Code Analysis: 209.432µs
Return Path Analysis: 89.74µs
Finalize Types: 51.21µs
Compile IR: 1.146012ms
Purity Check: 16.96µs
Inline Fn Calls: 54.66µs
Combine Constants: 3.84µs
Compile ASM: 2.341203ms
  Compiled contract "counter".
  Bytecode size is 256 bytes.

Curiously, the Dead Code Analysis phase is taking vastly longer than everything else when compiling std: Dead Code Analysis: 4.463190539s.

Compiling forc in --release does run significantly faster:

$ forc build --path examples/counter
Parsing: 202.012µs
Type Check: 311.453µs
Dead Code Analysis: 32.1µs
Return Path Analysis: 20.86µs
  Compiled library "core_utils".
Parsing: 1.419324ms
Type Check: 8.038199ms
Dead Code Analysis: 10.101929ms
Return Path Analysis: 585.396µs
  Compiled library "core".
Parsing: 2.477274ms
Type Check: 20.874826ms
Dead Code Analysis: 215.495149ms
Return Path Analysis: 1.455874ms
  Compiled library "std".
Parsing: 79.69µs
Type Check: 139.272µs
Dead Code Analysis: 19.1µs
Return Path Analysis: 7.08µs
Finalize Types: 6.3µs
Compile IR: 123.721µs
Purity Check: 1.94µs
Inline Fn Calls: 5.301µs
Combine Constants: 410ns
Compile ASM: 220.282µs
  Compiled contract "counter".
  Bytecode size is 256 bytes.

However Dead Code Analysis still takes ~10x the type-check stage for std. It appears there might be an exponential blow-up the bigger the program/library.

It would be worth investigating this soon in order to speed up the debug build, cut down our CI times and improve responsiveness in the upcoming LSP update. It also looks like sway could get close to instantaneous / real-time build times in release mode which would be a nice impression to leave :)

cc @sezna I think I remember saying you had an idea of what might be causing this?

@mitchmindtree mitchmindtree added enhancement New feature or request compiler General compiler. Should eventually become more specific as the issue is triaged ci language server LSP server compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jun 13, 2022
@otrho
Copy link
Contributor

otrho commented Jun 13, 2022

Hrmm, maybe the mark-and-sweep GC idea I had might apply. Absolutely depends on what the actual problem is though.

@sezna
Copy link
Contributor

sezna commented Jun 13, 2022

We check certain nodes waaaay too many times due to the deterministic abortion check. If we can memoize that code, we will see a huge gain here. Maybe not enough, but hopefully?

The deterministic abortion check traverses all the way down into every ASM block and has no cache/memo. So the stdlib asm blocks are checked thousands of times for even the most basic of projects.

@mitchmindtree
Copy link
Contributor Author

mitchmindtree commented Jun 14, 2022

Ah nice, sounds like we might be able to get a major win with some easy fixes!

We check certain nodes waaaay too many times due to the deterministic abortion check.

Sounds like we might want to do something like the common graph traversal trick where you plumb through a visited: &mut HashSet<NodeIndex> to keep track of and skip already checked nodes? Maybe something along these lines anyway.

@otrho
Copy link
Contributor

otrho commented Jun 14, 2022

I thought the abort check was part of the type checking, rather than dead code analysis..?

if !typed_expression.deterministically_aborts() {

So that might reduced the type check numbers but not the control flow.

@otrho
Copy link
Contributor

otrho commented Jun 14, 2022

With my recent attributes stuff I tried to add flags to the nodes at creation time, since the deterministically aborts property and annotations are known from the start, but found it would be very invasive... would require a non-trivial refactor of the parse tree and/or typed AST.

We currently do the aborts check just as a part of the recursive conversion to typed AST, so we query nodes for that property as we go, and this is why we might query nodes multiple times. So to solve this in a recursive way we need to pass some extra context around with memos, either pre-populating it or growing it as we go like how most memoisation works.

So this would also be fairly invasive -- it's passing another data structure around to the type checker, though it could probably go in that type-check-arguments struct.

@mitchmindtree
Copy link
Contributor Author

So this would also be fairly invasive -- it's passing another data structure around to the type checker, though it could probably go in that type-check-arguments struct.

Sounds like this might be better addressed after the decl engine stuff then? Then it could possibly be done in a dedicated phase following type check?

@otrho
Copy link
Contributor

otrho commented Jun 14, 2022

No, the aborts check is a part of the type checking AFAICT -- I didn't write it, but I think it's needed to know whether it's OK for an expression to have the 'wrong' type because it doesn't return.

@sezna
Copy link
Contributor

sezna commented Jun 15, 2022

I've just double checked and you're right, it's in type checking. I could have sworn we had written a warning for unreachable code if a node deterministically aborts and there's additional nodes after it. I guess we should do that, too.

Well, then yeah, we may want to wait until at the very least the context work is in. I don't think we'd need the full engine for this? Also, FWIW, if graph construction and traversal does become an issue, that's also got a lot of low hanging optimization fruit.

mitchmindtree added a commit that referenced this issue Jun 29, 2022
While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.
mitchmindtree added a commit that referenced this issue Jun 29, 2022
While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.
Repository owner moved this from Todo to Done in Fuel Network Jun 29, 2022
mitchmindtree added a commit that referenced this issue Jun 29, 2022
Fix slow `find_dead_code` pass in control flow analysis

While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.
SwayStar123 added a commit that referenced this issue Jun 30, 2022
* Remove extra "the" (#2042)

looks like an extra "the" got into this comment

* Run `cargo update`. (#2045)

* sway-fmt-v2 adds program type to the output (#1997)

* Fix couple of bugs in handling returns in if blocks (#2029)

* Config driven E2E testing. (#2003)

Completely refactor E2E tests to be config driven.

Rather than specifying which tests are to be run and how, we now can
describe each test with a TOML file.

* Handle enums and their impls for item imports (#2034)

* Add `Identity` type to Sway Book (#2041)

* Add Identity type to Sway Book

* Move Identity code to examples directory

* Add Forc.lock to gitignore

* Update docs/src/basics/blockchain_types.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

* Add path to std in Forc.toml and update Forc.lock std source

* Run forc fmt again

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Improve struct patterns with new warnings and rest pattern support. (#2032)

* Improve struct patterns with new warnings and rest pattern support.

This commit improves a couple aspects of handling of struct patterns.

First of all, it adds semantic checking (with a new warning) when
patterns are missing usage of all fields:

```
error
  --> src/main.sw:15:9
   |
13 |
14 |     let z = match p {
15 |         Point { x } => { x },
   |         ^^^^^^^^^^^ Pattern does not mention field: y
16 |     };
   |
____
```

Then it adds support for rest pattern, "..", which can be used as the
last token in a pattern to not have to specify all the struct fields.

The semantic AST model was updated to support modeling this pattern,
and further type checking was added to the code.

There is also a new warning for when the rest pattern doesn't appear as
the last location, or when it appears multiple times:

```
error
  --> src/main.sw:17:20
   |
15 |
16 |     let z = match p {
17 |         Point { x, .., .. } => { x },
|                    ^^ Unexpected rest token, must be at the end of
pattern.
18 |     };
   |
____
```

And lastly, tests were added to cover the changes and new functionality.

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Add the concept of semantic similarity to the type system (#1958)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Some updates to the known issues section (#2060)

Updates to the known issues section

* Constants formatting for sway-fmt-v2 (#2021)

* Update the check for unresolved types. (#2057)

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

* Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Bump non-transitive `dashmap` to v5.3.4. (#2062)

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Adds `attribute` handling to `sway-fmt-v2` (#2061)

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

* Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004)

* Introduce a type check `Context`. Replaces `TypeCheckArguments`.

* Add missing unknown type annotation. Clean up some formatting.

Also adds some resetting of the help text and type annotation (to
unknown) in many cases to better match the original behaviour. It's
difficult to tell which locations these values were originally used as
placeholders, and which locations they're a necessity for correctness.
This at least appears to fix an issue with expression return type
inference.

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

This should help to clarify how we can pass other type check context
(like the declaration and type engines once they're added) through to
the submodules. Previously, this was a little unclear as the
`TypeCheckContext` was only constructed at the module level.

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

* Small fixes to the `storage_map` example (#2079)

Small fix to storage_map example

* Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074)

Move the stuff.

* Ensure lock is applied when `BuildPlan` validation would require changes (#2090)

Ensure lock is applied if BuildPlan validation requires changes

While reviewing #2085, I noticed that some recent additions to
`BuildPlan` validation could result in some changes to the build plan
(and in turn, rewriting the lock file) even in the case that `--locked`
was specified.

This moves the `--locked` check to the moment before writing the new
lock file. This ensures all potential changes that would be required of
the `BuildPlan` are caught. It also allows us to provide a "Cause" for
*why* the lock file would need updating when `--locked` is passed to
prevent it.

Closes #2084
Closes #2085

* Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Add `abi` handling to `sway-fmt-v2` (#2044)

* Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094)

Previously, if any of the `print` args were set, the rest of the
selected build profile was ignored. This changes the behaviour so that
the command line arguments only override their associated build profile
fields.

Also renames `BuildConfig` to `BuildProfile` and moves it from
`forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the
serializable manifest types.

* Update all the E2E should_fail tests to verify their output. (#2082)

Using the `FileCheck` crate it can now pattern match against the
compiler output to be sure the errors and/or warnings are exactly what
we expect.

* forc: Improve the `print_*_asm` CLI option docs (#2095)

Previously, these implied no bytecode was generated if the flag was not
set, however this is not the case.

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

* Adding `--time-phases` to `forc build` (#2091)

* make items under [project] ordered alphabetically in forc.toml

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* if let to match on program type

* Update forc/src/cli/commands/build.rs

updating bin-root filename

Co-authored-by: mitchmindtree <mail@mitchellnordine.com>

* added benchmarks for compilation process

* use macro instead of closure for wrapping parts of compilation process

Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: Toby Hutton <toby@grusly.com>

* Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836)

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

* Add struct formatting to sway-fmt-v2 (#2058)

* internal: Reduce amount of String::new() in sway-fmt-v2 (#2111)

* examples: fix renaming to BASE_ASSET_ID in comment (#2120)

* Added storage field alignment threshold to formatter config (#2113)

* Enable storage initializers and emit a storage initialization JSON (#2078)

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

* lint, change initializers -> slots, and fixing some tests

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

* Test the storage slots JSON in e2e tests and add forc json-storage-slots command

* ignore *_output.json

* forc documenter changes

* Remove forc json-storage-slots and stop relying on forc json-abi

* Enhance some comments

* Remove unnecessary oracle

* Improve reserved keywords checking and add support for raw identifiers. (#2066)

Add support for raw identifiers and improve reserved keywords checking.

This commit deals with the usage and checking of reserved keywords
as identifiers, for code like:

```
fn main() {
    let mut mut = 0;
}

It introduces a new error that checks if an identifier is a reserved
keyword:

```
error
 --> /main.sw:4:13
  |
2 |
3 | fn main() {
4 |     let mut mut = 0;
  |             ^^^ Identifiers cannot be a reserved keyword.
5 | }
  |
____
```

There was an existing issue in the standard library, which
has a library/module named `storage`.

Instead of working around this by renaming it to something else,
an alternative solution with raw identifiers is implemented.

This raw identifier feature is implemented at the lexer level,
and allows you to use keywords as identifiers in places that
generally wouldn't be allowed.

Rust and a bunch of other modern languages also provide this escape
hatch, and it seemed the simplest solution for me to handle the issue.

It activates by declaring an identifier prefixed with `r#`, just like
Rust.

The complexity on the codebase to support this feature is pretty
minimal, but if there any objections to this, I can easily remove it,
but some other solution to the issue above will need to be figured out.

Closes #1996.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* remove `fuels-abigen-macro` dependency (#2007)

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Adds `Generics` handling to `sway-fmt-v2` (#2110)

* #2020 - changed BASE_ASSET_ID type to ContractId (#2137)

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

* #2039 - add storage keyword highlighting in book (#2141)

* #2039 - add storage keyword highlighting in book

* Changes after review

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

* feat: add impl U256 max, min, bits, new

* test: add new test assertions

* style: fmt

* test: generate oracle file

* Update sway-lib-std/src/u256.sw

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

* Revert "fix: remove #r prefix from storage lib"

This reverts commit 8dd0738.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097)

* Move monomorphization conceptually inside of the type engine (#2093)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

* `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136)

`forc-pkg` - Don't add transitive deps (besides `core`) to namespace

Currently `forc-pkg` adds all transitive dependencies to a package's
initial namespace prior to its compilation. This had the benefit of
implicitly including `core`, but with the downside of implicitly
including every other transitive dependency package, even if not a
direct depednency (not what we want).

This PR changes the behaviour to only include direct dependencies and
`core` within a package's initial namespace.

Addresses 1, 2 of #2125.

* Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132)

The bug is fixed.

* Remove unnecessary "core" str check in `Span::join` (#2156)

* Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160)

* Remove duplicate CI checks that already have dedicated jobs (#2161)

I noticed a bunch of our CI jobs were were duplicating existing checks.
In particular, there was a lot of copy-paste steps of installing forc
and the forc-fmt plugin, even when unused in the following checks.

This doesn't improve the real bottleneck (our stdlib test job), but it's
a start.

* Speedup `find_dead_code` pass in control flow analysis (#2159)

Fix slow `find_dead_code` pass in control flow analysis

While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Update broken link for contributing to Sway in README.md (#2172)

Closes #2171

* Backport improvements to `U128` type. (#2169)

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

* Lower to `Instruction::Cmp` instead of to assembly in IRGen

* Refactor intrinsics to all have arg and type arg vectors

* Improvements around `forc plugins` command (#1969)

Use the full path of the plugin when parsing it for a description.

This avoids the following panic caused by trying to exec an executable
in a sub-folder with a partial path:

```
~/dev/sway/target/debug$ forc plugins
Installed Plugins:
thread 'main' panicked at 'Could not get plugin description.: Os { code:
2, kind: NotFound, message: "No such file or directory" }',
forc/src/cli/commands/plugins.rs:43:10
stack backtrace:
   0: rust_begin_unwind
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: forc::cli::commands::plugins::parse_description_for_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16
   5: forc::cli::commands::plugins::format_print_description
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23
   6: forc::cli::commands::plugins::print_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5
   7: forc::cli::commands::plugins::exec
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21
```

* Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153)

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

* Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123)

* Add `CommentedTokenStream` to `sway_parse`

This doesn't yet collect any comments, but adds the necessary structure
and attempts to preserve the original API and behaviour where possible.

Collecting of comments to be added in a follow-up commit.

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

* Add Spanned impl for CommentedTokenTree. Add comment lexing test.

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>

* Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181)

Remove unused const_decl_origin from TypedVariableDeclaration

After #2158, constant declartaions use TypedConstantDeclaration
AST node, and hence this field is now useless. It must have been
removed in #2158 itself, but I missed doing that.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: bing <binggh@proton.me>
Co-authored-by: seem-less <mgirach@gmail.com>
Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: zhou fan <1247714429@qq.com>
Co-authored-by: Hlib Kanunnikov <hlibwondertan@gmail.com>
Co-authored-by: Emir <emirsalkicart@gmail.com>
Co-authored-by: r-sitko <19492095+r-sitko@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
SwayStar123 added a commit that referenced this issue Jun 30, 2022
* Remove extra "the" (#2042)

looks like an extra "the" got into this comment

* Run `cargo update`. (#2045)

* sway-fmt-v2 adds program type to the output (#1997)

* Fix couple of bugs in handling returns in if blocks (#2029)

* Config driven E2E testing. (#2003)

Completely refactor E2E tests to be config driven.

Rather than specifying which tests are to be run and how, we now can
describe each test with a TOML file.

* Handle enums and their impls for item imports (#2034)

* Add `Identity` type to Sway Book (#2041)

* Add Identity type to Sway Book

* Move Identity code to examples directory

* Add Forc.lock to gitignore

* Update docs/src/basics/blockchain_types.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

* Add path to std in Forc.toml and update Forc.lock std source

* Run forc fmt again

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Improve struct patterns with new warnings and rest pattern support. (#2032)

* Improve struct patterns with new warnings and rest pattern support.

This commit improves a couple aspects of handling of struct patterns.

First of all, it adds semantic checking (with a new warning) when
patterns are missing usage of all fields:

```
error
  --> src/main.sw:15:9
   |
13 |
14 |     let z = match p {
15 |         Point { x } => { x },
   |         ^^^^^^^^^^^ Pattern does not mention field: y
16 |     };
   |
____
```

Then it adds support for rest pattern, "..", which can be used as the
last token in a pattern to not have to specify all the struct fields.

The semantic AST model was updated to support modeling this pattern,
and further type checking was added to the code.

There is also a new warning for when the rest pattern doesn't appear as
the last location, or when it appears multiple times:

```
error
  --> src/main.sw:17:20
   |
15 |
16 |     let z = match p {
17 |         Point { x, .., .. } => { x },
|                    ^^ Unexpected rest token, must be at the end of
pattern.
18 |     };
   |
____
```

And lastly, tests were added to cover the changes and new functionality.

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Add the concept of semantic similarity to the type system (#1958)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Some updates to the known issues section (#2060)

Updates to the known issues section

* Constants formatting for sway-fmt-v2 (#2021)

* Update the check for unresolved types. (#2057)

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

* Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Bump non-transitive `dashmap` to v5.3.4. (#2062)

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Adds `attribute` handling to `sway-fmt-v2` (#2061)

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

* Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004)

* Introduce a type check `Context`. Replaces `TypeCheckArguments`.

* Add missing unknown type annotation. Clean up some formatting.

Also adds some resetting of the help text and type annotation (to
unknown) in many cases to better match the original behaviour. It's
difficult to tell which locations these values were originally used as
placeholders, and which locations they're a necessity for correctness.
This at least appears to fix an issue with expression return type
inference.

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

This should help to clarify how we can pass other type check context
(like the declaration and type engines once they're added) through to
the submodules. Previously, this was a little unclear as the
`TypeCheckContext` was only constructed at the module level.

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

* Small fixes to the `storage_map` example (#2079)

Small fix to storage_map example

* Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074)

Move the stuff.

* Ensure lock is applied when `BuildPlan` validation would require changes (#2090)

Ensure lock is applied if BuildPlan validation requires changes

While reviewing #2085, I noticed that some recent additions to
`BuildPlan` validation could result in some changes to the build plan
(and in turn, rewriting the lock file) even in the case that `--locked`
was specified.

This moves the `--locked` check to the moment before writing the new
lock file. This ensures all potential changes that would be required of
the `BuildPlan` are caught. It also allows us to provide a "Cause" for
*why* the lock file would need updating when `--locked` is passed to
prevent it.

Closes #2084
Closes #2085

* Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Add `abi` handling to `sway-fmt-v2` (#2044)

* Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094)

Previously, if any of the `print` args were set, the rest of the
selected build profile was ignored. This changes the behaviour so that
the command line arguments only override their associated build profile
fields.

Also renames `BuildConfig` to `BuildProfile` and moves it from
`forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the
serializable manifest types.

* Update all the E2E should_fail tests to verify their output. (#2082)

Using the `FileCheck` crate it can now pattern match against the
compiler output to be sure the errors and/or warnings are exactly what
we expect.

* forc: Improve the `print_*_asm` CLI option docs (#2095)

Previously, these implied no bytecode was generated if the flag was not
set, however this is not the case.

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

* Adding `--time-phases` to `forc build` (#2091)

* make items under [project] ordered alphabetically in forc.toml

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* if let to match on program type

* Update forc/src/cli/commands/build.rs

updating bin-root filename

Co-authored-by: mitchmindtree <mail@mitchellnordine.com>

* added benchmarks for compilation process

* use macro instead of closure for wrapping parts of compilation process

Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: Toby Hutton <toby@grusly.com>

* Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836)

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

* Add struct formatting to sway-fmt-v2 (#2058)

* internal: Reduce amount of String::new() in sway-fmt-v2 (#2111)

* examples: fix renaming to BASE_ASSET_ID in comment (#2120)

* Added storage field alignment threshold to formatter config (#2113)

* Enable storage initializers and emit a storage initialization JSON (#2078)

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

* lint, change initializers -> slots, and fixing some tests

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

* Test the storage slots JSON in e2e tests and add forc json-storage-slots command

* ignore *_output.json

* forc documenter changes

* Remove forc json-storage-slots and stop relying on forc json-abi

* Enhance some comments

* Remove unnecessary oracle

* Improve reserved keywords checking and add support for raw identifiers. (#2066)

Add support for raw identifiers and improve reserved keywords checking.

This commit deals with the usage and checking of reserved keywords
as identifiers, for code like:

```
fn main() {
    let mut mut = 0;
}

It introduces a new error that checks if an identifier is a reserved
keyword:

```
error
 --> /main.sw:4:13
  |
2 |
3 | fn main() {
4 |     let mut mut = 0;
  |             ^^^ Identifiers cannot be a reserved keyword.
5 | }
  |
____
```

There was an existing issue in the standard library, which
has a library/module named `storage`.

Instead of working around this by renaming it to something else,
an alternative solution with raw identifiers is implemented.

This raw identifier feature is implemented at the lexer level,
and allows you to use keywords as identifiers in places that
generally wouldn't be allowed.

Rust and a bunch of other modern languages also provide this escape
hatch, and it seemed the simplest solution for me to handle the issue.

It activates by declaring an identifier prefixed with `r#`, just like
Rust.

The complexity on the codebase to support this feature is pretty
minimal, but if there any objections to this, I can easily remove it,
but some other solution to the issue above will need to be figured out.

Closes #1996.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* remove `fuels-abigen-macro` dependency (#2007)

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Adds `Generics` handling to `sway-fmt-v2` (#2110)

* #2020 - changed BASE_ASSET_ID type to ContractId (#2137)

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

* #2039 - add storage keyword highlighting in book (#2141)

* #2039 - add storage keyword highlighting in book

* Changes after review

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

* feat: add impl U256 max, min, bits, new

* test: add new test assertions

* style: fmt

* test: generate oracle file

* Update sway-lib-std/src/u256.sw

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

* Revert "fix: remove #r prefix from storage lib"

This reverts commit 8dd0738.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097)

* Move monomorphization conceptually inside of the type engine (#2093)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

* `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136)

`forc-pkg` - Don't add transitive deps (besides `core`) to namespace

Currently `forc-pkg` adds all transitive dependencies to a package's
initial namespace prior to its compilation. This had the benefit of
implicitly including `core`, but with the downside of implicitly
including every other transitive dependency package, even if not a
direct depednency (not what we want).

This PR changes the behaviour to only include direct dependencies and
`core` within a package's initial namespace.

Addresses 1, 2 of #2125.

* Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132)

The bug is fixed.

* Remove unnecessary "core" str check in `Span::join` (#2156)

* Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160)

* Remove duplicate CI checks that already have dedicated jobs (#2161)

I noticed a bunch of our CI jobs were were duplicating existing checks.
In particular, there was a lot of copy-paste steps of installing forc
and the forc-fmt plugin, even when unused in the following checks.

This doesn't improve the real bottleneck (our stdlib test job), but it's
a start.

* Speedup `find_dead_code` pass in control flow analysis (#2159)

Fix slow `find_dead_code` pass in control flow analysis

While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Update broken link for contributing to Sway in README.md (#2172)

Closes #2171

* Backport improvements to `U128` type. (#2169)

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

* Lower to `Instruction::Cmp` instead of to assembly in IRGen

* Refactor intrinsics to all have arg and type arg vectors

* Improvements around `forc plugins` command (#1969)

Use the full path of the plugin when parsing it for a description.

This avoids the following panic caused by trying to exec an executable
in a sub-folder with a partial path:

```
~/dev/sway/target/debug$ forc plugins
Installed Plugins:
thread 'main' panicked at 'Could not get plugin description.: Os { code:
2, kind: NotFound, message: "No such file or directory" }',
forc/src/cli/commands/plugins.rs:43:10
stack backtrace:
   0: rust_begin_unwind
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: forc::cli::commands::plugins::parse_description_for_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16
   5: forc::cli::commands::plugins::format_print_description
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23
   6: forc::cli::commands::plugins::print_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5
   7: forc::cli::commands::plugins::exec
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21
```

* Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153)

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

* Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123)

* Add `CommentedTokenStream` to `sway_parse`

This doesn't yet collect any comments, but adds the necessary structure
and attempts to preserve the original API and behaviour where possible.

Collecting of comments to be added in a follow-up commit.

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

* Add Spanned impl for CommentedTokenTree. Add comment lexing test.

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>

* Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181)

Remove unused const_decl_origin from TypedVariableDeclaration

After #2158, constant declartaions use TypedConstantDeclaration
AST node, and hence this field is now useless. It must have been
removed in #2158 itself, but I missed doing that.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: bing <binggh@proton.me>
Co-authored-by: seem-less <mgirach@gmail.com>
Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: zhou fan <1247714429@qq.com>
Co-authored-by: Hlib Kanunnikov <hlibwondertan@gmail.com>
Co-authored-by: Emir <emirsalkicart@gmail.com>
Co-authored-by: r-sitko <19492095+r-sitko@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
SwayStar123 added a commit that referenced this issue Jul 14, 2022
* Initial commit - storagevec

* added an error and comments and documentation

* fixed the order of the Result types

* added suggested functions

* removed unncessary code

* renamed remove_index

* added swap remove and removed unncessary annotations

* moved storage_vec to storage and started on tests

* built some of the contract -- WIP

* made it so swap_remove returns the removed element

* removed extra ) and added all the test functions

* fixed a syntax error

* changed store to storage

* removed all other types for now

* made storagevecerror public

* removed unncessary code to streamline bugfixing

* fixed annotations

* made all the test contracts

* changed build.sh to include all the storage_vec projs

* updated fuels version

* unwrapped all results and options in the contract

* reduced fuels version

* merge master to storage_vec branch (#2183)

* Remove extra "the" (#2042)

looks like an extra "the" got into this comment

* Run `cargo update`. (#2045)

* sway-fmt-v2 adds program type to the output (#1997)

* Fix couple of bugs in handling returns in if blocks (#2029)

* Config driven E2E testing. (#2003)

Completely refactor E2E tests to be config driven.

Rather than specifying which tests are to be run and how, we now can
describe each test with a TOML file.

* Handle enums and their impls for item imports (#2034)

* Add `Identity` type to Sway Book (#2041)

* Add Identity type to Sway Book

* Move Identity code to examples directory

* Add Forc.lock to gitignore

* Update docs/src/basics/blockchain_types.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

* Add path to std in Forc.toml and update Forc.lock std source

* Run forc fmt again

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Improve struct patterns with new warnings and rest pattern support. (#2032)

* Improve struct patterns with new warnings and rest pattern support.

This commit improves a couple aspects of handling of struct patterns.

First of all, it adds semantic checking (with a new warning) when
patterns are missing usage of all fields:

```
error
  --> src/main.sw:15:9
   |
13 |
14 |     let z = match p {
15 |         Point { x } => { x },
   |         ^^^^^^^^^^^ Pattern does not mention field: y
16 |     };
   |
____
```

Then it adds support for rest pattern, "..", which can be used as the
last token in a pattern to not have to specify all the struct fields.

The semantic AST model was updated to support modeling this pattern,
and further type checking was added to the code.

There is also a new warning for when the rest pattern doesn't appear as
the last location, or when it appears multiple times:

```
error
  --> src/main.sw:17:20
   |
15 |
16 |     let z = match p {
17 |         Point { x, .., .. } => { x },
|                    ^^ Unexpected rest token, must be at the end of
pattern.
18 |     };
   |
____
```

And lastly, tests were added to cover the changes and new functionality.

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Add the concept of semantic similarity to the type system (#1958)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Some updates to the known issues section (#2060)

Updates to the known issues section

* Constants formatting for sway-fmt-v2 (#2021)

* Update the check for unresolved types. (#2057)

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

* Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Bump non-transitive `dashmap` to v5.3.4. (#2062)

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Adds `attribute` handling to `sway-fmt-v2` (#2061)

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

* Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004)

* Introduce a type check `Context`. Replaces `TypeCheckArguments`.

* Add missing unknown type annotation. Clean up some formatting.

Also adds some resetting of the help text and type annotation (to
unknown) in many cases to better match the original behaviour. It's
difficult to tell which locations these values were originally used as
placeholders, and which locations they're a necessity for correctness.
This at least appears to fix an issue with expression return type
inference.

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

This should help to clarify how we can pass other type check context
(like the declaration and type engines once they're added) through to
the submodules. Previously, this was a little unclear as the
`TypeCheckContext` was only constructed at the module level.

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

* Small fixes to the `storage_map` example (#2079)

Small fix to storage_map example

* Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074)

Move the stuff.

* Ensure lock is applied when `BuildPlan` validation would require changes (#2090)

Ensure lock is applied if BuildPlan validation requires changes

While reviewing #2085, I noticed that some recent additions to
`BuildPlan` validation could result in some changes to the build plan
(and in turn, rewriting the lock file) even in the case that `--locked`
was specified.

This moves the `--locked` check to the moment before writing the new
lock file. This ensures all potential changes that would be required of
the `BuildPlan` are caught. It also allows us to provide a "Cause" for
*why* the lock file would need updating when `--locked` is passed to
prevent it.

Closes #2084
Closes #2085

* Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Add `abi` handling to `sway-fmt-v2` (#2044)

* Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094)

Previously, if any of the `print` args were set, the rest of the
selected build profile was ignored. This changes the behaviour so that
the command line arguments only override their associated build profile
fields.

Also renames `BuildConfig` to `BuildProfile` and moves it from
`forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the
serializable manifest types.

* Update all the E2E should_fail tests to verify their output. (#2082)

Using the `FileCheck` crate it can now pattern match against the
compiler output to be sure the errors and/or warnings are exactly what
we expect.

* forc: Improve the `print_*_asm` CLI option docs (#2095)

Previously, these implied no bytecode was generated if the flag was not
set, however this is not the case.

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

* Adding `--time-phases` to `forc build` (#2091)

* make items under [project] ordered alphabetically in forc.toml

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* if let to match on program type

* Update forc/src/cli/commands/build.rs

updating bin-root filename

Co-authored-by: mitchmindtree <mail@mitchellnordine.com>

* added benchmarks for compilation process

* use macro instead of closure for wrapping parts of compilation process

Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: Toby Hutton <toby@grusly.com>

* Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836)

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

* Add struct formatting to sway-fmt-v2 (#2058)

* internal: Reduce amount of String::new() in sway-fmt-v2 (#2111)

* examples: fix renaming to BASE_ASSET_ID in comment (#2120)

* Added storage field alignment threshold to formatter config (#2113)

* Enable storage initializers and emit a storage initialization JSON (#2078)

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

* lint, change initializers -> slots, and fixing some tests

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

* Test the storage slots JSON in e2e tests and add forc json-storage-slots command

* ignore *_output.json

* forc documenter changes

* Remove forc json-storage-slots and stop relying on forc json-abi

* Enhance some comments

* Remove unnecessary oracle

* Improve reserved keywords checking and add support for raw identifiers. (#2066)

Add support for raw identifiers and improve reserved keywords checking.

This commit deals with the usage and checking of reserved keywords
as identifiers, for code like:

```
fn main() {
    let mut mut = 0;
}

It introduces a new error that checks if an identifier is a reserved
keyword:

```
error
 --> /main.sw:4:13
  |
2 |
3 | fn main() {
4 |     let mut mut = 0;
  |             ^^^ Identifiers cannot be a reserved keyword.
5 | }
  |
____
```

There was an existing issue in the standard library, which
has a library/module named `storage`.

Instead of working around this by renaming it to something else,
an alternative solution with raw identifiers is implemented.

This raw identifier feature is implemented at the lexer level,
and allows you to use keywords as identifiers in places that
generally wouldn't be allowed.

Rust and a bunch of other modern languages also provide this escape
hatch, and it seemed the simplest solution for me to handle the issue.

It activates by declaring an identifier prefixed with `r#`, just like
Rust.

The complexity on the codebase to support this feature is pretty
minimal, but if there any objections to this, I can easily remove it,
but some other solution to the issue above will need to be figured out.

Closes #1996.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* remove `fuels-abigen-macro` dependency (#2007)

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Adds `Generics` handling to `sway-fmt-v2` (#2110)

* #2020 - changed BASE_ASSET_ID type to ContractId (#2137)

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

* #2039 - add storage keyword highlighting in book (#2141)

* #2039 - add storage keyword highlighting in book

* Changes after review

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

* feat: add impl U256 max, min, bits, new

* test: add new test assertions

* style: fmt

* test: generate oracle file

* Update sway-lib-std/src/u256.sw

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

* Revert "fix: remove #r prefix from storage lib"

This reverts commit 8dd0738.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097)

* Move monomorphization conceptually inside of the type engine (#2093)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

* `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136)

`forc-pkg` - Don't add transitive deps (besides `core`) to namespace

Currently `forc-pkg` adds all transitive dependencies to a package's
initial namespace prior to its compilation. This had the benefit of
implicitly including `core`, but with the downside of implicitly
including every other transitive dependency package, even if not a
direct depednency (not what we want).

This PR changes the behaviour to only include direct dependencies and
`core` within a package's initial namespace.

Addresses 1, 2 of #2125.

* Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132)

The bug is fixed.

* Remove unnecessary "core" str check in `Span::join` (#2156)

* Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160)

* Remove duplicate CI checks that already have dedicated jobs (#2161)

I noticed a bunch of our CI jobs were were duplicating existing checks.
In particular, there was a lot of copy-paste steps of installing forc
and the forc-fmt plugin, even when unused in the following checks.

This doesn't improve the real bottleneck (our stdlib test job), but it's
a start.

* Speedup `find_dead_code` pass in control flow analysis (#2159)

Fix slow `find_dead_code` pass in control flow analysis

While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Update broken link for contributing to Sway in README.md (#2172)

Closes #2171

* Backport improvements to `U128` type. (#2169)

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

* Lower to `Instruction::Cmp` instead of to assembly in IRGen

* Refactor intrinsics to all have arg and type arg vectors

* Improvements around `forc plugins` command (#1969)

Use the full path of the plugin when parsing it for a description.

This avoids the following panic caused by trying to exec an executable
in a sub-folder with a partial path:

```
~/dev/sway/target/debug$ forc plugins
Installed Plugins:
thread 'main' panicked at 'Could not get plugin description.: Os { code:
2, kind: NotFound, message: "No such file or directory" }',
forc/src/cli/commands/plugins.rs:43:10
stack backtrace:
   0: rust_begin_unwind
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: forc::cli::commands::plugins::parse_description_for_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16
   5: forc::cli::commands::plugins::format_print_description
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23
   6: forc::cli::commands::plugins::print_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5
   7: forc::cli::commands::plugins::exec
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21
```

* Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153)

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

* Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123)

* Add `CommentedTokenStream` to `sway_parse`

This doesn't yet collect any comments, but adds the necessary structure
and attempts to preserve the original API and behaviour where possible.

Collecting of comments to be added in a follow-up commit.

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

* Add Spanned impl for CommentedTokenTree. Add comment lexing test.

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>

* Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181)

Remove unused const_decl_origin from TypedVariableDeclaration

After #2158, constant declartaions use TypedConstantDeclaration
AST node, and hence this field is now useless. It must have been
removed in #2158 itself, but I missed doing that.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: bing <binggh@proton.me>
Co-authored-by: seem-less <mgirach@gmail.com>
Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: zhou fan <1247714429@qq.com>
Co-authored-by: Hlib Kanunnikov <hlibwondertan@gmail.com>
Co-authored-by: Emir <emirsalkicart@gmail.com>
Co-authored-by: r-sitko <19492095+r-sitko@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>

* merge master to storage_vec (#2184)

* Remove extra "the" (#2042)

looks like an extra "the" got into this comment

* Run `cargo update`. (#2045)

* sway-fmt-v2 adds program type to the output (#1997)

* Fix couple of bugs in handling returns in if blocks (#2029)

* Config driven E2E testing. (#2003)

Completely refactor E2E tests to be config driven.

Rather than specifying which tests are to be run and how, we now can
describe each test with a TOML file.

* Handle enums and their impls for item imports (#2034)

* Add `Identity` type to Sway Book (#2041)

* Add Identity type to Sway Book

* Move Identity code to examples directory

* Add Forc.lock to gitignore

* Update docs/src/basics/blockchain_types.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

* Add path to std in Forc.toml and update Forc.lock std source

* Run forc fmt again

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Improve struct patterns with new warnings and rest pattern support. (#2032)

* Improve struct patterns with new warnings and rest pattern support.

This commit improves a couple aspects of handling of struct patterns.

First of all, it adds semantic checking (with a new warning) when
patterns are missing usage of all fields:

```
error
  --> src/main.sw:15:9
   |
13 |
14 |     let z = match p {
15 |         Point { x } => { x },
   |         ^^^^^^^^^^^ Pattern does not mention field: y
16 |     };
   |
____
```

Then it adds support for rest pattern, "..", which can be used as the
last token in a pattern to not have to specify all the struct fields.

The semantic AST model was updated to support modeling this pattern,
and further type checking was added to the code.

There is also a new warning for when the rest pattern doesn't appear as
the last location, or when it appears multiple times:

```
error
  --> src/main.sw:17:20
   |
15 |
16 |     let z = match p {
17 |         Point { x, .., .. } => { x },
|                    ^^ Unexpected rest token, must be at the end of
pattern.
18 |     };
   |
____
```

And lastly, tests were added to cover the changes and new functionality.

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Add the concept of semantic similarity to the type system (#1958)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Some updates to the known issues section (#2060)

Updates to the known issues section

* Constants formatting for sway-fmt-v2 (#2021)

* Update the check for unresolved types. (#2057)

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

* Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Bump non-transitive `dashmap` to v5.3.4. (#2062)

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Adds `attribute` handling to `sway-fmt-v2` (#2061)

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

* Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004)

* Introduce a type check `Context`. Replaces `TypeCheckArguments`.

* Add missing unknown type annotation. Clean up some formatting.

Also adds some resetting of the help text and type annotation (to
unknown) in many cases to better match the original behaviour. It's
difficult to tell which locations these values were originally used as
placeholders, and which locations they're a necessity for correctness.
This at least appears to fix an issue with expression return type
inference.

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

This should help to clarify how we can pass other type check context
(like the declaration and type engines once they're added) through to
the submodules. Previously, this was a little unclear as the
`TypeCheckContext` was only constructed at the module level.

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

* Small fixes to the `storage_map` example (#2079)

Small fix to storage_map example

* Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074)

Move the stuff.

* Ensure lock is applied when `BuildPlan` validation would require changes (#2090)

Ensure lock is applied if BuildPlan validation requires changes

While reviewing #2085, I noticed that some recent additions to
`BuildPlan` validation could result in some changes to the build plan
(and in turn, rewriting the lock file) even in the case that `--locked`
was specified.

This moves the `--locked` check to the moment before writing the new
lock file. This ensures all potential changes that would be required of
the `BuildPlan` are caught. It also allows us to provide a "Cause" for
*why* the lock file would need updating when `--locked` is passed to
prevent it.

Closes #2084
Closes #2085

* Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Add `abi` handling to `sway-fmt-v2` (#2044)

* Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094)

Previously, if any of the `print` args were set, the rest of the
selected build profile was ignored. This changes the behaviour so that
the command line arguments only override their associated build profile
fields.

Also renames `BuildConfig` to `BuildProfile` and moves it from
`forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the
serializable manifest types.

* Update all the E2E should_fail tests to verify their output. (#2082)

Using the `FileCheck` crate it can now pattern match against the
compiler output to be sure the errors and/or warnings are exactly what
we expect.

* forc: Improve the `print_*_asm` CLI option docs (#2095)

Previously, these implied no bytecode was generated if the flag was not
set, however this is not the case.

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

* Adding `--time-phases` to `forc build` (#2091)

* make items under [project] ordered alphabetically in forc.toml

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* if let to match on program type

* Update forc/src/cli/commands/build.rs

updating bin-root filename

Co-authored-by: mitchmindtree <mail@mitchellnordine.com>

* added benchmarks for compilation process

* use macro instead of closure for wrapping parts of compilation process

Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: Toby Hutton <toby@grusly.com>

* Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836)

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

* Add struct formatting to sway-fmt-v2 (#2058)

* internal: Reduce amount of String::new() in sway-fmt-v2 (#2111)

* examples: fix renaming to BASE_ASSET_ID in comment (#2120)

* Added storage field alignment threshold to formatter config (#2113)

* Enable storage initializers and emit a storage initialization JSON (#2078)

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

* lint, change initializers -> slots, and fixing some tests

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

* Test the storage slots JSON in e2e tests and add forc json-storage-slots command

* ignore *_output.json

* forc documenter changes

* Remove forc json-storage-slots and stop relying on forc json-abi

* Enhance some comments

* Remove unnecessary oracle

* Improve reserved keywords checking and add support for raw identifiers. (#2066)

Add support for raw identifiers and improve reserved keywords checking.

This commit deals with the usage and checking of reserved keywords
as identifiers, for code like:

```
fn main() {
    let mut mut = 0;
}

It introduces a new error that checks if an identifier is a reserved
keyword:

```
error
 --> /main.sw:4:13
  |
2 |
3 | fn main() {
4 |     let mut mut = 0;
  |             ^^^ Identifiers cannot be a reserved keyword.
5 | }
  |
____
```

There was an existing issue in the standard library, which
has a library/module named `storage`.

Instead of working around this by renaming it to something else,
an alternative solution with raw identifiers is implemented.

This raw identifier feature is implemented at the lexer level,
and allows you to use keywords as identifiers in places that
generally wouldn't be allowed.

Rust and a bunch of other modern languages also provide this escape
hatch, and it seemed the simplest solution for me to handle the issue.

It activates by declaring an identifier prefixed with `r#`, just like
Rust.

The complexity on the codebase to support this feature is pretty
minimal, but if there any objections to this, I can easily remove it,
but some other solution to the issue above will need to be figured out.

Closes #1996.

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* remove `fuels-abigen-macro` dependency (#2007)

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update test/src/sdk-harness/Cargo.toml

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Adds `Generics` handling to `sway-fmt-v2` (#2110)

* #2020 - changed BASE_ASSET_ID type to ContractId (#2137)

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

* #2039 - add storage keyword highlighting in book (#2141)

* #2039 - add storage keyword highlighting in book

* Changes after review

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

* feat: add impl U256 max, min, bits, new

* test: add new test assertions

* style: fmt

* test: generate oracle file

* Update sway-lib-std/src/u256.sw

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

* Revert "fix: remove #r prefix from storage lib"

This reverts commit 8dd0738.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097)

* Move monomorphization conceptually inside of the type engine (#2093)

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

* Add conceptual distinction between replacing TypeInfo::Self and monomorphization.

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

* `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136)

`forc-pkg` - Don't add transitive deps (besides `core`) to namespace

Currently `forc-pkg` adds all transitive dependencies to a package's
initial namespace prior to its compilation. This had the benefit of
implicitly including `core`, but with the downside of implicitly
including every other transitive dependency package, even if not a
direct depednency (not what we want).

This PR changes the behaviour to only include direct dependencies and
`core` within a package's initial namespace.

Addresses 1, 2 of #2125.

* Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132)

The bug is fixed.

* Remove unnecessary "core" str check in `Span::join` (#2156)

* Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160)

* Remove duplicate CI checks that already have dedicated jobs (#2161)

I noticed a bunch of our CI jobs were were duplicating existing checks.
In particular, there was a lot of copy-paste steps of installing forc
and the forc-fmt plugin, even when unused in the following checks.

This doesn't improve the real bottleneck (our stdlib test job), but it's
a start.

* Speedup `find_dead_code` pass in control flow analysis (#2159)

Fix slow `find_dead_code` pass in control flow analysis

While waiting for the tests to pass on a PR I thought I'd have a quick
look to see if I could find any quick wins for dead code analysis #1952.

I noticed that that we're using `has_path_connecting` for every
combination of node and entry point. This means we were re-checking the
same nodes many, many times, searching from scratch each time and not
re-using any of the knowledge of already visited nodes in each
consecutive traversal.

This commit refactors the approach to first collect all known live nodes
into a set by traversing from the entry points. We re-use the same `Dfs`
when searching from each entry in order to re-use its inner set of
visited nodes and avoid re-searching sections of the graph that we've
already visited.

The dead nodes are those not contained in the live set after traversal.

This reduces the time taken within the `find_dead_code` call when
building the `std` library in debug from ~7.9 seconds down to ~3.3
milliseconds. 1000x+ speedup in DCA :)

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>

* Update broken link for contributing to Sway in README.md (#2172)

Closes #2171

* Backport improvements to `U128` type. (#2169)

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

* Lower to `Instruction::Cmp` instead of to assembly in IRGen

* Refactor intrinsics to all have arg and type arg vectors

* Improvements around `forc plugins` command (#1969)

Use the full path of the plugin when parsing it for a description.

This avoids the following panic caused by trying to exec an executable
in a sub-folder with a partial path:

```
~/dev/sway/target/debug$ forc plugins
Installed Plugins:
thread 'main' panicked at 'Could not get plugin description.: Os { code:
2, kind: NotFound, message: "No such file or directory" }',
forc/src/cli/commands/plugins.rs:43:10
stack backtrace:
   0: rust_begin_unwind
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: forc::cli::commands::plugins::parse_description_for_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16
   5: forc::cli::commands::plugins::format_print_description
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23
   6: forc::cli::commands::plugins::print_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5
   7: forc::cli::commands::plugins::exec
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21
```

* Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153)

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

* Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123)

* Add `CommentedTokenStream` to `sway_parse`

This doesn't yet collect any comments, but adds the necessary structure
and attempts to preserve the original API and behaviour where possible.

Collecting of comments to be added in a follow-up commit.

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

* Add Spanned impl for CommentedTokenTree. Add comment lexing test.

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>

* Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181)

Remove unused const_decl_origin from TypedVariableDeclaration

After #2158, constant declartaions use TypedConstantDeclaration
AST node, and hence this field is now useless. It must have been
removed in #2158 itself, but I missed doing that.

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: bing <binggh@proton.me>
Co-authored-by: seem-less <mgirach@gmail.com>
Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: zhou fan <1247714429@qq.com>
Co-authored-by: Hlib Kanunnikov <hlibwondertan@gmail.com>
Co-authored-by: Emir <emirsalkicart@gmail.com>
Co-authored-by: r-sitko <19492095+r-sitko@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>

* removed unncessary use

* added one test

* deleted all contracts except u8s

* fixed bug in pop

* failing test for some reason

* .

* fixed some brackets

* fixed a mistake of >  where it should be >=

* added 2 remaining tests

* Update test/src/sdk-harness/test_artifacts/storage_vec/svec_u8/Cargo.toml

Co-authored-by: Braqzen <103777923+Braqzen@users.noreply.github.com>

* removed storagevecerrors

* assert was the other way round

* added a variable for repeated code

* merged use

* formatting

* expanded the testing

* rearranged file structure

* cargo fmt

* adjusted assert for removes

* removed non test and shortened the contract code

* added cant_get test

* added a todo

* Improved documentation

* updated tests with preconditional tests

* added initializer

* updated functions with sdk release

* mdae build.sh more generic

* fixed build script

* fix 2 electric boogaloo

* updated remove and insert tests

* added len checks

* FINALLY ADDED TESTS FOR ALL TYPES OMG

* alphabetical order

* cargo fmt + changed the b256 consts

* removed unncessary len checks

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Kaya Gökalp <kayagokalp@sabanciuniv.edu>
Co-authored-by: Vaivaswatha N <vaivaswatha@users.noreply.github.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: João Matos <joao@tritao.eu>
Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: Chris O'Brien <57543709+eureka-cpu@users.noreply.github.com>
Co-authored-by: mitchmindtree <mitchell.nordine@fuel.sh>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: bing <binggh@proton.me>
Co-authored-by: seem-less <mgirach@gmail.com>
Co-authored-by: Waseem G <contact@waseem-g.com>
Co-authored-by: mitchmindtree <mail@mitchellnordine.com>
Co-authored-by: zhou fan <1247714429@qq.com>
Co-authored-by: Hlib Kanunnikov <hlibwondertan@gmail.com>
Co-authored-by: Emir <emirsalkicart@gmail.com>
Co-authored-by: r-sitko <19492095+r-sitko@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Braqzen <103777923+Braqzen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request language server LSP server
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants