@@ -2789,6 +2789,7 @@ namespace {
27892789
27902790 enum class RetainReleaseOperationKind {
27912791 notAfunction,
2792+ notAnInstanceFunction,
27922793 invalidReturnType,
27932794 invalidParameters,
27942795 valid
@@ -2802,17 +2803,32 @@ namespace {
28022803 if (!operationFn)
28032804 return RetainReleaseOperationKind::notAfunction;
28042805
2805- if (operationFn->getParameters ()-> size () != 1 )
2806- return RetainReleaseOperationKind::invalidParameters ;
2806+ if (operationFn->isStatic () )
2807+ return RetainReleaseOperationKind::notAnInstanceFunction ;
28072808
2808- Type paramType =
2809- operationFn->getParameters ()->get (0 )->getInterfaceType ();
2810- // Unwrap if paramType is an OptionalType
2811- if (Type optionalType = paramType->getOptionalObjectType ()) {
2812- paramType = optionalType;
2813- }
2809+ if (operationFn->isInstanceMember ()) {
2810+ if (operationFn->getParameters ()->size () != 0 )
2811+ return RetainReleaseOperationKind::invalidParameters;
2812+ } else {
2813+ if (operationFn->getParameters ()->size () != 1 )
2814+ return RetainReleaseOperationKind::invalidParameters;
2815+ }
2816+
2817+ Type paramType;
2818+ NominalTypeDecl *paramDecl = nullptr ;
2819+ if (!operationFn->isInstanceMember ()) {
2820+ paramType =
2821+ operationFn->getParameters ()->get (0 )->getInterfaceType ();
2822+ // Unwrap if paramType is an OptionalType
2823+ if (Type optionalType = paramType->getOptionalObjectType ()) {
2824+ paramType = optionalType;
2825+ }
28142826
2815- swift::NominalTypeDecl *paramDecl = paramType->getAnyNominal ();
2827+ paramDecl = paramType->getAnyNominal ();
2828+ } else {
2829+ paramDecl = cast<NominalTypeDecl>(operationFn->getParent ());
2830+ paramType = paramDecl->getDeclaredInterfaceType ();
2831+ }
28162832
28172833 // The return type should be void (for release functions), or void
28182834 // or the parameter type (for retain functions).
@@ -2897,6 +2913,12 @@ namespace {
28972913 diag::foreign_reference_types_retain_release_not_a_function_decl,
28982914 false , retainOperation.name );
28992915 break ;
2916+ case RetainReleaseOperationKind::notAnInstanceFunction:
2917+ Impl.diagnose (
2918+ loc,
2919+ diag::foreign_reference_types_retain_release_not_an_instance_function,
2920+ false , retainOperation.name );
2921+ break ;
29002922 case RetainReleaseOperationKind::invalidReturnType:
29012923 Impl.diagnose (
29022924 loc,
@@ -2962,6 +2984,12 @@ namespace {
29622984 diag::foreign_reference_types_retain_release_not_a_function_decl,
29632985 true , releaseOperation.name );
29642986 break ;
2987+ case RetainReleaseOperationKind::notAnInstanceFunction:
2988+ Impl.diagnose (
2989+ loc,
2990+ diag::foreign_reference_types_retain_release_not_an_instance_function,
2991+ true , releaseOperation.name );
2992+ break ;
29652993 case RetainReleaseOperationKind::invalidReturnType:
29662994 Impl.diagnose (
29672995 loc,
@@ -3243,26 +3271,12 @@ namespace {
32433271
32443272 Decl *VisitClassTemplateSpecializationDecl (
32453273 const clang::ClassTemplateSpecializationDecl *decl) {
3246- bool isPair = decl->getSpecializedTemplate ()->isInStdNamespace () &&
3247- decl->getSpecializedTemplate ()->getName () == " pair" ;
3248-
3249- // Before we go any further, check if we've already got tens of thousands
3250- // of specializations. If so, it means we're likely instantiating a very
3251- // deep/complex template, or we've run into an infinite loop. In either
3252- // case, its not worth the compile time, so bail.
3253- // TODO: this could be configurable at some point.
3254- size_t specializationLimit = !isPair ? 1000 : 10000 ;
3255- if (size_t (
3256- llvm::size (decl->getSpecializedTemplate ()->specializations ())) >
3257- specializationLimit) {
3258- // Note: it would be nice to import a dummy unavailable struct,
3259- // but we would then need to instantiate the template here,
3260- // as we cannot import a struct without a definition. That would
3261- // defeat the purpose. Also, we can't make the dummy
3262- // struct simply unavailable, as that still makes the
3263- // typelias that references it available.
3274+ // Importing std::conditional substantially increases compile times when
3275+ // building with libstdc++, i.e. on most Linux distros.
3276+ if (decl->isInStdNamespace () && decl->getIdentifier () &&
3277+ (decl->getName () == " conditional" || decl->getName () == " __or_" ||
3278+ decl->getName () == " _Expr" ))
32643279 return nullptr ;
3265- }
32663280
32673281 // `decl->getDefinition()` can return nullptr before the call to sema and
32683282 // return its definition afterwards.
0 commit comments