Skip to content

Commit 65ee2e0

Browse files
authored
Merge pull request #768 from google-research/safe-names-dev
Recognize that "safe-names-dev" is the new "main"
2 parents f1ce5fa + 9cb9981 commit 65ee2e0

File tree

120 files changed

+19196
-21028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+19196
-21028
lines changed

.github/workflows/docs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
strategy:
1212
matrix:
13-
os: [ubuntu-18.04]
13+
os: [ubuntu-20.04]
1414
include:
15-
- os: ubuntu-18.04
16-
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config
17-
path_extension: /usr/lib/llvm-9/bin
15+
- os: ubuntu-20.04
16+
install_deps: sudo apt-get install llvm-12-tools llvm-12-dev pkg-config
17+
path_extension: /usr/lib/llvm-12/bin
1818

1919
steps:
2020
- name: Checkout the repository

.github/workflows/haskell-ci.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ on:
44
push:
55
branches: [ main ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ main, safe-names-dev ]
88

99
jobs:
1010
build:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-18.04, macos-latest]
14+
os: [ubuntu-20.04, macos-latest]
1515
include:
1616
- os: macos-latest
17-
install_deps: brew install llvm@9 pkg-config wget gzip
18-
path_extension: $(brew --prefix llvm@9)/bin
19-
- os: ubuntu-18.04
20-
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config wget gzip
21-
path_extension: /usr/lib/llvm-9/bin
17+
install_deps: brew install llvm@12 pkg-config wget gzip
18+
path_extension: $(brew --prefix llvm@12)/bin
19+
- os: ubuntu-20.04
20+
install_deps: sudo apt-get install llvm-12-tools llvm-12-dev pkg-config wget gzip
21+
path_extension: /usr/lib/llvm-12/bin
2222

2323
steps:
2424
- name: Checkout the repository
@@ -52,8 +52,8 @@ jobs:
5252
$GITHUB_WORKSPACE/examples/t10k-images-idx3-ubyte
5353
$GITHUB_WORKSPACE/examples/t10k-labels-idx1-ubyte
5454
55-
key: ${{ runner.os }}-v2-${{ hashFiles('**/*.cabal', 'stack*.yaml') }}
56-
restore-keys: ${{ runner.os }}-v2-
55+
key: ${{ runner.os }}-v5-${{ hashFiles('**/*.cabal', 'stack*.yaml') }}
56+
restore-keys: ${{ runner.os }}-v5-
5757

5858
# This step is a workaround.
5959
# See issue for context: https://github.com/actions/cache/issues/445

.github/workflows/julia-ci.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: Julia tests
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ ]
88

99
jobs:
1010
build:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-18.04]
14+
os: [ubuntu-20.04]
1515
include:
16-
- os: ubuntu-18.04
17-
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config wget gzip
18-
path_extension: /usr/lib/llvm-9/bin
16+
- os: ubuntu-20.04
17+
install_deps: sudo apt-get install llvm-12-tools llvm-12-dev pkg-config wget gzip
18+
path_extension: /usr/lib/llvm-12/bin
1919

2020
steps:
2121
- name: Checkout the repository

.github/workflows/python-ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ on:
44
push:
55
branches: [ main ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ main, safe-names-dev ]
88

99
jobs:
1010
build:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-18.04]
14+
os: [ubuntu-20.04]
1515
include:
16-
- os: ubuntu-18.04
17-
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config wget gzip
18-
path_extension: /usr/lib/llvm-9/bin
16+
- os: ubuntu-20.04
17+
install_deps: sudo apt-get install llvm-12-tools llvm-12-dev pkg-config wget gzip
18+
path_extension: /usr/lib/llvm-12/bin
1919

2020
steps:
2121
- name: Checkout the repository

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ examples/export/array
2828
hie.yaml
2929
Manifest.toml
3030
julia/deps/build.log
31+
examples/t10k-images-idx3-ubyte
32+
examples/t10k-labels-idx1-ubyte

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ development. Expect monstrous bugs and razor-sharp edges!**
3030
## Dependencies
3131

