Commit Graph

3421 Commits

Author SHA1 Message Date
Slava Pestov
dec124eda5 Merge pull request #80213 from slavapestov/protocol-order-fix
AST: Fix a problem with the protocol order
2025-03-28 07:37:00 -04:00
Pavel Yaskevich
2bb098c0ba Merge pull request #79560 from stzn/fix-subscript-sending-result
Add sending to subscript sending result
2025-03-28 00:26:29 -07:00
Slava Pestov
a7d2b24116 AST: Also respect @_originallyDefinedIn in TypeDecl::compare()
If a protocol was moved from one module to another, we need to
continue using the old module name when comparing it against
other protocols.
2025-03-27 16:38:57 -04:00
Slava Pestov
38c478f5ee AST: Look through module aliases in TypeDecl::compare()
The last step in building a generic signature is to sort the requirements.
Requirements are sorted by comparing their subject types. If two
requirements have the same subject type, which can only happen with
conformance requirements, we break the tie by comparing protocol
declarations.

We compare protocol declarations using TypeDecl::compare(), which is a
shortlex order on the components of the fully qualified name of a
protocol (eg, Swift.Sequence, etc.)

While this order is part of the ABI, it has not been updated over the
years for several important changes:

- It did not handle module aliases; if we import a module via an
  alias, we should use the real module name to compare protocols, and
  not the aliased name. This produced inconsistent results if the
  same module was imported under different names, which can happen
  with module interface files that use module aliases.

- It did not handle the -module-abi-name flag. Changing the ABI name
  of a module changes how we mangle protocol names, and the order
  should match the mangling.

This change fixes the first case only. The second requires more
careful staging, because of _Concurrency and CompilerSwiftSyntax.

Fixes rdar://147441890.
2025-03-27 16:38:47 -04:00
Becca Royal-Gordon
9be9b6fad6 Inherit access control in @abi
ABI-only declarations now inherit access control modifiers like `public` or `private(set)`, as well as `@usableFromInline` and `@_spi`, from their API counterpart. This means these attributes and modifiers don’t need to be specified in an `@abi` attribute.

Very few tests because we aren’t yet enforcing the absence of these attributes.
2025-03-26 10:47:13 -07:00
Becca Royal-Gordon
1bb2186377 Inherit @objc, dynamic, @implementation in @abi
ABI-only declarations now query their API counterpart for things like `isObjC()`, their ObjC name, dynamic status, etc. This means that `@objc` and friends can simply be omitted from an `@abi` attribute.

No tests in this commit since attribute checking hasn’t landed yet.
2025-03-26 10:47:13 -07:00
Becca Royal-Gordon
775bdacefc [NFC] Extract Decl::getExplicitObjCName()
Create a helper method which looks for an `@objc` attribute with an explicit name and returns it, and adopt it in various existing places.
2025-03-26 10:47:12 -07:00
Becca Royal-Gordon
1af5c04765 [NFC] Hoist getTypeSourceRangeForDiagnostics()
Allows code to get this for any AbstractStorageDecl.
2025-03-26 10:47:12 -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
Kuba (Brecka) Mracek
1c395e24f6 Merge pull request #79923 from kubamracek/mracek/constinitialized
[Compile Time Values] Add parsing of @constInitialized attribute under CompileTimeValues experimental feature
2025-03-25 13:41:17 -07:00
Anthony Latsis
6512aa1f5a AST: Introduce and use ValueDecl::isAsync 2025-03-25 02:07:03 +00:00
Slava Pestov
0155b41b50 AST: Extend @_originallyDefinedIn to allow specifying module name for linker directive purposes
The module name changes the symbol mangling, and also causes
TBDGen to emit linker directives. To separate out these two
behaviors, introduce a terrible hack. If the module name
contains a semicolon (`;`), the part before the semicolon
is the module name for mangling, and the part after the
semicolon is the module name for linker directives.

If there is no semicolon, both module names are identical,
and the behavior is the same as before.
2025-03-24 17:56:45 -04:00
Kuba Mracek
f402eb623c [Compile Time Values] Add parsing of @constInitialized attribute under CompileTimeValues experimental feature 2025-03-24 09:31:57 -07:00
Egor Zhdan
77ad256926 Merge pull request #80130 from swiftlang/egorzhdan/submodules-name-for-lookup
[cxx-interop] Determine owning module correctly for C++ decls in nested modules
2025-03-21 10:13:21 +00:00
Egor Zhdan
106a6af850 [cxx-interop] Determine owning module correctly for C++ decls in nested modules
This fixes a compiler bug that got exposed by f11abac652.

