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

comby-rust #2065

Merged
merged 4 commits into from
Jun 21, 2022
Merged

comby-rust #2065

merged 4 commits into from
Jun 21, 2022

Conversation

rakita
Copy link
Contributor

@rakita rakita commented Jun 21, 2022

Run comby_rust
some nits came up

@rakita rakita force-pushed the rakita/comby_rust branch from 62a3a3e to 74c85e9 Compare June 21, 2022 14:10
@mohammadfawaz
Copy link
Contributor

CI failure. Clippy has more suggestions.

@mohammadfawaz
Copy link
Contributor

CI failure. Clippy has more suggestions.

Alright should be good now.

Thanks for doing this!

@mohammadfawaz mohammadfawaz requested a review from a team June 21, 2022 22:59
@mohammadfawaz mohammadfawaz enabled auto-merge (squash) June 21, 2022 22:59
@eureka-cpu eureka-cpu added compiler: ir IRgen and sway-ir including optimization passes lib: core Core library compiler: parser Everything to do with the parser labels Jun 21, 2022
@mohammadfawaz mohammadfawaz merged commit 649bbbb into master Jun 21, 2022
@mohammadfawaz mohammadfawaz deleted the rakita/comby_rust branch June 21, 2022 23:08
@mohammadfawaz mohammadfawaz added code quality and removed lib: core Core library labels Jun 22, 2022
@rakita
Copy link
Contributor Author

rakita commented Jun 22, 2022

Sorry I didn't update it with clippy but yeah it was interesting to run comby

SwayStar123 added a commit that referenced this pull request 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 <[email protected]>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* if let to match on program type

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

updating bin-root filename

Co-authored-by: mitchmindtree <[email protected]>

* added benchmarks for compilation process

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

Co-authored-by: Waseem G <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>
Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>

* 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 <[email protected]>
Co-authored-by: Kaya Gökalp <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Emily Herbert <[email protected]>
Co-authored-by: rakita <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: bing <[email protected]>
Co-authored-by: seem-less <[email protected]>
Co-authored-by: Waseem G <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: zhou fan <[email protected]>
Co-authored-by: Hlib Kanunnikov <[email protected]>
Co-authored-by: Emir <[email protected]>
Co-authored-by: r-sitko <[email protected]>
Co-authored-by: Nick Furfaro <[email protected]>
Co-authored-by: Alex Hansen <[email protected]>
SwayStar123 added a commit that referenced this pull request 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 <[email protected]>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* if let to match on program type

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

updating bin-root filename

Co-authored-by: mitchmindtree <[email protected]>

* added benchmarks for compilation process

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

Co-authored-by: Waseem G <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>
Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>

* 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 <[email protected]>
Co-authored-by: Kaya Gökalp <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Emily Herbert <[email protected]>
Co-authored-by: rakita <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: bing <[email protected]>
Co-authored-by: seem-less <[email protected]>
Co-authored-by: Waseem G <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: zhou fan <[email protected]>
Co-authored-by: Hlib Kanunnikov <[email protected]>
Co-authored-by: Emir <[email protected]>
Co-authored-by: r-sitko <[email protected]>
Co-authored-by: Nick Furfaro <[email protected]>
Co-authored-by: Alex Hansen <[email protected]>
SwayStar123 added a commit that referenced this pull request 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 <[email protected]>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* if let to match on program type

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

updating bin-root filename

Co-authored-by: mitchmindtree <[email protected]>

* added benchmarks for compilation process

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

Co-authored-by: Waseem G <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>
Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>

* 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 <[email protected]>
Co-authored-by: Kaya Gökalp <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Emily Herbert <[email protected]>
Co-authored-by: rakita <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: bing <[email protected]>
Co-authored-by: seem-less <[email protected]>
Co-authored-by: Waseem G <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: zhou fan <[email protected]>
Co-authored-by: Hlib Kanunnikov <[email protected]>
Co-authored-by: Emir <[email protected]>
Co-authored-by: r-sitko <[email protected]>
Co-authored-by: Nick Furfaro <[email protected]>
Co-authored-by: Alex Hansen <[email protected]>

* 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 <[email protected]>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* if let to match on program type

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

updating bin-root filename

Co-authored-by: mitchmindtree <[email protected]>

* added benchmarks for compilation process

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

Co-authored-by: Waseem G <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

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

Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>
Co-authored-by: John Adler <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>

* 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 <[email protected]>
Co-authored-by: Kaya Gökalp <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Emily Herbert <[email protected]>
Co-authored-by: rakita <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: bing <[email protected]>
Co-authored-by: seem-less <[email protected]>
Co-authored-by: Waseem G <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: zhou fan <[email protected]>
Co-authored-by: Hlib Kanunnikov <[email protected]>
Co-authored-by: Emir <[email protected]>
Co-authored-by: r-sitko <[email protected]>
Co-authored-by: Nick Furfaro <[email protected]>
Co-authored-by: Alex Hansen <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Kaya Gökalp <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Emily Herbert <[email protected]>
Co-authored-by: rakita <[email protected]>
Co-authored-by: Chris O'Brien <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: bing <[email protected]>
Co-authored-by: seem-less <[email protected]>
Co-authored-by: Waseem G <[email protected]>
Co-authored-by: mitchmindtree <[email protected]>
Co-authored-by: zhou fan <[email protected]>
Co-authored-by: Hlib Kanunnikov <[email protected]>
Co-authored-by: Emir <[email protected]>
Co-authored-by: r-sitko <[email protected]>
Co-authored-by: Nick Furfaro <[email protected]>
Co-authored-by: Alex Hansen <[email protected]>
Co-authored-by: Braqzen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality compiler: ir IRgen and sway-ir including optimization passes compiler: parser Everything to do with the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants