Commit Graph

1727 Commits

Author SHA1 Message Date
Slava Pestov
25252cd683 Merge pull request #77728 from slavapestov/cg-cleanup
Sema: Small ConstraintGraph cleanup
2024-11-20 19:43:42 -05:00
Slava Pestov
7fef225c9f Sema: Allow turning off expression timer with -solver-expression-time-threshold=0 2024-11-20 13:46:19 -05:00
Slava Pestov
c8415aeac4 Sema: Record the trail step count in solver statistics
Also introduce two new frontend flags:

The -solver-scope-threshold flag sets the maximum number of scopes, which was
previously hardcoded to 1 million.

The -solver-trail-threshold flag sets the maximum number of trail steps,
which defaults to 64 million.
2024-11-20 13:46:19 -05:00
Slava Pestov
24de22a078 Sema: Split off ConstraintGraph::addTypeVariable() from ::operator[]
Also, since we add a vertex immediately after introducing a new type
variable, the code path to handle the case where the type variable
had a parent or fixed type was actually dead.
2024-11-20 13:35:21 -05:00
Slava Pestov
c5de105a2b Sema: Workaround for invalid logic in Solution::simplifyTypeForCodeCompletion() 2024-11-20 13:35:21 -05:00
Slava Pestov
de731b4d5d Sema: Preserve insertion order in Solution::typeBindings 2024-11-20 11:47:07 -05:00
Slava Pestov
b760cfd03d Sema: Fold ConstraintGraph::lookupNode() into ::operator[]
lookupNode() returned a pair but both callers only looked at the
first element of the pair.
2024-11-20 08:23:58 -05:00
Slava Pestov
a7b1e7854c Merge pull request #77174 from slavapestov/fix-undo-order
Sema: Undo changes in chronological order in SolverTrail::undo()
2024-11-20 08:00:53 -05:00
Slava Pestov
1a60685292 Sema: Address the FIXME in ConstraintGraph::mergeNodes() 2024-11-19 21:24:12 -05:00
Slava Pestov
5690addb4e Sema: Fix ordering of constraint graph updates vs fixed type assignment 2024-11-19 21:24:12 -05:00
Slava Pestov
1ecba36e76 Sema: Cache Solution::getTotalMemory()
This is showing up in performance profiles.
2024-11-19 16:04:57 -05: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
Doug Gregor
720429daf4 [Constraint solver] Disable fallback diagnostic when error emitted into a transaction
When we are using diagnostic transactions to disable immediate emission
of diagnostics, `DiagnosticEngine::hadAnyError()` no longer accurately
reports whether an error occurred. Thread the DiagnosticTransaction
into the ConstraintSystem so we can also check whether it contains an
error before emitting the fallback diagnostic.

Fixes rdar://128272346.
2024-11-06 17:07:13 -08:00
Allan Shortlidge
161dc2e09e Sema: Rename getUnmetDeclAvailabilityRequirement().
Name it `getUnsatisfiedAvailabilityConstraint()` to match
`AvailabilityConstraint`.
2024-11-04 19:58:28 -08:00
Hamish Knight
7061a20edd [CS] Remove ConstraintSystem::getVarType
The logic here for completion wasn't actually
helping things since it would result in adding the
var overload to the system, which would result
in an ErrorType binding. We could turn the ErrorType
into a placeholder when resolving the overload,
but the simpler solution is to just allow CSGen
to turn the reference into a PlaceholderType. This
matches what we do for regular solving, and fixes
a crash with an IUO completion.

rdar://89369091
2024-11-04 17:08:20 +00:00
Allan Shortlidge
7b5757b29b Sema: Replace TypeChecker::checkDeclarationAvailability().
Adopt `getUnmetDeclAvailabilityRequirement()` instead.
2024-11-03 11:37:01 -08:00
Allan Shortlidge
0377ef4afd Sema: Take a SourceLoc in getUnmetDeclAvailabilityRequirement().
Introduce a convenience overload for the common case where the
AvailabilityContext must first be looked up by source location.
2024-11-03 11:37:01 -08:00
Allan Shortlidge
a95891cbb8 Sema: Rename checkDeclarationAvailability().
Type checker functions with the prefix "check" usually check some requirement
and then diagnose it if it isn't satisfied. `checkDeclarationAvailability()`
doesn't diagnose on its own, so it should be named differently.
2024-11-03 11:37:01 -08:00
Allan Shortlidge
98b34c6ff6 Sema: Correctly treat overloads in unavailable extensions as unavailable.
Instead of checking for unavailability attributes directly in the solver, which
does not correctly handle members of unavailable extensions, query
`checkDeclarationAvailability()` instead. By using the same underlying logic as
the availability checker the constraint solver can be confident in the accuracy
of this result.

Resolves rdar://87403752.
2024-11-02 17:15:11 -07:00
Pavel Yaskevich
6109463cce [ConstraintSystem] NFC: Rename threshold in ExpressionTimer to clarify granularity
The variable was named incorrectly, it's actually expressed in seconds.
2024-10-28 17:29:01 -07:00
Slava Pestov
53794d3b6a Sema: Rename ConstraintSystem::generateConstraints() to ConstraintSystem::generateOverloadConstraints() 2024-10-22 20:14:43 -04:00
Slava Pestov
b44bff26b5 Sema: Fold Constraint::createFixedChoice() into Constraint::createBindOverload() 2024-10-22 20:14:42 -04:00
Slava Pestov
61bd58d5ef Sema: Split off TypeOfReference.cpp from ConstraintSystem.cpp 2024-10-10 17:53:12 -04:00
Slava Pestov
b0303bb5a1 Sema: Restore old behavior in ConstraintSystem::openType()
My change to preserve type sugar in type transforms introduced a
performance regression here, because openType() is called for
every disjunction choice.

My hope is to optimize the TypeAliasType representation and remove
this at some point, but for now, let's just restore the old
desugaring behavior in this case.
2024-10-08 11:53:45 -04:00
Slava Pestov
e47f9966ad Sema: ConstraintSystem::openType() uses TypeTransform 2024-10-07 17:46:40 -04:00
Slava Pestov
12eb7cec26 Sema: Record implicit callAsFunction() roots in the trail 2024-10-07 16:50:49 -04:00
Slava Pestov
72a60728fc Sema: Record argument lists in the trail 2024-10-07 16:50:49 -04:00
Slava Pestov
881a0100b2 Sema: Record implicit value conversions in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
ac17292dfe Sema: Record preconcurrency closures in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
b961a7ec51 Sema: Record isolated parameters in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
500acd122a Sema: Record potential throw sites 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
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
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
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
186589bd25 Sema: Remove SolverTrail::Change::introducedToInference() 2024-09-30 22:05:41 -04:00
Slava Pestov
148033930c Sema: Split off introduceToInference() into its own Change
Previously, retractFromInference() was the last step in
unbindTypeVariable(). This doesn't really make sense,
because bindTypeVariable() doesn't call introduceToInference();
its two callers do it later.

Start untangling this by splitting off introduceToInference()
into its own Change, but for now, record this change at the
incorrect place to maintain the same behavior as before.
2024-09-29 21:46:41 -04:00
Slava Pestov
8ee4eeee55 Sema: Migrate SavedTypeVariableBindings to SolverTrail 2024-09-26 23:15:27 -04:00