Commit Graph

198 Commits

Author SHA1 Message Date
Hamish Knight
a2d707be2a [test] Remove duplicate test case
This is essentially the same as `8668a3eb11f2baf.swift`.
2025-07-20 18:32:45 +01:00
Hamish Knight
7e22f9264b [test] Update some crasher signatures
The signatures have changed here either due to code changes in the
repo or due to improvements to the signature detection, update the
test cases.
2025-07-20 18:32:38 +01:00
Slava Pestov
ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Hamish Knight
818979fed8 Merge pull request #83034 from hamishknight/origami
[Sema] Avoid folding sequences multiple times
2025-07-15 09:14:55 +01:00
Hamish Knight
95a96f5593 Merge pull request #83026 from hamishknight/fuzzy 2025-07-15 03:54:25 +01:00
Hamish Knight
7508cb7d3b [test] Add some more known crashers 2025-07-14 19:56:51 +01:00
Hamish Knight
95f1b07e87 [Sema] Remove completion assert in foldSequence for now
Turns out we can also hit this case for some pattern type-checking
cases. I'll fix those in a follow-up and reinstate the assertion.
2025-07-14 18:50:42 +01:00
Hamish Knight
3244bffe71 [CS] Handle TVO_CanBindToPack in mergeEquivalenceClasses
Previously we could incorrectly propagate `TVO_CanBindToPack` to a
type variable that cannot bound to a pack type.
2025-07-14 12:44:23 +01:00
Hamish Knight
3ab8fb7053 [test] Tweak a couple of crasher test cases
- Make `539adae64314fae.swift` macOS-only and use guard malloc for it.
- Tweak `1e4b431ffe374ef1.swift` such that it succeeds if it either
times out after a minute or crashes. While here, also clean up the
test case a little.
2025-07-09 12:14:02 +01:00
Hamish Knight
5cbdcaf655 Merge pull request #82834 from hamishknight/fuzzy
[test] Add some more known crashers
2025-07-08 08:32:52 +01:00
Slava Pestov
4dc0db31f9 Sema: Improve the 'protocol method can't impose new requirements on Self' check
This check had two problems. First, it would assert upon encountering
a layout requirement, due to an unimplemented code path.

A more fundamental issue is that the logic wasn't fully sound, because
it would miss certain cases, for example:

    protocol P {
      associatedtype A

      func run<B: Equatable>(_: B) where B == Self.A
    }

Here, the reduced type of `Self.A` is `B`, and at first glance, the
requirement `B: Equatable` appears to be fine. However, this
is actually a new requirement on `Self`, and the protocol be rejected.

Now that we can change the reduction order by assigning weights to
generic parameters, this check can be implemented in a better way,
by building a new generic signature first, where all generic
parameters introduced by the protocol method, like 'B' above, are
assigned a non-zero weight.

With this reduction order, any type that is equivalent to
a member type of `Self` will have a reduced type rooted in `Self`,
at which point the previous syntactic check becomes sound.

Since this may cause us to reject code we accepted previously,
the type checker now performs the check once: first on the original
signature, which may miss certain cases, and then again on the new
signature built with the weighted reduction order.

If the first check fails, we diagnose an error. If the second
check fails, we only diagnose a warning.

However, this warning will become an error soon, and it really
can cause compiler crashes and miscompiles to have a malformed
protocol like this.

