Skip to content

Commit 944f84d

Browse files
committed
[NCGenerics] add tests for modules/interface files
1 parent fe328bf commit 944f84d

File tree

3 files changed

+167
-19
lines changed

3 files changed

+167
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
2-
3-
// A Swift × Haskell stdlib flavour.
4-
5-
public struct Vector<T: ~Copyable> {
6-
7-
subscript(_ i: UInt) -> T {
8-
fatalError("todo")
9-
}
10-
}
11-
12-
13-
14-
15-
// These are purely to add test coverage of different constructs
16-
public struct Toys {
1+
// These are purely to add test coverage of different constructs when emitting modules
2+
public struct _Toys {
173
static func test_parallelAssignment() {
184
var y: Int
195
var x: Int
@@ -32,4 +18,5 @@ public struct Toys {
3218
}
3319
}
3420

21+
public static func pickOne<T>(_ a: T, _ b: T) -> T { return a }
3522
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// --------------------------------
2+
// A Swift × Haskell stdlib flavour
3+
// --------------------------------
4+
5+
/// MARK: GHC.Show
6+
7+
public protocol Show: ~Copyable {
8+
borrowing func show() -> String
9+
}
10+
11+
public func print(_ s: borrowing some Show & ~Copyable) {
12+
print(s.show())
13+
}
14+
15+
/// MARK: Data.Eq
16+
17+
public protocol Eq: ~Copyable {
18+
static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool
19+
static func /=(_ a: borrowing Self, _ b: borrowing Self) -> Bool
20+
}
21+
22+
public extension Eq {
23+
static func /=(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
24+
return !(a == b)
25+
}
26+
}
27+
28+
public extension Eq where Self: Equatable {
29+
static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
30+
return a == b
31+
}
32+
}
33+
34+
35+
public struct Vector<T: ~Copyable> {
36+
37+
subscript(_ i: UInt) -> T {
38+
fatalError("todo")
39+
}
40+
}
41+
42+
43+
/// MARK: Data.Maybe
44+
45+
public enum Maybe<Value: ~Copyable> {
46+
case just(Value)
47+
case nothing
48+
}
49+
50+
extension Maybe: Show {
51+
public borrowing func show() -> String {
52+
fatalError("need borrowing switches")
53+
}
54+
}
55+
56+
extension Maybe: Eq where Value: Eq {
57+
public static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
58+
fatalError("need borrowing switches")
59+
}
60+
}
61+
62+
public func maybe<A: ~Copyable, B>(_ defaultVal: B,
63+
_ fn: (consuming A) -> B)
64+
-> (consuming Maybe<A>) -> B {
65+
return { (_ mayb: consuming Maybe<A>) -> B in
66+
switch consume mayb {
67+
case .just(_):
68+
fatalError("waiting for bugfix here")
69+
// return fn(val)
70+
case .nothing:
71+
return defaultVal
72+
}
73+
}
74+
}
75+
76+
@inlinable
77+
public func fromMaybe<A>(_ defaultVal: A) -> (Maybe<A>) -> A {
78+
return maybe(defaultVal, {$0})
79+
}
80+
81+
public func isJust<A: ~Copyable>(_ m: borrowing Maybe<A>) -> Bool {
82+
fatalError("need borrowing switches")
83+
}
84+
85+
@inlinable
86+
public func isNothing<A: ~Copyable>(_ m: borrowing Maybe<A>) -> Bool {
87+
return !isJust(m)
88+
}
Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -enable-library-evolution -emit-module -o %t/NoncopyableGenerics.swiftmodule -emit-module-interface-path %t/NoncopyableGenerics.swiftinterface -enable-experimental-feature NoncopyableGenerics %S/Inputs/NoncopyableGenerics.swift
4-
// RUN: %target-swift-frontend -emit-sil -sil-verify-all -I %t %s > /dev/null
3+
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
4+
// RUN: -enable-experimental-feature NoncopyableGenerics \
5+
// RUN: -o %t/NoncopyableGenerics_Misc.swiftmodule \
6+
// RUN: -emit-module-interface-path %t/NoncopyableGenerics_Misc.swiftinterface \
7+
// RUN: %S/Inputs/NoncopyableGenerics_Misc.swift
8+
9+
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
10+
// RUN: -enable-experimental-feature NoncopyableGenerics \
11+
// RUN: -o %t/Swiftskell.swiftmodule \
12+
// RUN: -emit-module-interface-path %t/Swiftskell.swiftinterface \
13+
// RUN: %S/Inputs/Swiftskell.swift
14+
15+
// Check the interfaces
16+
17+
// RUN: %FileCheck %s --check-prefix=CHECK-MISC < %t/NoncopyableGenerics_Misc.swiftinterface
18+
// RUN: %FileCheck %s < %t/Swiftskell.swiftinterface
519

620
// REQUIRES: asserts
721

8-
import NoncopyableGenerics
22+
import NoncopyableGenerics_Misc
23+
24+
// CHECK-MISC: public struct rdar118697289_S1<Element> where Element : Swift.Copyable {
25+
// CHECK-MISC: public struct rdar118697289_S2<Element> where Element : Swift.Copyable {
26+
// CHECK-MISC: public static func pickOne<T>(_ a: T, _ b: T) -> T where T : Swift.Copyable
27+
28+
// CHECK-MISC: extension NoncopyableGenerics_Misc._Toys : Swift.Copyable {}
29+
// CHECK-MISC: extension NoncopyableGenerics_Misc._Toys.rdar118697289_S1 : Swift.Copyable {}
30+
// CHECK-MISC: extension NoncopyableGenerics_Misc._Toys.rdar118697289_S2 : Swift.Copyable {}
31+
32+
import Swiftskell
33+
34+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
35+
// CHECK-NEXT: public protocol Show {
36+
37+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
38+
// CHECK-NEXT: public func print(_ s: borrowing some Show & ~Copyable)
39+
40+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
41+
// CHECK-NEXT: public protocol Eq {
42+
43+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
44+
// CHECK-NEXT: extension Swiftskell.Eq {
45+
46+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
47+
// CHECK-NEXT: extension Swiftskell.Eq where Self : Swift.Equatable {
48+
49+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
50+
// CHECK-NEXT: public struct Vector<T> {
51+
52+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
53+
// CHECK-NEXT: public enum Maybe<Value> {
54+
55+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
56+
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Show {
57+
58+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
59+
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Eq where Value : Swiftskell.Eq {
60+
61+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
62+
// CHECK-NEXT: public func maybe<A, B>(_ defaultVal: B, _ fn: (consuming A) -> B) -> (consuming Swiftskell.Maybe<A>) -> B where B : Swift.Copyable
63+
64+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
65+
// CHECK-NEXT: @inlinable public func fromMaybe<A>(_ defaultVal: A) -> (Swiftskell.Maybe<A>) -> A where A : Swift.Copyable {
66+
67+
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
68+
// CHECK-NEXT: public func isJust<A>(_ m: borrowing Swiftskell.Maybe<A>) -> Swift.Bool
69+
70+
71+
struct FileDescriptor: ~Copyable, Eq, Show {
72+
let id: Int
73+
74+
func show() -> String {
75+
return "FileDescriptor(id:\(id))"
76+
}
77+
78+
static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
79+
return a.id == b.id
80+
}
81+
}

0 commit comments

Comments
 (0)