Commit Graph

3245 Commits

Author SHA1 Message Date
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
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
Sam Pyankov
aa30b1a106 Merge branch 'main' into revert_public-decl-internal-protocol 2026-01-23 15:17:25 -08:00
Sam Pyankov
70835508b0 Revert "Diagnose public protocol witnessed by an internal protocol extension"
This reverts commit 6280a7001f.
rdar://168627163
2026-01-23 10:28:19 -08:00
Alexis Laferrière
c8f99af698 Merge pull request #86335 from xymus/exportability-nle-warn
Sema: Enable exportability checks in non-library-evolution mode as warnings by default
2026-01-22 09:47:52 -08:00
Sam Pyankov
a0dc22e819 Merge pull request #86392 from sepy97/strict_access_check_errors
Stricter access control enforcement
2026-01-13 15:45:16 -08:00
Slava Pestov
23b951b817 Merge pull request #86429 from slavapestov/fix-rdar167851622
Sema: Don't just ignore protocol type aliases in LookupResultBuilder::add()
2026-01-10 10:39:29 -05:00
Slava Pestov
688ba5d9ff Sema: Don't just ignore protocol type aliases in LookupResultBuilder::add()
Fix regression from 62e4979691.

An associated type can be witnessed by a type alias that is
directly declared in a protocol. Don't drop it in this case.

It seems that this didn't matter too much in the past, but
now that name lookup prefers an associated type declaration
over a type alias (which may or may not be the type witness),
we really must correctly resolve the associated type to a
type witness instead of just dropping it sometimes.

Fixes rdar://167851622.
2026-01-09 15:31:34 -05:00
Tim Kientzle
adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00
Sam Pyankov
b0eee67a7b Emit an errors instead of warnings access control violations that should be fixed in the future when StrictAccessControl upcoming feature is enabled 2026-01-08 14:24:35 -08:00
Hamish Knight
7c36833439 Merge pull request #86311 from hamishknight/ext-fix
Avoid loading serialized extensions for nominals in SourceFile
2026-01-08 21:38:06 +00:00
Alexis Laferrière
5cc4c788aa Sema: Update warning on @_implementationOnly import
Invite users of `@_implementationsOnly` imports from modules without
library-evolution to adopt `CheckImplementationOnly`. Use the existing warning
on the import statement. Adopting that feature reports unsafe references to
implementation-only imported types as errors and silences the warning on
the import.
2026-01-06 15:12:47 -08:00
Slava Pestov
62e4979691 AST: Prefer associated types over protocol type aliases 2026-01-06 11:50:32 -05:00
Hamish Knight
4e950e3591 Avoid loading serialized extensions for nominals in SourceFile
Looking up serialized extensions for a nested nominal type requires
computing its mangled name, which may kick semantic requests. Ensure
we don't do this for nominals in parsed SourceFiles such that we
don't end up kicking this during extension binding.
2026-01-06 15:34:33 +00:00
Hamish Knight
5d7ece7b7f [test] Move extension_binding_multi.swift 2026-01-06 15:34:00 +00:00
Tim Kientzle
104dba920b [SE-0474] Implement yielding borrow and yielding mutate syntax
This does not rename all the internal variables, functions, and types
whose names were based on the old syntax.

I think it adds new syntax support everywhere it's needed while
retaining enough of the old syntax support that early adopters will
see nice deprecation messages guiding them to the new syntax.
2026-01-03 15:07:10 -08:00
Hamish Knight
b1b7397aa3 [Sema] Use getFormalAccessScope in MemberwiseInitMaxAccessLevel
This ensures we handle nested types correctly for
`ExcludePrivateFromMemberwiseInit`.
2025-12-24 12:49:27 +00:00
Xi Ge
4a6badd6ee Merge pull request #85846 from sepy97/public-decl-internal-protocol
Diagnose public protocol requirements witnessed by internal protocol extensions
2025-12-17 09:39:32 -08:00
Sam Pyankov
6280a7001f Diagnose public protocol witnessed by an internal protocol extension
Private member witnessing a public constraint should be deprecated.
Previously existing workaround is checked and compiler emits a warning
when strict access check is not passed. Test files were fixed to expect
the corresponding warning.

