Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: support --via-ir flag when running forge coverage #3527

Closed
2 tasks done
colinnielsen opened this issue Oct 21, 2022 · 25 comments
Closed
2 tasks done

feat: support --via-ir flag when running forge coverage #3527

colinnielsen opened this issue Oct 21, 2022 · 25 comments
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-feature Type: feature T-to-discuss Type: requires discussion

Comments

@colinnielsen
Copy link
Contributor

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (d896050 2022-10-21T00:08:06.615745Z)

What command(s) is the bug in?

forge coverage --via-ir --report lcov

Operating System

macOS (Apple Silicon)

Describe the bug

Looks like COMPILER OPTIONS are listed when forge coverage -h is run, however it appears that the coverage command does not build through the YUL pipeline.
Screen Shot 2022-10-21 at 5 27 21 PM

@colinnielsen colinnielsen added the T-bug Type: bug label Oct 21, 2022
@gakonst gakonst added this to Foundry Oct 21, 2022
@gakonst gakonst moved this to Todo in Foundry Oct 21, 2022
@colinnielsen
Copy link
Contributor Author

Looks like forge coverage also ignores the via_ir flag in the foundry.toml

@mattsse
Copy link
Member

mattsse commented Oct 22, 2022

this is unfortunately a limitation, because --via-ir transforms the AST so there is no good way of keeping track afterwards.

@colinnielsen
Copy link
Contributor Author

Shoot... Is there a way around this? I'm worried that this feature would be bricked once solidity moves to the IR pipeline.

@Oighty
Copy link
Contributor

Oighty commented Nov 3, 2022

I've been having this same error without using --via-ir. My project compiles fine with forge build and forge test, but throws Stack too deep when running forge coverage. Also on Apple Silicon with forge 0.2.0 (7f4fb5 2022-11-02).

@mattsse
Copy link
Member

mattsse commented Nov 3, 2022

this is unfortunately a limitation, because --via-ir transforms the AST so there is no good way of keeping track of the original AST afterward right now.

we should make this clearer on the website.

@frank-lim-partior
Copy link

this is unfortunately a limitation, because --via-ir transforms the AST so there is no good way of keeping track afterwards.

Is the need for tracking AST isolated to the test contracts? Or does it apply to the primary source code as well?

@0xrusowsky
Copy link

0xrusowsky commented Dec 23, 2022

this is unfortunately a limitation, because --via-ir transforms the AST so there is no good way of keeping track afterwards.

I'm facing the same issue. Having this limitation in mind, do we have any alternative to see test coverage when getting Stack too deep error?

@PaulRBerg
Copy link
Contributor

PaulRBerg commented Dec 27, 2022

we should make this clearer on the website.

@mattsse what do you mean by "website"? The Foundry Book? Because if yes, I don't see any documentation about coverage on there.

I am not sufficiently experienced with test coverage software to understand why it is difficult (or impossible) to run coverage over IR-optimized code, but I agree with the commend made by @colinnielsen above - if coverage is not made to work with IR, it will not be as popular as it could be.

@haythemsellami
Copy link

haythemsellami commented Jun 13, 2023

My code compile without --via-ir, and tests works fine, but still getting stack too deep in coverage.

forge 0.2.0 (08a629a 2023-06-03T00:04:10.749254000Z)

@haythemsellami
Copy link

My code compile without --via-ir, but still getting stack too deep in coverage.

forge 0.2.0 (08a629a 2023-06-03T00:04:10.749254000Z)

This is an annoying error and probably will be a big blocker for Foundry adoption.Also, how to get more output from the CLI command, it does not show to me where the stack too deep error exactly is:

[⠰] Compiling...
[⠒] Compiling 100 files with 0.8.20
[⠘] Solc 0.8.20 finished in 4.24s
Error:
Compiler run failed:
Error: Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:68):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.

@smak0v
Copy link

smak0v commented Jun 26, 2023

I have the same issue with forge coverage command.

image

@ethereumdegen
Copy link
Contributor

I've been having this same error without using --via-ir. My project compiles fine with forge build and forge test, but throws Stack too deep when running forge coverage. Also on Apple Silicon with forge 0.2.0 (7f4fb5 2022-11-02).

i have the exact same issue

@golden-expiriensu
Copy link
Contributor

Hi, I have the exact same issue, is this fix planned?

