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

Update to the next version of the witx crate #2659

Merged
merged 8 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/wasi-common/WASI
Submodule WASI updated 68 files
+2 −2 docs/DesignPrinciples.md
+8 −5 docs/Proposals.md
+1 −1 meetings/2019/WASI-05-02.md
+1 −1 meetings/2019/WASI-05-16.md
+1 −1 meetings/2019/WASI-05-30.md
+1 −1 meetings/2019/WASI-06-27.md
+1 −1 meetings/2019/WASI-07-18.md
+2 −2 meetings/2019/WASI-10-15.md
+42 −1 meetings/2021/WASI-01-14.md
+174 −3 meetings/2021/WASI-01-28.md
+118 −0 meetings/2021/WASI-02-11.md
+33 −0 meetings/2021/WASI-02-25.md
+1 −1 phases/README.md
+775 −285 phases/ephemeral/docs.md
+45 −47 phases/ephemeral/witx/typenames.witx
+6 −8 phases/ephemeral/witx/wasi_ephemeral_args.witx
+2 −4 phases/ephemeral/witx/wasi_ephemeral_clock.witx
+6 −8 phases/ephemeral/witx/wasi_ephemeral_environ.witx
+23 −33 phases/ephemeral/witx/wasi_ephemeral_fd.witx
+12 −15 phases/ephemeral/witx/wasi_ephemeral_path.witx
+1 −2 phases/ephemeral/witx/wasi_ephemeral_poll.witx
+1 −1 phases/ephemeral/witx/wasi_ephemeral_random.witx
+1 −1 phases/ephemeral/witx/wasi_ephemeral_sched.witx
+4 −8 phases/ephemeral/witx/wasi_ephemeral_sock.witx
+731 −260 phases/old/snapshot_0/docs.md
+38 −38 phases/old/snapshot_0/witx/typenames.witx
+51 −76 phases/old/snapshot_0/witx/wasi_unstable.witx
+730 −259 phases/snapshot/docs.md
+38 −37 phases/snapshot/witx/typenames.witx
+50 −75 phases/snapshot/witx/wasi_snapshot_preview1.witx
+4 −0 proposal-template/README.md
+8 −0 proposals/README.md
+5 −0 snapshots/README.md
+159 −0 snapshots/make-snapshot.sh
+12 −0 standard/README.md
+7 −2 tools/witx/Cargo.toml
+925 −0 tools/witx/src/abi.rs
+221 −62 tools/witx/src/ast.rs
+0 −171 tools/witx/src/coretypes.rs
+121 −176 tools/witx/src/docs/ast.rs
+8 −51 tools/witx/src/docs/md.rs
+77 −99 tools/witx/src/layout.rs
+7 −14 tools/witx/src/lib.rs
+182 −81 tools/witx/src/parser.rs
+1 −1 tools/witx/src/polyfill.rs
+86 −96 tools/witx/src/render.rs
+46 −197 tools/witx/src/representation.rs
+14 −7 tools/witx/src/toplevel.rs
+313 −173 tools/witx/src/validate.rs
+0 −45 tools/witx/tests/anonymous.rs
+0 −53 tools/witx/tests/multimodule.rs
+0 −2 tools/witx/tests/multimodule/type_b.witx
+0 −2 tools/witx/tests/multimodule/type_c.witx
+0 −183 tools/witx/tests/union.rs
+0 −64 tools/witx/tests/wasi-docs.rs
+656 −0 tools/witx/tests/witxt.rs
+490 −0 tools/witx/tests/witxt/abi.witxt
+56 −0 tools/witx/tests/witxt/anonymous.witxt
+22 −0 tools/witx/tests/witxt/multimodule.witxt
+0 −0 tools/witx/tests/witxt/multimodule/redefine_a.witx
+0 −0 tools/witx/tests/witxt/multimodule/type_a.witx
+2 −0 tools/witx/tests/witxt/multimodule/type_b.witx
+2 −0 tools/witx/tests/witxt/multimodule/type_c.witx
+60 −0 tools/witx/tests/witxt/representation.witxt
+59 −0 tools/witx/tests/witxt/shorthand.witxt
+12 −0 tools/witx/tests/witxt/simple.witxt
+97 −0 tools/witx/tests/witxt/union.witxt
+26 −0 tools/witx/tests/witxt/wasi.witxt
10 changes: 6 additions & 4 deletions crates/wasi-crypto/src/wiggle_interfaces/asymmetric_common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::{guest_types, WasiCryptoCtx};

