-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add an immutable array type #5885
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
Conversation
a96c5a3
to
1783f42
Compare
Btw, the first lines of |
|
||
val xs = IArray(1, 2, 3) | ||
|
||
def f[T](ys: IArray[T]) = { |
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.
What type does this method erase to? f(ys: Array[AnyRef])
? Or f(ys: AnyRef)
?
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.
No, it's Object
. Just what Array[T]
erases to.
I tried to make opaque type IArray[+T] = Array[_ <: T] Unfortunately, that runs into problems when it comes to class tags. I get:
Indeed, there's no way to create an |
That shouldn't matter outside of the companion of |
1783f42
to
f0eb2bb
Compare
@sjrd Right. After adding some casts in iArray's implementation, I could make them covariant, after all. 👍 |
1e8f916
to
4f98732
Compare
tests/pos/covaraint-opqaue.scala
Outdated
@@ -0,0 +1,3 @@ | |||
import annotation.unchecked.uncheckedVariance |
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.
Typo in the file name: “covariant-opaque.scala”
val bs: IArray[Double] = IArray(1.0, 2.0) | ||
val cs: Array[Double] = bs.asInstanceOf[Array[Double]] | ||
cs(1) = 3.0 | ||
assert(bs(1) == 3.0) |
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.
Can we also check that apply
and update
don’t box elements?
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.
That's harder. I believe there are ways to test it, but I don't know them. The fact that apply
is an inline method means it is literally replaced by its right-hand side, so by the rules of inlining there can't be any boxing. I verified the code after erasure by looking at it to make sure that's the case.
bbca7f0
to
c7b0651
Compare
Community build fails with:
|
Are the changes to the community build submodules in c7b0651 intentional? |
Unary extension methods are inlined before the end of `extMethodApply`. Have to take this into account when checking that the call is to an extension method.
IArray[T] is an opaque alias for Array[T]
This gives us the right error message if we try to instantiate an hk opaque type with `new`.
Also, add `empty` method.
c7b0651
to
c532d3e
Compare
@OlivierBlanvillain No, I discovered my error: pushed wrong submodule hashes. |
Need to drop the explicit result type since apparently Array's unapplySeq type is different between 2.12 and 2.13.
a8b794c
to
b9decdc
Compare
Going to merge this now, to avoid further breakage by fast-moving infrastructure changes. |
So far, it's called
scala.IArray[T]
. I am not super happy with the name but could not come up with anything better yet.It's an opaque alias of
Array[T]
that only exposes theapply
andlength
methods.Still missing: Wrappers that add all sequence ops to IArrays. We should upgrade to the new collections before we do this.