Skip to content

Commit 9027d52

Browse files
committed
[AST] Fix friendship with AnyRequestBase
This was causing issues with MSVC. Have subclasses be friends with all specializations of AnyRequestBase, and define `getRawStorage` in the base class to make it accessible to `friend` top-level functions.
1 parent f081ae5 commit 9027d52

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

include/swift/AST/AnyRequest.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,15 @@ class AnyRequestBase {
154154
return *static_cast<const Derived *>(this);
155155
}
156156

157+
const void *getRawStorage() const { return asDerived().getRawStorage(); }
158+
157159
public:
158160
/// Cast to a specific (known) type.
159161
template<typename Request>
160162
const Request &castTo() const {
161163
assert(getVTable()->typeID == TypeID<Request>::value &&
162164
"Wrong type in cast");
163-
return *static_cast<const Request *>(asDerived().getRawStorage());
165+
return *static_cast<const Request *>(getRawStorage());
164166
}
165167

166168
/// Try casting to a specific (known) type, returning \c nullptr on
@@ -170,26 +172,27 @@ class AnyRequestBase {
170172
if (getVTable()->typeID != TypeID<Request>::value)
171173
return nullptr;
172174

173-
return static_cast<const Request *>(asDerived().getRawStorage());
175+
return static_cast<const Request *>(getRawStorage());
174176
}
175177

176178
/// Diagnose a cycle detected for this request.
177179
void diagnoseCycle(DiagnosticEngine &diags) const {
178-
getVTable()->diagnoseCycle(asDerived().getRawStorage(), diags);
180+
getVTable()->diagnoseCycle(getRawStorage(), diags);
179181
}
180182

181183
/// Note that this request is part of a cycle.
182184
void noteCycleStep(DiagnosticEngine &diags) const {
183-
getVTable()->noteCycleStep(asDerived().getRawStorage(), diags);
185+
getVTable()->noteCycleStep(getRawStorage(), diags);
184186
}
185187

186188
/// Retrieve the nearest source location to which this request applies.
187189
SourceLoc getNearestLoc() const {
188-
return getVTable()->getNearestLoc(asDerived().getRawStorage());
190+
return getVTable()->getNearestLoc(getRawStorage());
189191
}
190192

191193
/// Compare two instances for equality.
192-
friend bool operator==(const Derived &lhs, const Derived &rhs) {
194+
friend bool operator==(const AnyRequestBase<Derived> &lhs,
195+
const AnyRequestBase<Derived> &rhs) {
193196
// If the storage kinds don't match, we're done.
194197
if (lhs.getStorageKind() != rhs.getStorageKind())
195198
return false;
@@ -210,7 +213,7 @@ class AnyRequestBase {
210213
return !(lhs == rhs);
211214
}
212215

213-
friend hash_code hash_value(const Derived &req) {
216+
friend hash_code hash_value(const AnyRequestBase<Derived> &req) {
214217
// If there's no storage, return a trivial hash value.
215218
if (!req.hasStorage())
216219
return 1;
@@ -219,7 +222,8 @@ class AnyRequestBase {
219222
return hashForHolder(req.getVTable()->typeID, reqHash);
220223
}
221224

222-
friend void simple_display(llvm::raw_ostream &out, const Derived &req) {
225+
friend void simple_display(llvm::raw_ostream &out,
226+
const AnyRequestBase<Derived> &req) {
223227
req.getVTable()->simpleDisplay(req.getRawStorage(), out);
224228
}
225229
};
@@ -240,7 +244,9 @@ class AnyRequestBase {
240244
/// void noteCycleStep(DiagnosticEngine &diags) const;
241245
///
242246
class ActiveRequest final : public AnyRequestBase<ActiveRequest> {
247+
template <typename T>
243248
friend class AnyRequestBase;
249+
244250
friend class AnyRequest;
245251
friend llvm::DenseMapInfo<ActiveRequest>;
246252

@@ -280,7 +286,9 @@ class ActiveRequest final : public AnyRequestBase<ActiveRequest> {
280286
/// void noteCycleStep(DiagnosticEngine &diags) const;
281287
///
282288
class AnyRequest final : public AnyRequestBase<AnyRequest> {
289+
template <typename T>
283290
friend class AnyRequestBase;
291+
284292
friend llvm::DenseMapInfo<AnyRequest>;
285293

286294
/// Pointer to the request on the heap.

0 commit comments

Comments
 (0)