sway/scripts/bisect-forc
Daniel Frederico Lins Leite 5896b4cac2
Some checks failed
CI / build-reference-examples (push) Has been cancelled
CI / forc-fmt-check-sway-lib-std (push) Has been cancelled
CI / build-sway-examples (push) Has been cancelled
CI / check-dependency-version-formats (push) Has been cancelled
CI / get-fuel-core-version (push) Has been cancelled
CI / build-sway-lib-std (push) Has been cancelled
CI / forc-fmt-check-sway-examples (push) Has been cancelled
Codspeed Benchmarks / benchmarks (push) Has been cancelled
CI / check-forc-manifest-version (push) Has been cancelled
CI / forc-fmt-check-panic (push) Has been cancelled
CI / check-sdk-harness-test-suite-compatibility (push) Has been cancelled
CI / build-mdbook (push) Has been cancelled
CI / build-forc-doc-sway-lib-std (push) Has been cancelled
CI / build-forc-test-project (push) Has been cancelled
CI / cargo-build-workspace (push) Has been cancelled
CI / cargo-clippy (push) Has been cancelled
CI / cargo-toml-fmt-check (push) Has been cancelled
CI / cargo-fmt-check (push) Has been cancelled
CI / cargo-test-lib-std (push) Has been cancelled
CI / forc-run-benchmarks (push) Has been cancelled
CI / forc-unit-tests (push) Has been cancelled
CI / forc-pkg-fuels-deps-check (push) Has been cancelled
CI / cargo-unused-deps-check (push) Has been cancelled
CI / pre-publish-check (push) Has been cancelled
github pages / deploy (push) Has been cancelled
CI / Build and upload forc binaries to release (push) Has been cancelled
CI / verifications-complete (push) Has been cancelled
CI / cargo-run-e2e-test (push) Has been cancelled
CI / cargo-run-e2e-test-release (push) Has been cancelled
CI / Build and test various forc tools (push) Has been cancelled
CI / notify-slack-on-failure (push) Has been cancelled
CI / publish (push) Has been cancelled
CI / publish-sway-lib-std (push) Has been cancelled
Cost of contract calls snapshot tests (#7440)
## Description

This PR is a prequel for https://github.com/FuelLabs/sway/pull/7419.
It will set the baseline, which future PRs need to improve.

Apart from that it also:
1 - Fix a problem with `SubtsType` for `TyConstantDecl`;
2 - Introduce a new way to write snapshot tests. Now the test source
code can have "blocks"

```
    /* START BOOL */
    fn in_bool(v: bool) -> bool;
    /* END BOOL */
```

These blocks can be manipulated from inside the `snapshot.toml`. In this
case, the `toml` is:

```
cmds = [
    "forc test --path {root} --release --experimental const_generics",
    { repeat = "for-each-block", cmds = [
        "forc test --path {root} --release --experimental const_generics"
    ] }
]
```

Which repeats the inner `forc test` for each block, removing all others.
That allows me to check the cost of the contract method selection
algorithm for each contract method.

For example, `cost_of_in_array_64` with all other contract methods costs
`60382`, but alone it only costs `58218`, which means that around 2000
was "wasted" in the contract method selection.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2025-10-16 14:41:51 +00:00
..
bisect-forc.sh Cost of contract calls snapshot tests (#7440) 2025-10-16 14:41:51 +00:00
README.md One justfile to run them all (#7369) 2025-09-04 10:05:41 +10:00

bisect-forc.sh will automatically run forc bisect searching for a different behaviour between two commits.

The script accepts three arguments:

bisect-forc.sh sway_project test 30s

1 - First argument is the sway project that will be compiled over and over until a different behavior is found; 2 - The second argument is which forc subcommand will be used. It defaults to build.

So, forc will be run as:

> forc <SECONDARGUMENT> --path <FIRSTARGUMENT>

3 - The third argument is a sleep that is taken between compilations to avoid notebooks enter into thermal throttle mode, or that weaker machines become unusable. Default to zero.