@@ -1645,33 +1645,27 @@ ValueDecl::getSatisfiedProtocolRequirements(bool Sorted) const {
1645
1645
}
1646
1646
1647
1647
bool ValueDecl::hasInterfaceType () const {
1648
- // getInterfaceType() returns the contextual type for ParamDecls which
1649
- // don't have an explicit interface type.
1650
- if (auto *PD = dyn_cast<ParamDecl>(this ))
1651
- return PD->hasType ();
1652
-
1653
1648
return !!InterfaceTy;
1654
1649
}
1655
1650
1656
1651
Type ValueDecl::getInterfaceType () const {
1657
- if (InterfaceTy)
1658
- return InterfaceTy;
1659
-
1660
- // FIXME: ParamDecls are funky and don't always have an interface type
1661
- if (auto *PD = dyn_cast<ParamDecl>(this ))
1662
- return PD->getType ();
1663
-
1664
- llvm_unreachable (" no interface type was set" );
1652
+ assert (InterfaceTy && " No interface type was set" );
1653
+ return InterfaceTy;
1665
1654
}
1666
1655
1667
1656
void ValueDecl::setInterfaceType (Type type) {
1668
- assert ((type.isNull () || !type->hasTypeVariable ()) &&
1669
- " Type variable in interface type" );
1670
-
1671
1657
// lldb creates global typealiases with archetypes in them.
1672
1658
// FIXME: Add an isDebugAlias() flag, like isDebugVar().
1673
- if (!isa<TypeAliasDecl>(this )) {
1674
- assert ((type.isNull () || !type->hasArchetype ()) &&
1659
+ //
1660
+ // Also, ParamDecls in closure contexts can have type variables
1661
+ // archetype in them during constraint generation.
1662
+ if (!type.isNull () &&
1663
+ !isa<TypeAliasDecl>(this ) &&
1664
+ !(isa<ParamDecl>(this ) &&
1665
+ isa<AbstractClosureExpr>(getDeclContext ()))) {
1666
+ assert (!type->hasArchetype () &&
1667
+ " Archetype in interface type" );
1668
+ assert (!type->hasTypeVariable () &&
1675
1669
" Archetype in interface type" );
1676
1670
}
1677
1671
@@ -2174,8 +2168,7 @@ Type AbstractTypeParamDecl::getSuperclass() const {
2174
2168
if (!dc->isValidGenericContext ())
2175
2169
return nullptr ;
2176
2170
2177
- auto contextTy = ArchetypeBuilder::mapTypeIntoContext (
2178
- dc, getDeclaredInterfaceType ());
2171
+ auto contextTy = dc->mapTypeIntoContext (getDeclaredInterfaceType ());
2179
2172
if (auto *archetype = contextTy->getAs <ArchetypeType>())
2180
2173
return archetype->getSuperclass ();
2181
2174
@@ -2189,8 +2182,7 @@ AbstractTypeParamDecl::getConformingProtocols() const {
2189
2182
if (!dc->isValidGenericContext ())
2190
2183
return nullptr ;
2191
2184
2192
- auto contextTy = ArchetypeBuilder::mapTypeIntoContext (
2193
- dc, getDeclaredInterfaceType ());
2185
+ auto contextTy = dc->mapTypeIntoContext (getDeclaredInterfaceType ());
2194
2186
if (auto *archetype = contextTy->getAs <ArchetypeType>())
2195
2187
return archetype->getConformsTo ();
2196
2188
@@ -3667,6 +3659,8 @@ ParamDecl::ParamDecl(ParamDecl *PD)
3667
3659
IsTypeLocImplicit(PD->IsTypeLocImplicit),
3668
3660
defaultArgumentKind(PD->defaultArgumentKind) {
3669
3661
typeLoc = PD->getTypeLoc ();
3662
+ if (PD->hasInterfaceType ())
3663
+ setInterfaceType (PD->getInterfaceType ());
3670
3664
}
3671
3665
3672
3666
@@ -3697,22 +3691,6 @@ Type DeclContext::getSelfInterfaceType() const {
3697
3691
return getDeclaredInterfaceType ();
3698
3692
}
3699
3693
3700
- // / \brief Retrieve the type of 'self' for the given context.
3701
- Type DeclContext::getSelfTypeOfContext () const {
3702
- // For a protocol or extension thereof, the type is 'Self'.
3703
- if (auto *proto = getAsProtocolOrProtocolExtensionContext ()) {
3704
- auto *genericEnv = proto->getGenericEnvironment ();
3705
-
3706
- // In the parser, generic parameters won't be wired up yet, just give up on
3707
- // producing a type.
3708
- if (genericEnv == nullptr )
3709
- return Type ();
3710
-
3711
- return genericEnv->mapTypeIntoContext (getProtocolSelfType ());
3712
- }
3713
- return getDeclaredTypeOfContext ();
3714
- }
3715
-
3716
3694
// / Create an implicit 'self' decl for a method in the specified decl context.
3717
3695
// / If 'static' is true, then this is self for a static method in the type.
3718
3696
// /
@@ -3722,24 +3700,10 @@ Type DeclContext::getSelfTypeOfContext() const {
3722
3700
// / For a generic context, this also gives the parameter an unbound generic
3723
3701
// / type with the expectation that type-checking will fill in the context
3724
3702
// / generic parameters.
3725
- ParamDecl *ParamDecl::createUnboundSelf (SourceLoc loc, DeclContext *DC,
3726
- bool isStaticMethod, bool isInOut) {
3703
+ ParamDecl *ParamDecl::createUnboundSelf (SourceLoc loc, DeclContext *DC) {
3727
3704
ASTContext &C = DC->getASTContext ();
3728
- auto selfType = DC->getSelfTypeOfContext ();
3729
-
3730
- // If we have a valid selfType (i.e. we're not in the parser before we
3731
- // know such things, or we're nested inside an invalid extension),
3732
- // configure it.
3733
- if (selfType && !selfType->hasError ()) {
3734
- if (isStaticMethod)
3735
- selfType = MetatypeType::get (selfType);
3736
-
3737
- if (isInOut)
3738
- selfType = InOutType::get (selfType);
3739
- }
3740
-
3741
- auto *selfDecl = new (C) ParamDecl (/* IsLet*/ !isInOut, SourceLoc (),SourceLoc (),
3742
- Identifier (), loc, C.Id_self , selfType,DC);
3705
+ auto *selfDecl = new (C) ParamDecl (/* IsLet*/ true , SourceLoc (), SourceLoc (),
3706
+ Identifier (), loc, C.Id_self , Type (), DC);
3743
3707
selfDecl->setImplicit ();
3744
3708
return selfDecl;
3745
3709
}
@@ -3758,21 +3722,16 @@ ParamDecl *ParamDecl::createSelf(SourceLoc loc, DeclContext *DC,
3758
3722
ASTContext &C = DC->getASTContext ();
3759
3723
auto selfType = DC->getSelfTypeInContext ();
3760
3724
auto selfInterfaceType = DC->getSelfInterfaceType ();
3725
+ assert (selfType && selfInterfaceType);
3761
3726
3762
- assert (!!selfType == !!selfInterfaceType);
3763
-
3764
- // If we have a selfType (i.e. we're not in the parser before we know such
3765
- // things, configure it.
3766
- if (selfType && selfInterfaceType) {
3767
- if (isStaticMethod) {
3768
- selfType = MetatypeType::get (selfType);
3769
- selfInterfaceType = MetatypeType::get (selfInterfaceType);
3770
- }
3727
+ if (isStaticMethod) {
3728
+ selfType = MetatypeType::get (selfType);
3729
+ selfInterfaceType = MetatypeType::get (selfInterfaceType);
3730
+ }
3771
3731
3772
- if (isInOut) {
3773
- selfType = InOutType::get (selfType);
3774
- selfInterfaceType = InOutType::get (selfInterfaceType);
3775
- }
3732
+ if (isInOut) {
3733
+ selfType = InOutType::get (selfType);
3734
+ selfInterfaceType = InOutType::get (selfInterfaceType);
3776
3735
}
3777
3736
3778
3737
auto *selfDecl = new (C) ParamDecl (/* IsLet*/ !isInOut, SourceLoc (),SourceLoc (),
@@ -3947,39 +3906,31 @@ SourceRange SubscriptDecl::getSourceRange() const {
3947
3906
return { getSubscriptLoc (), ElementTy.getSourceRange ().End };
3948
3907
}
3949
3908
3950
- static Type getSelfTypeForContainer (AbstractFunctionDecl *theMethod,
3951
- bool isInitializingCtor,
3952
- bool wantInterfaceType) {
3953
- auto *dc = theMethod->getDeclContext ();
3909
+ Type AbstractFunctionDecl::computeInterfaceSelfType (bool isInitializingCtor,
3910
+ bool wantDynamicSelf) {
3911
+ auto *dc = getDeclContext ();
3954
3912
auto &Ctx = dc->getASTContext ();
3955
3913
3956
3914
// Determine the type of the container.
3957
- auto containerTy = wantInterfaceType ? dc->getDeclaredInterfaceType ()
3958
- : dc->getDeclaredTypeInContext ();
3915
+ auto containerTy = dc->getDeclaredInterfaceType ();
3959
3916
if (!containerTy || containerTy->hasError ())
3960
3917
return ErrorType::get (Ctx);
3961
3918
3962
3919
// Determine the type of 'self' inside the container.
3963
- auto selfTy = wantInterfaceType ? dc->getSelfInterfaceType ()
3964
- : dc->getSelfTypeInContext ();
3920
+ auto selfTy = dc->getSelfInterfaceType ();
3965
3921
if (!selfTy || selfTy->hasError ())
3966
3922
return ErrorType::get (Ctx);
3967
3923
3968
3924
bool isStatic = false ;
3969
3925
bool isMutating = false ;
3970
- Type selfTypeOverride;
3971
-
3972
- if (auto *FD = dyn_cast<FuncDecl>(theMethod)) {
3926
+
3927
+ if (auto *FD = dyn_cast<FuncDecl>(this )) {
3973
3928
isStatic = FD->isStatic ();
3974
3929
isMutating = FD->isMutating ();
3975
3930
3976
- // The non-interface type of a method that returns DynamicSelf
3977
- // uses DynamicSelf for the type of 'self', which is important
3978
- // when type checking the body of the function.
3979
- if (!wantInterfaceType && FD->hasDynamicSelf ()) {
3931
+ if (wantDynamicSelf && FD->hasDynamicSelf ())
3980
3932
selfTy = DynamicSelfType::get (selfTy, Ctx);
3981
- }
3982
- } else if (isa<ConstructorDecl>(theMethod)) {
3933
+ } else if (isa<ConstructorDecl>(this )) {
3983
3934
if (isInitializingCtor) {
3984
3935
// initializing constructors of value types always have an implicitly
3985
3936
// inout self.
@@ -3988,7 +3939,7 @@ static Type getSelfTypeForContainer(AbstractFunctionDecl *theMethod,
3988
3939
// allocating constructors have metatype 'self'.
3989
3940
isStatic = true ;
3990
3941
}
3991
- } else if (isa<DestructorDecl>(theMethod )) {
3942
+ } else if (isa<DestructorDecl>(this )) {
3992
3943
// destructors of value types always have an implicitly inout self.
3993
3944
isMutating = true ;
3994
3945
}
@@ -4064,14 +4015,6 @@ void AbstractFunctionDecl::setGenericParams(GenericParamList *GP) {
4064
4015
}
4065
4016
4066
4017
4067
- Type AbstractFunctionDecl::computeSelfType () {
4068
- return getSelfTypeForContainer (this , true , false );
4069
- }
4070
-
4071
- Type AbstractFunctionDecl::computeInterfaceSelfType (bool isInitializingCtor) {
4072
- return getSelfTypeForContainer (this , isInitializingCtor, true );
4073
- }
4074
-
4075
4018
// / \brief This method returns the implicit 'self' decl.
4076
4019
// /
4077
4020
// / Note that some functions don't have an implicit 'self' decl, for example,
@@ -4561,8 +4504,7 @@ bool EnumElementDecl::computeType() {
4561
4504
4562
4505
// The type of the enum element is either (T) -> T or (T) -> ArgType -> T.
4563
4506
if (auto inputTy = getArgumentType ()) {
4564
- resultTy = FunctionType::get (
4565
- ArchetypeBuilder::mapTypeOutOfContext (ED, inputTy), resultTy);
4507
+ resultTy = FunctionType::get (ED->mapTypeOutOfContext (inputTy), resultTy);
4566
4508
}
4567
4509
4568
4510
if (auto *genericSig = ED->getGenericSignatureOfContext ())
0 commit comments