Skip to content
CAI
Software that uses CAICheck a score

dotty-cps-async/dotty-cps-async

62.1

Adequate · 7 November 2026

27.5k

lines of production code

Scala

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a Scala 3 library and compiler plugin that enables direct-style asynchronous programming by transforming code into Continuation-Passing Style. It provides a comprehensive runtime for handling async/await patterns across JVM, JavaScript, and Native platforms, including support for Java Loom virtual threads and Scala.js promises. The library also extends its capabilities to support complex effect types, such as logic programming with backtracking and non-deterministic choice, alongside robust resource management and stream processing utilities.

How it got here

2020–2021 — Scala 3 migration and architecture refactor

39 changes.

The project underwent a major architectural overhaul to support Scala 3, migrating the build infrastructure to cross-compilation across JVM, JavaScript, and Native platforms. The core CPS transformation engine was restructured from a monolithic design into a modular forest of tree transformers, introducing new abstractions like CpsChunkBuilder and CpsPreprocessor. This period also saw the expansion of runtime capabilities, including async support for standard collections, JavaScript Promises, and asynchronous streaming, alongside comprehensive test coverage for the new architecture.

2022–2023 — CPS compiler plugin and Loom support

61 changes.

This period focused on the initial implementation and stabilization of the CPS compiler plugin, enabling Scala code transformation into Continuation-Passing Style. Significant work included adding support for Java Project Loom virtual threads and expanding comprehensive test coverage across JVM, Scala Native, and Scala.js platforms to verify async/await patterns, control flow, and structured concurrency.

2024–2026 — Logic monad and compiler plugin testing

17 changes.

This period focused on implementing a new Logic monad with stack-safe and concurrent capabilities, alongside extensive test coverage for the CPS compiler plugin's handling of async shifts, abstract methods, and preprocessing. The work also included fixing macro pattern matching issues and establishing infrastructure for tracking development tasks.

Features

Add async shift implementations for boundary, Either, Try, and resource management

New async shift implementations have been added to the runtime utility layer, enabling CPS-async support for Scala's standard control-flow and error-handling constructs. This includes BoundaryAsyncShift for handling break/return labels, EitherAsyncShift for async operations on Either types (including Left projections), TryAsyncShift for async operations on Try (with fixes for recover/recoverWith to avoid MatchErrors and correct forall logic), and UsingAsyncShift for safely managing resources with automatic release on success or failure paths.

shared/src/main/scala/cps/runtime/util · high confidence

Added Loom-based runtime await implementations

The JVM Loom addon now includes specific runtime await implementations for Scala's \Future\ and Java's \CompletableFuture\ that leverage the \blocking\ API to integrate with virtual threads. These new components (\FutureLoomRuntimeAwait\ and \CompletableFutureRuntimeAwait\) wrap the underlying asynchronous types, allowing the CPS runtime to efficiently await results on Loom-enabled threads without blocking platform threads.

jvm-loom-addon/src/main/scala/cps/runtime · high confidence

Added Loom-specific await transformation for JDK 19+ support

A new \LoomTransform\ macro implementation has been added to handle \cps.await\ calls specifically for Java Project Loom (JDK 19+). This component intercepts await expressions in the AST, distinguishes between the current CPS monad context and other monad types, and rewrites them to use the \CpsRuntimeAwait\ API, enabling compatibility with the new virtual thread-based concurrency model.

shared/src/main/scala/cps/macros/loom · high confidence

Added Monadless syntax support for await and unlift

Introduced a new \cps.syntax.monadless\ package providing extension methods for Monadless integration. This includes a \lift\ function as a synonym for \async\ and an \unlift\ extension method on \F\[T\]\ that serves as a synonym for \await\, enabling users to perform asynchronous operations within Monadless contexts using familiar syntax.

shared/src/main/scala/cps/syntax/monadless · high confidence

Added compiler plugin entry points for async transformations

The CPS compiler plugin now exposes specific entry points (cpsAsyncApply and cpsAsyncStreamApply) that delegate async transformation logic to the compiler. These methods are marked with @compileTimeOnly to ensure they are eliminated during compilation, allowing the plugin to intercept and rewrite async code blocks and streams.

shared/src/main/scala/cps/plugin · high confidence

Added debug settings for printing CPS-transformed code and trees

A new DebugSettings module has been introduced, defining PrintTree and PrintCode classes. These settings allow users to enable debugging output for the CPS transformation process, specifically to inspect the generated code structure and the resulting syntax trees.

shared/src/main/scala/cps/plugin/settings · high confidence

Added runtime await implementations for Future and CompletableFuture

The library now provides CpsRuntimeAwait instances for Scala's Future and Java's CompletableFuture, enabling these types to be used with the CPS runtime await mechanism.

jvm-loom-addon/src/main/scala/cps/monads · high confidence

Added short \`!\` syntax for awaiting CPS values

Users can now use the \!\ operator as a concise alternative to \await\ for unwrapping CPS-monad values. This new syntax, available via the \cps.syntax\ package (importing \ForSyntax\ and the package extensions), is particularly useful when automatic coloring is not supported or when the standard \await\ syntax is considered too verbose. It relies on \CpsMonadContext\ and \CpsMonadConversion\ to perform the unwrapping transparently.

shared/src/main/scala/cps/syntax · high confidence

Added support for CompletableFuture and timed Future operations

Users can now use the CPS compiler plugin with Java's CompletableFuture via the new CompletableFutureCpsMonad, which handles exception unwrapping and provides monad instance context. Additionally, new timedAwait and timedReady helper methods allow Scala Futures to be awaited with a specified timeout, throwing a TimeoutException if the operation exceeds the duration.

jvm/src/main · high confidence

Async shift support for collections, options, and functions

The runtime library now provides \AsyncShift\ implementations for \ArrayOps\, \Iterable\, \Seq\, \List\, \Map\, \Option\, \Function1\, and \PartialFunction\. This enables these standard Scala types to be used directly inside asynchronous blocks (e.g., \map\, \flatMap\, \foreach\, \filter\, \exists\, \forall\, \find\, \fold\, \distinctBy\, \indexWhere\, \segmentLength\, \andThen\, \compose\). The implementation ensures that operations on these types are executed sequentially or in parallel according to the underlying monad, allowing users to write asynchronous code using familiar collection and function APIs without manual wrapping.

shared/src/main/scala/cps/runtime · high confidence

Initial build infrastructure and documentation generation setup

This change establishes the foundational build structure for the project, introducing a custom Sbt plugin (SphinxPlugin) that integrates Sphinx documentation generation directly into the Sbt site mappings. It also defines the core build configuration files, setting Sbt to version 2.0.9 and adding essential plugins for publishing (sbt-pgp, sbt-ghpages), cross-compilation (Scala.js 1.22.0, Scala Native 0.5.12), API compatibility checking (sbt-mima-plugin), and code formatting (sbt-scalafmt).

project · high confidence

Initial implementation of the CPS compiler plugin

The compiler plugin (rssh.cps) is now available to transform Scala code into Continuation-Passing Style. It introduces a multi-phase pipeline that detects functions using CpsDirect or CpsMonadContext, generates shifted async methods for high-order functions annotated with @makeCPS, applies CPS transformations to the AST, and finally removes scaffolding to produce standard bytecode. Users can configure the plugin via options such as debugLevel, printTree, printCode, and useLoom.

compiler-plugin/src/main · high confidence

Initial setup of the anthill-todo work-item tracking system

This change introduces the \anthill-todo\ directory as a new location for tracking development tasks and technical debt. It establishes the project configuration (\project.anthill\) and store format (\store\_format.anthill\) required for the system, and adds initial work items including a delivered task to enable SIP-47 clause interleaving tests and open items to track a Scala 3 Quotes bug and the need for regression tests for newer Scala syntax features.

anthill-todo · high confidence

Introduce JSFuture for async/await interoperability with JavaScript Promises

Added JSFuture, a new Scala.js type that bridges Scala's Future and JavaScript's Promise, enabling the use of async/await syntax within JavaScript environments. This class wraps a js.Promise on the JavaScript side while maintaining a Future on the Scala side, allowing seamless conversion between JSFuture, Future, and js.Promise via provided implicit conversions. It supports standard monadic operations like map and flatMap, and integrates with the CPS compiler plugin to allow JSFuture to be used directly in await expressions.

js/src/main/scala/cps/monads/jsfuture · high confidence

Introduce async stream support with AsyncIterator and asyncStream macro

This change adds the core infrastructure for asynchronous streaming in the CPS library. It introduces the \AsyncIterator\ trait, providing a mutable async stream abstraction with operations like \map\, \flatMap\, \filter\, and \mapTry\ for handling asynchronous element generation and transformation. It also adds the \asyncStream\ compiler plugin entry point, implemented via \CpsAsyncEmitAbsorber\ and \CpsAsyncEmitter\, allowing users to define streams using a generator syntax (e.g., \asyncStream { out =\> ... out.emit(value) }\) that integrates with the existing CPS async/await model.

shared/src/main/scala/cps/stream · high confidence

Introduces two-stage async transformation with optional preprocessing

The \Async\ macro in \cps.macros\ now employs a two-stage approach for handling asynchronous code. The first stage, executed at compile-time via transparent inlines, checks for the presence of a \CpsPreprocessor\ typeclass; if one is found, it applies preprocessing to the expression before passing it to the second stage. The second stage performs the actual CPS transformation, which can either be handled by the Scala compiler plugin (if \UseCompilerPlugin\ is enabled) or by the macro implementation itself. This change allows users to inject custom preprocessing logic into async blocks while maintaining the existing plugin-based or macro-based transformation paths.

shared/src/main/scala/cps/macros · high confidence

New SIP-22 compatibility interface via FutureAsync

A new \FutureAsync\ object has been added to the \cps.compat\ package to provide a SIP-22 compatible interface for asynchronous operations. Users can now import this object to access \async\ and \await\ methods that leverage the \FutureContext\ and \CpsAsyncMonad\ implementations, enabling seamless integration with Scala's standard \Future\ type while maintaining compatibility with the CPS transformation macros.

shared/src/main/scala/cps/compat · high confidence

New logic monad implementations for synchronous and concurrent effects

The library introduces a new \CpsLogicMonad\ typeclass and concrete implementations for \LazyList\ (synchronous) and concurrent effect types (\CpsConcurrentLogicMonad\). This adds support for non-deterministic choice, backtracking, and stream-like logic operations such as \parOr\ (concurrent merge), \interleave\, \limit\, and \ifte\ (if-then-else on existence). The \LazyList\ implementation includes a stack-safe \tailRecM\ to prevent overflow, while the concurrent variant allows merging results from parallel fibers into a single logic stream.

logic/shared/src/main · high confidence

New macro utility and test components for tree manipulation

Added three new source files to the \cps.macros.misc\ package: \ChangeOwnerTest.scala\ provides test macros to verify that tree manipulations (such as \changeOwner\ and \BlockTransform\) do not break default getter selects; \CollectionHelper.scala\ introduces an inline macro to retrieve the \IterableFactory\ for a given collection type at compile time; and \WithOptExprProxy.scala\ adds a utility to create a proxy value definition for an expression, wrapping the result in a \Block\ to ensure correct ownership during macro expansion.

shared/src/main/scala/cps/macros/misc · high confidence

New stack-safe monad implementations for Identity, Either, Iterable, and TailRec

The library now provides dedicated CPS monad instances for several core types, each featuring a stack-safe \tailRecM\ implementation to prevent stack overflow during deep recursive computations. \CpsIdentityMonad\ handles identity transformations, \EitherCpsMonad\ and \EitherCpsTryMonad\ manage error handling with configurable exception mapping, \IterableCpsMonad\ supports generic iterable collections, and \TailRecCpsMonad\ integrates with Scala's \TailRec\ for deferred execution. These additions expand the range of data structures and control flows that can be used within \async\/\await\ blocks while maintaining safety against stack exhaustion.

shared/src/main/scala/cps/monads · high confidence

Support for awaiting JavaScript Promises via Future conversion

Users can now await JavaScript promises (scala.scalajs.js.Promise) within CPS-async blocks. This is enabled by a new given conversion in the cps.monads package that automatically converts a js.Promise to a scala.concurrent.Future, allowing the existing Future-based await mechanism to handle promise values seamlessly.

js/src/main/scala/cps/monads · high confidence

Support for break and return clauses inside async blocks

Users can now use \break\ and \return\ control-flow clauses within asynchronous code blocks. This change introduces \BreaksAsyncShift\ and \NonLocalReturnsAsyncShift\ to handle these control-flow operations, along with a \ControlThrowableAsyncWrapper\ to correctly propagate control exceptions through the async monad without being swallowed by standard non-fatal exception handlers.

shared/src/main/scala/cps/runtime/util/control · high confidence

Architecture

Compiler plugin introduces new internal transformation infrastructure and exception types

The compiler plugin now uses a new internal AST representation (CpsTree) and a suite of dedicated transformers (ApplyTransform, InlinedTransform, etc.) to handle CPS transformations, replacing previous inline or macro-based approaches. This refactor introduces specific exception types (CpsTransformException, CpsCompilationException) for better error reporting and adds support for handling inline bindings and complex application structures within the plugin's transformation pipeline.

repository · high confidence

Refactored macro transformation into a modular 'forest' of tree transformers

The macro implementation has been restructured to use a new set of specialized transformation classes (such as ApplyTransform, BlockTransform, and MatchTreeTransform) within the \cps.macros.forest\ package. This change replaces the previous monolithic approach with a modular system where specific Scala 3 TASTy tree nodes (like function applications, blocks, and matches) are handled by dedicated transformers. This improves the maintainability and clarity of the CPS transformation logic by separating concerns for each language construct.

shared/src/main/scala/cps/macros/forest · high confidence

Behavioural changes

Added scaffolding files to enforce compiler plugin usage

New scaffolding files (AdopDenotations, Brackets, DeferredShift, requiringCpsCompilerPlugin) were added to the shared plugin module. These files define functions annotated with @compileTimeOnly to ensure that the dotty-cps-async compiler plugin is enabled; if the plugin is missing, users will receive compile-time errors when attempting to use direct context functions or other CPS-specific APIs.

shared/src/main/scala/cps/plugin/scaffolding · high confidence

Improved macro pattern matching and tree transformation accuracy

The macro system now correctly handles named patterns (e.g., \case C(name = p)\) and \Bind\ patterns during tree traversal, preventing previous \MatchError\ crashes and ensuring proper substitution under \NonFatal\. Additionally, a workaround for Scala 3 issue \#17445 is included to preserve \Select\ name kinds (such as \DefaultGetterName\), which fixes \-Xcheck-macros\ symbol mismatch failures. These changes are implemented via new \PatternAwareTreeMap\ and \MacroReflectScope\ components in the common macro utilities.

shared/src/main/scala/cps/macros/common · high confidence

Project governance, build configuration, and documentation overhaul

This change introduces several foundational updates to the project's repository structure and build environment. It adds a \.gitignore\ file to exclude IDE and build artifacts (such as \.idea/\, \.vscode/\, and \target/\), and creates a \.sbtopts\ file to configure the sbt JVM with 8GB of heap memory and G1GC, addressing performance issues during Scala Native builds. The project license is switched to Apache 2.0, accompanied by the addition of \LICENSE.md\, \NOTICE\, \CODE\_OF\_CONDUCT.md\, \CONTRIBUTING.md\, and \CITATION.cff\ files to formalize contribution guidelines and citation metadata. Additionally, \.scalafmt.conf\ is added to enforce code formatting with Scala 3 future dialect, and the \README.md\ is significantly expanded with project highlights, presentation links, and a call to support Ukraine.

(repo-wide) · high confidence

Refactor internal CPS transformation architecture

The internal implementation of the CPS transformation engine has been restructured. The previous monolithic \Async\ object and associated result types (\CpsExprResult\, \CpsChunk\) have been removed in favor of a new modular architecture using \CpsExpr\, \CpsChunkBuilder\, and \TransformationContext\. This change consolidates transformation logic, simplifies the handling of async expressions and value discarding, and removes obsolete traits like \AsyncMetaMonad\ and \FutureMetaMonad\ from the public API surface, streamlining how the library processes asynchronous code.

src/main/scala/cps · high confidence

Refactored CPS forest transformers to use CpsChunkBuilder

The internal implementation of the CPS transformation forest has been refactored to replace the previous \CpsExprResult\-based approach with a new \CpsChunkBuilder\ abstraction. This change consolidates how asynchronous code blocks, function applications, and value definitions are constructed, simplifying the transformation logic for blocks, applies, and identifiers while ensuring consistent handling of async monads across the codebase.

src/main/scala/cps/forest · high confidence

Refactored macro argument application into modular scopes

The macro's argument application logic has been restructured into a set of new, specialized traits within the \cps.macros.forest.application\ package. \ApplyArgBuilderScope\ now handles the construction of argument records, correctly processing repeated arguments, named arguments, and lambdas. \ApplyArgRecordScope\ defines the data structures for tracking argument properties such as async status and evaluation order dependencies. \MethodParamsDescriptorScope\ provides a unified interface for inspecting method parameter metadata, including context parameters and CPS-direct types. \PartialShiftedApplyScope\ manages the application of shifted functions, supporting different shift types like \CPS\_RUNTIME\_AWAIT\ and \CPS\_DEFERR\_TO\_PLUGIN\. This refactoring isolates specific concerns of the CPS transformation, improving maintainability and clarity of the macro's internal logic.

shared/src/main/scala/cps/macros/forest/application · high confidence

Reworked monad context hierarchy and added CpsPreprocessor for async block customization

The library has restructured its monad context hierarchy, replacing the previous \CpsPureSchedulingMonad\ with \CpsConcurrentMonad\ and introducing a clearer chain of context traits (\CpsMonadContext\, \CpsThrowMonadContext\, \CpsTryMonadContext\, \CpsConcurrentMonadContext\) to better support different effect capabilities. Additionally, a new \CpsPreprocessor\ typeclass has been added, allowing monad authors to define custom transformations on async block bodies before the CPS transformation occurs, enabling features like caching or tracing specific to the monad's semantics.

shared/src/main/scala/cps · high confidence

Fixes

Fix async catch branch handling in compiler plugin tests

Added a test case (TestCBS1Try.scala) to verify that exceptions thrown within async blocks are correctly caught by try/catch blocks, ensuring the wasInCatch flag is set and the result is a Failure. This addresses the commit's note about fixing handling of async catch branches.

_compiler-plugin/testdata/set14runtests/m7\1 · medium confidence

Fix macro TreeMap handling of named patterns and NonFatal substitutions

The macro system's TreeMap implementation now parses patterns top-down, resolving issues where named patterns (e.g., \case C(name = p)\) and \NonFatal\ substitutions under \Bind\ nodes previously caused failures. This change ensures that macros traversing trees with these specific pattern structures execute correctly without throwing errors.

tests-cli · high confidence

Test coverage

Added JVM tests for LogicT monad and stack-safety guarantees; Added JVM tests for stack trace reporting accuracy; Added JVM-only test infrastructure for structured concurrency and cancellation; Added JVM-specific test utilities for futures and timers; Added JVM-specific tests for CPS async primitives and integration; Added Scala.js test case for compiler plugin integration; Added Scala.js test suite for CPS async/await and JS interop; Added compiler-plugin test cases for async dynamic application, Future range filtering, and stream fold/scan operations; Added compiler-plugin test suite for shifted extension methods and async shifts; Added dummy test configuration for macro testing; Added inline async function test case; Added test case for async calls within async blocks; Added test case for concurrent async fetch operations; Added test case for inline direct context functions; Added test case for nested async operations; Added test cases for CPS plugin behavior; Added test cases for CPS plugin bridge rewriting; Added test cases for CPS plugin with higher-order functions; Added test cases for async exception throwing in CPS; Added test cases for async/await patterns and extension methods; Added test cases for compiler crash and test runner logic; Added test cases for compiler-plugin CPS async validation; Added test cases for direct monad context inclusion and async argument handling; Added test cases for lazy effect handling in the compiler plugin; Added test cases for try/catch/finally in the compiler plugin; Added test cases for while-do loop transformation; Added test coverage for AsyncList and AsyncIterator operations; Added test coverage for CPS Loom transformations and runtime behaviors; Added test coverage for async stream merging, exception handling, and timed awaits; Added test coverage for concurrent example patterns; Added test data for CPS async operations; Added test data for JSDirect async compilation support; Added test data for abstract method handling in compiler plugin; Added test data for direct and inline direct reference types; Added test data for local direct reference support in CPS plugin; Added test file for CPS transformation utilities; Added test file for GSoC 2023 snippets; Added test file for Gopherlike CPS patterns; Added test for FizzBuzz in async context; Added test for Using resources with complex async computations; Added test for async stream fold operation; Added test for direct reference extension behavior; Added test for exception handling in try blocks within async computations; Added test for inline extensions in direct context functions; Added test for inlined ordinary direct function calls from macros; Added test for lambda typed as partial functions in iterable operations; Added test for nested async/await with Option monad; Added test for non-local returns in ComputationBound async blocks; Added test for resource interop in compiler plugin; Added test for resource management with context inclusion; Added test helper for MyList data structure; Added test infrastructure and examples for the chessboard domain; Added test infrastructure and test cases for the gopherlike2 CPS implementation; Added test infrastructure and unit tests for the PureEffect monad; Added test infrastructure for CpsPreprocessor validation; Added test infrastructure for compiler plugin validation; Added test scaffolding for Process-like CPS context; Added test suite for CPS gopher-like concurrency primitives; Added test suite for LogicT monad transformer implementations; Added test suite for SIP-22 async compatibility; Added test suite for compiler plugin support of Java Loom virtual threads; Added test suite for logic unification1 components; Added test suite for logical unification2 infrastructure; Added test suite for the Logic module's monad transformers and backtracking implementations; Added test suite for the Logic monad and LogicStream; Added test utilities for JS platform; Added test utilities for exception handling and time-based operations; Added test utilities for time-based operations in Scala Native; Added tests for CPS context resolution and deferred cleanup; Added tests for CPS-integrated LazyStream monad; Added tests for ComputationBound async shifts; Added tests for ComputationBound runtime await behavior on JVM Loom; Added tests for CpsPreprocessor functionality; Added tests for DBIO print behavior and Free monad structure; Added tests for FutureWithDeadline and DeadlineContext; Added tests for Scala Native CPS runtime support; Added tests for compiler plugin integration and direct CPS execution; Added tests for select loop simplification and context handling; Added utest-like assertion macro and test suite; Compiler plugin test infrastructure and coverage expansion; Compiler plugin test suite for match expressions with async selectors; Compiler rejects CpsDirect assignment in test cases; Expanded test coverage for CPS transformation features.

Dependencies

Upgrade to Scala 3.9.0 and restructure build for cross-compilation

The build system has been upgraded to use Scala 3.9.0 as the primary compiler version, with support for cross-compilation to Scala 3.8.4. The project structure has been significantly reorganized to support cross-compilation across JVM, JavaScript, and Native platforms for both the core \cps\ library and the new \logic\ module. Additionally, the build now includes a dedicated \compilerPlugin\ subproject and a \cpsLoomAddOn\ for JVM-specific features, replacing the previous monolithic setup.

(dependencies) · high confidence

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 54 → 62 (+8.5)
  • Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.

Lenses

  • Code Health 58 → 58 (+0.0)
  • Architecture 91 → 91 (+0.0)
  • Maturity 37 → 55 (+18.1)
  • Readiness 71 → 70 (-1.6)
  • Security 85 → 75 (-10.2)
  • Performance 100 (new)

Resolved (1)

  • Documentation: no installation or build instructions (docs/index.rst)

New (1)

  • Dependency hygiene PARTLY measured — sbt declarations read, dependency currency not (Maven Central unreachable)

Architecture

  • Unchanged — 0 containers · 1 contexts · 0 edges

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

dotty-cps-async/dotty-cps-async was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 7 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 2240f4065a7b7b54a95f7e57ecefde2063c761c0 — the exact code this score is about.
  • Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
  • Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.3+preprod-5f8314471808.