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
@lihaoyi
lihaoyi / gist:6386815
Last active March 19, 2022 12:22
Scala without braces/parens?
package metascala
import collection.mutable
import annotation.tailrec
import metascala.imm.Type
import metascala.rt.{Obj, FrameDump, Thread}
import metascala.natives.Bindings
import metascala.imm.Type.Prim
import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
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,
@lihaoyi
lihaoyi / gist:90fa7a60f93d32324d4f
Last active June 24, 2021 01:09
Scala Syntax Popularity, from Least Popular to Most Popular Syntactic Forms

These numbers are taken from the FastParse test suite, which runs over the following libraries:

  • fastparse
  • scalaJs
  • scalaz
  • shapeless
  • akka
  • lift
  • play
  • PredictionIO
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,
@lihaoyi
lihaoyi / debug.scala
Last active April 10, 2019 23:39
Scala.js pprint debug
def debug[T](value: sourcecode.Text[T], tag: String = "")
(implicit pprinter: pprint.PPrint[T],
path: sourcecode.Enclosing,
line: sourcecode.Line,
cfg: Config = pprint.Config.Colors.PPrintConfig)= {
val titleIter = path.value.split(" |#|\\.").filter(!_.contains("$")).last
val tagIter =
if (tag == "") ""
else " " + pprint.tokenize(tag).mkString

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(".")
@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"))
)
)
}