tapioca 0.17.9 → 0.18.0
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 +3 -2
- data/lib/tapioca/bundler_ext/auto_require_hook.rb +0 -3
- data/lib/tapioca/cli.rb +0 -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 -3
- data/lib/tapioca/commands/check_shims.rb +9 -2
- data/lib/tapioca/commands/command.rb +0 -1
- data/lib/tapioca/dsl/compiler.rb +17 -16
- data/lib/tapioca/dsl/compilers/aasm.rb +2 -6
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -6
- data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -5
- data/lib/tapioca/dsl/compilers/action_text.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_job.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -3
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -6
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +8 -5
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -4
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +45 -87
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -2
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -4
- data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -4
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_resource.rb +1 -5
- data/lib/tapioca/dsl/compilers/active_storage.rb +2 -6
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -10
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +4 -19
- data/lib/tapioca/dsl/compilers/active_support_environment_inquirer.rb +60 -0
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -5
- data/lib/tapioca/dsl/compilers/config.rb +2 -6
- data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -5
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -5
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -5
- data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -6
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +4 -18
- data/lib/tapioca/dsl/compilers/kredis.rb +1 -5
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -6
- data/lib/tapioca/dsl/compilers/protobuf.rb +2 -6
- data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -5
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -5
- data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -5
- data/lib/tapioca/dsl/compilers/state_machines.rb +2 -6
- data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -10
- data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +0 -2
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +3 -6
- data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +0 -2
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +18 -5
- data/lib/tapioca/dsl/pipeline.rb +25 -13
- data/lib/tapioca/executor.rb +0 -2
- data/lib/tapioca/gem/events.rb +15 -23
- data/lib/tapioca/gem/listeners/base.rb +0 -1
- data/lib/tapioca/gem/listeners/dynamic_mixins.rb +0 -2
- data/lib/tapioca/gem/listeners/foreign_constants.rb +0 -2
- data/lib/tapioca/gem/listeners/methods.rb +19 -9
- data/lib/tapioca/gem/listeners/mixins.rb +3 -5
- data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +0 -2
- data/lib/tapioca/gem/listeners/sorbet_enums.rb +0 -2
- data/lib/tapioca/gem/listeners/sorbet_helpers.rb +0 -2
- data/lib/tapioca/gem/listeners/sorbet_props.rb +0 -1
- data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +0 -2
- data/lib/tapioca/gem/listeners/sorbet_signatures.rb +0 -2
- data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -3
- data/lib/tapioca/gem/listeners/source_location.rb +6 -7
- data/lib/tapioca/gem/listeners/subconstants.rb +0 -2
- data/lib/tapioca/gem/listeners/yard_doc.rb +0 -2
- data/lib/tapioca/gem/pipeline.rb +25 -21
- data/lib/tapioca/gemfile.rb +1 -3
- data/lib/tapioca/helpers/cli_helper.rb +0 -1
- data/lib/tapioca/helpers/config_helper.rb +5 -2
- data/lib/tapioca/helpers/env_helper.rb +0 -1
- data/lib/tapioca/helpers/gem_helper.rb +0 -2
- data/lib/tapioca/helpers/git_attributes.rb +0 -2
- data/lib/tapioca/helpers/package_url.rb +416 -0
- data/lib/tapioca/helpers/rbi_files_helper.rb +8 -2
- data/lib/tapioca/helpers/rbi_helper.rb +0 -3
- data/lib/tapioca/helpers/sorbet_helper.rb +0 -2
- data/lib/tapioca/helpers/test/content.rb +0 -1
- data/lib/tapioca/helpers/test/dsl_compiler.rb +0 -3
- data/lib/tapioca/helpers/test/isolation.rb +0 -6
- data/lib/tapioca/helpers/test/template.rb +1 -9
- data/lib/tapioca/internal.rb +1 -1
- data/lib/tapioca/loaders/dsl.rb +0 -4
- data/lib/tapioca/loaders/gem.rb +14 -6
- data/lib/tapioca/loaders/loader.rb +0 -1
- data/lib/tapioca/rbi_ext/model.rb +9 -4
- data/lib/tapioca/rbi_formatter.rb +0 -2
- data/lib/tapioca/repo_index.rb +1 -4
- data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +6 -9
- data/lib/tapioca/runtime/generic_type_registry.rb +8 -12
- data/lib/tapioca/runtime/reflection.rb +25 -31
- data/lib/tapioca/runtime/trackers/autoload.rb +0 -3
- data/lib/tapioca/runtime/trackers/constant_definition.rb +30 -8
- data/lib/tapioca/runtime/trackers/method_definition.rb +4 -5
- data/lib/tapioca/runtime/trackers/mixin.rb +5 -8
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +2 -4
- data/lib/tapioca/runtime/trackers/tracker.rb +1 -4
- data/lib/tapioca/runtime/trackers.rb +0 -4
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +1 -3
- data/lib/tapioca/static/requires_compiler.rb +1 -3
- data/lib/tapioca/static/symbol_loader.rb +0 -1
- data/lib/tapioca/static/symbol_table_parser.rb +0 -4
- data/lib/tapioca/version.rb +1 -1
- data/lib/tapioca.rb +0 -2
- metadata +18 -5
- data/lib/tapioca/helpers/source_uri.rb +0 -84
- data/lib/tapioca/runtime/attached_class_of_32.rb +0 -20
- data/lib/tapioca/runtime/attached_class_of_legacy.rb +0 -24
|
@@ -4,10 +4,9 @@
|
|
|
4
4
|
module Tapioca
|
|
5
5
|
module Runtime
|
|
6
6
|
class DynamicMixinCompiler
|
|
7
|
-
extend T::Sig
|
|
8
7
|
include Runtime::Reflection
|
|
9
8
|
|
|
10
|
-
#: Array[Module]
|
|
9
|
+
#: Array[T::Module[top]]
|
|
11
10
|
attr_reader :dynamic_extends, :dynamic_includes
|
|
12
11
|
|
|
13
12
|
#: Array[Symbol]
|
|
@@ -16,7 +15,7 @@ module Tapioca
|
|
|
16
15
|
#: Array[Symbol]
|
|
17
16
|
attr_reader :instance_attribute_readers, :instance_attribute_writers, :instance_attribute_predicates
|
|
18
17
|
|
|
19
|
-
#: (Module constant) -> void
|
|
18
|
+
#: (T::Module[top] constant) -> void
|
|
20
19
|
def initialize(constant)
|
|
21
20
|
@constant = constant
|
|
22
21
|
mixins_from_modules = {}.compare_by_identity
|
|
@@ -95,8 +94,6 @@ module Tapioca
|
|
|
95
94
|
end
|
|
96
95
|
|
|
97
96
|
class << self
|
|
98
|
-
extend T::Sig
|
|
99
|
-
|
|
100
97
|
T::Sig::WithoutRuntime.sig { params(symbol: Symbol, args: T.untyped).returns(T.untyped) }
|
|
101
98
|
def method_missing(symbol, *args)
|
|
102
99
|
# Similarly, we need this here so that we can handle any
|
|
@@ -112,12 +109,12 @@ module Tapioca
|
|
|
112
109
|
# is the list of all dynamically extended modules because of that
|
|
113
110
|
# constant. We grab that value by deleting the key for the original
|
|
114
111
|
# constant.
|
|
115
|
-
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[Module]
|
|
112
|
+
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[T::Module[top]]
|
|
116
113
|
|
|
117
114
|
# Since we deleted the original constant from the list of keys, all
|
|
118
115
|
# the keys that remain are the ones that are dynamically included modules
|
|
119
116
|
# during the include of the original constant.
|
|
120
|
-
@dynamic_includes = mixins_from_modules.keys #: Array[Module]
|
|
117
|
+
@dynamic_includes = mixins_from_modules.keys #: Array[T::Module[top]]
|
|
121
118
|
|
|
122
119
|
@class_attribute_readers = class_attribute_readers #: Array[Symbol]
|
|
123
120
|
@class_attribute_writers = class_attribute_writers #: Array[Symbol]
|
|
@@ -176,7 +173,7 @@ module Tapioca
|
|
|
176
173
|
tree << RBI::Include.new("GeneratedInstanceMethods")
|
|
177
174
|
end
|
|
178
175
|
|
|
179
|
-
#: (RBI::Tree tree) -> [Array[Module], Array[Module]]
|
|
176
|
+
#: (RBI::Tree tree) -> [Array[T::Module[top]], Array[T::Module[top]]]
|
|
180
177
|
def compile_mixes_in_class_methods(tree)
|
|
181
178
|
includes = dynamic_includes.filter_map do |mod|
|
|
182
179
|
qname = qualified_name_of(mod)
|
|
@@ -211,7 +208,7 @@ module Tapioca
|
|
|
211
208
|
[[], []] # silence errors
|
|
212
209
|
end
|
|
213
210
|
|
|
214
|
-
#: (Module mod, Array[Module] dynamic_extends) -> bool
|
|
211
|
+
#: (T::Module[top] mod, Array[T::Module[top]] dynamic_extends) -> bool
|
|
215
212
|
def module_included_by_another_dynamic_extend?(mod, dynamic_extends)
|
|
216
213
|
dynamic_extends.any? do |dynamic_extend|
|
|
217
214
|
mod != dynamic_extend && ancestors_of(dynamic_extend).include?(mod)
|
|
@@ -21,18 +21,16 @@ 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
|
-
|
|
30
|
-
|
|
31
|
-
#: (Module raw_type, Module underlying_type) -> void
|
|
29
|
+
#: (T::Module[top] raw_type, T::Module[top] underlying_type) -> void
|
|
32
30
|
def initialize(raw_type, underlying_type)
|
|
33
31
|
super(raw_type)
|
|
34
32
|
|
|
35
|
-
@underlying_type = underlying_type #: Module
|
|
33
|
+
@underlying_type = underlying_type #: T::Module[top]
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
# @override
|
|
@@ -43,8 +41,6 @@ module Tapioca
|
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
class << self
|
|
46
|
-
extend T::Sig
|
|
47
|
-
|
|
48
44
|
# This method is responsible for building the name of the instantiated concrete type
|
|
49
45
|
# and cloning the given constant so that we can return a type that is the same
|
|
50
46
|
# as the current type but is a different instance and has a different name method.
|
|
@@ -56,7 +52,7 @@ module Tapioca
|
|
|
56
52
|
# 2 hash lookups (for the other two `Foo[Integer]`s).
|
|
57
53
|
#
|
|
58
54
|
# This method returns the created or cached clone of the constant.
|
|
59
|
-
#: (untyped constant, untyped types) -> Module
|
|
55
|
+
#: (untyped constant, untyped types) -> T::Module[top]
|
|
60
56
|
def register_type(constant, types)
|
|
61
57
|
# Build the name of the instantiated generic type,
|
|
62
58
|
# something like `"Foo[X, Y, Z]"`
|
|
@@ -76,7 +72,7 @@ module Tapioca
|
|
|
76
72
|
@generic_instances.values.any? { |generic_type| generic_type === instance }
|
|
77
73
|
end
|
|
78
74
|
|
|
79
|
-
#: (Module constant) -> Array[TypeVariableModule]?
|
|
75
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]?
|
|
80
76
|
def lookup_type_variables(constant)
|
|
81
77
|
@type_variables[constant]
|
|
82
78
|
end
|
|
@@ -99,7 +95,7 @@ module Tapioca
|
|
|
99
95
|
|
|
100
96
|
private
|
|
101
97
|
|
|
102
|
-
#: (Module constant, String name) -> Module
|
|
98
|
+
#: (T::Module[top] constant, String name) -> T::Module[top]
|
|
103
99
|
def create_generic_type(constant, name)
|
|
104
100
|
generic_type = case constant
|
|
105
101
|
when Class
|
|
@@ -168,7 +164,7 @@ module Tapioca
|
|
|
168
164
|
end
|
|
169
165
|
end
|
|
170
166
|
|
|
171
|
-
#: (Module constant) -> Array[TypeVariableModule]
|
|
167
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]
|
|
172
168
|
def lookup_or_initialize_type_variables(constant)
|
|
173
169
|
@type_variables[constant] ||= []
|
|
174
170
|
end
|
|
@@ -3,21 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
require "tapioca/runtime/source_location"
|
|
5
5
|
|
|
6
|
-
# On Ruby 3.2 or newer, Class defines an attached_object method that returns the
|
|
7
|
-
# attached class of a singleton class without iterating ObjectSpace. On older
|
|
8
|
-
# versions of Ruby, we fall back to iterating ObjectSpace.
|
|
9
|
-
if Class.method_defined?(:attached_object)
|
|
10
|
-
require "tapioca/runtime/attached_class_of_32"
|
|
11
|
-
else
|
|
12
|
-
require "tapioca/runtime/attached_class_of_legacy"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
6
|
module Tapioca
|
|
16
7
|
module Runtime
|
|
17
8
|
module Reflection
|
|
18
|
-
include AttachedClassOf
|
|
19
|
-
|
|
20
|
-
extend T::Sig
|
|
21
9
|
extend self
|
|
22
10
|
|
|
23
11
|
CLASS_METHOD = Kernel.instance_method(:class) #: UnboundMethod
|
|
@@ -32,7 +20,7 @@ module Tapioca
|
|
|
32
20
|
PROTECTED_INSTANCE_METHODS_METHOD = Module.instance_method(:protected_instance_methods) #: UnboundMethod
|
|
33
21
|
PRIVATE_INSTANCE_METHODS_METHOD = Module.instance_method(:private_instance_methods) #: UnboundMethod
|
|
34
22
|
METHOD_METHOD = Kernel.instance_method(:method) #: UnboundMethod
|
|
35
|
-
UNDEFINED_CONSTANT = Module.new.freeze #: Module
|
|
23
|
+
UNDEFINED_CONSTANT = Module.new.freeze #: T::Module[top]
|
|
36
24
|
|
|
37
25
|
REQUIRED_FROM_LABELS = ["<top (required)>", "<main>", "<compiled>"].freeze #: Array[String]
|
|
38
26
|
|
|
@@ -43,7 +31,7 @@ module Tapioca
|
|
|
43
31
|
end
|
|
44
32
|
|
|
45
33
|
# @without_runtime
|
|
46
|
-
#: (String symbol, ?inherit: bool, ?namespace: Module) -> BasicObject
|
|
34
|
+
#: (String symbol, ?inherit: bool, ?namespace: T::Module[top]) -> BasicObject
|
|
47
35
|
def constantize(symbol, inherit: false, namespace: Object)
|
|
48
36
|
namespace.const_get(symbol, inherit)
|
|
49
37
|
rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError
|
|
@@ -55,23 +43,23 @@ module Tapioca
|
|
|
55
43
|
CLASS_METHOD.bind_call(object)
|
|
56
44
|
end
|
|
57
45
|
|
|
58
|
-
#: (Module constant) -> Array[Symbol]
|
|
46
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
59
47
|
def constants_of(constant)
|
|
60
48
|
CONSTANTS_METHOD.bind_call(constant, false)
|
|
61
49
|
end
|
|
62
50
|
|
|
63
|
-
#: (Module constant) -> String?
|
|
51
|
+
#: (T::Module[top] constant) -> String?
|
|
64
52
|
def name_of(constant)
|
|
65
53
|
name = NAME_METHOD.bind_call(constant)
|
|
66
54
|
name&.start_with?("#<") ? nil : name
|
|
67
55
|
end
|
|
68
56
|
|
|
69
|
-
#: (Module constant) -> Class[top]
|
|
57
|
+
#: (T::Module[top] constant) -> Class[top]
|
|
70
58
|
def singleton_class_of(constant)
|
|
71
59
|
SINGLETON_CLASS_METHOD.bind_call(constant)
|
|
72
60
|
end
|
|
73
61
|
|
|
74
|
-
#: (Module constant) -> Array[Module]
|
|
62
|
+
#: (T::Module[top] constant) -> Array[T::Module[top]]
|
|
75
63
|
def ancestors_of(constant)
|
|
76
64
|
ANCESTORS_METHOD.bind_call(constant)
|
|
77
65
|
end
|
|
@@ -81,6 +69,12 @@ module Tapioca
|
|
|
81
69
|
SUPERCLASS_METHOD.bind_call(constant)
|
|
82
70
|
end
|
|
83
71
|
|
|
72
|
+
#: (Class[top] singleton_class) -> T::Module[top]?
|
|
73
|
+
def attached_class_of(singleton_class)
|
|
74
|
+
result = singleton_class.attached_object
|
|
75
|
+
Module === result ? result : nil
|
|
76
|
+
end
|
|
77
|
+
|
|
84
78
|
#: (BasicObject object) -> Integer
|
|
85
79
|
def object_id_of(object)
|
|
86
80
|
OBJECT_ID_METHOD.bind_call(object)
|
|
@@ -91,22 +85,22 @@ module Tapioca
|
|
|
91
85
|
EQUAL_METHOD.bind_call(object, other)
|
|
92
86
|
end
|
|
93
87
|
|
|
94
|
-
#: (Module constant) -> Array[Symbol]
|
|
88
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
95
89
|
def public_instance_methods_of(constant)
|
|
96
90
|
PUBLIC_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
97
91
|
end
|
|
98
92
|
|
|
99
|
-
#: (Module constant) -> Array[Symbol]
|
|
93
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
100
94
|
def protected_instance_methods_of(constant)
|
|
101
95
|
PROTECTED_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
102
96
|
end
|
|
103
97
|
|
|
104
|
-
#: (Module constant) -> Array[Symbol]
|
|
98
|
+
#: (T::Module[top] constant) -> Array[Symbol]
|
|
105
99
|
def private_instance_methods_of(constant)
|
|
106
100
|
PRIVATE_INSTANCE_METHODS_METHOD.bind_call(constant)
|
|
107
101
|
end
|
|
108
102
|
|
|
109
|
-
#: (Module constant) -> Array[Module]
|
|
103
|
+
#: (T::Module[top] constant) -> Array[T::Module[top]]
|
|
110
104
|
def inherited_ancestors_of(constant)
|
|
111
105
|
if Class === constant
|
|
112
106
|
ancestors_of(superclass_of(constant) || Object)
|
|
@@ -115,7 +109,7 @@ module Tapioca
|
|
|
115
109
|
end
|
|
116
110
|
end
|
|
117
111
|
|
|
118
|
-
#: (Module constant) -> String?
|
|
112
|
+
#: (T::Module[top] constant) -> String?
|
|
119
113
|
def qualified_name_of(constant)
|
|
120
114
|
name = name_of(constant)
|
|
121
115
|
return if name.nil?
|
|
@@ -148,7 +142,7 @@ module Tapioca
|
|
|
148
142
|
type.to_s
|
|
149
143
|
end
|
|
150
144
|
|
|
151
|
-
#: (Module constant, Symbol method) -> Method
|
|
145
|
+
#: (T::Module[top] constant, Symbol method) -> Method
|
|
152
146
|
def method_of(constant, method)
|
|
153
147
|
METHOD_METHOD.bind_call(constant, method)
|
|
154
148
|
end
|
|
@@ -217,32 +211,32 @@ module Tapioca
|
|
|
217
211
|
SourceLocation.from_loc([file, resolved_loc.lineno])
|
|
218
212
|
end
|
|
219
213
|
|
|
220
|
-
#: (Module constant) -> Set[String]
|
|
214
|
+
#: (T::Module[top] constant) -> Set[String]
|
|
221
215
|
def file_candidates_for(constant)
|
|
222
216
|
relevant_methods_for(constant).filter_map do |method|
|
|
223
217
|
method.source_location&.first
|
|
224
218
|
end.to_set
|
|
225
219
|
end
|
|
226
220
|
|
|
227
|
-
#: (Module constant) -> untyped
|
|
221
|
+
#: (T::Module[top] constant) -> untyped
|
|
228
222
|
def abstract_type_of(constant)
|
|
229
223
|
T::Private::Abstract::Data.get(constant, :abstract_type) ||
|
|
230
224
|
T::Private::Abstract::Data.get(singleton_class_of(constant), :abstract_type)
|
|
231
225
|
end
|
|
232
226
|
|
|
233
|
-
#: (Module constant) -> bool
|
|
227
|
+
#: (T::Module[top] constant) -> bool
|
|
234
228
|
def final_module?(constant)
|
|
235
229
|
T::Private::Final.final_module?(constant)
|
|
236
230
|
end
|
|
237
231
|
|
|
238
|
-
#: (Module constant) -> bool
|
|
232
|
+
#: (T::Module[top] constant) -> bool
|
|
239
233
|
def sealed_module?(constant)
|
|
240
234
|
T::Private::Sealed.sealed_module?(constant)
|
|
241
235
|
end
|
|
242
236
|
|
|
243
237
|
private
|
|
244
238
|
|
|
245
|
-
#: (Module constant) -> Array[UnboundMethod]
|
|
239
|
+
#: (T::Module[top] constant) -> Array[UnboundMethod]
|
|
246
240
|
def relevant_methods_for(constant)
|
|
247
241
|
methods = methods_for(constant).select(&:source_location)
|
|
248
242
|
.reject { |x| method_defined_by_forwardable_module?(x) }
|
|
@@ -258,7 +252,7 @@ module Tapioca
|
|
|
258
252
|
end
|
|
259
253
|
end
|
|
260
254
|
|
|
261
|
-
#: (Module constant) -> Array[UnboundMethod]
|
|
255
|
+
#: (T::Module[top] constant) -> Array[UnboundMethod]
|
|
262
256
|
def methods_for(constant)
|
|
263
257
|
modules = [constant, singleton_class_of(constant)]
|
|
264
258
|
method_list_methods = [
|
|
@@ -272,7 +266,7 @@ module Tapioca
|
|
|
272
266
|
end
|
|
273
267
|
end
|
|
274
268
|
|
|
275
|
-
#: (Module parent, String name) -> Module?
|
|
269
|
+
#: (T::Module[top] parent, String name) -> T::Module[top]?
|
|
276
270
|
def child_module_for_parent_with_name(parent, name)
|
|
277
271
|
return if parent.autoload?(name)
|
|
278
272
|
|
|
@@ -6,13 +6,10 @@ module Tapioca
|
|
|
6
6
|
module Trackers
|
|
7
7
|
module Autoload
|
|
8
8
|
extend Tracker
|
|
9
|
-
extend T::Sig
|
|
10
9
|
|
|
11
10
|
@constant_names_registered_for_autoload = [] #: Array[String]
|
|
12
11
|
|
|
13
12
|
class << self
|
|
14
|
-
extend T::Sig
|
|
15
|
-
|
|
16
13
|
#: -> void
|
|
17
14
|
def eager_load_all!
|
|
18
15
|
Runtime.with_disabled_exits do
|
|
@@ -11,9 +11,8 @@ module Tapioca
|
|
|
11
11
|
module ConstantDefinition
|
|
12
12
|
extend Tracker
|
|
13
13
|
extend Reflection
|
|
14
|
-
extend T::Sig
|
|
15
14
|
|
|
16
|
-
@class_files = {}.compare_by_identity #: Hash[Module, Set[SourceLocation]]
|
|
15
|
+
@class_files = {}.compare_by_identity #: Hash[T::Module[top], Set[SourceLocation]]
|
|
17
16
|
|
|
18
17
|
# Immediately activated upon load. Observes class/module definition.
|
|
19
18
|
@class_tracepoint = TracePoint.trace(:class) do |tp|
|
|
@@ -36,7 +35,7 @@ module Tapioca
|
|
|
36
35
|
])
|
|
37
36
|
end
|
|
38
37
|
|
|
39
|
-
(
|
|
38
|
+
ConstantDefinition.register(key, loc)
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
@creturn_tracepoint = TracePoint.trace(:c_return) do |tp|
|
|
@@ -46,12 +45,10 @@ module Tapioca
|
|
|
46
45
|
next unless Module === key
|
|
47
46
|
|
|
48
47
|
loc = build_source_location(tp, caller_locations)
|
|
49
|
-
(
|
|
48
|
+
ConstantDefinition.register(key, loc)
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
class << self
|
|
53
|
-
extend T::Sig
|
|
54
|
-
|
|
55
52
|
def disable!
|
|
56
53
|
@class_tracepoint.disable
|
|
57
54
|
@creturn_tracepoint.disable
|
|
@@ -67,15 +64,31 @@ module Tapioca
|
|
|
67
64
|
SourceLocation.from_loc([file || "", lineno])
|
|
68
65
|
end
|
|
69
66
|
|
|
67
|
+
def register(constant, loc)
|
|
68
|
+
return unless loc
|
|
69
|
+
|
|
70
|
+
(@class_files[constant] ||= Set.new) << loc
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def register_cname(cname, namespace, locations)
|
|
74
|
+
return if namespace.autoload?(cname)
|
|
75
|
+
|
|
76
|
+
key = Reflection.constantize(cname, namespace: namespace, inherit: true)
|
|
77
|
+
return unless Module === key
|
|
78
|
+
|
|
79
|
+
loc = Reflection.resolve_loc(locations)
|
|
80
|
+
ConstantDefinition.register(key, loc)
|
|
81
|
+
end
|
|
82
|
+
|
|
70
83
|
# Returns the files in which this class or module was opened. Doesn't know
|
|
71
84
|
# about situations where the class was opened prior to +require+ing,
|
|
72
85
|
# or where metaprogramming was used via +eval+, etc.
|
|
73
|
-
#: (Module klass) -> Set[String]
|
|
86
|
+
#: (T::Module[top] klass) -> Set[String]
|
|
74
87
|
def files_for(klass)
|
|
75
88
|
locations_for(klass).map(&:file).to_set
|
|
76
89
|
end
|
|
77
90
|
|
|
78
|
-
#: (Module klass) -> Set[SourceLocation]
|
|
91
|
+
#: (T::Module[top] klass) -> Set[SourceLocation]
|
|
79
92
|
def locations_for(klass)
|
|
80
93
|
@class_files.fetch(klass, Set.new)
|
|
81
94
|
end
|
|
@@ -84,3 +97,12 @@ module Tapioca
|
|
|
84
97
|
end
|
|
85
98
|
end
|
|
86
99
|
end
|
|
100
|
+
|
|
101
|
+
class Module
|
|
102
|
+
prepend(::Module.new do
|
|
103
|
+
def const_added(cname)
|
|
104
|
+
::Tapioca::Runtime::Trackers::ConstantDefinition.register_cname(cname, self, Kernel.caller_locations)
|
|
105
|
+
super(cname)
|
|
106
|
+
end
|
|
107
|
+
end)
|
|
108
|
+
end
|
|
@@ -6,12 +6,11 @@ module Tapioca
|
|
|
6
6
|
module Trackers
|
|
7
7
|
module MethodDefinition
|
|
8
8
|
extend Tracker
|
|
9
|
-
extend T::Sig
|
|
10
9
|
|
|
11
|
-
@method_definitions = {}.compare_by_identity #: Hash[Module, Hash[Symbol, Array[SourceLocation]]]
|
|
10
|
+
@method_definitions = {}.compare_by_identity #: Hash[T::Module[top], Hash[Symbol, Array[SourceLocation]]]
|
|
12
11
|
|
|
13
12
|
class << self
|
|
14
|
-
#: (Symbol method_name, Module owner, Array[Thread::Backtrace::Location] locations) -> void
|
|
13
|
+
#: (Symbol method_name, T::Module[top] owner, Array[Thread::Backtrace::Location] locations) -> void
|
|
15
14
|
def register(method_name, owner, locations)
|
|
16
15
|
return unless enabled?
|
|
17
16
|
# If Sorbet runtime is redefining a method, it sets this to true.
|
|
@@ -25,7 +24,7 @@ module Tapioca
|
|
|
25
24
|
registrations_for(method_name, owner) << loc
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
#: (Symbol method_name, Module owner) -> Array[SourceLocation]
|
|
27
|
+
#: (Symbol method_name, T::Module[top] owner) -> Array[SourceLocation]
|
|
29
28
|
def method_definitions_for(method_name, owner)
|
|
30
29
|
definitions = registrations_for(method_name, owner)
|
|
31
30
|
|
|
@@ -39,7 +38,7 @@ module Tapioca
|
|
|
39
38
|
|
|
40
39
|
private
|
|
41
40
|
|
|
42
|
-
#: (Symbol method_name, Module owner) -> Array[SourceLocation]
|
|
41
|
+
#: (Symbol method_name, T::Module[top] owner) -> Array[SourceLocation]
|
|
43
42
|
def registrations_for(method_name, owner)
|
|
44
43
|
owner_lookup = (@method_definitions[owner] ||= {})
|
|
45
44
|
owner_lookup[method_name] ||= []
|
|
@@ -6,7 +6,6 @@ module Tapioca
|
|
|
6
6
|
module Trackers
|
|
7
7
|
module Mixin
|
|
8
8
|
extend Tracker
|
|
9
|
-
extend T::Sig
|
|
10
9
|
|
|
11
10
|
@constants_to_mixin_locations = {}.compare_by_identity
|
|
12
11
|
@mixins_to_constants = {}.compare_by_identity
|
|
@@ -20,14 +19,12 @@ module Tapioca
|
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
class << self
|
|
23
|
-
extend T::Sig
|
|
24
|
-
|
|
25
22
|
#: [Result] { -> Result } -> Result
|
|
26
23
|
def with_disabled_registration(&block)
|
|
27
24
|
with_disabled_tracker(&block)
|
|
28
25
|
end
|
|
29
26
|
|
|
30
|
-
#: (Module constant, Module mixin, Type mixin_type) -> void
|
|
27
|
+
#: (T::Module[top] constant, T::Module[top] mixin, Type mixin_type) -> void
|
|
31
28
|
def register(constant, mixin, mixin_type)
|
|
32
29
|
return unless enabled?
|
|
33
30
|
|
|
@@ -49,19 +46,19 @@ module Tapioca
|
|
|
49
46
|
attached_class
|
|
50
47
|
end
|
|
51
48
|
|
|
52
|
-
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
|
49
|
+
#: (T::Module[top] mixin) -> Hash[Type, Hash[T::Module[top], String]]
|
|
53
50
|
def constants_with_mixin(mixin)
|
|
54
51
|
find_or_initialize_mixin_lookup(mixin)
|
|
55
52
|
end
|
|
56
53
|
|
|
57
|
-
#: (Module mixin, Type mixin_type, Module constant) -> String?
|
|
54
|
+
#: (T::Module[top] mixin, Type mixin_type, T::Module[top] constant) -> String?
|
|
58
55
|
def mixin_location(mixin, mixin_type, constant)
|
|
59
56
|
find_or_initialize_mixin_lookup(mixin).dig(mixin_type, constant)
|
|
60
57
|
end
|
|
61
58
|
|
|
62
59
|
private
|
|
63
60
|
|
|
64
|
-
#: (Module constant, Module mixin, Type mixin_type, String location) -> void
|
|
61
|
+
#: (T::Module[top] constant, T::Module[top] mixin, Type mixin_type, String location) -> void
|
|
65
62
|
def register_with_location(constant, mixin, mixin_type, location)
|
|
66
63
|
return unless @enabled
|
|
67
64
|
|
|
@@ -69,7 +66,7 @@ module Tapioca
|
|
|
69
66
|
constants.fetch(mixin_type).store(constant, location)
|
|
70
67
|
end
|
|
71
68
|
|
|
72
|
-
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
|
69
|
+
#: (T::Module[top] mixin) -> Hash[Type, Hash[T::Module[top], String]]
|
|
73
70
|
def find_or_initialize_mixin_lookup(mixin)
|
|
74
71
|
@mixins_to_constants[mixin] ||= {
|
|
75
72
|
Type::Prepend => {}.compare_by_identity,
|
|
@@ -9,8 +9,6 @@ module Tapioca
|
|
|
9
9
|
@required_ancestors_map = {}.compare_by_identity
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
extend T::Sig
|
|
13
|
-
|
|
14
12
|
#: (T::Helpers requiring, ^-> void block) -> void
|
|
15
13
|
def register(requiring, block)
|
|
16
14
|
return unless enabled?
|
|
@@ -19,12 +17,12 @@ module Tapioca
|
|
|
19
17
|
ancestors << block
|
|
20
18
|
end
|
|
21
19
|
|
|
22
|
-
#: (Module mod) -> Array[^-> void]
|
|
20
|
+
#: (T::Module[top] mod) -> Array[^-> void]
|
|
23
21
|
def required_ancestors_blocks_by(mod)
|
|
24
22
|
@required_ancestors_map[mod] || []
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
#: (Module mod) -> Array[untyped]
|
|
25
|
+
#: (T::Module[top] mod) -> Array[untyped]
|
|
28
26
|
def required_ancestors_by(mod)
|
|
29
27
|
blocks = required_ancestors_blocks_by(mod)
|
|
30
28
|
blocks.map do |block|
|
|
@@ -6,11 +6,8 @@ module Tapioca
|
|
|
6
6
|
module Trackers
|
|
7
7
|
# @abstract
|
|
8
8
|
module Tracker
|
|
9
|
-
extend T::Sig
|
|
10
9
|
class << self
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#: ((Tracker & Module) base) -> void
|
|
10
|
+
#: ((Tracker & T::Module[top]) base) -> void
|
|
14
11
|
def extended(base)
|
|
15
12
|
Trackers.register_tracker(base)
|
|
16
13
|
base.instance_exec do
|
|
@@ -6,13 +6,9 @@ require "tapioca/runtime/trackers/tracker"
|
|
|
6
6
|
module Tapioca
|
|
7
7
|
module Runtime
|
|
8
8
|
module Trackers
|
|
9
|
-
extend T::Sig
|
|
10
|
-
|
|
11
9
|
@trackers = [] #: Array[Tracker]
|
|
12
10
|
|
|
13
11
|
class << self
|
|
14
|
-
extend T::Sig
|
|
15
|
-
|
|
16
12
|
#: [Return] { -> Return } -> Return
|
|
17
13
|
def with_trackers_enabled(&blk)
|
|
18
14
|
# Currently this is a dirty hack to ensure disabling trackers
|
|
@@ -120,8 +120,6 @@ module Tapioca
|
|
|
120
120
|
# need to do any matching of constants to type variables to bind their names, Ruby will
|
|
121
121
|
# do that automatically for us and we get the `name` method for free from `Module`.
|
|
122
122
|
class TypeVariableModule < Module
|
|
123
|
-
extend T::Sig
|
|
124
|
-
|
|
125
123
|
class Type < T::Enum
|
|
126
124
|
enums do
|
|
127
125
|
Member = new("type_member")
|
|
@@ -135,7 +133,7 @@ module Tapioca
|
|
|
135
133
|
#: Type
|
|
136
134
|
attr_reader :type
|
|
137
135
|
|
|
138
|
-
#: (Module context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void
|
|
136
|
+
#: (T::Module[top] context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void
|
|
139
137
|
def initialize(context, type, variance, bounds_proc)
|
|
140
138
|
@context = context
|
|
141
139
|
@type = type
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
module Tapioca
|
|
5
5
|
module Static
|
|
6
6
|
class RequiresCompiler
|
|
7
|
-
extend T::Sig
|
|
8
|
-
|
|
9
7
|
#: (String sorbet_path) -> void
|
|
10
8
|
def initialize(sorbet_path)
|
|
11
9
|
@sorbet_path = sorbet_path
|
|
@@ -40,7 +38,7 @@ module Tapioca
|
|
|
40
38
|
end.sort.uniq
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
#: (String file_path) ->
|
|
41
|
+
#: (String file_path) -> Enumerable[String]
|
|
44
42
|
def collect_requires(file_path)
|
|
45
43
|
File.binread(file_path).lines.filter_map do |line|
|
|
46
44
|
/^\s*require\s*(\(\s*)?['"](?<name>[^'"]+)['"](\s*\))?/.match(line) { |m| m["name"] }
|
|
@@ -4,13 +4,9 @@
|
|
|
4
4
|
module Tapioca
|
|
5
5
|
module Static
|
|
6
6
|
class SymbolTableParser
|
|
7
|
-
extend T::Sig
|
|
8
|
-
|
|
9
7
|
SKIP_PARSE_KINDS = ["CLASS_OR_MODULE", "STATIC_FIELD"].freeze #: Array[String]
|
|
10
8
|
|
|
11
9
|
class << self
|
|
12
|
-
extend T::Sig
|
|
13
|
-
|
|
14
10
|
#: (String json_string) -> Set[String]
|
|
15
11
|
def parse_json(json_string)
|
|
16
12
|
obj = JSON.parse(json_string)
|
data/lib/tapioca/version.rb
CHANGED