Skip to content

Commit 108fd05

Browse files
committed
flesh out more of Swiftskell test
1 parent 0ab9d2f commit 108fd05

File tree

3 files changed

+93
-50
lines changed

3 files changed

+93
-50
lines changed

test/Inputs/Swiftskell.swift

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public extension Eq where Self: ~Copyable {
2626
}
2727

2828
/// MARK: Result
29-
public enum Either<Success, Failure: Error> {
29+
public enum Either<Success: ~Copyable, Failure: Error> {
3030
case success(Success)
3131
case failure(Failure)
3232
}
@@ -45,58 +45,84 @@ extension Either where Failure == Swift.Error {
4545

4646
public protocol Generator: ~Copyable {
4747
associatedtype Element: ~Copyable
48-
func next() -> Element
48+
func next() -> Maybe<Element>
4949
}
5050

51-
51+
/// MARK: Lists
5252
public struct Vector<T: ~Copyable> {
5353

5454
subscript(_ i: UInt) -> T {
5555
fatalError("todo")
5656
}
5757
}
5858

59+
// MARK: Tuples
60+
public enum Pair<L: ~Copyable, R: ~Copyable>: ~Copyable {
61+
case elms(L, R)
62+
}
63+
5964

6065
/// MARK: Data.Maybe
6166

62-
public enum Maybe<Value: ~Copyable> {
67+
public enum Maybe<Value: ~Copyable>: ~Copyable {
6368
case just(Value)
6469
case nothing
6570
}
6671

67-
extension Maybe: Show where Value: ~Copyable {
72+
extension Maybe: Copyable {}
73+
74+
extension Maybe: Show where Value: Show & ~Copyable {
6875
public borrowing func show() -> String {
69-
fatalError("need borrowing switches")
76+
switch self {
77+
case let .just(_borrowing elm):
78+
return elm.show()
79+
case .nothing:
80+
return "<nothing>"
81+
}
7082
}
7183
}
7284

7385
extension Maybe: Eq where Value: Eq, Value: ~Copyable {
7486
public static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
75-
fatalError("need borrowing switches")
76-
}
77-
}
78-
79-
public func maybe<A: ~Copyable, B>(_ defaultVal: B,
80-
_ fn: (consuming A) -> B)
81-
-> (consuming Maybe<A>) -> B {
82-
return { (_ mayb: consuming Maybe<A>) -> B in
83-
switch consume mayb {
84-
case .just(_):
85-
fatalError("waiting for bugfix here")
86-
// return fn(val)
87+
switch a {
88+
case let .just(_borrowing a1):
89+
switch b {
90+
case let .just(_borrowing b1):
91+
return a1 == b1
92+
case .nothing:
93+
return false
94+
}
8795
case .nothing:
88-
return defaultVal
96+
switch b {
97+
case .just:
98+
return false
99+
case .nothing:
100+
return true
101+
}
89102
}
90103
}
91104
}
92105

93-
@inlinable
94-
public func fromMaybe<A>(_ defaultVal: A) -> (Maybe<A>) -> A {
95-
return maybe(defaultVal, {$0})
96-
}
106+
107+
// FIXME: triggers crash!
108+
// @inlinable
109+
// public func fromMaybe<A: ~Copyable>(_ defaultVal: consuming A,
110+
// _ mayb: consuming Maybe<A>) -> A {
111+
// switch mayb {
112+
// case let .just(payload):
113+
// return payload
114+
// case .nothing:
115+
// return defaultVal
116+
// }
117+
// }
97118

98119
public func isJust<A: ~Copyable>(_ m: borrowing Maybe<A>) -> Bool {
99-
fatalError("need borrowing switches")
120+
switch m {
121+
case .just:
122+
return true
123+
case .nothing:
124+
return false
125+
}
100126
}
101127

102128
@inlinable
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift \
4+
// RUN: -emit-module-path %t \
5+
// RUN: -enable-library-evolution \
6+
// RUN: -module-name Swiftskell \
7+
// RUN: -parse-as-library \
8+
// RUN: %S/../Inputs/Swiftskell.swift -c -o %t/Swiftskell.o \
9+
// RUN: -enable-experimental-feature NoncopyableGenerics \
10+
// RUN: -enable-experimental-feature NonescapableTypes \
11+
// RUN: -enable-experimental-feature BorrowingSwitch
12+
13+
// RUN: %target-build-swift -o %t/a.out %s -I %t %t/Swiftskell.o
14+
// RUN: %target-codesign %t/a.out
15+
// RUN: %target-run %t/a.out | %FileCheck %s
16+
17+
// REQUIRES: executable_test
18+
19+
// XFAIL: *
20+
/* FIXME: there's a cycle getting triggered somehow (rdar://124117857)
21+
<unknown>:0: error: circular reference
22+
<unknown>:0: note: through reference here
23+
<unknown>:0: error: merge-module command failed with exit code 1 (use -v to see invocation)
24+
*/
25+
26+
import Swiftskell
27+
28+
print("hello, world")
29+
// CHECK: hello, world

test/ModuleInterface/noncopyable_generics.swift

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
1111
// RUN: -enable-experimental-feature NoncopyableGenerics \
1212
// RUN: -enable-experimental-feature NonescapableTypes \
13+
// RUN: -enable-experimental-feature BorrowingSwitch \
1314
// RUN: -o %t/Swiftskell.swiftmodule \
1415
// RUN: -emit-module-interface-path %t/Swiftskell.swiftinterface \
1516
// RUN: %S/../Inputs/Swiftskell.swift
@@ -150,42 +151,29 @@ import NoncopyableGenerics_Misc
150151

151152
import Swiftskell
152153

153-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
154-
// CHECK-NEXT: public protocol Show : ~Copyable {
154+
// CHECK-DAG: public protocol Show : ~Copyable {
155155

156-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
157-
// CHECK-NEXT: public func print(_ s: borrowing some Show & ~Copyable)
156+
// CHECK-DAG: public func print(_ s: borrowing some Show & ~Copyable)
158157

159-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
160-
// CHECK-NEXT: public protocol Eq : ~Copyable {
158+
// CHECK-DAG: public protocol Eq : ~Copyable {
161159

162-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
163-
// CHECK-NEXT: extension Swiftskell.Eq where Self : ~Copyable {
160+
// CHECK-DAG: extension Swiftskell.Eq where Self : ~Copyable {
164161

165-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
166-
// CHECK-NEXT: public protocol Generator : ~Copyable {
167-
// CHECK-NEXT: associatedtype Element : ~Copyable
168-
169-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
170-
// CHECK-NEXT: public struct Vector<T> where T : ~Copyable {
162+
// CHECK-DAG: public enum Either<Success, Failure> where Failure : Swift.Error, Success : ~Copyable {
171163

172-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
173-
// CHECK-NEXT: public enum Maybe<Value> where Value : ~Copyable {
164+
/// This one is position dependent so we can ensure the associated type was printed correctly.
165+
// CHECK: public protocol Generator : ~Copyable {
166+
// CHECK-NEXT: associatedtype Element : ~Copyable
174167

175-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
176-
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Show where Value : ~Copyable {
168+
// CHECK-DAG: public struct Vector<T> where T : ~Copyable {
177169

178-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
179-
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Eq where Value : Swiftskell.Eq, Value : ~Copyable {
170+
// CHECK-DAG: public enum Maybe<Value> : ~Copyable where Value : ~Copyable {
180171

181-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
182-
// CHECK-NEXT: public func maybe<A, B>(_ defaultVal: B, _ fn: (consuming A) -> B) -> (consuming Swiftskell.Maybe<A>) -> B where A : ~Copyable
172+
// CHECK-DAG: extension Swiftskell.Maybe : Swiftskell.Show where Value : Swiftskell.Show, Value : ~Copyable {
183173

184-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
185-
// CHECK-NEXT: @inlinable public func fromMaybe<A>(_ defaultVal: A) -> (Swiftskell.Maybe<A>) -> A {
174+
// CHECK-DAG: extension Swiftskell.Maybe : Swiftskell.Eq where Value : Swiftskell.Eq, Value : ~Copyable {
186175

187-
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
188-
// CHECK-NEXT: public func isJust<A>(_ m: borrowing Swiftskell.Maybe<A>) -> Swift.Bool where A : ~Copyable
176+
// CHECK-DAG: public func isJust<A>(_ m: borrowing Swiftskell.Maybe<A>) -> Swift.Bool where A : ~Copyable
189177

190178

191179
struct FileDescriptor: ~Copyable, Eq, Show {

0 commit comments

Comments
 (0)