rbs 2.8.4 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +17 -17
  5. data/README.md +1 -0
  6. data/Rakefile +66 -0
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +18 -2
  12. data/ext/rbs_extension/constants.h +9 -1
  13. data/ext/rbs_extension/lexer.c +834 -777
  14. data/ext/rbs_extension/lexer.h +3 -1
  15. data/ext/rbs_extension/lexer.re +3 -1
  16. data/ext/rbs_extension/lexstate.c +4 -2
  17. data/ext/rbs_extension/parser.c +287 -57
  18. data/ext/rbs_extension/ruby_objs.c +71 -5
  19. data/ext/rbs_extension/ruby_objs.h +9 -2
  20. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  21. data/lib/rbs/ast/declarations.rb +49 -2
  22. data/lib/rbs/ast/directives.rb +39 -0
  23. data/lib/rbs/ast/members.rb +49 -15
  24. data/lib/rbs/cli.rb +38 -19
  25. data/lib/rbs/collection/config/lockfile.rb +115 -0
  26. data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
  27. data/lib/rbs/collection/config.rb +12 -40
  28. data/lib/rbs/collection/installer.rb +9 -13
  29. data/lib/rbs/collection/sources/base.rb +2 -2
  30. data/lib/rbs/collection/sources/git.rb +135 -62
  31. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  32. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  33. data/lib/rbs/collection/sources.rb +7 -1
  34. data/lib/rbs/collection.rb +1 -0
  35. data/lib/rbs/definition.rb +1 -1
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  37. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  38. data/lib/rbs/definition_builder.rb +456 -579
  39. data/lib/rbs/environment/use_map.rb +77 -0
  40. data/lib/rbs/environment.rb +356 -85
  41. data/lib/rbs/environment_loader.rb +20 -17
  42. data/lib/rbs/environment_walker.rb +1 -1
  43. data/lib/rbs/errors.rb +34 -37
  44. data/lib/rbs/locator.rb +3 -3
  45. data/lib/rbs/parser_aux.rb +8 -6
  46. data/lib/rbs/prototype/helpers.rb +29 -13
  47. data/lib/rbs/prototype/node_usage.rb +99 -0
  48. data/lib/rbs/prototype/rb.rb +3 -2
  49. data/lib/rbs/prototype/rbi.rb +6 -4
  50. data/lib/rbs/prototype/runtime.rb +25 -12
  51. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  52. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  53. data/lib/rbs/sorter.rb +3 -3
  54. data/lib/rbs/substitution.rb +19 -0
  55. data/lib/rbs/test/setup.rb +1 -1
  56. data/lib/rbs/type_alias_dependency.rb +1 -1
  57. data/lib/rbs/type_alias_regularity.rb +3 -3
  58. data/lib/rbs/types.rb +1 -5
  59. data/lib/rbs/validator.rb +25 -3
  60. data/lib/rbs/variance_calculator.rb +2 -2
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +54 -19
  63. data/lib/rbs.rb +3 -2
  64. data/lib/rdoc_plugin/parser.rb +3 -3
  65. data/schema/members.json +15 -10
  66. data/sig/ancestor_graph.rbs +22 -2
  67. data/sig/collection/config/lockfile.rbs +80 -0
  68. data/sig/collection/config/lockfile_generator.rbs +53 -0
  69. data/sig/collection/config.rbs +5 -48
  70. data/sig/collection/installer.rbs +1 -1
  71. data/sig/collection/sources.rbs +76 -33
  72. data/sig/constant.rbs +1 -1
  73. data/sig/declarations.rbs +36 -3
  74. data/sig/definition.rbs +1 -1
  75. data/sig/definition_builder.rbs +94 -82
  76. data/sig/directives.rbs +61 -0
  77. data/sig/environment.rbs +150 -28
  78. data/sig/environment_loader.rbs +2 -2
  79. data/sig/errors.rbs +42 -0
  80. data/sig/members.rbs +31 -7
  81. data/sig/parser.rbs +8 -15
  82. data/sig/prototype/node_usage.rbs +20 -0
  83. data/sig/resolver/constant_resolver.rbs +1 -2
  84. data/sig/shims/bundler.rbs +31 -0
  85. data/sig/shims/rubygems.rbs +15 -0
  86. data/sig/shims.rbs +0 -22
  87. data/sig/substitution.rbs +6 -0
  88. data/sig/use_map.rbs +35 -0
  89. data/sig/validator.rbs +12 -5
  90. data/sig/writer.rbs +6 -2
  91. metadata +16 -9
  92. data/lib/rbs/constant_table.rb +0 -167
  93. data/lib/rbs/type_name_resolver.rb +0 -67
  94. data/sig/constant_table.rbs +0 -30
  95. data/sig/type_name_resolver.rbs +0 -26
@@ -1,27 +1,32 @@
1
1
  module RBS
2
2
  module Collection
3
3
  module Sources
4
- def self.from_config_entry: (source_entry) -> _Source
4
+ def self.from_config_entry: (Git::source_entry) -> Git
5
+ | (source_entry) -> t
5
6
 
6
7
  interface _Source
7
- def has?: (Config::gem_entry) -> boolish
8
- def versions: (Config::gem_entry) -> Array[String]
9
- def install: (dest: Pathname, config_entry: Config::gem_entry, stdout: CLI::_IO) -> void
8
+ def has?: (String name, String? version) -> boolish
9
+ def versions: (String name) -> Array[String]
10
+ def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
10
11
  def to_lockfile: () -> source_entry
11
- def manifest_of: (Config::gem_entry) -> manifest_entry?
12
- def dependencies_of: (Config::gem_entry) -> Array[{"name" => String}]?
12
+ def manifest_of: (String name, String version) -> manifest_entry?
13
+ def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
13
14
  end
14
15
 
16
+ type t = Git | Stdlib | Rubygems
17
+
15
18
  type source_entry = Git::source_entry
16
19
  | Stdlib::source_entry
17
20
  | Rubygems::source_entry
18
21
 
19
22
  type manifest_entry = {
20
- "dependencies" => Array[{"name" => String}]?,
23
+ "dependencies" => Array[manifest_dependency]?,
21
24
  }
22
25
 
26
+ type manifest_dependency = { "name" => String }
27
+
23
28
  module Base : _Source
24
- def dependencies_of: (Config::gem_entry config_entry) -> Array[{"name" => String}]?
29
+ def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
25
30
  end
26
31
 
27
32
  class Git
@@ -43,48 +48,82 @@ module RBS
43
48
  attr_reader name: String
44
49
  attr_reader remote: String
45
50
  attr_reader repo_dir: String
51
+ attr_reader revision: String
46
52
 
47
53
  def initialize: (name: String, revision: String, remote: String, repo_dir: String?) -> untyped
48
54
 
49
- def has?: (Config::gem_entry) -> bool
55
+ def has?: (String name, String? version) -> boolish
50
56
 
51
- def versions: (Config::gem_entry) -> Array[String]
57
+ def versions: (String name) -> Array[String]
52
58
 
53
- def install: (dest: Pathname, config_entry: Config::gem_entry, stdout: CLI::_IO) -> void
59
+ def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
54
60
 
55
61
  def to_lockfile: () -> source_entry
56
62
 
57
- def manifest_of: (Config::gem_entry) -> manifest_entry?
63
+ def manifest_of: (String name, String version) -> manifest_entry?
64
+
65
+ def resolved_revision: () -> String
58
66
 
59
67
  private
60
68
 
69
+ @need_setup: bool
70
+
61
71
  @git_dir: Pathname?
62
72
 
63
73
  @resolved_revision: String?
64
74
 
65
- def _install: (dest: Pathname , config_entry: Config::gem_entry) -> void
75
+ @gems_versions: Hash[String, Set[String]]?
66
76
 
67
- def cp_r: (Pathname, Pathname) -> void
77
+ def _install: (dest: Pathname , name: String, version: String) -> void
68
78
 
69
- def setup!: (revision: String) -> void
70
-
71
- def need_to_fetch?: (String revision ) -> bool
79
+ def cp_r: (Pathname, Pathname) -> void
72
80
 
81
+ # Ensure the git repository exists, and
82
+ #
83
+ # * When `revision` is a commit hash, the commit exists in the local repository, or
84
+ # * When `revision` is a branch name, the latest version is fetched from `origin`
85
+ #
86
+ # It may require a network connection to fetch or clone the repository from remote.
87
+ #
88
+ # * If `revision` is a commit hash and the commit doesn't exists in the local repository, it runs `git fetch`
89
+ # * If `revision` is a branch name, it runs `git fetch` once per instance
90
+ #
91
+ def setup!: [T] () { () -> T } -> T
92
+ | () -> void
93
+
94
+ def need_to_fetch?: (String revision) -> bool
95
+
96
+ # The full path of local git repository
73
97
  def git_dir: () -> Pathname
74
98
 
99
+ # The full path of `repo_dir` in the local git repository
75
100
  def gem_repo_dir: () -> Pathname
76
101
 
77
- def with_revision: [T] () { () -> T } -> T
78
-
79
- def resolved_revision: () -> String
80
-
81
- def resolve_revision: () -> String
102
+ # Returns `true` if `revision` looks like a commit hash
103
+ def commit_hash?: () -> bool
82
104
 
105
+ # Executes a git command, raises an error if failed
83
106
  def git: (*String cmd, **untyped opt) -> String
84
107
 
108
+ # Executes a git command, returns `nil` if failed
109
+ def git?: (*String cmd, **untyped opt) -> String?
110
+
85
111
  def sh!: (*String cmd, **untyped opt) -> String
86
112
 
87
- def format_config_entry: (Config::gem_entry) -> String
113
+ def format_config_entry: (String name, String version) -> String
114
+
115
+ type metadata = { 'name' => String, 'version' => String, 'source' => source_entry }
116
+
117
+ def metadata_content: (name: String, version: String) -> metadata
118
+
119
+ # Write `.rbs_meta.yaml`
120
+ def write_metadata: (dir: Pathname, name: String, version: String) -> void
121
+
122
+ # Load `.rbs_meta.yaml` from the `dir`, where is the destination of the RBS file installation, and return the cleaned up content
123
+ #
124
+ def load_metadata: (dir: Pathname) -> metadata
125
+
126
+ def gems_versions: () -> Hash[String, Set[String]]
88
127
  end
89
128
 
90
129
  # signatures that are bundled in rbs gem under the stdlib/ directory
@@ -101,19 +140,19 @@ module RBS
101
140
  # polyfill of singleton module
102
141
  def self.instance: () -> instance
103
142
 
104
- def has?: (Config::gem_entry) -> boolish
143
+ def has?: (String name, String? version) -> boolish
105
144
 
106
- def versions: (Config::gem_entry) -> Array[String]
145
+ def versions: (String name) -> Array[String]
107
146
 
108
- def install: (dest: Pathname, config_entry: Config::gem_entry, stdout: CLI::_IO) -> void
147
+ def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
109
148
 
110
149
  def to_lockfile: () -> source_entry
111
150
 
112
- def manifest_of: (Config::gem_entry) -> manifest_entry?
151
+ def manifest_of: (String name, String version) -> manifest_entry?
113
152
 
114
153
  private
115
154
 
116
- def lookup: (Config::gem_entry) -> Pathname?
155
+ def lookup: (String name, String? version) -> Pathname?
117
156
  end
118
157
 
119
158
  # sig/ directory
@@ -127,15 +166,19 @@ module RBS
127
166
  # polyfill of singleton module
128
167
  def self.instance: () -> instance
129
168
 
130
- def has?: (Config::gem_entry) -> boolish
131
- def versions: (Config::gem_entry) -> Array[String]
132
- def install: (dest: Pathname, config_entry: Config::gem_entry, stdout: CLI::_IO) -> void
169
+ def has?: (String name, String? version) -> boolish
170
+
171
+ def versions: (String name) -> Array[String]
172
+
173
+ def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
174
+
133
175
  def to_lockfile: () -> source_entry
134
- def manifest_of: (Config::gem_entry) -> manifest_entry?
176
+
177
+ def manifest_of: (String name, String version) -> manifest_entry?
135
178
 
136
179
  private
137
180
 
138
- def gem_sig_path: (Config::gem_entry) -> [Gem::Specification, Pathname]?
181
+ def gem_sig_path: (String name, String? version) -> [Gem::Specification, Pathname]?
139
182
  end
140
183
  end
141
184
  end
data/sig/constant.rbs CHANGED
@@ -2,7 +2,7 @@ module RBS
2
2
  class Constant
3
3
  type constant_entry = Environment::ClassEntry
4
4
  | Environment::ModuleEntry
5
- | Environment::SingleEntry[TypeName, AST::Declarations::Constant]
5
+ | Environment::ConstantEntry
6
6
 
7
7
  attr_reader name: TypeName
8
8
 
data/sig/declarations.rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  module RBS
2
2
  module AST
