Serialization: Skip invalid @available attributes during lazy serialization.

When performing lazy module serialization, we may be making the first attempt
to turn an `AvailableAttr` into a `SemanticAvailableAttr`. If it turns out the
attribute is invalid at that point, we need to skip it instead of assuming
that the attribute will always be valid there.

Resolves rdar://147539902.
This commit is contained in:
Allan Shortlidge
2025-03-21 15:42:49 -07:00
parent 35c8ba878a
commit 3af72e4dca
2 changed files with 17 additions and 1 deletions

View File

@@ -3093,7 +3093,11 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
case DeclAttrKind::Available: {
auto theAttr = D->getSemanticAvailableAttr(cast<AvailableAttr>(DA));
assert(theAttr);
// In lazy typechecking mode, it's possible that we just discovered that
// the attribute is invalid.
if (!theAttr)
return;
ENCODE_VER_TUPLE(Introduced, theAttr->getIntroduced())
ENCODE_VER_TUPLE(Deprecated, theAttr->getDeprecated())

View File

@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend -swift-version 5 %s -module-name lazy_typecheck -enable-library-evolution -parse-as-library -emit-module -emit-module-path /dev/null -experimental-lazy-typecheck -experimental-skip-non-inlinable-function-bodies -experimental-skip-non-exportable-decls
public protocol P {
func req()
}
@available(macOS, renamed: "P")
@available(iOS, renamed: "P")
@available(tvOS, renamed: "P")
@available(watchOS, renamed: "P")
@available(visionOS, renamed: "P")
public typealias Q = P