Skip to content

Simplify how anonymous functions are parsed #314

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

Merged
merged 1 commit into from
Aug 5, 2025

Conversation

saulshanabrook
Copy link
Member

Updates the way that we handle passing higher order functions into egglog to remove some previous metaprogramming magic and replace it with a simpler algorithm that just removes any unbound variables left in a function and hoists them as args to the function.

Updates the way that we handle passing higher order functions into egglog
to remove some previous metaprogramming magic and replace it with a simpler
algorithm that just removes any unbound variables left in a function and hoists
them as args to the function.
@saulshanabrook saulshanabrook requested a review from Copilot August 5, 2025 19:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the handling of anonymous functions in egglog by replacing a complex metaprogramming approach with a more straightforward algorithm. The key change is removing the functionalize module and its complex introspection logic in favor of directly collecting unbound variables from function bodies and hoisting them as function arguments.

  • Removes the functionalize.py module and its complex metaprogramming approach
  • Adds a new collect_unbound_vars function to identify unbound variables in expressions
  • Updates function conversion logic to use direct variable collection instead of code introspection

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python/egglog/functionalize.py Entire file removed - contained complex metaprogramming logic for function transformation
python/tests/test_functionalize.py Entire test file removed along with the functionalize module
python/egglog/builtins.py Replaces functionalize usage with new direct variable collection approach in _convert_function
python/egglog/declarations.py Adds collect_unbound_vars utility function for identifying unbound variables
python/egglog/egraph.py Simplifies _fn_decl function signature and removes unnamed function logic
python/egglog/runtime.py Adds equality and hash methods to RuntimeFunction for comparison support
python/tests/test_high_level.py Adds test for new UnstableFn.eval() functionality
docs/changelog.md Documents the changes to anonymous function handling
Comments suppressed due to low confidence (1)

python/egglog/builtins.py:1100

  • The variable fn shadows the function parameter fn from line 1072. Consider renaming the local variable to something like runtime_fn or fn_obj to avoid confusion.
    fn = RuntimeFunction(Thunk.value(decls), Thunk.value(fn_ref))

Copy link

codspeed-hq bot commented Aug 5, 2025

CodSpeed WallTime Performance Report

Merging #314 will improve performances by 76.22%

Comparing reimplemention-tmp-fn (00d1b65) with main (3b41794)1

Summary

⚡ 2 improvements
✅ 5 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_jit[lda] 16.6 s 9.4 s +76.22%
test_jit[tuple] 998 ms 737 ms +35.41%

Footnotes

  1. No successful run was found on main (c1d8d81) during the generation of this report, so 3b41794 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link

codspeed-hq bot commented Aug 5, 2025

CodSpeed Instrumentation Performance Report

Merging #314 will not alter performance

Comparing reimplemention-tmp-fn (00d1b65) with main (c1d8d81)

Summary

✅ 7 untouched benchmarks

@saulshanabrook saulshanabrook merged commit 5aa044f into main Aug 5, 2025
22 checks passed
@saulshanabrook saulshanabrook deleted the reimplemention-tmp-fn branch August 5, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant