tapioca 0.17.9 → 0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/tapioca/commands/abstract_dsl.rb +21 -2
- data/lib/tapioca/commands/abstract_gem.rb +20 -1
- data/lib/tapioca/commands/annotations.rb +7 -1
- data/lib/tapioca/commands/check_shims.rb +9 -1
- data/lib/tapioca/dsl/compiler.rb +17 -12
- data/lib/tapioca/dsl/compilers/aasm.rb +2 -2
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -2
- data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -1
- data/lib/tapioca/dsl/compilers/action_text.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_job.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +8 -2
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +12 -81
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_storage.rb +2 -2
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -6
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -1
- data/lib/tapioca/dsl/compilers/config.rb +2 -2
- data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -1
- data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -2
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/kredis.rb +1 -1
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -2
- data/lib/tapioca/dsl/compilers/protobuf.rb +2 -2
- data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -1
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -1
- data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -1
- data/lib/tapioca/dsl/compilers/state_machines.rb +2 -2
- data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -7
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +3 -1
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +18 -3
- data/lib/tapioca/dsl/pipeline.rb +25 -11
- data/lib/tapioca/gem/events.rb +15 -8
- data/lib/tapioca/gem/listeners/methods.rb +19 -7
- data/lib/tapioca/gem/listeners/mixins.rb +3 -3
- data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -1
- data/lib/tapioca/gem/pipeline.rb +25 -18
- data/lib/tapioca/gemfile.rb +1 -1
- data/lib/tapioca/helpers/config_helper.rb +5 -1
- data/lib/tapioca/helpers/rbi_files_helper.rb +8 -1
- data/lib/tapioca/loaders/gem.rb +14 -2
- data/lib/tapioca/rbi_ext/model.rb +9 -2
- data/lib/tapioca/repo_index.rb +1 -1
- data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
- data/lib/tapioca/runtime/attached_class_of_legacy.rb +1 -1
- data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +6 -6
- data/lib/tapioca/runtime/generic_type_registry.rb +8 -8
- data/lib/tapioca/runtime/reflection.rb +19 -19
- data/lib/tapioca/runtime/trackers/constant_definition.rb +3 -3
- data/lib/tapioca/runtime/trackers/method_definition.rb +4 -4
- data/lib/tapioca/runtime/trackers/mixin.rb +5 -5
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +2 -2
- data/lib/tapioca/runtime/trackers/tracker.rb +1 -1
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +1 -1
- data/lib/tapioca/static/requires_compiler.rb +1 -1
- data/lib/tapioca/version.rb +1 -1
- metadata +1 -1
data/lib/tapioca/gem/pipeline.rb
CHANGED
|
@@ -72,27 +72,34 @@ module Tapioca
|
|
|
72
72
|
@events << Gem::ConstantFound.new(symbol, constant)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#: (String symbol, Module constant) -> void
|
|
75
|
+
#: (String symbol, T::Module[top] constant) -> void
|
|
76
76
|
def push_foreign_constant(symbol, constant)
|
|
77
77
|
@events << Gem::ForeignConstantFound.new(symbol, constant)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
#: (String symbol, Module constant, RBI::Const node) -> void
|
|
80
|
+
#: (String symbol, T::Module[top] constant, RBI::Const node) -> void
|
|
81
81
|
def push_const(symbol, constant, node)
|
|
82
82
|
@events << Gem::ConstNodeAdded.new(symbol, constant, node)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
#: (String symbol, Module constant, RBI::Scope node) -> void
|
|
85
|
+
#: (String symbol, T::Module[top] constant, RBI::Scope node) -> void
|
|
86
86
|
def push_scope(symbol, constant, node)
|
|
87
87
|
@events << Gem::ScopeNodeAdded.new(symbol, constant, node)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
#: (String symbol, Module constant, RBI::Scope node) -> void
|
|
90
|
+
#: (String symbol, T::Module[top] constant, RBI::Scope node) -> void
|
|
91
91
|
def push_foreign_scope(symbol, constant, node)
|
|
92
92
|
@events << Gem::ForeignScopeNodeAdded.new(symbol, constant, node)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
#: (
|
|
95
|
+
#: (
|
|
96
|
+
#| String symbol,
|
|
97
|
+
#| T::Module[top] constant,
|
|
98
|
+
#| UnboundMethod method,
|
|
99
|
+
#| RBI::Method node,
|
|
100
|
+
#| untyped signature,
|
|
101
|
+
#| Array[[Symbol, String]] parameters
|
|
102
|
+
#| ) -> void
|
|
96
103
|
def push_method(symbol, constant, method, node, signature, parameters) # rubocop:disable Metrics/ParameterLists
|
|
97
104
|
@events << Gem::MethodNodeAdded.new(symbol, constant, method, node, signature, parameters)
|
|
98
105
|
end
|
|
@@ -145,7 +152,7 @@ module Tapioca
|
|
|
145
152
|
end
|
|
146
153
|
end
|
|
147
154
|
|
|
148
|
-
#: (Symbol method_name, Module owner) -> MethodDefinitionLookupResult
|
|
155
|
+
#: (Symbol method_name, T::Module[top] owner) -> MethodDefinitionLookupResult
|
|
149
156
|
def method_definition_in_gem(method_name, owner)
|
|
150
157
|
definitions = Tapioca::Runtime::Trackers::MethodDefinition.method_definitions_for(method_name, owner)
|
|
151
158
|
|
|
@@ -171,7 +178,7 @@ module Tapioca
|
|
|
171
178
|
|
|
172
179
|
# Helpers
|
|
173
180
|
|
|
174
|
-
#: (Module constant) -> String?
|
|
181
|
+
#: (T::Module[top] constant) -> String?
|
|
175
182
|
def name_of(constant)
|
|
176
183
|
name = name_of_proxy_target(constant, super(class_of(constant)))
|
|
177
184
|
return name if name
|
|
@@ -243,7 +250,7 @@ module Tapioca
|
|
|
243
250
|
|
|
244
251
|
# Compiling
|
|
245
252
|
|
|
246
|
-
#: (String symbol, Module constant) -> void
|
|
253
|
+
#: (String symbol, T::Module[top] constant) -> void
|
|
247
254
|
def compile_foreign_constant(symbol, constant)
|
|
248
255
|
return if skip_foreign_constant?(symbol, constant)
|
|
249
256
|
return if seen?(symbol)
|
|
@@ -269,7 +276,7 @@ module Tapioca
|
|
|
269
276
|
end
|
|
270
277
|
end
|
|
271
278
|
|
|
272
|
-
#: (String name, Module constant) -> void
|
|
279
|
+
#: (String name, T::Module[top] constant) -> void
|
|
273
280
|
def compile_alias(name, constant)
|
|
274
281
|
return if seen?(name)
|
|
275
282
|
|
|
@@ -324,7 +331,7 @@ module Tapioca
|
|
|
324
331
|
@root << node
|
|
325
332
|
end
|
|
326
333
|
|
|
327
|
-
#: (String name, Module constant) -> void
|
|
334
|
+
#: (String name, T::Module[top] constant) -> void
|
|
328
335
|
def compile_module(name, constant)
|
|
329
336
|
return if skip_module?(name, constant)
|
|
330
337
|
return if seen?(name)
|
|
@@ -335,7 +342,7 @@ module Tapioca
|
|
|
335
342
|
push_scope(name, constant, scope)
|
|
336
343
|
end
|
|
337
344
|
|
|
338
|
-
#: (String name, Module constant) -> RBI::Scope
|
|
345
|
+
#: (String name, T::Module[top] constant) -> RBI::Scope
|
|
339
346
|
def compile_scope(name, constant)
|
|
340
347
|
scope = if constant.is_a?(Class)
|
|
341
348
|
superclass = compile_superclass(constant)
|
|
@@ -418,7 +425,7 @@ module Tapioca
|
|
|
418
425
|
false
|
|
419
426
|
end
|
|
420
427
|
|
|
421
|
-
#: (String name, Module constant) -> bool
|
|
428
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
422
429
|
def skip_alias?(name, constant)
|
|
423
430
|
return true if symbol_in_payload?(name)
|
|
424
431
|
return true unless constant_in_gem?(name)
|
|
@@ -436,12 +443,12 @@ module Tapioca
|
|
|
436
443
|
false
|
|
437
444
|
end
|
|
438
445
|
|
|
439
|
-
#: (String name, Module constant) -> bool
|
|
446
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
440
447
|
def skip_foreign_constant?(name, constant)
|
|
441
448
|
Tapioca::TypeVariableModule === constant
|
|
442
449
|
end
|
|
443
450
|
|
|
444
|
-
#: (String name, Module constant) -> bool
|
|
451
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
445
452
|
def skip_module?(name, constant)
|
|
446
453
|
return true unless defined_in_gem?(constant, strict: false)
|
|
447
454
|
return true if Tapioca::TypeVariableModule === constant
|
|
@@ -449,7 +456,7 @@ module Tapioca
|
|
|
449
456
|
false
|
|
450
457
|
end
|
|
451
458
|
|
|
452
|
-
#: (Module constant, ?strict: bool) -> bool
|
|
459
|
+
#: (T::Module[top] constant, ?strict: bool) -> bool
|
|
453
460
|
def defined_in_gem?(constant, strict: true)
|
|
454
461
|
files = get_file_candidates(constant)
|
|
455
462
|
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))
|
|
@@ -461,7 +468,7 @@ module Tapioca
|
|
|
461
468
|
end
|
|
462
469
|
end
|
|
463
470
|
|
|
464
|
-
#: (Module constant) -> Set[String]
|
|
471
|
+
#: (T::Module[top] constant) -> Set[String]
|
|
465
472
|
def get_file_candidates(constant)
|
|
466
473
|
file_candidates_for(constant)
|
|
467
474
|
rescue ArgumentError, NameError
|
|
@@ -492,7 +499,7 @@ module Tapioca
|
|
|
492
499
|
|
|
493
500
|
# Helpers
|
|
494
501
|
|
|
495
|
-
#: ((Module & T::Generic) constant) -> String
|
|
502
|
+
#: ((T::Module[top] & T::Generic) constant) -> String
|
|
496
503
|
def generic_name_of(constant)
|
|
497
504
|
type_name = T.must(constant.name)
|
|
498
505
|
return type_name if type_name =~ /\[.*\]$/
|
|
@@ -508,7 +515,7 @@ module Tapioca
|
|
|
508
515
|
"#{type_name}[#{type_variable_names}]"
|
|
509
516
|
end
|
|
510
517
|
|
|
511
|
-
#: (Module constant, String? class_name) -> String?
|
|
518
|
+
#: (T::Module[top] constant, String? class_name) -> String?
|
|
512
519
|
def name_of_proxy_target(constant, class_name)
|
|
513
520
|
return unless class_name == "ActiveSupport::Deprecation::DeprecatedConstantProxy"
|
|
514
521
|
|
data/lib/tapioca/gemfile.rb
CHANGED
|
@@ -64,7 +64,7 @@ module Tapioca
|
|
|
64
64
|
[dependencies, missing_specs]
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
#: -> [
|
|
67
|
+
#: -> [Enumerable[Spec], Array[String]]
|
|
68
68
|
def materialize_deps
|
|
69
69
|
deps = definition.locked_gems.dependencies.except(*@excluded_gems).values
|
|
70
70
|
resolve = definition.resolve
|
|
@@ -89,7 +89,11 @@ module Tapioca
|
|
|
89
89
|
@validating_config = false
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
#: (
|
|
92
|
+
#: (
|
|
93
|
+
#| Hash[Symbol, Thor::Option] command_options,
|
|
94
|
+
#| String config_key,
|
|
95
|
+
#| Hash[untyped, untyped] config_options
|
|
96
|
+
#| ) -> Array[ConfigError]
|
|
93
97
|
def validate_config_options(command_options, config_key, config_options)
|
|
94
98
|
config_options.filter_map do |config_option_key, config_option_value|
|
|
95
99
|
command_option = command_options[config_option_key.to_sym]
|
|
@@ -64,7 +64,14 @@ module Tapioca
|
|
|
64
64
|
url
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
#: (
|
|
67
|
+
#: (
|
|
68
|
+
#| command: String,
|
|
69
|
+
#| gem_dir: String,
|
|
70
|
+
#| dsl_dir: String,
|
|
71
|
+
#| auto_strictness: bool,
|
|
72
|
+
#| ?gems: Array[Gemfile::GemSpec],
|
|
73
|
+
#| ?compilers: Enumerable[singleton(Dsl::Compiler)]
|
|
74
|
+
#| ) -> void
|
|
68
75
|
def validate_rbi_files(command:, gem_dir:, dsl_dir:, auto_strictness:, gems: [], compilers: [])
|
|
69
76
|
error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE
|
|
70
77
|
|
data/lib/tapioca/loaders/gem.rb
CHANGED
|
@@ -9,7 +9,13 @@ module Tapioca
|
|
|
9
9
|
class << self
|
|
10
10
|
extend T::Sig
|
|
11
11
|
|
|
12
|
-
#: (
|
|
12
|
+
#: (
|
|
13
|
+
#| bundle: Gemfile,
|
|
14
|
+
#| prerequire: String?,
|
|
15
|
+
#| postrequire: String,
|
|
16
|
+
#| default_command: String,
|
|
17
|
+
#| halt_upon_load_error: bool
|
|
18
|
+
#| ) -> void
|
|
13
19
|
def load_application(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
|
|
14
20
|
loader = new(
|
|
15
21
|
bundle: bundle,
|
|
@@ -30,7 +36,13 @@ module Tapioca
|
|
|
30
36
|
|
|
31
37
|
protected
|
|
32
38
|
|
|
33
|
-
#: (
|
|
39
|
+
#: (
|
|
40
|
+
#| bundle: Gemfile,
|
|
41
|
+
#| prerequire: String?,
|
|
42
|
+
#| postrequire: String,
|
|
43
|
+
#| default_command: String,
|
|
44
|
+
#| halt_upon_load_error: bool
|
|
45
|
+
#| ) -> void
|
|
34
46
|
def initialize(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
|
|
35
47
|
super()
|
|
36
48
|
|
|
@@ -5,7 +5,7 @@ module RBI
|
|
|
5
5
|
class Tree
|
|
6
6
|
extend T::Sig
|
|
7
7
|
|
|
8
|
-
#: (::Module constant) ?{ (Scope scope) -> void } -> Scope
|
|
8
|
+
#: (T::Module[top] constant) ?{ (Scope scope) -> void } -> Scope
|
|
9
9
|
def create_path(constant, &block)
|
|
10
10
|
constant_name = Tapioca::Runtime::Reflection.name_of(constant)
|
|
11
11
|
raise "given constant does not have a name" unless constant_name
|
|
@@ -61,7 +61,14 @@ module RBI
|
|
|
61
61
|
create_node(RBI::TypeMember.new(name, value))
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
#: (
|
|
64
|
+
#: (
|
|
65
|
+
#| String name,
|
|
66
|
+
#| ?parameters: Array[TypedParam],
|
|
67
|
+
#| ?return_type: String?,
|
|
68
|
+
#| ?class_method: bool,
|
|
69
|
+
#| ?visibility: RBI::Visibility,
|
|
70
|
+
#| ?comments: Array[RBI::Comment]
|
|
71
|
+
#| ) ?{ (RBI::Method node) -> void } -> void
|
|
65
72
|
def create_method(name, parameters: [], return_type: nil, class_method: false, visibility: RBI::Public.new,
|
|
66
73
|
comments: [], &block)
|
|
67
74
|
return unless Tapioca::RBIHelper.valid_method_name?(name)
|
data/lib/tapioca/repo_index.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Tapioca
|
|
|
10
10
|
module AttachedClassOf
|
|
11
11
|
extend T::Sig
|
|
12
12
|
|
|
13
|
-
#: (Class singleton_class) -> Module?
|
|
13
|
+
#: (Class singleton_class) -> T::Module[top]?
|
|
14
14
|
def attached_class_of(singleton_class)
|
|
15
15
|
result = singleton_class.attached_object
|
|
16
16
|
Module === result ? result : nil
|
|
@@ -10,7 +10,7 @@ module Tapioca
|
|
|
10
10
|
# @requires_ancestor: Tapioca::Runtime::Reflection
|
|
11
11
|
module AttachedClassOf
|
|
12
12
|
extend T::Sig
|
|
13
|
-
#: (Class singleton_class) -> Module?
|
|
13
|
+
#: (Class singleton_class) -> T::Module[top]?
|
|
14
14
|
def attached_class_of(singleton_class)
|
|
15
15
|
# https://stackoverflow.com/a/36622320/98634
|
|
16
16
|
result = ObjectSpace.each_object(singleton_class).find do |klass|
|
|
@@ -7,7 +7,7 @@ module Tapioca
|
|
|
7
7
|
extend T::Sig
|
|
8
8
|
include Runtime::Reflection
|
|
9
9
|
|
|
10
|
-
#: Array[Module]
|
|
10
|
+
#: Array[T::Module[top]]
|
|
11
11
|
attr_reader :dynamic_extends, :dynamic_includes
|
|
12
12
|
|
|
13
13
|
#: Array[Symbol]
|
|
@@ -16,7 +16,7 @@ module Tapioca
|
|
|
16
16
|
#: Array[Symbol]
|
|
17
17
|
attr_reader :instance_attribute_readers, :instance_attribute_writers, :instance_attribute_predicates
|
|
18
18
|
|
|
19
|
-
#: (Module constant) -> void
|
|
19
|
+
#: (T::Module[top] constant) -> void
|
|
20
20
|
def initialize(constant)
|
|
21
21
|
@constant = constant
|
|
22
22
|
mixins_from_modules = {}.compare_by_identity
|
|
@@ -112,12 +112,12 @@ module Tapioca
|
|
|
112
112
|
# is the list of all dynamically extended modules because of that
|
|
113
113
|
# constant. We grab that value by deleting the key for the original
|
|
114
114
|
# constant.
|
|
115
|
-
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[Module]
|
|
115
|
+
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[T::Module[top]]
|
|
116
116
|
|
|
117
117
|
# Since we deleted the original constant from the list of keys, all
|
|
118
118
|
# the keys that remain are the ones that are dynamically included modules
|
|
119
119
|
# during the include of the original constant.
|
|
120
|
-
@dynamic_includes = mixins_from_modules.keys #: Array[Module]
|
|
120
|
+
@dynamic_includes = mixins_from_modules.keys #: Array[T::Module[top]]
|
|
121
121
|
|
|
122
122
|
@class_attribute_readers = class_attribute_readers #: Array[Symbol]
|
|
123
123
|
@class_attribute_writers = class_attribute_writers #: Array[Symbol]
|
|
@@ -176,7 +176,7 @@ module Tapioca
|
|
|
176
176
|
tree << RBI::Include.new("GeneratedInstanceMethods")
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
-
#: (RBI::Tree tree) -> [Array[Module], Array[Module]]
|
|
179
|
+
#: (RBI::Tree tree) -> [Array[T::Module[top]], Array[T::Module[top]]]
|
|
180
180
|
def compile_mixes_in_class_methods(tree)
|
|
181
181
|
includes = dynamic_includes.filter_map do |mod|
|
|
182
182
|
qname = qualified_name_of(mod)
|
|
@@ -211,7 +211,7 @@ module Tapioca
|
|
|
211
211
|
[[], []] # silence errors
|
|
212
212
|
end
|
|
213
213
|
|
|
214
|
-
#: (Module mod, Array[Module] dynamic_extends) -> bool
|
|
214
|
+
#: (T::Module[top] mod, Array[T::Module[top]] dynamic_extends) -> bool
|
|
215
215
|
def module_included_by_another_dynamic_extend?(mod, dynamic_extends)
|
|
216
216
|
dynamic_extends.any? do |dynamic_extend|
|
|
217
217
|
mod != dynamic_extend && ancestors_of(dynamic_extend).include?(mod)
|
|
@@ -21,18 +21,18 @@ module Tapioca
|
|
|
21
21
|
# variable to type variable serializers. This allows us to associate type variables
|
|
22
22
|
# to the constant names that represent them, easily.
|
|
23
23
|
module GenericTypeRegistry
|
|
24
|
-
@generic_instances = {} #: Hash[String, Module]
|
|
24
|
+
@generic_instances = {} #: Hash[String, T::Module[top]]
|
|
25
25
|
|
|
26
|
-
@type_variables = {}.compare_by_identity #: Hash[Module, Array[TypeVariableModule]]
|
|
26
|
+
@type_variables = {}.compare_by_identity #: Hash[T::Module[top], Array[TypeVariableModule]]
|
|
27
27
|
|
|
28
28
|
class GenericType < T::Types::Simple
|
|
29
29
|
extend T::Sig
|
|
30
30
|
|
|
31
|
-
#: (Module raw_type, Module underlying_type) -> void
|
|
31
|
+
#: (T::Module[top] raw_type, T::Module[top] underlying_type) -> void
|
|
32
32
|
def initialize(raw_type, underlying_type)
|
|
33
33
|
super(raw_type)
|
|
34
34
|
|
|
35
|
-
@underlying_type = underlying_type #: Module
|
|
35
|
+
@underlying_type = underlying_type #: T::Module[top]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# @override
|
|
@@ -56,7 +56,7 @@ module Tapioca
|
|
|
56
56
|
# 2 hash lookups (for the other two `Foo[Integer]`s).
|
|
57
57
|
#
|
|
58
58
|
# This method returns the created or cached clone of the constant.
|
|
59
|
-
#: (untyped constant, untyped types) -> Module
|
|
59
|
+
#: (untyped constant, untyped types) -> T::Module[top]
|
|
60
60
|
def register_type(constant, types)
|
|
61
61
|
# Build the name of the instantiated generic type,
|
|
62
62
|
# something like `"Foo[X, Y, Z]"`
|
|
@@ -76,7 +76,7 @@ module Tapioca
|
|
|
76
76
|
@generic_instances.values.any? { |generic_type| generic_type === instance }
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
#: (Module constant) -> Array[TypeVariableModule]?
|
|
79
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]?
|
|
80
80
|
def lookup_type_variables(constant)
|
|
81
81
|
@type_variables[constant]
|
|
82
82
|
end
|
|
@@ -99,7 +99,7 @@ module Tapioca
|
|
|
99
99
|
|
|
100
100
|
private
|
|
101
101
|
|
|
102
|
-
#: (Module constant, String name) -> Module
|
|
102
|
+
#: (T::Module[top] constant, String name) -> T::Module[top]
|
|
103
103
|
def create_generic_type(constant, name)
|
|
104
104
|
generic_type = case constant
|
|
105
105
|
when Class
|
|
@@ -168,7 +168,7 @@ module Tapioca
|
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
#: (Module constant) -> Array[TypeVariableModule]
|
|
171
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]
|
|
172
172
|
def lookup_or_initialize_type_variables(constant)
|
|
173
173
|
@type_variables[constant] ||= []
|
|
174
174
|
end
|
|
@@ -32,7 +32,7 @@ module Tapioca
|
|
|
32
32
|
PROTECTED_INSTANCE_METHODS_METHOD = Module.instance_method(:protected_instance_methods) #: UnboundMethod
|
|
33
33
|
PRIVATE_INSTANCE_METHODS_METHOD = Module.instance_method(:private_instance_methods) #: UnboundMethod
|
|
34
34
|
METHOD_METHOD = Kernel.instance_method(:method) #: UnboundMethod
|
|
35
|
-
UNDEFINED_CONSTANT = Module.new.freeze #: Module
|
|
35
|
+
UNDEFINED_CONSTANT = Module.new.freeze #: T::Module[top]
|
|
36
36
|
|
|
37
37
|
REQUIRED_FROM_LABELS = ["<top (required)>", "<main>", "<compiled>"].freeze #: Array[String]
|
|
38
38
|
|
|
@@ -43,7 +43,7 @@ module Tapioca
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# @without_runtime
|
|
46
|
-
#: (String symbol, ?inherit: bool, ?namespace: Module) -> BasicObject
|
|
46
|
+
#: (String symbol, ?inherit: bool, ?namespace: T::Module[top]) -> BasicObject
|
|
47
47
|
def constantize(symbol, inherit: false, namespace: Object)
|
|
48
48
|
namespace.const_get(symbol, inherit)
|
|
49
49
|
rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError
|
|
@@ -55,23 +55,23 @@ module Tapioca
|
|
|
55
55
|
CLASS_METHOD.bind_call(object)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
#: (Module constant) -> Array[Symbol]
|
|
58
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
59
59
|
def constants_of(constant)
|
|
60
60
|
CONSTANTS_METHOD.bind_call(constant, false)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
#: (Module constant) -> String?
|
|
63
|
+
#: (T::Module[top] constant) -> String?
|
|
64
64
|
def name_of(constant)
|
|
65
65
|
name = NAME_METHOD.bind_call(constant)
|
|
66
66
|
name&.start_with?("#<") ? nil : name
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
#: (Module constant) -> Class[top]
|
|
69
|
+
#: (T::Module[top] constant) -> Class[top]
|
|
70
70
|
def singleton_class_of(constant)
|
|
71
71
|
SINGLETON_CLASS_METHOD.bind_call(constant)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
#: (Module constant) -> Array[Module]
|
|
74
|
+
#: (T::Module[top] constant) -> Array[T::Module[top]]
|
|
75
75
|
def ancestors_of(constant)
|
|
76
76
|
ANCESTORS_METHOD.bind_call(constant)
|
|
77
77
|
end
|
|
@@ -91,22 +91,22 @@ module Tapioca
|
|
|
91
91
|
EQUAL_METHOD.bind_call(object, other)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
#: (Module constant) -> Array[Symbol]
|
|
94
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
95
95
|
def public_instance_methods_of(constant)
|
|
96
96
|
PUBLIC_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
#: (Module constant) -> Array[Symbol]
|
|
99
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
100
100
|
def protected_instance_methods_of(constant)
|
|
101
101
|
PROTECTED_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
#: (Module constant) -> Array[Symbol]
|
|
104
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
105
105
|
def private_instance_methods_of(constant)
|
|
106
106
|
PRIVATE_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
#: (Module constant) -> Array[Module]
|
|
109
|
+
#: (T::Module[top] constant) -> Array[T::Module[top]]
|
|
110
110
|
def inherited_ancestors_of(constant)
|
|
111
111
|
if Class === constant
|
|
112
112
|
ancestors_of(superclass_of(constant) || Object)
|
|
@@ -115,7 +115,7 @@ module Tapioca
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
#: (Module constant) -> String?
|
|
118
|
+
#: (T::Module[top] constant) -> String?
|
|
119
119
|
def qualified_name_of(constant)
|
|
120
120
|
name = name_of(constant)
|
|
121
121
|
return if name.nil?
|
|
@@ -148,7 +148,7 @@ module Tapioca
|
|
|
148
148
|
type.to_s
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
#: (Module constant, Symbol method) -> Method
|
|
151
|
+
#: (T::Module[top] constant, Symbol method) -> Method
|
|
152
152
|
def method_of(constant, method)
|
|
153
153
|
METHOD_METHOD.bind_call(constant, method)
|
|
154
154
|
end
|
|
@@ -217,32 +217,32 @@ module Tapioca
|
|
|
217
217
|
SourceLocation.from_loc([file, resolved_loc.lineno])
|
|
218
218
|
end
|
|
219
219
|
|
|
220
|
-
#: (Module constant) -> Set[String]
|
|
220
|
+
#: (T::Module[top] constant) -> Set[String]
|
|
221
221
|
def file_candidates_for(constant)
|
|
222
222
|
relevant_methods_for(constant).filter_map do |method|
|
|
223
223
|
method.source_location&.first
|
|
224
224
|
end.to_set
|
|
225
225
|
end
|
|
226
226
|
|
|
227
|
-
#: (Module constant) -> untyped
|
|
227
|
+
#: (T::Module[top] constant) -> untyped
|
|
228
228
|
def abstract_type_of(constant)
|
|
229
229
|
T::Private::Abstract::Data.get(constant, :abstract_type) ||
|
|
230
230
|
T::Private::Abstract::Data.get(singleton_class_of(constant), :abstract_type)
|
|
231
231
|
end
|
|
232
232
|
|
|
233
|
-
#: (Module constant) -> bool
|
|
233
|
+
#: (T::Module[top] constant) -> bool
|
|
234
234
|
def final_module?(constant)
|
|
235
235
|
T::Private::Final.final_module?(constant)
|
|
236
236
|
end
|
|
237
237
|
|
|
238
|
-
#: (Module constant) -> bool
|
|
238
|
+
#: (T::Module[top] constant) -> bool
|
|
239
239
|
def sealed_module?(constant)
|
|
240
240
|
T::Private::Sealed.sealed_module?(constant)
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
private
|
|
244
244
|
|
|
245
|
-
#: (Module constant) -> Array[UnboundMethod]
|
|
245
|
+
#: (T::Module[top] constant) -> Array[UnboundMethod]
|
|
246
246
|
def relevant_methods_for(constant)
|
|
247
247
|
methods = methods_for(constant).select(&:source_location)
|
|
248
248
|
.reject { |x| method_defined_by_forwardable_module?(x) }
|
|
@@ -258,7 +258,7 @@ module Tapioca
|
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
260
|
|
|
261
|
-
#: (Module constant) -> Array[UnboundMethod]
|
|
261
|
+
#: (T::Module[top] constant) -> Array[UnboundMethod]
|
|
262
262
|
def methods_for(constant)
|
|
263
263
|
modules = [constant, singleton_class_of(constant)]
|
|
264
264
|
method_list_methods = [
|
|
@@ -272,7 +272,7 @@ module Tapioca
|
|
|
272
272
|
end
|
|
273
273
|
end
|
|
274
274
|
|
|
275
|
-
#: (Module parent, String name) -> Module?
|
|
275
|
+
#: (T::Module[top] parent, String name) -> T::Module[top]?
|
|
276
276
|
def child_module_for_parent_with_name(parent, name)
|
|
277
277
|
return if parent.autoload?(name)
|
|
278
278
|
|
|
@@ -13,7 +13,7 @@ module Tapioca
|
|
|
13
13
|
extend Reflection
|
|
14
14
|
extend T::Sig
|
|
15
15
|
|
|
16
|
-
@class_files = {}.compare_by_identity #: Hash[Module, Set[SourceLocation]]
|
|
16
|
+
@class_files = {}.compare_by_identity #: Hash[T::Module[top], Set[SourceLocation]]
|
|
17
17
|
|
|
18
18
|
# Immediately activated upon load. Observes class/module definition.
|
|
19
19
|
@class_tracepoint = TracePoint.trace(:class) do |tp|
|
|
@@ -70,12 +70,12 @@ module Tapioca
|
|
|
70
70
|
# Returns the files in which this class or module was opened. Doesn't know
|
|
71
71
|
# about situations where the class was opened prior to +require+ing,
|
|
72
72
|
# or where metaprogramming was used via +eval+, etc.
|
|
73
|
-
#: (Module klass) -> Set[String]
|
|
73
|
+
#: (T::Module[top] klass) -> Set[String]
|
|
74
74
|
def files_for(klass)
|
|
75
75
|
locations_for(klass).map(&:file).to_set
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
#: (Module klass) -> Set[SourceLocation]
|
|
78
|
+
#: (T::Module[top] klass) -> Set[SourceLocation]
|
|
79
79
|
def locations_for(klass)
|
|
80
80
|
@class_files.fetch(klass, Set.new)
|
|
81
81
|
end
|
|
@@ -8,10 +8,10 @@ module Tapioca
|
|
|
8
8
|
extend Tracker
|
|
9
9
|
extend T::Sig
|
|
10
10
|
|
|
11
|
-
@method_definitions = {}.compare_by_identity #: Hash[Module, Hash[Symbol, Array[SourceLocation]]]
|
|
11
|
+
@method_definitions = {}.compare_by_identity #: Hash[T::Module[top], Hash[Symbol, Array[SourceLocation]]]
|
|
12
12
|
|
|
13
13
|
class << self
|
|
14
|
-
#: (Symbol method_name, Module owner, Array[Thread::Backtrace::Location] locations) -> void
|
|
14
|
+
#: (Symbol method_name, T::Module[top] owner, Array[Thread::Backtrace::Location] locations) -> void
|
|
15
15
|
def register(method_name, owner, locations)
|
|
16
16
|
return unless enabled?
|
|
17
17
|
# If Sorbet runtime is redefining a method, it sets this to true.
|
|
@@ -25,7 +25,7 @@ module Tapioca
|
|
|
25
25
|
registrations_for(method_name, owner) << loc
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
#: (Symbol method_name, Module owner) -> Array[SourceLocation]
|
|
28
|
+
#: (Symbol method_name, T::Module[top] owner) -> Array[SourceLocation]
|
|
29
29
|
def method_definitions_for(method_name, owner)
|
|
30
30
|
definitions = registrations_for(method_name, owner)
|
|
31
31
|
|
|
@@ -39,7 +39,7 @@ module Tapioca
|
|
|
39
39
|
|
|
40
40
|
private
|
|
41
41
|
|
|
42
|
-
#: (Symbol method_name, Module owner) -> Array[SourceLocation]
|
|
42
|
+
#: (Symbol method_name, T::Module[top] owner) -> Array[SourceLocation]
|
|
43
43
|
def registrations_for(method_name, owner)
|
|
44
44
|
owner_lookup = (@method_definitions[owner] ||= {})
|
|
45
45
|
owner_lookup[method_name] ||= []
|
|
@@ -27,7 +27,7 @@ module Tapioca
|
|
|
27
27
|
with_disabled_tracker(&block)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
#: (Module constant, Module mixin, Type mixin_type) -> void
|
|
30
|
+
#: (T::Module[top] constant, T::Module[top] mixin, Type mixin_type) -> void
|
|
31
31
|
def register(constant, mixin, mixin_type)
|
|
32
32
|
return unless enabled?
|
|
33
33
|
|
|
@@ -49,19 +49,19 @@ module Tapioca
|
|
|
49
49
|
attached_class
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
|
52
|
+
#: (T::Module[top] mixin) -> Hash[Type, Hash[T::Module[top], String]]
|
|
53
53
|
def constants_with_mixin(mixin)
|
|
54
54
|
find_or_initialize_mixin_lookup(mixin)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
#: (Module mixin, Type mixin_type, Module constant) -> String?
|
|
57
|
+
#: (T::Module[top] mixin, Type mixin_type, T::Module[top] constant) -> String?
|
|
58
58
|
def mixin_location(mixin, mixin_type, constant)
|
|
59
59
|
find_or_initialize_mixin_lookup(mixin).dig(mixin_type, constant)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
private
|
|
63
63
|
|
|
64
|
-
#: (Module constant, Module mixin, Type mixin_type, String location) -> void
|
|
64
|
+
#: (T::Module[top] constant, T::Module[top] mixin, Type mixin_type, String location) -> void
|
|
65
65
|
def register_with_location(constant, mixin, mixin_type, location)
|
|
66
66
|
return unless @enabled
|
|
67
67
|
|
|
@@ -69,7 +69,7 @@ module Tapioca
|
|
|
69
69
|
constants.fetch(mixin_type).store(constant, location)
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
|
72
|
+
#: (T::Module[top] mixin) -> Hash[Type, Hash[T::Module[top], String]]
|
|
73
73
|
def find_or_initialize_mixin_lookup(mixin)
|
|
74
74
|
@mixins_to_constants[mixin] ||= {
|
|
75
75
|
Type::Prepend => {}.compare_by_identity,
|
|
@@ -19,12 +19,12 @@ module Tapioca
|
|
|
19
19
|
ancestors << block
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
#: (Module mod) -> Array[^-> void]
|
|
22
|
+
#: (T::Module[top] mod) -> Array[^-> void]
|
|
23
23
|
def required_ancestors_blocks_by(mod)
|
|
24
24
|
@required_ancestors_map[mod] || []
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
#: (Module mod) -> Array[untyped]
|
|
27
|
+
#: (T::Module[top] mod) -> Array[untyped]
|
|
28
28
|
def required_ancestors_by(mod)
|
|
29
29
|
blocks = required_ancestors_blocks_by(mod)
|
|
30
30
|
blocks.map do |block|
|
|
@@ -135,7 +135,7 @@ module Tapioca
|
|
|
135
135
|
#: Type
|
|
136
136
|
attr_reader :type
|
|
137
137
|
|
|
138
|
-
#: (Module context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void
|
|
138
|
+
#: (T::Module[top] context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void
|
|
139
139
|
def initialize(context, type, variance, bounds_proc)
|
|
140
140
|
@context = context
|
|
141
141
|
@type = type
|