diff --git a/Cargo.lock b/Cargo.lock index 2c30e757793..d46684a0762 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1123,25 +1123,49 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "bytecheck" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" dependencies = [ - "bytecheck_derive", - "ptr_meta", + "bytecheck_derive 0.6.12", + "ptr_meta 0.1.4", + "simdutf8", +] + +[[package]] +name = "bytecheck" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c8f430744b23b54ad15161fcbc22d82a29b73eacbe425fea23ec822600bc6f" +dependencies = [ + "bytecheck_derive 0.8.0", + "ptr_meta 0.3.0", + "rancor", + "simdutf8", ] [[package]] name = "bytecheck_derive" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" dependencies = [ "proc-macro2", "quote", "syn 1.0.103", ] +[[package]] +name = "bytecheck_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523363cbe1df49b68215efdf500b103ac3b0fb4836aed6d15689a076eadb8fff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -3847,6 +3871,26 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" +[[package]] +name = "munge" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64142d38c84badf60abf06ff9bd80ad2174306a5b11bd4706535090a30a419df" +dependencies = [ + "munge_macro", +] + +[[package]] +name = "munge_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "native-tls" version = "0.2.10" @@ -4986,7 +5030,7 @@ dependencies = [ "hashbrown 0.14.5", "near-vm-types", "near-vm-vm", - "rkyv", + "rkyv 0.8.8", "target-lexicon 0.12.16", "thiserror 2.0.0", "tracing", @@ -5038,7 +5082,7 @@ dependencies = [ "near-vm-types", "near-vm-vm", "region", - "rkyv", + "rkyv 0.8.8", "rustc-demangle", "rustix", "target-lexicon 0.12.16", @@ -5176,7 +5220,7 @@ dependencies = [ "bolero", "indexmap 2.2.6", "num-traits", - "rkyv", + "rkyv 0.8.8", "thiserror 2.0.0", ] @@ -5194,7 +5238,7 @@ dependencies = [ "more-asserts", "near-vm-types", "region", - "rkyv", + "rkyv 0.8.8", "thiserror 2.0.0", "tracing", "winapi", @@ -6347,7 +6391,16 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" dependencies = [ - "ptr_meta_derive", + "ptr_meta_derive 0.1.4", +] + +[[package]] +name = "ptr_meta" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9e76f66d3f9606f44e45598d155cb13ecf09f4a28199e48daf8c8fc937ea90" +dependencies = [ + "ptr_meta_derive 0.3.0", ] [[package]] @@ -6361,6 +6414,17 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "ptr_meta_derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "pulley-interpreter" version = "26.0.1" @@ -6398,6 +6462,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rancor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf5f7161924b9d1cea0e4cabc97c372cea92b5f927fc13c6bca67157a0ad947" +dependencies = [ + "ptr_meta 0.3.0", +] + [[package]] name = "rand" version = "0.8.5" @@ -6596,11 +6669,20 @@ dependencies = [ [[package]] name = "rend" -version = "0.3.6" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck 0.6.12", +] + +[[package]] +name = "rend" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79af64b4b6362ffba04eef3a4e10829718a4896dac19daa741851c86781edf95" +checksum = "a35e8a6bf28cd121053a66aa2e6a2e3eaffad4a60012179f0e864aa5ffeff215" dependencies = [ - "bytecheck", + "bytecheck 0.8.0", ] [[package]] @@ -6683,29 +6765,63 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.38" +version = "0.7.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" dependencies = [ - "bytecheck", + "bitvec", + "bytecheck 0.6.12", + "bytes", "hashbrown 0.12.3", - "ptr_meta", - "rend", - "rkyv_derive", + "ptr_meta 0.1.4", + "rend 0.4.2", + "rkyv_derive 0.7.45", "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395027076c569819ea6035ee62e664f5e03d74e281744f55261dd1afd939212b" +dependencies = [ + "bytecheck 0.8.0", + "bytes", + "hashbrown 0.14.5", + "indexmap 2.2.6", + "munge", + "ptr_meta 0.3.0", + "rancor", + "rend 0.5.2", + "rkyv_derive 0.8.8", + "tinyvec", + "uuid", ] [[package]] name = "rkyv_derive" -version = "0.7.38" +version = "0.7.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" dependencies = [ "proc-macro2", "quote", "syn 1.0.103", ] +[[package]] +name = "rkyv_derive" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cb82b74b4810f07e460852c32f522e979787691b0b7b7439fe473e49d49b2f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "rlimit" version = "0.7.0" @@ -7332,6 +7448,12 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + [[package]] name = "similar" version = "2.1.0" @@ -8339,6 +8461,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" + [[package]] name = "valuable" version = "0.1.0" @@ -8516,7 +8644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46fdae7245128f284476e6db9653ef0a15b011975091bcd7f9d7303132409662" dependencies = [ "enumset", - "rkyv", + "rkyv 0.7.45", "smallvec", "target-lexicon 0.12.16", "thiserror 1.0.50", @@ -8573,7 +8701,7 @@ dependencies = [ "enumset", "leb128", "region", - "rkyv", + "rkyv 0.7.45", "thiserror 1.0.50", "wasmer-compiler-near", "wasmer-engine-near", @@ -8653,7 +8781,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ba154adffb0fbd33f5dabd3788a1744d846b43e6e090d44269c7ee8fa5743e4" dependencies = [ "indexmap 1.9.2", - "rkyv", + "rkyv 0.7.45", "thiserror 1.0.50", ] @@ -8671,7 +8799,7 @@ dependencies = [ "memoffset 0.6.5", "more-asserts", "region", - "rkyv", + "rkyv 0.7.45", "thiserror 1.0.50", "wasmer-types-near", "winapi", diff --git a/Cargo.toml b/Cargo.toml index 98ef7b882ce..e7cfc6f1087 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -325,7 +325,7 @@ regex = "1.7.1" region = "3.0" reqwest = { version = "0.11.14", features = ["blocking"] } ripemd = "0.1.1" -rkyv = "0.7.31" +rkyv = "0.8.0" rlimit = "0.7" rlp = "0.5.2" rocksdb = { version = "0.21.0", default-features = false, features = [ diff --git a/deny.toml b/deny.toml index 443e010e348..c0cb6f1665a 100644 --- a/deny.toml +++ b/deny.toml @@ -47,6 +47,10 @@ skip = [ # old version used by wasmer et al { name = "dynasm", version = "=1.2.3" }, { name = "dynasmrt", version = "=1.2.3" }, + { name = "rkyv", version = "^0.7" }, + { name = "rkyv_derive", version = "^0.7" }, + { name = "ptr_meta", version = "^0.1" }, + { name = "ptr_meta_derive", version = "^0.1" }, # wasmer and wasmtime { name = "target-lexicon", version = "=0.10.0" }, @@ -69,8 +73,6 @@ skip = [ { name = "parking_lot_core", version = "=0.7.2" }, { name = "lock_api", version = "=0.3.4" }, { name = "digest", version = "=0.8.1" }, - - # wasmer 0.18 { name = "nix", version = "=0.15.0" }, # many crates haven't updated to syn 2.0 yet. diff --git a/runtime/near-vm-runner/src/near_vm_runner/mod.rs b/runtime/near-vm-runner/src/near_vm_runner/mod.rs index e2f70bf6cc0..c25ebe840c3 100644 --- a/runtime/near-vm-runner/src/near_vm_runner/mod.rs +++ b/runtime/near-vm-runner/src/near_vm_runner/mod.rs @@ -38,7 +38,7 @@ enum NearVmCompiler { // major version << 6 // minor version const VM_CONFIG: NearVmConfig = NearVmConfig { - seed: (2 << 29) | (2 << 6) | 3, + seed: (2 << 29) | (2 << 6) | 4, engine: NearVmEngine::Universal, compiler: NearVmCompiler::Singlepass, }; diff --git a/runtime/near-vm-runner/src/tests/cache.rs b/runtime/near-vm-runner/src/tests/cache.rs index fe2bf0d4492..62b0442bf41 100644 --- a/runtime/near-vm-runner/src/tests/cache.rs +++ b/runtime/near-vm-runner/src/tests/cache.rs @@ -158,13 +158,13 @@ fn test_wasmer2_artifact_output_stability() { ]; let mut got_prepared_hashes = Vec::with_capacity(seeds.len()); let compiled_hashes = [ - 7897366507246831520, - 4504708181643041916, - 12437432560773026476, - 3217201805099435580, - 17987183739396987305, - 7265745711428292723, - 4973318757824608216, + 17577916829021396775, + 8041373570933915084, + 6630926580728989211, + 4387381945665529622, + 4511251750786693810, + 4599571621125708978, + 18136310787576767811, ]; let mut got_compiled_hashes = Vec::with_capacity(seeds.len()); for seed in seeds { @@ -238,13 +238,13 @@ fn test_near_vm_artifact_output_stability() { let mut got_prepared_hashes = Vec::with_capacity(seeds.len()); let compiled_hashes = [ // See the above comment if you want to change this - 14308529260517090966, - 13346695179117473012, - 7039559215467115488, - 2326827595782652597, - 2563919585736953738, - 18320128353038066787, - 4007078811749074507, + 17541855811103092909, + 11151026003357116368, + 6536268071368571568, + 3800417228716434560, + 12640841643239683751, + 10206902649207070630, + 14540739231666637305, ]; let mut got_compiled_hashes = Vec::with_capacity(seeds.len()); for seed in seeds { diff --git a/runtime/near-vm-runner/src/tests/fuzzers.rs b/runtime/near-vm-runner/src/tests/fuzzers.rs index 1a31dd57592..8d40faac3f9 100644 --- a/runtime/near-vm-runner/src/tests/fuzzers.rs +++ b/runtime/near-vm-runner/src/tests/fuzzers.rs @@ -1,5 +1,4 @@ use super::test_vm_config; -use crate::internal::wasmparser::{Export, ExternalKind, Parser, Payload, TypeDef}; use crate::logic::errors::FunctionCallError; use crate::logic::mocks::mock_external::MockedExternal; use crate::logic::VMContext; @@ -12,7 +11,9 @@ use near_test_contracts::ArbitraryModule; use std::sync::Arc; /// Finds a no-parameter exported function, something like `(func (export "entry-point"))`. +#[cfg(feature = "prepare")] pub fn find_entry_point(contract: &ContractCode) -> Option { + use crate::internal::wasmparser::{Export, ExternalKind, Parser, Payload, TypeDef}; let mut tys = Vec::new(); let mut fns = Vec::new(); for payload in Parser::default().parse_all(contract.code()) { @@ -60,6 +61,7 @@ pub fn create_context(input: Vec) -> VMContext { } } +#[cfg(feature = "prepare")] fn run_fuzz(code: &ContractCode, vm_kind: VMKind) -> VMResult { let mut fake_external = MockedExternal::with_code(code.clone_for_tests()); let method_name = find_entry_point(code).unwrap_or_else(|| "main".to_string()); @@ -94,6 +96,7 @@ fn run_fuzz(code: &ContractCode, vm_kind: VMKind) -> VMResult { } #[test] +#[cfg(feature = "prepare")] fn slow_test_current_vm_does_not_crash_fuzzer() { let config = test_vm_config(); if config.vm_kind.is_available() { @@ -108,6 +111,7 @@ fn slow_test_current_vm_does_not_crash_fuzzer() { #[test] #[cfg_attr(not(all(feature = "wasmtime_vm", feature = "near_vm", target_arch = "x86_64")), ignore)] +#[cfg(feature = "prepare")] fn slow_test_near_vm_and_wasmtime_agree_fuzzer() { bolero::check!().with_arbitrary::().for_each(|module: &ArbitraryModule| { let code = ContractCode::new(module.0.to_bytes(), None); diff --git a/runtime/near-vm-runner/src/tests/wasm_validation.rs b/runtime/near-vm-runner/src/tests/wasm_validation.rs index b2a01036996..26077b64c83 100644 --- a/runtime/near-vm-runner/src/tests/wasm_validation.rs +++ b/runtime/near-vm-runner/src/tests/wasm_validation.rs @@ -1,6 +1,5 @@ use super::test_builder::test_builder; use super::test_vm_config; -use crate::prepare::prepare_contract; use crate::tests::with_vm_variants; use expect_test::expect; @@ -100,12 +99,13 @@ static EXPECTED_UNSUPPORTED: &[(&str, &str)] = &[ ]; #[test] +#[cfg(feature = "prepare")] fn ensure_fails_verification() { let config = test_vm_config(); with_vm_variants(&config, |kind| { for (feature_name, wat) in EXPECTED_UNSUPPORTED { let wasm = wat::parse_str(wat).expect("parsing test wat should succeed"); - if let Ok(_) = prepare_contract(&wasm, &config, kind) { + if let Ok(_) = crate::prepare::prepare_contract(&wasm, &config, kind) { panic!("wasm containing use of {} feature did not fail to prepare", feature_name); } } diff --git a/runtime/near-vm-runner/src/wasmer2_runner.rs b/runtime/near-vm-runner/src/wasmer2_runner.rs index 740212cb711..db16accd7d9 100644 --- a/runtime/near-vm-runner/src/wasmer2_runner.rs +++ b/runtime/near-vm-runner/src/wasmer2_runner.rs @@ -218,7 +218,7 @@ impl Wasmer2Config { // major version << 6 // minor version const WASMER2_CONFIG: Wasmer2Config = Wasmer2Config { - seed: (1 << 29) | (12 << 6) | 2, + seed: (1 << 29) | (12 << 6) | 3, engine: WasmerEngine::Universal, compiler: WasmerCompiler::Singlepass, }; diff --git a/runtime/near-vm/compiler/src/jump_table.rs b/runtime/near-vm/compiler/src/jump_table.rs index 8c6744aafe7..efda19d8f44 100644 --- a/runtime/near-vm/compiler/src/jump_table.rs +++ b/runtime/near-vm/compiler/src/jump_table.rs @@ -12,7 +12,7 @@ use near_vm_types::entity::{entity_impl, SecondaryMap}; /// `JumpTable`s are used for indirect branching and are specialized for dense, /// 0-based jump offsets. #[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] -#[archive_attr(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord))] +#[rkyv(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord))] #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct JumpTable(u32); diff --git a/runtime/near-vm/compiler/src/section.rs b/runtime/near-vm/compiler/src/section.rs index eb752e2e0b2..2c5629193df 100644 --- a/runtime/near-vm/compiler/src/section.rs +++ b/runtime/near-vm/compiler/src/section.rs @@ -11,12 +11,10 @@ use near_vm_types::entity::entity_impl; /// Index type of a Section defined inside a WebAssembly `Compilation`. #[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] -#[archive_attr(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug))] +#[rkyv(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug))] #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] pub struct SectionIndex(u32); - entity_impl!(SectionIndex); - entity_impl!(ArchivedSectionIndex); /// Custom section Protection. @@ -73,9 +71,12 @@ impl<'a> From<&'a CustomSection> for CustomSectionRef<'a> { impl<'a> From<&'a ArchivedCustomSection> for CustomSectionRef<'a> { fn from(section: &'a ArchivedCustomSection) -> Self { CustomSectionRef { - protection: Result::<_, std::convert::Infallible>::unwrap( - rkyv::Deserialize::deserialize(§ion.protection, &mut rkyv::Infallible), - ), + protection: match section.protection { + ArchivedCustomSectionProtection::Read => CustomSectionProtection::Read, + ArchivedCustomSectionProtection::ReadExecute => { + CustomSectionProtection::ReadExecute + } + }, bytes: §ion.bytes.0[..], } } diff --git a/runtime/near-vm/compiler/src/sourceloc.rs b/runtime/near-vm/compiler/src/sourceloc.rs index bd57d27e0c7..e8d9457baeb 100644 --- a/runtime/near-vm/compiler/src/sourceloc.rs +++ b/runtime/near-vm/compiler/src/sourceloc.rs @@ -14,7 +14,6 @@ use crate::lib::std::fmt; /// The default source location uses the all-ones bit pattern `!0`. It is used for instructions /// that can't be given a real source location. #[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Clone, Copy, PartialEq, Eq)] -#[archive(as = "Self")] #[repr(transparent)] pub struct SourceLoc(u32); diff --git a/runtime/near-vm/engine/src/universal/engine.rs b/runtime/near-vm/engine/src/universal/engine.rs index bd77ff3f09f..87cbe531983 100644 --- a/runtime/near-vm/engine/src/universal/engine.rs +++ b/runtime/near-vm/engine/src/universal/engine.rs @@ -20,7 +20,8 @@ use near_vm_vm::{ VMCallerCheckedAnyfunc, VMFuncRef, VMImportType, VMLocalFunction, VMOffsets, VMSharedSignatureIndex, VMTrampoline, }; -use rkyv::de::deserializers::SharedDeserializeMap; +use rkyv::tuple::ArchivedTuple3; +use rkyv::Archived; use std::collections::BTreeMap; use std::convert::TryFrom; use std::sync::{Arc, Mutex}; @@ -313,14 +314,14 @@ impl UniversalEngine { let import_counts: ImportCounts = unrkyv(&module.import_counts); let local_memories = (import_counts.memories as usize..module.memories.len()) .map(|idx| { - let idx = MemoryIndex::new(idx); + let idx = Archived::::new(idx); let mty = &module.memories[&idx]; (unrkyv(mty), unrkyv(&info.memory_styles[&idx])) }) .collect(); let local_tables = (import_counts.tables as usize..module.tables.len()) .map(|idx| { - let idx = TableIndex::new(idx); + let idx = Archived::::new(idx); let tty = &module.tables[&idx]; (unrkyv(tty), unrkyv(&info.table_styles[&idx])) }) @@ -331,14 +332,16 @@ impl UniversalEngine { .skip(import_counts.globals as _) .enumerate() .map(|(idx, (_, t))| { - let init = unrkyv(&module.global_initializers[&LocalGlobalIndex::new(idx)]); - (*t, init) + let init = &module.global_initializers[&Archived::::new(idx)]; + (unrkyv(t), unrkyv(init)) }) .collect(); - let passive_data = - rkyv::Deserialize::deserialize(&module.passive_data, &mut SharedDeserializeMap::new()) - .map_err(|_| CompileError::Validate("could not deserialize passive data".into()))?; + let passive_data = rkyv::api::high::deserialize(&module.passive_data).map_err( + |e: rkyv::rancor::Error| { + CompileError::Validate(format!("could not deserialize passive data: {e:}")) + }, + )?; let data_segments = executable.data_initializers.iter(); let data_segments = data_segments.map(|s| DataInitializer::from(s).into()).collect(); let element_segments = unrkyv(&module.table_initializers); @@ -370,7 +373,7 @@ impl UniversalEngine { executable.custom_sections.iter().map(|(_, s)| s.into()), |idx: LocalFunctionIndex| { let func_idx = import_counts.function_index(idx); - let sig_idx = module.functions[&func_idx]; + let sig_idx = unrkyv(module.functions.index_by_native(&func_idx)); (sig_idx, signatures[sig_idx]) }, )?; @@ -378,24 +381,28 @@ impl UniversalEngine { module .imports .iter() - .map(|((module_name, field, idx), entity)| near_vm_vm::VMImport { + .map(|(ArchivedTuple3(module_name, field, idx), entity)| near_vm_vm::VMImport { module: String::from(module_name.as_str()), field: String::from(field.as_str()), - import_no: *idx, + import_no: idx.into(), ty: match entity { - ImportIndex::Function(i) => { - let sig_idx = module.functions[i]; + Archived::::Function(i) => { + let sig_idx = unrkyv(&module.functions[i]); VMImportType::Function { sig: signatures[sig_idx], static_trampoline: trampolines[sig_idx], } } - ImportIndex::Table(i) => VMImportType::Table(unrkyv(&module.tables[i])), - ImportIndex::Memory(i) => { + Archived::::Table(i) => { + VMImportType::Table(unrkyv(&module.tables[i])) + } + Archived::::Memory(i) => { let ty = unrkyv(&module.memories[i]); VMImportType::Memory(ty, unrkyv(&info.memory_styles[i])) } - ImportIndex::Global(i) => VMImportType::Global(unrkyv(&module.globals[i])), + Archived::::Global(i) => { + VMImportType::Global(unrkyv(&module.globals[i])) + } }, }) .collect() @@ -406,9 +413,9 @@ impl UniversalEngine { crate::universal::link_module( &functions, |func_idx, jt_idx| { - let func_idx = rkyv::Archived::::new(func_idx.index()); - let jt_idx = rkyv::Archived::::new(jt_idx.index()); - executable.function_jt_offsets[&func_idx][&jt_idx] + let func_idx = Archived::::new(func_idx.index()); + let jt_idx = Archived::::new(jt_idx.index()); + executable.function_jt_offsets[&func_idx][&jt_idx].into() }, function_relocations.map(|(i, r)| (i, r.iter().map(unrkyv))), &custom_sections, diff --git a/runtime/near-vm/engine/src/universal/executable.rs b/runtime/near-vm/engine/src/universal/executable.rs index 23717594e2b..f24b7d26e86 100644 --- a/runtime/near-vm/engine/src/universal/executable.rs +++ b/runtime/near-vm/engine/src/universal/executable.rs @@ -3,18 +3,16 @@ use near_vm_compiler::{ CompileModuleInfo, CompiledFunctionFrameInfo, CustomSection, Dwarf, FunctionBody, JumpTableOffsets, Relocation, SectionIndex, TrampolinesSection, }; -use near_vm_types::entity::PrimaryMap; +use near_vm_types::entity::{EntityRef as _, PrimaryMap}; use near_vm_types::{ ExportIndex, FunctionIndex, ImportIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex, }; -use rkyv::de::deserializers::SharedDeserializeMap; -use rkyv::ser::serializers::{ - AllocScratchError, AllocSerializer, CompositeSerializerError, SharedSerializeMapError, -}; +use rkyv::tuple::ArchivedTuple3; +use rkyv::Archived; const MAGIC_HEADER: [u8; 32] = { - let value = *b"\0nearvm-universal\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; + let value = *b"\0nearvm-universal\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; let _length_must_be_multiple_of_16: bool = [true][value.len() % 16]; value }; @@ -64,20 +62,20 @@ impl<'a> UniversalExecutableRef<'a> { let mut position_value = [0u8; 8]; position_value.copy_from_slice(position); let (_, data) = archive.split_at(MAGIC_HEADER.len()); + Ok(UniversalExecutableRef { - archive: rkyv::archived_value::( - data, - u64::from_le_bytes(position_value) as usize, - ), + archive: rkyv::api::high::access_pos(data, u64::from_le_bytes(position_value) as usize) + .map_err(|e: rkyv::rancor::Error| { + DeserializeError::CorruptedBinary(e.to_string()) + })?, }) } // TODO(0-copy): this should never fail. /// Convert this reference to an owned `UniversalExecutable` value. pub fn to_owned(self) -> Result { - let mut deserializer = SharedDeserializeMap::new(); - rkyv::Deserialize::deserialize(self.archive, &mut deserializer) - .map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e))) + rkyv::api::high::deserialize(self.archive) + .map_err(|e: rkyv::rancor::Error| DeserializeError::CorruptedBinary(format!("{:?}", e))) } } @@ -108,14 +106,7 @@ pub struct UniversalExecutable { #[derive(thiserror::Error, Debug)] pub enum ExecutableSerializeError { #[error("could not serialize the executable data")] - Executable( - #[source] - CompositeSerializerError< - std::convert::Infallible, - AllocScratchError, - SharedSerializeMapError, - >, - ), + Executable(#[source] rkyv::rancor::Error), } impl UniversalExecutable { @@ -130,16 +121,15 @@ impl UniversalExecutable { // RKYV POSITION // // It is expected that any framing for message length is handled by the caller. - let mut serializer = AllocSerializer::<1024>::default(); - let pos = rkyv::ser::Serializer::serialize_value(&mut serializer, self) - .map_err(ExecutableSerializeError::Executable)? as u64; + let mut output = Vec::new(); + output.extend_from_slice(&MAGIC_HEADER); + rkyv::api::high::to_bytes_in(self, &mut output) + .map_err(ExecutableSerializeError::Executable)?; + let pos = + rkyv::api::root_position::>(output.len() - MAGIC_HEADER.len()) as u64; let pos_bytes = pos.to_le_bytes(); - let data = serializer.into_serializer().into_inner(); - let mut out = Vec::with_capacity(MAGIC_HEADER.len() + pos_bytes.len() + data.len()); - out.extend(&MAGIC_HEADER); - out.extend(data.as_slice()); - out.extend(&pos_bytes); - Ok(out) + output.extend_from_slice(&pos_bytes); + Ok(output) } } @@ -148,20 +138,21 @@ impl<'a> UniversalExecutableRef<'a> { /// /// Test-only API pub fn function_name(&self, index: FunctionIndex) -> Option<&str> { + let aidx = Archived::::new(index.index()); let module = &self.compile_info.module; // First, lets see if there's a name by which this function is exported. for (name, idx) in module.exports.iter() { match idx { - &ExportIndex::Function(fi) if fi == index => return Some(&*name), + Archived::::Function(fi) if fi == &aidx => return Some(&*name), _ => continue, } } - if let Some(r) = module.function_names.get(&index) { - return Some(&**r); + if let Some(r) = module.function_names.get_key_value(&aidx) { + return Some(r.1.as_str()); } - for ((_, field, _), idx) in module.imports.iter() { + for (ArchivedTuple3(_, field, _), idx) in module.imports.iter() { match idx { - &ImportIndex::Function(fi) if fi == index => return Some(&*field), + Archived::::Function(fi) if fi == &aidx => return Some(&*field), _ => continue, } } @@ -172,10 +163,10 @@ impl<'a> UniversalExecutableRef<'a> { pub(crate) fn unrkyv(archive: &T::Archived) -> T where T: rkyv::Archive, - T::Archived: rkyv::Deserialize, + T::Archived: rkyv::Deserialize>, { - Result::<_, std::convert::Infallible>::unwrap(rkyv::Deserialize::deserialize( + rkyv::rancor::ResultExt::<_, rkyv::rancor::Panic>::always_ok(rkyv::api::deserialize_using( archive, - &mut rkyv::Infallible, + &mut (), )) } diff --git a/runtime/near-vm/types/Cargo.toml b/runtime/near-vm/types/Cargo.toml index 9ce7cf317b2..e6782892872 100644 --- a/runtime/near-vm/types/Cargo.toml +++ b/runtime/near-vm/types/Cargo.toml @@ -18,7 +18,7 @@ workspace = true thiserror.workspace = true indexmap.workspace = true num-traits.workspace = true -rkyv.workspace = true +rkyv = { workspace = true, features = ["indexmap-2"] } [dev-dependencies] bolero.workspace = true diff --git a/runtime/near-vm/types/src/archives.rs b/runtime/near-vm/types/src/archives.rs deleted file mode 100644 index 59257a37587..00000000000 --- a/runtime/near-vm/types/src/archives.rs +++ /dev/null @@ -1,39 +0,0 @@ -use indexmap::IndexMap; -use rkyv::Archive; -use std::hash::Hash; - -#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] -/// See [`IndexMap`] -pub struct ArchivableIndexMap { - entries: Vec<(K, V)>, -} - -impl ArchivedArchivableIndexMap { - pub fn iter(&self) -> core::slice::Iter<'_, (K::Archived, V::Archived)> { - self.entries.iter() - } -} - -impl From> - for ArchivableIndexMap -{ - fn from(it: IndexMap) -> Self { - let mut r = Self { entries: Vec::new() }; - for (k, v) in it.into_iter() { - r.entries.push((k, v)); - } - r - } -} - -impl Into> - for ArchivableIndexMap -{ - fn into(self) -> IndexMap { - let mut r = IndexMap::new(); - for (k, v) in self.entries.into_iter() { - r.insert(k, v); - } - r - } -} diff --git a/runtime/near-vm/types/src/entity/mod.rs b/runtime/near-vm/types/src/entity/mod.rs index 73226af7a70..753e2825a38 100644 --- a/runtime/near-vm/types/src/entity/mod.rs +++ b/runtime/near-vm/types/src/entity/mod.rs @@ -20,17 +20,17 @@ macro_rules! entity_impl { impl $crate::entity::EntityRef for $entity { fn new(index: usize) -> Self { debug_assert!(index < ($crate::lib::std::u32::MAX as usize)); - $entity(index as u32) + $entity(From::from(index as u32)) } fn index(self) -> usize { - self.0 as usize + u32::from(self.0) as usize } } impl $crate::entity::packed_option::ReservedValue for $entity { fn reserved_value() -> $entity { - $entity($crate::lib::std::u32::MAX) + $entity(From::from($crate::lib::std::u32::MAX)) } fn is_reserved_value(&self) -> bool { @@ -42,12 +42,12 @@ macro_rules! entity_impl { /// Create a new instance from a `u32`. pub fn from_u32(x: u32) -> Self { debug_assert!(x < $crate::lib::std::u32::MAX); - $entity(x) + $entity(From::from(x)) } /// Return the underlying index value as a `u32`. pub fn as_u32(self) -> u32 { - self.0 + self.0.into() } } }; diff --git a/runtime/near-vm/types/src/entity/primary_map.rs b/runtime/near-vm/types/src/entity/primary_map.rs index 26fc04ac5d1..ef4cc075ea4 100644 --- a/runtime/near-vm/types/src/entity/primary_map.rs +++ b/runtime/near-vm/types/src/entity/primary_map.rs @@ -245,6 +245,14 @@ where pub fn iter(&self) -> Iter> { Iter::new(self.elems.iter()) } + + /// Similar to `Index::index` but keys by the native type rather than archive of it. + pub fn index_by_native(&self, k: &K) -> &::Archived + where + K: EntityRef + Archive, + { + &self.elems[k.index()] + } } /// Immutable indexing into an `PrimaryMap`. diff --git a/runtime/near-vm/types/src/indexes.rs b/runtime/near-vm/types/src/indexes.rs index 09412dc8065..9b81f635e3e 100644 --- a/runtime/near-vm/types/src/indexes.rs +++ b/runtime/near-vm/types/src/indexes.rs @@ -16,10 +16,11 @@ use core::u32; rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct LocalFunctionIndex(u32); entity_impl!(LocalFunctionIndex); +entity_impl!(ArchivedLocalFunctionIndex); /// Index type of a table defined locally inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] @@ -45,10 +46,11 @@ entity_impl!(LocalMemoryIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct LocalGlobalIndex(u32); entity_impl!(LocalGlobalIndex); +entity_impl!(ArchivedLocalGlobalIndex); /// Index type of a function (imported or local) inside the WebAssembly module. #[derive( @@ -64,10 +66,11 @@ entity_impl!(LocalGlobalIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash))] #[repr(transparent)] pub struct FunctionIndex(u32); entity_impl!(FunctionIndex); +entity_impl!(ArchivedFunctionIndex); /// Index type of a table (imported or local) inside the WebAssembly module. #[derive( @@ -83,10 +86,11 @@ entity_impl!(FunctionIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct TableIndex(u32); entity_impl!(TableIndex); +entity_impl!(ArchivedTableIndex); /// Index type of a global variable (imported or local) inside the WebAssembly module. #[derive( @@ -102,10 +106,11 @@ entity_impl!(TableIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct GlobalIndex(u32); entity_impl!(GlobalIndex); +entity_impl!(ArchivedGlobalIndex); /// Index type of a linear memory (imported or local) inside the WebAssembly module. #[derive( @@ -121,10 +126,11 @@ entity_impl!(GlobalIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct MemoryIndex(u32); entity_impl!(MemoryIndex); +entity_impl!(ArchivedMemoryIndex); /// Index type of a signature (imported or local) inside the WebAssembly module. #[derive( @@ -140,10 +146,11 @@ entity_impl!(MemoryIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] +#[rkyv(derive(Copy, Clone, PartialEq, Eq))] #[repr(transparent)] pub struct SignatureIndex(u32); entity_impl!(SignatureIndex); +entity_impl!(ArchivedSignatureIndex); /// Index type of a passive data segment inside the WebAssembly module. #[derive( @@ -159,8 +166,8 @@ entity_impl!(SignatureIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(transparent)] +#[rkyv(derive(PartialOrd, Ord, PartialEq, Eq))] pub struct DataIndex(u32); entity_impl!(DataIndex); @@ -178,8 +185,8 @@ entity_impl!(DataIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(transparent)] +#[rkyv(derive(PartialOrd, Ord, PartialEq, Eq))] pub struct ElemIndex(u32); entity_impl!(ElemIndex); @@ -197,7 +204,6 @@ entity_impl!(ElemIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(transparent)] pub struct CustomSectionIndex(u32); entity_impl!(CustomSectionIndex); @@ -215,7 +221,6 @@ entity_impl!(CustomSectionIndex); rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(u8)] pub enum ExportIndex { /// Function export. @@ -241,7 +246,6 @@ pub enum ExportIndex { rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(u8)] pub enum ImportIndex { /// Function import. diff --git a/runtime/near-vm/types/src/initializers.rs b/runtime/near-vm/types/src/initializers.rs index 28987189144..0afec1b17a3 100644 --- a/runtime/near-vm/types/src/initializers.rs +++ b/runtime/near-vm/types/src/initializers.rs @@ -65,8 +65,9 @@ impl<'a> From<&'a OwnedDataInitializer> for DataInitializer<'a> { impl<'a> From<&'a ArchivedOwnedDataInitializer> for DataInitializer<'a> { fn from(init: &'a ArchivedOwnedDataInitializer) -> Self { DataInitializer { - location: rkyv::Deserialize::deserialize(&init.location, &mut rkyv::Infallible) - .expect("deserialization cannot fail"), + location: rkyv::rancor::ResultExt::<_, rkyv::rancor::Panic>::always_ok( + rkyv::api::deserialize_using(&init.location, &mut ()), + ), data: &*init.data, } } diff --git a/runtime/near-vm/types/src/lib.rs b/runtime/near-vm/types/src/lib.rs index 4dbf7fb5129..0536751ce0e 100644 --- a/runtime/near-vm/types/src/lib.rs +++ b/runtime/near-vm/types/src/lib.rs @@ -30,7 +30,6 @@ pub mod lib { } } -mod archives; mod extern_ref; mod features; mod indexes; @@ -67,7 +66,5 @@ pub use types::{ Import, InstanceConfig, MemoryType, Mutability, TableType, Type, V128, }; -pub use archives::ArchivableIndexMap; - /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/runtime/near-vm/types/src/module.rs b/runtime/near-vm/types/src/module.rs index 14bfc0de207..e29de0c375e 100644 --- a/runtime/near-vm/types/src/module.rs +++ b/runtime/near-vm/types/src/module.rs @@ -5,7 +5,6 @@ //! `wasmer::Module`. use crate::entity::{EntityRef, PrimaryMap}; -use crate::ArchivableIndexMap; use crate::{ CustomSectionIndex, DataIndex, ElemIndex, ExportIndex, FunctionIndex, FunctionType, GlobalIndex, GlobalInit, GlobalType, ImportIndex, LocalFunctionIndex, LocalGlobalIndex, @@ -13,12 +12,7 @@ use crate::{ SignatureIndex, TableIndex, TableType, }; use indexmap::IndexMap; -use rkyv::{ - de::SharedDeserializeRegistry, ser::ScratchSpace, ser::Serializer, - ser::SharedSerializeRegistry, Archive, Archived, Fallible, -}; use std::collections::BTreeMap; -use std::collections::HashMap; use std::fmt; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; @@ -45,7 +39,6 @@ impl Default for ModuleId { #[derive( Debug, Copy, Clone, Default, PartialEq, Eq, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] pub struct ImportCounts { /// Number of imported functions in the module. pub functions: u32, @@ -116,16 +109,13 @@ impl ImportCounts { /// A translated WebAssembly module, excluding the function bodies and /// memory initializers. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] pub struct ModuleInfo { /// A unique identifier (within this process) for this module. /// /// We skip serialization/deserialization of this field, as it /// should be computed by the process. - /// - /// It's not skipped in rkyv, but that is okay, because even though it's skipped in - /// bincode/serde it's still deserialized back as a garbage number, and later override from - /// computed by the process + #[rkyv(with = rkyv::with::Skip)] pub id: ModuleId, /// The name of this wasm module, often found in the wasm file. @@ -157,7 +147,7 @@ pub struct ModuleInfo { pub global_initializers: PrimaryMap, /// WebAssembly function names. - pub function_names: HashMap, + pub function_names: BTreeMap, /// WebAssembly function signatures. pub signatures: PrimaryMap, @@ -184,110 +174,6 @@ pub struct ModuleInfo { pub import_counts: ImportCounts, } -/// Mirror version of ModuleInfo that can derive rkyv traits -#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] -pub struct ArchivableModuleInfo { - pub name: Option, - pub imports: ArchivableIndexMap<(String, String, u32), ImportIndex>, - pub exports: ArchivableIndexMap, - pub start_function: Option, - pub table_initializers: Vec, - pub passive_elements: BTreeMap>, - pub passive_data: BTreeMap>, - pub global_initializers: PrimaryMap, - pub function_names: BTreeMap, - pub signatures: PrimaryMap, - pub functions: PrimaryMap, - pub tables: PrimaryMap, - pub memories: PrimaryMap, - pub globals: PrimaryMap, - pub custom_sections: ArchivableIndexMap, - pub custom_sections_data: PrimaryMap>, - pub import_counts: ImportCounts, -} - -impl From for ArchivableModuleInfo { - fn from(it: ModuleInfo) -> Self { - Self { - name: it.name, - imports: ArchivableIndexMap::from(it.imports), - exports: ArchivableIndexMap::from(it.exports), - start_function: it.start_function, - table_initializers: it.table_initializers, - passive_elements: it.passive_elements.into_iter().collect(), - passive_data: it.passive_data.into_iter().collect(), - global_initializers: it.global_initializers, - function_names: it.function_names.into_iter().collect(), - signatures: it.signatures, - functions: it.functions, - tables: it.tables, - memories: it.memories, - globals: it.globals, - custom_sections: ArchivableIndexMap::from(it.custom_sections), - custom_sections_data: it.custom_sections_data, - import_counts: it.import_counts, - } - } -} - -impl From for ModuleInfo { - fn from(it: ArchivableModuleInfo) -> Self { - Self { - id: Default::default(), - name: it.name, - imports: it.imports.into(), - exports: it.exports.into(), - start_function: it.start_function, - table_initializers: it.table_initializers, - passive_elements: it.passive_elements.into_iter().collect(), - passive_data: it.passive_data.into_iter().collect(), - global_initializers: it.global_initializers, - function_names: it.function_names.into_iter().collect(), - signatures: it.signatures, - functions: it.functions, - tables: it.tables, - memories: it.memories, - globals: it.globals, - custom_sections: it.custom_sections.into(), - custom_sections_data: it.custom_sections_data, - import_counts: it.import_counts, - } - } -} - -impl From<&ModuleInfo> for ArchivableModuleInfo { - fn from(it: &ModuleInfo) -> Self { - Self::from(it.clone()) - } -} - -impl Archive for ModuleInfo { - type Archived = ::Archived; - type Resolver = ::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - ArchivableModuleInfo::from(self).resolve(pos, resolver, out) - } -} - -impl rkyv::Serialize - for ModuleInfo -{ - fn serialize(&self, serializer: &mut S) -> Result { - ArchivableModuleInfo::from(self).serialize(serializer) - } -} - -impl rkyv::Deserialize - for Archived -{ - fn deserialize(&self, deserializer: &mut D) -> Result { - let r: ArchivableModuleInfo = - rkyv::Deserialize::::deserialize(self, deserializer)?; - Ok(ModuleInfo::from(r)) - } -} - // For test serialization correctness, everything except module id should be same impl PartialEq for ModuleInfo { fn eq(&self, other: &Self) -> bool { diff --git a/runtime/near-vm/types/src/types.rs b/runtime/near-vm/types/src/types.rs index ab6210de112..2e78d713e09 100644 --- a/runtime/near-vm/types/src/types.rs +++ b/runtime/near-vm/types/src/types.rs @@ -15,9 +15,21 @@ use std::sync::Arc; /// A list of all possible value types in WebAssembly. #[derive( - Copy, Debug, Clone, Eq, PartialEq, Hash, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, + Copy, + Debug, + Clone, + Eq, + PartialEq, + Hash, + rkyv::Serialize, + rkyv::Deserialize, + rkyv::Archive, + rkyv::Portable, + rkyv::bytecheck::CheckBytes, )] -#[archive(as = "Self")] +#[bytecheck(crate = rkyv::bytecheck)] +#[rkyv(as = Type)] +#[repr(u8)] pub enum Type { /// Signed 32 bit integer. I32, @@ -57,7 +69,6 @@ impl fmt::Display for Type { #[derive( Copy, Clone, Debug, Eq, PartialEq, Hash, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] /// The WebAssembly V128 type pub struct V128(pub(crate) [u8; 16]); @@ -267,7 +278,6 @@ impl<'a> From<&'a ArchivedFunctionType> for FunctionTypeRef<'a> { #[derive( Debug, Clone, Copy, PartialEq, Eq, Hash, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] pub enum Mutability { /// The global is constant and its value does not change Const, @@ -289,7 +299,6 @@ impl Mutability { #[derive( Debug, Clone, Copy, PartialEq, Eq, Hash, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] pub struct GlobalType { /// The type of the value stored in the global. pub ty: Type, @@ -332,7 +341,6 @@ impl fmt::Display for GlobalType { /// Globals are initialized via the `const` operators or by referring to another import. #[derive(Debug, Clone, Copy, PartialEq, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)] -#[archive(as = "Self")] pub enum GlobalInit { /// An `i32.const`. I32Const(i32), diff --git a/runtime/near-vm/types/src/units.rs b/runtime/near-vm/types/src/units.rs index 09d5741da67..d160e6443ed 100644 --- a/runtime/near-vm/types/src/units.rs +++ b/runtime/near-vm/types/src/units.rs @@ -29,7 +29,6 @@ pub const WASM_MIN_PAGES: u32 = 0x100; rkyv::Deserialize, rkyv::Archive, )] -#[archive(as = "Self")] #[repr(transparent)] pub struct Pages(pub u32); diff --git a/runtime/near-vm/vm/src/vmoffsets.rs b/runtime/near-vm/vm/src/vmoffsets.rs index cd8ae5be650..14377158337 100644 --- a/runtime/near-vm/vm/src/vmoffsets.rs +++ b/runtime/near-vm/vm/src/vmoffsets.rs @@ -134,10 +134,10 @@ impl VMOffsets { /// Add imports and locals from the provided ModuleInfo. pub fn with_archived_module_info(mut self, module: &rkyv::Archived) -> Self { - self.num_imported_functions = module.import_counts.functions; - self.num_imported_tables = module.import_counts.tables; - self.num_imported_memories = module.import_counts.memories; - self.num_imported_globals = module.import_counts.globals; + self.num_imported_functions = module.import_counts.functions.into(); + self.num_imported_tables = module.import_counts.tables.into(); + self.num_imported_memories = module.import_counts.memories.into(); + self.num_imported_globals = module.import_counts.globals.into(); self.num_signature_ids = cast_to_u32(module.signatures.len()); // FIXME = these should most likely be subtracting the corresponding imports!!? self.num_local_tables = cast_to_u32(module.tables.len());