Skip to content

Conversation

@KRRT7
Copy link
Collaborator

@KRRT7 KRRT7 commented Jan 19, 2026

No description provided.

KRRT7 added 11 commits January 18, 2026 21:19
When LLM-generated optimizations use module-level code that depends on
functions defined later in the original file (e.g., `_TABLE = func(...)`),
the assignments were being inserted after imports but before the function
definitions, causing NameError at import time.

This fix:
- Adds NameCollector visitor to extract names from assignment values
- Tracks positions of function/class definitions in the module
- Inserts each assignment after all its dependencies are defined
- Assignments without dependencies still go after imports

Fixes optimization failures for functions like `standardize_quotes` that
use helper functions like `unicode_to_char` defined later in the file.
…ization results

Adds a new `codeflash create-pr` subcommand that creates PRs from
previously applied optimizations stored in a JSON results file.
This enables a two-phase workflow where optimizations are applied
locally first, then PRs can be created separately.
…n add_global_assignments

Previously, GlobalStatementCollector only collected SimpleStatementLine nodes,
causing module-level for-loops (and other compound statements) to be dropped.
This caused NameError for loop variables like 'uval', 'unicode_val', 'ch' when
LLM-generated optimizations used for-loops to build translation tables.

- Add compound statement collection to GlobalStatementCollector
- Update ImportInserter to handle both simple and compound statements
- Add tests for all reported NameError cases
For-loops and other compound statements at module level may call functions
defined later in the file. Previously, they were inserted after imports,
causing NameError when the called function was defined after the for-loop.

Now:
- Simple statements (assignments) are inserted after imports
- Compound statements (for/while/with/try) are inserted at the END of the module

This fixes NameError cases like 'unicode_to_char is not defined' when
LLM-generated optimizations use module-level for-loops to build translation
tables that call helper functions.
When LLM-generated optimizations introduce new helper functions that are
called at module level, these functions must be transferred to the original
code. Added FunctionDefCollector, FunctionNameCollector, and FunctionDefInserter
to detect and transfer new function definitions before assignments that depend
on them.
Capture test report summary and loop count during phase1 optimization
so the create-pr CLI can generate PR comments without re-running tests.
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.

2 participants