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

[FRONTEND] Keep pointer_type name and its __str__ in-sync. #3453

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

ttsugriy
Copy link
Contributor

This change ensures that name cannot get out of sync with __str__ and __repr__, since all of the fields are technically mutable and can be changed at any time. This also comes with a potential performance benefit of computing this f-string only once instead of computing it on each __str__/__repr__ invocation.

It would be even better to also to make this class immutable, but it's a separate story.

This change ensures that `name` cannot get out of sync with `__str__` and `__repr__`, since all of the fields are technically mutable and can be changed at any time. This also comes with a potential performance benefit of computing this f-string only once instead of computing it on each `__str__`/`__repr__` invocation.

It would be even better to also to make this class immutable, but it's a separate story.
@ttsugriy ttsugriy requested a review from ptillet as a code owner March 25, 2024 02:49
@ThomasRaoux
Copy link
Collaborator

I'm curious, when would the current code cause a problem?

@ttsugriy
Copy link
Contributor Author

ttsugriy commented Mar 25, 2024

I'm curious, when would the current code cause a problem?

in terms of correctness it would cause a problem if someone assigns some value to .name, since in such case .name and __str__ would return different results. Also, as I've mentioned it's always an unnecessary perf overhead.

Also, it's generally not a good idea to call any functions inside of constructor since due to virtual dispatch it's very hard to reason about class invariants.

@ThomasRaoux ThomasRaoux changed the title [core] Keep pointer_type name and its __str__ in-sync. [FRONTEND] Keep pointer_type name and its __str__ in-sync. Mar 25, 2024
@ThomasRaoux ThomasRaoux merged commit c3bcae7 into triton-lang:main Mar 25, 2024
5 checks passed
@ttsugriy ttsugriy deleted the patch-2 branch March 25, 2024 07:17
karupayun pushed a commit to openxla/triton that referenced this pull request Apr 3, 2024
…ng#3453)

This change ensures that `name` cannot get out of sync with `__str__`
and `__repr__`, since all of the fields are technically mutable and can
be changed at any time. This also comes with a potential performance
benefit of computing this f-string only once instead of computing it on
each `__str__`/`__repr__` invocation.

It would be even better to also to make this class immutable, but it's a
separate story.
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.

2 participants