Commit Graph

1790 Commits

Author SHA1 Message Date
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
Pavel Yaskevich 201e76bfa6 [ConstraintSystem] Propagate a hole from function value to arguments/result
In diagnostic mode, propagate function value placeholder/hole to
arguments and result. This helps to avoid recording extraneous
fixes because generic parameters and leading-dot syntax arguments
cannot be inferred in this case.
2026-06-01 11:28:20 -07:00
Dario Rexin 2ff89dc880 Merge pull request #89069 from drexin/wip-166720900
[AST] Print movesAsLike if present on @_rawLayout
2026-05-14 17:21:11 -07:00
Dario Rexin e653441d08 [AST] Print movesAsLike if present on @_rawLayout
rdar://166720900

A missing movesAsLike on the attribute in an interface file will cause miscompiles.
2026-05-14 11:16:26 -07:00
Artem Chikin 68bd6ba1d1 [Source Warning Control] Ensure we do not attempt to serialize @diagnose attributes
It is already not printed into textual interfaces and we forgot to also ensure it never gets serialized into binary modules

Resolves rdar://176893559
2026-05-12 18:59:42 +01:00
Konrad Malawski c8e9b5bd9e Cleanups: remove redundant special-casing, fix rebase-dropped test content
- Remove redundant isCrossingCheck ternary in MismatchedIsolatedConformances:
  printStringForDiagnostics now correctly returns "@concurrent" for
  NonisolatedConcurrent and "nonisolated" for Nonisolated, so the manual
  override is unnecessary. Remove the isCrossingCheck field entirely.
- Change isolated_conformance_wrong_domain and
  isolated_conformance_may_cross_isolation diagnostics to accept
  ActorIsolation directly instead of StringRef, letting the diagnostic
  engine call printForDiagnostics.
- Rename ASTDumper flag from "isolated_to_caller_isolation" to
  "nonisolated_nonsending".
- Restore SIL test CHECK lines that lost @caller_isolated annotations
  during rebase conflict resolution (optimize_hop_to_executor.sil,
  attr_execution tests, SILGen tests, Serialization tests).
- Apply caller_isolation_inheriting -> nonisolated(nonsending) rename
  to restored test files.
2026-04-28 09:21:46 -07:00
Konrad Malawski 384a02d980 [Tests] NFC: Update nonisolated -> @concurrent on async declarations 2026-04-28 09:21:23 -07:00
Konrad Malawski 77ac31d946 Rename to ActorIsolation::Kind::Nonisolated*Concurrent* 2026-04-28 09:21:23 -07:00
Joe Groff 097b0d3400 SIL: Split unchecked_*_enum_data_addr according to ownership and effects.
We cannot use spare bits or other overlapping storage layout tricks with fundamentally
address-only enums, and we can take advantage of this to do borrowing switches or other
in-place projections without copying the value. However, for resilient enums, the
implementation may use spare bit packing, but the type must be handled address-only
outside of its defining module, and we didn't have a way to express that with
borrowing switch. Optimization passes have also been running into problems with the
complexity that we were using `unchecked_take_enum_data_addr` sometimes as a pure
operation. This patch splits the instruction into three:

- `unchecked_inplace_enum_data_addr` represents a nondestructive in-place enum
  projection. It is only allowed for enums whose projection operation is
  nondestructive.
- `unchecked_take_enum_data_addr` represents a destructive enum projection,
  invalidating the enum and leaving the payload to be further consumed.
  This matches the current instruction's semantics.
- `unchecked_borrow_enum_data_addr` represents a borrowing enum projection.
  The instruction takes a second operand for "scratch" space, which the
  enum representation may be copied into in order to avoid invalidating the
  enum value, so the result is dependent on the lifetime of both the
  original enum and the scratch buffer. This allows for borrowing switches
  over resilient enums.

`unchecked_borrow_enum_data_addr` is implemented by taking advantage of the
"address-only enums can't do spare bit optimization" property at runtime.
We inspect the operand type's bitwise-borrowability from its metadata. If
the type is bitwise-borrowable, then we are allowed to bitwise-copy the
enum to the scratch space and apply the projection to the scratch space,
preserving the original value. If the type is not bitwise-borrowable, then
we cannot use spare bit optimization in its layout, so we apply the
projection in-place.

Fixes rdar://174952822.
2026-04-27 15:40:37 -07:00
Aidan Hall eac68b5283 LifetimeDependence: Closure lifetimes tests 2026-04-24 16:14:25 +01:00
Doug Gregor 8713c13bef Centralize computation of the "code generation model" for object code & SIL
For a given function, we might end up emitting it's definition as
object code, serialized SIL, or both. The @export, @inlinable, and
@inline(always) attributes provide control of this behavior at the
declaration level.

Centralize the query function that will look for each of these
attributes and map down to a specific "code generation model", whose 3
options follow the naming from SE-0497: interface, inlinable, and
implementation. Use this one computation to back the queries for
"always emit into client", "never emit into client", and "inlinable"
so we can't get inconsistent results from places that are doing
one-off checks for these attributes.
2026-04-15 13:03:55 -07:00
Pavel Yaskevich 98ae4222a3 Merge pull request #88404 from xedin/rdar-169998321
[AST/SIL] Expand SIL function type isolation to include `nonisolated(nonsending)`
2026-04-15 06:47:54 -07:00
Saleem Abdulrasool 2b8ee6e5a2 test: disallow llvm-bcanalyzer and use new macro
This ensures that we use the correct llvm-bcanalyzer from the just built
compiler tools.
2026-04-13 16:22:02 -07:00
Pavel Yaskevich 5b6a29fd8a [Frontend] Use @caller_isolated to represent nonisolated(nonsending) isolation of SIL function type
`nonisolated(nonsending)` is a modifier and it's really hard to
work with in SIL because most of the things are represented as
attributes there.
2026-04-13 14:18:53 -07:00
Pavel Yaskevich 25c339dba1 [SIL] Teach getSILFunctionType about nonisolated(nonsending) isolation
If a function type requires an implicit isolation parameter
also set `nonisolated(nonsending)` isolation on it. This helps
us track all of the references to `nonisolated(nonsending)`
functions.
2026-04-10 09:35:31 -07:00
Sam Pyankov a09cf04718 Serialize library level into .swiftmodule binary format
Add a LIBRARY_LEVEL record to the .swiftmodule options block so the
declared -library-level value survives across compilations. Without
this, imported modules have to always fell back to a path heuristic
that could only distinguish API vs SPI and never returned IPI.

rdar://174255626
2026-04-08 12:17:32 -07:00
Meghana Gupta 3d3d476b6f Merge pull request #88107 from meg-gupta/enableborrow
Enable BorrowAndMutateAccessors by default
2026-03-27 12:43:02 -07:00
Steven Wu e577ce4729 [TEST-ONLY] Fix test: Serialization/search-paths.swift
Fix Serialization/search-paths.swift after new driver switch.

rdar://173260313
2026-03-26 19:11:07 -07:00
Meghana Gupta d6e220669f Enable BorrowAndMutateAccessors by default 2026-03-25 16:52:39 -07:00
Steven Wu 169e7ebfe1 Merge pull request #85930 from cachemeifyoucan/fix-new-swift-driver-tests 2026-03-24 06:13:50 -07:00
Doug Gregor 22ba5f693d Diagnose the use of actor without _Concurrency imported 2026-03-23 22:25:29 -07:00
Steven Wu 12f8d9c6c9 [TEST] Switch to use new swift-driver when running tests
Default to use new swift-driver to run lit tests as legacy swift driver
is deprecated for a long time. The lit tests for legacy drivers are also
disable when running new swift-driver.

Tests that relies on legacy swift driver (for example, tests merge
module) can be enabled on conditions `legacy_swift_driver`. Fix and
split up some existing tests that relies on legacy driver.
2026-03-23 09:48:45 -07:00
Slava Pestov c197635ad9 AST: Factor out ASTContext::get{CGFloat,Double}InitDecl() from CSApply.cpp
Also, since the mock SDK's implementation of CGFloat is wrong,
update some existing tests to use the real SDK instead. This
exposed a few instances where the behavior was not as intended;
I added FIXME comments explaining what's going on.
2026-03-20 15:56:32 -04:00
Erik Eckstein 0ed01a0fc0 Optimizer: extend OSSA throughout the mid-level pass pipeline
* replace the non-OSSA ClosureSpecializer with the new OSSA ClosureSpecialization pass
* move the OwnershipModelEliminator after the mid-level and closure-specialization pipelines
* add an additional RedundantLoadElimination pass at the begin of the low-level pipeline to compensate for not eliminated loads in OSSA
2026-03-16 16:12:29 +01:00
Kavon Farvardin fe50668d0e SuppAssocTypes: add deprecation warning of legacy version
We need to start moving people over to using the version of
suppressed associated types that has the officially accepted
behavior according to SE-503, and that is via
`SuppressedAssociatedTypesWithDefaults`.

