Commit Graph

3502 Commits

Author SHA1 Message Date
Joe Groff
a52e96e358 Merge pull request #71263 from jckarter/borrowing-switch-3
Parse `_borrowing x` in patterns as a borrow binding.
2024-01-31 07:08:32 -08:00
Joe Groff
6706feaf5e Parse _borrowing x in patterns as a borrow binding.
Treat it as a contextual keyword when followed by an identifier, like our
other ownership-related declarations and operators.
2024-01-30 17:33:42 -08:00
Hamish Knight
9cf8f5b1f0 [AST] Remove AbstractFunctionDecl::getSingleExpressionBody
This is now unused.
2024-01-30 14:08:54 +00:00
Hamish Knight
d5a3e36309 [AST] Remove AbstractFunctionDecl::setSingleExpressionBody
This is now unused.
2024-01-30 14:08:53 +00:00
Allan Shortlidge
52abd6c4fc AST/Sema: Adjust @backDeployed attribute diagnostics for unavailable decls
Use `inheritsAvailabilityFromPlatform()` to determine whether to suppress
diagnostics about back deployed functions being unavailable. Previously, if the
platform of the `@backDeployed` attribute and the platform of the `@available`
attribute did not match exactly the diagnostic was always suppressed, which was
too permissive.
2024-01-29 16:57:29 -08:00
John McCall
41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
Holly Borla
7bcade6cd3 Merge pull request #71143 from hborla/isolation-inheritance
[Concurrency] More precise modeling of `ActorIsolation` for isolated arguments and captures.
2024-01-25 10:11:50 -08:00
Holly Borla
a43779c396 [Concurrency] Handle #isolation in isolated argument checking. 2024-01-24 22:00:40 -08:00
Holly Borla
f2b088518c [Concurrency] Implement more precise actor isolation for isolated argument
values.

Teach ActorIsolation that a `nil` isolated argument is statically nonisolated,
and a reference to GlobalActor.shared statically has global actor isolation.

This change also models arbitrary actor instance isolation using VarDecls
when possible, which allows comparing two ActorIsolation values that may
represent different actor instances. Previously, ActorIsolation was
modeled only by storing the nominal actor type and the parameter index,
so the actor isolation value for two different actors was considered
to be equal. Now, the nominal actor type is only used for isolated `self`
in cases where there is no implicit self parameter decl, such as for
stored properties.
2024-01-24 20:24:34 -08:00
Holly Borla
f7326618ae [Concurrency] Model actor isolation to an arbitrary actor instance using
a VarDecl or Expr.

This generalization exposed a bug where distributed actor isolation checking
was skipped in some cases, including for the isolated call in `whenLocal`.
The `whenLocal` implementation violated distributed actor isolation because
despite the `__isLocal` dynamic check, the `self` value passed to the `body`
function argument is still not statically local. To workaround this, I
applied the `_local` modifier explicitly to `self` before the call, which
also necessitated allowing `_local` to be written explicitly in the Distributed
library.
2024-01-24 16:11:09 -08:00
Kavon Farvardin
58480c3be1 [NCGenerics] provide namespace for CanBeInvertible 2024-01-23 22:42:38 -08:00
Kavon Farvardin
b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08:00
Kavon Farvardin
9d6ac1c7f7 [NCGenerics] fix hack in requiresInvertible 2024-01-23 22:41:59 -08:00
Ellie Shin
ab3b5add3a Currently decls defined with package access level have a different
access level for optimization: `public`. It requires an extra check for
the actual access level that was declared when determining serialization
since the behavior should be different.

This PR sets its effective access level to `package` as originally defined,
updates call sites to make appropriate acces level comparisons, and removes
`package` specific checks.
2024-01-23 11:02:49 -08:00
Holly Borla
d60a06760b Merge pull request #71050 from hborla/global-actor-unsafe
[Concurrency] Deprecate `@GlobalActor(unsafe)` in favor of `@preconcurrency @GlobalActor`
2024-01-22 16:52:56 -08:00
Ellie Shin
663f068668 Merge pull request #70141 from apple/es-res
Treat package as resilient as non-frozen public by default
2024-01-23 08:48:48 +09:00
Hamish Knight
fd97268393 Merge pull request #70983 from hamishknight/another-cleanup
[AST] Remove SerializedLocalDeclContext
2024-01-22 18:49:42 +00:00
Ellie Shin
c24a003309 Treat package as resilient as non-frozen public by default.
If the defining module is built resiliently, treat the package decl as resilient,
just as we do for public decls.
Access methods to `package` should be the same as for non-frozen `public`, i.e. indirect.
Added tests for SIL/IR wrt serialization and indirect access with/out resilience enabled.

