Skip to content

Commit 970ffab

Browse files
committed
Merge branch 'master' of https://github.com/apple/swift
2 parents 00d771c + 2493986 commit 970ffab

File tree

62 files changed

+499
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+499
-189
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ option(SWIFT_INCLUDE_DOCS
9393
"Create targets for building docs."
9494
TRUE)
9595

96+
set(_swift_include_apinotes_default FALSE)
97+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
98+
set(_swift_include_apinotes_default TRUE)
99+
endif()
100+
101+
option(SWIFT_INCLUDE_APINOTES
102+
"Create targets for installing the remaining apinotes in the built toolchain."
103+
${_swift_include_apinotes_default})
104+
96105
#
97106
# Miscellaneous User-configurable options.
98107
#
@@ -1042,12 +1051,8 @@ endif()
10421051
# https://bugs.swift.org/browse/SR-5975
10431052
add_subdirectory(stdlib)
10441053

1045-
if(SWIFT_BUILD_SDK_OVERLAY)
1046-
list_intersect("${SWIFT_APPLE_PLATFORMS}" "${SWIFT_SDKS}"
1047-
building_darwin_sdks)
1048-
if(building_darwin_sdks)
1049-
add_subdirectory(apinotes)
1050-
endif()
1054+
if(SWIFT_INCLUDE_APINOTES)
1055+
add_subdirectory(apinotes)
10511056
endif()
10521057

10531058
add_subdirectory(include)

apinotes/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ add_custom_target("copy_apinotes"
2828
COMMENT "Copying API notes to ${output_dir}"
2929
SOURCES "${sources}")
3030

31-
# This is treated as an OPTIONAL target because if we don't build the SDK
32-
# overlay, the files will be missing anyway. It also allows us to build
33-
# single overlays without installing the API notes.
3431
swift_install_in_component(DIRECTORY "${output_dir}"
3532
DESTINATION "lib/swift/"
36-
COMPONENT sdk-overlay
37-
OPTIONAL)
33+
COMPONENT compiler)

include/swift/ABI/Metadata.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ template <typename Runtime> struct TargetStructMetadata;
457457
template <typename Runtime> struct TargetOpaqueMetadata;
458458
template <typename Runtime> struct TargetValueMetadata;
459459
template <typename Runtime> struct TargetForeignClassMetadata;
460+
template <typename Runtime> struct TargetContextDescriptor;
460461
template <typename Runtime> class TargetTypeContextDescriptor;
461462
template <typename Runtime> class TargetClassDescriptor;
462463
template <typename Runtime> class TargetValueTypeDescriptor;
@@ -2085,12 +2086,12 @@ struct TargetTypeMetadataRecord {
20852086
private:
20862087
union {
20872088
/// A direct reference to a nominal type descriptor.
2088-
RelativeDirectPointerIntPair<TargetTypeContextDescriptor<Runtime>,
2089+
RelativeDirectPointerIntPair<TargetContextDescriptor<Runtime>,
20892090
TypeReferenceKind>
20902091
DirectNominalTypeDescriptor;
20912092

20922093
/// An indirect reference to a nominal type descriptor.
2093-
RelativeDirectPointerIntPair<TargetTypeContextDescriptor<Runtime> * const,
2094+
RelativeDirectPointerIntPair<TargetContextDescriptor<Runtime> * const,
20942095
TypeReferenceKind>
20952096
IndirectNominalTypeDescriptor;
20962097

@@ -2103,8 +2104,8 @@ struct TargetTypeMetadataRecord {
21032104
return DirectNominalTypeDescriptor.getInt();
21042105
}
21052106

2106-
const TargetTypeContextDescriptor<Runtime> *
2107-
getTypeContextDescriptor() const {
2107+
const TargetContextDescriptor<Runtime> *
2108+
getContextDescriptor() const {
21082109
switch (getTypeKind()) {
21092110
case TypeReferenceKind::DirectTypeDescriptor:
21102111
return DirectNominalTypeDescriptor.getPointer();
@@ -3043,11 +3044,16 @@ struct TargetOpaqueTypeDescriptor final
30433044
return getNumUnderlyingTypeArguments();
30443045
}
30453046

3047+
const RelativeDirectPointer<const char> &
3048+
getUnderlyingTypeArgumentMangledName(unsigned i) const {
3049+
assert(i < getNumUnderlyingTypeArguments());
3050+
return (this
3051+
->template getTrailingObjects<RelativeDirectPointer<const char>>())[i];
3052+
}
3053+
30463054
StringRef getUnderlyingTypeArgument(unsigned i) const {
30473055
assert(i < getNumUnderlyingTypeArguments());
3048-
const char *ptr =
3049-
(this->template getTrailingObjects<RelativeDirectPointer<const char>>())[i];
3050-
3056+
const char *ptr = getUnderlyingTypeArgumentMangledName(i);
30513057
return Demangle::makeSymbolicMangledNameStringRef(ptr);
30523058
}
30533059

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ class ASTMangler : public Mangler {
171171

172172
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
173173

174+
std::string mangleOpaqueTypeDescriptor(const OpaqueTypeDecl *decl);
175+
174176
std::string mangleDeclType(const ValueDecl *decl);
175177

176178
std::string mangleObjCRuntimeName(const NominalTypeDecl *Nominal);

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ class LoadedFile : public FileUnit {
13971397
}
13981398

13991399
/// Returns the Swift module that overlays a Clang module.
1400-
virtual ModuleDecl *getAdapterModule() const { return nullptr; }
1400+
virtual ModuleDecl *getOverlayModule() const { return nullptr; }
14011401

14021402
virtual bool isSystemModule() const { return false; }
14031403

include/swift/AST/Types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,6 +4803,18 @@ class OpaqueTypeArchetypeType final : public ArchetypeType,
48034803
return T->getKind() == TypeKind::OpaqueTypeArchetype;
48044804
}
48054805

4806+
/// Get the ordinal of the type within the declaration's opaque signature.
4807+
///
4808+
/// If a method declared its return type as:
4809+
///
4810+
/// func foo() -> (some P, some Q)
4811+
///
4812+
/// then the underlying type of `some P` would be ordinal 0, and `some Q` would be ordinal 1.
4813+
unsigned getOrdinal() const {
4814+
// TODO: multiple opaque types
4815+
return 0;
4816+
}
4817+
48064818
static void Profile(llvm::FoldingSetNodeID &ID,
48074819
OpaqueTypeDecl *OpaqueDecl,
48084820
SubstitutionMap Substitutions);

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class ClangImporterOptions {
9494
/// and this is not set, clang will rebuild the module.
9595
bool DisableModulesValidateSystemHeaders = false;
9696

97-
/// When set, don't look for or load adapter modules.
98-
bool DisableAdapterModules = false;
97+
/// When set, don't look for or load overlays.
98+
bool DisableOverlayModules = false;
9999

100100
/// When set, don't enforce warnings with -Werror.
101101
bool DebuggerSupport = false;
@@ -118,7 +118,7 @@ class ClangImporterOptions {
118118
Code = hash_combine(Code, InferImportAsMember);
119119
Code = hash_combine(Code, DisableSwiftBridgeAttr);
120120
Code = hash_combine(Code, DisableModulesValidateSystemHeaders);
121-
Code = hash_combine(Code, DisableAdapterModules);
121+
Code = hash_combine(Code, DisableOverlayModules);
122122
return Code;
123123
}
124124
};

include/swift/ClangImporter/ClangModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ModuleLoader;
3434
class ClangModuleUnit final : public LoadedFile {
3535
ClangImporter::Implementation &owner;
3636
const clang::Module *clangModule;
37-
llvm::PointerIntPair<ModuleDecl *, 1, bool> adapterModule;
37+
llvm::PointerIntPair<ModuleDecl *, 1, bool> overlayModule;
3838
mutable ArrayRef<ModuleDecl::ImportedModule> importedModulesForLookup;
3939
/// The metadata of the underlying Clang module.
4040
clang::ExternalASTSource::ASTSourceDescriptor ASTSourceDescriptor;
@@ -57,7 +57,7 @@ class ClangModuleUnit final : public LoadedFile {
5757
bool isTopLevel() const;
5858

5959
/// Returns the Swift module that overlays this Clang module.
60-
ModuleDecl *getAdapterModule() const override;
60+
ModuleDecl *getOverlayModule() const override;
6161

6262
/// Retrieve the "exported" name of the module, which is usually the module
6363
/// name, but might be the name of the public module through which this

include/swift/IRGen/Linking.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,10 @@ class LinkEntity {
770770
return entity;
771771
}
772772

773-
static LinkEntity forAnonymousDescriptor(DeclContext *dc) {
773+
static LinkEntity forAnonymousDescriptor(
774+
PointerUnion<DeclContext *, VarDecl *> dc) {
774775
LinkEntity entity;
775-
entity.Pointer = const_cast<void*>(static_cast<const void*>(dc));
776+
entity.Pointer = dc.getOpaqueValue();
776777
entity.SecondaryPointer = nullptr;
777778
entity.Data =
778779
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::AnonymousDescriptor));
@@ -1015,9 +1016,10 @@ class LinkEntity {
10151016
return reinterpret_cast<ExtensionDecl*>(Pointer);
10161017
}
10171018

1018-
const DeclContext *getDeclContext() const {
1019+
const PointerUnion<DeclContext *, VarDecl *> getAnonymousDeclContext() const {
10191020
assert(getKind() == Kind::AnonymousDescriptor);
1020-
return reinterpret_cast<DeclContext*>(Pointer);
1021+
return PointerUnion<DeclContext *, VarDecl *>
1022+
::getFromOpaqueValue(reinterpret_cast<void*>(Pointer));
10211023
}
10221024

10231025
SILFunction *getSILFunction() const {

include/swift/Remote/MetadataReader.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,35 @@ class MetadataReader {
724724
return nullptr;
725725
return buildContextMangling(context, Dem);
726726
}
727+
728+
/// Read the mangled underlying type from an opaque type descriptor.
729+
BuiltType
730+
readUnderlyingTypeForOpaqueTypeDescriptor(StoredPointer contextAddr,
731+
unsigned ordinal) {
732+
auto context = readContextDescriptor(contextAddr);
733+
if (!context)
734+
return BuiltType();
735+
if (context->getKind() != ContextDescriptorKind::OpaqueType)
736+
return BuiltType();
737+
738+
auto opaqueType =
739+
reinterpret_cast<const TargetOpaqueTypeDescriptor<Runtime> *>(
740+
context.getLocalBuffer());
741+
742+
if (ordinal >= opaqueType->getNumUnderlyingTypeArguments())
743+
return BuiltType();
744+
745+
auto nameAddr = resolveRelativeField(context,
746+
opaqueType->getUnderlyingTypeArgumentMangledName(ordinal));
747+
748+
Demangle::Demangler Dem;
749+
auto node = readMangledName(RemoteAddress(nameAddr),
750+
MangledNameKind::Type, Dem);
751+
if (!node)
752+
return BuiltType();
753+
754+
return decodeMangledType(node);
755+
}
727756

728757
bool isTaggedPointer(StoredPointer objectAddress) {
729758
if (getTaggedPointerEncoding() != TaggedPointerEncodingKind::Extended)
@@ -1396,6 +1425,12 @@ class MetadataReader {
13961425
case ContextDescriptorKind::Protocol:
13971426
baseSize = sizeof(TargetProtocolDescriptor<Runtime>);
13981427
break;
1428+
case ContextDescriptorKind::OpaqueType:
1429+
baseSize = sizeof(TargetOpaqueTypeDescriptor<Runtime>);
1430+
metadataInitSize =
1431+
sizeof(typename Runtime::template RelativeDirectPointer<const char>)
1432+
* flags.getKindSpecificFlags();
1433+
break;
13991434
default:
14001435
// We don't know about this kind of context.
14011436
return nullptr;
@@ -2076,6 +2111,29 @@ class MetadataReader {
20762111
// contexts; just create the node directly here and return.
20772112
return dem.createNode(nodeKind, std::move(moduleName));
20782113
}
2114+
2115+
case ContextDescriptorKind::OpaqueType: {
2116+
// The opaque type may have a named anonymous context for us to map
2117+
// back to its defining decl.
2118+
if (!parentDescriptorResult)
2119+
return nullptr;
2120+
auto anonymous =
2121+
dyn_cast_or_null<TargetAnonymousContextDescriptor<Runtime>>(
2122+
parentDescriptorResult->getLocalBuffer());
2123+
if (!anonymous)
2124+
return nullptr;
2125+
2126+
auto mangledNode =
2127+
demangleAnonymousContextName(*parentDescriptorResult, dem);
2128+
if (!mangledNode)
2129+
return nullptr;
2130+
if (mangledNode->getKind() == Node::Kind::Global)
2131+
mangledNode = mangledNode->getChild(0);
2132+
2133+
auto opaqueNode = dem.createNode(Node::Kind::OpaqueReturnTypeOf);
2134+
opaqueNode->addChild(mangledNode, dem);
2135+
return opaqueNode;
2136+
}
20792137

20802138
default:
20812139
// Not a kind of context we know about.

0 commit comments

Comments
 (0)