Skip to content

Commit

Permalink
Update deps including wasmtime to 22.0
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Jun 27, 2024
1 parent 5c461b3 commit d9ccab8
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 369 deletions.
520 changes: 257 additions & 263 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ home = "0.5.9"
log = "0.4"
nom = "7.1.3"
nom_locate = "4.2"
rustyline = "13.0.0"
tokio = { version = "1.36.0", features = ["macros"] }
rustyline = "14.0.0"
tokio = { version = "1.38", features = ["macros"] }

wasmtime = { version = "18.0.1", features = ["component-model"] }
wasmtime-wasi = { version = "18.0.2", features = ["tokio"] }
wasmtime = "22.0"
wasmtime-wasi = "22.0"
wasi-virt = { git = "https://github.com/bytecodealliance/WASI-Virt", rev = "fd2fae04342ea58aab2426ca041da68be046b030" }
wit-component = "0.201.0"
wit-parser = "0.201.0"
wasm-compose = "0.201.0"
wit-component = "0.211"
wit-parser = "0.211"
wasm-compose = "0.211"
24 changes: 10 additions & 14 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> Cmd<'a> {
"{}",
results
.into_iter()
.map(|v| format!("{}", format_val(&v)))
.map(|v| format_val(&v))
.collect::<Vec<_>>()
.join("\n")
)
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> Cmd<'a> {
bail!("unrecognized token {}", token.input.str);
};
let adapter =
std::fs::read(&*path).context("could not read path to adapter module")?;
std::fs::read(path).context("could not read path to adapter module")?;
runtime.compose(&adapter)?;
*resolver = WorldResolver::from_bytes(runtime.component_bytes())?;
}
Expand All @@ -183,7 +183,7 @@ impl<'a> Cmd<'a> {
};
let component_bytes = std::fs::read(component)
.with_context(|| format!("could not read component '{component}'"))?;
runtime.stub(&resolver, import_ident, export_ident, &component_bytes)?;
runtime.stub(resolver, import_ident, export_ident, &component_bytes)?;
}
Cmd::BuiltIn {
name: "inspect",
Expand Down Expand Up @@ -252,7 +252,7 @@ There are also builtin functions that can be called with a preceding '.'. Suppor
fn format_world_item(item: &wit_parser::WorldItem, resolver: &WorldResolver) -> Option<String> {
match item {
wit_parser::WorldItem::Function(f) => Some(format_function(f, resolver)),
wit_parser::WorldItem::Interface(id) => {
wit_parser::WorldItem::Interface { id, .. } => {
let interface = resolver.interface_by_id(*id).unwrap();
if interface.functions.is_empty() {
return None;
Expand Down Expand Up @@ -323,34 +323,30 @@ fn format_val(val: &Val) -> String {
Val::Float32(f) => f.to_string(),
Val::Float64(f) => f.to_string(),
Val::Char(c) => c.to_string(),
Val::Option(o) => match o.value() {
Val::Option(o) => match o {
Some(o) => format!("some({})", format_val(o)),
None => "none".into(),
},
Val::Result(r) => match r.value() {
Val::Result(r) => match r {
Ok(Some(o)) => format!("ok({})", format_val(o)),
Ok(None) => "ok".to_string(),
Err(Some(e)) => format!("err({})", format_val(e)),
Err(None) => "err".to_string(),
},
Val::List(l) => {
let items = l
.iter()
.map(|value| format!("{}", format_val(value)))
.collect::<Vec<_>>()
.join(", ");
let items = l.iter().map(format_val).collect::<Vec<_>>().join(", ");
format!("[{items}]")
}
Val::Record(r) => {
let fields = r
.fields()
.iter()
.map(|(key, value)| format!("{}: {}", key, format_val(value)))
.collect::<Vec<_>>()
.join(", ");
format!("{{ {fields} }}")
}
Val::Tuple(_) => todo!(),
Val::Variant(_) => todo!(),
Val::Variant(_, _) => todo!(),
Val::Enum(_) => todo!(),
Val::Flags(_) => todo!(),
Val::Resource(_) => todo!(),
Expand All @@ -377,7 +373,7 @@ fn val_as_type(val: &Val) -> &'static str {
Val::List(_) => "list",
Val::Record(_) => "record",
Val::Tuple(_) => todo!(),
Val::Variant(_) => todo!(),
Val::Variant(_, _) => todo!(),
Val::Enum(_) => todo!(),
Val::Flags(_) => todo!(),
Val::Resource(_) => todo!(),
Expand Down
8 changes: 5 additions & 3 deletions src/command/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ impl<'a> Expr<'a> {
}
}
}
return Err(ParserError::UnexpectedEndOfInput);
Err(ParserError::UnexpectedEndOfInput)
}
TokenKind::OpenBrace => {
input.pop_front();
#[allow(clippy::enum_variant_names)]
enum State<'a> {
ExpectIdent,
ExpectColon(&'a str),
Expand Down Expand Up @@ -190,7 +191,7 @@ impl<'a> Expr<'a> {
_ => return Err(ParserError::UnexpectedToken(*token)),
}
}
return Err(ParserError::UnexpectedEndOfInput);
Err(ParserError::UnexpectedEndOfInput)
}
TokenKind::Ident(_) => {
let func = FunctionCall::try_parse(input)?;
Expand All @@ -200,7 +201,7 @@ impl<'a> Expr<'a> {
}
}

_ => return Ok(None),
_ => Ok(None),
}
}
}
Expand Down Expand Up @@ -341,6 +342,7 @@ pub struct InterfaceIdent<'a> {
impl<'a> InterfaceIdent<'a> {
fn try_parse<'b>(input: &'b mut VecDeque<Token<'a>>) -> Result<Option<Self>, ParserError<'a>> {
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
enum State<'a> {
ExpectFirst,
ExpectColon(&'a str),
Expand Down
2 changes: 1 addition & 1 deletion src/command/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Deref for SpannedStr<'_> {
type Target = str;

fn deref(&self) -> &Self::Target {
&self.str
self.str
}
}

Expand Down
58 changes: 30 additions & 28 deletions src/evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use anyhow::{bail, Context};
use wasmtime::component::{self, List, Record, Val};
use wasmtime::component::{self, Val};

use crate::{command::parser, runtime::Runtime, wit::WorldResolver};

Expand Down Expand Up @@ -33,7 +33,7 @@ impl<'a> Evaluator<'a> {
) -> anyhow::Result<Val> {
match expr {
parser::Expr::Literal(l) => self.eval_literal(l, type_hint),
parser::Expr::Ident(ident) => self.resolve_ident(&*ident, type_hint),
parser::Expr::Ident(ident) => self.resolve_ident(ident, type_hint),
parser::Expr::FunctionCall(func) => {
let ident = func.ident;
let mut args = func.args;
Expand All @@ -47,19 +47,19 @@ impl<'a> Evaluator<'a> {
if ident.interface.is_none() && ident.item == "some" && args.len() == 1 =>
{
let val = self.eval(args.remove(0), Some(&o.ty()))?;
return o.new_val(Some(val));
return Ok(val);
}
Some(component::Type::Result(r)) if args.len() == 1 => {
if let Some(ok) = r.ok() {
if ident.interface.is_none() && ident.item == "ok" {
let val = self.eval(args.remove(0), Some(&ok))?;
return r.new_val(Ok(Some(val)));
return Ok(val);
}
}
if let Some(err) = r.err() {
if ident.interface.is_none() && ident.item == "err" {
let val = self.eval(args.remove(0), Some(&err))?;
return r.new_val(Err(Some(val)));
return Ok(val);
}
}
}
Expand Down Expand Up @@ -126,18 +126,15 @@ impl<'a> Evaluator<'a> {
for item in list.items {
values.push(self.eval(item, Some(&l.ty()))?)
}
Ok(Val::List(List::new(&l, values.into_boxed_slice())?))
Ok(Val::List(values))
}
Some(component::Type::Option(o)) => match o.ty() {
component::Type::List(l) => {
let mut values = Vec::new();
for item in list.items {
values.push(self.eval(item, Some(&l.ty()))?)
}
Ok(Val::Option(component::OptionVal::new(
o,
Some(Val::List(List::new(&l, values.into_boxed_slice())?)),
)?))
Ok(Val::Option(Some(Box::new(Val::List(values)))))
}
t => bail!(
"type error - required option<{}> found = list",
Expand Down Expand Up @@ -177,18 +174,21 @@ impl<'a> Evaluator<'a> {
.sort_by(|(f1, _), (f2, _)| types.get(f1).unwrap().cmp(types.get(f2).unwrap()));

for ((name, field_expr), field_type) in r.fields.into_iter().zip(ty.fields()) {
values.push((name, self.eval(field_expr, Some(&field_type.ty))?));
values.push((
name.to_owned(),
self.eval(field_expr, Some(&field_type.ty))?,
));
}
Ok(Val::Record(Record::new(ty, values)?))
Ok(Val::Record(values))
}
parser::Literal::String(s) => {
let val = Val::String(s.to_owned().into());
let val = Val::String(s.to_owned());
match type_hint {
Some(component::Type::Result(r)) => r.new_val(match (r.ok(), r.err()) {
(Some(_), _) => Ok(Some(val)),
(_, Some(_)) => Err(Some(val)),
Some(component::Type::Result(r)) => Ok(Val::Result(match (r.ok(), r.err()) {
(Some(_), _) => Ok(Some(Box::new(val))),
(_, Some(_)) => Err(Some(Box::new(val))),
(None, None) => return Ok(val),
}),
})),
_ => Ok(val),
}
}
Expand All @@ -209,19 +209,21 @@ impl<'a> Evaluator<'a> {
Some(t) => match t {
component::Type::Bool if ident == "true" => Ok(Val::Bool(true)),
component::Type::Bool if ident == "false" => Ok(Val::Bool(false)),
component::Type::Enum(e) => e.new_val(ident),
component::Type::Variant(v) => match self.lookup_in_scope(ident) {
component::Type::Enum(_) => Ok(Val::Enum(ident.to_owned())),
component::Type::Variant(_) => match self.lookup_in_scope(ident) {
Ok(v) => Ok(v),
Err(_) => v.new_val(ident, None),
Err(_) => Ok(Val::Option(None)),
},
component::Type::Option(o) if ident == "none" => o.new_val(None),
component::Type::Option(o) => {
o.new_val(Some(self.resolve_ident(ident, Some(&o.ty()))?))
}
component::Type::Result(r) => r.new_val(match (r.ok(), r.err()) {
(Some(o), _) => Ok(Some(self.resolve_ident(ident, Some(&o))?)),
(None, None) if ident == "ok" => Ok(None),
(None, None) if ident == "err" => Err(None),
component::Type::Option(_) if ident == "none" => Ok(Val::Option(None)),
component::Type::Option(o) => Ok(Val::Option(Some(Box::new(
self.resolve_ident(ident, Some(&o.ty()))?,
)))),
component::Type::Result(r) => Ok(match (r.ok(), r.err()) {
(Some(o), _) => {
Val::Result(Ok(Some(Box::new(self.resolve_ident(ident, Some(&o))?))))
}
(None, None) if ident == "ok" => Val::Result(Ok(None)),
(None, None) if ident == "err" => Val::Result(Err(None)),
_ => return self.lookup_in_scope(ident),
}),
component::Type::Bool
Expand Down
Loading

0 comments on commit d9ccab8

Please sign in to comment.