Adding typeinfer from grid.New statement. #1
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds type inference for the grid.New statement so that a grid’s dimensions become (Nx+1, Ny+1) based on the input list lengths.
- Updates the test to verify that grid.New returns a GridType with dimensions inferred from the input list lengths.
- Adjusts the grid.New statement signature to use type variables and introduces a new type inference method in _typeinfer.py.
- Registers the new type inference feature in the grid dialect initialization.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/grid/test_typeinfer.py | Adds a test to validate type inference of grid.New |
| src/bloqade/geometry/prelude.py | Introduces a typeinfer flag in the geometry DSL pass |
| src/bloqade/geometry/dialects/grid/stmts.py | Updates type annotations for spacing and result with type variables |
| src/bloqade/geometry/dialects/grid/_typeinfer.py | Implements type inference logic by computing grid dimensions based on input lengths |
| src/bloqade/geometry/dialects/grid/init.py | Registers TypeInferMethods in the grid dialect |
Comments suppressed due to low confidence (1)
src/bloqade/geometry/dialects/grid/stmts.py:29
- [nitpick] The type variable used for x_spacing ('NumXStep') and y_spacing ('NumYStep') is different from the result type variables ('NumX' and 'NumY'). Consider aligning these names to improve clarity and reduce potential confusion in type inference.
x_spacing: ir.SSAValue = info.argument(
type=ilist.IListType[types.Float, types.TypeVar("NumXStep")]
)
| class TypeInferMethods(MethodTable): | ||
|
|
||
| def get_len(self, typ: types.TypeAttribute): | ||
| if typ.is_subseteq(ilist.IListType[types.Int, types.Any]): |
There was a problem hiding this comment.
The get_len function checks for a list of integers while grid.New declares spacing as a list of floats. Verify that this discrepancy is intentional or update the types to ensure consistency in type inference.
Suggested change
| if typ.is_subseteq(ilist.IListType[types.Int, types.Any]): | |
| if typ.is_subseteq(ilist.IListType[types.Int, types.Any]) or typ.is_subseteq(ilist.IListType[types.Float, types.Any]): |
weinbe58
added a commit
that referenced
this pull request
May 9, 2025
* adding type infer for * making type check a bit tighter bound
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.
This PR implements the type inference from the
grid.Newstatement since the grid shape is equal to (Nx+1, Ny+1) where (Nx, Ny) comes from the input arguments.