mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[InterfaceGen] Print property initializers in resilient, fixed-layout types (#19619)
Augment the ASTPrinter to print the name and text of initializer expressions if a property has an initializer and the type is @_fixed_layout and resides in a resilient module, and serialize the text for partial modules. With this change, all .swiftinterface files in the project (except for SwiftLang) compile to swiftmodules on macOS. rdar://43774580 rdar://43812188
This commit is contained in:
@@ -1181,18 +1181,19 @@ unsigned PatternBindingDecl::getPatternEntryIndexForVarDecl(const VarDecl *VD) c
|
||||
}
|
||||
|
||||
SourceRange PatternBindingEntry::getOrigInitRange() const {
|
||||
auto Init = InitAndFlags.getPointer();
|
||||
auto Init = getInitAsWritten();
|
||||
return Init ? Init->getSourceRange() : SourceRange();
|
||||
}
|
||||
|
||||
void PatternBindingEntry::setInit(Expr *E) {
|
||||
auto F = InitAndFlags.getInt();
|
||||
auto F = PatternAndFlags.getInt();
|
||||
if (E) {
|
||||
InitAndFlags.setInt(F - Flags::Removed);
|
||||
InitAndFlags.setPointer(E);
|
||||
PatternAndFlags.setInt(F - Flags::Removed);
|
||||
} else {
|
||||
InitAndFlags.setInt(F | Flags::Removed);
|
||||
PatternAndFlags.setInt(F | Flags::Removed);
|
||||
}
|
||||
InitExpr.Node = E;
|
||||
InitContextAndIsText.setInt(false);
|
||||
}
|
||||
|
||||
VarDecl *PatternBindingEntry::getAnchoringVarDecl() const {
|
||||
@@ -1225,6 +1226,25 @@ SourceRange PatternBindingEntry::getSourceRange(bool omitAccessors) const {
|
||||
return SourceRange(startLoc, endLoc);
|
||||
}
|
||||
|
||||
bool PatternBindingEntry::hasInitStringRepresentation() const {
|
||||
if (InitContextAndIsText.getInt())
|
||||
return !InitStringRepresentation.empty();
|
||||
return getInit() && getInit()->getSourceRange().isValid();
|
||||
}
|
||||
|
||||
StringRef PatternBindingEntry::getInitStringRepresentation(
|
||||
SmallVectorImpl<char> &scratch) const {
|
||||
|
||||
assert(hasInitStringRepresentation() &&
|
||||
"must check if pattern has string representation");
|
||||
|
||||
if (InitContextAndIsText.getInt() && !InitStringRepresentation.empty())
|
||||
return InitStringRepresentation;
|
||||
auto &sourceMgr = getAnchoringVarDecl()->getASTContext().SourceMgr;
|
||||
auto init = getInit();
|
||||
return extractInlinableText(sourceMgr, init, scratch);
|
||||
}
|
||||
|
||||
SourceRange PatternBindingDecl::getSourceRange() const {
|
||||
SourceLoc startLoc = getStartLoc();
|
||||
SourceLoc endLoc = getPatternList().back().getSourceRange().End;
|
||||
@@ -1279,6 +1299,19 @@ VarDecl *PatternBindingDecl::getSingleVar() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool VarDecl::isInitExposedToClients() const {
|
||||
auto parent = dyn_cast<NominalTypeDecl>(getDeclContext());
|
||||
if (!parent) return false;
|
||||
if (!hasInitialValue())
|
||||
return false;
|
||||
if (isStatic())
|
||||
return false;
|
||||
if (!parent->getAttrs().hasAttribute<FixedLayoutAttr>())
|
||||
return false;
|
||||
auto *module = parent->getModuleContext();
|
||||
return module->getResilienceStrategy() == ResilienceStrategy::Resilient;
|
||||
}
|
||||
|
||||
/// Check whether the given type representation will be
|
||||
/// default-initializable.
|
||||
static bool isDefaultInitializable(const TypeRepr *typeRepr) {
|
||||
|
||||
Reference in New Issue
Block a user