Resolves rdar://118947451
2024-01-22 09:56:59 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Holly Borla
f581eb7d1b [Concurrency] Remove remaining special cases of ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Holly Borla
99978027fc [Concurrency] Represent an unsafe global actor using preconcurrency.
`@GlobalActor(unsafe)` and `@preconcurrency @GlobalActor` mean the same
thing, but there were two different representations in the actor isolation
checker. Standardize on the preconcurrency representation.
2024-01-21 17:05:26 -08:00
Pavel Yaskevich
57bf9d52b1 Merge pull request #71014 from xedin/inheritedentry-bitfields
[AST] NFC: Convert `InheritedEntry` flags to bitfields
2024-01-19 16:19:47 -08:00
Pavel Yaskevich
7f6a8f865c [AST] NFC: Convert InheritedEntry flags to bitfields 2024-01-19 10:22:39 -08:00
Michael Gottesman
9513d298ec [region-isolation] Add parsing/serialization/type system support for a transferring OwnershipSpecifier. 2024-01-18 13:20:28 -08:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Hamish Knight
f6b7301259 Merge pull request #70591 from hamishknight/doritos-and-fritos
[AST] A couple of PatternBindingInitializer cleanups
2024-01-18 11:33:19 +00:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Hamish Knight
af82121286 [AST] Make PatternBindingInitializer::setBinding private
And add some assertions to ensure we don't attempt
to re-set the binding or index (the parent context
can unfortunately change currently).
2024-01-17 16:02:33 +00:00
Hamish Knight
990d15567d [AST] Split up PatternBindingDecl::setPattern
Most clients only want to set one of the two
parameters, split it into `setPattern` and
`setInitContext` (the latter of which now
handles calling `setBinding`).
2024-01-17 16:02:33 +00:00
Hamish Knight
47f7a31095 [AST] Tighten up type of InitContext
Switch from promising a DeclContext to a
PatternBindingInitializer.

This has a couple of benefits:
- It eliminates a few places where we were force
`cast`'ing to PatternBindingInitializer.
- It improves the clarity of what's being stored,
it's not whatever the parent context of the
initializer is, it's specifically the
PatternBindingInitializer context if it exists.
2024-01-17 16:02:33 +00:00
Hamish Knight
e3261f6b04 [AST] Remove SerializedPatternBindingInitializer
This stores the same state as
PatternBindingInitializer, we can use that
instead.
2024-01-17 16:02:32 +00:00
Hamish Knight
fb0a75fe55 [AST] NFC: Introduce PatternBindingInitializer::create 2024-01-17 16:02:32 +00:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Doug Gregor
b31133e67d Ensure that freestanding macros get consistent discriminators
Due to the duality between the expression and declaration forms of
freestanding macros, we could end up assigning two different discriminators
to what is effectively the same freestanding macro expansion. Across
different source files, this could lead to inconsistent discriminators in
different translation units. Unify the storage of the discriminator to
avoid this issue.

Fixes rdar://116259748
2024-01-11 08:18:28 -08:00
Kavon Farvardin
c777e5a2dc [NFC] non-null assertion for inheritsFrom 2024-01-10 19:37:21 -08:00
Kavon Farvardin
778a413745 [NCGenerics] ensure ExistentialLayout is minimal
Instead of injecting Copyable & Escapable protocols into every
ExistentialLayout, only add those protocols if the existing protocols
don't already imply them. This simplifies things like `any Error`
protocol, so it still only lists one protocol in its existential layout.
But existentials like `any NoCopyP` still end up with a Copyable in its
layout.
2024-01-10 19:37:21 -08:00
Rintaro Ishizaki
f7e35cb835 [AST] Requestify local type declarations
Instead of recording local type declarations while parsing, make a
request to collect them from the AST. This reduces the side effect of
parsing.
2024-01-05 13:26:55 -08:00
Meghana Gupta
d3e921dc47 Make _resultDependsOn available on SILFunctionArgument 2023-12-29 01:57:19 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Sima Nerush
2fd5843a79 Merge pull request #70355 from simanerush/pack-iteration-fixes
[SE-0408] Pack iteration review feedback!
2023-12-16 09:50:31 -08:00
Sima Nerush
0482bd3652 [Sema] Refactor code and improve documentation pertaining to SE-0408. 2023-12-15 20:39:40 -08:00
Hamish Knight
2f25d8fa58 [AST] Compute SubscriptDecl EndLoc
Instead of having the parser set it, compute it
using the recorded brace location for the accessor
record.
2023-12-15 21:44:31 +00:00
Hamish Knight
8fdb48d910 [AST] Rename SubscriptDecl::create -> createParsed
And generate the DeclName using the argument labels
on the ParameterList.
2023-12-15 21:44:31 +00:00
Hamish Knight
526dcfbe11 [AST] Factor out AccessorDecl::createParsed
Move the logic for splicing together the
accessor's parameter list out of the parser so
that ASTGen will be able to use it too.
2023-12-15 21:44:30 +00:00
Hamish Knight
b04d5d5abc [ASTGen] Better handle pattern binding entries
Generate all entries, and ensure we introduce a
PatternBindingInitializer context for non-local
cases. Also use this opportunity to cleanup
`PatternBindingDecl::create`.
2023-12-15 21:44:30 +00:00
Hamish Knight
f10365597d [AST] Use PatternBindingDecl::createImplicit in more places
And simplify the implementation of `create`.
2023-12-15 21:44:30 +00:00
Doug Gregor
ab5ab28010 Merge pull request #70454 from DougGregor/full-typed-throws-inference
[Typed throws] Implement thrown type inference for do..catch within closures
2023-12-14 16:09:33 -08:00
Kavon Farvardin
64226fbcba Merge pull request #70452 from kavon/fix-typelowering
[NCGenerics] fix type lowering
2023-12-14 11:38:55 -08:00
Kavon Farvardin
4657fa9d48 [NCGenerics] fix type lowering
TypeDecl::canBeNoncopyable is never going to be fully accurate. In this
instance, we were incorrectly treating some types like `S<T: ~Copyable>`
 as noncopyable, and thus non-trivial, despite them in some cases being
 Copyable.
2023-12-14 08:45:27 -08:00