@kevinsslin
Copy link

kevinsslin commented Nov 20, 2023

I can pass forge build without --via-ir, but still occur the same error while running forge coverage.
image
Does anyone know how to fix it?

@Pai-Sho
Copy link

Pai-Sho commented Jan 26, 2024

Same issue here

@QEDK
Copy link

QEDK commented Jan 27, 2024

Do we have any workarounds for this issue yet?

@Pai-Sho
Copy link

Pai-Sho commented Jan 31, 2024

forge coverage --ir-minimum works

@sanbir
Copy link

sanbir commented Jun 7, 2024

forge coverage --ir-minimum is a life saver!

I also had to replace all my assembly { with assembly ("memory-safe") { for it to start working.

@NoahMarconi
Copy link

forge coverage --ir-minimum is a life saver!

I also had to replace all my assembly { with assembly ("memory-safe") { for it to start working.

@sanbir To confirm, your assembly blocks are in fact memory safe before you add the annotation?

@zerosnacks zerosnacks changed the title --via-ir flag ignore when running forge coverage --via-ir flag is ignored when running forge coverage Jun 26, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@zerosnacks zerosnacks changed the title --via-ir flag is ignored when running forge coverage feat: support --via-ir flag when running forge coverage Aug 2, 2024
@zerosnacks zerosnacks added T-feature Type: feature and removed T-bug Type: bug labels Aug 2, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Aug 2, 2024

Looks like this is a current limitation of forge coverage because --via-ir transforms the AST so there is no good way of keeping track afterwards. Converted the ticket into a feature request so we can look into how we could possible overcome this limitation.

@mohib231
Copy link

mohib231 commented Aug 6, 2024

forge coverage --ir-minimum is runnning with some limitations on --via-ir. we can use --ir-minimum as an alternate for sometime

@kartojal
Copy link

kartojal commented Sep 9, 2024

anyone facing memory leaks with --ir-minimum?

forge coverage --ir-minimum causes memory leaks while is compiling a large project, it runs out of memory with a 32gb machine

forge 0.2.0 (ea3ba89 2024-09-05T00:20:31.915792582Z)

logs:

$ forge coverage --ir-minimum
Warning! "--ir-minimum" flag enables viaIR with minimum optimization, which can result in inaccurate source mappings.
Only use this flag as a workaround if you are experiencing "stack too deep" errors.
Note that "viaIR" is only available in Solidity 0.8.13 and above.
See more: https://github.com/foundry-rs/foundry/issues/3357
[⠒] Compiling...
[⠢] Compiling 341 files with Solc 0.8.22
[⠰] Compiling 90 files with Solc 0.7.6
[⠒] Solc 0.7.6 finished in 61.74ms
Error: 
solc exited with signal: 9 (SIGKILL)
<empty output>

@siguint
Copy link

siguint commented Oct 2, 2024

anyone facing memory leaks with --ir-minimum?
i have the same issue

@anajuliabit
Copy link

λ forge coverage --ir-minimum --skip test --skip script
Warning! "--ir-minimum" flag enables viaIR with minimum optimization, which can result in inaccurate source mappings.
Only use this flag as a workaround if you are experiencing "stack too deep" errors.
Note that "viaIR" is only available in Solidity 0.8.13 and above.
See more: https://github.com/foundry-rs/foundry/issues/3357
[⠊] Compiling...
[⠒] Compiling 311 files with Solc 0.8.19
[⠢] Compiling 43 files with Solc 0.6.12
[⠆] Compiling 12 files with Solc 0.8.10
[⠰] Solc 0.8.10 finished in 969.96ms
[⠔] Solc 0.6.12 finished in 614.18s
[⠒] Solc 0.8.19 finished in 614.78s
Error: 
Compiler run failed:
Error: Unknown key "inliner

--ir-minimum for me fails with Error: Unknown key "inliner

@grandizzy
Copy link
Collaborator

--ir-minimum should work, mind though that coverage disables optimizer (that is equivalent to setting optimizer = false in config file) so you could hit the behavior where test compiles but coverage fails (see #8840 (comment)). The Unknown key "inliner issue was solved with #9341
Also re memory issues when running coverage - there are big improvements in latest builds, please update and retry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-feature Type: feature T-to-discuss Type: requires discussion
Projects
Archived in project
Development

No branches or pull requests