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 7925 - extern(C++) delegates #13217

Merged
merged 1 commit into from Nov 30, 2021
Merged

Conversation

tim-dlang
Copy link
Contributor

The linkage is already part of the type for delegates. Member functions
for extern(C++) on Win32 use a different calling convention than other
functions. This commit changes the calling convention of extern(C++)
delegates for Win32 to match member functions. The calling convention
for nested functions is also changed, because they can become delegates,
too.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @tim-dlang! 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
7925 enhancement extern(C++) delegates?

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 "master + dmd#13217"

The linkage is already part of the type for delegates. Member functions
for extern(C++) on Win32 use a different calling convention than other
functions. This commit changes the calling convention of extern(C++)
delegates for Win32 to match member functions. The calling convention
for nested functions is also changed, because they can become delegates,
too.
if (tf.linkage == LINK.cpp && !target.is64bit && target.os == Target.OS.Windows)
tym = (tf.parameterList.varargs == VarArg.variadic) ? TYnfunc : TYmfunc;
else
tym = totym(tf);
Copy link
Member

Choose a reason for hiding this comment

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

It looks to me like totym() is in the wrong here, not the caller.

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 looks to me like totym() is in the wrong here, not the caller.

totym() does not know, that the function is used in a delegate, because the argument tf contains the type of funcptr and not the whole delegate. TypeFunction does not seem to have information about the hidden this pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative implementation would be to add a flag to TypeFunction, which marks functions with hidden this pointer. Function tytym could then choose the calling convention based on that flag. The flag could also be used to fix https://issues.dlang.org/show_bug.cgi?id=3720 and https://issues.dlang.org/show_bug.cgi?id=17080, but it would be a bigger change and affect more code. You would probably also need a new syntax for function types with hidden this pointer and a trait for getting the flag.

Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Looks good to me. cc @WalterBright

@RazvanN7 RazvanN7 merged commit 10134cf into dlang:master Nov 30, 2021
@tim-dlang tim-dlang deleted the fix7925 branch November 30, 2021 20:35
MoonlightSentinel added a commit that referenced this pull request Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants