Commit Graph

5662 Commits

Author SHA1 Message Date
Xi Ge
d144524209 CustomAvailability: synthesized dynamic availability checking function should be private
When compiling a Swift module in incremental mode, each Swift source file is compiled into an object file
and we use linker to link them together. Because the predicate function for checking dynamic feature
availability is eagerly synthesized per compilation unit, the linker will complain about duplicated
symbols for them. Setting their visibility as private ensures that linker doesn't see them, thus addressing
the linker errors.

One workaround for this problem is to enable WMO.

rdar://164971313
2025-11-18 09:19:26 -08:00
Doug Gregor
b21485dd1f Only foreign thunks need to be serialized, not foreign definitions
This eliminates a SIL verification error with `@c` functions, which
provide definitions for foreign entrypoints. We were serializing @c
definitions when we shouldn't be, which would cause problems down the
line if those @c definitions referenced something internal that they
shouldn't.
2025-11-13 18:39:08 -08:00
Slava Pestov
0fc67522ea Merge pull request #85415 from slavapestov/fix-issue-78598
SILGen: Fix break/continue inside 'for ... in ... repeat' loop
2025-11-11 03:18:48 -05:00
Xi Ge
bc9df74304 Merge pull request #85405 from nkcsgexi/serialization-dynamic-check
CustomAvailability: avoid exposing the synthesized function for dynamic availability checking as an API entry
2025-11-10 18:30:58 -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
Xi Ge
e31c1cc7f8 CustomAvailability: avoid exposing the synthesized function for dynamic availability checking as an API entry
For dynamic features defined from a header, we synthesize a pure Clang function to check whether the feature should
be enabled at runtime. Swift modules don't have capability to deserialize this clang predicate function, leading to
crasher as a result. This change fixes the crasher by hiding the synthesized function to be a module internal one.

rdar://164410957
2025-11-10 09:26:28 -08: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
Arnold Schwaighofer
9795f65145 Change tests to also test that this feature is available per default 2025-11-07 10:10:47 -08:00
eeckstein
552b665a9e Merge pull request #85334 from eeckstein/mandatory-destroy-hoisting
Optimizer: make destroy hoisting a mandatory pass
2025-11-07 06:45:03 +01:00
Erik Eckstein
62786b01e2 Optimizer: add the mandatory destroy hoisting pass
It hoists `destroy_value` instructions for non-lexical values.

```
  %1 = some_ownedValue
  ...
  last_use(%1)
  ... // other instructions
  destroy_value %1
```
->
```
  %1 = some_ownedValue
  ...
  last_use(%1)
  destroy_value %1    // <- moved after the last use
  ... // other instructions
```

In contrast to non-mandatory optimization passes, this is the only pass which hoists destroys over deinit-barriers.
This ensures consistent behavior in -Onone and optimized builds.
2025-11-06 21:00:44 +01: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
e48bdf7307 [NFC] Test rename 2025-11-06 10:55:41 -08:00
Meghana Gupta
778ad0dfb5 Add SIL verification to ensure we don't return local addresses 2025-11-06 10:55:39 -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
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
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
ba507ab822 Merge pull request #85203 from DougGregor/clang-decl-asmname 2025-11-01 20:46:50 -07:00
Doug Gregor
f1ad1be919 MAke FileCheck more general to not worry about nullability of UIApplicationMain from C 2025-11-01 10:54:41 -07:00
Hamish Knight
828b10abd9 [test] Remove a FIXME
These cases are odd, but well defined.
2025-11-01 17:38:27 +00:00
Hamish Knight
dad3acebd7 [test] Add some extra variants in capture_order.swift
The existing tests we have here I'm hoping to reject in Sema, add
equivalent variants that use local functions which will continue to
be caught in SILGen.
2025-11-01 17:36:55 +00:00
Doug Gregor
576cb0257c Update iOS test for asmname change 2025-11-01 06:30:58 -07:00
Alexis Laferrière
048c9276a9 Merge pull request #85122 from xymus/official-c-attr
SE-495: Make `@c` an official feature
2025-10-30 16:06:25 -07:00
Doug Gregor
523b3b7ab7 Various test updates for Linux, Windows, iOS, and x86_64 macOS 2025-10-30 09:45:10 -07: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
Doug Gregor
f267f62f65 [SILGen] Consistently use SIL asmname for foreign function/variable references
Whenever we have a reference to a foreign function/variable in SIL, use
a mangled name at the SIL level with the C name in the asmname
attribute. The expands the use of asmname to three kinds of cases that
it hadn't been used in yet:

* Declarations imported from C headers/modules
* @_cdecl @implementation of C headers/modules
* @_cdecl functions in general

Some code within the SIL pipeline makes assumptions that the C names of
various runtime functions are reflected at the SIL level. For example,
the linking of Embedded Swift runtime functions is done by-name, and
some of those names refer to C functions (like `swift_retain`) and
others refer to Swift functions that use `@_silgen_name` (like
`swift_getDefaultExecutor`). Extend the serialized module format to
include a table that maps from the asmname of functions/variables over
to their mangled names, so we can look up functions by asmname if we
want. These tables could also be used for checking for declarations
that conflict on their asmname in the future. Right now, we leave it
up to LLVM or the linker to do the checking.

`@_silgen_name` is not affected by these changes, nor should it be:
that hidden feature is specifically meant to affect the name at the
SIL level.

The vast majority of test changes are SIL tests where we had expected
to see the C/C++/Objective-C names in the tests for references to
foreign entities, and now we see Swift mangled names (ending in To).
The SIL declarations themselves will have a corresponding asmname.

Notably, the IRGen tests have *not* changed, because we generally the
same IR as before. It's only the modeling at the SIL lever that has
changed.

Another part of rdar://137014448.
2025-10-29 19:35:55 -07: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
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07: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
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
Meghana Gupta
7e8d8b671f Merge pull request #85097 from meg-gupta/withdiagpr
Update borrow accessor diagnostics and synthesis
2025-10-24 15:06:19 -07:00
Meghana Gupta
c85e214369 Fix synthesis of get/set protocol constraints when borrow/mutate accessors are present 2025-10-24 04:29:46 -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
4369c9c56a [NFC] Update test with return_borrow 2025-10-23 05:19:12 -07:00
Meghana Gupta
fc71233688 [NFC] Update tests 2025-10-23 05:19:10 -07:00
Doug Gregor
45fa67020e Merge pull request #85065 from DougGregor/c-sil-mangled-name
[SIL] Use mangled names + asmname for `@c` functions
2025-10-22 21:38:48 -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
Doug Gregor
fad8b24dbb [SIL] Use mangled names + asmname for @c functions
Instead of using the C name for `@c` functions in SIL, retain mangled
names and apply the `asmname` attribute, so we retain more type
information until later in the pipeline and avoid collisions.

Another part of rdar://137014448.
2025-10-22 10:54:42 -07:00
Allan Shortlidge
16dee385bf AST/Basic: Introduce the StandaloneSwiftAvailability experimental feature.
This experimental feature will be used to force the compiler to treat `Swift`
runtime availability as separate from platform availability when compiling for
targets that have the Swift runtime built-in.
2025-10-21 21:55:24 -07:00
Kavon Farvardin
12a915ff6d OpaqueValues: resurrect closure test
This effectively reverts 8ca5c83c51
2025-10-21 17:46:28 -07:00
Allan Shortlidge
484f3bef8e Merge pull request #85015 from tshortli/never-weak-link-on-windows
AST: Skip weak linking on Windows consistently
2025-10-21 14:29:20 -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
Allan Shortlidge
f87aa5323f AST: Skip weak linking on Windows consistently.
Always special-case Windows targets in `isAlwaysWeakImported()` instead of
limiting the special case to declarations that are marked unavailable.
2025-10-21 09:04:54 -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
0bd6825aa2 Update SIL utilities for borrow and mutate accessors under opaque values mode 2025-10-20 09:05:38 -07:00
Meghana Gupta
69ef88bcb9 [NFC] Update tests 2025-10-20 09:05:38 -07:00
Meghana Gupta
25f0e2f934 [NFC] Replace @guaranteed_addr by @guaranteed_address 2025-10-20 09:05:37 -07:00
Pavel Yaskevich
2b7adbc4ff Merge pull request #84800 from xedin/remove-csapply-operator-devirt
[CSApply] Don't attempt operator devirtualization
2025-10-18 23:09:23 +09:00