Skip to content

Commit 13afff5

Browse files
committed
Merge remote-tracking branch 'origin/async'
2 parents ac25557 + 5167cbe commit 13afff5

File tree

7 files changed

+91
-10
lines changed

7 files changed

+91
-10
lines changed

examples_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ func TestWal(t *testing.T) {
183183
testExample(t, "wal", goose.Translator{TypeCheck: true})
184184
}
185185

186+
func TestAsync(t *testing.T) {
187+
testExample(t, "async", goose.Translator{TypeCheck: false})
188+
}
189+
186190
func TestLogging2(t *testing.T) {
187191
testExample(t, "logging2", goose.Translator{TypeCheck: true})
188192
}

goose.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func getFfi(pkg *packages.Package) string {
8585
seenFfis := make(map[string]struct{})
8686
packages.Visit([]*packages.Package{pkg},
8787
func(pkg *packages.Package) bool {
88+
// the dependencies of an FFI are not considered as being used; this
89+
// allows one FFI to be built on top of another
90+
if _, ok := ffiMapping[pkg.PkgPath]; ok {
91+
return false
92+
}
8893
return true
8994
},
9095
func(pkg *packages.Package) {
@@ -1859,19 +1864,21 @@ func stringLitValue(lit *ast.BasicLit) string {
18591864

18601865
// TODO: put this in another file
18611866
var builtinImports = map[string]bool{
1862-
"github.com/tchajed/goose/machine": true,
1863-
"github.com/tchajed/goose/machine/filesys": true,
1864-
"github.com/mit-pdos/gokv/grove_ffi": true,
1865-
"github.com/tchajed/goose/machine/disk": true,
1866-
"github.com/mit-pdos/gokv/time": true,
1867-
"sync": true,
1868-
"log": true,
1869-
"fmt": true,
1867+
"github.com/tchajed/goose/machine": true,
1868+
"github.com/tchajed/goose/machine/filesys": true,
1869+
"github.com/mit-pdos/gokv/grove_ffi": true,
1870+
"github.com/tchajed/goose/machine/disk": true,
1871+
"github.com/tchajed/goose/machine/async_disk": true,
1872+
"github.com/mit-pdos/gokv/time": true,
1873+
"sync": true,
1874+
"log": true,
1875+
"fmt": true,
18701876
}
18711877

18721878
var ffiMapping = map[string]string{
1873-
"github.com/mit-pdos/gokv/grove_ffi": "grove",
1874-
"github.com/tchajed/goose/machine/disk": "disk",
1879+
"github.com/mit-pdos/gokv/grove_ffi": "grove",
1880+
"github.com/tchajed/goose/machine/disk": "disk",
1881+
"github.com/tchajed/goose/machine/async_disk": "async_disk",
18751882
}
18761883

18771884
func (ctx Ctx) imports(d []ast.Spec) []coq.Decl {

internal/examples/async/async.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// async just uses the async disk FFI
2+
package async
3+
4+
import "github.com/tchajed/goose/machine/async_disk"
5+
6+
func TakesDisk(d async_disk.Disk) {}
7+
8+
func UseDisk(d async_disk.Disk) {
9+
v := make([]byte, 4096)
10+
d.Write(0, v)
11+
d.Barrier()
12+
}

internal/examples/async/async.gold.v

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(* autogenerated from github.com/tchajed/goose/internal/examples/async *)
2+
From Perennial.goose_lang Require Import prelude.
3+
From Perennial.goose_lang Require Import ffi.async_disk_prelude.
4+
5+
(* async just uses the async disk FFI *)
6+
7+
Definition TakesDisk: val :=
8+
rec: "TakesDisk" "d" :=
9+
#().
10+
11+
Definition UseDisk: val :=
12+
rec: "UseDisk" "d" :=
13+
let: "v" := NewSlice byteT #4096 in
14+
disk.Write #0 "v";;
15+
disk.Barrier #();;
16+
#().

machine/async_disk/async_disk.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package async_disk
2+
3+
import (
4+
"github.com/tchajed/goose/machine/disk"
5+
)
6+
7+
// Essentially a copy + paste of the disk interface. We do this so that we can
8+
// change what Goose translate client code to (either the Disk FFI model or
9+
// Async Disk FFI model) based on which package is used.
10+
11+
// Block is a 4096-byte buffer
12+
type Block = disk.Block
13+
14+
const BlockSize uint64 = disk.BlockSize
15+
16+
type Disk = disk.Disk

machine/async_disk/file.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package async_disk
2+
3+
import (
4+
"github.com/tchajed/goose/machine/disk"
5+
)
6+
7+
type FileDisk = disk.FileDisk
8+
9+
func NewFileDisk(path string, numBlocks uint64) (FileDisk, error) {
10+
return disk.NewFileDisk(path, numBlocks)
11+
}
12+
13+
var _ Disk = FileDisk{}

machine/async_disk/mem.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package async_disk
2+
3+
import (
4+
"github.com/tchajed/goose/machine/disk"
5+
)
6+
7+
type MemDisk = disk.MemDisk
8+
9+
func NewMemDisk(numBlocks uint64) MemDisk {
10+
return MemDisk(disk.NewMemDisk(numBlocks))
11+
}
12+
13+
var _ Disk = MemDisk{}

0 commit comments

Comments
 (0)