Skip to content

Commit

Permalink
Make InvalidEventHandler signature consistent with normal EventHandlers
Browse files Browse the repository at this point in the history
Summary:
This brings two benefits:

1. The unspecialized EventHandler that calls `SM::InvalidEventHandler` can now simply tail call `InvalidEventHandler`. Prior to this diff, the call to `InvalidEventHandler` depended on the `event` non-type template parameter, which meant that _every_ invalid transition would result in a separate instantiation with distinct code in order to set up the event argument.
2. In a future diff, we can leave the default EventHandler unimplemented and SFIANE the instantiation in `getEventHandler`.

Before:
```
   45594:       f81f0ffe        str     x30, [sp, #-16]!
   45598:       aa0103e2        mov     x2, x1
   4559c:       52800181        mov     w1, #0xc                        // #12
   455a0:       97ffa9dc        bl      2fd10 <_ZN4fizz6client6detail18handleInvalidEventERKNS0_5StateENS_5EventERNS_5ParamE>
```

After:
```
0000000000045374 <_ZN4fizz2sm12EventHandlerINS_6client11ClientTypesELNS2_9StateEnumE3ELNS_5EventE12EE6handleERKNS2_5StateES5_RNS_5ParamE>:
   45374:       f81f0ffe        str     x30, [sp, #-16]!
   45378:       97ffaa68        bl      2fd18 <_ZN4fizz6client6detail18handleInvalidEventERKNS0_5StateENS_5EventERNS_5ParamE>
```

Reviewed By: zalecodez, knekritz

Differential Revision: D58147022

fbshipit-source-id: aa7075ad03528234ef0cd1090d5e9e3629076135
  • Loading branch information
Mingtao Yang authored and facebook-github-bot committed Jun 6, 2024
1 parent fdb847e commit dff7dc1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion fizz/client/ClientProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ Actions handleAppClose(const State& state) {
}
}

Actions handleInvalidEvent(const State& state, Event event, Param& param) {
Actions handleInvalidEvent(const State& state, Param& param) {
auto event = EventVisitor()(param);
if (event == Event::Alert) {
auto& alert = *param.asAlert();
throw FizzException(
Expand Down
2 changes: 1 addition & 1 deletion fizz/client/ClientProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Actions handleError(
Actions handleAppCloseImmediate(const State& state);
Actions handleAppClose(const State& state);

Actions handleInvalidEvent(const State& state, Event event, Param& param);
Actions handleInvalidEvent(const State& state, Param& param);
} // namespace detail

struct ClientTypes {
Expand Down
2 changes: 1 addition & 1 deletion fizz/protocol/StateMachine-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EventHandler : public EventHandlerBase<SM, state, event> {
static typename SM::Actions handle(
const typename SM::State& curState,
typename SM::Param& param) {
return SM::InvalidEventHandler(curState, event, param);
return SM::InvalidEventHandler(curState, param);
}
};

Expand Down
3 changes: 2 additions & 1 deletion fizz/server/ServerProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ Actions handleAppClose(const State& state) {
}
}

Actions handleInvalidEvent(const State& state, Event event, Param& param) {
AsyncActions handleInvalidEvent(const State& state, Param& param) {
auto event = EventVisitor()(param);
if (event == Event::Alert) {
auto& alert = *param.asAlert();
throw FizzException(
Expand Down
2 changes: 1 addition & 1 deletion fizz/server/ServerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Actions handleError(
Actions handleAppCloseImmediate(const State& state);
Actions handleAppClose(const State& state);

Actions handleInvalidEvent(const State& state, Event event, Param& param);
AsyncActions handleInvalidEvent(const State& state, Param& param);
} // namespace detail

struct ServerTypes {
Expand Down

0 comments on commit dff7dc1

Please sign in to comment.