-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-5682: Move default constructor and operator== implementation to CPP file #2755
Conversation
I don't think that the failing checks are caused by my change. Most of the failing tests are in some other languages, and the C++ tests (which are run with |
Hi @Jens-G , thanks for having a look. How do we proceed with the Jira ticket? Should I contact someone to get a Jira account? If so, whom? The user mailing list did not help. Or are you creating a Jira ticket for this? Thanks! |
We need some info to create the account for you. Send this to jensg at apache dot com and I can do the rest. Sorry for the inconveniences. |
@Jens-G Don't worry, I actually got ahead and contacted a friend who's involved in some other Apache project. I have an account, will create the ticket tomorrow. |
@Jens-G I created a Jira ticket here: https://issues.apache.org/jira/browse/THRIFT-5682 Somehow Jira mangled my code examples, I'll try to clean them up later. |
I would love to move forward with this. I think this is more or less a necessary precondition to use Apache Thrift with C++20 - and even before C++20, the previous behavior is UB. We are using a Thrift version with this patch in production by now. Maybe a review of my proposed changes could be a first step towards a merge? @Jens-G @cyyever @kashirin-alex @zeshuai007 @dsandbrink you contributed to this file "relatively" recently (although it was potentially several years ago - there is not much movement in this file). Maybe one of you would feel up to the task? Thanks a lot in advance! |
I think the changes are fine if they pass C++ tests. |
That would been my next list of things todo, whereas part of app-dev, it
requires extended Flags, for client interface library to be compatible with
all pedantic kind of flags.
I think, These flags, with the generated code use, can indicate that the
mission is accomplished:
-Wdeprecated-copy-dtor
-Weffc++
…On Mon, Apr 3, 2023, 12:15 PM Lukas Barth ***@***.***> wrote:
I would love to move forward with this. I think this is more or less a
necessary precondition to use Apache Thrift with C++20 - and even before
C++20, the previous behavior is UB. We are using a Thrift version with this
patch in production by now. Maybe a review of my proposed changes could be
a first step towards a merge?
@Jens-G <https://github.com/Jens-G> @cyyever <https://github.com/cyyever>
@kashirin-alex <https://github.com/kashirin-alex> @zeshuai007
<https://github.com/zeshuai007> @dsandbrink
<https://github.com/dsandbrink> you contributed to this file "relatively"
recently (although it was potentially several years ago - there is not much
movement in this file). Maybe one of you would feel up to the task? Thanks
a lot in advance!
—
Reply to this email directly, view it on GitHub
<#2755 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHLKBNUJ3STDTJV7HJWZO3W7KILBANCNFSM6AAAAAAUU67ON4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Regarding the main subject , definitions in header and impl. in source
files. Agree.
Undefined type for pointer storage is understandable but storage without
pre defined size for dynamic or not container is a mistake. I haven't
checked but I'm sure std::array would not let to compile.
…On Mon, Apr 3, 2023, 12:44 PM Kashirin Alex ***@***.***> wrote:
That would been my next list of things todo, whereas part of app-dev, it
requires extended Flags, for client interface library to be compatible with
all pedantic kind of flags.
I think, These flags, with the generated code use, can indicate that the
mission is accomplished:
-Wdeprecated-copy-dtor
-Weffc++
On Mon, Apr 3, 2023, 12:15 PM Lukas Barth ***@***.***>
wrote:
> I would love to move forward with this. I think this is more or less a
> necessary precondition to use Apache Thrift with C++20 - and even before
> C++20, the previous behavior is UB. We are using a Thrift version with this
> patch in production by now. Maybe a review of my proposed changes could be
> a first step towards a merge?
>
> @Jens-G <https://github.com/Jens-G> @cyyever <https://github.com/cyyever>
> @kashirin-alex <https://github.com/kashirin-alex> @zeshuai007
> <https://github.com/zeshuai007> @dsandbrink
> <https://github.com/dsandbrink> you contributed to this file
> "relatively" recently (although it was potentially several years ago -
> there is not much movement in this file). Maybe one of you would feel up to
> the task? Thanks a lot in advance!
>
> —
> Reply to this email directly, view it on GitHub
> <#2755 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABHLKBNUJ3STDTJV7HJWZO3W7KILBANCNFSM6AAAAAAUU67ON4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Hi there, for context Apple released a new version of Xcode (which can be auto-updated with the rest of the OS), they might prepare for the Apple Developer Conference and a new Xcode 15 release. In this version of xcode, this error show up when using C++20 mode, while it wasn't the case before, so a lot of code-base are breaking, pytorch for example had this problem. |
One of the failed appveyor job has those, double definitions ? Here it is for reference, if it can gives ideas -> pytorch/pytorch@e7874ee |
Hi @bsergean Yeah, I just started noticing these, too, when I tried to build with the warning settings suggested by @kashirin-alex . I have no clue why I did not see these in my earlier tests. I just pushed the fix for that. |
That’s cool, thanks Lukas.
… On Apr 4, 2023, at 7:48 AM, Lukas Barth ***@***.***> wrote:
Hi @bsergean <https://github.com/bsergean> Yeah, I just started noticing these, too, when I tried to build with the warning settings suggested by @kashirin-alex <https://github.com/kashirin-alex> . I have no clue why I did not see these in my earlier tests. I just pushed the fix for that.
—
Reply to this email directly, view it on GitHub <#2755 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AC2O6UO7FZWWGCJUW53I763W7QYDFANCNFSM6AAAAAAUU67ON4>.
You are receiving this because you were mentioned.
|
Whenever this land in master, in a branch or in a tag release … somewhere :) we can help testing this.
… On Apr 4, 2023, at 7:51 AM, Benjamin Sergeant ***@***.***> wrote:
That’s cool, thanks Lukas.
> On Apr 4, 2023, at 7:48 AM, Lukas Barth ***@***.***> wrote:
>
>
> Hi @bsergean <https://github.com/bsergean> Yeah, I just started noticing these, too, when I tried to build with the warning settings suggested by @kashirin-alex <https://github.com/kashirin-alex> . I have no clue why I did not see these in my earlier tests. I just pushed the fix for that.
>
> —
> Reply to this email directly, view it on GitHub <#2755 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AC2O6UO7FZWWGCJUW53I763W7QYDFANCNFSM6AAAAAAUU67ON4>.
> You are receiving this because you were mentioned.
>
|
Thanks @Jens-G for triggering the CI builds again. I'm not sure whether I interpret the results, especially the failures, correctly:
Failed AppVeyor Builds
This is weird. Usually, MSVC does print an error if it fails to compile / link something…
|
@tinloaf / maybe one way to prove your theory would be to make a separate 'no-op' PR, (say that add #include header somewhere to the generated code), and see if those 3 same errors + the golang one still show up. |
@bsergean I could do that, but I think this would just run the same tests as are run on all commits on However, I think that the failing Go tests have been fixed in 5cdf890. I will rebase this PR on top of the current |
9d6b673
to
42c0656
Compare
I did the rebase - @Jens-G if you approve the workflows to run I think the go tests should pass now. |
Just for clarification @Jens-G - are the failing cross-tests (which I still think are not failing because of this change) blocking this PR? Or is there anything else I can do to help you? Is this a change that's just not wanted in Thrift, in which case we should discuss other ways of getting rid of the UB? Don't get me wrong, I understand this is FOSS software, everyone is doing as much as they can/want, nobody is paid for their time working on this, and everyone has different priorities. I'm just trying to get this moving again. We are using Thrift with this patch applied in production for a while now, it's working, and it would of course be preferrable not to roll our own patched Thrift version. |
I think the cross test failures should be fixed first if caused by this PR. |
The following cross-tests currently fail on the current master (see here):
The following cross-tests fail in this PR:
If I'm not mistaken, the set of faling cross-tests in this PR is a subset of the failing cross-tests on master (which this PR was forked from). Also, none of these cross-tests involve C++, and I only made changes to the C++ generator. Both leads me to believe that my changes do not contribute to breaking all these cross-tests. I'm sorry, but I won't have the time (or the knowledge) to fix all these independently broken cross-tests. If that is a precondition for acceptance of this PR, I will have to abandon it (and just keep using a privately patched Thrift version). |
This is a nice, and very relevant change. I will try to find some time to look into it. @tinloaf could you kindly rebase your changes on latest master and force push one more time, so we get more up-to-date test results? Thanks a lot! |
Both the default constructor and operator== implementations reference certain member functions of the class' members. As an example, the default constructor references (i.e., "uses") the default constructors of its members. If a class contains a std::vector<Foo>, and Foo has only been *forward*- declared (which happens often in Thrift-generated code), this creates undefined behavior: The std::vector specification states that as long as Foo is an incomplete type, it is fine to reference std::vector<Foo>, but not any members (such as its default constructor). Thus, we must defer our default constructor's implementation (which references the default constructor of std::vector<Foo>) to a point where Foo is a complete type. That is the case in the .cpp file. The same holds for operator==.
This makes sure that helper structs like _args and _result also have their default constructors defined.
42c0656
to
2d51167
Compare
Hi @emmenlau , thanks for reviving this. :) I just rebased and force-pushed. It seems that after the rebase, I cannot execute the
Looks like a locale is requested that my system does not have? This may be because I'm working in WSL, but I'm pretty sure it is not caused by my changes, which do not touch anything around locales. Edit: Okay, this was easy, I just needed to generate the |
Hi @emmenlau , is there anything more I can do to help getting this in? |
Hi @emmenlau @Jens-G any chance of getting this moving? It's been over a year now, and as I wrote multiple times already: This PR does not break any of the tests. All the tests reported as broken in this PR are broken because they are broken in We're using a Thrift version patched with this PR in production for over a year now, since it is otherwise impossible to build Thrift-generated code in C++20 mode, as @bsergean confirmed. I will gladly rebase the changes one more time, but only if somebody actually takes a look at them then. Just spending the time of rebasing them every couple of months with zero effect seems kind of a waste. |
You are right. Quite a bunch of eyes had seen/evaluated this so I guess its good to merge now. |
Thanks a lot. :) |
I guess https://issues.apache.org/jira/browse/THRIFT-5682 can be closed as well |
Overview
Both the default constructor and
operator==
implementations reference certain member functions of the class' members. As an example, the default constructor references (i.e., "uses") the default constructors of its members.If a class contains a
std::vector<Foo>
, andFoo
has only been forward declared (which happens often in Thrift-generated code), this creates undefined behavior: Thestd::vector
specification states that as long asFoo
is an incomplete type, it is fine to referencestd::vector<Foo>
, but not any members (such as its default constructor).Thus, we must defer our default constructor's implementation (which references the default constructor of std::vector) to a point where Foo is a complete type. That is the case in the .cpp file.
The same holds for operator==.
Example
Take this very simple Thrift file:
If I compile this using
thrift --gen cpp:no_skeleton -o out ./file.thrift
I get a header file that contains the following (full file here ):In this case, the default constructor for
StructA
references the default constructor ofstd::vector<StructB>
whileStructB
is still an incomplete type. This is undefined behavior. It did apparently compile with all big compilers until recently, but with C++20, Clang 15 stops accepting this kind of construct, as you can see here at CompilerExplorer.Checklist
Note: As far as I can tell, no ticket exists for this.