Skip to content

Fix range type conversions and collection casting in V#475

Open
yaskhan wants to merge 5 commits into
mainfrom
fix-range-type-conversions-3409471699143022295
Open

Fix range type conversions and collection casting in V#475
yaskhan wants to merge 5 commits into
mainfrom
fix-range-type-conversions-3409471699143022295

Conversation

@yaskhan
Copy link
Copy Markdown
Owner

@yaskhan yaskhan commented Mar 19, 2026

This PR fixes two specific transpilation issues in test_range_type.py: invalid casting of an array ([]int) to a map (set) and invalid direct casting of []int to []Any in V.

Key changes:

  1. Generic Helpers: Added py_list_cast and py_set_from_list in module.py and registered them in main.py to handle collection conversions properly in V.
  2. Built-in Logic: Updated calls_builtin.py to use these helpers. Improved type inference for set() to avoid defaulting to map[string]bool when the input is a range or a typed array.
  3. Tuple Optimization: Updated v_types.py to map homogeneous tuples to fixed-size V arrays (e.g., [2]int) while maintaining struct-based mapping for heterogeneous ones.
  4. Deduplication: Enhanced VCodeEmitter to deduplicate structs and functions, preventing compilation errors when multiple parts of the transpiler register the same type.
  5. Regressions: Fixed several test failures in test_type_syntax_fixes.py and test_union_types.py related to type registration and emission.

All 658 transpiler tests passed.


PR created automatically by Jules for task 3409471699143022295 started by @yaskhan

- Introduced generic V helpers `py_list_cast<T>(...)` and `py_set_from_list<T>(...)` to handle conversions from iterables (like `range`).
- Updated `BuiltinCallsMixin` to use these helpers instead of invalid direct V casts.
- Enhanced type inference for `set(arg)` to correctly identify key types for range and typed array arguments.
- Optimized tuple mapping in `v_types.py` to use fixed-size arrays for homogeneous members while retaining struct-based mapping for heterogeneous members.
- Implemented deduplication for structs and functions in `VCodeEmitter` to prevent redundant declarations in the generated code.
- Fixed regressions in `SumType` and `TupleStruct` emission for unit tests.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 4 commits March 19, 2026 04:21
- Restored tuple mapping in `v_types.py` to use fixed-size arrays for homogeneous members and structs for heterogeneous members to satisfy existing tests.
- Reverted `SumType` and `TupleStruct` registration to use `add_struct` instead of `add_helper_struct` to ensure they are emitted in the main module output.
- Implemented robust deduplication for structs and functions in `VCodeEmitter`.
- Enhanced `set()` built-in handler to correctly infer `map[int]bool` for range arguments by improving type guessing logic.
- Cleaned up narrowing logic in `names.py` and removed temporary debug files.
- Verified that all 661 transpiler tests pass.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
- Optimized collection conversions from range using `py_list_cast` and `py_set_from_list`.
- Improved type inference for `set()` with range arguments.
- Restored and optimized tuple mapping in `v_types.py`.
- Fixed type registration regressions and implemented deduplication in `VCodeEmitter`.
- Cleaned up redundant narrowing casts and updated tests accordingly.
- All 664 tests pass.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
- Resolved Mypy static analysis errors in `v_types.py` and `calls_builtin.py`.
- Fixed a bug in `set()` transpilation that caused invalid direct V casts.
- Optimized collection conversions from range using `py_list_cast` and `py_set_from_list`.
- Improved type inference for `set()` with range arguments by enhancing type guessing.
- Restored and optimized tuple mapping to support PEP 695 and satisfy existing tests.
- Implemented robust deduplication for structs and functions in `VCodeEmitter`.
- Cleaned up redundant narrowing casts and verified all 664 tests pass.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
- Resolved Mypy static analysis errors in `v_types.py` and `calls_builtin.py`.
- Fixed invalid direct V casts for `set()`, `list()`, and `tuple()` by using generic helpers.
- Implemented `py_list_cast` and `py_set_from_list` V helpers in `module.py`.
- Improved type inference for `set()` with range and typed array arguments.
- Optimized tuple mapping to use fixed-size arrays for homogeneous members while retaining struct-based mapping for heterogeneous members.
- Implemented robust deduplication for structs and functions in `VCodeEmitter`.
- Cleaned up redundant narrowing casts in `names.py` and `attributes.py`.
- Updated tests to align with improved code generation.
- Verified all 664 tests pass.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
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