Commit Graph

672 Commits

Author SHA1 Message Date
Slava Pestov
c0787f337f Sema: Fix soundness hole with variable initializers and opaque return types
Just because the type of the initializer expression is an opaque return type,
does not mean it is the opaque return type *for the variable being initialized*.

It looks like there is a bit of duplicated logic and layering violations going
on so I only fixed one caller of openOpaqueType(). This addresses the test case
in the issue. For the remaining calls I added FIXMEs to investigate what is
going on.

Fixes https://github.com/swiftlang/swift/issues/73245.
Fixes rdar://127180656.
2024-12-04 15:13:22 -05:00
Pavel Yaskevich
08720eef82 Merge pull request #77936 from xedin/revert-void-favoring
Revert changes related to `Void` binding favoring
2024-12-04 10:24:20 -08:00
Pavel Yaskevich
8aa6280bf3 Revert "[CSBindings] Don't favor application result types before application happens"
This reverts commit bc949c3680.
2024-12-03 13:15:46 -08:00
Hamish Knight
d25bdfa4a3 [CS] Remove hack for rdar://139234188
Now that "is compound" is a separate bit in
FunctionRefInfo, we can correctly track the
application level for an EnumElementPattern.
2024-12-03 11:32:11 +00:00
Hamish Knight
0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Hamish Knight
746135b4d7 [CS] Add a narrow hack for rdar://139234188
Currently we set `FunctionRefKind::Compound` for
enum element patterns with tuple sub-patterns to
ensure the member has argument labels stripped. As
such, we need to account for the correct application
level in `getNumApplications`. We ought to be
setting the correct FunctionRefKind and properly
handling the label matching in the solver though.
We also ought to consider changing FunctionRefKind
such that "is compound" is a separate bit from the
application level.

rdar://139234188
2024-11-22 13:43:58 +00:00
Pavel Yaskevich
e61bf2089c [ConstraintSystem] Make types of implicit result builder variables locatable
This would aid `FailureDiagnostic` in anchoring conformance failures to `View`.
2024-11-21 14:12:57 -08:00
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
60d34a4162 Sema: Micro-optimize PotentialBindings
PotentialBindings is part of ConstraintGraphNode and there's no need
to store the ConstraintSystem and TypeVariableType twice.

Also it doesn't need to be optional either, because we no longer need
to reset and recompute bindings.
2024-11-20 13:35:22 -05:00
Slava Pestov
1a18d70f90 Sema: Remove ConstraintSystem::SolverState::isRecordingChanges()
All but two remaining call sites can be changed to just check for a
non-null solverState, because we want to assert if we're inside
of an active undo.

The two places inside binding inference can check isUndoActive()
directly.
2024-11-20 13:35:22 -05:00
Slava Pestov
de731b4d5d Sema: Preserve insertion order in Solution::typeBindings 2024-11-20 11:47:07 -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
1ecba36e76 Sema: Cache Solution::getTotalMemory()
This is showing up in performance profiles.
2024-11-19 16:04:57 -05:00
Slava Pestov
09df48f9fb Sema: Remove DenseMap usage when opening types 2024-11-18 11:40:38 -05:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Pavel Yaskevich
bc949c3680 [CSBindings] Don't favor application result types before application happens
Until `ApplicableFunction` constraint is simplified result type
associated with it cannot be bound because the binding set if
incomplete.

Resolves: rdar://139237088
2024-11-08 14:00:01 -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
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
3400022c63 Sema: Remove ConstraintKind::SelfObjectOfProtocol 2024-10-22 20:14:43 -04:00
Slava Pestov
c728c2aa8b Sema: Simplify doesStorageProduceLValue() 2024-10-22 20:14:43 -04:00
Slava Pestov
6c02529cf8 Sema: Simplify ConstraintSystem::getUnopenedTypeOfReference() 2024-10-22 20:14:43 -04:00
Slava Pestov
53794d3b6a Sema: Rename ConstraintSystem::generateConstraints() to ConstraintSystem::generateOverloadConstraints() 2024-10-22 20:14:43 -04:00
Slava Pestov
58a6a64647 Sema: SolverTrail::Change::RetiredConstraint now remembers the position 2024-10-21 17:19:01 -04:00
Slava Pestov
38fe0696a4 Sema: Factor out clearScore() and replayScore() 2024-10-09 11:48:07 -04:00
Slava Pestov
c8db9f55e6 Sema: Remove last heap allocation of Scope 2024-10-09 11:48:07 -04:00
Slava Pestov
0b85ce6f00 Sema: Remove SolverScope::numFixes 2024-10-08 16:57:49 -04:00
Slava Pestov
5fdc1a81b8 Sema: Record retired constraints in the trail 2024-10-08 16:39:34 -04:00
Slava Pestov
90175400d2 Sema: Record generated constraints in the trail 2024-10-08 16:17:28 -04:00
Slava Pestov
1e2d4fbc59 Sema: Record score increases in the trail 2024-10-08 16:16:31 -04:00
Slava Pestov
877c60e3d0 Sema: Rename applySolution() to replaySolution() 2024-10-08 16:16:01 -04:00
Slava Pestov
1323953219 Sema: Try not to make a negative impact 2024-10-08 16:14:05 -04:00
Slava Pestov
e47f9966ad Sema: ConstraintSystem::openType() uses TypeTransform 2024-10-07 17:46:40 -04:00
Slava Pestov
4a82d384b7 Sema: Record synthesized conformances in the trail 2024-10-07 16:50:49 -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
f2412f318e Sema: Record key path expressions in the trail 2024-10-07 16:50:48 -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
1d177d0187 Sema: Record expression patterns 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
39d0eab275 Sema: Record case label items in the trail 2024-10-07 16:50:47 -04:00
Slava Pestov
8c8a385a4a Sema: Record SyntacticElementTargetKeys in the trail 2024-10-07 16:50:47 -04:00
Slava Pestov
516277f0fd Sema: Record contextual types in the trail 2024-10-07 16:50:47 -04:00
Slava Pestov
666361adf2 Sema: Record implied results in the trail 2024-10-07 16:50:47 -04:00