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

Renaming idents, second stage: use proper renaming in scalc and Python #666

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

AltGr
Copy link
Contributor

@AltGr AltGr commented Aug 8, 2024

This completes (and builds on top of) #664 :
renaming is now in its own module, customisable enough, and called with the proper options for each backend. In particular, this simplifies the generated Python code, while being at the same time much more reliable.

  • the runtime idents used are still not registered as reserved names
  • no specific support for module names yet

@AltGr
Copy link
Contributor Author

AltGr commented Aug 8, 2024

CI fails because of a bug in the python printer, independent from this (an ident became longer, which triggered a line cut at a point that python doesn't like)

Copy link
Contributor

@vincent-botbol vincent-botbol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outputs look much better overall. The surrounding parenthesis in the generated python code is unfortunate but, at least, it works.

Same remark as for #664: I'm not sufficiently knowledgeable for super relevant remarks but based on the output, it looks good to me.

compiler/scalc/print.ml Outdated Show resolved Hide resolved
compiler/scalc/print.ml Outdated Show resolved Hide resolved
Base automatically changed from renaming to master August 28, 2024 15:18
AltGr and others added 9 commits August 28, 2024 18:10
it's not very satisfying, but we make it pass through renaming for now. A better
approach could be to make this special handling structural, or to have something
more specific than an id to hold onto.
Statements are often flattened, in which case their idents need to be
conflict-free. We pass along the renaming context to handle this.
matches can bind, but switches cannot, so we can assume the switch argument
should always be bound to a name ; this allow the intermediate variable to be
better renamed.
I can't find where the line cut triggering the error at
https://github.com/CatalaLang/catala/actions/runs/10304111306/job/28522272547?pr=666
came from:
```
/home/ocaml/french-law/_python_venv/lib/python3.12/site-packages/french_law/Aides_logement.py:27785:
error: invalid syntax  [syntax]
```

the file at this point contains:
```
    def traitement_aide_finale_montee_en_charge_saint_pierre_miquelon1(
        aide_finale4:Money):
→       traitement_aide_finale_montee_en_charge_saint_pierre_miquelon4 =
            handle_exceptions(
                [],
                []
            )
```

This workaround adds parens after `=`, which ensures the syntax will be correct.
@AltGr AltGr merged commit 78eaa16 into master Aug 28, 2024
5 checks passed
@AltGr AltGr deleted the renaming2 branch August 28, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants