Skip to content

Commit c62bfdd

Browse files
committed
Sema: Retire ExportContext::shouldDiagnoseDeclAsUnavailable().
NFC.
1 parent 01177b0 commit c62bfdd

File tree

3 files changed

+6
-43
lines changed

3 files changed

+6
-43
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -345,40 +345,6 @@ static bool computeContainedByDeploymentTarget(AvailabilityScope *scope,
345345
AvailabilityRange::forDeploymentTarget(ctx));
346346
}
347347

348-
/// Returns true if the reference or any of its parents is an
349-
/// unconditional unavailable declaration for the same platform.
350-
static bool isInsideCompatibleUnavailableDeclaration(
351-
const Decl *D, AvailabilityContext availabilityContext,
352-
const SemanticAvailableAttr &attr) {
353-
if (!availabilityContext.isUnavailable())
354-
return false;
355-
356-
if (!attr.isUnconditionallyUnavailable())
357-
return false;
358-
359-
// Refuse calling universally unavailable functions from unavailable code,
360-
// but allow the use of types.
361-
auto declDomain = attr.getDomain();
362-
if (!isa<TypeDecl>(D) && !isa<ExtensionDecl>(D)) {
363-
if (declDomain.isUniversal() || declDomain.isSwiftLanguage())
364-
return false;
365-
}
366-
367-
return availabilityContext.containsUnavailableDomain(declDomain);
368-
}
369-
370-
std::optional<SemanticAvailableAttr>
371-
ExportContext::shouldDiagnoseDeclAsUnavailable(const Decl *D) const {
372-
auto attr = D->getUnavailableAttr();
373-
if (!attr)
374-
return std::nullopt;
375-
376-
if (isInsideCompatibleUnavailableDeclaration(D, Availability, *attr))
377-
return std::nullopt;
378-
379-
return attr;
380-
}
381-
382348
static bool shouldAllowReferenceToUnavailableInSwiftDeclaration(
383349
const Decl *D, const ExportContext &where) {
384350
auto *DC = where.getDeclContext();

lib/Sema/TypeCheckAvailability.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,6 @@ class ExportContext {
201201
/// Get the ExportabilityReason for diagnostics. If this is 'None', there
202202
/// are no restrictions on referencing unexported declarations.
203203
std::optional<ExportabilityReason> getExportabilityReason() const;
204-
205-
/// If \p decl is unconditionally unavailable in this context, and the context
206-
/// is not also unavailable in the same way, then this returns the specific
207-
/// `@available` attribute that makes the decl unavailable. Otherwise, returns
208-
/// nullptr.
209-
std::optional<SemanticAvailableAttr>
210-
shouldDiagnoseDeclAsUnavailable(const Decl *decl) const;
211204
};
212205

213206
/// Check if a declaration is exported as part of a module's external interface.

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4963,12 +4963,16 @@ static bool diagnoseTypeWitnessAvailability(
49634963
bool shouldError =
49644964
ctx.LangOpts.EffectiveLanguageVersion.isVersionAtLeast(warnBeforeVersion);
49654965

4966-
if (auto attr = where.shouldDiagnoseDeclAsUnavailable(witness)) {
4966+
auto constraint =
4967+
getAvailabilityConstraintsForDecl(witness, where.getAvailability())
4968+
.getPrimaryConstraint();
4969+
if (constraint && constraint->isUnavailable()) {
4970+
auto attr = constraint->getAttr();
49674971
ctx.addDelayedConformanceDiag(
49684972
conformance, shouldError,
49694973
[witness, assocType, attr](NormalProtocolConformance *conformance) {
49704974
SourceLoc loc = getLocForDiagnosingWitness(conformance, witness);
4971-
EncodedDiagnosticMessage encodedMessage(attr->getMessage());
4975+
EncodedDiagnosticMessage encodedMessage(attr.getMessage());
49724976
auto &ctx = conformance->getDeclContext()->getASTContext();
49734977
ctx.Diags
49744978
.diagnose(loc, diag::witness_unavailable, witness,

0 commit comments

Comments
 (0)