Skip to content

Commit 19d9ebd

Browse files
committed
Revert "[AST] De/mangling for functions with generic sigs."
This reverts commit dbe689a.
1 parent 75dcd34 commit 19d9ebd

File tree

5 files changed

+91
-160
lines changed

5 files changed

+91
-160
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class ASTBuilder {
5959
using BuiltType = swift::Type;
6060
using BuiltTypeDecl = swift::GenericTypeDecl *; // nominal or type alias
6161
using BuiltProtocolDecl = swift::ProtocolDecl *;
62-
using BuiltSubstitution = std::pair<Type, Type>;
63-
using BuiltRequirement = swift::Requirement;
6462
explicit ASTBuilder(ASTContext &ctx) : Ctx(ctx) {}
6563

6664
ASTContext &getASTContext() { return Ctx; }
@@ -103,14 +101,11 @@ class ASTBuilder {
103101
FunctionMetadataDifferentiabilityKind diffKind);
104102

105103
Type createImplFunctionType(
106-
Demangle::ImplParameterConvention calleeConvention,
107-
BuiltRequirement *witnessMethodConformanceRequirement,
108-
ArrayRef<BuiltType> GenericParameters,
109-
ArrayRef<BuiltRequirement> Requirements,
110-
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
111-
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
112-
Optional<Demangle::ImplFunctionResult<Type>> errorResult,
113-
ImplFunctionTypeFlags flags);
104+
Demangle::ImplParameterConvention calleeConvention,
105+
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
106+
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
107+
Optional<Demangle::ImplFunctionResult<Type>> errorResult,
108+
ImplFunctionTypeFlags flags);
114109

