Commit Graph

22502 Commits

Author SHA1 Message Date
Anton Korobeynikov
0b345097e0 Deconstruct Escapable check for coroutines with normal results 2025-11-13 12:34:16 -08:00
Anton Korobeynikov
263f6e3dd6 Few fixes related to coroutine function types. 2025-11-12 21:02:55 -08:00
Anton Korobeynikov
366b552286 Properly substitute coroutines 2025-11-12 21:02:55 -08:00
Anton Korobeynikov
6c504bb9fa Add parsing of @yield_once and @yields attributes and corresponding type checks 2025-11-12 21:02:55 -08:00
Anton Korobeynikov
76c9a23f27 First cut of making coroutine AST type 2025-11-12 21:02:53 -08:00
Anton Korobeynikov
797f500286 Add basic boilerplate for AST coroutines and yields 2025-11-12 21:02:25 -08:00
Kavon Farvardin
47a6f2acfd Merge pull request #85392 from kavon/borrow-expr-implicit-infra
SILGen: add RValue emission for BorrowExpr
2025-11-12 11:23:52 -08:00
Alexis Laferrière
937e6c5241 Merge pull request #85446 from xymus/serial-xref-check
Serialization: Error on leaked cross-references to `@_implementationOnly` dependencies
2025-11-12 10:42:58 -08:00
Pavel Yaskevich
30b207ecf4 Merge pull request #85418 from xedin/rdar-164267736
[AST/Serialization] A few fixes for `nonisolated(nonsending)` handling
2025-11-12 09:34:49 -08:00
Pavel Yaskevich
47805810be [AST/Serialization] Remove isCallerIsolated bit from ParamDecl
This was used primarily by the printer and doesn't work when
`nonisolated(nonsending)` is inferred, so let's remove it.
2025-11-11 16:07:19 -08:00
Anthony Latsis
8992ea82a2 Merge pull request #85433 from swiftlang/jepa-main4
AST: Rename `GenericContext::isGeneric` to `hasGenericParamList`
2025-11-11 21:12:34 +00:00
Alexis Laferrière
5a49e34426 Serialization: Error on xref to implementation-only dependencies
Introduce a last resort check reporting references to
implementation-only dependencies that would appear in the generated
swiftmodule. This check is applied at serialization, long after
exportability checking applied at typechecking. It should act as a back
stop to references missed by typechecking or @_implementationOnly decls
that should have been skipped.

This check is gated behind CheckImplementationOnlyStrict and should be
used with embedded only.

rdar://160697599
2025-11-11 13:03:16 -08:00
Alexis Laferrière
06db612d79 Sema: Intro the CheckImplementationOnlyStrict feature 2025-11-11 10:26:00 -08:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Hamish Knight
7821c2c89c Merge pull request #85422 from hamishknight/modulo-module
[AST] NFC: Rename `LookupConformanceInModuleRequest` -> `LookupConformanceRequest`
2025-11-11 14:12:12 +00:00
Hamish Knight
5e1279516b [AST] NFC: Rename LookupConformanceInModuleRequest -> LookupConformanceRequest
This request no longer takes a module argument.
2025-11-10 21:25:07 +00:00
Pavel Yaskevich
8ea8a99e99 [AST] Make sure that nonisolated(nonsending) works together with @autoclosure 2025-11-10 11:31:24 -08:00
Pavel Yaskevich
c3ea3031b9 [AST] Fix printing of nonisolated(nonsending) in parameter type positions
Printing shouldn't rely on parameter declaration bit because it only
works in cases when there is an explicit `nonisolated(nonsending)`
modifier on the type.

Always print `nonisolated(nonsending)` before `sending`, `@escaping`
and other declaration attributes/modifiers to avoid parsing issues.

Resolves: rdar://164267736
2025-11-10 11:31:24 -08:00
Hamish Knight
33e6c0fb6c [AST] Also cache protocol kind in getBuiltinInitDecl
Make sure we don't return the wrong witness if you query with 2
different builtin protocol kinds.
2025-11-10 15:57:33 +00:00
Hamish Knight
92e5e7b5b7 [AST] Remove asserts from getBuiltinInitDecl
Allow querying for types that may not conform. Failures here should
be asserted downstream (e.g in `setBuiltinInitializer`).
2025-11-10 15:57:33 +00:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Pavel Yaskevich
5f91e49c9c Merge pull request #85105 from xedin/rdar-140928937
[AST/Sema] Allow `Sendable` suppression on Objective-C class declarations
2025-11-07 15:09:35 -08:00
Kavon Farvardin
314093f426 SILGen: add RValue emission for BorrowExpr 2025-11-07 14:01:35 -08:00
Alexis Laferrière
1e1361f4ee Merge pull request #85369 from xymus/exportability-nle-classes-and-structs
Sema: Exportability check enums and classes in non-library-evolution mode
2025-11-07 09:19:25 -08:00
Doug Gregor
66e7a783a6 Merge pull request #85370 from DougGregor/extern-global-variables 2025-11-06 21:40:24 -08:00
Michael Gottesman
a302d4e627 Merge pull request #85224 from gottesmm/pr-6cb303a9f5f15489fa44c26d00c70155a6d7cc97
[concurrency] Create builtins for invoking specific concurrency runtime functions.
2025-11-06 20:33:16 -08:00
Hamish Knight
8b73c9c717 Merge pull request #85363 from hamishknight/hattrick
[Sema] Avoid member attribute cycle in ResolveMacroRequest
2025-11-07 04:02:44 +00:00
Anton Korobeynikov
89a7663f1d [AutoDiff] Initial support for differentiation of throwing functions (#82653)
This adds initial support for differentiation of functions that may produce `Error` result. 

Essentially we wrap the pullback into `Optional` and emit a diamond-shape control flow pattern depending on whether the pullback value is available or not. VJP emission was modified to accommodate for this. In addition to this, some additional tricks are required as `try_apply` result is not available in the instruction parent block, it is available in normal successor basic block.

As a result we can now:
- differentiate an active `try_apply` result (that would be produced from `do ... try .. catch` constructions)
- `try_apply` when error result is unreachable (usually `try!` and similar source code constructs)
- Support (some) throwing functions with builtin differentiation operators. stdlib change will follow. Though we cannot support typed throws here (yet)
- Correctly propagate error types during currying around differentiable functions as well as type-checking for `@derivative(of:)` attribute, so we can register custom derivatives for functions producing error result
- Added custom derivative for `Optional.??` operator (note that support here is not yet complete as we cannot differentiate through autoclosures, so `x ?? y` works only if `y` is not active, e.g. a constant value).

Some fixes here and there
2025-11-06 13:12:43 -08:00
Hamish Knight
f2b0b92dc1 [Sema] Avoid member attribute cycle in ResolveMacroRequest
If we have a custom attribute on a type that does a qualified lookup
into the same type, we need to be able to expand member attribute
macros for that type. As such, the check to see if we already have
a nominal for the attribute would hit a cycle. Limit this check such
that it only applies to local vars, which is the only case where it
actually matters.

rdar://163961797
2025-11-06 19:33:09 +00:00
Alexis Laferrière
b107169153 Sema: Exportability check super types 2025-11-06 11:30:44 -08:00
Doug Gregor
5b642f548f Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such
variables need to have types represented in C (of course), have only
storage (no accessors), and cannot have initializers. At the SIL
level, we use the SIL asmname attribute to get the appropriate C name.

While here, slightly shore up the `@_extern(c)` checking, which should
fix issue #70776 / rdar://153515764.
2025-11-06 11:09:31 -08:00
Hamish Knight
9981dc8126 [AST] NFC: Move shouldPreferPropertyWrapperOverMacro onto CustomAttr 2025-11-06 14:39:52 +00:00
John Hui
eedefc5d57 [NFC] Delete unused feature SuppressCXXForeignReferenceTypeInitializers (#85301) 2025-11-05 17:12:09 -08:00
Alexis Laferrière
579a228d3f Merge pull request #85179 from xymus/exportability-nle-structs
Sema: Opt-in check for structs references to hidden dependencies in non-library-evolution mode
2025-11-05 15:32:05 -08:00
Michael Gottesman
97b0e2ebae [concurrency] Create builtins for invoking specific concurrency runtime functions.
Specifically:

1. swift_task_addCancellationHandler
2. swift_task_removeCancellationHandler
3. swift_task_addPriorityEscalationHandler
4. swift_task_removePriorityEscalationHandler
5. swift_task_localValuePush
6. swift_task_localValuePop

rdar://109850951
2025-11-05 11:03:44 -08:00
Michael Gottesman
5cb2409ba6 [sil] In SILGenBuiltin a constexpr StringLiteral to reference names of Builtins instead of using raw c strings.
Before this patch we referred to builtin names in SILGenBuiltin using raw c
strings. This can lead to potential spelling mistakes yielding bugs. Rather than
doing this, I stole a technique that we use in other parts of the compiler:
constexpr StringLiteral generation using CPP macros. Specifically, I defined in
Builtins.h a new namespace called BuiltinNames and inside of BuiltinNames I used
CPP macros to define a StringLiteral for each Builtin. Thus one can get the
appropriate name for a Builtin by writing:

```
BuiltinNames::Sizeof
```

instead of writing "Sizeof". I also cleaned up the code a little by adding for
functions that take identifiers an additional overload that takes a StringRef
and converts the StringRef to an identifier internally. This just eliminates
unnecessary code from call sites by moving them into the callee.
2025-11-05 11:02:44 -08:00
John McCall
13937fdb4e Merge pull request #84528 from rjmccall/async-let-runtime-realism
Model async let begin/finish as builtins in SIL
2025-11-05 10:24:46 -08:00
Alexis Laferrière
bf443413b7 Sema: Fix superfluous error about private decls in internal memory layouts
Don't consider implicitly exposed memory layouts when checking for
usable from inline correctness. That check applies only to memory
layouts marked as exposed explicitly. Consider the implict state only at
the general availability checking.
2025-11-04 14:37:10 -08:00
Alexis Laferrière
1383fcda80 Sema: Report non-LE structs as fragile use sites in CheckImplementationOnly
In non-library-evolution mode, gated behind the CheckImplementationOnly
feature flag, consider structs to be a fragile use site by default,
unless marked `@_implementationOnly`. This prevents them to refer to
restricted imports like implementation-only.
2025-11-04 13:50:37 -08:00
Alexis Laferrière
62ee4486d7 Features: Intro CheckImplementationOnly 2025-11-04 13:50:25 -08:00
Kuba (Brecka) Mracek
b6c29f1ce6 Merge pull request #85136 from kubamracek/section-top-level
SE-0492: Handle top-level `@section`-annotated globals
2025-11-04 11:15:50 -08:00
Kavon Farvardin
9c63a5629a Merge pull request #85309 from hamishknight/follow-up
[Sema] A couple of minor follow-ups to #85245
2025-11-04 09:06:58 -08:00
Pavel Yaskevich
3ce0f941e8 Merge pull request #85187 from xedin/rdar-161739470
[AST] NonisolatedNonsendingByDefault: Print `@concurrent` on `nonisol…
2025-11-04 06:28:02 -08:00
Hamish Knight
adb7aaa8cd [AST] NFC: Rename SpecialDistributedProperty -> SpecialDistributedActorProperty
Disambiguate from `distributed var`.
2025-11-04 13:54:34 +00:00
Becca Royal-Gordon
2504beeccc Merge pull request #85043 from beccadax/mod-squad-interface
[SE-0491] Conditionally emit module selectors into swiftinterfaces
2025-11-03 19:08:09 -08:00
Slava Pestov
46b41a3ae4 Merge pull request #85288 from slavapestov/narrow-cxx-roundtrip-carveout
IRGen: Only skip round-trip demangler check for types that involve C++ types
2025-11-03 20:17:10 -05:00
Hamish Knight
0f58eb2104 [Sema] Fix and cleanup distributed id/actorSystem synthesis (#85245) 2025-11-04 10:17:05 +09:00
Hamish Knight
e0de61caa4 Merge pull request #85135 from hamishknight/lazy-fix
[AST] Avoid exposing `lazy` local storage var to name lookup
2025-11-04 00:53:31 +00:00
John McCall
a7d7970e29 Turn finishAsyncLet into a builtin.
This is necessary because we need to model its stack-allocation
behavior, although I'm not yet doing that in this patch because
StackNesting first needs to be taught to not try to move the
deallocation.

I'm not convinced that `async let` *should* be doing a stack allocation,
but it undoubtedly *is* doing a stack allocation, and until we have an
alternative to that, we will need to model it properly.
2025-11-03 16:33:40 -08:00
Doug Gregor
73b03ed414 Merge pull request #85262 from DougGregor/clang-deserialization-near-miss
[Serialization] Allow near-misses when matching imported Clang declarations
2025-11-03 14:16:03 -08:00