rbs 4.0.3 → 4.1.0.pre.2

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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +3 -0
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/jruby.yml +67 -0
  5. data/.github/workflows/milestone.yml +4 -1
  6. data/.github/workflows/ruby.yml +40 -0
  7. data/.github/workflows/rust.yml +3 -2
  8. data/.github/workflows/truffleruby.yml +54 -0
  9. data/.github/workflows/typecheck.yml +3 -0
  10. data/.github/workflows/wasm.yml +53 -0
  11. data/.github/workflows/windows.yml +3 -0
  12. data/.gitignore +7 -0
  13. data/CHANGELOG.md +0 -8
  14. data/README.md +3 -3
  15. data/Rakefile +118 -3
  16. data/Steepfile +7 -0
  17. data/config.yml +24 -0
  18. data/core/array.rbs +144 -144
  19. data/core/builtin.rbs +7 -6
  20. data/core/class.rbs +5 -3
  21. data/core/enumerable.rbs +109 -109
  22. data/core/enumerator/product.rbs +5 -5
  23. data/core/enumerator.rbs +28 -28
  24. data/core/file.rbs +24 -1018
  25. data/core/file_constants.rbs +463 -0
  26. data/core/file_stat.rbs +534 -0
  27. data/core/hash.rbs +117 -101
  28. data/core/integer.rbs +21 -58
  29. data/core/io.rbs +25 -7
  30. data/core/kernel.rbs +26 -11
  31. data/core/module.rbs +88 -74
  32. data/core/numeric.rbs +3 -0
  33. data/core/object_space/weak_key_map.rbs +7 -7
  34. data/core/range.rbs +23 -23
  35. data/core/rbs/ops.rbs +154 -0
  36. data/core/rbs/unnamed/argf.rbs +3 -3
  37. data/core/ruby_vm.rbs +40 -0
  38. data/core/set.rbs +3 -3
  39. data/core/struct.rbs +16 -16
  40. data/core/thread.rbs +6 -6
  41. data/docs/CONTRIBUTING.md +2 -1
  42. data/docs/inline.md +65 -7
  43. data/docs/rbs_by_example.md +20 -20
  44. data/docs/syntax.md +2 -2
  45. data/docs/wasm_serialization.md +80 -0
  46. data/ext/rbs_extension/ast_translation.c +1298 -956
  47. data/ext/rbs_extension/ast_translation.h +4 -0
  48. data/ext/rbs_extension/class_constants.c +2 -0
  49. data/ext/rbs_extension/class_constants.h +1 -0
  50. data/ext/rbs_extension/extconf.rb +1 -0
  51. data/ext/rbs_extension/main.c +139 -4
  52. data/include/rbs/ast.h +323 -298
  53. data/include/rbs/defines.h +13 -0
  54. data/include/rbs/lexer.h +1 -0
  55. data/include/rbs/serialize.h +39 -0
  56. data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
  57. data/lib/rbs/ast/ruby/annotations.rb +42 -0
  58. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  59. data/lib/rbs/ast/ruby/declarations.rb +11 -1
  60. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  61. data/lib/rbs/ast/ruby/members.rb +40 -1
  62. data/lib/rbs/buffer.rb +48 -11
  63. data/lib/rbs/cli.rb +3 -5
  64. data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
  65. data/lib/rbs/collection/sources/git.rb +6 -0
  66. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  67. data/lib/rbs/environment.rb +10 -3
  68. data/lib/rbs/inline_parser.rb +54 -28
  69. data/lib/rbs/namespace.rb +47 -11
  70. data/lib/rbs/prototype/runtime.rb +2 -0
  71. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  72. data/lib/rbs/rewriter.rb +70 -0
  73. data/lib/rbs/test/type_check.rb +6 -1
  74. data/lib/rbs/type_name.rb +33 -13
  75. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  76. data/lib/rbs/version.rb +1 -1
  77. data/lib/rbs/wasm/deserializer.rb +213 -0
  78. data/lib/rbs/wasm/location.rb +61 -0
  79. data/lib/rbs/wasm/parser.rb +137 -0
  80. data/lib/rbs/wasm/runtime.rb +217 -0
  81. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  82. data/lib/rbs.rb +14 -2
  83. data/rbs.gemspec +19 -2
  84. data/sig/annotate/rdoc_annotater.rbs +12 -9
  85. data/sig/ast/ruby/annotations.rbs +49 -0
  86. data/sig/ast/ruby/members.rbs +21 -1
  87. data/sig/buffer.rbs +19 -1
  88. data/sig/collection/config/lockfile_generator.rbs +2 -0
  89. data/sig/inline_parser.rbs +2 -0
  90. data/sig/manifest.yaml +0 -1
  91. data/sig/namespace.rbs +20 -0
  92. data/sig/parser.rbs +10 -0
  93. data/sig/resolver/type_name_resolver.rbs +2 -4
  94. data/sig/rewriter.rbs +45 -0
  95. data/sig/typename.rbs +15 -0
  96. data/sig/unit_test/type_assertions.rbs +4 -0
  97. data/sig/wasm/deserializer.rbs +66 -0
  98. data/sig/wasm/serialization_schema.rbs +13 -0
  99. data/src/ast.c +186 -162
  100. data/src/lexer.c +137 -114
  101. data/src/lexer.re +1 -0
  102. data/src/lexstate.c +6 -1
  103. data/src/parser.c +55 -5
  104. data/src/serialize.c +958 -0
  105. data/src/util/rbs_allocator.c +1 -4
  106. data/stdlib/abbrev/0/array.rbs +1 -1
  107. data/stdlib/csv/0/csv.rbs +5 -5
  108. data/stdlib/digest/0/digest.rbs +1 -1
  109. data/stdlib/etc/0/etc.rbs +18 -4
  110. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/openssl/0/openssl.rbs +7 -7
  113. data/stdlib/resolv/0/resolv.rbs +1 -1
  114. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  115. data/stdlib/stringio/0/stringio.rbs +32 -10
  116. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  117. data/stdlib/tsort/0/cyclic.rbs +1 -1
  118. data/stdlib/tsort/0/interfaces.rbs +8 -8
  119. data/stdlib/tsort/0/tsort.rbs +9 -9
  120. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  121. data/wasm/README.md +59 -0
  122. data/wasm/rbs_wasm.c +411 -0
  123. metadata +23 -5
  124. data/.vscode/extensions.json +0 -5
  125. data/.vscode/settings.json +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77f310d0293781c4da3d3835ee34be5b310dc4aace7b75db580060432f5dd10c
