Skip to content

Commit 7c5f9cc

Browse files
committed
Merge commit '154d840a3c7d7836207e05c93d3e4c98cb15d44a' into _goto_for_early_return0
2 parents b313cd3 + 154d840 commit 7c5f9cc

83 files changed

Lines changed: 2369 additions & 280 deletions

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ jobs:
3939
uses: actions/cache/restore@v4
4040
with:
4141
path: _opam
42-
key: opam-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
42+
key: opam-${{ runner.os }}-${{ runner.arch }}-fstar1-${{ github.run_id }}
4343
restore-keys: |
44+
opam-${{ runner.os }}-${{ runner.arch }}-fstar1-
4445
opam-${{ runner.os }}-${{ runner.arch }}-
4546
46-
# Build F* master.
47+
# Build F*, from the fstar1 branch.
4748
- run: opam update
48-
- run: opam pin -n fstar --dev-repo
49+
- run: opam pin -n fstar git+https://github.com/FStarLang/FStar#fstar1
4950
- run: opam install fstar
5051

5152
# Install karamel deps
@@ -64,9 +65,10 @@ jobs:
6465
# and so far no Karamel regression test suite for EverParse
6566
# requires 3d
6667
68+
# Paranoid delete before saving. Note: run_id is constant across reruns.
6769
- name: Delete OPAM state if it already existed
6870
run: |
69-
gh cache delete opam-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }} || true
71+
gh cache delete opam-${{ runner.os }}-${{ runner.arch }}-fstar1-${{ github.run_id }} || true
7072
env:
7173
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7274
GH_REPO: ${{ github.repository }}
@@ -76,7 +78,7 @@ jobs:
7678
uses: actions/cache/save@v4
7779
with:
7880
path: _opam
79-
key: opam-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
81+
key: opam-${{ runner.os }}-${{ runner.arch }}-fstar1-${{ github.run_id }}
8082

8183
build-and-test:
8284
needs: build-deps
@@ -94,7 +96,7 @@ jobs:
9496
- name: Setup ocaml
9597
uses: ocaml/setup-ocaml@v3
9698
with:
97-
ocaml-compiler: 4.14.2
99+
ocaml-compiler: 5.3.0
98100

99101
- uses: actions/checkout@master
100102
with:
@@ -103,16 +105,14 @@ jobs:
103105
- name: Restore OPAM state
104106
uses: actions/cache/restore@v4
105107
with:
106-
fail-on-cache-miss: true
108+
fail-on-cache-miss: true # should never happen, cache was filled by build-deps
107109
path: _opam
108-
key: opam-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
110+
key: opam-${{ runner.os }}-${{ runner.arch }}-fstar1-${{ github.run_id }}
109111

110112
- uses: actions/setup-node@v4
111113
with:
112114
node-version: 16
113115

114-
- run: echo "KRML_HOME=$(pwd)/karamel" >> $GITHUB_ENV
115-
116116
- name: Karamel CI
117117
working-directory: karamel
118118
run: |
@@ -144,7 +144,7 @@ jobs:
144144
- name: Setup ocaml
145145
uses: ocaml/setup-ocaml@v3
146146
with:
147-
ocaml-compiler: 4.14.2
147+
ocaml-compiler: 5.3.0
148148

149149
- uses: actions/checkout@master
150150
with:
@@ -153,9 +153,9 @@ jobs:
153153
- name: Restore OPAM state
154154
uses: actions/cache/restore@v4
155155
with:
156-
fail-on-cache-miss: true
156+
fail-on-cache-miss: true # should never happen, cache was filled by build-deps
157157
path: _opam
158-
key: opam-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
158+
key: opam-${{ runner.os }}-${{ runner.arch }}-fstar1-${{ github.run_id }}
159159

