Commit Graph

49268 Commits

Author SHA1 Message Date
Hamish Knight 2aa884122d Merge pull request #89845 from hamishknight/fix-opaque
[Sema] Allow member on opaque parameter type
2026-06-12 00:44:19 +01:00
Steven Wu f8bf21ded6 Merge pull request #89649 from cachemeifyoucan/eng/PR-178563432
[Caching] Improve swift caching remarks
2026-06-11 09:12:29 -07:00
Egor Zhdan 9f99a8c5fa Merge pull request #89794 from egorzhdan/egorzhdan/nullopt
[cxx-interop] Fix-it for using `nil` instead of `std::nullopt`
2026-06-11 12:51:02 +01:00
Aidan Hall e63e41c22f Merge pull request #89834 from aidan-hall/fix-pack-archetype-conformance-substitution
[SILCloner] Preserve expansion level when cloning pack conformances
2026-06-11 11:51:39 +01:00
Hamish Knight a2cd1fb8f1 [Sema] Improve diag for uninferrable opaque generic param 2026-06-11 11:44:13 +01:00
Aidan Hall bdfaf743c8 [SILCloner] Preserve expansion level when cloning pack conformances
If an InFlightSubstitution has an active pack expansion, then substituting a
PackArchetypeType could cause a PackElementType to be introduced, possibly
erroneously. ProtocolConformanceRef::forAbstract cannot handle PackElementType
types, so set the PreservePackExpansionLevel flag prevents this.
2026-06-10 15:45:33 +01:00
Meghana Gupta 4812e2ad8f Merge pull request #89788 from meg-gupta/dereffeature
Add a feature for Builtin.dereferenceable
2026-06-10 19:35:17 +05:30
Kavon Farvardin c77c1fd33a Merge pull request #89813 from kavon/fix/rdar176892954-pt2 2026-06-10 06:24:17 -07:00
Erik Eckstein 541664237c Optimizer: add the MergeBorrowScopes pass
The pass merges to adjacent borrow scopes in a basic block.

```
  %2 = begin_borrow %1
  use(%2)
  end_borrow %2
  ...
  %6 = begin_borrow %1
  use(%6)
  end_borrow %6

```
->
```
  %2 = begin_borrow %1
  use(%2)
  ...
  use(%2)
  end_borrow %2
```

This helps other optimizations, like common-subexpression-elimination, because the borrow liveranges are larger and not split.
2026-06-10 08:18:51 +02:00
Meghana Gupta f2e5629edf Add a feature for Builtin.dereferenceable 2026-06-10 09:40:24 +05:30
eeckstein 1edbe51050 Merge pull request #89784 from eeckstein/index_addr
Fix the design of the `index_addr` SIL instruction
2026-06-10 05:40:01 +02:00
Sam Pyankov 1def6c09dc Merge pull request #89648 from sepy97/diagnostic-group-ipi
[Sema] Group the IPI public-import diagnostic and emit it as a warning
2026-06-09 17:02:59 -07:00
Kavon Farvardin b7acd216a7 NFC: introduce PatternBindingDecl::getCheckedPattern
This should help cleanup some calls to
`getCheckedPatternBindingEntry` that are just there to
precede `getPattern`.
2026-06-09 16:41:07 -07:00
Egor Zhdan dc4ba09d44 [cxx-interop] Fix-it for using nil instead of std::nullopt
In C++, `std::nullopt` is implicitly convertible to `std::optional<T>`. Swift doesn't support implicit type conversions between arbitrary types. Instead, the developer is expected to use `nil` literal, which is implicitly converted to `std::optional<T>`. This works via `CxxOptional`'s conformance to `ExpressibleByNilLiteral`.

This improves the diagnostic produced by Swift for the attempted usage of `std::nullopt` in places where the type conversion expected by the developer doesn't happen. A note will now be emitted:
```
use the 'nil' literal instead
```

rdar://162203520
2026-06-09 18:22:43 +01:00
Erik Eckstein 4a8444ad42 add Builtin.gepProjection
It's like Builtin.gep, but marks the resulting `index_addr` as a projection, meaning the result can only reach the single element at the given index and cannot be used for general pointer arithmetic by chaining `index_addr` instructions.
2026-06-09 16:17:53 +02:00
Erik Eckstein 8949e1387e Optimizer: simplify index_addr and index_raw_pointer
Which replaces the old index_addr SIL combine optimization
2026-06-09 16:17:53 +02:00
Erik Eckstein 7ea1b1b23e SIL: add a flag [projection] to index_addr
The `projection` flag indicates that `index_addr` projects an element address from an array base address, as opposed to being used for general pointer arithmetic.
When this flag is set, the result address can only reach the single element at the given index — it is not possible to chain multiple `index_addr` instructions to reach other array elements from the result.
Without this flag, the result may be used as the base of another `index_addr`, allowing arithmetic across element boundaries (e.g. an `index_addr` with index 1 followed by an `index_addr` with index 2 reaches the element at offset 3).

