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

absolutePath should be available for imports in the AST when using stopAfter: parsing #11756

Closed
cameel opened this issue Aug 6, 2021 · 0 comments · Fixed by #12199
Closed
Assignees
Labels
annoys users 😢 protocol design 🔮 Potential changes to ABI, meta data, standard JSON

Comments

@cameel
Copy link
Member

cameel commented Aug 6, 2021

Abstract

Tools should be using absolutePath from ImportDirective AST node for more reliable import resolution but it's not available when stopAfter: parsing option is used - even though that's when they need it the most.

Motivation

One of the uses case for stopAfter: parsing is to make it possible for tools to easily scan source files for imports. The raw path used in the import statement however is of limited utility - many tools are actually interested in a resolved path that can be used as a key in sources in Standard JSON. This resolution must account for relative imports and remappings and current compiler logic for doing that is full of unintuitive corner cases so it's easy to get it wrong. Doing it wrong, however, results in the compiler not being able to find the file matching the import where it expects it to be.

The compiler does make the resolved path available in the AST but it's not there yet when stopAfter: parsing setting is used.

Specification

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.

Backwards Compatibility

Making a previously unavailable AST key available is fully backwards-compatible.

Example showing the current output

With stopAfter: parsing

Input

{
    "language": "Solidity",
    "sources": {
        "/project/../C.sol": {"content": "import \"../L.sol\";"}
    },
    "settings": {
        "stopAfter": "parsing",
        "remappings": [":/project/=/lib/"],
        "outputSelection": {"*": {"": ["ast"]}}
    }
}

AST from the output

{
    "sources": {
        "/project/../C.sol": {
            "ast": {
                "absolutePath": "/project/../C.sol",
                "id": 2,
                "nodeType": "SourceUnit",
                "nodes": [
                    {
                        "file": "../L.sol",
                        "id": 1,
                        "nameLocation": "-1:-1:-1",
                        "nodeType": "ImportDirective",
                        "src": "0:18:0",
                        "symbolAliases": [],
                        "unitAlias": ""
                    }
                ],
                "src": "0:18:0"
            },
            "id": 0
        }
    }
}

Without stopAfter: parsing

Input

{
    "language": "Solidity",
    "sources": {
        "/project/../C.sol": {"content": "import \"../L.sol\";"},
        "/lib/L.sol": {"content": ""}
    },
    "settings": {
        "remappings": [":/project/=/lib/"],
        "outputSelection": {"*": {"": ["ast"]}}
    }
}

AST from the output

{
    "sources": {
        "/lib/L.sol": {
            "ast": {
                "absolutePath": "/lib/L.sol",
                "exportedSymbols": {},
                "id": 1,
                "nodeType": "SourceUnit",
                "nodes": [],
                "src": "0:0:0"
            },
            "id": 0
        },
        "/project/../C.sol": {
            "ast": {
                "absolutePath": "/project/../C.sol",
                "exportedSymbols": {},
                "id": 3,
                "nodeType": "SourceUnit",
                "nodes": [
                    {
                        "absolutePath": "/lib/L.sol",
                        "file": "../L.sol",
                        "id": 2,
                        "nameLocation": "-1:-1:-1",
                        "nodeType": "ImportDirective",
                        "scope": 3,
                        "sourceUnit": 1,
                        "src": "0:18:1",
                        "symbolAliases": [],
                        "unitAlias": ""
                    }
                ],
                "src": "0:18:1"
            },
            "id": 1
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annoys users 😢 protocol design 🔮 Potential changes to ABI, meta data, standard JSON
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants