GithubHelp home page GithubHelp logo

ghc-tcplugin-api's Introduction

ghc-tcplugin-api

This library provides a convenient and cross-compatible interface for authors of GHC type-checking plugins (starting from GHC 8.8).

Different stages of a type-checking plugin (initialisation, solving, rewriting, shutdown) are given different monads to operate within. This ensures operations that only make sense in one context aren't mistakenly carried out in another.

To provide a unified interface to these monads (whenever this makes sense), two MTL-style typeclasses are provided: MonadTcPlugin and MonadTcPluginWork.

  • MonadTcPlugin enables overloading of monadic operations common to all stages, such as lifting IO operations or performing name resolution.
    MonadTcPlugin is internally implemented using lifting and unlifting of GHC's TcM monad, but it is hoped that users will not need to access these internals.

  • MonadTcPluginWork allows plugins to emit new work (additional constraints for GHC to process), including throwing custom type errors. These operations are only available in the solving and rewriting stages of a type-checking plugin.
    Helpers for throwing custom type-errors are also provided, by means of the datatype TcPluginErrorMessage (which mimics the ErrorMessage datakind from GHC.TypeLits) and the interpreter mkTcPluginErrorTy.

Discoverability

One goal of this library is to ensure that authors of type-checking plugins should, for the most part, only need to import this library for their type-checking plugin needs, and not the ghc package itself.
This should assist discoverability: instead of having to trawl through the entire GHC codebase, new users should be able to determine at a glance what functions might be appropriate for their usecase using this library's interface. This can be particularly useful when using typed holes.

Compatibility

This library provides a unified interface that works across different GHC versions (starting from GHC 8.8), aiming to reduce the CPP burden imposed on authors of type-checking plugins.

We make use of GHC's new API for rewriting type-families in typechecker plugins, which was part of GHC 9.4.
A compatibility layer is provided, which retro-fits the rewriting functionality onto previous versions of GHC.

Documentation

The package documentation includes an overview of type-checking plugins, and should provide a good starting point for anyone interested in writing a type-checking plugin.

Examples

A simple example plugin which rewrites type family applications, emitting wanted constraints and throwing custom type errors as it goes, is provided here.

A more complex example, that of type-checking an intrinsically typed System F, is provided here. This implements the equational theory of the confluent calculus of explicit substitutions from the paper Confluence properties of weak and strong calculi of explicit substitutions:

Rewrite rules for the confluent calculus of substitutions

ghc-tcplugin-api's People

Contributors

edsko avatar sheaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ghc-tcplugin-api's Issues

Add type variable re-exports

We should re-export TyVar, CoVar and various functions to handle type variables such as isMetaTyVar, isSkolemTyVar, etc.

Re-export some built-ins (e.g. type-level list TyCons)

Some built-in things such as type-level lists, Maybe, Nat, Symbol, tuples... should be re-exported, and the documentation should clarify that these should be used directly instead of the usual name resolution process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.