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

Fix Issue 21613 - DMD crash: copy ctor + templated rvalue ctor #13687

Merged
merged 1 commit into from
Jan 26, 2023

Conversation

RazvanN7
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21613 critical DMD crash: copy ctor + templated rvalue ctor

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#13687"


continue;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copying this code isn't a good solution. Maybe this bug indicates that the checks done in dsymbolsem.d are not in the right location to begin with. But at the very least move the logic into a common function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check in dsymbolsem is definitely in the right location. The problem is that function resolution does not fully instantiate a templated function (i.e. it does not perform any semantic analysis) to check whether it is a match or not. It just creates a dummy template instance to check the constraints. Bypassing semantic analysis is the problem here, that's why we need to redo the check.

void main(){
const Test cb;
Test b = cb;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add this test to fail_compilation/test22593.d because it checks another manifestation of the same error.

auto ad = fd.isThis();
auto sd = ad.isStructDeclaration();
immutable dim = tf.parameterList.length;
if (sd && sd.hasCopyCtor && (dim == 1 || (dim > 1 && tf.parameterList[1].defaultArg)) )
Copy link
Member

@PetarKirov PetarKirov Mar 22, 2022

Choose a reason for hiding this comment

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

I see that the almost the same condition appears in two other places:

Can you refactor the code by adding a function that better clarifies the intent?

Edit: Nevermind, I didn't see that @MoonlightSentinel had posted a similar comment (I was reviewing with comments/annotations off).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the difference between the 2 occurrences you provided is that one checks for an rvalue constructor, whereas the other one checks for a copy constructor. I would conflate the two.

Copy link
Contributor Author

@RazvanN7 RazvanN7 May 26, 2022

Choose a reason for hiding this comment

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

What I can do is to put the rvalue constructor check in a function and look in a subsequent PR to create a function isSpecialConstructor which receives a TypeFunction and returns an enum value from enum CtorType { Normal, CopyConstructor, RvalueConstructor}

@ibuclaw
Copy link
Member

ibuclaw commented Jan 15, 2023

@RazvanN7 going to rebase and finish this?

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jan 16, 2023

@9il it seems that this PR causes a breakage in mir/core. To me it looks like Algebraic ends up defining both a copy constructor and an rvalue constructor. Could you please update the code so that that does not happen anymore?

Edit: Offending code:

    Variant!S a = S();
    auto b = a;

Variant (which is an alias to Algebraic) defines a copy constructor because S defines a copy constructor. Algebraic also defines a templated constructor which is also tried auto b = a is semantically analyzed. This leads to the compiler seeing the possibility of this struct having both an rvalue constructor and a copy constructor.

I think we can get away by simply adding a constraint that excludes the constructor when the RHSTypes matches the instantiation types.

@RazvanN7
Copy link
Contributor Author

PR: libmir/mir-core#81

@RazvanN7
Copy link
Contributor Author

@ibuclaw this should be ready to go once libmir/mir-core#81 is in.

@RazvanN7
Copy link
Contributor Author

@ibuclaw this is ready to go.

@dlang-bot dlang-bot merged commit 353f2b6 into dlang:stable Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants