Commit Graph

720 Commits

Author SHA1 Message Date
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
Pavel Yaskevich 8bb3bf09fb [CodeSynthesis] Factor property wrappers into isolation decision for memberwise initializers
If a property has a property wrapper, the memberwise initializer
could use a wrapped type instead of a backing storage type depending
on a property wrapper capabilities. Sendable check has to be
performed on the type that would be used by the initializer.

Resolves: rdar://175648722
2026-05-06 13:48:16 -07:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Anthony Latsis 31cafb0a27 Switch DiagnosticEngine::warnUntilLanguageMode and co. to LanguageMode 2026-02-10 16:06:56 +00:00
Hamish Knight bc65846be2 [Sema] SE-0502: Enable ExcludePrivateFromMemberwiseInit by default
Enable the feature by default, and add an experimental feature
`DeprecateCompatMemberwiseInit` to control the deprecation behavior
which was deferred from the proposal.
2026-02-06 11:50:40 +00:00
Hamish Knight 48464a9cbd [Sema] Correctly handle properties in nested macros
We need to ensure that we recurse into the auxiliary decls in
`enumerateStoredPropertiesAndMissing` to pick up properties in
nested macro expansions. Also do the same in
`enumerateCurrentPropertiesAndAuxiliaryVars` and
`InitializablePropertiesRequest` to ensure the memberwise initializer
correctly handles this case. This would technically be ABI breaking,
but previously we would have just crashed in SILGen.

rdar://166908960
2026-02-04 15:25:31 +00:00
Hamish Knight 1bff51d40d [AST] NFC: Introduce isAtLeastFutureMajorLanguageMode
And use it for clients checking for the next future major language mode.
2026-01-27 23:30:43 +00:00
Hamish Knight 45683f6561 [Sema] Exclude private initialized vars from memberwise initializer
Exclude properties with initial values from the memberwise initializer
if they are less accessible than the most accessible property, up to
`internal`. Introduce a compatibility overload that continues to
include the same properties as before until the next language mode.

This is gated behind the `ExcludePrivateFromMemberwiseInit` feature.

