Skip to content

Commit e804c93

Browse files
committed
Sema: Retire ExportContext::shouldDiagnoseDeclAsUnavailable().
NFC.
1 parent 949a6c6 commit e804c93

File tree

3 files changed

+6
-43
lines changed

3 files changed

+6
-43
lines changed

lib/Sema/TypeCheckAvailability.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -346,40 +346,6 @@ static bool computeContainedByDeploymentTarget(AvailabilityScope *scope,
346346
AvailabilityRange::forDeploymentTarget(ctx));
347347
}
348348

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

lib/Sema/TypeCheckAvailability.h

-7
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -4964,12 +4964,16 @@ static bool diagnoseTypeWitnessAvailability(
49644964
bool shouldError =
49654965
ctx.LangOpts.EffectiveLanguageVersion.isVersionAtLeast(warnBeforeVersion);
49664966

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

0 commit comments

Comments
 (0)