Commit Graph

28382 Commits

Author SHA1 Message Date
Pavel Yaskevich
67ee63d875 [ConstraintSystem] InferSendableFromCaptures: Mark unapplied operator references as @Sendable
Both of these functions are single-apply instance members,
even though their names could be compound the application
is still a regular call with like `next(isolation: ...)`
vs. `next(isolation:)(...)` it would have to be for a "compound"
application.

Operator references don't have a base type and could be found via
unqualified lookup, `adjustFunctionTypeForConcurrency` should handle
them specifically.

Resolves: rdar://131321053
2024-08-30 15:24:26 -07:00
Hamish Knight
89a3390aa1 [Sema] Move SingleValueStmtUsageChecker into pre-checking
These diagnostics are better suited for pre-checking
since we ought to be emitting them even if there's
some other error with the expression.
2024-08-30 18:55:48 +01:00
Hamish Knight
1139b0e799 Remove shouldWalkCaptureInitializerExpressions from PreCheckTarget
We walk into PatternBindingDecls, so I don't think
there should be any reason we can't walk captures
normally (i.e via their PBD).
2024-08-30 18:55:48 +01:00
Hamish Knight
f0e487dc81 NFC: Rename PreCheckExpression -> PreCheckTarget 2024-08-30 18:55:48 +01:00
Hamish Knight
0a71ca7219 NFC: Fix PreCheckExpression indent
Avoid indenting in the anonymous namespace.
2024-08-30 18:55:48 +01:00
Doug Gregor
03c429c5e6 Merge pull request #76157 from DougGregor/parse-if-config-same-buffer 2024-08-29 19:56:25 -07:00
Slava Pestov
d36dcea88d Merge pull request #76154 from slavapestov/combine-substitution-maps
Move combineSubstitutionMaps() to SILOptimizer and fix an assertion
2024-08-29 20:51:49 -04:00
Pavel Yaskevich
0a4ff7df81 [CSBindings] Allow inference of l-value type from its object type
This aims to help with cases like `_ = { x in x = 0 }` or `.test = 42`
which are currently supported because the member is eagerly bound to
an `@lvalue $T` during constraint generation.
2024-08-29 16:49:44 -07:00
Doug Gregor
6a310074c4 Ensure that the source buffer passed to #if evaluation contains the condition
The implementation of `#if` configuration evaluation assumed that the
SourceFile instance within the `Parser` contained all of the source ranges
for code parsed within that `Parser` instance. This is not always the case,
so avoid using the SourceFile directly and instead use the source buffer
that directly contains the condition.

Fixes https://github.com/swiftlang/swift/issues/76137. Big thank you
to Alex Hoppen and the stress tester for finding this.
2024-08-29 14:31:48 -07:00
Slava Pestov
e918422271 Sema: Remove commented out code and fix line breaks 2024-08-29 16:18:13 -04:00
Pavel Yaskevich
6bbf945053 Merge pull request #76141 from xedin/downgrade-specialization-errors-to-warnings
[ConstraintSystem] Downgrade some invalid specialization uses to a warning until Swift 6 language mode
2024-08-29 12:35:30 -07:00
Pavel Yaskevich
2e53bc26cd [CSSimplify] Implement LValueObject constraint simplification 2024-08-29 10:10:14 -07:00
Pavel Yaskevich
5a93255133 [ConstraintSystem] Introduce new LValueObject constraint 2024-08-29 10:10:14 -07:00
Mykola Pokhylets
e0ad7bde82 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/AST/ASTPrinter.cpp
#	lib/AST/FeatureSet.cpp
2024-08-29 11:28:43 +02:00
Pavel Yaskevich
b6fd5fe1ba [CSDiangostics] Adjust phrasing of invalid specialization diagnostic
Instead of "a generic function" which is too abstract and not always
correct, let's actually point to a kind of the declaration being referenced.
2024-08-29 00:15:57 -07:00
Pavel Yaskevich
2a6cc12a63 [ConstraintSystem] Downgrade some invalid specialization uses to a warning until Swift 6 language mode
Some invalid specializations were previously allowed by the compiler
and we found some existing code that used that (albeit invalid) syntax,
so we need to stage that error as a warning until Swift 6 language mode
to avoid source compatibility break.

