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

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

Merged
merged 3 commits into from Jun 22, 2022

Conversation

emilyaherbert
Copy link
Contributor

@emilyaherbert emilyaherbert added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Jun 21, 2022
@emilyaherbert emilyaherbert self-assigned this Jun 21, 2022
@emilyaherbert emilyaherbert requested a review from a team June 21, 2022 20:18
@emilyaherbert emilyaherbert enabled auto-merge (squash) June 21, 2022 20:59
@emilyaherbert emilyaherbert requested review from mohammadfawaz and a team June 21, 2022 22:47
mohammadfawaz
mohammadfawaz previously approved these changes Jun 21, 2022
@emilyaherbert emilyaherbert requested a review from a team June 21, 2022 23:42
mitchmindtree
mitchmindtree previously approved these changes Jun 22, 2022
Copy link
Contributor

@mitchmindtree mitchmindtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicccee

@mitchmindtree
Copy link
Contributor

Ahh woops, looks like some small conflicts following #2004.

@mohammadfawaz mohammadfawaz requested review from mitchmindtree and a team June 22, 2022 19:31
@emilyaherbert emilyaherbert merged commit 44e7fe9 into master Jun 22, 2022
@emilyaherbert emilyaherbert deleted the emilyaherbert/type-parameters-and-type-binding branch June 22, 2022 22:45
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 <adlerjohn@users.noreply.github.com>

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

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

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

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

* Run forc fmt again

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

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

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

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

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

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

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

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

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

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

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

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

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

Updates to the known issues section

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

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

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

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

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

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

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

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

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

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

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

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

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

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

Small fix to storage_map example

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

Move the stuff.

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

Ensure lock is applied if BuildPlan validation requires changes

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

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

Closes #2084
Closes #2085

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

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

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

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

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

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

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

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

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

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

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

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

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

* if let to match on program type

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

updating bin-root filename

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

* added benchmarks for compilation process

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

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

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

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

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

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

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

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

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

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

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

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

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

* ignore *_output.json

* forc documenter changes

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

* Enhance some comments

* Remove unnecessary oracle

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

Add support for raw identifiers and improve reserved keywords checking.

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

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

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

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

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

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

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

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

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

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

Closes #1996.

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

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

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

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

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

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

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

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

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

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

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

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

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

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

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

* #2039 - add storage keyword highlighting in book

* Changes after review

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

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

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

* test: add new test assertions

* style: fmt

* test: generate oracle file

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

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

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

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

This reverts commit 8dd0738.

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

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

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

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

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

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

Addresses 1, 2 of #2125.

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

The bug is fixed.

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

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

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

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

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

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

Fix slow `find_dead_code` pass in control flow analysis

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

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

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

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

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

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

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

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

Closes #2171

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

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

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

* Refactor intrinsics to all have arg and type arg vectors

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

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

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

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

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

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

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

* Add `CommentedTokenStream` to `sway_parse`

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

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

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

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

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

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

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

Remove unused const_decl_origin from TypedVariableDeclaration

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

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

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

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

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

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

* Run forc fmt again

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

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

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

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

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

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

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

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

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

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

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

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

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

Updates to the known issues section

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

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

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

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

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

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

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

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

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

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

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

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

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

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

Small fix to storage_map example

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

Move the stuff.

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

Ensure lock is applied if BuildPlan validation requires changes

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

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

Closes #2084
Closes #2085

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

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

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

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

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

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

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

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

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

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

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

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

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

* if let to match on program type

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

updating bin-root filename

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

* added benchmarks for compilation process

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

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

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

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

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

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

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

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

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

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

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

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

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

* ignore *_output.json

* forc documenter changes

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

* Enhance some comments

* Remove unnecessary oracle

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

Add support for raw identifiers and improve reserved keywords checking.

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

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

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

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

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

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

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

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

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

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

Closes #1996.

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

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

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

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

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

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

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

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

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

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

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

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

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

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

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

* #2039 - add storage keyword highlighting in book

* Changes after review

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

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

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

* test: add new test assertions

* style: fmt

* test: generate oracle file

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

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

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

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

This reverts commit 8dd0738.

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

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

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

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

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

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

Addresses 1, 2 of #2125.

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

The bug is fixed.

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

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

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

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

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

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

Fix slow `find_dead_code` pass in control flow analysis

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

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

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

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

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

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

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

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

Closes #2171

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

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

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

* Refactor intrinsics to all have arg and type arg vectors

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

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

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

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

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

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

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

* Add `CommentedTokenStream` to `sway_parse`

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

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

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

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

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

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

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

Remove unused const_decl_origin from TypedVariableDeclaration

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

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

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

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

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

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

