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
@@ -0,0 +1,12 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
Block = Block1,
UncheckedExtrinsic = Uxt,
{}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `Block` was declared above. Please use exactly one delcataion for `Block`.
--> $DIR/abundant_where_param.rs:7:3
|
7 | Block = Block1,
| ^^^^^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::{Config, Call, Config<T>, Origin<T>},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `Config` was already declared before. Please remove the duplicate declaration
--> $DIR/double_module_parts.rs:10:37
|
10 | Balance: balances::{Config, Call, Config<T>, Origin<T>},
| ^^^^^^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::{default, Config},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `Config` is already included in `default`. Either remove `default` or remove `Config`
--> $DIR/double_module_parts_default.rs:10:32
|
10 | Balance: balances::{default, Config},
| ^^^^^^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::<Instance1>::{Call<T>, Origin<T>},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `Call` is not allowed to have generics. Only the following modules are allowed to have generics: `Event`, `Origin`, `Config`.
--> $DIR/generics_in_invalid_module.rs:10:36
|
10 | Balance: balances::<Instance1>::{Call<T>, Origin<T>},
| ^^^^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
system: System::(),
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected curly braces
--> $DIR/invalid_module_details.rs:9:19
|
9 | system: System::(),
| ^^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
system: System::{enum},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected `default` or identifier
--> $DIR/invalid_module_details_keyword.rs:9:20
|
9 | system: System::{enum},
| ^^^^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
system: System ?
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected `,`
--> $DIR/invalid_token_after_module.rs:9:18
|
9 | system: System ?
| ^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
system ?
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected `:`
--> $DIR/invalid_token_after_name.rs:9:10
|
9 | system ?
| ^
@@ -0,0 +1,12 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
TypeX = Block,
UnchekcedExtrinsic = UnchekcedExtrinsic,
{}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected one of: `Block`, `NodeBlock`, `UncheckedExtrinsic`
--> $DIR/invalid_where_param.rs:7:3
|
7 | TypeX = Block,
| ^^^^^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::<Instance1>::{Event},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: Instantiable module with no generic `Event` cannot be constructed: module `Balance` must have generic `Event`
--> $DIR/missing_event_generic_on_module_with_instance.rs:10:3
|
10 | Balance: balances::<Instance1>::{Event},
| ^^^^^^^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
system: System::<>,
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected identifier
--> $DIR/missing_module_instance.rs:9:20
|
9 | system: System::<>,
| ^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::<Instance1>::{Origin},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: Instantiable module with no generic `Origin` cannot be constructed: module `Balance` must have generic `Origin`
--> $DIR/missing_origin_generic_on_module_with_instance.rs:10:3
|
10 | Balance: balances::<Instance1>::{Origin},
| ^^^^^^^
@@ -0,0 +1,12 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
}
}
fn main() {}
@@ -0,0 +1,7 @@
error: `System` module declaration is missing. Please add this line: `System: system::{Module, Call, Storage, Config, Event},`
--> $DIR/missing_system_module.rs:8:2
|
8 | {
| _____^
9 | | }
| |_____^
@@ -0,0 +1,7 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime {}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected `where`
--> $DIR/missing_where_block.rs:4:19
|
4 | pub enum Runtime {}
| ^^
@@ -0,0 +1,10 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
{}
}
fn main() {}
@@ -0,0 +1,5 @@
error: Missing associated type for `UncheckedExtrinsic`. Add `UncheckedExtrinsic` = ... to where section.
--> $DIR/missing_where_param.rs:7:2
|
7 | {}
| ^^
@@ -0,0 +1,13 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
UncheckedExtrinsic = UncheckedExtrinsic
Block = Block,
NodeBlock = Block,
{
System: system,
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: Expected `,` or `{`
--> $DIR/no_comma_after_where.rs:6:3
|
6 | Block = Block,
| ^^^^^
@@ -0,0 +1,14 @@
use support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
Balance: balances::<Instance1>::{Call(toto), Origin<I>},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `Call` is not allowed to have arguments in parens. Only the following modules are allowed to have arguments in parens: `Inherent`.
--> $DIR/params_in_invalid_module.rs:10:40
|
10 | Balance: balances::<Instance1>::{Call(toto), Origin<I>},
| ^^^^^^