Skip to content

Commit 717880e

Browse files
committed
PerformanceDiagnostics: avoid false meta-data alarms for non-loadable types
Non-loadable types don't necessarily need metadata, for example, structs with `@_rawLayout` swiftlang#73951
1 parent 20f0353 commit 717880e

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

include/swift/SIL/SILType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ class SILType {
366366
/// address-only. This is the opposite of isLoadable.
367367
bool isAddressOnly(const SILFunction &F) const;
368368

369+
/// For details see the comment of `IsFixedABI_t`.
370+
bool isFixedABI(const SILFunction &F) const;
371+
369372
/// True if the underlying AST type is trivial, meaning it is loadable and can
370373
/// be trivially copied, moved or destroyed. Returns false for address types
371374
/// even though they are technically trivial.

lib/SIL/IR/SILType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ bool SILType::isAddressOnly(const SILFunction &F) const {
450450
return F.getTypeLowering(contextType).isAddressOnly();
451451
}
452452

453+
bool SILType::isFixedABI(const SILFunction &F) const {
454+
auto contextType = hasTypeParameter() ? F.mapTypeIntoContext(*this) : *this;
455+
return F.getTypeLowering(contextType).isFixedABI();
456+
}
457+
453458
SILType SILType::substGenericArgs(SILModule &M, SubstitutionMap SubMap,
454459
TypeExpansionContext context) const {
455460
auto fnTy = castTo<SILFunctionType>();

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
618618
case SILInstructionKind::StructElementAddrInst:
619619
case SILInstructionKind::IndexAddrInst:
620620
// TODO: hasArchetype() ?
621-
if (!inst->getOperand(0)->getType().isLoadable(*inst->getFunction())) {
621+
if (!inst->getOperand(0)->getType().isFixedABI(*inst->getFunction())) {
622622
impactType = inst->getOperand(0)->getType();
623623
return RuntimeEffect::MetaData;
624624
}

test/SILOptimizer/performance-annotations.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -import-objc-header %S/Inputs/perf-annotations.h -emit-sil %s -o /dev/null -verify
1+
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -enable-experimental-feature RawLayout -import-objc-header %S/Inputs/perf-annotations.h -emit-sil %s -o /dev/null -verify
22
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
33
// REQUIRES: swift_in_compiler
44

@@ -514,3 +514,16 @@ func testNonCopyable() {
514514
let t = NonCopyableStruct()
515515
t.foo()
516516
}
517+
518+
public struct RawLayoutWrapper: ~Copyable {
519+
private let x = RawLayout<Int>()
520+
521+
@_noLocks func testit() {
522+
x.test()
523+
}
524+
}
525+
526+
@_rawLayout(like: T)
527+
public struct RawLayout<T>: ~Copyable {
528+
public func test() {}
529+
}

0 commit comments

Comments
 (0)