mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #41647 from xymus/recover-from-anyobject-lookup
[Serialization] Recover from failures under AnyObjectLookup
This commit is contained in:
@@ -774,7 +774,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
|
|||||||
// one.
|
// one.
|
||||||
if (name.isSimpleName()) {
|
if (name.isSimpleName()) {
|
||||||
for (auto item : *iter) {
|
for (auto item : *iter) {
|
||||||
auto vd = cast<ValueDecl>(getDecl(item.second));
|
auto declOrError = getDeclChecked(item.second);
|
||||||
|
if (!declOrError) {
|
||||||
|
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||||
|
fatal(declOrError.takeError());
|
||||||
|
consumeError(declOrError.takeError());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vd = cast<ValueDecl>(declOrError.get());
|
||||||
auto dc = vd->getDeclContext();
|
auto dc = vd->getDeclContext();
|
||||||
while (!dc->getParent()->isModuleScopeContext())
|
while (!dc->getParent()->isModuleScopeContext())
|
||||||
dc = dc->getParent();
|
dc = dc->getParent();
|
||||||
@@ -784,7 +792,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto item : *iter) {
|
for (auto item : *iter) {
|
||||||
auto vd = cast<ValueDecl>(getDecl(item.second));
|
auto declOrError = getDeclChecked(item.second);
|
||||||
|
if (!declOrError) {
|
||||||
|
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||||
|
fatal(declOrError.takeError());
|
||||||
|
consumeError(declOrError.takeError());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vd = cast<ValueDecl>(declOrError.get());
|
||||||
if (!vd->getName().matchesRef(name))
|
if (!vd->getName().matchesRef(name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -800,7 +816,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto item : *iter) {
|
for (auto item : *iter) {
|
||||||
auto vd = cast<ValueDecl>(getDecl(item.second));
|
auto declOrError = getDeclChecked(item.second);
|
||||||
|
if (!declOrError) {
|
||||||
|
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||||
|
fatal(declOrError.takeError());
|
||||||
|
consumeError(declOrError.takeError());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vd = cast<ValueDecl>(declOrError.get());
|
||||||
results.push_back(vd);
|
results.push_back(vd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -818,6 +842,8 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
|
|||||||
for (auto item : list) {
|
for (auto item : list) {
|
||||||
auto decl = getDeclChecked(item.second);
|
auto decl = getDeclChecked(item.second);
|
||||||
if (!decl) {
|
if (!decl) {
|
||||||
|
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||||
|
fatal(decl.takeError());
|
||||||
llvm::consumeError(decl.takeError());
|
llvm::consumeError(decl.takeError());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -839,6 +865,8 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
|
|||||||
for (auto item : list) {
|
for (auto item : list) {
|
||||||
auto decl = getDeclChecked(item.second);
|
auto decl = getDeclChecked(item.second);
|
||||||
if (!decl) {
|
if (!decl) {
|
||||||
|
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||||
|
fatal(decl.takeError());
|
||||||
llvm::consumeError(decl.takeError());
|
llvm::consumeError(decl.takeError());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#import <Foundation.h>
|
||||||
|
|
||||||
|
@interface ImplOnlyBase: NSObject @end
|
||||||
@@ -14,3 +14,4 @@ module Typedefs { header "Typedefs.h" }
|
|||||||
module TypeRemovalObjC { header "TypeRemovalObjC.h" }
|
module TypeRemovalObjC { header "TypeRemovalObjC.h" }
|
||||||
module Types { header "Types.h" }
|
module Types { header "Types.h" }
|
||||||
module Conformance { header "Conformance.h" }
|
module Conformance { header "Conformance.h" }
|
||||||
|
module AnyObjectLookup { header "AnyObjectLookup.h" }
|
||||||
|
|||||||
29
test/Serialization/Recovery/anyobject-lookup.swift
Normal file
29
test/Serialization/Recovery/anyobject-lookup.swift
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/// Recover from searching though all possible methods on AnyObject.
|
||||||
|
/// rdar://89494507
|
||||||
|
|
||||||
|
// RUN: %empty-directory(%t)
|
||||||
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -DLIB_B %s -module-name B -emit-module-path %t/B.swiftmodule -I %t -I %S/Inputs/custom-modules -enable-library-evolution -swift-version 5
|
||||||
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -DLIB_C %s -I %t -verify
|
||||||
|
// Add this flag to the previous line to get back the original crash: -disable-deserialization-recovery
|
||||||
|
|
||||||
|
// REQUIRES: objc_interop
|
||||||
|
|
||||||
|
#if LIB_B
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
@_implementationOnly import AnyObjectLookup
|
||||||
|
|
||||||
|
@objc internal class InternalClass: ImplOnlyBase {
|
||||||
|
@objc func invisibleMethod() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elseif LIB_C
|
||||||
|
|
||||||
|
import B
|
||||||
|
|
||||||
|
func use(_ obj: AnyObject) {
|
||||||
|
obj.invisibleMethod() // expected-error {{value of type 'AnyObject' has no member 'invisibleMethod'}}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user