Commit Graph

6969 Commits

Author SHA1 Message Date
Anton Korobeynikov
263f6e3dd6 Few fixes related to coroutine function types. 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
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
Hamish Knight
fb62a8538f Merge pull request #85436 from hamishknight/add-assert
[SILGen] Add assert to `emitApplyAllocatingInitializer`
2025-11-11 21:29:52 +00: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
Doug Gregor
2002b90531 Merge pull request #85425 from DougGregor/irgen-multithreaded-lazy-global-var
[IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen
2025-11-11 13:10:00 -08:00
Hamish Knight
90bc9a12c7 [SILGen] Add assert to emitApplyAllocatingInitializer
Make sure we reliably assert in release builds if `getBuiltinInitDecl`
passes a null value here.
2025-11-11 15:58:24 +00: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
Doug Gregor
bce3fa000b [IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen
With multi-threaded IRGen, the global variables associated with "once"
initialization tokens were not getting colocated with their actual
global variables, which caused the initialization code to get split
across different files. This issue manifest as autolinking errors in
some projects.

Fixes rdar://162400654.
2025-11-10 23:08:57 -08:00
Slava Pestov
522a6b7c80 SILGen: Fix break/continue inside 'for ... in ... repeat' loop
We were creating the JumpDests too early, so lowering a 'break' or 'continue'
statement would perform cleanups that were recorded while evaluating the
pack expansion expression, which would cause SIL verifier errors and
runtime crashes.

- Fixes https://github.com/swiftlang/swift/issues/78598
- Fixes rdar://131847933
2025-11-10 20:51:45 -05:00
Meghana Gupta
e2123e1b3b Merge pull request #85362 from meg-gupta/moreborrow
Add SIL verification for borrow and mutate accessors and some other minor fixes
2025-11-10 09:04:28 -08: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
Kavon Farvardin
314093f426 SILGen: add RValue emission for BorrowExpr 2025-11-07 14:01:35 -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
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
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
Meghana Gupta
290d2f00a3 Fix mark_unresolved_noncopyable_value instruction introduced for mutate accessor result 2025-11-06 10:55:43 -08:00
Meghana Gupta
d50aa8ad87 [NFC] Comment on the use of unchecked_ownership 2025-11-06 10:55:41 -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
Hamish Knight
80f426e6bb [SILGen] NFC: Remove unused var 2025-11-04 14:58:06 +00:00
Hamish Knight
adb7aaa8cd [AST] NFC: Rename SpecialDistributedProperty -> SpecialDistributedActorProperty
Disambiguate from `distributed var`.
2025-11-04 13:54:34 +00: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
John McCall
cd67912a50 Remove the deprecated and unused endAsyncLet builtin. 2025-11-03 13:45:18 -08:00
John McCall
1d95fe14de Remove the deprecated and unused startAsyncLet builtin 2025-11-03 13:44:58 -08:00
Slava Pestov
4677512a74 Merge pull request #84664 from jamieQ/fix-iso-default-param-idx-bug
[SILGen]: fix a bug in isolated default argument handling
2025-10-30 03:40:49 -04:00
Slava Pestov
778281ace9 Merge pull request #84951 from jamieQ/fix-address-only-DI
[SILGen]: ban forward captures of let temporary allocations
2025-10-29 22:23:42 -04:00
Hamish Knight
55ebd0774e [AST] Avoid exposing lazy local storage var to name lookup
We already reject attempts to reference this for `lazy` properties.
For `lazy` locals let's just not expose it to name lookup to begin
with. This ensures we don't attempt to prematurely kick the interface
type computation for the var, fixing a couple of crashers.
2025-10-25 15:07:11 +01:00
Hamish Knight
a341c86f3c [AST] NFC: Rename VarDecl::visitAuxiliaryDecls -> visitAuxiliaryVars
Make it more obvious it's different to `Decl::visitAuxiliaryDecls`.
2025-10-25 15:07:11 +01:00
Allan Shortlidge
17a87065b7 Merge pull request #85130 from tshortli/refactor-version-remap
AST: Refactor availability version remapping
2025-10-25 01:40:42 -07:00
Kavon Farvardin
03d61ed75a Merge pull request #85090 from kavon/manual-ownership/usability-fixes-6
ManualOwnership: provide ability to apply to entire compilation unit
2025-10-25 00:15:03 -07:00
Anton Korobeynikov
186f88bead [AutoDiff] Fix two issues related with emission of differentiability witnesses (#80983)
1. When differentiable nested function (closure) is specialized by capture promotion pass ensure we generate a differentiability witness for the specialized function as well. Ensure the original witness is removed if the original function becomes dead. 
2. Differentiability witnesses for a function could originate either from its `@differentiable` attribute or from explicit `@derivative(of:)` attribute on the derivative. In the latter case the derivative itself might not be emitted, while original function is (e.g. original function is `@inlineable`, but derivative is `@usableFromInline`). Previously both cases were handled only when function body was emitted. As a result we missed witness in the aforementioned case. Ensure the
differentiability witness originating from `@derivative(of:)` is emitted even if we're not going to emit body of the derivative.

Fixes #59135
2025-10-24 20:02:08 -07:00
Kavon Farvardin
2d881bdc9c ManualOwnership: provide ability to apply to entire compilation unit
With this patch, I'm flipping the polarity of things.

The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics,
but they're all silenced by default. So, you need to add -Wwarning or -Werror to
your build settings to turn on the specific diagnostics you care about.

These are the diagnostic groups relevant to the feature:

- SemanticCopies aka "explicit copies mode"
- DynamicExclusivity

For example, the build setting `-Werror SemanticCopies` now gives you errors about
explicit copies, just as before, but now you can make them just warnings with -Wwarning.

To opt-out a declaration from everything when using the feature, use @_noManualOwnership.

@_manualOwnership is no longer an attribute as a result.

resolves rdar://163372569
2025-10-24 18:54:07 -07:00
Allan Shortlidge
88bc79f6af AST: Remove unnecessary ASTContext argument.
There's no need to take one as input to a method on `Decl`. NFC.
2025-10-24 16:20:02 -07:00
Kavon Farvardin
38c61d7dd6 Merge pull request #85054 from kavon/opaque-values/fixes-3
OpaqueValues: add support for property wrappers
2025-10-23 22:18:54 -07:00
Kavon Farvardin
19bd65c89b OpaqueValues: add support for property wrappers
resolves rdar://163071245
2025-10-23 16:31:01 -07:00
Meghana Gupta
7c25466b21 Avoid unnecessary insertion of mark_unresolved_noncopyable_value
SILGen inserts mark_unresolved_noncopyable_value at the introducer in some cases and at uses in other cases. This inconsistency can causes insertion of a redundant mark* instruction which crashes the move-only checker.

This change avoids inserting a redundant mark* instruction.
2025-10-23 05:19:16 -07:00
Meghana Gupta
bef207521d Use unchecked_ownership during SILGen of borrow accessors 2025-10-23 05:19:10 -07:00
Meghana Gupta
a150c67896 Remove unchecked_ownership_conversion from borrow accessor silgen 2025-10-23 05:19:04 -07:00
Joe Groff
f3d361370f Merge pull request #85042 from jckarter/subscript-borrowable-base
SILGen: Subscripts can also be borrowed bases.
2025-10-22 18:54:00 -07:00
Joe Groff
d7ea0b821e SILGen: Subscripts can also be borrowed bases.
SILGenBorrowedBaseVisitor did not take subscripts into account during its
visit. Add this case following the handling of MemberRefExpr for properties.
Fixes rdar://163022690.
2025-10-21 11:50:16 -07:00
Jamie
a246e37996 [SILGen]: ban forward captures of let temporary allocations
This addresses the same problem as https://github.com/swiftlang/swift/pull/37935
but handles address-only lets rather than vars.
2025-10-21 07:27:14 -05:00
Meghana Gupta
6c4dd2bc8b [NFC] Eliminate unused variable warning 2025-10-20 09:05:40 -07:00
Meghana Gupta
0bd6825aa2 Update SIL utilities for borrow and mutate accessors under opaque values mode 2025-10-20 09:05:38 -07:00
Meghana Gupta
a0c939bd3b Use @inout result convention for mutate accessors 2025-10-20 09:05:32 -07:00
Doug Gregor
1b2e6ad473 Merge pull request #84989 from DougGregor/c-only-c-entrypoint 2025-10-18 00:59:00 -07:00