Commit Graph

7754 Commits

Author SHA1 Message Date
Hamish Knight
cb0a21da2a Merge pull request #83170 from hamishknight/fix-assert
[IDE] Fix assertion failure in `PostfixCompletionCallback::Result::tryMerge`
2025-07-21 18:48:03 +01:00
Hamish Knight
347d94bda5 [test] Add some alias crash signatures
The signatures here are bogus, put the correct signatures in as
aliases.
2025-07-20 18:46:18 +01:00
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
b70f8a82b1 Sema: Improve the infinite opaque return type check
Now look through other opaque return types that appear in the
underlying type. This catches various forms of recursion that
otherwise would cause a SILGen or SILOptimizer crash.

- Fixes rdar://82992151.
2025-07-18 20:03:03 -04:00
Slava Pestov
7b0ad4a6c8 Sema: Add a type checker test that is now fast
release/6.2 chokes on this file. Nice work @xedin :)
2025-07-18 19:12:33 -04:00
Hamish Knight
62f1303bca [IDE] Fix assertion failure in PostfixCompletionCallback::Result::tryMerge
Unfortunately due to pre-checking multiple times the recorded
application level can change. Just OR the bits together.
2025-07-18 11:00:37 +01:00
Evan Wilde
22f32e0e87 Merge pull request #83106 from etcwilde/ewilde/freebsd-test-updates
FreeBSD: Fix issues in tests
2025-07-17 08:25:38 -07:00
Hamish Knight
213ad8aa8c Merge pull request #83096 from hamishknight/ret
[Sema] Set ReturnStmt result even if type-checking fails
2025-07-17 02:58:26 +01:00
Evan Wilde
79f7b638eb FreeBSD: Testing: pthread handling
Fixing pthread usage in tsan and tsan-inout tests. pthreads are imported
as opaque pointers on FreeBDS, and thus need to be kept in an optional
pthread_t, like on Apple platforms.

Unlike on macOS, pthread_join is not annotated with nullability
annotations and thus takes an optional opaque pointer, so we don't need
to unwrap it.
2025-07-16 11:16:41 -07:00
Evan Wilde
3316e82af3 FreeBSD: Disable SIMDParameterPassing
The SIMD module is not available on FreeBSD, disabling it.
2025-07-16 11:01:13 -07:00
Hamish Knight
72db18073c [Sema] Set ReturnStmt result even if type-checking fails
Make sure we set the updated expression since e.g pre-checking may
have folded a top-level SequenceExpr that we need to remove from the
AST.
2025-07-16 14:40:57 +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
af96c9860c [Sema] Avoid folding sequences multiple times for completion
Completion can end up calling into pre-checking multiple times in
certain cases, make sure we don't attempt to fold a SequenceExpr
multiple times since its original AST is in a broken state
post-folding. Instead, just return the already-folded expression.

rdar://133717866
2025-07-14 17:30:02 +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
b1a7efbfe3 [test] Remove duplicate test case
This is effectively the same as `eb61865acc77c50.swift`.
2025-07-11 17:25:07 +01:00
Hamish Knight
3f74263ab4 Merge pull request #82910 from hamishknight/unbounded 2025-07-10 08:42:55 +01:00
Hamish Knight
adbbb9e3cd [IDE] Fix sort predicate in printCodeCompletionLookedupTypeNames
This wasn't a strict weak ordering, and it turns out violating that
is undefined behavior which can result in buffer overruns.
2025-07-09 19:50:43 +01:00
Hamish Knight
ed3961bcd5 Merge pull request #82908 from hamishknight/test-tweaks
[test] Tweak a couple of crasher test cases
2025-07-09 19:46:53 +01:00
Hamish Knight
e631a37d0b [Completion] Avoid using unbound contextual type in argument completion
Match the logic in `getTypeForCompletion` and avoid using an unbound
generic type as the expected type for a completion.

rdar://155420395
2025-07-09 12:57:36 +01:00
nate-chandler
270336e706 Merge pull request #82902 from nate-chandler/rdar155059418
[ODL] Visit objc_method insts.
2025-07-09 04:56:30 -07: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
Nate Chandler
fc4a49334f [ODL] Visit objc_method insts.
No update is needed for the values they produce.  This pass should
really be refactored not to crash on instructions that aren't explicitly
listed or at least not to compile if not every instruction is listed.

