Skip to content

Conversation

@xymus
Copy link
Contributor

@xymus xymus commented Oct 1, 2025

Consider functions in embedded mode to be fragile unless marked with @_neverEmitIntoClient. Basically treating them as if they were @_alwaysEmitIntoClient by default. A fragile function cannot reference restricted imports such as @_implementationOnly, internal import, etc.

We consider them as fragile only for type-checking, at the SIL level they remain treated as normal functions like before. This allows the later optimization to work as expected. We may want to likely align both ends of the compiler once this is properly supported in sema.

This is enabled only in embedded. Fragile functions in library-evolution are marked with attributes and are already checked. We do not need this is non-embedded non-library-evolution as CMO handles inlining and already takes into consideration @_implementationOnly imports.

Note: We'll need a similar check for memory layouts exposed to clients. We can still see compiler crashes and miscompiles in this scenario. This will apply to both embedded and non-library-evolution modes. That will likely need to extend the @_neverEmitIntoClient attribute and may require a staged deployment.

rdar://161365361

@xymus
Copy link
Contributor Author

xymus commented Oct 1, 2025

@swift-ci Please smoke test

@xymus xymus changed the title Sema: In embedded mode, consider functions as fragile unless marked with @_neverEmitIntoClient Sema: In embedded, consider functions as fragile unless @_neverEmitIntoClient Oct 1, 2025
@xymus
Copy link
Contributor Author

xymus commented Oct 1, 2025

@swift-ci Please smoke test

@xymus xymus force-pushed the non-neic-funcs-are-fragile branch from 660baaa to 00d64e1 Compare October 2, 2025 19:54
@xymus
Copy link
Contributor Author

xymus commented Oct 2, 2025

@swift-ci Please smoke test

1 similar comment
@xymus
Copy link
Contributor Author

xymus commented Oct 2, 2025

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Oct 3, 2025

@swift-ci please test

@xymus xymus requested review from artemcm and tshortli October 3, 2025 16:23
@rauhul rauhul added the embedded Embedded Swift label Oct 3, 2025
@xymus
Copy link
Contributor Author

xymus commented Oct 6, 2025

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Oct 6, 2025

@swift-ci Please smoke test Linux

@xymus
Copy link
Contributor Author

xymus commented Oct 7, 2025

@swift-ci Please smoke test Windows

@rauhul rauhul moved this to In Progress in Embedded Swift Oct 9, 2025
xymus added 7 commits October 14, 2025 14:14
Consider functions in embedded mode to be fragile unless marked with
`@_neverEmitIntoClient`. Basically treating them as if they were
`@_alwaysEmitIntoClient` by default. A fragile function cannot reference
restricted imports such as `@_implementationOnly`, `internal import`,
etc.

We consider them as fragile only for type-checking, at the SIL level
they remain treated as normal functions like before. This allows the
later optimization to work as expected. We may want to likely align both
ends of the compiler once this is properly supported in sema.

This is enabled only in embedded. Fragile functions in library-evolution
are marked with attributes and are already checked. We do not need this
is non-embedded non-library-evolution as CMO handles inlining and
already takes into consideration `@_implementationOnly` imports.

Note: We'll need a similar check for memory layouts exposed to clients.
We can still see compiler crashes and miscompiles in this scenario. This
will apply to both embedded and non-library-evolution modes. That will
likely need to extend the `@_neverEmitIntoClient` attribute and may
require a staged deployment.

rdar://161365361
Availability macros are rejected from library-evolution inlinable code
as the compiler didn't know how to print them in the swiftinterface.
This isn't a concern with the embedded style of fragile functions, we
can allow availability macros there.
@xymus xymus force-pushed the non-neic-funcs-are-fragile branch from 991c737 to 9380507 Compare October 14, 2025 21:57
@xymus
Copy link
Contributor Author

xymus commented Oct 14, 2025

@swift-ci Please smoke test

@xymus xymus merged commit 860f2db into swiftlang:main Oct 16, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Embedded Swift Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

embedded Embedded Swift

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants