mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Accept @_weakLinked on import decls to force weak linkage of symbols from a module.
The effect of declaring an import `@_weakLinked` is to treat every declaration from the module as if it were declared with `@_weakLinked`. This is useful in environments where entire modules may not be present at runtime. Although it is already possible to instruct the linker to weakly link an entire dylib, a Swift attribute provides a way to declare intent in source code and also opens the door to diagnostics and other compiler behaviors that depend on knowing that all the module's symbols will be weakly linked. rdar://96098097
This commit is contained in:
@@ -64,6 +64,11 @@ enum IsDistributed_t {
|
||||
IsNotDistributed,
|
||||
IsDistributed,
|
||||
};
|
||||
enum IsWeakImported_t {
|
||||
IsNotWeakImported,
|
||||
IsWeakImportedByModule,
|
||||
IsAlwaysWeakImported,
|
||||
};
|
||||
|
||||
enum class PerformanceConstraints : uint8_t {
|
||||
None = 0,
|
||||
@@ -317,9 +322,8 @@ private:
|
||||
/// would indicate.
|
||||
unsigned HasCReferences : 1;
|
||||
|
||||
/// Whether cross-module references to this function should always use
|
||||
/// weak linking.
|
||||
unsigned IsWeakImported : 1;
|
||||
/// Whether cross-module references to this function should use weak linking.
|
||||
unsigned IsWeakImported : 2;
|
||||
|
||||
/// Whether the implementation can be dynamically replaced.
|
||||
unsigned IsDynamicReplaceable : 1;
|
||||
@@ -797,12 +801,18 @@ public:
|
||||
|
||||
/// Returns whether this function's symbol must always be weakly referenced
|
||||
/// across module boundaries.
|
||||
bool isAlwaysWeakImported() const { return IsWeakImported; }
|
||||
|
||||
void setAlwaysWeakImported(bool value) {
|
||||
IsWeakImported = value;
|
||||
bool isAlwaysWeakImported() const {
|
||||
return IsWeakImported == IsWeakImported_t::IsAlwaysWeakImported;
|
||||
}
|
||||
|
||||
/// Returns whether this function's symbol was referenced by a module that
|
||||
/// imports the defining module \c @_weakLinked.
|
||||
bool isWeakImportedByModule() const {
|
||||
return IsWeakImported == IsWeakImported_t::IsWeakImportedByModule;
|
||||
}
|
||||
|
||||
void setIsWeakImported(IsWeakImported_t value) { IsWeakImported = value; }
|
||||
|
||||
bool isWeakImported() const;
|
||||
|
||||
/// Returns whether this function implementation can be dynamically replaced.
|
||||
|
||||
Reference in New Issue
Block a user