4
- data.tar.gz: 8d982db360beced794afa05c156c40db8b368f7b2d0b0180ad61434d3c1eb0a9
3
+ metadata.gz: 125952c7d052ff2adaa683375a5e5079c4019f43ea9bc86546a4efd9eed2ed0e
4
+ data.tar.gz: 8df793a9e6419ec7d4d137fec60811e0eadc68e8ebe6359a149cad43deb26f6e
5
5
  SHA512:
6
- metadata.gz: 87d0a52295c6167fb791c2ff843dee5a9b7c1d4cc9d13fe5ccf8c12abcc7ed507497021e691dd0cd1a134ff886c9ba29461f03f2a26fc3402af1c78bc36ec62f
7
- data.tar.gz: 40381f1988f06a3262de9367042ad0e04864f7c9f0a1556f30dc01003874db8018a77b10c613e090993738d3787861ccb84417631a4cc57c3998ca99c831eb8b
6
+ metadata.gz: 254fc00d7c4bf3910796b4af6b573cf0be978b68a1db193a703a90e44e18df53b7399611d8acd40bff853e2c21fffd83468815fa24f71bdb36255b5cf164907a
7
+ data.tar.gz: 0b4bf3195dede912a3eee97ea770e9c99b907eea6e7e28b5492818ee64d6128dc9d0262bab70d127c2e946a3f7f77536fa4a3fa884ea576f746231abcbfd9458
@@ -7,6 +7,9 @@ on:
7
7
  pull_request: {}
8
8
  merge_group: {}
9
9
 
10
+ permissions:
11
+ contents: read
12
+
10
13
  jobs:
11
14
  format-check:
12
15
  runs-on: ubuntu-latest
@@ -14,7 +14,7 @@ jobs:
14
14
  if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
15
15
  steps:
16
16
  - name: Dependabot metadata
17
- uses: dependabot/fetch-metadata@ffa630c65fa7e0ecfa0625b5ceda64399aea1b36 # v3.0.0
17
+ uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
18
18
  id: metadata
19
19
  - name: Checkout repository
