diff --git a/Cargo.lock b/Cargo.lock index 0633fb2ca..52a43ab1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,15 +59,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "bitmaps" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" -dependencies = [ - "typenum", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -438,20 +429,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "im-rc" -version = "15.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe" -dependencies = [ - "bitmaps", - "rand_core 0.6.4", - "rand_xoshiro", - "sized-chunks", - "typenum", - "version_check", -] - [[package]] name = "indexmap" version = "1.9.2" @@ -744,15 +721,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_xoshiro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" -dependencies = [ - "rand_core 0.6.4", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -860,16 +828,6 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -[[package]] -name = "sized-chunks" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" -dependencies = [ - "bitmaps", - "typenum", -] - [[package]] name = "soroban-auth" version = "0.3.2" @@ -883,7 +841,7 @@ dependencies = [ [[package]] name = "soroban-env-common" version = "0.0.11" -source = "git+https://github.com/stellar/rs-soroban-env?rev=c551daf#c551daf2b2f7fb4eb2d6e12ede320670133b54fe" +source = "git+https://github.com/stellar/rs-soroban-env?rev=995386a#995386a39bce05133c26361aa18fb98afbcb2fdd" dependencies = [ "crate-git-revision", "serde", @@ -896,7 +854,7 @@ dependencies = [ [[package]] name = "soroban-env-guest" version = "0.0.11" -source = "git+https://github.com/stellar/rs-soroban-env?rev=c551daf#c551daf2b2f7fb4eb2d6e12ede320670133b54fe" +source = "git+https://github.com/stellar/rs-soroban-env?rev=995386a#995386a39bce05133c26361aa18fb98afbcb2fdd" dependencies = [ "soroban-env-common", "static_assertions", @@ -905,14 +863,13 @@ dependencies = [ [[package]] name = "soroban-env-host" version = "0.0.11" -source = "git+https://github.com/stellar/rs-soroban-env?rev=c551daf#c551daf2b2f7fb4eb2d6e12ede320670133b54fe" +source = "git+https://github.com/stellar/rs-soroban-env?rev=995386a#995386a39bce05133c26361aa18fb98afbcb2fdd" dependencies = [ "backtrace", "curve25519-dalek", "dyn-fmt", "ed25519-dalek", "hex", - "im-rc", "log", "num-derive", "num-integer", @@ -928,7 +885,7 @@ dependencies = [ [[package]] name = "soroban-env-macros" version = "0.0.11" -source = "git+https://github.com/stellar/rs-soroban-env?rev=c551daf#c551daf2b2f7fb4eb2d6e12ede320670133b54fe" +source = "git+https://github.com/stellar/rs-soroban-env?rev=995386a#995386a39bce05133c26361aa18fb98afbcb2fdd" dependencies = [ "itertools", "proc-macro2", @@ -950,7 +907,7 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" version = "0.0.11" -source = "git+https://github.com/stellar/rs-soroban-env?rev=c551daf#c551daf2b2f7fb4eb2d6e12ede320670133b54fe" +source = "git+https://github.com/stellar/rs-soroban-env?rev=995386a#995386a39bce05133c26361aa18fb98afbcb2fdd" dependencies = [ "itertools", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index b41dbbd04..00cf3afd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,17 +35,17 @@ soroban-token-spec = { version = "0.3.2", path = "soroban-token-spec" } [workspace.dependencies.soroban-env-common] version = "0.0.11" git = "https://github.com/stellar/rs-soroban-env" -rev = "c551daf" +rev = "995386a" [workspace.dependencies.soroban-env-guest] version = "0.0.11" git = "https://github.com/stellar/rs-soroban-env" -rev = "c551daf" +rev = "995386a" [workspace.dependencies.soroban-env-host] version = "0.0.11" git = "https://github.com/stellar/rs-soroban-env" -rev = "c551daf" +rev = "995386a" [workspace.dependencies.stellar-strkey] version = "0.0.6" diff --git a/soroban-ledger-snapshot/src/lib.rs b/soroban-ledger-snapshot/src/lib.rs index 76df473cf..5174a4084 100644 --- a/soroban-ledger-snapshot/src/lib.rs +++ b/soroban-ledger-snapshot/src/lib.rs @@ -3,6 +3,7 @@ use std::{ fs::File, io::{Read, Write}, path::Path, + rc::Rc, }; use soroban_env_host::{ @@ -79,12 +80,12 @@ impl LedgerSnapshot { // entry. pub fn update_entries<'a>( &mut self, - entries: impl IntoIterator, &'a Option>)>, + entries: impl IntoIterator, Option>)>, ) { for (k, e) in entries { - let i = self.ledger_entries.iter().position(|(ik, _)| ik == k); + let i = self.ledger_entries.iter().position(|(ik, _)| **ik == **k); if let Some(e) = e { - let new = (k.clone(), e.clone()); + let new = (Box::new((**k).clone()), Box::new((**e).clone())); if let Some(i) = i { self.ledger_entries[i] = new; } else { diff --git a/soroban-sdk/src/accounts.rs b/soroban-sdk/src/accounts.rs index ca0c1c308..4d3d611de 100644 --- a/soroban-sdk/src/accounts.rs +++ b/soroban-sdk/src/accounts.rs @@ -5,8 +5,7 @@ use core::{cmp::Ordering, fmt::Debug}; use crate::{ env::internal::xdr, - env::internal::{Env as _, RawVal, RawValConvertible}, - env::EnvObj, + env::internal::{Env as _, EnvBase as _, RawVal, RawValConvertible}, BytesN, ConversionError, Env, IntoVal, Object, TryFromVal, TryIntoVal, }; @@ -76,7 +75,10 @@ impl Accounts { /// /// In tests account identifiers can be generated using [`Accounts`]. #[derive(Clone)] -pub struct AccountId(EnvObj); +pub struct AccountId { + env: Env, + obj: Object, +} impl Debug for AccountId { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -111,16 +113,21 @@ impl PartialOrd for AccountId { impl Ord for AccountId { fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.cmp(&other.0) + self.env.check_same_env(&other.env); + let v = self.env.obj_cmp(self.obj.to_raw(), other.obj.to_raw()); + v.cmp(&0) } } impl TryFromVal for AccountId { type Error = ConversionError; - fn try_from_val(env: &Env, val: Object) -> Result { - if val.is_obj_type(xdr::ScObjectType::AccountId) { - Ok(AccountId(val.in_env(env))) + fn try_from_val(env: &Env, obj: Object) -> Result { + if obj.is_obj_type(xdr::ScObjectType::AccountId) { + Ok(AccountId { + env: env.clone(), + obj, + }) } else { Err(ConversionError {}) } @@ -182,7 +189,7 @@ use super::xdr::ScVal; impl TryFrom<&AccountId> for ScVal { type Error = ConversionError; fn try_from(v: &AccountId) -> Result { - ScVal::try_from_val(&v.0.env, v.0.val.to_raw()) + ScVal::try_from_val(&v.env, v.obj.to_raw()) } } @@ -248,28 +255,28 @@ impl TryIntoVal for super::xdr::AccountId { } impl AccountId { - pub(crate) unsafe fn unchecked_new(obj: EnvObj) -> Self { - Self(obj) + pub(crate) unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + Self { env, obj } } pub fn env(&self) -> &Env { - self.0.env() + &self.env } pub fn as_raw(&self) -> &RawVal { - self.0.as_raw() + self.obj.as_raw() } pub fn as_object(&self) -> &Object { - self.0.as_object() + &self.obj } pub fn to_raw(&self) -> RawVal { - self.0.to_raw() + self.obj.to_raw() } pub fn to_object(&self) -> Object { - self.0.to_object() + self.obj } } @@ -421,7 +428,11 @@ impl testutils::Accounts for Accounts { last_modified_ledger_seq: 0, ext: xdr::LedgerEntryExt::V0, }; - storage.put(&k, &v) + storage.put( + &k, + &v, + soroban_env_host::budget::AsBudget::as_budget(env.host()), + ) }) .unwrap(); } @@ -473,7 +484,10 @@ impl testutils::Accounts for Accounts { env.host() .with_mut_storage(|storage| { let k = xdr::LedgerKey::Account(xdr::LedgerKeyAccount { account_id: id }); - storage.del(&k) + storage.del( + &k, + soroban_env_host::budget::AsBudget::as_budget(env.host()), + ) }) .unwrap(); } @@ -507,7 +521,10 @@ impl Accounts { account_id: id.clone(), }); let mut v = storage - .get(&k) + .get( + &k, + soroban_env_host::budget::AsBudget::as_budget(env.host()), + ) .ok() .and_then(|v| { if let xdr::LedgerEntryData::Account(_) = v.data { @@ -526,7 +543,11 @@ impl Accounts { } else { panic!("ledger entry is not an account"); } - storage.put(&k, &v) + storage.put( + &k, + &v, + soroban_env_host::budget::AsBudget::as_budget(env.host()), + ) }) .unwrap(); } diff --git a/soroban-sdk/src/bytes.rs b/soroban-sdk/src/bytes.rs index a5ed8cba4..446dd8bd2 100644 --- a/soroban-sdk/src/bytes.rs +++ b/soroban-sdk/src/bytes.rs @@ -8,9 +8,9 @@ use core::{ use super::{ env::internal::{Env as _, EnvBase as _, RawValConvertible}, - env::{EnvObj, IntoVal}, + env::IntoVal, xdr::ScObjectType, - ConversionError, Env, EnvVal, Object, RawVal, TryFromVal, TryIntoVal, + ConversionError, Env, Object, RawVal, TryFromVal, TryIntoVal, }; use crate::unwrap::UnwrapOptimized; @@ -121,8 +121,10 @@ macro_rules! bytesn { /// assert_eq!(slice, [1u8; 32]); /// ``` #[derive(Clone)] -#[repr(transparent)] -pub struct Bytes(EnvObj); +pub struct Bytes { + env: Env, + obj: Object, +} impl Debug for Bytes { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -155,7 +157,9 @@ impl PartialOrd for Bytes { impl Ord for Bytes { fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.cmp(&other.0) + self.env.check_same_env(&other.env); + let v = self.env.obj_cmp(self.obj.to_raw(), other.obj.to_raw()); + v.cmp(&0) } } @@ -176,7 +180,7 @@ impl TryFromVal for Bytes { fn try_from_val(env: &Env, val: Object) -> Result { if val.is_obj_type(ScObjectType::Bytes) { - Ok(unsafe { Bytes::unchecked_new(val.in_env(env)) }) + Ok(unsafe { Bytes::unchecked_new(env.clone(), val) }) } else { Err(ConversionError {}) } @@ -222,35 +226,21 @@ impl IntoVal for &Bytes { impl From for RawVal { #[inline(always)] fn from(v: Bytes) -> Self { - v.0.into() - } -} - -impl From for EnvVal { - #[inline(always)] - fn from(v: Bytes) -> Self { - v.0.into() - } -} - -impl From for EnvObj { - #[inline(always)] - fn from(v: Bytes) -> Self { - v.0 + v.obj.into() } } impl From for Object { #[inline(always)] fn from(v: Bytes) -> Self { - v.0.val + v.obj } } impl From<&Bytes> for Object { #[inline(always)] fn from(v: &Bytes) -> Self { - v.0.val + v.obj } } @@ -265,7 +255,7 @@ impl From<&Bytes> for Bytes { impl TryFrom<&Bytes> for ScVal { type Error = ConversionError; fn try_from(v: &Bytes) -> Result { - ScVal::try_from_val(&v.0.env, v.0.val.to_raw()) + ScVal::try_from_val(&v.env, v.obj.to_raw()) } } @@ -322,36 +312,36 @@ impl IntoVal for &[u8; N] { impl Bytes { #[inline(always)] - pub(crate) unsafe fn unchecked_new(obj: EnvObj) -> Self { - Self(obj) + pub(crate) unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + Self { env, obj } } #[inline(always)] pub fn env(&self) -> &Env { - self.0.env() + &self.env } pub fn as_raw(&self) -> &RawVal { - self.0.as_raw() + self.obj.as_raw() } pub fn to_raw(&self) -> RawVal { - self.0.to_raw() + self.obj.to_raw() } pub fn as_object(&self) -> &Object { - self.0.as_object() + &self.obj } pub fn to_object(&self) -> Object { - self.0.to_object() + self.obj } /// Create an empty Bytes. #[inline(always)] pub fn new(env: &Env) -> Bytes { - let obj = env.bytes_new().in_env(env); - unsafe { Self::unchecked_new(obj) } + let obj = env.bytes_new(); + unsafe { Self::unchecked_new(env.clone(), obj) } } /// Create a Bytes from the given `[u8]`. @@ -362,20 +352,16 @@ impl Bytes { #[inline(always)] pub fn from_slice(env: &Env, items: &[u8]) -> Bytes { - Bytes( - env.bytes_new_from_slice(items) - .unwrap_optimized() - .in_env(env), - ) + Bytes { + env: env.clone(), + obj: env.bytes_new_from_slice(items).unwrap_optimized(), + } } #[inline(always)] pub fn set(&mut self, i: u32, v: u8) { let v32: u32 = v.into(); - self.0 = self - .env() - .bytes_put(self.0.to_object(), i.into(), v32.into()) - .in_env(self.env()); + self.obj = self.env().bytes_put(self.obj, i.into(), v32.into()) } #[inline(always)] @@ -391,7 +377,7 @@ impl Bytes { pub fn get_unchecked(&self, i: u32) -> u8 { let res = self .env() - .bytes_get(self.0.to_object(), i.into()) + .bytes_get(self.obj, i.into()) .try_into() .unwrap_optimized(); let res32: u32 = unsafe { <_ as RawValConvertible>::unchecked_from_val(res) }; @@ -400,12 +386,12 @@ impl Bytes { #[inline(always)] pub fn is_empty(&self) -> bool { - self.env().bytes_len(self.0.to_object()).is_u32_zero() + self.env().bytes_len(self.obj).is_u32_zero() } #[inline(always)] pub fn len(&self) -> u32 { - let len = self.env().bytes_len(self.0.to_object()); + let len = self.env().bytes_len(self.obj); unsafe { <_ as RawValConvertible>::unchecked_from_val(len) } } @@ -420,7 +406,7 @@ impl Bytes { #[inline(always)] pub fn first_unchecked(&self) -> u8 { - let res = self.env().bytes_front(self.0.to_object()); + let res = self.env().bytes_front(self.obj); let res32: u32 = unsafe { <_ as RawValConvertible>::unchecked_from_val(res) }; res32 as u8 } @@ -436,7 +422,7 @@ impl Bytes { #[inline(always)] pub fn last_unchecked(&self) -> u8 { - let res = self.env().bytes_back(self.0.to_object()); + let res = self.env().bytes_back(self.obj); let res32: u32 = unsafe { <_ as RawValConvertible>::unchecked_from_val(res) }; res32 as u8 } @@ -453,33 +439,26 @@ impl Bytes { #[inline(always)] pub fn remove_unchecked(&mut self, i: u32) { - let env = self.env(); - let bin = env.bytes_del(self.0.to_object(), i.into()); - self.0 = bin.in_env(env); + self.obj = self.env().bytes_del(self.obj, i.into()) } #[inline(always)] pub fn push(&mut self, x: u8) { let x32: u32 = x.into(); - let env = self.env(); - let bin = env.bytes_push(self.0.to_object(), x32.into()); - self.0 = bin.in_env(env); + self.obj = self.env().bytes_push(self.obj, x32.into()) } #[inline(always)] pub fn pop(&mut self) -> Option { let last = self.last()?; - let env = self.env(); - let bin = env.bytes_pop(self.0.to_object()); - self.0 = bin.in_env(env); + self.obj = self.env().bytes_pop(self.obj); Some(last) } #[inline(always)] pub fn pop_unchecked(&mut self) -> u8 { let last = self.last_unchecked(); - let env = self.env(); - self.0 = env.bytes_pop(self.0.to_object()).in_env(env); + self.obj = self.env().bytes_pop(self.obj); last } @@ -491,10 +470,8 @@ impl Bytes { /// When `i` is greater than the length of [Bytes]. #[inline(always)] pub fn insert(&mut self, i: u32, b: u8) { - let env = self.env(); let b32: u32 = b.into(); - let bin = env.bytes_insert(self.0.to_object(), i.into(), b32.into()); - self.0 = bin.in_env(env); + self.obj = self.env().bytes_insert(self.obj, i.into(), b32.into()) } /// Insert the bytes in `bytes` into this [Bytes] starting at position @@ -538,9 +515,7 @@ impl Bytes { #[inline(always)] pub fn append(&mut self, other: &Bytes) { - let env = self.env(); - let bin = env.bytes_append(self.0.to_object(), other.0.to_object()); - self.0 = bin.in_env(env); + self.obj = self.env().bytes_append(self.obj, other.obj) } #[inline(always)] @@ -550,11 +525,10 @@ impl Bytes { #[inline(always)] pub fn extend_from_slice(&mut self, slice: &[u8]) { - let env = self.env(); - self.0 = env + self.obj = self + .env() .bytes_copy_from_slice(self.to_object(), self.len().into(), slice) .unwrap_optimized() - .in_env(env); } /// Copy the bytes from slice into [Bytes]. @@ -563,11 +537,10 @@ impl Bytes { /// if necessary. #[inline(always)] pub fn copy_from_slice(&mut self, i: u32, slice: &[u8]) { - let env = self.env(); - self.0 = env + self.obj = self + .env() .bytes_copy_from_slice(self.to_object(), i.into(), slice) .unwrap_optimized() - .in_env(env); } /// Copy the bytes in [Bytes] into the given slice. @@ -594,8 +567,8 @@ impl Bytes { Bound::Unbounded => self.len(), }; let env = self.env(); - let bin = env.bytes_slice(self.0.to_object(), start_bound.into(), end_bound.into()); - unsafe { Self::unchecked_new(bin.in_env(env)) } + let bin = env.bytes_slice(self.obj, start_bound.into(), end_bound.into()); + unsafe { Self::unchecked_new(env.clone(), bin) } } pub fn iter(&self) -> BinIter { @@ -628,7 +601,7 @@ impl Iterator for BinIter { if self.0.is_empty() { None } else { - let val = self.0.env().bytes_front(self.0 .0.to_object()); + let val = self.0.env().bytes_front(self.0.obj); self.0 = self.0.slice(1..); let val = unsafe { ::unchecked_from_val(val) } as u8; Some(val) @@ -647,7 +620,7 @@ impl DoubleEndedIterator for BinIter { if len == 0 { None } else { - let val = self.0.env().bytes_back(self.0 .0.to_object()); + let val = self.0.env().bytes_back(self.0.obj); self.0 = self.0.slice(..len - 1); let val = unsafe { ::unchecked_from_val(val) } as u8; Some(val) @@ -903,20 +876,6 @@ impl From> for RawVal { } } -impl From> for EnvVal { - #[inline(always)] - fn from(v: BytesN) -> Self { - v.0.into() - } -} - -impl From> for EnvObj { - #[inline(always)] - fn from(v: BytesN) -> Self { - v.0.into() - } -} - impl From> for Bytes { #[inline(always)] fn from(v: BytesN) -> Self { @@ -935,7 +894,7 @@ impl From<&BytesN> for Bytes { impl TryFrom<&BytesN> for ScVal { type Error = ConversionError; fn try_from(v: &BytesN) -> Result { - ScVal::try_from_val(&v.0 .0.env, v.0 .0.val.to_raw()) + ScVal::try_from_val(&v.0.env, v.0.obj.to_raw()) } } @@ -968,8 +927,8 @@ impl TryIntoVal> for ScVal { impl BytesN { #[inline(always)] - pub(crate) unsafe fn unchecked_new(obj: EnvObj) -> Self { - Self(Bytes::unchecked_new(obj)) + pub(crate) unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + Self(Bytes::unchecked_new(env, obj)) } pub fn env(&self) -> &Env { diff --git a/soroban-sdk/src/crypto.rs b/soroban-sdk/src/crypto.rs index e0adb455c..2b61d8e6d 100644 --- a/soroban-sdk/src/crypto.rs +++ b/soroban-sdk/src/crypto.rs @@ -18,8 +18,8 @@ impl Crypto { /// Returns the SHA-256 hash of the data. pub fn sha256(&self, data: &Bytes) -> BytesN<32> { let env = self.env(); - let bin_obj = internal::Env::compute_hash_sha256(env, data.into()); - unsafe { BytesN::unchecked_new(bin_obj.in_env(env)) } + let bin = internal::Env::compute_hash_sha256(env, data.into()); + unsafe { BytesN::unchecked_new(env.clone(), bin) } } /// Verifies an ed25519 signature. diff --git a/soroban-sdk/src/deploy.rs b/soroban-sdk/src/deploy.rs index e5b14fa2d..bb532fb0f 100644 --- a/soroban-sdk/src/deploy.rs +++ b/soroban-sdk/src/deploy.rs @@ -109,7 +109,7 @@ impl DeployerWithCurrentContract { wasm_hash.into_val(env).to_object(), self.salt.to_object(), ); - unsafe { BytesN::<32>::unchecked_new(id.in_env(env)) } + unsafe { BytesN::<32>::unchecked_new(env.clone(), id) } } /// Deploy a built-in token contract. @@ -121,7 +121,7 @@ impl DeployerWithCurrentContract { pub fn deploy_token(&self) -> BytesN<32> { let env = &self.env; let id = env.create_token_from_contract(self.salt.to_object()); - unsafe { BytesN::<32>::unchecked_new(id.in_env(env)) } + unsafe { BytesN::<32>::unchecked_new(env.clone(), id) } } } diff --git a/soroban-sdk/src/env.rs b/soroban-sdk/src/env.rs index 621be59c8..1baf29d4c 100644 --- a/soroban-sdk/src/env.rs +++ b/soroban-sdk/src/env.rs @@ -12,18 +12,18 @@ pub mod internal { pub type EnvImpl = Host; #[doc(hidden)] - impl TryConvert for super::Env + impl Convert for super::Env where - EnvImpl: TryConvert, + EnvImpl: Convert, { - type Error = >::Error; + type Error = >::Error; fn convert(&self, f: F) -> Result { self.env_impl.convert(f) } } } -// Testutils from the environmen are pub here, and then pub re-exported out of +// Testutils from the environment are pub here, and then pub re-exported out of // the SDK in the crate::testutils mod. #[cfg(any(test, feature = "testutils"))] pub mod testutils { @@ -35,6 +35,7 @@ pub mod testutils { pub use internal::meta; pub use internal::xdr; pub use internal::BitSet; +pub use internal::Compare; pub use internal::ConversionError; pub use internal::EnvBase; pub use internal::FromVal; @@ -49,9 +50,6 @@ pub use internal::TryFromVal; pub use internal::TryIntoVal; pub use internal::Val; -pub type EnvVal = internal::EnvVal; -pub type EnvObj = internal::EnvVal; - use crate::{ accounts::Accounts, address::Address, crypto::Crypto, deploy::Deployer, events::Events, ledger::Ledger, logging::Logger, storage::Storage, AccountId, Bytes, BytesN, Vec, @@ -103,10 +101,10 @@ impl Env { .expect("unrecognized invoker type"); match invoker_type { InvokerType::Account => Address::Account(unsafe { - AccountId::unchecked_new(internal::Env::get_invoking_account(self).in_env(self)) + AccountId::unchecked_new(self.clone(), internal::Env::get_invoking_account(self)) }), InvokerType::Contract => Address::Contract(unsafe { - BytesN::unchecked_new(internal::Env::get_invoking_contract(self).in_env(self)) + BytesN::unchecked_new(self.clone(), internal::Env::get_invoking_contract(self)) }), } } @@ -160,7 +158,7 @@ impl Env { /// Get the 32-byte hash identifier of the current executing contract. pub fn current_contract(&self) -> BytesN<32> { let id = internal::Env::get_current_contract(self); - unsafe { BytesN::<32>::unchecked_new(id.in_env(self)) } + unsafe { BytesN::<32>::unchecked_new(self.clone(), id) } } /// Get the 32-byte hash identifier of the current executing contract. @@ -205,7 +203,7 @@ impl Env { /// ``` pub fn call_stack(&self) -> Vec<(BytesN<32>, Symbol)> { let stack = internal::Env::get_current_call_stack(self); - unsafe { Vec::unchecked_new(stack.in_env(self)) } + unsafe { Vec::unchecked_new(self.clone(), stack) } } #[doc(hidden)] @@ -536,6 +534,7 @@ impl Env { val: xdr::ScVal::Object(Some(xdr::ScObject::ContractCode(source))), }), }, + &self.env_impl.budget_cloned(), ) }) .unwrap(); @@ -651,11 +650,12 @@ impl Env { let snapshot = self.snapshot.clone().unwrap_or_default(); let mut snapshot = (*snapshot).clone(); snapshot.set_ledger_info(self.ledger().get()); + let budget = soroban_env_host::budget::AsBudget::as_budget(&self.env_impl); let storage = self .env_impl .with_mut_storage(|s| Ok(s.map.clone())) .unwrap(); - snapshot.update_entries(storage.iter()); + snapshot.update_entries(storage.iter(budget).unwrap()); snapshot } @@ -670,7 +670,7 @@ impl Env { /// Get the budget that tracks the resources consumed for the environment. pub fn budget(&self) -> Budget { - self.env_impl.with_budget(|b| Budget::new(b.clone())) + self.env_impl.with_budget(|b| Budget::new(b)) } } diff --git a/soroban-sdk/src/ledger.rs b/soroban-sdk/src/ledger.rs index e174366d4..9fbcc8943 100644 --- a/soroban-sdk/src/ledger.rs +++ b/soroban-sdk/src/ledger.rs @@ -89,7 +89,7 @@ impl Ledger { pub fn network_passphrase(&self) -> Bytes { let env = self.env(); let bin_obj = internal::Env::get_ledger_network_passphrase(env); - unsafe { Bytes::unchecked_new(bin_obj.in_env(env)) } + unsafe { Bytes::unchecked_new(env.clone(), bin_obj) } } } diff --git a/soroban-sdk/src/lib.rs b/soroban-sdk/src/lib.rs index 52238d607..f63eb24b5 100644 --- a/soroban-sdk/src/lib.rs +++ b/soroban-sdk/src/lib.rs @@ -602,7 +602,6 @@ pub use env::TryIntoVal; pub use env::Symbol; mod envhidden { - pub use super::env::EnvVal; pub use super::env::Object; pub use super::env::Status; } diff --git a/soroban-sdk/src/map.rs b/soroban-sdk/src/map.rs index d3f72f219..4d3488ea0 100644 --- a/soroban-sdk/src/map.rs +++ b/soroban-sdk/src/map.rs @@ -3,10 +3,9 @@ use core::{cmp::Ordering, fmt::Debug, iter::FusedIterator, marker::PhantomData}; use crate::iter::{UncheckedEnumerable, UncheckedIter}; use super::{ - env::internal::{Env as _, RawValConvertible}, - env::EnvObj, + env::internal::{Env as _, EnvBase as _, RawValConvertible}, xdr::ScObjectType, - ConversionError, Env, EnvVal, IntoVal, Object, RawVal, Status, TryFromVal, TryIntoVal, Vec, + ConversionError, Env, IntoVal, Object, RawVal, Status, TryFromVal, TryIntoVal, Vec, }; #[cfg(not(target_family = "wasm"))] @@ -84,9 +83,13 @@ macro_rules! map { /// map![&env, (2, 20), (1, 10)], /// ) /// ``` -#[repr(transparent)] #[derive(Clone)] -pub struct Map(EnvObj, PhantomData, PhantomData); +pub struct Map { + env: Env, + obj: Object, + _k: PhantomData, + _v: PhantomData, +} impl Eq for Map where @@ -121,7 +124,9 @@ where V: IntoVal + TryFromVal, { fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.cmp(&other.0) + self.env.check_same_env(&other.env); + let v = self.env.obj_cmp(self.obj.to_raw(), other.obj.to_raw()); + v.cmp(&0) } } @@ -156,7 +161,12 @@ where #[inline(always)] fn try_from_val(env: &Env, obj: Object) -> Result { if obj.is_obj_type(ScObjectType::Map) { - Ok(Map(obj.in_env(env), PhantomData, PhantomData)) + Ok(Map { + env: env.clone(), + obj, + _k: PhantomData, + _v: PhantomData, + }) } else { Err(ConversionError {}) } @@ -226,29 +236,7 @@ where { #[inline(always)] fn from(m: Map) -> Self { - m.0.into() - } -} - -impl From> for EnvVal -where - K: IntoVal + TryFromVal, - V: IntoVal + TryFromVal, -{ - #[inline(always)] - fn from(m: Map) -> Self { - m.0.into() - } -} - -impl From> for EnvObj -where - K: IntoVal + TryFromVal, - V: IntoVal + TryFromVal, -{ - #[inline(always)] - fn from(m: Map) -> Self { - m.0 + m.obj.into() } } @@ -256,7 +244,7 @@ where impl TryFrom<&Map> for ScVal { type Error = ConversionError; fn try_from(v: &Map) -> Result { - ScVal::try_from_val(&v.0.env, v.0.val.to_raw()) + ScVal::try_from_val(&v.env, v.obj.to_raw()) } } @@ -301,39 +289,43 @@ where V: IntoVal + TryFromVal, { #[inline(always)] - pub(crate) unsafe fn unchecked_new(obj: EnvObj) -> Self { - Self(obj, PhantomData, PhantomData) + pub(crate) unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + Self { + env, + obj, + _k: PhantomData, + _v: PhantomData, + } } #[inline(always)] pub fn env(&self) -> &Env { - self.0.env() + &self.env } #[inline(always)] pub fn as_raw(&self) -> &RawVal { - self.0.as_raw() + self.obj.as_raw() } #[inline(always)] pub fn to_raw(&self) -> RawVal { - self.0.to_raw() + self.obj.to_raw() } #[inline(always)] pub(crate) fn as_object(&self) -> &Object { - self.0.as_object() + &self.obj } #[inline(always)] pub(crate) fn to_object(&self) -> Object { - self.0.to_object() + self.obj } #[inline(always)] pub fn new(env: &Env) -> Map { - let obj = env.map_new().in_env(env); - unsafe { Self::unchecked_new(obj) } + unsafe { Self::unchecked_new(env.clone(), env.map_new()) } } #[inline(always)] @@ -348,7 +340,7 @@ where #[inline(always)] pub fn contains_key(&self, k: K) -> bool { let env = self.env(); - let has = env.map_has(self.0.to_object(), k.into_val(env)); + let has = env.map_has(self.obj, k.into_val(env)); has.is_true() } @@ -356,9 +348,9 @@ where pub fn get(&self, k: K) -> Option> { let env = self.env(); let k = k.into_val(env); - let has = env.map_has(self.0.to_object(), k); + let has = env.map_has(self.obj, k); if has.is_true() { - let v = env.map_get(self.0.to_object(), k); + let v = env.map_get(self.obj, k); Some(V::try_from_val(env, v)) } else { None @@ -368,25 +360,23 @@ where #[inline(always)] pub fn get_unchecked(&self, k: K) -> Result { let env = self.env(); - let v = env.map_get(self.0.to_object(), k.into_val(env)); + let v = env.map_get(self.obj, k.into_val(env)); V::try_from_val(env, v) } #[inline(always)] pub fn set(&mut self, k: K, v: V) { let env = self.env(); - let map = env.map_put(self.0.to_object(), k.into_val(env), v.into_val(env)); - self.0 = map.in_env(env); + self.obj = env.map_put(self.obj, k.into_val(env), v.into_val(env)); } #[inline(always)] pub fn remove(&mut self, k: K) -> Option<()> { let env = self.env(); let k = k.into_val(env); - let has = env.map_has(self.0.to_object(), k); + let has = env.map_has(self.obj, k); if has.is_true() { - let map = env.map_del(self.0.to_object(), k); - self.0 = map.in_env(env); + self.obj = env.map_del(self.obj, k); Some(()) } else { None @@ -396,35 +386,34 @@ where #[inline(always)] pub fn remove_unchecked(&mut self, k: K) { let env = self.env(); - let map = env.map_del(self.0.to_object(), k.into_val(env)); - self.0 = map.in_env(env); + self.obj = env.map_del(self.obj, k.into_val(env)); } #[inline(always)] pub fn is_empty(&self) -> bool { let env = self.env(); - let len = env.map_len(self.0.to_object()); + let len = env.map_len(self.obj); len.is_u32_zero() } #[inline(always)] pub fn len(&self) -> u32 { let env = self.env(); - let len = env.map_len(self.0.to_object()); + let len = env.map_len(self.obj); unsafe { ::unchecked_from_val(len) } } #[inline(always)] pub fn keys(&self) -> Vec { let env = self.env(); - let vec = env.map_keys(self.0.to_object()); + let vec = env.map_keys(self.obj); Vec::::try_from_val(env, vec).unwrap() } #[inline(always)] pub fn values(&self) -> Vec { let env = self.env(); - let vec = env.map_values(self.0.to_object()); + let vec = env.map_values(self.obj); Vec::::try_from_val(env, vec).unwrap() } @@ -489,13 +478,13 @@ where type Item = Result<(K, V), ConversionError>; fn next(&mut self) -> Option { - let env = &self.0 .0.env; - let key = env.map_min_key(self.0 .0.to_object()); + let env = &self.0.env; + let key = env.map_min_key(self.0.obj); if Status::try_from(key).is_ok() { return None; } - let value = env.map_get(self.0 .0.to_object(), key); - self.0 .0.val = env.map_del(self.0 .0.to_object(), key); + let value = env.map_get(self.0.obj, key); + self.0.obj = env.map_del(self.0.obj, key); Some(Ok(( match K::try_from_val(env, key) { Ok(k) => k, @@ -522,13 +511,13 @@ where V: IntoVal + TryFromVal, { fn next_back(&mut self) -> Option { - let env = &self.0 .0.env; - let key = env.map_max_key(self.0 .0.to_object()); + let env = &self.0.env; + let key = env.map_max_key(self.0.obj); if Status::try_from(key).is_ok() { return None; } - let value = env.map_get(self.0 .0.to_object(), key); - self.0 .0.val = env.map_del(self.0 .0.to_object(), key); + let value = env.map_get(self.0.obj, key); + self.0.obj = env.map_del(self.0.obj, key); Some(Ok(( match K::try_from_val(env, key) { Ok(k) => k, diff --git a/soroban-sdk/src/serde.rs b/soroban-sdk/src/serde.rs index 78833ca23..afda58242 100644 --- a/soroban-sdk/src/serde.rs +++ b/soroban-sdk/src/serde.rs @@ -46,7 +46,7 @@ where fn serialize(self, env: &Env) -> Bytes { let val: RawVal = self.into_val(env); let bin = env.serialize_to_bytes(val); - unsafe { Bytes::unchecked_new(bin.in_env(env)) } + unsafe { Bytes::unchecked_new(env.clone(), bin) } } } diff --git a/soroban-sdk/src/set.rs b/soroban-sdk/src/set.rs index 1cdd62eb6..69270fb23 100644 --- a/soroban-sdk/src/set.rs +++ b/soroban-sdk/src/set.rs @@ -1,8 +1,8 @@ use core::{cmp::Ordering, fmt::Debug, iter::FusedIterator}; use super::{ - env::internal::Env as _, env::EnvObj, xdr::ScObjectType, ConversionError, Env, IntoVal, Map, - Object, RawVal, TryFromVal, TryIntoVal, Vec, + env::internal::Env as _, xdr::ScObjectType, ConversionError, Env, IntoVal, Map, Object, RawVal, + TryFromVal, TryIntoVal, Vec, }; /// Create a [Set] with the given items. @@ -73,8 +73,8 @@ where Self(map) } - unsafe fn unchecked_new(obj: EnvObj) -> Self { - let map = Map::unchecked_new(obj); + unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + let map = Map::unchecked_new(env, obj); Self(map) } @@ -283,7 +283,7 @@ where fn try_from_val(env: &Env, obj: Object) -> Result { if obj.is_obj_type(ScObjectType::Map) { - Ok(unsafe { Set::::unchecked_new(obj.in_env(env)) }) + Ok(unsafe { Set::::unchecked_new(env.clone(), obj) }) } else { Err(ConversionError {}) } diff --git a/soroban-sdk/src/vec.rs b/soroban-sdk/src/vec.rs index ecb7e9ae0..460e5c154 100644 --- a/soroban-sdk/src/vec.rs +++ b/soroban-sdk/src/vec.rs @@ -10,9 +10,9 @@ use core::{ use crate::iter::{UncheckedEnumerable, UncheckedIter}; use super::{ - env::{internal::Env as _, EnvObj, RawValConvertible}, + env::{internal::Env as _, internal::EnvBase as _, RawValConvertible}, xdr::ScObjectType, - ConversionError, Env, EnvVal, IntoVal, Object, RawVal, Set, TryFromVal, TryIntoVal, + ConversionError, Env, IntoVal, Object, RawVal, Set, TryFromVal, TryIntoVal, }; #[cfg(doc)] @@ -114,8 +114,11 @@ impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 /// [im_rc::Vector]: https://docs.rs/im-rc/latest/im_rc/struct.Vector.html /// [rrb]: https://infoscience.epfl.ch/record/213452/files/rrbvector.pdf #[derive(Clone)] -#[repr(transparent)] -pub struct Vec(EnvObj, PhantomData); +pub struct Vec { + env: Env, + obj: Object, + _t: PhantomData, +} impl Eq for Vec where T: IntoVal + TryFromVal {} @@ -142,7 +145,9 @@ where T: IntoVal + TryFromVal, { fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.cmp(&other.0) + self.env.check_same_env(&other.env); + let v = self.env.obj_cmp(self.obj.to_raw(), other.obj.to_raw()); + v.cmp(&0) } } @@ -167,13 +172,13 @@ where impl IntoVal> for Vec { fn into_val(self, _env: &Env) -> Vec { - unsafe { Vec::unchecked_new(self.0) } + unsafe { Vec::unchecked_new(self.env, self.obj) } } } impl IntoVal> for &Vec { fn into_val(self, _env: &Env) -> Vec { - unsafe { Vec::unchecked_new(self.0.clone()) } + unsafe { Vec::unchecked_new(self.env.clone(), self.obj.clone()) } } } @@ -186,7 +191,7 @@ where #[inline(always)] fn try_from_val(env: &Env, obj: Object) -> Result { if obj.is_obj_type(ScObjectType::Vec) { - Ok(unsafe { Vec::::unchecked_new(obj.in_env(env)) }) + Ok(unsafe { Vec::::unchecked_new(env.clone(), obj) }) } else { Err(ConversionError {}) } @@ -251,7 +256,7 @@ where { #[inline(always)] fn from(v: Vec) -> Self { - v.0.into() + v.obj.into() } } @@ -270,26 +275,7 @@ where { #[inline(always)] fn from(v: Vec) -> Self { - v.0.into() - } -} - -impl From> for EnvVal -where - T: IntoVal + TryFromVal, -{ - fn from(v: Vec) -> Self { - v.0.into() - } -} - -impl From> for EnvObj -where - T: IntoVal + TryFromVal, -{ - #[inline(always)] - fn from(v: Vec) -> Self { - v.0 + v.obj } } @@ -313,7 +299,7 @@ use super::xdr::{ScObject, ScVal, ScVec}; impl TryFrom<&Vec> for ScVal { type Error = ConversionError; fn try_from(v: &Vec) -> Result { - ScVal::try_from_val(&v.0.env, v.0.val.to_raw()) + ScVal::try_from_val(&v.env, v.obj.to_raw()) } } @@ -438,28 +424,32 @@ where impl Vec { #[inline(always)] - pub(crate) unsafe fn unchecked_new(obj: EnvObj) -> Self { - Self(obj, PhantomData) + pub(crate) unsafe fn unchecked_new(env: Env, obj: Object) -> Self { + Self { + env, + obj, + _t: PhantomData, + } } pub fn env(&self) -> &Env { - self.0.env() + &self.env } pub fn as_raw(&self) -> &RawVal { - self.0.as_raw() + self.obj.as_raw() } pub fn to_raw(&self) -> RawVal { - self.0.to_raw() + self.obj.to_raw() } pub fn as_object(&self) -> &Object { - self.0.as_object() + &self.obj } pub fn to_object(&self) -> Object { - self.0.to_object() + self.obj } } @@ -469,8 +459,7 @@ where { #[inline(always)] pub fn new(env: &Env) -> Vec { - let obj = env.vec_new(().into()).in_env(env); - unsafe { Self::unchecked_new(obj) } + unsafe { Self::unchecked_new(env.clone(), env.vec_new(().into())) } } #[inline(always)] @@ -494,7 +483,7 @@ where pub fn get(&self, i: u32) -> Option> { if i < self.len() { let env = self.env(); - let val = env.vec_get(self.0.to_object(), i.into()); + let val = env.vec_get(self.obj, i.into()); Some(T::try_from_val(env, val)) } else { None @@ -507,15 +496,14 @@ where T::Error: Debug, { let env = self.env(); - let val = env.vec_get(self.0.to_object(), i.into()); + let val = env.vec_get(self.obj, i.into()); T::try_from_val(env, val) } #[inline(always)] pub fn set(&mut self, i: u32, v: T) { let env = self.env(); - let vec = env.vec_put(self.0.to_object(), i.into(), v.into_val(env)); - self.0 = vec.in_env(env); + self.obj = env.vec_put(self.obj, i.into(), v.into_val(env)); } #[inline(always)] @@ -531,37 +519,34 @@ where #[inline(always)] pub fn remove_unchecked(&mut self, i: u32) { let env = self.env(); - let vec = env.vec_del(self.0.to_object(), i.into()); - self.0 = vec.in_env(env); + self.obj = env.vec_del(self.obj, i.into()); } #[inline(always)] pub fn is_empty(&self) -> bool { let env = self.env(); - let val = env.vec_len(self.0.to_object()); + let val = env.vec_len(self.obj); val.is_u32_zero() } #[inline(always)] pub fn len(&self) -> u32 { let env = self.env(); - let val = env.vec_len(self.0.to_object()); + let val = env.vec_len(self.obj); unsafe { <_ as RawValConvertible>::unchecked_from_val(val) } } #[inline(always)] pub fn push_front(&mut self, x: T) { let env = self.env(); - let vec = env.vec_push_front(self.0.to_object(), x.into_val(env)); - self.0 = vec.in_env(env); + self.obj = env.vec_push_front(self.obj, x.into_val(env)); } #[inline(always)] pub fn pop_front(&mut self) -> Option> { let last = self.last()?; let env = self.env(); - let vec = env.vec_pop_front(self.0.to_object()); - self.0 = vec.in_env(env); + self.obj = env.vec_pop_front(self.obj); Some(last) } @@ -569,24 +554,21 @@ where pub fn pop_front_unchecked(&mut self) -> Result { let last = self.first_unchecked(); let env = self.env(); - let vec = env.vec_pop_front(self.0.to_object()); - self.0 = vec.in_env(env); + self.obj = env.vec_pop_front(self.obj); last } #[inline(always)] pub fn push_back(&mut self, x: T) { let env = self.env(); - let vec = env.vec_push_back(self.0.to_object(), x.into_val(env)); - self.0 = vec.in_env(env); + self.obj = env.vec_push_back(self.obj, x.into_val(env)); } #[inline(always)] pub fn pop_back(&mut self) -> Option> { let last = self.last()?; let env = self.env(); - let vec = env.vec_pop_back(self.0.to_object()); - self.0 = vec.in_env(env); + self.obj = env.vec_pop_back(self.obj); Some(last) } @@ -594,8 +576,7 @@ where pub fn pop_back_unchecked(&mut self) -> Result { let last = self.last_unchecked(); let env = self.env(); - let vec = env.vec_pop_back(self.0.to_object()); - self.0 = vec.in_env(env); + self.obj = env.vec_pop_back(self.obj); last } @@ -622,16 +603,16 @@ where if self.is_empty() { None } else { - let env = self.0.env(); - let val = env.vec_front(self.0.to_object()); + let env = &self.env; + let val = env.vec_front(self.obj); Some(T::try_from_val(env, val)) } } #[inline(always)] pub fn first_unchecked(&self) -> Result { - let env = self.0.env(); - let val = env.vec_front(self.0.to_object()); + let env = &self.env; + let val = env.vec_front(self.obj); T::try_from_val(env, val) } @@ -641,7 +622,7 @@ where None } else { let env = self.env(); - let val = env.vec_back(self.0.to_object()); + let val = env.vec_back(self.obj); Some(T::try_from_val(env, val)) } } @@ -649,22 +630,20 @@ where #[inline(always)] pub fn last_unchecked(&self) -> Result { let env = self.env(); - let val = env.vec_back(self.0.to_object()); + let val = env.vec_back(self.obj); T::try_from_val(env, val) } #[inline(always)] pub fn insert(&mut self, i: u32, x: T) { let env = self.env(); - let vec = env.vec_put(self.0.to_object(), i.into(), x.into_val(env)); - self.0 = vec.in_env(env); + self.obj = env.vec_put(self.obj, i.into(), x.into_val(env)); } #[inline(always)] pub fn append(&mut self, other: &Vec) { let env = self.env(); - let vec = env.vec_append(self.0.to_object(), other.0.to_object()); - self.0 = vec.in_env(env); + self.obj = env.vec_append(self.obj, other.obj); } #[inline(always)] @@ -697,9 +676,8 @@ where Bound::Unbounded => self.len(), }; let env = self.env(); - let vec = env.vec_slice(self.0.to_object(), start_bound.into(), end_bound.into()); - let vec = vec.in_env(env); - unsafe { Self::unchecked_new(vec) } + let obj = env.vec_slice(self.obj, start_bound.into(), end_bound.into()); + unsafe { Self::unchecked_new(env.clone(), obj) } } pub fn iter(&self) -> VecIter @@ -737,7 +715,7 @@ where pub fn contains(&self, item: impl Borrow) -> bool { let env = self.env(); let val = item.borrow().into_val(env); - !env.vec_first_index_of(self.to_object(), val).is_void() + !env.vec_first_index_of(self.obj, val).is_void() } /// Returns the index of the first occurrence of the item. @@ -747,7 +725,7 @@ where pub fn first_index_of(&self, item: impl Borrow) -> Option { let env = self.env(); let val = item.borrow().into_val(env); - env.vec_first_index_of(self.to_object(), val) + env.vec_first_index_of(self.obj, val) .try_into_val(env) .unwrap() } @@ -759,7 +737,7 @@ where pub fn last_index_of(&self, item: impl Borrow) -> Option { let env = self.env(); let val = item.borrow().into_val(env); - env.vec_last_index_of(self.to_object(), val) + env.vec_last_index_of(self.obj, val) .try_into_val(env) .unwrap() } @@ -777,7 +755,7 @@ where pub fn binary_search(&self, item: impl Borrow) -> Result { let env = self.env(); let val = item.borrow().into_val(env); - let high_low = env.vec_binary_search(self.to_object(), val); + let high_low = env.vec_binary_search(self.obj, val); let high: u32 = (high_low >> u32::BITS) as u32; let low: u32 = high_low as u32; if high == 1 { @@ -835,7 +813,7 @@ where if len == 0 { None } else { - let val = self.0.env().vec_front(self.0 .0.to_object()); + let val = self.0.env().vec_front(self.0.obj); self.0 = self.0.slice(1..); Some(T::try_from_val(self.0.env(), val)) } @@ -859,7 +837,7 @@ where if len == 0 { None } else { - let val = self.0.env().vec_back(self.0 .0.to_object()); + let val = self.0.env().vec_back(self.0.obj); self.0 = self.0.slice(..len - 1); Some(T::try_from_val(self.0.env(), val)) }