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

refactor[next]: use eve.datamodel for types #1750

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

havogt
Copy link
Contributor

@havogt havogt commented Nov 26, 2024

No description provided.

@@ -108,7 +108,7 @@ def visit_Subscript(self, node: past.Subscript, **kwargs: Any) -> past.Subscript
value = self.visit(node.value, **kwargs)
return past.Subscript(
value=value,
slice_=self.visit(node.slice_, **kwargs),
slice_=node.slice_, # TODO: I don't think we are using this type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
slice_=node.slice_, # TODO: I don't think we are using this type
slice_=node.slice_,

check and remove

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have a type for past.Slice, but the visit here also types & validates its children (e.g 1+1. in a slice bound would error here). For that reason I consider unconditionally visiting all children a good approach. The role of ts.DeferredType and None in the type system is however not well specified. I would postpone that discussion to the point where we also have time to think about generics / "templated" / partial types, because the discussion is related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are you proposing to do? Accept None in TupleType elements, this proposed solution or add visit_Slice and return DeferredType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I overlooked that slice_ is a tuple of slices (maybe the attr name is not so great?). visit_Slice with DeferredType makes sense to me even though this would add another violation of all-type-attrs-of-types-are-concrete rule of a ts.TypeSpec. Otherwise introduction of a slice type makes sense to me too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 99 to 101
# TODO: or DimensionType is a DataType
types: list[DataType | DimensionType | DeferredType]
# TODO validate DeferredType constraints
Copy link
Contributor Author

Choose a reason for hiding this comment

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

check this

@havogt havogt requested a review from tehrengruber November 26, 2024 21:38
@havogt havogt requested a review from egparedes November 26, 2024 21:43
src/gt4py/next/type_system/type_specifications.py Outdated Show resolved Hide resolved
@@ -108,7 +108,7 @@ def visit_Subscript(self, node: past.Subscript, **kwargs: Any) -> past.Subscript
value = self.visit(node.value, **kwargs)
return past.Subscript(
value=value,
slice_=self.visit(node.slice_, **kwargs),
slice_=node.slice_, # TODO: I don't think we are using this type
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have a type for past.Slice, but the visit here also types & validates its children (e.g 1+1. in a slice bound would error here). For that reason I consider unconditionally visiting all children a good approach. The role of ts.DeferredType and None in the type system is however not well specified. I would postpone that discussion to the point where we also have time to think about generics / "templated" / partial types, because the discussion is related.

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

LGTM. Just a couple of questions.

src/gt4py/next/iterator/type_system/inference.py Outdated Show resolved Hide resolved
return constraint
case ts.TypeSpec() as concrete_type:
return concrete_type.__class__
if isinstance(symbol_type, ts.DeferredType):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: why move away from the match pattern matching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed, datamodels don't implement __match_args__


def __init_subclass__(cls) -> None:
cls.__hash__ = TypeSpec.__hash__ # type: ignore[method-assign]
class TypeSpec(eve_datamodels.DataModel, kw_only=False, frozen=True): ... # type: ignore[call-arg]
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous implementation used a custom hash definition which would work even for non frozen classes and classes with mutable attributes (e.g. lists). I think that was made just for convenience, because it doesn't follow the python semantics for hash, but the new implementation doesn't replicate the previous behavior. How does it work? It is not really needed to hash instances with mutable attributes like lists or none of the subclasses contains mutable attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since there is no issue (in our tests), I assume it's fine.

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