Developing the Wolfram Language Compiler
summary
A compiler converts Wolfram Language ASTs to an SSA IR, runs a constraint-based type inference with parametric types and type classes, then emits native code via LLVM JIT; compiled functions unbox/box between interpreter expressions and typed arguments and can be emitted as dynamic libraries. It enforces semantics (overflow checks, abort handling) but allows unchecked blocks for C-like speed, provides packed arrays and array-backed tensors, and already supports automatic differentiation plus targets like WebAssembly and CUDA; compilation is slow but generated code rivals hand-tuned C.
AI-written summary · about
chapters (23)
- 0:00Intro
- 0:28Developing The Wolfram Compiler This talk will cover The Wolfram Language The Wolfram Compiler Embedding in an existing language Compiler Type System Compiler trade-offs and their resolution Interesting and notable features Program transformation, Automatic Differentiation
- 1:37The Wolfram Language: Programming Functional programming style Execution via AST rewriting Pattem matching on AST Function definition using patterns Various specialized optimizations
- 3:33Expression Structure: Code Code is really the same as Data
- 7:50Compilation Challenges Infinite evaluation Immutability semantics Holding / Quoting Adhere to semantics (e.g. arithmetic) Cross platform compatibility performance & functionality Variadic functions and overloading Sequences
- 8:25Version 1 Compiler (1990) Supports a language subsct Fixed to numerical types and operations Translates operations to Wolfram bytecode Bytecode can be either interpreted or exported to C Very popular with users to achieve performance Quite successful in its time
- 9:07The Wolfram Compiler A compiler for the Wolfram Language Long term project from 2015 Built in the Wolfram language Leverage Latest Compiler knowledge and technology Initial Mathematica release
- 9:58Compiler Operations Convert Wolfram Language into native machine code uses LLVM as backend in-memory JIT compilation dynamic library generation static type annotations with inferencing alternative execution model for Wolfram Language integrates with Wolfram Language interpreter easy linkage to dynamic libraries can run standalone
- 10:43Compiling an existing language sets expectations constrains semantics constrains syntax
- 16:48Type System Borrows from Haskell and Scala's type system Ad-hoc and parametric polymorphism Type classes Qualified types Type defaults Overloading with ambiguity resolution Dependent types and type evaluation no sub-typing Independent of the compiler Work with other groups at Wolfram for theorem proving
- 18:35Type Inferencing Constraints
- 20:42Library of Functions and Types Wolfram Language support needs function implementations types that support Wolfram Language Polymorphic type system is a great assistance much less code to write Built-in: Types Functions
- 26:20Functions Provided Need to support functions from interpreted code Compiled code has many more types interpreter has expression compiled code has Integer, UnsignedInteger etc... Need to be fast but need to maintain semantics
- 27:54Validation is a runtime error, uses exception mechanism With compiler intrinsics is quite fast, but branch loop optimization problems
- 32:12Disambiguation Based on a subsumption mechanism Given a choice pick the one that the others can be instantiated into
- 35:14Scripting Function Generation Use Wolfram Language for function preparation
- 36:09Create Data Tables Use Wolfram Language to prepare data at compilation time
- 37:43Development Workflow Create interpreted code Then compile
- 37:54Good example of program transformation Important for HPC, Machine Learning Suitable for multivariate problems generates a projection of the Jacobian
- 39:38GPU Integration Work with CUDA Generate PTX code, LLVM does this Integrate with CUDA Toolkit Generate host code for memory setup, launching, etc.
- 40:25Current Directions Compilation speed
- 40:55Summary Covered the following The Wolfram Language The Wolfram Compiler Embedding in an existing language The Type System Trade-offs and their resolution Interesting and notable features Program transformation, Automatic Differentiation Initial GPU integration also
- 41:10Embedding in an existing language The Type System Trade-offs and their resolution Interesting and notable features Program transformation, Automatic Differentiation Initial GPU integration also Many opportunities for developers/interns new technologies building out current features developing new compiler techniques
related talks
14mI compiled WebAssembly to lambda calculus! A journey into esoteric programming
24mCompilers and LLVM Demystified
29mPartially Evaluating Symbolic Interpreters for All
52mA bird's eye view of a compiler
53mLLVM
21mTowards Compiler-Guided Static Analysis
01h 05mAll the Languages Together
18mCompiling with Abstract Interpretation