If a C++ type is declared in a nested Clang submodule, Swift was emitting errors that look like:
```
Type alias 'string' is not available due to missing import of defining module 'fwd’
```

rdar://146899125
2025-03-20 19:14:46 +00:00
Rintaro Ishizaki
92a6fece48 [ASTGen] ObjC improvements
* Generate `#selector(...)` expression
* Generate `#keyPath(...)` expression
* Implicit `@objc` attribute for `@_objcImplementation` attribute
2025-03-20 05:04:58 -07:00
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Amritpan Kaur
60e03a85d9 [SILGen] Lower applied keypath methods. 2025-03-19 10:54:09 -07:00
Allan Shortlidge
151c9dee39 AST: Consolidate abstract/contrete syntax decl lookup functions. 2025-03-15 23:47:29 -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
Rintaro Ishizaki
accd108e4a Merge pull request #79857 from rintaro/retire-pound-diagnostics-decl
[Parse/AST] Remove PoundDiagnosticDecl
2025-03-09 21:23:16 -07:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
nate-chandler
38c8cc8ff4 Merge pull request #77661 from nate-chandler/general-coro/20241115/1
[CoroutineAccessors] Default implementations are transparent.
2025-03-07 11:39:21 -08:00
Allan Shortlidge
b64df7384e AST: Simplify AvailabilityRange construction.
Introduce a constructor that takes an `llvm::VersionTuple` directly, instead of
needing to spell out `VersionRange::allGTE(<tuple>)` which is unnecessarily
verbose.
2025-03-04 19:41:04 -08:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Allan Shortlidge
c89df2fc38 AST/Sema: Adopt AvailabilityDomain arguments in more diagnostics.
Update explicit unavailability and deprecation diagnostics to take
`AvailabiiltyDomain` instead of a platform string.
2025-02-28 13:57:00 -08:00
Doug Gregor
52c46f838a Parsing and type checking for the definition of isolated conformances
Allow a conformance to be "isolated", meaning that it stays in the same
isolation domain as the conforming type. Only allow this for
global-actor-isolated types.

