Commit Graph

1538 Commits

Author SHA1 Message Date
Pavel Yaskevich
1760bd1f1e [CSOptimizer] Remove an outdated optimization to compare resolved argument types with all else equal
This is already accounted for by `determineBestChoicesInContext`
and reflected in the overall score, which means that we no longer
need to use this in vacuum.
2024-12-17 11:36:39 -08:00
Pavel Yaskevich
c429f5b9ec [CSOptimizer] NFC: Switch from llvm::Optional to std::optional post-rebase 2024-12-17 11:36:39 -08:00
Pavel Yaskevich
0fc6806922 [CSOptimizer] NFC: Switch to llvm::Optional 2024-12-17 11:36:39 -08:00
Pavel Yaskevich
e404ed722a [CSStep] Don't favor choices until the disjunction is picked 2024-12-17 11:36:38 -08:00
Pavel Yaskevich
4432c51f57 [CSGen] Remove ConstraintOptimizer and all favoring logic 2024-12-17 11:36:37 -08:00
Pavel Yaskevich
757ca24e8a [ConstraintSystem] Remove shrink 2024-12-17 11:36:37 -08:00
Slava Pestov
351c36f327 Merge pull request #77959 from slavapestov/fix-issue-73245
Sema: Fix soundness hole with variable initializers and opaque return types
2024-12-05 15:36:55 -05:00
Pavel Yaskevich
464ff30cfa Merge pull request #77952 from xedin/print-changes-in-a-more-readable-way
[CSTrail] NFC: Make `dumpActiveScopeChanges` friendlier to humans
2024-12-05 08:20:26 -08:00
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
f94685e704 [CSTrail] NFC: Add dump() methods to SolverTrail 2024-12-04 10:36:12 -08: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
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00: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
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
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
a19c92a4e0 Sema: Extract duplication from ConstraintGraph::introduceTo/retractFromInference(Type) overloads 2024-11-19 21:24:13 -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
0d3d31599f Sema: Remove ConstraintGraph::reintroduceToInference() 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
Hamish Knight
27995eed19 [Completion] Type-check parent closures for local functions
Local functions can capture variables from parent
closures, so we need to make sure we type-check
parent closures when doing completion in a local
function. Ideally we ought to be able to be more
selective about the elements of the parent closure
that we type-check, but that's a more complex change
I'm leaving as future work for now.
2024-11-11 19:34:21 +00: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
Hamish Knight
df7cac3114 Merge pull request #59141 from hamishknight/wrapping-paper
[AST] Remove ParenType
2024-11-01 16:52:23 +00:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Pavel Yaskevich
e68e4ea1b1 [CSFix] Add a new kind of invalid ref in key path - unsupported static members
Replaces feature flag check with module compiler version check
which implements the behavior discussed in the SE-0438.
2024-10-30 10:53:42 -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
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
b44bff26b5 Sema: Fold Constraint::createFixedChoice() into Constraint::createBindOverload() 2024-10-22 20:14:42 -04:00
Slava Pestov
2eaec5a97f Sema: Remove Constraint::clone() 2024-10-22 20:14:42 -04:00
Slava Pestov
0de8428f34 Sema: Tail-allocate Constraint::Overload::Choice
OverloadChoice is rather large, 40 bytes.
2024-10-22 20:14:42 -04:00
Slava Pestov
a48591d71d Sema: Tail-allocate Constraint::TheFix
Most constraints don't have a fix, so we can tail-allocate the fix.
This saves 16 bytes per constraint, because it also eliminates some
padding.
2024-10-22 20:14:42 -04:00