Skip to content
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
13 changes: 11 additions & 2 deletions include/swift/Demangling/StandardTypesMangling.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
/// STANDARD_TYPE(KIND, MANGLING, TYPENAME)
/// The 1-character MANGLING for a known TYPENAME of KIND.

STANDARD_TYPE(Structure, A, AutoreleasingUnsafeMutablePointer)
/// OBJC_INTEROP_STANDARD_TYPE(KIND, MANGLING, TYPENAME)
/// The 1-character MANGLING for a known TYPENAME of KIND, for a type that's
/// only available with ObjC interop enabled.

#ifndef OBJC_INTEROP_STANDARD_TYPE
#define OBJC_INTEROP_STANDARD_TYPE(KIND, MANGLING, TYPENAME) \
STANDARD_TYPE(KIND, MANGLING, TYPENAME)
#endif

OBJC_INTEROP_STANDARD_TYPE(Structure, A, AutoreleasingUnsafeMutablePointer)
STANDARD_TYPE(Structure, a, Array)
STANDARD_TYPE(Structure, b, Bool)
STANDARD_TYPE(Structure, c, UnicodeScalar)
STANDARD_TYPE(Structure, D, Dictionary)
STANDARD_TYPE(Structure, d, Double)
STANDARD_TYPE(Structure, f, Float)
Expand Down Expand Up @@ -66,3 +74,4 @@ STANDARD_TYPE(Protocol, Z, SignedInteger)
STANDARD_TYPE(Protocol, z, BinaryInteger)

#undef STANDARD_TYPE
#undef OBJC_INTEROP_STANDARD_TYPE
50 changes: 45 additions & 5 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,21 +708,61 @@ _findContextDescriptorInCache(TypeMetadataPrivateState &T,
return iter->getSecond();
}

#define DESCRIPTOR_MANGLING_SUFFIX_Structure Mn
#define DESCRIPTOR_MANGLING_SUFFIX_Enum Mn
#define DESCRIPTOR_MANGLING_SUFFIX_Protocol Mp

#define DESCRIPTOR_MANGLING_SUFFIX_(X) X
#define DESCRIPTOR_MANGLING_SUFFIX(KIND) \
DESCRIPTOR_MANGLING_SUFFIX_(DESCRIPTOR_MANGLING_SUFFIX_ ## KIND)

#define DESCRIPTOR_MANGLING_(CHAR, SUFFIX) \
$sS ## CHAR ## SUFFIX
#define DESCRIPTOR_MANGLING(CHAR, SUFFIX) DESCRIPTOR_MANGLING_(CHAR, SUFFIX)

#define STANDARD_TYPE(KIND, MANGLING, TYPENAME) \
extern "C" const ContextDescriptor DESCRIPTOR_MANGLING(MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND));

#if !SWIFT_OBJC_INTEROP
# define OBJC_INTEROP_STANDARD_TYPE(KIND, MANGLING, TYPENAME)
#endif

#include "swift/Demangling/StandardTypesMangling.def"

static const ContextDescriptor *
_findContextDescriptor(Demangle::NodePointer node,
Demangle::Demangler &Dem) {
const ContextDescriptor *foundContext = nullptr;
auto &T = TypeMetadataRecords.get();

// If we have a symbolic reference to a context, resolve it immediately.
Demangle::Demangler &Dem) {
NodePointer symbolicNode = node;
if (symbolicNode->getKind() == Node::Kind::Type)
symbolicNode = symbolicNode->getChild(0);

// If we have a symbolic reference to a context, resolve it immediately.
if (symbolicNode->getKind() == Node::Kind::TypeSymbolicReference) {
return cast<TypeContextDescriptor>(
(const ContextDescriptor *)symbolicNode->getIndex());
}

// Fast-path lookup for standard library type references with short manglings.
if (symbolicNode->getNumChildren() >= 2
&& symbolicNode->getChild(0)->getKind() == Node::Kind::Module
&& symbolicNode->getChild(0)->getText().equals("Swift")
&& symbolicNode->getChild(1)->getKind() == Node::Kind::Identifier) {
auto name = symbolicNode->getChild(1)->getText();

#define STANDARD_TYPE(KIND, MANGLING, TYPENAME) \
if (name.equals(#TYPENAME)) { \
return &DESCRIPTOR_MANGLING(MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND)); \
}
#if !SWIFT_OBJC_INTEROP
# define OBJC_INTEROP_STANDARD_TYPE(KIND, MANGLING, TYPENAME)
#endif

#include "swift/Demangling/StandardTypesMangling.def"
}

const ContextDescriptor *foundContext = nullptr;
auto &T = TypeMetadataRecords.get();

// Nothing to resolve if have a generic parameter.
if (symbolicNode->getKind() == Node::Kind::DependentGenericParamType)
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions test/SILGen/arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func arg_tuple(x: Int, y: Float) {}
arg_tuple(x: i, y: f)

func arg_deep_tuples(x: Int, y: (Float, UnicodeScalar)) {}
// CHECK-LABEL: sil hidden [ossa] @$ss15arg_deep_tuples1x1yySi_Sf_ScttF
// CHECK-LABEL: sil hidden [ossa] @$ss15arg_deep_tuples1x1yySi_Sf_s13UnicodeScalarVttF
// CHECK: bb0([[X:%[0-9]+]] : $Int, [[Y_0:%[0-9]+]] : $Float, [[Y_1:%[0-9]+]] : $UnicodeScalar):

arg_deep_tuples(x:i, y:(f, c))
Expand All @@ -37,7 +37,7 @@ var named_subtuple = (x:f, y:c)
arg_deep_tuples(x:i, y: named_subtuple)

func arg_deep_tuples_2(x: Int, _: (y: Float, z: UnicodeScalar)) {}
// CHECK-LABEL: sil hidden [ossa] @$ss17arg_deep_tuples_21x_ySi_Sf1y_Sc1zttF
// CHECK-LABEL: sil hidden [ossa] @$ss17arg_deep_tuples_21x_ySi_Sf1y_s13UnicodeScalarV1zttF
// CHECK: bb0([[X:%[0-9]+]] : $Int, [[Y:%[0-9]+]] : $Float, [[Z:%[0-9]+]] : $UnicodeScalar):

arg_deep_tuples_2(x: i, (f, c))
Expand Down