@@ -3368,16 +3368,6 @@ bool NominalTypeDecl::isResilient(ModuleDecl *M,
3368
3368
llvm_unreachable (" bad resilience expansion" );
3369
3369
}
3370
3370
3371
- void NominalTypeDecl::computeType () {
3372
- assert (!hasInterfaceType ());
3373
-
3374
- Type declaredInterfaceTy = getDeclaredInterfaceType ();
3375
- setInterfaceType (MetatypeType::get (declaredInterfaceTy, getASTContext ()));
3376
-
3377
- if (declaredInterfaceTy->hasError ())
3378
- setInvalid ();
3379
- }
3380
-
3381
3371
enum class DeclTypeKind : unsigned {
3382
3372
DeclaredType,
3383
3373
DeclaredInterfaceType
@@ -3556,25 +3546,6 @@ SourceRange TypeAliasDecl::getSourceRange() const {
3556
3546
return { TypeAliasLoc, getNameLoc () };
3557
3547
}
3558
3548
3559
- void TypeAliasDecl::computeType () {
3560
- assert (!hasInterfaceType ());
3561
-
3562
- // Set the interface type of this declaration.
3563
- ASTContext &ctx = getASTContext ();
3564
-
3565
- auto genericSig = getGenericSignature ();
3566
- SubstitutionMap subs;
3567
- if (genericSig)
3568
- subs = genericSig->getIdentitySubstitutionMap ();
3569
-
3570
- Type parent;
3571
- auto parentDC = getDeclContext ();
3572
- if (parentDC->isTypeContext ())
3573
- parent = parentDC->getSelfInterfaceType ();
3574
- auto sugaredType = TypeAliasType::get (this , parent, subs, getUnderlyingType ());
3575
- setInterfaceType (MetatypeType::get (sugaredType, ctx));
3576
- }
3577
-
3578
3549
Type TypeAliasDecl::getUnderlyingType () const {
3579
3550
auto &ctx = getASTContext ();
3580
3551
return evaluateOrDefault (ctx.evaluator ,
@@ -3684,14 +3655,6 @@ AssociatedTypeDecl::AssociatedTypeDecl(DeclContext *dc, SourceLoc keywordLoc,
3684
3655
assert (Resolver && " missing resolver" );
3685
3656
}
3686
3657
3687
- void AssociatedTypeDecl::computeType () {
3688
- assert (!hasInterfaceType ());
3689
-
3690
- auto &ctx = getASTContext ();
3691
- auto interfaceTy = getDeclaredInterfaceType ();
3692
- setInterfaceType (MetatypeType::get (interfaceTy, ctx));
3693
- }
3694
-
3695
3658
Type AssociatedTypeDecl::getDefaultDefinitionType () const {
3696
3659
return evaluateOrDefault (getASTContext ().evaluator ,
3697
3660
DefaultDefinitionTypeRequest{const_cast <AssociatedTypeDecl *>(this )},
@@ -3876,9 +3839,6 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
3876
3839
// Propagate access control and versioned-ness.
3877
3840
DD->copyFormalAccessFrom (CD, /* sourceIsParentContext*/ true );
3878
3841
3879
- // Wire up generic environment of DD.
3880
- DD->setGenericSignature (CD->getGenericSignatureOfContext ());
3881
-
3882
3842
// Mark DD as ObjC, as all dtors are.
3883
3843
DD->setIsObjC (ctx.LangOpts .EnableObjCInterop );
3884
3844
if (ctx.LangOpts .EnableObjCInterop )
@@ -6168,30 +6128,11 @@ void SubscriptDecl::setIndices(ParameterList *p) {
6168
6128
}
6169
6129
6170
6130
Type SubscriptDecl::getElementInterfaceType () const {
6171
- auto elementTy = getInterfaceType ();
6172
- if (elementTy->is <ErrorType>())
6173
- return elementTy;
6174
- return elementTy->castTo <AnyFunctionType>()->getResult ();
6175
- }
6176
-
6177
- void SubscriptDecl::computeType () {
6178
- auto elementTy = getElementTypeLoc ().getType ();
6179
-
6180
- SmallVector<AnyFunctionType::Param, 2 > argTy;
6181
- getIndices ()->getParams (argTy);
6182
-
6183
- Type funcTy;
6184
- if (auto sig = getGenericSignature ())
6185
- funcTy = GenericFunctionType::get (sig, argTy, elementTy);
6186
- else
6187
- funcTy = FunctionType::get (argTy, elementTy);
6188
-
6189
- // Record the interface type.
6190
- setInterfaceType (funcTy);
6191
-
6192
- // Make sure that there are no unresolved dependent types in the
6193
- // generic signature.
6194
- assert (!funcTy->findUnresolvedDependentMemberType ());
6131
+ auto &ctx = getASTContext ();
6132
+ auto mutableThis = const_cast <SubscriptDecl *>(this );
6133
+ return evaluateOrDefault (ctx.evaluator ,
6134
+ ResultTypeRequest{mutableThis},
6135
+ ErrorType::get (ctx));
6195
6136
}
6196
6137
6197
6138
ObjCSubscriptKind SubscriptDecl::getObjCSubscriptKind () const {
@@ -6325,7 +6266,9 @@ BraceStmt *AbstractFunctionDecl::getBody(bool canSynthesize) const {
6325
6266
}
6326
6267
6327
6268
auto mutableThis = const_cast <AbstractFunctionDecl *>(this );
6328
- return evaluateOrDefault (ctx.evaluator , ParseAbstractFunctionBodyRequest{mutableThis}, nullptr );
6269
+ return evaluateOrDefault (ctx.evaluator ,
6270
+ ParseAbstractFunctionBodyRequest{mutableThis},
6271
+ nullptr );
6329
6272
}
6330
6273
6331
6274
SourceRange AbstractFunctionDecl::getBodySourceRange () const {
@@ -6606,34 +6549,18 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
6606
6549
}
6607
6550
6608
6551
void AbstractFunctionDecl::computeType (AnyFunctionType::ExtInfo info) {
6609
- auto &ctx = getASTContext ();
6610
6552
auto sig = getGenericSignature ();
6611
6553
bool hasSelf = hasImplicitSelfDecl ();
6612
6554
6613
6555
// Result
6614
6556
Type resultTy;
6615
6557
if (auto fn = dyn_cast<FuncDecl>(this )) {
6616
- resultTy = fn->getBodyResultTypeLoc ().getType ();
6617
- if (!resultTy) {
6618
- resultTy = TupleType::getEmpty (ctx);
6619
- }
6620
-
6558
+ resultTy = fn->getResultInterfaceType ();
6621
6559
} else if (auto ctor = dyn_cast<ConstructorDecl>(this )) {
6622
- auto *dc = ctor->getDeclContext ();
6623
-
6624
- if (hasSelf) {
6625
- if (!dc->isTypeContext ())
6626
- resultTy = ErrorType::get (ctx);
6627
- else
6628
- resultTy = dc->getSelfInterfaceType ();
6629
- }
6630
-
6631
- // Adjust result type for failability.
6632
- if (ctor->isFailable ())
6633
- resultTy = OptionalType::get (resultTy);
6560
+ resultTy = ctor->getResultInterfaceType ();
6634
6561
} else {
6635
6562
assert (isa<DestructorDecl>(this ));
6636
- resultTy = TupleType::getEmpty (ctx );
6563
+ resultTy = TupleType::getEmpty (getASTContext () );
6637
6564
}
6638
6565
6639
6566
// (Args...) -> Result
@@ -6883,14 +6810,11 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
6883
6810
}
6884
6811
6885
6812
Type FuncDecl::getResultInterfaceType () const {
6886
- Type resultTy = getInterfaceType ();
6887
- if (resultTy.isNull () || resultTy->is <ErrorType>())
6888
- return resultTy;
6889
-
6890
- if (hasImplicitSelfDecl ())
6891
- resultTy = resultTy->castTo <AnyFunctionType>()->getResult ();
6892
-
6893
- return resultTy->castTo <AnyFunctionType>()->getResult ();
6813
+ auto &ctx = getASTContext ();
6814
+ auto mutableThis = const_cast <FuncDecl *>(this );
6815
+ return evaluateOrDefault (ctx.evaluator ,
6816
+ ResultTypeRequest{mutableThis},
6817
+ ErrorType::get (ctx));
6894
6818
}
6895
6819
6896
6820
bool FuncDecl::isUnaryOperator () const {
@@ -7033,34 +6957,6 @@ SourceRange EnumElementDecl::getSourceRange() const {
7033
6957
return {getStartLoc (), getNameLoc ()};
7034
6958
}
7035
6959
7036
- void EnumElementDecl::computeType () {
7037
- assert (!hasInterfaceType ());
7038
-
7039
- auto &ctx = getASTContext ();
7040
- auto *ED = getParentEnum ();
7041
-
7042
- // The type of the enum element is either (Self.Type) -> Self
7043
- // or (Self.Type) -> (Args...) -> Self.
7044
- auto resultTy = ED->getDeclaredInterfaceType ();
7045
-
7046
- AnyFunctionType::Param selfTy (MetatypeType::get (resultTy, ctx));
7047
-
7048
- if (auto *PL = getParameterList ()) {
7049
- SmallVector<AnyFunctionType::Param, 4 > argTy;
7050
- PL->getParams (argTy);
7051
-
7052
- resultTy = FunctionType::get (argTy, resultTy);
7053
- }
7054
-
7055
- if (auto genericSig = ED->getGenericSignature ())
7056
- resultTy = GenericFunctionType::get (genericSig, {selfTy}, resultTy);
7057
- else
7058
- resultTy = FunctionType::get ({selfTy}, resultTy);
7059
-
7060
- // Record the interface type.
7061
- setInterfaceType (resultTy);
7062
- }
7063
-
7064
6960
Type EnumElementDecl::getArgumentInterfaceType () const {
7065
6961
if (!hasAssociatedValues ())
7066
6962
return nullptr ;
@@ -7143,10 +7039,19 @@ SourceRange ConstructorDecl::getSourceRange() const {
7143
7039
}
7144
7040
7145
7041
Type ConstructorDecl::getResultInterfaceType () const {
7146
- Type ArgTy = getInterfaceType ();
7147
- ArgTy = ArgTy->castTo <AnyFunctionType>()->getResult ();
7148
- ArgTy = ArgTy->castTo <AnyFunctionType>()->getResult ();
7149
- return ArgTy;
7042
+ Type resultTy;
7043
+
7044
+ auto *dc = getDeclContext ();
7045
+ if (!dc->isTypeContext ())
7046
+ resultTy = ErrorType::get (getASTContext ());
7047
+ else
7048
+ resultTy = dc->getSelfInterfaceType ();
7049
+
7050
+ // Adjust result type for failability.
7051
+ if (isFailable ())
7052
+ return OptionalType::get (resultTy);
7053
+
7054
+ return resultTy;
7150
7055
}
7151
7056
7152
7057
Type ConstructorDecl::getInitializerInterfaceType () {
0 commit comments