Fixes rdar://116938972.
2025-07-07 12:23:58 -04:00
Hamish Knight
5730eb2e10 [test] Add some more known crashers 2025-07-07 11:12:36 +01:00
Hamish Knight
d6037049b1 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 16:24:31 +01:00
Hamish Knight
3daae5955e [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 14:46:55 +01:00
Hamish Knight
dc880588ff Merge pull request #82619 from hamishknight/fuzzy
[test] Add some more known crashers
2025-07-01 13:24:42 +01:00
Pavel Yaskevich
bec4ebd126 Merge pull request #82574 from xedin/solver-perf-behind-a-flag
[ConstraintSystem] Implement disjunction favoring algorithm behind a flag
2025-06-30 16:27:01 -07:00
Pavel Yaskevich
d3f86b4efd Merge pull request #82593 from xedin/rdar-148076903
[Concurrency] Fix a crash caused by misuse of `isolated` modifier
2025-06-30 13:06:17 -07:00
Hamish Knight
b9afc87c28 [test] Add some more known crashers 2025-06-30 20:52:06 +01:00
Hamish Knight
e912eeb2f4 [CS] Use the resolved type in NonOptionalUnwrapFailure::diagnoseAsError
Diagnostics can outlive the ConstraintSystem itself if we have a
diagnostic transaction for e.g `typeCheckParameterDefault`, make sure
we don't try to use a solver-allocated type as an argument.
2025-06-28 12:13:19 +01:00
Hamish Knight
2b05212ff5 [CS] Avoid escaping solver-allocated types in computeSubstitutions
Make sure we call `simplifyType` for the opened type bindings to
ensure holes get converted to UnresolvedType.

rdar://154553285
2025-06-28 11:19:13 +01:00
Pavel Yaskevich
358067917e [Concurrency] Fix a crash caused by misuse of isolated modifier
Adjust isolation checking to handle misused `isolated` attribute
and let attribute checker property diagnose it.

Resolves: rdar://148076903
Resolves: https://github.com/swiftlang/swift/issues/80363
2025-06-27 23:45:53 -07:00
Pavel Yaskevich
2957da3591 [ConstraintSystem] Disable performance hacks by default
This also changes the flag to `-enable-constraint-solver-performance-hacks`.
2025-06-27 23:43:09 -07:00
Hamish Knight
aec446521a [test] Add some more known type-checker crashers 2025-06-23 10:05:22 +01:00
Hamish Knight
19af3bc295 Merge pull request #82332 from hamishknight/fuzzy
[test] Add some more known type-checker crashers
2025-06-20 18:35:14 +01:00
Hamish Knight
3c8a8a860a Merge pull request #82292 from hamishknight/bigger-hammer
[AST] Replace type variables and placeholders in original ErrorTypes
2025-06-20 10:59:24 +01:00
Hamish Knight
c3fc76fb7a [test] Add a few more known type-checker crashers 2025-06-19 14:47:52 +01:00
Hamish Knight
61aa5a0b07 [test] Add some more known type-checker crashers 2025-06-19 14:42:54 +01:00
Hamish Knight
f62cb8f91a [test] Use guard malloc in 4c84d3d852cdd1d4.swift
This should hopefully make it crash reliably.
2025-06-19 14:42:54 +01:00
Hamish Knight
5276f2e1ef Merge pull request #82334 from hamishknight/record-opened 2025-06-19 08:18:49 +01:00
Hamish Knight
9b21efdf7d Merge pull request #82316 from hamishknight/keyed 2025-06-19 08:18:29 +01:00
Slava Pestov
5987bbf966 Merge pull request #82321 from slavapestov/rqm-fixes
RequirementMachine: Add more limits to catch runaway computation, and fix a bug
2025-06-18 23:00:38 -04:00
Hamish Knight
c6ec3156f7 [CS] Distinguish locators for generic args in addSpecializationConstraint
Make sure we give each argument a different locator to ensure we
can correctly record any opened types.

rdar://153674889
2025-06-18 12:19:12 +01:00
Hamish Knight
3d9e49038b Merge pull request #82295 from hamishknight/wrapping-paper 2025-06-18 08:50:57 +01:00
Hamish Knight
b37e34ea8d [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:46 +01:00
Slava Pestov
bf3f4a6d79 AST: Fix lost GenericSignatureErrors in getPlaceholderRequirementSignature() 2025-06-17 17:51:25 -04:00
Hamish Knight
89a7014db9 [Sema] Add null check in createMemberwiseInitParameter
The property wrapper initializer info may be null if e.g we had a
request cycle, just use the property's interface type in that case.

rdar://82899428
2025-06-17 15:16:44 +01:00
Slava Pestov
cfa9de8f0a Parse: Address an llvm_unreachable that is actually reachable 2025-06-17 10:15:30 -04:00
Slava Pestov
b79f2817f9 Sema: Fix MissingCallFailure::diagnoseAsError() crash with special base names 2025-06-17 09:52:04 -04:00
Slava Pestov
0d6470345b Sema: Fix crash on invalid code in isOverrideBasedOnType() 2025-06-17 09:52:04 -04:00
Slava Pestov
ef5e2861a2 Sema: Fix crash on invalid code in diagnoseDictionaryLiteralDuplicateKeyEntries() 2025-06-17 09:52:03 -04:00
Slava Pestov
8b12f8cb8e Sema: Fix null pointer dereference in LazyStoragePropertyRequest::evaluate() 2025-06-17 09:52:03 -04:00
Slava Pestov
eec924b505 Sema: Fix crash in diagnoseIfSynthesisUnsupportedForDecl() with tuple extension 2025-06-17 09:52:03 -04:00
Slava Pestov
9a01e872da Sema: Address FIXME resulting in a crash in filterProtocolRequirements() 2025-06-17 09:52:03 -04:00
Slava Pestov
4fa2e979fa RequirementMachine: Don't crash if we cannot desugar a same-shape requirement 2025-06-17 09:52:02 -04:00
Slava Pestov
908c9368ed Parse: Only accept certain literals as enum case raw values
Just checking for LiteralExpr is too broad, because Sema doesn't
know what to do with RegexLiteralExpr for example.
2025-06-17 09:19:00 -04:00
Hamish Knight
6257828593 [AST] Replace type variables and placeholders in original ErrorTypes
Turns out we can also get solver-allocated original ErrorTypes through
type resolution. Given the original type is only used for
printing/debugging, let's just fold away any type variables and
placeholders into UnresolvedType (which print as placeholders). This
matches what `Solution::simplifyType` does.
2025-06-17 12:09:25 +01:00
Hamish Knight
05ae4c4729 [test] Add a few more known type-checker crashers 2025-06-16 21:02:30 +01:00
Hamish Knight
6570da30e0 [test] Clean up some crasher test cases 2025-06-16 11:19:53 +01:00
Hamish Knight
6d0da8d5cc [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-12 12:11:19 +01:00
Hamish Knight
580f20efec Merge pull request #82150 from hamishknight/fixed-test
[test] Mark `8c2d6198e18a56a.swift` as fixed
2025-06-11 11:13:09 +01:00