* Run forc fmt again

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

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

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

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

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

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

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

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

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

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

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

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

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

Updates to the known issues section

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

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

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

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

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

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

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

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

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

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

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

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

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

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

Small fix to storage_map example

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

Move the stuff.

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

Ensure lock is applied if BuildPlan validation requires changes

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

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

Closes #2084
Closes #2085

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

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

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

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

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

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

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

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

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

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

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

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

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

* if let to match on program type

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

updating bin-root filename

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

* added benchmarks for compilation process

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

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

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

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

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

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

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

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

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

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

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

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

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

* ignore *_output.json

* forc documenter changes

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

* Enhance some comments

* Remove unnecessary oracle

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

Add support for raw identifiers and improve reserved keywords checking.

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

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

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

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

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

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

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

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

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

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

Closes #1996.

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

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

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

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

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

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

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

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

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

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

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

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

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

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

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

* #2039 - add storage keyword highlighting in book

* Changes after review

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

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

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

* test: add new test assertions

* style: fmt

* test: generate oracle file

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

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

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

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

This reverts commit 8dd0738.

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

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

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

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

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

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

Addresses 1, 2 of #2125.

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

The bug is fixed.

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

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

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

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

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

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

Fix slow `find_dead_code` pass in control flow analysis

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

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

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

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

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

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

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

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

Closes #2171

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

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

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

* Refactor intrinsics to all have arg and type arg vectors

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

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

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

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

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

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

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

* Add `CommentedTokenStream` to `sway_parse`

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

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

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

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

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

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

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

Remove unused const_decl_origin from TypedVariableDeclaration

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

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

