Skip to content

[cxx-interop] Runtime support for foreign reference types. #59439

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

Merged
merged 4 commits into from
Jun 17, 2022

Conversation

zoecarver
Copy link
Contributor

This is the first of a few PRs to add a value witness table, metadata, and runtime support for foreign reference types.

@zoecarver zoecarver added the c++ interop Feature: Interoperability with C++ label Jun 14, 2022
@zoecarver zoecarver requested review from rjmccall, hyp and egorzhdan June 14, 2022 19:17
@zoecarver zoecarver force-pushed the frt-metatdata-runtime branch from 595f4ef to f972f66 Compare June 14, 2022 19:18
@@ -53,6 +53,8 @@ NOMINALTYPEMETADATAKIND(Optional, 2 | MetadataKindIsNonHeap)
/// A foreign class, such as a Core Foundation class.
METADATAKIND(ForeignClass, 3 | MetadataKindIsNonHeap)

METADATAKIND(ForeignReferenceType, 4 | MetadataKindIsNonHeap)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rjmccall I have no idea what this value should be.

@@ -1688,7 +1688,7 @@ namespace {
VTable(IGM.getSILModule().lookUpVTable(getType())),
Resilient(IGM.hasResilientMetadata(Type, ResilienceExpansion::Minimal)) {

if (getType()->isForeign() || Type->isForeignReferenceType())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This was just a redundant check.)

@@ -1788,7 +1787,8 @@ namespace {
// is a foreign class.
if ((IGM.IRGen.Opts.ReflectionMetadata !=
ReflectionMetadataMode::Runtime) ||
getType()->isForeign()) {
getType()->isForeign() ||
getType()->isForeignReferenceType()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should remove this (see above).

@zoecarver
Copy link
Contributor Author

@rjmccall can you verify that this won't affect ABI at all for existing metadata? (Specifically with the added METADATAKIND.)

@zoecarver
Copy link
Contributor Author

@swift-ci please test.

@zoecarver zoecarver requested a review from beccadax June 14, 2022 20:32
// Always leave the superclass pointer unfilled. We'll have to
// unique it during initialization anyway, so we might as well spare
// ourselves the load-time work.
B.addNullPointer(IGM.TypeMetadataPtrTy);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this superclass field in the metadata class.

In general, if there isn't any commonality of layout in the metadata classes, I'm not sure we should be using related metadata builder classes; it just ends up obscuring how the code in GenMeta matches the structs in Metadata.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is using ForeignMetadataBuilderBase which seemed generic enough. I'll just make this into a no-op + assert. Let me know if you want me to add another builder, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this again, I see that I am actually using ForeignClassMetadataBuilderBase. I added my own builder for FRTs and updated it to use that. Thanks for pointing this out.

@zoecarver
Copy link
Contributor Author

@swift-ci please test.

@@ -1,7 +1,7 @@
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-llvm-verify -g)
//
// REQUIRES: executable_test
// REQUIRES: foreign-reference-type-metadata-support
// XFAIL: OS=windows-msvc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matches all existing executable tests for foreign reference types.

@zoecarver
Copy link
Contributor Author

@swift-ci please test.

@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

@zoecarver
Copy link
Contributor Author

I'm going to go ahead and merge this. If there are any more comments, I'm happy to address them post-commit (or if necessary, revert).

@zoecarver zoecarver merged commit fd52592 into swiftlang:main Jun 17, 2022
@@ -31,6 +31,7 @@ swift::_swift_isObjCTypeNameSerializable(Class theClass) {
switch (type->getKind()) {
case MetadataKind::ObjCClassWrapper:
case MetadataKind::ForeignClass:
case MetadataKind::ForeignReferenceType:
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 right?

  • Zoe wrote this from the future

@etcwilde
Copy link
Member

The pieces in the runtime directory will need to be back deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants