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

Type inference module. PR #411 part 3/3 #439

Merged
merged 5 commits into from
Nov 17, 2020
Merged

Conversation

collinc97
Copy link
Collaborator

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.

@codecov
Copy link

codecov bot commented Nov 13, 2020

Codecov Report

Merging #439 (dafaa66) into master (0bc0ee4) will increase coverage by 1.11%.
The diff coverage is 86.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #439      +/-   ##
==========================================
+ Coverage   72.19%   73.31%   +1.11%     
==========================================
  Files         430      453      +23     
  Lines       12267    13467    +1200     
==========================================
+ Hits         8856     9873    +1017     
- Misses       3411     3594     +183     
Impacted Files Coverage Δ
compiler/src/errors/compiler.rs 17.14% <0.00%> (-1.61%) ⬇️
type-inference/src/errors/scope.rs 0.00% <0.00%> (ø)
type-inference/src/errors/variable_table.rs 0.00% <0.00%> (ø)
type-inference/src/errors/type_inference.rs 10.00% <10.00%> (ø)
type-inference/src/errors/type_assertion.rs 33.33% <33.33%> (ø)
type-inference/src/assertions/type_membership.rs 65.00% <65.00%> (ø)
type-inference/src/errors/frame.rs 71.57% <71.57%> (ø)
compiler/tests/syntax/mod.rs 53.33% <83.33%> (+7.50%) ⬆️
type-inference/src/objects/frame.rs 89.47% <89.47%> (ø)
type-inference/src/assertions/type_assertion.rs 91.30% <91.30%> (ø)
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0bc0ee4...dafaa66. Read the comment docs.

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.

None yet

2 participants