Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Use solidity fuzzy import parser #1291

Merged
merged 7 commits into from
Dec 10, 2019

Conversation

spalladino
Copy link
Contributor

Increases performance of nothing-to-compile runs by using a custom fuzzy parser that only extracts imports from the text, instead of the full antlr4 parser.

Running both versions in the contracts repository, this yields a 40% speed increase when having nothing to compile.

This commit also lazy-loads truffle-flattener, which was causing significant delays to the CLI startup.

@spalladino spalladino force-pushed the feature/use-solidity-fuzzy-imports-parser branch from ab27e07 to 0bcee48 Compare November 22, 2019 22:16
@spalladino
Copy link
Contributor Author

We should wait until OpenZeppelin/fuzzy-import-parser#2 is implemented before merging

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

Neat! 🙌

I took a look at the whole compiler execution flow looking for differences that may arise from switching to this new parser (which is somewhat lax and may yield false positives) and found two. One is a simple change to this PR's changeset, while the other is not as straightforward.

On ResolverEngineGatherer, gatherSources will call resolvePath on each imported path. and resolveImportFile will later try to find the file, erroring out if it doesn't find it (Could not find file X imported from Y). Because the fuzzy parser may yield false positives, this behaviour is no longer correct.

A reasonable course of action might be to emit a warning instead of an error and attempt to carry on, assuming the missing dependency is a false positive detection. If it is indeed a false positive Solidity will correctly identify the syntax error, leading to a happy user. On true positives and missing imports, we will emit a warning ourselves about a possible missing import, and Solidity will complain about an unresolved dependency: these two together should be enough for the user to figure out what's wrong.

For reference, this is the message emitted by Solidity when an import is not resolved.

contracts/mocks/Boolean.sol:3:1: ParserError: Source "Foo.sol" not found: File import callback not supported
import "Foo.sol";
^---------------^

We may want to reference the 'file import callback not supported' bit in our warning, since it is a red herring.

packages/cli/src/utils/solidity.ts Show resolved Hide resolved
spalladino and others added 3 commits November 28, 2019 16:10
Increases performance of nothing-to-compile runs by using a custom fuzzy parser that only extracts imports from the text, instead of the full antlr4 parser.

Running both versions in the contracts repository, this yields a 40% speed increase when having nothing to compile.

This commit also lazy-loads truffle-flattener, which was causing significant delays to the CLI startup.
@spalladino
Copy link
Contributor Author

spalladino commented Nov 28, 2019 via email

@nventuro nventuro force-pushed the feature/use-solidity-fuzzy-imports-parser branch from 04290b0 to 25f17f4 Compare December 5, 2019 22:54
@nventuro
Copy link
Contributor

@spalladino Once CI passes, this should be ready to merge. I extracted the error handling out of getImports to make it more explicit, and added calls to trimURL whenever we report a problematic file location that may have been the result of buggy parsing.

@spalladino
Copy link
Contributor Author

@nventuro given I'm the author, I cannot approve the PR. Please approve it and merge, I think it's ok!

@nventuro nventuro merged commit 92cff22 into master Dec 10, 2019
@nventuro nventuro deleted the feature/use-solidity-fuzzy-imports-parser branch December 10, 2019 18:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants