1
1
# frozen_string_literal: true
2
2
3
+ require 'set'
4
+
3
5
module Jazzy
4
6
module SymbolGraph
5
7
# For extensions we need to track constraints of the extended type
@@ -26,7 +28,7 @@ class ExtNode < BaseNode
26
28
attr_accessor :real_usr
27
29
attr_accessor :name
28
30
attr_accessor :all_constraints # ExtConstraints
29
- attr_accessor :conformances # array , can be empty
31
+ attr_accessor :conformances # set , can be empty
30
32
31
33
# Deduce an extension from a member of an unknown type or
32
34
# of known type with additional constraints
@@ -54,7 +56,7 @@ def initialize(usr, name, constraints)
54
56
self . usr = usr
55
57
self . name = name
56
58
self . all_constraints = constraints
57
- self . conformances = [ ]
59
+ self . conformances = Set . new
58
60
super ( )
59
61
end
60
62
@@ -65,13 +67,13 @@ def constraints
65
67
end
66
68
67
69
def add_conformance ( protocol )
68
- conformances . append ( protocol ) . sort!
70
+ conformances . add ( protocol )
69
71
end
70
72
71
73
def full_declaration
72
74
decl = "extension #{ name } "
73
75
unless conformances . empty?
74
- decl += " : #{ conformances . join ( ', ' ) } "
76
+ decl += " : #{ conformances . sort . join ( ', ' ) } "
75
77
end
76
78
decl + all_constraints . ext . to_where_clause
77
79
end
@@ -90,7 +92,7 @@ def to_sourcekit(module_name, ext_module_name)
90
92
}
91
93
92
94
unless conformances . empty?
93
- hash [ 'key.inheritedtypes' ] = conformances . map do |conformance |
95
+ hash [ 'key.inheritedtypes' ] = conformances . sort . map do |conformance |
94
96
{ 'key.name' => conformance }
95
97
end
96
98
end
@@ -100,11 +102,13 @@ def to_sourcekit(module_name, ext_module_name)
100
102
hash
101
103
end
102
104
103
- # Sort order - by type name then constraint
105
+ # Sort order - by type name then constraint then conformances
106
+ # Conformance check needed for stable order with Swift 5.9
107
+ # extension symbols that can't merge as well as previously.
104
108
include Comparable
105
109
106
110
def sort_key
107
- name + constraints . map ( &:to_swift ) . join
111
+ name + constraints . map ( &:to_swift ) . join + conformances . sort . join
108
112
end
109
113
110
114
def <=>( other )
0 commit comments