Resolves: rdar://134740240
2024-08-29 00:15:08 -07:00
Slava Pestov
f2fff10cc9 SIL: Synchronous local functions don't need to capture the isolation parameter
Also, move this rule from the computation of lowered captures in SIL,
to the computation of AST captures in Sema. This allows us to
correctly handle the case where an async function nests inside a
sync function. It also removes a special case that was added recently
to cope with a generic `self` type.

Fixes rdar://129366819.
2024-08-28 17:03:49 -04:00
Hamish Knight
3436c49ee4 Merge pull request #76123 from hamishknight/a-form-of-expression
[Sema] Remove `preCheckExpression`
2024-08-28 21:25:36 +01:00
Pavel Yaskevich
6465bdc6e1 Merge pull request #76042 from xedin/rdar-133415157
[Sema/SILGen] Emit dynamic actor isolation checks for closures
2024-08-28 13:06:55 -07:00
Pavel Yaskevich
88e2484b39 [ConstraintSystem] Fix isPartialApplication to handle unappled operator references 2024-08-28 12:47:57 -07:00
Pavel Yaskevich
00eee36ea7 Merge pull request #76115 from xedin/rdar-131524246
[CSBindings] Don't prioritize closures that are assigned to overloade…
2024-08-28 12:32:22 -07:00
Hamish Knight
3c16ecf568 [Sema] Remove preCheckExpression
There are only a couple of clients left using this,
migrate them onto `preCheckTarget`.
2024-08-28 15:09:40 +01:00
Pavel Yaskevich
c8690b34e7 [CSBindings] Don't prioritize closures that are assigned to overloaded members
Constraint generation uses a special pattern while generating
constraints for assignments to make sure that the source type
is convertible to r-value type of the destination.

`BindingSet::favoredOverDisjunction` needs to recognize this
pattern, where disjunction type variable is bound early, and
avoid prioritizing closure if it's connected to the "fixed type"
of the disjunction or risk losing annotations associated with
the member such as `@Sendable` or a global actor.

Resolves: rdar://131524246
2024-08-27 16:19:29 -07:00
Pavel Yaskevich
2b1fb8b17a Merge pull request #76048 from xedin/improve-existential-matching-diagnostics
[Diagnostics] Produce a diagnostic for existential mismatch in same-type constraint
2024-08-27 00:22:38 -07:00
Allan Shortlidge
d8db750f0f Merge pull request #76066 from tshortli/associated-type-inference-availability
Sema: Relax availability of typealiases for inferred type witness
2024-08-26 09:49:47 -07:00
Allan Shortlidge
06aeddeb0c Merge pull request #76071 from tshortli/require-explicit-availability-protocol-extension
Sema: Fix required availability diagnostics for protocol extensions
2024-08-26 09:28:32 -07:00
Doug Gregor
225e562dda Requestify the #if computation using SwiftIfConfig
We're not caching this now, but it lets us dodge annoying layering
issues because ASTGen (where this is available) sits on top of the C++
parser, which needs to call it.
2024-08-24 21:31:41 -07:00
Michael Gottesman
da597be76d Merge pull request #76075 from gottesmm/rdar133531625
[region-isolation] Treat as Sendable values that are meant to be ignored since they are marked with preconcurrency
2024-08-24 22:26:00 -04:00
Slava Pestov
8315120eaf Merge pull request #76051 from slavapestov/archetype-get-parent
AST: Remove ArchetypeType::getParent()
2024-08-24 15:31:01 -04:00
Allan Shortlidge
16ac3553c9 Sema: Fix required availability diagnostics for protocol extensions.
Extending a protocol cannot introduce new conformances to other protocols, so
skip checking for associated conformances to public protocols when diagnosing
required availability on such an extension.

Resolves rdar://133873836.
2024-08-23 22:23:39 -07:00
Michael Gottesman
bbc4816861 [sema] Move getConcurrencyDiagnosticBehaviorLimit and hasExplicitSendableConformance out of Sema and into libAST.
I am going to expose this on TypeBase, so I am attempting to prevent a layering
violation in between AST and Sema.
2024-08-23 20:42:51 -04:00
Allan Shortlidge
1c9b6eb723 Sema: Relax availability of typealiases for inferred type witness.
Only constrain the availability of the synthesized typealias for an inferred
type witness by the availability of the associated type if the associated type
is less available than its protocol. Without this, source compatibility is
broken for some conformances. For example:

```
struct IdentifiableValue: Identifiable {
  let id = 42
}

extension IdentifiableValue {
  // error: 'ID' is only available in macOS 10.15 or newer
  var nextID: ID {
    return id + 1
  }
}

```

