rbs 4.1.0.pre.1 → 4.1.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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +37 -0
  3. data/.github/workflows/bundle-update.yml +1 -1
  4. data/.github/workflows/c-check.yml +14 -6
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/jruby.yml +79 -0
  8. data/.github/workflows/milestone.yml +13 -2
  9. data/.github/workflows/ruby.yml +16 -4
  10. data/.github/workflows/rust.yml +13 -8
  11. data/.github/workflows/truffleruby.yml +54 -0
  12. data/.github/workflows/typecheck.yml +5 -2
  13. data/.github/workflows/wasm.yml +55 -0
  14. data/.github/workflows/windows.yml +8 -2
  15. data/.gitignore +8 -0
  16. data/CHANGELOG.md +88 -0
  17. data/Dockerfile.jruby +53 -0
  18. data/README.md +3 -3
  19. data/Rakefile +103 -1
  20. data/Steepfile +9 -0
  21. data/core/array.rbs +243 -180
  22. data/core/builtin.rbs +6 -6
  23. data/core/enumerable.rbs +109 -109
  24. data/core/enumerator/product.rbs +5 -5
  25. data/core/enumerator.rbs +28 -28
  26. data/core/file.rbs +24 -1018
  27. data/core/file_constants.rbs +463 -0
  28. data/core/file_stat.rbs +534 -0
  29. data/core/float.rbs +0 -24
  30. data/core/hash.rbs +117 -101
  31. data/core/integer.rbs +21 -58
  32. data/core/io.rbs +25 -7
  33. data/core/match_data.rbs +1 -1
  34. data/core/module.rbs +88 -74
  35. data/core/numeric.rbs +3 -0
  36. data/core/object_space/weak_key_map.rbs +7 -7
  37. data/core/pathname.rbs +0 -10
  38. data/core/ractor.rbs +0 -10
  39. data/core/range.rbs +23 -23
  40. data/core/rbs/ops.rbs +154 -0
  41. data/core/rbs/unnamed/argf.rbs +3 -3
  42. data/core/rubygems/errors.rbs +4 -1
  43. data/core/rubygems/requirement.rbs +0 -10
  44. data/core/rubygems/rubygems.rbs +4 -1
  45. data/core/rubygems/specification.rbs +8 -0
  46. data/core/rubygems/version.rbs +0 -160
  47. data/core/set.rbs +3 -3
  48. data/core/struct.rbs +16 -16
  49. data/core/thread.rbs +9 -14
  50. data/docs/CONTRIBUTING.md +2 -1
  51. data/docs/inline.md +36 -6
  52. data/docs/rbs_by_example.md +20 -20
  53. data/docs/release.md +69 -0
  54. data/docs/syntax.md +2 -2
  55. data/docs/wasm_serialization.md +80 -0
  56. data/ext/rbs_extension/ast_translation.c +1294 -973
  57. data/ext/rbs_extension/ast_translation.h +4 -0
  58. data/ext/rbs_extension/legacy_location.c +11 -6
  59. data/ext/rbs_extension/main.c +139 -4
  60. data/include/rbs/ast.h +9 -1
  61. data/include/rbs/serialize.h +39 -0
  62. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  63. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  64. data/lib/rbs/ast/ruby/members.rb +12 -1
  65. data/lib/rbs/buffer.rb +48 -11
  66. data/lib/rbs/collection/sources/git.rb +6 -0
  67. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  68. data/lib/rbs/environment.rb +4 -3
  69. data/lib/rbs/inline_parser.rb +5 -3
  70. data/lib/rbs/namespace.rb +47 -11
  71. data/lib/rbs/parser_aux.rb +4 -2
  72. data/lib/rbs/prototype/rbi.rb +193 -25
  73. data/lib/rbs/prototype/runtime.rb +2 -0
  74. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  75. data/lib/rbs/type_name.rb +33 -13
  76. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  77. data/lib/rbs/version.rb +1 -1
  78. data/lib/rbs/wasm/deserializer.rb +213 -0
  79. data/lib/rbs/wasm/location.rb +61 -0
  80. data/lib/rbs/wasm/parser.rb +137 -0
  81. data/lib/rbs/wasm/runtime.rb +196 -0
  82. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  83. data/lib/rbs.rb +13 -2
  84. data/lib/rbs_jars.rb +39 -0
  85. data/lib/rdoc_plugin/parser.rb +5 -0
  86. data/rbs.gemspec +32 -2
  87. data/sig/ast/ruby/members.rbs +6 -1
  88. data/sig/buffer.rbs +19 -1
  89. data/sig/namespace.rbs +20 -0
  90. data/sig/parser.rbs +10 -0
  91. data/sig/prototype/rbi.rbs +33 -4
  92. data/sig/resolver/type_name_resolver.rbs +2 -4
  93. data/sig/typename.rbs +15 -0
  94. data/sig/unit_test/type_assertions.rbs +4 -0
  95. data/sig/wasm/deserializer.rbs +66 -0
  96. data/sig/wasm/serialization_schema.rbs +13 -0
  97. data/src/ast.c +78 -78
  98. data/src/lexer.c +97 -93
  99. data/src/lexer.re +1 -1
  100. data/src/lexstate.c +9 -1
  101. data/src/serialize.c +958 -0
  102. data/src/util/rbs_allocator.c +14 -8
  103. data/stdlib/abbrev/0/array.rbs +1 -1
  104. data/stdlib/csv/0/csv.rbs +5 -5
  105. data/stdlib/delegate/0/delegator.rbs +2 -1
  106. data/stdlib/digest/0/digest.rbs +11 -5
  107. data/stdlib/erb/0/erb.rbs +1 -1
  108. data/stdlib/etc/0/etc.rbs +18 -4
  109. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  110. data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/monitor/0/monitor.rbs +2 -2
  113. data/stdlib/openssl/0/openssl.rbs +44 -38
  114. data/stdlib/resolv/0/resolv.rbs +1 -1
  115. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  116. data/stdlib/stringio/0/stringio.rbs +32 -10
  117. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  118. data/stdlib/tempfile/0/manifest.yaml +3 -0
  119. data/stdlib/timeout/0/timeout.rbs +0 -5
  120. data/stdlib/tsort/0/cyclic.rbs +1 -1
  121. data/stdlib/tsort/0/interfaces.rbs +8 -8
  122. data/stdlib/tsort/0/tsort.rbs +9 -9
  123. data/stdlib/uri/0/generic.rbs +0 -5
  124. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  125. data/stdlib/zlib/0/zstream.rbs +0 -1
  126. data/wasm/README.md +60 -0
  127. data/wasm/rbs_wasm.c +423 -0
  128. metadata +26 -5
  129. data/.vscode/extensions.json +0 -5
  130. data/.vscode/settings.json +0 -19
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # This file is generated by the templates/template.rb script and should not be
4
+ # modified manually. To change the template see
5
+ # templates/lib/rbs/wasm/serialization_schema.rb.erb
6
+
7
+ module RBS
8
+ module WASM
9
+ # Describes how to decode the binary buffer produced by `rbs_serialize_node`
10
+ # (src/serialize.c) back into RBS::AST objects. RBS::WASM::Deserializer walks
11
+ # this table; the matching encoder is generated from the same config.yml, so
12
+ # the two stay in sync.
13
+ #
14
+ # SCHEMA is indexed by node tag: tag 0 is NULL and SYMBOL_TAG is the
15
+ # interned-symbol tag. Each remaining entry is one of:
16
+ #
17
+ # [:node, class_name, expose_location, loc_children, fields, resolve_type_params]
18
+ # [:bool] / [:integer] / [:string_value] / [:record_field]
19
+ # [:signature] / [:namespace] / [:type_name]
20
+ #
21
+ # where loc_children is [[name, required?], ...] and fields is
22
+ # [[name, reader], ...] with reader one of :node, :node_list, :hash, :string,
23
+ # :bool, :location_range, :location_range_list, :attr_ivar_name, or
24
+ # [:enum, [value_or_nil, ...]].
25
+ module SerializationSchema
26
+ SYMBOL_TAG = 78
27
+
28
+ SCHEMA = [
29
+ nil, # tag 0 is reserved for NULL
30
+ [:node, "RBS::AST::Annotation", true, nil, [[:string, :string]], false],
31
+ [:bool],
32
+ [:node, "RBS::AST::Comment", true, nil, [[:string, :string]], false],
33
+ [:node, "RBS::AST::Declarations::Class", true, [[:keyword, true], [:name, true], [:end, true], [:type_params, false], [:lt, false]], [[:name, :node], [:type_params, :node_list], [:super_class, :node], [:members, :node_list], [:annotations, :node_list], [:comment, :node]], true],
34
+ [:node, "RBS::AST::Declarations::Class::Super", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
35
+ [:node, "RBS::AST::Declarations::ClassAlias", true, [[:keyword, true], [:new_name, true], [:eq, true], [:old_name, true]], [[:new_name, :node], [:old_name, :node], [:comment, :node], [:annotations, :node_list]], false],
36
+ [:node, "RBS::AST::Declarations::Constant", true, [[:name, true], [:colon, true]], [[:name, :node], [:type, :node], [:comment, :node], [:annotations, :node_list]], false],
37
+ [:node, "RBS::AST::Declarations::Global", true, [[:name, true], [:colon, true]], [[:name, :node], [:type, :node], [:comment, :node], [:annotations, :node_list]], false],
38
+ [:node, "RBS::AST::Declarations::Interface", true, [[:keyword, true], [:name, true], [:end, true], [:type_params, false]], [[:name, :node], [:type_params, :node_list], [:members, :node_list], [:annotations, :node_list], [:comment, :node]], true],
39
+ [:node, "RBS::AST::Declarations::Module", true, [[:keyword, true], [:name, true], [:end, true], [:type_params, false], [:colon, false], [:self_types, false]], [[:name, :node], [:type_params, :node_list], [:self_types, :node_list], [:members, :node_list], [:annotations, :node_list], [:comment, :node]], true],
40
+ [:node, "RBS::AST::Declarations::Module::Self", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
41
+ [:node, "RBS::AST::Declarations::ModuleAlias", true, [[:keyword, true], [:new_name, true], [:eq, true], [:old_name, true]], [[:new_name, :node], [:old_name, :node], [:comment, :node], [:annotations, :node_list]], false],
42
+ [:node, "RBS::AST::Declarations::TypeAlias", true, [[:keyword, true], [:name, true], [:eq, true], [:type_params, false]], [[:name, :node], [:type_params, :node_list], [:type, :node], [:annotations, :node_list], [:comment, :node]], true],
43
+ [:node, "RBS::AST::Directives::Use", true, [[:keyword, true]], [[:clauses, :node_list]], false],
44
+ [:node, "RBS::AST::Directives::Use::SingleClause", true, [[:type_name, true], [:keyword, false], [:new_name, false]], [[:type_name, :node], [:new_name, :node]], false],
45
+ [:node, "RBS::AST::Directives::Use::WildcardClause", true, [[:namespace, true], [:star, true]], [[:namespace, :node]], false],
46
+ [:integer],
47
+ [:node, "RBS::AST::Members::Alias", true, [[:keyword, true], [:new_name, true], [:old_name, true], [:new_kind, false], [:old_kind, false]], [[:new_name, :node], [:old_name, :node], [:kind, [:enum, [:instance, :singleton]]], [:annotations, :node_list], [:comment, :node]], false],
48
+ [:node, "RBS::AST::Members::AttrAccessor", true, [[:keyword, true], [:name, true], [:colon, true], [:kind, false], [:ivar, false], [:ivar_name, false], [:visibility, false]], [[:name, :node], [:type, :node], [:ivar_name, :attr_ivar_name], [:kind, [:enum, [:instance, :singleton]]], [:annotations, :node_list], [:comment, :node], [:visibility, [:enum, [nil, :public, :private]]]], false],
49
+ [:node, "RBS::AST::Members::AttrReader", true, [[:keyword, true], [:name, true], [:colon, true], [:kind, false], [:ivar, false], [:ivar_name, false], [:visibility, false]], [[:name, :node], [:type, :node], [:ivar_name, :attr_ivar_name], [:kind, [:enum, [:instance, :singleton]]], [:annotations, :node_list], [:comment, :node], [:visibility, [:enum, [nil, :public, :private]]]], false],
50
+ [:node, "RBS::AST::Members::AttrWriter", true, [[:keyword, true], [:name, true], [:colon, true], [:kind, false], [:ivar, false], [:ivar_name, false], [:visibility, false]], [[:name, :node], [:type, :node], [:ivar_name, :attr_ivar_name], [:kind, [:enum, [:instance, :singleton]]], [:annotations, :node_list], [:comment, :node], [:visibility, [:enum, [nil, :public, :private]]]], false],
51
+ [:node, "RBS::AST::Members::ClassInstanceVariable", true, [[:name, true], [:colon, true], [:kind, false]], [[:name, :node], [:type, :node], [:comment, :node]], false],
52
+ [:node, "RBS::AST::Members::ClassVariable", true, [[:name, true], [:colon, true], [:kind, false]], [[:name, :node], [:type, :node], [:comment, :node]], false],
53
+ [:node, "RBS::AST::Members::Extend", true, [[:name, true], [:keyword, true], [:args, false]], [[:name, :node], [:args, :node_list], [:annotations, :node_list], [:comment, :node]], false],
54
+ [:node, "RBS::AST::Members::Include", true, [[:name, true], [:keyword, true], [:args, false]], [[:name, :node], [:args, :node_list], [:annotations, :node_list], [:comment, :node]], false],
55
+ [:node, "RBS::AST::Members::InstanceVariable", true, [[:name, true], [:colon, true], [:kind, false]], [[:name, :node], [:type, :node], [:comment, :node]], false],
56
+ [:node, "RBS::AST::Members::MethodDefinition", true, [[:keyword, true], [:name, true], [:kind, false], [:overloading, false], [:visibility, false]], [[:name, :node], [:kind, [:enum, [:instance, :singleton, :singleton_instance]]], [:overloads, :node_list], [:annotations, :node_list], [:comment, :node], [:overloading, :bool], [:visibility, [:enum, [nil, :public, :private]]]], false],
57
+ [:node, "RBS::AST::Members::MethodDefinition::Overload", false, nil, [[:annotations, :node_list], [:method_type, :node]], false],
58
+ [:node, "RBS::AST::Members::Prepend", true, [[:name, true], [:keyword, true], [:args, false]], [[:name, :node], [:args, :node_list], [:annotations, :node_list], [:comment, :node]], false],
59
+ [:node, "RBS::AST::Members::Private", true, nil, nil, false],
60
+ [:node, "RBS::AST::Members::Public", true, nil, nil, false],
61
+ [:node, "RBS::AST::Ruby::Annotations::BlockParamTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:ampersand_location, :location_range], [:name_location, :location_range], [:colon_location, :location_range], [:question_location, :location_range], [:type_location, :location_range], [:type, :node], [:comment_location, :location_range]], false],
62
+ [:node, "RBS::AST::Ruby::Annotations::ClassAliasAnnotation", true, nil, [[:prefix_location, :location_range], [:keyword_location, :location_range], [:type_name, :node], [:type_name_location, :location_range]], false],
63
+ [:node, "RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:annotations, :node_list], [:method_type, :node]], false],
64
+ [:node, "RBS::AST::Ruby::Annotations::DoubleSplatParamTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:star2_location, :location_range], [:name_location, :location_range], [:colon_location, :location_range], [:param_type, :node], [:comment_location, :location_range]], false],
65
+ [:node, "RBS::AST::Ruby::Annotations::InstanceVariableAnnotation", true, nil, [[:prefix_location, :location_range], [:ivar_name, :node], [:ivar_name_location, :location_range], [:colon_location, :location_range], [:type, :node], [:comment_location, :location_range]], false],
66
+ [:node, "RBS::AST::Ruby::Annotations::MethodTypesAnnotation", true, nil, [[:prefix_location, :location_range], [:overloads, :node_list], [:vertical_bar_locations, :location_range_list], [:dot3_location, :location_range]], false],
67
+ [:node, "RBS::AST::Ruby::Annotations::ModuleAliasAnnotation", true, nil, [[:prefix_location, :location_range], [:keyword_location, :location_range], [:type_name, :node], [:type_name_location, :location_range]], false],
68
+ [:node, "RBS::AST::Ruby::Annotations::ModuleSelfAnnotation", true, nil, [[:prefix_location, :location_range], [:keyword_location, :location_range], [:colon_location, :location_range], [:name, :node], [:args, :node_list], [:open_bracket_location, :location_range], [:close_bracket_location, :location_range], [:args_comma_locations, :location_range_list], [:comment_location, :location_range]], false],
69
+ [:node, "RBS::AST::Ruby::Annotations::NodeTypeAssertion", true, nil, [[:prefix_location, :location_range], [:type, :node]], false],
70
+ [:node, "RBS::AST::Ruby::Annotations::ParamTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:name_location, :location_range], [:colon_location, :location_range], [:param_type, :node], [:comment_location, :location_range]], false],
71
+ [:node, "RBS::AST::Ruby::Annotations::ReturnTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:return_location, :location_range], [:colon_location, :location_range], [:return_type, :node], [:comment_location, :location_range]], false],
72
+ [:node, "RBS::AST::Ruby::Annotations::SkipAnnotation", true, nil, [[:prefix_location, :location_range], [:skip_location, :location_range], [:comment_location, :location_range]], false],
73
+ [:node, "RBS::AST::Ruby::Annotations::SplatParamTypeAnnotation", true, nil, [[:prefix_location, :location_range], [:star_location, :location_range], [:name_location, :location_range], [:colon_location, :location_range], [:param_type, :node], [:comment_location, :location_range]], false],
74
+ [:node, "RBS::AST::Ruby::Annotations::TypeApplicationAnnotation", true, nil, [[:prefix_location, :location_range], [:type_args, :node_list], [:close_bracket_location, :location_range], [:comma_locations, :location_range_list]], false],
75
+ [:string_value],
76
+ [:node, "RBS::AST::TypeParam", true, [[:name, true], [:variance, false], [:unchecked, false], [:upper_bound, false], [:lower_bound, false], [:default, false]], [[:name, :node], [:variance, [:enum, [:invariant, :covariant, :contravariant]]], [:upper_bound, :node], [:lower_bound, :node], [:default_type, :node], [:unchecked, :bool]], false],
77
+ [:node, "RBS::MethodType", true, [[:type, true], [:type_params, false]], [[:type_params, :node_list], [:type, :node], [:block, :node]], true],
78
+ [:namespace],
79
+ [:signature],
80
+ [:type_name],
81
+ [:node, "RBS::Types::Alias", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
82
+ [:node, "RBS::Types::Bases::Any", true, nil, [[:todo, :bool]], false],
83
+ [:node, "RBS::Types::Bases::Bool", true, nil, nil, false],
84
+ [:node, "RBS::Types::Bases::Bottom", true, nil, nil, false],
85
+ [:node, "RBS::Types::Bases::Class", true, nil, nil, false],
86
+ [:node, "RBS::Types::Bases::Instance", true, nil, nil, false],
87
+ [:node, "RBS::Types::Bases::Nil", true, nil, nil, false],
88
+ [:node, "RBS::Types::Bases::Self", true, nil, nil, false],
89
+ [:node, "RBS::Types::Bases::Top", true, nil, nil, false],
90
+ [:node, "RBS::Types::Bases::Void", true, nil, nil, false],
91
+ [:node, "RBS::Types::Block", true, nil, [[:type, :node], [:required, :bool], [:self_type, :node]], false],
92
+ [:node, "RBS::Types::ClassInstance", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
93
+ [:node, "RBS::Types::ClassSingleton", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
94
+ [:node, "RBS::Types::Function", false, nil, [[:required_positionals, :node_list], [:optional_positionals, :node_list], [:rest_positionals, :node], [:trailing_positionals, :node_list], [:required_keywords, :hash], [:optional_keywords, :hash], [:rest_keywords, :node], [:return_type, :node]], false],
95
+ [:node, "RBS::Types::Function::Param", true, [[:name, false]], [[:type, :node], [:name, :node]], false],
96
+ [:node, "RBS::Types::Interface", true, [[:name, true], [:args, false]], [[:name, :node], [:args, :node_list]], false],
97
+ [:node, "RBS::Types::Intersection", true, nil, [[:types, :node_list]], false],
98
+ [:node, "RBS::Types::Literal", true, nil, [[:literal, :node]], false],
99
+ [:node, "RBS::Types::Optional", true, nil, [[:type, :node]], false],
100
+ [:node, "RBS::Types::Proc", true, nil, [[:type, :node], [:block, :node], [:self_type, :node]], false],
101
+ [:node, "RBS::Types::Record", true, nil, [[:all_fields, :hash]], false],
102
+ [:record_field],
103
+ [:node, "RBS::Types::Tuple", true, nil, [[:types, :node_list]], false],
104
+ [:node, "RBS::Types::Union", true, nil, [[:types, :node_list]], false],
105
+ [:node, "RBS::Types::UntypedFunction", false, nil, [[:return_type, :node]], false],
106
+ [:node, "RBS::Types::Variable", true, nil, [[:name, :node]], false],
107
+ ].freeze
108
+ end
109
+ end
110
+ end
data/lib/rbs.rb CHANGED
@@ -4,7 +4,11 @@ require "rbs/version"
4
4
 
5
5
  require "set"
6
6
  require "json"
7
- require "pathname" unless defined?(Pathname)
7
+ # Always require pathname: `Pathname()` (Kernel#Pathname) is only defined once
8
+ # pathname is loaded. Guarding on `defined?(Pathname)` is wrong because another
9
+ # library (e.g. Bundler) can define the Pathname constant without that method,
10
+ # which left RBS::EnvironmentLoader's `Pathname(...)` undefined on JRuby.
11
+ require "pathname"
8
12
  require "pp"
9
13
  require "logger"
10
14
  require "tsort"
@@ -69,7 +73,14 @@ require "rbs/type_alias_dependency"
69
73
  require "rbs/type_alias_regularity"
70
74
  require "rbs/collection"
71
75
 
72
- require "rbs_extension"
76
+ if RUBY_ENGINE == "jruby"
77
+ # JRuby cannot load the MRI C extension. Run the parser in WebAssembly and
78
+ # provide pure-Ruby implementations of RBS::Location and RBS::Parser instead.
79
+ require "rbs/wasm/location"
80
+ require "rbs/wasm/parser"
81
+ else
82
+ require "rbs_extension"
83
+ end
73
84
  require "rbs/parser_aux"
74
85
  require "rbs/location_aux"
75
86
 
data/lib/rbs_jars.rb ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the file jar-dependencies generates from the `jar` requirements in
4
+ # rbs.gemspec, kept with hand edits:
5
+ # 1. the `com.dylibso.chicory:runtime` require_jar line is corrected -- the
6
+ # generator mangles that artifact id to `jar` (it collides with a Maven
7
+ # scope keyword), which breaks loading;
8
+ # 2. the "# this is a generated file" marker is dropped so jar-dependencies
9
+ # does not regenerate (and re-break) this file at gem install;
10
+ # 3. a frozen_string_literal magic comment is added (rubocop).
11
+ # `rake wasm:install_jars` downloads the jars into ~/.m2; to refresh the list
12
+ # after a version bump, regenerate the file and re-apply these edits.
13
+ begin
14
+ require 'jar_dependencies'
15
+ rescue LoadError
16
+ require 'com/dylibso/chicory/compiler/1.7.5/compiler-1.7.5.jar'
17
+ require 'com/dylibso/chicory/runtime/1.7.5/runtime-1.7.5.jar'
18
+ require 'com/dylibso/chicory/wasm/1.7.5/wasm-1.7.5.jar'
19
+ require 'org/ow2/asm/asm/9.9.1/asm-9.9.1.jar'
20
+ require 'org/ow2/asm/asm-commons/9.9.1/asm-commons-9.9.1.jar'
21
+ require 'org/ow2/asm/asm-tree/9.9.1/asm-tree-9.9.1.jar'
22
+ require 'org/ow2/asm/asm-util/9.9.1/asm-util-9.9.1.jar'
23
+ require 'org/ow2/asm/asm-analysis/9.9.1/asm-analysis-9.9.1.jar'
24
+ require 'com/dylibso/chicory/wasi/1.7.5/wasi-1.7.5.jar'
25
+ require 'com/dylibso/chicory/log/1.7.5/log-1.7.5.jar'
26
+ end
27
+
28
+ if defined? Jars
29
+ require_jar 'com.dylibso.chicory', 'compiler', '1.7.5'
30
+ require_jar 'com.dylibso.chicory', 'runtime', '1.7.5'
31
+ require_jar 'com.dylibso.chicory', 'wasm', '1.7.5'
32
+ require_jar 'org.ow2.asm', 'asm', '9.9.1'
33
+ require_jar 'org.ow2.asm', 'asm-commons', '9.9.1'
34
+ require_jar 'org.ow2.asm', 'asm-tree', '9.9.1'
35
+ require_jar 'org.ow2.asm', 'asm-util', '9.9.1'
36
+ require_jar 'org.ow2.asm', 'asm-analysis', '9.9.1'
37
+ require_jar 'com.dylibso.chicory', 'wasi', '1.7.5'
38
+ require_jar 'com.dylibso.chicory', 'log', '1.7.5'
39
+ end
@@ -14,6 +14,11 @@ module RBS
14
14
  end
15
15
 
16
16
  def scan
17
+ Kernel.warn(
18
+ "The RBS RDoc parser plugin is deprecated and will be removed from RBS. " \
19
+ "RDoc 8.0 provides RBS parsing directly."
20
+ )
21
+
17
22
  _, _, decls = ::RBS::Parser.parse_signature(@content)
18
23
  decls.each do |decl|
19
24
  parse_member(decl: decl, context: @top_level)
data/rbs.gemspec CHANGED
@@ -30,12 +30,42 @@ Gem::Specification.new do |spec|
30
30
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
31
  `git ls-files -z`.split("\x0").reject do |f|
32
32
  [
33
- %r{^(test|spec|features|bin|steep|benchmark|templates|rust)/},
33
+ %r{^(test|spec|features|bin|steep|benchmark|templates|rust|\.vscode)/},
34
34
  /Gemfile/,
35
35
  ].any? {|r| f.match(r) }
36
36
  end
37
37
  end
38
- spec.extensions = %w{ext/rbs_extension/extconf.rb}
38
+
39
+ # JRuby cannot load the MRI C extension. On JRuby (and in the `java` platform
40
+ # gem, built with RBS_PLATFORM=java) RBS runs the WebAssembly-backed parser, so
41
+ # ship the prebuilt parser (built by `rake wasm:build`) and skip the C
42
+ # extension. The Chicory/ASM jars the runtime needs are NOT shipped in the gem:
43
+ # they are declared as `jar-dependencies` requirements below and fetched from
44
+ # Maven Central at install time (see lib/rbs/wasm/jars.rb).
45
+ building_java_gem = ENV["RBS_PLATFORM"] == "java"
46
+ on_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
47
+
48
+ if building_java_gem || on_jruby
49
+ # Only stamp the platform when building the release gem; leave it unset for
50
+ # local development on JRuby so it still matches a `ruby` platform lockfile.
51
+ spec.platform = "java" if building_java_gem
52
+ # rbs_parser.wasm is a build artifact (not tracked in git), so add it
53
+ # explicitly. lib/rbs_jars.rb is committed, so git ls-files already has it.
54
+ spec.files += Dir.chdir(File.expand_path('..', __FILE__)) do
55
+ Dir.glob("lib/rbs/wasm/rbs_parser.wasm")
56
+ end
57
+
58
+ # jar-dependencies (bundled with JRuby) downloads these jars from Maven when
59
+ # the gem is installed, keeping the gem small and avoiding conflicting copies.
60
+ # Only the top-level artifacts are declared; Maven resolves the rest (runtime,
61
+ # wasm, asm, ...) transitively. lib/rbs_jars.rb require_jars the full resolved
62
+ # set at load time.
63
+ spec.add_dependency "jar-dependencies", ">= 0.1.7"
64
+ spec.requirements << "jar com.dylibso.chicory:compiler, 1.7.5"
65
+ spec.requirements << "jar com.dylibso.chicory:wasi, 1.7.5"
66
+ else
67
+ spec.extensions = %w{ext/rbs_extension/extconf.rb}
68
+ end
39
69
 
40
70
  if false
41
71
  spec.required_ruby_version = ">= 3.4"
@@ -84,10 +84,15 @@ module RBS
84
84
 
85
85
  attr_reader name: Symbol
86
86
  attr_reader node: Prism::DefNode
87
+ attr_reader kind: :instance | :singleton
87
88
  attr_reader method_type: MethodTypeAnnotation
88
89
  attr_reader leading_comment: CommentBlock?
89
90
 
90
- def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation, CommentBlock? leading_comment) -> void
91
+ def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation, CommentBlock? leading_comment, ?kind: :instance | :singleton) -> void
92
+
93
+ def singleton?: () -> bool
94
+
95
+ def instance?: () -> bool
91
96
 
92
97
  def location: () -> Location
93
98
 
data/sig/buffer.rbs CHANGED
@@ -60,6 +60,19 @@ module RBS
60
60
  def rbs_location: (Prism::Location) -> Location
61
61
  | (Prism::Location, Prism::Location) -> Location
62
62
 
63
+ # Translate a byte offset (into the top buffer's source) to a character offset.
64
+ #
65
+ # Resolution is delegated to the top buffer, which keeps a sparse cache of
66
+ # resolved (byte, char) pairs so successive calls scan only the delta from the
67
+ # nearest cached pair. Amortizes to O(content_size) across all calls; a single
68
+ # call is one byteslice + length.
69
+ #
70
+ def character_offset: (Integer byte_offset) -> Integer
71
+
72
+ # Sparse cache backing `#character_offset`: a pair `[byte_keys, char_values]`
73
+ # kept in ascending byte order to support binary search.
74
+ @character_offset_cache: [Array[Integer], Array[Integer]]?
75
+
63
76
  # Construct a buffer from substrings of this buffer.
64
77
  #
65
78
  # The returned buffer contains lines from given ranges.
@@ -75,7 +88,12 @@ module RBS
75
88
  # buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline
76
89
  # ```
77
90
  #
78
- %a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer
91
+ # `byte_lines_hint:` is an optional performance hint: byte ranges corresponding
92
+ # to `lines:`. When provided, slicing uses `byteslice` (O(slice_size) per line)
93
+ # instead of `content[char_range]`, which on a multi-byte string is O(content_size)
94
+ # per call. Result is identical either way.
95
+ #
96
+ %a{pure} def sub_buffer: (lines: Array[Range[Integer]], ?byte_lines_hint: Array[Range[Integer]]?) -> Buffer
79
97
 
80
98
  %a{pure} def parent_buffer: () -> Buffer?
81
99
 
data/sig/namespace.rbs CHANGED
@@ -40,10 +40,30 @@ module RBS
40
40
 
41
41
  @parent: Namespace?
42
42
 
43
+ @hash: Integer?
44
+
43
45
  self.@root: Namespace?
44
46
 
45
47
  self.@empty: Namespace?
46
48
 
49
+ self.@intern_mutex: Mutex
50
+
51
+ # Per-`absolute` flag tries of nested Hashes keyed on path Symbols,
52
+ # with the cached Namespace stored under the `INTERN_LEAF` sentinel
53
+ # at each path's terminal node.
54
+ self.@intern_trie_absolute: Hash[Symbol | Module, untyped]
55
+
56
+ self.@intern_trie_relative: Hash[Symbol | Module, untyped]
57
+
58
+ INTERN_LEAF: Module
59
+
60
+ # Returns an interned `Namespace` instance.
61
+ #
62
+ # Subsequent calls with structurally equal `path` and `absolute` arguments
63
+ # return the same object. The internal `path` array is duplicated and
64
+ # frozen before being cached.
65
+ def self.[]: (Array[Symbol] path, boolish absolute) -> Namespace
66
+
47
67
  # Returns new _empty_ namespace.
48
68
  def self.empty: () -> Namespace
49
69
 
data/sig/parser.rbs CHANGED
@@ -140,6 +140,16 @@ module RBS
140
140
 
141
141
  def self._parse_signature: (Buffer, Integer start_pos, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
142
142
 
143
+ # Parse and serialize the result to the binary format consumed by
144
+ # RBS::WASM::Deserializer (see ext/rbs_extension/main.c and
145
+ # docs/wasm_serialization.md). The `_to_bytes` variants exist so the
146
+ # round-trip can be exercised on CRuby.
147
+ def self._parse_type_to_bytes: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof, bool void_allowed, bool self_allowed, bool classish_allowed) -> String?
148
+
149
+ def self._parse_method_type_to_bytes: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof) -> String?
150
+
151
+ def self._parse_signature_to_bytes: (Buffer, Integer start_pos, Integer end_pos) -> String
152
+
143
153
  def self._parse_type_params: (Buffer, Integer start_pos, Integer end_pos, bool module_type_params) -> Array[AST::TypeParam]
144
154
 
145
155
  def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
@@ -2,7 +2,17 @@ module RBS
2
2
  module Prototype
3
3
  class RBI
4
4
  include Helpers
5
-
5
+
6
+ type visibility = :private | :protected | :public
7
+
8
+ class Context
9
+ attr_accessor singleton: bool
10
+
11
+ attr_accessor visibility: visibility
12
+
13
+ def initialize: (singleton: bool, visibility: visibility) -> void
14
+ end
15
+
6
16
  attr_reader decls: Array[AST::Declarations::t]
7
17
 
8
18
  type module_decl = AST::Declarations::Class | AST::Declarations::Module
@@ -13,13 +23,15 @@ module RBS
13
23
  # Last subsequent `sig` calls
14
24
  attr_reader last_sig: Array[RubyVM::AbstractSyntaxTree::Node]?
15
25
 
26
+ @contexts: Array[Context]
27
+
28
+ @emitted_visibility: Hash[Integer, visibility]
29
+
16
30
  def initialize: () -> void
17
31
 
18
32
  def parse: (String) -> void
19
33
 
20
- def nested_name: (RubyVM::AbstractSyntaxTree::Node name) -> TypeName
21
-
22
- def current_namespace: () -> Namespace
34
+ def append_decl: (AST::Declarations::t decl) -> void
23
35
 
24
36
  def push_class: (
25
37
  RubyVM::AbstractSyntaxTree::Node name,
@@ -35,6 +47,17 @@ module RBS
35
47
  # The inner most module/class definition, raises on toplevel
36
48
  def current_module!: () -> module_decl
37
49
 
50
+ def current_context: () -> Context?
51
+
52
+ def current_context!: () -> Context
53
+
54
+ # Visibility of a member, given as `private def ...` in RBS
55
+ #
56
+ # Returns `nil` for members in a visibility _section_, which `sync_visibility` emits instead.
57
+ def member_visibility: (Context) -> AST::Members::visibility?
58
+
59
+ def sync_visibility: (visibility) -> void
60
+
38
61
  # Put a `sig` call to current list.
39
62
  def push_sig: (RubyVM::AbstractSyntaxTree::Node node) -> void
40
63
 
@@ -45,6 +68,12 @@ module RBS
45
68
 
46
69
  def process: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment], ?outer: Array[RubyVM::AbstractSyntaxTree::Node]) -> void
47
70
 
71
+ def process_visibility: (RubyVM::AbstractSyntaxTree::Node node, outer: Array[RubyVM::AbstractSyntaxTree::Node], comments: Hash[Integer, AST::Comment]) -> void
72
+
73
+ def process_attribute: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment]) -> void
74
+
75
+ def attribute_type: (:attr_reader | :attr_writer | :attr_accessor kind, Array[RubyVM::AbstractSyntaxTree::Node]? sigs) -> Types::t
76
+
48
77
  def method_type: (RubyVM::AbstractSyntaxTree::Node? args_node, RubyVM::AbstractSyntaxTree::Node? type_node, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType?
49
78
 
50
79
  def parse_params: (RubyVM::AbstractSyntaxTree::Node args_node, RubyVM::AbstractSyntaxTree::Node args, MethodType method_type, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType
@@ -6,8 +6,6 @@ module RBS
6
6
  # It just ignores included modules and super classes.
7
7
  #
8
8
  class TypeNameResolver
9
- type query = [TypeName, context]
10
-
11
9
  def initialize: (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> void
12
10
 
13
11
  def self.build: (Environment) -> instance
@@ -32,7 +30,7 @@ module RBS
32
30
 
33
31
  attr_reader aliases: Hash[TypeName, [TypeName, context]]
34
32
 
35
- attr_reader cache: Hash[query, TypeName?]
33
+ attr_reader cache: Hash[context, Hash[TypeName, TypeName?]]
36
34
 
37
35
  # Returns the type name if it exists in `all_names` (normalized)
38
36
  #
@@ -42,7 +40,7 @@ module RBS
42
40
  #
43
41
  def aliased_name?: (TypeName) -> TypeName?
44
42
 
45
- def try_cache: (query) { () -> TypeName? } -> TypeName?
43
+ def try_cache: (TypeName, context) { () -> TypeName? } -> TypeName?
46
44
 
47
45
  # Translates the head module name in the context and returns an absolute type name
48
46
  #
data/sig/typename.rbs CHANGED
@@ -28,6 +28,21 @@ module RBS
28
28
  #
29
29
  def initialize: (namespace: Namespace, name: Symbol) -> void
30
30
 
31
+ @hash: Integer?
32
+
33
+ self.@intern_mutex: Mutex
34
+
35
+ # Two-level Hash keyed by canonical Namespace identity (outer uses
36
+ # `compare_by_identity`) and name Symbol.
37
+ self.@intern_cache: Hash[Namespace, Hash[Symbol, TypeName]]
38
+
39
+ # Returns an interned `TypeName` instance.
40
+ #
41
+ # The given `namespace` is canonicalized so cached instances always hold an
42
+ # interned namespace. Subsequent calls with structurally equal arguments
43
+ # return the same object.
44
+ def self.[]: (Namespace namespace, Symbol name) -> TypeName
45
+
31
46
  def ==: (untyped other) -> bool
32
47
 
33
48
  def hash: () -> Integer
@@ -179,6 +179,10 @@ module RBS
179
179
  #
180
180
  def assert_type: (String | Types::t value_type, untyped value) -> void
181
181
 
182
+ # Asserts if RBS definition declares given `method_name` with `visibility`
183
+ #
184
+ def assert_visibility: (:private | :public visibility, Symbol method_name) -> void
185
+
182
186
  # Allow non _simple-type_ method types given to `assert_send_type` and `refute_send_type`
183
187
  #
184
188
  # ```ruby
@@ -0,0 +1,66 @@
1
+ module RBS
2
+ module WASM
3
+ # Rebuilds RBS::AST objects from the binary buffer produced by
4
+ # `rbs_serialize_node` (src/serialize.c), driven by SerializationSchema.
5
+ class Deserializer
6
+ @bytes: String
7
+
8
+ @buffer: Buffer
9
+
10
+ @encoding: Encoding
11
+
12
+ @pos: Integer
13
+
14
+ @class_cache: Hash[String, untyped]
15
+
16
+ # Deserialize a buffer produced for a whole signature, returning
17
+ # `[directives, declarations]` to match RBS::Parser._parse_signature.
18
+ def self.deserialize: (String bytes, Buffer buffer) -> untyped
19
+
20
+ # Deserialize a bare node list (RBS::Parser._parse_type_params).
21
+ def self.deserialize_node_list: (String bytes, Buffer buffer) -> Array[untyped]
22
+
23
+ # Deserialize the token stream from rbs_wasm_lex (RBS::Parser._lex).
24
+ def self.deserialize_tokens: (String bytes, Buffer buffer) -> Array[[ Symbol, Location ]]
25
+
26
+ def initialize: (String bytes, Buffer buffer) -> void
27
+
28
+ # Reads the next node and returns the reconstructed Ruby value.
29
+ def read_node: () -> untyped
30
+
31
+ def read_node_list: () -> Array[untyped]
32
+
33
+ def read_tokens: () -> Array[[ Symbol, Location ]]
34
+
35
+ private
36
+
37
+ def read_struct: (Array[untyped] entry) -> untyped
38
+
39
+ def read_field: (untyped reader) -> untyped
40
+
41
+ def read_hash: () -> Hash[untyped, untyped]
42
+
43
+ def read_count: () -> Integer
44
+
45
+ def read_location: (Array[untyped]? loc_children) -> Location?
46
+
47
+ def read_location_value: () -> Location?
48
+
49
+ def read_location_value_list: () -> Array[Location?]
50
+
51
+ def read_attr_ivar_name: () -> (Symbol | false | nil)
52
+
53
+ def read_range: () -> [ Integer, Integer ]?
54
+
55
+ def read_u8: () -> Integer
56
+
57
+ def read_u32: () -> Integer
58
+
59
+ def read_i32: () -> Integer
60
+
61
+ def read_string: (Encoding encoding) -> String
62
+
63
+ def class_for: (String name) -> untyped
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ module RBS
2
+ module WASM
3
+ # Generated from config.yml. See `templates/lib/rbs/wasm/serialization_schema.rb.erb`.
4
+ module SerializationSchema
5
+ # The node tag used for interned symbols (`rbs_ast_symbol`).
6
+ SYMBOL_TAG: Integer
7
+
8
+ # Indexed by node tag. Each entry describes how to decode one node; see the
9
+ # generated file for the exact shape.
10
+ SCHEMA: Array[Array[untyped]?]
11
+ end
12
+ end
13
+ end