This repository contains the artifact for the paper "Meta-monomorphizing Specializations". The artifact consists of three main components: a prototype implementation, an instrumentation tool for empirical analysis, and a benchmark evaluation suite.
- Overview
- Repository Structure
- Requirements
- Getting Started
- Reproducing the Empirical Evaluation
- Pre-computed Results
- Contact
This artifact provides:
-
spec-trait-impl/— A prototype implementation of trait specialization in Rust, featuring procedural macros and compile-time trait ordering. -
spec-trait-inst/— An instrumentation tool built as acargo/rustcwrapper that statically analyzes Rust projects to identify trait specialization opportunities. -
spec-trait-evaluation/— A benchmark suite that comparesspec!/#[when]compile-time specialization against alternative dispatch strategies (naive, enum, runtimeTypeId), measuring runtime performance, build time, and binary size. See the evaluation README for details.
spec-trait/
├── spec-trait-impl/ # Prototype implementation
│ └── crates/
│ ├── spec-trait-bin/ # Binary crate (entry point)
│ ├── spec-trait-macro/ # Procedural macros for specialization
│ ├── spec-trait-order/ # Compile-time trait ordering
│ └── spec-trait-utils/ # Shared utilities
│
├── spec-trait-inst/ # Instrumentation tool
│ ├── src/ # Source code
│ └── tests/
│
└── spec-trait-evaluation/ # Benchmark evaluation suite
├── benches-crate/ # Criterion benchmarks
├── notebooks/ # Analysis notebooks
├── results/ # Pre-computed CSV results
└── scripts/ # Metric collection scripts
├── scripts/ # Analysis scripts and results
│ ├── analysis.sh # Main analysis script
│ ├── repos.txt # List of repositories analyzed
│ ├── summary-90.csv # Pre-computed results (90th percentile)
│ └── summary-99.csv # Pre-computed results (99th percentile)
├── snippets/ # Test snippets
└── workspaces/ # Test workspaces
- Rust nightly toolchain (
nightly-2026-01-01) - Git (for cloning repositories during analysis)
- Bash (for running the analysis script)
The prototype implementation showcases our approach to trait specialization through procedural macros.
cd spec-trait-impl
cargo buildcd spec-trait-impl
cargo testThe instrumentation tool analyzes Rust projects to identify existing and potential trait specialization patterns.
First, install the required nightly toolchain with all necessary components:
rustup toolchain install nightly-2026-01-01
rustup component add --toolchain nightly-2026-01-01 \
rust-src rustc-dev llvm-tools-preview miri rust-analyzer clippycd spec-trait-inst
cargo buildExecute the test suite on all example workspaces:
cd spec-trait-inst
cargo test --no-fail-fast -- --test-threads=1 --nocaptureTo analyze a specific Rust project:
cd /path/to/target/project
# On Linux:
LD_LIBRARY_PATH=$(rustc --print sysroot)/lib \
/path/to/spec-trait-inst/target/debug/cargo-spec-trait-inst
# On macOS:
DYLD_LIBRARY_PATH=$(rustc --print sysroot)/lib \
/path/to/spec-trait-inst/target/debug/cargo-spec-trait-instNote: Additional logging can be enabled by setting
RUST_LOG=debugorRUST_LOG=trace. UseRUST_LOG_STYLE=alwaysto force colored output.
The empirical evaluation from the paper can be fully reproduced using the provided analysis script. This script clones repositories from a curated list, runs the instrumentation tool on each, and aggregates the results.
cd spec-trait-inst/tests
./scripts/analysis.shUsage: analysis.sh [-f <file>] [-w <workdir>] [-l <logs>] [-k] [-c] [-h]
-f File with newline-separated repo URLs (default: ./scripts/repos.txt)
-w Working directory for cloned repos (default: ./workspaces)
-l Logs directory (default: ./logs)
-c Continue mode: append to existing summary file
-k Keep cloned repositories after analysis
-h Show help message
cd spec-trait-inst/tests
./scripts/analysis.sh -f /path/to/custom-repos.txt -kFor convenience, we provide pre-computed analysis results in the spec-trait-inst/tests/scripts/ directory:
| File | Description |
|---|---|
summary-90.csv |
Analysis results with 90th percentile threshold |
summary-99.csv |
Analysis results with 99th percentile threshold |
repos.txt |
List of analyzed repositories (top Rust crates from crates.io and popular GitHub projects) |
These results were generated by running analysis.sh on the repositories listed in repos.txt. The CSV files contain detailed metrics including:
- Repository metadata (crate name, downloads, stars)
- Function and trait counts
- Specialization opportunity metrics (existing and potential)
- Analysis performance data (time, memory usage)