Commit Graph

672 Commits

Author SHA1 Message Date
Slava Pestov
1d18cd07cf Sema: Record closure types in the trail 2024-10-07 16:50:47 -04:00
Slava Pestov
43a4ac9216 Sema: Record resolved overloads in the trail 2024-10-07 16:50:46 -04:00
Slava Pestov
892e79cd70 Sema: Use an xmacro to clean up some duplication in CSTrail.cpp 2024-10-07 16:50:46 -04:00
Slava Pestov
6862955244 Sema: Record applied property wrappers in the trail 2024-10-07 16:50:46 -04:00
Slava Pestov
c7edc3494e Sema: Record result builder transforms in the trail 2024-10-07 16:50:45 -04:00
Slava Pestov
64293ece51 Sema: Push reconciliation down into applySolution() to strengthen invariants
Now, we assert if you try to record the same change twice in any
other code path.
2024-10-07 16:50:45 -04:00
Slava Pestov
61575d9913 Sema: Remove a few isRecordingChanges() checks to tighten invariants
In these places we now assert if we attempt to record a change
during an active undo.
2024-10-07 16:50:45 -04:00
Slava Pestov
9115a46736 Sema: Record favored constraints in the trail 2024-10-07 16:50:45 -04:00
Slava Pestov
b2adf51d78 Sema: Record disabled constraints in the trail 2024-10-07 16:50:45 -04:00
Slava Pestov
411c590bc8 Sema: Record key path component types in the trail 2024-10-07 16:50:44 -04:00
Slava Pestov
7ea975015f Sema: Record ASTNode types in the trail 2024-10-07 16:50:44 -04:00
Slava Pestov
3dc16a9f5b Sema: Record defaulted constraints in the trail 2024-10-01 18:10:20 -04:00
Slava Pestov
fcd6bc04fd Sema: Remove Solution::PackElementGenericEnvironments 2024-10-01 18:10:20 -04:00
Slava Pestov
0518b762d1 Sema: Record pack environments in the trail 2024-10-01 18:10:20 -04:00
Slava Pestov
f51bf3cf9d Sema: Record pack expansion environments in the trail 2024-10-01 18:10:20 -04:00
Slava Pestov
9afb1a960b Sema: Record opened pack expansion types in the trail 2024-10-01 18:10:20 -04:00
Slava Pestov
7d3350d0f2 Sema: Record opened existential types in the trail 2024-10-01 18:10:19 -04:00
Slava Pestov
f963f36a16 Sema: Record opened types in the trail 2024-10-01 18:10:19 -04:00
Slava Pestov
a9f392278f Sema: Record argument matching choices in the trail 2024-10-01 18:10:18 -04:00
Slava Pestov
8b4a58fb02 Sema: Record applied disjunctions in the trail 2024-10-01 18:10:18 -04:00
Slava Pestov
8799596bed Sema: Record disjunction choices in the trail 2024-10-01 18:10:18 -04:00
Slava Pestov
49487b8893 Sema: Record fixed requirements in the trail 2024-10-01 18:10:17 -04:00
Slava Pestov
df692edc7c Sema: Record fixes in the trail 2024-10-01 12:34:41 -04:00
Slava Pestov
62a470e3d5 Sema: Record conversion restrictions in the trail 2024-10-01 12:34:41 -04:00
Slava Pestov
c0afe3fce1 Sema: Don't create new ConstraintGraphNode during active undo
This messes up the bookkeeping for the trail.
2024-09-27 10:51:47 -04:00
Slava Pestov
105b6b39a9 Sema: Remove ConstraintGraphScope 2024-09-26 23:15:27 -04:00
Slava Pestov
8ee4eeee55 Sema: Migrate SavedTypeVariableBindings to SolverTrail 2024-09-26 23:15:27 -04:00
Slava Pestov
4cc27c9b20 Sema: Factor out SolverTrail from ConstraintGraph 2024-09-26 23:15:26 -04:00
Kavon Farvardin
df73eecdeb Sema: generalize findSyntacticErrorForConsume
Since this function is being called from the constraint solver now, we
need to generalize the way it obtains the Type of an Expression, as the
expression itself may not know its own type, only the solver does.

resolves rdar://134371893 / https://github.com/swiftlang/swift/issues/75999
2024-09-24 13:59:29 -07:00
Hamish Knight
1cc00e3676 [CS] NFC: Remove SolutionApplicationToFunctionResult
This is now no longer needed.
2024-09-17 12:35:11 +01:00
Hamish Knight
930dc18eb7 [CS] Avoid delaying application for multi-statement closures
We ought to be able to apply the solution to them
immediately now.
2024-09-17 12:35:11 +01:00
Hamish Knight
f0151c1d21 [CS] Delay type-checking of local decls
Delay `typeCheckDecl` for local decls until the
end of CSApply. This replaces the existing logic
for delaying type-checking for local functions.
2024-09-17 12:35:10 +01:00
Hamish Knight
d99d881af5 [CS] NFC: Factor out base class SyntacticElementTargetRewriter
Pass this instead of a function for rewriting
targets.
2024-09-17 12:35:10 +01:00
Allan Shortlidge
58a77206c4 ConstraintSystem: Remove UnviableReason::UR_MissingImport.
Now that `MemberImportVisibility` behavior is implemented using ranking there
is no need to support the `UR_MissingImport` unviability reason.
2024-09-10 09:47:42 -07:00
Allan Shortlidge
c868378d96 ConstraintSystem: Use scoring to implement MemberImportVisibility.
Previously, the constraint solver would first attempt member lookup that
excluded members from transitively imported modules. If there were no viable
candidates, it would perform a second lookup that included the previously
excluded members, treating any candidates as unviable. This meant that if the
member reference did resolve to one of the unviable candidates the resulting
AST would be broken, which could cause unwanted knock-on diagnostics.

Now, members from transitively imported modules are always returned in the set
of viable candidates. However, scoring will always prioritize candidates from
directly imported modules over members from transitive imports. This solves the
ambiguities that `MemberImportVisibility` is designed to prevent. If the only
viable candidates are from transitively imported modules, though, then the
reference will be resolved successfully and diagnosed later in
`MiscDiagnostics.cpp`. The resulting AST will not contain any errors, which
ensures that necessary access levels can be computed correctly for the imports
suggested by `MemberImportVisibility` fix-its.

Resolves rdar://126637855.
2024-09-10 09:47:42 -07:00
Hamish Knight
ee0e408a8c [Sema] Remove separate closure type-checking logic
`participatesInInference` is now always true for
a non-empty body, remove it along with the separate
type-checking logic such that empty bodies are
type-checked together with the context.
2024-09-08 16:17:11 +01:00
Slava Pestov
851a829063 Sema: Consolidate logic for opening existentials in OpenedExistentials.cpp 2024-09-04 14:57:38 -04:00
Pavel Yaskevich
f9e08bc6ec Merge pull request #76174 from xedin/remodel-constraint-generation-for-assignment
[ConstraintSystem] Introduce `LValueObject` constraint to replace direct l-value assignments
2024-09-04 09:27:59 -07:00
Pavel Yaskevich
bd313deae5 Merge pull request #76136 from xedin/rdar-131321053
[ConstraintSystem] InferSendableFromCaptures: Mark unapplied operator references as `@Sendable`
2024-09-02 08:29:56 -07:00
Pavel Yaskevich
df27db1534 [ConstraintSystem] NFC: Remove obsolete isPartialApplication 2024-08-30 17:04:51 -07:00
Pavel Yaskevich
05b0adac5d [ConstraintSystem] Use getNumApplications + ValueDecl::getNumCurryLevels to detect partial applications
We used to detect partial applications based on member locators
and parent expressions, but using function reference kind +
check to see if self is applied is such simpler and hits both
uses of `isPartialApplication`.
2024-08-30 17:04:46 -07:00
Pavel Yaskevich
5a93255133 [ConstraintSystem] Introduce new LValueObject constraint 2024-08-29 10:10:14 -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
Slava Pestov
d4d85572ce Sema: typeEraseOpenedArchetypesWithRoot() => typeEraseOpenedArchetypesFromEnvironment() 2024-08-19 16:55:10 -04:00
Hamish Knight
22b08da0dd [Sema] Remove replaceInvalidRefsWithErrors param
Doesn't seem like anything is relying on setting
this to `false` anymore, remove it.
2024-07-21 15:27:15 +01:00
Allan Shortlidge
d002da0ef2 AST: Add a IgnoreMissingImports option to name lookup.
Control enforcement of member import visibility requirements via a new option,
instead of piggy-backing on the existing IgnoreAccessControl option. Adopt the
option when doing fallback lookups for unviable members so that the compiler
can diagnose the reason that a member is inaccessible more reliably.
Previously, with MemberImportVisibility enabled decls with the package access
level could be mis-diagnosed as inaccessible due to their access level when
really they were inaccessible due to a missing import.

Resolves rdar://131501862.
2024-07-10 22:57:15 -07:00
Hamish Knight
ee5df0041a [Sema] Remove DisableExprAvailabilityChecking 2024-07-06 16:20:21 +01:00
Hamish Knight
09a1f0b0c1 [CS] NFC: Factor out includingParentApply 2024-06-12 19:38:09 +01:00
Kavon Farvardin
e55e247f0c ConstraintSystem: clarify consuming conversions
There are a number of implicit conversions in Swift, such as to Optional
and to an existential, which are now possible for noncopyable types.

But all type casts are consuming operations for noncopyable types. So
it's confusing when a function that takes a borrowed argument of
optional type appears to be consuming:

```
func f(_ x: borrowing NC?) { ... }

let x = NC()
f(x)
f(x) // error!
```

So, rather than for people to write `x as T?` around all implicit
conversions, require them to write `consume x` around expressions
that will consume some lvalue. Since that makes it much more clear what
the consequences will be.

Expressions like `f(g())`, where you're passing an rvalue to the callee,
are not confusing. And those are exactly the expressions you're not
allowed to write `consume` for, anyway.

fixes rdar://127450418
2024-06-04 14:04:19 -07:00
Allan Shortlidge
15545a4ed3 NFC: Fix some out of sync doccomments. 2024-05-24 14:43:16 -07:00