Skip to content
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

Can we make taichi ignore annotation in annotated assignment when annotation is not a primitive type, or allow ti.template()/typing.Any to serve as a dummy annotation(without any compile-time or runtime effect, only edit-time effect for developer experience)? #6610

Closed
YouJiacheng opened this issue Nov 15, 2022 · 2 comments
Assignees

Comments

@YouJiacheng
Copy link

YouJiacheng commented Nov 15, 2022

With this we can improve developer experience leveraging the existing intelliSense(auto complete, jump to source, semantic highlight) infrastructure for Python.
Use case:

from typing import Generic, TypeVar

import taichi as ti
from taichi.lang.struct import StructType

T = TypeVar('T')

vec3 = ti.types.vector(3, ti.float32)
vec2 = ti.types.vector(2, ti.float32)

# make IntelliSense happy
class TypedStructType(Generic[T], StructType): ...

def ti_dataclass(cls: type[T]) -> TypedStructType[T]:
    return ti.dataclass(cls)

def typing(_: TypedStructType[T], obj) -> type[T]:
    return obj

@ti_dataclass
class Triangle:
    V0: vec3
    V1: vec3
    V2: vec3
TriangleT = typing(Triangle, ti.template())

@ti_dataclass
class TextureTriangle:
    V0: vec2
    V1: vec2
    V2: vec2
TextureTriangleT = typing(TextureTriangle, ti.template())

@ti_dataclass
class Primitive:
    position_triangle: Triangle
    texture_triangle: TextureTriangle
    material_index: ti.i32
PrimitiveT = typing(Primitive, ti.template())

@ti.func
def foo(p: PrimitiveT): # taichi allows ti.template() as argument annotation
    pos = p.position_triangle
    pos.V0
    pos2: TriangleT = p.position_triangle # taichi doesn't allow ti.template() as assignment annotation
    pos2.V0 # intelliSense enabled

image

Originally posted by @YouJiacheng in #2610 (comment)

@YouJiacheng
Copy link
Author

I attempted to use ast to remove annotations in assignments. But taichi doesn't support ast transformation extension, and always require source as input(doesn't allow AST input) for ti.func and ti.kernel.

@ailzhang
Copy link
Contributor

I guess this is pretty close to #6591 so let's track all the IDE experience progress there?
(feel free to reopen if I'm wrong)

Repository owner moved this from Backlog to Done in Taichi Lang Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants