-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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(forge
): new flatten
implementation
#6936
Conversation
forge
) New flatten
implementationforge
) New flatten
implementation
(You have to write "closes" before each PR, preferably each on a new line) |
@klkvr Great work, congrats! I run your version of flatten on a project that uses prb math (both UD60x18 and SD59x18) and I can see that the resulted file has some issues renamed variables in assembly blocks. For example, in the code below uUNIT was not replaced with the renamed version (uUNIT_1, _2, ...)
Is this an easy fix for you? |
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!!
nice work
forge
) New flatten
implementationforge
): new flatten
implementation
@avniculae ah, assembly blocks are not in scope of renaming atm It shouldn't be hard to fix, could you please drop a link to the contract you are flattening or a minimal repro so it's easier to debug? |
Thanks for letting me know! I run it on a private repo, but I think this file should represent a good test. |
@klkvr another point worth mentioning: docs comments are also not updated during flattening, preventing the final file from compiling successfully. For example:
|
@klkvr another point: if the contract renames an import (e.g., |
@avniculae thanks for all the points, will try to fix all of them regarding imports renaming could you please give a bit more context as this case was addressed directly during development and it shouldn't fail which entity is the mulUD? I mean variable/enum/struct etc |
@klkvr I am experiencing issues with function renaming (mul is a function here) Later Edit: I am experiencing the same issue with some imported variables as well, which are not renamed in the original import at all. Does the code work for constant variables as well (that are freely declared in a file -- i.e. not within a contract?) Later Edit 2: I think the bigger problem here might be that identifiers are not replaced when prepended or appended with characters such as |
I can't reproduce this behavior locally, maybe I got something wrong? mul.sol: function mul(uint256 a, uint256 b) pure returns(uint256) {
return a * b;
} test.sol pragma solidity 0.8.6;
import {mul as mulUD} from "./mul.sol";
contract Test {
function foo() public {
mulMD(1, 2);
}
} And test.sol is getting flattened to pragma solidity 0.8.6;
function mul(uint256 a, uint256 b) pure returns(uint256) {
return a * b;
}
uint256 constant someVar = 1;
contract Test {
function foo(uint256 a) public {
mul(1, 2);
}
} which seems correct |
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
@klkvr Here's a small counterexample: SFixed.sol
UFixed.sol
Contract.sol
In the flattened version, |
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.
🔥
hey @avniculae thank you once again for all the edge cases I belive that all of them should be fixed now, could you please pull this PRs version and try once again if they are working for you? |
@klkvr Thanks for pushing these fixes! I re-run the latest version and I now get the following error:
However, it's hard to tell what's causing this error since the flattened code has over 11k loc, and I wasn't able to reproduce it with small examples |
@avniculae is this repo public? |
@avniculae this happens while updating |
@avniculae any chance you can share names of other dependencies besides prb-math? |
@klkvr I think the main ones are prb-math and @openzeppelin/contracts/ |
Ref foundry-rs/foundry#6936 (comment) Not sure why exactly this unwrap is failing, adding `None` variant handling and some logs to debug it. --------- Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This includes a ton of improvements, but might still have some limitations which we can fix as soon as they get reported. |
Motivation
Ref foundry-rs/compilers#52
Full rewrite of flattening utilizing native solc AST.
forge flatten
command, then I run forge build, it shows: Multiple SPDX license identifiers found in source file. #3678forge flatten
with renamed interface import does not compile #3265forge flatten
does not support qualified imports #2545Solution
It seems that we don't have any tests for
forge flatten
but creating PR with patched dep to run CI just in case.