@@ -316,7 +316,8 @@ class TupleTypeRef final : public TypeRef {
316316
317317public:
318318 TupleTypeRef (std::vector<const TypeRef *> Elements, bool Variadic=false )
319- : TypeRef(TypeRefKind::Tuple), Elements(Elements), Variadic(Variadic) {}
319+ : TypeRef(TypeRefKind::Tuple), Elements(std::move(Elements)),
320+ Variadic (Variadic) {}
320321
321322 template <typename Allocator>
322323 static const TupleTypeRef *create (Allocator &A,
@@ -338,6 +339,84 @@ class TupleTypeRef final : public TypeRef {
338339 }
339340};
340341
342+ class OpaqueArchetypeTypeRef final : public TypeRef {
343+ std::string ID;
344+ std::string Description;
345+ unsigned Ordinal;
346+ // Each ArrayRef in ArgumentLists references into the buffer owned by this
347+ // vector, which must not be modified after construction.
348+ std::vector<const TypeRef *> AllArgumentsBuf;
349+ std::vector<ArrayRef<const TypeRef *>> ArgumentLists;
350+
351+ static TypeRefID Profile (StringRef idString,
352+ StringRef description, unsigned ordinal,
353+ ArrayRef<ArrayRef<const TypeRef *>> argumentLists) {
354+ TypeRefID ID;
355+ ID.addString (idString);
356+ ID.addInteger (ordinal);
357+ for (auto argList : argumentLists) {
358+ ID.addInteger (0u );
359+ for (auto arg : argList)
360+ ID.addPointer (arg);
361+ }
362+
363+ return ID;
364+ }
365+
366+ public:
367+ OpaqueArchetypeTypeRef (StringRef id,
368+ StringRef description, unsigned ordinal,
369+ ArrayRef<ArrayRef<const TypeRef *>> argumentLists)
370+ : TypeRef(TypeRefKind::OpaqueArchetype),
371+ ID (id), Description(description), Ordinal(ordinal)
372+ {
373+ std::vector<unsigned > argumentListLengths;
374+
375+ for (auto argList : argumentLists) {
376+ argumentListLengths.push_back (argList.size ());
377+ AllArgumentsBuf.insert (AllArgumentsBuf.end (),
378+ argList.begin (), argList.end ());
379+ }
380+ auto *data = AllArgumentsBuf.data ();
381+ for (auto length : argumentListLengths) {
382+ ArgumentLists.push_back (ArrayRef<const TypeRef *>(data, length));
383+ data += length;
384+ }
385+ assert (data == AllArgumentsBuf.data () + AllArgumentsBuf.size ());
386+ }
387+
388+ template <typename Allocator>
389+ static const OpaqueArchetypeTypeRef *create (Allocator &A,
390+ StringRef id, StringRef description,
391+ unsigned ordinal,
392+ ArrayRef<ArrayRef<const TypeRef *>> arguments) {
393+ FIND_OR_CREATE_TYPEREF (A, OpaqueArchetypeTypeRef,
394+ id, description, ordinal, arguments);
395+ }
396+
397+ ArrayRef<ArrayRef<const TypeRef *>> getArgumentLists () const {
398+ return ArgumentLists;
399+ }
400+
401+ unsigned getOrdinal () const {
402+ return Ordinal;
403+ }
404+
405+ // / A stable identifier for the opaque type.
406+ StringRef getID () const {
407+ return ID;
408+ }
409+
410+ // / A human-digestible, but not necessarily stable, description of the opaque type.
411+ StringRef getDescription () const {
412+ return Description;
413+ }
414+
415+ static bool classof (const TypeRef *T) {
416+ return T->getKind () == TypeRefKind::OpaqueArchetype;
417+ }
418+ };
419+
341420class FunctionTypeRef final : public TypeRef {
342421 using Param = remote::FunctionParam<const TypeRef *>;
343422
0 commit comments