An `index_addr [projection]` is mandatory to go from an array base address to an element - even if it's the first element, i.e. the index is zero.
This means that the optimizer must not remove `index_addr [projection]` with a zero index.
2026-06-09 16:17:53 +02:00
Konrad `ktoso` Malawski 3f4ed9500a [Concurrency] change task name from record to fragment, static location (#89678) 2026-06-09 21:51:57 +09:00
John Hui cde043e6f5 Merge pull request #89731 from j-hui/frt-revisited
[cxx-interop] Enforce that derived FRTs have a single shared FRT base
2026-06-08 23:03:21 -07:00
Meghana Gupta 2d53a89dcb Merge pull request #89760 from meg-gupta/deref
Introduce Builtin.dereferenceable
2026-06-09 09:08:54 +05:30
John Hui d9328382f9 [cxx-interop] [NFC] Refactor FRTInfo checking into visitor class
This patch consolidates the FRTInfo checking logic into a single
recursive traversal within a visitor class. It is not intended to have
any observable functional difference in the analysis.
2026-06-08 13:05:52 -07:00
Allan Shortlidge e722685790 Merge pull request #89724 from tshortli/switch-stmt-availability-refinement
AST: Refine availability of switch case bodies using enum element availability
2026-06-08 09:02:49 -07:00
Paul Passeron 425cd0ebd7 [experimental] Infrastructure for derived conformances via macros (#89419)
**Overview**:
This PR introduces the basic infrastructure needed to eventually migrate
derived macros generation from hand-crafted AST nodes to macros. No
conformance have been migrated yet.

**Motivation**:
Derived conformances (e.g. `Equatable`, `Hashable`, `Codable`, ...) are
currently implemented as a special case in the compiler, producing
synthetic AST nodes directly. Migrating this to macros will hopefully
unify the code path with the existing macro expansion infrastructure,
make conformance synthesis easier to extend and test as well as reducing
the amount of special cases in the compiler.

**Changes**:
- New experimental feature flag `DeriveConformancesViaMacros`:
Introduces the flag that will eventually gate the new derived
conformance code paths. It does not control any behaviour for the moment
as none have been migrated yet but this enables future changes to be
built incrementally.
- New GeneratedSourceInfo and SourceFile kinds `SyntheticMacro`:
Introduces new GSI and SourceFile kinds named `SyntheticMacro` to
represent macros synthesized by the compiler. Since macros need a real
buffer to expand, this is the kind of source file and GSI associated
with those buffers.
- Conformance derivation via macros API:
Introduces the `deriveRequirementViaMacro` function that produces the
required witness via macro expansion.

See https://github.com/swiftlang/llvm-project/pull/13124 for
llvm-related changes.

**Next steps**:
- Macros do not contain any semantic information, especially regarding
types. Therefore it is necessary to provide them with type information
as an argument so they can eventually derive the conformances. A
separate PR is being created to generate this type information as
strings containing swift-parsable code for easy parsing on the macro
end.
- Implement derived conformance synthesis for individual protocols using
the new infrastructure, like `Equatable` or `Hashable` for starters.
- Wire the experimental flag to gate the new path once an implementation
exists

---------

Co-authored-by: Hamish Knight <hamish_knight@apple.com>
2026-06-08 14:23:58 +01:00
Egor Zhdan 72ad2e5a91 Merge pull request #89660 from egorzhdan/egorzhdan/super-virtual
[cxx-interop] Support static dispatch for virtual methods using `super`
2026-06-08 12:23:28 +01:00
Meghana Gupta e56942b533 Introduce Builtin.dereferenceable
This PR introduces a new Swift builtin `Builtin.dereferenceable` that
allows the compiler to provide dereferenceable memory hints to LLVM for
optimization purposes.

Resolves rdar://174255636
2026-06-08 12:06:23 +05:30
Tony Allevato 2b09e500f1 Merge pull request #87115 from allevato/optional-anysome
[SE-0521] Allow `some P?` and `any P?` syntax (removing the need for parentheses).
2026-06-07 13:50:47 -04:00
Egor Zhdan 338c8eafd8 [cxx-interop] Support static dispatch for virtual methods using super
This adds support for calling virtual methods of C++ foreign reference types with static dispatch.

In C++, one can do:
```cpp
this->Base::virtualMethod()
```

Swift doesn't allow calling a particular overload of an overridden method, however, it allows calling an overload from the superclass with `super`:
```swift
extension Derived {
  public func callSuper() {
    return super.foo()
  }
}
```

For inherited FRTs, the example above behaved in an unexpected way: the call would still be dispatched dynamically, despite using the syntax reserved for static dispatch. This change makes it behave similarly to pure-Swift classes.

rdar://177619427
2026-06-07 12:14:31 +01:00
Doug Gregor 67c82cb991 Merge pull request #89741 from DougGregor/freestanding-concurrency-global-executor
[Cooperative global executor] Drop explicit <chrono> usage
2026-06-06 18:22:06 -07:00
Allan Shortlidge 5cbb9f1f28 Merge pull request #89727 from tshortli/unnecessary-unsafe
AST: Introduce the UnnecessaryUnsafe diagnostic group
2026-06-06 16:33:44 -07:00
Tony Allevato bd216eb75a Merge pull request #89125 from allevato/raw-identifier-decl-names
Handle raw identifiers correctly in renamed APIs.
2026-06-06 19:22:43 -04:00
Doug Gregor 64f98f8b57 [Cooperative global executor] Drop explicit <chrono> usage
The cooperative global executor uses <chrono> for its handling of
times. This creates a dependency on a C++11 standard library, and
doesn't actually work with freestanding implementations like we want
for Embedded Swift.

Replace this <chrono> usage with swift_sleep / swift_get_time from
the concurrency library, which already considers various
platform-specific implementations before falling back to <chrono>.

Enable -ffreestanding for the embedded Concurrency library and its
support libraries.
2026-06-06 11:53:07 -07:00
Egor Zhdan df7d8cb3a6 [cxx-interop] Guard FRT inheritance behind an experimental feature flag
This is a follow-up to 6c464579.

Importing superclasses of C++ foreign reference types can introduce source breaks in Swift under some circumstances.

This change puts the feature behind an experimental flag.

rdar://178736469
2026-06-06 15:43:32 +01:00
Mike Ash 93d582a067 Merge pull request #88650 from mikeash/metadata-allocator-back-pointer
[Runtime] Add back pointers to the ends of metadata allocator pages.
2026-06-05 23:30:33 -04:00
Allan Shortlidge 35bd17fefc AST: Refine availability of switch case bodies using enum element availability.
When a case statement body inside a switch statement is only reachable if a
specific enum element matches the switch subject, the compiler now generates an
availability scope for the case body that matches the availability of the enum
element:

```
@available(macOS 26, *)
func f() -> Int { 0 }

enum E {
  @available(macOS 26, *)
  case a
}

func multiplex(_ e: E) -> Int {
  switch e {
  case .a:
    return f() // OK, .a is only available in macOS 26
  }
}
```

Supporting the same refinement for cases in switch expressions will need to be
handled as a follow-up as it may require changes to the order in which switch
expression case bodies are type checked relative to the case label.

Resolves https://github.com/swiftlang/swift/issues/46662 and rdar://20937722.
2026-06-05 20:15:14 -07:00
Anthony Latsis 6534c73f20 Merge pull request #89600 from swiftlang/jepa-main8
Basic: Handle new llvm target triples
2026-06-06 03:03:51 +01:00
Anthony Latsis bdb420bac2 Merge pull request #89413 from swiftlang/jepa-rebranch2
SILOptimizer: Adjust to "[Support][NFCI] Store DomTree children as linked list (#176409)"
2026-06-06 03:03:02 +01:00
John Hui 889e989924 Merge pull request #87060 from j-hui/no-samespace-lookup 2026-06-05 15:27:59 -07:00
Allan Shortlidge f0745b2143 AST: Introduce the UnnecessaryUnsafe diagnostic group.
Put diagnostics about unnecessary 'unsafe' markers to a dedicated group.

Resolves rdar://177377552.
2026-06-05 15:10:44 -07:00
Slava Pestov eaaf110ec9 Merge pull request #89688 from slavapestov/fix-rdar177052246
AST: Escape member names when printing a DependentMemberType
2026-06-05 16:42:21 -04:00
Allan Shortlidge b7c747b457 Merge pull request #89706 from tshortli/versioned-canimport-missing-module-warning
AST: Warn when module specified by versioned canImport cannot be found
2026-06-05 13:06:05 -07:00
finagolfin da0de8aa96 Revert "Pack env vars into a struct and initialize them all at once, … (#89709)
…rather than lazily populating the _isSet flags on access. In most cases
this should go from O(n) writes to 0, since none of them will be set
(#89651)"

This reverts commit c5f72c8f19.

This optimization pull broke the Android CI, #89708, so reverting until
we can figure out why.
2026-06-05 12:14:29 -07:00
Artem Chikin d060156218 Merge pull request #89077 from artemcm/DiagnoseIfConfigSupport
[Source Warning Control] Plumb `ConfiguredRegions` through @diagnose region queries
2026-06-05 19:50:45 +01:00
Mike Ash 2c6c87fcee [Runtime] Add back pointers to the ends of metadata allocator pages.
Memory analysis tools have trouble identifying the metadata allocator pages. When allocating a new page, write a pointer to the previous page at the end. Combined with the existing _swift_debug_allocationPoolPointer variable, this will allow all metadata allocation pages to be identified definitively.

rdar://175515505
2026-06-05 12:20:49 -04:00
Allan Shortlidge 4d52c36aa4 AST: Warn when module specified by versioned canImport cannot be found.
If the module named in `#if canImport(<Module>, _version: ...)` cannot be
found, it may indicate that the developer misspelled the module name. Emit a
warning to indicate that the directive evaluates to false. If it is intentional
that the module not be found, the developer can avoid the warning by first
checking whether the module can be imported and then check its version.

Resolves rdar://128367758.
2026-06-05 06:42:18 -07:00
Emil Pedersen 9ea3618e7d Merge pull request #89628 from Snowy1803/salvage-optimize-enum-alloc-stack
[DebugInfo] Salvage enums in SimplifyAllocStack
2026-06-05 14:27:43 +01:00
Artem Chikin ff187ae3b2 [Source Warning Control] Emit canImport diagnostics in ASTGen-only mode
Avoiding the duplicate `cannot_find_module_version` diagnostics routed
`ExportedSourceFile.configuredRegions(astContext:)` through the side-effect-free
`.analyzing` canImport query. For the default C++ parser that is always correct:
its `EvaluateIfConditionRequest` remains the canonical site that emits the
diagnostic and records the result in `CanImportModuleVersions`, and the
configured-regions walk is only a secondary re-derivation used for various
compiler analysis clients (e.g. warning group control).

In ASTGen-only mode (`-enable-experimental-feature ParserASTGen`) the C++
parser, and therefore `EvaluateIfConditionRequest`, never runs; the
configured-regions walk is the only evaluation that drives `canImport`. Routing
it through `.analyzing` consequently suppressed the diagnostic.

This change adds `swift_ASTGen_evaluateConfiguredRegionsForDiagnostics`, invoked
once at the start of `parseSourceFileViaASTGen`, which evaluates the file's
`#if` directives in `.driving` mode to emit the diagnostics and populate the
version cache before any analysis path consumes the configured-regions cache.
2026-06-05 10:44:13 +01:00
Artem Chikin 690dbc530c [Source Warning Control] Avoid duplicate canImport diagnostics from secondary #if walks
`#if canImport(...)` conditions are evaluated by the parser's primary
`EvaluateIfConditionRequest`, which emits `cannot_find_module_version` and
records the result in `CanImportModuleVersions`. Several later analyses re-walk
the same directives and, before this change, routed through that same emitting
`canImportModule` path, duplicating the diagnostic: the
`ExportedSourceFile.configuredRegions` region-tree rebuild that backs
diagnostic-group control (which could also recurse indefinitely), and the
`VarDeclUsageChecker` inactive-code scans behind unused-variable diagnostics.

Introduce a `CanImportMode` on `CompilerBuildConfiguration` distinguishing the
canonical, diagnostic-emitting `.driving` query from a side-effect-free
`.analyzing` re-derivation. `.analyzing` routes to the new
`BridgedASTContext.testCanImport` -> `ASTContext::testImportModule` bridge,
which answers from the module loaders without emitting diagnostics or populating
`CanImportModuleVersions`; `.driving` keeps the existing `canImport` behavior.
The mode defaults to `.analyzing`, so only the canonical site
`evaluatePoundIfCondition` drives, while every secondary walk re-derives `#if`
activity without repeating the diagnostic.
2026-06-05 10:29:15 +01:00
Artem Chikin 6b9edbaca0 [Source Warning Control] Plumb ConfiguredRegions through @diagnose region queries
Adopt changes to `SwiftWarningControl` library API that allow specifying an
input `ConfiguredRegions` parameter to construct a `warningControlTree`.

Resolves rdar://176454319
2026-06-05 10:29:12 +01:00
Sam Pyankov 4742af0081 [Sema] Group the IPI public-import diagnostic and emit it as a warning
The initial IPI implementation emits an error when an api/spi-level
module publicly imports an ipi-level module. That is too aggressive for
incremental adoption.

Wrap the diagnostic in a new diagnostic group (IPIVerification) and emit
it as a warning.

Also reword the message from "...from non-internal module 'X'" to a clearer
"...because 'X' has '-library-level api/spi'"

rdar://178560797
2026-06-04 15:16:43 -07:00
Slava Pestov 0fbe0faef0 AST: Remove unused method 2026-06-04 13:36:20 -04:00