dispalt / squid

Scala Quoted DSLs – a metaprogramming framework based on type-safe and hygienic quasiquotes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Squid ― Scala Quoted DSLs

Join the chat at https://gitter.im/epfldata-squid/Lobby

Introduction

Squid (for the approximative contraction of Scala Quoted DSLs) is a metaprogramming framework that facilitates the type-safe manipulation of Scala programs. Squid is geared towards the implementation of library-defined optimizations [2] and helps with the compilation of Domain-Specific Languages (DSL) embedded in Scala [1]. In addition, it has an advanced static typing capabilities that reduce common metaprogramming errors [3].

Caution: Squid is still experimental, and the interfaces it exposes may change in the future (especially the semi-internal interfaces used to implement intermediate representation backends).

Installation

Squid currently supports Scala versions 2.11.3 to 2.11.11 (more recent versions might work as well, but have not yet been tested).

The project is not yet published on Maven, so in order to use it you'll have to clone this repository and publish Squid locally, which can be done by executing the script in bin/publishLocal.sh.

In your project, add the following to your build.sbt:

libraryDependencies += "ch.epfl.data" %% "squid" % "0.2-SNAPSHOT"

Some features related to library-defined optimizations and squid macros, such as @embed and @macroDef, require the use of the macro-paradise plugin. To use these features, add the following to your build.sbt:

val paradiseVersion = "2.1.0"

autoCompilerPlugins := true

addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full)

Overview of Features

Squid Quasiquotes

Quasiquotes are the primitive tool that Squid provides to manipulate program fragments –– building, composing and decomposing them. Quasiquotes are central to most aspects of program transformation in Squid.

Type-Safe Code Manipulation

Unlike the standard Scala Reflection quasiquotes, Squid quasiquotes are statically-typed and hygienic, ensuring that manipulated programs remain well-typed and that variable bindings and other symbols do not get mixed up. Squid quasiquotes focus on expressions (not definitions), but Squid provides way to embed arbitrary class and object definitions so that their methods can be inlined at any point (or even automatically).

Flavors of Quasiquotes

Two forms of quasiquotes co-exist in Squid:

  • Simple Quasiquotes (tutorial) provide the basic functionalities expected from statically-typed quasiquotes, and can be used for a wide range of tasks, including multi-stage programming (MSP). They support both runtime interpretation, runtime compilation and static code generation. For more information, see [1].

  • Contextual Quasiquotes (tutorial) push the type-safety guarantees already offered by simple quasiquotes even further, making sure that all generated programs are well-scoped in addition to being well-typed. While they are slightly less ergonomic than the previous flavor, these quasiquotes are especially well-suited for expressing advanced program transformation algorithms and complicated staging techniques. For more information, see [3].

Both forms of quasiquotes support a flexible pattern-matching syntax and facilities to traverse programs recursively while applying transformations.

As a quick reference available to all Squid users, we provide a cheat sheet that summarizes the features of each system. Also see the quasiquotes tutorial.

TODO

Link to transformers documentation.

TODO

Link to IR documentation

TODO

TODO

Applications of Squid

Squid is new. See the examples folder for examples. A little query compiler built with Squid can be found here. Another LINQ-inspired query engine build with Squid can be found here.

Publications

[1]: Lionel Parreaux, Amir Shaikhha, and Christoph E. Koch. 2017. Squid: Type-Safe, Hygienic, and Reusable Quasiquotes. In Proceedings of the 2017 8th ACM SIGPLAN Symposium on Scala (SCALA 2017). (Get the paper here.)

[2]: Lionel Parreaux, Amir Shaikhha, and Christoph E. Koch. 2017. Quoted Staged Rewriting: a Practical Approach to Library-Defined Optimizations. In Proceedings of the 2017 ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences (GPCE 2017). Best Paper Award. (Get the paper here.)

[3]: Lionel Parreaux, Antoine Voizard, Amir Shaikhha, and Christoph E. Koch. Unifying Analytic and Statically-Typed Quasiquotes. To appear in Proc. POPL 2018. (Get the paper here.)

About

Scala Quoted DSLs – a metaprogramming framework based on type-safe and hygienic quasiquotes

License:Apache License 2.0


Languages

Language:Scala 100.0%Language:Shell 0.0%