20
20
  uses: actions/checkout@v6
@@ -0,0 +1,67 @@
1
+ name: JRuby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ paths:
9
+ - ".github/workflows/jruby.yml"
10
+ - "include/**"
11
+ - "src/**"
12
+ - "wasm/**"
13
+ - "lib/**"
14
+ - "sig/**"
15
+ - "core/**"
16
+ - "stdlib/**"
17
+ - "test/**"
18
+ - "Rakefile"
19
+ - "rbs.gemspec"
20
+
21
+ permissions:
22
+ contents: read
23
+
24
+ env:
25
+ # Keep in sync with .github/workflows/wasm.yml.
26
+ WASI_SDK_VERSION: "33"
27
+ WASI_SDK_RELEASE: "33.0"
28
+
29
+ jobs:
30
+ test:
31
+ name: jruby
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v6
35
+ - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
36
+
37
+ # Build the .wasm and fetch the Chicory jars with CRuby + the WASI SDK,
38
+ # then run RBS itself on JRuby against those artifacts.
39
+ - name: Set up Ruby (to assemble the WebAssembly runtime)
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ruby
43
+ bundler: none
44
+ - name: Update rubygems & bundler
45
+ run: gem update --system
46
+ - name: Install gems
47
+ run: |
48
+ bundle config set --local without libs:profilers
49
+ bundle install --jobs 4 --retry 3
50
+ - name: Install the WASI SDK
51
+ run: |
52
+ url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_RELEASE}-x86_64-linux.tar.gz"
53
+ mkdir -p "$HOME/wasi-sdk"
54
+ curl -sSL "$url" | tar xz --strip-components=1 -C "$HOME/wasi-sdk"
55
+ echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> "$GITHUB_ENV"
56
+ - name: Assemble the JRuby runtime (rbs_parser.wasm + Chicory jars)
57
+ run: bundle exec rake wasm:jruby_setup
58
+
59
+ - name: Set up JRuby
60
+ uses: ruby/setup-ruby@v1
61
+ with:
62
+ ruby-version: jruby
63
+ bundler: none
64
+ - name: Install runtime and test gems
65
+ run: gem install prism rake rake-compiler test-unit rdoc rspec minitest json-schema pry --no-document
66
+ - name: Run the test suite on JRuby
67
+ run: jruby -S rake test
@@ -4,6 +4,9 @@ on:
4
4
  pull_request:
5
5
  types: [opened, edited, labeled, unlabeled, milestoned, demilestoned, synchronize]
6
6
 
7
+ permissions:
8
+ contents: read
9
+
7
10
  jobs:
8
11
  check:
9
12
  runs-on: ubuntu-latest
@@ -27,7 +30,7 @@ jobs:
27
30
  echo "RBS::VERSION = $version (major=$major, minor=$minor, patch=$patch)"
28
31
 
29
32
  - name: Check milestone
30
- uses: actions/github-script@v8
33
+ uses: actions/github-script@v9
31
34
  with:
32
35
  script: |
33
36
  const pr = context.payload.pull_request;
@@ -7,6 +7,9 @@ on:
7
7
  pull_request: {}
8
8
  merge_group: {}
9
9
 
10
+ permissions:
11
+ contents: read
12
+
10
13
  jobs:
11
14
  test:
12
15
  runs-on: "ubuntu-latest"
@@ -116,3 +119,40 @@ jobs:
116
119
  run: |
117
120
  bin/setup
118
121
  - run: bundle exec rake clean compile_c99
122
+
123
+ clang_compile:
124
+ runs-on: macos-latest
125
+ strategy:
126
+ fail-fast: false
127
+ matrix:
128
+ ruby: ['4.0', head]
129
+ steps:
130
+ - uses: actions/checkout@v6
131
+ - name: Install dependencies
132
+ run: |
133
+ brew install ruby-build
134
+ - uses: ruby/setup-ruby@v1
135
+ with:
136
+ ruby-version: ${{ matrix.ruby }}
137
+ bundler: none
138
+ - name: Set working directory as safe
139
+ run: git config --global --add safe.directory $(pwd)
140
+ - name: Update rubygems & bundler
141
+ run: |
142
+ ruby -v
143
+ gem update --system
144
+ - name: install erb
145
+ run: gem install erb
146
+ - name: clang version
147
+ run: clang --version
148
+ - name: bundle config set force_ruby_platform true if head
149
+ if: ${{ contains(matrix.ruby, 'head') }}
150
+ run: |
151
+ bundle config set force_ruby_platform true
152
+ - name: Ignore Gemfile.lock's BUNDLED WITH on ruby-head
153
+ if: ${{ contains(matrix.ruby, 'head') }}
154
+ run: bundle config set --local version system
155
+ - name: bin/setup
156
+ run: |
157
+ bin/setup
158
+ - run: bundle exec rake clean compile
@@ -8,12 +8,13 @@ on:
8
8
  paths:
