Skip to content

Conversation

@Bersier
Copy link
Contributor

@Bersier Bersier commented Dec 15, 2025

Better handling of trivial ranges in distributeArgs.

Currently, distributeArgs immediately returns false for invariant type parameters when encountering a Range argument.

However, nothing currently disallows trivial ranges from being constructed (see paramInstances). In these cases, the range effectively represents a precise type.

Support trivial ranges in ApproximatingTypeMap.distributeArgs

Currently, `distributeArgs` immediately returns `false` for invariant type parameters when encountering a `Range` argument.

However, nothing currently prevents trivial ranges from being constructed (see `paramInstances`). In these cases, the range effectively represents a precise type.
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

The problem is that == is a meaningless test on types. Two types might be conceptually the same but not the same wrt ==. The semantically correct way to compare two types is via =:=. But that is too expensive and risks cycles.

Also == is potentially expensive since we have to traverse the two types. We can use eq instead of ==, at least that's cheap. But that should be used strictly for optimization not for something that might have semantic consequences. So, in summary I don't think this change is correct, nor is it feasible to make it correct.

@odersky odersky removed their assignment Dec 16, 2025
@Bersier
Copy link
Contributor Author

Bersier commented Dec 16, 2025

@odersky Thank you for taking a look. I don't have any personal stake in this, but I would like to understand, so I can do better next time.

Here is my current reasoning:

  1. Either the current logic does the right thing. In that case, my change (but with == replaced by eq) should not change the semantics in any way, since it also does the right thing (which is already partially done in other places by not creating a Range at all when the bounds are equal). It should only be an optimization, avoiding the triggering of more expensive fallbacks.
  2. Or the current logic doesn't always do the right thing, in which case it should be feasible to find a fix that is correct.

In both cases, I get a contradiction with your answer, so I'm clearly missing something. And that should be documented in the code, otherwise, places like this become unmaintainable by new contributors without constant supervision.

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