Skip to content

Instantly share code, notes, and snippets.

View hrhino's full-sized avatar

Harrison Houghton hrhino

View GitHub Profile
@szeiger
szeiger / gist:d73a42b67a318244a7ef04ae7021e260
Created September 27, 2018 14:49
When you think 5 or 10 warmup iterations are sufficient...
[info] # Run progress: 91.67% complete, ETA 00:00:50
[info] # Fork: 2 of 2
[info] # Warmup Iteration 1: 94986.818 ns/op
[info] # Warmup Iteration 2: 90830.986 ns/op
[info] # Warmup Iteration 3: 90552.242 ns/op
[info] # Warmup Iteration 4: 93412.241 ns/op
[info] # Warmup Iteration 5: 90682.330 ns/op
[info] # Warmup Iteration 6: 92394.442 ns/op
[info] # Warmup Iteration 7: 95510.477 ns/op
[info] # Warmup Iteration 8: 92989.488 ns/op
package newts.plugin
import scala.collection.mutable
import scala.reflect.internal.util.StatisticsStatics
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
import scala.tools.nsc.transform.{Transform, TypingTransformers}
import scala.tools.nsc.typechecker.Analyzer
import scala.tools.nsc.{Global, Phase, SubComponent}
class NewtsPlugin(override val global: Global) extends Plugin { plugin =>
The general pattern of Namer is:
- Enter: create a symbol for a XDef tree, enter in in the enclosing scope, and set its info to be a type completer (aka lazy type) that ends up calling into templateSig/classSig/methodSig etc the first time `thatSymbol.info` is called, which can either be when the typer phase makes it to that spot in that compilation unit, or could be when some other typechecking needs that type earlier on.
- Complete: Create the MethodType/ClassInfoType/etc for the symbol. This can recursively enter symbols for members of the class/object/package. It can also invoke the typechecker (e.g. to typecheck the parent types of a class, or to look up the inheritance chain for the overriden method that might have defaults that are relevant to this method symbol.
The lazy parts of this process capture the relevant `Namer` instance, which has a `Typer` focussed at the right spot in the tree.
This process can create symbols for synthetic methods. For instance, in the type completer for a case clas
import scala.language.existentials
class A { class E }
class B extends A { class E }
trait CD { type E }
trait C extends CD { type E = Int }
trait D extends CD { type E = String }
object Test {
type EE[+X <: { type E }] = X#E
@retronym
retronym / doc.md
Last active September 21, 2018 20:55
Scripts for convenient access to Scala pre-release builds
@chrisvest
chrisvest / CodeGenMeta.java
Created March 30, 2014 14:53
Example showing how to generate, compile, load and run Java programs at run-time.
import javax.tools.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;