mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Serialization] Name lookup hack for mixed omit-needless-words/non-omit-needless-words.
This egregious hack makes it so that we can properly dump APIs using "-enable-omit-needless-words" even when the compiler was built without it.
This commit is contained in:
@@ -1051,11 +1051,47 @@ Decl *ModuleFile::resolveCrossReference(Module *M, uint32_t pathLen) {
|
||||
if (!isType)
|
||||
pathTrace.addType(filterTy);
|
||||
|
||||
bool retrying = false;
|
||||
retry:
|
||||
|
||||
M->lookupQualified(ModuleType::get(M), name,
|
||||
NL_QualifiedDefault | NL_KnownNoDependency,
|
||||
/*typeResolver=*/nullptr, values);
|
||||
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt, None,
|
||||
values);
|
||||
|
||||
// HACK HACK HACK: Omit-needless-words hack to try to cope with
|
||||
// the "NS" prefix being added/removed. No "real" compiler mode
|
||||
// has to go through this path: a Swift 2 compiler will have the
|
||||
// prefix, while a Swift 3 compiler will not have the
|
||||
// prefix. However, one can set OmitNeedlessWords in a Swift 2
|
||||
// compiler to get API dumps and perform basic testing; this hack
|
||||
// keeps that working.
|
||||
if (values.empty() && !retrying &&
|
||||
getContext().LangOpts.OmitNeedlessWords &&
|
||||
(M->getName().str() == "ObjectiveC" ||
|
||||
M->getName().str() == "Foundation")) {
|
||||
if (name.str().startswith("NS")) {
|
||||
if (name.str().size() > 2 && name.str() != "NSCocoaError") {
|
||||
auto known = getKnownFoundationEntity(name.str());
|
||||
if (!known || !nameConflictsWithStandardLibrary(*known)) {
|
||||
// FIXME: lowercasing magic for non-types.
|
||||
name = getContext().getIdentifier(name.str().substr(2));
|
||||
retrying = true;
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SmallString<16> buffer;
|
||||
buffer += "NS";
|
||||
buffer += name.str();
|
||||
// FIXME: Try uppercasing for non-types.
|
||||
name = getContext().getIdentifier(buffer);
|
||||
retrying = true;
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user