Commit Graph

3451 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
elsh
bd9272c695 [PackageInterface] Fix isInterfacePackageEffectivelyPublic.
ValueDecl::isInterfacePackageEffectivelyPublic is used to check if a package decl in
interface file can be skipped for typecheck; if the decl is inlinable and in public or
private interface, it should be allowed to skip. This PR adds a missing check which
looks up the Interface source kind.

Resolves rdar://135388095
2024-09-07 08:49:23 -07:00
Alejandro Alonso
45d7ea39a5 Merge pull request #75518 from Azoy/integer-generics
Implement Value generics
2024-09-05 15:33:46 -07:00
Doug Gregor
9d3c265572 Merge pull request #76287 from DougGregor/local-let-of-tuple-type
Expand the tuple "hack" for initializable values to local tuples
2024-09-05 15:07:04 -07:00
Doug Gregor
ac850bf86f Expand the tuple "hack" for initializable values to local tuples
Back off treating local lets of tuple type as "initializable", expanding
on the narrow carve-out from #74133. Without this, we would reject local
lets of tuple type that are initialized piecemeal.

Fixes rdar://135028163.
2024-09-05 10:57:02 -07:00
Alejandro Alonso
22349bcfb9 Use intptr_t instead of ssize_t and more test fixes 2024-09-04 15:13:49 -07:00
Alejandro Alonso
46a4d56c2b Bring back the isOpaqueType parameter for deserialization 2024-09-04 15:13:49 -07:00
Alejandro Alonso
71fee06c9a Requestify GTPD::getValueType 2024-09-04 15:13:46 -07:00
Slava Pestov
b9b6bb7b69 AST: Introduce new kind of sugared GenericTypeParamType
This one just stores an identifier instead of a declaration.
2024-09-04 15:13:46 -07:00