Commit Graph

3461 Commits

Author SHA1 Message Date
Joe Groff
3c0b08dbcb Prototype an @_addressable attribute that puts an argument at a stable address.
Many APIs using nonescapable types would like to vend interior pointers to their
parameter bindings, but this isn't normally always possible because of representation
changes the caller may do around the call, such as moving the value in or out of memory,
bridging or reabstracting it, etc. `@_addressable` forces the corresponding parameter
to be passed indirectly in memory, in its maximally-abstracted representation.
[TODO] If return values have a lifetime dependency on this parameter, the caller must
keep this in-memory representation alive for the duration of the dependent value's
lifetime.
2024-12-03 20:39:23 -08:00
Allan Shortlidge
ecf7ac910e Merge pull request #77907 from tshortli/semantic-decl-availability
AST: Refactor semantic unavailability queries
2024-12-03 08:30:13 -08:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Allan Shortlidge
64f9d5b945 AST: Remove Decl::getSemanticUnavailableAttr().
Also remove the underlying `SemanticUnavailableAttrRequest`, which used memory
very inefficiently in order to cache a detailed answer to what was usually a
much simpler question.

The only remaining use of `Decl::getSemanticUnavailableAttr()` that actually
needed to locate the semantic attribute making a declaration unavailable was in
`TypeCheckAttr.cpp`. The implementation of the request could just be used
directly in that one location. The other remaining callers only needed to know
if the decl was unavailable or not, which there are simpler queries for.

 # Please enter the commit message for your changes. Lines starting
2024-12-02 23:00:43 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01: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
cd13d7d777 AST: Remove AvailableAttr::RenameDecl.
The renamed decl is now stored exclusively in the split request evaluator
storage, which is more efficient since most availability attributes do not
specify a renamed decl.
2024-11-29 10:35:02 -05:00
Allan Shortlidge
e6741d5e9e AST: Adopt ValueDecl::getRenamedDecl().
This unblocks removing `RenameDecl` from `AvailableAttr`.
2024-11-29 10:34:49 -05:00
Allan Shortlidge
88c0638f37 AST: Introduce a ValueDecl convenience for looking up the renamed decl.
Wrap `RenamedDeclRequest` instead of evaluating it directly.
2024-11-22 14:35:23 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Nate Chandler
563f932a00 [NFC] Extracted predicate. 2024-11-19 15:52:24 -08:00
Nate Chandler
8eaae59c3b [NFC] AST: Moved impl from Sema.
Now that the function is declared in AST, it should be implemented
there.
2024-11-19 15:52:24 -08:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Nate Chandler
de86cc037c [CoroutineAccessors] Tweak diags for old accessors
When the feature is enabled, refer to the old accessors as they are
actually spelled (i.e. `_read` and `_modify`).
2024-11-11 18:34:01 -08:00
nate-chandler
aab880da05 Merge pull request #77429 from nate-chandler/general-coro/20241104/1
[CoroutineAccessors] Synthesize default requirement implementations.
2024-11-10 07:43:11 -08:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Gábor Horváth
88c2269e69 Merge pull request #77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2024-11-07 17:44:07 +00:00
Nate Chandler
76dc6e12a8 [NFC] Cache preexisting synthesized accessor.
Move the bailout from getSynthesizedAccessor from the wrapper function
into the evaluate body.  Will enable the request to do work on
non-synthesized accessors, which is required to provide a default
implementation for modify2 and read2 members.
2024-11-06 20:52:21 -08:00
Allan Shortlidge
49b59f69c9 Revert https://github.com/swiftlang/swift/pull/75745.
Finishes resolving rdar://139236053.
2024-11-05 14:37:56 -08:00
Hamish Knight
152812cc86 [AST] Use cached deserialized decl in getOpaqueResultTypeDecl
Mangling and looking up the opaque result type decl
for serialized decls is a fairly expensive
operation. Instead, fallthrough to the request
which will have a cached value set by deserialization.
This shaves ~30ms off the cached completion for:

```swift
import SwiftUI

struct V: View {
  var body: some View {
    Table(#^CC^#
  }
}
```
2024-11-04 11:29:55 +00:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
Gábor Horváth
09c89fb983 Merge pull request #77204 from swiftlang/gaborh/diagnostic-location
[cxx-interop] Import more C++ source locations into Swift
2024-10-31 11:06:11 +00:00
nate-chandler
65a6d03805 Merge pull request #77265 from nate-chandler/general-coro/20241024/1
[CoroutineAccessors] Key table membership off availability.
2024-10-30 18:01:38 -07:00
Gabor Horvath
86e708a39b [cxx-interop] Import more C++ source locations into Swift
Occasionally, when the Swift compiler emits a diagnostic for a construct
that was imported from C++ we get a diagnostic with unknown location.
This is a bad user experience. It is particularly bad with the
borrow-checker related diagnostics. This patch extends the source
location importing to declarations in ClangImporter. There are some
invariants enforced by the Swift compile, e.g., a source range is
comprised of two valid source locations or two invalid ones. As a
result, this patch adds approximate source locations to some separators
like braces or parens that are not maintained by Clang. Having slightly
incorrect ranges in this case is better than emitting unknown source
locations.
2024-10-30 10:58:26 +00:00
Michael Gottesman
12538618fb [gardening] Move ActorIsolation method definitions from Decl.cpp -> ActorIsolation.cpp.
Just noticed this while working in the general area.
2024-10-29 16:08:09 -07:00
Nate Chandler
b87b42cd1e [CoroutineAccessors] If available, provide old ABI
If the feature is enabled, base the requirement for the underscored
accessors on the availability of the non-underscored accessors.  If the
(non-underscored) accessor's was available earlier than the feature,
interpret that to mean that the underscored version was available in
that earlier version, and require the underscored version.  The goal is
to ensure that the ABI is preserved, so long as the simplest migration
is done (namely, deleting the underscores from the old accessors).

