mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[IRGen] Don't set HasLayoutString flag on non-copyable generic types
rdar://151176697 While generic types generally have layout strings (when enabled), non-copyable types don't, so we have to make sure the flag does not get set.
This commit is contained in:
@@ -6014,12 +6014,14 @@ namespace {
|
|||||||
if (!layoutStringsEnabled(IGM)) {
|
if (!layoutStringsEnabled(IGM)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !!getLayoutString() ||
|
const auto &TI = IGM.getTypeInfo(getLoweredType());
|
||||||
|
return (!!getLayoutString() ||
|
||||||
(IGM.Context.LangOpts.hasFeature(
|
(IGM.Context.LangOpts.hasFeature(
|
||||||
Feature::LayoutStringValueWitnessesInstantiation) &&
|
Feature::LayoutStringValueWitnessesInstantiation) &&
|
||||||
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
|
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
|
||||||
(HasDependentVWT || HasDependentMetadata) &&
|
(HasDependentVWT || HasDependentMetadata) &&
|
||||||
!isa<FixedTypeInfo>(IGM.getTypeInfo(getLoweredType())));
|
!isa<FixedTypeInfo>(TI))) &&
|
||||||
|
TI.isCopyable(ResilienceExpansion::Maximal);
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Constant *emitNominalTypeDescriptor() {
|
llvm::Constant *emitNominalTypeDescriptor() {
|
||||||
@@ -6547,13 +6549,15 @@ namespace {
|
|||||||
if (!layoutStringsEnabled(IGM)) {
|
if (!layoutStringsEnabled(IGM)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
auto &TI = IGM.getTypeInfo(getLoweredType());
|
||||||
|
|
||||||
return !!getLayoutString() ||
|
return (!!getLayoutString() ||
|
||||||
(IGM.Context.LangOpts.hasFeature(
|
(IGM.Context.LangOpts.hasFeature(
|
||||||
Feature::LayoutStringValueWitnessesInstantiation) &&
|
Feature::LayoutStringValueWitnessesInstantiation) &&
|
||||||
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
|
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
|
||||||
(HasDependentVWT || HasDependentMetadata) &&
|
(HasDependentVWT || HasDependentMetadata) &&
|
||||||
!isa<FixedTypeInfo>(IGM.getTypeInfo(getLoweredType())));
|
!isa<FixedTypeInfo>(TI))) &&
|
||||||
|
TI.isCopyable(ResilienceExpansion::Maximal);
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Constant *emitNominalTypeDescriptor() {
|
llvm::Constant *emitNominalTypeDescriptor() {
|
||||||
|
|||||||
@@ -673,6 +673,21 @@ public enum MultiPayloadAnyObject {
|
|||||||
case z(AnyObject)
|
case z(AnyObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct NonCopyableGenericStruct<T>: ~Copyable {
|
||||||
|
let x: Int
|
||||||
|
let y: T
|
||||||
|
|
||||||
|
public init(x: Int, y: T) {
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum NonCopyableGenericEnum<T>: ~Copyable {
|
||||||
|
case x(Int, T?)
|
||||||
|
case y(Int)
|
||||||
|
}
|
||||||
|
|
||||||
@inline(never)
|
@inline(never)
|
||||||
public func consume<T>(_ x: T.Type) {
|
public func consume<T>(_ x: T.Type) {
|
||||||
withExtendedLifetime(x) {}
|
withExtendedLifetime(x) {}
|
||||||
@@ -751,6 +766,11 @@ public func testGenericArrayDestroy<T>(_ buffer: UnsafeMutableBufferPointer<T>)
|
|||||||
buffer.deinitialize()
|
buffer.deinitialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@inline(never)
|
||||||
|
public func testGenericArrayDestroy<T: ~Copyable>(_ buffer: UnsafeMutableBufferPointer<T>) {
|
||||||
|
buffer.deinitialize()
|
||||||
|
}
|
||||||
|
|
||||||
@inline(never)
|
@inline(never)
|
||||||
public func testGenericArrayInitWithCopy<T>(dest: UnsafeMutableBufferPointer<T>, src: UnsafeMutableBufferPointer<T>) {
|
public func testGenericArrayInitWithCopy<T>(dest: UnsafeMutableBufferPointer<T>, src: UnsafeMutableBufferPointer<T>) {
|
||||||
_ = dest.initialize(fromContentsOf: src)
|
_ = dest.initialize(fromContentsOf: src)
|
||||||
|
|||||||
@@ -1239,6 +1239,42 @@ func testGenericResilientWithUnmanagedAndWeak() {
|
|||||||
|
|
||||||
testGenericResilientWithUnmanagedAndWeak()
|
testGenericResilientWithUnmanagedAndWeak()
|
||||||
|
|
||||||
|
func testNonCopyableGenericStructSimpleClass() {
|
||||||
|
let ptr = UnsafeMutableBufferPointer<NonCopyableGenericStruct<SimpleClass>>.allocate(capacity: 1)
|
||||||
|
|
||||||
|
let x = NonCopyableGenericStruct(x: 23, y: SimpleClass(x: 23))
|
||||||
|
ptr[0] = x
|
||||||
|
|
||||||
|
// CHECK-NEXT: Before deinit
|
||||||
|
print("Before deinit")
|
||||||
|
|
||||||
|
|
||||||
|
// CHECK-NEXT: SimpleClass deinitialized!
|
||||||
|
testGenericArrayDestroy(ptr)
|
||||||
|
|
||||||
|
ptr.deallocate()
|
||||||
|
}
|
||||||
|
|
||||||
|
testNonCopyableGenericStructSimpleClass()
|
||||||
|
|
||||||
|
func testNonCopyableGenericEnumSimpleClass() {
|
||||||
|
let ptr = UnsafeMutableBufferPointer<NonCopyableGenericEnum<SimpleClass>>.allocate(capacity: 1)
|
||||||
|
|
||||||
|
let x = NonCopyableGenericEnum.x(23, SimpleClass(x: 23))
|
||||||
|
ptr[0] = x
|
||||||
|
|
||||||
|
// CHECK-NEXT: Before deinit
|
||||||
|
print("Before deinit")
|
||||||
|
|
||||||
|
|
||||||
|
// CHECK-NEXT: SimpleClass deinitialized!
|
||||||
|
testGenericArrayDestroy(ptr)
|
||||||
|
|
||||||
|
ptr.deallocate()
|
||||||
|
}
|
||||||
|
|
||||||
|
testNonCopyableGenericEnumSimpleClass()
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|||||||
Reference in New Issue
Block a user