Commit Graph

103370 Commits

Author SHA1 Message Date
Allan Shortlidge
680b3663d0 SILGen: Fix if #available for unavailable custom domains in zippered modules.
When generating SIL for an `if #available(SomeDomain)` query in code being
compiled for a zippered target, the generated code was mis-compiled if
`SomeDomain` were disabled at compile time. Empty version ranges need to be
handled explicitly by `SILGenFunction::emitZipperedOSVersionRangeCheck()`.

SILGen still miscompiles `if #unavailable` queries generally in code compiled
for a zippered target (rdar://147929876).

Resolves rdar://150888941.
2025-05-26 09:07:28 -07:00
eeckstein
826bc76a71 Merge pull request #81736 from eeckstein/fix-mda-6.2
[6.2] SIL: define `mark_dependence_addr` to read and write to its address operand
2025-05-24 15:29:07 +02:00
Slava Pestov
0c44681cad Merge pull request #81694 from slavapestov/fix-rdar145184871-6.2
[6.2] Sema: Don't diagnose implied conformance of imported type to Sendable
2025-05-24 09:00:55 -04:00
Ian Anderson
44b2c08a5a [6.2][Driver][Frontend] -nostdimport and -nostdlibimport should remove the default framework search paths
-nostdimport and -nostdlibimport only remove the toolchain and usr/lib/swift search paths, and they leave the framework search paths intact. That makes it impossible to get a fully custom SDK environment. Make their behavior match clang's -nostdinc/-nostdlibinc behavior: treat framework and non-framework paths the same. In other words, -nostdinc removes *all* compiler provided search paths, and -nostdlibinc removes *all* SDK search paths.

Rename SkipRuntimeLibraryImportPaths to SkipAllImportPaths, and ExcludeSDKPathsFromRuntimeLibraryImportPaths to SkipSDKImportPaths to reflect their updated behavior.

Move the DarwinImplicitFrameworkSearchPaths handling from SearchPathOptions to CompilerInvocation, where RuntimeLibraryImportPaths is managed. Rename it to just ImplicitFrameworkSearchPaths, and filter for Darwin when it's set up so that all of the clients don't have to do Darwin filtering themselves later.

rdar://150557632
2025-05-23 22:12:45 -07:00
Doug Gregor
e2ee46d724 Merge pull request #81743 from DougGregor/no-unchecked-6.2 2025-05-24 03:58:49 +01:00
Shubham Sandeep Rastogi
de425be15b Set the Compilation directory when generating the Skeleton CU
When creating a skeleton Compile Unit, the DIFile passed
in, it always uses the include path. This leads to the DW_AT_comp_dir
being wrong, if the -file-compilation-dir option is passed, we need to
use the remapped compilation dir passed in to the DIFile instead.

This patch fixes that problem.

(cherry picked from commit b286b1c3a5)
2025-05-23 14:43:57 -07:00
Slava Pestov
58a9435485 Sema: Don't complain about implied Sendable conformance of imported type being retroactive
- Fixes rdar://145184871.
2025-05-23 14:34:33 -04:00
Slava Pestov
1e35ffff68 Sema: Fix diagnoseRetroactiveConformances() to handle protocol compositions 2025-05-23 14:34:33 -04:00
Slava Pestov
7c4564cbdc Sema: Allow parameterized existential compositions 2025-05-23 14:20:35 -04:00
Slava Pestov
447a1b173b ASTDemangler: Add support for constrained existential compositions 2025-05-23 14:20:35 -04:00
Henrik G. Olsson
2913255c8d [Swiftify] Fix __sized_by and nullable return values (#81693) (#81725)
Nullable return Spans did not include __swiftifyOverrideLifetime,
resulting in a lifetime error when returning the Span. Meanwhile return
values for __sized_by did not use the correct label for the call to the
RawSpan initializer, using `count` instead of `byteCount`.

rdar://151804085
rdar://151799287
(cherry picked from commit 526c683)
2025-05-23 10:54:53 -07:00
Pavel Yaskevich
7077ef5ccf Merge pull request #81737 from xedin/rdar-151720646-6.2
[6.2][TypeChecker] Improve diagnostics for access to actor-isolated values…
2025-05-23 10:12:46 -07:00
Pavel Yaskevich
d0d0afb131 Merge pull request #81718 from xedin/rdar-151797372-6.2
[6.2][CSApply] Don't inject global actor into closure type if it's marked …
2025-05-23 09:09:16 -07:00
Doug Gregor
3eb28dcc81 Remove the note that suggests using @unchecked
`@unchecked Sendble` is dangerous, and almost always the wrong thing to
use. Don't have the compiler suggest it.

(cherry picked from commit a922e8e356)
2025-05-23 16:08:59 +01:00
susmonteiro
d81d6547ba [cxx-interop] Fix metadata mismatch regarding fields of structs
In https://github.com/swiftlang/swift/pull/78467 and https://github.com/swiftlang/swift/pull/78961, we stopped emitting metadata for private C++ fields. However, this created a mismatch between the fields emitted and the number of fields + their offsets in the StructDescriptor.

rdar://147263490
(cherry picked from commit 72b13b3b48)
2025-05-23 11:16:09 +01:00
Hamish Knight
6f437241f8 Merge pull request #81721 from hamishknight/macrotrail-6.2
[6.2] [IDE] Better handle macro trailing closures
2025-05-23 10:37:44 +01:00
Pavel Yaskevich
dd95c60c70 [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
(cherry picked from commit 7a6ba8e8c58c58b3438f31fec06102d02bae81a5)
2025-05-22 23:52:02 -07:00
Erik Eckstein
30e138c48b SIL: define mark_dependence_addr to read and write to its address operand
This prevents simplification and SILCombine passes to remove (alive) `mark_dependence_addr`.
The instruction is conceptually equivalent to
```
  %v = load %addr
  %d = mark_dependence %v on %base
  store %d to %addr
```

Therefore the address operand has to be defined as writing to the address.
2025-05-23 07:53:14 +02:00
Pavel Yaskevich
8079f1b12b Merge pull request #81645 from xedin/alwaysInheritActorContext+Task-immediate-6.2
[6.2][Sema/stdlib] SE-0472: implement `@_inheritActorContext(always)` and adopt it in `Task.immediate` APIs
2025-05-22 21:27:26 -07:00
Ben Barham
9bb3f589b5 [Driver] Add missing -default-isolation to the old driver
Resolves rdar://151643763.

(cherry picked from commit 0b7fbb6419)
2025-05-22 19:10:01 -07:00
Artem Chikin
8140cbe7b2 Merge pull request #81682 from artemcm/CxxUnderlyingStdLibLookupRemap_62
[6.2 🍒][Dependency Scanning][C++ Interop] Remap lookup of Clang module `CxxStdlib` to `std`
2025-05-22 14:15:52 -07:00
Hamish Knight
fee6c5aee2 [Completion] Suggest trivial trailing closures for macros
Follow the same logic as function decl completion and suggest a
trailing closure for trivial cases.

rdar://150550747
2025-05-22 20:17:17 +01:00
Hamish Knight
c28d706fe6 [Completion] NFC: Factor out addMacroCallArguments 2025-05-22 20:17:17 +01:00
Hamish Knight
26517a1239 [SourceKit] Handle CustomAttrs arguments for placeholder expansion
Introduce a new ASTWalker option for walking CustomAttrs and use it
for the placeholder scanner to ensure we can expand placeholders in
attribute arguments.
2025-05-22 20:17:17 +01:00
Pavel Yaskevich
c5828ad362 [Concurrency] Fix @_inheritActorContext(always) to use forActorInstanceCapture for parameters
SILGen expects actor instance isolation to always come from captures,
we need to maintain that with implicit isolation capture performed by
`@_inheritActorContext(always)`.

(cherry picked from commit 91047446ad)
2025-05-22 11:32:37 -07:00
Pavel Yaskevich
e12201769d [AST/Sema/SIL] Implement @_inheritActorContext(always)
- Extend `@_inheritActorContext` attribute to support optional `always` modifier.
  The new modifier will make closure context isolated even if the parameter is not
  captured by the closure.
- Implementation `@_inheritActorContext` attribute validation - it could only be
  used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or
  `async` function type (downgraded to a warning until future major Swift mode
  to avoid source compatibility issues).
- Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files
- Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)`
- Update serialization code to store `always` modifier

(cherry picked from commit 04d46760bb)
(cherry picked from commit c050e8f75a)
(cherry picked from commit c0aca5384b)
(cherry picked from commit a4f6d710cf)
(cherry picked from commit 6c911f5d42)
(cherry picked from commit 17b8f7ef12)
2025-05-22 11:32:35 -07:00
Steven Wu
db85088493 [DependencyScanning] Avoid extra cc1 arg round-trip to speed up bridging
Use the underlying compiler invocation inside module scanning result to
speed up the clang module dependency bridging. This avoids converting
cc1 arguments to compiler invocation and back, just to modify the cc1
arguments needed for building PCM using swift-frontend.

rdar://151705822
(cherry picked from commit 391446d4b3)
2025-05-22 11:19:33 -07:00
Steven Wu
19c0919cf7 [Caching] Clear benign CodeGen options when building modules
Use `resetBenignCodeGenOptions()` from clang dependency scanner to clear
the swift explicit module build cc1 arguments. This fixes the problem
that CurrentWorkingDirectory is leaking through
`-fcoverage-compilation-dir` that can cause extra module variants when
caching is enabled. This also avoid the duplicating the logics for
clearing CodeGen options inside Swift.

rdar://151395300
(cherry picked from commit 531227d4b9)
2025-05-22 11:14:09 -07:00
Steven Wu
ed4e035f97 [Caching] Remove capture clang extra files
After removing the CASFS implementation for clang modules, there is no
need to capture clang extra file that sets up the VFS for the clang
modules since all content imported by ClangImporter is dependency
scanned and available via include-tree. This saves more ClangImporter
instance when caching is enabled.

Update the test to check that clang content found via `-Xcc` VFS options
can currently work without capture the headermaps and vfs overlays.

(cherry picked from commit 1506a0d495)
2025-05-22 11:13:52 -07:00
Steven Wu
559734c6d0 [Caching] Remove CASFS clang module implemenation
Remove the CASFS based clang module implemenation as it is not longer
used.

(cherry picked from commit 3c81c1ca9f)
2025-05-22 11:13:36 -07:00
Steven Wu
4670acf7f9 [Caching] Reduce the number of cas ID passed on frontend commandline
Using IncludeTree::FileList to concat the include tree file systems that
are passed on the command-line. This significantly reduce the
command-line size, and also makes the cache key computation a lot
faster.

rdar://148752988
(cherry picked from commit 201e4faea7)
2025-05-22 11:12:31 -07:00
Pavel Yaskevich
b79e922a50 [CSApply] Don't inject global actor into closure type if it's marked as @concurrent
When the attribute is specified explicitly passing a `@concurrent`
closure to a global actor-isolated parameter or contextual type
should result in a conversion and closure itself should be nonisolated.

Resolves: rdar://151797372
(cherry picked from commit efc6efc4ed)
2025-05-22 10:15:39 -07:00
John Hui
3db1314ba8 Merge pull request #81699 from j-hui/cherry-pick-6.2/fix-unavailable-enum
[6.2 🍒][cxx-interop] Fix assertion failure from unavailable typedef + enum pattern
2025-05-22 09:47:32 -07:00
Michael Gottesman
63a436ec04 Merge pull request #81615 from gottesmm/release/6.2-rdar151394209
[6.2] Fix a few issues around nonisolated(nonsending) and  protocol witness thunks/vtable thunks
2025-05-22 00:04:01 -07:00
Anthony Latsis
9be69e2c08 Merge pull request #81672 from AnthonyLatsis/caranx-melampygus-6.2
[6.2] InFlightDiagnostic: Minor improvement to `fixItAddAttribute`
2025-05-22 05:50:23 +01:00
John Hui
323e9f0b84 [cxx-interop] Fix assertion failure from unavailable NS_ENUM typedef
The NS_OPTIONS macro sometimes uses a pattern where it loosely
associates a typedef with an anonymous enum via a shared underlying
integer type (emphasis on "loosely"). The typedef is marked as
unavailable in Swift so as to not cause name ambiguity when we associate
the anonymous enum with said typedef. We use unavailability as
a heuristic during the import process, but that conflates NS_OPTIONS
with NS_ENUMs that can be marked as unavailable for entirely unrelated
reasons.

That in and of itself is fine, because the import logic is general
enough to handle both cases, but we have an assertion that seems to be
unaware of this scenario, and trips on unavailable NS_ENUMs. (In those
cases, the typedef points to the enum rather than the underlying integer
type.) This patch fixes the assertion to be resilient against such cases
by looking through the enum a typedef refers to.

rdar://150399978
(cherry picked from commit 80db05455f)
2025-05-21 18:54:42 -07:00
John Hui
1586d01409 [NFC] Use explicit ImportedType() constructor
(cherry picked from commit 2c7d01fa91)
2025-05-21 18:54:42 -07:00
John Hui
d1c2c76a19 [NFC] [cxx-interop] Flatten findOptionSetEnum() and move it to ImportEnumInfo.cpp
It's at home there alongside other ObjC enum-specific logic, rather than
in the middle of ImportDecl.cpp (since it isn't directly or exclusively
related to importing decls).

(cherry picked from commit 5aa5bcfea2)
2025-05-21 18:54:42 -07:00
John Hui
1f4ce612ba [NFC] [cxx-interop] Consolidate uses of findOptionSetType() helper function
Also renames it to findOptionSetEnum() to make it a bit clearer at face
value that the returned ImportedType will contain a Swift enum.

Also refactors some nearby instances of

  if (auto e = dyn_cast<ElaboratedType>(t))
      t = e->desugar();

into a helper function, desugarIfElaborated().

(cherry picked from commit c7070e73fe)
2025-05-21 18:54:42 -07:00
Doug Gregor
214536eef7 Merge pull request #81677 from DougGregor/unsafe-pattern-match-6.2
[6.2] Handle unsafe pattern match expressions correctly
2025-05-22 02:18:46 +01:00
Meghana Gupta
00dcffcd24 [6.2] Fix use-after-free on substituting function type involving conditional ~Escapable with Escapable type 2025-05-21 16:30:02 -07:00
Stephen Canon
85b304220f [6.2] Implement Builtin.select binding llvm select instruction (#81665)
Not used (yet), but needed to implement SIMD.replacing(with:where:)
idiomatically, and probably useful otherwise.

**Explanation:** Makes select available in Swift's builtin module, which
allows implementing concrete SIMD operations more efficiently.
**Risk:** Low. New builtin protected by a feature flag, currently
unused.
**Testing:** New tests added.
**Reviewers:** @eeckstein, @Azoy 
**Main branch PR:** https://github.com/swiftlang/swift/pull/81598
2025-05-21 19:14:33 -04:00
Egor Zhdan
36511a2937 Merge pull request #81674 from swiftlang/egorzhdan/6.2-silverifier-trivial-frt
🍒[cxx-interop] Relax a SILVerifier assertion for immortal reference types
2025-05-21 22:35:59 +01:00
Rintaro Ishizaki
6d254b7fd9 Merge pull request #81653 from calda/cal--6.2-trailing-comma-fixes
[6.2] Add trailing comma support in cases missing from Swift 6.1
2025-05-21 14:00:18 -07:00
Andrew Trick
9e02af878b Merge pull request #81657 from atrick/62-lifedep-inout-infer
[6.2] Allow passing MutableSpan 'inout' without an experimental feature.
2025-05-21 13:59:28 -07:00
nate-chandler
1887346228 Merge pull request #81659 from nate-chandler/cherrypick/release/6.2/rdar147207926
6.2: [TypeLowering] Record packs used in signatures.
2025-05-21 13:40:48 -07:00
Anthony Latsis
55b4193646 InFlightDiagnostic: Minor improvement to fixItAddAttribute
Do not follow `in` keyword with a space unless the first token inside
the body begins with the next char after `{`.

(cherry picked from commit eedc774fca)
2025-05-21 21:24:37 +01:00
Anthony Latsis
c1ad869e63 Merge pull request #81655 from AnthonyLatsis/acer-campestri-2-6.2
[6.2] Sema: Fix an issue with `NonisolatedNonsendingByDefault` migration fo…
2025-05-21 20:36:58 +01:00
Artem Chikin
93da5b4797 [Dependency Scanning][C++ Interop] Remap lookup of Clang module 'CxxStdlib' to 'std'
Otherwise querying this clang module, e.g. from the corresponding Swift overlay's underlying module import, will fail, since no such module exists.

Resolves rdar://151718115
2025-05-21 09:56:56 -07:00
Doug Gregor
d794c95d44 Improve diagnostic for unsafe call arguments
Use the argument type rather than the (potentially generic) parameter type.
2025-05-21 13:48:18 +01:00