@@ -343,6 +343,12 @@ struct ASTContext::Implementation {
343
343
// / The declaration of Swift.Optional<T>.None.
344
344
EnumElementDecl *OptionalNoneDecl = nullptr ;
345
345
346
+ // / The declaration of Optional<T>.TangentVector.init
347
+ ConstructorDecl *OptionalTanInitDecl = nullptr ;
348
+
349
+ // / The declaration of Optional<T>.TangentVector.value
350
+ VarDecl *OptionalTanValueDecl = nullptr ;
351
+
346
352
// / The declaration of Swift.Void.
347
353
TypeAliasDecl *VoidDecl = nullptr ;
348
354
@@ -2246,41 +2252,49 @@ void ASTContext::loadObjCMethods(
2246
2252
}
2247
2253
2248
2254
ConstructorDecl *ASTContext::getOptionalTanInitDecl (CanType optionalTanType) {
2249
- auto *optionalTanDecl = optionalTanType.getNominalOrBoundGenericNominal ();
2250
- // Look up the `Optional<T>.TangentVector.init` declaration.
2251
- auto initLookup =
2252
- optionalTanDecl->lookupDirect (DeclBaseName::createConstructor ());
2253
- ConstructorDecl *constructorDecl = nullptr ;
2254
- for (auto *candidate : initLookup) {
2255
- auto candidateModule = candidate->getModuleContext ();
2256
- if (candidateModule->getName () == Id_Differentiation ||
2257
- candidateModule->isStdlibModule ()) {
2258
- assert (!constructorDecl && " Multiple `Optional.TangentVector.init`s" );
2259
- constructorDecl = cast<ConstructorDecl>(candidate);
2255
+ if (!getImpl ().OptionalTanInitDecl ) {
2256
+ auto *optionalTanDecl = optionalTanType.getNominalOrBoundGenericNominal ();
2257
+ // Look up the `Optional<T>.TangentVector.init` declaration.
2258
+ auto initLookup =
2259
+ optionalTanDecl->lookupDirect (DeclBaseName::createConstructor ());
2260
+ ConstructorDecl *constructorDecl = nullptr ;
2261
+ for (auto *candidate : initLookup) {
2262
+ auto candidateModule = candidate->getModuleContext ();
2263
+ if (candidateModule->getName () == Id_Differentiation ||
2264
+ candidateModule->isStdlibModule ()) {
2265
+ assert (!constructorDecl && " Multiple `Optional.TangentVector.init`s" );
2266
+ constructorDecl = cast<ConstructorDecl>(candidate);
2260
2267
#ifdef NDEBUG
2261
- break ;
2268
+ break ;
2262
2269
#endif
2270
+ }
2263
2271
}
2272
+ assert (constructorDecl && " No `Optional.TangentVector.init`" );
2273
+
2274
+ getImpl ().OptionalTanInitDecl = constructorDecl;
2264
2275
}
2265
- assert (constructorDecl && " No `Optional.TangentVector.init`" );
2266
2276
2267
- return constructorDecl ;
2277
+ return getImpl (). OptionalTanInitDecl ;
2268
2278
}
2269
2279
2270
2280
VarDecl *ASTContext::getOptionalTanValueDecl (CanType optionalTanType) {
2271
- // TODO: Maybe it would be better to have getters / setters here that we
2272
- // can call and hide this implementation detail?
2273
- StructDecl *optStructDecl = optionalTanType.getStructOrBoundGenericStruct ();
2274
- assert (optStructDecl && " Unexpected type of Optional.TangentVector" );
2281
+ if (!getImpl ().OptionalTanValueDecl ) {
2282
+ // TODO: Maybe it would be better to have getters / setters here that we
2283
+ // can call and hide this implementation detail?
2284
+ StructDecl *optStructDecl = optionalTanType.getStructOrBoundGenericStruct ();
2285
+ assert (optStructDecl && " Unexpected type of Optional.TangentVector" );
2275
2286
2276
- ArrayRef<VarDecl *> properties = optStructDecl->getStoredProperties ();
2277
- assert (properties.size () == 1 && " Unexpected type of Optional.TangentVector" );
2278
- VarDecl *wrappedValueVar = properties[0 ];
2287
+ ArrayRef<VarDecl *> properties = optStructDecl->getStoredProperties ();
2288
+ assert (properties.size () == 1 && " Unexpected type of Optional.TangentVector" );
2289
+ VarDecl *wrappedValueVar = properties[0 ];
2279
2290
2280
- assert (wrappedValueVar->getTypeInContext ()->getEnumOrBoundGenericEnum () ==
2281
- getOptionalDecl () && " Unexpected type of Optional.TangentVector" );
2291
+ assert (wrappedValueVar->getTypeInContext ()->getEnumOrBoundGenericEnum () ==
2292
+ getOptionalDecl () && " Unexpected type of Optional.TangentVector" );
2293
+
2294
+ getImpl ().OptionalTanValueDecl = wrappedValueVar;
2295
+ }
2282
2296
2283
- return wrappedValueVar ;
2297
+ return getImpl (). OptionalTanValueDecl ;
2284
2298
}
2285
2299
2286
2300
void ASTContext::loadDerivativeFunctionConfigurations (
0 commit comments