Giter Club home page Giter Club logo

type-layout's Introduction

Filling a Niche

Note: I am not currently accepting pull requests.

This is the artifact for my POPL 2022 Student Research Competition project, "Filling a Niche: Using Spare Bits to Optimize Data Representation". You can read the 3-page extended abstract here, and you can watch the 3-minute lightning talk here.

This artifact implements a type layout engine and interpreter for a simple, purely-functional language. See below for instructions on how to use the interpreter.

Building and Running

  1. Install Rust.
  2. Run cargo run in the repository to launch the interactive interpreter.

Usage

If you enter an expression into the interpreter, it will compile it to LIR (a low-level IR; like a functional LLVM IR), evaluate it, and print the resulting LIR machine value (not the equivalent high-level, abstract value). For example, the following code demonstrates the niched representation of None of type Maybe<Bool>:

> alias MaybeBool = < None of {} | Some of < False of {} | True of {} > > in <None = {}> as MaybeBool
{ tag = 2_u64 }

You can find some example expressions in example.fun. (Note that multiline input is not currently supported by the interpreter, so you will have to replace newlines within an expression with spaces.)

The interpreter also has several commands that you can use to introspect an expression or type. For example, :lyt will print the computed memory layout of a type:

> :lyt < None of {} | Some of < False of {} | True of {} > >
Variant(Tagged(tag: Niche(path: ({root} as(transparent) Some).{tag}, values: { None => 2 }), variants:
| None => Aggregate {}
| Some => Variant(Tagged(tag: Direct(values: { False => 0, True => 1 }, niches: 3..=18446744073709551615), variants:
| False => Aggregate {}
| True => Aggregate {}
))
))
Command Argument Description
:hir expression Print the HIR (high-level IR; desugared syntax)
:lir expression Compile to LIR and print it (low-level IR; like a functional LLVM IR)
:lyt, :layout type Print the type's layout
:t, :hty, :hirty expression Print the type of the expression's HIR form
:lty, :lirty expression Compile to LIR and print the LIR type
:size type Print the packed size, in bytes, of a type (i.e., the size ignoring padding)

type-layout's People

Contributors

camelid 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.