3
3
  module Declarations
4
- type t = Class | Module | Interface | Constant | Global | Alias
4
+ type t = Class | Module | Interface | Constant | Global | TypeAlias | ClassAlias | ModuleAlias
5
5
 
6
6
  class Base
7
7
  end
@@ -135,7 +135,7 @@ module RBS
135
135
  include _ToJson
136
136
  end
137
137
 
138
- class Interface
138
+ class Interface < Base
139
139
  type member = Members::t
140
140
 
141
141
  # interface _Foo end
@@ -166,7 +166,7 @@ module RBS
166
166
  include _ToJson
167
167
  end
168
168
 
169
- class Alias < Base
169
+ class TypeAlias < Base
170
170
  # type loc[T] = Location[T, bot]
171
171
  # ^^^^ keyword
172
172
  # ^^^ name
@@ -223,6 +223,39 @@ module RBS
223
223
  include _HashEqual
224
224
  include _ToJson
225
225
  end
226
+
227
+ class AliasDecl < Base
228
+ # module Foo = Bar
229
+ # ^^^^^^ keyword
230
+ # ^^^ new_name
231
+ # ^ eq
232
+ # ^^^ old_name
233
+ #
234
+ # class Foo = Bar
235
+ # ^^^^^ keyword
236
+ #
237
+ type loc = Location[:keyword | :new_name | :eq | :old_name, bot]
238
+
239
+ attr_reader new_name: TypeName
240
+
241
+ attr_reader old_name: TypeName
242
+
243
+ attr_reader location: loc?
244
+
245
+ attr_reader comment: Comment?
246
+
247
+ def initialize: (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?) -> void
248
+
249
+ include _HashEqual
250
+ end
251
+
252
+ class ClassAlias < AliasDecl
253
+ include _ToJson
254
+ end
255
+
256
+ class ModuleAlias < AliasDecl
257
+ include _ToJson
258
+ end
226
259
  end
227
260
  end
228
261
  end
data/sig/definition.rbs CHANGED
@@ -119,7 +119,7 @@ module RBS
119
119
  end
120
120
 
121
121
  type self_type = Types::ClassSingleton | Types::ClassInstance | Types::Interface
122
- type definition_entry = Environment::ModuleEntry | Environment::ClassEntry | Environment::SingleEntry[TypeName, AST::Declarations::Interface]
122
+ type definition_entry = Environment::ModuleEntry | Environment::ClassEntry | Environment::InterfaceEntry
123
123
 
124
124
  attr_reader type_name: TypeName
125
125
  attr_reader entry: definition_entry
@@ -1,111 +1,39 @@
1
1
  module RBS
2
2
  # DefinitionBuilder translates TypeName to Definition of the type
3
3
  #
4
- # The translation goes three steps:
5
- #
6
- # 1. Calculate _ancestors_ of the type with AncestorBuilder
7
- # 2. Calculate _partial_ definitions of each ancestor
8
- # 3. Merge _partial_ definitions
9
- #
10
- # A _partial_ definition is a definition of one type name, in terms of it doesn't have methods of super classes nor included modules.
11
- #
4
+ # It also provides semantic utilities that depends on Environment.
12
5
  #
13
6
  class DefinitionBuilder
14
7
  attr_reader env: Environment
15
- attr_reader type_name_resolver: TypeNameResolver
16
8
  attr_reader ancestor_builder: AncestorBuilder
17
9
  attr_reader method_builder: MethodBuilder
18
10
 
19
- attr_reader instance_cache: Hash[[TypeName, bool], Definition | false | nil]
11
+ attr_reader instance_cache: Hash[TypeName, Definition | false | nil]
20
12
  attr_reader singleton_cache: Hash[TypeName, Definition | false | nil]
21
13
  attr_reader singleton0_cache: Hash[TypeName, Definition | false | nil]
22
14
  attr_reader interface_cache: Hash[TypeName, Definition | false | nil]
23
15
 
24
16
  def initialize: (env: Environment, ?ancestor_builder: AncestorBuilder?, ?method_builder: MethodBuilder?) -> void
25
17
 
18
+ # Returns a Definition of a interface
19
+ #
26
20
  def build_interface: (TypeName) -> Definition
27
21
 
28
- # Returns a Definition of a instance of given type name.
22
+ # Returns a Definition of an instance type
29
23
  #
30
24
  # If TypeName is a module and `no_self_types` is `true`, it won't have methods of _self type constraints_.
31
25
  # This typically happens when definition is being calculated for mixin.
32
26
  #
33
- def build_instance: (TypeName, ?no_self_types: bool) -> Definition
27
+ def build_instance: (TypeName) -> Definition
34
28
 
29
+ # Returns a Definition of a singleton type
35
30
  def build_singleton: (TypeName) -> Definition
36
31
 
37
- def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
38
-
39
- def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
40
-
41
- def build_singleton0: (TypeName) -> Definition
42
-
43
- def merge_definition: (src: Definition, dest: Definition, subst: Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
44
-
45
- def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
46
-
47
- def merge_variable: (Hash[Symbol, Definition::Variable], Symbol, Definition::Variable, Substitution, ?keep_super: bool) -> void
48
-
49
- def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
50
- | [A] (TypeName, cache: Hash[A, Definition | false | nil], key: A) { () -> Definition } -> Definition
51
-
52
- def validate_params_with: (Array[AST::TypeParam], result: VarianceCalculator::Result) { (AST::TypeParam) -> void } -> void
53
-
54
- def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
55
-
56
- def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
57
-
58
- def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
59
-
60
- # Add methods from `methods` to Definition
61
- #
62
- # * `methods`:
63
- # * `interface_methods`: Methods of interfaces mixed into the type
64
- # * `self_constraints_methods`: Methods of the self constraints methods
65
- # * `super_interface_method`: `true` to have super method of existing method (`true` is the Definition is the target module)
66
- #
67
- def define_methods: (
68
- Definition,
69
- methods: MethodBuilder::Methods,
70
- interface_methods: Hash[Symbol, Definition::Method],
71
- methods_with_self: Hash[Symbol, Definition::Method]?,
72
- super_interface_method: bool
73
- ) -> void
74
-
75
- # Define methods on singleton type
76
- #
77
- def define_methods_singleton: (
78
- Definition,
79
- methods: MethodBuilder::Methods,
80
- interface_methods: Hash[Symbol, Definition::Method]
81
- ) -> void
82
-
83
- # Define methods on instance type
84
- #
85
- def define_methods_instance: (
86
- Definition,
87
- methods: MethodBuilder::Methods,
88
- interface_methods: Hash[Symbol, Definition::Method]
89
- ) -> void
90
-
91
- # Define methods on module instance type
32
+ # Validates the given Namespace and its ancestor namespaces exists
92
33
  #
93
- # * Pass `nil` to `module_self_methods:` to build a module instance type that will be mixed in to other modules/classes
94
- # * Pass methods from self-type-constraints to build a module instance type alone (to type check itself)
34
+ # Raises NoTypeFoundError
95
35
  #
96
- def define_methods_module_instance: (
97
- Definition,
98
- methods: MethodBuilder::Methods,
99
- interface_methods: Hash[Symbol, Definition::Method],
100
- module_self_methods: Hash[Symbol, Definition::Method]?
101
- ) -> void
102
-
103
- # Validates presence of type names recursively.
104
- # Assumes the type names are already resolved.
105
- #
106
- def validate_type_presence: (Types::t) -> void
107
-
108
- def validate_type_name: (TypeName, Location[untyped, untyped]?) -> void
36
+ def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
109
37
 
110
38
  # Expand a type alias of given name without type arguments.
111
39
  # Raises an error if the type alias requires arguments.
@@ -138,6 +66,90 @@ module RBS
138
66
  #
139
67
  def expand_alias2: (TypeName, Array[Types::t] args) -> Types::t
140
68
 
69
+ # Validates presence of type names recursively
70
+ #
71
+ # Assumes the type names are already resolved.
72
+ # Raises NoTypeFoundError in case of failure.
73
+ #
74
+ def validate_type_presence: (Types::t) -> void
75
+
76
+ # Validates presence of an absolute type name
77
+ #
78
+ # Raises NoTypeFoundError in case of error.
79
+ #
80
+ def validate_type_name: (TypeName, Location[untyped, untyped]?) -> void
81
+
82
+ # Returns a new DefinitionBuilder with updated Environment, AncestorBuilder, and exceptions
83
+ #
141
84
  def update: (env: Environment, ancestor_builder: AncestorBuilder, except: _Each[TypeName]) -> DefinitionBuilder
85
+
86
+ private
87
+
88
+ def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
89
+
90
+ def build_singleton0: (TypeName) -> Definition
91
+
92
+ # Returns `interface_methods` from given array of interface ancestors
93
+ #
94
+ def interface_methods: (Array[Definition::Ancestor::Instance] interface_ancestors) -> interface_methods
95
+
96
+ def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
97
+
98
+ def validate_params_with: (Array[AST::TypeParam], result: VarianceCalculator::Result) { (AST::TypeParam) -> void } -> void
99
+
100
+ def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
101
+
102
+ def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
103
+
104
+ def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
105
+
106
+ # Add method definition to `methods`, which will be merged to `class_definition` after defining all methods at this *level* -- class, module, or interface
107
+ #
108
+ # `class_definition` is a definition of given type, but it has definitions of prior levels.
109
+ #
110
+ def define_method: (
111
+ Hash[Symbol, Definition::Method] methods,
112
+ Definition class_definition,
113
+ MethodBuilder::Methods::Definition method_definition,
114
+ Substitution subst,
115
+ defined_in: TypeName,
116
+ ?implemented_in: TypeName?
117
+ ) -> void
118
+
119
+ # The `interface_methods` type describes the association between the interface name to its name and the *mixin* to a module
120
+ #
121
+ type interface_methods = Hash[
122
+ Definition::Ancestor::Instance,
123
+ [MethodBuilder::Methods, AST::Members::Include | AST::Members::Extend]
124
+ ]
125
+
126
+ # Add method definitions from `module_methods` to `definition`
127
+ #
128
+ # It also processes interface mixins, with duplication detection.
129
+ # It doesn't process module mixins.
130
+ #
131
+ def import_methods: (
132
+ Definition definition,
133
+ TypeName module_name,
134
+ MethodBuilder::Methods module_methods,
135
+ interface_methods interface_methods,
136
+ Substitution subst
137
+ ) -> void
138
+
139
+ # Updates `definition` with methods and variables of `type_name` that can be a module or a class
140
+ #
141
+ # It processes includes and prepends recursively.
142
+ #
143
+ def define_instance: (Definition definition, TypeName type_name, Substitution subst) -> void
144
+
145
+ def define_interface: (Definition definition, TypeName type_name, Substitution subst) -> void
146
+
147
+ # Returns a substitution that corresponds to type application
148
+ #
149
+ # ```
150
+ # tapp_subst(`::Array`, [`::Integer`]) # => Subsitution.build([:Elem], [`::Integer`])
151
+ # ```
152
+ #
153
+ def tapp_subst: (TypeName, Array[Types::t]) -> Substitution
142
154
  end
143
155
  end
@@ -0,0 +1,61 @@
1
+ module RBS
2
+ module AST
3
+ module Directives
4
+ type t = Use
5
+
6
+ class Base
7
+ end
8
+
9
+ # ```
10
+ # use Foo, Foo::Bar as FBar, Foo:Baz::*
11
+ # ```
12
+ #
13
+ class Use < Base
14
+ type clause = SingleClause | WildcardClause
15
+
16
+ class SingleClause
17
+ # Foo::Bar
18
+ # ^^^^^^^^ type_name
19
+ #
20
+ # Foo::Bar as X
21
+ # ^^ keyword
22
+ # ^ new_name
23
+ #
24
+ type loc = Location[:type_name, :keyword | :new_name]
25
+
26
+ attr_reader type_name: TypeName
27
+
28
+ attr_reader new_name: Symbol?
29
+
30
+ attr_reader location: loc?
31
+
32
+ def initialize: (type_name: TypeName, new_name: Symbol?, location: loc?) -> void
33
+ end
34
+
35
+ class WildcardClause
36
+ # Foo::Bar::*
37
+ # ^^^^^^^^^^ namespace
38
+ # ^ star
39
+ #
40
+ type loc = Location[:namespace | :star, bot]
41
+
42
+ attr_reader namespace: Namespace
43
+
44
+ attr_reader location: loc?
45
+
46
+ def initialize: (namespace: Namespace, location: loc?) -> void
47
+ end
48
+
49
+ # use Foo
50
+ # ^^^ keyword
51
+ type loc = Location[:keyword, bot]
52
+
53
+ attr_reader clauses: Array[clause]
54
+
55
+ attr_reader location: loc?
56
+
57
+ def initialize: (clauses: Array[clause], location: loc?) -> void
58
+ end
59
+ end
60
+ end
61
+ end