mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
//===--- Substitution.cpp - Type substitutions ----------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the Substitution class and operations on it.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/AST/Substitution.h"
|
|
|
|
#include "swift/AST/ASTContext.h"
|
|
#include "swift/AST/GenericEnvironment.h"
|
|
#include "swift/AST/Module.h"
|
|
#include "swift/AST/ProtocolConformance.h"
|
|
#include "swift/AST/SubstitutionMap.h"
|
|
#include "swift/AST/Types.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
using namespace swift;
|
|
|
|
bool Substitution::operator==(const Substitution &other) const {
|
|
// The archetypes may be missing, but we can compare them directly
|
|
// because archetypes are always canonical.
|
|
return
|
|
Replacement->isEqual(other.Replacement) &&
|
|
Conformance.equals(other.Conformance);
|
|
}
|
|
|
|
Substitution::Substitution(Type Replacement,
|
|
ArrayRef<ProtocolConformanceRef> Conformance)
|
|
: Replacement(Replacement), Conformance(Conformance)
|
|
{
|
|
// The replacement type must be materializable.
|
|
assert(Replacement->isMaterializable()
|
|
&& "cannot substitute with a non-materializable type");
|
|
}
|
|
|
|
bool Substitution::isCanonical() const {
|
|
if (!getReplacement()->isCanonical())
|
|
return false;
|
|
for (auto conf : getConformances()) {
|
|
if (!conf.isCanonical())
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|