Skip to content

Instantly share code, notes, and snippets.

View paulp's full-sized avatar
🤫

Paul Phillips paulp

🤫
  • CAZ, Inc.
  • Cascadia Autonomous Zone
View GitHub Profile
% test/partest --srcpath pending test/pending/pos/t46*scala
testing: [...]/pending/pos/t4606.scala [FAILED] (compilation errors)
testing: [...]/pending/pos/t4683.scala [FAILED] (caught scala.reflect.internal.FatalError)
testing: [...]/pending/pos/t4649.scala [ OK ]
2 of 3 tests failed (elapsed time: 00:00:04)
*** Summary of failed tests ***
=== pos/t4683.scala ===
[ start]
import scala.util.control.ControlThrowable
import java.util.{Timer, TimerTask}
import language.implicitConversions
% /scala/inst/271/bin/scalac a.scala
% /scala/inst/26/bin/scalac a.scala
a.scala:22: error: ambiguous implicit values:
both value fooa in object FooImplicits2 of type => Foo[A]
and value foob in object FooImplicits2 of type => Foo[B]
match expected type Foo[A]
def foo = implicitly[Foo[A]]
^
a.scala:41: error: ambiguous implicit values:
both value barx in object BarImplicits2 of type => Bar[X]
@paulp
paulp / gist:3729673
Created September 15, 2012 20:47
Exploration of how hotspot punishes overrides
// Thresholds which can be seen being crossed at various points:
//
// intx MinInliningThreshold = 250 {product}
// intx FreqInlineSize = 325 {pd product}
// intx InlineSmallCode = 1000 {pd product}
//
// usage is e.g. -J-XX:MinInliningThreshold=1000, -J-XX:FreqInlineSize=1000
//
// scala -J-XX:+UnlockDiagnosticVMOptions -J-XX:+PrintCompilation -J-XX:+PrintInlining Test 100000000 1001 B0
148 1 java.lang.String::hashCode (67 bytes)
159 2 sun.nio.cs.UTF_8$Encoder::encode (361 bytes)
@ 14 java.lang.Math::min (11 bytes) (intrinsic)
@ 139 java.lang.Character::isSurrogate (18 bytes) never executed
213 3 java.lang.String::charAt (33 bytes)
215 4 java.lang.String::indexOf (87 bytes)
@ 83 java.lang.String::indexOfSupplementary (88 bytes) too big
309 5 java.io.UnixFileSystem::normalize (75 bytes)
@ 1 java.lang.String::length (5 bytes) inline (hot)
@ 19 java.lang.String::charAt (33 bytes) inline (hot)
@paulp
paulp / devirtualized.md
Created September 17, 2012 03:38 — forked from c9r/devirtualized.md
De-virtualized Collections

De-virtualized Collections

De-virtualizing abstract collections would increase performance and decrease bytecode bloat for common use cases–without tying the hands of implementors. Conceptually, operations on abstract collections become syntactic sugar for inlined code templates. You opt-in to dynamic behavior by choosing subtypes that override extension methods with virtual ones. The root collections then become an encapsulation of their elements, but not an abstraction over operations on those elements; you can still perform such operations on these collections, but the compiler statically binds the implementation rather than indirecting to the run-time type's vtable-provided version. Collection sub-families–parallel, non-strict, and the like–override generic extension methods with virtual ones, and any value statically typed to such a collection works in the usual object-oriented way.

Sample de-virtualized collection hierarchy

import collection.generic.CanBuildFrom
import language.im
#!/bin/bash
#
set -e
PACKDIR=/packs
SCALA_REPO=$SCALA_SRC_HOME
runGit="git --git-dir $SCALA_REPO/.git --no-pager"
unset HASH WHEN DONE failed
@paulp
paulp / devirtualized.md
Created October 1, 2012 22:55 — forked from c9r/devirtualized.md
De-virtualized Collections

De-virtualized Collections

De-virtualizing abstract collections would increase performance and decrease bytecode bloat for common use cases–without tying the hands of implementors. Conceptually, operations on abstract collections become syntactic sugar for inlined code templates. You opt-in to dynamic behavior by choosing subtypes that override extension methods with virtual ones. The root collections then become an encapsulation of their elements, but not an abstraction over operations on those elements; you can still perform such operations on these collections, but the compiler statically binds the implementation rather than indirecting to the run-time type's vtable-provided version. Collection sub-families–parallel, non-strict, and the like–override generic extension methods with virtual ones, and any value statically typed to such a collection works in the usual object-oriented way.

Sample de-virtualized collection hierarchy

import collection.generic.CanBuildFrom
import language.im
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe._
import Ops._
object Main {
def main(args: Array[String]): Unit = bippy("dog", 1.1f, List(Set(1)))
def show[T](x: T): T = { println(x) ; x }
def bippy[T: WeakTypeTag, U: WeakTypeTag, V: WeakTypeTag](x: T, y: U, z: V) = call.log[T, U, V](x, y, z)
}
trait ImplicitCollectorFunction[M[_], V, R] {
def breakIf[T: ClassTag](assertion: => Boolean, args: NamedParam*): Unit =
if (assertion) break[T](args.toList)
// start a repl, binding supplied args
def break[T: ClassTag](args: List[NamedParam]): Unit = savingContextLoader {
val msg = if (args.isEmpty) "" else " Binding " + args.size + " value%s.".format(
if (args.size == 1) "" else "s"
)