160160
- name: Setup environment
161161
run: |
@@ -193,6 +193,7 @@ jobs:
193193
run: |
194194
git pull && make cbor-extract-krml cose-extract-krml -kj$(nproc)
195195
196+
# Paranoid delete before saving. Note: run_id is constant across reruns.
196197
- name: Delete EverParse cache if it already existed
197198
run: |
198199
gh cache delete everparse-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }} || true
@@ -239,17 +240,96 @@ jobs:
239240
- uses: actions/checkout@master
240241
- name: Build the checked-in krmllib
241242
run: |
242-
export KRML_HOME=$(pwd)
243243
export CC=${{matrix.cc}}
244+
export KRML_INCLUDEDIR=$(pwd)/include
245+
export KRML_LIBDIR=$(pwd)/krmllib
244246
make -kj$(nproc) -C krmllib/dist/generic -f Makefile.basic
245247
248+
build-and-test-pulse:
249+
runs-on: ubuntu-latest
250+
needs: build-deps
251+
steps:
252+
- name: Setup ocaml
253+
uses: ocaml/setup-ocaml@v3
254+
with:
255+
ocaml-compiler: 5.3.0
256+
257+
# Note, we prefer to restore the -master cache, but if it doesn't exist,
258+
# we restore the latest normal one.
259+
- name: Restore OPAM state
260+
uses: actions/cache/restore@v4
261+
with:
262+
fail-on-cache-miss: true
263+
path: _opam
264+
key: opam-${{ runner.os }}-${{ runner.arch }}-master-${{ github.run_id }}
265+
restore-keys: |
266+
opam-${{ runner.os }}-${{ runner.arch }}-master-
267+
opam-${{ runner.os }}-${{ runner.arch }}-
268+
269+
# Build F*, master branch
270+
- run: opam update
271+
- run: opam pin -n fstar git+https://github.com/FStarLang/FStar#master
272+
- run: opam install fstar
273+
274+
# Save OPAM state, note master- in key.
275+
- name: Save OPAM state
276+
uses: actions/cache/save@v4
277+
with:
278+
path: _opam
279+
key: opam-${{ runner.os }}-${{ runner.arch }}-master-${{ github.run_id }}
280+
281+
- name: Install Z3 with script
282+
run: |
283+
wget https://raw.githubusercontent.com/FStarLang/FStar/refs/heads/master/.scripts/get_fstar_z3.sh -O get_fstar_z3.sh
284+
chmod +x get_fstar_z3.sh
285+
./get_fstar_z3.sh /usr/local/bin
286+
# If these fail, stop right now.
287+
- run: which z3-4.8.5
288+
- run: which z3-4.13.3
289+
290+
- uses: actions/checkout@master
291+
with:
292+
path: karamel
293+
294+
- uses: actions/setup-node@v4
295+
with:
296+
node-version: 16
297+
298+
- run: echo "KRML_HOME=$(pwd)/karamel" >> $GITHUB_ENV
299+
300+
- name: Karamel CI (test-pulse)
301+
working-directory: karamel
302+
run: |
303+
eval $(opam env)
304+
export OCAMLRUNPARAM=b
305+
make -kj$(nproc) test-pulse
306+
307+
test-eurydice:
308+
runs-on: ubuntu-latest
309+
steps:
310+
- name: Install Nix
311+
uses: DeterminateSystems/nix-installer-action@main
312+
313+
- name: Setup Cachix
314+
uses: cachix/cachix-action@v15
315+
with:
316+
name: hacl
317+
318+
- name: Build and test Eurydice against this Karamel
319+
run: |
320+
nix build -L --no-link \
321+
"github:AeneasVerif/eurydice#checks.x86_64-linux.default" \
322+
--override-input karamel "github:FStarLang/karamel/$GITHUB_SHA"
323+
246324
# A single no-op job to use for branch protection
247325
ciok:
248326
runs-on: ubuntu-latest
249327
if: ${{ cancelled() || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure') }}
250328
needs:
251329
- build-and-test
330+
- build-and-test-pulse
252331
- build-krmllib
332+
- test-eurydice
253333
steps:
254334
# Note: this only runs when a dependency fails. If they all succeed,
255335
# this jobs is skipped, which counts as a success.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ fstar-mode.el
1212
lib/Version.ml
1313
*.runlim
1414
karamel-nofstar.opam
15-
lib/AutoConfig.ml
1615
*.orig
1716
.exrc
1817
*.cmd
1918
*.err
2019
*.output
2120
*.time
21+
out
22+
krml.tar.gz

.nix/karamel.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ in
6565
# the library is named `krml` rather than `karamel`
6666
mv karamel.opam krml.opam
6767
sed -i '/name krml/a (public_name krml)' lib/dune
68-
make lib/Version.ml lib/AutoConfig.ml
68+
make lib/Version.ml
6969
'';
7070
src = ../.;
7171
};

CI.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Extended CI for krml
2+
3+
In addition to the regular krml test files (`test/*.fst`), we now run three
4+
additional "extended" CIs, two of which track the C output to catch any code
5+
quality regressions.
6+
- Pulse-based tests (in `test/pulse`), along with the expected C
7+
- EverParse
8+
- Eurydice, which contains the expected C in its own repository
9+
10+
# Coarse instructions for dealing with PRs that have impact on Eurydice
11+
12+
If a PR changes the generated C code, chances are it will generate a diff in
13+
Eurydice, which will make the corresponding CI job fail.
14+
15+
Because krml does *not* have a flake.lock, it always builds against Eurydice
16+
`main`. This means that Eurydice must be upgraded first. So, once a krml PR is
17+
ready to be merged:
18+
19+
```bash
20+
$ cd eurydice
21+
$ (cd karamel && git fetch && git checkout my-pr-branch && git merge)
22+
$ (cd out/ && git clean -fdx)
23+
$ make test -j
24+
$ nix flake update karamel --override-input karamel "github:fstarlang/karamel/$(cd karamel && git rev-parse head)"
25+
$ git commit -am "Update krml to latest revision on branch my-pr-branch"
26+
```
27+
28+
If the PR is being submitted from a *fork* of krml, then you must replicate the
29+
branch on the `fstarlang/karamel` repository (or face a two-step process on the
30+
Eurydice side).
31+
32+
Then, merge the Eurydice PR and restart the krml-side PR for it to pick up the
33+
changes. Do NOT squash or rebase while merging otherwise the commit that
34+
Eurydice points to will disappear and you'll need a second PR on Eurydice to fix
35+
that up.

Makefile

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,40 @@
1-
# Including a Makefile from the visitors package, but making sure
2-
# to give decent errors.
3-
41
# make src/Ast.processed.ml
5-
_:=$(shell ocamlfind query)
6-
ifneq ($(.SHELLSTATUS),0)
7-
_: $(error "'ocamlfind query' failed, please install OCaml and put it in your PATH)
8-
endif
9-
visitors_root:=$(shell ocamlfind query visitors)
10-
ifneq ($(.SHELLSTATUS),0)
11-
_: $(error "'ocamlfind query visitors' failed, please 'opam install visitors')
12-
endif
13-
include $(visitors_root)/Makefile.preprocess
2+
include visitors.mk
143

154
.PHONY: all minimal clean test pre krmllib install
165

176
FSTAR_EXE ?= fstar.exe
187

19-
all: minimal krmllib
8+
all: local-install
209

2110
# If we are just trying to do a minimal build, we don't need F*.
2211
# Note: lazy assignment so this does not warn if fstar.exe is not there
2312
# (e.g. on a minimal build or cleaning)
2413
FSTAR_OCAMLENV = $(shell $(FSTAR_EXE) --ocamlenv)
2514

26-
minimal: lib/AutoConfig.ml lib/Version.ml
15+
# Creates a top-level ./krml symlink to the built Karamel executable. But, does
16+
# not build krmllib nor is set up in a way that allows karamel to find its
17+
# runtime/misc/include directories, so it is somewhat barebones.
18+
minimal: lib/Version.ml
2719
dune build
2820
ln -sf _build/default/src/Karamel.exe krml
2921

3022
krmllib: minimal
31-
$(MAKE) -C krmllib
32-
33-
lib/AutoConfig.ml:
34-
@if [ x"$(PREFIX)" != x ]; then \
35-
echo "let krmllib_dir = \"$(PREFIX)/lib/krml\";;" > $@; \
36-
echo "let runtime_dir = \"$(PREFIX)/lib/krml/runtime\";;" >> $@; \
37-
echo "let include_dir = \"$(PREFIX)/include/\";;" >> $@; \
38-
echo "let misc_dir = \"$(PREFIX)/share/krml/misc/\";;" >> $@; \
39-
else \
40-
echo "let krmllib_dir = \"\";;" > $@; \
41-
echo "let runtime_dir = \"\";;" >> $@; \
42-
echo "let include_dir = \"\";;" >> $@; \
43-
echo "let misc_dir = \"\";;" >> $@; \
44-
fi
45-
46-
.PHONY: src/Version.ml
23+
@# Make sure krml can find its relevant directories, since
24+
@# it is not yet installed with them.
25+
env \
26+
KRML_LIBDIR=$(CURDIR)/krmllib \
27+
KRML_INCLUDEDIR=$(CURDIR)/include \
28+
KRML_MISCDIR=$(CURDIR)/misc \
29+
$(MAKE) -C krmllib
30+
31+
# A full local install. out/ will contain essentially the same directory
32+
# as an OPAM install or binary package.
33+
local-install: krmllib
34+
$(MAKE) PREFIX=$(CURDIR)/out _install
35+
ln -sf out/bin/krml krml
36+
37+
.PHONY: lib/Version.ml
4738
lib/Version.ml:
4839
@echo "let version = \"$(shell git rev-parse HEAD || echo ${GIT_REV})\"" > $@
4940

@@ -56,24 +47,38 @@ clean:
5647
test: all
5748
$(MAKE) -C test
5849

50+
# This depends on minimal since fstar2 (with Pulse) is not expected
51+
# to be able to build krmllib.
52+
test-pulse: minimal
53+
$(MAKE) -C test/pulse
54+
5955
# Auto-detection
6056
pre:
6157
@eval "$(FSTAR_OCAMLENV)" && \
6258
ocamlfind query fstar.lib >/dev/null 2>&1 || \
6359
{ echo "Didn't find fstar.lib via ocamlfind; is F* properly installed? (FSTAR_EXE = $(FSTAR_EXE))"; exit 1; }
6460

65-
6661
install: all
62+
$(MAKE) _install
63+
64+
_install:
6765
@if [ x"$(PREFIX)" = x ]; then echo "please define PREFIX"; exit 1; fi
6866
mkdir -p $(PREFIX)/bin
69-
cp _build/default/src/Karamel.exe $(PREFIX)/bin/krml
70-
mkdir -p $(PREFIX)/include
71-
cp -r include/* $(PREFIX)/include
67+
install _build/default/src/Karamel.exe $(PREFIX)/bin/krml
68+
mkdir -p $(PREFIX)/include/krml
69+
cp -r include/* $(PREFIX)/include/krml
7270
mkdir -p $(PREFIX)/lib/krml
7371
cp -r krmllib/* $(PREFIX)/lib/krml
74-
mkdir -p $(PREFIX)/lib/krml/runtime
75-
cp -r runtime/* $(PREFIX)/lib/krml/runtime
72+
echo 'obj' >> $(PREFIX)/lib/krml/fstar.include
73+
@# ^ So users can just --include lib/krml and also see the checked files.
7674
mkdir -p $(PREFIX)/share/krml/examples
7775
cp -r test/*.fst $(PREFIX)/share/krml/examples
7876
mkdir -p $(PREFIX)/share/krml/misc
7977
cp -r misc/* $(PREFIX)/share/krml/misc
78+
79+
package: krml.tar.gz
80+
81+
krml.tar.gz:
82+
$(MAKE) _install PREFIX=$(CURDIR)/pkgtmp/krml
83+
tar czf krml.tar.gz -C pkgtmp .
84+
rm -rf pkgtmp

book/tutorial/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ obj/Specs_Driver.ml: specs/ml/Specs_Driver.ml
139139
# F* --> C
140140
# --------
141141

142-
KRML=$(KRML_HOME)/krml
142+
KRML_EXE ?= krml
143143

144144
# Note: the implementation of the intrinsic uses external linkage, but you could
145145
# easily turn this file into a .h, use -add-include '"Impl_Bignum_Intrinsics.h"'
@@ -240,7 +240,7 @@ obj/specs-test.exe: $(ALL_CMX_FILES) obj/Specs_Driver.cmx
240240
# Compiling the hand-written test
241241
# -------------------------------
242242

243-
CFLAGS += -I dist -I $(KRML_HOME)/include
243+
CFLAGS += -I dist -I $(shell $(KRML_EXE) -locate-include)
244244

245245
tests/c-tests.exe: tests/c-tests.o dist/libbignum.a
246246
$(CC) $^ -o $@

0 commit comments

Comments
 (0)