|
19 | 19 |
|
20 | 20 | #include "swift/AST/ASTNode.h" |
21 | 21 | #include "swift/AST/Availability.h" |
| 22 | +#include "swift/AST/Module.h" |
22 | 23 | #include "swift/AST/ResilienceExpansion.h" |
23 | 24 | #include "swift/Basic/ProfileCounter.h" |
24 | 25 | #include "swift/Basic/SwiftObjectHeader.h" |
@@ -64,11 +65,6 @@ enum IsDistributed_t { |
64 | 65 | IsNotDistributed, |
65 | 66 | IsDistributed, |
66 | 67 | }; |
67 | | -enum IsWeakImported_t { |
68 | | - IsNotWeakImported, |
69 | | - IsWeakImportedByModule, |
70 | | - IsAlwaysWeakImported, |
71 | | -}; |
72 | 68 |
|
73 | 69 | enum class PerformanceConstraints : uint8_t { |
74 | 70 | None = 0, |
@@ -222,6 +218,10 @@ class SILFunction |
222 | 218 | /// The AST decl context of the function. |
223 | 219 | DeclContext *DeclCtxt = nullptr; |
224 | 220 |
|
| 221 | + /// The module that defines this function. This member should only be set as |
| 222 | + /// a fallback when a \c DeclCtxt is unavailable. |
| 223 | + ModuleDecl *ParentModule = nullptr; |
| 224 | + |
225 | 225 | /// The profiler for instrumentation based profiling, or null if profiling is |
226 | 226 | /// disabled. |
227 | 227 | SILProfiler *Profiler = nullptr; |
@@ -322,8 +322,9 @@ class SILFunction |
322 | 322 | /// would indicate. |
323 | 323 | unsigned HasCReferences : 1; |
324 | 324 |
|
325 | | - /// Whether cross-module references to this function should use weak linking. |
326 | | - unsigned IsWeakImported : 2; |
| 325 | + /// Whether cross-module references to this function should always use weak |
| 326 | + /// linking. |
| 327 | + unsigned IsAlwaysWeakImported : 1; |
327 | 328 |
|
328 | 329 | /// Whether the implementation can be dynamically replaced. |
329 | 330 | unsigned IsDynamicReplaceable : 1; |
@@ -801,19 +802,11 @@ class SILFunction |
801 | 802 |
|
802 | 803 | /// Returns whether this function's symbol must always be weakly referenced |
803 | 804 | /// across module boundaries. |
804 | | - bool isAlwaysWeakImported() const { |
805 | | - return IsWeakImported == IsWeakImported_t::IsAlwaysWeakImported; |
806 | | - } |
807 | | - |
808 | | - /// Returns whether this function's symbol was referenced by a module that |
809 | | - /// imports the defining module \c @_weakLinked. |
810 | | - bool isWeakImportedByModule() const { |
811 | | - return IsWeakImported == IsWeakImported_t::IsWeakImportedByModule; |
812 | | - } |
| 805 | + bool isAlwaysWeakImported() const { return IsAlwaysWeakImported; } |
813 | 806 |
|
814 | | - void setIsWeakImported(IsWeakImported_t value) { IsWeakImported = value; } |
| 807 | + void setIsAlwaysWeakImported(bool value) { IsAlwaysWeakImported = value; } |
815 | 808 |
|
816 | | - bool isWeakImported() const; |
| 809 | + bool isWeakImported(ModuleDecl *module) const; |
817 | 810 |
|
818 | 811 | /// Returns whether this function implementation can be dynamically replaced. |
819 | 812 | IsDynamicallyReplaceable_t isDynamicallyReplaceable() const { |
@@ -960,6 +953,18 @@ class SILFunction |
960 | 953 | DeclCtxt = (DS ? DebugScope->Loc.getAsDeclContext() : nullptr); |
961 | 954 | } |
962 | 955 |
|
| 956 | + /// Returns the module that defines this function. |
| 957 | + ModuleDecl *getParentModule() const { |
| 958 | + return DeclCtxt ? DeclCtxt->getParentModule() : ParentModule; |
| 959 | + } |
| 960 | + |
| 961 | + /// Sets \c ParentModule as fallback if \c DeclCtxt is not available to |
| 962 | + /// provide the parent module. |
| 963 | + void setParentModule(ModuleDecl *module) { |
| 964 | + assert(!DeclCtxt && "already have a DeclCtxt"); |
| 965 | + ParentModule = module; |
| 966 | + } |
| 967 | + |
963 | 968 | /// Initialize the debug scope for debug info on SIL level |
964 | 969 | /// (-sil-based-debuginfo). |
965 | 970 | void setSILDebugScope(const SILDebugScope *DS) { |
|
0 commit comments