steep-activesupport-4 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGELOG.md +1032 -0
  5. data/LICENSE +21 -0
  6. data/README.md +260 -0
  7. data/Rakefile +227 -0
  8. data/Steepfile +68 -0
  9. data/bin/console +14 -0
  10. data/bin/generate-diagnostics-docs.rb +112 -0
  11. data/bin/mem_graph.rb +67 -0
  12. data/bin/mem_prof.rb +102 -0
  13. data/bin/output_rebaseline.rb +34 -0
  14. data/bin/output_test.rb +60 -0
  15. data/bin/rbs +20 -0
  16. data/bin/rbs-inline +19 -0
  17. data/bin/setup +9 -0
  18. data/bin/stackprof_test.rb +19 -0
  19. data/bin/steep +19 -0
  20. data/bin/steep-check.rb +251 -0
  21. data/bin/steep-prof +16 -0
  22. data/doc/narrowing.md +195 -0
  23. data/doc/shape.md +194 -0
  24. data/exe/steep +18 -0
  25. data/guides/README.md +5 -0
  26. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +126 -0
  27. data/guides/src/getting-started/getting-started.md +163 -0
  28. data/guides/src/nil-optional/nil-optional.md +195 -0
  29. data/lib/steep/annotation_parser.rb +199 -0
  30. data/lib/steep/ast/annotation/collection.rb +172 -0
  31. data/lib/steep/ast/annotation.rb +137 -0
  32. data/lib/steep/ast/builtin.rb +104 -0
  33. data/lib/steep/ast/ignore.rb +148 -0
  34. data/lib/steep/ast/node/type_application.rb +88 -0
  35. data/lib/steep/ast/node/type_assertion.rb +81 -0
  36. data/lib/steep/ast/types/any.rb +35 -0
  37. data/lib/steep/ast/types/boolean.rb +45 -0
  38. data/lib/steep/ast/types/bot.rb +35 -0
  39. data/lib/steep/ast/types/class.rb +43 -0
  40. data/lib/steep/ast/types/factory.rb +557 -0
  41. data/lib/steep/ast/types/helper.rb +40 -0
  42. data/lib/steep/ast/types/instance.rb +42 -0
  43. data/lib/steep/ast/types/intersection.rb +93 -0
  44. data/lib/steep/ast/types/literal.rb +59 -0
  45. data/lib/steep/ast/types/logic.rb +84 -0
  46. data/lib/steep/ast/types/name.rb +128 -0
  47. data/lib/steep/ast/types/nil.rb +41 -0
  48. data/lib/steep/ast/types/proc.rb +117 -0
  49. data/lib/steep/ast/types/record.rb +79 -0
  50. data/lib/steep/ast/types/self.rb +43 -0
  51. data/lib/steep/ast/types/shared_instance.rb +11 -0
  52. data/lib/steep/ast/types/top.rb +35 -0
  53. data/lib/steep/ast/types/tuple.rb +60 -0
  54. data/lib/steep/ast/types/union.rb +97 -0
  55. data/lib/steep/ast/types/var.rb +65 -0
  56. data/lib/steep/ast/types/void.rb +35 -0
  57. data/lib/steep/cli.rb +401 -0
  58. data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
  59. data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
  60. data/lib/steep/diagnostic/helper.rb +18 -0
  61. data/lib/steep/diagnostic/lsp_formatter.rb +78 -0
  62. data/lib/steep/diagnostic/result_printer2.rb +48 -0
  63. data/lib/steep/diagnostic/ruby.rb +1221 -0
  64. data/lib/steep/diagnostic/signature.rb +570 -0
  65. data/lib/steep/drivers/annotations.rb +52 -0
  66. data/lib/steep/drivers/check.rb +339 -0
  67. data/lib/steep/drivers/checkfile.rb +210 -0
  68. data/lib/steep/drivers/diagnostic_printer.rb +105 -0
  69. data/lib/steep/drivers/init.rb +66 -0
  70. data/lib/steep/drivers/langserver.rb +56 -0
  71. data/lib/steep/drivers/print_project.rb +113 -0
  72. data/lib/steep/drivers/stats.rb +203 -0
  73. data/lib/steep/drivers/utils/driver_helper.rb +143 -0
  74. data/lib/steep/drivers/utils/jobs_option.rb +26 -0
  75. data/lib/steep/drivers/vendor.rb +27 -0
  76. data/lib/steep/drivers/watch.rb +194 -0
  77. data/lib/steep/drivers/worker.rb +58 -0
  78. data/lib/steep/equatable.rb +23 -0
  79. data/lib/steep/expectations.rb +228 -0
  80. data/lib/steep/index/rbs_index.rb +350 -0
  81. data/lib/steep/index/signature_symbol_provider.rb +185 -0
  82. data/lib/steep/index/source_index.rb +167 -0
  83. data/lib/steep/interface/block.rb +103 -0
  84. data/lib/steep/interface/builder.rb +843 -0
  85. data/lib/steep/interface/function.rb +1090 -0
  86. data/lib/steep/interface/method_type.rb +330 -0
  87. data/lib/steep/interface/shape.rb +239 -0
  88. data/lib/steep/interface/substitution.rb +159 -0
  89. data/lib/steep/interface/type_param.rb +115 -0
  90. data/lib/steep/located_value.rb +20 -0
  91. data/lib/steep/method_name.rb +42 -0
  92. data/lib/steep/module_helper.rb +24 -0
  93. data/lib/steep/node_helper.rb +273 -0
  94. data/lib/steep/path_helper.rb +30 -0
  95. data/lib/steep/project/dsl.rb +268 -0
  96. data/lib/steep/project/group.rb +31 -0
  97. data/lib/steep/project/options.rb +63 -0
  98. data/lib/steep/project/pattern.rb +59 -0
  99. data/lib/steep/project/target.rb +92 -0
  100. data/lib/steep/project.rb +78 -0
  101. data/lib/steep/rake_task.rb +132 -0
  102. data/lib/steep/range_extension.rb +29 -0
  103. data/lib/steep/server/base_worker.rb +97 -0
  104. data/lib/steep/server/change_buffer.rb +73 -0
  105. data/lib/steep/server/custom_methods.rb +77 -0
  106. data/lib/steep/server/delay_queue.rb +45 -0
  107. data/lib/steep/server/interaction_worker.rb +492 -0
  108. data/lib/steep/server/lsp_formatter.rb +455 -0
  109. data/lib/steep/server/master.rb +912 -0
  110. data/lib/steep/server/target_group_files.rb +205 -0
  111. data/lib/steep/server/type_check_controller.rb +366 -0
  112. data/lib/steep/server/type_check_worker.rb +303 -0
  113. data/lib/steep/server/work_done_progress.rb +64 -0
  114. data/lib/steep/server/worker_process.rb +176 -0
  115. data/lib/steep/services/completion_provider.rb +802 -0
  116. data/lib/steep/services/content_change.rb +61 -0
  117. data/lib/steep/services/file_loader.rb +74 -0
  118. data/lib/steep/services/goto_service.rb +441 -0
  119. data/lib/steep/services/hover_provider/rbs.rb +88 -0
  120. data/lib/steep/services/hover_provider/ruby.rb +221 -0
  121. data/lib/steep/services/hover_provider/singleton_methods.rb +20 -0
  122. data/lib/steep/services/path_assignment.rb +46 -0
  123. data/lib/steep/services/signature_help_provider.rb +202 -0
  124. data/lib/steep/services/signature_service.rb +428 -0
  125. data/lib/steep/services/stats_calculator.rb +68 -0
  126. data/lib/steep/services/type_check_service.rb +394 -0
  127. data/lib/steep/services/type_name_completion.rb +236 -0
  128. data/lib/steep/signature/validator.rb +651 -0
  129. data/lib/steep/source/ignore_ranges.rb +69 -0
  130. data/lib/steep/source.rb +691 -0
  131. data/lib/steep/subtyping/cache.rb +30 -0
  132. data/lib/steep/subtyping/check.rb +1113 -0
  133. data/lib/steep/subtyping/constraints.rb +341 -0
  134. data/lib/steep/subtyping/relation.rb +101 -0
  135. data/lib/steep/subtyping/result.rb +324 -0
  136. data/lib/steep/subtyping/variable_variance.rb +89 -0
  137. data/lib/steep/test.rb +9 -0
  138. data/lib/steep/thread_waiter.rb +43 -0
  139. data/lib/steep/type_construction.rb +5183 -0
  140. data/lib/steep/type_inference/block_params.rb +416 -0
  141. data/lib/steep/type_inference/case_when.rb +303 -0
  142. data/lib/steep/type_inference/constant_env.rb +56 -0
  143. data/lib/steep/type_inference/context.rb +195 -0
  144. data/lib/steep/type_inference/logic_type_interpreter.rb +613 -0
  145. data/lib/steep/type_inference/method_call.rb +193 -0
  146. data/lib/steep/type_inference/method_params.rb +531 -0
  147. data/lib/steep/type_inference/multiple_assignment.rb +194 -0
  148. data/lib/steep/type_inference/send_args.rb +712 -0
  149. data/lib/steep/type_inference/type_env.rb +341 -0
  150. data/lib/steep/type_inference/type_env_builder.rb +138 -0
  151. data/lib/steep/typing.rb +321 -0
  152. data/lib/steep/version.rb +3 -0
  153. data/lib/steep.rb +369 -0
  154. data/manual/annotations.md +181 -0
  155. data/manual/ignore.md +20 -0
  156. data/manual/ruby-diagnostics.md +1879 -0
  157. data/sample/Steepfile +22 -0
  158. data/sample/lib/conference.rb +49 -0
  159. data/sample/lib/length.rb +35 -0
  160. data/sample/sig/conference.rbs +42 -0
  161. data/sample/sig/generics.rbs +15 -0
  162. data/sample/sig/length.rbs +34 -0
  163. data/steep-activesupport-4.gemspec +55 -0
  164. metadata +437 -0
