@@ -213,6 +213,29 @@ struct SynthesizedExtensionAnalyzer::Implementation {
213
213
operator bool () const { return Ext; }
214
214
SynthesizedExtensionInfo (bool IsSynthesized = true ) :
215
215
IsSynthesized (IsSynthesized) {}
216
+ bool operator < (const SynthesizedExtensionInfo& Rhs) const {
217
+
218
+ // Synthesized are always after actual ones.
219
+ if (IsSynthesized != Rhs.IsSynthesized )
220
+ return !IsSynthesized;
221
+
222
+ // If not from the same file, sort by file name.
223
+ if (auto LFile = Ext->getSourceFileName ()) {
224
+ if (auto RFile = Rhs.Ext ->getSourceFileName ()) {
225
+ int Result = LFile.getValue ().compare (RFile.getValue ());
226
+ if (Result != 0 )
227
+ return Result < 0 ;
228
+ }
229
+ }
230
+
231
+ // Otherwise, sort by source order.
232
+ if (auto LeftOrder = Ext->getSourceOrder ()) {
233
+ if (auto RightOrder = Rhs.Ext ->getSourceOrder ()) {
234
+ return LeftOrder.getValue () < RightOrder.getValue ();
235
+ }
236
+ }
237
+ return false ;
238
+ }
216
239
};
217
240
218
241
struct ExtensionMergeInfo {
@@ -270,6 +293,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
270
293
MergeGroupKind::UnmergableWithTypeDef) {
271
294
Members.push_back (Info);
272
295
}
296
+
297
+ void sortMembers () {
298
+ std::sort (Members.begin (), Members.end (),
299
+ [](SynthesizedExtensionInfo *LHS, SynthesizedExtensionInfo *RHS) {
300
+ return (*LHS) < (*RHS);
301
+ });
302
+ }
303
+
273
304
bool operator < (const ExtensionMergeGroup& Rhs) const {
274
305
if (RequirementsCount == Rhs.RequirementsCount )
275
306
return InheritanceCount < Rhs.InheritanceCount ;
@@ -493,6 +524,9 @@ struct SynthesizedExtensionAnalyzer::Implementation {
493
524
494
525
populateMergeGroup (*InfoMap, MergeInfoMap, AllGroups);
495
526
std::sort (AllGroups.begin (), AllGroups.end ());
527
+ for (auto &Group : AllGroups) {
528
+ Group.sortMembers ();
529
+ }
496
530
return InfoMap;
497
531
}
498
532
};
0 commit comments