-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Remove inline typeconvert when logging some thrift typedefs #464
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #464 +/- ##
==========================================
+ Coverage 78.96% 79.00% +0.03%
==========================================
Files 125 125
Lines 15981 16048 +67
==========================================
+ Hits 12620 12678 +58
- Misses 2056 2060 +4
- Partials 1305 1310 +5
Continue to review full report at Codecov.
|
gen/zap.go
Outdated
// zapTypedefGenerateMarshaler is similar to zapMarshaler but always converts a typedef | ||
// to its root value. This should be used when generating the code for the Zap | ||
// marshal implementation of the typedef. | ||
func (z *zapGenerator) zapTypedefGenerateMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we need this separate function exposed in the template? Looks
like zapMarshaler can (and does) already do this if spec is a
compile.TypedefSpec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This zapMarshaler
is used in the template that generates MarshalLogObject
/MarshalLogArray
for typedef, as well as in the template for other object's MarshalLog...
function if they have typedef for a field. In the field case you want to not convert to the underlying go type, in the other one you need to typeconvert to the underlying to avoid the typedef's generated MarshalLog...
to call itself.
To avoid adding adding an extra parameter to zapMarshaler
(something like forceTypedefToRoot bool
), I made/exported a new function.
fa663f4
to
46a6854
Compare
#366 added fast zap logging by generating extra `MarshalLog...` methods on generated types. For typedefs in thrift, other types that log them will cast to the underlying type in their `MarshalLog...` method, causing the generated code to need to import multiple go packages generated from both direct and indirect thrift dependencies. This should not be necessary, as typedefs of complex types (anything that cannot be mapped directly to a go stdlb type) get their own `MarshalLog...` methods, which cast to underlying type when necessary. This PR changes the logging for typedef'ed fields to: - cast to the underlying type inline when the underlying thrift type directly maps to a go type. - defer to the typedef's generated `MarshalLog...` method otherwise. This results in having more predictable importpaths (eg knowing that one thrift import will lead to one go import in generated code) makes implementing good bazel rules for thriftrw easier. See internal issue GO-362 for a more elaborate example of how the current behaviour complicates our Bazel setup.
46a6854
to
bbdb77f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM.
To address coverage drop, check out gen/quick_test.go. We need to add newly declared types there.
Co-authored-by: Abhinav Gupta <abg@uber.com>
#366 added fast zap logging by generating extra `MarshalLog...` methods on generated types. For typedefs in thrift, other types that log them will cast to the underlying type in their `MarshalLog...` method, causing the generated code to need to import multiple go packages generated from both direct and indirect thrift dependencies. This should not be necessary, as typedefs of complex types (anything that cannot be mapped directly to a go stdlib type) get their own `MarshalLog...` methods, which cast to underlying type when necessary. This PR changes the logging for typedef'ed fields to: - cast to the underlying type inline when the underlying thrift type directly maps to a go type. - defer to the typedef's generated `MarshalLog...` method otherwise. This results in having more predictable importpaths (eg knowing that one thrift import will lead to one go import in generated code) makes implementing good bazel rules for thriftrw easier. See internal issue GO-362 for a more elaborate example of how the current behaviour complicates our Bazel setup. Co-authored-by: Abhinav Gupta <abg@uber.com>
#366 added fast zap logging
by generating extra
MarshalLog...
methods on generated types. Fortypedefs in thrift, other types that log them will cast to the
underlying type in their
MarshalLog...
method, causing the generatedcode to need to import multiple go packages generated from both direct
and indirect thrift dependencies.
This should not be necessary, as typedefs of complex types (anything
that cannot be mapped directly to a go stdlb type) get their own
MarshalLog...
methods, which cast to underlying type when necessary.This PR changes the logging for typedef'ed fields to:
directly maps to a go type.
MarshalLog...
method otherwise.This results in having more predictable importpaths (eg knowing that one
thrift import will lead to one go import in generated code) makes
implementing good bazel rules for thriftrw easier.
See internal issue GO-362 for a more elaborate example of how the
current behaviour complicates our Bazel setup.