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(forge): forge inspect subcommand #873

Merged
merged 19 commits into from
Mar 11, 2022
Merged

feat(forge): forge inspect subcommand #873

merged 19 commits into from
Mar 11, 2022

Conversation

refcell
Copy link
Contributor

@refcell refcell commented Mar 8, 2022

Overview

Introduces an inspect subcommand for forge that outputs one of {ir, bytecode} for a given contract as specified by #859

TODO

Implement the following modes for forge inspect <CONTRACT> <MODE>

  • ContractArtifactFields::Abi
  • ContractArtifactFields::Bytecode
  • ContractArtifactFields::DeployedBytecode
  • ContractArtifactFields::Assembly
  • ContractArtifactFields::AssemblyOptimized
  • ContractArtifactFields::MethodIdentifiers
  • ContractArtifactFields::GasEstimates
  • ContractArtifactFields::StorageLayout
  • ContractArtifactFields::DevDoc
  • ContractArtifactFields::Ir
  • ContractArtifactFields::IrOptimized
  • ContractArtifactFields::Metadata
  • ContractArtifactFields::UserDoc
  • ContractArtifactFields::Ewasm

Compilation Suppression

  • Suppress compilation output to allow clean redirecting or piping from inspect

Example compilation output:
Screenshot from 2022-03-09 12-02-58

Override Compiler Optimization for certain ContractArtifactFields variants

  • ContractArtifactFields::AssemblyOptimized

Extra Output Fixes

@refcell refcell changed the title feat(cast): inspect command feat(cast): cast inspect subcommand Mar 8, 2022
@onbjerg onbjerg added the T-feature Type: feature label Mar 8, 2022
@refcell refcell changed the title feat(cast): cast inspect subcommand feat(forge): forge inspect subcommand Mar 8, 2022
@gakonst
Copy link
Member

gakonst commented Mar 9, 2022

FYI printing ir does not seem to render the newlines, so may need some extra work on the formatting of the output! Nice work so far otherwise.

image

@refcell
Copy link
Contributor Author

refcell commented Mar 9, 2022

FYI printing ir does not seem to render the newlines, so may need some extra work on the formatting of the output! Nice work so far otherwise.

image

Yep! Working on that... @mds1 's base command in #859 used perl to sed newline chars, so trying to figure out what to use internally for serde_json::Values here. Open to suggestions!

@refcell refcell marked this pull request as ready for review March 10, 2022 04:28
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this.
some nits :)

cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
cli/src/cmd/inspect.rs Show resolved Hide resolved
cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
cli/src/cmd/mod.rs Show resolved Hide resolved
cli/src/cmd/inspect.rs Outdated Show resolved Hide resolved
@@ -452,6 +452,39 @@ script ran
);
});

// tests that the `inspect` command works correctly
forgetest!(can_execute_inspect_command, |prj: TestProject, mut cmd: TestCommand| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

@gakonst gakonst merged commit 91b1b0a into foundry-rs:master Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: forge inspect <file> <mode> to dump various compiler output types to a file
4 participants