rdar://122416579
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 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Hamish Knight 0f58eb2104 [Sema] Fix and cleanup distributed id/actorSystem synthesis (#85245) 2025-11-04 10:17:05 +09: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
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
Arnold Schwaighofer 3447bd1b31 Change implementation to infer @inlinable semantics from @inline(always) on public declarations 2025-09-30 08:36:32 -07:00
Hamish Knight 3d9e49038b Merge pull request #82295 from hamishknight/wrapping-paper 2025-06-18 08:50:57 +01:00
Hamish Knight 89a7014db9 [Sema] Add null check in createMemberwiseInitParameter
The property wrapper initializer info may be null if e.g we had a
request cycle, just use the property's interface type in that case.

rdar://82899428
2025-06-17 15:16:44 +01:00
Slava Pestov 84997b47ef Sema: Protocols don't have implicit members 2025-06-13 14:54:43 -04:00
Doug Gregor 2dacde1a6d [SE-0470] Include isolated conformance checks for default value expressions
Per SE-0411, we compute the isolation of a default value expression
based on what isolation it requires. Include isolated conformance
checks in this computation, rather than always emitting diagnostics,
so that the combination of isolated default values + isolated
conformances works as expected.

Fixes rdar://150691429.
2025-05-12 09:48:30 -07:00
Doug Gregor 9d493db479 [SE-0470] Fix synthesized conformances with default main actor isolation
When defaulting to main-actor isolation, types that have synthesized
conformances (e.g., for Equatable, Hashable, Codable) were getting
nonisolated members by default. That would cause compiler errors
because the conformances themselves defaulted to main-actor isolation
when their types were.

Be careful to only mark these members as 'nonisolated' when it makes
sense, and leave them to get the isolation of their enclosing type
when the conformance might have isolation. This ensures that one can
use synthesis of these protocols along with default main-actor mode.

There is a one-off trick here to force the synthesized CodingKeys to
be nonisolated, because the CodingKey protocol requires Sendable.
We'll separately consider whether to generalize this rule.

More of rdar://150691429.
2025-05-09 14:35:56 -07:00
Alexis Laferrière e55c9bf2f8 Merge pull request #80900 from xymus/cdecl-reason-language
Sema: Simplify tracking the foreign language for @cdecl
2025-04-18 09:09:13 -07:00
Alexis Laferrière 384b0302c2 Sema: Simplify tracking the foreign language of an @objc decl
Apply review comments from #80744.
2025-04-17 15:33:46 -07:00
Alexis Laferrière a6beaf8deb Merge branch 'main' into cdecl-global-function-checking 2025-04-16 11:19:37 -07:00
Pavel Yaskevich 3906980f58 [AST] NFC: Add a convenient way to create implicit NonisolatedAttrs 2025-04-11 15:59:25 -07:00
Alexis Laferrière ae6bf75378 Sema: Basic type-checking of @cdecl on global functions
This implements basic checks on the validity of the @cdecl attribute and
ensures the parameters and result types are representable in C. Many
more diagnostics will need to be updated to verify full representability
in C.
2025-04-11 11:34:40 -07:00
Anthony Latsis a0930dec31 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSema.def 2025-04-05 12:31:19 +01:00
Anthony Latsis 3fd8f0a008 [NFC] Sema: Factor out derived conformance sources into subdirectory 2025-04-05 05:32:37 +01:00
Slava Pestov ed441e0ea2 Sema: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Hamish Knight 1e8dc55b7f [AST] NFC: Remove InitRetType
This is no longer used.
2025-02-16 18:52:23 +00:00
Becca Royal-Gordon f393962482 Merge pull request #79207 from beccadax/objcquious-indexes
Fix indexing crasher with implicit objcImpl inits
2025-02-10 18:24:28 -08:00
Becca Royal-Gordon 6e9d386d9e Fix indexing crasher with implicit objcImpl inits
Implicit initializers are given a source location within the type they belong to. This works poorly for @objc @implementation classes, because the class they belong to is imported and so those SourceLocs are in a different source buffer from the extension they’re inside, breaking an invariant enforced by index-while-building features.

Fix these SourceLocs to come from the implementation context, so they’ll come from the extension for an objcImpl class and the type itself otherwise.
2025-02-07 13:22:43 -08:00
Allan Shortlidge e019a32122 AST: Introduce and adopt DeclContext::isInSwiftinterface().
Checking whether a declaration is in a `.swiftinterface` is a very common query
that is made somewhat awkward because declarations are not always in source
files. To make these checks more ergonomic, expose a convenience on
DeclContext.
2025-01-27 19:25:41 -08:00
Pavel Yaskevich f10a4819fd [Sema] NFC: Add a variant of addNonIsolatedToSynthesized that checks for @preconcurrency conformances
If derived conformance is marked as `@preconcurrency` instead of
marking synthesized members as `nonisolated` the compiler should
insert dynamic checks.
2025-01-14 15:44:57 -08:00
Allan Shortlidge d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Allan Shortlidge 1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -08:00
Allan Shortlidge 7819dd7833 AST/Sema: Remove unnecessary ASTContext parameters from availability APIs.
Many of the methods on `AvailabilityInference` take both a `Decl` and an
`ASTContext`, which is redundant.
2024-10-14 17:46:53 -07:00
Slava Pestov fd2ab505d7 AST/Sema: Remove a couple of pointless FrontendStatsTracers
To get timings here, just use -fine-grained-timers.
2024-09-23 17:12:46 -04:00
Alejandro Alonso f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Slava Pestov ae77d6f0c1 AST: Replace one-off predicates with SubstitutionMap::getRecursiveProperties() 2024-08-21 13:19:10 -04:00
Slava Pestov 375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Allan Shortlidge 5d6f6947ed Merge pull request #75158 from tshortli/member-import-visibility-package
AST: Add a `IgnoreMissingImports` option to name lookup
2024-07-11 11:07:39 -07:00
Allan Shortlidge d002da0ef2 AST: Add a IgnoreMissingImports option to name lookup.
Control enforcement of member import visibility requirements via a new option,
instead of piggy-backing on the existing IgnoreAccessControl option. Adopt the
option when doing fallback lookups for unviable members so that the compiler
can diagnose the reason that a member is inaccessible more reliably.
Previously, with MemberImportVisibility enabled decls with the package access
level could be mis-diagnosed as inaccessible due to their access level when
really they were inaccessible due to a missing import.

Resolves rdar://131501862.
2024-07-10 22:57:15 -07:00
Meghana Gupta 8137aed238 Rename LifetimeDependentReturnTypeRepr -> LifetimeDependentTypeRepr 2024-07-10 14:20:03 -07:00
Slava Pestov 86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov e8d717bcd6 AST: Remove ModuleDecl parameter from checkRequirements() 2024-07-06 12:05:46 -04:00
Tim Kientzle 1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Slava Pestov 33071e2525 Sema: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00
Allan Shortlidge 64dc2e9f33 SILGen: Avoid crashing for invalid conformances.
Force resolution of value witnesses and check the conformance for validity
before proceeding to witness table emission in SILGen to avoid crashing because
of unexpected errors in the AST.

Resolves rdar://123027739
2024-03-12 21:57:35 -07:00
Ben Barham ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Meghana Gupta c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -08:00
Slava Pestov 1bf5e1be8b Sema: Refactor ResolveImplicitMemberRequest to not call TypeChecker::checkConformance() 2024-01-31 21:56:45 -05:00