Code Monkey home page Code Monkey logo

izumi-reflect's Introduction

Project stage Build javadoc Latest Release Maven Central Latest version


Izumi


izumi-reflect

@quote: Looks a bit similar to TypeTag

izumi-reflect is a fast, lightweight, portable and efficient alternative for TypeTag from scala-reflect.

izumi-reflect is a lightweight model of Scala type system and provides a simulator of the important parts of the Scala typechecker.

Why izumi-reflect

  1. izumi-reflect compiles faster, runs a lot faster than scala-reflect and is fully immutable and thread-safe,
  2. izumi-reflect supports Scala 2.11, 2.12, 2.13 and Scala 3,
  3. izumi-reflect supports Scala.js and Scala Native,
  4. izumi-reflect works well with GraalVM Native Image,
  5. izumi-reflect allows you to obtain tags for unapplied type constructors (F[_]) and combine them at runtime.

Credits

izumi-reflect has been created by Septimal Mind to power Izumi Project, as a replacement for TypeTag in reaction to a lack of confirmed information about the future of scala-reflect/TypeTag in Scala 3 (Motivation), and donated to ZIO.

Izumi

Limitations

izumi-reflect model of the Scala type system is not 100% precise, but "good enough" for the vast majority of the usecases.

Known limitations are:

  1. Recursive type bounds (F-bounded types) are not preserved and may produce false positives,
  2. Existential types, both written with wildcards and forSome may produce unexpected results, the support is limited,
  3. Path-Dependent Types are based on variable names and may cause unexpected results when variables with different names have the same type or vice-versa (vs. Scala compiler)
  4. This-Types such as X.this.type are ignored and identical to X
  5. At the moment Scala 3 port does not support Structural Refinements. This will be fixed in the future.
  6. izumi-reflect is less powerful than scala-reflect: it does not preserve fields and methods when it's not necessary for equality and subtype checks, it does not preserve code trees, internal compiler data structures, etc.

Debugging

Set -Dizumi.reflect.debug.macro.rtti=true to enable debug output during compilation when tags are constructed and at runtime when they are compared.

sbt -Dizumi.reflect.debug.macro.rtti=true

To see debug output when compiling in Intellij, add the above flag to VM options in Preferences -> Build, Execution, Deployment -> Compiler -> Scala Compiler -> Scala Compile Server

You may also set it in .jvmopts file during development. (.jvmopts properties will not apply to Intellij compile server, only to sbt)

Set -Dizumi.reflect.debug.macro.rtti.assertions=true to enable additional assertions.

Other useful system properties are:

Build

build.sbt is generated by sbtgen. During development you may not want to mess with ScalaJS and ScalaNative, you may generate a pure-JVM Scala project:

./sbtgen.sc

Once you finished tinkering with the code you may want to generate full project and test it for all the platforms:

./sbtgen.sc --js --native
sbt +test

To develop using Scala 2 invoke sbtgen with a scala version argument:

./sbtgen.sc 2 // 2.13
./sbtgen.sc 2.12 // 2.12

Likewise with Scala 3:

./sbtgen.sc 3

In Intellij, you may also set Scala version by changing the option sbt -> sbt settings -> Open cross-compiled projects Scala 3 / Scala 2 projects as:

Talks

See also

  • Scala 3 only
  • No support for subtype checks
  • Requires compiler plugin
  • Type lambdas are not supported
  • Preserves field information
  • Scala 2 and Scala 3
  • No support for subtype checks
  • Preserves field information

izumi-reflect's People

Contributors

adamgfraser avatar ajaychandran avatar ghostdogpr avatar hughsimpson avatar indiscriminatecoding avatar khajavi avatar kitlangton avatar lermex avatar lvitaly avatar neko-kai avatar pshirshov avatar scala-steward avatar scalavision avatar sideeffffect avatar y-yu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.