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

Expose "parsingAndImporting" setting to user #12199

Merged
merged 1 commit into from
Nov 8, 2021

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented Oct 27, 2021

fixes #11756

@Marenz Marenz force-pushed the expose-parsingAndImporting branch 2 times, most recently from a255e20 to 70a7c70 Compare October 27, 2021 12:30
@chriseth
Copy link
Contributor

I don't understand - why do we need a new "stop after" setting? I thought the idea would be to just fill the absolute path during parsing and before actually trying to load the file?

@Marenz
Copy link
Contributor Author

Marenz commented Oct 27, 2021

The ticket specified

Either perform import resolution earlier so that absolutePath is already in the AST when stopAfter: parsing is used or introduce a new value for stopAfter (parsingAndImportResolution?) that still stops before analysis but after import resolution.

and I figured we have that internal step already so just exposing it would be the easiest solution.. and I figured it makes sense to expose more steps as necessary..

@chriseth
Copy link
Contributor

I think that, unless it is complicated to do, we should expose more useful data earlier.

@Marenz Marenz force-pushed the expose-parsingAndImporting branch 2 times, most recently from 1cda14c to 0a6852b Compare October 28, 2021 14:10
@@ -1102,12 +1116,8 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check for import->annotation().absolutePath instead now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out: No. The path can actually be empty after we resolved it. What was previously "." becomes empty. But we still have the assert pre-resolve stage as it was originally...

Changelog.md Outdated
@@ -8,6 +8,7 @@ Compiler Features:
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
* Commandline Interface: Add ``--debug-info`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.
* Commandline Interface: Use different colors when printing errors, warnings and infos.
* General: Absolute paths of imports are now set in the ``parsing`` stage.
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use "now" in every entry, so I think it is better to not use it at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh and as category, maybe "JSON AST"? Because that is what is relevant to the user reading the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The option is available using the command line as well though?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but the json ast is a generic thing that is available to all ways to access the compiler.

@leonardoalt
Copy link
Member

Tests failing

Comment on lines 354 to 369
for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");

// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
import->annotation().absolutePath =
applyRemapping(
util::absolutePath(
import->path(),
path
),
path
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
import->annotation().absolutePath =
applyRemapping(
util::absolutePath(
import->path(),
path
),
path
);
}
for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
import->annotation().absolutePath = applyRemapping(util::absolutePath(
import->path(),
path
), path);
}

@Marenz Marenz force-pushed the expose-parsingAndImporting branch 2 times, most recently from 139b5cd to f860891 Compare November 8, 2021 15:10
{
"ast":
{
"absolutePath": "/project/../C.sol",
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, it was named like that in the input json.

chriseth
chriseth previously approved these changes Nov 8, 2021
{
"ast":
{
"absolutePath": "/project/../C.sol",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, it was named like that in the input json.

@chriseth chriseth merged commit 1633e36 into develop Nov 8, 2021
@chriseth chriseth deleted the expose-parsingAndImporting branch November 8, 2021 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

absolutePath should be available for imports in the AST when using stopAfter: parsing
3 participants