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

Commit

Permalink
remove no_dispatch from parser
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Apr 29, 2022
1 parent 5042284 commit 97ed4b5
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 89 deletions.
4 changes: 2 additions & 2 deletions node/overseer/overseer-gen/examples/duo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl<Context> GoblinTower {
}
}

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

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

i_like_pi: f64,
Expand Down
24 changes: 1 addition & 23 deletions node/overseer/overseer-gen/examples/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct EvX;

impl EvX {
pub fn focus<'a, T>(&'a self) -> Result<EvX, ()> {
unimplemented!("dispatch")
unimplemented!("focus")
}
}

Expand Down Expand Up @@ -65,25 +65,3 @@ pub struct MsgStrukt(pub u8);

#[derive(Debug, Clone, Copy)]
pub struct Plinko;

impl From<NetworkMsg> for MsgStrukt {
fn from(_event: NetworkMsg) -> Self {
MsgStrukt(1u8)
}
}

#[derive(Debug, Clone, Copy)]
pub enum NetworkMsg {
A,
B,
C,
}

impl NetworkMsg {
pub fn focus(&self) -> Result<Self, WrongVariant> {
Ok(match self {
Self::B => return Err(WrongVariant),
Self::A | Self::C => self.clone(),
})
}
}
4 changes: 2 additions & 2 deletions node/overseer/overseer-gen/examples/solo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ mod misc;

pub use self::misc::*;

