or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

context-management.mdcore-compilation.mdindex.mdinteractive-compilation.mdjava-interfaces.mdplugin-development.mdrepl-scripting.md
tile.json

tessl/maven-org-scala-lang--scala3-compiler_3

The Scala 3 compiler (Dotty) providing advanced type inference, metaprogramming capabilities, and enhanced performance for modern Scala development

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.scala-lang/scala3-compiler_3@3.7.x

To install, run

npx @tessl/cli install tessl/maven-org-scala-lang--scala3-compiler_3@3.7.0

index.mddocs/

Scala 3 Compiler

The Scala 3 compiler (Dotty) is a next-generation compiler for the Scala programming language featuring advanced type inference, improved metaprogramming capabilities through inline functions and macros, better error messages, and enhanced performance. It supports modern language features like union and intersection types, opaque type aliases, extension methods, and contextual abstractions.

Package Information

  • Package Name: scala3-compiler_3
  • Package Type: maven
  • Language: Scala
  • Installation: Add to build.sbt: libraryDependencies += "org.scala-lang" %% "scala3-compiler" % "3.7.0"

Core Imports

import dotty.tools.dotc.{Main, Driver, Compiler}
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.interfaces._

For plugin development:

import dotty.tools.dotc.plugins.{Plugin, StandardPlugin, PluginPhase}
import dotty.tools.dotc.core.Phases.Phase

For interactive/IDE usage:

import dotty.tools.dotc.interactive.{InteractiveDriver, InteractiveCompiler}

Basic Usage

import dotty.tools.dotc.{Main, Driver}
import dotty.tools.dotc.interfaces.{SimpleReporter, CompilerCallback}

// Simple compilation using Main entry point
Main.main(Array("MyFile.scala", "-d", "output"))

// Programmatic compilation with custom settings
val driver = new Driver
val reporter = driver.process(Array("MyFile.scala", "-classpath", "lib/*"))

// Compilation with custom reporter and callback
val customReporter: SimpleReporter = diagnostic => 
  println(s"${diagnostic.level}: ${diagnostic.message}")

val callback: CompilerCallback = new CompilerCallback {
  override def onClassGenerated(source, generatedClass, className) = 
    println(s"Generated class: $className")
}

val result = driver.process(
  Array("MyFile.scala", "-d", "classes"),
  customReporter,
  callback
)

Architecture

The Scala 3 compiler is built around several key components:

  • Driver System: Entry points (Main, Driver) for different compilation modes with customizable compilation process
  • Compilation Pipeline: Compiler class managing phases and runs with context-based execution
  • Phase Framework: Extensible phase system with MegaPhase combining multiple mini-phases for efficiency
  • Plugin System: Extensible architecture supporting both standard and research plugins
  • Interactive Features: IDE integration through InteractiveDriver with incremental compilation support
  • Type System: Advanced type system with Contexts, Types, Symbols, and Names infrastructure
  • AST Infrastructure: Comprehensive abstract syntax tree system with typed and untyped variants

Capabilities

Core Compilation API

Primary compilation interfaces for batch compilation, programmatic usage, and build tool integration.

object Main extends Driver {
  def main(args: Array[String]): Unit
}

class Driver {
  def process(args: Array[String]): Reporter
  def process(args: Array[String], reporter: Reporter | Null, callback: CompilerCallback | Null): Reporter
  def setup(args: Array[String], rootCtx: Context): Option[(List[AbstractFile], Context)]
}

class Compiler {
  def phases: List[List[Phase]]
  def newRun(using Context): Run
  def nextRunId: Int
  def reset()(using Context): Unit
}

Core Compilation

Plugin Development API

Framework for creating compiler plugins that can extend the compilation pipeline with custom phases and transformations.

sealed trait Plugin {
  def name: String
  def description: String
  def optionsHelp: Option[String]
}

trait StandardPlugin extends Plugin {
  def initialize(options: List[String])(using Context): List[PluginPhase]
}

trait ResearchPlugin extends Plugin {
  def init(options: List[String], plan: List[List[Phase]])(using Context): List[List[Phase]]
}

Plugin Development

Interactive Compilation API

IDE integration capabilities providing incremental compilation, context preservation, and interactive features for development tools.

class InteractiveDriver extends Driver {
  def currentCtx: Context
  // Interactive compilation methods for IDE features
}

class InteractiveCompiler extends Compiler {
  // Compiler variant optimized for interactive usage
}

Interactive Compilation

Java Interfaces

External Java-compatible interfaces for tool integration and reporting, enabling seamless integration with Java-based build tools and IDEs.

trait SimpleReporter {
  def report(diag: Diagnostic): Unit
}

trait CompilerCallback {
  def onClassGenerated(source: SourceFile, generatedClass: AbstractFile, className: String): Unit = {}
  def onSourceCompiled(source: SourceFile): Unit = {}
}

trait Diagnostic {
  def level(): Int
  def message(): String
  def position(): Option[SourcePosition]
}

Java Interfaces

Context Management

Context system providing compilation state management, phase execution control, and configuration handling throughout the compilation pipeline.

object Contexts {
  def ctx(using ctx: Context): Context
  def inContext[T](c: Context)(inline op: Context ?=> T): T
  def atPhase[T](phase: Phase)(inline op: Context ?=> T)(using Context): T
}

Context Management

REPL and Scripting

REPL (Read-Eval-Print Loop) functionality for interactive Scala development and script execution capabilities.

class ReplDriver {
  // REPL compilation and execution engine
}

object repl.Main {
  def main(args: Array[String]): Unit
}

class ScriptEngine extends javax.script.ScriptEngine {
  // JSR-223 ScriptEngine implementation
}

REPL and Scripting