Commit Graph

3638 Commits

Author SHA1 Message Date
Doug Gregor 92dcbd17c6 [SIL] Explicitly keep the code generation model in SILGlobalVariable
Just like we do with SILFunction, allow a code generation model to be
specified on a SILGlobalVariable and maintain that through the printed
and serialized forms.
2026-05-20 08:35:22 -07:00
Doug Gregor ae942071ae @export(interface|implementation) on a property affects its accessors 2026-05-20 08:35:22 -07:00
Doug Gregor 14bc0baecf Introduce the notion of an "effective" code generation model
The code generation model for a particular declaration or conformance
can be defined explicitly with `@export(interface)`,
`@export(implementation)`, or `@inlinable` (for declarations),
indicating where the definition will occur.

Embedded Swift also has some limitations on what can be emitted into
IR. For example, a generic function cannot be `@export(interface)`
because Embedded Swift does not support unspecialized generics.

Compute the effective code generation model based on what was
explicitly specified, the limitations of the model, and the default
code generation model for the given module, which defaults to
"inlinable" but can be made "implementation" by the DeferredCodeGen
feature. Use the effective code generation model for IR- and SIL-level
determinations of linkage and where to emit symbols.
[WIP] Start computing and using the "effective" code generation model

FIXUP linkage of the alias symbol
2026-05-20 08:35:11 -07:00
Slava Pestov 6b84857d6f AST: Remove useDC parameter from getDynamicMemberLookupKind() 2026-05-08 15:46:20 -04:00
Slava Pestov 29768061ef Sema: Remove useDC parameter from DynamicMemberLookupSubscriptRequest 2026-05-08 15:46:18 -04:00
Slava Pestov 8f5ab7f8e8 Sema: Change assert() to ASSERT() 2026-05-08 15:46:18 -04:00
Slava Pestov 4926234b54 Sema: Remove SubscriptDecl::isValidDynamicMemberLookupSubscript() 2026-05-08 15:46:18 -04:00
Slava Pestov b062b8a285 Convert SubscriptDecl @dynamicMemberLookup checking to request
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
2026-05-08 15:46:17 -04:00
Itai Ferber c191d4994c Cache SubscriptDecl @dynamicMemberLookup eligibility
`SubscriptDecl`s may get checked multiple times for eligibility in
fulfilling `@dynamicMemberLookup` requirements; since the checks are
non-trivial and the result doesn't change, this eligibility can be
cached in the decl's `Bits`.
2026-05-08 15:46:17 -04:00
Doug Gregor f8df6ea1ff Merge pull request #87869 from calda/cal--body-macro-computed-properties
Add support for body macros on variables and accessors
2026-05-03 21:35:34 -07:00
Cal Stephens a2c82139d3 Update check 2026-04-29 16:32:39 -07:00
Hamish Knight 3d09efb607 [AST] NFC: Factor out isMacroExpansionInContext 2026-04-29 23:23:08 +01:00
Pavel Yaskevich eb47ad8d7d [Concurrency] Always set @concurrent isolation on async declarations/closures
Use `@concurrent` regardless of feature flags and explicit `@concurrent` attribute
to make the semantics and diagnostics consistent in all modes.
2026-04-28 09:21:46 -07:00
Konrad Malawski 384a02d980 [Tests] NFC: Update nonisolated -> @concurrent on async declarations 2026-04-28 09:21:23 -07:00
Konrad Malawski 4e4769de49 Rename stale CallerIsolated to NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Konrad Malawski 003028c17c more rename followups for isNonisolated and the enum change 2026-04-28 09:21:23 -07:00
Konrad Malawski 77ac31d946 Rename to ActorIsolation::Kind::Nonisolated*Concurrent* 2026-04-28 09:21:23 -07:00
Konrad Malawski 3beefe5bd8 Rename CallerIsolationInheriting -> NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Cal Stephens 2812f937cb Clean up 2026-04-21 10:43:21 -07:00
Cal Stephens 35b5d0969c Handle sending AccessorDeclSyntax via plugin message 2026-04-21 10:43:20 -07:00
Cal Stephens 45fef8a8af Support body macros on computed properties 2026-04-21 10:43:20 -07:00
Konrad Malawski bfe8dbca59 [Concurrency] Warn about un-used throwing unstructured tasks
Pending swift evolution discussion: https://github.com/swiftlang/swift-evolution/pull/3133

