Skip to content

[cxx-interop] Teach importer to interpret lifetimebound annotations #76311

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 1 commit into from
Sep 18, 2024

Conversation

Xazax-hun
Copy link
Contributor

@Xazax-hun Xazax-hun commented Sep 6, 2024

The lifetimebound annotations are now imported as lifetime dependencies. This works for basic cases but there are still some parts missing:

  • Support lifeitmebound annotations on constructors
  • A way to represent immortal/static lifetimes on the C++ side

rdar://135875896

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Sep 6, 2024
@Xazax-hun Xazax-hun force-pushed the gaborh/import-lifetimebound branch 2 times, most recently from c349cab to 00965c2 Compare September 10, 2024 17:44
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

I only have a couple comments regarding tests, otherwise LGTM.

}

//--- test.swift

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a module interface test that would check that the Swift lifetime attributes are printed in the generated interface for a C++ module?

See test/Interop/Cxx/class/access-specifiers-module-interface.swift for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the Swift lifetimes are not supported by the module printer yet as there is no official/final syntax for it. That being said, I added checks like that because it is still useful to see what parameters are imported as borrowing. Let me know if that looks good.

Copy link
Contributor

Choose a reason for hiding this comment

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

@meg-gupta is planning to add @lifetime() annotations to the module printer.
rdar://130342167 ([nonescapable] add .swiftinterface support for lifetime dependence)

Copy link
Contributor

Choose a reason for hiding this comment

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

You can write an -emit-sil test like test/SIL/lifetime_dependence_buffer_view_test.swift to ensure that the SIL representation has _scope/ _inherit in the interim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A slightly unrelated comment: I might be missing something but lifetime_dependence_buffer_view_test.swift does not seem to invoke FileCheck? Is that intentional, or a bug?

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 updated the test to check the SIL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. I'll fix lifetime_dependence_buffer_view_test.swift to include FileCheck!

@Xazax-hun Xazax-hun force-pushed the gaborh/import-lifetimebound branch from 00965c2 to a810bea Compare September 12, 2024 10:44
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@atrick atrick requested a review from meg-gupta September 13, 2024 17:46
@atrick
Copy link
Contributor

atrick commented Sep 13, 2024

This all looks reasonable to me.

@Xazax-hun Xazax-hun force-pushed the gaborh/import-lifetimebound branch 2 times, most recently from 5e317ec to beddb76 Compare September 16, 2024 16:35
Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

LGTM, the tests that I was asking for can be added in a follow-up patch, once the module interface printer is aware of lifetime attributes.

The lifetimebound annotations are now imported as lifetime dependencies.
This works for basic cases but there are still some parts missing:
* Support lifeitmebound annotations on constructors
* A way to represent immortal/static lifetimes on the C++ side
@Xazax-hun Xazax-hun force-pushed the gaborh/import-lifetimebound branch from beddb76 to 16e012b Compare September 18, 2024 09:51
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun merged commit ffa1014 into main Sep 18, 2024
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/import-lifetimebound branch September 18, 2024 14:24
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.

4 participants