For modify2, cache the required-ness in the same way that it is cached
for modify.
2024-10-29 14:24:36 -07:00
Nate Chandler
651436d46a [CoroutineAccessors] Prefer for access.
If read2/modify2 exist, prefer them as part of the access strategy for
reading/writing/read-writing.
2024-10-29 14:24:36 -07:00
Nate Chandler
c3f9cc18e8 [CoroutineAccessors] Visit new accessors.
Every required accessors should be visited.  Results in the new
accessors appearing in vtables and wtables.
2024-10-29 14:24:36 -07:00
Nate Chandler
829fe3ef3c [CoroutineAccessors] Separate requires predicates.
Whether read2/modify2 are required will not always be identical to
whether read/modify are required.  Add separate prediates for the
former.  For now, duplicate the latter's implementation.
2024-10-29 14:24:36 -07:00
Nate Chandler
5f362c5916 [NFC] Sema: Moved predicate to cpp.
In preparation to make it more involved.
2024-10-29 14:24:35 -07:00
Hamish Knight
3c8921aa69 [Sema] Avoid relying on ParenType in space engine
Refactor `decomposeDisjuncts` to avoid relying on
the modeling of single unlabeled associated values
as ParenTypes.
2024-10-24 15:29:48 +01: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
Holly Borla
2f33d875d9 Merge pull request #76988 from hborla/init-checking-order
[Sema] Fix an issue with the ordering of effects checking and actor isolation checking.
2024-10-12 11:21:33 -07:00
Holly Borla
e1bf19822d [Sema] Put effects checking behind a request for experimental lazy
type checking.
2024-10-11 20:33:38 -07:00
Anthony Latsis
41adfec8da [NFC] AST, Sema: Move TypeChecker::findReturnStatements into AnyFunctionRef
Also rename it to `getExplicitReturnStmts` for clarity and have it
take a `SmallVector` out parameter instead as a small optimization and
to discourage use of this new method as an alternative to
`AnyFunctionRef::bodyHasExplicitReturnStmt`.
2024-10-11 03:57:43 +03:00
Anthony Latsis
c7ea672463 [NFC] AST, Sema: Internalize BraceHasReturnRequest evaluation in AnyFunctionRef method 2024-10-11 03:44:43 +03:00
Meghana Gupta
011b5bf10c Delete dependsOn support
Lifetime dependencies will now be represented with @lifetime attribute in the language.

dependsOn is a type modifier and was represented as a LifetimeDependentTypeRepr in the AST.

I am deleting dependsOn syntax parsing support and retaining LifetimeDependentTypeRepr support.

We may want to represent lifetime dependencies in a function type with a type attribute in the future.
If we use a decl attribute instead, then support for LifetimeDependentTypeRepr can be deleted.
2024-10-07 00:24:35 -07:00
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
nate-chandler
ba8f8ea282 Merge pull request #76526 from nate-chandler/general-coro/20240906/1
[CoroutineAccessors] Initial framing.
2024-09-30 07:04:04 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
Hamish Knight
bf6bb650ea Merge pull request #76771 from hamishknight/rename-arg-interface-ty
[AST] NFC: Rename `getArgumentInterfaceType` -> `getPayloadInterfaceType`
2024-09-29 22:53:13 +01:00
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Allan Shortlidge
d2b562aca3 Merge pull request #76756 from tshortli/member-import-visibility-cxx
SE-0444: Fix interactions with Cxx interop
2024-09-28 08:07:03 -07:00
Zhen Li
f91ad050c6 [ImportResolution] Fix import kind when value decl is a typealias of an existential type (#72738) 2024-09-28 09:14:56 +00:00
Allan Shortlidge
b11bb1ceea SE-0444: Fix interactions with Cxx interop.
With the upcoming `MemberImportVisibility` feature enabled, code built with Cxx
interop also enabled could be rejected by the compiler with cryptic errors
about the `__ObjC` module not being imported. This is the result of a
surprising implementation detail of Cxx interop. When importing C++ namespaces
and their members, the Clang importer puts these declarations in the Clang
header import module (a.k.a. the bridging header module, `__ObjC`). C++
namespaces don't have a logical modular home in the Swift AST because they can
span multiple modules, so it's understandable why this implementation was
chosen. However, the concrete members of namespaces also get placed in the
`__ObjC` module too, and this really confuses things.

To work around this idiosyncrasy of Cxx interop, I've introduced
`Decl::getModuleContextForNameLookup()` which returns the module that a
declaration would ideally belong to if Cxx interop didn't have this behavior.
This alternative to `Decl::getModuleContext()` is now used everywhere that
`MemberImportVisibility` rules are enforced to provide consistency.

Additionally, I found that I also had to further special-case the header import
module for Cxx interop because it turns out that there are some additional
declarations, beyond imported namespaces, that also live there and need to be
implicitly visible in every source file. The `__ObjC` module is not implicitly
imported in source files when Cxx interop is enabled, so these declarations are
not deemed visible under normal name lookup rules. When I tried to add an
implicit import of `__ObjC` when Cxx interop is enabled, it broke a bunch
tests. So for now, when a decl really belongs to the `__ObjC` module in Cxx
interop mode, we just always allow it to be referenced.

This Cxx interop behavior really needs a re-think in my opinion, but that will
require larger discussions.

Resolves rdar://136600598.
2024-09-27 12:16:38 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Konrad `ktoso` Malawski
d89347bed0 Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-20 18:34:45 +09:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00