Files
swift-mirror/include/swift/SILAnalysis/DestructorAnalysis.h
Arnold Schwaighofer 06a0a23562 Add a destructor memory effect analysis
This adds an analysis to the compiler that identifies types that are may store
to memory on destruction.

It adds a compiler known protocol _DestructorSafeContainer that allows the
standard library to identify containers whose destructor's memory effects
depends strictly on the type parameters of the container.

Array<T> : _DestructorSafeContainer {} may not store to memory during
destruction if the bound T is a type that does not store to memory on
destruction.

This is needed to deduce that for example Array<Array<Int>> is does not store to
memory on destruction (e.g during a call to release).

rdar://18940376

Swift SVN r23242
2014-11-11 19:27:41 +00:00

43 lines
1.3 KiB
C++

//===--- DestructorAnalysis.h ------------------------------*- C++ -*------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILANALYSIS_DESTRUCTORANALYSIS_H
#define SWIFT_SILANALYSIS_DESTRUCTORANALYSIS_H
#include "swift/SIL/SILValue.h"
#include "swift/SILAnalysis/Analysis.h"
namespace swift {
/// This analysis determines memory effects during destruction.
class DestructorAnalysis : public SILAnalysis {
SILModule *Mod;
public:
DestructorAnalysis(SILModule *M)
: SILAnalysis(AnalysisKind::Destructor), Mod(M) {}
static bool classof(const SILAnalysis *S) {
return S->getKind() == AnalysisKind::Destructor;
}
/// Returns true if destruction of T may store to memory.
bool mayStoreToMemoryOnDestruction(SILType T);
protected:
bool isSafeType(Type);
bool implementsDestructorSafeContainerProtocol(NominalTypeDecl *);
bool areTypeParametersSafe(CanType);
ASTContext &getASTContext();
};
}
#endif