Commit Graph

30200 Commits

Author SHA1 Message Date
Allan Shortlidge 75ee444a94 Sema: Add source loc to implicit CGFloat/Double conversion.
This ensures MemberImportVisibility diagnostics about missing imports of
CoreFoundation for `CGFloat.init(_:)` get a source location.

Resolves rdar://177380270.
2026-05-19 14:50:32 -07:00
Allan Shortlidge de6676024a Merge pull request #88489 from tshortli/member-import-visibility-allow-default-implementations
Sema: Allow default implementations of conformance requirements regardless of visibility
2026-05-19 14:00:01 -07:00
Xi Ge e562a4b6c1 Merge pull request #89227 from nkcsgexi/hide-types-on-emit 2026-05-18 19:19:49 -07:00
Slava Pestov e33a43aa3e Merge pull request #89167 from slavapestov/clean-up-variadic-parameter-requirement-check
Sema: Fix crash when declaring an old-style variadic parameter with nonescaping type
2026-05-18 22:19:08 -04:00
Slava Pestov 1de87f81b5 Merge pull request #89215 from slavapestov/create-implicit-constructor-generic-property-wrapper-fix
Sema: Fix type parameter/archetype mixup in createImplicitConstructor()
2026-05-18 17:33:40 -04:00
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
Slava Pestov f05d1cab32 Sema: Fix crash when declaring an old-style variadic parameter with nonescaping type
This is not supported for the same reason you can't have a noncopyable
variadic parameter, but the code was hard-coded to check for copyability
only.

Generalize this to apply the generic signature for Array via the
common code path, and add a custom note to explain why those requirements
are checked in the first place.

Cleaning this up also fixed some fuzzer crashes.

Reported on the forums:
https://forums.swift.org/t/variadic-escapable-arguments-crash-the-compiler/86727/2
2026-05-18 10:49:23 -04:00
Slava Pestov 853db7a568 Sema: Fix type parameter/archetype mixup in createImplicitConstructor()
Some new logic was added in 8bb3bf09fb but
it would overwrite a contextual type stored in the 'type' local variable
with an interface type.

Instead, let's only map the type into the generic environment after we
figure out what's going on with the property wrapper.
2026-05-18 10:33:57 -04:00
Xi Ge 0e96664855 Merge pull request #89177 from nkcsgexi/serialize-hidden-type-layout 2026-05-16 06:20:06 -07:00
Hamish Knight 16742ae9fa Merge pull request #89126 from hamishknight/try-fix
[Sema] Fix missing async sequence `for` loop throwing diagnostic
2026-05-15 20:54:06 +01:00
Xi Ge 7972ea36ee Merge remote-tracking branch 'origin/main' into serialize-hidden-type-layout 2026-05-15 10:12:20 -07:00
Xi Ge 00897a0efb [Serialization] Add precomputed layout table for hidden types
Add the module-format machinery that lets a Swift library record the
physical layout of hidden types (currently limited to C types imported via internal bridging header).
into binary modules, so downstream consumers can pull the layouts of these hidden types without
loading the internal dependency.

To test this, this change also added a frontend action to print hidden types' layouts
from both the module under compilation and all the modules being imported.
2026-05-15 10:07:19 -07:00
Kavon Farvardin 19119ad88a introduce @_preInverseGenerics(except:)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
2026-05-14 18:27:00 -07:00
Pavel Yaskevich c296d3fb47 [TypeChecker] PropertyWrappers: When setting projected value setter access account for projectedValue setter
Previously, the synthesis set the access of the setter of a newly
synthesized projected value property to match that of the parent
property setter, but `projectedValue` of the property wrapper could
be less accessible than that and the synthesis needs to account
for that. Otherwise, the interface file might get a setter printed
even though it's not part of the ABI.

Resolves: rdar://176978806
2026-05-14 09:47:35 -07:00
Hamish Knight bbef9e16b8 [Sema] Fix missing async sequence for loop throwing diagnostic
The diagnostic for an async sequence `for` loop missing a `try` got
accidentally dropped during the `for` loop desugaring rework. Restore
it here.

rdar://177062849
2026-05-14 12:55:50 +01:00
Allan Shortlidge 233906cd57 Sema: Allow default implementations of conformance requirements regardless of visibility.
When checking conformances, if the witness to a protocol requirement is the
default witness for that requirement, ignore MemberImportVisibility
restrictions. A default witness is the witness that will be used at runtime for
a conformance to a resilient protocol when the conformance does not provide its
own witness. Default witnesses must belong to an unconstrained extension of the
protocol and be declared in the same module as that protocol. This exception is
necessary because otherwise evolving a protocol by adding a new requirement
with a default witness is potentially source breaking, even though it would not
be ABI breaking.

Resolves https://github.com/swiftlang/swift/issues/87227 and rdar://170348842.
2026-05-13 09:47:14 -07:00
Xi Ge 4f60cc6e6e Merge pull request #89057 from nkcsgexi/hidden-type 2026-05-13 06:38:57 -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
Artem Chikin 2a01c35e53 Merge pull request #88952 from artemcm/ImprovedLiteralExpressions
[Literal Expressions] Improvements to semantics to address feedback
2026-05-12 10:48:56 +01:00
Pavel Yaskevich 7cf861b9e5 Merge pull request #88811 from xedin/optimize-nonisolated-nonsending-emission
[Concurrency] SILGen: Emit special closures that behave like `nonisolated(nonsending)`
2026-05-11 16:53:05 -07:00
Slava Pestov 40cb62fb54 Merge pull request #88480 from slavapestov/additional-dynamicmemberlookup-args-v2
[Sema] Support additional args in @dynamicMemberLookup subscripts 2.0
2026-05-11 17:56:52 -04:00
Doug Gregor 86febb3a3e Merge pull request #88979 from DougGregor/export-interface-types-and-conformances
[Embedded] Extend @export(interface) to non-generic types and protocol conformances
2026-05-11 11:25:10 -07:00
Doug Gregor 7c3b534eab Diagnose @export(interface) on generic types in embedded swift 2026-05-10 15:34:30 -07:00
Allan Shortlidge 18e4fd76b5 Merge pull request #88886 from tshortli/improve-use-any-apple-os-diags
Sema: Improve `UseAnyAppleOSAvailability` diagnostics
2026-05-08 14:41:40 -07:00
Slava Pestov 25e3f47a1c Sema: Tweak @dynamicMemberLookup diagnostics
Make sure we diagnose something if we had an invalid subscript,
but don't diagnose an error in the case we used to emit an
access control warning.
2026-05-08 15:46:20 -04:00
Slava Pestov 1f269ebcf0 AST: Remove SubscriptDecl field from DynamicMemberLookupSubscriptEligibility 2026-05-08 15:46:20 -04:00
Slava Pestov 6b84857d6f AST: Remove useDC parameter from getDynamicMemberLookupKind() 2026-05-08 15:46:20 -04:00
Slava Pestov 97d6221295 Sema: Remove redundant call to setType() 2026-05-08 15:46:19 -04:00
Slava Pestov 94cf639f8c Sema: Replace counted for loop with for loop over indices 2026-05-08 15:46:19 -04:00
Slava Pestov 2caba51bc0 Sema: Remove unused variable from buildArgumentListForDynamicMemberLookupSubscript() 2026-05-08 15:46:19 -04:00
Slava Pestov 9c94940eaa Sema: Simplify source range logic in DynamicMemberLookupSubscriptEligibility::diagnose() 2026-05-08 15:46:19 -04:00
Slava Pestov 8d29946c99 Sema: Use llvm::indices() in dynamic member lookup checking 2026-05-08 15:46:19 -04:00
Slava Pestov e8f000647d Sema: Remove redundant vector from AttributeChecker::visitDynamicMemberLookupAttr() 2026-05-08 15:46:19 -04:00
Slava Pestov 29768061ef Sema: Remove useDC parameter from DynamicMemberLookupSubscriptRequest 2026-05-08 15:46:18 -04:00
Slava Pestov 4926234b54 Sema: Remove SubscriptDecl::isValidDynamicMemberLookupSubscript() 2026-05-08 15:46:18 -04:00
Slava Pestov fa2448b4ff Sema: Migrate dynamic member lookup to use matchCallArguments() 2026-05-08 15:46:18 -04:00
Slava Pestov 2c62d6ed5d Sema: Add MatchCallArgumentResult::dump() 2026-05-08 15:46:18 -04:00
Itai Ferber 7055622ed1 Migrate @dynamicMemberLookup subscript override checking to OverrideMatcher
This validation was being performed too late in override checking, and
is appropriate to perform along with other checks in
`checkSingleOverride`.
2026-05-08 15:46:18 -04:00
Itai Ferber ea785dcef9 Improve @dynamicMemberLookup diagnostics
Instead of producing a single error (with notes) for most
`@dynamicMemberLookup` failures, introduce individual errors with
fix-its.
2026-05-08 15:46:17 -04:00
Slava Pestov 092bbe120a Sema: Fix cross-module dynamic member subscripts 2026-05-08 15:46:17 -04:00
Slava Pestov b062b8a285 Convert SubscriptDecl @dynamicMemberLookup checking to request
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
2026-05-08 15:46:17 -04:00
Itai Ferber f448191d34 Support additional args in @dynamicMemberLookup subscripts
Adds support for `SubscriptDecl`s to fulfill `@dynamicMemberLookup`
requirements if they have additional arguments after `dynamicMember:` so
long as those arguments have default values, or are variadic.

This allows exposing values like `#function`, `#fileID`, `#line`, etc.
to dynamic member lookup.
2026-05-08 15:46:17 -04:00
Slava Pestov e4f99cc3be Use SubscriptDecl interface for @dynamicMemberLookup checks
`SubscriptDecl` exposes eligibility for `@dynamicMemberLookup`
requirements directly, so the `TypeChecker` interface for these members
can be replaced.
2026-05-08 15:46:17 -04:00
Itai Ferber c191d4994c Cache SubscriptDecl @dynamicMemberLookup eligibility
`SubscriptDecl`s may get checked multiple times for eligibility in
fulfilling `@dynamicMemberLookup` requirements; since the checks are
non-trivial and the result doesn't change, this eligibility can be
cached in the decl's `Bits`.
2026-05-08 15:46:17 -04:00
Slava Pestov a2ed8c66c2 Merge pull request #88875 from slavapestov/fix-rdar152143989
Sema: Don't record bogus trail changes in salvage()
2026-05-08 15:37:53 -04:00
Allan Shortlidge e9aa9ac3f4 Merge pull request #88813 from tshortli/expand-any-apple-os-in-symbol-graphs 2026-05-08 09:35:30 -07:00
Pavel Yaskevich 0e5660b0be Merge pull request #88895 from xedin/rdar-175648722
[CodeSynthesis] Factor property wrappers into isolation decision for …
2026-05-08 09:02:59 -07:00
Artem Chikin 27a02602b9 [Literal Expressions] Reject references to publicly visible let bindings
A `let` binding declared `public`, `package`, or `open` participates in its module's ABI surface as a symbol — clients link against the declaration, not against its value, so the author is free to change the value in a future release. Folding such a reference in a literal expression would risk "baking" a module-private value into client code and remove the author's room to evolve the binding. Reject these references with a new diagnostic that reports the offending access level. `internal`, `fileprivate`, and `private` bindings continue to fold, as do Clang-imported constants.
2026-05-08 14:23:28 +01:00
Artem Chikin 0d39a2b257 [Literal Expressions] Use arithmetic shift for signed >>
The expression folder previously applied `APInt::lshr` for every `>>` regardless of signedness. For a negative signed operand this yields a large positive value and diverges from Swift runtime behavior, which performs an arithmetic right shift that preserves the sign bit.

Dispatch to `APInt::ashr` when the operand type is signed, and retain `APInt::lshr` for unsigned operands.
2026-05-08 14:23:24 +01:00
Artem Chikin 04be54c2b9 [Literal Expressions] Add support for wrapping arithmetic and masking shift operators 2026-05-08 10:52:06 +01:00