Skip to content

Commit

Permalink
P22 with wasmi reverted to 031 (#1460)
Browse files Browse the repository at this point in the history
This reverts wasmi from 0.36 to 0.31 while retaining everything else
that's happened in p22. In particular the host still only speaks p22 and
refuses to emulate p21.
  • Loading branch information
graydon authored Oct 2, 2024
1 parent f0bc81b commit d230d7d
Show file tree
Hide file tree
Showing 339 changed files with 77,526 additions and 77,825 deletions.
54 changes: 8 additions & 46 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ default-features = false

[workspace.dependencies.wasmi]
package = "soroban-wasmi"
version = "=0.36.1-soroban.22.0.0"
features = ["no-hash-maps"]
# git = "https://github.com/stellar/wasmi"
# rev = "8eb77b143ca5382c349dd5a8170ffa32a2d0ef03"
version = "=0.31.1-soroban.20.0.1"
git = "https://github.com/stellar/wasmi"
rev = "0ed3f3dee30dc41ebe21972399e0a73a41944aa0"

# [patch."https://github.com/stellar/rs-stellar-xdr"]
# [patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ crate-git-revision = "0.0.6"
[dependencies]
soroban-env-macros = { workspace = true }
stellar-xdr = { workspace = true, default-features = false, features = [ "curr" ] }
wasmi = { workspace = true, optional = true, features = ["no-hash-maps"] }
wasmi = { workspace = true, optional = true }
wasmparser = { workspace = true, optional = true}
serde = { version = "1.0.192", features = ["derive"], optional = true }
static_assertions = "1.1.0"
Expand Down
27 changes: 11 additions & 16 deletions soroban-env-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@ impl From<wasmi::core::TrapCode> for Error {
#[cfg(feature = "wasmi")]
impl From<wasmi::errors::FuncError> for Error {
fn from(err: wasmi::errors::FuncError) -> Self {
(&err).into()
}
}

#[cfg(feature = "wasmi")]
impl From<&wasmi::errors::FuncError> for Error {
fn from(err: &wasmi::errors::FuncError) -> Self {
let ec = match err {
wasmi::errors::FuncError::ExportedFuncNotFound => ScErrorCode::MissingValue,
wasmi::errors::FuncError::MismatchingParameterType
Expand All @@ -227,20 +220,20 @@ impl From<wasmi::Error> for Error {
const INDEX_BOUND: Error =
Error::from_type_and_code(ScErrorType::WasmVm, ScErrorCode::IndexBounds);

match e.kind() {
wasmi::errors::ErrorKind::Memory(e) => match e {
match e {
wasmi::Error::Memory(e) => match e {
wasmi::errors::MemoryError::OutOfBoundsAllocation
| wasmi::errors::MemoryError::OutOfBoundsGrowth => return EXCEEDED_LIMIT,
wasmi::errors::MemoryError::OutOfBoundsAccess => return INDEX_BOUND,
_ => (),
},
wasmi::errors::ErrorKind::Table(e) => match e {
wasmi::Error::Table(e) => match e {
wasmi::errors::TableError::GrowOutOfBounds { .. } => return EXCEEDED_LIMIT,
wasmi::errors::TableError::AccessOutOfBounds { .. }
| wasmi::errors::TableError::CopyOutOfBounds => return INDEX_BOUND,
_ => (),
},
wasmi::errors::ErrorKind::Instantiation(e) => match e {
wasmi::Error::Instantiation(e) => match e {
wasmi::errors::InstantiationError::Memory(me) => match me {
wasmi::errors::MemoryError::OutOfBoundsAllocation
| wasmi::errors::MemoryError::OutOfBoundsGrowth => return EXCEEDED_LIMIT,
Expand All @@ -255,18 +248,20 @@ impl From<wasmi::Error> for Error {
},
_ => (),
},
wasmi::errors::ErrorKind::Fuel(e) => {
wasmi::Error::Store(e) => {
if let wasmi::errors::FuelError::OutOfFuel = e {
return EXCEEDED_LIMIT;
}
}
wasmi::errors::ErrorKind::TrapCode(code) => {
return (*code).into();
wasmi::Error::Trap(trap) => {
if let Some(code) = trap.trap_code() {
return code.into();
}
}
wasmi::errors::ErrorKind::Func(e) => {
wasmi::Error::Func(e) => {
return e.into();
}
wasmi::errors::ErrorKind::Global(e) => {
wasmi::Error::Global(e) => {
if matches!(e, wasmi::errors::GlobalError::TypeMismatch { .. }) {
return Error::from_type_and_code(
ScErrorType::WasmVm,
Expand Down
28 changes: 14 additions & 14 deletions soroban-env-common/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ impl_tryfroms_and_tryfromvals_delegating_to_valconvert!(Error);

#[cfg(feature = "wasmi")]
pub trait WasmiMarshal: Sized {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self>;
fn marshal_from_self(self) -> wasmi::Val;
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self>;
fn marshal_from_self(self) -> wasmi::Value;
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for Val {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
let v = Val::from_payload(i as u64);
if v.is_good() {
Some(v)
Expand All @@ -423,38 +423,38 @@ impl WasmiMarshal for Val {
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self.get_payload() as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self.get_payload() as i64)
}
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for u64 {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
Some(i as u64)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self as i64)
}
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for i64 {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
Some(i)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self)
}
}

Expand Down
12 changes: 6 additions & 6 deletions soroban-env-common/src/wrapper_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ macro_rules! impl_wrapper_wasmi_conversions {
// wasmi / VM argument support
#[cfg(feature = "wasmi")]
impl $crate::WasmiMarshal for $wrapper {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let Some(val) = $crate::Val::try_marshal_from_value(v) {
if <Self as $crate::val::ValConvert>::is_val_type(val) {
return Some(unsafe {
Expand All @@ -95,7 +95,7 @@ macro_rules! impl_wrapper_wasmi_conversions {
None
}

fn marshal_from_self(self) -> wasmi::Val {
fn marshal_from_self(self) -> wasmi::Value {
$crate::Val::marshal_from_self(self.to_val())
}
}
Expand Down Expand Up @@ -188,17 +188,17 @@ macro_rules! declare_wasmi_marshal_for_enum {
($ENUM:ident) => {
#[cfg(feature = "wasmi")]
impl $crate::WasmiMarshal for $ENUM {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
use num_traits::FromPrimitive;
$ENUM::from_i64(i)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self as i64)
}
}
};
Expand Down
Loading

0 comments on commit d230d7d

Please sign in to comment.