replaces #87171

update new error message according to proposal

also handle untyped throws in _nonDiscardableWhenThrowing attr

Rename the internal attr _nonDiscardableWhenThrowingOperation
2026-04-21 23:53:56 +09:00
Tim Kientzle c46cabde95 Merge pull request #88504 from tbkka/tbkka-yielding-in-swiftinterface
Write `yielding` accessor names to swiftinterface files
2026-04-19 13:35:54 -07:00
Hamish Knight 9cc084e290 Merge pull request #88515 from hamishknight/outer-order
[AST] Use `getOutermostParentSourceFile` in `getAccessScopeForFormalAccess`
2026-04-17 21:22:39 +01:00
Hamish Knight a4f2b0b904 [AST] Use getOutermostParentSourceFile in getAccessScopeForFormalAccess
A fileprivate access scope should always be rooted in the outermost
SourceFile since macros do not introduce their own file access scopes.

rdar://174872704
2026-04-17 11:10:38 +01:00
Doug Gregor 8713c13bef Centralize computation of the "code generation model" for object code & SIL
For a given function, we might end up emitting it's definition as
object code, serialized SIL, or both. The @export, @inlinable, and
@inline(always) attributes provide control of this behavior at the
declaration level.

Centralize the query function that will look for each of these
attributes and map down to a specific "code generation model", whose 3
options follow the naming from SE-0497: interface, inlinable, and
implementation. Use this one computation to back the queries for
"always emit into client", "never emit into client", and "inlinable"
so we can't get inconsistent results from places that are doing
one-off checks for these attributes.
2026-04-15 13:03:55 -07:00
Tim Kientzle c85ebdaed5 Write yielding accessor names to swiftinterface files
Back in January, I updated the swiftinterface _reading_ code to accept either
`read`/`modify` or `yielding borrow`/`yielding mutate`.  That update has been
around for long enough that we can now switch over the swiftinterface _writing_
code to emit the standard final `yielding borrow`/`yielding mutate` spellings.

Interface files written with the old spellings will continue to be
accepted for some time (likely a year or more).
2026-04-15 12:34:46 -07:00
Alexis Laferrière 8d5d16a9f3 Merge branch 'main' into exportability-embedded-class-properties 2026-04-07 08:36:09 -07:00
Doug Gregor fa4c4facae Merge pull request #88325 from DougGregor/dtor-lookup-embedded
Replace an O(n) search for a destructor with a lookup
2026-04-06 15:35:50 -07:00
Doug Gregor ed0acb74d7 Replace an O(n) search for a destructor with a lookup 2026-04-06 10:47:59 -07:00
Alexis Laferrière dd798e0079 Embedded: Accept and enforce @_implementationOnly class properties
When hiding dependencies in embedded mode there are special rules for
classes. Classes properties can safely reference the hidden
dependencies, however code referencing these properties must be marked
`@export(interface)`.

We previously added a check to report implicit code without the requited
`@export(interface)`. However explicit references from user written code
wasn't fully checked, only explicit references to the imported type or
the type's services would be reported, not references to the property
itself.

We patch that hole here by introducing new requirements and a new layer
of check specific to class properies in embedded mode.

---

Class properties referencing a hidden dependency must be marked
`@_implementationOnly`. This adds on top of the requirement for the
class itself to have an explicit `@export(interface) deinit`.

This allows to report references from user written code using existing
diagnostics.
2026-03-24 13:18:23 -07:00
Alexis Laferrière 0b4827c775 Embedded: Check exportability of implicit inits in classes
Without library-evolution we can be more permissive about references to
hidden dependencies from classes properties. However, lifting these
checks broke other checks on properties. Here we fix this hole and
ensure that while we allow references from stored properties we still
checking implicit initializers.

rdar://173011223
2026-03-23 10:49:17 -07:00
Alexis Laferrière 7c1b4802c8 Sema: Require classes to have a deinit for references non Embedded
Even without library-evolution, we allow references to hidden
dependencies from class properties as long as the class is not marked
open. In embedded, references from functions are only accepted when
marked `@export(interface)` as it can't be inlined in clients.

