fix[next]: lower function definitions to let bindings - #2905
Open
tehrengruber wants to merge 2 commits into
Open
tehrengruber wants to merge 2 commits into
tehrengruber wants to merge 2 commits into
Conversation
`InlineFundefs` replaced every `SymRef` matching a program-level function definition, regardless of any binder of the same name in between. A lambda parameter named like a function definition was therefore silently replaced by that function, producing an ill-typed program (e.g. an `AssertionError` in `type_synthesizer._canonicalize_nb_fields`). Instead of substituting references, bind all function definitions in a `let` wrapping every statement expression. Regular scoping rules then apply, i.e. an inner binder shadows the function definition, and unused bindings are removed by dead code elimination, which makes the separate `prune_unreferenced_fundefs` pass obsolete.
Contributor
Author
|
|
The traced `flux` function definition is polymorphic in its parameter `d`, it is called with an `I` and a `J` offset. Type inference can not type a `let` bound function used at several types, which the function definitions are lowered to now. Dropping the `fundef` decorator makes tracing inline `flux` as a lambda instead, which keeps the test unchanged otherwise.
havogt
self-requested a review
September 23, 2026 09:00
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InlineFundefsreplaced everySymRefmatching a program-level function definition, regardless of any binder of the same name in between. A lambda parameter named like a field operator was therefore silently replaced by that function, producing an ill-typed program (e.g. anAssertionErrorintype_synthesizer._canonicalize_nb_fields).Instead of substituting references, all function definitions are now bound in nested
lets wrapping every statement expression, andProgram.function_definitionsis cleared. Regular scoping rules then apply, i.e. an inner binder shadows the function definition, and unused bindings are removed by dead code elimination, which makes the separateprune_unreferenced_fundefspass obsolete. Thelets are nested in topological order since function definitions may call each other.Follow-up to #2833 (comment), where tuple-comprehension targets made this easy to hit.
AI disclaimer: This PR has been created with the help of AI tools. The code has been reviewed, but tests were only briefly sighted.