rbs 3.9.0.dev.1 → 3.9.0.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 311aed14b7b84b6b21cb187b72c1ddd87a427b6ec02805017f83b5fbcbfaac7b
4
- data.tar.gz: 4fc2e119368352b2fbded9355834757399cde34f3912c24ae82e91db67042762
3
+ metadata.gz: dfc16707bf516d2296468a341b413fd87a4ecb032b8fb54717fa36ffe6310d10
4
+ data.tar.gz: ecbf8ac797a87c14b34aa0e78bf7c7c708762bc5048c16230f5d2bf23d38f981
5
5
  SHA512:
6
- metadata.gz: 6c9b1a6188ac4585b3ea5b9dd72432f12ea13ee4c8311a15a86f0cee5595acef46901e04105e40a84703ea51e036efb645a53cacaa1517d213420b2251f3f506
7
- data.tar.gz: 4061149d53166bbe1a6029cebbacc54117eccf5d414c1859b50c5049d2898245a27ccf8f558b9c11d5edaa0b276ba88c111b8c80505a5b911664e77b5351dc2a
6
+ metadata.gz: c8f881cc73012ba92d79512a934c1d75fe879e0de1b03e44286d4288414cf7678b5d5cf1319718765c6457136fc1a72ce435fe8392fc186abdd3d712f4662d6e
7
+ data.tar.gz: e724bc074e0ac9e3cd46e8eb40ad6b0837a31820786d924bc4e79760946f55cf0ad8d7ca7ca2bee97ca9ad98ef5c4671e9df0dee4ece85f636f72ebd8787a85d
@@ -80,3 +80,29 @@ jobs:
80
80
  - name: Run test
81
81
  run: |
82
82
  bundle exec rake ${{ matrix.job }}
