Skip to content

Commit 186e55f

Browse files
authored
[Compile Time Constant Extraction] Add extraction computed variables in extensions (#62465)
1 parent 7415cb8 commit 186e55f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/ConstExtract/ConstExtract.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ ConstantValueInfoRequest::evaluate(Evaluator &Evaluator,
205205
Properties.push_back(
206206
{Property, extractPropertyInitializationValue(Property)});
207207
}
208+
208209
for (auto Member : Decl->getMembers()) {
209210
auto *VD = dyn_cast<VarDecl>(Member);
210211
// Ignore plain stored properties collected above,
@@ -214,6 +215,14 @@ ConstantValueInfoRequest::evaluate(Evaluator &Evaluator,
214215
Properties.push_back({VD, extractPropertyInitializationValue(VD)});
215216
}
216217

218+
for (auto Extension: Decl->getExtensions()) {
219+
for (auto Member : Extension->getMembers()) {
220+
if (auto *VD = dyn_cast<VarDecl>(Member)) {
221+
Properties.push_back({VD, extractPropertyInitializationValue(VD)});
222+
}
223+
}
224+
}
225+
217226
return ConstValueTypeInfo{Decl, Properties};
218227
}
219228

test/ConstExtraction/fields.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@
154154
// CHECK-NEXT: "isComputed": "true",
155155
// CHECK-NEXT: "valueKind": "RawLiteral",
156156
// CHECK-NEXT: "value": "3"
157+
// CHECK-NEXT: },
158+
// CHECK-NEXT: {
159+
// CHECK-NEXT: "label": "e1",
160+
// CHECK-NEXT: "type": "fields.Foo.Boo",
161+
// CHECK-NEXT: "isStatic": "false",
162+
// CHECK-NEXT: "isComputed": "true",
163+
// CHECK-NEXT: "valueKind": "Runtime"
157164
// CHECK-NEXT: }
158165
// CHECK-NEXT: ]
159166
// CHECK-NEXT: }
@@ -178,6 +185,12 @@ public struct Foo {
178185
let p13: Int = adder(2, 3)
179186
}
180187

188+
extension Foo {
189+
struct Boo {}
190+
191+
var e1: Boo { Boo() }
192+
}
193+
181194
func adder(_ x: Int, _ y: Int) -> Int {
182195
x + y
183196
}

0 commit comments

Comments
 (0)