use std::convert::TryInto;
use wasi_crypto::{ensure, CryptoError, KeyPairEncoding, PublicKeyEncoding, SecretKeyEncoding};
use wasi_crypto::{
ensure, CryptoError, KeyPairEncoding, PublicKeyEncoding, SecretKeyEncoding, Version,
};

impl super::wasi_ephemeral_crypto_asymmetric_common::WasiEphemeralCryptoAsymmetricCommon
for WasiCryptoCtx
Expand Down Expand Up @@ -57,7 +59,7 @@ impl super::wasi_ephemeral_crypto_asymmetric_common::WasiEphemeralCryptoAsymmetr
kp_old_handle.into(),
kp_new_handle.into(),
)?
.into())
.0)
}

fn keypair_from_id(
Expand All @@ -69,7 +71,7 @@ impl super::wasi_ephemeral_crypto_asymmetric_common::WasiEphemeralCryptoAsymmetr
) -> Result<guest_types::Keypair, guest_types::CryptoErrno> {
let kp_id = &*kp_id_ptr.as_array(kp_id_len).as_slice()?;
Ok(self
.keypair_from_id(secrets_manager_handle.into(), kp_id, kp_version.into())?
.keypair_from_id(secrets_manager_handle.into(), kp_id, Version(kp_version))?
.into())
}

Expand Down Expand Up @@ -116,7 +118,7 @@ impl super::wasi_ephemeral_crypto_asymmetric_common::WasiEphemeralCryptoAsymmetr
let (kp_id, version) = self.keypair_id(kp_handle.into())?;
ensure!(kp_id.len() <= kp_id_buf.len(), CryptoError::Overflow.into());
kp_id_buf.copy_from_slice(&kp_id);
Ok((kp_id.len().try_into()?, version.into()))
Ok((kp_id.len().try_into()?, version.0))
}

fn keypair_export(
Expand Down
14 changes: 1 addition & 13 deletions crates/wasi-crypto/src/wiggle_interfaces/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl super::wasi_ephemeral_crypto_common::WasiEphemeralCryptoCommon for WasiCryp
Ok(self.secrets_manager_invalidate(
secrets_manager_handle.into(),
key_id,
key_version.into(),
Version(key_version),
)?)
}
}
Expand All @@ -125,15 +125,3 @@ impl From<guest_types::AlgorithmType> for AlgorithmType {
}
}
}

impl From<guest_types::Version> for Version {
fn from(version: guest_types::Version) -> Self {
Version(version.into())
}
}

impl From<Version> for guest_types::Version {
fn from(version: Version) -> Self {
version.into()
}
}
8 changes: 4 additions & 4 deletions crates/wasi-crypto/src/wiggle_interfaces/symmetric.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{guest_types, WasiCryptoCtx};

use std::convert::TryInto;
use wasi_crypto::{ensure, CryptoError};
use wasi_crypto::{ensure, CryptoError, Version};

impl super::wasi_ephemeral_crypto_symmetric::WasiEphemeralCryptoSymmetric for WasiCryptoCtx {
// --- secrets_manager
Expand Down Expand Up @@ -55,7 +55,7 @@ impl super::wasi_ephemeral_crypto_symmetric::WasiEphemeralCryptoSymmetric for Wa
symmetric_key_old_handle.into(),
symmetric_key_new_handle.into(),
)?
.into())
.0)
}

fn symmetric_key_from_id(
Expand All @@ -72,7 +72,7 @@ impl super::wasi_ephemeral_crypto_symmetric::WasiEphemeralCryptoSymmetric for Wa
.symmetric_key_from_id(
secrets_manager_handle.into(),
symmetric_key_id,
symmetric_key_version.into(),
Version(symmetric_key_version),
)?
.into())
}
Expand Down Expand Up @@ -129,7 +129,7 @@ impl super::wasi_ephemeral_crypto_symmetric::WasiEphemeralCryptoSymmetric for Wa
CryptoError::Overflow.into()
);
key_id_buf.copy_from_slice(&key_id);
Ok((key_id.len().try_into()?, version.into()))
Ok((key_id.len().try_into()?, version.0))
}

