-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Specialized traits design draft #21950
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
base: main
Are you sure you want to change the base?
Conversation
def hasNext: Boolean | ||
def next(): Int | ||
|
||
trait ArrayIterator_Int extends ArrayIterator[Int], Iterator[Int] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky I've just tried it with 3.5.0 and it compiles fine with the following parents. But we agree that after erasure, we should have Iterator_Int
anyways.
trait ArrayIterator_Int extends ArrayIterator[Int], Iterator[Int] | |
trait ArrayIterator_Int extends ArrayIterator[Int], Iterator_Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it does not work if you replace both uses, the one here and the one that would map Seq[Int]
to Seq_Int
.
e550ab4
to
9daa075
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I was reading it, I added comments for typos and such.
@@ -0,0 +1,418 @@ | |||
# Specialized Traits and Classes | |||
|
|||
Specialization is one of the few remaining desirable features from Scala 2 that's are as yet missing in Scala 3. We could try to port the Scala 2 scheme, which would be non-trivial since the implementation is quite complex. But that scheme is problematic enough to suggest that we also look for alternatives. A possible alternative is described here. It is meant to complement the [proposal on inline traits](https://github.com/lampepfl/dotty/issues/15532). That proposal also contains a more detailed critique of Scala 2 specialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specialization is one of the few remaining desirable features from Scala 2 that's are as yet missing in Scala 3. We could try to port the Scala 2 scheme, which would be non-trivial since the implementation is quite complex. But that scheme is problematic enough to suggest that we also look for alternatives. A possible alternative is described here. It is meant to complement the [proposal on inline traits](https://github.com/lampepfl/dotty/issues/15532). That proposal also contains a more detailed critique of Scala 2 specialization. | |
Specialization is one of the few remaining desirable features from Scala 2 that are still missing in Scala 3. We could try to port the Scala 2 scheme, which would be non-trivial since the implementation is quite complex. But that scheme is problematic enough to suggest that we also look for alternatives. A possible alternative is described here. It is meant to complement the [proposal on inline traits](https://github.com/lampepfl/dotty/issues/15532). That proposal also contains a more detailed critique of Scala 2 specialization. |
|
||
## Expansion of Specialized Traits | ||
|
||
A type instance of a specialized trait such as Vec[Tp] has a special erasure, which depends on the specializing supertype of `Tp`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A type instance of a specialized trait such as Vec[Tp] has a special erasure, which depends on the specializing supertype of `Tp`. | |
A type instance of a specialized trait such as `Vec[Tp]` has a special erasure, which depends on the specializing supertype of `Tp`. |
|
||
**Definition**: A _simple class type_ is a reference to a static class that does not have type parameters. References to traits and references containing non-static prefixes or refinements are excluded. | ||
|
||
**Definition**: A top class is one of `Any`, `AnyVal`, or `Object`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Definition**: A top class is one of `Any`, `AnyVal`, or `Object`. | |
**Definition**: A _top class_ is one of `Any`, `AnyVal`, or `Object`. |
1. _Inline traits._ With them one can create specialized modules and classes, but no specialization on type parameters is possible. Inline traits also enable new patterns for meta programming. | ||
2. _Specialized traits and classes._ With them one can create class hierarchies that can require and exploit statically known type parameters. | ||
3. _Specialized overloads and path splitting_. With these additions one can create structures that can take advantage of statically known type parameters when they are available while still working for other type parameters as well. They also allow retro-fitting specializaton to existing libraries. | ||
4. _Hand-written specializations_. They allow to make use-defined algorithmic optimizations based on statically known type parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4. _Hand-written specializations_. They allow to make use-defined algorithmic optimizations based on statically known type parameters. | |
4. _Hand-written specializations_. They allow to make user-defined algorithmic optimizations based on statically known type parameters. |
No description provided.