In this case study, we run Prisma over Ecto, Elixir's flagship data-mapping and language-integrated query toolkit. With 58 .ex source files compiling into 104 BEAM modules full of macros, protocols, structs, recursive Macro.t() ASTs, and complex @spec contracts, Ecto is a demanding real-world stress test for Elixir static analysis.
Using Prisma's hybrid analyzer (v0.2.4) on Elixir 1.20.4 / OTP 29, the entire Ecto codebase is checked in 0.65 seconds (0.631s–0.689s). Prisma surfaced 3 real @spec inconsistencies and 7 unused private-function parameters (oxbow_code) that Elixir 1.20's compiler left unreported. All fixes and a portable ecto_3.15.0-dev.pplt (173 KB) have been submitted upstream in elixir-ecto/ecto#4817.
1. Execution Metrics & Summary
| Metric | Value |
|---|---|
| Source files / BEAM modules |
58 .ex / 104 .beam |
| Elixir / Erlang runtime | Elixir 1.20.4 / OTP 29 (ERTS 17.1.1) |
Prisma check wall time (hybrid) |
0.65 s (0.631s – 0.689s, 0.80s CPU) |
| Dialyzer check wall time (warm PLT) | 2.28 s (5.14 s CPU, +21.14 s initial PLT build) |
Portable .pplt vs Dialyzer PLT |
173 KB (ecto_3.15.0-dev.pplt) vs 2,000 KB |
Elixir 1.20.4 compiler warnings in lib/ |
0 |
Dialyzer warnings in lib/ecto/ |
9 (including changeset.ex:2664 && false positive; missed all 3 @spec bugs & 7 oxbow_code) |
| Prisma findings resolved |
10 (3 @spec mismatches + 7 oxbow_code) |
Post-fix mix test |
1649 passed (97 doctests, 1552 tests) |
Post-fix prisma check (hybrid) |
0 warnings |
2. Why Elixir 1.20.4 Missed These Findings
Compiling Ecto with Elixir 1.20.4 produces 0 type warnings across lib/ (only 3 intentional error-case warnings in test/). That is expected given Elixir's current gradual set-theoretic type system roadmap:
-
No
@specvs. body verification yet: Elixir 1.20 infers types from patterns and guards inside a function, but does not cross-check traditional@specattributes against the function body or callers. -
No structural dead-parameter analysis (
oxbow_code): Unused parameters in private functions (defp) are not flagged when prefixed with_.
Prisma reads Elixir's debug_info directly from .beam files, checks @spec contracts in hybrid mode (strict gradual subtyping where specs exist, success typing where they do not), and runs structural oxbow_code reachability analysis on private functions.
3. Real Bugs & Cleanups Found in Ecto
A. @spec Mismatches (3)
-
Ecto.Repo.Assoc.query/4(lib/ecto/repo/assoc.ex:10)-
Declared:
@spec query([list], list, tuple, (list -> list)) :: [Ecto.Schema.t] -
Actual: Every clause returns
[list]([],Enum.map(rows, fun)wherefun :: (list -> list), and[load_assocs(item, refls) | sub_structs]), andEcto.Repo.Queryable.execute/4pipes the result straight intoEcto.Repo.Preloader.query/7, whose@specexpects[list]. -
Fix: Updated the return spec to
:: [list].
-
Declared:
-
Ecto.Query.Builder.From.build/5(lib/ecto/query/builder/from.ex:80)-
Declared:
@spec build(..., atom, ...)for theasparameter. -
Actual: Immediately matches
{:^, _, [as]}for runtime-interpolated aliases (from(p in Post, as: ^name)), which is a 3-tuple AST rather than anatom. -
Fix: Widened
asin@spectoatom | Macro.t().
-
Declared:
-
Ecto.Query.Builder.Join.build/10(lib/ecto/query/builder/join.ex:155)-
Declared & Actual: Same
@specnarrowing (atomvs.{:^, _, [as]}). -
Fix: Widened
asin@spectoatom | Macro.t().
-
Declared & Actual: Same
B. Unused Private Parameters (oxbow_code, 7)
All 7 findings are in private (defp) functions, so removing them preserves 100% of Ecto's public API and backwards compatibility:
-
Ecto.Multi.apply_operation/4->/3(lib/ecto/multi.ex:917):_apply_argswas ignored across all 7 clauses (leftover from an earlier refactor;_wrapinapply_operation/5was also marked unused). -
Ecto.Query.Builder.Windows.build_runtime_window/2->/1(lib/ecto/query/builder/windows.ex:158):_envwas unused. -
Ecto.Changeset.put_relation/5->/4(lib/ecto/changeset.ex:2223):_optswas unused (publicput_assoc/4andput_embed/4signatures remain unchanged). -
Ecto.Repo.Preloader.maybe_pmap/3->/2(lib/ecto/repo/preloader.ex:152):_repo_namewas unused. -
Ecto.Repo.Schema(lib/ecto/repo/schema.ex:36, 476, 604):_namewas unused in privatedo_insert_all/7->/6,do_insert/4->/3, anddo_update/4->/3(publicinsert_all/5,insert/4, andupdate/4remain unchanged).
4. What Ecto Taught Us About Prisma (v0.2.4)
Running Prisma against Ecto's heavy metaprogramming also exposed 6 real edge cases in Prisma itself, all fixed and covered by new tests in v0.2.4:
-
Recursive types in tuple/list patterns:
extract_tuple_elems/2,extract_list_elem/1, andlist_tail_type/1now treatunresolved/1types (such as{recursive_ref, ...}inEcto.Type.t()) asanyinstead ofnone, fixing falsedead_codeinEcto.Type.dump/3andload/3for{:array, {:parameterized, _}}. -
Heterogeneous cons patterns
[H | T]:bind_pattern({cons, _, H, T}, ...)now joinsHTwithextract_list_elem(TT)instead of assuming the whole list hasH's type (e.g.[Access, :get]inEcto.Query.Builder). -
Elixir multi-
whenguards:when G1 when G2in Elixirelixir_v1AST is a disjunction ([[G1], [G2]]), not a conjunction ([[G1, G2]]), eliminating falsedead_codeinEcto.Query.Builder.escape/5. -
Open map updates (
%{m | k: v}):update_map_type/2onany_mapor unresolved bases now preserves openness (any_map) rather than collapsing into a closed map with only the updated keys (Ecto.Query.Planner.plan_subquery/6). -
Elixir macro hygiene & intrinsics:
&&/||expansions (x@...@Elixir.Kernel) are recognized as macro-generated clauses ininfer_case, andEnum.__in__/2(-> boolean()) andIO.warn/1,2(-> :ok) are modeled directly. -
Raise-only stub functions:
prisma_oxbownow exempts private stub helpers where every clause unconditionally raises/errors (such asEcto.Query.API.doc!/1andEcto.Query.WindowAPI.doc!/1).
5. Performance Comparison: Prisma vs. Dialyzer on Ecto
Running both tools on the same 104 Ecto BEAM modules on Apple Silicon:
| Metric | Dialyzer (OTP 29) |
Prisma v0.2.4 (hybrid) |
|---|---|---|
Initial PLT / .pplt build |
21.14 s | < 0.2 s |
| Warm check wall time | 2.28 s |
0.65 s (0.631s – 0.689s) |
| Warm check CPU time |
5.14 s (4.42s user + 0.72s sys) |
0.80 s (~0.57s user + 0.23s sys) |
| Artifact size on disk | 2,000 KB (PLT) |
173 KB (ecto_3.15.0-dev.pplt) |
Findings in lib/ecto/ |
9 warnings (incl. changeset.ex:2664 && false positive; 0 @spec bugs) |
10 real findings (3 @spec bugs + 7 oxbow_code) |
Open-Source Regression Check (v0.2.0 vs. v0.2.4, 3 runs)
| Corpus |
v0.2.0 (14f26c0) |
v0.2.4 |
Notes |
|---|---|---|---|
prisma (ebin/*.beam) |
0.340s – 0.660s | 0.440s – 0.464s | 0 warnings |
jsone (ebin/*.beam) |
0.250s – 0.259s | 0.274s – 0.281s | 0 warnings |
saxy (ebin/*.beam) |
0.372s – 0.397s | 0.478s – 0.558s | 0 warnings |
ecto (104 modules) |
0.507s – 0.562s | 0.631s – 0.689s | 0 warnings |