Skip to content

Commit

Permalink
Avoid memory allocation for interface enforcer
Browse files Browse the repository at this point in the history
Summary:
Old:
```
// Compile time interface enforcer
var _ thrift.Struct = &Foo{}
```
New:
```
// Compile time interface enforcer
var _ thrift.Struct = (*Foo)(nil)
```

Why?
* Unnecessary memory allocation is avoided. Profit.

Reviewed By: podtserkovskiy

Differential Revision: D57456069

fbshipit-source-id: 89c05b773e9117a5b5ab20dc528ca0b432282f72
  • Loading branch information
echistyakov authored and facebook-github-bot committed May 17, 2024
1 parent b5151a7 commit 367c418
Show file tree
Hide file tree
Showing 89 changed files with 1,197 additions and 1,197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type {{service:go_name}}ChannelClient struct {
ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ {{service:go_name}}ChannelClientInterface = &{{service:go_name}}ChannelClient{}
var _ {{service:go_name}}ChannelClientInterface = (*{{service:go_name}}ChannelClient)(nil)

func New{{service:go_name}}ChannelClient(channel thrift.RequestChannel) *{{service:go_name}}ChannelClient {
return &{{service:go_name}}ChannelClient{
Expand Down Expand Up @@ -57,8 +57,8 @@ type {{service:go_name}}Client struct {
Mu sync.Mutex
}
// Compile time interface enforcer
var _ {{service:go_name}}ClientInterface = &{{service:go_name}}Client{}
var _ {{service:go_name}}ContextClientInterface = &{{service:go_name}}Client{}
var _ {{service:go_name}}ClientInterface = (*{{service:go_name}}Client)(nil)
var _ {{service:go_name}}ContextClientInterface = (*{{service:go_name}}Client)(nil)

func New{{service:go_name}}Client(prot thrift.Protocol) *{{service:go_name}}Client {
return &{{service:go_name}}Client{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type {{service:go_name}}Processor struct {
{{/service:extends?}}
}
// Compile time interface enforcer
var _ thrift.ProcessorContext = &{{service:go_name}}Processor{}
var _ thrift.ProcessorContext = (*{{service:go_name}}Processor)(nil)

func New{{service:go_name}}Processor(handler {{service:go_name}}) *{{service:go_name}}Processor {
p := &{{service:go_name}}Processor{
Expand Down Expand Up @@ -102,7 +102,7 @@ type {{> svc/proc_func_name}} struct {
handler {{service:go_name}}
}
// Compile time interface enforcer
var _ thrift.ProcessorFunctionContext = &{{> svc/proc_func_name}}{}
var _ thrift.ProcessorFunctionContext = (*{{> svc/proc_func_name}})(nil)

func (p *{{> svc/proc_func_name}}) Read(iprot thrift.Format) (thrift.Struct, thrift.Exception) {
args := newReq{{service:go_name}}{{function:go_name}}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type {{struct:go_name}} struct {
{{/struct:fields_sorted}}
}
// Compile time interface enforcer
var _ thrift.Struct = &{{struct:go_name}}{}
var _ thrift.Struct = (*{{struct:go_name}})(nil)
{{#struct:resp?}}
var _ thrift.WritableResult = &{{struct:go_name}}{}
var _ thrift.WritableResult = (*{{struct:go_name}})(nil)

{{! TODO: resp struct is an internal implementation detail. Can we unexport it? }}
// Deprecated: {{struct:go_public_resp_name}} is deprecated, since it is supposed to be internal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ServiceChannelClient struct {
ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ ServiceChannelClientInterface = &ServiceChannelClient{}
var _ ServiceChannelClientInterface = (*ServiceChannelClient)(nil)

func NewServiceChannelClient(channel thrift.RequestChannel) *ServiceChannelClient {
return &ServiceChannelClient{
Expand All @@ -64,8 +64,8 @@ type ServiceClient struct {
Mu sync.Mutex
}
// Compile time interface enforcer
var _ ServiceClientInterface = &ServiceClient{}
var _ ServiceContextClientInterface = &ServiceClient{}
var _ ServiceClientInterface = (*ServiceClient)(nil)
var _ ServiceContextClientInterface = (*ServiceClient)(nil)

func NewServiceClient(prot thrift.Protocol) *ServiceClient {
return &ServiceClient{
Expand Down Expand Up @@ -107,7 +107,7 @@ type reqServiceFunc struct {
Arg3 *Foo `thrift:"arg3,3" json:"arg3" db:"arg3"`
}
// Compile time interface enforcer
var _ thrift.Struct = &reqServiceFunc{}
var _ thrift.Struct = (*reqServiceFunc)(nil)

// Deprecated: ServiceFuncArgsDeprecated is deprecated, since it is supposed to be internal.
type ServiceFuncArgsDeprecated = reqServiceFunc
Expand Down Expand Up @@ -379,8 +379,8 @@ type respServiceFunc struct {
Success *MyI32_4873 `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = &respServiceFunc{}
var _ thrift.WritableResult = &respServiceFunc{}
var _ thrift.Struct = (*respServiceFunc)(nil)
var _ thrift.WritableResult = (*respServiceFunc)(nil)

// Deprecated: ServiceFuncResultDeprecated is deprecated, since it is supposed to be internal.
type ServiceFuncResultDeprecated = respServiceFunc
Expand Down Expand Up @@ -538,7 +538,7 @@ type ServiceProcessor struct {
handler Service
}
// Compile time interface enforcer
var _ thrift.ProcessorContext = &ServiceProcessor{}
var _ thrift.ProcessorContext = (*ServiceProcessor)(nil)

func NewServiceProcessor(handler Service) *ServiceProcessor {
p := &ServiceProcessor{
Expand Down Expand Up @@ -584,7 +584,7 @@ type procFuncServiceFunc struct {
handler Service
}
// Compile time interface enforcer
var _ thrift.ProcessorFunctionContext = &procFuncServiceFunc{}
var _ thrift.ProcessorFunctionContext = (*procFuncServiceFunc)(nil)

func (p *procFuncServiceFunc) Read(iprot thrift.Format) (thrift.Struct, thrift.Exception) {
args := newReqServiceFunc()
Expand Down Expand Up @@ -660,7 +660,7 @@ type AdapterServiceChannelClient struct {
ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ AdapterServiceChannelClientInterface = &AdapterServiceChannelClient{}
var _ AdapterServiceChannelClientInterface = (*AdapterServiceChannelClient)(nil)

func NewAdapterServiceChannelClient(channel thrift.RequestChannel) *AdapterServiceChannelClient {
return &AdapterServiceChannelClient{
Expand All @@ -677,8 +677,8 @@ type AdapterServiceClient struct {
Mu sync.Mutex
}
// Compile time interface enforcer
var _ AdapterServiceClientInterface = &AdapterServiceClient{}
var _ AdapterServiceContextClientInterface = &AdapterServiceClient{}
var _ AdapterServiceClientInterface = (*AdapterServiceClient)(nil)
var _ AdapterServiceContextClientInterface = (*AdapterServiceClient)(nil)

func NewAdapterServiceClient(prot thrift.Protocol) *AdapterServiceClient {
return &AdapterServiceClient{
Expand Down Expand Up @@ -734,7 +734,7 @@ func (c *AdapterServiceClient) AdaptedTypesContext(ctx context.Context, arg *Hea
type reqAdapterServiceCount struct {
}
// Compile time interface enforcer
var _ thrift.Struct = &reqAdapterServiceCount{}
var _ thrift.Struct = (*reqAdapterServiceCount)(nil)

// Deprecated: AdapterServiceCountArgsDeprecated is deprecated, since it is supposed to be internal.
type AdapterServiceCountArgsDeprecated = reqAdapterServiceCount
Expand Down Expand Up @@ -810,8 +810,8 @@ type respAdapterServiceCount struct {
Success *CountingStruct `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = &respAdapterServiceCount{}
var _ thrift.WritableResult = &respAdapterServiceCount{}
var _ thrift.Struct = (*respAdapterServiceCount)(nil)
var _ thrift.WritableResult = (*respAdapterServiceCount)(nil)

// Deprecated: AdapterServiceCountResultDeprecated is deprecated, since it is supposed to be internal.
type AdapterServiceCountResultDeprecated = respAdapterServiceCount
Expand Down Expand Up @@ -969,7 +969,7 @@ type reqAdapterServiceAdaptedTypes struct {
Arg *HeapAllocated `thrift:"arg,1" json:"arg" db:"arg"`
}
// Compile time interface enforcer
var _ thrift.Struct = &reqAdapterServiceAdaptedTypes{}
var _ thrift.Struct = (*reqAdapterServiceAdaptedTypes)(nil)

// Deprecated: AdapterServiceAdaptedTypesArgsDeprecated is deprecated, since it is supposed to be internal.
type AdapterServiceAdaptedTypesArgsDeprecated = reqAdapterServiceAdaptedTypes
Expand Down Expand Up @@ -1124,8 +1124,8 @@ type respAdapterServiceAdaptedTypes struct {
Success *HeapAllocated `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = &respAdapterServiceAdaptedTypes{}
var _ thrift.WritableResult = &respAdapterServiceAdaptedTypes{}
var _ thrift.Struct = (*respAdapterServiceAdaptedTypes)(nil)
var _ thrift.WritableResult = (*respAdapterServiceAdaptedTypes)(nil)

// Deprecated: AdapterServiceAdaptedTypesResultDeprecated is deprecated, since it is supposed to be internal.
type AdapterServiceAdaptedTypesResultDeprecated = respAdapterServiceAdaptedTypes
Expand Down Expand Up @@ -1287,7 +1287,7 @@ type AdapterServiceProcessor struct {
handler AdapterService
}
// Compile time interface enforcer
var _ thrift.ProcessorContext = &AdapterServiceProcessor{}
var _ thrift.ProcessorContext = (*AdapterServiceProcessor)(nil)

func NewAdapterServiceProcessor(handler AdapterService) *AdapterServiceProcessor {
p := &AdapterServiceProcessor{
Expand Down Expand Up @@ -1335,7 +1335,7 @@ type procFuncAdapterServiceCount struct {
handler AdapterService
}
// Compile time interface enforcer
var _ thrift.ProcessorFunctionContext = &procFuncAdapterServiceCount{}
var _ thrift.ProcessorFunctionContext = (*procFuncAdapterServiceCount)(nil)

func (p *procFuncAdapterServiceCount) Read(iprot thrift.Format) (thrift.Struct, thrift.Exception) {
args := newReqAdapterServiceCount()
Expand Down Expand Up @@ -1386,7 +1386,7 @@ type procFuncAdapterServiceAdaptedTypes struct {
handler AdapterService
}
// Compile time interface enforcer
var _ thrift.ProcessorFunctionContext = &procFuncAdapterServiceAdaptedTypes{}
var _ thrift.ProcessorFunctionContext = (*procFuncAdapterServiceAdaptedTypes)(nil)

func (p *procFuncAdapterServiceAdaptedTypes) Read(iprot thrift.Format) (thrift.Struct, thrift.Exception) {
args := newReqAdapterServiceAdaptedTypes()
Expand Down

0 comments on commit 367c418

Please sign in to comment.