#1 Merged at 244a7f0
  1. Stephen Compall

DynamicF is used in a lot of places in remote.Format because type synonyms are always expanding, leading to an explosion of type information, especially for formats that are expanded over and over, leading scalac to try to generate invalid classfiles.

This uses abstract singleton format types to "erase" format information after it's been used to verify that a Reader and Writer are consistent. This also has the effect of preventing expansion of formats; that is, in error messages, they remain their singleton-dependent F types without expansion.

The biggest benefits are to be had from erasing more primitive formats; note below how much erasing PrimExprF saved, despite that most of its expansions had already been erased unsafely with DynamicF.

Change ErmineFormat$.class Format$.class total remote directory
before 26950 199078 1232k
Op 26950 200011 1248k
PrimExpr 26950 166019 1204k
PrimT 25942 163808 1196k
Ext 25908 162280 1204k
Predicate 25908 162809 1204k
WFormat 25908 157530 1196k
Relation 25908 139610 1216k
SM 25908 139697 1216k
ProcessSymbol 25908 140099 1216k
Agg/Mem 25908 122661 1224k
RLevel/MLevel 25908 122725 1224k
no more dyn 25908 122118 1216k

These were derived with

$ java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
$ uname -a
Darwin ... 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

There was another interesting benefit: the erasure means that full mutual and polymorphic recursion of codecs (the latter via higher-kinded existentials like CodecPair2) can be safely described, because the [infinite] type no longer expands. This also obviates FixF generally, but I haven't done that. So this change removes all use of DynamicF and erase.

This also fixes a bug where Relation reading didn't implement one of the writing cases, which was found by the use of its proper Format instead of DynamicF.

I haven't built everything, because utilJavafx doesn't build on Java 8. There might be a few things in htmlWriter that won't compile, either needing more type parameters (e.g. extW) or not calling erase. I also don't know whether you'd want to do this in scala-2.9.2, but it should work if you do.

Comments (0)