Combine both requirements to protect the implicitly generated destructor
as well. Add a requirement for classes with such a property to
explicitly declare a `@export(interface)` deinit. Otherwise that deinit
may be inlined in clients and cause a deserialization failure.

rdar://170855491
2026-03-12 09:59:59 -07:00
John Hui 9fe81ed792 Merge pull request #87643 from j-hui/frt-rq 2026-03-06 16:11:10 -08:00
John Hui e178af568c [cxx-interop] [NFC] Replace some uses of CxxRecordSemantics
... with ForeignReferenceTypeInfoRequest (which CxxRecordSemantics now
uses under the hood anyway).

rdar://170858418
2026-03-05 14:22:57 -08:00
Meghana Gupta 62b89ec16e Remove blanket restriction of borrow accessors in classes
borrow accessors can be supported in classes when they return 'let' properties, global 'let'.
Remove blanket restriction and add tests for supported cases
2026-03-04 16:03:25 -08:00
Alexis Laferrière deca181658 Merge pull request #87203 from xymus/public-c-impl
Sema: Public `@implementation` signatures can reference hidden dependencies
2026-02-25 09:29:39 -08:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Pavel Yaskevich 7f096ece51 Merge pull request #87389 from xedin/fix-concurrency-issue-with-imported-macro-aliases
[ClangImporter] ImportMacroAliases: Mark imported alias declarations …
2026-02-23 06:58:07 -08:00
Meghana Gupta 7a7dcad44d Diagnose borrow/mutate requirement conformers that are not structs (#87392)
Resolves rdar://170847587
2026-02-22 22:30:23 -08:00
Pavel Yaskevich dc2222095a [ClangImporter] ImportMacroAliases: Mark imported alias declarations as preconcurrency and computed
Extract logic that synthesizes a `VarDecl` for an alias into
`VarDecl::createImported` and set the new declaration as
synthesized, imported and `@preconcurrency`.

Use `makeComputed` to set all the appropriate bits about storage.
2026-02-20 22:20:04 -08:00
Hamish Knight 41524f9591 Merge pull request #87253 from hamishknight/completion 2026-02-19 09:02:58 +00:00
Alexis Laferrière 5fc499cbc5 Sema: @implementation signatures can reference hidden dependencies
Implementations functions marked `@c @implementation` or members of an
`@objc @implementation` aren't part of the Swift API. Their declaration
in C is the API definition, the Swift part only contributes to the ABI.
This allows us to loosen some of the usual exportability checks on these
functions as these checks are only relevant to APIs.

Here we allow such functions to be marked public even if their signature
use types from a restricted import. One may want to do so to set the
symbol visibility. Since the API visibility is determined by how the
C headers are distributed, the restrictions on the import aren't
relevant here.
2026-02-17 15:21:00 -08:00
Kavon Farvardin fa7e9b3437 Merge pull request #87232 from kavon/reparenting-availability-2-redo
Reparenting: handle less-available reparented base protocols
2026-02-17 00:37:29 -08:00
Hamish Knight ff60f5365c [Completion] Explicitly handle witness overrides that should be public
Ensure we correctly handle the case where you're overriding a witness
that should be `public`. Currently this is working as a side-effect
of conformance checking, but we ought to be able to compute it with
lazy type-checking. No test case since it will be covered once we
rip out the eager type-checking in a following commit.
2026-02-16 11:18:49 +00:00
Kavon Farvardin 494b449851 Reparenting: introduce getReparentingProtocols
This centralizes the search for the extension defining
the reparenting.
2026-02-12 15:29:15 -08:00
Susana Monteiro a2babfd44f Merge pull request #86573 from susmonteiro/susmonteiro/cxxpair-non-copyable
[cxx-interop] CxxPair: suppress conformance to Copyable
2026-02-12 13:06:18 +00:00
susmonteiro 04d9f3bc76 [cxx-interop] CxxPair: suppress conformance to Copyable 2026-02-11 20:54:14 +00:00
Artem Chikin f53ccd656d Merge pull request #86934 from artemcm/LiteralExpressionEnumRawValues
[Literal Expressions] Add support for literal expressions in enum raw values
2026-02-10 22:28:59 +00:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00