Commit Graph

1993 Commits

Author SHA1 Message Date
Xi Ge 886f856f7e [Serialization] Substitute HiddenType for hidden stored-property types when emitting binary modules
The substitution is driven by a canonical type to mangled name table on ASTContext,
populated by exportability checking at the same site where the corresponding
diagnostics are suppressed. After this change, the module emitter and module
loader see hidden types differently: the emitter still sees the real types
defined in the bridging header, while the loader sees only a mangled name
wrapped in a HiddenType placeholder.
2026-05-18 12:48:59 -07:00
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Allan Shortlidge e4df98c532 Use std::uninitialized_copy instead of memcpy for lifetime dependencies.
Resolves the following warning:
```
ASTContext.cpp:5475:47: warning: first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'swift::LifetimeDependenceInfo' [-Wnontrivial-memcall]
```

Fixes a regression from https://github.com/swiftlang/swift/pull/87217.
2026-05-08 16:10:18 -07:00
Kavon Farvardin 21b2ebff12 Sema: infer inverses in opaque return types
Opaque return types are special type declarations that have it
own nested generic signature. Thus, given this:
```
  protocol P<A> { associatedtype A: ~Copyable }
  func f<T: ~Copyable>() -> some P<T> {}
```
The generic signature for f is <T where T Escapable>, and
for the opaque return type, its nested signature ends up as
```
  <X where X: P, X.A == T>
```
With SE-503, we will now also expand a default for the suppressed
primary associated type, so the signature after expansion becomes
```
  <X where X: P, X.A == T, X.A: Copyable>
```
It would be smarter to effectively have this rule
```
  X.A == T, T: ~Copyable
  ----------------------
     X.A: ~Copyable
```
where we infer the inverse on X.A to cancel-out the
expanded default X.A: Copyable. We already do this for
two in-scope type parameters, and it would be better if
we did it if one side was out-of-scope, but that would
be source-breaking to do in general.

In the case of opaque return types, the fact that
it has a nested generic signature seems more an
artifact of the implementation. There also is little
risk of source break, as the only kinds of same-type
requirements that can appear are from parameterized
protocol type.

The experimental suppressed associated types prior to
SE-503 wouldn't be broken by this change, as they do
not infer defaults that need suppression, and we only
filter-out requirements from defaults expansion, rather
than explicitly-written ones.

rdar://175500824
2026-05-04 14:49:34 -07:00
Kavon Farvardin 6651cb6389 NFC: refactor the applyInverses bool
There's a need for more control over how default requirements
for conformance to Copyable/Escapable are expanded, and
subsequently how inverses are applied or inferred to cancel-out
those defaults.

The pattern of `/*applyInverses*/BOOL` is insufficient, so this
is a refactoring to grow that into a proper type that carries
an option that can be used in some future scenario about inferring
inverses for opaque return types.
2026-04-29 16:56:00 -07:00
Pavel Yaskevich 1f8c8e149e [SILOptimizer] Prevent function signature optimization from removing implicit leading isolation parameter
Doing so changes isolation because the invariant is that if
the function is `@caller_isolated` it should have an implicit
leading parameter.
2026-04-13 14:19:04 -07:00
Slava Pestov e7a94ee205 AST: Remove TypeBase::hasDependentMember()
I need to free up a bit.
2026-03-21 08:48:47 -04: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
Steven Wu 3ba1ba45d4 Merge pull request #87892 from cachemeifyoucan/eng/PR-172693314
[DependencyScan] Propagate module library level through dependency scanner for CAS builds
2026-03-18 09:08:27 -07:00
Steven Wu 34d52cfe1a [DependencyScan] Propagate module library level through dependency scanner for CAS builds
Compute and propagate the library level (api/spi/ipi) of each module
dependency through the dependency scanner so that the compiler can
correctly enforce private module import diagnostics in CAS mode, where
path-based SPI detection fails because CAS abstracts file paths to
content IDs.

Swift modules:
- Detect library level from the module interface path using
  libraryLevelFromPath() during scanning, for both textual (.swiftinterface)
  and binary (.swiftmodule) Swift modules.

Clang modules:
- Expose ModuleMapIsPrivate from clang::Module in ModuleDeps via the
  dependency scanning infrastructure.
- Set library level for clang modules in bridgeClangModuleDependency()
  using ModuleMapIsPrivate (catches module.private.modulemap in any
  SDK location) and libraryLevelFromPath() on the module map file
  (catches modules under PrivateFrameworks directories).

The library level is:
- Stored in ModuleDependencyInfo and serialized in the module dependency
  cache (format version bumped to v8).
- Exposed through the swiftscan C API via a new
  swiftscan_module_info_get_library_level() function (API minor version
  bumped to 3).
- Emitted in the dependency scanner JSON output as "libraryLevel" for
  all module kinds (Swift textual, Swift binary, Clang, and main module).
- Parsed from the explicit module map JSON by ExplicitModuleMapParser
  for both Swift (ExplicitSwiftModuleInputInfo) and Clang
  (ExplicitClangModuleInputInfo) modules.
- Looked up in ModuleLibraryLevelRequest via
  ASTContext::getExplicitModuleLibraryLevel(name, isClang), which
  consults the appropriate map (Swift or Clang) based on module kind.

rdar://172693314

Assisted-By: Claude
2026-03-17 11:04:18 -07:00
Allan Shortlidge 8dee947aa3 AST: Relax availability checking for decls in unavailable contexts.
Loosen availability checking to allow references to a decl that is unavailable
in a broader platform context in contexts which are unavailable in a more
specific platform context. For example, `@available(macOS, unavailable)` decls
should be allowed in `@available(macOSApplicationExtension, unavailable)`
contexts. This enhancement, which has always been desirable but wasn't high
priority, became more important with the introduction of `anyAppleOS`. Some
library authors may replace platform-specific availability annotations with
`anyAppleOS` availability and without this behavior change those attribute
updates would be source breaking.

Test updates assisted by claude.
2026-03-16 14:49:09 -07:00
Hamish Knight 11070797cf [AST] Factor out Type::replaceTypeVariablesAndPlaceholdersWithErrors 2026-03-10 23:42: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
susmonteiro e2752096b6 [cxx-interop] Add CxxBorrowingSequence to the C++ stdlib overlay 2026-02-13 08:37:29 +00:00
elsa af7069a10e Merge pull request #86811 from elsakeirouz/for-in-borrowing-support-no-stdlib-changes
ForEach support for Borrowing sequence

For testing purposes, this commit includes _BorrowingSequence and _BorrowingIterator protocols, with conformance for Span and InlineArray.
2026-02-12 10:08:24 +00:00
Hamish Knight 64d4e85b13 Merge pull request #87139 from hamishknight/return-to-sender
[CS] A couple of Sendable dependence fixes
2026-02-11 21:06:37 +00:00
Steven Wu ce64a73316 Merge pull request #87098 from cachemeifyoucan/eng/PR-169886913
[SDKInfo] Fix SDKInfo loading to use correct VFS
2026-02-11 09:58:40 -08:00
Elsa Keirouz 2a0bc57763 [AST] desugar ForEachStmt for BorrowingSequence protocol 2026-02-11 16:02:25 +00:00
Hamish Knight 131073553d [AST] Fold away sendable dependence for replacingTypeVariablesAndPlaceholders
Make sure we eliminate the type variables present in the sendable
dependent type if present.
2026-02-11 12:08:32 +00:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Steven Wu 17d969924c [SDKInfo] Fix SDKInfo loading to use correct VFS
Partially revert https://github.com/swiftlang/swift/pull/86309. Keep the
SDKInfo parsing in the ASTContext separately from the search path
configuration. This allows the availablity checking to load SDKSettings
from the correct VFS.