@@ -0,0 +1,56 @@
1
+ module Steep
2
+ module TypeInference
3
+ class ConstantEnv
4
+ attr_reader :context
5
+ attr_reader :factory
6
+ attr_reader :resolver
7
+
8
+ def initialize(factory:, context:, resolver:)
9
+ @factory = factory
10
+ @context = context
11
+ @resolver = resolver
12
+ end
13
+
14
+ def resolve(name)
15
+ decompose_constant(
16
+ resolver.resolve(name, context: context)
17
+ )
18
+ end
19
+
20
+ def toplevel(name)
21
+ decompose_constant(
22
+ resolver.table.toplevel[name]
23
+ )
24
+ end
25
+
26
+ def constants
27
+ cs = resolver.constants(context) or raise
28
+ cs.transform_values {|c| decompose_constant!(c) }
29
+ end
30
+
31
+ def resolve_child(module_name, constant_name)
32
+ decompose_constant(
33
+ resolver.resolve_child(module_name, constant_name)
34
+ )
35
+ end
36
+
37
+ def children(module_name)
38
+ resolver.children(module_name).transform_values {|c| decompose_constant!(c) }
39
+ end
40
+
41
+ def decompose_constant!(constant)
42
+ decompose_constant(constant) || raise
43
+ end
44
+
45
+ def decompose_constant(constant)
46
+ if constant
47
+ [
48
+ factory.type(constant.type),
49
+ constant.name,
50
+ constant.entry
51
+ ]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,195 @@
1
+ module Steep
2
+ module TypeInference
3
+ class Context
4
+ class MethodContext
5
+ attr_reader :name
6
+ attr_reader :method
7
+ attr_reader :method_type
8
+ attr_reader :return_type
9
+ attr_reader :super_method
10
+ attr_reader :forward_arg_type
11
+
12
+ def initialize(name:, method:, method_type:, return_type:, super_method:, forward_arg_type:)
13
+ @name = name
14
+ @method = method
15
+ @return_type = return_type
16
+ @method_type = method_type
17
+ @super_method = super_method
18
+ @forward_arg_type = forward_arg_type
19
+ end
20
+
21
+ def block_type
22
+ method_type&.block
23
+ end
24
+
25
+ def attribute_setter?
26
+ name.to_s.end_with?('=')
27
+ end
28
+ end
29
+
30
+ class BlockContext
31
+ attr_reader :body_type
32
+
33
+ def initialize(body_type:)
34
+ @body_type = body_type
35
+ end
36
+
37
+ def subst(s)
38
+ BlockContext.new(body_type: body_type&.subst(s))
39
+ end
40
+ end
41
+
42
+ class BreakContext
43
+ attr_reader :break_type
44
+ attr_reader :next_type
45
+
46
+ def initialize(break_type:, next_type:)
47
+ @break_type = break_type
48
+ @next_type = next_type
49
+ end
50
+
51
+ def subst(s)
52
+ BreakContext.new(break_type: break_type.subst(s), next_type: next_type&.subst(s))
53
+ end
54
+ end
55
+
56
+ class ModuleContext
57
+ attr_reader :instance_type
58
+ attr_reader :module_type
59
+ attr_reader :defined_instance_methods
60
+ attr_reader :defined_module_methods
61
+ attr_reader :nesting
62
+ attr_reader :implement_name
63
+ attr_reader :class_name
64
+ attr_reader :instance_definition
65
+ attr_reader :module_definition
66
+
67
+ def initialize(instance_type:, module_type:, implement_name:, class_name:, instance_definition: nil, module_definition: nil, nesting:)
68
+ @instance_type = instance_type
69
+ @module_type = module_type
70
+ @defined_instance_methods = Set.new
71
+ @defined_module_methods = Set.new
72
+ @implement_name = implement_name
73
+ @nesting = nesting
74
+ @class_name = class_name
75
+ @instance_definition = instance_definition
76
+ @module_definition = module_definition
77
+ end
78
+
79
+ def class_variables
80
+ if module_definition
81
+ @class_variables ||= module_definition.class_variables.transform_values do |var_def|
82
+ var_def.type
83
+ end
84
+ end
85
+ end
86
+
87
+ def update(
88
+ instance_type: self.instance_type,
89
+ module_type: self.module_type,
90
+ implement_name: self.implement_name,
91
+ class_name: self.class_name,
92
+ instance_definition: self.instance_definition,
93
+ module_definition: self.module_definition,
94
+ nesting: self.nesting
95
+ )
96
+ ModuleContext.new(
97
+ instance_type: instance_type,
98
+ module_type: module_type,
99
+ implement_name: implement_name,
100
+ nesting: nesting,
101
+ class_name: class_name,
102
+ instance_definition: instance_definition,
103
+ module_definition: module_definition
104
+ )
105
+ end
106
+ end
107
+
108
+ class TypeVariableContext
109
+ attr_reader :table
110
+ attr_reader :type_params
111
+
112
+ def initialize(type_params, parent_context: nil)
113
+ @type_params = type_params
114
+
115
+ @table = {}
116
+ table.merge!(parent_context.table) if parent_context
117
+
118
+ type_params.each do |param|
119
+ table[param.name] = param
120
+ end
121
+ end
122
+
123
+ def [](name)
124
+ table.fetch(name).upper_bound
125
+ end
126
+
127
+ def upper_bounds
128
+ @upper_bounds ||= table.each_value.with_object({}) do |type_param, bounds| #$ Hash[Symbol, AST::Types::t]
129
+ if type_param.upper_bound
130
+ bounds[type_param.name] = type_param.upper_bound
131
+ end
132
+ end
133
+ end
134
+
135
+ def self.empty
136
+ new([])
137
+ end
138
+ end
139
+
140
+ attr_reader :call_context
141
+ attr_reader :method_context
142
+ attr_reader :block_context
143
+ attr_reader :break_context
144
+ attr_reader :module_context
145
+ attr_reader :self_type
146
+ attr_reader :type_env
147
+ attr_reader :variable_context
148
+
149
+ def initialize(method_context:, block_context:, break_context:, module_context:, self_type:, type_env:, call_context:, variable_context:)
150
+ @method_context = method_context
151
+ @block_context = block_context
152
+ @break_context = break_context
153
+ @module_context = module_context
154
+ @self_type = self_type
155
+ @type_env = type_env
156
+ @call_context = call_context
157
+ @variable_context = variable_context
158
+ end
159
+
160
+ def with(method_context: self.method_context,
161
+ block_context: self.block_context,
162
+ break_context: self.break_context,
163
+ module_context: self.module_context,
164
+ self_type: self.self_type,
165
+ type_env: self.type_env,
166
+ call_context: self.call_context,
167
+ variable_context: self.variable_context)
168
+ self.class.new(
169
+ method_context: method_context,
170
+ block_context: block_context,
171
+ break_context: break_context,
172
+ module_context: module_context,
173
+ self_type: self_type,
174
+ type_env: type_env,
175
+ call_context: call_context,
176
+ variable_context: variable_context
177
+ )
178
+ end
179
+
180
+ def inspect
181
+ s = "#<%s:%#018x " % [self.class, object_id]
182
+ s << instance_variables.map(&:to_s).sort.map {|name| "#{name}=..." }.join(", ")
183
+ s + ">"
184
+ end
185
+
186
+ def factory
187
+ type_env.constant_env.factory
188
+ end
189
+
190
+ def env
191
+ factory.env
192
+ end
193
+ end
194
+ end
195
+ end