Commit Graph

4265 Commits

Author SHA1 Message Date
Alexis Laferrière
175d0ba8e6 Serialization: Minor improvements to the error on conformance mismatch
Clarify the sources of information when a conformance reference in a
swiftmodule doesn't match with the requirements seen by the reader.
2025-12-10 15:08:03 -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
Pavel Yaskevich
df3aa1e011 Merge pull request #85879 from xedin/add-supression-note-to-explicit-sendable-warning
[Diagnostics] TildeSendable: Suggest `Sendable` suppression in explic…
2025-12-08 13:29:25 -08:00
Pavel Yaskevich
f0fd506745 [Diagnostics] TildeSendable: Suggest Sendable suppression in explicit Senable warning
Add a note to missing explicit `Sendable` conformance warning
(produced by `-Wwarning ExplicitSendable`) and a fix-it with
a suggestion to suppress `Senable` conformance  via `~Sendable`.
2025-12-05 17:20:55 -08:00
Alexis Laferrière
8e04430498 Sema: Differentiate the reason for implictly public memory layouts 2025-12-05 09:25:37 -08:00
Alexis Laferrière
e6976e6291 Sema: Centralize exportability reason spelling 2025-12-04 17:01:44 -08:00
Doug Gregor
1706fce370 Merge pull request #85806 from DougGregor/custom-availability-domain-serialization
[Custom availability] Serialize custom domains described on the command line
2025-12-03 02:07:02 -08:00
Doug Gregor
e624915ed9 [Custom availability] Serialize custom domains described on the command line
When a custom domain is described on the command line, there is no
backing declaration for it. Serialize such custom domains by
identifier and look them up globally at the point of deserialization.
When that fails, warn and drop the annotation.

This is all a stopgap until we have a way to spell custom availability
domains in the Swift language itself.
2025-12-02 12:12:50 -08:00
Hamish Knight
ae82b29e35 Rework emission of EditorPlaceholderExprs
Rather than synthesizing a semantic expression to emit, add a compiler
intrinsic to the stdlib that is simple enough to just SILGen the
emission.
2025-11-30 11:12:39 +00:00
Kuba Mracek
8da5f3141e SE-0492: Add support for closures (with no captures) into @section expressions 2025-11-16 09:21:12 -08:00
Henrik G. Olsson
54cfd7a1c3 Merge pull request #85354 from hnrklssn/verify-expansion-content
[macros] add -Rmacro-expansions
2025-11-13 11:56:41 -08:00
Alexis Laferrière
5a49e34426 Serialization: Error on xref to implementation-only dependencies
Introduce a last resort check reporting references to
implementation-only dependencies that would appear in the generated
swiftmodule. This check is applied at serialization, long after
exportability checking applied at typechecking. It should act as a back
stop to references missed by typechecking or @_implementationOnly decls
that should have been skipped.

This check is gated behind CheckImplementationOnlyStrict and should be
used with embedded only.

rdar://160697599
2025-11-11 13:03:16 -08:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Alexis Laferrière
1e1361f4ee Merge pull request #85369 from xymus/exportability-nle-classes-and-structs
Sema: Exportability check enums and classes in non-library-evolution mode
2025-11-07 09:19:25 -08:00
Doug Gregor
66e7a783a6 Merge pull request #85370 from DougGregor/extern-global-variables 2025-11-06 21:40:24 -08:00
Alexis Laferrière
5bffd70452 Sema: Accept @_implementationOnly on enums and classes 2025-11-06 11:30:43 -08:00
Doug Gregor
5b642f548f Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such
variables need to have types represented in C (of course), have only
storage (no accessors), and cannot have initializers. At the SIL
level, we use the SIL asmname attribute to get the appropriate C name.

