-
-
Notifications
You must be signed in to change notification settings - Fork 35
Fix mutual recursion support in type inference #525
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
base: dev
Are you sure you want to change the base?
Conversation
Co-authored-by: nielstron <[email protected]>
Co-authored-by: nielstron <[email protected]>
Co-authored-by: nielstron <[email protected]>
✅ Binary Size Check PassedBinary Size Comparison ReportNo significant binary size changes were detected in this PR. This report compares the binary sizes of compiled contracts against the baseline from the latest release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the approach looks sounds. But it needs to be more general to handle all possible settings.
Formatting seems invalid too. Run black to format the files correctly.
|
Note that a proper fix for #522 requires this fix too. |
It seems that the compiler does not correctly handle this though
|
@copilot can you look at my changes and take it from there? |
…d test cases for nested functions and classes Co-authored-by: nielstron <[email protected]>
Addressed the generality concerns by accepting @nielstron's refactor to visit_sequence() and added test cases for nested functions and classes. Fixed formatting and removed unrelated changes in commit f7d9d20. |
This PR fixes mutual recursion support in OpShin by implementing a two-pass type inference approach that works for all function scopes.
Problem
Previously, mutual recursion would fail to compile because the type inference system processed functions sequentially. When an earlier function tried to call a later-defined function, the later function wasn't yet in scope:
Solution
Implemented a two-pass approach in
AggressiveTypeInferencer.visit_sequence():This ensures that all function names are available before any function bodies are processed, enabling mutual recursion at any scope level.
Key Features
Test Coverage
Added comprehensive test cases covering:
The fix handles various mutual recursion scenarios while maintaining full backward compatibility with existing code.
Fixes #524.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.