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

test convertible var + range conv logic #24036

Closed
wants to merge 1 commit into from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Aug 31, 2024

closes #24032

The var match change is likely to break code but so is the potentially buggy new behavior for range types being considered the same for conversions/the backend

The var change straight up breaks +=, *= etc for range types, making them work again individually seems counterproductive and is hard because we can't just match on any range type, the base type needs to be constrained too, which there is no way to express in the core language afaik

errmsgs/t22097 needs error message change

@metagn
Copy link
Collaborator Author

metagn commented Aug 31, 2024

Yeah basically all the failures are from the var change for range as described in #24032, mostly +=, json deserialization, atomicInc.

Also the same failure from #23176 by normalize is encountered again by var int32 not matching var int.

I can easily split the sameType/isAssignable changes to another PR so that variables like var x: range can be converted to var int like int(x) *= 2, I'm not sure how good the code is though.

For the var match changes, we could add the new logic except still allow isSubrange, and maybe disallow isSubrange behind a preview define? It feels like something people might want for strictness but it might be too annoying for others which I don't know what we normally use for.

@Araq
Copy link
Member

Araq commented Aug 31, 2024

Sure make it opt-in for the next version, then opt-out for the version after that.

@metagn
Copy link
Collaborator Author

metagn commented Aug 31, 2024

Split between #24037 and #24038

@metagn metagn closed this Aug 31, 2024
Araq pushed a commit that referenced this pull request Sep 3, 2024
…24037)

refs #24032, split from #24036

Conversion from variables of range types or base types of range types to
the other are now considered mutable for `var` params, similar to how
distinct types are mutable when converted to their base type or vice
versa. There are 2 main differences:

1. Conversions from base types to range types need to emit
`nkChckRange`, which is not generated for things like tuple/object
fields.
2. Range types can still correspond to different types in the backend
when nested in other types, such as `set[range[3..5]]` vs
`set[range[0..5]]`.

Since the convertibility check for `var` params and a check whether to
emit a no-op for `nkConv` (and now also `nkChckRange`) so that the
output is still addressable both use `sameType`, we accomplish this by
adding a new flag to `sameType` that ignores range types, but only when
they're not nested in other types. The implementation for this might be
flawed, I didn't include children of some metatypes as "nested in other
types", but stuff like `tyGenericInst` params are respected.
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.

Unexpected behavior with range types and custom operators
2 participants