Commit Graph

2410 Commits

Author SHA1 Message Date
swift-ci
a66951aa3d Merge pull request #60521 from kavon/preconcurrency-var-access
Add missing function conversion for member access to preconcurrency vardecl.
2022-08-30 00:58:49 -07:00
Kavon Farvardin
6c24bc57cb [AST][SILGen] model ABI-safe casts of LValues
We needed a way to describe an ABI-safe cast of an address
representing an LValue to implement `@preconcurrency` and
its injection of casts during accesses of members.

This new AST node, `ABISafeConversionExpr` models what is
essentially an `unchecked_addr_cast` in SIL when accessing
the LVAlue.

As of now I simply implemented it and the verification of
the node for the concurrency needs to ensure that it's not
misused by accident. If it finds use outside of that,
feel free to update the verifier.
2022-08-29 20:58:26 -07:00
Kavon Farvardin
e70fbbc738 [ConstraintSystem] correct the @preconcurrency adjustment of var references
We intended to introduce AST conversions that strip concurrency
attributes off of types associated with `@preconcurrency` decls.
But for VarDecl references, we stripped it too early, leading to
things like a MemberVarDecl that doesn't have `@Sendable` in its
result type, but the VarDecl it refers to does have it.

That caused crashes in SIL where types didn't match up. This patch
fixes things by delaying the stripping until the right point.

resolves rdar://98018067
2022-08-29 20:58:25 -07:00
Pavel Yaskevich
932c6b40c5 [ConstraintSystem] Don't use special locator for value-to-value conversions related to contextual type
Previously locator for value-to-value conversion would just drop
all the contextual information if the conversion occurred while
converting expression to a contextual type. This is incorrect for
i.e. `return` statements and other targets because because they
are solved separately and using the same locator would result in
a clash when solutions are merged.
2022-08-25 14:33:03 -07:00
Pavel Yaskevich
b23f1c23e9 [CSApply] Adjust contextual locator of single expression closure before coercion
Contextual conversion constraint is placed on `result of closure body`
and solution application logic should match that.
2022-08-25 14:32:13 -07:00
Slava Pestov
40c2678e38 Sema: Fix existential opening for arguments to self.init/super.init delegation
Fixes rdar://problem/98404682.
2022-08-24 00:24:55 -04:00
Pavel Yaskevich
b02e16de07 Merge pull request #60568 from xedin/rdar-98577451
[CSApply] Attempt value-to-opaque-result abstraction only after canon…
2022-08-16 09:47:42 -07:00
Pavel Yaskevich
b4949a0b2c [CSApply] Attempt value-to-opaque-result abstraction only after canonicalization
`ExprRewriter::coerceToType` should canonicalize contextual type before
attempting to use it for value abstraction, because sugared type could
have typealias references that hide their underlying opaque result types.

