Skip to content

Commit a0aa318

Browse files
author
Quinn Taylor
committed
Address PR feedback, including narrowing element type of DictionaryValue to TupleValue.
1 parent 813f542 commit a0aa318

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

include/swift/AST/ConstTypeInfo.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,6 @@ class BuilderValue : public CompileTimeValue {
102102
std::vector<CompileTimeValue> Members;
103103
};
104104

105-
/// A dictionary literal value representation
106-
class DictionaryValue : public CompileTimeValue {
107-
public:
108-
DictionaryValue(std::vector<std::shared_ptr<CompileTimeValue>> elements)
109-
: CompileTimeValue(ValueKind::Dictionary), elements(elements) {}
110-
111-
static bool classof(const CompileTimeValue *T) {
112-
return T->getKind() == ValueKind::Dictionary;
113-
}
114-
115-
std::vector<std::shared_ptr<CompileTimeValue>> getElements() const {
116-
return elements;
117-
}
118-
119-
private:
120-
std::vector<std::shared_ptr<CompileTimeValue>> elements;
121-
};
122-
123105
struct TupleElement {
124106
Optional<std::string> Label;
125107
swift::Type Type;
@@ -159,6 +141,24 @@ class ArrayValue : public CompileTimeValue {
159141
std::vector<std::shared_ptr<CompileTimeValue>> Elements;
160142
};
161143

144+
/// A dictionary literal value representation
145+
class DictionaryValue : public CompileTimeValue {
146+
public:
147+
DictionaryValue(std::vector<std::shared_ptr<TupleValue>> elements)
148+
: CompileTimeValue(ValueKind::Dictionary), Elements(elements) {}
149+
150+
static bool classof(const CompileTimeValue *T) {
151+
return T->getKind() == ValueKind::Dictionary;
152+
}
153+
154+
std::vector<std::shared_ptr<TupleValue>> getElements() const {
155+
return Elements;
156+
}
157+
158+
private:
159+
std::vector<std::shared_ptr<TupleValue>> Elements;
160+
};
161+
162162
/// A representation of an arbitrary value that does not fall under
163163
/// any of the above categories.
164164
class RuntimeValue : public CompileTimeValue {

lib/ConstExtract/ConstExtract.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
148148

149149
case ExprKind::Dictionary: {
150150
auto dictionaryExpr = cast<DictionaryExpr>(expr);
151-
std::vector<std::shared_ptr<CompileTimeValue>> elementValues;
152-
for (unsigned n = dictionaryExpr->getNumElements(), i = 0; i != n; i++) {
153-
auto elementExpr = dictionaryExpr->getElement(i);
154-
elementValues.push_back(extractCompileTimeValue(elementExpr));
151+
std::vector<std::shared_ptr<TupleValue>> tuples;
152+
for (auto elementExpr : dictionaryExpr->getElements()) {
153+
auto elementValue = extractCompileTimeValue(elementExpr);
154+
tuples.push_back(std::static_pointer_cast<TupleValue>(elementValue));
155155
}
156-
return std::make_shared<DictionaryValue>(elementValues);
156+
return std::make_shared<DictionaryValue>(tuples);
157157
}
158158

159159
case ExprKind::Tuple: {
@@ -392,8 +392,8 @@ void writeValue(llvm::json::OStream &JSON,
392392
case CompileTimeValue::ValueKind::Dictionary: {
393393
JSON.attribute("valueKind", "Dictionary");
394394
JSON.attributeArray("value", [&] {
395-
for (auto element : cast<DictionaryValue>(value)->getElements()) {
396-
auto tupleElements = cast<TupleValue>(element.get())->getElements();
395+
for (auto tupleValue : cast<DictionaryValue>(value)->getElements()) {
396+
auto tupleElements = tupleValue.get()->getElements();
397397
JSON.object([&] {
398398
JSON.attributeObject(
399399
"key", [&] { writeValue(JSON, tupleElements[0].Value); });

0 commit comments

Comments
 (0)