Commit Graph

21504 Commits

Author SHA1 Message Date
Hamish Knight
6d89ed3d73 [ASTScope] Use PrettyStackTraceString to print verification errors
Use the same approach as `ModuleFileSharedCore::fatal`, ensuring the
verification error ends up in the crash log.
2025-03-28 17:00:35 +00:00
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
Alastair Houghton
47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00: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
Karoy Lorentey
5583e6916c Merge pull request #73258 from lorentey/you-cannot-escape-optionals
[stdlib] Generalize some constructs for non-escapable types
2025-03-27 20:02:00 -07:00
Anthony Latsis
72c0d4cc75 Diag: Handle CustomAttr in formatDiagnosticArgument 2025-03-28 02:03:38 +00:00
Becca Royal-Gordon
29a2d32d0e Avoid objcImpl @_hasStorage in module interfaces
If an `@objc implementation extension` had a public stored property with an observer, Swift would print `@_hasStorage` on the extension. This is Not Good because in a module interface, an objcImpl extension appears to be an ordinary extension, and properties in ordinary extensions are not supposed to have storage.

Suppress printing this attribute in objcImpl extensions to avoid this problem.

Partially fixes rdar://144811653 by suppressing emission of bad attributes.
2025-03-27 16:51:16 -07:00
Doug Gregor
8a8e108cae Stop propagating @unsafe/@safe from type definitions down to their members 2025-03-27 16:48:09 -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
Slava Pestov
d61c21ba2b Merge pull request #80304 from slavapestov/not-so-abstract-anymore
AST: Check subject type in ProtocolConformanceRef::forAbstract()
2025-03-27 08:21:16 -04:00
Slava Pestov
09a4e16ac0 Merge pull request #80301 from slavapestov/subst-generic-function-type
Clean up GenericFunctionType substitution
2025-03-27 08:20:59 -04:00
Hamish Knight
1980f7235f [ASTScope] Re-enable checkSourceRangeBeforeAddingChild
Update the logic to correctly handle replacement ranges, and re-enable
the assertion. For now, carve out an exception for attributes on
extensions, I'll try and tackle those in a follow-up.
2025-03-27 11:31:24 +00:00
Hamish Knight
60da121c1f [ASTScope] Avoid adding accessors in macro expansions
`visitParsedAccessors` currently iterates over any non-implicit
accessor that happens to be present. This means we end up with
accessors added by macro expansions if the expansion happens before
the ASTScope expansion. Make sure we avoid adding such accessors to
the ASTScope tree, they should instead use their own tree. Ideally
we'd better formalize `visitParsedAccessors` such that it only ever
visits non-expansion accessors, but I'm leaving that for another day.
2025-03-27 11:31:24 +00:00
Hamish Knight
6b502f0d68 [AST] Handle accessors specially in isInMacroExpansionInContext
Rather than looking at their DeclContext, look at the location of
their storage. This allows us to differentiate accessors added by
macro expansions vs accessors that are attached to storage that's
in a macro expansion.
2025-03-27 11:31:24 +00:00
Hamish Knight
62839d1199 [ASTScope] Avoid treating @abi bindings as local
Such bindings may have a local decl context, but their scope shouldn't
extend past the `@abi` attribute.
2025-03-27 11:31:24 +00:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Slava Pestov
1859533b43 AST: Remove substGenericFunctionType() 2025-03-26 20:06:07 -04:00
Slava Pestov
0c29f7f410 ASTMangler: Replace unnecessary subst() with tranformRec() 2025-03-26 20:06:06 -04:00
Slava Pestov
9c19c8d5d5 AST: Fix GenericFunctionType::substGenericArgs() to support parameter packs
Instead of doing the bespoke thing, just erase this down to a
FunctionType and call subst() on it.
2025-03-26 20:06:06 -04:00
Becca Royal-Gordon
a5a84f188e Merge pull request #79466 from beccadax/abi-inspected-your-appearance
@abi checking
2025-03-26 15:28:39 -07:00
Slava Pestov
09ed91fab5 AST: Fix some comments 2025-03-26 17:45:38 -04:00
Becca Royal-Gordon
7703d115db Filter bad attrs out of module interface @abis
When printing an `@abi` attribute’s decl, we now filter out any attrs that are not valid in that position. Fixes a broken test.
2025-03-26 10:47:58 -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
Becca Royal-Gordon
32b8a11b11 Add flags to specify @abi behavior of attributes
This PR adds a set of DeclAttr.def flags for specifying how a given attribute interacts with `@abi`, and declares a behavior for each existing attribute. Future attributes will be *required* to declare an `@abi` behavior lest they fail a static assert.

Note that the behavior is not actually enforced in this commit—it is merely specified here.
2025-03-26 10:47:56 -07:00
Becca Royal-Gordon
495d464044 Add DeclAttribute::isEquivalent()
Adds a new method to `DeclAttribute` which can compare two attributes and see if they would be “equivalent” in light of the given decl. “Equivalent” here means that they would have the same effect on the declaration; for instance, two attrs with different source locations can be equivalent, and two attributes with the same arguments in a different order are equivalent if the ordering of those argumetns is not semantically equivalent.

This capability is not yet used in this commit, but in a future commit `@abi` will check if certain attributes are equivalent or not.
2025-03-26 10:47:14 -07:00
Becca Royal-Gordon
e88b99a6ff Inherit availability in @abi
ABI-only declarations now inherit `@available`, `@backDeployed`, etc. from their ABI counterpart. This will make it unnecessary to specify these attributes in `@abi`. Also some changes to make sure we suggest inserting `@available` in the correct place.

No tests because the enforcement is not yet in.
2025-03-26 10:47:13 -07: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
d8349e72ca [NFC] Expose default param specifier computation
Make this logic accessible outside of the mangler.
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
Becca Royal-Gordon
cd61fd4dc5 [NFC] Fix ImplementsAttr::clone()
Correct an issue with `ImplementsAttr` that would come up if you ever tried to clone an attribute that had been deserialized.

No tests because there’s nothing in the compiler yet that might actually do so.
2025-03-26 10:47:11 -07:00
Michael Gottesman
8cfb029b5c [sil] Make SILFunctionTypeInfo a struct enum.
I am doing this in preparation for adding the ability to represent in the SIL
type system that a function is global actor isolated. Since we have isolated
parameters in SIL, we do not need to represent parameter, nonisolated, or
nonisolated caller in the type system. So this should be sufficient for our
purposes.

I am adding this since I need to ensure that we mangle into thunks that convert
execution(caller) functions to `global actor` functions what the global actor
is. Otherwise, we cannot tell the difference in between such a thunk and a thunk
that converts execution(caller) to execution(concurrent).
2025-03-26 10:23:44 -07:00
Slava Pestov
cc05e1e79a AST: Check subject type in ProtocolConformanceRef::forAbstract() 2025-03-26 12:29:35 -04:00
Slava Pestov
4289b98f9b AST: Fix handling of ErrorType in MakeAbstractConformanceForGenericType
And remove the assert, it will be replaced with one inside forAbstract().
2025-03-26 12:29:34 -04:00
Slava Pestov
d77c6f413d RequirementMachine: Skip protocol type aliases that contain unbound dependent member types
In the below, 'Self.A.A' is not a type parameter; rather, since
'Self.A' is concretely known to be 'S', we resolve it as 'S.A',
which performs a name lookup and finds the concrete type alias 'A':

    public struct S {
      public typealias A = Int
    }

    public protocol P {
      typealias A = S
    }

    public struct G<T> {}

    public protocol Q: P {
      typealias B = G<Self.A.A>
    }

This is fine, but such a type alias should not participate in
the rewrite system. Let's exclude them like any other invalid
requirement.

The type alias itself is not an error; however, it is an error
to use it from a 'where' clause requirement. This is not
diagnosed yet, though.

Fixes rdar://136686001.
2025-03-26 10:55:23 -04:00
Hamish Knight
b719498369 Merge pull request #80242 from hamishknight/mutable-problems-require-mutable-solutions
[AST] Always walk folded SequenceExpr if available
2025-03-26 10:43:50 +00: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
Anthony Latsis
a75b63ab6d Merge pull request #77920 from AnthonyLatsis/fissidens
AST: Rename debugger pretty printer `Type::dumpPrint` to `print`
2025-03-25 23:42:36 +00:00
Anthony Latsis
a95785c5b2 Merge pull request #80260 from AnthonyLatsis/eutrema-japonicum
DiagnosticEngine: Print the ID of the wrapped, not wrapper, diagnostic
2025-03-25 23:14:43 +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
Michael Gottesman
7648bce91b Merge pull request #80210 from gottesmm/pr-5cf03315e9a3442419b1bab18b46f755fdf0b405
[concurrency] Make sure that TypeLowering inserts the extra actor parameter for @execution(caller) parameters.
2025-03-25 10:09:44 -07:00
Slava Pestov
6463dcb9c9 Merge pull request #79703 from slavapestov/span-backward-deployment
Build CompatibilitySpan shim
2025-03-25 07:28:47 -04:00
Dylan Sturgeon
2c8e337f25 Merge pull request #80074 from dylansturg/objc_enum_refs
The Error enum synthesized declarations, e.g. the struct and its static accessors, should generally appear to be identical to the underlying Clang definitions. There are some specific use cases where the synthesized declarations are necessary though.

I've added an option for USR generation to override the Clang node and emit the USR of the synthesized Swift declaration. This is used by SwiftDocSupport so that the USRs of the synthesized declarations are emitted.

Fixes 79912
2025-03-25 11:21:21 +00:00
Anthony Latsis
77e673a723 DiagnosticEngine: Print the ID of the wrapped, not wrapper, diagnostic 2025-03-25 02:25:39 +00:00
Anthony Latsis
8ad2e02596 Sema: Allow @execution on storage declarations 2025-03-25 02:07:04 +00:00
Anthony Latsis
d73402af25 AST: Restrict @execution to func and init declarations 2025-03-25 02:07:04 +00:00
Anthony Latsis
6512aa1f5a AST: Introduce and use ValueDecl::isAsync 2025-03-25 02:07:03 +00:00
Steven Wu
df86e089c8 Merge pull request #80172 from cachemeifyoucan/eng/PR-147513165
Fix `.swiftdeps` file deterministic issues
2025-03-24 15:15:17 -07:00