Skip to content

Commit ee15a40

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 0cdd51d + d1f3416 commit ee15a40

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/Types.h"
3333
#include "swift/Demangling/Demangler.h"
3434
#include "swift/Demangling/ManglingMacros.h"
35+
#include "llvm/ADT/StringSwitch.h"
3536

3637
using namespace swift;
3738

@@ -838,22 +839,45 @@ CanGenericSignature ASTBuilder::demangleGenericSignature(
838839
break;
839840
}
840841
case Demangle::Node::Kind::DependentGenericLayoutRequirement: {
841-
// FIXME: Other layout constraints
842-
LayoutConstraint constraint;
843842
auto kindChild = child->getChild(1);
844843
if (kindChild->getKind() != Demangle::Node::Kind::Identifier)
845844
return CanGenericSignature();
846845

847-
if (kindChild->getText() == "C") {
848-
auto kind = LayoutConstraintKind::Class;
849-
auto layout = LayoutConstraint::getLayoutConstraint(kind, Ctx);
850-
builder.addRequirement(
851-
Requirement(RequirementKind::Layout, subjectType, layout),
852-
source, nullptr);
853-
break;
846+
auto kind = llvm::StringSwitch<Optional<
847+
LayoutConstraintKind>>(kindChild->getText())
848+
.Case("U", LayoutConstraintKind::UnknownLayout)
849+
.Case("R", LayoutConstraintKind::RefCountedObject)
850+
.Case("N", LayoutConstraintKind::NativeRefCountedObject)
851+
.Case("C", LayoutConstraintKind::Class)
852+
.Case("D", LayoutConstraintKind::NativeClass)
853+
.Case("T", LayoutConstraintKind::Trivial)
854+
.Cases("E", "e", LayoutConstraintKind::TrivialOfExactSize)
855+
.Cases("M", "m", LayoutConstraintKind::TrivialOfAtMostSize)
856+
.Default(None);
857+
858+
if (!kind)
859+
return CanGenericSignature();
860+
861+
LayoutConstraint layout;
862+
863+
if (kind != LayoutConstraintKind::TrivialOfExactSize &&
864+
kind != LayoutConstraintKind::TrivialOfAtMostSize) {
865+
layout = LayoutConstraint::getLayoutConstraint(*kind, Ctx);
866+
} else {
867+
auto size = child->getChild(2)->getIndex();
868+
auto alignment = 0;
869+
870+
if (child->getNumChildren() == 4)
871+
alignment = child->getChild(3)->getIndex();
872+
873+
layout = LayoutConstraint::getLayoutConstraint(*kind, size, alignment,
874+
Ctx);
854875
}
855876

856-
return CanGenericSignature();
877+
builder.addRequirement(
878+
Requirement(RequirementKind::Layout, subjectType, layout),
879+
source, nullptr);
880+
break;
857881
}
858882
default:
859883
return CanGenericSignature();

test/TypeDecoder/extensions.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ extension Generic where T == Int {
4242
// CHECK-DECL: extensions.(file).Generic extension.Nested1
4343

4444
// DEMANGLE-DECL: $s10extensions7GenericVAASiRszlE7Nested2V
45-
// CHECK-DECL: extensions.(file).Generic extension.Nested2
45+
// CHECK-DECL: extensions.(file).Generic extension.Nested2
46+
47+
// Layout Constraints
48+
// FIXME: When other layout constraints are allowed in source level swift, test
49+
// that we correctly demangle those as well.
50+
51+
extension Generic where T: AnyObject {
52+
struct NestedViaAnyObject {}
53+
}
54+
55+
// DEMANGLE-TYPE: $s10extensions7GenericVAARlzClE18NestedViaAnyObjectVyx_GD
56+
// CHECK-TYPE: Generic<τ_0_0>.NestedViaAnyObject
57+
58+
// DEMANGLE-DECL: $s10extensions7GenericVAARlzClE18NestedViaAnyObjectV
59+
// CHECK-DECL: extensions.(file).Generic extension.NestedViaAnyObject
60+

0 commit comments

Comments
 (0)