dart-lang / dart-lang/language
Consider using bounds information when computing the greatest closure
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Several issues have been filed calling out the fact that the [greatest closure computation](https://github.com/dart-lang/language/blob/main/resources/type-system/inference.md#type-variable-elimination-least-and-greatest-closure-of-a-type) does not take into account the bounds on type parameters. That is, when computing the greatest closure of a type variable `T`, we always choose `Object?` as the closing type, even if `T` was declared with a more precise bound. This extends to taking the greatest closure of a type with respect to the unknown types `_` as well (this is the common case in the algorithm, and the source of the motivating examples). See #1761 and #3567 for motivating examples for the `_` case. A motivating example for the type variable case would, I believe, be more esoteric.
It seems plausible that we could instead choose to use the bound of `T` to replace `T` when computing the greatest (but not least) closure. Similarly, if we associated with each unknown type `_` the bound of the type variable from which it was produced, we could choose to replace `_` with a more precise type when computing the greatest closure. Assuming this all works out, this would possibly help with examples like the ones referenced above.
cc @dart-lang/language-team
Contributor guide
Research direction
Start with the greatest-closure section of resources/type-system/inference.md, then read issues #1761 and #3567 for the motivating unknown-type cases. Determine whether bounds can safely guide greatest closure for both type variables and unknown types, and validate the result against those examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100