Skip to content

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 14, 2024

No description provided.

@odersky odersky requested a review from hamzaremmal November 14, 2024 16:32
@hamzaremmal hamzaremmal self-assigned this Nov 14, 2024
def hasNext: Boolean
def next(): Int

trait ArrayIterator_Int extends ArrayIterator[Int], Iterator[Int]
Copy link
Member

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.

Suggested change
trait ArrayIterator_Int extends ArrayIterator[Int], Iterator[Int]
trait ArrayIterator_Int extends ArrayIterator[Int], Iterator_Int

Copy link
Contributor Author

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.

@odersky odersky force-pushed the specialized-traits-design branch from e550ab4 to 9daa075 Compare November 15, 2024 23:22
Copy link
Member

@kasiaMarek kasiaMarek left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
**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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

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.

4 participants