polytropos-plugin: TcPlugin that emits literal evidence for Polytropos row classes

[ compiler-plugin, library ] [ Propose Tags ] [ Report a vulnerability ]

A GHC typechecker plugin for polytropos that solves the evidence-class constraints (Polytropos.Core.FieldIndex, Polytropos.Core.ConstructorIndex, Polytropos.Core.RowEq, Polytropos.Core.RowShow, Polytropos.Core.RowEqSum, Polytropos.Core.RowShowSum, Polytropos.Core.AllFields) by inspecting the row carried in a Polytropos.Core.RowRep's type and emitting literal slot indices, tags, and dictionary vectors directly into GHC Core AST — eliminating inductive type-level search and pointer-chasing runtime overhead entirely.

Uses the ghc-tcplugin-api library for a streamlined interface to GHC's typechecker plugin API across compiler versions.

Start at the front door module Polytropos.Plugin for complete usage instructions and worked examples. Enable in consuming packages via: ghc-options: -fplugin=Polytropos.Plugin.


[Skip to Readme]

Modules

  • Polytropos
    • Polytropos.Plugin
      • Polytropos.Plugin.Source

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.2
Change log CHANGELOG.md
Dependencies base (>=4.18 && <4.23), ghc (>=9.6 && <9.15), ghc-tcplugin-api (>=0.1 && <0.21) [details]
License (EUPL-1.2 OR Apache-2.0)
Author Nadia Yvette Chambers
Maintainer nadia.yvette.chambers@ik.me
Uploaded by nyc at 2026-10-21T21:34:23Z
Category Compiler Plugin
Home page https://github.com/NadiaYvette/polytropos
Bug tracker https://github.com/NadiaYvette/polytropos/issues
Source repo head: git clone https://github.com/NadiaYvette/polytropos(packages/polytropos-plugin)
Distributions
Reverse Dependencies 15 direct, 0 indirect [details]
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs pending
Build status unknown [no reports yet]

Readme for polytropos-plugin-0.1.0.2

[back to package description]

polytropos-plugin

GHC typechecker plugin synthesizing literal dictionaries and \(O(1)\) jump tables directly into Core AST for polytropos.

Overview

In traditional Haskell row libraries, solving field offsets or dictionary instances involves either:

  1. Recursive type-level search (\(O(N)\) or \(O(N^2)\) compile-time scaling).
  2. Runtime dictionary passing and pointer chasing.

polytropos-plugin solves evidence constraints (FieldIndex, ConstructorIndex, RowEq, RowShow, RowEqSum, RowShowSum, AllFields) by inspecting the row at compile time and emitting literal slot indices, tags, and dictionary vectors directly into GHC Core AST.

Usage

Enable the plugin in your .cabal file or module:

build-depends:
    polytropos-core >= 0.1 && < 0.2
  , polytropos-plugin >= 0.1 && < 0.2

ghc-options: -fplugin=Polytropos.Plugin

Quick Example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# OPTIONS_GHC -fplugin=Polytropos.Plugin #-}

import Polytropos

type User = Record '[ "name" := String, "score" := Int ]

main :: IO ()
main = do
  -- The plugin lowers REC into flat array construction:
  let user = REC { name = "Alice", score = 100 }
  putStrLn ("User: " ++ user.name)

  -- The plugin solves REC_UPD into O(1) setField without parentheses:
  let updated = REC_UPD user { score = 150 }
  print updated.score

Features

  • Literal Offset Resolution: Solves FieldIndex @"foo" r directly to integer slot literals.
  • Literal Tag Resolution: Solves ConstructorIndex @"Bar" s directly to integer constructor tags.
  • Unrolled Core Synthesis: Direct code generation for record equality (RowEq) and formatting (RowShow).
  • Human-Centric Error Diagnostics: Custom TypeError reporting with Levenshtein-distance fuzzy field name suggestions when fields or constructors are missing.
  • Cross-GHC Support: Supports GHC 9.6 through GHC 9.14 via internal compatibility shims.

Documentation & Repository

License

Dual-licensed under EUPL-1.2 OR Apache-2.0.