rdar://74904373
2025-12-15 16:23:06 -08: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
Jamie
2c4e26b94f [test]: update existing tests for new fixit 2025-12-06 04:05:44 -06:00
Hamish Knight
bf760aa3dd Merge pull request #85615 from jamieQ/async-let-it-be
[Sema]: suppress unexpected type warning on some async-let patterns
2025-12-01 14:39:08 +00:00
Jamie
9c48c9e0ba [Sema]: don't warn about optional Void async-lets either 2025-11-21 05:27:04 -06:00
Jamie
2e901a1f10 [Sema]: suppress unexpected type warning on some async-let patterns
It is somewhat common to use an async-let binding to run a synchronous,
void-returning function in an async context. In such cases, the
binding's type being inferred as Void is expected, and requiring
programmers to explicitly write this to suppress a warning seems like
unnecessary boilerplate. This patch changes the diagnostic logic to
exempt async-let bindings from the existing diagnostic when the inferred
type is Void.
2025-11-20 06:21:03 -06:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Hamish Knight
dad263728f Merge pull request #85193 from hamishknight/wrapping-paper
[CS] A couple of property wrapper fixes
2025-11-05 19:51:51 +00:00
Hamish Knight
0f58eb2104 [Sema] Fix and cleanup distributed id/actorSystem synthesis (#85245) 2025-11-04 10:17:05 +09:00
Hamish Knight
3b57a7cd91 [CS] Clean up some property wrapper logic
These methods can be simplified a bunch since the returned decl is
always the input decl and we can refactor the lambdas to just return
the auxiliary variable and have the type computation in the caller.
2025-11-04 00:56:01 +00:00
Hamish Knight
e0de61caa4 Merge pull request #85135 from hamishknight/lazy-fix
[AST] Avoid exposing `lazy` local storage var to name lookup
2025-11-04 00:53:31 +00:00
Alexis Laferrière
048c9276a9 Merge pull request #85122 from xymus/official-c-attr
SE-495: Make `@c` an official feature
2025-10-30 16:06:25 -07:00
Jamie
0d99dbd2b0 [Sema]: ban the use of 'nonisolated' on actor declarations (#85185)
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
2025-10-31 06:02:33 +09:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Alexis Laferrière
bce585c133 SE-495: Make CImplementation an official feature 2025-10-29 11:55:51 -07:00
Hamish Knight
00d8774032 [Sema] Upgrade tuple shuffle warning to error in future lang mode
This has been deprecated for a while now, flip it to an error for a
future language mode.
2025-10-29 15:14:23 +00:00
Hamish Knight
24347812f5 [Diag] Reword the tuple shuffle diagnostic
"reorder" seems a bit less jargony than "shuffle", and include the 
labels that are being reordered.
2025-10-29 15:14:23 +00:00
Hamish Knight
55ebd0774e [AST] Avoid exposing lazy local storage var to name lookup
We already reject attempts to reference this for `lazy` properties.
For `lazy` locals let's just not expose it to name lookup to begin
with. This ensures we don't attempt to prematurely kick the interface
type computation for the var, fixing a couple of crashers.
2025-10-25 15:07:11 +01:00
Hamish Knight
41b47f48cb [Sema] Fix crash in CheckRedeclarationRequest for IUO mismatch check
Make sure we only check this if both declarations have parameter lists.
While here, clean up the logic a bit such that we just iterate over
the parameter lists.

rdar://156874925
2025-10-24 14:32:05 +01:00
Hamish Knight
57557dec8e [Evaluator] Enforce consistent results for cyclic requests
Record when we encounter a request cycle, and enforce that the outer
step of the cycle also returns the default value. This fixes a couple
of crashers where we were ending up with conflicting values depending
on whether the request was queried from within the cycle or from
outside it.
2025-10-08 21:16:02 +01:00
Hamish Knight
e7c7239587 [Sema] Insert ErrorType same-type constraints for placeholder signatures
This helps avoid producing more downstream errors. This changes
`GenericSignature::forInvalid` to produce the same signature as e.g
`<T where T == Undefined>`. This subsumes the need to introduce
conformance requirements for invertible protocols.
2025-10-08 21:16:02 +01:00
Hamish Knight
11d299c212 Merge pull request #84698 from hamishknight/carousel
[Evaluator] Avoid emitting duplicate "through reference here" notes
2025-10-07 20:14:52 +01:00
Henrik G. Olsson
d3214de950 Merge pull request #84685 from hnrklssn/verify-all
This adds the -verify-ignore-unrelated flag. When -verify is used without -verify-ignore-unrelated, diagnostics emitted in buffers other than the main file and those passed with -verify-additional-file (except diagnostics emitted at <unknown>:0) will now result in an error. They were previously ignored. The old behaviour is still available as opt-in using -verify-ignore-unrelated, but by being strict by default it should make it harder to accidentally miss diagnostics.

To avoid unnecessary performance overhead, -verify-additional-file is still required to parse the expected-* directives in files other than the main file.
2025-10-06 18:01:47 -07:00
Hamish Knight
f643f3d990 [Evaluator] Add "through" to "declared here" request cycle notes
Make it a bit clearer that these are steps in the request cycle.
2025-10-05 20:48:08 +01:00
Hamish Knight
13023de4c4 [Evaluator] Avoid emitting duplicate "through reference here" notes
Filter out any duplicate notes to help cut down on the noise for
request cycle diagnostics. Some of the note locations here still aren't
great, but this at least stops us from repeating them for each
intermediate request.
2025-10-05 20:48:08 +01:00
Hamish Knight
d06d12632b Merge pull request #84666 from hamishknight/can-opener
[CS] Consolidate placeholder handling logic into `Solution::simplifyType`
2025-10-04 22:55:38 +01:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Hamish Knight
669a2ce9b0 [CS] Sink placeholder handling logic into Solution::simplifyType
Move the logic from `FailureDiagnostic::resolveType` into
`Solution::simplifyType` to allow completion to use it too. While
here, also handle cases where the placeholder is from a different
member of the equivalence class to the generic parameter.
2025-10-04 12:56:52 +01:00
Doug Gregor
67c7fbc87b [SE-0495] Make sure we can find imported C functions for @c @implementation
@c @implementation relies on matching the original C declaration. The
lookup for the original C declaration was doing the wrong kind of
lookup, meaning that it could only find the C declaration if it came
through a bridging header, and not through a normal module import.
Using unqualified lookup here finds the name appropriately.

Clarify the diagnostics here as well to not talk about umbrella and
bridging headers.

Fixes rdar://161909754.
2025-10-03 12:03:12 -07:00
Hamish Knight
44efcb3a10 Merge pull request #84460 from hamishknight/open-and-shut
[CS] Fix typealias handling in InferableTypeOpener
2025-09-24 16:25:01 +01:00
Hamish Knight
20202f53a9 [CS] Quick workaround for rdar://160135085
Temporarily disable the checking requirements for typealias types,
and desugar the typealias since the constraint system does not
currently correctly handle type variables in the underlying type.
2025-09-23 14:36:06 +01:00
Alexis Laferrière
9ec824c20b Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The
legacy `@_cdecl` remains unaffected.
2025-09-19 11:55:07 -07:00