exo-lang / exo

Exocompilation for productive programming of hardware accelerators
https://exo-lang.dev
MIT License
307 stars 28 forks source link

Distinguish type error from name error in pyparser #733

Closed akeley98 closed 1 month ago

akeley98 commented 1 month ago

Previously, when parse_expr failed to resolve a name to a value, it always reported "undefined variable" errors regardless of whether the cause was due to failing to look up the name in the global/local scope, or due to correctly looking up the name but the value not being a valid type (e.g. the name resolving to a str value). I changed the parser to distinguish these 2 cases in the error message (see the new tests I added to see what I mean).

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 70.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 88.00%. Comparing base (2c31b61) to head (206f1e2). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_uast.py 68.42% 12 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #733 +/- ## ========================================== - Coverage 88.01% 88.00% -0.01% ========================================== Files 86 86 Lines 20928 20965 +37 ========================================== + Hits 18419 18450 +31 - Misses 2509 2515 +6 ```

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

akeley98 commented 1 month ago

Not sure if I'm understanding codecov correctly, but it's mad that the new tests are not themselves tested?

akeley98 commented 1 month ago

I was emulating the existing tests in test_uast.py which lack @proc

akeley98 commented 1 month ago

Yes, they are

mantissa@MantissaAmpere:~/Documents/exo$ pytest -v tests/test_uast.py                       
=================================== test session starts ====================================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/mantissa/Documents/exo
configfile: pyproject.toml
collected 6 items                                                                          

tests/test_uast.py::test_conv1d PASSED                                               [ 16%]
tests/test_uast.py::test_unary_neg PASSED                                            [ 33%]
tests/test_uast.py::test_alloc_nest PASSED                                           [ 50%]
tests/test_uast.py::test_variable_lookup_positive PASSED                             [ 66%]
tests/test_uast.py::test_variable_lookup_type_error PASSED                           [ 83%]
tests/test_uast.py::test_variable_lookup_name_error PASSED                           [100%]

===================================== warnings summary =====================================
tests/conftest.py:2
  /home/mantissa/Documents/exo/tests/conftest.py:2: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    import distutils.spawn

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================== 6 passed, 1 warning in 0.06s ===============================

Looking at the report, it is just flagging the test functions that are passed to the uast parser (since the funcs are defined only for their AST, they are not actually executed).