To allow for time to migrate to the new version, I'm introducing
the deprecation message as a warning for now.

This set of changes also moves most of the test suite over to using
the officially accepted version.

rdar://172231663
2026-03-10 17:08:10 -07:00
Aidan Hall 5f0d531d6e [Serialization] Test static method lifetime serialization 2026-03-04 17:08:20 +00:00
Adrian Prantl fa71d1da59 [Serialization] Store the explicit module map in swiftmodules
Currently only the top level dependencies get serialized in Swift modules. In
practice this is not enough information to fully replay a module import
sequence, especially when the dependencies include binary SDK modules that were
built elsewhere. In this case we cannot follow the links to its depenencies,
since they refer to paths on a different machine or unavailable CAS. During an
EBM build, the dependency scanner writes the complete list of dependencies into
a json file called the explicit Swift module map -- including the local
locations of the dependencies of binary SDK modules. Using this LLDB can replay
a module import with 100% accuracy.

rdar://170514919
2026-02-23 14:07:08 -08:00
Yuta Saito b5162b1804 [Serialization][wasm] Preserve wasm import metadata for SIL serialization (#87250)
Serialize/deserialize wasm import module/name for SIL serialization so inlined decls keep their import names. Otherwise, inlining a function with `@_extern(wasm)` would lose the import name and cause IRGen to emit an import from the default module "env".

Related links: https://github.com/swiftwasm/JavaScriptKit/pull/631 https://github.com/swiftwasm/JavaScriptKit/pull/628

Resolves https://github.com/swiftlang/swift/issues/87320
2026-02-23 19:24:50 +00:00
Slava Pestov f0efc2350b Sema: Add temporary flags to turn generation of transitive conformance constraints on and off 2026-02-20 21:59:24 -05:00
Becca Royal-Gordon 1f008fb0d0 [ModuleInterface] Enable module selectors by default
And update tests to use them.

This commit depends on fixes in swiftlang/swift PRs #86905, #87129, and #87130.

Fixes rdar://169749886.
2026-02-20 00:35:23 -08:00
Hunter Baker a4f20039b7 Rename SwiftSyntax experimental SPI to ExperimentalLanguageFeatures to unify naming
Replaces the other ExperimentalLanguageFeature (non-plural) SPI usages with the plural version. Also removes the `@_spi` flag from BodyMacroWithControlFlow as body macros are no longer an experimental feature. This is liked to a PR on swift-syntax: https://github.com/swiftlang/swift-syntax/pull/3272
2026-02-16 17:41:59 -05:00
Slava Pestov ae4f5e7c82 Run tests with -solver-enable-crash-on-valid-salvage 2026-02-13 09:57:22 -05:00
Alexis Laferrière 0ac40aada4 Serialization: Error on type members broken by invalid modularization
Extend support for proper errors on broken modularization to type
members, previously only top-level declarations were reported as error.
This change raises errors with relevant context if a type member is
referenced from a swiftmodule file but at reading the member is not
found or changed shape.

It doesn't report moves between modules like we do for top-level
declarations. This is less likely to happen at the member level as the
check is already applied at the top-level for the same reference. We may
still see such issues when using `SWIFT_NAME` to assign a top-level
declaration to a type from a different module.
2026-02-05 09:56:31 -08:00
Alexis Laferrière 231f43f162 Serialization: Limit modularization recovery to clang modules 2026-01-26 09:57:00 -08:00
Alexis Laferrière be0b7595fe Serialization: Enable recovery from types moving between modules by default 2026-01-26 09:56:30 -08:00
Meghana Gupta 88ede1f057 [NFC] Add ~Copyable versions to the borrow/mutate protocol tests 2026-01-20 11:44:22 -08:00
Meghana Gupta 07e945fe9e [NFC] Add serialization tests for get/set requirements satisfied by borrow/mutate accessors 2026-01-20 11:44:21 -08:00
Meghana Gupta 907fa198d7 [NFC] Add serialization tests for borrow/mutate protocol requirements 2026-01-20 11:44:20 -08:00
Gabor Horvath 6eb4d5b915 [cxx-interop] Fix crash deserializing some Clang function types
When a function type refers to a Swift declaration we get a crash during
deserialization. This patch prevents serializing the problematic clang
function types to avoid this crash.

rdar://166359524
2026-01-14 15:39:58 +00:00
Alexis Laferrière 175d0ba8e6 Serialization: Minor improvements to the error on conformance mismatch
Clarify the sources of information when a conformance reference in a
swiftmodule doesn't match with the requirements seen by the reader.
2025-12-10 15:08:03 -08:00
Erik Eckstein 8aa911ba2f Optimizer: add simplifications for destroy_value
Attempt to optimize by forwarding the destroy to operands of forwarding instructions.

```
  %3 = struct $S (%1, %2)
  destroy_value %3         // the only use of %3
```
->
```
  destroy_value %1
  destroy_value %2
```

The benefit of this transformation is that the forwarding instruction can be removed.

Also, handle `destroy_value` for phi arguments.
This is a more complex case where the destroyed value comes from different predecessors via a phi argument.
The optimization moves the `destroy_value` to each predecessor block.

```
bb1:
  br bb3(%0)
bb2:
  br bb3(%1)
bb3(%3 : @owned T):
  ...                // no deinit-barriers
  destroy_value %3   // the only use of %3
```
->
```
bb1:
  destroy_value %0
  br bb3
bb2:
  destroy_value %1
  br bb3
bb3:
  ...
```
2025-12-03 15:53:55 +01:00
Mishal Shah a1b41acf8d Merge pull request #85550 from hjyamauchi/guid
Fix the issue that struct _GUID isn't found on Windows
2025-11-21 09:32:28 -08: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
Hiroshi Yamauchi be641d73ef Fix the GUID type not found error on Windows
Predefined declarations (like _GUID) are special forward declarations
inserted by Clang and aren't serialized into the pcm and their
definition pointers aren't retained across serialization and
deserialization, which causes this type not found error. Avoid putting
non-defining predefined declarations into the swift lookup table when
their definitions exist in the same module so that the definitions
will be associated with the base name and avoid this error.
2025-11-19 17:27:50 -08:00
Alexis Laferrière 937e6c5241 Merge pull request #85446 from xymus/serial-xref-check
Serialization: Error on leaked cross-references to `@_implementationOnly` dependencies
2025-11-12 10:42:58 -08:00
Alexis Laferrière 5a49e34426 Serialization: Error on xref to implementation-only dependencies
Introduce a last resort check reporting references to
implementation-only dependencies that would appear in the generated
swiftmodule. This check is applied at serialization, long after
exportability checking applied at typechecking. It should act as a back
stop to references missed by typechecking or @_implementationOnly decls
that should have been skipped.

This check is gated behind CheckImplementationOnlyStrict and should be
used with embedded only.

rdar://160697599
2025-11-11 13:03:16 -08:00
Adrian Prantl 11356acd44 Merge pull request #85397 from adrian-prantl/163167975
[SILOptimzer] Fix a crash caused by SILCombine mishandling inlined variables
2025-11-10 18:41:07 -08:00
Adrian Prantl 99cf35cdce [SILOptimzer] Fix a crash caused by SILCombine mishandling inlined variables
This showed up on and off again on the source-compatibility testsuite project hummingbird.

The gist of the problem is that transformations may not rewrite the
type of an inlined instance of a variable without also createing a
deep copy of the inlined function with a different name (and e.g., a
specialization suffix). Otherwise the modified inlined variable will
cause an inconsistency when later compiler passes try to create the
abstract declaration of that inlined function as there would be
conflicting declarations for that variable.

Since SILDebugScope isn't yet available in the SwiftCompilerSources
this fix just drop these variables, but it would be absolutely
possible to preserve them by using the same mechanism that SILCloner
uses to create a deep copy of the inlined function scopes.

rdar://163167975
2025-11-07 17:06:33 -08: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
Kuba (Brecka) Mracek eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00