rdar://155059418
2025-07-08 17:19:56 -07:00
Pavel Yaskevich
57ef411ce9 Merge pull request #82869 from xedin/logic-infix-operators-perf
[CSOptimizer] Prefer logical infix operator if it has smaller overload set
2025-07-08 16:49:45 -07:00
Ben Barham
044e97b416 Merge pull request #82663 from bnbarham/generate-doc-index
[userdocs] Automatically generate doc indices
2025-07-08 13:42:52 -07: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
Pavel Yaskevich
1f8e487e2e [CSOptimizer] Prefer logical infix operator if it has smaller overload set
Infix logical operators are usually not overloaded and don't
form disjunctions, but when they do, let's prefer them over
other operators when they have fewer choices because it helps
to split operator chains.
2025-07-08 00:10:47 -07:00
Hamish Knight
8b3cb86d7f Merge pull request #82802 from hamishknight/context-fail
[Completion] Map failable initializer result type into context
2025-07-08 06:20:17 +01:00
Ben Barham
5ee91339c3 [userdocs] Automatically generate doc indices
Add a tool for automatically generating the doc indices for notes,
groups, and features.
2025-07-07 13:59:09 -07: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
3a8bf75951 Merge pull request #82761 from hamishknight/req-assert
[test] Require asserts for IDE crashers
2025-07-04 14:10:10 +01:00
Hamish Knight
e7bf62dd81 [Completion] Map failable initializer result type into context
Make sure we don't pass an interface type to `setTypeContext`.

rdar://155038769
2025-07-04 13:55:40 +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
4aee90318a [test] Require asserts for IDE crashers 2025-07-03 10:53:27 +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
beb2b58d62 [test] Mark a couple of IDE crashers as fixed (#82685)
Seems like these may have been fixed by #82574, unfortunately there was
a race with #82619
2025-07-01 11:00:29 -07: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
QuietMisdreavus
1948907eb3 use RespectOriginallyDefinedIn when mangling extension contexts (#82348)
Resolves rdar://152598492

Consider the following Swift, adapted from a real-world framework:

```swift
@available(macOS 10.8, *)
@_originallyDefinedIn(module: "another", macOS 11.0)
public struct SimpleStruct {}

@available(macOS 12.0, iOS 13.0, *)
public extension SimpleStruct {
    struct InnerStruct {}
}
```

In this scenario, `SimpleStruct` was originally in a module called
`another`, but was migrated to this module around the time of macOS
11.0. Since then, the module was ported to iOS and gained a nested type
`SimpleStruct.InnerStruct`. When mangling USRs for this nested type, the
result differs depending on whether we're targeting macOS or iOS.
They're mostly the same, but the macOS build yields a USR with an `AAE`
infix, designating that the `InnerStruct` was defined in an extension
from a module with the name of the base module. On iOS, this infix does
not exist.

The reason this is happening is because of the implementation of
`getAlternateModuleName` checking the availability spec in the
`@_originallyDefinedIn` attribute against the currently active target.
If the target matches the spec, then the alternate module name is
reported, otherwise the real module name is. Since the iOS build reports
the real module name, the mangling code doesn't bother including the
extension-context infix, instead just opting to include the parent
type's name and moving on.

This PR routes around this issue by passing the
`RespectOriginallyDefinedIn` variable to the
`ExtensionDecl::isInSameDefiningModule` method, and using that to skip
the alternate module name entirely. It also sets
`RespectOriginallyDefinedIn` to `false` in more places when mangling
USRs, but i'm not 100% confident that it was all necessary. The goal was
to make USRs more consistent across platforms, regardless of the
surrounding context.
2025-06-30 12:57:12 -06: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
eee40b4ecc [CSGen] Make collection subscript result type inference more principled
Infer result type of a subscript with Array or Dictionary base type
if argument type matches the key type exactly or it's a supported
literal type.

This helps to maintain the existing behavior without having to resort
to "favored type" computation.
2025-06-27 23:43:12 -07:00