Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

[POC] Using native solc for parsing #1720

Closed
wants to merge 3 commits into from

Conversation

maxsam4
Copy link
Contributor

@maxsam4 maxsam4 commented Feb 17, 2019

Currently, truffle requires solcjs for parsing. This is a poc to show that it can do it with native solc as well.
Relevant issue #1567

PS. This is just a POC. I don't really know why it was decided to use solcjs for parsing nor do I know if my changes are in the right place.

@gnidan
Copy link
Contributor

gnidan commented Feb 17, 2019

Hey @maxsam4 thanks for getting this started! I'll try to get eyes on this early this upcoming week.

Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

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

So upon first review, this seems to make sense. I'd love to learn more about what you tried / what led you to this solution.

I'm also wondering if you have any ideas for anything we can do to clean up that whole import error key mechanism, since it was a hack when you started :)

Thanks for this!

@@ -5,7 +5,7 @@ const VersionRange = require("./VersionRange");
class Native extends LoadingStrategy {
load() {
const versionString = this.validateAndGetSolcVersion();
const command = "solc --standard-json";
const command = "solc --standard-json --allow-paths '.'";
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why this was necessary. I think it's fine but I'm a bit concerned about this causing problems if it's too restrictive. My guess is that Truffle currently does not support paths outside the project root, and I don't believe it's normal use case, so it's probably fine, but, yeah, just wondering what led you to include this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"just wondering what led you to include this."
Failing tests.

Without this, solc was not allowing the 'incorrect paths' to be accessed in the test solidity code which included incorrect paths by choice. Before merging, we can fix the incorrect paths in the test to be incorrect allowed paths and remove this change.

FWIW, this change is not adding any restriction, it is only removing some restrictions. by default, solc native does not allow any paths outside the contracts. This change allows the base directory of the project to be included.

@@ -18,10 +18,9 @@ module.exports = {
// the imports speedily without doing extra work.

// If we're using docker/native, we'll still want to use solcjs to do this part.
if (solc.importsParser) solc = solc.importsParser;

// if (solc.importsParser) solc = solc.importsParser;
Copy link
Contributor

Choose a reason for hiding this comment

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

(We'll have to remember to delete this commented out line of code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, need to update comments before merging. Right now, it's just a POC to make sure I am heading in the right direction.

// Helper to detect import errors with an easy regex.
var importErrorKey = "TRUFFLE_IMPORT";
var importErrorKey = "not found: File";
Copy link
Contributor

Choose a reason for hiding this comment

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

Gosh. This is what we have to do now? (I mean, if it's the only option, it's the only option)

// Without this, we'll get an error message we *can* detect, but the key will make it easier.
// Note: This is not a normal callback. See docs here: https://github.com/ethereum/solc-js#from-version-021
return { error: importErrorKey };
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. So if I get this right, the crux of the problem seems to be that our profiling relied on this weird error object, which was only available via solc-js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't totally understand how this was even working. First of all, the object is named "errors" and not "error". Secondly, an almost same object is being returned by native solc as well but it did not work for the native solc object (the changes seemed to be in values and not keys so they should not matter).

@maxsam4
Copy link
Contributor Author

maxsam4 commented Feb 19, 2019

Hey @gnidan , thanks for the review!
I'll try to explain the changes now. Starting with the current system.

Currently, the profiling took the errors array generated by solcjs and added "TRUFFLE_IMPORT" to all the "file not found" errors. Later, the code checks if the error contains "TRUFFLE_IMPORT" to decide if the error is a "file not found" error or not.

The errors object passed by native and docker solc is a bit different so the code was failing to add "TRUFFLE_IMPORT" to the file not found errors. This meant that when it was searching for "file not found" errors later by searching for "TRUFFLE_IMPORT" in the string, it was finding none.

What I did was stop adding "TRUFFLE_IMPORT" to the errors altogether and use "not found: File" as the substring to search for when checking "file not found" errors. The advantage is that this works with all solc versions I tested. the disadvantage is that if solc changes the error message in the future, this will break. It will be an easy fix but yeah.

We can use a less restrictive/different search query as well. Or even make a regex like "Source.*not found".

@CruzMolina
Copy link
Contributor

Thanks for getting this POC up @maxsam4! #1913 should fully enable this & resolve #1567.

@maxsam4
Copy link
Contributor Author

maxsam4 commented Apr 16, 2019

Thanks for continuing this poc @CruzMolina .
I am closing this PR as I think it has served its purpose.

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.

3 participants