9
9
  - ".github/workflows/rust.yml"
10
10
  - "rust/**"
11
- - "include/**"
12
- - "src/**"
13
11
 
14
12
  env:
15
13
  RUSTFLAGS: "-D warnings"
16
14
 
15
+ permissions:
16
+ contents: read
17
+
17
18
  jobs:
18
19
  test:
19
20
  name: cargo:test
@@ -0,0 +1,54 @@
1
+ name: TruffleRuby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request: {}
8
+ merge_group: {}
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: "ubuntu-latest"
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: ['truffleruby']
20
+ job:
21
+ - test
22
+ env:
23
+ RANDOMIZE_STDLIB_TEST_ORDER: "true"
24
+ # TruffleRuby warns and falls back to US-ASCII unless the locale is UTF-8.
25
+ LANG: "en_US.UTF-8"
26
+ steps:
27
+ - uses: actions/checkout@v6
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ bundler: none
32
+ - name: Set working directory as safe
33
+ run: git config --global --add safe.directory $(pwd)
34
+ - name: Install dependencies
35
+ run: |
36
+ sudo apt-get update
37
+ sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool python3
38
+ - name: Update rubygems & bundler
39
+ run: |
40
+ ruby -v
41
+ gem update --system
42
+ - name: install erb
43
+ run: gem install erb
44
+ - name: bundle config
45
+ run: |
46
+ # Profilers and the typecheck tooling are not needed for the smoke test,
47
+ # and some of them do not support TruffleRuby.
48
+ bundle config set --local without 'profilers typecheck_test'
49
+ - name: bin/setup
50
+ run: |
51
+ bin/setup
52
+ - name: Run test
53
+ run: |
54
+ bundle exec rake ${{ matrix.job }}
@@ -7,6 +7,9 @@ on:
7
7
  pull_request: {}
8
8
  merge_group: {}
9
9
 
10
+ permissions:
11
+ contents: read
12
+
10
13
  jobs:
11
14
  steep:
12
15
  runs-on: "ubuntu-latest"
@@ -0,0 +1,53 @@
1
+ name: WebAssembly
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ paths:
9
+ - ".github/workflows/wasm.yml"
10
+ - "Rakefile"
11
+ - "include/**"
12
+ - "src/**"
13
+ - "wasm/**"
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ env:
19
+ # Pinned so the smoke test is reproducible. Bump together when upgrading.
20
+ WASI_SDK_VERSION: "33"
21
+ WASI_SDK_RELEASE: "33.0"
22
+ WASMTIME_VERSION: "v45.0.2"
23
+
24
+ jobs:
25
+ build:
26
+ name: wasm:check
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - uses: actions/checkout@v6
30
+ - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
31
+ - name: Set up Ruby
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ruby
35
+ bundler: none
36
+ - name: Update rubygems & bundler
37
+ run: gem update --system
38
+ - name: Install gems
39
+ run: |
40
+ bundle config set --local without libs:profilers
41
+ bundle install --jobs 4 --retry 3
42
+ - name: Install the WASI SDK
43
+ run: |
44
+ url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_RELEASE}-x86_64-linux.tar.gz"
45
+ mkdir -p "$HOME/wasi-sdk"
46
+ curl -sSL "$url" | tar xz --strip-components=1 -C "$HOME/wasi-sdk"
47
+ echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> "$GITHUB_ENV"
48
+ - name: Install wasmtime
49
+ uses: bytecodealliance/actions/wasmtime/setup@v1
50
+ with:
51
+ version: ${{ env.WASMTIME_VERSION }}
52
+ - name: Build and smoke-test the WebAssembly module
53
+ run: bundle exec rake wasm:check
@@ -7,6 +7,9 @@ on:
7
7
  pull_request: {}
