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:
Allan Shortlidge
2022-08-03 18:51:19 -07:00
parent 9151db55e7
commit bc5f13cb6b
15 changed files with 317 additions and 12 deletions

View File

@@ -554,6 +554,9 @@ UnboundImport::UnboundImport(ImportDecl *ID)
import.options |= ImportFlags::Preconcurrency;
import.preconcurrencyRange = attr->getRangeWithAt();
}
if (auto attr = ID->getAttrs().getAttribute<WeakLinkedAttr>())
import.options |= ImportFlags::WeakLinked;
}
bool UnboundImport::checkNotTautological(const SourceFile &SF) {