Skip to content

Two fixes for parameter packs and parameterized existentials #72885

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
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
14 changes: 7 additions & 7 deletions lib/IRGen/GenExistential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ namespace {

void assignWithCopy(IRGenFunction &IGF, Address dest, Address src, SILType T,
bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
Address destValue = projectValue(IGF, dest);
Address srcValue = projectValue(IGF, src);
asDerived().emitValueAssignWithCopy(IGF, destValue, srcValue);
Expand All @@ -262,7 +262,7 @@ namespace {

void initializeWithCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
Address destValue = projectValue(IGF, dest);
Address srcValue = projectValue(IGF, src);
asDerived().emitValueInitializeWithCopy(IGF, destValue, srcValue);
Expand All @@ -277,7 +277,7 @@ namespace {

void assignWithTake(IRGenFunction &IGF, Address dest, Address src, SILType T,
bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
Address destValue = projectValue(IGF, dest);
Address srcValue = projectValue(IGF, src);
asDerived().emitValueAssignWithTake(IGF, destValue, srcValue);
Expand All @@ -292,7 +292,7 @@ namespace {

void initializeWithTake(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
Address destValue = projectValue(IGF, dest);
Address srcValue = projectValue(IGF, src);
asDerived().emitValueInitializeWithTake(IGF, destValue, srcValue);
Expand All @@ -307,7 +307,7 @@ namespace {

void destroy(IRGenFunction &IGF, Address existential, SILType T,
bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
Address valueAddr = projectValue(IGF, existential);
asDerived().emitValueDestroy(IGF, valueAddr);
} else {
Expand Down Expand Up @@ -955,7 +955,7 @@ class OpaqueExistentialTypeInfo final :

void initializeWithCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
llvm::Value *metadata = copyType(IGF, dest, src);

auto layout = getLayout();
Expand All @@ -977,7 +977,7 @@ class OpaqueExistentialTypeInfo final :

void initializeWithTake(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
if (isOutlined) {
if (isOutlined || T.hasLocalArchetype()) {
// memcpy the existential container. This is safe because: either the
// value is stored inline and is therefore by convention bitwise takable
// or the value is stored in a reference counted heap buffer, in which
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3294,7 +3294,7 @@ TypeConverter::computeLoweredRValueType(TypeExpansionContext forExpansion,
AbstractionPattern origType)
: TC(TC), forExpansion(forExpansion), origType(origType) {
if (auto origEltType = origType.getVanishingTupleElementPatternType())
origType = *origEltType;
this->origType = *origEltType;
}

// AST function types are turned into SIL function types:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking

public protocol P1<A> {
associatedtype A
}

public protocol P2<A>: class {
associatedtype A
}

public func f1<each T>(p: repeat any P1<each T>) {
let _ = (repeat each p)
}

public func f2<each T>(p: repeat any P2<each T>) {
let _ = (repeat each p)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking

public protocol P {}

extension P {
@_transparent
public func f() {
let x: any Q<Self> = S<Self>()

// force a copy
g(x, x)
}
}

@_optimize(none)
public func g<T>(_: consuming T, _: consuming T) {}

public enum G<T> {
case ok(String)
case bar
}

public func h(e: any P) {
// We inline P.f(), because it is transparent, so we end
// up working with an `any Q<@opened ...>`.
e.f()
}

public protocol Q<A> {
associatedtype A
}

public struct S<A>: Q {
public init() {}
}
43 changes: 43 additions & 0 deletions test/SILGen/variadic-generic-lowering.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// RUN: %target-swift-emit-silgen %s -disable-availability-checking

// Make sure we can lower all of these types without crashing.

public struct G1<each T> {
public let t: (repeat each T)
}

public struct S1 {
public let g: G1< >
public let gg: G1<Int>
public let ggg: G1<Int, Float>
}

public struct G2<each T> {
public let t: (repeat (each T).Type)
}

public struct S2 {
public let g: G2< >
public let gg: G2<Int>
public let ggg: G2<Int, Float>
}

public struct G3<each T> {
public let t: (repeat (each T) -> ())
}

public struct S3 {
public let g: G3< >
public let gg: G3<Int>
public let ggg: G3<Int, Float>
}

public struct G4<each T> {
public let t: (repeat ((each T).Type) -> ())
}

public struct S4 {
public let g: G4< >
public let gg: G4<Int>
public let ggg: G4<Int, Float>
}