@@ -246,6 +246,10 @@ struct ASTContext::Implementation {
246
246
// Declare cached declarations for each of the known declarations.
247
247
#define FUNC_DECL (Name, Id ) FuncDecl *Get##Name = nullptr ;
248
248
#include " swift/AST/KnownDecls.def"
249
+
250
+ // Declare cached declarations for each of the known declarations.
251
+ #define KNOWN_SDK_FUNC_DECL (Module, Name, Id ) FuncDecl *Get##Name = nullptr ;
252
+ #include " swift/AST/KnownSDKDecls.def"
249
253
250
254
// / func <Int, Int) -> Bool
251
255
FuncDecl *LessThanIntDecl = nullptr ;
@@ -699,10 +703,10 @@ Identifier ASTContext::getIdentifier(StringRef Str) const {
699
703
return Identifier (I->getKeyData ());
700
704
}
701
705
702
- void ASTContext::lookupInSwiftModule (
703
- StringRef name ,
704
- SmallVectorImpl<ValueDecl *> &results) const {
705
- ModuleDecl *M = getStdlibModule ();
706
+ void ASTContext::lookupInModule (
707
+ ModuleDecl *M ,
708
+ StringRef name,
709
+ SmallVectorImpl<ValueDecl *> &results) const {
706
710
if (!M)
707
711
return ;
708
712
@@ -711,6 +715,12 @@ void ASTContext::lookupInSwiftModule(
711
715
M->lookupValue (identifier, NLKind::UnqualifiedLookup, results);
712
716
}
713
717
718
+ void ASTContext::lookupInSwiftModule (
719
+ StringRef name,
720
+ SmallVectorImpl<ValueDecl *> &results) const {
721
+ lookupInModule (getStdlibModule (), name, results);
722
+ }
723
+
714
724
FuncDecl *ASTContext::getPlusFunctionOnRangeReplaceableCollection () const {
715
725
if (getImpl ().PlusFunctionOnRangeReplaceableCollection ) {
716
726
return getImpl ().PlusFunctionOnRangeReplaceableCollection ;
@@ -1033,16 +1043,24 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
1033
1043
return nullptr ;
1034
1044
}
1035
1045
1036
- // / Find the implementation for the given "intrinsic" library function.
1046
+ // / Find the implementation for the given "intrinsic" library function,
1047
+ // / in the passed in module.
1037
1048
static FuncDecl *findLibraryIntrinsic (const ASTContext &ctx,
1049
+ ModuleDecl *M,
1038
1050
StringRef name) {
1039
1051
SmallVector<ValueDecl *, 1 > results;
1040
- ctx.lookupInSwiftModule ( name, results);
1052
+ ctx.lookupInModule (M, name, results);
1041
1053
if (results.size () == 1 )
1042
1054
return dyn_cast_or_null<FuncDecl>(results.front ());
1043
1055
return nullptr ;
1044
1056
}
1045
1057
1058
+ // / Find the implementation for the given "intrinsic" library function.
1059
+ static FuncDecl *findLibraryIntrinsic (const ASTContext &ctx,
1060
+ StringRef name) {
1061
+ return findLibraryIntrinsic (ctx, ctx.getStdlibModule (), name);
1062
+ }
1063
+
1046
1064
// / Returns the type of an intrinsic function if it is not generic, otherwise
1047
1065
// / returns nullptr.
1048
1066
static FunctionType *
@@ -1492,7 +1510,7 @@ ASTContext::associateInfixOperators(PrecedenceGroupDecl *left,
1492
1510
}
1493
1511
1494
1512
// Find library intrinsic function.
1495
- static FuncDecl *findLibraryFunction (const ASTContext &ctx, FuncDecl *&cache,
1513
+ static FuncDecl *findLibraryFunction (const ASTContext &ctx, FuncDecl *&cache,
1496
1514
StringRef name) {
1497
1515
if (cache) return cache;
1498
1516
@@ -1501,12 +1519,33 @@ static FuncDecl *findLibraryFunction(const ASTContext &ctx, FuncDecl *&cache,
1501
1519
return cache;
1502
1520
}
1503
1521
1504
- #define FUNC_DECL (Name, Id ) \
1505
- FuncDecl *ASTContext::get##Name() const { \
1522
+ // Find library intrinsic function in passed in module
1523
+ static FuncDecl *findLibraryFunction (const ASTContext &ctx,
1524
+ ModuleDecl *M, FuncDecl *&cache,
1525
+ StringRef name) {
1526
+ if (cache) return cache;
1527
+
1528
+ // Look for a generic function.
1529
+ cache = findLibraryIntrinsic (ctx, M, name);
1530
+ return cache;
1531
+ }
1532
+
1533
+ #define FUNC_DECL (Name, Id ) \
1534
+ FuncDecl *ASTContext::get##Name() const { \
1506
1535
return findLibraryFunction (*this , getImpl ().Get ##Name, Id); \
1507
1536
}
1508
1537
#include " swift/AST/KnownDecls.def"
1509
1538
1539
+ #define KNOWN_SDK_FUNC_DECL (Module, Name, Id ) \
1540
+ FuncDecl *ASTContext::get##Name() const { \
1541
+ if (ModuleDecl *M = getLoadedModule (Id_##Module)) { \
1542
+ return findLibraryFunction (*this , M, getImpl ().Get ##Name, Id); \
1543
+ } else { \
1544
+ return findLibraryFunction (*this , getImpl ().Get ##Name, Id); \
1545
+ } \
1546
+ }
1547
+ #include " swift/AST/KnownSDKDecls.def"
1548
+
1510
1549
bool ASTContext::hasOptionalIntrinsics () const {
1511
1550
return getOptionalDecl () &&
1512
1551
getOptionalSomeDecl () &&
0 commit comments