mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Swift AST: make Conformance hashable and rename var proto -> var protocol
This commit is contained in:
@@ -17,7 +17,7 @@ import ASTBridging
|
||||
/// members to the type (or extension) members that provide the functionality for the concrete type.
|
||||
///
|
||||
/// TODO: Ideally, `Conformance` should be an enum
|
||||
public struct Conformance: CustomStringConvertible, NoReflectionChildren {
|
||||
public struct Conformance: CustomStringConvertible, Hashable, NoReflectionChildren {
|
||||
public let bridged: BridgedConformance
|
||||
|
||||
public init(bridged: BridgedConformance) {
|
||||
@@ -28,6 +28,14 @@ public struct Conformance: CustomStringConvertible, NoReflectionChildren {
|
||||
return String(taking: bridged.getDebugDescription())
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(bridged.opaqueValue)
|
||||
}
|
||||
|
||||
public static func ==(lhs: Conformance, rhs: Conformance) -> Bool {
|
||||
lhs.bridged.opaqueValue == rhs.bridged.opaqueValue
|
||||
}
|
||||
|
||||
public var isConcrete: Bool { bridged.isConcrete() }
|
||||
|
||||
public var isValid: Bool { bridged.isValid() }
|
||||
@@ -37,7 +45,7 @@ public struct Conformance: CustomStringConvertible, NoReflectionChildren {
|
||||
return Type(bridged: bridged.getType())
|
||||
}
|
||||
|
||||
public var proto: ProtocolDecl {
|
||||
public var `protocol`: ProtocolDecl {
|
||||
return bridged.getRequirement().getAs(ProtocolDecl.self)
|
||||
}
|
||||
public var isSpecialized: Bool {
|
||||
|
||||
@@ -145,8 +145,10 @@ func specializeWitnessTable(forConformance conformance: Conformance,
|
||||
let substType = witness.subst(with: conformance.specializedSubstitutions)
|
||||
return .associatedType(requirement: requirement, witness: substType)
|
||||
case .associatedConformance(let requirement, let assocConf):
|
||||
// FIXME: let concreteAssociateConf = assocConf.subst(with: conformance.specializedSubstitutions)
|
||||
let concreteAssociateConf = conformance.getAssociatedConformance(ofAssociatedType: requirement.rawType, to: assocConf.proto)
|
||||
// TODO: once we have the API, replace this with:
|
||||
// let concreteAssociateConf = assocConf.subst(with: conformance.specializedSubstitutions)
|
||||
let concreteAssociateConf = conformance.getAssociatedConformance(ofAssociatedType: requirement.rawType,
|
||||
to: assocConf.protocol)
|
||||
if concreteAssociateConf.isSpecialized {
|
||||
specializeWitnessTable(forConformance: concreteAssociateConf,
|
||||
errorLocation: errorLocation,
|
||||
|
||||
Reference in New Issue
Block a user