Skip to content

[eudsl-python-extras] support types as GenericAlias for input arg annotations#356

Merged
makslevental merged 1 commit into
mainfrom
users/makslevental/generic_alias
Mar 9, 2026
Merged

[eudsl-python-extras] support types as GenericAlias for input arg annotations#356
makslevental merged 1 commit into
mainfrom
users/makslevental/generic_alias

Conversation

@makslevental
Copy link
Copy Markdown
Contributor

@makslevental makslevental commented Mar 8, 2026

This PR adds support for using the upstream types as bare arg annotions for func.funcs:

@func
def f_same_type_args(
    x: RankedTensorType[[2, 3], F32Type],
    y: RankedTensorType[[2, 3], F32Type],
) -> RankedTensorType[[2, 3], F32Type]: ...

emits

func.func private @f_same_type_args(tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>

This is thanks to a PR @PragmaTwice recently landed upstream (I can't remember which one exactly...).

As well, we now support the completely "correct" version of this:

@func
def f_mixed_args(
    a: Value[F32Type],
    b: Value[VectorType[[4], F32Type]],
    c: Value[MemRefType[[2, 3], F32Type]],
):
    return b

where tab-complete will now actually do the correct thing as well, and the IR emitted is

func.func @f_mixed_args(%[[A:.*]]: f32, %[[B:.*]]: vector<4xf32>, %[[C:.*]]: memref<2x3xf32>) -> vector<4xf32>

This is thanks to a PR @superbobry landed recently.

NOTE: this actually fixes a long-standing issue with the bindings/extras/DSL: namely that you could not write @funcs without having an active ir.Context (because you cannot actually instantiate ir.Type without an active ir.Context). Since these GenericAliases are unevaluated until we actually emit the func.func, we can now write these safely without an active context.

Comment on lines +851 to +862
def test_reinterpret_cast_zero_sized_to_dynamic(ctx: MLIRContext):
input = alloc((0,), T.f32())
c0 = constant(0, index=True)
c1 = constant(1, index=True)
reinterpret_cast(input, offsets=[c0], sizes=[c1], strides=[c1])

# CHECK: %[[ALLOC:.*]] = memref.alloc() : memref<0xf32>
# CHECK: %[[C0:.*]] = arith.constant 0 : index
# CHECK: %[[C1:.*]] = arith.constant 1 : index
# CHECK: %[[OUT:.*]] = memref.reinterpret_cast %[[ALLOC]] to offset: [%[[C0]]], sizes: [%[[C1]]], strides: [%[[C1]]] : memref<0xf32> to memref<?xf32, strided<[?], offset: ?>>

filecheck_with_comments(ctx.module)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unrelated but just a test I forgot to check in here

@makslevental makslevental force-pushed the users/makslevental/generic_alias branch from 7924540 to 0f09728 Compare March 8, 2026 21:48
@makslevental makslevental requested a review from rolfmorel March 8, 2026 21:51
@makslevental makslevental force-pushed the users/makslevental/generic_alias branch 6 times, most recently from 969aec6 to f9f3d40 Compare March 8, 2026 22:03
@makslevental makslevental requested a review from Copilot March 8, 2026 22:03
@makslevental makslevental force-pushed the users/makslevental/generic_alias branch from f9f3d40 to b100fd6 Compare March 8, 2026 22:09

This comment was marked as resolved.

@makslevental makslevental force-pushed the users/makslevental/generic_alias branch from b100fd6 to 76fa66e Compare March 8, 2026 22:25
@makslevental makslevental merged commit 1227b63 into main Mar 9, 2026
20 checks passed
@makslevental makslevental deleted the users/makslevental/generic_alias branch March 9, 2026 01:50
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.

3 participants