115110
Type createProtocolCompositionType(ArrayRef<ProtocolDecl *> protocols,
116111
Type superclass,
@@ -135,6 +130,8 @@ class ASTBuilder {
135130

136131
Type createSILBoxType(Type base);
137132
using BuiltSILBoxField = llvm::PointerIntPair<Type, 1>;
133+
using BuiltSubstitution = std::pair<Type, Type>;
134+
using BuiltRequirement = swift::Requirement;
138135
using BuiltLayoutConstraint = swift::LayoutConstraint;
139136
Type createSILBoxTypeWithLayout(ArrayRef<BuiltSILBoxField> Fields,
140137
ArrayRef<BuiltSubstitution> Substitutions,

include/swift/Demangling/TypeDecoder.h

Lines changed: 32 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,9 @@ class TypeDecoder {
814814
}
815815
case NodeKind::ImplFunctionType: {
816816
auto calleeConvention = ImplParameterConvention::Direct_Unowned;
817-
BuiltRequirement *witnessMethodConformanceRequirement = nullptr;
818817
llvm::SmallVector<ImplFunctionParam<BuiltType>, 8> parameters;
819818
llvm::SmallVector<ImplFunctionResult<BuiltType>, 8> results;
820819
llvm::SmallVector<ImplFunctionResult<BuiltType>, 8> errorResults;
821-
llvm::SmallVector<BuiltType, 4> genericParameters;
822-
llvm::SmallVector<BuiltRequirement, 4> requirements;
823820
ImplFunctionTypeFlags flags;
824821

825822
for (unsigned i = 0; i < Node->getNumChildren(); i++) {
@@ -852,9 +849,6 @@ class TypeDecoder {
852849
} else if (text == "block") {
853850
flags =
854851
flags.withRepresentation(ImplFunctionRepresentation::Block);
855-
} else if (text == "witness_method") {
856-
flags = flags.withRepresentation(
857-
ImplFunctionRepresentation::WitnessMethod);
858852
}
859853
} else if (child->getKind() == NodeKind::ImplFunctionAttribute) {
860854
if (!child->hasText())
@@ -892,27 +886,6 @@ class TypeDecoder {
892886
if (decodeImplFunctionPart(child, errorResults))
893887
return MAKE_NODE_TYPE_ERROR0(child,
894888
"failed to decode function part");
895-
} else if (child->getKind() == NodeKind::DependentGenericSignature) {
896-
llvm::SmallVector<unsigned, 4> genericParamsAtDepth;
897-
898-
if (auto error = decodeDependentGenericSignatureNode(
899-
child, requirements, genericParamsAtDepth))
900-
return *error;
901-
if (flags.getRepresentation() ==
902-
ImplFunctionRepresentation::WitnessMethod) {
903-
// By convention, the first requirement of a witness method is the
904-
// conformance of Self to the protocol.
905-
witnessMethodConformanceRequirement = &requirements[0];
906-
}
907-
908-
for (unsigned long depth = 0, depths = genericParamsAtDepth.size();
909-
depth < depths; ++depth) {
910-
for (unsigned index = 0; index < genericParamsAtDepth[depth];
911-
++index) {
912-
genericParameters.emplace_back(
913-
Builder.createGenericTypeParameterType(depth, index));
914-
}
915-
}
916889
} else {
917890
return MAKE_NODE_TYPE_ERROR0(child, "unexpected kind");
918891
}
@@ -933,11 +906,11 @@ class TypeDecoder {
933906
// TODO: Some cases not handled above, but *probably* they cannot
934907
// appear as the types of values in SIL (yet?):
935908
// - functions with yield returns
909+
// - functions with generic signatures
936910
// - foreign error conventions
937-
return Builder.createImplFunctionType(
938-
calleeConvention, witnessMethodConformanceRequirement,
939-
genericParameters, requirements, parameters, results, errorResult,
940-
flags);
911+
return Builder.createImplFunctionType(calleeConvention,
912+
parameters, results,
913+
errorResult, flags);
941914
}
942915

943916
case NodeKind::ArgumentTuple:
@@ -1108,12 +1081,35 @@ class TypeDecoder {
11081081
return MAKE_NODE_TYPE_ERROR0(substNode, "expected type list");
11091082

11101083
auto *dependentGenericSignatureNode = Node->getChild(1);
1084+
if (dependentGenericSignatureNode->getKind() !=
1085+
NodeKind::DependentGenericSignature)
1086+
return MAKE_NODE_TYPE_ERROR0(dependentGenericSignatureNode,
1087+
"expected dependent generic signature");
1088+
if (dependentGenericSignatureNode->getNumChildren() < 1)
1089+
return MAKE_NODE_TYPE_ERROR(
1090+
dependentGenericSignatureNode,
1091+
"fewer children (%zu) than required (1)",
1092+
dependentGenericSignatureNode->getNumChildren());
1093+
decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
1094+
BuilderType>(
1095+
dependentGenericSignatureNode, requirements, Builder/*,
1096+
[&](NodePointer Node) -> BuiltType {
1097+
return decodeMangledType(Node).getType();
1098+
},
1099+
[&](LayoutConstraintKind Kind) -> BuiltLayoutConstraint {
1100+
return {}; // Not implemented!
1101+
},
1102+
[&](LayoutConstraintKind Kind, unsigned SizeInBits,
1103+
unsigned Alignment) -> BuiltLayoutConstraint {
1104+
return {}; // Not Implemented!
1105+
}*/);
1106+
// The number of generic parameters at each depth are in a mini
1107+
// state machine and come first.
11111108
llvm::SmallVector<unsigned, 4> genericParamsAtDepth;
1112-
if (auto error = decodeDependentGenericSignatureNode(
1113-
dependentGenericSignatureNode, requirements,
1114-
genericParamsAtDepth))
1115-
return *error;
1116-
1109+
for (auto *reqNode : *dependentGenericSignatureNode)
1110+
if (reqNode->getKind() == NodeKind::DependentGenericParamCount)
1111+
if (reqNode->hasIndex())
1112+
genericParamsAtDepth.push_back(reqNode->getIndex());
11171113
unsigned depth = 0;
11181114
unsigned index = 0;
11191115
for (auto *subst : *substNode) {
@@ -1463,43 +1459,6 @@ class TypeDecoder {
14631459
params.push_back(std::move(param));
14641460
return true;
14651461
}
1466-
1467-
llvm::Optional<TypeLookupError> decodeDependentGenericSignatureNode(
1468-
NodePointer dependentGenericSignatureNode,
1469-
llvm::SmallVectorImpl<BuiltRequirement> &requirements,
1470-
llvm::SmallVectorImpl<unsigned> &genericParamsAtDepth) {
1471-
using NodeKind = Demangle::Node::Kind;
1472-
if (dependentGenericSignatureNode->getKind() !=
1473-
NodeKind::DependentGenericSignature)
1474-
return llvm::Optional<TypeLookupError>(
1475-
MAKE_NODE_TYPE_ERROR0(dependentGenericSignatureNode,
1476-
"expected dependent generic signature"));
1477-
if (dependentGenericSignatureNode->getNumChildren() < 1)
1478-
return llvm::Optional<TypeLookupError>(MAKE_NODE_TYPE_ERROR(
1479-
dependentGenericSignatureNode,
1480-
"fewer children (%zu) than required (1)",
1481-
dependentGenericSignatureNode->getNumChildren()));
1482-
decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
1483-
BuilderType>(dependentGenericSignatureNode, requirements,
1484-
Builder /*,
1485-
[&](NodePointer Node) -> BuiltType {
1486-
return decodeMangledType(Node).getType();
1487-
},
1488-
[&](LayoutConstraintKind Kind) -> BuiltLayoutConstraint {
1489-
return {}; // Not implemented!
1490-
},
1491-
[&](LayoutConstraintKind Kind, unsigned SizeInBits,
1492-
unsigned Alignment) -> BuiltLayoutConstraint {
1493-
return {}; // Not Implemented!
1494-
}*/);
1495-
// The number of generic parameters at each depth are in a mini
1496-
// state machine and come first.
1497-
for (auto *reqNode : *dependentGenericSignatureNode)
1498-
if (reqNode->getKind() == NodeKind::DependentGenericParamCount)
1499-
if (reqNode->hasIndex())
1500-
genericParamsAtDepth.push_back(reqNode->getIndex());
1501-
return llvm::None;
1502-
}
15031462
};
15041463

15051464
template <typename BuilderType>

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,9 @@ class TypeRefBuilder {
418418
FunctionMetadataDifferentiabilityKind diffKind) {
419419
return FunctionTypeRef::create(*this, params, result, flags, diffKind);
420420
}
421-
using BuiltSubstitution = std::pair<const TypeRef *, const TypeRef *>;
422-
using BuiltRequirement = TypeRefRequirement;
423421

424422
const FunctionTypeRef *createImplFunctionType(
425423
Demangle::ImplParameterConvention calleeConvention,
426-
BuiltRequirement *witnessMethodConformanceRequirement,
427-
const llvm::SmallVectorImpl<BuiltType> &genericParameters,
428-
const llvm::SmallVectorImpl<BuiltRequirement> &requirements,
429424
llvm::ArrayRef<Demangle::ImplFunctionParam<const TypeRef *>> params,
430425
llvm::ArrayRef<Demangle::ImplFunctionResult<const TypeRef *>> results,
431426
llvm::Optional<Demangle::ImplFunctionResult<const TypeRef *>> errorResult,
@@ -545,6 +540,8 @@ class TypeRefBuilder {
545540
}
546541

547542
using BuiltSILBoxField = typename SILBoxTypeWithLayoutTypeRef::Field;
543+
using BuiltSubstitution = std::pair<const TypeRef *, const TypeRef *>;
544+
using BuiltRequirement = TypeRefRequirement;
548545
using BuiltLayoutConstraint = TypeRefLayoutConstraint;
549546
BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) {
550547
// FIXME: Implement this.

lib/AST/ASTDemangler.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -483,24 +483,11 @@ getResultDifferentiability(ImplResultDifferentiability diffKind) {
483483

484484
Type ASTBuilder::createImplFunctionType(
485485
Demangle::ImplParameterConvention calleeConvention,
486-
BuiltRequirement *witnessMethodConformanceRequirement,
487-
ArrayRef<BuiltType> GenericParameters,
488-
ArrayRef<BuiltRequirement> Requirements,
489486
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
490487
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
491488
Optional<Demangle::ImplFunctionResult<Type>> errorResult,
492489
ImplFunctionTypeFlags flags) {
493490
GenericSignature genericSig;
494-
if (GenericParameters.size() > 0) {
495-
llvm::SmallVector<GenericTypeParamType *, 4> CastGenericParameters;
496-
for (auto Parameter : GenericParameters) {
497-
CastGenericParameters.push_back(
498-
Parameter->castTo<GenericTypeParamType>());
499-
}
500-
genericSig = GenericSignature::get(CastGenericParameters, Requirements);
501-
} else {
502-
assert(Requirements.size() == 0);
503-
}
504491

505492
SILCoroutineKind funcCoroutineKind = SILCoroutineKind::None;
506493
ParameterConvention funcCalleeConvention =
@@ -585,15 +572,11 @@ Type ASTBuilder::createImplFunctionType(
585572
representation, flags.isPseudogeneric(), !flags.isEscaping(),
586573
flags.isSendable(), flags.isAsync(), diffKind, clangFnType)
587574
.build();
588-
auto witnessMethodConformance =
589-
witnessMethodConformanceRequirement
590-
? ProtocolConformanceRef(
591-
witnessMethodConformanceRequirement->getProtocolDecl())
592-
: ProtocolConformanceRef();
593-
return SILFunctionType::get(
594-
genericSig, einfo, funcCoroutineKind, funcCalleeConvention, funcParams,
595-
funcYields, funcResults, funcErrorResult,
596-
SubstitutionMap(), SubstitutionMap(), Ctx, witnessMethodConformance);
575+
576+
return SILFunctionType::get(genericSig, einfo, funcCoroutineKind,
577+
funcCalleeConvention, funcParams, funcYields,
578+
funcResults, funcErrorResult,
579+
SubstitutionMap(), SubstitutionMap(), Ctx);
597580
}
598581

599582
Type ASTBuilder::createProtocolCompositionType(

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,58 +1508,8 @@ class DecodedMetadataBuilder {
15081508
result);
15091509
}
15101510

1511-
struct BuiltLayoutConstraint {
1512-
bool operator==(BuiltLayoutConstraint rhs) const { return true; }
1513-
operator bool() const { return true; }
1514-
};
1515-
using BuiltLayoutConstraint = BuiltLayoutConstraint;
1516-
BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) {
1517-
return {};
1518-
}
1519-
BuiltLayoutConstraint
1520-
getLayoutConstraintWithSizeAlign(LayoutConstraintKind kind, unsigned size,
1521-
unsigned alignment) {
1522-
return {};
1523-
}
1524-
1525-
#if LLVM_PTR_SIZE == 4
1526-
/// Unfortunately the alignment of TypeRef is too large to squeeze in 3 extra
1527-
/// bits on (some?) 32-bit systems.
1528-
class BigBuiltTypeIntPair {
1529-
BuiltType Ptr;
1530-
RequirementKind Int;
1531-
1532-
public:
1533-
BigBuiltTypeIntPair(BuiltType ptr, RequirementKind i) : Ptr(ptr), Int(i) {}
1534-
RequirementKind getInt() const { return Int; }
1535-
BuiltType getPointer() const { return Ptr; }
1536-
uint64_t getOpaqueValue() const {
1537-
return (uint64_t)Ptr | ((uint64_t)Int << 32);
1538-
}
1539-
};
1540-
#endif
1541-
1542-
struct Requirement : public RequirementBase<BuiltType,
1543-
#if LLVM_PTR_SIZE == 4
1544-
BigBuiltTypeIntPair,
1545-
#else
1546-
llvm::PointerIntPair<BuiltType, 3, RequirementKind>,
1547-
1548-
#endif
1549-
BuiltLayoutConstraint> {
1550-
Requirement(RequirementKind kind, BuiltType first, BuiltType second)
1551-
: RequirementBase(kind, first, second) {}
1552-
Requirement(RequirementKind kind, BuiltType first,
1553-
BuiltLayoutConstraint second)
1554-
: RequirementBase(kind, first, second) {}
1555-
};
1556-
using BuiltRequirement = Requirement;
1557-
15581511
TypeLookupErrorOr<BuiltType> createImplFunctionType(
15591512
Demangle::ImplParameterConvention calleeConvention,
1560-
BuiltRequirement *witnessMethodConformanceRequirement,
1561-
llvm::ArrayRef<BuiltType> genericParameters,
1562-
llvm::ArrayRef<BuiltRequirement> requirements,
15631513
llvm::ArrayRef<Demangle::ImplFunctionParam<BuiltType>> params,
15641514
llvm::ArrayRef<Demangle::ImplFunctionResult<BuiltType>> results,
15651515
llvm::Optional<Demangle::ImplFunctionResult<BuiltType>> errorResult,
@@ -1627,6 +1577,51 @@ class DecodedMetadataBuilder {
16271577

16281578
using BuiltSILBoxField = llvm::PointerIntPair<BuiltType, 1>;
16291579
using BuiltSubstitution = std::pair<BuiltType, BuiltType>;
1580+
struct BuiltLayoutConstraint {
1581+
bool operator==(BuiltLayoutConstraint rhs) const { return true; }
1582+
operator bool() const { return true; }
1583+
};
1584+
using BuiltLayoutConstraint = BuiltLayoutConstraint;
1585+
BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) {
1586+
return {};
1587+
}
1588+
BuiltLayoutConstraint
1589+
getLayoutConstraintWithSizeAlign(LayoutConstraintKind kind, unsigned size,
1590+
unsigned alignment) {
1591+
return {};
1592+
}
1593+
1594+
#if LLVM_PTR_SIZE == 4
1595+
/// Unfortunately the alignment of TypeRef is too large to squeeze in 3 extra
1596+
/// bits on (some?) 32-bit systems.
1597+
class BigBuiltTypeIntPair {
1598+
BuiltType Ptr;
1599+
RequirementKind Int;
1600+
public:
1601+
BigBuiltTypeIntPair(BuiltType ptr, RequirementKind i) : Ptr(ptr), Int(i) {}
1602+
RequirementKind getInt() const { return Int; }
1603+
BuiltType getPointer() const { return Ptr; }
1604+
uint64_t getOpaqueValue() const {
1605+
return (uint64_t)Ptr | ((uint64_t)Int << 32);
1606+
}
1607+
};
1608+
#endif
1609+
1610+
struct Requirement : public RequirementBase<BuiltType,
1611+
#if LLVM_PTR_SIZE == 4
1612+
BigBuiltTypeIntPair,
1613+
#else
1614+
llvm::PointerIntPair<BuiltType, 3, RequirementKind>,
1615+
1616+
#endif
1617+
BuiltLayoutConstraint> {
1618+
Requirement(RequirementKind kind, BuiltType first, BuiltType second)
1619+
: RequirementBase(kind, first, second) {}
1620+
Requirement(RequirementKind kind, BuiltType first,
1621+
BuiltLayoutConstraint second)
1622+
: RequirementBase(kind, first, second) {}
1623+
};
1624+
using BuiltRequirement = Requirement;
16301625

16311626
TypeLookupErrorOr<BuiltType> createSILBoxTypeWithLayout(
16321627
llvm::ArrayRef<BuiltSILBoxField> Fields,

0 commit comments

Comments
 (0)