Coder Social home page Coder Social logo

boa's Introduction

Boa - A static type inference engine for Python

A type checker for python that is capable of inferring types and performing flow sensitive static analysis. Boa is also capable of compiling a subset of Python to native code, making it upwards of 50 times faster and suitable for use in low-energy embedded programming environments like microprocessors.

Here is a very basic example that detects a type error before any code is run:

x = 123 + 3.0 / 1.0 # type of x = float
y = 'abc' # type of y = string
bad = x + y # woops!

The above code is obviously incorrect, because we're trying to add a float and a string, but the Python interpreter won't know that until this chunk of code is executed. With Boa, mistakes like these can be caught easily even before we have any test coverage:

(All type soundness errors are detected live, as you're writing the code.)

With a trivial example like that, it might seem redundant to have an inference engine point out mistakes that only a beginner would make. However, when a codebase gets large enough and you've got several functions all over the place that have certain restrictions on their parameter types, Boa can be a huge benefit.

Boa exists to demonstrate that a level of indirection and transpilation is not always needed (as in the case of Typescript and flow) to maintain type soundness in a codebase.

Boa also aims to compile a subset of the Python programming language to native machine code. This would allow seemingly dynamically typed code to be used for embedded programming environments that cannot afford to run an entire Python interpreter.

How does it work ?

To perform the flow sensitive type inference, we use a variation of Damas-Hindley-Milner, empowered with concepts like Typeclasses, traits and dependent types.

For compilation to ASM, we use C as a backend, along with a High level IR.

References:

  1. Hindley Milner inference by Stephen Diehl
  2. Type traits in rust
  3. Ian Grant - The Hindley Milner Type inference Algorithm

boa's People

Contributors

srijan-paul avatar manoharbabun avatar deepsource-io[bot] avatar

Stargazers

Ellis Breen avatar

Watchers

 avatar  avatar

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.