JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Annotate AST with types #308

Closed JSAbrahams closed 2 years ago

JSAbrahams commented 2 years ago

Relevant issues

implement #279

Summary

Annotate the output AST with types. It does this by noting the Position of types and storing their Name. This is because we do everything in a functional-ish manner: We can't just go around passing references to a single AST stored somewhere. Instead, we make use of the positions of AST nodes, and then in a final stage traverse the whole tree till we find all these positions and annotate them.

A traveral is then done of the AST to produce ASTTy with the Name at the correct position. A special NodeTy type had to be created.

In future, should have a session where I catalogue all encountered issues when I do enable annotation generation in output source. The source of some issues is not yet known, i.e.

Added Tests

Not much has been done in the way of testing since the output of the application has not been changed. This is inherently difficult code to test without testing for the sake of testing.

Perhaps good to in future add a test option to actually generated output src with annotations. That way, we can debug the checker as we go along, instead of doing this clumsily locally, reverting changes, and then pushing.

codecov[bot] commented 2 years ago

Codecov Report

Merging #308 (447c92a) into develop (befb939) will increase coverage by 0.43%. The diff coverage is 90.19%.

@@             Coverage Diff             @@
##           develop     #308      +/-   ##
===========================================
+ Coverage    86.12%   86.55%   +0.43%     
===========================================
  Files          101      104       +3     
  Lines        10038    10881     +843     
===========================================
+ Hits          8645     9418     +773     
- Misses        1393     1463      +70     
Impacted Files Coverage Δ
src/check/constrain/generate/control_flow.rs 90.78% <ø> (+8.64%) :arrow_up:
src/check/constrain/unify/ty.rs 68.88% <ø> (ø)
src/generate/name.rs 0.00% <0.00%> (ø)
src/parse/ast/mod.rs 100.00% <ø> (ø)
src/parse/ast/node.rs 79.24% <ø> (+0.11%) :arrow_up:
src/generate/convert/common.rs 93.75% <50.00%> (ø)
src/generate/convert/state.rs 94.23% <57.14%> (-5.77%) :arrow_down:
src/generate/convert/definition.rs 90.69% <68.75%> (-1.04%) :arrow_down:
src/generate/convert/ty.rs 77.27% <70.00%> (ø)
src/generate/convert/call.rs 84.61% <75.00%> (ø)
... and 31 more

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more