Skip to content
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
642 changes: 342 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ tar = "0.4.42"
tempfile = "3.13.0"
zstd = "0.13.2"
componentize-py-shared = { path = "shared" }
wasm-encoder = "0.219.0"
wit-parser = "0.219.0"
wit-component = "0.219.0"
wasmparser = "0.219.0"
wasm-encoder = "0.227.0"
wit-parser = "0.227.0"
wit-component = "0.227.0"
wasmparser = "0.227.0"
indexmap = "2.6.0"
bincode = "1.3.3"
heck = "0.5.0"
pyo3 = { version = "0.22.5", features = [
"abi3-py39",
"extension-module",
], optional = true }
wasmtime = "25.0.2"
wasmtime-wasi = "25.0.2"
wasi-common = "25.0.2"
wasmtime = "30.0.2"
wasmtime-wasi = "30.0.2"
wasi-common = "30.0.2"
once_cell = "1.20.2"
component-init = { git = "https://github.com/dicej/component-init", rev = "6964d14" }
wasm-convert = { git = "https://github.com/dicej/wasm-convert", rev = "a42b419" }
component-init = { git = "https://github.com/dicej/component-init", rev = "2db53ece" }
wasm-convert = { git = "https://github.com/dicej/wasm-convert", rev = "713e2d6a" }
async-trait = "0.1.83"
futures = "0.3.31"
tokio = { version = "1.41.0", features = [
Expand Down
3 changes: 2 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ once_cell = "1.20.2"
pyo3 = { version = "0.22.5", features = ["abi3-py312", "num-bigint"] }
componentize-py-shared = { path = "../shared" }
num-bigint = "0.4.6"
wit-bindgen = "0.34.0"
wit-bindgen = { version = "0.40.0", default-features = false, features = ["macros", "realloc"] }
wit-bindgen-rt = { version = "0.40.0" }
5 changes: 5 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(warnings)]
#![allow(
clippy::useless_conversion,
reason = "some pyo3 macros produce code that does this"
)]
#![allow(static_mut_refs, reason = "wit-bindgen produces code that does this")]

