Skip to content

Commit c596a26

Browse files
authored
Merge pull request #25423 from slavapestov/the-right-type-escapes-me-5.1
AST: Fix type reconstruction for @convention(c) function types [5.1]
2 parents cb1cd39 + 496b805 commit c596a26

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: lib/AST/ASTDemangler.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,14 @@ Type ASTBuilder::createFunctionType(
378378

379379
auto einfo = AnyFunctionType::ExtInfo(representation,
380380
/*throws*/ flags.throws());
381-
if (flags.isEscaping())
382-
einfo = einfo.withNoEscape(false);
383-
else
384-
einfo = einfo.withNoEscape(true);
381+
382+
if (representation == FunctionTypeRepresentation::Swift ||
383+
representation == FunctionTypeRepresentation::Block) {
384+
if (flags.isEscaping())
385+
einfo = einfo.withNoEscape(false);
386+
else
387+
einfo = einfo.withNoEscape(true);
388+
}
385389

386390
// The result type must be materializable.
387391
if (!output->isMaterializable()) return Type();

Diff for: test/TypeDecoder/structural_types.swift

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ do {
120120
let escaping: (@escaping () -> ()) -> () = { _ in }
121121
blackHole(escaping)
122122
}
123+
124+
do {
125+
let c: [@convention(c) () -> ()] = []
126+
blackHole(c)
127+
}
128+
123129
// DEMANGLE: $syycD
124130
// DEMANGLE: $sySSzcD
125131
// DEMANGLE: $sySSncD
@@ -136,6 +142,7 @@ do {
136142
// DEMANGLE: $sSim_Sf1xSitD
137143
// DEMANGLE: $sSi1x_SfSim1ytD
138144
// DEMANGLE: $syyyccD
145+
// DEMANGLE: $sSayyyXCGD
139146

140147
// CHECK: () -> ()
141148
// CHECK: (inout String) -> ()
@@ -153,6 +160,7 @@ do {
153160
// CHECK: (Int.Type, x: Float, Int)
154161
// CHECK: (x: Int, Float, y: Int.Type)
155162
// CHECK: (@escaping () -> ()) -> ()
163+
// CHECK: Array<@convention(c) () -> ()>
156164

157165
// DEMANGLE: $sSimD
158166
// DEMANGLE: $syycmD
@@ -171,6 +179,7 @@ do {
171179
// DEMANGLE: $sSim_Sf1xSitmD
172180
// DEMANGLE: $sSi1x_SfSim1ytmD
173181
// DEMANGLE: $syyyccmD
182+
// DEMANGLE: $sSayyyXCGmD
174183

175184
// CHECK: Int.Type
176185
// CHECK: ((inout String) -> ()).Type
@@ -188,3 +197,4 @@ do {
188197
// CHECK: (Int.Type, x: Float, Int).Type
189198
// CHECK: (x: Int, Float, y: Int.Type).Type
190199
// CHECK: ((@escaping () -> ()) -> ()).Type
200+
// CHECK: Array<@convention(c) () -> ()>.Type

0 commit comments

Comments
 (0)