Skip to content

Do even less availability checking under -disable-availability-checking. #4214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
}

static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
DiagnosticEngine &Diags, bool isImmediate) {
DiagnosticEngine &Diags,
const FrontendOptions &FrontendOpts) {
using namespace options;

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

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
Opts.DisableAvailabilityChecking = true;

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

if (ParseLangArgs(LangOpts, ParsedArgs, Diags,
FrontendOpts.actionIsImmediate())) {
if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
return true;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,9 +2045,6 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName(), call);
}

if (TC.getLangOpts().DisableAvailabilityChecking)
return false;

// Diagnose for potential unavailability
auto maybeUnavail = TC.checkDeclarationAvailability(D, R.Start, DC);
if (maybeUnavail.hasValue()) {
Expand Down Expand Up @@ -3582,7 +3579,8 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
diagSyntacticUseRestrictions(TC, E, DC, isExprStmt);
diagRecursivePropertyAccess(TC, E, DC);
diagnoseImplicitSelfUseInClosure(TC, E, DC);
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
if (!TC.getLangOpts().DisableAvailabilityChecking)
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
if (TC.Context.LangOpts.EnableObjCInterop)
diagDeprecatedObjCSelectors(TC, DC, E);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,8 @@ Type TypeChecker::resolveIdentifierType(
bool AllowPotentiallyUnavailableProtocol =
options.contains(TR_InheritanceClause);

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

if (Context.LangOpts.DisableAvailabilityChecking)
options |= TR_AllowUnavailable;

switch (repr->getKind()) {
case TypeReprKind::Error:
return ErrorType::get(Context);
Expand Down Expand Up @@ -1782,9 +1785,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,

if (base) {
Optional<MetatypeRepresentation> storedRepr;
// The instance type is not a SIL type. We still want to allow
// unavailable references, though.
auto instanceOptions = options - TR_SILType | TR_AllowUnavailable;
// The instance type is not a SIL type.
auto instanceOptions = options - TR_SILType;
auto instanceTy = resolveType(base, instanceOptions);
if (!instanceTy || instanceTy->is<ErrorType>())
return instanceTy;
Expand Down
4 changes: 0 additions & 4 deletions test/Sema/availability_versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1068,15 +1068,12 @@ func functionWithUnavailableInDeadBranch() {

localFuncAvailableOn10_51() // no-warning

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

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

// CHECK:error: 'explicitlyUnavailable()' is unavailable
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
}
}
Expand Down Expand Up @@ -1624,6 +1621,5 @@ func useShortFormAvailable() {
// expected-note@-1 {{add @available attribute to enclosing global function}}
// expected-note@-2 {{add 'if #available' version check}}

// CHECK:error: 'unavailableWins()' is unavailable
unavailableWins() // expected-error {{'unavailableWins()' is unavailable}}
}
1 change: 1 addition & 0 deletions tools/sil-extract/SILExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ int main(int argc, char **argv) {
Invocation.setRuntimeResourcePath(ResourceDir);
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
Invocation.setParseStdlib();
Invocation.getLangOptions().DisableAvailabilityChecking = true;
Invocation.getLangOptions().EnableAccessControl = false;
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;

Expand Down
1 change: 1 addition & 0 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ int main(int argc, char **argv) {
// cache.
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
Invocation.setParseStdlib();
Invocation.getLangOptions().DisableAvailabilityChecking = true;
Invocation.getLangOptions().EnableAccessControl = false;
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;

Expand Down