Skip to content

Refactored Type Checking and Analysis Annotations #13365

@ekpyron

Description

@ekpyron

What

Make type checking robust against several invocations (creation mode; runtime mode), as well as out-of-order execution, even in the presence of cycles.

Why

To enable compile-time constant expression evaluation and the code data location, as well as making support of generics easier in the future.

What

Currently, the Solidity AST is const after parsing and then annotation()-annotated by the analysis steps in CompilerStack::analyze.

However, some AST nodes and some Types have interfaces that implicitly depend on annotations. (e.g. for types: ContractType::stateVariables, StructType::nativeMembers; e.g. for AST nodes: StructDefinition::type, VariableDeclaration::hasReferenceOrMappingType, etc.).

In the past we regularly had ICEs due to such implicit dependencies. That has gotten better recently, but it's still an easy source of error.

This issue is going to get worse, once we want to move to compile-time constant expression evaluation since this will probably entail switching multiple analysis steps to simultaneous cycle-resistant lazy-evaluation.

Furthermore we need to evaluate additional requirements looking ahead to type checking in the presence of future generics.

So we need to come up with a nicer way to:

  • Make all implicit dependencies of AST node and Type interfaces explicit. If possible, even syntactically prohibit errors (as in "too early use").
  • Make the relevant parts of type checking and analysis procedure robust against out-of-order lazy evaluation.
    • Since array lengths should be allowed to be calculated using compile-time constant expressions, this at least entails DeclarationTypeChecker and TypeChecker, with implicit interactions with ContractLevelChecker.

Notes

Metadata

Metadata

Labels

epic effortMulti-stage task that may require coordination between team members across multiple PRs.high impactChanges are very prominent and affect users or the project in a major way.needs designThe proposal is too vague to be implemented right awayrefactorselected for developmentIt's on our short-term development

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions