Commit Graph

1034 Commits

Author SHA1 Message Date
Konrad Malawski 4e4769de49 Rename stale CallerIsolated to NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Allan Shortlidge 38988365d3 AST: Filter out un-imported overrides when MemberImportVisibility is enabled.
When performing qualified lookup with MemberImportVisibility enabled, always
filter out all overridden methods that come from modules that have not been
imported. This ensures that new overrides of a method in dependencies are not
source breaking for dependents with MemberImportVisibility enabled. This
generalizes the logic added in https://github.com/swiftlang/swift/pull/81089
that was previously limited to overrides coming from Obj-C categories.

Resolves rdar://170089840.
2026-04-10 16:21:28 -07:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Kavon Farvardin 858cf2b37a Reparenting: adjust name lookup for associated types
We don't consider an associated type of a @reparentable protocol
to be an overridden decl of any protocols inheriting from it.
If we did, then it'd affect how getReducedType and other bits of
comparison between associated types work, because they prefer
anchors, i.e., associated types not overriding anything else
(see `swift::compareAssociatedTypes`).

That worked fine until availability checking brought to light that
name lookup also relies getOverriddenDecls() to determine which
associated type decl one would be the one we refer to in a protocol.
So in this case it's not the reduced type, but rather the actual
`DeclRefTypeRepr` that name-lookup finds for `Element`, that actually
_does_ need to view that one coming from the @reparentable one as being
"overridden", or shadowed I guess, by any other protocols downstream of it.

rdar://170819864
2026-02-20 18:04:35 -08:00
Kavon Farvardin fa7e9b3437 Merge pull request #87232 from kavon/reparenting-availability-2-redo
Reparenting: handle less-available reparented base protocols
2026-02-17 00:37:29 -08:00
Kavon Farvardin 35758d4956 Reparenting: diagnose duplicate reparentings
I could be confusing to have more than one, because one could
declare different conditions in the `where` clauses of the
extensions, to witness associatedtype requirements using
different types.
2026-02-16 11:43:26 -08:00
Kavon Farvardin 494b449851 Reparenting: introduce getReparentingProtocols
This centralizes the search for the extension defining
the reparenting.
2026-02-12 15:29:15 -08:00
Becca Royal-Gordon 710e2af8ed Fix module selector lookup with C++ members
Imported C++ declarations have some complicated special cases relating to module ownership that module selectors did not previously take into account. This meant that members of C++ classes and namespaces would sometimes only allow a module selector of `__ObjC` rather than the module they would normally be attributed to. Fix this oversight.
2026-02-10 16:48:25 -08:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Kavon Farvardin 6dda8b98d9 Reparenting: require statement of inheritance
We were walking the extensions of protocols in
requirement lowering and in getInheritedProtocols
to also count the @reparented entries in all
extensions. I had already seen some request
evaluator cycles triggered by this with objc
protocols, and it seems unnessecary as it's
actually a benefit to force people to write the
inheritance on the protocol itself.
2026-02-06 13:23:22 -08:00
Kavon Farvardin 006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00
Slava Pestov 62e4979691 AST: Prefer associated types over protocol type aliases 2026-01-06 11:50:32 -05:00
Slava Pestov e075e3df1e AST: Introduce NL_RemoveAssociatedTypes 2026-01-05 19:27:45 -05:00
Anthony Latsis 153dd02cd8 Merge pull request #85833 from swiftlang/jepa-main
[NFC] "SwiftVersion" → "LanguageMode" in `DiagnosticEngine::warnUntilSwiftVersion`, etc.
2025-12-05 09:34:30 +00:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Becca Royal-Gordon b9747b77da Don’t repeat lookup work that may not round-trip
When a DeclRefTypeRepr is bound to a known declaration, the exact DeclNameRef used to create it is erased. This means that we no longer know exactly which module selector was used in the source code, so repeating the lookup with the same instance might produce different results.

Avoid this problem by reusing the bound decl instead of trying to look up the same declaration again.

Fixes rdar://164647850.
2025-11-15 19:16:12 -08: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
Pavel Yaskevich 5f91e49c9c Merge pull request #85105 from xedin/rdar-140928937
[AST/Sema] Allow `Sendable` suppression on Objective-C class declarations
2025-11-07 15:09:35 -08:00
Hamish Knight 9981dc8126 [AST] NFC: Move shouldPreferPropertyWrapperOverMacro onto CustomAttr 2025-11-06 14:39:52 +00:00
Becca Royal-Gordon ec92be4955 Support module selectors for cross-import overlays 2025-10-24 16:23:50 -07:00
Becca Royal-Gordon ffaa35810c Handle lookup into Builtin with module selector
Lookups like Builtin::Int64 were failing because BuiltinUnit rejected all unqualified lookups. Make it allow unqualified lookups with a module selector.
2025-10-24 16:23:48 -07:00
Becca Royal-Gordon 1dfc0bff86 Handle module selectors in qualified lookup 2025-10-24 16:23:33 -07:00
Pavel Yaskevich 65599ce1f1 [AST/Sema] Allow Sendable suppression on Objective-C class declarations
Expressed as `__swift_attr__("~Sendable")` this acts like `: ~Sendable`
on Swift type declarations and supersedes `@_nonSendable(_assumed)`.

Resolves: rdar://140928937
2025-10-24 20:36:24 +09:00
Hamish Knight 485dda20bd [AST] Prefer parent PatternBindingDecl as owner for CustomAttr
If we have a VarDecl, use its parent PatternBindingDecl as the owner
to ensure we can correctly represent pattern bindings that bind multiple
vars.
2025-10-16 11:21:54 +01:00
Hamish Knight 4b41fe1142 [NameLookup] Prefer property wrapper over attached macro on local var
We don't properly support peer declarations in local contexts, as such
if we have both a property wrapper and macro with a given name on a
local var, let's prefer the property wrapper.

rdar://148782639
2025-10-13 13:37:29 +01:00
Hamish Knight 2b8a1cccfd [AST] Store owning Decl/DeclContext on CustomAttr
Introduce CustomAttrOwner that can store either a Decl for an
attached attribute, or a DeclContext for e.g a type or closure
attribute. Store this on CustomAttr such that we can query it from
the name lookup requests.
2025-10-13 13:37:29 +01:00
Hamish Knight 8ec8902e56 [Sema] Reject tuple extensions early when feature is disabled
Tuple extensions are still an experimental feature, but we have a
number of crashers in the repo for them because we still use their
type-checker machinery even when disabled. Change the logic here such
that we reject them early in extension binding when the feature is
disabled. This will ensure we address the crashers before productizing.
2025-10-05 11:22:54 +01:00
Hamish Knight 17fe3de8c7 [Sema] Clean up extension binding a little
- Turn `BindExtensionsForIDEInspectionRequest` into the main extension
binding request.
- Change `ExtendedNominalRequest` such that it's no longer what
extension binding calls into to do the name lookup, instead it calls
directly into `computeExtendedNominal`. `getExtendedNominal` can
then be the entrypoint for `ExtendedNominalRequest` and assumes that
extension binding has already run. This avoids needing to fake the
dependency relationship in the DeclChecker.
2025-09-09 23:18:52 +01:00
Anthony Latsis fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Anthony Latsis ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Slava Pestov d4280d4f98 AST: Add excludeMacroExpansions parameter to computeExtendedNominal() 2025-06-11 20:07:42 -04:00
Allan Shortlidge aca604660f AST/Sema: Make MemberImportVisibility a migratable feature.
The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
2025-05-30 15:34:08 -07:00
Allan Shortlidge f3ef07083b AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled.
Unlike in Swift, Obj-C allows method overrides to be declared in extensions
(categories), even outside of the module that defines the type that is being
extended. When MemberImportVisibility is enabled, these overrides must be
filtered out to prevent them from hijacking name lookup and causing the
compiler to insist that the module that defines the extension be imported.

Resolves rdar://145329988.
2025-04-25 08:05:32 -07:00
Allan Shortlidge a8ce5462a0 Revert "AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled."
This reverts commit eafb84713e.
2025-04-21 17:04:11 -07:00
Becca Royal-Gordon d81ffe854f Typecheck ABI-only VarDecls
The decl checker was effectively not being run on these because we weren’t typechecking the PBD and typechecking the VarDecl itself is basically a no-op.
2025-04-18 14:44:24 -07:00
Alejandro Alonso ae355007fc Store TypeRepr in TypeValueExpr 2025-04-14 15:33:08 -07:00
Alejandro Alonso b34b6e58e0 Make it an error to redeclare properties with the same name as a value generic
Update value_generics.swift
2025-04-14 15:32:45 -07:00
Alejandro Alonso 1aaf2c9d29 Allow value generics to show up as static members 2025-04-14 15:32:43 -07:00
Pavel Yaskevich 54b62ae983 [AST/Parse] Implement nonisolated(nonsending) type modifier 2025-04-11 15:59:25 -07:00
Allan Shortlidge eafb84713e AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled.
Unlike in Swift, Obj-C allows method overrides to be declared in extensions
(categories), even outside of the module that defines the type that is being
extended. When MemberImportVisibility is enabled, these overrides must be
filtered out to prevent them from hijacking name lookup and causing the
compiler to insist that the module that defines the extension be imported.

Resolves rdar://145329988.
2025-04-05 17:34:21 -07:00
Anthony Latsis 2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Artem Chikin 281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Becca Royal-Gordon d2276362a4 Support @abi on subscripts
And make sure we reject it on `deinit`s and accessors.
2025-03-26 10:47:57 -07:00
Anthony Latsis 631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Hamish Knight f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Anthony Latsis 487d3b4ae7 [NFC] Simplify some code using ValueDecl::getParameterList 2025-03-20 00:26:00 +00:00
Allan Shortlidge 017dae382e ClangImporter: Look up availability domains defined in bridging headers.
This is very brittle in this first iteration. For now we require the
declaration representing the availability domain be deserialized before it can
be looked up by name since Clang does not have a lookup table for availabilty
domains in its module representation. As a result, it only works for bridging
headers that are not precompiled.

Part of rdar://138441266.
2025-03-15 07:44:37 -07:00
Doug Gregor 0e873e723c [Isolated conformances] Change syntax to @<global actor type> P
Instead of using the `isolated P` syntax, switch to specifying the
global actor type directly, e.g.,

   class MyClass: @MainActor MyProto { ... }

No functionality change at this point
2025-03-12 23:18:10 -07:00
Artem Chikin 6da529f098 Merge pull request #79753 from artemcm/NewConstFeatureDefinition
[Compile Time Values] Add a new experimental feature and the parsing of the `@const` attribute
2025-03-04 12:26:04 -08:00
Pavel Yaskevich 157e71a791 Merge pull request #79478 from xedin/sendable-completion-handler-fixes
[TypeChecker/NameLookup] SE-0463: A few fixes for `SendableCompletionHandlers` feature
2025-03-04 09:34:10 -08:00