-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #543 from FStarLang/taramana_rust_val_test
Honor rename-prefix for *external* Rust declarations
- Loading branch information
Showing
13 changed files
with
222 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.exe | ||
*.krml | ||
rusttest.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module AuxA | ||
|
||
val foo : bool -> bool | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module AuxB | ||
|
||
val bar : bool -> bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
RECENT_GCC = $(shell [ "$$(gcc -dumpversion | cut -c -1)" -ge 5 ] && echo yes) | ||
|
||
ifeq (3.81,$(MAKE_VERSION)) | ||
$(error You seem to be using the OSX antiquated Make version. Hint: brew \ | ||
install make, then invoke gmake instead of make) | ||
endif | ||
|
||
FSTAR_EXE ?= fstar.exe | ||
|
||
TEST_OPTS = -warn-error @4 -verbose -skip-makefiles | ||
KRML_BIN = ../../_build/default/src/Karamel.exe | ||
KRML = $(KRML_BIN) -fstar $(FSTAR_EXE) $(KOPTS) $(TEST_OPTS) | ||
CACHE_DIR = .cache | ||
FSTAR = $(FSTAR_EXE) --cache_checked_modules \ | ||
--cache_dir $(CACHE_DIR) \ | ||
--include ../../krmllib/compat --include ../../krmllib/obj \ | ||
--include ../../krmllib --include ../../runtime \ | ||
--ext context_pruning \ | ||
--already_cached 'Prims FStar C TestLib Spec.Loops -C.Compat -C.Nullity LowStar WasmSupport' \ | ||
--trivial_pre_for_unannotated_effectful_fns false \ | ||
--cmi --warn_error -274 | ||
SED=$(shell which gsed >/dev/null 2>&1 && echo gsed || echo sed) | ||
|
||
all: rusttest.rust-test impl | ||
|
||
impl: | ||
+$(MAKE) -C $@ | ||
|
||
.PHONY: impl | ||
|
||
FSTAR_FILES=$(wildcard *.fst *.fsti) | ||
|
||
.PRECIOUS: %.krml | ||
|
||
# Use F*'s dependency mechanism and fill out the missing rules. | ||
|
||
ifndef MAKE_RESTARTS | ||
ifndef NODEPEND | ||
.depend: .FORCE | ||
$(FSTAR) --dep full $(FSTAR_FILES) --extract 'krml:*,-Prims' --output_deps_to $@ | ||
|
||
.PHONY: .FORCE | ||
.FORCE: | ||
endif | ||
endif | ||
|
||
include .depend | ||
|
||
$(CACHE_DIR)/%.checked: | .depend | ||
$(FSTAR) $(OTHERFLAGS) $< && \ | ||
touch $@ | ||
|
||
%.krml: | .depend | ||
$(FSTAR) $(OTHERFLAGS) --codegen krml \ | ||
--extract_module $(basename $(notdir $(subst .checked,,$<))) \ | ||
$(notdir $(subst .checked,,$<)) | ||
|
||
######## | ||
# Rust # | ||
######## | ||
|
||
.PRECIOUS: %.rs | ||
%.rs: $(ALL_KRML_FILES) $(KRML_BIN) | ||
$(KRML) -minimal -bundle AuxA+AuxB=[rename=Aux,rename-prefix] -bundle $(notdir $(subst rust,Rust,$*))=\* \ | ||
-backend rust $(EXTRA) -tmpdir $(dir $@) $(filter %.krml,$^) | ||
$(SED) -i 's/\(patterns..\)/\1\nmod aux; mod lowstar { pub mod ignore { pub fn ignore<T>(_x: T) {}}}\n/' $@ | ||
echo 'fn main () { let r = main_ (); if r != 0 { println!("main_ returned: {}\\n", r); panic!() } }' >> $@ | ||
|
||
%.rust-test: %.rs | ||
rustc $< -o $*.exe && ./$*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Rusttest | ||
|
||
module B = LowStar.Buffer | ||
module HST = FStar.HyperStack.ST | ||
module I32 = FStar.Int32 | ||
|
||
let test2 (b: B.buffer bool) : HST.Stack bool | ||
(fun h -> B.live h b /\ B.length b == 1) | ||
(fun _ _ _ -> True) | ||
= | ||
let x = B.index b C._zero_for_deref in | ||
let r1 = AuxA.foo x in | ||
let r2 = AuxB.bar x in | ||
r1 && r2 | ||
|
||
let main_ () : HST.Stack I32.t | ||
(fun _ -> True) | ||
(fun _ _ _ -> True) | ||
= | ||
HST.push_frame (); | ||
let b = B.alloca true 1ul in | ||
let _ = test2 b in | ||
HST.pop_frame (); | ||
0l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(non_snake_case)] | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(unused_assignments)] | ||
#![allow(unreachable_patterns)] | ||
|
||
pub fn foo(x: bool) -> bool | ||
{ | ||
return !x; | ||
} | ||
|
||
pub fn bar(x: bool) -> bool | ||
{ | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.rs | ||
*.rlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module AuxA | ||
|
||
let foo x = not x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module AuxB | ||
|
||
let bar x = x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
RECENT_GCC = $(shell [ "$$(gcc -dumpversion | cut -c -1)" -ge 5 ] && echo yes) | ||
|
||
ifeq (3.81,$(MAKE_VERSION)) | ||
$(error You seem to be using the OSX antiquated Make version. Hint: brew \ | ||
install make, then invoke gmake instead of make) | ||
endif | ||
|
||
FSTAR_EXE ?= fstar.exe | ||
|
||
TEST_OPTS = -warn-error @4 -verbose -skip-makefiles | ||
KRML_BIN = ../../../_build/default/src/Karamel.exe | ||
KRML = $(KRML_BIN) -fstar $(FSTAR_EXE) $(KOPTS) $(TEST_OPTS) | ||
CACHE_DIR = .cache | ||
FSTAR = $(FSTAR_EXE) --cache_checked_modules \ | ||
--cache_dir $(CACHE_DIR) \ | ||
--include ../../../krmllib/compat --include ../../../krmllib/obj \ | ||
--include ../../../krmllib --include ../../../runtime \ | ||
--include .. \ | ||
--ext context_pruning \ | ||
--already_cached 'Prims FStar C TestLib Spec.Loops -C.Compat -C.Nullity LowStar WasmSupport' \ | ||
--trivial_pre_for_unannotated_effectful_fns false \ | ||
--cmi --warn_error -274 | ||
SED=$(shell which gsed >/dev/null 2>&1 && echo gsed || echo sed) | ||
|
||
all: aux.rust-test | ||
|
||
FSTAR_FILES=$(wildcard *.fst *.fsti) | ||
|
||
.PRECIOUS: %.krml | ||
|
||
# Use F*'s dependency mechanism and fill out the missing rules. | ||
|
||
ifndef MAKE_RESTARTS | ||
ifndef NODEPEND | ||
.depend: .FORCE | ||
$(FSTAR) --dep full $(FSTAR_FILES) --extract 'krml:*,-Prims' --output_deps_to $@ | ||
|
||
.PHONY: .FORCE | ||
.FORCE: | ||
endif | ||
endif | ||
|
||
include .depend | ||
|
||
$(CACHE_DIR)/%.checked: | .depend | ||
$(FSTAR) $(OTHERFLAGS) $< && \ | ||
touch $@ | ||
|
||
%.krml: | .depend | ||
$(FSTAR) $(OTHERFLAGS) --codegen krml \ | ||
--extract_module $(basename $(notdir $(subst .checked,,$<))) \ | ||
$(notdir $(subst .checked,,$<)) | ||
|
||
######## | ||
# Rust # | ||
######## | ||
|
||
.PRECIOUS: %.rs | ||
%.rs: $(ALL_KRML_FILES) $(KRML_BIN) | ||
$(KRML) -minimal -bundle AuxA+AuxB=\*[rename=Aux,rename-prefix] \ | ||
-backend rust $(EXTRA) -tmpdir $(dir $@) $(filter %.krml,$^) | ||
|
||
%.rust-test: %.rs | ||
rustc --crate-type rlib $< -o $*.rlib |