#[overlord(signal=SigSigSig, event=EvX, error=Yikes, network=NetworkMsg, gen=AllMessages)]
#[overlord(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)]
struct Solo<T> {
#[subsystem(no_dispatch, consumes: Plinko, sends: [MsgStrukt])]
#[subsystem(consumes: Plinko, sends: [MsgStrukt])]
goblin_tower: GoblinTower,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use quote::{quote, ToTokens};

mod kw {
syn::custom_keyword!(wip);
syn::custom_keyword!(no_dispatch);
syn::custom_keyword!(blocking);
syn::custom_keyword!(consumes);
syn::custom_keyword!(sends);
Expand All @@ -44,9 +43,6 @@ pub(crate) enum SubSysAttrItem {
/// The subsystem is blocking and requires to be
/// spawned on an exclusive thread.
Blocking(kw::blocking),
/// External messages should not be - after being converted -
/// be dispatched to the annotated subsystem.
NoDispatch(kw::no_dispatch),
/// Message to be sent by this subsystem.
Sends(Sends),
/// Message to be consumed by this subsystem.
Expand All @@ -60,8 +56,6 @@ impl Parse for SubSysAttrItem {
Self::Wip(input.parse::<kw::wip>()?)
} else if lookahead.peek(kw::blocking) {
Self::Blocking(input.parse::<kw::blocking>()?)
} else if lookahead.peek(kw::no_dispatch) {
Self::NoDispatch(input.parse::<kw::no_dispatch>()?)
} else if lookahead.peek(kw::sends) {
Self::Sends(input.parse::<Sends>()?)
} else {
Expand All @@ -79,9 +73,6 @@ impl ToTokens for SubSysAttrItem {
Self::Blocking(blocking) => {
quote! { #blocking }
},
Self::NoDispatch(no_dispatch) => {
quote! { #no_dispatch }
},
Self::Sends(_) => {
quote! {}
},
Expand All @@ -94,7 +85,7 @@ impl ToTokens for SubSysAttrItem {
}

/// A field of the struct annotated with
/// `#[subsystem(no_dispatch, , A | B | C)]`
/// `#[subsystem(A, B, C)]`
#[derive(Clone, Debug)]
pub(crate) struct SubSysField {
/// Name of the field.
Expand All @@ -107,9 +98,6 @@ pub(crate) struct SubSysField {
pub(crate) message_to_consume: Path,
/// Types of messages to be sent by the subsystem.
pub(crate) messages_to_send: Vec<Path>,
/// If `no_dispatch` is present, if the message is incoming via
/// an `extern` `Event`, it will not be dispatched to all subsystems.
pub(crate) no_dispatch: bool,
/// If the subsystem implementation is blocking execution and hence
/// has to be spawned on a separate thread or thread pool.
pub(crate) blocking: bool,
Expand Down Expand Up @@ -206,12 +194,10 @@ impl Parse for Consumes {
}
}

/// Parses `(no_dispatch, Foo, sends = [Bar, Baz])`
/// Parses `(Foo, sends = [Bar, Baz])`
/// including the `(` and `)`.
#[derive(Debug, Clone)]
pub(crate) struct SubSystemAttrItems {
#[allow(dead_code)]
pub(crate) no_dispatch: bool,
/// The subsystem is in progress, only generate the `Wrapper` variant, but do not forward messages
/// and also not include the subsystem in the list of subsystems.
pub(crate) wip: bool,
Expand Down Expand Up @@ -258,11 +244,10 @@ impl Parse for SubSystemAttrItems {
))
}

let no_dispatch = extract_variant!(unique, NoDispatch; default = false);
let blocking = extract_variant!(unique, Blocking; default = false);
let wip = extract_variant!(unique, Wip; default = false);

Ok(Self { no_dispatch, blocking, wip, sends, consumes })
Ok(Self { blocking, wip, sends, consumes })
}
}

Expand Down Expand Up @@ -479,7 +464,7 @@ impl OverseerGuts {
}
unique_subsystem_idents.insert(generic.clone());

let SubSystemAttrItems { no_dispatch, wip, blocking, consumes, sends, .. } =
let SubSystemAttrItems { wip, blocking, consumes, sends, .. } =
subsystem_attrs;

// messages to be sent
Expand All @@ -501,7 +486,6 @@ impl OverseerGuts {
generic,
message_to_consume: consumes,
messages_to_send: sends,
no_dispatch,
wip,
blocking,
});
Expand Down
19 changes: 5 additions & 14 deletions node/overseer/overseer-gen/proc-macro/src/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ mod strukt {
});
}

#[test]
fn parse_subsystem_attr_item_works_01_no_dispatch() {
assert_matches!(
syn::parse2::<SubSysAttrItem>(quote! {
no_dispatch
}), Ok(SubSysAttrItem::NoDispatch(_)) => {
});
}

#[test]
fn parse_subsystem_attr_item_works_02_sends() {
assert_matches!(
Expand Down Expand Up @@ -137,7 +128,7 @@ mod strukt {
#[test]
fn parse_subsystem_attributes_works_00() {
syn::parse2::<SubSystemAttrItems>(quote! {
(wip, no_dispatch, blocking, consumes: Foo, sends: [])
(wip, blocking, consumes: Foo, sends: [])
})
.unwrap();
}
Expand Down Expand Up @@ -219,7 +210,7 @@ mod strukt {
fn parse_subsystem_attributes_works_09_neither_consumes_nor_sends() {
assert_matches!(
syn::parse2::<SubSystemAttrItems>(quote! {
(no_dispatch, sends: [])
(sends: [])
}), Err(e) => {
// must either consume smth or sends smth, neither is NOK
dbg!(e)
Expand Down Expand Up @@ -260,7 +251,7 @@ mod strukt {
fn struct_parse_baggage() {
let item: OverseerGuts = parse_quote! {
pub struct Ooooh<X = Pffffffft> where X: Secrit {
#[subsystem(no_dispatch, consumes: Foo, sends: [])]
#[subsystem(consumes: Foo, sends: [])]
sub0: FooSubsystem,

metrics: Metrics,
Expand All @@ -273,13 +264,13 @@ mod strukt {
fn struct_parse_full() {
let item: OverseerGuts = parse_quote! {
pub struct Ooooh<X = Pffffffft> where X: Secrit {
#[subsystem(no_dispatch, consumes: Foo, sends: [])]
#[subsystem(consumes: Foo, sends: [])]
sub0: FooSubsystem,

#[subsystem(blocking, consumes: Bar, sends: [])]
yyy: BaersBuyBilliardBalls,

#[subsystem(no_dispatch, blocking, consumes: Twain, sends: [])]
#[subsystem(blocking, consumes: Twain, sends: [])]
fff: Beeeeep,

#[subsystem(consumes: Rope)]
Expand Down
8 changes: 4 additions & 4 deletions node/overseer/overseer-gen/proc-macro/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ fn print() {

let item = quote! {
pub struct Ooooh<X = Pffffffft> where X: Secrit {
#[subsystem(no_dispatch, Foo)]
#[subsystem(Foo)]
sub0: FooSubsystem,

#[subsystem(blocking, Bar)]
yyy: BaersBuyBilliardBalls,

#[subsystem(no_dispatch, blocking, Twain)]
#[subsystem(blocking, Twain)]
fff: Beeeeep,

#[subsystem(Rope)]
Expand All @@ -57,13 +57,13 @@ fn print() {
fn struct_parse_full() {
let item: OverseerGuts = parse_quote! {
pub struct Ooooh<X = Pffffffft> where X: Secrit {
#[subsystem(no_dispatch, Foo)]
#[subsystem(Foo)]
sub0: FooSubsystem,

#[subsystem(blocking, Bar)]
yyy: BaersBuyBilliardBalls,

#[subsystem(no_dispatch, blocking, Twain)]
#[subsystem(blocking, Twain)]
fff: Beeeeep,

#[subsystem(Rope)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, event=Event, gen=AllMessages)]
struct Overseer {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,

i_like_pie: f64,
Expand Down
4 changes: 2 additions & 2 deletions node/overseer/overseer-gen/tests/ui/err-05-missing-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
struct Overseer {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,
i_like_pie: f64,
}
Expand Down Expand Up @@ -58,4 +58,4 @@ fn main() {
.spawner(DummySpawner)
.build()
.unwrap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
struct Overseer {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,
i_like_pie: f64,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
struct Overseer {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,
i_like_pie: f64,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
struct Overseer {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,
i_like_pie: f64,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MsgStrukt(u8);

#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
struct Overseer<T> {
#[subsystem(no_dispatch, MsgStrukt)]
#[subsystem(MsgStrukt)]
sub0: AwesomeSubSys,
i_like_pie: T,
}
Expand Down
Loading

0 comments on commit 97ed4b5

Please sign in to comment.