Skip to content

6.2: [TypeLowering] Record packs used in signatures. #81659

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
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ bool SILInstruction::isDeallocatingStack() const {
}

static bool typeOrLayoutInvolvesPack(SILType ty, SILFunction const &F) {
return ty.hasAnyPack() || ty.isOrContainsPack(F);
return ty.isOrContainsPack(F);
}

bool SILInstruction::mayRequirePackMetadata(SILFunction const &F) const {
Expand Down
11 changes: 9 additions & 2 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,12 +2290,14 @@ namespace {

TypeLowering *handleTrivial(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
auto silType = SILType::getPrimitiveObjectType(type);
return new (TC) TrivialTypeLowering(silType, properties, Expansion);
}

TypeLowering *handleReference(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
auto silType = SILType::getPrimitiveObjectType(type);
if (type.isForeignReferenceType() &&
type->getReferenceCounting() == ReferenceCounting::None)
Expand All @@ -2307,13 +2309,15 @@ namespace {

TypeLowering *handleMoveOnlyReference(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
auto silType = SILType::getPrimitiveObjectType(type);
return new (TC)
MoveOnlyReferenceTypeLowering(silType, properties, Expansion);
}

TypeLowering *handleMoveOnlyAddressOnly(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
if (!TC.Context.SILOpts.EnableSILOpaqueValues &&
!TypeLoweringForceOpaqueValueLowering) {
auto silType = SILType::getPrimitiveAddressType(type);
Expand All @@ -2326,13 +2330,15 @@ namespace {
}

TypeLowering *handleReference(CanType type) {
auto properties = RecursiveProperties::forReference();
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
auto silType = SILType::getPrimitiveObjectType(type);
return new (TC) ReferenceTypeLowering(
silType, RecursiveProperties::forReference(), Expansion);
return new (TC) ReferenceTypeLowering(silType, properties, Expansion);
}

TypeLowering *handleAddressOnly(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
if (!TC.Context.SILOpts.EnableSILOpaqueValues &&
!TypeLoweringForceOpaqueValueLowering) {
auto silType = SILType::getPrimitiveAddressType(type);
Expand All @@ -2347,6 +2353,7 @@ namespace {

TypeLowering *handleInfinite(CanType type,
RecursiveProperties properties) {
properties = mergeHasPack(HasPack_t(type->hasAnyPack()), properties);
// Infinite types cannot actually be instantiated, so treat them as
// opaque for code generation purposes.
properties.setAddressOnly();
Expand Down
65 changes: 65 additions & 0 deletions validation-test/IRGen/rdar147207926.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend \
// RUN: %t/Library.swift \
// RUN: -emit-module \
// RUN: -target %target-swift-5.9-abi-triple \
// RUN: -enable-library-evolution \
// RUN: -module-name Library \
// RUN: -emit-module-path %t/Library.swiftmodule

// RUN: %target-build-swift \
// RUN: %t/Downstream.swift \
// RUN: -c \
// RUN: -target %target-swift-5.9-abi-triple \
// RUN: -parse-as-library \
// RUN: -module-name main \
// RUN: -lLibrary \
// RUN: -I %t \
// RUN: -o %t/Executable.o

//--- Library.swift

public struct Paq<each T> {
public var uette: (repeat each T)
}

public class Loq<each T> {
}

// Enums don't take packs yet.

// public enum Orq<each T> {
// case uette(repeat each T)
// case uettette(repeat each T, repeat each T)
// }

//--- Downstream.swift

import Library

struct Sleeve<T> {
var impl: Paq<T>
}

func bin<Moribund>(_ s: consuming Sleeve<Moribund>) {
}

struct Laq<T> {
var impl: Loq<T>
var t: T
}

@_silgen_name("bun")
func bun<T>(_ l: consuming Laq<T>) {
}

// Enums don't take packs yet.

// struct Etiq<T> {
// var impl: Orq<T>
// }
//
// func bon<Moribund>(_ i: consuming Etiq<Moribund>) {
// }