Git Product home page Git Product logo

bolt's Introduction

Bolt - Data-Race Freedom Baked In

CircleCI Coverage Status

What, another programming language?

Yep, this one prevents data races! Concurrent code is hard to get right, so let the language take care of it for you! The best part is that you get more fine-grained concurrency than Rust and this language doesn't get in the way when you want to write single-threaded code. Want to write Rusty ownership-style code - yep, you can do that in Bolt too!

For a description of the theory, check out the accompanying dissertation.

Alright so what does this language do?

You can already write a lot of Java-esque code - see examples/ in this repo. Bolt already supports inheritance, method overloading and overriding, and generics. Is Bolt missing something? Comment on this issue - I'm all ears.

Two ways Bolt differs from traditional languages - the capability annotations for fields and function/method type signatures, and a structured approach to concurrency - so you know exactly how long your threads live for:

finish{
  async{ // fork a thread using the async command - you can spawn as many as you like!
    ... // execute an expression in the forked thread
  }
  ... // continue executing your code on current thread

} // all forked threads finish executing here

Wait, how did you build this?

A lot of trial-and-error and experimenting with reverse-engineering C++ code! I'll save you the trouble - step-by-step tutorials for how I built this all are incoming - I'll tweet about them when they drop so follow me on Twitter. Update: all the posts are live.

Unlike your run-of-the-mill compiler tutorials, we'll be talking about more advanced language features too, like generics, inheritance, method overloading and overriding!

Getting started

Bolt's compiler is written in OCaml and C++. You'll need OCaml and opam installed. You'll also need to install Bazel.

Note you don't need to have LLVM installed - just update llvm.bzl to use the right pre-built LLVM Binary, and Bazel will download and extract that binary for you!

Once you have these installed, the Makefile details all the main commands. To get started run these commands!

  • make install - install dependencies
  • make hook - install the git pre-commit hook
  • make build - build the project

To compile a program:

  • scripts/compile_program.sh <filename> <flag> - run a Bolt program (extension .bolt) - pass in the-help flag to see the list of possible flags you can pass in.
  • alias boltc=./scripts/compile_program.sh >> ~/.bashrc

To compile and run the program:

  • scripts/run_program.sh <filename> <flag> - run a Bolt program (extension .bolt) - pass in the-help flag to see the list of possible flags you can pass in.
  • alias bolt=./scripts/run_program.sh >> ~/.bashrc - okay this isn't strictly necessary, but running bolt <filename> to execute a Bolt program is super cool!

Okay, - the boltc and bolt aliasing isn't strictly necessary, but running boltc <filename> to compile and bolt <filename> to run a Bolt program is super cool!

Check out the REPO_OVERVIEW.md file for more details about the project structure.

bolt's People

Contributors

mukul-rathi avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bolt's Issues

Design AST output structure of Menhir

This should have a corresponding .mli file and contain Ocaml types for the expression and class / trait definitions.

(To be used for the subsequent type-checking and interpreter stages).

Check linear references are not aliased

Use a capture checker of sorts - the idea being that new Foo() is an un-captured object, but let x = (new Foo()) is captured (owned by x).

So check let exprs -> let x = e in ___ is only allowed if either e is not a linear object, or if e is an uncaptured linear object.

Read in a program file

Given the path to a file as a command-line argument, read in the text from the file as a string.

Add methods to classes

For now, methods will be associated with classes rather than traits (since diverging from the type system Kappa to use regions)

Create driver function

This drives the computation until the first thread has finished executing - reduced to a value.

Make dune build files less verbose

Rewrite dune files so one library for each folder, rather than the verbose "one library per module" approach used (not the right approach).

Add binary operators to Bolt

i.e. for ints

+ - * / % < <= > >= (where / is integer division e.g 7/2 = 3)

and for bools

&& ||

and for both
!= ==

Define heap

Abstract Address type as well as ability to allocate object on the heap (generate new address type)

Create sample programs

These will be used for E2E testing (as well as any unit/integration tests involving the lexer).

Fix deployment of docs

Currently Circle CI is not deploying documentation to https://bolt.mukulrathi.com

Odoc only builds docs for the public libraries - so it isn't generating documentation files for each of the .mli files (worth switching to ocamldoc?).

Create run-time env

Env maps vars -> values
Should also have helper functions to get/set/update environment.

Only run relevant integration E2E tests

Currently running the entire suite of programs for each of the stages - parsing, type-checking, checking data-races, interpreter. This is very slow.

Improvements

  • If a program fails the preceding stage (e.g. parse error etc.) then don't run it for this stage
  • look at flakiness of data-racey programs with the interpreter e2e test
  • rely more on unit tests than integration tests and reduce the overall program suite to more interesting examples. (Potentially longer more complex programs)

Coveralls shows incorrect path for files

E.g. src/parsing/ast_types.ml is shown in coveralls as src/ast_types.ml - this means you cannot click on file and see the per-line coverage.

This is likely due to the (copy files) stanza used in the dune build file - which during the build puts all files in the same src/ folder for easy referencing of modules.

Move to dune 2.0

Currently using v1.1 of dune - worth switching to v2.0 since that's what the most up-to-date documentation refers to.

Check thread references are not accessed in another thread

A simple way of ensuring this would be to filter out var bindings to "thread" objects in the env of e2 in finish{ async{e1} async{e2} };e and then infer the type of the e2 to see if still type-checks.

Could also check that free-vars of e2 don't contain thread vars.

Use Top Level Functions rather than Lambda Fns

Matter of style:

This is more in line with Java - closures aren't really used in OOP and it's much cleaner to define all the functions beforehand as

function int f (int x) { 
        x
}

rather than

 let f = fun x:int -> x end in   
        ....
end

Create type env

This consists of a set of utility functions that allow look-up of types in the environment
E.g. Var -> Type mapping, Class_name -> Class defn mapping etc.

Implement Lexer

Tokenise syntax - for a given Bolt program file, read it in and output a stream of tokens.

Define let-bindings in terms of block scope

Matter of style - simillar to ES2015 JS:

{
let x = 5;
let y = 6;
....
}
(* x and y not accessible in this scope *)

is cleaner than

let x = 5 in 
  let y = 6 in
      ....
  end
end

Ensure envs of async expressions are disjoint

This could be enforced by removing free variables in the first expression from the environment of the second and then running type-checking on second expression using the reduced environment.

Implement abstract classes

classes can override the capability modes.

So can override AbstractCounter with LockedCounter and LinearCounter etc.

Check consumed vars cannot be referenced subsequently

Core type-checker should return the updated env after having inferred the type of an expression, since the env may change (e.g. x now is a dangling pointer after consume x).

Currently these are not being caught by the type-checker - resulting in a run-time error.

Check well-formedness of class/trait definitions

Use trait definitions to check well-formedness of class definitions - i.e. if all required fields match up, no duplication of fields etc.

Likewise, check that traits with capability read have only const fields.

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.