Commit Graph

47821 Commits

Author SHA1 Message Date
Susana Monteiro
9e216edf5e Merge pull request #85643 from susmonteiro/susmonteiro/remove-annotationonly-flag
[cxx-interop] Remove annotationOnly flag from Escapability request
2025-12-02 14:36:56 +00:00
susmonteiro
b06631e4da [cxx-interop] Remove annotationOnly flag from Escapability request 2025-12-02 09:27:30 +00:00
susmonteiro
fbfcd4d241 [cxx-interop] Implicitly defined copy and move constructors 2025-12-02 09:15:37 +00:00
Arnold Schwaighofer
36a3c6e611 Merge pull request #85644 from aschwaighofer/wip_embedded_exits_with_eriks_changes_v1
[embedded] Fix associated type conformances for specialized witness tables
2025-12-01 16:40:31 -08:00
Susana Monteiro
92cbcb6864 Merge pull request #85485 from susmonteiro/susmonteiro/remove-request-cycles
[cxx-interop] Refactor ClangTypeEscapability and CxxValueSemantics requests
2025-12-01 21:09:03 +00:00
Aidan Hall
96dca43eb9 Merge pull request #85244 from aidan-hall/fixing-debug-info-rebase
Retain more debug info in optimized builds
2025-12-01 20:49:40 +00:00
Michael Gottesman
24c69c674d Merge pull request #85604 from gottesmm/alloc_stack_non_nested
[irgen] Implement support for alloc_stack non_nested.
2025-12-01 09:38:06 -08:00
eeckstein
9304ce951c Merge pull request #85707 from eeckstein/embedded-witness-method-specialization
embedded: change the function representation of directly called witness methods
2025-12-01 09:36:45 +01:00
eeckstein
46c69e40c1 Merge pull request #85533 from eeckstein/fix-access-simplification
SILOptimizer: don't remove empty conflicting access scopes
2025-12-01 09:35:48 +01:00
eeckstein
c8b5df5129 Merge pull request #85647 from eeckstein/fix-embedded-cpp-classes
embedded: don't try to specialize vtables of C++ imported reference-counted classes
2025-12-01 09:35:19 +01:00
eeckstein
e18ba6d1bb Merge pull request #85691 from eeckstein/fix-sil-combine
SILCombine: fix propagation of concrete existentials in enums
2025-12-01 09:34:55 +01:00
Aidan Hall
a95d2979f9 [DebugInfo] Salvage more in -O builds
Specifically, improved debug info retention in:
* tryReplaceRedundantInstructionPair,
* splitAggregateLoad,
* TempLValueElimination,
* Mem2Reg,
* ConstantFolding.

The changes to Mem2Reg allow debug info to be retained in the case tested by
self-nostorage.swift in -O builds, so we have just enabled -O in that file
instead of writing a new test for it.

We attempted to add a case to salvageDebugInfo for unchecked_enum_data, but it
caused crashes in Linux CI that we were not able to reproduce.
2025-11-28 17:42:18 +00:00
Erik Eckstein
64dd574bea embedded: change the function representation of directly called witness methods
This is needed in Embedded Swift because the `witness_method` convention requires passing the witness table to the callee.
However, the witness table is not necessarily available.
A witness table is only generated if an existential value of a protocol is created.

This is a rare situation because only witness thunks have `witness_method` convention and those thunks are created as "transparent" functions, which means they are always inlined (after de-virtualization of a witness method call).
However, inlining - even of transparent functions - can fail for some reasons.

This change adds a new EmbeddedWitnessCallSpecialization pass:
If a function with `witness_method` convention is directly called, the function is specialized by changing the convention to `method` and the call is replaced by a call to the specialized function:

```
  %1 = function_ref @callee : $@convention(witness_method: P) (@guaranteed C) -> ()
  %2 = apply %1(%0) : $@convention(witness_method: P) (@guaranteed C) -> ()
...
sil [ossa] @callee : $@convention(witness_method: P) (@guaranteed C) -> () {
  ...
}
```
->
```
  %1 = function_ref @$e6calleeTfr9 : $@convention(method) (@guaranteed C) -> ()
  %2 = apply %1(%0) : $@convention(method) (@guaranteed C) -> ()
...
// specialized callee
sil shared [ossa] @$e6calleeTfr9 : $@convention(method) (@guaranteed C) -> () {
  ...
}
```