fn symmetric_key_close(
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-nn/spec
Submodule spec updated 84 files
+1 −1 .github/workflows/main.yml
+26 −18 README.md
+1 −1 design/application-abi.md
+6 −6 docs/DesignPrinciples.md
+37 −0 docs/Explainer.md
+17 −12 docs/Proposals.md
+15 −0 docs/README.md
+2 −2 docs/witx.md
+1 −1 meetings/2019/WASI-05-02.md
+1 −1 meetings/2019/WASI-05-16.md
+1 −1 meetings/2019/WASI-05-30.md
+1 −1 meetings/2019/WASI-06-27.md
+1 −1 meetings/2019/WASI-07-18.md
+2 −2 meetings/2019/WASI-10-15.md
+36 −0 meetings/2020/WASI-07-30.md
+42 −0 meetings/2020/WASI-08-27.md
+33 −0 meetings/2020/WASI-09-10.md
+30 −0 meetings/2020/WASI-09-24.md
+42 −0 meetings/2020/WASI-10-08.md
+211 −0 meetings/2020/WASI-10-22.md
+153 −0 meetings/2020/WASI-11-19.md
+130 −0 meetings/2020/WASI-12-03.md
+75 −0 meetings/2021/WASI-01-14.md
+206 −0 meetings/2021/WASI-01-28.md
+118 −0 meetings/2021/WASI-02-11.md
+33 −0 meetings/2021/WASI-02-25.md
+12 −0 meetings/README.md
+1 −1 phases/README.md
+902 −324 phases/ephemeral/docs.md
+45 −47 phases/ephemeral/witx/typenames.witx
+6 −8 phases/ephemeral/witx/wasi_ephemeral_args.witx
+2 −4 phases/ephemeral/witx/wasi_ephemeral_clock.witx
+6 −8 phases/ephemeral/witx/wasi_ephemeral_environ.witx
+23 −33 phases/ephemeral/witx/wasi_ephemeral_fd.witx
+25 −26 phases/ephemeral/witx/wasi_ephemeral_nn.witx
+13 −16 phases/ephemeral/witx/wasi_ephemeral_path.witx
+1 −2 phases/ephemeral/witx/wasi_ephemeral_poll.witx
+1 −1 phases/ephemeral/witx/wasi_ephemeral_random.witx
+1 −1 phases/ephemeral/witx/wasi_ephemeral_sched.witx
+4 −8 phases/ephemeral/witx/wasi_ephemeral_sock.witx
+732 −261 phases/old/snapshot_0/docs.md
+38 −38 phases/old/snapshot_0/witx/typenames.witx
+53 −77 phases/old/snapshot_0/witx/wasi_unstable.witx
+731 −260 phases/snapshot/docs.md
+38 −37 phases/snapshot/witx/typenames.witx
+52 −76 phases/snapshot/witx/wasi_snapshot_preview1.witx
+4 −0 proposal-template/README.md
+8 −0 proposals/README.md
+5 −0 snapshots/README.md
+159 −0 snapshots/make-snapshot.sh
+12 −0 standard/README.md
+7 −2 tools/witx/Cargo.toml
+925 −0 tools/witx/src/abi.rs
+222 −65 tools/witx/src/ast.rs
+0 −171 tools/witx/src/coretypes.rs
+121 −176 tools/witx/src/docs/ast.rs
+8 −51 tools/witx/src/docs/md.rs
+77 −99 tools/witx/src/layout.rs
+7 −14 tools/witx/src/lib.rs
+185 −90 tools/witx/src/parser.rs
+1 −1 tools/witx/src/polyfill.rs
+91 −104 tools/witx/src/render.rs
+47 −226 tools/witx/src/representation.rs
+14 −7 tools/witx/src/toplevel.rs
+315 −207 tools/witx/src/validate.rs
+0 −45 tools/witx/tests/anonymous.rs
+0 −53 tools/witx/tests/multimodule.rs
+0 −2 tools/witx/tests/multimodule/type_b.witx
+0 −2 tools/witx/tests/multimodule/type_c.witx
+0 −183 tools/witx/tests/union.rs
+1 −65 tools/witx/tests/wasi-docs.rs
+656 −0 tools/witx/tests/witxt.rs
+490 −0 tools/witx/tests/witxt/abi.witxt
+56 −0 tools/witx/tests/witxt/anonymous.witxt
+22 −0 tools/witx/tests/witxt/multimodule.witxt
+0 −0 tools/witx/tests/witxt/multimodule/redefine_a.witx
+0 −0 tools/witx/tests/witxt/multimodule/type_a.witx
+2 −0 tools/witx/tests/witxt/multimodule/type_b.witx
+2 −0 tools/witx/tests/witxt/multimodule/type_c.witx
+60 −0 tools/witx/tests/witxt/representation.witxt
+59 −0 tools/witx/tests/witxt/shorthand.witxt
+12 −0 tools/witx/tests/witxt/simple.witxt
+97 −0 tools/witx/tests/witxt/union.witxt
+33 −0 tools/witx/tests/witxt/wasi.witxt
2 changes: 1 addition & 1 deletion crates/wasi-nn/src/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use wiggle::GuestPtr;

#[derive(Debug, Error)]
pub enum UsageError {
#[error("Only OpenVINO's IR is currently supported, passed encoding: {0}")]
#[error("Only OpenVINO's IR is currently supported, passed encoding: {0:?}")]
InvalidEncoding(GraphEncoding),
#[error("OpenVINO expects only two buffers (i.e. [ir, weights]), passed: {0}")]
InvalidNumberOfBuilders(u32),
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-nn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ wasmtime_wiggle::wasmtime_integration!({
wasi_ephemeral_nn => {
name: WasiNn,
docs: "An instantiated instance of the wasi-nn exports.",
function_override: {}
}
},
});
12 changes: 6 additions & 6 deletions crates/wasi-nn/src/witx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ use crate::ctx::WasiNnError;
wiggle::from_witx!({
witx: ["$WASI_ROOT/phases/ephemeral/witx/wasi_ephemeral_nn.witx"],
ctx: WasiNnCtx,
errors: { errno => WasiNnError }
errors: { nn_errno => WasiNnError }
});

use types::Errno;
use types::NnErrno;

/// Wiggle generates code that performs some input validation on the arguments passed in by users of
/// wasi-nn. Here we convert the validation error into one (or more, eventually) of the error
/// variants defined in the witx.
impl types::GuestErrorConversion for WasiNnCtx {
fn into_errno(&self, e: wiggle::GuestError) -> Errno {
fn into_nn_errno(&self, e: wiggle::GuestError) -> NnErrno {
eprintln!("Guest error: {:?}", e);
Errno::InvalidArgument
NnErrno::InvalidArgument
}
}

impl<'a> types::UserErrorConversion for WasiNnCtx {
fn errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result<Errno, wiggle::Trap> {
fn nn_errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result<NnErrno, wiggle::Trap> {
eprintln!("Host error: {:?}", e);
match e {
WasiNnError::OpenvinoError(_) => unimplemented!(),
Expand All @@ -33,7 +33,7 @@ impl<'a> types::UserErrorConversion for WasiNnCtx {
}

/// Additionally, we must let Wiggle know which of our error codes represents a successful operation.
impl wiggle::GuestErrorType for Errno {
impl wiggle::GuestErrorType for NnErrno {
fn success() -> Self {
Self::Success
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include = ["src/**/*", "LICENSE"]

[dependencies]
thiserror = "1"
witx = { path = "../wasi-common/WASI/tools/witx", version = "0.8.7", optional = true }
witx = { path = "../wasi-common/WASI/tools/witx", version = "0.9", optional = true }
wiggle-macro = { path = "macro", version = "0.23.0" }
tracing = "0.1.15"
bitflags = "1.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/generate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include = ["src/**/*", "LICENSE"]
[lib]

[dependencies]
witx = { version = "0.8.7", path = "../../wasi-common/WASI/tools/witx" }
witx = { version = "0.9", path = "../../wasi-common/WASI/tools/witx" }
quote = "1.0"
proc-macro2 = "1.0"
heck = "0.3"
Expand Down
6 changes: 5 additions & 1 deletion crates/wiggle/generate/src/error_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ impl ErrorTransform {

pub fn for_abi_error(&self, tref: &TypeRef) -> Option<&UserErrorType> {
match tref {
TypeRef::Name(nt) => self.m.iter().find(|u| u.abi_type.name == nt.name),
TypeRef::Name(nt) => self.for_name(nt),
TypeRef::Value { .. } => None,
}
}

pub fn for_name(&self, nt: &NamedType) -> Option<&UserErrorType> {
self.m.iter().find(|u| u.abi_type.name == nt.name)
}
}

pub struct UserErrorType {
Expand Down
Loading