-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathextension.swift.gyb
108 lines (93 loc) · 5.62 KB
/
extension.swift.gyb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: %empty-directory(%t)
// RUN: %gyb %s > %t/main.swift
// Other module is not resilient:
// RUN: %empty-directory(%t/types)
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/types/ExtensionTypes.swiftmodule
// This module is both not resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -O
// ... and resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -O
// The same, but with -enable-testing:
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-testing -O
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -enable-testing -O
// Other module is resilient:
// RUN: %empty-directory(%t/types)
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/types/ExtensionTypes.swiftmodule -enable-library-evolution
// This module is both not resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -O
// ... and resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -O
// The same but with -enable-testing:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-testing -O
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -enable-testing -O
import ExtensionTypes
// This generates all combinations of a public/internal/private struct
// (plus a public one from another module) being extended to conform
// to a public/internal/private protocol (plus a public one from
// another module), both with and without inheritance/defaulting.
%{
local_decl_names = ["Public", "Internal", "Private"]
all_decl_names = ["Foreign"] + local_decl_names
decl_name_to_access = {
"Foreign": "public",
"Public": "public",
"Internal": "internal",
"Private": "fileprivate"
}
def conformanceBody(protocol):
return """
{access} func {name}Method() {{}}
{access} var {name}Get: Int {{ return 0 }}
{access} var {name}GetSet: Int {{
get {{ return 0 }}
set {{}}
}}
""".format(access = decl_name_to_access[protocol],
name = protocol.lower())
}%
% for name in local_decl_names:
% access = name.lower()
${access} protocol Extension${name} {
func ${access}Method()
var ${access}Get: Int { get }
var ${access}GetSet: Int { get set }
}
// Defaulted methods:
${access} protocol Extension${name}Inherit: ExtensionForeign {}
extension Extension${name}Inherit {
${conformanceBody(name)}
}
${access} struct ${name}Struct {}
${access} struct ${name}StructInherit {}
${access} struct ${name}StructInheritNoDefault {}
${access} struct ${name}StructOneExtension {}
% end
% for sname in all_decl_names:
% access = sname.lower()
% for pname in all_decl_names:
// e.g. extension PublicStruct: Private { ... }
extension ${sname}Struct: Extension${pname} {
${conformanceBody(pname)}
}
// e.g. extension PublicStructInherit: PrivateInherit {}
extension ${sname}StructInherit: Extension${pname}Inherit {}
// e.g. extension PublicStructInheritNoDefault: PrivateInherit { ... }
extension ${sname}StructInheritNoDefault: Extension${pname}Inherit {
${conformanceBody(pname)}
}
% end
// e.g. extension PublicStructOneExtension: ExtensionForeign, ExtensionPublic, ExtensionInternal, ExtensionPrivate { ... }
extension ${sname}StructOneExtension: ${", ".join("Extension" + p for p in all_decl_names)} {
% for pname in all_decl_names:
${conformanceBody(pname)}
% end
}
% end