Skip to content

Commit 4f84d8a

Browse files
committed
[Sema] TypeWrappers: Request type wrapper attribute type eagerly
The type is needed for serialization so it has to be requested and chached in type wrapper info.
1 parent 740ae8d commit 4f84d8a

File tree

4 files changed

+18
-48
lines changed

4 files changed

+18
-48
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,23 +3546,6 @@ class GetTypeWrapper
35463546
bool isCached() const { return true; }
35473547
};
35483548

3549-
/// Return a type of the type wrapper (if any) associated with the given
3550-
/// declaration.
3551-
class GetTypeWrapperType
3552-
: public SimpleRequest<GetTypeWrapperType, Type(NominalTypeDecl *),
3553-
RequestFlags::Cached> {
3554-
public:
3555-
using SimpleRequest::SimpleRequest;
3556-
3557-
private:
3558-
friend SimpleRequest;
3559-
3560-
Type evaluate(Evaluator &evaluator, NominalTypeDecl *) const;
3561-
3562-
public:
3563-
bool isCached() const { return true; }
3564-
};
3565-
35663549
/// Inject or get `$Storage` type which has all of the stored properties
35673550
/// of the given type with a type wrapper.
35683551
class GetTypeWrapperStorage

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,6 @@ SWIFT_REQUEST(TypeChecker, GetSourceFileAsyncNode,
404404
SWIFT_REQUEST(TypeChecker, GetTypeWrapper,
405405
Optional<TypeWrapperInfo>(NominalTypeDecl *),
406406
Cached, NoLocationInfo)
407-
SWIFT_REQUEST(TypeChecker, GetTypeWrapperType,
408-
Type(NominalTypeDecl *),
409-
Cached, NoLocationInfo)
410407
SWIFT_REQUEST(TypeChecker, GetTypeWrapperStorage,
411408
TypeDecl *(NominalTypeDecl *),
412409
Cached, NoLocationInfo)

include/swift/AST/TypeWrappers.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ namespace swift {
2121

2222
struct TypeWrapperInfo {
2323
CustomAttr *Attr;
24+
Type AttrType;
2425
NominalTypeDecl *Wrapper;
2526
NominalTypeDecl *AttachedTo;
2627
bool IsInferred;
2728

28-
TypeWrapperInfo(CustomAttr *attr, NominalTypeDecl *wrapperDecl,
29+
TypeWrapperInfo(CustomAttr *attr, Type attrType, NominalTypeDecl *wrapperDecl,
2930
NominalTypeDecl *attachedTo, bool isInferred)
30-
: Attr(attr), Wrapper(wrapperDecl), AttachedTo(attachedTo),
31-
IsInferred(isInferred) {}
31+
: Attr(attr), AttrType(attrType), Wrapper(wrapperDecl),
32+
AttachedTo(attachedTo), IsInferred(isInferred) {}
3233

3334
TypeWrapperInfo asInferred() const {
34-
return {Attr, Wrapper, AttachedTo, true};
35+
return {Attr, AttrType, Wrapper, AttachedTo, true};
3536
}
3637
};
3738

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,19 @@ static void getTypeWrappers(NominalTypeDecl *decl,
130130
continue;
131131

132132
auto *typeWrapper = nominal->getAttrs().getAttribute<TypeWrapperAttr>();
133-
if (typeWrapper && typeWrapper->isValid())
133+
if (typeWrapper && typeWrapper->isValid()) {
134+
auto attrType = evaluateOrDefault(
135+
ctx.evaluator,
136+
CustomAttrTypeRequest{mutableAttr, decl,
137+
CustomAttrTypeKind::TypeWrapper},
138+
Type());
139+
140+
if (!attrType || attrType->hasError())
141+
continue;
142+
134143
typeWrappers.push_back(
135-
{mutableAttr, nominal, decl, /*isInferred=*/false});
144+
{mutableAttr, attrType, nominal, decl, /*isInferred=*/false});
145+
}
136146
}
137147

138148
// Do not allow transitive protocol inference between protocols.
@@ -195,24 +205,6 @@ GetTypeWrapper::evaluate(Evaluator &evaluator, NominalTypeDecl *decl) const {
195205
return typeWrappers.front();
196206
}
197207

198-
Type GetTypeWrapperType::evaluate(Evaluator &evaluator,
199-
NominalTypeDecl *decl) const {
200-
auto typeWrapperInfo = decl->getTypeWrapper();
201-
if (!typeWrapperInfo)
202-
return Type();
203-
204-
auto type = evaluateOrDefault(
205-
evaluator,
206-
CustomAttrTypeRequest{typeWrapperInfo->Attr, decl->getDeclContext(),
207-
CustomAttrTypeKind::TypeWrapper},
208-
Type());
209-
210-
if (!type || type->hasError()) {
211-
return ErrorType::get(decl->getASTContext());
212-
}
213-
return type;
214-
}
215-
216208
VarDecl *NominalTypeDecl::getTypeWrapperProperty() const {
217209
auto *mutableSelf = const_cast<NominalTypeDecl *>(this);
218210
return evaluateOrDefault(getASTContext().evaluator,
@@ -352,10 +344,7 @@ GetTypeWrapperProperty::evaluate(Evaluator &evaluator,
352344
auto *storage = parent->getTypeWrapperStorageDecl();
353345
assert(storage);
354346

355-
auto *typeWrapperType =
356-
evaluateOrDefault(ctx.evaluator, GetTypeWrapperType{parent}, Type())
357-
->castTo<AnyGenericType>();
358-
assert(typeWrapperType);
347+
auto *typeWrapperType = typeWrapper->AttrType->castTo<AnyGenericType>();
359348

360349
// $storage: Wrapper<<ParentType>, <ParentType>.$Storage>
361350
auto propertyTy = BoundGenericType::get(

0 commit comments

Comments
 (0)