While here, slightly shore up the `@_extern(c)` checking, which should
fix issue #70776 / rdar://153515764.
2025-11-06 11:09:31 -08:00
Alexis Laferrière
b52781e1e1 Sema: Generalize the diagnostic about types with @_implementationOnly 2025-11-06 10:19:39 -08:00
Pavel Yaskevich
e39a31a05f Merge pull request #85319 from xedin/rdar-162394810
[AST/Sema] Add a diagnostic group `ExplicitSendable` to replace `-require-explicit-sendable`
2025-11-06 06:48:50 -08:00
Henrik G. Olsson
040c9e6729 [macros] add -Rmacro-expansions
This adds the -Rmacro-expansions flag. It provides similar functionality
to -dump-macro-expansions, but instead of dumping the macro expansion to
stderr, it emits it line by line as remarks. This is useful for testing
with -verify, where both macro expansion content and warnings need to be
tested at the same time.
2025-11-05 18:45:34 -08:00
Alexis Laferrière
579a228d3f Merge pull request #85179 from xymus/exportability-nle-structs
Sema: Opt-in check for structs references to hidden dependencies in non-library-evolution mode
2025-11-05 15:32:05 -08:00
Pavel Yaskevich
22ec081377 [AST/Sema] Add a diagnostic group ExplicitSendable to replace -require-explicit-sendable
Always run explicit `Sendable` checks on public types and suppress
warning printing by default instead of using a special compiler argument.

