Skip to content
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

Issue 10194. Variant does not call struct destructors. #2147

Merged
merged 2 commits into from
Jul 14, 2014
Merged

Issue 10194. Variant does not call struct destructors. #2147

merged 2 commits into from
Jul 14, 2014

Conversation

yglukhov
Copy link
Contributor

@yglukhov yglukhov commented May 6, 2014

First commit fixes issue 10194
The second commit adds support for elaborate copying.

@yglukhov yglukhov mentioned this pull request May 6, 2014
@DmitryOlshansky
Copy link
Member

LGTM

@@ -561,6 +578,16 @@ public:
opAssign(value);
}

this(this)
{
fptr(OpID.postblit, &store, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this covered by the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's implicitly covered by lots of tests. But i can add an "explicit" test for that, if needed.

@quickfur
Copy link
Member

ping
Any update since last comment? This looks like an important fix for structs with dtors.

@yglukhov
Copy link
Contributor Author

Well, the only update I have, is trying to call opAssign when appropriate appeared to be a really bulky solution, which I'm not proud of, also it has some bugs, and I didn't manage to debug it yet. I would be really happy if you guys accept the current "always-destruct-on-assign" solution. If you think of that as RAII support, it should be almost-the-same semantically. Also opAssign support could be an additional improvement with a separate PR. What do you think?

@mihails-strasuns
Copy link

I agree. While missing opAssign support will be rather annoying bug current situation is MUCH worse and this PR improves it.

@mihails-strasuns
Copy link

Auto-merge toggled on

@mihails-strasuns
Copy link

Still, if you can come up with update PR which adds opAssign support, that will be very appreciated ;)

mihails-strasuns pushed a commit that referenced this pull request Jul 14, 2014
Issue 10194. Variant does not call struct destructors.
@mihails-strasuns mihails-strasuns merged commit 45fda72 into dlang:master Jul 14, 2014
@yglukhov
Copy link
Contributor Author

Thanx! Regarding opAssign - I'll try my best =)

@yglukhov yglukhov deleted the issue10194 branch July 14, 2014 10:43
@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=13300

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=13303

@yglukhov
Copy link
Contributor Author

Thats a shame. I can suggest the following solutions:

  1. Quick and dirty. Make variant.postblit pure, call fptr, assuming pure. Static assert if type's postblit is not pure, effectively forbidding types with non-pure postblits.
  2. Revert this PR.
    What do you think?

@@ -544,6 +547,20 @@ private:
}
break;

case OpID.postblit:
static if (hasElaborateAssign!A)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to check that A has an elaborate copy operation, you should use std.traits.hasElaborateCopyConstructor.

@yglukhov
Copy link
Contributor Author

Check for elaborate copying corrected: 2437

@yglukhov
Copy link
Contributor Author

The bugs remain open though. The problem is that variant.postblit is not pure. Also, it's not safe and it may throw. Purity, safety and nothrowness are runtime properties of Variant. So maybe it would be safer to always treat variant.postblit as non-pure, @System and throwing, and wrapping it's postblit in assume-blocks where appropriate. And in such case those bugs are no more bugs.

@9rnsr
Copy link
Contributor

9rnsr commented Aug 19, 2014

@yglukhov I opened PR #2439 to fix the regression, which will conditionally define postblit and destructor.

@mihails-strasuns
Copy link

This PR has introduced regression https://issues.dlang.org/show_bug.cgi?id=13871 which is still present in Phobos master.

@mihails-strasuns
Copy link

Reduced test case:

import std.variant;
alias A = Algebraic!(int, typeof(null));
struct B { A value; }
alias C = Algebraic!B;

void main()
{
   C var;
   var = C( B() );
}

Crashes since this PR has been merged.
Ping @yglukhov @9rnsr

@yglukhov
Copy link
Contributor Author

Quick fix: #2826.

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=14062

(This was known since 2015-01-31, I'm only posting here to notify the PR participants)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants