-
Notifications
You must be signed in to change notification settings - Fork 458
Implement storage (revision 2) module #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
558 commits
Select commit
Hold shift + click to select a range
46a300e
Merge branch 'master' of github.com:paritytech/ink into redo-init-and…
Robbepop f34389f
[core] apply rustfmt
Robbepop b7cd8be
[core] fix warnings related to Wasm compilation
Robbepop bdbd583
[core] add SpreadLayout impl for DynamicAllocator
Robbepop 82a722e
[core] remove unused method on Bits256RefMut
Robbepop 3abc99a
[core] apply rustfmt
Robbepop 4e3ce32
[core] remove some unneded ToDo comments
Robbepop be13953
[core] transit to new traits for LazyIndexMap
Robbepop 487dff0
[core] transit to new traits for storage::Vec
Robbepop 63b5025
[core] transit to new traits for storage::Stash
Robbepop 1954a09
[core] transit to new traits for storage::Bitvec
Robbepop ede8055
[core] transit to new traits for dynamic storage allocator
Robbepop f0c48ab
[core] transit to new traits for LazyHashMap
Robbepop 4586f34
[core] transit to new traits for storage::HashMap
Robbepop f5ff4a3
[core] apply rustfmt
Robbepop c87034d
[core] remove old storage traits for storage::Pack
Robbepop e89ffd1
[core] transit to new storage traits for LazyArray
Robbepop 41cf862
[core] transit to new storage traits for storage::SmallVec
Robbepop b00c458
[core] transit to new storage traits for the rest of the lazy abstrac…
Robbepop 07296c2
[core] transit to new storage traits for storage::Box
Robbepop 3250b96
[core] fix compile error in Drop impl for storage::Box
Robbepop e800f77
[core] remove old storage trait impls for Bits256
Robbepop c3cb918
[core] remove old storage trait impls for dynamic storage allocator
Robbepop e9d5876
[core] apply rustfmt
Robbepop abdbc82
[core] remove old traits module
Robbepop cbbbcc7
[core] replace KeyPtr2 usage with KeyPtr
Robbepop ee650de
[core] rename traits2 module to traits
Robbepop b585f2a
[core] apply rustfmt
Robbepop d252df1
[core] add Drop impl to storage::Vec
Robbepop d65b6bb
[core] don't clear storage if key is none for storage::Vec
Robbepop 635fd9f
[core] impl Drop for storage::Stash
Robbepop 9a8fbdc
[core] simplify trait bounds for LazyHashMap
Robbepop 58b69b1
[core] impl Drop for storage::HashMap
Robbepop f5264b7
[core] add Drop impl for storage::SmallVec
Robbepop cbe5317
[core] add are_trait_objects lint as deny
Robbepop 71fd6ae
[core] fix minor formatting issue
Robbepop 0fbf5ac
[core] add storage2::Memory utility
Robbepop 50a4718
[core] remove usage of storage::Pack from internals of storage::Bitvec
Robbepop c1a6985
[core] remove usage of storage::Pack from internals of storage::Stash
Robbepop a0a4f13
[core] remove usage of storage::Pack from internals of storage::HashMap
Robbepop a04db0e
[core] add better Debug impl for LazyIndexMap
Robbepop 69862e9
[core] apply rustfmt
Robbepop 5d06196
[core] improve Debug impl for LazyHashMap
Robbepop add9229
[core] improve Debug impl for lazy::Entry
Robbepop 58bec7c
[core] improve Debug impl for LazyCell
Robbepop 74f78b4
[core] improve Debug impl for LazyArray
Robbepop a3a6be1
[core] apply rustfmt
Robbepop 68a8b8a
[core] add REQUIRES_DEEP_CLEAN_UP to SpreadLayout
Robbepop 9640cec
[core] implement REQUIRES_DEEP_CLEAN_UP for all built-in types
Robbepop b95a7ed
[core] add non-storage trait impls for storage::HashMap
Robbepop f62a80e
[core] simplify traits bounds of SpreadLayout impl for storage::HashMap
Robbepop c84c9e6
[core] fix bug in Wasm compilation
Robbepop 244ce97
[core] add initial unit tests for storage::HashMap
Robbepop 2fc4e12
[core] allow loading without key from LazyHashMap
Robbepop 7bab683
[core] merge storage::HashMap insert and insert_get and fix bugs with it
Robbepop a840ec8
[core] add new unit test for storage::HashMap
Robbepop 92fd483
[core] generally allow lazy loading without keys for lazy abstractions
Robbepop 996bb78
[core] apply rustfmt
Robbepop fff9a80
[core] remove outdated docs of storage::HashMap::insert
Robbepop cb34edb
[core] add unit test for storage::HashMap::contains_key
Robbepop 7f90b14
[core] apply rustfmt to storage::HashMap unit tests
Robbepop 018e5f6
[core] add unit test for storage::HashMap::{get, get_mut}
Robbepop a5eb767
[core] fix the doc comment of storage::HashMap::remove
Robbepop a1bd0ba
[core] add unit test for storage::HashMap::take
Robbepop 5786266
[core] add unit test for storage::HashMap::insert
Robbepop b7e9195
[core] remove storage::HashMap::remove
Robbepop 989f38b
[core] implement Iterator::count efficiently for storage::HashMap ite…
Robbepop c968895
[core] add prelude trait impls for crypto hashers
Robbepop e2864ee
[core] add unit test for storage::HashMap::iter
Robbepop 2e99a7d
[core] remove outdated doc comment line
Robbepop 7ffb304
[core] add doc comments to fowarding-to-packed utility functions
Robbepop c4f4610
[core] add some high-level documentation for some root storage2 modules
Robbepop c1c441a
[core] add some more high-level docs
Robbepop 2aecb7d
[core] add return value to storage::Stash::defrag
Robbepop 4ef116b
[core] add return value to storage::HashMap::defrag
Robbepop f23ddc9
[core] add unit test for storage::HashMap::{values, values_mut}
Robbepop 9287708
[core] add tests for Iterator::size_hint impls of storage::Vec
Robbepop 6374a10
[core] add unit test for storage::HashMap::keys
Robbepop 01f9192
[core] add unit test for storage::HashMap::defrag
Robbepop ba04b06
[core] add unit tests for LazyIndexMap
Robbepop 21efe5a
[core] remove lazy::Entry::take_value
Robbepop f17f074
[core] remove LazyIndexMap::take
Robbepop 122251b
[core] remove Entry::set_state
Robbepop 0c556b4
[core] remove Lazy{Array, HashMap}::take method
Robbepop a2286b6
[core] add unit test for LazyIndexMap::put
Robbepop eb65e00
[core] add unit test for LazyIndexMap::swap
Robbepop 5964798
[core] apply rustfmt
Robbepop f50d659
[core] cover Default impl of LazyIndexMap with unit test
Robbepop 4b54852
[core] move imports to top for LazyIndexMap .rs file
Robbepop 9b38030
[core] refactor lazy::Entry internals a bit
Robbepop efa636a
[core] add unit tests for Index impl of storage::Vec
Robbepop 098c21f
[core] add unit tests for Index impl of storage::SmallVec
Robbepop 11fcf3a
[core] add tests for Index impl of StorageStash
Robbepop 5fa4c5d
[core] improve panic message for Index{Mut} impl of storage::Stash
Robbepop 8f53bfa
[core] add unit tests for Index{Mut} impl of storage::Stash
Robbepop 750dd28
[core] extend unit test for storage::Stash::get
Robbepop 7345251
[core] disable certain tests in --release mode testing
Robbepop bf5584b
[core] add unit test for LazyIndexMap::{get, get_mut}
Robbepop e92ff3e
[core] add some unit tests for LazyArray
Robbepop 011d936
[core] add some more unit tests for LazyArray
Robbepop 6970fc7
[core] add some more unit tests to LaryArray
Robbepop 642217c
[core] apply rustfmt
Robbepop 008ea74
[core] add unit tests for LazyCell
Robbepop b841e46
[core] add unit test for SpreadLayout impl of LazyCell
Robbepop 436d536
[core] extend SpreadLayout test for LazyCell
Robbepop 161d687
[core] extend SpreadLayout test to also cover the clear_spread impl
Robbepop 370c056
[core] rename unit test for LazyCell
Robbepop 0d48b35
[core] fix clippy warning
Robbepop 6358e40
[core] fix some LazyCell cache entry in lazy form
Robbepop 8a2183c
[core] add new unit test for Debug impl of lazy initialized LazyCell
Robbepop b4d4a70
[core] add more unit tests for lazily initialized LazyCell
Robbepop 415ff70
[core] implement shallow clean-up of storage via LazyCell
Robbepop d4cd87c
[core] test that a lazily loaded LazyCell preserves its cached value
Robbepop 6cdf7bc
[core] apply rustfmt
Robbepop 1fbc81d
[core] add additional check for LazyCell cache preservation
Robbepop a6b040f
[core] fix bug in LazyIndexMap::clear_packed_at
Robbepop f778ccc
[core] add unit test for SpreadLayout impl of LazyIndexMap
Robbepop 9d01301
[core] fix bug in LazyArray::clear_packed_at
Robbepop 29e824b
[core] add unit test for SpreadLayout impl of LazyArray
Robbepop 9cab25c
[core] make LazyArray::capacity and SmallVec::capcity more user friendly
Robbepop ad62f54
[core] remove unnecessary trait bounds
Robbepop 2631567
[core] remove more unnecessary trait bounds
Robbepop 7acbc25
[core] add initial unit test for LazyHashMap
Robbepop a8802a2
[core] add unit test for LazyHashMap::key_at
Robbepop c2f3738
[core] apply rustfmt
Robbepop 9127a57
[core] indent a block in test
Robbepop 7a1ba47
[core] add unit test for LazyHashMap::put_get
Robbepop 8216d52
[core] add unit test for LazyHashMap::{get, get_mut}
Robbepop 9a3455e
[core] add unit test for LazyHashMap::put
Robbepop dcdde2e
[core] add unit test for LazyHashMap::swap
Robbepop 9e59e15
[core] make hash builders reset their accumulator upon finalization
Robbepop 36ef90a
[core] add unit test for SpreadLayout impl of LazyHashMap
Robbepop e9d0d87
[core] fix unit test for LazyHashMap::key_at
Robbepop dfbe0e9
[core] add unit tests for SpreadLayout impl of storage::Vec
Robbepop dcedc81
[core] add unit tests for SpreadLayout impl of storage::SmallVec
Robbepop 96bed80
[core] add unit tests for SpreadLayout impl of storage::Stash
Robbepop 1b9bd9b
[core] apply rustfmt
Robbepop 5e5ef04
[core] add unit tests for SpreadLayout impl of storage::HashMap
Robbepop 928ee74
[core] add unit test for DynamicAllocation::key
Robbepop 6c60470
[core] add unit tests for SpreadLayout impl of storage::Bitvec
Robbepop 78b32b2
[core] fix LazyCell::get unit test
Robbepop c721e68
[core] remove unused dependencies from Cargo.toml
Robbepop b3dda7b
[core] add missing docs for storage::{Stash, HashMap}
Robbepop ec9de2a
[core] deny missing docs of public items
Robbepop 1fe65af
[core] add Debug impl to storage::Box
Robbepop 4625dd4
[core] add unit tests for storage::Box
Robbepop bb809f3
[core] remove internal Pack::{get, get_mut} methods
Robbepop a458630
[core] fix bug in storage::Memory::{get, get_mut} API
Robbepop 897143f
[core] add unit tests for storage::Pack
Robbepop 1104843
[core] improve storage::Pack unit tests
Robbepop 53ad667
[core] experimental inline(never) for debug_assertions compilation
Robbepop 0519721
[core] apply rustfmt
Robbepop 551d158
[core] remove experimental #[inline(never)]
Robbepop 25a3e2c
[core] add unit test for Default impl of storage::Pack
Robbepop 73d3c67
[core] add unit tests for storage::Memory
Robbepop 57f33d2
[core] fix a unit test for storage::Box
Robbepop bf2f703
[core] fix minor bug in BitRefMut utility of storage::Bitvec
Robbepop bdf51ec
[core] cover storage::Bitvec::get_mut in get_works unit test
Robbepop ad2f011
[core] add unit tests for BitRefMut utility of storage::Bitvec
Robbepop 965b7c2
[core] apply rustfmt
Robbepop cccadf7
[core] improve panic message when encountering a double free
Robbepop c17735a
[core] adjust double free unit test for storage::Box
Robbepop 58d7123
[core] improve double free of dynamic storage panic message
Robbepop a1c8d3b
[core] apply rustfmt
Robbepop 689d772
[core] merge Bits256Ref and Bits256RefMut into ChunkRef<T>
Robbepop c195738
[core] split access.rs into bitref.rs and bitsref.rs
Robbepop 597565f
[core] apply rustfmt
Robbepop 0267278
[core] replace transmute with pointer cast
Robbepop 2615700
[core] add comment to explain repr(C)
Robbepop 312b943
[core] add PartialEq and Eq impls to BitRefMut
Robbepop f2200b0
[core] add unit tests for ChunkRef
Robbepop 73dfea0
[core] add failure unit tests for dynamic storage allocator
Robbepop 54eb932
Merge branch 'master' of github.com:paritytech/ink into redo-init-and…
Robbepop a37dbc6
[core] fix bug in SpreadLayout impl of Option<T>
Robbepop 8003fcc
[core] add unit test for dynamic storage allocator SpreadLayout impl
Robbepop f30aa6e
[core] fix SpreadLayout impl for Result<T, E>
Robbepop c333304
[core] fix yet another bug in SpreadLayout impl of Result<T, E>
Robbepop 350ad01
[core] move forward_supported_array_lens macro to usage site
Robbepop fcd3ee5
[core] refactor some code duplication with clear_spread_root_opt
Robbepop e44b874
[core] fix doc comment in storage::Pack
Robbepop 164a817
[core] remove some unused unsafe blocks
Robbepop a3a99b0
fix typo
Robbepop b26eb3d
fix typo
Robbepop a866192
fix typo
Robbepop 4d0fa7f
fix typo
Robbepop 4e58ee3
fix typo
Robbepop da288bd
[core] remove usage of storage::Pack in dynamic storage allocator
Robbepop 641fc7c
[core] improve panic message in Lazy::{get, get_mut}
Robbepop a8fc3e2
[core] add test for SpreadLayout::clear_spread impl of dynamic storag…
Robbepop 3156d84
[core] remove code dupe
Robbepop 32bac89
[core] refactor clear_spread_root_opt utility function
Robbepop c28ca4b
[core] implement SpreadLayout::REQUIRES_DEEP_CLEAN_UP for some types
Robbepop bbacb5e
[core] move from bool to u8 for Option and Result SpreadLayout impls
Robbepop 915e129
[core] fix bug in SpreadLayout impl for Option
Robbepop 0fcfdc3
fix typo
Robbepop 0533517
[core] update LazyCell SAFETY comment
Robbepop 4d934f9
Merge branch 'redo-init-and-flush' of github.com:paritytech/ink into …
Robbepop cfa4e99
[core] update Entry docs
Robbepop 7fc236f
[core] remove unneeded code in lazy::Entry::pull_packed_root
Robbepop abe950a
fix typo
Robbepop 3120149
fix typo
Robbepop 26637f5
fix typo
Robbepop 132c31f
fix typo
Robbepop 942fc21
[core] remove commented out code
Robbepop 8dca61b
Merge branch 'redo-init-and-flush' of github.com:paritytech/ink into …
Robbepop 981ccbc
[core] add new unit test for dynamic storage allocator
Robbepop 386554a
[core] refactor global storage allocator initialization routines
Robbepop 9aa98df
[core] fix Wasm compilation errors
Robbepop 6a4e988
[core] apply rustfmt
Robbepop 72c8d24
[core] surpress bad clippy lint
Robbepop 1d1cf88
[core] remove dead code
Robbepop 7781e46
[core] improve call_setup_works test
Robbepop 0141966
[core] fix bug in initialize_for for off-chain env
Robbepop 8b0c43a
[core] initial steps to factor out BitStash from DynamicAllocator
Robbepop 7707b60
[core] apply rustfmt
Robbepop c09c1d8
[core] add Derive impl for BitStash
Robbepop 7cb766f
[core] make use of storage::BitStash from dynamic storage allocator
Robbepop 87c9332
[core] add unit tests for storage::BitStash
Robbepop 41df228
[core] apply rustfmt
Robbepop 9c76b94
[core] remove invalid TODO comment
Robbepop bfdd049
[core] fix some out of bounds panic messages
Robbepop 3c6fdff
[core] remove deliberate memory leak in test suite
Robbepop e732fbb
[core] fix build failure for Wasm target
Robbepop 4b90999
[core] add unit tests for SpreadLayout & PackedLayout impls of primit…
Robbepop 9dce884
[core] add unit tests for packed layout explicitely
Robbepop 460114d
Fix some typos
ascjones 013fe32
Add simple double ended iter test
ascjones de472da
typos
ascjones ff86777
comment typos
ascjones 064b8ed
split hashmap to hash map in comments
ascjones 4e2526d
Merge branch 'master' of github.com:paritytech/ink into redo-init-and…
Robbepop 6f4ad98
Merge branch 'redo-init-and-flush' of github.com:paritytech/ink into …
Robbepop dd8e701
fix typo
Robbepop 8abd87c
fix typo in unreachable! message
Robbepop 94a210d
fix typo in expects message
Robbepop 0afc002
fix typo
Robbepop 2bf18eb
fix typo
Robbepop c51c5dd
[core] add more comments to storage2::HashMap::defrag
Robbepop c663917
[core] make early return for storage2::HashMap::defrag for limit = 0
Robbepop 8c51af4
[core] improve storage2::HashMap::contains_key implementation
Robbepop 96bac02
[core] rename new_vec_works test to new_works
Robbepop 7f6fd36
[core] apply Andrew's suggestions (and more)
Robbepop 9477306
[core] fix typo: increase -> decrease
Robbepop 6e4abe3
[core] add panic to Bitvec::push in case it reached its maximum capacity
Robbepop c5dedc3
[core] update comments for storage bit stash
Robbepop c05739d
[core] add more explanation comments
Robbepop 07d3c23
[core] some more renamings of test internals
Robbepop 3308797
improve reasoning
Robbepop ac873eb
fix typo
Robbepop 58f3645
Merge branch 'redo-init-and-flush' of github.com:paritytech/ink into …
Robbepop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[core] refactor global storage allocator initialization routines
- Loading branch information
commit 386554afb3802ef47378aeed0223eceabc1b2c61
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright 2019-2020 Parity Technologies (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use super::DynamicAllocator; | ||
use cfg_if::cfg_if; | ||
use crate::storage2::traits::pull_spread_root; | ||
use ink_primitives::Key; | ||
|
||
/// The default dynamic allocator key offset. | ||
/// | ||
/// This is where the dynamic allocator is stored on the contract storage. | ||
const DYNAMIC_ALLOCATOR_KEY_OFFSET: [u8; 32] = [0xFE; 32]; | ||
|
||
/// The phase in which a contract execution can be. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
pub enum ContractPhase { | ||
/// Initializes the global dynamic storage allocator from scratch. | ||
/// | ||
/// Upon initialization it will be created from scratch as if the | ||
/// contract has been deployed for the first time. | ||
Deploy, | ||
/// Initializes the global dynamic storage allocator from storage. | ||
/// | ||
/// Upon initialization the dynamic storage allocator will be pulled | ||
/// from the contract storage with the assumption that a former | ||
/// contract deployment has already taken place in the past. | ||
Call, | ||
} | ||
|
||
/// The state of the dynamic allocator global instance. | ||
#[derive(Debug)] | ||
enum DynamicAllocatorState { | ||
/// The global instance has not yet been initialized. | ||
/// | ||
/// Upon initialization it will be created from scratch as if the | ||
/// contract has been deployed for the first time. | ||
UninitDeploy, | ||
/// The global instance has not yet been initialized. | ||
/// | ||
/// Upon initialization it will be pulled from the contract storage | ||
/// with the assumption that a former contract deployment has already | ||
/// taken place in the past. | ||
UninitCall, | ||
/// The global instance has already been initialized successfully. | ||
Initialized(DynamicAllocator), | ||
} | ||
|
||
impl From<ContractPhase> for DynamicAllocatorState { | ||
fn from(phase: ContractPhase) -> Self { | ||
match phase { | ||
ContractPhase::Deploy => DynamicAllocatorState::UninitDeploy, | ||
ContractPhase::Call => DynamicAllocatorState::UninitCall, | ||
} | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(all(not(feature = "std"), target_arch = "wasm32"))] { | ||
// Procedures for the Wasm compilation: | ||
|
||
/// The global instance for the dynamic storage allocator. | ||
static mut GLOBAL_INSTANCE: DynamicAllocatorState = DynamicAllocatorState::UninitDeploy; | ||
|
||
/// Commands the (re-)initialization of the global instance for the dynamic | ||
/// storage allocator. | ||
pub fn initialize_for(phase: ContractPhase) { | ||
let instance = unsafe { &mut GLOBAL_INSTANCE }; | ||
// We do not allow reinitialization for Wasm targets for performance reasons. | ||
assert!(!instance.is_initialized()); | ||
*instance = phase.into(); | ||
} | ||
|
||
/// Runs the given closure on the global instance for the dynamic storage allocator. | ||
pub fn on_call<F, R>(f: F) -> R | ||
where | ||
F: FnOnce(&mut DynamicAllocator) -> R, | ||
{ | ||
let instance = unsafe { &mut GLOBAL_INSTANCE }; | ||
match instance { | ||
DynamicAllocatorState::UninitDeploy => { | ||
let mut allocator = DynamicAllocator::new(); | ||
let result = f(&mut allocator); | ||
*instance = allocator; | ||
result | ||
} | ||
DynamicAllocatorState::UninitCall => { | ||
let mut allocator = pull_spread_root::<DynamicAllocator>(&Key(DYNAMIC_ALLOCATOR_KEY_OFFSET)); | ||
Robbepop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let result = f(&mut allocator); | ||
*instance = allocator; | ||
result | ||
} | ||
DynamicAllocatorState::Initialized(ref mut allocator) => { | ||
f(allocator) | ||
} | ||
} | ||
} | ||
|
||
} else if #[cfg(feature = "std")] { | ||
// Procedures for the off-chain environment and testing compilation: | ||
|
||
use ::core::cell::RefCell; | ||
thread_local!( | ||
/// The global instance for the dynamic storage allocator. | ||
static GLOBAL_INSTANCE: RefCell<DynamicAllocatorState> = RefCell::new(DynamicAllocatorState::UninitDeploy); | ||
); | ||
|
||
/// Commands the (re-)initialization of the global instance for the dynamic | ||
/// storage allocator. | ||
pub fn initialize_for(phase: ContractPhase) { | ||
GLOBAL_INSTANCE.with(|instance| instance.replace_with(|_| phase.into())); | ||
} | ||
|
||
/// Runs the given closure on the global instance for the dynamic storage allocator. | ||
pub fn on_call<F, R>(f: F) -> R | ||
where | ||
F: FnOnce(&mut DynamicAllocator) -> R, | ||
{ | ||
GLOBAL_INSTANCE.with(|instance| { | ||
match &mut *instance.borrow_mut() { | ||
instance @ DynamicAllocatorState::UninitDeploy => { | ||
let mut allocator = DynamicAllocator::new(); | ||
let result = f(&mut allocator); | ||
*instance = DynamicAllocatorState::Initialized(allocator); | ||
result | ||
} | ||
instance @ DynamicAllocatorState::UninitCall => { | ||
let mut allocator = pull_spread_root::<DynamicAllocator>(&Key(DYNAMIC_ALLOCATOR_KEY_OFFSET)); | ||
let result = f(&mut allocator); | ||
*instance = DynamicAllocatorState::Initialized(allocator); | ||
result | ||
} | ||
DynamicAllocatorState::Initialized(instance) => { | ||
f(instance) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
} else { | ||
compile_error! { | ||
"ink! only support compilation as `std` or `no_std` + `wasm32-unknown`" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.