83
+ valgrind:
84
+ runs-on: ubuntu-latest
85
+ steps:
86
+ - uses: actions/checkout@v2
87
+ - uses: ruby/setup-ruby@v1
88
+ with:
89
+ ruby-version: "3.4"
90
+ bundler-cache: none
91
+ - name: Set working directory as safe
92
+ run: git config --global --add safe.directory $(pwd)
93
+ - name: Set up permission
94
+ run: chmod -R o-w /opt/hostedtoolcache/Ruby
95
+ - name: Install dependencies
96
+ run: |
97
+ sudo apt-get update
98
+ sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool python3 valgrind
99
+ - name: Update rubygems & bundler
100
+ run: |
101
+ ruby -v
102
+ gem update --system
103
+ - name: bin/setup
104
+ run: |
105
+ bin/setup
106
+ - run: bundle exec rake test:valgrind
107
+ env:
108
+ RUBY_FREE_AT_EXIT: 1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.9.0.pre.1 (2025-03-11)
4
+
5
+ ### Signature updates
6
+
7
+ * `CGI.escape/unescape_uri_component` ([#2299](https://github.com/ruby/rbs/pull/2299))
8
+ * `Enumerator::Chain` ([#2220](https://github.com/ruby/rbs/pull/2220))
9
+ * `IO.read` ([#2216](https://github.com/ruby/rbs/pull/2216))
10
+ * `IPAddr#netmask` ([#2311](https://github.com/ruby/rbs/pull/2311))
11
+ * `Kernel#gets`, `Kernel#readline`, `Kernel#readlines` ([#2212](https://github.com/ruby/rbs/pull/2212))
12
+ * `Net::HTTP.start` ([#2225](https://github.com/ruby/rbs/pull/2225))
13
+ * `OpenSSL::BN` ([#2267](https://github.com/ruby/rbs/pull/2267))
14
+ * `OpenSSL::PKey::{RSA,DSA,DH}#params` ([#2255](https://github.com/ruby/rbs/pull/2255))
15
+ * `UNIXSocket#send_io`, `UNIXSocket#recv_io` ([#2264](https://github.com/ruby/rbs/pull/2264))
16
+ * `URI.encode/decode_uri_component` ([#2299](https://github.com/ruby/rbs/pull/2299))
17
+ * Rename to reduce top-level interface and type alias ([#2250](https://github.com/ruby/rbs/pull/2250))
18
+
19
+ ### Language updates
20
+
21
+ * Let class/module alias decls, global decls, and constant decls be annotated ([#2302](https://github.com/ruby/rbs/pull/2302))
22
+ * Add `resolve-type-names: false` magic comment ([#2234](https://github.com/ruby/rbs/pull/2234))
23
+
24
+ ### Library changes
25
+
26
+ * Remove unused root variable ([#2307](https://github.com/ruby/rbs/pull/2307))
27
+ * Run Valgrind on CI and fix memory leaks ([#2309](https://github.com/ruby/rbs/pull/2309))
28
+ * Add information for VariableDuplicationError ([#2310](https://github.com/ruby/rbs/pull/2310))
29
+ * Reduce Array object allocation during parsing ([#2304](https://github.com/ruby/rbs/pull/2304))
30
+ * No class variable duplication validation ([#2305](https://github.com/ruby/rbs/pull/2305))
31
+ * Keep annotations during type name resolution ([#2303](https://github.com/ruby/rbs/pull/2303))
32
+ * Fix method annotations ([#2301](https://github.com/ruby/rbs/pull/2301))
33
+ * Fix class variable ([#2300](https://github.com/ruby/rbs/pull/2300))
34
+ * Add bundled gems to alumnus ([#2288](https://github.com/ruby/rbs/pull/2288))
35
+ * Exclude `attr_*` methods from duplicate checks. ([#2294](https://github.com/ruby/rbs/pull/2294))
36
+ * Validate superclass and module-self-type ([#2289](https://github.com/ruby/rbs/pull/2289))
37
+ * Remove case when `rubygems` and `set` ([#2279](https://github.com/ruby/rbs/pull/2279))
38
+ * Check variable duplication ([#2241](https://github.com/ruby/rbs/pull/2241))
39
+ * Validate variable types ([#2237](https://github.com/ruby/rbs/pull/2237))
40
+ * Remove call to `TypeParam#unchecked!` from C parser ([#2256](https://github.com/ruby/rbs/pull/2256))
41
+ * Remove call to `Any#todo!` from C parser ([#2249](https://github.com/ruby/rbs/pull/2249))
42
+ * [rbs/unit_test] Treat nil as a return value ([#2257](https://github.com/ruby/rbs/pull/2257))
43
+
44
+ ### Miscellaneous
45
+
46
+ * Apply rubocop style to RBS ([#2292](https://github.com/ruby/rbs/pull/2292))
47
+ * Eliminate external HTTP requests on test ([#2253](https://github.com/ruby/rbs/pull/2253))
48
+ * Prevent a warning: the block passed to 'map_type_name' .. may be ignored ([#2248](https://github.com/ruby/rbs/pull/2248))
49
+ * Update ruby version for rubocop ([#2251](https://github.com/ruby/rbs/pull/2251))
50
+ * Drop templates from package ([#2214](https://github.com/ruby/rbs/pull/2214))
51
+
3
52
  ## 3.8.1 (2024-12-27)
4
53
 
5
54
  ### Signature updates
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ bin = File.join(__dir__, "bin")
11
11
 
12
12
  Rake::ExtensionTask.new("rbs_extension")
13
13
 
14
- Rake::TestTask.new(:test => :compile) do |t|
14
+ test_config = lambda do |t|
15
15
  t.libs << "test"
16
16
  t.libs << "lib"
17
17
  t.test_files = FileList["test/**/*_test.rb"].reject do |path|
@@ -19,6 +19,16 @@ Rake::TestTask.new(:test => :compile) do |t|
19
19
  end
20
20
  end
21
21
 
22
+ Rake::TestTask.new(test: :compile, &test_config)
23
+
24
+ unless Gem.win_platform?
25
+ require "ruby_memcheck"
26
+
27
+ namespace :test do
28
+ RubyMemcheck::TestTask.new(valgrind: :compile, &test_config)
29
+ end
30
+ end
31
+
22
32
  multitask :default => [:test, :stdlib_test, :typecheck_test, :rubocop, :validate, :test_doc]
23
33
 
24
34
  task :lexer do
@@ -61,6 +61,7 @@ typedef struct {
61
61
  } method_params;
62
62
 
63
63
  static VALUE EMPTY_ARRAY;
64
+ static VALUE EMPTY_HASH;
64
65
 
65
66
  static inline void melt_array(VALUE *array) {
66
67
  if (*array == EMPTY_ARRAY) {
@@ -68,6 +69,12 @@ static inline void melt_array(VALUE *array) {
68
69
  }
69
70
  }
70
71
 
72
+ static inline void melt_hash(VALUE *hash) {
73
+ if (*hash == EMPTY_HASH) {
74
+ *hash = rb_hash_new();
75
+ }
76
+ }
77
+
71
78
  static bool rbs_is_untyped_params(method_params *params) {
72
79
  return NIL_P(params->required_positionals);
73
80
  }
@@ -343,7 +350,7 @@ static VALUE parse_keyword_key(parserstate *state) {
343
350
  /*
344
351
  keyword ::= {} keyword `:` <function_param>
345
352
  */
346
- static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
353
+ static void parse_keyword(parserstate *state, VALUE *keywords, VALUE memo) {
347
354
  VALUE key = parse_keyword_key(state);
348
355
 
349
356
  if (!NIL_P(rb_hash_aref(memo, key))) {
@@ -359,7 +366,8 @@ static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
359
366
  parser_advance_assert(state, pCOLON);
360
367
  VALUE param = parse_function_param(state);
361
368
 
362
- rb_hash_aset(keywords, key, param);
369
+ melt_hash(keywords);
370
+ rb_hash_aset(*keywords, key, param);
363
371
 
364
372
  return;
365
373
  }
@@ -466,7 +474,7 @@ PARSE_OPTIONAL_PARAMS:
466
474
  parser_advance(state);
467
475
 
468
476
  if (is_keyword(state)) {
469
- parse_keyword(state, params->optional_keywords, memo);
477
+ parse_keyword(state, &params->optional_keywords, memo);
470
478
  parser_advance_if(state, pCOMMA);
471
479
  goto PARSE_KEYWORDS;
472
480
  }
@@ -533,7 +541,7 @@ PARSE_KEYWORDS:
533
541
  case pQUESTION:
534
542
  parser_advance(state);
535
543
  if (is_keyword(state)) {
536
- parse_keyword(state, params->optional_keywords, memo);
544
+ parse_keyword(state, &params->optional_keywords, memo);
537
545
  } else {
538
546
  raise_syntax_error(
539
547
  state,
@@ -556,7 +564,7 @@ PARSE_KEYWORDS:
556
564
  case tBANGIDENT:
557
565
  KEYWORD_CASES
558
566
  if (is_keyword(state)) {
559
- parse_keyword(state, params->required_keywords, memo);
567
+ parse_keyword(state, &params->required_keywords, memo);
560
568
  } else {
561
569
  raise_syntax_error(
562
570
  state,
@@ -613,8 +621,8 @@ static void initialize_method_params(method_params *params){
613
621
  .optional_positionals = EMPTY_ARRAY,
614
622
  .rest_positionals = Qnil,
615
623
  .trailing_positionals = EMPTY_ARRAY,
616
- .required_keywords = rb_hash_new(),
617
- .optional_keywords = rb_hash_new(),
624
+ .required_keywords = EMPTY_HASH,
625
+ .optional_keywords = EMPTY_HASH,
618
626
  .rest_keywords = Qnil,
619
627
  };
620
628
  }
@@ -2958,10 +2966,15 @@ rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) {
2958
2966
  void rbs__init_parser(void) {
2959
2967
  RBS_Parser = rb_define_class_under(RBS, "Parser", rb_cObject);
2960
2968
  rb_gc_register_mark_object(RBS_Parser);
2969
+
2961
2970
  VALUE empty_array = rb_obj_freeze(rb_ary_new());
2962
2971
  rb_gc_register_mark_object(empty_array);
2963
2972
  EMPTY_ARRAY = empty_array;
2964
2973
 
2974
+ VALUE empty_hash = rb_obj_freeze(rb_hash_new());
2975
+ rb_gc_register_mark_object(empty_hash);
2976
+ EMPTY_HASH = empty_hash;
2977
+
2965
2978
  rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 5);
2966
2979
  rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5);
2967
2980
  rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3);
@@ -363,6 +363,7 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
363
363
 
364
364
  if (!NIL_P(variables)) {
365
365
  if (!RB_TYPE_P(variables, T_ARRAY)) {
366
+ free_parser(parser);
366
367
  rb_raise(rb_eTypeError,
367
368
  "wrong argument type %"PRIsVALUE" (must be array or nil)",
368
369
  rb_obj_class(variables));
@@ -387,11 +388,24 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
387
388
  return parser;
388
389
  }
389
390
 
391
+ void free_typevar_tables(id_table *table) {
392
+ while (table != NULL) {
393
+ id_table *next = table->next;
394
+ if (table->ids != NULL) {
395
+ free(table->ids);
396
+ }
397
+ free(table);
398
+ table = next;
399
+ }
400
+ }
401
+
390
402
  void free_parser(parserstate *parser) {
391
403
  free(parser->lexstate);
392
404
  if (parser->last_comment) {
393
405
  free_comment(parser->last_comment);
394
406
  }
407
+
408
+ free_typevar_tables(parser->vars);
395
409
  rbs_constant_pool_free(&parser->constant_pool);
396
410
  free(parser);
397
411
  }
@@ -569,11 +569,11 @@ module RBS
569
569
  case l.source
570
570
  when AST::Members::InstanceVariable
571
571
  if r.source.instance_of?(AST::Members::InstanceVariable) && l.declared_in == r.declared_in
572
- raise InstanceVariableDuplicationError.new(member: l.source)
572
+ raise InstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
573
573
  end
574
574
  when AST::Members::ClassInstanceVariable
575
575
  if r.source.instance_of?(AST::Members::ClassInstanceVariable) && l.declared_in == r.declared_in
576
- raise ClassInstanceVariableDuplicationError.new(member: l.source)
576
+ raise ClassInstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
577
577
  end
578
578
  end
579
579
  end
data/lib/rbs/errors.rb CHANGED
@@ -325,24 +325,25 @@ module RBS
325
325
  class VariableDuplicationError < DefinitionError
326
326
  include DetailedMessageable
327
327
 
328
- attr_reader :member
329
-
330
- def initialize(member:)
331
- @member = member
328
+ attr_reader :type_name
329
+ attr_reader :variable_name
330
+ attr_reader :location
332
331
 
333
- super "#{Location.to_string location}: Duplicated variable name #{member.name}"
334
- end
332
+ def initialize(type_name:, variable_name:, location:)
333
+ @type_name = type_name
334
+ @variable_name = variable_name
335
+ @location = location
335
336
 
336
- def location
337
- loc = @member.location or raise
338
- loc[:name]
337
+ super "#{Location.to_string location}: Duplicated #{kind} variable name `#{variable_name}` in `#{type_name}`"
339
338
  end
340
339
  end
341
340
 
342
341
  class InstanceVariableDuplicationError < VariableDuplicationError
342
+ def kind = 'instance'
343
343
  end
344
344
 
345
345
  class ClassInstanceVariableDuplicationError < VariableDuplicationError
346
+ def kind = 'class instance'
346
347
  end
347
348
 
348
349
  class UnknownMethodAliasError < DefinitionError
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.9.0.dev.1"
4
+ VERSION = "3.9.0.pre.1"
5
5
  end
data/sig/errors.rbs CHANGED
@@ -185,17 +185,20 @@ module RBS
185
185
  class VariableDuplicationError < DefinitionError
186
186
  include DetailedMessageable
187
187
 
188
- attr_reader member: AST::Members::Var
189
-
190
- def initialize: (member: AST::Members::Var) -> void
188
+ attr_reader type_name: TypeName
189
+ attr_reader variable_name: Symbol
190
+ attr_reader location: Location[untyped, untyped]?
191
191
 
192
- def location: () -> Location[bot, bot]
192
+ def initialize: (type_name: TypeName, variable_name: Symbol, location: Location[untyped, untyped]?) -> void
193
+ def kind: () -> String
193
194
  end
194
195
 
195
196
  class InstanceVariableDuplicationError < VariableDuplicationError
197
+ def kind: () -> String
196
198
  end
197
199
 
198
200
  class ClassInstanceVariableDuplicationError < VariableDuplicationError
201
+ def kind: () -> String
199
202
  end
200
203
 
201
204
  # The `alias` member declares an alias from unknown method
@@ -276,6 +276,14 @@ class IPAddr
276
276
  #
277
277
  def native: () -> IPAddr
278
278
 
279
+ # <!--
280
+ # rdoc-file=lib/ipaddr.rb
281
+ # - netmask()
282
+ # -->
283
+ # Returns the netmask in string format e.g. 255.255.0.0
284
+ #
285
+ def netmask: () -> String
286
+
279
287
  # <!--
280
288
  # rdoc-file=lib/ipaddr.rb
281
289
  # - prefix()
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0.dev.1
4
+ version: 3.9.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-06 00:00:00.000000000 Z
10
+ date: 2025-03-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: logger