Fixes a regression introduced by https://github.com/swiftlang/swift/pull/71496.

Resolves rdar://134584323
2024-08-23 15:49:51 -07:00
Allan Shortlidge
359de85af3 Sema: Relax associated conformance availability checking.
If an associated conformance comes from an associated type requirement, then
the associated conformance only needs to be as available as that associated
type.

Resolves rdar://133544161.
2024-08-22 20:44:46 -07:00
Pavel Yaskevich
815699d21a [Diagnostics] Produce a diagnostic for existential mismatch in same-type constraint
Previously this would result in a fallback diagnostic because
type mismatches associated with `ExistentialConstraintType`
locations weren't handled at all.
2024-08-22 16:51:48 -07:00
Slava Pestov
da4d076f02 AST: Introduce SubstFlags::SubstitutePrimaryArchetypes 2024-08-22 18:41:14 -04:00
Allan Shortlidge
4420ea853b Sema: Check availability of conformance type witnesses.
The type satisfying a protocol requirement must be at least as available as the
associated type for the requirement.

Resolves rdar://134093006
2024-08-22 15:23:21 -07:00
Pavel Yaskevich
d151118833 [CSSimplify] Don't erase sugar while forming locators for generic types during matching
Fixes retrieve information form locators which means that we
need to preserve the original form for diagnostics.
2024-08-22 14:46:36 -07:00
Allan Shortlidge
4757eebcf7 Sema: Expose a utility on ExportContext for checking unavailability.
Code that wants to determine whether a given declaration should be considered
unavailable should use this new utility, which will take the unavailability of
the context of use into consideration.

NFC.
2024-08-22 14:02:04 -07:00
Allan Shortlidge
11304b7804 AST: Take decls instead of identifiers in some conformance diagnostics.
NFC.
2024-08-22 13:57:32 -07:00
Pavel Yaskevich
44d83aee8a [CSApply] Start marking closures that require dynamic isolation checking
If a closure is passed as an argument to a not-fully concurrency
checked callee - require dynamic isolation checking.

This information is going to be used by SILGen to inject expected
executor precondition when necessary.
2024-08-22 09:57:17 -07:00
Pavel Yaskevich
a4d9b3b5b2 [AST] Add a bit to closure expr to indiciate whether it requires dynamic isolation checking
This is an important information for closures because the compiler
might need to emit dynamic actor isolation checks in some circumstances
(i.e. when a closure is isolated and passed to a not fully concurrency
checked API).
2024-08-22 09:57:06 -07:00
Ben Langmuir
f39a4a6d23 Merge pull request #76018 from benlangmuir/fix-availability-narrowing-fixit
[sema] Fix availability narrowing fixits for macOS >= 11
2024-08-22 08:46:30 -07:00
Slava Pestov
07b697e178 Merge pull request #76030 from slavapestov/open-existential-get
AST: Remove OpenedArchetypeType::get() overload taking an interface type
2024-08-22 09:32:57 -04:00
Konrad `ktoso` Malawski
1861375f88 [Concurrency] Suggest adding a method, when mutating actor property cross isolation (#75922) 2024-08-22 20:24:39 +09:00
Slava Pestov
e9b6f0b82d AST: Remove OpenedArchetypeType::get() overload taking an interface type 2024-08-21 19:47:30 -04:00
Slava Pestov
863afad0a2 Merge pull request #75947 from slavapestov/type-subst-rework-2
Type::subst() rework, part 2
2024-08-21 19:31:08 -04:00
Ben Langmuir
c957826c28 [sema] Fix availability narrowing fixits for macOS >= 11
For macOS >= 11 the fixit for narrowing an availability check rather
than adding a new one should fire if the major version is the same, like
on other platforms.
2024-08-21 10:22:07 -07:00
Slava Pestov
ae77d6f0c1 AST: Replace one-off predicates with SubstitutionMap::getRecursiveProperties() 2024-08-21 13:19:10 -04:00
Pavel Yaskevich
3df5e9c997 Merge pull request #75991 from xedin/rename-ispassedtosendingparameter
[AST] NFC: Rename `ParameterInfoList::isPassedToSendableParameter` to…
2024-08-21 09:14:00 -07:00
Allan Shortlidge
abce071cb2 Merge pull request #76000 from tshortli/no-app-extensions-in-if-available-fix-its
Sema: Avoid application extension platforms in `if #available` fix-its
2024-08-20 21:21:43 -07:00