-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Improvements around forc plugins
command
#1969
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats on your first PR 🎉 (sorry if it is not 👀). Thank you for the fix and the fix seems good to me. But I think you may need to run cargo fmt
since CI is resulting in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM will defer the final approval to @ra0x3 or @FuelLabs/tooling
@tritao Does this PR have an associated issue? I see the PR fixes something (from your PR description), but trying to see what the originating issue is/was |
No, found the issue today and sent the PR directly. Should I create one? |
@tritao For housekeeping purposes, yes that would be great if you could create one :) |
Issue is now open and linked to the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Pulled down and tested.
- Can reproduce the error, and can see that the mentioned fix removes the error.
- One minor/small requested change.
forc/src/cli/commands/plugins.rs
Outdated
@@ -78,7 +78,7 @@ fn format_print_description( | |||
.to_string() | |||
}; | |||
|
|||
let description = parse_description_for_plugin(&display); | |||
let description = parse_description_for_plugin(path.to_str().unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works fine. I think we can leave this as is though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by leave this as-is? Revert this change?
If that is the case, then we will continue passing only the partial path to the executable exec, which could lead to the same bug this is trying to fix. The second commit will workaround the deps
issue, but other cases (forc plugins nested in a directory) could still trigger the crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I agree :)
- I'll defer to @mitchmindtree on this as I'm not sure why there are arbitrary folders in
~/.cargo/bin
or how many there can/might be. But other than that, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tritao instead of passing in a &str
here, it looks like we might be better off changing the parse_description_for_plugin
function to take a &Path
instead.
We can still call Command::new(plugin)
directly inside parse_description_for_plugin
(without any str conversion) as Path
implements AsRef<OsStr>
.
We should also update its comment to reflect that it expects the canonical path to the plugin, not just the plugin name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that is cleaner for sure, will update the PR
forc/src/cli/plugin.rs
Outdated
@@ -63,6 +63,11 @@ fn is_executable(path: &Path) -> bool { | |||
|
|||
/// Whether or not the given path points to a valid forc plugin. | |||
fn is_plugin(path: &Path) -> bool { | |||
// This is to check that we do not match executables like `deps/forc-cd4662b67fa2a5c9`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the helpful comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, where these deps
coming from? I'm curious how they end up in your PATH
?
I don't think it's feasible for us to filter out every possible unwanted directory of executables that a user might have carelessly/accidentally placed in their PATH
, however if this is particularly common for some reason I'm open to it.
I think the proper fix here is: Rather than panic!
ing when failing to retrieve a description for a plugin, we should instead use an empty description, or perhaps some default string along the lines of "Unable to retrieve a description for this plugin."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking on this further, if we fail to retrieve a description, perhaps we can just skip the plugin altogether? We could instead update our definition of forc
plugins to require a description in order to be enumerated under the forc plugins
command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, where these
deps
coming from? I'm curious how they end up in yourPATH
?
They exist after a cargo build
inside target/debug/deps
folder. If PATH
contains sway/target/debug
, then it triggers this issue, since files are recursively enumerated when searching for plugins.
I don't think it's feasible for us to filter out every possible unwanted directory of executables that a user might have carelessly/accidentally placed in their
PATH
, however if this is particularly common for some reason I'm open to it.
Agreed, but in this case it happens in a default build environment, so I thought it was worth dealing with it directly.
Might be worth noting these executables respond to -h
:
~/dev/sway/target/debug$ deps/forc-cd4662b67fa2a5c9 -h
Usage: -h [OPTIONS] [FILTERS...]
Options:
--include-ignored
Run ignored and not ignored tests
--ignored Run only ignored tests
...
And that is why they are being considered as plugins.
I think the most reliable fix here would be to make sure that forc plugins provide some kind of well-specified manifest (say with a --manifest
flag which could return a JSON description). That would make sure there are no conflicts with other executables providing an -h
flag.
For my first PR, however, I decided to take the easy route and just fix the panic, and skip them directly since I wasn't sure it was worth spending too much time on this.
If you think it's worth the time fixing this in a more solid way let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @tritao!
I think the most reliable fix here would be to make sure that forc plugins provide some kind of well-specified manifest (say with a --manifest flag which could return a JSON description).
That sounds like a great idea! But probably best for a future PR like you mention.
They exist after a cargo build inside target/debug/deps folder. If PATH contains sway/target/debug, then it triggers this issue, since files are recursively enumerated when searching for plugins.
I'm still a little unsure of how sway/target/debug
ends up in your PATH
in this case? Do you normally manually add the target directory of projects you work on to your PATH
?
I think the more conventional approach for having Rust bins available on PATH
is to have ~/.cargo/bin
on the PATH
- that way when cargo install <crate>
is ran, the <crate>
bin is available via PATH
.
If you want the debug build to be available on your PATH
while you're testing etc, another option is to use cargo install --debug --path /path/to/crate
.
When I'm testing in Sway locally, I find it more useful to make a habit of running forc
with the cargo run
command to ensure I'm always using the local state, and to avoid the need to have two steps. E.g.
cargo run --bin forc -- build --path /path/to/forc/project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the target dir to the PATH
because I was just getting started and didn't know any better regarding the workflow.
Thanks for explaining your workflow with cargo
, I can just use that going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats on the first PR @tritao and thanks for catching this!
I've left some comments inline.
forc/src/cli/commands/plugins.rs
Outdated
@@ -78,7 +78,7 @@ fn format_print_description( | |||
.to_string() | |||
}; | |||
|
|||
let description = parse_description_for_plugin(&display); | |||
let description = parse_description_for_plugin(path.to_str().unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tritao instead of passing in a &str
here, it looks like we might be better off changing the parse_description_for_plugin
function to take a &Path
instead.
We can still call Command::new(plugin)
directly inside parse_description_for_plugin
(without any str conversion) as Path
implements AsRef<OsStr>
.
We should also update its comment to reflect that it expects the canonical path to the plugin, not just the plugin name.
forc/src/cli/plugin.rs
Outdated
@@ -63,6 +63,11 @@ fn is_executable(path: &Path) -> bool { | |||
|
|||
/// Whether or not the given path points to a valid forc plugin. | |||
fn is_plugin(path: &Path) -> bool { | |||
// This is to check that we do not match executables like `deps/forc-cd4662b67fa2a5c9`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, where these deps
coming from? I'm curious how they end up in your PATH
?
I don't think it's feasible for us to filter out every possible unwanted directory of executables that a user might have carelessly/accidentally placed in their PATH
, however if this is particularly common for some reason I'm open to it.
I think the proper fix here is: Rather than panic!
ing when failing to retrieve a description for a plugin, we should instead use an empty description, or perhaps some default string along the lines of "Unable to retrieve a description for this plugin."
My review was requested again recently, however I still have some outstanding Qs here. To clarify, the premise for some of these changes is that it may be common to have the |
ce1e6f7
to
7a20fea
Compare
I've updated the PR with just the fix to use the full path to the plugin, which seems like the correct thing to do either way. |
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 ```
7a20fea
to
d5e8d43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks so much @tritao!
Poking @ra0x3 for re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, deferring to @ra0x3 for final approval
* Remove extra "the" (#2042) looks like an extra "the" got into this comment * Run `cargo update`. (#2045) * sway-fmt-v2 adds program type to the output (#1997) * Fix couple of bugs in handling returns in if blocks (#2029) * Config driven E2E testing. (#2003) Completely refactor E2E tests to be config driven. Rather than specifying which tests are to be run and how, we now can describe each test with a TOML file. * Handle enums and their impls for item imports (#2034) * Add `Identity` type to Sway Book (#2041) * Add Identity type to Sway Book * Move Identity code to examples directory * Add Forc.lock to gitignore * Update docs/src/basics/blockchain_types.md Co-authored-by: John Adler <[email protected]> * Typo * Ran forc fmt * Update Cargo.toml * Update examples/identity/src/main.sw Co-authored-by: Mohammad Fawaz <[email protected]> * Delete Cargo.toml * Update Identity docs to use anchor * Fix CI * Add path to std in Forc.toml and update Forc.lock std source * Run forc fmt again Co-authored-by: John Adler <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> * Improve struct patterns with new warnings and rest pattern support. (#2032) * Improve struct patterns with new warnings and rest pattern support. This commit improves a couple aspects of handling of struct patterns. First of all, it adds semantic checking (with a new warning) when patterns are missing usage of all fields: ``` error --> src/main.sw:15:9 | 13 | 14 | let z = match p { 15 | Point { x } => { x }, | ^^^^^^^^^^^ Pattern does not mention field: y 16 | }; | ____ ``` Then it adds support for rest pattern, "..", which can be used as the last token in a pattern to not have to specify all the struct fields. The semantic AST model was updated to support modeling this pattern, and further type checking was added to the code. There is also a new warning for when the rest pattern doesn't appear as the last location, or when it appears multiple times: ``` error --> src/main.sw:17:20 | 15 | 16 | let z = match p { 17 | Point { x, .., .. } => { x }, | ^^ Unexpected rest token, must be at the end of pattern. 18 | }; | ____ ``` And lastly, tests were added to cover the changes and new functionality. Closes #1568. * Do not use an underscored identifier. * Add some more pattern matching tests. * Port to new config-driven tests. Co-authored-by: Mohammad Fawaz <[email protected]> * Add the concept of semantic similarity to the type system (#1958) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Some updates to the known issues section (#2060) Updates to the known issues section * Constants formatting for sway-fmt-v2 (#2021) * Update the check for unresolved types. (#2057) * Update the check for unresolved types. * clippy * Remove calls to log. * fmt * Remove unused file. * Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Bump non-transitive `dashmap` to v5.3.4. (#2062) Bump explicit `dashmap` to v5.3.4. * comby-rust (#2065) * comby-rust * Fix clippy warning Co-authored-by: Mohammad Fawaz <[email protected]> * Adds `attribute` handling to `sway-fmt-v2` (#2061) * wip * add unit test * update tests * updated unimplemented cases to return span * test now passes incorrectly * update AttributeDecl::format() * update test comment * add close paren * update Annotated for consistency * chng return type for Annotated * remove test and add todos * Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004) * Introduce a type check `Context`. Replaces `TypeCheckArguments`. * Add missing unknown type annotation. Clean up some formatting. Also adds some resetting of the help text and type annotation (to unknown) in many cases to better match the original behaviour. It's difficult to tell which locations these values were originally used as placeholders, and which locations they're a necessity for correctness. This at least appears to fix an issue with expression return type inference. * Rename semantic_analysis::Context to TypeCheckContext * Improve field doc comments for help_text, self_type * Add doc comment to mode field in TypeCheckContext * Construct TypeCheckContext at Program level, not module level. This should help to clarify how we can pass other type check context (like the declaration and type engines once they're added) through to the submodules. Previously, this was a little unclear as the `TypeCheckContext` was only constructed at the module level. * Add missing namespace field doc comment to TypeCheckContext * Fix TypeCheckContext constructor in IR test * Add `forc check` command (#2026) * wip * moving back to PC computer * adding check function to forc pkg * have ast returning from forc pkg * can now successfully parse all sway examples * fmt * added forc check * tidy up lsp tests * add forc check command * forc ops doesnt need to be public * tidy up lsp tests * remove non relevant code * rebase on master * add Cargo.lock file * add forc check to mdbook * Small fixes to the `storage_map` example (#2079) Small fix to storage_map example * Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074) Move the stuff. * Ensure lock is applied when `BuildPlan` validation would require changes (#2090) Ensure lock is applied if BuildPlan validation requires changes While reviewing #2085, I noticed that some recent additions to `BuildPlan` validation could result in some changes to the build plan (and in turn, rewriting the lock file) even in the case that `--locked` was specified. This moves the `--locked` check to the moment before writing the new lock file. This ensures all potential changes that would be required of the `BuildPlan` are caught. It also allows us to provide a "Cause" for *why* the lock file would need updating when `--locked` is passed to prevent it. Closes #2084 Closes #2085 * Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Add `abi` handling to `sway-fmt-v2` (#2044) * Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094) Previously, if any of the `print` args were set, the rest of the selected build profile was ignored. This changes the behaviour so that the command line arguments only override their associated build profile fields. Also renames `BuildConfig` to `BuildProfile` and moves it from `forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the serializable manifest types. * Update all the E2E should_fail tests to verify their output. (#2082) Using the `FileCheck` crate it can now pattern match against the compiler output to be sure the errors and/or warnings are exactly what we expect. * forc: Improve the `print_*_asm` CLI option docs (#2095) Previously, these implied no bytecode was generated if the flag was not set, however this is not the case. * update fuelup related instructions (#2099) * update fuelup instructions * better instructions * better wording for modifying path * Adding `--time-phases` to `forc build` (#2091) * make items under [project] ordered alphabetically in forc.toml * issue #1893store/show bytecode hash * formatted * added cargo lock file * cargo toml dependencies in alphabetical order * hash bin of script or predicate only * format * generating bytecode hash only on scripts and predicates * removed option from Compiled::tree_type * ran clippy * added to forc_build documentation * made filename suffix containing bin hash a constant * get root of predicate bytecode * Apply suggestions from code review Co-authored-by: Mohammad Fawaz <[email protected]> * if let to match on program type * Update forc/src/cli/commands/build.rs updating bin-root filename Co-authored-by: mitchmindtree <[email protected]> * added benchmarks for compilation process * use macro instead of closure for wrapping parts of compilation process Co-authored-by: Waseem G <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Toby Hutton <[email protected]> * Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836) * Bump to v0.16.2 (#2105) * bump to v0.16.2 * Fix one test not pointing to local std * Add struct formatting to sway-fmt-v2 (#2058) * internal: Reduce amount of String::new() in sway-fmt-v2 (#2111) * examples: fix renaming to BASE_ASSET_ID in comment (#2120) * Added storage field alignment threshold to formatter config (#2113) * Enable storage initializers and emit a storage initialization JSON (#2078) * Enable storage initializers and dump out a JSON file * Move the new functions into a separate storage module * Use StorageSlot directly from fuel-tx * forc deploy now uses the storage slots * add some tests * lint, change initializers -> slots, and fixing some tests * enhance a comment * Revert unneeded changes to sway-types * add a failing test * Fix failing test * renaming some functions * Test the storage slots JSON in e2e tests and add forc json-storage-slots command * ignore *_output.json * forc documenter changes * Remove forc json-storage-slots and stop relying on forc json-abi * Enhance some comments * Remove unnecessary oracle * Improve reserved keywords checking and add support for raw identifiers. (#2066) Add support for raw identifiers and improve reserved keywords checking. This commit deals with the usage and checking of reserved keywords as identifiers, for code like: ``` fn main() { let mut mut = 0; } It introduces a new error that checks if an identifier is a reserved keyword: ``` error --> /main.sw:4:13 | 2 | 3 | fn main() { 4 | let mut mut = 0; | ^^^ Identifiers cannot be a reserved keyword. 5 | } | ____ ``` There was an existing issue in the standard library, which has a library/module named `storage`. Instead of working around this by renaming it to something else, an alternative solution with raw identifiers is implemented. This raw identifier feature is implemented at the lexer level, and allows you to use keywords as identifiers in places that generally wouldn't be allowed. Rust and a bunch of other modern languages also provide this escape hatch, and it seemed the simplest solution for me to handle the issue. It activates by declaring an identifier prefixed with `r#`, just like Rust. The complexity on the codebase to support this feature is pretty minimal, but if there any objections to this, I can easily remove it, but some other solution to the issue above will need to be figured out. Closes #1996. Co-authored-by: Mohammad Fawaz <[email protected]> * remove `fuels-abigen-macro` dependency (#2007) * add remove fuels-abigen-macro dependency * add change dep. versions * add fuel 0.16 * add fuel-core-lib flag * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add remove -- form forc test command * add replace constants * add expand CI command * add fix tests * add fix tests * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * add return -- cmd * add remove fuels-abigen-macro from tests * add remove fuel-core-lib flag * add fuel-core-lib flag * add reverte CI file * add remove features * add remove [features] * add merge master Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: John Adler <[email protected]> * Adds `Generics` handling to `sway-fmt-v2` (#2110) * #2020 - changed BASE_ASSET_ID type to ContractId (#2137) * #2020 - changed BASE_ASSET_ID type to ContractId * Fix identity example * Changes after review * #2039 - add storage keyword highlighting in book (#2141) * #2039 - add storage keyword highlighting in book * Changes after review Co-authored-by: John Adler <[email protected]> * Add the U256 type (#2103) * feat: add new bare u256 module to std * feat: Add base type + from,into traits * test: setup testing for U256 * cleanup * feat: add impl U256 max, min, bits, new * test: add new test assertions * style: fmt * test: generate oracle file * Update sway-lib-std/src/u256.sw Co-authored-by: John Adler <[email protected]> * fix: remove * import * fix: improve error handling * test: better test coverage * style: fmt * docs: add test comments * test: add more test cases for to_u64() * fix: remove #r prefix from storage lib * test: remove redundant test * refactor: rename to_u64 to as_u64 * Revert "fix: remove #r prefix from storage lib" This reverts commit 8dd0738. Co-authored-by: John Adler <[email protected]> * sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097) * Move monomorphization conceptually inside of the type engine (#2093) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Move the stuff. * Move monomorphization conceptually inside of the type engine. * Remove commented out test. * `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136) `forc-pkg` - Don't add transitive deps (besides `core`) to namespace Currently `forc-pkg` adds all transitive dependencies to a package's initial namespace prior to its compilation. This had the benefit of implicitly including `core`, but with the downside of implicitly including every other transitive dependency package, even if not a direct depednency (not what we want). This PR changes the behaviour to only include direct dependencies and `core` within a package's initial namespace. Addresses 1, 2 of #2125. * Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132) The bug is fixed. * Remove unnecessary "core" str check in `Span::join` (#2156) * Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160) * Remove duplicate CI checks that already have dedicated jobs (#2161) I noticed a bunch of our CI jobs were were duplicating existing checks. In particular, there was a lot of copy-paste steps of installing forc and the forc-fmt plugin, even when unused in the following checks. This doesn't improve the real bottleneck (our stdlib test job), but it's a start. * Speedup `find_dead_code` pass in control flow analysis (#2159) Fix slow `find_dead_code` pass in control flow analysis While waiting for the tests to pass on a PR I thought I'd have a quick look to see if I could find any quick wins for dead code analysis #1952. I noticed that that we're using `has_path_connecting` for every combination of node and entry point. This means we were re-checking the same nodes many, many times, searching from scratch each time and not re-using any of the knowledge of already visited nodes in each consecutive traversal. This commit refactors the approach to first collect all known live nodes into a set by traversing from the entry points. We re-use the same `Dfs` when searching from each entry in order to re-use its inner set of visited nodes and avoid re-searching sections of the graph that we've already visited. The dead nodes are those not contained in the live set after traversal. This reduces the time taken within the `find_dead_code` call when building the `std` library in debug from ~7.9 seconds down to ~3.3 milliseconds. 1000x+ speedup in DCA :) Hopefully this speeds up our CI a bit! Closes #1952. * const initialization: a few fixes (#2158) * const initialization: a few fixes * cargo fmt * Address review comments * Add IR test Co-authored-by: Mohammad Fawaz <[email protected]> * Update broken link for contributing to Sway in README.md (#2172) Closes #2171 * Backport improvements to `U128` type. (#2169) * feat: improve U128 type errors & rename to_u264 * test: add tests for renamed as_u64 * Introduce `__eq` intrinsic (#2100) * Introduce `__eq` intrinsic * Lower to `Instruction::Cmp` instead of to assembly in IRGen * Refactor intrinsics to all have arg and type arg vectors * Improvements around `forc plugins` command (#1969) Use the full path of the plugin when parsing it for a description. This avoids the following panic caused by trying to exec an executable in a sub-folder with a partial path: ``` ~/dev/sway/target/debug$ forc plugins Installed Plugins: thread 'main' panicked at 'Could not get plugin description.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', forc/src/cli/commands/plugins.rs:43:10 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::result::unwrap_failed at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5 3: core::result::Result<T,E>::expect at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23 4: forc::cli::commands::plugins::parse_description_for_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16 5: forc::cli::commands::plugins::format_print_description at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23 6: forc::cli::commands::plugins::print_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5 7: forc::cli::commands::plugins::exec at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21 ``` * Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153) * update user_def with AlignFields & fix corresponding use cases * rmv unused consts * update doc comments in ItemEnum * Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123) * Add `CommentedTokenStream` to `sway_parse` This doesn't yet collect any comments, but adds the necessary structure and attempts to preserve the original API and behaviour where possible. Collecting of comments to be added in a follow-up commit. * Collect multi-line comments in CommentedTokenStream * Collect single-line comments in CommentedTokenStream * Add token_trees and spanned impls for CommentedTokenStream * Add Spanned impl for CommentedTokenTree. Add comment lexing test. * Expose `lex_commented` function from root * Add CommentedTree and CommentedGroup aliases * Move CommentedTokenTree impl to better location * Clean up by using CommentedTree type alias where applicable Co-authored-by: Alex Hansen <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> * Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181) Remove unused const_decl_origin from TypedVariableDeclaration After #2158, constant declartaions use TypedConstantDeclaration AST node, and hence this field is now useless. It must have been removed in #2158 itself, but I missed doing that. Co-authored-by: John Adler <[email protected]> Co-authored-by: Kaya Gökalp <[email protected]> Co-authored-by: Vaivaswatha N <[email protected]> Co-authored-by: Toby Hutton <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Cameron Carstens <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: Emily Herbert <[email protected]> Co-authored-by: rakita <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: bing <[email protected]> Co-authored-by: seem-less <[email protected]> Co-authored-by: Waseem G <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: zhou fan <[email protected]> Co-authored-by: Hlib Kanunnikov <[email protected]> Co-authored-by: Emir <[email protected]> Co-authored-by: r-sitko <[email protected]> Co-authored-by: Nick Furfaro <[email protected]> Co-authored-by: Alex Hansen <[email protected]>
* Remove extra "the" (#2042) looks like an extra "the" got into this comment * Run `cargo update`. (#2045) * sway-fmt-v2 adds program type to the output (#1997) * Fix couple of bugs in handling returns in if blocks (#2029) * Config driven E2E testing. (#2003) Completely refactor E2E tests to be config driven. Rather than specifying which tests are to be run and how, we now can describe each test with a TOML file. * Handle enums and their impls for item imports (#2034) * Add `Identity` type to Sway Book (#2041) * Add Identity type to Sway Book * Move Identity code to examples directory * Add Forc.lock to gitignore * Update docs/src/basics/blockchain_types.md Co-authored-by: John Adler <[email protected]> * Typo * Ran forc fmt * Update Cargo.toml * Update examples/identity/src/main.sw Co-authored-by: Mohammad Fawaz <[email protected]> * Delete Cargo.toml * Update Identity docs to use anchor * Fix CI * Add path to std in Forc.toml and update Forc.lock std source * Run forc fmt again Co-authored-by: John Adler <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> * Improve struct patterns with new warnings and rest pattern support. (#2032) * Improve struct patterns with new warnings and rest pattern support. This commit improves a couple aspects of handling of struct patterns. First of all, it adds semantic checking (with a new warning) when patterns are missing usage of all fields: ``` error --> src/main.sw:15:9 | 13 | 14 | let z = match p { 15 | Point { x } => { x }, | ^^^^^^^^^^^ Pattern does not mention field: y 16 | }; | ____ ``` Then it adds support for rest pattern, "..", which can be used as the last token in a pattern to not have to specify all the struct fields. The semantic AST model was updated to support modeling this pattern, and further type checking was added to the code. There is also a new warning for when the rest pattern doesn't appear as the last location, or when it appears multiple times: ``` error --> src/main.sw:17:20 | 15 | 16 | let z = match p { 17 | Point { x, .., .. } => { x }, | ^^ Unexpected rest token, must be at the end of pattern. 18 | }; | ____ ``` And lastly, tests were added to cover the changes and new functionality. Closes #1568. * Do not use an underscored identifier. * Add some more pattern matching tests. * Port to new config-driven tests. Co-authored-by: Mohammad Fawaz <[email protected]> * Add the concept of semantic similarity to the type system (#1958) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Some updates to the known issues section (#2060) Updates to the known issues section * Constants formatting for sway-fmt-v2 (#2021) * Update the check for unresolved types. (#2057) * Update the check for unresolved types. * clippy * Remove calls to log. * fmt * Remove unused file. * Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Bump non-transitive `dashmap` to v5.3.4. (#2062) Bump explicit `dashmap` to v5.3.4. * comby-rust (#2065) * comby-rust * Fix clippy warning Co-authored-by: Mohammad Fawaz <[email protected]> * Adds `attribute` handling to `sway-fmt-v2` (#2061) * wip * add unit test * update tests * updated unimplemented cases to return span * test now passes incorrectly * update AttributeDecl::format() * update test comment * add close paren * update Annotated for consistency * chng return type for Annotated * remove test and add todos * Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004) * Introduce a type check `Context`. Replaces `TypeCheckArguments`. * Add missing unknown type annotation. Clean up some formatting. Also adds some resetting of the help text and type annotation (to unknown) in many cases to better match the original behaviour. It's difficult to tell which locations these values were originally used as placeholders, and which locations they're a necessity for correctness. This at least appears to fix an issue with expression return type inference. * Rename semantic_analysis::Context to TypeCheckContext * Improve field doc comments for help_text, self_type * Add doc comment to mode field in TypeCheckContext * Construct TypeCheckContext at Program level, not module level. This should help to clarify how we can pass other type check context (like the declaration and type engines once they're added) through to the submodules. Previously, this was a little unclear as the `TypeCheckContext` was only constructed at the module level. * Add missing namespace field doc comment to TypeCheckContext * Fix TypeCheckContext constructor in IR test * Add `forc check` command (#2026) * wip * moving back to PC computer * adding check function to forc pkg * have ast returning from forc pkg * can now successfully parse all sway examples * fmt * added forc check * tidy up lsp tests * add forc check command * forc ops doesnt need to be public * tidy up lsp tests * remove non relevant code * rebase on master * add Cargo.lock file * add forc check to mdbook * Small fixes to the `storage_map` example (#2079) Small fix to storage_map example * Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074) Move the stuff. * Ensure lock is applied when `BuildPlan` validation would require changes (#2090) Ensure lock is applied if BuildPlan validation requires changes While reviewing #2085, I noticed that some recent additions to `BuildPlan` validation could result in some changes to the build plan (and in turn, rewriting the lock file) even in the case that `--locked` was specified. This moves the `--locked` check to the moment before writing the new lock file. This ensures all potential changes that would be required of the `BuildPlan` are caught. It also allows us to provide a "Cause" for *why* the lock file would need updating when `--locked` is passed to prevent it. Closes #2084 Closes #2085 * Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Add `abi` handling to `sway-fmt-v2` (#2044) * Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094) Previously, if any of the `print` args were set, the rest of the selected build profile was ignored. This changes the behaviour so that the command line arguments only override their associated build profile fields. Also renames `BuildConfig` to `BuildProfile` and moves it from `forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the serializable manifest types. * Update all the E2E should_fail tests to verify their output. (#2082) Using the `FileCheck` crate it can now pattern match against the compiler output to be sure the errors and/or warnings are exactly what we expect. * forc: Improve the `print_*_asm` CLI option docs (#2095) Previously, these implied no bytecode was generated if the flag was not set, however this is not the case. * update fuelup related instructions (#2099) * update fuelup instructions * better instructions * better wording for modifying path * Adding `--time-phases` to `forc build` (#2091) * make items under [project] ordered alphabetically in forc.toml * issue #1893store/show bytecode hash * formatted * added cargo lock file * cargo toml dependencies in alphabetical order * hash bin of script or predicate only * format * generating bytecode hash only on scripts and predicates * removed option from Compiled::tree_type * ran clippy * added to forc_build documentation * made filename suffix containing bin hash a constant * get root of predicate bytecode * Apply suggestions from code review Co-authored-by: Mohammad Fawaz <[email protected]> * if let to match on program type * Update forc/src/cli/commands/build.rs updating bin-root filename Co-authored-by: mitchmindtree <[email protected]> * added benchmarks for compilation process * use macro instead of closure for wrapping parts of compilation process Co-authored-by: Waseem G <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Toby Hutton <[email protected]> * Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836) * Bump to v0.16.2 (#2105) * bump to v0.16.2 * Fix one test not pointing to local std * Add struct formatting to sway-fmt-v2 (#2058) * internal: Reduce amount of String::new() in sway-fmt-v2 (#2111) * examples: fix renaming to BASE_ASSET_ID in comment (#2120) * Added storage field alignment threshold to formatter config (#2113) * Enable storage initializers and emit a storage initialization JSON (#2078) * Enable storage initializers and dump out a JSON file * Move the new functions into a separate storage module * Use StorageSlot directly from fuel-tx * forc deploy now uses the storage slots * add some tests * lint, change initializers -> slots, and fixing some tests * enhance a comment * Revert unneeded changes to sway-types * add a failing test * Fix failing test * renaming some functions * Test the storage slots JSON in e2e tests and add forc json-storage-slots command * ignore *_output.json * forc documenter changes * Remove forc json-storage-slots and stop relying on forc json-abi * Enhance some comments * Remove unnecessary oracle * Improve reserved keywords checking and add support for raw identifiers. (#2066) Add support for raw identifiers and improve reserved keywords checking. This commit deals with the usage and checking of reserved keywords as identifiers, for code like: ``` fn main() { let mut mut = 0; } It introduces a new error that checks if an identifier is a reserved keyword: ``` error --> /main.sw:4:13 | 2 | 3 | fn main() { 4 | let mut mut = 0; | ^^^ Identifiers cannot be a reserved keyword. 5 | } | ____ ``` There was an existing issue in the standard library, which has a library/module named `storage`. Instead of working around this by renaming it to something else, an alternative solution with raw identifiers is implemented. This raw identifier feature is implemented at the lexer level, and allows you to use keywords as identifiers in places that generally wouldn't be allowed. Rust and a bunch of other modern languages also provide this escape hatch, and it seemed the simplest solution for me to handle the issue. It activates by declaring an identifier prefixed with `r#`, just like Rust. The complexity on the codebase to support this feature is pretty minimal, but if there any objections to this, I can easily remove it, but some other solution to the issue above will need to be figured out. Closes #1996. Co-authored-by: Mohammad Fawaz <[email protected]> * remove `fuels-abigen-macro` dependency (#2007) * add remove fuels-abigen-macro dependency * add change dep. versions * add fuel 0.16 * add fuel-core-lib flag * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add remove -- form forc test command * add replace constants * add expand CI command * add fix tests * add fix tests * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * add return -- cmd * add remove fuels-abigen-macro from tests * add remove fuel-core-lib flag * add fuel-core-lib flag * add reverte CI file * add remove features * add remove [features] * add merge master Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: John Adler <[email protected]> * Adds `Generics` handling to `sway-fmt-v2` (#2110) * #2020 - changed BASE_ASSET_ID type to ContractId (#2137) * #2020 - changed BASE_ASSET_ID type to ContractId * Fix identity example * Changes after review * #2039 - add storage keyword highlighting in book (#2141) * #2039 - add storage keyword highlighting in book * Changes after review Co-authored-by: John Adler <[email protected]> * Add the U256 type (#2103) * feat: add new bare u256 module to std * feat: Add base type + from,into traits * test: setup testing for U256 * cleanup * feat: add impl U256 max, min, bits, new * test: add new test assertions * style: fmt * test: generate oracle file * Update sway-lib-std/src/u256.sw Co-authored-by: John Adler <[email protected]> * fix: remove * import * fix: improve error handling * test: better test coverage * style: fmt * docs: add test comments * test: add more test cases for to_u64() * fix: remove #r prefix from storage lib * test: remove redundant test * refactor: rename to_u64 to as_u64 * Revert "fix: remove #r prefix from storage lib" This reverts commit 8dd0738. Co-authored-by: John Adler <[email protected]> * sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097) * Move monomorphization conceptually inside of the type engine (#2093) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Move the stuff. * Move monomorphization conceptually inside of the type engine. * Remove commented out test. * `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136) `forc-pkg` - Don't add transitive deps (besides `core`) to namespace Currently `forc-pkg` adds all transitive dependencies to a package's initial namespace prior to its compilation. This had the benefit of implicitly including `core`, but with the downside of implicitly including every other transitive dependency package, even if not a direct depednency (not what we want). This PR changes the behaviour to only include direct dependencies and `core` within a package's initial namespace. Addresses 1, 2 of #2125. * Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132) The bug is fixed. * Remove unnecessary "core" str check in `Span::join` (#2156) * Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160) * Remove duplicate CI checks that already have dedicated jobs (#2161) I noticed a bunch of our CI jobs were were duplicating existing checks. In particular, there was a lot of copy-paste steps of installing forc and the forc-fmt plugin, even when unused in the following checks. This doesn't improve the real bottleneck (our stdlib test job), but it's a start. * Speedup `find_dead_code` pass in control flow analysis (#2159) Fix slow `find_dead_code` pass in control flow analysis While waiting for the tests to pass on a PR I thought I'd have a quick look to see if I could find any quick wins for dead code analysis #1952. I noticed that that we're using `has_path_connecting` for every combination of node and entry point. This means we were re-checking the same nodes many, many times, searching from scratch each time and not re-using any of the knowledge of already visited nodes in each consecutive traversal. This commit refactors the approach to first collect all known live nodes into a set by traversing from the entry points. We re-use the same `Dfs` when searching from each entry in order to re-use its inner set of visited nodes and avoid re-searching sections of the graph that we've already visited. The dead nodes are those not contained in the live set after traversal. This reduces the time taken within the `find_dead_code` call when building the `std` library in debug from ~7.9 seconds down to ~3.3 milliseconds. 1000x+ speedup in DCA :) Hopefully this speeds up our CI a bit! Closes #1952. * const initialization: a few fixes (#2158) * const initialization: a few fixes * cargo fmt * Address review comments * Add IR test Co-authored-by: Mohammad Fawaz <[email protected]> * Update broken link for contributing to Sway in README.md (#2172) Closes #2171 * Backport improvements to `U128` type. (#2169) * feat: improve U128 type errors & rename to_u264 * test: add tests for renamed as_u64 * Introduce `__eq` intrinsic (#2100) * Introduce `__eq` intrinsic * Lower to `Instruction::Cmp` instead of to assembly in IRGen * Refactor intrinsics to all have arg and type arg vectors * Improvements around `forc plugins` command (#1969) Use the full path of the plugin when parsing it for a description. This avoids the following panic caused by trying to exec an executable in a sub-folder with a partial path: ``` ~/dev/sway/target/debug$ forc plugins Installed Plugins: thread 'main' panicked at 'Could not get plugin description.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', forc/src/cli/commands/plugins.rs:43:10 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::result::unwrap_failed at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5 3: core::result::Result<T,E>::expect at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23 4: forc::cli::commands::plugins::parse_description_for_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16 5: forc::cli::commands::plugins::format_print_description at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23 6: forc::cli::commands::plugins::print_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5 7: forc::cli::commands::plugins::exec at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21 ``` * Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153) * update user_def with AlignFields & fix corresponding use cases * rmv unused consts * update doc comments in ItemEnum * Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123) * Add `CommentedTokenStream` to `sway_parse` This doesn't yet collect any comments, but adds the necessary structure and attempts to preserve the original API and behaviour where possible. Collecting of comments to be added in a follow-up commit. * Collect multi-line comments in CommentedTokenStream * Collect single-line comments in CommentedTokenStream * Add token_trees and spanned impls for CommentedTokenStream * Add Spanned impl for CommentedTokenTree. Add comment lexing test. * Expose `lex_commented` function from root * Add CommentedTree and CommentedGroup aliases * Move CommentedTokenTree impl to better location * Clean up by using CommentedTree type alias where applicable Co-authored-by: Alex Hansen <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> * Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181) Remove unused const_decl_origin from TypedVariableDeclaration After #2158, constant declartaions use TypedConstantDeclaration AST node, and hence this field is now useless. It must have been removed in #2158 itself, but I missed doing that. Co-authored-by: John Adler <[email protected]> Co-authored-by: Kaya Gökalp <[email protected]> Co-authored-by: Vaivaswatha N <[email protected]> Co-authored-by: Toby Hutton <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Cameron Carstens <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: Emily Herbert <[email protected]> Co-authored-by: rakita <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: bing <[email protected]> Co-authored-by: seem-less <[email protected]> Co-authored-by: Waseem G <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: zhou fan <[email protected]> Co-authored-by: Hlib Kanunnikov <[email protected]> Co-authored-by: Emir <[email protected]> Co-authored-by: r-sitko <[email protected]> Co-authored-by: Nick Furfaro <[email protected]> Co-authored-by: Alex Hansen <[email protected]>
* Initial commit - storagevec * added an error and comments and documentation * fixed the order of the Result types * added suggested functions * removed unncessary code * renamed remove_index * added swap remove and removed unncessary annotations * moved storage_vec to storage and started on tests * built some of the contract -- WIP * made it so swap_remove returns the removed element * removed extra ) and added all the test functions * fixed a syntax error * changed store to storage * removed all other types for now * made storagevecerror public * removed unncessary code to streamline bugfixing * fixed annotations * made all the test contracts * changed build.sh to include all the storage_vec projs * updated fuels version * unwrapped all results and options in the contract * reduced fuels version * merge master to storage_vec branch (#2183) * Remove extra "the" (#2042) looks like an extra "the" got into this comment * Run `cargo update`. (#2045) * sway-fmt-v2 adds program type to the output (#1997) * Fix couple of bugs in handling returns in if blocks (#2029) * Config driven E2E testing. (#2003) Completely refactor E2E tests to be config driven. Rather than specifying which tests are to be run and how, we now can describe each test with a TOML file. * Handle enums and their impls for item imports (#2034) * Add `Identity` type to Sway Book (#2041) * Add Identity type to Sway Book * Move Identity code to examples directory * Add Forc.lock to gitignore * Update docs/src/basics/blockchain_types.md Co-authored-by: John Adler <[email protected]> * Typo * Ran forc fmt * Update Cargo.toml * Update examples/identity/src/main.sw Co-authored-by: Mohammad Fawaz <[email protected]> * Delete Cargo.toml * Update Identity docs to use anchor * Fix CI * Add path to std in Forc.toml and update Forc.lock std source * Run forc fmt again Co-authored-by: John Adler <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> * Improve struct patterns with new warnings and rest pattern support. (#2032) * Improve struct patterns with new warnings and rest pattern support. This commit improves a couple aspects of handling of struct patterns. First of all, it adds semantic checking (with a new warning) when patterns are missing usage of all fields: ``` error --> src/main.sw:15:9 | 13 | 14 | let z = match p { 15 | Point { x } => { x }, | ^^^^^^^^^^^ Pattern does not mention field: y 16 | }; | ____ ``` Then it adds support for rest pattern, "..", which can be used as the last token in a pattern to not have to specify all the struct fields. The semantic AST model was updated to support modeling this pattern, and further type checking was added to the code. There is also a new warning for when the rest pattern doesn't appear as the last location, or when it appears multiple times: ``` error --> src/main.sw:17:20 | 15 | 16 | let z = match p { 17 | Point { x, .., .. } => { x }, | ^^ Unexpected rest token, must be at the end of pattern. 18 | }; | ____ ``` And lastly, tests were added to cover the changes and new functionality. Closes #1568. * Do not use an underscored identifier. * Add some more pattern matching tests. * Port to new config-driven tests. Co-authored-by: Mohammad Fawaz <[email protected]> * Add the concept of semantic similarity to the type system (#1958) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Some updates to the known issues section (#2060) Updates to the known issues section * Constants formatting for sway-fmt-v2 (#2021) * Update the check for unresolved types. (#2057) * Update the check for unresolved types. * clippy * Remove calls to log. * fmt * Remove unused file. * Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Bump non-transitive `dashmap` to v5.3.4. (#2062) Bump explicit `dashmap` to v5.3.4. * comby-rust (#2065) * comby-rust * Fix clippy warning Co-authored-by: Mohammad Fawaz <[email protected]> * Adds `attribute` handling to `sway-fmt-v2` (#2061) * wip * add unit test * update tests * updated unimplemented cases to return span * test now passes incorrectly * update AttributeDecl::format() * update test comment * add close paren * update Annotated for consistency * chng return type for Annotated * remove test and add todos * Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004) * Introduce a type check `Context`. Replaces `TypeCheckArguments`. * Add missing unknown type annotation. Clean up some formatting. Also adds some resetting of the help text and type annotation (to unknown) in many cases to better match the original behaviour. It's difficult to tell which locations these values were originally used as placeholders, and which locations they're a necessity for correctness. This at least appears to fix an issue with expression return type inference. * Rename semantic_analysis::Context to TypeCheckContext * Improve field doc comments for help_text, self_type * Add doc comment to mode field in TypeCheckContext * Construct TypeCheckContext at Program level, not module level. This should help to clarify how we can pass other type check context (like the declaration and type engines once they're added) through to the submodules. Previously, this was a little unclear as the `TypeCheckContext` was only constructed at the module level. * Add missing namespace field doc comment to TypeCheckContext * Fix TypeCheckContext constructor in IR test * Add `forc check` command (#2026) * wip * moving back to PC computer * adding check function to forc pkg * have ast returning from forc pkg * can now successfully parse all sway examples * fmt * added forc check * tidy up lsp tests * add forc check command * forc ops doesnt need to be public * tidy up lsp tests * remove non relevant code * rebase on master * add Cargo.lock file * add forc check to mdbook * Small fixes to the `storage_map` example (#2079) Small fix to storage_map example * Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074) Move the stuff. * Ensure lock is applied when `BuildPlan` validation would require changes (#2090) Ensure lock is applied if BuildPlan validation requires changes While reviewing #2085, I noticed that some recent additions to `BuildPlan` validation could result in some changes to the build plan (and in turn, rewriting the lock file) even in the case that `--locked` was specified. This moves the `--locked` check to the moment before writing the new lock file. This ensures all potential changes that would be required of the `BuildPlan` are caught. It also allows us to provide a "Cause" for *why* the lock file would need updating when `--locked` is passed to prevent it. Closes #2084 Closes #2085 * Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Add `abi` handling to `sway-fmt-v2` (#2044) * Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094) Previously, if any of the `print` args were set, the rest of the selected build profile was ignored. This changes the behaviour so that the command line arguments only override their associated build profile fields. Also renames `BuildConfig` to `BuildProfile` and moves it from `forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the serializable manifest types. * Update all the E2E should_fail tests to verify their output. (#2082) Using the `FileCheck` crate it can now pattern match against the compiler output to be sure the errors and/or warnings are exactly what we expect. * forc: Improve the `print_*_asm` CLI option docs (#2095) Previously, these implied no bytecode was generated if the flag was not set, however this is not the case. * update fuelup related instructions (#2099) * update fuelup instructions * better instructions * better wording for modifying path * Adding `--time-phases` to `forc build` (#2091) * make items under [project] ordered alphabetically in forc.toml * issue #1893store/show bytecode hash * formatted * added cargo lock file * cargo toml dependencies in alphabetical order * hash bin of script or predicate only * format * generating bytecode hash only on scripts and predicates * removed option from Compiled::tree_type * ran clippy * added to forc_build documentation * made filename suffix containing bin hash a constant * get root of predicate bytecode * Apply suggestions from code review Co-authored-by: Mohammad Fawaz <[email protected]> * if let to match on program type * Update forc/src/cli/commands/build.rs updating bin-root filename Co-authored-by: mitchmindtree <[email protected]> * added benchmarks for compilation process * use macro instead of closure for wrapping parts of compilation process Co-authored-by: Waseem G <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Toby Hutton <[email protected]> * Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836) * Bump to v0.16.2 (#2105) * bump to v0.16.2 * Fix one test not pointing to local std * Add struct formatting to sway-fmt-v2 (#2058) * internal: Reduce amount of String::new() in sway-fmt-v2 (#2111) * examples: fix renaming to BASE_ASSET_ID in comment (#2120) * Added storage field alignment threshold to formatter config (#2113) * Enable storage initializers and emit a storage initialization JSON (#2078) * Enable storage initializers and dump out a JSON file * Move the new functions into a separate storage module * Use StorageSlot directly from fuel-tx * forc deploy now uses the storage slots * add some tests * lint, change initializers -> slots, and fixing some tests * enhance a comment * Revert unneeded changes to sway-types * add a failing test * Fix failing test * renaming some functions * Test the storage slots JSON in e2e tests and add forc json-storage-slots command * ignore *_output.json * forc documenter changes * Remove forc json-storage-slots and stop relying on forc json-abi * Enhance some comments * Remove unnecessary oracle * Improve reserved keywords checking and add support for raw identifiers. (#2066) Add support for raw identifiers and improve reserved keywords checking. This commit deals with the usage and checking of reserved keywords as identifiers, for code like: ``` fn main() { let mut mut = 0; } It introduces a new error that checks if an identifier is a reserved keyword: ``` error --> /main.sw:4:13 | 2 | 3 | fn main() { 4 | let mut mut = 0; | ^^^ Identifiers cannot be a reserved keyword. 5 | } | ____ ``` There was an existing issue in the standard library, which has a library/module named `storage`. Instead of working around this by renaming it to something else, an alternative solution with raw identifiers is implemented. This raw identifier feature is implemented at the lexer level, and allows you to use keywords as identifiers in places that generally wouldn't be allowed. Rust and a bunch of other modern languages also provide this escape hatch, and it seemed the simplest solution for me to handle the issue. It activates by declaring an identifier prefixed with `r#`, just like Rust. The complexity on the codebase to support this feature is pretty minimal, but if there any objections to this, I can easily remove it, but some other solution to the issue above will need to be figured out. Closes #1996. Co-authored-by: Mohammad Fawaz <[email protected]> * remove `fuels-abigen-macro` dependency (#2007) * add remove fuels-abigen-macro dependency * add change dep. versions * add fuel 0.16 * add fuel-core-lib flag * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add remove -- form forc test command * add replace constants * add expand CI command * add fix tests * add fix tests * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * add return -- cmd * add remove fuels-abigen-macro from tests * add remove fuel-core-lib flag * add fuel-core-lib flag * add reverte CI file * add remove features * add remove [features] * add merge master Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: John Adler <[email protected]> * Adds `Generics` handling to `sway-fmt-v2` (#2110) * #2020 - changed BASE_ASSET_ID type to ContractId (#2137) * #2020 - changed BASE_ASSET_ID type to ContractId * Fix identity example * Changes after review * #2039 - add storage keyword highlighting in book (#2141) * #2039 - add storage keyword highlighting in book * Changes after review Co-authored-by: John Adler <[email protected]> * Add the U256 type (#2103) * feat: add new bare u256 module to std * feat: Add base type + from,into traits * test: setup testing for U256 * cleanup * feat: add impl U256 max, min, bits, new * test: add new test assertions * style: fmt * test: generate oracle file * Update sway-lib-std/src/u256.sw Co-authored-by: John Adler <[email protected]> * fix: remove * import * fix: improve error handling * test: better test coverage * style: fmt * docs: add test comments * test: add more test cases for to_u64() * fix: remove #r prefix from storage lib * test: remove redundant test * refactor: rename to_u64 to as_u64 * Revert "fix: remove #r prefix from storage lib" This reverts commit 8dd0738. Co-authored-by: John Adler <[email protected]> * sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097) * Move monomorphization conceptually inside of the type engine (#2093) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Move the stuff. * Move monomorphization conceptually inside of the type engine. * Remove commented out test. * `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136) `forc-pkg` - Don't add transitive deps (besides `core`) to namespace Currently `forc-pkg` adds all transitive dependencies to a package's initial namespace prior to its compilation. This had the benefit of implicitly including `core`, but with the downside of implicitly including every other transitive dependency package, even if not a direct depednency (not what we want). This PR changes the behaviour to only include direct dependencies and `core` within a package's initial namespace. Addresses 1, 2 of #2125. * Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132) The bug is fixed. * Remove unnecessary "core" str check in `Span::join` (#2156) * Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160) * Remove duplicate CI checks that already have dedicated jobs (#2161) I noticed a bunch of our CI jobs were were duplicating existing checks. In particular, there was a lot of copy-paste steps of installing forc and the forc-fmt plugin, even when unused in the following checks. This doesn't improve the real bottleneck (our stdlib test job), but it's a start. * Speedup `find_dead_code` pass in control flow analysis (#2159) Fix slow `find_dead_code` pass in control flow analysis While waiting for the tests to pass on a PR I thought I'd have a quick look to see if I could find any quick wins for dead code analysis #1952. I noticed that that we're using `has_path_connecting` for every combination of node and entry point. This means we were re-checking the same nodes many, many times, searching from scratch each time and not re-using any of the knowledge of already visited nodes in each consecutive traversal. This commit refactors the approach to first collect all known live nodes into a set by traversing from the entry points. We re-use the same `Dfs` when searching from each entry in order to re-use its inner set of visited nodes and avoid re-searching sections of the graph that we've already visited. The dead nodes are those not contained in the live set after traversal. This reduces the time taken within the `find_dead_code` call when building the `std` library in debug from ~7.9 seconds down to ~3.3 milliseconds. 1000x+ speedup in DCA :) Hopefully this speeds up our CI a bit! Closes #1952. * const initialization: a few fixes (#2158) * const initialization: a few fixes * cargo fmt * Address review comments * Add IR test Co-authored-by: Mohammad Fawaz <[email protected]> * Update broken link for contributing to Sway in README.md (#2172) Closes #2171 * Backport improvements to `U128` type. (#2169) * feat: improve U128 type errors & rename to_u264 * test: add tests for renamed as_u64 * Introduce `__eq` intrinsic (#2100) * Introduce `__eq` intrinsic * Lower to `Instruction::Cmp` instead of to assembly in IRGen * Refactor intrinsics to all have arg and type arg vectors * Improvements around `forc plugins` command (#1969) Use the full path of the plugin when parsing it for a description. This avoids the following panic caused by trying to exec an executable in a sub-folder with a partial path: ``` ~/dev/sway/target/debug$ forc plugins Installed Plugins: thread 'main' panicked at 'Could not get plugin description.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', forc/src/cli/commands/plugins.rs:43:10 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::result::unwrap_failed at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5 3: core::result::Result<T,E>::expect at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23 4: forc::cli::commands::plugins::parse_description_for_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16 5: forc::cli::commands::plugins::format_print_description at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23 6: forc::cli::commands::plugins::print_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5 7: forc::cli::commands::plugins::exec at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21 ``` * Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153) * update user_def with AlignFields & fix corresponding use cases * rmv unused consts * update doc comments in ItemEnum * Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123) * Add `CommentedTokenStream` to `sway_parse` This doesn't yet collect any comments, but adds the necessary structure and attempts to preserve the original API and behaviour where possible. Collecting of comments to be added in a follow-up commit. * Collect multi-line comments in CommentedTokenStream * Collect single-line comments in CommentedTokenStream * Add token_trees and spanned impls for CommentedTokenStream * Add Spanned impl for CommentedTokenTree. Add comment lexing test. * Expose `lex_commented` function from root * Add CommentedTree and CommentedGroup aliases * Move CommentedTokenTree impl to better location * Clean up by using CommentedTree type alias where applicable Co-authored-by: Alex Hansen <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> * Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181) Remove unused const_decl_origin from TypedVariableDeclaration After #2158, constant declartaions use TypedConstantDeclaration AST node, and hence this field is now useless. It must have been removed in #2158 itself, but I missed doing that. Co-authored-by: John Adler <[email protected]> Co-authored-by: Kaya Gökalp <[email protected]> Co-authored-by: Vaivaswatha N <[email protected]> Co-authored-by: Toby Hutton <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Cameron Carstens <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: Emily Herbert <[email protected]> Co-authored-by: rakita <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: bing <[email protected]> Co-authored-by: seem-less <[email protected]> Co-authored-by: Waseem G <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: zhou fan <[email protected]> Co-authored-by: Hlib Kanunnikov <[email protected]> Co-authored-by: Emir <[email protected]> Co-authored-by: r-sitko <[email protected]> Co-authored-by: Nick Furfaro <[email protected]> Co-authored-by: Alex Hansen <[email protected]> * merge master to storage_vec (#2184) * Remove extra "the" (#2042) looks like an extra "the" got into this comment * Run `cargo update`. (#2045) * sway-fmt-v2 adds program type to the output (#1997) * Fix couple of bugs in handling returns in if blocks (#2029) * Config driven E2E testing. (#2003) Completely refactor E2E tests to be config driven. Rather than specifying which tests are to be run and how, we now can describe each test with a TOML file. * Handle enums and their impls for item imports (#2034) * Add `Identity` type to Sway Book (#2041) * Add Identity type to Sway Book * Move Identity code to examples directory * Add Forc.lock to gitignore * Update docs/src/basics/blockchain_types.md Co-authored-by: John Adler <[email protected]> * Typo * Ran forc fmt * Update Cargo.toml * Update examples/identity/src/main.sw Co-authored-by: Mohammad Fawaz <[email protected]> * Delete Cargo.toml * Update Identity docs to use anchor * Fix CI * Add path to std in Forc.toml and update Forc.lock std source * Run forc fmt again Co-authored-by: John Adler <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> * Improve struct patterns with new warnings and rest pattern support. (#2032) * Improve struct patterns with new warnings and rest pattern support. This commit improves a couple aspects of handling of struct patterns. First of all, it adds semantic checking (with a new warning) when patterns are missing usage of all fields: ``` error --> src/main.sw:15:9 | 13 | 14 | let z = match p { 15 | Point { x } => { x }, | ^^^^^^^^^^^ Pattern does not mention field: y 16 | }; | ____ ``` Then it adds support for rest pattern, "..", which can be used as the last token in a pattern to not have to specify all the struct fields. The semantic AST model was updated to support modeling this pattern, and further type checking was added to the code. There is also a new warning for when the rest pattern doesn't appear as the last location, or when it appears multiple times: ``` error --> src/main.sw:17:20 | 15 | 16 | let z = match p { 17 | Point { x, .., .. } => { x }, | ^^ Unexpected rest token, must be at the end of pattern. 18 | }; | ____ ``` And lastly, tests were added to cover the changes and new functionality. Closes #1568. * Do not use an underscored identifier. * Add some more pattern matching tests. * Port to new config-driven tests. Co-authored-by: Mohammad Fawaz <[email protected]> * Add the concept of semantic similarity to the type system (#1958) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Some updates to the known issues section (#2060) Updates to the known issues section * Constants formatting for sway-fmt-v2 (#2021) * Update the check for unresolved types. (#2057) * Update the check for unresolved types. * clippy * Remove calls to log. * fmt * Remove unused file. * Make `resolve_type_with_self` and `resolve_type_without_self` take `TypeId`'s instead of `TypeInfo`'s (#1982) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Bump non-transitive `dashmap` to v5.3.4. (#2062) Bump explicit `dashmap` to v5.3.4. * comby-rust (#2065) * comby-rust * Fix clippy warning Co-authored-by: Mohammad Fawaz <[email protected]> * Adds `attribute` handling to `sway-fmt-v2` (#2061) * wip * add unit test * update tests * updated unimplemented cases to return span * test now passes incorrectly * update AttributeDecl::format() * update test comment * add close paren * update Annotated for consistency * chng return type for Annotated * remove test and add todos * Introduce a type check `Context`. Replaces `TypeCheckArguments`. (#2004) * Introduce a type check `Context`. Replaces `TypeCheckArguments`. * Add missing unknown type annotation. Clean up some formatting. Also adds some resetting of the help text and type annotation (to unknown) in many cases to better match the original behaviour. It's difficult to tell which locations these values were originally used as placeholders, and which locations they're a necessity for correctness. This at least appears to fix an issue with expression return type inference. * Rename semantic_analysis::Context to TypeCheckContext * Improve field doc comments for help_text, self_type * Add doc comment to mode field in TypeCheckContext * Construct TypeCheckContext at Program level, not module level. This should help to clarify how we can pass other type check context (like the declaration and type engines once they're added) through to the submodules. Previously, this was a little unclear as the `TypeCheckContext` was only constructed at the module level. * Add missing namespace field doc comment to TypeCheckContext * Fix TypeCheckContext constructor in IR test * Add `forc check` command (#2026) * wip * moving back to PC computer * adding check function to forc pkg * have ast returning from forc pkg * can now successfully parse all sway examples * fmt * added forc check * tidy up lsp tests * add forc check command * forc ops doesnt need to be public * tidy up lsp tests * remove non relevant code * rebase on master * add Cargo.lock file * add forc check to mdbook * Small fixes to the `storage_map` example (#2079) Small fix to storage_map example * Move `TypeArgument`, `TypeParameter`, and `TraitConstraints` to be conceptually inside of the type engine (#2074) Move the stuff. * Ensure lock is applied when `BuildPlan` validation would require changes (#2090) Ensure lock is applied if BuildPlan validation requires changes While reviewing #2085, I noticed that some recent additions to `BuildPlan` validation could result in some changes to the build plan (and in turn, rewriting the lock file) even in the case that `--locked` was specified. This moves the `--locked` check to the moment before writing the new lock file. This ensures all potential changes that would be required of the `BuildPlan` are caught. It also allows us to provide a "Cause" for *why* the lock file would need updating when `--locked` is passed to prevent it. Closes #2084 Closes #2085 * Add conceptual distinction between replacing `TypeInfo::Self` and monomorphization (#2017) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Add `abi` handling to `sway-fmt-v2` (#2044) * Refactor `forc_pkg::BuildConfig` -> `BuildProfile`, fix CLI arg handling (#2094) Previously, if any of the `print` args were set, the rest of the selected build profile was ignored. This changes the behaviour so that the command line arguments only override their associated build profile fields. Also renames `BuildConfig` to `BuildProfile` and moves it from `forc_pkg::pkg` to `forc_pkg::manifest` along with the rest of the serializable manifest types. * Update all the E2E should_fail tests to verify their output. (#2082) Using the `FileCheck` crate it can now pattern match against the compiler output to be sure the errors and/or warnings are exactly what we expect. * forc: Improve the `print_*_asm` CLI option docs (#2095) Previously, these implied no bytecode was generated if the flag was not set, however this is not the case. * update fuelup related instructions (#2099) * update fuelup instructions * better instructions * better wording for modifying path * Adding `--time-phases` to `forc build` (#2091) * make items under [project] ordered alphabetically in forc.toml * issue #1893store/show bytecode hash * formatted * added cargo lock file * cargo toml dependencies in alphabetical order * hash bin of script or predicate only * format * generating bytecode hash only on scripts and predicates * removed option from Compiled::tree_type * ran clippy * added to forc_build documentation * made filename suffix containing bin hash a constant * get root of predicate bytecode * Apply suggestions from code review Co-authored-by: Mohammad Fawaz <[email protected]> * if let to match on program type * Update forc/src/cli/commands/build.rs updating bin-root filename Co-authored-by: mitchmindtree <[email protected]> * added benchmarks for compilation process * use macro instead of closure for wrapping parts of compilation process Co-authored-by: Waseem G <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Toby Hutton <[email protected]> * Add forc feature for overriding packages in the package graph, akin to cargo's [patch] feature (#1836) * Bump to v0.16.2 (#2105) * bump to v0.16.2 * Fix one test not pointing to local std * Add struct formatting to sway-fmt-v2 (#2058) * internal: Reduce amount of String::new() in sway-fmt-v2 (#2111) * examples: fix renaming to BASE_ASSET_ID in comment (#2120) * Added storage field alignment threshold to formatter config (#2113) * Enable storage initializers and emit a storage initialization JSON (#2078) * Enable storage initializers and dump out a JSON file * Move the new functions into a separate storage module * Use StorageSlot directly from fuel-tx * forc deploy now uses the storage slots * add some tests * lint, change initializers -> slots, and fixing some tests * enhance a comment * Revert unneeded changes to sway-types * add a failing test * Fix failing test * renaming some functions * Test the storage slots JSON in e2e tests and add forc json-storage-slots command * ignore *_output.json * forc documenter changes * Remove forc json-storage-slots and stop relying on forc json-abi * Enhance some comments * Remove unnecessary oracle * Improve reserved keywords checking and add support for raw identifiers. (#2066) Add support for raw identifiers and improve reserved keywords checking. This commit deals with the usage and checking of reserved keywords as identifiers, for code like: ``` fn main() { let mut mut = 0; } It introduces a new error that checks if an identifier is a reserved keyword: ``` error --> /main.sw:4:13 | 2 | 3 | fn main() { 4 | let mut mut = 0; | ^^^ Identifiers cannot be a reserved keyword. 5 | } | ____ ``` There was an existing issue in the standard library, which has a library/module named `storage`. Instead of working around this by renaming it to something else, an alternative solution with raw identifiers is implemented. This raw identifier feature is implemented at the lexer level, and allows you to use keywords as identifiers in places that generally wouldn't be allowed. Rust and a bunch of other modern languages also provide this escape hatch, and it seemed the simplest solution for me to handle the issue. It activates by declaring an identifier prefixed with `r#`, just like Rust. The complexity on the codebase to support this feature is pretty minimal, but if there any objections to this, I can easily remove it, but some other solution to the issue above will need to be figured out. Closes #1996. Co-authored-by: Mohammad Fawaz <[email protected]> * remove `fuels-abigen-macro` dependency (#2007) * add remove fuels-abigen-macro dependency * add change dep. versions * add fuel 0.16 * add fuel-core-lib flag * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add fuel-core-lib flag fix * add remove -- form forc test command * add replace constants * add expand CI command * add fix tests * add fix tests * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * Update test/src/sdk-harness/Cargo.toml Co-authored-by: John Adler <[email protected]> * add return -- cmd * add remove fuels-abigen-macro from tests * add remove fuel-core-lib flag * add fuel-core-lib flag * add reverte CI file * add remove features * add remove [features] * add merge master Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: John Adler <[email protected]> * Adds `Generics` handling to `sway-fmt-v2` (#2110) * #2020 - changed BASE_ASSET_ID type to ContractId (#2137) * #2020 - changed BASE_ASSET_ID type to ContractId * Fix identity example * Changes after review * #2039 - add storage keyword highlighting in book (#2141) * #2039 - add storage keyword highlighting in book * Changes after review Co-authored-by: John Adler <[email protected]> * Add the U256 type (#2103) * feat: add new bare u256 module to std * feat: Add base type + from,into traits * test: setup testing for U256 * cleanup * feat: add impl U256 max, min, bits, new * test: add new test assertions * style: fmt * test: generate oracle file * Update sway-lib-std/src/u256.sw Co-authored-by: John Adler <[email protected]> * fix: remove * import * fix: improve error handling * test: better test coverage * style: fmt * docs: add test comments * test: add more test cases for to_u64() * fix: remove #r prefix from storage lib * test: remove redundant test * refactor: rename to_u64 to as_u64 * Revert "fix: remove #r prefix from storage lib" This reverts commit 8dd0738. Co-authored-by: John Adler <[email protected]> * sway-fmt-v2 formatting should use tokens directly from sway-parse (#2097) * Move monomorphization conceptually inside of the type engine (#2093) * Do not rely on TypeMapping when type checking declarations. * Prevent leaking types in impls. * Prevent unconstrained type parameters. * WIP * clippy * WIP * Use TypeId in TypeMapping and in TraitMap. * Add semantic type constraints. * Update test case. * fix * Use TypeId inside of resolve_type_with_self and resolve_type_without_self. * clippy * X * Remove self_type from monomorphization. * Add conceptual distinction between replacing TypeInfo::Self and monomorphization. * Bug is fixed. * Add forc.lock. * update * Move test to inside of the SDK. * Fix test cases. * Add lock files. * Fix test. * Move the stuff. * Move monomorphization conceptually inside of the type engine. * Remove commented out test. * `forc-pkg` - Don't add transitive deps (besides `core`) to a package's initial namespace (#2136) `forc-pkg` - Don't add transitive deps (besides `core`) to namespace Currently `forc-pkg` adds all transitive dependencies to a package's initial namespace prior to its compilation. This had the benefit of implicitly including `core`, but with the downside of implicitly including every other transitive dependency package, even if not a direct depednency (not what we want). This PR changes the behaviour to only include direct dependencies and `core` within a package's initial namespace. Addresses 1, 2 of #2125. * Demonstrate that `T` for `Vec` can now be inferred by arguments (#2132) The bug is fixed. * Remove unnecessary "core" str check in `Span::join` (#2156) * Update the book to explicitly mention that `impl` functions can't call each other yet. (#2160) * Remove duplicate CI checks that already have dedicated jobs (#2161) I noticed a bunch of our CI jobs were were duplicating existing checks. In particular, there was a lot of copy-paste steps of installing forc and the forc-fmt plugin, even when unused in the following checks. This doesn't improve the real bottleneck (our stdlib test job), but it's a start. * Speedup `find_dead_code` pass in control flow analysis (#2159) Fix slow `find_dead_code` pass in control flow analysis While waiting for the tests to pass on a PR I thought I'd have a quick look to see if I could find any quick wins for dead code analysis #1952. I noticed that that we're using `has_path_connecting` for every combination of node and entry point. This means we were re-checking the same nodes many, many times, searching from scratch each time and not re-using any of the knowledge of already visited nodes in each consecutive traversal. This commit refactors the approach to first collect all known live nodes into a set by traversing from the entry points. We re-use the same `Dfs` when searching from each entry in order to re-use its inner set of visited nodes and avoid re-searching sections of the graph that we've already visited. The dead nodes are those not contained in the live set after traversal. This reduces the time taken within the `find_dead_code` call when building the `std` library in debug from ~7.9 seconds down to ~3.3 milliseconds. 1000x+ speedup in DCA :) Hopefully this speeds up our CI a bit! Closes #1952. * const initialization: a few fixes (#2158) * const initialization: a few fixes * cargo fmt * Address review comments * Add IR test Co-authored-by: Mohammad Fawaz <[email protected]> * Update broken link for contributing to Sway in README.md (#2172) Closes #2171 * Backport improvements to `U128` type. (#2169) * feat: improve U128 type errors & rename to_u264 * test: add tests for renamed as_u64 * Introduce `__eq` intrinsic (#2100) * Introduce `__eq` intrinsic * Lower to `Instruction::Cmp` instead of to assembly in IRGen * Refactor intrinsics to all have arg and type arg vectors * Improvements around `forc plugins` command (#1969) Use the full path of the plugin when parsing it for a description. This avoids the following panic caused by trying to exec an executable in a sub-folder with a partial path: ``` ~/dev/sway/target/debug$ forc plugins Installed Plugins: thread 'main' panicked at 'Could not get plugin description.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', forc/src/cli/commands/plugins.rs:43:10 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::result::unwrap_failed at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5 3: core::result::Result<T,E>::expect at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23 4: forc::cli::commands::plugins::parse_description_for_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16 5: forc::cli::commands::plugins::format_print_description at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23 6: forc::cli::commands::plugins::print_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5 7: forc::cli::commands::plugins::exec at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21 ``` * Updates `user_def` with `FieldAlignment` & fix corresponding use cases (#2153) * update user_def with AlignFields & fix corresponding use cases * rmv unused consts * update doc comments in ItemEnum * Add `lex_commented` and `CommentedTokenStream` to `sway_parse` (#2123) * Add `CommentedTokenStream` to `sway_parse` This doesn't yet collect any comments, but adds the necessary structure and attempts to preserve the original API and behaviour where possible. Collecting of comments to be added in a follow-up commit. * Collect multi-line comments in CommentedTokenStream * Collect single-line comments in CommentedTokenStream * Add token_trees and spanned impls for CommentedTokenStream * Add Spanned impl for CommentedTokenTree. Add comment lexing test. * Expose `lex_commented` function from root * Add CommentedTree and CommentedGroup aliases * Move CommentedTokenTree impl to better location * Clean up by using CommentedTree type alias where applicable Co-authored-by: Alex Hansen <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> * Remove unused field `const_decl_origin` from `TypedVariableDeclaration` (#2181) Remove unused const_decl_origin from TypedVariableDeclaration After #2158, constant declartaions use TypedConstantDeclaration AST node, and hence this field is now useless. It must have been removed in #2158 itself, but I missed doing that. Co-authored-by: John Adler <[email protected]> Co-authored-by: Kaya Gökalp <[email protected]> Co-authored-by: Vaivaswatha N <[email protected]> Co-authored-by: Toby Hutton <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Cameron Carstens <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: Emily Herbert <[email protected]> Co-authored-by: rakita <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: bing <[email protected]> Co-authored-by: seem-less <[email protected]> Co-authored-by: Waseem G <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: zhou fan <[email protected]> Co-authored-by: Hlib Kanunnikov <[email protected]> Co-authored-by: Emir <[email protected]> Co-authored-by: r-sitko <[email protected]> Co-authored-by: Nick Furfaro <[email protected]> Co-authored-by: Alex Hansen <[email protected]> * removed unncessary use * added one test * deleted all contracts except u8s * fixed bug in pop * failing test for some reason * . * fixed some brackets * fixed a mistake of > where it should be >= * added 2 remaining tests * Update test/src/sdk-harness/test_artifacts/storage_vec/svec_u8/Cargo.toml Co-authored-by: Braqzen <[email protected]> * removed storagevecerrors * assert was the other way round * added a variable for repeated code * merged use * formatting * expanded the testing * rearranged file structure * cargo fmt * adjusted assert for removes * removed non test and shortened the contract code * added cant_get test * added a todo * Improved documentation * updated tests with preconditional tests * added initializer * updated functions with sdk release * mdae build.sh more generic * fixed build script * fix 2 electric boogaloo * updated remove and insert tests * added len checks * FINALLY ADDED TESTS FOR ALL TYPES OMG * alphabetical order * cargo fmt + changed the b256 consts * removed unncessary len checks Co-authored-by: John Adler <[email protected]> Co-authored-by: Kaya Gökalp <[email protected]> Co-authored-by: Vaivaswatha N <[email protected]> Co-authored-by: Toby Hutton <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Cameron Carstens <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: Emily Herbert <[email protected]> Co-authored-by: rakita <[email protected]> Co-authored-by: Chris O'Brien <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: bing <[email protected]> Co-authored-by: seem-less <[email protected]> Co-authored-by: Waseem G <[email protected]> Co-authored-by: mitchmindtree <[email protected]> Co-authored-by: zhou fan <[email protected]> Co-authored-by: Hlib Kanunnikov <[email protected]> Co-authored-by: Emir <[email protected]> Co-authored-by: r-sitko <[email protected]> Co-authored-by: Nick Furfaro <[email protected]> Co-authored-by: Alex Hansen <[email protected]> Co-authored-by: Braqzen <[email protected]>
Hey, so I was getting started with Sway, and tried calling
forc plugins
command while I was exploring the functionality.This lead to a crash:
The first commit deals with this, which happens due to not using the full path while exec'ing the plugin, so it just changes the function to receive the full path. The docs say
unwrap
should not generally be used because it can lead to a panic, but here we know we have a valid path, so I thought it was okay. If that is not the case, let me know.After that, we get:
The second commit just skips those executables from being considered plugins. While I generally don't like hardcoding the
deps
folder in the check, it seemed like a sensible solution for this not too frequent edge case, since it will probably only happens for developers. What do you think?