Skip to content

Instantly share code, notes, and snippets.

View nicolasstucki's full-sized avatar
🌴
On vacation

Nicolas Stucki nicolasstucki

🌴
On vacation
  • LAMP / EPFL
  • Switzerland
View GitHub Profile
This file has been truncated, but you can view the full file.
dotty.tools.backend.jvm.DottyBackendInterface::symHelper (10 bytes) inlining too deep
dotty.tools.backend.jvm.DottyBackendInterface::symHelper (10 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned$$Lambda$756/146107826::get$Lambda (9 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::contains (81 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
dotty.tools.dotc.ast.Positioned::pos (5 bytes) inlining too deep
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
"","","","","","","",""
"Exclusive","Inclusive","Exclusive Instructions","Exclusive","Exclusive CPU","Exclusive L3","Exclusive L1","Name"
"Total CPU Time","Total CPU Time","Per Cycle","Instructions Executed","Cycles Time","Cache Misses","D-cache Misses",""
"V (sec.)"," (sec.)"," "," "," "," "," "," "
"941.469","941.469","1.233","820593220611","831.809","479198042","5965260856","<Total>"
"66.026","66.026","1.999","68853512104","43.053","200202","35211009","dotty.tools.dotc.core.Types$ParamRef.underlying(dotty.tools.dotc.core.Contexts$Context)"
"31.462","31.462","1.476","2468979130","2.091","0","3200998","sched_yield"
"24.137","174.012","1.407","5117160176","4.547","1367576","26163721","dotty.tools.dotc.core.SymDenotations$ClassDenotation.collect$1(dotty.tools.dotc.core.Names$Name, dotty.tools.dotc.core.Contexts$Context, dotty.tools.dotc.core.Denotations$PreDenotation, dotty.tools.dotc.core.Denotations$PreDenotation, scala.collection.immutable.List)"
"23.036","31.202","1.215","21814153330","22.43
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 10.
"","","","","","","","",""
"Exclusive","Inclusive","Exclusive Instructions","Exclusive Cycles","Exclusive","Exclusive CPU","Exclusive L3","Exclusive","Name"
"Total CPU Time","Total CPU Time","Per Cycle","Per Instruction","Instructions Executed","Cycles Time","Cache Misses","DTLB Misses",""
"V (sec.)"," (sec.)"," "," "," "," "," "," "," "
"1431.842","1431.842","1.157","0.864","1268421578129","1370.584","882869123","662882619","<Total>"
"815.330","815.330","1.214","0.824","757521873525","780.231","503144433","273962039","<JVM-System>"
"205.033","205.033","1.052","0.950","170526483591","202.564","84820085","101125893","<no Java callstack recorded>"
"7.465","8.176","1.279","0.782","7042200705","6.882","5739586","1001309","dotty.tools.dotc.core.Flags$FlagSet$.$bar$extension(long, long)"
"6.214","7.735","0.917","1.090","2722306500","3.709","1901922","3156944","java.lang.ClassLoader.defineClass1(java.lang.String, byte[], int, int, java.security.ProtectionDomain, java.lang.String)"
"5.134","91.114","
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 10.
"","","","","","","","",""
"Exclusive","Inclusive","Exclusive Instructions","Exclusive Cycles","Exclusive","Exclusive CPU","Exclusive L3","Exclusive L2","Name"
"Total CPU Time","Total CPU Time","Per Cycle","Per Instruction","Instructions Executed","Cycles Time","Cache Misses","Cache Misses",""
"V (sec.)"," (sec.)"," "," "," "," "," "," "," "
"400.960","400.960","1.078","0.928","331536890705","384.385","275967027","1382745376","<Total>"
"305.674","305.674","1.180","0.847","276264202471","292.580","214724555","890599668","<JVM-System>"
"22.556","22.556","0.648","1.543","11657039096","22.482","14969978","114809445","<no Java callstack recorded>"
"1.741","1.741","1.656","0.604","1670055813","1.261","433393","5004987","sun.misc.Unsafe.defineAnonymousClass(java.lang.Class, byte[], java.lang.Object[])"
"0.921","6.284","1.342","0.745","768415887","0.716","0","2779760","scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(java.lang.Object, scala.tools.nsc.backend.jvm.BTypes$BType)"
"0
I: File: out/linkCustomLib/custom-lib/Map2.class
I: Done in 0.118 ms, nt size: 54
I: public interface abstract class Map2#2
* Version: 52.0 (supported by JDK 1.8)
* Constant Pool [34]
#0 [null entry]: -
#1 [Utf8]: Map2
#2 [Class]: Map2#1
#3 [Utf8]: java/lang/Object
#4 [Class]: java/lang/Object#3

Example implementation: safe type constraint =:=

In this example we will see how to reimplement =:= using phantom types and in the process fix a vulnerability that it has. It is a simplified version of TypeConstraint which also implements <:<.

=:= in Scala 2.x

Type constraints =:= gives an evidence that two generic types are in fact equal and provides a mechanism to safely cast one type to the other. In the following example we want to assign an x: X to an ys: Array[Y] where we don't know if it is possible (this will be known at call site). Therefore we use an implicit evidence ev: X =:= Y to know that they are equal and ev(x) to cast x form X to Y.

import scala.annotation.implicitNotFound
import scala.reflect.ClassTag

object Test {

  import Phantom_=::=._
  //  import Normal_=::=._

  def main(args: Array[String]): Unit = {

With fingerprints

[info] Test run started
[info] Test dotty.tools.dotc.CompilationTests.runAll started
[=======================================] completed (775/775, 38s)  
[info] Test dotty.tools.dotc.CompilationTests.compileNeg started
[=======================================] completed (252/252, 2s)  
[info] Test dotty.tools.dotc.CompilationTests.compilePos started
[=======================================] completed (871/871, 59s)  
[info] Test dotty.tools.dotc.CompilationTests.testPickling started
val badType = RefinedType(RefinedType(TypeRef(RefinedType(RefinedType(RefinedType(RefinedType(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,immutable)),Nil$),$anon), scala$collection$TraversableOnce$$A, TypeAlias(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,immutable)),Nil$),scala$collection$LinearSeqLike$$A), 1)), scala$collection$GenTraversableOnce$$A, TypeAlias(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,immutable)),Nil$),scala$collection$LinearSeqLike$$A), 1)), scala$collection$Iterator$$A, TypeAlias(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,immutable)),Nil$),scala$collection$LinearSeqLike$$A), 1)), scala$collection$AbstractIterator$$A, TypeAlias(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,immutable)),Nil$),scala$collection$LinearSeqLike$$A), 1)),$anon), scala$collection$TraversableOnce$$A, TypeAlias(RefinedType(RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Tuple2), scala$Tuple2$$T1, TypeAlias(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,scala)),Predef),String), 1)), scala$Tuple2$$T2, TypeAlias(TypeRef

Phantom types

Phantom types are designed to support compile time type evidences without any overhead costs to runtime. Phantom evidences are usually in the form of implicit arguments, which once resolved, can be erased by the compiler.

Because of these properties, phantom types are completely outside of the normal type lattice, and as such these phantom types do not inherit the semantics of Any.