Skip to content

Commit

Permalink
Change isset field from bool to uint8_t
Browse files Browse the repository at this point in the history
Summary:
We want to replace `isset` from `bool` to `bit` and we will do it step by step. So in this diff, we will replace `isset` from `bool` to `uint_8` and update related code.

- It will replace:
```
 struct Foo {
 private:
  struct __isset {
    bool field1;
    bool field2;
    // ...
    bool field9;

    bool __fbthrift_get (folly::index_constant<0>) const {
        return field1 ;
    }
    bool __fbthrift_get (folly::index_constant<1>) const {
        return field1;
    }
   ...

    bool __fbthrift_get (folly::index_constant<8>) const {
        return field9;
    }

    void __fbthrift_set (folly::index_constant<0>, bool isset_flag) const {
        field1 = isset_flag;
        return;
    }
    void __fbthrift_set (folly::index_constant<1>, bool isset_flag) const {
        field2 = isset_flag;
        return;
    }
    ...

    void __fbthrift_set (folly::index_constant<8>, bool isset_flag) const {
        field9 = isset_flag;
        return;
    }

  } __isset = {};
  // ...
};
```
with:
```
 struct Foo {
 private:
  struct __isset {
    uint_8 field1;
    uint_8 field2;
    // ...
    uint_8 field9;

    bool __fbthrift_get (folly::index_constant<0>) const {
        return field1 == 1;
    }
    bool __fbthrift_get (folly::index_constant<1>) const {
        return field1 == 1;
    }
   ...

    bool __fbthrift_get (folly::index_constant<8>) const {
        return field9 == 1;
    }

    void __fbthrift_set (folly::index_constant<0>, bool isset_flag) const {
        field1 = isset_flag ? 1 : 0;;
    }
    void __fbthrift_set (folly::index_constant<1>, bool isset_flag) const {
        field2 = isset_flag ? 1 : 0;;
    }
    ...

    void __fbthrift_set (folly::index_constant<8>, bool isset_flag) const {
        field9 = isset_flag ? 1 : 0;;
    }

  } __isset = {};
  // ...
};
```
- Add new functions `make_optional_field_ref` and `make_field_ref` in detail namespace, and replace `optional_field_ref` and `field_ref` with these new functions.

Next steps:
- Change multiple isset fields into a single array of uint8_t
- Compress array of uint8_t into bits.
- Change isset struct into bitset.

Reviewed By: Mizuchi

Differential Revision: D30523019

fbshipit-source-id: 8d1060f89af560c9a5e707cba88dea0c2903d0f7
  • Loading branch information
Jinfeng Chen authored and facebook-github-bot committed Sep 17, 2021
1 parent 90abc80 commit b9f8b44
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 170 deletions.
13 changes: 8 additions & 5 deletions mcrouter/lib/carbon/ReplyCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <memory>

#include <thrift/lib/cpp2/FieldRef.h>
#include "mcrouter/lib/carbon/MessageCommon.h"
#include "mcrouter/lib/carbon/gen-cpp2/carbon_result_types.h"

Expand Down Expand Up @@ -49,17 +50,19 @@ class ReplyCommonThrift : public ReplyCommon {
return result_;
}

apache::thrift::field_ref<const carbon::Result&> result_ref() const& {
return {this->result_, __isset.result};
auto result_ref() const& {
return apache::thrift::detail::make_field_ref(
this->result_, __isset.result);
}

apache::thrift::field_ref<carbon::Result&> result_ref() & {
return {this->result_, __isset.result};
auto result_ref() & {
return apache::thrift::detail::make_field_ref(
this->result_, __isset.result);
}

private:
struct __isset {
bool result;
uint8_t result;
} __isset = {};
carbon::Result result_{carbon::Result::UNKNOWN};
};
Expand Down
6 changes: 3 additions & 3 deletions mcrouter/lib/carbon/test/a/b/gen/BMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SimpleStruct {

private:
struct __isset {
bool member1;
uint8_t member1;
} __isset = {};

int64_t member1_{0};
Expand Down Expand Up @@ -275,7 +275,7 @@ class YetAnotherRequest : public carbon::RequestCommon {

private:
struct __isset {
bool key;
uint8_t key;
} __isset = {};

carbon::Keys<folly::IOBuf> key_;
Expand Down Expand Up @@ -326,7 +326,7 @@ class YetAnotherReply : public carbon::ReplyCommon {

private:
struct __isset {
bool result;
uint8_t result;
} __isset = {};

carbon::Result result_{carbon::Result::UNKNOWN};
Expand Down
4 changes: 2 additions & 2 deletions mcrouter/lib/carbon/test/a/gen/AMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AnotherRequest : public carbon::RequestCommon {

private:
struct __isset {
bool key;
uint8_t key;
} __isset = {};

carbon::Keys<folly::IOBuf> key_;
Expand Down Expand Up @@ -139,7 +139,7 @@ class AnotherReply : public carbon::ReplyCommon {

private:
struct __isset {
bool result;
uint8_t result;
} __isset = {};

carbon::Result result_{carbon::Result::UNKNOWN};
Expand Down
12 changes: 6 additions & 6 deletions mcrouter/lib/carbon/test/b/gen/BMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BaseStruct {

private:
struct __isset {
bool baseInt64Member;
uint8_t baseInt64Member;
} __isset = {};

int64_t baseInt64Member_{0};
Expand Down Expand Up @@ -208,11 +208,11 @@ class SimpleStruct {

private:
struct __isset {
bool _carbon_basestruct_;
bool int32Member;
bool stringMember;
bool enumMember;
bool vectorMember;
uint8_t _carbon_basestruct_;
uint8_t int32Member;
uint8_t stringMember;
uint8_t enumMember;
uint8_t vectorMember;
} __isset = {};

BaseStruct _carbon_basestruct_;
Expand Down
Loading

0 comments on commit b9f8b44

Please sign in to comment.