Skip to content

NFC: Expand -experimental-lazy-typecheck test coverage #68251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion test/Inputs/lazy_typecheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func internalFunc() -> DoesNotExist { // expected-error {{cannot find type 'Does
}

@inlinable func inlinableFunc() -> Int {
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
return 1
}

private func privateFunc() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
Expand Down Expand Up @@ -61,13 +61,25 @@ protocol InternalProto {
public struct PublicStruct {
// FIXME: Test properties

public init(x: Int) {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}

public func publicMethod() -> Int {
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
}

public static func publicStaticMethod() {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}

func internalMethod() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
return 1
}

static func internalStaticMethod() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
return 1
}
}

struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
Expand All @@ -76,6 +88,32 @@ struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'Does
func f(_ x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
}

public class PublicClass {
// FIXME: Test properties

public init(x: Int) {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}

// FIXME: TBDGen causes this constructor to be type checked
// init(_ x: DoesNotExist) {}

public func publicMethod() -> Int {
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
}

public class func publicClassMethod() {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}

// FIXME: TBDGen causes these methods to be type checked
// func internalMethod() -> DoesNotExist {}
// class func internalClassMethod() -> DoesNotExist {}
}

class InternalClass: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
init(x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
}
// FIXME: Test enums
// FIXME: Test conformances
// FIXME: Test global vars
33 changes: 33 additions & 0 deletions test/Inputs/lazy_typecheck_client.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This source file contains an example client of all the public declarations
// exposed by the library implemented in lazy_typecheck.swift.

import lazy_typecheck

struct ConformsToPublicProto: PublicProto {
func req() -> Int { return 1 }
}

func testGlobalFunctions() {
_ = publicFunc()
_ = publicFuncWithDefaultArg()
#if TEST_PACKAGE
_ = packageFunc()
#endif
constrainedGenericPublicFunction(ConformsToPublicProto())
if #available(SwiftStdlib 5.1, *) {
_ = publicFuncWithOpaqueReturnType()
_ = publicAEICFuncWithOpaqueReturnType()
}
}

func testPublicStruct() {
var s = PublicStruct(x: 1)
_ = s.publicMethod()
PublicStruct.publicStaticMethod()
}

func testPublicClass() {
let c = PublicClass(x: 2)
_ = c.publicMethod()
PublicClass.publicClassMethod()
}
16 changes: 14 additions & 2 deletions test/ModuleInterface/lazy-typecheck.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -emit-module -emit-module-path /dev/null -emit-module-interface-path %t/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
// RUN: %FileCheck %s < %t/lazy_typecheck.swiftinterface

// RUN: rm -rf %t/*.swiftmodule
// RUN: %target-swift-frontend -package-name Package -typecheck %S/../Inputs/lazy_typecheck_client.swift -I %t

// CHECK: import Swift

// CHECK: public func publicFunc() -> Swift.Int
// CHECK: publicFuncWithDefaultArg(_ x: Swift.Int = 1) -> Swift.Int
// CHECK: @inlinable internal func inlinableFunc() -> Swift.Int {
// CHECK-NEXT: return true // expected-error {{[{][{]}}cannot convert return expression of type 'Bool' to return type 'Int'{{[}][}]}}
// CHECK-NEXT: return 1
// CHECK-NEXT: }
// CHECK: public func constrainedGenericPublicFunction<T>(_ t: T) where T : lazy_typecheck.PublicProto
// CHECK: @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
Expand All @@ -28,5 +31,14 @@
// CHECK: }

// CHECK: public struct PublicStruct {
// CHECK: public init(x: Swift.Int)
// CHECK: public func publicMethod() -> Swift.Int
// CHECK: public static func publicStaticMethod()
// CHECK: }

// CHECK: public class PublicClass {
// CHECK: public init(x: Swift.Int)
// CHECK: public func publicMethod() -> Swift.Int
// CHECK: public class func publicClassMethod()
// CHECK: deinit
// CHECK: }
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -enable-library-evolution -parse-as-library -package-name Package -typecheck -verify
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -emit-module -emit-module-path %t/lazy_typecheck.swiftmodule -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
// RUN: %target-swift-frontend -package-name Package -typecheck %s -I %t

import lazy_typecheck

struct ConformsToPublicProto: PublicProto {
func req() -> Int { return 1 }
}

func testGlobalFunctions() {
_ = publicFunc()
_ = publicFuncWithDefaultArg()
_ = packageFunc()
constrainedGenericPublicFunction(ConformsToPublicProto())
if #available(SwiftStdlib 5.1, *) {
_ = publicFuncWithOpaqueReturnType()
_ = publicAEICFuncWithOpaqueReturnType()
}
}

func testPublicStruct(_ s: PublicStruct) {
_ = s.publicMethod()
}
// RUN: %target-swift-frontend -package-name Package -typecheck %S/../Inputs/lazy_typecheck_client.swift -D TEST_PACKAGE -I %t
28 changes: 19 additions & 9 deletions test/TBD/lazy-typecheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ compatibility-version: 0
swift-abi-version: 7
exports:
- targets: [ arm64-macos ]
symbols: [ '_$s14lazy_typecheck10publicFuncSiyF', '_$s14lazy_typecheck11PublicProtoMp',
'_$s14lazy_typecheck11PublicProtoP3reqSiyFTj', '_$s14lazy_typecheck11PublicProtoP3reqSiyFTq',
'_$s14lazy_typecheck11PublicProtoTL', '_$s14lazy_typecheck11packageFuncSiyF',
'_$s14lazy_typecheck12PublicStructV12publicMethodSiyF', '_$s14lazy_typecheck12PublicStructVMa',
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF' ]
symbols: [ '_$s14lazy_typecheck10publicFuncSiyF', '_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTj',
'_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTq',
'_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTj', '_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTq',
'_$s14lazy_typecheck11PublicClassC1xACSi_tcfC', '_$s14lazy_typecheck11PublicClassC1xACSi_tcfCTj',
'_$s14lazy_typecheck11PublicClassC1xACSi_tcfCTq', '_$s14lazy_typecheck11PublicClassC1xACSi_tcfc',
'_$s14lazy_typecheck11PublicClassCMa', '_$s14lazy_typecheck11PublicClassCMm',
'_$s14lazy_typecheck11PublicClassCMn', '_$s14lazy_typecheck11PublicClassCMo',
'_$s14lazy_typecheck11PublicClassCMu', '_$s14lazy_typecheck11PublicClassCN',
'_$s14lazy_typecheck11PublicClassCfD', '_$s14lazy_typecheck11PublicClassCfd',
'_$s14lazy_typecheck11PublicProtoMp', '_$s14lazy_typecheck11PublicProtoP3reqSiyFTj',
'_$s14lazy_typecheck11PublicProtoP3reqSiyFTq', '_$s14lazy_typecheck11PublicProtoTL',
'_$s14lazy_typecheck11packageFuncSiyF', '_$s14lazy_typecheck12PublicStructV12publicMethodSiyF',
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructVMa',
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF' ]
...