* merge master to storage_vec (#2184)

* Remove extra "the" (#2042)

looks like an extra "the" got into this comment

* Run `cargo update`. (#2045)

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

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

* Config driven E2E testing. (#2003)

Completely refactor E2E tests to be config driven.

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

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

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

* Add Identity type to Sway Book

* Move Identity code to examples directory

* Add Forc.lock to gitignore

* Update docs/src/basics/blockchain_types.md

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

* Typo

* Ran forc fmt

* Update Cargo.toml

* Update examples/identity/src/main.sw

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

* Delete Cargo.toml

* Update Identity docs to use anchor

* Fix CI

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

* Run forc fmt again

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

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

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

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

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

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

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

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

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

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

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

Closes #1568.

* Do not use an underscored identifier.

* Add some more pattern matching tests.

* Port to new config-driven tests.

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

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

Updates to the known issues section

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

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

* Update the check for unresolved types.

* clippy

* Remove calls to log.

* fmt

* Remove unused file.

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

Bump explicit `dashmap` to v5.3.4.

* comby-rust (#2065)

* comby-rust

* Fix clippy warning

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

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

* wip

* add unit test

* update tests

* updated unimplemented cases to return span

* test now passes incorrectly

* update AttributeDecl::format()

* update test comment

* add close paren

* update Annotated for consistency

* chng return type for Annotated

* remove test and add todos

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

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

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

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

* Rename semantic_analysis::Context to TypeCheckContext

* Improve field doc comments for help_text, self_type

* Add doc comment to mode field in TypeCheckContext

* Construct TypeCheckContext at Program level, not module level.

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

* Add missing namespace field doc comment to TypeCheckContext

* Fix TypeCheckContext constructor in IR test

* Add `forc check` command (#2026)

* wip

* moving back to PC computer

* adding check function to forc pkg

* have ast returning from forc pkg

* can now successfully parse all sway examples

* fmt

* added forc check

* tidy up lsp tests

* add forc check command

* forc ops doesnt need to be public

* tidy up lsp tests

* remove non relevant code

* rebase on master

* add Cargo.lock file

* add forc check to mdbook

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

Small fix to storage_map example

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

Move the stuff.

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

Ensure lock is applied if BuildPlan validation requires changes

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

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

Closes #2084
Closes #2085

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

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

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

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

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

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

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

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

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

* update fuelup related instructions (#2099)

* update fuelup instructions

* better instructions

* better wording for modifying path

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

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

* issue #1893store/show bytecode hash

* formatted

* added cargo lock file

* cargo toml dependencies in alphabetical order

* hash bin of script or predicate only

* format

* generating bytecode hash only on scripts and predicates

* removed option from Compiled::tree_type

* ran clippy

* added to forc_build documentation

* made filename suffix containing bin hash a constant

* get root of predicate bytecode

* Apply suggestions from code review

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

* if let to match on program type

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

updating bin-root filename

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

* added benchmarks for compilation process

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

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

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

* Bump to v0.16.2 (#2105)

* bump to v0.16.2

* Fix one test not pointing to local std

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

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

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

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

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

* Enable storage initializers and dump out a JSON file

* Move the new functions into a separate storage module

* Use StorageSlot directly from fuel-tx

* forc deploy now uses the storage slots

* add some tests

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

* enhance a comment

* Revert unneeded changes to sway-types

* add a failing test

* Fix failing test

* renaming some functions

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

* ignore *_output.json

* forc documenter changes

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

* Enhance some comments

* Remove unnecessary oracle

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

Add support for raw identifiers and improve reserved keywords checking.

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

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

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

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

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

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

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

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

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

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

Closes #1996.

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

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

* add remove fuels-abigen-macro dependency

* add change dep. versions

* add fuel 0.16

* add fuel-core-lib flag

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add fuel-core-lib flag fix

* add remove -- form forc test command

* add replace constants

* add expand CI command

* add fix tests

* add fix tests

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

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

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

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

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

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

* add return -- cmd

* add remove fuels-abigen-macro from tests

* add remove fuel-core-lib flag

* add fuel-core-lib flag

* add reverte CI file

* add remove features

* add remove [features]

* add merge master

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

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

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

* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review

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

* #2039 - add storage keyword highlighting in book

* Changes after review

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

* Add the U256 type (#2103)

* feat: add new bare u256 module to std

* feat: Add base type + from,into traits

* test: setup testing for U256

* cleanup

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

* test: add new test assertions

* style: fmt

* test: generate oracle file

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

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

* fix: remove * import

* fix: improve error handling

* test: better test coverage

* style: fmt

* docs: add test comments

* test: add more test cases for to_u64()

* fix: remove #r prefix from storage lib

* test: remove redundant test

* refactor: rename to_u64 to as_u64

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

This reverts commit 8dd0738.

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

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

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

* Do not rely on TypeMapping when type checking declarations.

* Prevent leaking types in impls.

* Prevent unconstrained type parameters.

* WIP

* clippy

* WIP

* Use TypeId in TypeMapping and in TraitMap.

* Add semantic type constraints.

* Update test case.

* fix

* Use TypeId inside of resolve_type_with_self and resolve_type_without_self.

* clippy

* X

* Remove self_type from monomorphization.

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

* Bug is fixed.

* Add forc.lock.

* update

* Move test to inside of the SDK.

* Fix test cases.

* Add lock files.

* Fix test.

* Move the stuff.

* Move monomorphization conceptually inside of the type engine.

* Remove commented out test.

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

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

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

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

Addresses 1, 2 of #2125.

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

The bug is fixed.

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

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

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

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

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

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

Fix slow `find_dead_code` pass in control flow analysis

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

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

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

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

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

Hopefully this speeds up our CI a bit!

Closes #1952.

* const initialization: a few fixes (#2158)

* const initialization: a few fixes

* cargo fmt

* Address review comments

* Add IR test

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

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

Closes #2171

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

* feat: improve U128 type errors & rename to_u264

* test: add tests for renamed as_u64

* Introduce `__eq` intrinsic (#2100)

* Introduce `__eq` intrinsic

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

* Refactor intrinsics to all have arg and type arg vectors

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

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

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

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

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

* update user_def with AlignFields & fix corresponding use cases

* rmv unused consts

* update doc comments in ItemEnum

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

* Add `CommentedTokenStream` to `sway_parse`

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

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

* Collect multi-line comments in CommentedTokenStream

* Collect single-line comments in CommentedTokenStream

* Add token_trees and spanned impls for CommentedTokenStream

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

* Expose `lex_commented` function from root

* Add CommentedTree and CommentedGroup aliases

* Move CommentedTokenTree impl to better location

* Clean up by using CommentedTree type alias where applicable

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

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

Remove unused const_decl_origin from TypedVariableDeclaration

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

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

* removed unncessary use

* added one test

* deleted all contracts except u8s

* fixed bug in pop

* failing test for some reason

* .

* fixed some brackets

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

* added 2 remaining tests

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

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

* removed storagevecerrors

* assert was the other way round

* added a variable for repeated code

* merged use

* formatting

* expanded the testing

* rearranged file structure

* cargo fmt

* adjusted assert for removes

* removed non test and shortened the contract code

* added cant_get test

* added a todo

* Improved documentation

* updated tests with preconditional tests

* added initializer

* updated functions with sdk release

* mdae build.sh more generic

* fixed build script

* fix 2 electric boogaloo

* updated remove and insert tests

* added len checks

* FINALLY ADDED TESTS FOR ALL TYPES OMG

* alphabetical order

* cargo fmt + changed the b256 consts

* removed unncessary len checks

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

Successfully merging this pull request may close these issues.

None yet

3 participants