forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubstitution.cpp
54 lines (48 loc) · 1.77 KB
/
Substitution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//===--- 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;
}