Fixes a compiler crash
rdar://165184147
2025-11-26 16:23:47 +01:00
Erik Eckstein
17ca4d9787 Optimizer: add FunctionPassContext.mangle(withChangedRepresentation original: Function) 2025-11-26 16:23:47 +01:00
Erik Eckstein
4c09fa6805 Mangling: add a specialization mangling for changing the function type representation of a function 2025-11-26 16:23:47 +01:00
Erik Eckstein
ab2345a2ed FunctionPassContext: support setting arbitrary function type representations when creating specialized functions 2025-11-26 16:23:47 +01:00
Erik Eckstein
4920ace11e AST: add enum FunctionTypeRepresentation and TypeProperties.functionTypeRepresentation 2025-11-26 16:23:46 +01:00
Erik Eckstein
2ac69f3c55 SILCombine: fix propagation of concrete existentials in enums
This peephole optimization didn't consider that an alloc_stack of an enum can be overridden by another value.
The fix is to remove this peephole optimization at all because it is already covered by `optimizeEnum` in alloc_stack simplification.

Fixes a miscompile
https://github.com/swiftlang/swift/issues/85687
rdar://165374568
2025-11-25 09:42:19 +01:00
Erik Eckstein
9a124742b0 Optimizer: add the DeadAccessScopeElimination optimization pass
It eliminates dead access scopes if they are not conflicting with other scopes.

Removes:
```
  %2 = begin_access [modify] [dynamic] %1
  ...                                       // no uses of %2
  end_access %2
```

However, dead _conflicting_ access scopes are not removed.
If a conflicting scope becomes dead because an optimization e.g. removed a load, it is still important to get an access violation at runtime.
Even a propagated value of a redundant load from a conflicting scope is undefined.

```
  %2 = begin_access [modify] [dynamic] %1
  store %x to %2
  %3 = begin_access [read] [dynamic] %1    // conflicting with %2!
  %y = load %3
  end_access %3
  end_access %2
  use(%y)
```
After redundant-load-elimination:
```
  %2 = begin_access [modify] [dynamic] %1
  store %x to %2
  %3 = begin_access [read] [dynamic] %1    // now dead, but still conflicting with %2
  end_access %3
  end_access %2
  use(%x)                                  // propagated from the store, but undefined here!
```
In this case the scope `%3` is not removed because it's important to get an access violation error at runtime before the undefined value `%x` is used.