use {
anyhow::{Error, Result},
Expand Down
5 changes: 3 additions & 2 deletions src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub fn has_pointer(resolve: &Resolve, ty: Type) -> bool {
| Type::U64
| Type::S64
| Type::F32
| Type::F64 => false,
| Type::F64
| Type::ErrorContext => false,
Type::String => true,
Type::Id(id) => match &resolve.types[id].kind {
TypeDefKind::Record(record) => record
Expand Down Expand Up @@ -164,7 +165,7 @@ pub fn abi(resolve: &Resolve, ty: Type) -> Abi {
align: 2,
flattened: vec![ValType::I32],
},
Type::U32 | Type::S32 | Type::Char => Abi {
Type::U32 | Type::S32 | Type::Char | Type::ErrorContext => Abi {
size: 4,
align: 4,
flattened: vec![ValType::I32],
Expand Down
38 changes: 20 additions & 18 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
once_cell::sync::Lazy,
std::collections::HashMap,
wasm_encoder::{BlockType, Instruction as Ins, MemArg, ValType},
wit_parser::{Handle, Resolve, Results, Type, TypeDefKind, TypeId},
wit_parser::{Handle, Resolve, Type, TypeDefKind, TypeId},
};

// Assume Wasm32
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct FunctionBindgen<'a> {
stack_pointer: u32,
types: &'a IndexSet<TypeId>,
params: &'a [(String, Type)],
results: &'a Results,
result: &'a Option<Type>,
params_abi: Abi,
results_abi: Abi,
local_stack: Vec<bool>,
Expand All @@ -204,9 +204,9 @@ impl<'a> FunctionBindgen<'a> {
stack_pointer,
types: &summary.types,
params: function.params,
results: function.results,
result: function.result,
params_abi: abi::record_abi(summary.resolve, function.params.types()),
results_abi: abi::record_abi(summary.resolve, function.results.types()),
results_abi: abi::record_abi(summary.resolve, function.result.types()),
local_types: Vec::new(),
local_stack: Vec::new(),
instructions: Vec::new(),
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<'a> FunctionBindgen<'a> {
})
.collect::<Vec<_>>();

self.from_canon_record(self.results.types(), context, &locals, output);
self.from_canon_record(self.result.types(), context, &locals, output);

for (local, ty) in locals.iter().zip(&self.results_abi.flattened.clone()).rev() {
self.pop_local(*local, *ty);
Expand All @@ -343,7 +343,7 @@ impl<'a> FunctionBindgen<'a> {
self.get_stack();
self.push(Ins::LocalSet(source));

self.load_record(self.results.types(), context, source, output);
self.load_record(self.result.types(), context, source, output);

self.pop_local(source, ValType::I32);
self.pop_stack(self.results_abi.size);
Expand All @@ -369,7 +369,7 @@ impl<'a> FunctionBindgen<'a> {
}

pub fn compile_export(&mut self, index: i32, from_canon: i32, to_canon: i32) {
let return_style = match self.results.types().collect::<Vec<_>>().as_slice() {
let return_style = match self.result.types().collect::<Vec<_>>().as_slice() {
[Type::Id(id)] if matches!(&self.resolve.types[*id].kind, TypeDefKind::Result(_)) => {
ReturnStyle::Result
}
Expand Down Expand Up @@ -429,7 +429,7 @@ impl<'a> FunctionBindgen<'a> {
self.get_stack();
self.push(Ins::LocalSet(source));

self.load_copy_record(self.results.types(), source);
self.load_copy_record(self.result.types(), source);

self.pop_local(source, ValType::I32);

Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a> FunctionBindgen<'a> {

let mut store_offset = 0;
let mut load_offset = 0;
for ty in self.results.types() {
for ty in self.result.types() {
let abi = abi::abi(self.resolve, ty);
store_offset = abi::align(store_offset, abi.align);

Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a> FunctionBindgen<'a> {
// Arg 0: *mut MyResults
let value = 0;

self.free_stored_record(self.results.types(), value);
self.free_stored_record(self.result.types(), value);

self.push(Ins::LocalGet(value));
self.push(Ins::I32Const(self.results_abi.size.try_into().unwrap()));
Expand Down Expand Up @@ -619,7 +619,7 @@ impl<'a> FunctionBindgen<'a> {
*IMPORTS.get("componentize-py#ToCanonI32").unwrap(),
));
}
Type::U8 | Type::U16 | Type::U32 => {
Type::U8 | Type::U16 | Type::U32 | Type::ErrorContext => {
self.push(Ins::LocalGet(context));
self.push(Ins::LocalGet(value));
self.push(Ins::Call(
Expand Down Expand Up @@ -920,7 +920,7 @@ impl<'a> FunctionBindgen<'a> {
self.to_canon(ty, context, value);
self.push(Ins::I32Store16(mem_arg(0, 1)));
}
Type::U32 | Type::S32 => {
Type::U32 | Type::S32 | Type::ErrorContext => {
self.push(Ins::LocalGet(destination));
self.to_canon(ty, context, value);
self.push(Ins::I32Store(mem_arg(0, 2)));
Expand Down Expand Up @@ -1212,7 +1212,7 @@ impl<'a> FunctionBindgen<'a> {
self.push(Ins::LocalGet(source[0]));
self.push(Ins::I32Store16(mem_arg(0, 1)));
}
Type::U32 | Type::S32 | Type::Char => {
Type::U32 | Type::S32 | Type::Char | Type::ErrorContext => {
self.push(Ins::LocalGet(destination));
self.push(Ins::LocalGet(source[0]));
self.push(Ins::I32Store(mem_arg(0, 2)));
Expand Down Expand Up @@ -1458,7 +1458,7 @@ impl<'a> FunctionBindgen<'a> {
*IMPORTS.get("componentize-py#FromCanonI32").unwrap(),
));
}
Type::U8 | Type::U16 | Type::U32 => {
Type::U8 | Type::U16 | Type::U32 | Type::ErrorContext => {
self.push(Ins::LocalGet(context));
self.push(Ins::LocalGet(value[0]));
self.push(Ins::Call(
Expand Down Expand Up @@ -1793,7 +1793,7 @@ impl<'a> FunctionBindgen<'a> {
self.from_canon(ty, context, &[value]);
self.pop_local(value, ValType::I32);
}
Type::U32 | Type::S32 | Type::Char => {
Type::U32 | Type::S32 | Type::Char | Type::ErrorContext => {
let value = self.push_local(ValType::I32);
self.push(Ins::LocalGet(source));
self.push(Ins::I32Load(mem_arg(0, 2)));
Expand Down Expand Up @@ -2091,7 +2091,7 @@ impl<'a> FunctionBindgen<'a> {
self.push(Ins::LocalGet(source));
self.push(Ins::I32Load16S(mem_arg(0, 1)));
}
Type::U32 | Type::S32 | Type::Char => {
Type::U32 | Type::S32 | Type::Char | Type::ErrorContext => {
self.push(Ins::LocalGet(source));
self.push(Ins::I32Load(mem_arg(0, 2)));
}
Expand Down Expand Up @@ -2307,7 +2307,8 @@ impl<'a> FunctionBindgen<'a> {
| Type::U64
| Type::S64
| Type::F32
| Type::F64 => {}
| Type::F64
| Type::ErrorContext => {}

Type::String => {
self.push(Ins::LocalGet(value[0]));
Expand Down Expand Up @@ -2466,7 +2467,8 @@ impl<'a> FunctionBindgen<'a> {
| Type::U64
| Type::S64
| Type::F32
| Type::F64 => {}
| Type::F64
| Type::ErrorContext => {}

Type::String => {
self.push(Ins::LocalGet(value));
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use {
},
wasmtime_wasi::{
pipe::{MemoryInputPipe, MemoryOutputPipe},
DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView,
DirPerms, FilePerms, IoView, WasiCtx, WasiCtxBuilder, WasiView,
},
wit_parser::{Resolve, TypeDefKind, UnresolvedPackageGroup, WorldId, WorldItem, WorldKey},
};
Expand Down Expand Up @@ -63,6 +63,9 @@ impl WasiView for Ctx {
fn ctx(&mut self) -> &mut WasiCtx {
&mut self.wasi
}
}

impl IoView for Ctx {
fn table(&mut self) -> &mut ResourceTable {
&mut self.table
}
Expand Down
5 changes: 5 additions & 0 deletions src/python.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(
clippy::useless_conversion,
reason = "some pyo3 macros produce code that does this"
)]

use {
pyo3::{
exceptions::PyAssertionError,
Expand Down
Loading
Loading