Files
swift-mirror/SwiftCompilerSources/Sources/AST/SubstitutionMap.swift
Erik Eckstein 10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00

56 lines
1.9 KiB
Swift

//===--- SubstitutionMap.swift --------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
import Basic
import ASTBridging
/// SubstitutionMap describes the mapping of abstract types to replacement types,
/// together with associated conformances to use for deriving nested types and conformances.
///
/// Substitution maps are primarily used when performing substitutions into any entity that
/// can reference type parameters and conformances.
public struct SubstitutionMap {
public let bridged: BridgedSubstitutionMap
public init(bridged: BridgedSubstitutionMap) {
self.bridged = bridged
}
public init() {
self.bridged = BridgedSubstitutionMap()
}
public var isEmpty: Bool { bridged.isEmpty() }
public var hasAnySubstitutableParams: Bool { bridged.hasAnySubstitutableParams() }
public var conformances: ConformanceArray { ConformanceArray(substitutionMap: self) }
public struct ConformanceArray : BridgedRandomAccessCollection {
fileprivate let bridgedSubs: BridgedSubstitutionMap
public let count: Int
init(substitutionMap: SubstitutionMap) {
self.bridgedSubs = substitutionMap.bridged
self.count = substitutionMap.bridged.getNumConformances()
}
public var startIndex: Int { return 0 }
public var endIndex: Int { return count }
public subscript(_ index: Int) -> Conformance {
assert(index >= startIndex && index < endIndex)
return Conformance(bridged: bridgedSubs.getConformance(index))
}
}
}