Resolves: rdar://98577451
2022-08-15 21:30:17 -07:00
Pavel Yaskevich
7bcb8d4a93 Merge pull request #60541 from xedin/fix-opened-type-printing
[ConstraintSystem] NFC: Check whether opened type has a binding befor…
2022-08-15 09:27:55 -07:00
Hamish Knight
76931677a8 Merge pull request #60438 from hamishknight/factor-in-factor-out 2022-08-13 17:21:37 +01:00
Pavel Yaskevich
389cfe7f65 [ConstraintSystem] NFC: Check whether opened type has a binding before printing
In some circumstances opened type might not have a fixed binding.
A good example could be dependent sub-component produced for
result builder transformed code (connected via one-way constraints),
in such a case `OpenedTypes` would have outer generic parameters
but they might not be bound yet, so they have to be printed as
type variables.
2022-08-12 17:29:29 -07:00
Pavel Yaskevich
42135e27c4 Merge pull request #60387 from amritpan/improve-solution-printing
[ConstraintSystem] Improve solution printing in the type inference algorithm debug output
2022-08-10 09:03:29 -07:00
Amritpan Kaur
2786f24b67 [TypeCheckConstraints.cpp] Remove printing of any empty constraint choice headings and fix minor spacing issues. 2022-08-09 14:09:39 -07:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Pavel Yaskevich
5ee5a22cf1 [TypeChecker] NFC: Add a dedicated method to get outermost attached wrapper
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
2022-08-04 17:30:02 -07:00
Pavel Yaskevich
3e65a7cab0 Merge pull request #60065 from xedin/result-builder-ast-transform-under-flag
[TypeChecker] Implement result builder transform via AST modification under a flag
2022-08-02 16:22:01 -07:00
Pavel Yaskevich
432ce1cf4e [ConstraintSystem] Allow placeholder vars to have initializer and nested holes
Initializers of such variables are going to be type-checked post factum,
when the type of the variable itself has been determined by the solver.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
a6421fc94e [CSClosure] Declarations prefixed with $ can act as inferrable placeholders
If the type for such declaration could be completely inferred it
would be used during solution application. This is used to infer
types for result builder components.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
65aeb4ad89 [CSSolver] Add support for TypeJoinExpr 2022-08-02 11:41:35 -07:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Hamish Knight
77b00821aa [CS] Remove an obsolete bit of logic
SILGen shouldn't care whether or not a self
parameter is wrapped in a paren with ownership.
2022-08-02 13:56:32 +01:00
Hamish Knight
4915513387 [CS] Filter out uncallable vars when simplifying applied overloads
This improves diagnostics as we can now consider
functions that don't line up exactly with the
argument list if no other viable candidates exist.
2022-07-26 12:51:53 +01:00
Hamish Knight
13fe88cc57 [AST] Rename isCallableNominalType -> isCallAsFunctionType
Make it explicit that we're checking for
`callAsFunction` instead of `dynamicallyCall`.
2022-07-25 22:03:55 +01:00
Pavel Yaskevich
01d7d51e4e Merge pull request #60137 from xedin/rdar-97261826
[CSApply] Use fully qualified locator while coercing member chain result
2022-07-20 19:14:13 -07:00
Pavel Yaskevich
53ce55a166 [CSApply] Use fully qualified locator while coercing member chain result
Constraint generator records conversion between chain result expression
and contextual type as anchored on an implicit unresolved chain result,
which means that coercion has to do the same in case restrictions
(like Double<->CGFloat conversion) depend on locators to retrieve
information for the solution.

Resolves: rdar://97261826
2022-07-19 11:48:56 -07:00
Doug Gregor
36c99173ac [Constraint system] Simplify stripping inout/lvalue type for opened existentials 2022-07-18 14:50:13 -07:00
Doug Gregor
6ce24548cd Make sure we open an lvalue of existential type during application. 2022-07-15 13:30:07 -07:00
Slava Pestov
421f39a371 Sema: Fix some edge cases with opaque return types in structural position
Move the check where we insert UnderlyingToOpaqueExpr earlier in
coerceToType(). Otherwise, returning a metatype or function type
would attempt to perform a conversion instead of building a
UnderlyingToOpaqueExpr.

Fixes part of https://github.com/apple/swift/issues/60038.
2022-07-14 11:07:52 -04:00
Doug Gregor
8ccaad3dec Merge pull request #59975 from DougGregor/cleanup-fix-behavior
Cleanup after recent refactoring for fix behaviors
2022-07-08 20:08:14 -07:00
Doug Gregor
7436fb365a Rename CSFix::affectsSolutionScore() to impact(). 2022-07-08 13:03:12 -07:00
Doug Gregor
de7b840661 Replace CSFix::canApplySolution() with isFatal(). 2022-07-08 13:03:12 -07:00
Doug Gregor
b9afb79f50 Merge pull request #59963 from DougGregor/constraint-system-preconcurrency
[Constraint solver] Track "isolated by preconcurrency" in the solver.
2022-07-08 09:52:24 -07:00
Doug Gregor
5b537eab1b Merge pull request #59958 from DougGregor/constraint-solver-recoverable-error
[Constraint solver] Improve fix behaviors for better concurrency-related recovery and overloading
2022-07-08 09:51:53 -07:00
Doug Gregor
4fc4bd79e8 [Constraint solver] Track "isolated by preconcurrency" in the solver.
Rather than only setting the isolated-by-preconcurrency bit during
constraint application, track the closures it will be set for as part
of the constraint system and solution. Then, use that bit when
performing "strict concurrency context" checks and type adjustments,
so we don't treat an inferred-to-by-`@Sendable`-by-preconcurrency
closure in the solver as if it weren't related to preconcurrency.

