johnynek / bosatsu

A python-ish pure and total functional programming language
Apache License 2.0
222 stars 11 forks source link

Optimize if-matches case #1193

Closed johnynek closed 3 months ago

johnynek commented 3 months ago

the pattern:

if x matches p:
  trueCase
else:
  falseCase

was being compiled into:

b = match x:
  case p: True
  case _: False

match b:
  case True: trueCase
  case False: falseCase

rather than relying on optimization later, it's easy to detect this pattern while still at the source AST and directly convert to:

match x:
  case p: trueCase
  case _: falseCase
codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.66%. Comparing base (04a0e87) to head (479e241). Report is 23 commits behind head on main.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1193 +/- ## ========================================== + Coverage 91.32% 91.66% +0.34% ========================================== Files 96 96 Lines 11846 12070 +224 Branches 2675 2744 +69 ========================================== + Hits 10818 11064 +246 + Misses 1028 1006 -22 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.