JSAbrahams / mamba

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

Rework Collections for `Expect` and `Name` #439

Closed JSAbrahams closed 1 year ago

JSAbrahams commented 1 year ago

Relevant issues

Summary

As has been a running theme for the past few days, this PR changes quite a lot more than originally intended. However, we had some sloppy code which I figured would be best to clean up now instead of laborously splitting it over many PR's. For now I see this a one in a set of major refactors, which for now is fine since I'm the only active developer. Best to just improve the quality of the codebase now and get rid of as many bugs as possible by generalizing the type system as much as possible. This includes getting rid of as much superfluous logic as possible.

Main change: Except::Collection to Expect::Call { ... }

Remove the collection Expect construct. Instead, we use generics now and substitution of generics to deal with unification of collections.

This greatly simplifies a lot of exceptions we had to make for collections. We also get to make use of type annotation logic now.

Secondary: Remove NameVariant

Instead, we just make use of Tuple[...] and Callable[Tuple[...],[...] by making helper methods which create these for us on the fly. Under the hood, it's always StringName. For now, I leave optionality untouched, so we don't make use of Optional[...], but instead have a boolean in TrueName.

This makes it much easier to match names directly and simplifies a lot of substitution logic within Name. The changes here don't affect the codebase outside of name too much, because most of it was abstracted away. But it does greatly reduce the chances of introducing a bug. And it also simplifies the unification stage even further.

To accomodate these changes, we also revamp the generic system:

Added Tests

TODO: list tests

JSAbrahams commented 1 year ago

Add issue that we should only override identifiers with Python type in:

codecov[bot] commented 1 year ago

Codecov Report

Merging #439 (cb8fb18) into develop (7d06ae2) will decrease coverage by 0.13%. The diff coverage is 85.27%.

@@             Coverage Diff             @@
##           develop     #439      +/-   ##
===========================================
- Coverage    88.59%   88.46%   -0.14%     
===========================================
  Files          110      107       -3     
  Lines        11956    11729     -227     
===========================================
- Hits         10593    10376     -217     
+ Misses        1363     1353      -10     
Impacted Files Coverage Δ
src/check/constrain/constraint/iterator.rs 84.61% <0.00%> (ø)
src/check/constrain/unify/mod.rs 75.00% <ø> (ø)
src/check/context/field/mod.rs 54.28% <ø> (ø)
src/generate/convert/control_flow.rs 90.25% <ø> (ø)
src/parse/lex/result.rs 14.28% <0.00%> (ø)
src/parse/result.rs 43.07% <0.00%> (ø)
src/check/result.rs 76.92% <33.33%> (+1.36%) :arrow_up:
src/generate/convert/ty.rs 57.14% <33.33%> (-12.25%) :arrow_down:
src/check/context/parent/mod.rs 42.85% <42.85%> (ø)
src/check/context/arg/generic.rs 76.54% <50.00%> (ø)
... and 71 more