Skip to content

ModuleInterface: Avoid printing @_spi enum elements in public swiftinterfaces #62300

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
Dec 1, 2022

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Nov 29, 2022

The @_spi attribute was accepted on enum case declarations but the cases were still printed in public swiftinterfaces, leaking the SPI. The compiler now avoids printing enum cases in public swiftinterfaces when they are declared as @_spi by checking whether the enum case declaration contains any enum elements that are SPI (enum case declarations apparently do not themselves have a copy of the attributes they were written with). The compiler now also diagnoses @_spi on enum case declarations when the enum is @frozen since all the cases of a frozen enum must be known to the client so that the memory layout for the enum can be computed.

This PR also includes tests that show that the exportability of case statements is not checked. Unfortunately this gap is not simple to close since exportability is usually checked during availability checking but availability checking isn't appropriate for case statements and there isn't existing infrastructure to check exportability independently. A follow up PR will be needed to address this.

Resolves rdar://72873771

@@ -1,29 +0,0 @@
// Test limits of SPI members in frozen types.
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 file was deleted because the tests it contains seem to be completely superseded by the spi_members.swift test.

@@ -34,14 +34,6 @@
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Main.swiftinterface
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Main.private.swiftinterface -module-name Main

/// Serialize and deserialize this module, then print.
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 removed this because it interfered with the stability of printing the interface with an enum case declaration like case a, b. It seemed safe to remove to me because there are many other tests exercising serialization and deserialization of the @_spi attribute simply by compiling a helper module with @_spi declarations. If this is still needed for some reason, though, I can split it into a new test case.

These tests identified a gap in type checking the exportability of case statements. Unfortunately this gap is not simple to close, since exportability is usually checked during availability checking but availability checking isn't appropriate for case statements and there isn't existing infrastructure to check exportability independently.
This utility helps codify the practice of using the attributes of the first element of a case decl as the attributes for the entire case.
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli merged commit 25e36ad into swiftlang:main Dec 1, 2022
@tshortli tshortli deleted the spi-enum-cases branch December 1, 2022 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants