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

Forge test debugger is unable to load sourcemaps for any ContractDefinition that contains references invoking external library functions #7038

Closed
2 tasks done
emo-eth opened this issue Feb 7, 2024 · 3 comments · Fixed by #7504
Labels
T-bug Type: bug
Milestone

Comments

@emo-eth
Copy link
Contributor

emo-eth commented Feb 7, 2024

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge --version

What command(s) is the bug in?

forge test --debug

Operating System

macOS (Apple Silicon)

Describe the bug

Sourcemaps in the Forge debugger have been flaky for a while now; see #5435 for an example.

I've finally come across a minimal reproduction – with the caveat that the error displayed in this reproduction is different from the one I'm used to seeing. The error displayed by this reproduction is No PC-IC maps for contract <contract>; I am used to seeing No source map for contract <contract>.

Currently, source maps break for any contract/library that contains any invocations of an external library method (of any nested depth). The source maps for the library itself are unaffected (as long as that library does not invoke any external library methods).

Since I never normally use external library methods, this is definitely not the issue I usually run into.

(As a side note, I know coverage for libraries also has many issues; I can't help but wonder if this is related. See #2567 for discussion and other relevant linked issues).

Note that internal library function invocations do not seem to break sourcemaps, at least in this reproduction.

Reproduce with the following contracts by running forge test --debug test_Increment

Counter.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

/**
 * Sourcemaps for this ContractDefinition work because it does not invoke any
 * library functions.
 */
library Countable {
    function increment(uint256 number) public pure returns (uint256) {
        return ++number;
    }

    function setNumber(uint256, uint256 newNumber) public pure returns (uint256) {
        return newNumber;
    }
}

/**
 * Sourcemaps for this ContractDefinition *do not work* because it invokes
 * the above library functions.
 */
library NestedCountable {
    using Countable for uint256;

    function increment(uint256 number) public pure returns (uint256) {
        return number.increment();
    }

    function setNumber(uint256 number, uint256 newNumber) public pure returns (uint256) {
        return number.setNumber(newNumber);
    }
}

/**
 * Sourcemaps for this ContractDefinition do not work because it invokes
 * the NestedCountable library's functions
 */
contract Counter {
    uint256 public number;

    function setNumber(uint256 newNumber) public {
        number = NestedCountable.setNumber(number, newNumber);
    }

    function increment() public {
        number = NestedCountable.increment(number);
    }
}

Counter.t.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "src/Counter.sol";

/**
 * Sourcemaps for this test ContractDefinition do not work because it contains
 * a reference to Counter, which invokes library functions.
 */
contract CounterTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
        counter.setNumber(0);
    }

    function test_Increment() public {
        counter.increment();
        assertEq(counter.number(), 1);
    }

    function testFuzz_SetNumber(uint256 x) public {
        counter.setNumber(x);
        assertEq(counter.number(), x);
    }
}
@emo-eth emo-eth added the T-bug Type: bug label Feb 7, 2024
@emo-eth emo-eth changed the title Forge test debugger is unable to load sourcemaps for any ContractDefinition that invokes library functions Forge test debugger is unable to load sourcemaps for any ContractDefinition that contains references invoking library functions Feb 7, 2024
@emo-eth emo-eth changed the title Forge test debugger is unable to load sourcemaps for any ContractDefinition that contains references invoking library functions Forge test debugger is unable to load sourcemaps for any ContractDefinition that contains references invoking external library functions Feb 7, 2024
@onbjerg
Copy link
Member

onbjerg commented Feb 7, 2024

Just to be entirely precise here

Currently, source maps break for any contract/library that contains any invocations of an internal library method (of any nested depth – note that I did not try external methods).

The example only contains public/external functions in the library, is this intentional?

@jmcph4
Copy link

jmcph4 commented Feb 7, 2024

Related to #1058 perhaps?

Maybe delegatecall usage is impacting source mapping?

@emo-eth
Copy link
Contributor Author

emo-eth commented Feb 8, 2024

Just to be entirely precise here

Currently, source maps break for any contract/library that contains any invocations of an internal library method (of any nested depth – note that I did not try external methods).

The example only contains public/external functions in the library, is this intentional?

Sorry, edited a few times – current edit I think should be accurate:

External function invocations break sourcemaps – internal function invocations are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants