Type inference module. PR #411 part 3/3 #439
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part 3/3 for merging PR #411
Motivation
The type inference module resolves implicit types in a Leo program.
For a visual aid see https://github.com/AleoHQ/leo-semantics/blob/master/acl2/variable-environments.pdf
Each function in a Leo program is represented by a frame. Frames can store one or more type assertions which define an equality between a type and an expression. A new type assertion is created from each statement inside of a function. If a statement contains an unknown type, then a unique type variable is created for the type assertion.
After parsing all statements in a function, the frame's type assertions can be checked. Each unknown type variable is substituted for its expression type until all types are known. If any unknown types exist at the end of substitution, then the check fails indicating that the compiler cannot infer the type.
Test Plan
Unit tests have been added in the type inference module to test basic parsing and simple type inference errors.
Integration tests have been added in the compiler module to test generic leo program files and advanced type inference errors.