Introduce type sugar for InlineArray (#80087)

* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
This commit is contained in:
Hamish Knight
2025-03-23 22:31:37 +00:00
committed by GitHub
parent 564191e07c
commit f8ab391737
55 changed files with 856 additions and 75 deletions

View File

@@ -2,18 +2,22 @@
// RUN: %target-swift-frontend-dump-parse -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature NamedOpaqueTypes \
// RUN: -enable-experimental-feature InlineArrayTypeSugar \
// RUN: | %sanitize-address > %t/astgen.ast
// RUN: %target-swift-frontend-dump-parse \
// RUN: -enable-experimental-feature NamedOpaqueTypes \
// RUN: -enable-experimental-feature InlineArrayTypeSugar \
// RUN: | %sanitize-address > %t/cpp-parser.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature NamedOpaqueTypes
// RUN: -enable-experimental-feature NamedOpaqueTypes \
// RUN: -enable-experimental-feature InlineArrayTypeSugar
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_NamedOpaqueTypes
// REQUIRES: swift_feature_InlineArrayTypeSugar
// rdar://116686158
// UNSUPPORTED: asan
@@ -78,4 +82,12 @@ typealias TestSpecifierAndAttr<T> = (__owned @Sendable @escaping () async -> T)
let globalOptionalInt: _? = 42
let optionalIntArray: Array<_> = [42]
@available(SwiftStdlib 9999, *)
func testInlineArray() {
let _: [3 x Int] = [1, 2, 3]
let _: [_ x _] = [1, 2]
let _ = [3 x Int](repeating: 0)
let _ = [3 x _](repeating: 0)
}
func testNamedOpaqueReturnTy() -> <T> T { return () }