Skip to content

Infer version #1047

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

Merged
merged 14 commits into from
Oct 1, 2024
Merged

Infer version #1047

merged 14 commits into from
Oct 1, 2024

Conversation

Janther
Copy link
Contributor

@Janther Janther commented Sep 27, 2024

The version inference works as follows:

  1. Slang is error-tolerant, so we can parse using any version.
  2. We read the pragma statements from the parsed output.
  3. We use the pragma statements to figure out the latest supported version.

Simple enough but when developing I encountered cases where:

  • slang would still throw when parsing
  • there are no pragma statements
  • the pragma statements is not a supported version

Therefore, to mitigate errors we calculate milestone versions which are the first and last patch versions of any minor version supported (0.8.26, 0.8.0, 0.7.6, 0.7.0, 0.6.12, 0.6.0, 0.5.17, 0.5.0, 0.4.26, 0.4.11).

Starting from the latest version, we attempt the original steps.
If there are errors or no pragma statement, we attempt with the next version (this will add a processing tax on older syntaxes)
If the pragma statement is not a supported version (e.g. 0.8.27), we assume the latest supported version.

Another albeit ridiculous thing that could happen is that a developer could add a random comment.

pragma solidity ^0.5.0 /* ^0.6.0 */ ^0.7.0;

To address this we use our own AST structure, to fetch the comments and replace them manually with empty space from the unparsed version range.

@Janther Janther requested a review from fvictorio September 27, 2024 04:57
@Janther
Copy link
Contributor Author

Janther commented Sep 27, 2024

I think that once we recover the pragmas we should go for the minSatisfyingVersion instead of the maxSatisfyingVersion. Any thoughts?

@Janther Janther merged commit 44a48ea into v2 Oct 1, 2024
7 checks passed
@Janther Janther deleted the infer-version branch October 1, 2024 03:45
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.

2 participants