Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wit syntax: use semicolons #135

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wit: use semicolons as statement separator
  • Loading branch information
Pat Hickey committed Oct 16, 2023
commit 43035c919f9db2bd77b5ab168507732488b9c726
4 changes: 2 additions & 2 deletions wit/preopens.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface preopens {
use types.{descriptor}
use types.{descriptor};

/// Return the set of preopened directories, and their path.
get-directories: func() -> list<tuple<descriptor, string>>
get-directories: func() -> list<tuple<descriptor, string>>;
}
92 changes: 52 additions & 40 deletions wit/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
///
/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
interface types {
use wasi:io/streams.{input-stream, output-stream}
use wasi:clocks/wall-clock.{datetime}
use wasi:io/streams.{input-stream, output-stream, error};
use wasi:clocks/wall-clock.{datetime};

/// File size or length of a region within a file.
type filesize = u64
type filesize = u64;

/// The type of a filesystem object referenced by a descriptor.
///
Expand Down Expand Up @@ -166,7 +166,7 @@ interface types {
}

/// Number of hard links to an inode.
type link-count = u64
type link-count = u64;

/// When setting a timestamp, this gives the value to set it to.
variant new-timestamp {
Expand Down Expand Up @@ -315,7 +315,7 @@ interface types {
read-via-stream: func(
/// The offset within the file at which to start reading.
offset: filesize,
) -> result<input-stream, error-code>
) -> result<input-stream, error-code>;

/// Return a stream for writing to a file, if available.
///
Expand All @@ -326,15 +326,15 @@ interface types {
write-via-stream: func(
/// The offset within the file at which to start writing.
offset: filesize,
) -> result<output-stream, error-code>
) -> result<output-stream, error-code>;

/// Return a stream for appending to a file, if available.
///
/// May fail with an error-code describing why the file cannot be appended.
///
/// Note: This allows using `write-stream`, which is similar to `write` with
/// `O_APPEND` in in POSIX.
append-via-stream: func() -> result<output-stream, error-code>
append-via-stream: func() -> result<output-stream, error-code>;

/// Provide file advisory information on a descriptor.
///
Expand All @@ -346,23 +346,23 @@ interface types {
length: filesize,
/// The advice.
advice: advice
) -> result<_, error-code>
) -> result<_, error-code>;

/// Synchronize the data of a file to disk.
///
/// This function succeeds with no effect if the file descriptor is not
/// opened for writing.
///
/// Note: This is similar to `fdatasync` in POSIX.
sync-data: func() -> result<_, error-code>
sync-data: func() -> result<_, error-code>;

/// Get flags associated with a descriptor.
///
/// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
///
/// Note: This returns the value that was the `fs_flags` value returned
/// from `fdstat_get` in earlier versions of WASI.
get-flags: func() -> result<descriptor-flags, error-code>
get-flags: func() -> result<descriptor-flags, error-code>;

/// Get the dynamic type of a descriptor.
///
Expand All @@ -374,13 +374,13 @@ interface types {
///
/// Note: This returns the value that was the `fs_filetype` value returned
/// from `fdstat_get` in earlier versions of WASI.
get-type: func() -> result<descriptor-type, error-code>
get-type: func() -> result<descriptor-type, error-code>;

/// Adjust the size of an open file. If this increases the file's size, the
/// extra bytes are filled with zeros.
///
/// Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
set-size: func(size: filesize) -> result<_, error-code>
set-size: func(size: filesize) -> result<_, error-code>;

/// Adjust the timestamps of an open file or directory.
///
Expand All @@ -392,7 +392,7 @@ interface types {
data-access-timestamp: new-timestamp,
/// The desired values of the data modification timestamp.
data-modification-timestamp: new-timestamp,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Read from a descriptor, without using and updating the descriptor's offset.
///
Expand All @@ -410,7 +410,7 @@ interface types {
length: filesize,
/// The offset within the file at which to read.
offset: filesize,
) -> result<tuple<list<u8>, bool>, error-code>
) -> result<tuple<list<u8>, bool>, error-code>;

/// Write to a descriptor, without using and updating the descriptor's offset.
///
Expand All @@ -426,7 +426,7 @@ interface types {
buffer: list<u8>,
/// The offset within the file at which to write.
offset: filesize,
) -> result<filesize, error-code>
) -> result<filesize, error-code>;

/// Read directory entries from a directory.
///
Expand All @@ -437,23 +437,23 @@ interface types {
/// This always returns a new stream which starts at the beginning of the
/// directory. Multiple streams may be active on the same directory, and they
/// do not interfere with each other.
read-directory: func() -> result<directory-entry-stream, error-code>
read-directory: func() -> result<directory-entry-stream, error-code>;

/// Synchronize the data and metadata of a file to disk.
///
/// This function succeeds with no effect if the file descriptor is not
/// opened for writing.
///
/// Note: This is similar to `fsync` in POSIX.
sync: func() -> result<_, error-code>
sync: func() -> result<_, error-code>;

/// Create a directory.
///
/// Note: This is similar to `mkdirat` in POSIX.
create-directory-at: func(
/// The relative path at which to create the directory.
path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Return the attributes of an open file or directory.
///
Expand All @@ -464,7 +464,7 @@ interface types {
/// modified, use `metadata-hash`.
///
/// Note: This was called `fd_filestat_get` in earlier versions of WASI.
stat: func() -> result<descriptor-stat, error-code>
stat: func() -> result<descriptor-stat, error-code>;

/// Return the attributes of a file or directory.
///
Expand All @@ -478,7 +478,7 @@ interface types {
path-flags: path-flags,
/// The relative path of the file or directory to inspect.
path: string,
) -> result<descriptor-stat, error-code>
) -> result<descriptor-stat, error-code>;

/// Adjust the timestamps of a file or directory.
///
Expand All @@ -495,7 +495,7 @@ interface types {
data-access-timestamp: new-timestamp,
/// The desired values of the data modification timestamp.
data-modification-timestamp: new-timestamp,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Create a hard link.
///
Expand All @@ -509,7 +509,7 @@ interface types {
new-descriptor: borrow<descriptor>,
/// The relative destination path at which to create the hard link.
new-path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Open a file or directory.
///
Expand Down Expand Up @@ -540,7 +540,7 @@ interface types {
%flags: descriptor-flags,
/// Permissions to use when creating a new file.
modes: modes
) -> result<descriptor, error-code>
) -> result<descriptor, error-code>;

/// Read the contents of a symbolic link.
///
Expand All @@ -551,7 +551,7 @@ interface types {
readlink-at: func(
/// The relative path of the symbolic link from which to read.
path: string,
) -> result<string, error-code>
) -> result<string, error-code>;

/// Remove a directory.
///
Expand All @@ -561,7 +561,7 @@ interface types {
remove-directory-at: func(
/// The relative path to a directory to remove.
path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Rename a filesystem object.
///
Expand All @@ -573,7 +573,7 @@ interface types {
new-descriptor: borrow<descriptor>,
/// The relative destination path to which to rename the file or directory.
new-path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Create a symbolic link (also known as a "symlink").
///
Expand All @@ -586,7 +586,7 @@ interface types {
old-path: string,
/// The relative destination path at which to create the symbolic link.
new-path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Check accessibility of a filesystem path.
///
Expand All @@ -605,7 +605,7 @@ interface types {
path: string,
/// The type of check to perform.
%type: access-type
) -> result<_, error-code>
) -> result<_, error-code>;

/// Unlink a filesystem object that is not a directory.
///
Expand All @@ -614,7 +614,7 @@ interface types {
unlink-file-at: func(
/// The relative path to a file to unlink.
path: string,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Change the permissions of a filesystem object that is not a directory.
///
Expand All @@ -629,7 +629,7 @@ interface types {
path: string,
/// The new permissions for the filesystem object.
modes: modes,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Change the permissions of a directory.
///
Expand All @@ -648,7 +648,7 @@ interface types {
path: string,
/// The new permissions for the directory.
modes: modes,
) -> result<_, error-code>
) -> result<_, error-code>;

/// Request a shared advisory lock for an open file.
///
Expand All @@ -670,7 +670,7 @@ interface types {
/// locking, this function returns `error-code::unsupported`.
///
/// Note: This is similar to `flock(fd, LOCK_SH)` in Unix.
lock-shared: func() -> result<_, error-code>
lock-shared: func() -> result<_, error-code>;

/// Request an exclusive advisory lock for an open file.
///
Expand All @@ -694,7 +694,7 @@ interface types {
/// locking, this function returns `error-code::unsupported`.
///
/// Note: This is similar to `flock(fd, LOCK_EX)` in Unix.
lock-exclusive: func() -> result<_, error-code>
lock-exclusive: func() -> result<_, error-code>;

/// Request a shared advisory lock for an open file.
///
Expand All @@ -717,7 +717,7 @@ interface types {
/// locking, this function returns `error-code::unsupported`.
///
/// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix.
try-lock-shared: func() -> result<_, error-code>
try-lock-shared: func() -> result<_, error-code>;

/// Request an exclusive advisory lock for an open file.
///
Expand All @@ -742,20 +742,20 @@ interface types {
/// locking, this function returns `error-code::unsupported`.
///
/// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix.
try-lock-exclusive: func() -> result<_, error-code>
try-lock-exclusive: func() -> result<_, error-code>;

/// Release a shared or exclusive lock on an open file.
///
/// Note: This is similar to `flock(fd, LOCK_UN)` in Unix.
unlock: func() -> result<_, error-code>
unlock: func() -> result<_, error-code>;

/// Test whether two descriptors refer to the same filesystem object.
///
/// In POSIX, this corresponds to testing whether the two descriptors have the
/// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
/// wasi-filesystem does not expose device and inode numbers, so this function
/// may be used instead.
is-same-object: func(other: borrow<descriptor>) -> bool
is-same-object: func(other: borrow<descriptor>) -> bool;

/// Return a hash of the metadata associated with a filesystem object referred
/// to by a descriptor.
Expand All @@ -776,7 +776,7 @@ interface types {
/// computed hash.
///
/// However, none of these is required.
metadata-hash: func() -> result<metadata-hash-value, error-code>
metadata-hash: func() -> result<metadata-hash-value, error-code>;

/// Return a hash of the metadata associated with a filesystem object referred
/// to by a directory descriptor and a relative path.
Expand All @@ -787,12 +787,24 @@ interface types {
path-flags: path-flags,
/// The relative path of the file or directory to inspect.
path: string,
) -> result<metadata-hash-value, error-code>
) -> result<metadata-hash-value, error-code>;
}

/// A stream of directory entries.
resource directory-entry-stream {
/// Read a single directory entry from a `directory-entry-stream`.
read-directory-entry: func() -> result<option<directory-entry>, error-code>
read-directory-entry: func() -> result<option<directory-entry>, error-code>;
}

/// Attempts to extract a filesystem-related `error-code` from the stream
/// `error` provided.
///
/// Stream operations which return `stream-error::last-operation-failed`
/// have a payload with more information about the operation that failed.
/// This payload can be passed through to this function to see if there's
/// filesystem-related information about the error to return.
///
/// Note that this function is fallible because not all stream-related
/// errors are filesystem-related errors.
filesystem-error-code: func(err: borrow<error>) -> option<error-code>;
}
6 changes: 3 additions & 3 deletions wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wasi:filesystem
package wasi:filesystem;

world imports {
import types
import preopens
import types;
import preopens;
}