Resolves: rdar://162394810
2025-11-04 17:53:20 -08:00
Doug Gregor
b1c2bc1731 Merge pull request #85305 from DougGregor/custom-conformance-availability
[Custom availability] Fix conformance availability diagnostic
2025-11-04 15:25:43 -08:00
Alexis Laferrière
488321256e Sema: Consider non-LE structs to be of a restricted type by default
In non-library-evolution mode, gated behind the CheckImplementationOnly
feature flag, report references to structs marked with
`@_implementationOnly` from a fragile context. Preventing references
from inlinable functions and structs not marked `@_implementationOnly`.
2025-11-04 13:50:37 -08:00
Alexis Laferrière
71035a51de Sema: Accept @_implementationOnly on non-public structs
Gate it behind CheckImplementationOnly.
2025-11-04 13:50:36 -08:00
Artem Chikin
d1529b5303 Merge pull request #85282 from jamieQ/dead-diags
[NFC][Diagnostics]: remove a number of unused diagnostics
2025-11-04 12:06:26 -05:00
Doug Gregor
b0a565e458 [Custom availability] Fix conformance availability diagnostic
Emit a proper diagnostic for a conformance that is not available due to
custom availability that doesn't have version information, eliminating
an assertion.
2025-11-03 22:35:57 -08:00
Hamish Knight
0f58eb2104 [Sema] Fix and cleanup distributed id/actorSystem synthesis (#85245) 2025-11-04 10:17:05 +09:00
Jamie
c2a42e28f7 [NFC][Diagnostics]: remove a number of unused diagnostics 2025-11-03 07:39:12 -06:00
Henrik G. Olsson
87af5538d3 Merge pull request #84871 from hnrklssn/inherit-literal-std
[ImportResolution] Only disallow explicit `std` imports (allow implicit)
2025-10-31 14:22:16 -07: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
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Hamish Knight
6a7bf6fef5 Merge pull request #85188 from hamishknight/tuple-trouble
[CS] Upgrade a couple of tuple warnings to error for future lang mode
2025-10-29 23:34:22 +00:00
Artem Chikin
1b38c919c7 Merge pull request #85098 from artemcm/DefaultIgnoreDiagnosticGroups
[Diagnostics] Replace diagnostics' `DefaultIgnore` option with a corresponding option on diagnostic groups
2025-10-29 18:10:32 -04:00
Alexis Laferrière
000c2604b0 SE-495: Make @c an official feature 2025-10-29 11:55:41 -07:00
Artem Chikin
9e35f82b2c [Diagnostics] Replace diagnostics' 'DefaultIgnore' option with a corresponding option on diagnostic groups
This brings this control in line with other diagnostic controls we have which operate on a per-group level.
'DefaultIgnoreWarnings' diagnostic group option applies to all warnings belonging to a certain diagnostic group.

The inheritance rules are:
- Marking a diagnostic group as 'DefaultIgnoreWarnings' means warnings belonging to this group will not be emitted by-default
  - Warnings belonging to sub-groups of this group will also not be emitted by-default
- Enabling a 'DefaultIgnoreWarnings' group (with '-Werror','-Wwarning', etc.) means warnings belonging to this group will be emitted.
  - Warnings belonging to sub-groups of this group will also be emitted.
  - Warnings belonging to super-groups of this group will not be affected.
2025-10-29 09:42:03 -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
1781faba1a [CS] Upgrade tuple label mismatch warning to error for future lang mode
I missed upgrading this to an error for Swift 6 mode, let's upgrade it
to an error for a future language mode. It's important we reject these
cases since we're otherwise allowing subtyping to be a weaker constraint
than conversion.
2025-10-29 15:14:23 +00: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
Kavon Farvardin
2d881bdc9c ManualOwnership: provide ability to apply to entire compilation unit
With this patch, I'm flipping the polarity of things.

The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics,
but they're all silenced by default. So, you need to add -Wwarning or -Werror to
your build settings to turn on the specific diagnostics you care about.

These are the diagnostic groups relevant to the feature:

- SemanticCopies aka "explicit copies mode"
- DynamicExclusivity

For example, the build setting `-Werror SemanticCopies` now gives you errors about
explicit copies, just as before, but now you can make them just warnings with -Wwarning.

To opt-out a declaration from everything when using the feature, use @_noManualOwnership.

@_manualOwnership is no longer an attribute as a result.

resolves rdar://163372569
2025-10-24 18:54:07 -07:00
Becca Royal-Gordon
e3495f5fe7 Forbid module selectors on dependent member types
In code like the following:

```
protocol P { associatedtype A: Hashable }
protocol Q { associatedtype A: Comparable }

func fn<T: P & Q>(_: T) where T.A == Int { … }
```

`T.A` is actually the union of `P.A` and `Q.A`—it satisfies both associated types and has both of their constraints. This means it doesn’t actually make sense to apply a module selector to `A`—even if `P` and `Q` are in different modules, `T.A` always represents both of the declarations, not one or the other. We therefore now ban module selectors in this position, since they don’t actually jibe with the nature of a generic signature.

This justification technically doesn’t hold for *every* member type of a generic parameter—a member type can refer to a concrete typealias in a protocol extension, for instance—but in those situations, you can disambiguate (and add module selectors) by writing `P.A` or `Q.A` instead of `T.A`, so we’re not really worried about this limitation.
2025-10-24 16:23:50 -07:00
Becca Royal-Gordon
d1e391094d Improve module selector expr lookup diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
7949224b69 Improve module selector type lookup diagnostics 2025-10-24 16:23:48 -07:00
Becca Royal-Gordon
b35aaef526 Handle module selectors in macro lookups 2025-10-24 16:23:34 -07:00
Meghana Gupta
7e8d8b671f Merge pull request #85097 from meg-gupta/withdiagpr
Update borrow accessor diagnostics and synthesis
2025-10-24 15:06:19 -07:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
John Hui
781489f067 Merge pull request #85021 from j-hui/return-frt-diagnostics
[cxx-interop] Put RETURNS_RETAINED warnings in a diagnostic group

rdar://161932849
rdar://144976203
2025-10-24 12:05:48 -04:00
Kuba Mracek
ca737d3d97 Tweak diagnostic text on @section/@const errors 2025-10-23 17:05:41 -07:00
Meghana Gupta
f44d7e53be Add diagnostics for ownership modifiers on borrow/mutate accessors 2025-10-23 11:49:10 -07:00