Skip to content

Commit 5ac6283

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 36ad1a4 + c266662 commit 5ac6283

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

docs/ABIStabilityManifesto.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ ABI stability means nailing down type layout and making decisions about how to h
213213

214214
For all of the areas discussed above, more aggressive layout improvements may be invented in the post-ABI stability future. For example, we may want to explore rearranging and packing nested type data members with outer type data members. Such improvements would have to be done in an ABI-additive fashion through deployment target and/or min-version checking. This may mean that the module file will need to track per-type ABI versioning information.
215215

216-
A potentially out of date description of Swift's current type layout can be found in the [Type Layout docs](https://github.com/apple/swift/blob/master/docs/ABI.rst#type-layout).
216+
A potentially out of date description of Swift's current type layout can be found in the [Type Layout docs](https://github.com/apple/swift/blob/master/docs/ABI/TypeLayout.rst).
217217

218218

219219
## <a name="metadata"></a>Type Metadata
@@ -230,7 +230,7 @@ Metadata has many historical artifacts in its representation that we want to cle
230230

231231
Stabilizing the ABI means producing a precise technical specification for the fixed part of the metadata layout of all language constructs so that future compilers and tools can continue to read and write them. A prose description is not necessarily needed, though explanations are useful. We will also want to carve out extra space for areas where it is likely to be needed for future functionality [[SR-3731](https://bugs.swift.org/browse/SR-3731)].
232232

233-
For more, but potentially out of date, details see the [Type Metadata docs](https://github.com/apple/swift/blob/master/docs/ABI.rst#type-metadata).
233+
For more, but potentially out of date, details see the [Type Metadata docs](https://github.com/apple/swift/blob/master/docs/ABI/TypeMetadata.rst).
234234

235235
### Generic Parameters
236236

@@ -284,7 +284,7 @@ In addition to common metadata entries, function type metadata stores informatio
284284

285285
Mangling is used to produce unique symbols. It applies to both external (public) symbols as well as internal or hidden symbols. Only the mangling scheme for external symbols is part of ABI.
286286

287-
ABI stability means a stable mangling scheme, fully specified so that future compilers and tools can honor it. For a potentially out-of-date specification of what the mangling currently looks like, see the [Name Mangling docs](https://github.com/apple/swift/blob/master/docs/ABI.rst#mangling).
287+
ABI stability means a stable mangling scheme, fully specified so that future compilers and tools can honor it. For a potentially out-of-date specification of what the mangling currently looks like, see the [Name Mangling docs](https://github.com/apple/swift/blob/master/docs/ABI/Mangling.rst).
288288

289289
There are some corner cases currently in the mangling scheme that should be fixed before declaring ABI stability. We need to come up with a canonicalization of generic and protocol requirements to allow for order-agnostic mangling [[SR-3733](https://bugs.swift.org/browse/SR-3733)]. We also may decide to more carefully mangle variadicity of function parameters, etc [[SR-3734](https://bugs.swift.org/browse/SR-3734)]. Most often, though, mangling improvements focus on reducing symbol size.
290290

lib/ClangImporter/ClangImporter.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ getClangTopLevelOwningModule(ClangNode Node,
20232023
}
20242024

20252025
static bool isVisibleFromModule(const ClangModuleUnit *ModuleFilter,
2026-
const ValueDecl *VD) {
2026+
ValueDecl *VD) {
20272027
assert(ModuleFilter);
20282028

20292029
auto ContainingUnit = VD->getDeclContext()->getModuleScopeContext();
@@ -2038,24 +2038,34 @@ static bool isVisibleFromModule(const ClangModuleUnit *ModuleFilter,
20382038

20392039
auto ClangNode = VD->getClangNode();
20402040
if (!ClangNode) {
2041-
// If we synthesized a ValueDecl, it won't have a Clang node. But so far
2042-
// all the situations where we synthesize top-level declarations are
2043-
// situations where we don't have to worry about C redeclarations.
2044-
// We should only consider the declaration visible from its owning module.
2041+
// If we synthesized a ValueDecl, it won't have a Clang node. Find the
2042+
// associated declaration that /does/ have a Clang node, and use that.
20452043
auto *SynthesizedTypeAttr =
20462044
VD->getAttrs().getAttribute<ClangImporterSynthesizedTypeAttr>();
20472045
assert(SynthesizedTypeAttr);
20482046

2049-
// When adding new ClangImporterSynthesizedTypeAttr::Kinds, make sure that
2050-
// the above statement still holds: "we don't want to allow these
2051-
// declarations to be treated as present in multiple modules".
20522047
switch (SynthesizedTypeAttr->getKind()) {
20532048
case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapper:
2054-
case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapperAnon:
2049+
case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapperAnon: {
2050+
ASTContext &Ctx = ContainingUnit->getASTContext();
2051+
auto LookupFlags =
2052+
NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
2053+
auto WrapperStruct = cast<StructDecl>(VD);
2054+
TinyPtrVector<ValueDecl *> LookupResults =
2055+
WrapperStruct->lookupDirect(Ctx.Id_Code, LookupFlags);
2056+
assert(!LookupResults.empty() && "imported error enum without Code");
2057+
2058+
auto CodeEnumIter = llvm::find_if(LookupResults,
2059+
[&](ValueDecl *Member) -> bool {
2060+
return Member->getDeclContext() == WrapperStruct;
2061+
});
2062+
assert(CodeEnumIter != LookupResults.end() &&
2063+
"could not find Code enum in wrapper struct");
2064+
assert((*CodeEnumIter)->hasClangNode());
2065+
ClangNode = (*CodeEnumIter)->getClangNode();
20552066
break;
20562067
}
2057-
2058-
return false;
2068+
}
20592069
}
20602070

20612071
// Macros can be "redeclared" by putting an equivalent definition in two
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
@import Foundation;
2+
#ifndef NO_IMPORT_BASE_FROM_REDECLARED
23
@import Base;
4+
#endif
35

46
extern NSString * const SomeErrorDomain;
57
// typedef NS_ERROR_ENUM(SomeErrorDomain, SomeErrorCode);
68
typedef enum SomeErrorCode : long SomeErrorCode;
7-
enum __attribute__((ns_error_domain(SomeErrorDomain))) SomeErrorCode : long;
9+
enum __attribute__((ns_error_domain(SomeErrorDomain))) SomeErrorCode : long
10+
#ifdef NO_IMPORT_BASE_FROM_REDECLARED
11+
{
12+
SomeErrorX,
13+
SomeErrorY
14+
}
15+
#endif
16+
;

test/ClangImporter/enum-error-redeclared.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify -enable-objc-interop -I %S/Inputs/custom-modules/RedeclaredErrorEnum
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify -enable-objc-interop -I %S/Inputs/custom-modules/RedeclaredErrorEnum -DIMPORT_BASE
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify -enable-objc-interop -I %S/Inputs/custom-modules/RedeclaredErrorEnum -DIMPORT_BASE -Xcc -DNO_IMPORT_BASE_FROM_REDECLARED
4+
5+
#if IMPORT_BASE
6+
import Base
7+
#endif
28

39
import Redeclared
410

0 commit comments

Comments
 (0)