This pass considers potential conflicting access scopes in called functions.
But it does not consider potential conflicting access in callers (because it can't!).
However, optimizations, like redundant-load-elimination, can only do such transformations if the outer access scope is within the function, e.g.

```
bb0(%0 : $*T):     // an inout from a conflicting scope in the caller
  store %x to %0
  %3 = begin_access [read] [dynamic] %1
  %y = load %3     // cannot be propagated because it cannot be proved that %1 is the same address as %0
  end_access %3
```

All those checks are only done for dynamic access scopes, because they matter for runtime exclusivity checking.
Dead static scopes are removed unconditionally.
2025-11-24 14:49:45 +01:00
Michael Gottesman
c876c1ee88 [sil-verifier] Split SILVerifier verificationFailure into separate functions for Instructions, Arguments, and add a variant for Values.
This also required me to change how we handled which instruction/argument we
emit an error about in the verifier. Previously we were using two global
variables that we made nullptr to control which thing we emitted an error about.
This was unnecessary. Instead I added a little helper struct that internally
controls what we will emit an error about and an external "guard" RAII struct
that makes sure we push/pop the instruction/argument we are erroring upon
correctly.
2025-11-21 11:21:15 -08:00
Michael Gottesman
29229a9410 [sil] Add basic SIL support for alloc_stack [non_nested].
This means I just added the flag and added support for
cloning/printing/serializing the bit on alloc_stack.
2025-11-21 11:21:14 -08:00
Erik Eckstein
a371aecb95 AST: add var ClassDecl.isForeign 2025-11-21 16:33:06 +01:00
Erik Eckstein
9d02917087 SIL: make a linkage mismatch during de-serialization a human readable diagnostic
Although this error can only happen when tinkering with the stdlib's runtime functions, it's nice to get a readable error message. So far, the compiler just crashed later without a hint to the original problem.
2025-11-21 11:47:46 +01:00
Erik Eckstein
95d5b5da33 SIL: make getLinkageString(SILLinkage linkage) available as general API 2025-11-21 11:47:06 +01:00
Slava Pestov
fa55b2520d Merge pull request #85593 from slavapestov/lazy-opaque-type-decl
Serialization: Lazily deserialize OpaqueTypeDecl's underlying substitutions
2025-11-21 00:43:22 -05:00
Konrad `ktoso` Malawski
80913591cd Adjust availability checks in DispatchShims.h (#85634) 2025-11-20 21:23:21 -08:00
Arnold Schwaighofer
1b6da50ed9 Merge pull request #85602 from aschwaighofer/wip_embedded_exit_cast
[embedded] Implement swift_dynamicCast suport for casts from existential to concrete type
2025-11-20 21:01:41 -05:00
Slava Pestov
27097430cc Serialization: Lazily deserialize OpaqueTypeDecl's underlying substitutions
We need to serialize the underlying type substitution map for an
inlinable function. However, there is no reason to deserialize it
eagerly, since doing so can lead to cycles. It is better for
correctness and performance to only deserialize it when needed.

Technically this fixes a regression from #84299, but the actual
problem was there all along, it was just exposed by my change
on a specific project.

Fixes rdar://163301203.
2025-11-20 18:13:50 -05:00
Ryan Mansfield
233414032f Merge pull request #85610 from ktoso/wip-adjust-availability
Follow up: Availability of Set thread base priority when running escalated Tasks
2025-11-20 16:13:24 -05:00
Erik Eckstein
1486d009b0 AST: add var ProtocolDecl.isMarkerProtocol 2025-11-20 10:56:05 -08:00
Erik Eckstein
b218d9ab5c SIL: add some APIs for InitExistentialAddrInst
* `var conformances: ConformanceArray`
* `var formalConcreteType: CanonicalType`
2025-11-20 10:55:47 -08:00
Erik Eckstein
60a28cd570 embedded: don't re-abstract witness method calls for existentials
Don't convert indirect to direct arguments. This is needed to support general existentials in embedded swift.
2025-11-20 10:54:37 -08:00
susmonteiro
791194b0ff Simplify CxxValueSemanticsKind 2025-11-20 18:43:04 +00:00
Kavon Farvardin
7d4f45b303 Merge pull request #85608 from kavon/opaque-values/fixes-5
OpaqueValues: fixes for distributed actors + introduce AccessControls
2025-11-20 06:48:24 -08:00
Aidan Hall
2c9013b2a4 Merge pull request #84648 from swiftlang/users/kovdan01/ast-bridges-for-autodiff-closure-spec
Bridging: Implement bridges required for ongoing AutoDiff changes
2025-11-20 14:45:28 +00:00
Slava Pestov
bfb6c826c4 Merge pull request #85560 from slavapestov/fix-ridiculous-irgen-thing
IRGen: Remove unsafe usage of static variable
2025-11-20 02:54:38 -05:00
Bryce Wilson
5f83c54f8c [Concurrency] Set thread base priority when running escalated Tasks 2025-11-20 11:15:22 +09:00
Kavon Farvardin
7c6d54efa6 OpaqueValues: fix emitDistributedActorSystemWitnessCall
This code was not consulting SILFunctionConventions, so it was
passing things indirect when they are not in sil-opaque-values.

This fixes callers as well to ensure they pass arguments and
results correctly in both modes.
2025-11-19 17:35:14 -08:00
Kavon Farvardin
199156b307 SILGen: ban getSILArgumentConvention
This function will give the wrong convention in SILGen when
using -enable-sil-opaque-values. In particular, it will say
arguments are indirect when they are not.
2025-11-19 17:32:20 -08:00
Kavon Farvardin
5e9fba115a NFC: provide deprecation & unavailable attribute macros 2025-11-19 17:32:19 -08:00
Bryce Wilson
b30f63530a [Concurrency] Set thread base priority when running escalated Tasks (#84895) 2025-11-20 09:58:08 +09:00
Arnold Schwaighofer
3cff05d540 [embedded] Implement swift_dynamicCast suport for casts from existential to concrete type 2025-11-19 14:41:37 -08:00
Slava Pestov
6c1a2df419 IRGen: LinkEntity::Kind::DifferentiabilityWitness is not a type kind
As the above comments imply, when isTypeKind() returns true, then
getType() should return a valid Type. This wasn't true with
DifferentiabilityWitness.
2025-11-19 10:19:18 -05:00
Daniil Kovalev
5bd3d80ec9 Fix build 2025-11-19 04:15:52 +03:00
Arnold Schwaighofer
17447a3378 Merge pull request #85551 from aschwaighofer/wip_embedded_exit
Preliminary support for existential in embedded Swift
2025-11-18 15:10:40 -05:00
Daniil Kovalev
c0935fcca1 Fix build 2025-11-18 22:50:44 +03:00
Egor Zhdan
4234fb7358 Merge pull request #85340 from egorzhdan/egorzhdan/revert-cs-std-string
Revert "[ConstraintSystem] C++ Interop: Binding a string literal to `std.string` shouldn't increase the score"
2025-11-18 18:51:12 +00:00
Steven Wu
e519e59acc Merge pull request #85547 from cachemeifyoucan/eng/PR-164903080
Revert "[Caching][NFC] Using llvm::cas::CASConfiguration"
2025-11-18 09:43:41 -08:00
Steven Wu
b56f541732 Merge pull request #85499 from cachemeifyoucan/eng/PR-164409895
[Caching] Fix multi-threaded WMO with MCCAS
2025-11-18 09:22:13 -08:00
Adrian Prantl
5c3a26633a Merge pull request #85519 from adrian-prantl/unregister-api
[LLDB] Add an API for unregistering MemoryBuffer modules (NFC)
2025-11-18 08:27:05 -08:00