8
8
  merge_group: {}
9
9
 
10
+ permissions:
11
+ contents: read
12
+
10
13
  jobs:
11
14
  compile:
12
15
  runs-on: "windows-latest"
data/.gitignore CHANGED
@@ -29,3 +29,10 @@ ext/rbs_extension/.cache
29
29
  # Rust crate vendored RBS source (managed by rake rust:rbs:sync or rust:rbs:symlink)
30
30
  rust/ruby-rbs-sys/vendor/rbs/
31
31
  rust/ruby-rbs/vendor/rbs/
32
+
33
+ # Compiled WebAssembly module (built by rake wasm:build)
34
+ wasm/*.wasm
35
+
36
+ # JRuby runtime artifacts (assembled by rake wasm:jruby_setup, bundled in the JRuby gem)
37
+ lib/rbs/wasm/*.wasm
38
+ lib/rbs/wasm/jars/
data/CHANGELOG.md CHANGED
@@ -1,13 +1,5 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 4.0.3 (2026-06-18)
4
-
5
- ### Miscellaneous
6
-
7
- * Fix Ruby CI failure with compressed `Zlib::GzipReader` test fixtures. ([#3005](https://github.com/ruby/rbs/pull/3005))
8
- * Fix flaky `DirSingletonTest#test_fchdir` and `DirSingletonTest#test_for_fd` under aggressive GC. ([#3005](https://github.com/ruby/rbs/pull/3005))
9
- * Fix Ruby head CI failure caused by the lockfile-pinned Bundler version. ([#3005](https://github.com/ruby/rbs/pull/3005))
10
-
11
3
  ## 4.0.2 (2026-03-25)
12
4
 
13
5
  ### Library changes
data/README.md CHANGED
@@ -54,8 +54,8 @@ end
54
54
 
55
55
  ## The Target Version
56
56
 
57
- * The standard library signatures targets the latest release of Ruby. (`3.2` as of 2023.)
58
- * The library code targets non-EOL versions of Ruby. (`>= 3.0` as of 2023.)
57
+ * The standard library signatures targets the [latest release of Ruby](https://www.ruby-lang.org/en/downloads/branches/). (`4.0` as of 2026.)
58
+ * The library code targets [non-EOL versions of Ruby](https://www.ruby-lang.org/en/downloads/branches/). (`>= 3.3` as of 2026.)
59
59
 
60
60
  ## Installation
61
61
 
@@ -122,7 +122,7 @@ This is only a starting point, and you should edit the output to match your sign
122
122
 
123
123
  - `rb` generates from just the available Ruby code
124
124
  - `rbi` generates from Sorbet RBI
125
- - `runtime` generates from runtime API
125
+ - `runtime` generates from runtime API (**deprecated**; see [#2841](https://github.com/ruby/rbs/issues/2841))
126
126
 
127
127
  ## Library
128
128
 
data/Rakefile CHANGED
@@ -33,7 +33,14 @@ test_config = lambda do |t|
33
33
  end
34
34
  end
35
35
 
36
- Rake::TestTask.new(test: :compile, &test_config)
36
+ if RUBY_ENGINE == "jruby"
37
+ # JRuby runs the parser in WebAssembly instead of the C extension, so there is
38
+ # nothing to compile. The wasm runtime must be assembled first with
39
+ # `rake wasm:jruby_setup` (which needs CRuby + the WASI SDK).
40
+ Rake::TestTask.new(:test, &test_config)
41
+ else
42
+ Rake::TestTask.new(test: :compile, &test_config)
43
+ end
37
44
 
38
45
  multitask :default => [:test, :stdlib_test, :typecheck_test, :rubocop, :validate, :test_doc]
39
46
 
@@ -160,6 +167,10 @@ task :templates do
160
167
  sh "#{ruby} templates/template.rb include/rbs/ast.h"
161
168
  sh "#{ruby} templates/template.rb src/ast.c"
162
169
 
170
+ sh "#{ruby} templates/template.rb include/rbs/serialize.h"
171
+ sh "#{ruby} templates/template.rb src/serialize.c"
172
+ sh "#{ruby} templates/template.rb lib/rbs/wasm/serialization_schema.rb"
173
+
163
174
  # Format the generated files
164
175
  Rake::Task["format:c"].invoke
165
176
  end
@@ -206,8 +217,8 @@ task :validate => :compile do
206
217
  args = ["-r", lib]
207
218
 
208
219
  if lib == "rbs"
209
- args << "-r"
210
- args << "prism"
220
+ args << "-r" << "prism"
221
+ args << "-r" << "logger"
211
222
  end
212
223
 
213
224
  sh "#{ruby} #{rbs} #{args.join(' ')} validate"
@@ -549,6 +560,110 @@ task :prepare_profiling do
549
560
  Rake::Task[:"compile"].invoke
550
561
  end
551
562
 
563
+ namespace :wasm do
564
+ WASM_DIR = File.expand_path("wasm", __dir__)
565
+ WASM_OUTPUT = File.join(WASM_DIR, "rbs_parser.wasm")
566
+
567
+ # The parser under src/ is plain, self-contained C with no dependency on the
568
+ # Ruby C API, so it can be compiled to WebAssembly as-is. The only extra
569
+ # translation unit is the entry-point shim under wasm/.
570
+ def wasm_source_files
571
+ Dir.glob(File.join(__dir__, "src/**/*.c")).sort + [File.join(WASM_DIR, "rbs_wasm.c")]
572
+ end
573
+
574
+ # Locate the clang shipped with the WASI SDK.
575
+ #
576
+ # The system clang can target wasm32, but the WASI SDK additionally provides
577
+ # the wasi-libc sysroot and the wasm32 compiler-rt builtins that the link
578
+ # step needs, so we require it explicitly.
579
+ def wasi_clang
580
+ sdk = ENV["WASI_SDK_PATH"]
581
+ if sdk.nil? || sdk.empty?
582
+ raise <<~MSG
583
+ WASI_SDK_PATH is not set.
584
+
585
+ Install the WASI SDK from https://github.com/WebAssembly/wasi-sdk/releases
586
+ and point WASI_SDK_PATH at the extracted directory, for example:
587
+
588
+ export WASI_SDK_PATH=/opt/wasi-sdk
589
+ rake wasm:build
590
+ MSG
591
+ end
592
+
593
+ clang = File.join(sdk, "bin", "clang")
594
+ raise "clang not found at #{clang} (is WASI_SDK_PATH correct?)" unless File.executable?(clang)
595
+
596
+ clang
597
+ end
598
+
599
+ desc "Build the RBS parser as a WebAssembly module (requires WASI_SDK_PATH)"
600
+ task :build do
601
+ mkdir_p WASM_DIR
602
+ sh wasi_clang,
603
+ "--target=wasm32-wasip1",
604
+ # No `main`; the host calls `_initialize` and then the exported functions.
605
+ "-mexec-model=reactor",
606
+ "-std=gnu11",
607
+ "-O2",
608
+ "-Wno-unused-parameter",
609
+ "-I#{File.join(__dir__, "include")}",
610
+ "-o", WASM_OUTPUT,
611
+ *wasm_source_files
612
+ puts "Built #{WASM_OUTPUT}"
613
+ end
614
+
615
+ desc "Build and smoke-test the WebAssembly module (requires wasmtime)"
616
+ task :check => :build do
617
+ wasmtime = ENV["WASMTIME"] || "wasmtime"
618
+
619
+ # `rbs_wasm_selftest` parses a small fixed signature and returns 1 on
620
+ # success. `--invoke` prints the return value to stdout.
621
+ output = IO.popen([wasmtime, "run", "--invoke", "rbs_wasm_selftest", WASM_OUTPUT], err: File::NULL, &:read).to_s.strip
622
+
623
+ if output == "1"
624
+ puts "WebAssembly selftest passed."
625
+ else
626
+ raise "WebAssembly selftest failed: rbs_wasm_selftest returned #{output.inspect} (expected \"1\")"
627
+ end
628
+ end
629
+
630
+ # Where the runtime looks for the module and jars by default (see
631
+ # RBS::WASM::Runtime). These are build artifacts, bundled into the JRuby gem.
632
+ JRUBY_WASM_DIR = File.expand_path("lib/rbs/wasm", __dir__)
633
+ CHICORY_VERSION = ENV.fetch("CHICORY_VERSION", "1.7.5")
634
+ # `compiler` is Chicory's AOT compiler (wasm -> JVM bytecode); the asm* jars
635
+ # are the ow2 ASM libraries it depends on. Keep ASM_VERSION in sync with what
636
+ # the pinned Chicory release declares.
637
+ CHICORY_JARS = %w[wasm runtime log wasi compiler].freeze
638
+ ASM_VERSION = ENV.fetch("ASM_VERSION", "9.9.1")
639
+ ASM_JARS = %w[asm asm-tree asm-util asm-commons asm-analysis].freeze
640
+
641
+ desc "Download the Chicory and ASM jars the JRuby runtime needs into lib/rbs/wasm/jars"
642
+ task :vendor_jars do
643
+ require "open-uri"
644
+ require "fileutils"
645
+
646
+ jars_dir = File.join(JRUBY_WASM_DIR, "jars")
647
+ FileUtils.mkdir_p(jars_dir)
648
+
649
+ downloads = CHICORY_JARS.map { |name| ["#{name}.jar", "https://repo1.maven.org/maven2/com/dylibso/chicory/#{name}/#{CHICORY_VERSION}/#{name}-#{CHICORY_VERSION}.jar"] }
650
+ downloads += ASM_JARS.map { |name| ["#{name}.jar", "https://repo1.maven.org/maven2/org/ow2/asm/#{name}/#{ASM_VERSION}/#{name}-#{ASM_VERSION}.jar"] }
651
+
652
+ downloads.each do |filename, url|
653
+ puts "Downloading #{url}"
654
+ URI.open(url) { |io| File.binwrite(File.join(jars_dir, filename), io.read) } # steep:ignore
655
+ end
656
+
657
+ puts "Vendored Chicory #{CHICORY_VERSION} + ASM #{ASM_VERSION} into #{jars_dir}"
658
+ end
659
+
660
+ desc "Assemble everything the JRuby gem needs: the .wasm and the Chicory jars"
661
+ task :jruby_setup => [:build, :vendor_jars] do
662
+ cp WASM_OUTPUT, File.join(JRUBY_WASM_DIR, "rbs_parser.wasm")
663
+ puts "JRuby runtime is ready under #{JRUBY_WASM_DIR}"
664
+ end
665
+ end
666
+
552
667
  namespace :rust do
