Skip to content

Instantly share code, notes, and snippets.

View lihaoyi's full-sized avatar

Li Haoyi lihaoyi

View GitHub Profile
lihaoyi mill$ javap -c -l out/integration/feature/codesig-simple/local/workspaceDir.dest/out/mill-build/compile.dest/classes/millbuild/build\$crossOuter\$\$anonfun\$7.class
Compiled from "build.sc"
public final class millbuild.build$crossOuter$$anonfun$7 extends scala.runtime.AbstractFunction1<java.lang.Object, scala.Tuple2<java.lang.Class<millbuild.build$crossOuter$$anonfun$7$CrossOuter$macro$9$1>, scala.Function1<mill.define.Ctx, millbuild.build$crossOuter$$anonfun$7$CrossOuter$macro$9$1>>> implements java.io.Serializable {
public final scala.Tuple2<java.lang.Class<millbuild.build$CrossOuter>, scala.Function1<mill.define.Ctx, millbuild.build$CrossOuter>> apply(int);
Code:
0: new #39 // class scala/Tuple2
3: dup
4: ldc #26 // class millbuild/build$crossOuter$$anonfun$7$CrossOuter$macro$9$1
6: aload_0
7: iload_1
import java.io.File
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import scala.io.Source
import collection.mutable
case class Decl(val index: Int,
val cls: String,
val name: String,
import $ivy.`io.getquill::quill-jdbc:3.5.1`, io.getquill._
val ctx: PostgresJdbcContext[LowerCase.type] = ???
import ctx._
case class CountryLanguage(countryCode: String,
language: String,
isOfficial: Boolean,
percentage: Double)
case class City(id: Int,

Provisional benchmarks of AST-free serialization puts my WIP branch of uPickle about ~40% faster than circe on my current set of ad-hoc benchmarks, if the encoders/decoders are cached (bigger numbers is better)

playJson Read 2761067
playJson Write 3412630
circe Read 6005895
circe Write 5205007
upickleDefault Read 4543628
upickleDefault Write 3814459
upickleLegacy Read 8393416
package mill.main
import mill.util.EitherOps
import fastparse.all._
import mill.define.Segment
import mill.main.ParseArgs.Fragment
object ParseArgs {
def apply(scriptArgs: Seq[String])
def compileScala(scalaVersion: String,
sources: Path,
compileClasspath: Seq[Path],
scalacOptions: Seq[String],
javacOptions: Seq[String],
outputPath: Path): PathRef = {
val compileClasspathFiles = compileClasspath.map(_.toIO).toArray
pprint.log(compileClasspathFiles)
val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".")
val compilerCache = new CompilerCache(10)
def compileScala(scalaVersion: String,
sources: Path,
compileClasspath: Seq[Path],
outputPath: Path): PathRef = {
val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".")
def grepJar(s: String) = {
compileClasspath
.find(_.toString.endsWith(s))
.getOrElse(throw new Exception("Cannot find " + s))
@ case class Cross[T](items: T*){
def flatMap[V](f: T => Cross[V]): Cross[(T, V)] = {
val flattened = for{
i <- items
k <- f(i).items
} yield (i, k)
Cross(flattened:_*)
}
def map[V](f: T => V): Cross[(T, V)] = {
Cross(items.map(i => i -> f(i)):_*)
import scala.reflect.macros.blackbox.Context
import language.experimental.macros
object Applicative {
def apply[T](t: T): Option[T] = macro Applicative.impl[T]
def impl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Option[T]] = {
import c.universe._
def rec(t: Tree): Iterator[c.Tree] = Iterator(t) ++ t.children.flatMap(rec(_))
val bound = collection.mutable.Buffer.empty[(c.Tree, ValDef)]
val defsWithinMacro = rec(t.tree).filter(_.isDef).map(_.symbol).toSet
@lihaoyi
lihaoyi / Test.scala
Created October 30, 2017 13:49
Resolving jars with Coursier and compiling Scala with the Zinc incremental compiler, in a self-contained Ammonite script
import play.api.libs.json.Json
object Main{
def main(args: Array[String]): Unit = {
println(
Json.prettyPrint(
Json.toJson(Seq("Hello", "World", "Cow"))
)
)
}