In How Prisma Reasons About Types and Verifies Correctness on November 11 (v0.2.1), we ended our roadmap with an honest admission: our large-corpus evaluation covered Erlang (RabbitMQ), while ra and real-world Elixir codebases were still ahead of us.
Nine days and eight patch releases later—landing on v0.2.9—that gap has been exercised hard against ra, ecto, padmark, a full production Phoenix/Ecto application (3,477 dependency modules), and Elixir main itself.
Along the way, real Elixir code exposed subtle edge cases in polymorphic specs, macro-generated code, open struct maps, and a severe combinatorial blowup in PPLT construction. Here is what changed in the engine between v0.2.1 and v0.2.9, what stayed on the roadmap, and the exact numbers we measured.
1. What Changed in the Type & Inference Engine
1.1 Instantiating bounded_fun Clauses (when var :: bound)
Elixir's @spec ... when clauses (such as Ecto.Repo.Preloader.preload/4, structs when structs: [Ecto.Schema.t()] | Ecto.Schema.t() | nil) compile to 4-tuple bounded_fun AST nodes: {bounded_fun, RawArgs, RawRet, Constraints}.
In v0.2.1, declared_return/6 simply unfolded the bounds, erasing the caller's concrete argument type. Calling Repo.preload(payment, user: [:profile]) with a %Payment{} struct came back typed as nil | [Ecto.Schema.t()] | Ecto.Schema.t(), immediately triggering false gradual_mismatch warnings downstream in Ecto.Changeset.change/2.
declared_return/6 now calls instantiate_bounded_clause/3 to bind type variables to meet(ActualArg, Bound) at the call site before unfolding RawRet, preserving the caller's %Payment{} struct across the call.
1.2 Demand-Driven Specialization Without Exponential Blowup
Fixing Ecto.Repo.Preloader.preload/4 alone wasn't enough, because MyApp.Repo.preload/2 is an un-specced 1-clause default-argument wrapper generated by use Ecto.Repo that forwards to MyApp.Repo.preload/3, which in turn calls Ecto.Repo.Preloader.preload/4.
To preserve types across un-specced wrappers:
-
Cross-module specialization: When a callee has no declared spec and all call-site arguments are concrete (
=/= any),prisma_inferspecializes the callee's body on demand for those argument types (returninganywhen any argument isanyto avoid pointless work). -
Per-pass memoization (
$prisma_spec_cache): Repeated specialized calls within afixpoint_looppass are cached by{CalleeMFA, ArgTypes, VisitedKeys}. -
Clause-aware depth bounds:
should_specialize_local/5allows recursion depth2for single-clause wrappers ([_])—sopreload/2 -> preload/3chains resolve cleanly—while capping multi-clause functions at depth1so branching combinatorics cannot explode quadratically.
The impact on real libraries was dramatic:
| Workload | Before optimization |
v0.2.9 |
Speedup |
|---|---|---|---|
postgrex (95 modules PPLT build) |
358.69 s | 1.78 s | ~201× faster |
ex_gram (492 modules PPLT build) |
47.43 s | 10.21 s | ~4.6× faster |
| Production Phoenix/Ecto deps (3,477 modules) | 644.50 s | 48.13 s | ~13.4× faster |
In prisma_type, two additional bounds keep lattice operations predictable: an $O(1)$ __struct__ mismatch fast-path in subtype_map_fields/2, and a map_size(Visited) >= 5 cap in expand_remote for deeply chained remote types.
1.3 Elixir AST, Macros, and Pattern Refinement
Running against production Elixir apps and Elixir's own stdlib surfaced four Elixir-specific frontend gaps, all fixed and covered by EUnit tests (bringing the suite from 249 tests on November 11 to 297/297 passing today alongside 18/18 PropEr properties):
-
Direct
elixir_v1debug info & external macro attribution (prisma_abstract/prisma_elixir): BEAM files compiled by Elixir also embed an Erlangabstract_codechunk that strips macrocontextmetadata.abstract_forms/2now defers{debug_info_v1, elixir_erl, _}toprisma_elixir:from_elixir_dbgi/5, andGenAttrsinspects all{context, CtxMod}entries inMeta(not just the first, which is oftenelixir_def), properly marking external macro injections likeuse Hammer(context: Hammer.ETS) ascompiler_generated. -
Dynamic
%mod{}struct patterns: Intranslate_pattern,%mod{}(wheremodis a pattern variable rather than an alias) previously fell through tounwrap_atom/1and turned into'Elixir.Any', breaking variable binding with guards likewhen mod in @formatter_exceptions(a falsediscrepancyinExUnit.Formatter). It now translates the variable pattern directly. -
Private macros in
oxbow_code:defmacropfunctions compile toMACRO-*helpers that are expanded at compile time rather than called at runtime.prisma_oxbownow ignoresMACRO-*names, eliminating 70 false unused-function warnings across Elixir's stdlib. -
Match-scrutinee variable refinement:
refine_match_scrutinee_vars/4now refines bare{var, _, V}scrutinees incasebranches (not only{match, ...}nodes), preventing false warnings afterif/casetruthiness checks.
2. Production Validation & Checking Elixir main
2.1 Production Phoenix/Ecto App (3,477 Dependency Modules)
On a real production Phoenix + Ecto + Oban + Hammer codebase (dymmer.com):
-
Dependency
.ppltbuild (3,477 modules): 48.13 s -
prisma check(default &--mode hybrid): 14.77 s – 16.82 s, 0 warnings
2.2 Checking Elixir main (3bce30a)
Running prisma check across all 6 core Elixir applications (elixir, eex, ex_unit, iex, logger, mix) on main (3bce30a) finishes in ~9.2 s with 0 discrepancy warnings:
| Category | Count | Notes |
|---|---|---|
discrepancy |
0 | Clean across all 6 core apps |
opacity_violation |
2 |
Real: Version inspecting @opaque Version.Requirement.t() (version.ex:325, 492) |
oxbow_code |
23 |
Real: 2 uncalled private functions (System.strip/1, System.read_stripped/1) and 21 unused private parameters |
dead_code |
32 |
Mostly defensive error clauses outside narrow @specs (List.first!([]), Access.*, Calendar.ISO.valid_time?/4, Logger.Formatter.prune/1) |
gradual_mismatch |
116 |
Spec-vs-code mismatches in stdlib (e.g., Agent.start/2,4 missing :ignore, Code.eval_quoted/3 options vs env_for_eval/1, DateTime.add/4 passing :day) |
By comparison, Elixir's own make dialyze target (which is not gated in .github/workflows/ci.yml) currently exits with Error 2 and 465 warnings in 12.92 s (after building .elixir.plt). Several unused private parameters and tight @specs surfaced by Prisma were already merged upstream in elixir-lang/elixir#16151.
3. Regression Check: RabbitMQ Benchmark vs v0.2.0
With all of these precision and Elixir improvements enabled, we re-ran the RabbitMQ corpus from DISCREPANCIES.md using hyperfine --runs 5 --warmup 1:
| Corpus / Mode |
v0.2.0 |
v0.2.8 / v0.2.9 |
Dialyzer (DISCREPANCIES.md) |
|---|---|---|---|
rabbit (234 modules) — discrepancy |
1.08 s / 295.5 MiB | 1.71 s / 382.5 MiB | 6.75 s / 405.1 MiB (3.9× faster) |
rabbit (234 modules) — all |
1.18 s / 287.8 MiB | 1.86 s / 387.2 MiB | — |
440 modules (7 apps) — discrepancy |
3.02 s / 536.0 MiB | 4.40 s / 574.9 MiB | 17.27 s / 1,456.7 MiB (3.9× faster) |
440 modules (7 apps) — all |
3.38 s / 546.1 MiB | 5.37 s / 626.2 MiB | — |
The added polymorphic instantiation and cross-module wrapper specialization cost
45–59% relative to v0.2.0 while keeping Prisma **
3.9× faster than Dialyzer and using ~2.5× less peak RAM** on the 440-module corpus.
4. Still on the Roadmap
Just as on November 11, three items from that original list remain open:
-
Nominal Types (
-nominal, EEP-69 / OTP 28+): Parsed askind = nominal, still expanded structurally. -
Native Records (
-record #name{}, EEP-79 / OTP 29+): Not yet extracted or checked. -
Value-Correlated Spec Overloads & Formalization: Dispatch correlations like
rabbit_ff_controller:run_callback/5and the standaloneTYPESYSTEM.md/ Lean 4 / Rocq formalization remain queued.