When a conformance is isolated, a nonisolated requirement can be
witnessed by a declaration with the same global actor isolation as the
enclosing type.
2025-02-25 21:16:51 -08:00
Pavel Yaskevich
b84bf055f0 [TypeChecker] Implement ExtensibleEnums feature exhaustivily handling
If an enum comes from a different module that has `ExtensibleEnums`
feature enabled, unless it requires either `@unknown default:` or
`@frozen` because it is allowed to introduce new cases in the future
versions of the module.
2025-02-25 00:05:23 -08:00
Kuba (Brecka) Mracek
874c62513c Merge pull request #79403 from kubamracek/embedded-unique-macro-names
[Macros] Recognize the $e Embedded Swift prefix in MacroDecl::isUniqueMacroName
2025-02-24 10:16:40 -08:00
stzn
43e60304ad Add sending to subscript getter sending result 2025-02-23 10:52:01 +09:00
Rintaro Ishizaki
efea164d04 [ASTGen] Generate from 'MissingTypeSyntax'
Just emit ErrorTypeRepr
2025-02-21 11:36:29 -08:00
Rintaro Ishizaki
6805e155d5 Merge pull request #79503 from rintaro/astgen-paramdecl-typerepr
[AST] Sink ParamDecl flag collection logic from Parse to AST
2025-02-21 02:18:52 -08:00
fahadnayyar
9782eae585 Merge pull request #77522 from fahadnayyar/cxx-frt-inheritance-diagnostics
[cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
2025-02-20 13:46:28 -08:00
Rintaro Ishizaki
8833ff58a2 [AST] Sink the flag collection logic from Parse to AST
* Collect flag in `ParamDecl::setTypeRepr()`.

* [ASTGen] Separate `BridgedParamDecl.setTypeRepr(_:)` from
`BridgedParamDecl.createParsed(_:)` aligning with C++ API. The majority
of the creations don't set the typerepr.

* Update `ParamSpecifierRequest::evaluate` to handle non-implicit
`ParamDecl` without `TypeRepr` (i.e. untyped closure parameter), instead
of `setSpecifier(::Default)` manually in Parse.
2025-02-20 10:04:49 -08:00
fahadnayyar
d8f919778d [cxx-interop] [cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
rdar://97914474
2025-02-20 08:46:57 -08:00
Rintaro Ishizaki
e5d5026992 Merge pull request #79456 from rintaro/astgen-paramdecl
[ASTGen] ParamDecl generation improvements
2025-02-19 14:05:55 -08:00
Allan Shortlidge
342dc1d36f AST: Fix an unused variable warning in Decl.cpp. 2025-02-18 21:31:48 -08:00
Rintaro Ishizaki
6980509f8c [ASTGen] Generate DefaultArgumentInitializer
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Gabor Horvath
410341671e [SE-0458] Unify escapibility inference for AST and Interop
Interop is injecting escapability annotations for the STL and doing a
limited inference for aggregates. Let's reuse the same facilities in the
AST when we calculate the safety of the foreign types.
2025-02-17 13:41:40 +00:00
Doug Gregor
c2e36decfe Merge pull request #79424 from DougGregor/se-0458-match-proposal
[SE-0458] Bring implementation in line with the latest proposal revision
2025-02-16 19:15:27 -08:00
Allan Shortlidge
902053341e Merge pull request #79423 from tshortli/case-iterable-invalid-available
AST: Type-check `@available` attributes before synthesizing `CaseIterable`
2025-02-16 17:58:10 -08:00
Allan Shortlidge
b6ee0796c8 AST: Type-check @available attributes before synthesizing CaseIterable.
An `AvailableAttr` written in source with an unrecognized availability domain
is now only marked invalid after type-checking the attribute. This resulted in a
regression where `CaseIterable` synthesis was blocked incorrectly under the
following very narrow circumstances:

1. Every `@available` attribute on the elements of the enum is invalid.
2. The module is being emitted and lazy type-checking is enabled.
3. The enum is public and the only top-level declaration in the file.

Type-checking the attribute was delayed just enough that it would not be
considered invalid by the type the `CaseIterable` conformance was being
synthesized, resulting in a spurious error.

There were zero tests exercising `CaseIterable` synthesis for enums with
elements that have availability requirements, so I added some.

Resolves rdar://144897917.
2025-02-16 12:20:48 -08:00
Hamish Knight
1e8dc55b7f [AST] NFC: Remove InitRetType
This is no longer used.
2025-02-16 18:52:23 +00:00
Doug Gregor
c0fb9f990a [Strict memory safety] Infer safe/unsafe for imported C types 2025-02-16 00:55:43 -08:00
Kuba Mracek
e037aaaf85 [Macros] Recognize the $e Embedded Swift prefix in MacroDecl::isUniqueMacroName 2025-02-14 14:23:26 -08:00
Anthony Latsis
e8b393430f Merge pull request #78459 from AnthonyLatsis/tuber-magnatum-2
TypeCheckType: Unconditionally warn about missing existential `any` until Swift 7
2025-02-14 19:08:33 +00:00
Rintaro Ishizaki
e066bb266b Merge pull request #79355 from rintaro/astgen-toplevelvardecl
[ASTGen] Generate PatternBindingDecl at top level
2025-02-13 09:43:10 -08:00
Rintaro Ishizaki
6ea6a31ec7 [ASTGen] Generate TopLevelCodeDecl for PatternBindingDecl
* Instead of hoisting VarDecl in the bridging functions, do it in
  ASTGen.
* Introduce `Decl::forEachDeclToHoist` to handle VarDecls in
  PatternBindingDecl, and EnumElementDecl in EnumCaseDecl.
* Intorduce `withBridgedSwiftClosure(closure:call:)` as a callback
  mechanism between Swift and C++
* In `generate(sourceFile:)`, instead of using `generate(codeBlockItem:)`
  handle `CodeBlockItemSyntax.Item` manually to handle `TLCD` wrapping
  and `VarDecl` hoisting.
* Make `generate(variableDecl:)` handle TLCD correctly.
2025-02-13 00:09:22 -08:00
Rintaro Ishizaki
563ddc47e2 [AST] Eliminate 'SYNTAX_KIND' from MagicIdentifierKinds.def
Nothing is using it.
2025-02-12 23:19:34 -08:00