Skip to content

Commit e385993

Browse files
committed
Add some documentation and minor changes
1 parent e20b787 commit e385993

File tree

5 files changed

+22
-179
lines changed

5 files changed

+22
-179
lines changed

.github/workflows/nix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Cpp Backend CI with Nix
1+
name: CI with Nix
22

33
on:
44
pull_request:
55
push:
6-
branches: [ mlscript ]
6+
branches: [ mlscript, hkmc2 ]
77

88
jobs:
99
build:

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ We recommend you to install JDK and sbt via [coursier][coursier]. The versions o
4444
[node.js]: https://nodejs.org/
4545
[coursier]: https://get-coursier.io/
4646

47+
Some tests in the `compiler` subproject generate and compile C++ while making use of some libraries.
48+
You can run these by installing `nix` (for MacOS, we recommend https://determinate.systems/posts/graphical-nix-installer/)
49+
and running `nix develop` before launching SBT.
50+
If you don't want to use nix, you can install the dependencies manually as follows, but this has not been tested on non-MacOS systems:
51+
```bash
52+
brew install mimalloc boost gmp
53+
```
54+
4755
### Running the tests
4856

4957
Running the main MLscript tests only requires the Scala Build Tool installed.

compiler/shared/test/diff-ir/cpp/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CXX := g++
2-
CFLAGS := $(CFLAGS) -O3 -Wall -Wextra -std=c++20 -I. -Wno-inconsistent-missing-override
3-
LDFLAGS := $(LDFLAGS) -lmimalloc -lgmp
2+
CFLAGS := $(CFLAGS) -O3 -Wall -Wextra -std=c++20 -I. -Wno-inconsistent-missing-override -I/opt/homebrew/include
3+
LDFLAGS := $(LDFLAGS) -lmimalloc -lgmp -L/opt/homebrew/lib
44
SRC :=
55
INCLUDES = mlsprelude.h
66
DST :=

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
];
3232
};
3333
});
34-
}
34+
}

shared/src/test/diff/fcp/NestedDataTypes.mls

Lines changed: 9 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -60,177 +60,12 @@ n4: PerfectTree[int]
6060
//│ = Node1 { subTree: Node1 { subTree: Leaf { value: [Array] } } }
6161

6262

