Refactor construct_runtime to procedural (#3810)

* interim

* interim

* interim

* first working section

* cleanup

* finished parsing

* cleanup

* added system module search

* added clone and find_entry

* generic find_module_entry

* interim

* working event

* added generic event with no instance error

* cleanup

* added decl origin

* cleanup

* added all modules

* added outer dispatch

* added modules expansion

* refactored transformations

* updated error message

* added resolve mechanics

* added metadata

* finished config

* finished inherents

* added validate_unsigned

* added compares

* cleanup

* cleanup

* cleanup

* fix

* updated modules for last one wins

* cleanup

* made nested modules

* updated impl version

* removed comment

* cleanup

* added ui tests

* added optional comma

* removed unnecessary to string cast

* removed no compile

* cleanup

* fmt

* returned nocompile

* Update srml/support/procedural/src/construct_runtime/parse.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* added where definition

* updated ui tests

* updated ui test cases

* added test case

* updated tests

* interim

* added parse for module part

* removed totokens

* fixes

* fixed multiple iter

* changed TokenStream

* fmt

* updated trybuild

* added test for arguments

* fmt

* fixes + more tests

* fixes

* fmt

* rolled back runtime

* minor fixes

* empty

* fixes

* fmt

* Update paint/support/procedural/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update paint/support/procedural/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update paint/support/procedural/src/construct_runtime/parse.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* interim

* refactored seen_keys

* refactored hash_set

* Update paint/support/procedural/src/construct_runtime/mod.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* refactored find

* fix

* fixed all_modules

* added double declaration check

* small fix

* fmt

* fix

* fix default

* format
This commit is contained in:
Alexey
2019-11-25 19:48:18 +03:00
committed by Bastian Köcher
parent d56d6163ef
commit d7b9dd300b
43 changed files with 1148 additions and 955 deletions
@@ -23,6 +23,7 @@
extern crate proc_macro;
mod storage;
mod construct_runtime;
use proc_macro::TokenStream;
@@ -219,3 +220,63 @@ use proc_macro::TokenStream;
pub fn decl_storage(input: TokenStream) -> TokenStream {
storage::decl_storage_impl(input)
}
/// Construct a runtime, with the given name and the given modules.
///
/// The parameters here are specific types for `Block`, `NodeBlock`, and `UncheckedExtrinsic`
/// and the modules that are used by the runtime.
/// `Block` is the block type that is used in the runtime and `NodeBlock` is the block type
/// that is used in the node. For instance they can differ in the extrinsics type.
///
/// # Example:
///
/// ```nocompile
/// construct_runtime!(
/// pub enum Runtime where
/// Block = Block,
/// NodeBlock = runtime::Block,
/// UncheckedExtrinsic = UncheckedExtrinsic
/// {
/// System: system,
/// Test: test::{default},
/// Test2: test_with_long_module::{Module},
///
/// // Module with instances
/// Test3_Instance1: test3::<Instance1>::{Module, Call, Storage, Event<T, I>, Config<T, I>, Origin<T, I>},
/// Test3_DefaultInstance: test3::{Module, Call, Storage, Event<T>, Config<T>, Origin<T>},
/// }
/// )
/// ```
///
/// The module `System: system` will expand to `System: system::{Module, Call, Storage, Event<T>, Config<T>}`.
/// The identifier `System` is the name of the module and the lower case identifier `system` is the
/// name of the Rust module/crate for this Substrate module.
///
/// The module `Test: test::{default}` will expand to
/// `Test: test::{Module, Call, Storage, Event<T>, Config<T>}`.
///
/// The module `Test2: test_with_long_module::{Module}` will expand to
/// `Test2: test_with_long_module::{Module}`.
///
/// We provide support for the following types in a module:
///
/// - `Module`
/// - `Call`
/// - `Storage`
/// - `Event` or `Event<T>` (if the event is generic)
/// - `Origin` or `Origin<T>` (if the origin is generic)
/// - `Config` or `Config<T>` (if the config is generic)
/// - `Inherent ( $(CALL),* )` - If the module provides/can check inherents. The optional parameter
/// is for modules that use a `Call` from a different module as
/// inherent.
/// - `ValidateUnsigned` - If the module validates unsigned extrinsics.
///
/// # Note
///
/// The population of the genesis storage depends on the order of modules. So, if one of your
/// modules depends on another module, the module that is depended upon needs to come before
/// the module depending on it.
#[proc_macro]
pub fn construct_runtime(input: TokenStream) -> TokenStream {
construct_runtime::construct_runtime(input)
}