Skip to content

[sil] Add an implementation of isIndirectResultOperand() onto ApplySite that returns false for partial_apply. #33112

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
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
42 changes: 36 additions & 6 deletions include/swift/SIL/ApplySite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef SWIFT_SIL_APPLYSITE_H
#define SWIFT_SIL_APPLYSITE_H

#include "swift/Basic/STLExtras.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILBasicBlock.h"
#include "swift/SIL/SILFunction.h"
Expand All @@ -29,6 +30,8 @@

namespace swift {

class FullApplySite;

//===----------------------------------------------------------------------===//
// ApplySite
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -396,6 +399,10 @@ class ApplySite {
llvm_unreachable("covered switch");
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const;

/// Return whether the given apply is of a formally-throwing function
/// which is statically known not to throw.
bool isNonThrowing() const {
Expand Down Expand Up @@ -425,6 +432,10 @@ class ApplySite {
}

void dump() const LLVM_ATTRIBUTE_USED { getInstruction()->dump(); }

/// Attempt to cast this apply site to a full apply site, returning None on
/// failure.
Optional<FullApplySite> asFullApplySite() const;
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -562,12 +573,6 @@ class FullApplySite : public ApplySite {
return op.getOperandNumber() < getOperandIndexOfFirstArgument();
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const {
return getCalleeArgIndex(op) < getNumIndirectSILResults();
}

/// Is this an ApplySite that begins the evaluation of a coroutine.
bool beginsCoroutineEvaluation() const {
switch (getKind()) {
Expand Down Expand Up @@ -637,6 +642,12 @@ class FullApplySite : public ApplySite {
llvm_unreachable("covered switch isn't covered");
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const {
return getCalleeArgIndex(op) < getNumIndirectSILResults();
}

static FullApplySite getFromOpaqueValue(void *p) { return FullApplySite(p); }

static bool classof(const SILInstruction *inst) {
Expand Down Expand Up @@ -729,4 +740,23 @@ template <> struct DenseMapInfo<::swift::FullApplySite> {

} // namespace llvm

//===----------------------------------------------------------------------===//
// Inline Definitions to work around Forward Declaration
//===----------------------------------------------------------------------===//

namespace swift {

inline Optional<FullApplySite> ApplySite::asFullApplySite() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gottesmm this new API is inconsistent with existing apply site type coercion which always returns an invalid apply site on failure. Adding another layer of Optional is extremely confusing. I don't think you need this API anyway, but it definitely should not change the return type.

return FullApplySite::isa(getInstruction());
}

inline bool ApplySite::isIndirectResultOperand(const Operand &op) const {
auto fas = asFullApplySite();
if (!fas)
return false;
return fas->isIndirectResultOperand(op);
}

} // namespace swift

#endif