#![allow(
clippy::large_enum_variant,
clippy::type_complexity,
clippy::too_many_arguments
)]
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send, session::Session};
use mpstthree::role::broadcast::RoleBroadcast;
use mpstthree::role::end::RoleEnd;
use mpstthree::{
bundle_struct_fork_close_multi, choose_mpst_multi_to_all, create_multiple_normal_name,
create_multiple_normal_role, create_recv_mpst_session_bundle, create_send_mpst_session_bundle,
offer_mpst,
};
use std::error::Error;
create_multiple_normal_role!(
RoleC, RoleCDual |
RoleS, RoleSDual |
);
create_multiple_normal_name!(NameC, NameS);
create_send_mpst_session_bundle!(
send_mpst_c_to_s, RoleS, 1 | =>
NameC, MeshedChannels, 2
);
create_send_mpst_session_bundle!(
send_mpst_s_to_c, RoleC, 1 | =>
NameS, MeshedChannels, 2
);
create_recv_mpst_session_bundle!(
recv_mpst_c_from_s, RoleS, 1 | =>
NameC, MeshedChannels, 2
);
create_recv_mpst_session_bundle!(
recv_mpst_s_from_c, RoleC, 1 | =>
NameS, MeshedChannels, 2
);
bundle_struct_fork_close_multi!(close_mpst_multi, fork_mpst, MeshedChannels, 2);
type Choose0fromCtoS = Send<Branching0fromCtoS, End>;
type EndpointC0 = MeshedChannels<Recv<(), Choose0fromCtoS>, RoleS<RoleBroadcast>, NameC>;
enum Branching0fromCtoS {
Continue(MeshedChannels<Recv<(), Choose1fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer0fromCtoS = <Choose0fromCtoS as Session>::Dual;
type EndpointS0 = MeshedChannels<Send<(), Offer0fromCtoS>, RoleC<RoleC<RoleEnd>>, NameS>;
enum Branching1fromStoC {
Continue(MeshedChannels<Recv<(), Choose2fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer1fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer1fromStoC = <Choose1fromStoC as Session>::Dual;
type EndpointC1 = MeshedChannels<Offer1fromStoC, RoleS<RoleEnd>, NameC>;
type Choose1fromStoC = Send<Branching1fromStoC, End>;
type EndpointS1 = MeshedChannels<Choose1fromStoC, RoleBroadcast, NameS>;
type Choose2fromCtoS = Send<Branching2fromCtoS, End>;
type EndpointC2 = MeshedChannels<Choose2fromCtoS, RoleBroadcast, NameC>;
enum Branching2fromCtoS {
Continue(
MeshedChannels<Recv<(), Send<(), Offer3fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>,
),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer2fromCtoS = <Choose2fromCtoS as Session>::Dual;
type EndpointS2 = MeshedChannels<Offer2fromCtoS, RoleC<RoleEnd>, NameS>;
type Choose3fromCtoS = Send<Branching3fromCtoS, End>;
type EndpointC3 = MeshedChannels<Choose3fromCtoS, RoleBroadcast, NameC>;
enum Branching3fromCtoS {
Continue(MeshedChannels<Recv<(), Choose4fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer3fromCtoS = <Choose3fromCtoS as Session>::Dual;
type EndpointS3 = MeshedChannels<Offer3fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching4fromStoC {
Continue(MeshedChannels<Recv<(), Choose5fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer4fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer4fromStoC = <Choose4fromStoC as Session>::Dual;
type EndpointC4 = MeshedChannels<Offer4fromStoC, RoleS<RoleEnd>, NameC>;
type Choose4fromStoC = Send<Branching4fromStoC, End>;
type EndpointS4 = MeshedChannels<Choose4fromStoC, RoleBroadcast, NameS>;
type Choose5fromCtoS = Send<Branching5fromCtoS, End>;
type EndpointC5 = MeshedChannels<Choose5fromCtoS, RoleBroadcast, NameC>;
enum Branching5fromCtoS {
Continue(MeshedChannels<Recv<(), Choose6fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer5fromCtoS = <Choose5fromCtoS as Session>::Dual;
type EndpointS5 = MeshedChannels<Offer5fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching6fromStoC {
Continue(MeshedChannels<Recv<(), Choose7fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer6fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer6fromStoC = <Choose6fromStoC as Session>::Dual;
type EndpointC6 = MeshedChannels<Offer6fromStoC, RoleS<RoleEnd>, NameC>;
type Choose6fromStoC = Send<Branching6fromStoC, End>;
type EndpointS6 = MeshedChannels<Choose6fromStoC, RoleBroadcast, NameS>;
type Choose7fromCtoS = Send<Branching7fromCtoS, End>;
type EndpointC7 = MeshedChannels<Choose7fromCtoS, RoleBroadcast, NameC>;
enum Branching7fromCtoS {
Continue(MeshedChannels<Recv<(), Choose8fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer7fromCtoS = <Choose7fromCtoS as Session>::Dual;
type EndpointS7 = MeshedChannels<Offer7fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching8fromStoC {
Continue(MeshedChannels<Recv<(), Choose9fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Choose7fromCtoS>, RoleS<RoleBroadcast>, NameC>),
}
type Offer8fromStoC = <Choose8fromStoC as Session>::Dual;
type EndpointC8 = MeshedChannels<Offer8fromStoC, RoleS<RoleEnd>, NameC>;
type Choose8fromStoC = Send<Branching8fromStoC, End>;
type EndpointS8 = MeshedChannels<Choose8fromStoC, RoleBroadcast, NameS>;
type Choose9fromCtoS = Send<Branching9fromCtoS, End>;
type EndpointC9 = MeshedChannels<Choose9fromCtoS, RoleBroadcast, NameC>;
enum Branching9fromCtoS {
Continue(
MeshedChannels<
Recv<(), Send<(), Recv<(), Recv<(), Offer10fromCtoS>>>>,
RoleC<RoleC<RoleC<RoleC<RoleC<RoleEnd>>>>>,
NameS,
>,
),
Loop(MeshedChannels<Recv<(), Send<(), Offer9fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
}
type Offer9fromCtoS = <Choose9fromCtoS as Session>::Dual;
type EndpointS9 = MeshedChannels<Offer9fromCtoS, RoleC<RoleEnd>, NameS>;
type Choose10fromCtoS = Send<Branching10fromCtoS, End>;
type EndpointC10 = MeshedChannels<Choose10fromCtoS, RoleBroadcast, NameC>;
enum Branching10fromCtoS {
Data(MeshedChannels<Recv<(), Recv<(), Offer10fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
Subject(
MeshedChannels<Recv<(), Recv<(), Offer10fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>,
),
End(MeshedChannels<Recv<(), Send<(), Offer7fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
}
type Offer10fromCtoS = <Choose10fromCtoS as Session>::Dual;
type EndpointS10 = MeshedChannels<Offer10fromCtoS, RoleC<RoleEnd>, NameS>;
fn endpoint_c_init(s: EndpointC0) -> Result<(), Box<dyn Error>> {
endpoint_c_0(s, 100)
}
fn endpoint_c_0(s: EndpointC0, loops: i32) -> Result<(), Box<dyn Error>> {
let (_, s) = recv_mpst_c_from_s(s)?;
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching0fromCtoS::Quit, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
close_mpst_multi(s)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching0fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
endpoint_c_1(s, loops)
}
}
}
fn endpoint_c_1(s: EndpointC1, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_c_from_s, {
Branching1fromStoC::Continue(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_2(s, loops)
},
Branching1fromStoC::Loop(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_1(s, loops)
},
})
}
fn endpoint_c_2(s: EndpointC2, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching2fromCtoS::Quit, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
close_mpst_multi(s)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching2fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_3(s, loops)
}
}
}
fn endpoint_c_3(s: EndpointC3, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching3fromCtoS::Quit, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
close_mpst_multi(s)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching3fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
endpoint_c_4(s, loops)
}
}
}
fn endpoint_c_4(s: EndpointC4, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_c_from_s, {
Branching4fromStoC::Continue(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_5(s, loops)
},
Branching4fromStoC::Loop(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_4(s, loops)
},
})
}
fn endpoint_c_5(s: EndpointC5, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching5fromCtoS::Quit, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
close_mpst_multi(s)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching5fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
endpoint_c_6(s, loops)
}
}
}
fn endpoint_c_6(s: EndpointC6, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_c_from_s, {
Branching6fromStoC::Continue(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_7(s, loops)
},
Branching6fromStoC::Loop(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_6(s, loops)
},
})
}
fn endpoint_c_7(s: EndpointC7, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching7fromCtoS::Quit, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
close_mpst_multi(s)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching7fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
endpoint_c_8(s, loops)
}
}
}
fn endpoint_c_8(s: EndpointC8, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_c_from_s, {
Branching8fromStoC::Continue(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_9(s, loops)
},
Branching8fromStoC::Loop(s) => {
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_7(s, loops)
},
})
}
fn endpoint_c_9(s: EndpointC9, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching9fromCtoS::Loop, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_9(s, loops)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching9fromCtoS::Continue, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let (_, s) = recv_mpst_c_from_s(s)?;
let s = send_mpst_c_to_s((), s);
let s = send_mpst_c_to_s((), s);
endpoint_c_10(s, loops)
}
}
}
fn endpoint_c_10(s: EndpointC10, loops: i32) -> Result<(), Box<dyn Error>> {
if loops == 0 {
let s = choose_mpst_multi_to_all!(
s,
Branching10fromCtoS::End, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let (_, s) = recv_mpst_c_from_s(s)?;
endpoint_c_7(s, loops)
} else if loops % 2 == 1 {
let s = choose_mpst_multi_to_all!(
s,
Branching10fromCtoS::Subject, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let s = send_mpst_c_to_s((), s);
endpoint_c_10(s, loops - 1)
} else {
let s = choose_mpst_multi_to_all!(
s,
Branching10fromCtoS::Data, =>
NameC, MeshedChannels, 1
);
let s = send_mpst_c_to_s((), s);
let s = send_mpst_c_to_s((), s);
endpoint_c_10(s, loops - 1)
}
}
fn endpoint_s_init(s: EndpointS0) -> Result<(), Box<dyn Error>> {
endpoint_s_0(s, 100)
}
fn endpoint_s_0(s: EndpointS0, loops: i32) -> Result<(), Box<dyn Error>> {
let s = send_mpst_s_to_c((), s);
offer_mpst!(s, recv_mpst_s_from_c, {
Branching0fromCtoS::Quit(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
close_mpst_multi(s)
},
Branching0fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_1(s, loops)
},
})
}
fn endpoint_s_1(s: EndpointS1, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching1fromStoC::Loop, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_1(s, loops)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching1fromStoC::Continue, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_2(s, loops)
}
}
}
fn endpoint_s_2(s: EndpointS2, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching2fromCtoS::Quit(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
close_mpst_multi(s)
},
Branching2fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let s = send_mpst_s_to_c((), s);
endpoint_s_3(s, loops)
},
})
}
fn endpoint_s_3(s: EndpointS3, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching3fromCtoS::Quit(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
close_mpst_multi(s)
},
Branching3fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_4(s, loops)
},
})
}
fn endpoint_s_4(s: EndpointS4, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching4fromStoC::Loop, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_4(s, loops)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching4fromStoC::Continue, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_5(s, loops)
}
}
}
fn endpoint_s_5(s: EndpointS5, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching5fromCtoS::Quit(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
close_mpst_multi(s)
},
Branching5fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_6(s, loops)
},
})
}
fn endpoint_s_6(s: EndpointS6, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching6fromStoC::Loop, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_6(s, loops)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching6fromStoC::Continue, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_7(s, loops)
}
}
}
fn endpoint_s_7(s: EndpointS7, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching7fromCtoS::Quit(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
close_mpst_multi(s)
},
Branching7fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_8(s, loops)
},
})
}
fn endpoint_s_8(s: EndpointS8, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_multi_to_all!(
s,
Branching8fromStoC::Loop, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_7(s, loops)
}
_ => {
let s = choose_mpst_multi_to_all!(
s,
Branching8fromStoC::Continue, =>
NameS, MeshedChannels, 2
);
let s = send_mpst_s_to_c((), s);
endpoint_s_9(s, loops)
}
}
}
fn endpoint_s_9(s: EndpointS9, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching9fromCtoS::Loop(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let s = send_mpst_s_to_c((), s);
endpoint_s_9(s, loops)
},
Branching9fromCtoS::Continue(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let s = send_mpst_s_to_c((), s);
let (_, s) = recv_mpst_s_from_c(s)?;
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_10(s, loops)
},
})
}
fn endpoint_s_10(s: EndpointS10, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, recv_mpst_s_from_c, {
Branching10fromCtoS::Data(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_10(s, loops - 1)
},
Branching10fromCtoS::Subject(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let (_, s) = recv_mpst_s_from_c(s)?;
endpoint_s_10(s, loops - 1)
},
Branching10fromCtoS::End(s) => {
let (_, s) = recv_mpst_s_from_c(s)?;
let s = send_mpst_s_to_c((), s);
endpoint_s_7(s, loops - 1)
},
})
}
fn aux() {
let (thread_c, thread_s) = fork_mpst(black_box(endpoint_c_init), black_box(endpoint_s_init));
thread_c.join().unwrap();
thread_s.join().unwrap();
}
pub fn smtp(c: &mut Criterion) {
c.bench_function("SMTP basic", |b| b.iter(aux));
}
criterion_group! {
name = bench;
config = Criterion::default().significance_level(0.05).without_plots().sample_size(100000);
targets = smtp,
}
criterion_main! {
bench
}