Skip to content

TypeDecoder: Push one-element tuple unwrapping down into createTupleType() implementations [5.9] #67936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2023
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
7 changes: 0 additions & 7 deletions include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,13 +1052,6 @@ class TypeDecoder {
return *optError;
}

// Unwrap unlabeled one-element tuples.
//
// FIXME: The behavior of one-element labeled tuples is inconsistent throughout
// the different re-implementations of type substitution and pack expansion.
if (elements.size() == 1 && labels[0].empty())
return elements[0];

return Builder.createTupleType(elements, labels);
}
case NodeKind::TupleElement:
Expand Down
11 changes: 11 additions & 0 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
}

Type ASTBuilder::createTupleType(ArrayRef<Type> eltTypes, ArrayRef<StringRef> labels) {
// Unwrap unlabeled one-element tuples.
//
// FIXME: The behavior of one-element labeled tuples is inconsistent
// throughout the different re-implementations of type substitution
// and pack expansion.
if (eltTypes.size() == 1 &&
!eltTypes[0]->is<PackExpansionType>() &&
labels[0].empty()) {
return eltTypes[0];
}

SmallVector<TupleTypeElt, 4> elements;
elements.reserve(eltTypes.size());
for (unsigned i : indices(eltTypes)) {
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,14 @@ class DecodedMetadataBuilder {
TypeLookupErrorOr<BuiltType>
createTupleType(llvm::ArrayRef<BuiltType> elements,
llvm::ArrayRef<StringRef> labels) const {
// Unwrap unlabeled one-element tuples.
//
// FIXME: The behavior of one-element labeled tuples is inconsistent
// throughout the different re-implementations of type substitution
// and pack expansion.
if (elements.size() == 1 && labels[0].empty())
return elements[0];

for (auto element : elements) {
if (!element.isMetadata()) {
return TYPE_LOOKUP_ERROR_FMT("Tried to build a tuple type where "
Expand Down
34 changes: 33 additions & 1 deletion test/DebugInfo/variadic-generics.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -emit-ir %s -g -o - \
// RUN: -parse-as-library -module-name a | %IRGenFileCheck %s
// RUN: -parse-as-library -module-name a -disable-availability-checking | %IRGenFileCheck %s

public func foo<each T>(args: repeat each T) {
// CHECK: define {{.*}} @"$s1a3foo4argsyxxQp_tRvzlF"
Expand All @@ -21,3 +21,35 @@ public func foo<each T>(args: repeat each T) {
// CHECK-DAG: ![[TYPE_PACK_TY]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "$sBpD"
}

// Test ASTDemangler round-tripping of various pack expansion types

public func paramExpansionWithPattern<each T>(args: repeat Array<each T>) {}

public func paramExpansionWithMemberType<each T: Sequence>(args: repeat each T, elements: repeat (each T).Element) {}

public func tupleExpansion<each T>(args: (repeat each T)) {}

public func tupleExpansionWithPattern<each T>(args: (repeat Array<each T>)) {}

// FIXME: Crashes due to unrelated bug
// public func tupleExpansionWithMemberType<each T: Sequence>(args: repeat each T, elements: (repeat (each T).Element)) {}

public func functionExpansion<each T>(args: (repeat each T) -> ()) {}

public func functionExpansionWithPattern<each T>(args: (repeat Array<each T>) -> ()) {}

public func functionExpansionWithMemberType<each T: Sequence>(args: repeat each T, elements: (repeat (each T).Element) -> ()) {}

public struct G<each T> {}

public func nominalExpansion<each T>(args: G<repeat each T>) {}

public func nominalExpansionWithPattern<each T>(args: G<repeat Array<each T>>) {}

public func nominalExpansionWithMemberType<each T: Sequence>(args: repeat each T, elements: G<repeat (each T).Element>) {}

//

public typealias First<T, U> = T

public func concreteExpansion<each T>(args: repeat each T, concrete: repeat First<Int, each T>) {}