Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
intermediate commit, use petgraph for convenience and the dot graph
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Apr 19, 2022
1 parent 647636e commit efb1d10
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 101 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions node/overseer/overseer-gen/examples/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use std::collections::HashMap;
#[derive(Default)]
pub struct AwesomeSubSys;

impl ::polkadot_overseer_gen::Subsystem<SubsystemContext<MsgStrukt>, Yikes> for AwesomeSubSys {
fn start(self, ctx: SubsystemContext<MsgStrukt>) -> SpawnedSubsystem<Yikes> {
self.spawn(async move { ctx.send_message(Plinko).await });
impl ::polkadot_overseer_gen::Subsystem<AwesomeSubSysContext, Yikes> for AwesomeSubSys {
fn start(self, ctx: AwesomeSubSysContext) -> SpawnedSubsystem<Yikes> {
ctx.spawn("awesome", Box::pin(async move { ctx.send_message(Plinko).await }));
unimplemented!("starting yay!")
}
}

#[derive(Default)]
pub struct GoblinTower;

impl ::polkadot_overseer_gen::Subsystem<SubsystemContext<Plinko>, Yikes> for GoblinTower {
fn start(self, ctx: SubsystemContext<Plinko>) -> SpawnedSubsystem<Yikes> {
self.spawn(async move { ctx.send_message(MsgStrukt).await });
impl ::polkadot_overseer_gen::Subsystem<GoblinTowerContext, Yikes> for GoblinTower {
fn start(self, ctx: GoblinTowerContext) -> SpawnedSubsystem<Yikes> {
ctx.spawn("awesome", Box::pin(async move { ctx.send_message(MsgStrukt(0u8)).await }));
unimplemented!("welcum")
}
}
Expand Down Expand Up @@ -91,15 +91,11 @@ impl NetworkMsg {
}

#[overlord(signal=SigSigSig, event=EvX, error=Yikes, network=NetworkMsg, gen=AllMessages)]
struct Xxx<T> {
#[subsystem(
consumes: MsgStrukt,
sends: Plinko
)]
struct Yyy<T> {
#[subsystem(consumes: MsgStrukt, sends: Plinko)]
sub0: AwesomeSubSys,

#[subsystem(no_dispatch, blocking, consumes: Plinko, sends: MsgStruckt)
]
#[subsystem(no_dispatch, blocking, consumes: Plinko, sends: MsgStrukt)]
plinkos: GoblinTower,

i_like_pi: f64,
Expand Down Expand Up @@ -134,7 +130,7 @@ impl SpawnNamed for DummySpawner {
struct DummyCtx;

fn main() {
let (overseer, _handle): (Xxx<_, f64>, _) = Xxx::builder()
let (overseer, _handle): (Yyy<_, f64>, _) = Yyy::builder()
.sub0(AwesomeSubSys::default())
.plinkos(GoblinTower::default())
.i_like_pi(::std::f64::consts::PI)
Expand Down
3 changes: 2 additions & 1 deletion node/overseer/overseer-gen/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ quote = "1.0.17"
proc-macro2 = "1.0.37"
proc-macro-crate = "1.1.3"
expander = { version = "0.0.6", default-features = false }
petgraph = "0.6.0"

[dev-dependencies]
assert_matches = "1.5.0"

[features]
default = []
default = ["expand"]
# write the expanded version to a `overlord-expansion.[a-f0-9]{10}.rs`
# in the `OUT_DIR` as defined by `cargo` for the `expander` crate.
expand = []
18 changes: 10 additions & 8 deletions node/overseer/overseer-gen/proc-macro/src/impl_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
let builder = format_ident!("{}Builder", overseer_name);
let handle = format_ident!("{}Handle", overseer_name);
let connector = format_ident!("{}Connector", overseer_name);
let subsystem_ctx_name = format_ident!("{}SubsystemContext", overseer_name);

let subsystem_name = &info.subsystem_names_without_wip();
let subsystem_generics = &info.subsystem_generic_types();
let subsystem_ctx_names =
&Vec::from_iter(subsystem_generics.iter().map(|name| format_ident!("{}Context", name)));

let consumes = &info.consumes_without_wip();
let channel_name = &info.channel_names_without_wip("");
Expand Down Expand Up @@ -103,7 +104,8 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
info.subsystems().iter().filter(|ssf| !ssf.wip).enumerate().map(|(idx, ssf)| {
let field_name = &ssf.name;
let field_type = &ssf.generic;
let subsystem_consumes = &ssf.message_to_consume;
let subsystem_ctx_name = format_ident!("{}Context", &field_type);

// Remove state generic for the item to be replaced. It sufficient to know `field_type` for
// that since we always move from `Init<#field_type>` to `Init<NEW>`.
let impl_subsystem_state_generics = recollect_without_idx(&subsystem_passthrough_state_generics[..], idx);
Expand Down Expand Up @@ -135,7 +137,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
impl <InitStateSpawner, #field_type, #( #impl_subsystem_state_generics, )* #( #baggage_passthrough_state_generics, )*>
#builder <InitStateSpawner, #( #current_state_generics, )* #( #baggage_passthrough_state_generics, )*>
where
#field_type : Subsystem<#subsystem_ctx_name<#subsystem_consumes>, #error_ty>,
#field_type : Subsystem<#subsystem_ctx_name, #error_ty>,
{
/// Specify the subsystem in the builder directly
pub fn #field_name (self, var: #field_type ) ->
Expand Down Expand Up @@ -179,7 +181,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
impl <InitStateSpawner, #field_type, #( #impl_subsystem_state_generics, )* #( #baggage_passthrough_state_generics, )*>
#builder <InitStateSpawner, #( #post_setter_state_generics, )* #( #baggage_passthrough_state_generics, )*>
where
#field_type : Subsystem<#subsystem_ctx_name<#subsystem_consumes>, #error_ty>,
#field_type : Subsystem<#subsystem_ctx_name, #error_ty>,
{
/// Replace a subsystem by another implementation for the
/// consumable message type.
Expand All @@ -188,7 +190,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
where
#field_type: 'static,
F: 'static + FnOnce(#field_type) -> NEW,
NEW: #support_crate ::Subsystem<#subsystem_ctx_name< #subsystem_consumes >, #error_ty>,
NEW: #support_crate ::Subsystem<#subsystem_ctx_name, #error_ty>,
{
let replacement: Init<NEW> = match self.#field_name {
Init::Fn(fx) =>
Expand Down Expand Up @@ -323,7 +325,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
#builder<Missing<S> #(, Missing<#field_type> )* >
where
#(
#subsystem_generics : Subsystem<#subsystem_ctx_name< #consumes >, #error_ty>,
#subsystem_generics : Subsystem<#subsystem_ctx_names, #error_ty>,
)*
{
#builder :: new()
Expand Down Expand Up @@ -441,7 +443,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
where
#spawner_where_clause,
#(
#subsystem_generics : Subsystem<#subsystem_ctx_name< #consumes >, #error_ty>,
#subsystem_generics : Subsystem<#subsystem_ctx_names, #error_ty>,
)*
{
/// Complete the construction and create the overseer type.
Expand Down Expand Up @@ -518,7 +520,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
// Convert owned `snake case` string to a `kebab case` static str.
let subsystem_static_str = Box::leak(subsystem_string.replace("_", "-").into_boxed_str());

let ctx = #subsystem_ctx_name::< #consumes >::new(
let ctx = #subsystem_ctx_names::new(
signal_rx,
message_rx,
channels_out.clone(),
Expand Down
Loading

0 comments on commit efb1d10

Please sign in to comment.