553
668
  namespace :rbs do
554
669
  RUST_DIR = File.expand_path("rust", __dir__)
data/Steepfile CHANGED
@@ -6,6 +6,13 @@ target :lib do
6
6
  ignore(
7
7
  "lib/rbs/test",
8
8
  # "lib/rbs/test.rb"
9
+
10
+ # JRuby-only implementations of RBS::Location and RBS::Parser. Like the C
11
+ # extension, these implement interfaces already described in sig/, and
12
+ # runtime.rb is Java interop, so they are not type-checked here.
13
+ "lib/rbs/wasm/location.rb",
14
+ "lib/rbs/wasm/runtime.rb",
15
+ "lib/rbs/wasm/parser.rb",
9
16
  )
10
17
 
11
18
  library "pathname", "json", "logger", "monitor", "tsort", "uri", 'dbm', 'pstore', 'singleton', 'shellwords', 'fileutils', 'find', 'digest', 'prettyprint', 'yaml', "psych", "securerandom"
data/config.yml CHANGED
@@ -784,6 +784,30 @@ nodes:
784
784
  - name: type_name_location
785
785
  c_type: rbs_location_range
786
786
  optional: true
787
+ - name: RBS::AST::Ruby::Annotations::ModuleSelfAnnotation
788
+ rust_name: ModuleSelfAnnotationNode
789
+ fields:
790
+ - name: prefix_location
791
+ c_type: rbs_location_range
792
+ - name: keyword_location
793
+ c_type: rbs_location_range
794
+ - name: colon_location
795
+ c_type: rbs_location_range
796
+ - name: name
797
+ c_type: rbs_type_name
798
+ - name: args
799
+ c_type: rbs_node_list
800
+ - name: open_bracket_location
801
+ c_type: rbs_location_range
802
+ optional: true
803
+ - name: close_bracket_location
804
+ c_type: rbs_location_range
805
+ optional: true
806
+ - name: args_comma_locations
807
+ c_type: rbs_location_range_list
808
+ - name: comment_location
809
+ c_type: rbs_location_range
810
+ optional: true
787
811
  - name: RBS::AST::Ruby::Annotations::ParamTypeAnnotation
788
812
  rust_name: ParamTypeAnnotationNode
789
813
  fields: