Skip to content

IRGen: Outlining thunks don't need to receive fixed-size metadata #15972

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
Apr 18, 2018
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
2 changes: 1 addition & 1 deletion lib/IRGen/GenArchetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class OpaqueArchetypeTypeInfo
void collectMetadataForOutlining(OutliningMetadataCollector &collector,
SILType T) const override {
// We'll need formal type metadata for this archetype.
collector.collectFormalTypeMetadata(T.getSwiftRValueType());
collector.collectTypeMetadataForLayout(T);
}
};

Expand Down
10 changes: 6 additions & 4 deletions lib/IRGen/Outlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ void OutliningMetadataCollector::collectTypeMetadataForLayout(SILType type) {
return;
}

CanType formalType = type.getSwiftRValueType();
if (isa<FixedTypeInfo>(IGF.IGM.getTypeInfoForLowered(formalType))) {
return;
}

// If the type is a legal formal type, add it as a formal type.
// FIXME: does this force us to emit a more expensive metadata than we need
// to?
CanType formalType = type.getSwiftRValueType();
if (formalType->isLegalFormalType()) {
return collectFormalTypeMetadata(formalType);
}
Expand All @@ -53,9 +57,7 @@ void OutliningMetadataCollector::collectTypeMetadataForLayout(SILType type) {

void OutliningMetadataCollector::collectFormalTypeMetadata(CanType type) {
// If the type has no archetypes, we can emit it from scratch in the callee.
if (!type->hasArchetype()) {
return;
}
assert(type->hasArchetype());

auto key = LocalTypeDataKey(type, LocalTypeDataKind::forFormalTypeMetadata());
if (Values.count(key)) return;
Expand Down
28 changes: 26 additions & 2 deletions test/IRGen/outlined_copy_addr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,33 @@ public struct StructWithBaseStruct<T: BaseProt> {
var elem2: BaseStruct<Element>
}

// CHECK-LABEL: define hidden swiftcc void @"$S11outcopyaddr010StructWithbc4BaseB0V4elemAA0bcdB0VyxGvg"(%T11outcopyaddr014StructWithBaseB0V.0* noalias nocapture sret, %swift.type* %"StructWithStructWithBaseStruct<T>", %T11outcopyaddr010StructWithbc4BaseB0V* noalias nocapture swiftself)
// CHECK: call %T11outcopyaddr014StructWithBaseB0V.0* @"$S11outcopyaddr014StructWithBaseB0VyxGAA9ChildProtRzlWOc"
// CHECK-LABEL: define hidden swiftcc void @"$S11outcopyaddr010StructWithbc4BaseB0V4elemAA0bcdB0VyxGvg"(%T11outcopyaddr014StructWithBaseB0V.4* noalias nocapture sret, %swift.type* %"StructWithStructWithBaseStruct<T>", %T11outcopyaddr010StructWithbc4BaseB0V* noalias nocapture swiftself)
// CHECK: call %T11outcopyaddr014StructWithBaseB0V.4* @"$S11outcopyaddr014StructWithBaseB0VyxGAA9ChildProtRzlWOc"
public struct StructWithStructWithBaseStruct<T: ChildProt> {
public typealias Element = T
let elem: StructWithBaseStruct<Element>
}

protocol P { }

class OtherPrivate<T> { }

struct OtherInternal<T> {
var myPrivate: OtherPrivate<T>? = nil
}

struct MyPrivate<T: P> {
var otherHelper: OtherInternal<T>? = nil

// CHECK-LABEL: define hidden swiftcc {{i32|i64}} @"$S11outcopyaddr9MyPrivateVyACyxGxcfC"(%swift.opaque* noalias nocapture, %swift.type* %T, i8** %T.P) {{.*}} {
// CHECK: call %T11outcopyaddr9MyPrivateV* @"$S11outcopyaddr9MyPrivateVyxGAA1PRzlWOh"(%T11outcopyaddr9MyPrivateV* %self)
// CHECK: ret
init(_: T) { }
}

extension P {
func foo(data: Any) {
_ = MyPrivate(data as! Self)
}
}

5 changes: 5 additions & 0 deletions test/multifile/Inputs/outlined-thunks-other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
private class OtherPrivate<T> { }

struct OtherInternal<T> {
fileprivate var myPrivate: OtherPrivate<T>? = nil
}
18 changes: 18 additions & 0 deletions test/multifile/outlined-thunks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-library -module-name outlined_thunks %S/Inputs/outlined-thunks-other.swift %s
// RUN: %target-build-swift -emit-library -module-name outlined_thunks -whole-module-optimization %S/Inputs/outlined-thunks-other.swift %s

// rdar://problem/39470607

protocol P { }

private struct MyPrivate<T: P> {
private var otherHelper: OtherInternal<T>? = nil
init(_: T) { }
}

extension P {
func foo(data: Any) {
_ = MyPrivate(data as! Self)
}
}