3232
* Install [stack](https://www.haskellstack.org)
33-
* Install LLVM 9
34-
* Ubuntu/Debian: `apt-get install llvm-9-dev`
35-
* macOS: `brew install llvm@9`
36-
* Make sure `llvm@9` is on your `PATH` before building. Example: `export PATH="$(brew --prefix llvm@9)/bin:$PATH"`
37-
* Install clang 9 (may be installed together with llvm)
38-
* Ubuntu/Debian: `apt-get install clang-9`
33+
* Install LLVM 12
34+
* Ubuntu/Debian: `apt-get install llvm-12-dev`
35+
* macOS: `brew install llvm@12`
36+
* Make sure `llvm@12` is on your `PATH` before building. Example: `export PATH="$(brew --prefix llvm@12)/bin:$PATH"`
37+
* Install clang 12 (may be installed together with llvm)
38+
* Ubuntu/Debian: `apt-get install clang-12`
3939
* macOS: installs with llvm
4040
* Install libpng (often included by default in *nix platforms)
4141
* Ubuntu/Debian: `apt-get install libpng-dev`
@@ -85,6 +85,28 @@ manually. This will be ignored by git.
8585

8686
This should work out of the box with Emacs' `lsp-haskell` package.
8787

88+
### Building with Nix
89+
90+
[Nix](https://nixos.org/) is a functional package manager and build system.
91+
92+
To build with vanilla Nix:
93+
```bash
94+
$ nix-build
95+
```
96+
97+
To build with flakes-enabled Nix:
98+
```bash
99+
$ nix build .#dex
100+
```
101+
The resulting `dex` binary should be in `result/bin/dex`.
102+
103+
For development purposes, you can use a Nix environment with
104+
```bash
105+
$ nix-shell
106+
$ nix develop # With flakes
107+
```
108+
and use `make` to use Stack to build Dex.
109+
88110
## Running
89111

90112
* Traditional REPL: `dex repl`

default.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{ pkgs ? import <nixpkgs> {},
2+
llvm-hs-src ? pkgs.fetchFromGitHub {
3+
owner = "llvm-hs";
4+
repo = "llvm-hs";
5+
rev = "llvm-12";
6+
sha256 = "IG4Mh89bY+PtBJtzlXKYsPljfHP7OSQk03pV6fSmdRY=";
7+
},
8+
cudaPackage ? pkgs.cudaPackages.cudatoolkit_11,
9+
cuda ? false,
10+
optimized ? true,
11+
live ? true,
12+
}:
13+
let
14+
llvm-hs-pure = pkgs.haskellPackages.callCabal2nix "llvm-hs-pure" "${llvm-hs-src}/llvm-hs-pure" {
15+
};
16+
llvm-hs = (pkgs.haskellPackages.callCabal2nix "llvm-hs" "${llvm-hs-src}/llvm-hs" {
17+
inherit llvm-hs-pure;
18+
}).overrideAttrs (oldAttrs: rec {
19+
buildInputs = oldAttrs.buildInputs ++ [
20+
pkgs.llvm_12
21+
];
22+
});
23+
buildFlags = pkgs.lib.optionals optimized [
24+
"-foptimized"
25+
] ++ pkgs.lib.optionals live [
26+
"-flive"
27+
] ++ pkgs.lib.optionals cuda [
28+
"-fcuda"
29+
"--extra-include-dirs=${cudaPackage}/include"
30+
"--extra-lib-dirs=${cudaPackage}/lib64/stubs"
31+
];
32+
cxxFlags = [
33+
"-fPIC"
34+
"-std=c++11"
35+
"-fno-exceptions"
36+
"-fno-rtti"
37+
] ++ pkgs.lib.optional cuda "-DDEX_CUDA"
38+
++ pkgs.lib.optional live "-DDEX_LIVE";
39+
buildRuntimeCommand = ''
40+
${pkgs.clang_9}/bin/clang++ \
41+
${builtins.concatStringsSep " " cxxFlags} \
42+
-c \
43+
-emit-llvm \
44+
-I${pkgs.libpng}/include \
45+
src/lib/dexrt.cpp \
46+
-o src/lib/dexrt.bc
47+
'';
48+
in
49+
# `callCabal2nix` converts `dex.cabal` into a Nix file and builds it.
50+
# Before we do the Haskell build though, we need to first compile the Dex runtime
51+
# so it's properly linked in when compiling Dex. Normally the makefile does this,
52+
# so we instead sneak compiling the runtime in the configuration phase for the Haskell build.
53+
(pkgs.haskellPackages.callCabal2nix "dex" ./. {
54+
inherit llvm-hs;
55+
inherit llvm-hs-pure;
56+
}).overrideAttrs (attrs: {
57+
configurePhase = ''
58+
# Compile the Dex runtime
59+
echo 'Compiling the Dex runtime...'
60+
set -x
61+
${buildRuntimeCommand}
62+
set +x
63+
echo 'Done compiling the Dex runtime.'
64+
65+
# Run the Haskell configuration phase
66+
${attrs.configurePhase}
67+
'';
68+
configureFlags = builtins.concatStringsSep " " buildFlags;
69+
buildInputs = attrs.buildInputs ++ (pkgs.lib.optional cuda
70+
cudaPackage
71+
);
72+
})

dex.cabal

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ flag llvm-head
3636

3737
flag foreign
3838
description: Build the C interface to Dex
39-
default: True
39+
default: False
4040

41-
flag safe-names
42-
description: Enables building with safe names checks
41+
flag debug
42+
description: Enable extra checks and stack trace printing (useful for developers)
4343
default: False
4444

4545
library dex-resources
@@ -51,25 +51,19 @@ library dex-resources
5151
default-extensions: CPP
5252

5353
library
54-
exposed-modules: Env, Syntax, Type, Inference,
55-
Parser, Util, Imp, Imp.Builder, Imp.Optimize,
56-
PPrint, Algebra, Parallelize, Optimize, Serialize
57-
Builder, Cat,
58-
Simplify, TopLevel,
59-
Autodiff, Interpreter, Logging, CUDA,
60-
LLVM.JIT, LLVM.Shims, JIT, LLVMExec, Export
61-
Err, LabeledItems, SourceRename,
62-
SaferNames.Name, SaferNames.LazyMap,
63-
SaferNames.Syntax, SaferNames.Bridge,
64-
SaferNames.PPrint, SaferNames.Parser,
65-
SaferNames.ResolveImplicitNames, SaferNames.SourceRename,
66-
SaferNames.Type, SaferNames.Builder, SaferNames.Inference,
67-
SaferNames.CheapReduction
54+
exposed-modules: Syntax, Cat, Util, PPrint, Serialize
55+
TopLevel, Interpreter, Logging, CUDA,
56+
LLVM.JIT, LLVM.Shims, JIT, LLVMExec,
57+
Err, LabeledItems, SourceRename, Name, Parser, MTL1,
58+
Type, Builder, Inference, CheapReduction, GenericTraversal,
59+
Simplify, Imp, Algebra, Linearize, Transpose,
60+
LLVM.HEAD.JIT
6861
if flag(live)
6962
exposed-modules: Actor, RenderHtml, LiveOutput
7063
other-modules: Paths_dex
7164
build-depends: base, containers, mtl, bytestring,
72-
llvm-hs-pure, llvm-hs, transformers,
65+
llvm-hs-pure, llvm-hs, transformers, hashable, unordered-containers,
66+
exceptions, utf8-string, cryptonite,
7367
-- Parsing
7468
megaparsec, parser-combinators,
7569
-- Text output
@@ -82,9 +76,8 @@ library
8276
build-depends: warp, wai, blaze-html, http-types, cmark, binary
8377
cpp-options: -DDEX_LIVE
8478
cxx-options: -DDEX_LIVE
85-
if flag(safe-names)
86-
cpp-options: -DDEX_SAFE_NAMES
87-
cxx-options: -DDEX_SAFE_NAMES
79+
if flag(debug)
80+
cpp-options: -DDEX_DEBUG
8881
if !os(darwin)
8982
exposed-modules: Resources
9083
hs-source-dirs: src/resources
@@ -101,7 +94,8 @@ library
10194
TupleSections, ScopedTypeVariables, LambdaCase, PatternSynonyms,
10295
BlockArguments, GADTs, TypeOperators, DataKinds, KindSignatures
10396
ConstraintKinds, FlexibleContexts, RankNTypes, QuantifiedConstraints,
104-
TypeOperators, MultiParamTypeClasses, FunctionalDependencies
97+
TypeOperators, MultiParamTypeClasses, FunctionalDependencies,
98+
GeneralizedNewtypeDeriving
10599
pkgconfig-depends: libpng
106100
if flag(cuda)
107101
include-dirs: /usr/local/cuda/include
@@ -112,21 +106,13 @@ library
112106
ghc-options: -O3
113107
else
114108
ghc-options: -O0
115-
if flag(llvm-head)
116-
cpp-options: -DDEX_LLVM_VERSION=HEAD
117-
build-depends: mlir-hs
118-
exposed-modules: LLVM.HEAD.JIT,
119-
MLIR.Lower, MLIR.Eval
120-
else
121-
cpp-options: -DDEX_LLVM_VERSION=9
122-
exposed-modules: LLVM.V9.JIT, LLVM.V9.Shims
123109

124110
executable dex
125111
main-is: dex.hs
126112
other-extensions: OverloadedStrings
127113
build-depends: dex, base, containers, haskeline, prettyprinter, mtl,
128114
optparse-applicative, ansi-wl-pprint,
129-
unix, store, bytestring, directory
115+
unix, store, bytestring, directory, exceptions
130116
if os(darwin)
131117
build-depends: dex-resources
132118
default-language: Haskell2010

examples/ctc.dx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@ pass automatically. That makes this code much shorter than
1818
most implementations.
1919

2020

21-
def interleave (blank:v) (labels: m=>v) : (m & (Fin 2))=>v =
21+
def interleave {m v} (blank:v) (labels: m=>v) : (m & (Fin 2))=>v =
2222
-- Turns "text" into "t e x t " by first pairing each letter with a blank,
2323
-- then flattening the pairs back into a single-index table.
2424
pairs = for i. [labels.i, blank]
2525
for (i, j). pairs.i.j
2626

27-
def prepend (first: v) (seq: m=>v) : ({head:Unit | tail:m }=>v) =
27+
def prepend {m v} (first: v) (seq: m=>v) : ((Unit|m)=>v) =
2828
-- Concatenates a single element to the beginning of a sequence.
2929
for idx. case idx of
30-
{| head = () |} -> first
31-
{| tail = i |} -> seq.i
30+
Left () -> first
31+
Right i -> seq.i
3232

33-
def prepend_and_interleave (blank:v) (seq: m=>v) :
34-
({head:Unit | tail:(m & (Fin 2))}=>v) =
33+
def prepend_and_interleave {m v} (blank:v) (seq: m=>v) : ((Unit|(m & (Fin 2)))=>v) =
3534
-- Turns "text" into " t e x t".
3635
-- The output of this function has a slightly complicated output type, which
3736
-- has size 1 + 2 * (size m).
3837
interleaved = interleave blank seq
3938
prepend blank interleaved
4039

41-
def clipidx (n:Type) -> (i:Int) : n =
40+
def clipidx (n:Type) [Ix n] (i:Int) : n =
4241
-- Returns element at 0 if less than zero.
4342
-- Ideally we could have an alternative
4443
-- to Fin that just clips the index at its bounds.
@@ -48,7 +47,8 @@ def logaddexp (x:Float) (y:Float) : Float =
4847
m = max x y
4948
m + ( log ( (exp (x - m) + exp (y - m))))
5049

51-
def ctc [Eq vocab, Eq position, Eq time]
50+
def ctc {vocab time position}
51+
[Eq vocab, Eq position, Eq time]
5252
(blank: vocab)
5353
(logits: time=>vocab=>Float)
5454
(labels: position=>vocab)
@@ -102,7 +102,7 @@ def ctc [Eq vocab, Eq position, Eq time]
102102

103103
'### Demo
104104

105-
def randIdxNoZero (n:Type) -> (k:Key) : n =
105+
def randIdxNoZero (n:Type) [Ix n] (k:Key) : n =
106106
unif = rand k
107107
fromOrdinal n $ (1 + (FToI (floor ( unif * IToF ((size n) - 1)))))
108108

0 commit comments

Comments
 (0)