@@ -102,6 +102,45 @@ static unsigned getGenericParamIndex(Type type) {
102102 return paramTy->getIndex ();
103103}
104104
105+ // / Reverses the transformation performed by
106+ // / RewriteSystemBuilder::getConcreteSubstitutionSchema().
107+ static Type getTypeFromSubstitutionSchema (Type schema,
108+ ArrayRef<Term> substitutions,
109+ TypeArrayView<GenericTypeParamType> genericParams,
110+ const ProtocolGraph &protos,
111+ RewriteContext &ctx) {
112+ assert (!schema->isTypeParameter () && " Must have a concrete type here" );
113+
114+ if (!schema->hasTypeParameter ())
115+ return schema;
116+
117+ return schema.transformRec ([&](Type t) -> Optional<Type> {
118+ if (t->is <GenericTypeParamType>()) {
119+ auto index = getGenericParamIndex (t);
120+
121+ return ctx.getTypeForTerm (substitutions[index],
122+ genericParams, protos);
123+ }
124+
125+ assert (!t->isTypeParameter ());
126+ return None;
127+ });
128+ }
129+
130+ // / Get the concrete type of this equivalence class.
131+ // /
132+ // / Asserts if this equivalence class is not concrete.
133+ Type EquivalenceClass::getConcreteType (
134+ TypeArrayView<GenericTypeParamType> genericParams,
135+ const ProtocolGraph &protos,
136+ RewriteContext &ctx) const {
137+ return getTypeFromSubstitutionSchema (ConcreteType->getConcreteType (),
138+ ConcreteType->getSubstitutions (),
139+ genericParams,
140+ protos,
141+ ctx);
142+ }
143+
105144// / Given a concrete type that is a structural sub-component of a concrete
106145// / type produced by RewriteSystemBuilder::getConcreteSubstitutionSchema(),
107146// / collect the subset of referenced substitutions and renumber the generic
0 commit comments