Skip to content

Commit f940799

Browse files
committed
Try to avoid the deserialized swiftmodule contains un-supported platform visionOS
This is the quick fix for non-visionOS build (like iOS) when seeing the @available decl
1 parent 5fed479 commit f940799

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,17 @@ ModuleDecl *ModuleFile::getModule(ImportPath::Module name,
27622762
return getContext().getLoadedModule(name);
27632763
}
27642764

2765+
static void filterUnsupportedPlatformKinds(SmallVectorImpl<AvailableAttr *> &availabilityAttrs) {
2766+
auto it = availabilityAttrs.begin();
2767+
while(it != availabilityAttrs.end()) {
2768+
unsigned platform = (unsigned)(*it)->Platform;
2769+
if (platform >= /*PlatformKind::visionOS*/13) {
2770+
it = availabilityAttrs.erase(it);
2771+
} else {
2772+
++it;
2773+
}
2774+
}
2775+
}
27652776

27662777
/// Translate from the Serialization associativity enum values to the AST
27672778
/// strongly-typed enum.
@@ -5280,6 +5291,11 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
52805291
isPackageDescriptionVersionSpecific, isSPI, LIST_VER_TUPLE_PIECES(Introduced),
52815292
LIST_VER_TUPLE_PIECES(Deprecated), LIST_VER_TUPLE_PIECES(Obsoleted),
52825293
platform, renameDeclID, messageSize, renameSize);
5294+
5295+
// Hack: Filter the un-supported platforms from swiftmodule
5296+
if (platform >= /*PlatformKind::visionOS*/13) {
5297+
return nullptr;
5298+
}
52835299

52845300
ValueDecl *renameDecl = nullptr;
52855301
if (renameDeclID) {
@@ -5513,6 +5529,7 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
55135529

55145530
case decls_block::Available_DECL_ATTR: {
55155531
Attr = readAvailable_DECL_ATTR(scratch, blobData);
5532+
if (!Attr) skipAttr = true;
55165533
break;
55175534
}
55185535

@@ -5629,6 +5646,15 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
56295646
restoreOffset2.cancel();
56305647
--numAvailabilityAttrs;
56315648
}
5649+
5650+
// Hack: When deserialized from some un-supported @available attr decl, we should remove it
5651+
// @available (iOS, macOS, visionOS) -> @available (iOS, macOS)
5652+
filterUnsupportedPlatformKinds(availabilityAttrs);
5653+
if (availabilityAttrs.empty()) {
5654+
// If attr list is empty, then remove this attr
5655+
skipAttr = true;
5656+
break;
5657+
}
56325658

56335659
auto specializedSig = MF.getGenericSignature(specializedSigID);
56345660
Attr = SpecializeAttr::create(ctx, exported != 0, specializationKind,

0 commit comments

Comments
 (0)