Skip to content

Commit 280c20d

Browse files
jrose-appleMax Moiseev
authored andcommitted
Do even less availability checking under -disable-availability-checking. (swiftlang#4214)
...and make sure we're in that mode for SIL inputs and for sil-opt and sil-extract, even when working with AST types and declarations rather than SIL types. Without this, we get zillions of deprecation warnings coming out of the validation tests SIL/parse_stdlib_*.sil, which dump the standard library and then attempt to re-parse it. This has been causing the "long" tests to take, well, too long.
1 parent 3507271 commit 280c20d

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
727727
}
728728

729729
static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
730-
DiagnosticEngine &Diags, bool isImmediate) {
730+
DiagnosticEngine &Diags,
731+
const FrontendOptions &FrontendOpts) {
731732
using namespace options;
732733

733734
Opts.AttachCommentsToDecls |= Args.hasArg(OPT_dump_api_path);
@@ -745,6 +746,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
745746

746747
Opts.DisableAvailabilityChecking |=
747748
Args.hasArg(OPT_disable_availability_checking);
749+
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
750+
Opts.DisableAvailabilityChecking = true;
748751

749752
if (auto A = Args.getLastArg(OPT_enable_access_control,
750753
OPT_disable_access_control)) {
@@ -1327,8 +1330,7 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
13271330
return true;
13281331
}
13291332

1330-
if (ParseLangArgs(LangOpts, ParsedArgs, Diags,
1331-
FrontendOpts.actionIsImmediate())) {
1333+
if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
13321334
return true;
13331335
}
13341336

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,9 +2040,6 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
20402040
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName(), call);
20412041
}
20422042

2043-
if (TC.getLangOpts().DisableAvailabilityChecking)
2044-
return false;
2045-
20462043
// Diagnose for potential unavailability
20472044
auto maybeUnavail = TC.checkDeclarationAvailability(D, R.Start, DC);
20482045
if (maybeUnavail.hasValue()) {
@@ -3574,7 +3571,8 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
35743571
diagSyntacticUseRestrictions(TC, E, DC, isExprStmt);
35753572
diagRecursivePropertyAccess(TC, E, DC);
35763573
diagnoseImplicitSelfUseInClosure(TC, E, DC);
3577-
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
3574+
if (!TC.getLangOpts().DisableAvailabilityChecking)
3575+
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
35783576
if (TC.Context.LangOpts.EnableObjCInterop)
35793577
diagDeprecatedObjCSelectors(TC, DC, E);
35803578
}

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,8 @@ Type TypeChecker::resolveIdentifierType(
14411441
bool AllowPotentiallyUnavailableProtocol =
14421442
options.contains(TR_InheritanceClause);
14431443

1444-
// Check the availability of the type. Skip checking for SIL.
1445-
if (!(options & TR_SILType) && !(options & TR_AllowUnavailable) &&
1444+
// Check the availability of the type.
1445+
if (!(options & TR_AllowUnavailable) &&
14461446
diagnoseAvailability(result, IdType,
14471447
Components.back()->getIdLoc(), DC, *this,
14481448
AllowPotentiallyUnavailableProtocol)) {
@@ -1664,6 +1664,9 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
16641664
options -= TR_FunctionInput;
16651665
}
16661666

1667+
if (Context.LangOpts.DisableAvailabilityChecking)
1668+
options |= TR_AllowUnavailable;
1669+
16671670
switch (repr->getKind()) {
16681671
case TypeReprKind::Error:
16691672
return ErrorType::get(Context);
@@ -1768,9 +1771,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
17681771

17691772
if (base) {
17701773
Optional<MetatypeRepresentation> storedRepr;
1771-
// The instance type is not a SIL type. We still want to allow
1772-
// unavailable references, though.
1773-
auto instanceOptions = options - TR_SILType | TR_AllowUnavailable;
1774+
// The instance type is not a SIL type.
1775+
auto instanceOptions = options - TR_SILType;
17741776
auto instanceTy = resolveType(base, instanceOptions);
17751777
if (!instanceTy || instanceTy->is<ErrorType>())
17761778
return instanceTy;

test/Sema/availability_versions.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,12 @@ func functionWithUnavailableInDeadBranch() {
10681068

10691069
localFuncAvailableOn10_51() // no-warning
10701070

1071-
// We still want to error on references to explicitly unavailable symbols
1072-
// CHECK:error: 'explicitlyUnavailable()' is unavailable
10731071
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
10741072
}
10751073

10761074
guard #available(iOS 8.0, *) else {
10771075
_ = globalFuncAvailableOn10_51() // no-warning
10781076

1079-
// CHECK:error: 'explicitlyUnavailable()' is unavailable
10801077
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
10811078
}
10821079
}
@@ -1624,6 +1621,5 @@ func useShortFormAvailable() {
16241621
// expected-note@-1 {{add @available attribute to enclosing global function}}
16251622
// expected-note@-2 {{add 'if #available' version check}}
16261623

1627-
// CHECK:error: 'unavailableWins()' is unavailable
16281624
unavailableWins() // expected-error {{'unavailableWins()' is unavailable}}
16291625
}

tools/sil-extract/SILExtract.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int main(int argc, char **argv) {
163163
Invocation.setRuntimeResourcePath(ResourceDir);
164164
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
165165
Invocation.setParseStdlib();
166+
Invocation.getLangOptions().DisableAvailabilityChecking = true;
166167
Invocation.getLangOptions().EnableAccessControl = false;
167168
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
168169

tools/sil-opt/SILOpt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int main(int argc, char **argv) {
210210
// cache.
211211
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
212212
Invocation.setParseStdlib();
213+
Invocation.getLangOptions().DisableAvailabilityChecking = true;
213214
Invocation.getLangOptions().EnableAccessControl = false;
214215
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
215216

0 commit comments

Comments
 (0)