foundry-rs/foundry

`--via-ir` flag is ignored when running `forge coverage`

Opened this issue ยท 19 comments

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

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

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

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

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).

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.

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?

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?

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.

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)

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 commented

I have the same issue with forge coverage command.

image

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

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

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?

Same issue here

QEDK commented

Do we have any workarounds for this issue yet?

forge coverage --ir-minimum works

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.

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?