Fixes the spurious warning from
https://github.com/apple/swift/issues/59910.
2022-07-07 23:46:30 -07:00
Doug Gregor
2e3aa67c02 [Constraint solver] Treat downgraded errors as "disfavored overloads".
This allows us to still maintain them in the score kind, but not treat
them as being as severe as an error requiring a fix.
2022-07-07 18:12:56 -07:00
Pavel Yaskevich
b35372367e Merge pull request #59902 from xedin/rdar-96469597
[CSApply] A couple of locator adjustments to support updated Double<->CGFloat conversion
2022-07-07 13:25:03 -07:00
Doug Gregor
c564698625 [Constraint solver] Improve modeling of fix behavior.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:

* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether

These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
2022-07-07 12:17:11 -07:00
Holly Borla
380e370157 Merge pull request #59853 from hborla/invalid-covariant-erasure
[CSApply] Don't attempt covariant result type erasure when parameters use dynamic `Self`.
2022-07-07 11:02:14 -07:00
Pavel Yaskevich
b8cba10a5f [CSApply] Use fully qualified locator while coercing ternary branches
The locator needs to much what was produced by constraint generator
otherwise Double<->CGFloat implicit coercion wouldn't be able to
find the overload choice.
2022-07-07 09:17:02 -07:00
Pavel Yaskevich
7cc6892ab7 [CSApply] Adjust locator while coercion source of assignment to destination type
Constraint generator records conversion between source and destination
types as anchored on an assignment, which means that coercion has to do
the same in case restrictions (like Double<->CGFloat conversion) depend
on locators to retrieve information for the solution.
2022-07-07 09:17:02 -07:00
Pavel Yaskevich
074035b24f [CSApply] Use fully qualified locator while coercing dictionary elements
Just like in case of array elements, the locator needs to much what
was produced by constraint generator otherwise Double<->CGFloat implicit
coercion wouldn't be able to find the overload choice.
2022-07-07 09:16:56 -07:00
Pavel Yaskevich
1d1f065f8e [CSApply] Use fully qualified locator while coercing array elements
Double/CGFloat implicit conversion expects a full locator
(array-expr + tuple-element <idx>) to find selected overload.
2022-07-07 09:14:42 -07:00
Doug Gregor
afd65fa728 Merge pull request #59849 from DougGregor/preconcurrency-sendable-params 2022-07-01 21:44:22 -07:00
Anthony Latsis
f1207ff04f Merge pull request #59171 from AnthonyLatsis/init-delegation-optional
CSGen, SILGen: Fix delegations to `Optional` initializers
2022-07-02 02:28:18 +03:00
Doug Gregor
43399bad78 Make sure we propagate @preconcurrency to closures consistently.
The type checker is now permitting `@Sendable` closures whose captures
can be by-reference, because we do not error. Remove an aspirational
SIL verifier check that banned this.
2022-07-01 15:29:49 -07:00
Holly Borla
6cff3aadc7 [CSApply] Don't attempt covariant result type erasure for parameters
of method references.
2022-07-01 14:21:59 -07:00
Doug Gregor
0674058ba0 Introduce more AST function conversions for @preconcurrency-adjusted types.
When referring to a `@preconcurrency` function as a value, use the normal
type for the initial declaration reference and then introduce an
appropriate function conversion expression to the adjusted type.

Fixes more issues related to rdar://94597323.
2022-06-30 17:00:56 -07:00
Doug Gregor
01c2e42354 Introduce a function conversion for "adjusted" dynamic member references.
When we have adjusted the type of a dynamic member reference (e.g.,
for `@objc optional` methods) due to `@preconcurrency` or similar,
form the original dynamic member reference based on the original type
and then introduce an appropriate conversion. This better reflects the
adjustment in the AST, eliminating a SIL verifier crash.

Fixes rdar://94597323.
2022-06-30 17:00:32 -07:00
Doug Gregor
248b72bbff Track the pre-adjusted "reference" type for declaration reference. 2022-06-30 17:00:32 -07:00
Doug Gregor
1063e8126e [Constraint system] Track the original opened type for a selected overload. 2022-06-30 17:00:31 -07:00