looking for pointers for making a dotty phase

88 views
Skip to first unread message

Jeffrey Shaw

unread,
Aug 11, 2016, 10:34:27 PM8/11/16
to scala-internals
I've had an idea that classes (particularly, implicit classes) that can be AnyVals should always be AnyVals. It's something I've wanted to try adding to the compiler for fun, if nothing else. Now that dotty is becoming mature it seems like a good time to try.

I've poked around a bit, but could use some pointers. Is there another phase that's similar that I could use to learn from? Are there some good (simpler, or clearer) of traversing a class and determining if it conforms to some structure, or some simple transformation examples?

Thanks much!

Guillaume Martres

unread,
Sep 22, 2016, 6:04:43 AM9/22/16
to scala-i...@googlegroups.com, Jeffrey Shaw, dotty-i...@googlegroups.com, Dmitry Petrashko
Hi Jeffrey,

The scala-internals ML is reserved for discussing the scalac compiler, for
discussing dotty we have a dotty-internals mailing list (CC'd): https://
groups.google.com/forum/#!forum/dotty-internals as well as a gitter channel:
http://gitter.im/lampepfl/dotty

On jeudi 11 août 2016 19:34:27 CEST Jeffrey Shaw wrote:
> I've had an idea that classes (particularly, implicit classes) that can be
> AnyVals should always be AnyVals. It's something I've wanted to try adding
> to the compiler for fun, if nothing else. Now that dotty is becoming mature
> it seems like a good time to try.

There are some issues with this:
- Making a class a value class can change the behavior of your program, e.g:
def foo(x: AnyVal) = println("got AnyVal")
def foo(x: AnyRef) = println("got AnyRef")
foo(new C("x")) // output depends on whether C is a value class or not
- Making something a value class will not necessarily make your program faster
because value classes sometimes need to be boxed/unboxed and that overhead
might be significant.
- Value classes do not have an `eq` method, therefore you can only make a
class a value class if you're sure that `eq` is never called on it, this means
that you need to assume a closed world (your program is never going to be used
as a library by another program) and do some complicated analysis on your
whole program, there is no infrastructure in Dotty itself to do this, but this
exactly what the Dotty Linker does, for more information see:
"Dotty Linker: Making your Scala applications smaller and faster" (slides:
https://d-d.me/talks/scaladays2015/#/ video: https://www.parleys.com/tutorial/
making-your-scala-applications-smaller-faster-dotty-linker). The linker
currently lives at https://github.com/dotty-linker/dotty, if you're interested
in working on it you should contact Dmitry (CC'ed).

>
> I've poked around a bit, but could use some pointers. Is there another
> phase that's similar that I could use to learn from? Are there some good
> (simpler, or clearer) of traversing a class and determining if it conforms
> to some structure, or some simple transformation examples?

You may be interested in reading my thesis on implementing value classes in
Dotty: http://guillaume.martres.me/master_thesis.pdf


> Thanks much!

You're welcome!
Reply all
Reply to author
Forward
0 new messages