rdar://169886913
2026-02-09 15:03:53 -08:00
Hamish Knight 2bcd8c791e [AST] Introduce Sendable-dependent functions
These will allow the constraint system to represent function types 
that have sendability that depends on the sendability of an
unresolved type.
2026-01-27 11:06:54 +00:00
Joe Groff 373211a902 SILGen: Lowering for Builtin.makeBorrow 2026-01-23 08:02:08 -08:00
Joe Groff bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Steven Wu 9d76a62a33 Merge pull request #86501 from cachemeifyoucan/eng/PR-167784812
[ScanDependency] Fix canImport when versioned checks all eval to false
2026-01-21 09:59:21 -08:00
Michael Gottesman f10ca1c949 [sil] Add convenience APIs to SILBoxType for generics safe field access
Before this patch it was easy to try to work with the types in a SILBoxType by
accessing the layout of the SILBoxType... especially if one was working with
mutability since there wasn't any comment/APIs on SILBoxType that pointed one at
the appropriate API on SILType.

To make this easier to use and self document, I added some new helper APIs onto
SILBoxType that:

1. Let one grab the fields without touching the layout. The layout is an
internal detail of SILBoxType that shouldn't be touched unless it is necessary.

2. Get a specific properly specialized SILType of a SILType for a given
SILFunction.

3. Access the number of SILFIelds and also whether or not a specific SILField is
mutable.

4. Yields a transform range that transform the SILFields in the SILBoxType into
a range of properly specialized SILTypes.

This should prevent these sorts of mistakes from happening in the future.
2026-01-16 08:22:21 -08:00
Michael Gottesman 307892451f [ast] Add a new helper SILBoxType::withMutable to take in a SILBoxType and produce a new BoxType with mutated mutability of its fields.
This is properly prepared for multiple field boxes since we take in an
initializer_list of fields/mutability changes.

Given that I made this change to SILBoxType, I aligned the same API on SILLayout
to also take an initializer_list of fields/mutability changes instead of just
assuming a single field layout.
2026-01-16 08:22:21 -08:00
Steven Wu c5189de182 [ScanDependency] Fix canImport when versioned checks all eval to false
Fix a corner case when following conditions are met in a single module:
* Module A is imported in the current module
* There exists a versioned `canImport` check for a module A
* All `canImport` check within the module evaluated to false

If all above conditions are met, swift-frontend will not received the
version number from scanner, and it will be confused if version is
either not available (thus a warning, and treat as true), or condition
is not met (eval to false).

Now make sure if when scanner tries to resolve `canImport`, it will
record all instances that a module can be imported, or a version of the
module is found.

rdar://167784812
2026-01-12 15:57:52 -08:00
Ian Anderson 48ab4b0595 [Frontend][Darwin] Use the system prefix from SDK when constructing the default search paths
Some Darwin platforms like DriverKit use a system prefix on all of their search paths. Even though DriverKit isn't supported, add support to get the system prefix from SDKSettings when constructing the default search paths.

This requires the DarwinSDKInfo to be gotten earlier in CompilerInvocation, pass that down to ASTContext through CompilerInstance.

-platform-availability-inheritance-map-path is no longer needed to support visionOS in tests, remove that and its supporting code that gets an alternative DarwinSDKInfo.

rdar://166277280
2026-01-09 12:41:32 -08:00
Artem Chikin 828813c7e4 Merge pull request #85036 from artemcm/AddSupportForWarnAttr
Add support for a declaration attribute `@warn` for source-level warning group behavior control
2025-12-14 19:14:36 -08:00
Slava Pestov 54521bd21b AST: Canonicalize opaque archetype substitution maps in the solver arena
Preserving sugar if we have type variables uses way too much memory.

Canonicalize these substitution maps for now, as a (temporary?) workaround.

In the future, if we decide preserving sugar is more important than a
few dozen Mb of memory usage, we can also bump the arena memory limit,
instead.

Fixes rdar://166237860.
Fixes rdar://165863647.
2025-12-12 18:11:04 -05:00
Artem Chikin 8e97cb4d8d Implement support for unified warning group behavior queries per-diagnostic
Unified across module-wide configuration flags (`-Wwarning`, `-Werror`, etc.) and syntactic configuration attribute `@warn`.
2025-12-12 10:14:20 -08:00
Hamish Knight 302e803b2f [AST] Store original lazy VarDecl for backing storage
Store the original VarDecl in the same map we use for tracking the
original wrapper var for property wrappers. This will allow us to
use the same logic to determine the original var for both.
2025-12-08 23:22:35 +00:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00: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
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Anthony Latsis 8992ea82a2 Merge pull request #85433 from swiftlang/jepa-main4
AST: Rename `GenericContext::isGeneric` to `hasGenericParamList`
2025-11-11 21:12:34 +00:00
Anthony Latsis bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Hamish Knight 33e6c0fb6c [AST] Also cache protocol kind in getBuiltinInitDecl
Make sure we don't return the wrong witness if you query with 2
different builtin protocol kinds.
2025-11-10 15:57:33 +00:00
Hamish Knight 92e5e7b5b7 [AST] Remove asserts from getBuiltinInitDecl
Allow querying for types that may not conform. Failures here should
be asserted downstream (e.g in `setBuiltinInitializer`).
2025-11-10 15:57:33 +00:00
Joe Groff e002d96ac9 Merge pull request #85169 from jckarter/builtin-generic-base-class
Add a BuiltinGenericType base class.
2025-10-31 12:45:58 -07:00
Becca Royal-Gordon 393965090e Merge pull request #34556 from beccadax/mod-squad-2
[SE-0491] Implement lookup and diagnostics for module selectors (MyMod::someName)
2025-10-28 16:00:26 -07:00
Joe Groff cf5f7c8637 Add a BuiltinGenericType base class.
Builtin.FixedArray was introduced as the first generic builtin type, with
special case handling in all the various recursive visitors. Introduce
a base class, and move the handling to that base class, so it is easier
to introduce other generic builtins in the future.
2025-10-28 12:48:18 -07:00
Becca Royal-Gordon 64d8b70942 Make DeclNameRef able to store a module selector
In this commit, this change affects certain diagnostics but doesn’t actually alter name lookup behavior yet.
2025-10-24 16:23:33 -07:00
Adrian Prantl c91211a5d2 Serialize explicit module dependencies in swift module files
For clients, such as the debugger, who do not have access the full
output of the dependency scanner, it is a huger performance and
correctness improvement if each explicitly built Swift module not just
serialized all its Clang .pcm dependencies (via the serialized Clang
compiler invocation) but also its direct Swift module dependencies.

This patch changes the Swift module format to store the absolute path
or cas cache key for each dependency in the INPUT block, and makes
sure the deserialization makes these available to the ESML.

rdar://150969755
2025-10-21 09:08:58 -07:00
Allan Shortlidge 3151bcb1d8 Merge pull request #84943 from tshortli/silgen-swift-runtime-availability
stdlib/SILGen: Emit SIL for Swift runtime availability queries
2025-10-16 15:08:09 -07:00
Hamish Knight 73710e3eef [AST] Introduce Decl::addAttribute
Introduce a convenience entrypoint that also calls `attachToDecl` on
the attribute, and migrate all existing uses of `getAttrs().add` onto
it.
2025-10-16 11:21:54 +01:00
Allan Shortlidge 085f8ecca9 stdlib/SILGen: Emit SIL for Swift runtime availability queries.
When emitting SIL for `if #available(Swift ..., *)` queries, call the new
`_isSwiftRuntimeVersionAtLeast()` function in the stdlib to check the
condition. To support back deployment, the implementation of
`_isSwiftRuntimeVersionAtLeast()` is `@_alwaysEmitIntoClient` and performs its
comparison against the result of `_SwiftStdlibVersion.current`, which is
pre-existing ABI that the stdlib exposes for querying the Swift runtime
version.

Resolves rdar://162726037.
2025-10-15 22:42:53 -07:00
Hamish Knight a83ea3c8bb Merge pull request #84745 from hamishknight/fishmonger
[Evaluator] Enforce consistent results for cyclic requests
2025-10-09 17:08:04 +01:00
Hamish Knight 48ac5126d9 [AST] Fold away nested ErrorTypes
Remove the now-unnecessary hack where we could build recursive
ErrorTypes.
2025-10-08 21:16:02 +01:00