63-
:e // * Needs precise-rec-typing (see below)
64-
rec def map f tree = case tree of {
65-
| Leaf -> Leaf { value = f tree.value }
66-
| Node -> Node { subTree = map (mapTwo f) tree.subTree }
67-
}
68-
//│ ╔══[ERROR] Inferred recursive type: 'a
69-
//│ where
70-
//│ 'a <: {subTree: Leaf[?] & {value: ((?, (?, ?,),), ((?, ?,), ?,),)} | Node[?] & 'a}
71-
//│ ║ l.64: rec def map f tree = case tree of {
72-
//│ ╙── ^^^^
73-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
74-
//│ ║ l.64: rec def map f tree = case tree of {
75-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
76-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
77-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
79-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80-
//│ ║ l.67: }
81-
//│ ║ ^^^
82-
//│ ╙── Note: use flag `:ex` to see internal error info.
83-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
84-
//│ ║ l.64: rec def map f tree = case tree of {
85-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
86-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
87-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
89-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90-
//│ ║ l.67: }
91-
//│ ║ ^^^
92-
//│ ╙── Note: use flag `:ex` to see internal error info.
93-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
94-
//│ ║ l.64: rec def map f tree = case tree of {
95-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
96-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
97-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
99-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100-
//│ ║ l.67: }
101-
//│ ║ ^^^
102-
//│ ╙── Note: use flag `:ex` to see internal error info.
103-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
104-
//│ ║ l.64: rec def map f tree = case tree of {
105-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
106-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
107-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
109-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110-
//│ ║ l.67: }
111-
//│ ║ ^^^
112-
//│ ╙── Note: use flag `:ex` to see internal error info.
113-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
114-
//│ ║ l.64: rec def map f tree = case tree of {
115-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
116-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
117-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
119-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120-
//│ ║ l.67: }
121-
//│ ║ ^^^
122-
//│ ╙── Note: use flag `:ex` to see internal error info.
123-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
124-
//│ ║ l.64: rec def map f tree = case tree of {
125-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
126-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
127-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
129-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130-
//│ ║ l.67: }
131-
//│ ║ ^^^
132-
//│ ╙── Note: use flag `:ex` to see internal error info.
133-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
134-
//│ ║ l.64: rec def map f tree = case tree of {
135-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
136-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
137-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
139-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140-
//│ ║ l.67: }
141-
//│ ║ ^^^
142-
//│ ╙── Note: use flag `:ex` to see internal error info.
143-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
144-
//│ ║ l.64: rec def map f tree = case tree of {
145-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
146-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
147-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
149-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
150-
//│ ║ l.67: }
151-
//│ ║ ^^^
152-
//│ ╙── Note: use flag `:ex` to see internal error info.
153-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
154-
//│ ║ l.64: rec def map f tree = case tree of {
155-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
156-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
157-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
159-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160-
//│ ║ l.67: }
161-
//│ ║ ^^^
162-
//│ ╙── Note: use flag `:ex` to see internal error info.
163-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
164-
//│ ║ l.64: rec def map f tree = case tree of {
165-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
166-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
167-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
169-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170-
//│ ║ l.67: }
171-
//│ ║ ^^^
172-
//│ ╙── Note: use flag `:ex` to see internal error info.
173-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
174-
//│ ║ l.64: rec def map f tree = case tree of {
175-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
176-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
177-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
179-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180-
//│ ║ l.67: }
181-
//│ ║ ^^^
182-
//│ ╙── Note: use flag `:ex` to see internal error info.
183-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
184-
//│ ║ l.64: rec def map f tree = case tree of {
185-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
186-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
187-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
189-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
190-
//│ ║ l.67: }
191-
//│ ║ ^^^
192-
//│ ╙── Note: use flag `:ex` to see internal error info.
193-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
194-
//│ ║ l.64: rec def map f tree = case tree of {
195-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
196-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
197-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
199-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200-
//│ ║ l.67: }
201-
//│ ║ ^^^
202-
//│ ╙── Note: use flag `:ex` to see internal error info.
203-
//│ ╔══[ERROR] Cyclic-looking constraint while typing binding of lambda expression; a type annotation may be required
204-
//│ ║ l.64: rec def map f tree = case tree of {
205-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
206-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
207-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
208-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
209-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
210-
//│ ║ l.67: }
211-
//│ ║ ^^^
212-
//│ ╙── Note: use flag `:ex` to see internal error info.
213-
//│ ╔══[ERROR] Subtyping constraint of the form `?a -> ?b -> (?c | ?d) <: ?map` exceeded recursion depth limit (250)
214-
//│ ║ l.64: rec def map f tree = case tree of {
215-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^
216-
//│ ║ l.65: | Leaf -> Leaf { value = f tree.value }
217-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218-
//│ ║ l.66: | Node -> Node { subTree = map (mapTwo f) tree.subTree }
219-
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220-
//│ ║ l.67: }
221-
//│ ║ ^^^
222-
//│ ╙── Note: use flag `:ex` to see internal error info.
223-
//│ map: ('value -> (Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'value0) & 'a -> (Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'b & 'A) & 'c -> (Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'd & 'A) & 'e -> (Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'f & 'A) & 'g -> (Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'h & 'A)) -> 'i -> (Leaf[((nothing, (nothing, nothing,) | 'd,) | 'b, ((nothing, nothing,) | 'h, nothing,) | 'f,) | 'value0] | 'j)
224-
//│ where
225-
//│ 'j :> Node['A] with {
226-
//│ subTree: Leaf[((nothing, (nothing, nothing,) | 'd,) | 'b, ((nothing, nothing,) | 'h, nothing,) | 'f,) | 'value0] | 'j
227-
//│ }
228-
//│ 'i <: Leaf[?] & {
229-
//│ value: ((anything, (anything, anything,) & 'c,) & 'a, ((anything, anything,) & 'g, anything,) & 'e,) & 'value
230-
//│ } | (Node[?] with {subTree: 'i})
231-
//│ 'A :> ((nothing, nothing,) | 'h, (nothing, nothing,) | 'd,)
232-
//│ <: Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two[Two['A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A] & 'A]
233-
//│ = [Function: map]
63+
// * On some systems, the default -Xss4M is not enough for this case
64+
// :e // * Needs precise-rec-typing (see below)
65+
// rec def map f tree = case tree of {
66+
// | Leaf -> Leaf { value = f tree.value }
67+
// | Node -> Node { subTree = map (mapTwo f) tree.subTree }
68+
// }
23469

23570
:e // occurs-check
23671
:precise-rec-typing
@@ -255,7 +90,7 @@ rec def map f tree = case tree of {
25590
//│ where
25691
//│ 'a <: 'b -> 'c & 'd -> 'e) -> 'subTree -> (PerfectTree[Two['A]] & 'subTree0)
25792
//│ 'a <: 'value -> 'value0)
258-
//│ = [Function: map1]
93+
//│ = [Function: map]
25994

26095
:e
26196
map succ n4
@@ -269,8 +104,8 @@ map succ n4
269104
//│ 'a <: 'value -> 'value0)
270105
//│ ╙──
271106
//│ ╔══[ERROR] Cyclic-looking constraint while typing application; a type annotation may be required
272-
//│ ║ l.261: map succ n4
273-
//│ ║ ^^^^^^^^^^^
107+
//│ ║ l.96: map succ n4
108+
//│ ║ ^^^^^^^^^^^
274109
//│ ╙── Note: use flag `:ex` to see internal error info.
275110
//│ res: error
276111
//│ = Node1 { subTree: Node1 { subTree: Leaf { value: [Array] } } }

0 commit comments

Comments
 (0)