Skip to content

[IRGen] Add metadata pack markers for destroys. #67493

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 2 commits into from
Jul 25, 2023
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
4 changes: 4 additions & 0 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,10 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
llvm::report_fatal_error(
"Instruction resulted in on-stack pack metadata emission but no "
"cleanup instructions were added");
// The markers which indicate where on-stack pack metadata should be
// deallocated were not inserted for I. To fix this, add I's opcode to
// SILInstruction::mayRequirePackMetadata subject to the appropriate
// checks.
}
}
#endif
Expand Down
14 changes: 7 additions & 7 deletions lib/SIL/IR/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,18 +1296,18 @@ bool SILInstruction::mayRequirePackMetadata() const {
}
return false;
}
case SILInstructionKind::DebugValueInst: {
auto *dvi = cast<DebugValueInst>(this);
return dvi->getOperand()->getType().hasPack();
case SILInstructionKind::ClassMethodInst:
case SILInstructionKind::DebugValueInst:
case SILInstructionKind::DestroyAddrInst:
case SILInstructionKind::DestroyValueInst:
// Unary instructions.
{
return getOperand(0)->getType().hasPack();
}
case SILInstructionKind::MetatypeInst: {
auto *mi = cast<MetatypeInst>(this);
return mi->getType().hasPack();
}
case SILInstructionKind::ClassMethodInst: {
auto *cmi = cast<ClassMethodInst>(this);
return cmi->getOperand()->getType().hasPack();
}
case SILInstructionKind::WitnessMethodInst: {
auto *wmi = cast<WitnessMethodInst>(this);
auto ty = wmi->getLookupType();
Expand Down
41 changes: 41 additions & 0 deletions test/IRGen/rdar112792831.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// RUN: %target-swift-frontend -emit-ir -O %s

@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
public struct Predicate<each Input> {
var x: Any? = nil
public func evaluate(_: repeat each Input) -> Bool { return false }
}

public struct PredicateBindings {
}

@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
public protocol PredicateExpression<Output> {
associatedtype Output

func evaluate(_ bindings: PredicateBindings) throws -> Output
}

@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
public struct PredicateEvaluate<
Condition : PredicateExpression,
each Input : PredicateExpression
>
where
Condition.Output == Predicate<repeat (each Input).Output>
{

public typealias Output = Bool

public let predicate: Condition
public let input: (repeat each Input)

public init(predicate: Condition, input: repeat each Input) {
self.predicate = predicate
self.input = (repeat each input)
}

public func evaluate(_ bindings: PredicateBindings) throws -> Output {
try predicate.evaluate(bindings).evaluate(repeat (each input).evaluate(bindings))
}
}