rbs 3.8.0 → 3.9.0.dev.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 +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +7 -7
- data/.github/workflows/typecheck.yml +2 -0
- data/.github/workflows/windows.yml +15 -0
- data/.rubocop.yml +20 -1
- data/CHANGELOG.md +14 -0
- data/Rakefile +5 -2
- data/config.yml +6 -0
- data/core/data.rbs +1 -1
- data/core/enumerator.rbs +14 -2
- data/core/exception.rbs +148 -39
- data/core/gc.rbs +2 -2
- data/core/io.rbs +7 -3
- data/core/kernel.rbs +58 -16
- data/core/method.rbs +2 -2
- data/core/module.rbs +3 -3
- data/core/proc.rbs +2 -2
- data/core/ractor.rbs +4 -1
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/regexp.rbs +4 -2
- data/core/ruby_vm.rbs +8 -8
- data/core/rubygems/version.rbs +2 -2
- data/core/string.rbs +1 -1
- data/core/time.rbs +1 -1
- data/core/unbound_method.rbs +1 -1
- data/docs/syntax.md +10 -5
- data/ext/rbs_extension/extconf.rb +2 -1
- data/ext/rbs_extension/location.c +32 -10
- data/ext/rbs_extension/location.h +4 -3
- data/ext/rbs_extension/main.c +22 -1
- data/ext/rbs_extension/parser.c +144 -136
- data/ext/rbs_extension/parserstate.c +40 -9
- data/ext/rbs_extension/parserstate.h +6 -4
- data/include/rbs/ruby_objs.h +6 -6
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/lib/rbs/ast/declarations.rb +9 -4
- data/lib/rbs/ast/directives.rb +10 -0
- data/lib/rbs/ast/members.rb +2 -0
- data/lib/rbs/ast/type_param.rb +2 -2
- data/lib/rbs/cli/validate.rb +1 -0
- data/lib/rbs/cli.rb +3 -3
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -7
- data/lib/rbs/collection/sources/rubygems.rb +1 -1
- data/lib/rbs/definition.rb +46 -31
- data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
- data/lib/rbs/definition_builder.rb +86 -30
- data/lib/rbs/environment.rb +33 -18
- data/lib/rbs/errors.rb +23 -0
- data/lib/rbs/locator.rb +2 -0
- data/lib/rbs/method_type.rb +2 -0
- data/lib/rbs/parser_aux.rb +38 -1
- data/lib/rbs/subtractor.rb +3 -3
- data/lib/rbs/test/hook.rb +2 -2
- data/lib/rbs/test/type_check.rb +7 -5
- data/lib/rbs/types.rb +44 -5
- data/lib/rbs/unit_test/spy.rb +4 -2
- data/lib/rbs/unit_test/type_assertions.rb +17 -11
- data/lib/rbs/validator.rb +4 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +10 -5
- data/lib/rbs.rb +1 -0
- data/rbs.gemspec +1 -1
- data/sig/collection/config/lockfile_generator.rbs +1 -1
- data/sig/declarations.rbs +10 -3
- data/sig/definition.rbs +67 -14
- data/sig/definition_builder.rbs +17 -3
- data/sig/directives.rbs +17 -1
- data/sig/environment.rbs +2 -0
- data/sig/errors.rbs +16 -0
- data/sig/parser.rbs +5 -1
- data/sig/subtractor.rbs +1 -1
- data/sig/test/type_check.rbs +2 -2
- data/sig/type_param.rbs +1 -1
- data/sig/types.rbs +3 -0
- data/sig/unit_test/spy.rbs +2 -0
- data/sig/unit_test/type_assertions.rbs +2 -0
- data/sig/validator.rbs +4 -0
- data/sig/writer.rbs +1 -1
- data/src/ruby_objs.c +12 -6
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/cgi/0/core.rbs +10 -0
- data/stdlib/json/0/json.rbs +52 -50
- data/stdlib/monitor/0/monitor.rbs +13 -4
- data/stdlib/net-http/0/net-http.rbs +2 -2
- data/stdlib/openssl/0/openssl.rbs +73 -73
- data/stdlib/resolv/0/resolv.rbs +8 -8
- data/stdlib/socket/0/addrinfo.rbs +1 -1
- data/stdlib/socket/0/unix_socket.rbs +4 -2
- data/stdlib/stringio/0/stringio.rbs +1 -1
- data/stdlib/uri/0/common.rbs +17 -0
- metadata +4 -7
- data/templates/include/rbs/constants.h.erb +0 -20
- data/templates/include/rbs/ruby_objs.h.erb +0 -10
- data/templates/src/constants.c.erb +0 -36
- data/templates/src/ruby_objs.c.erb +0 -27
- data/templates/template.rb +0 -122
@@ -1,4 +1,5 @@
|
|
1
1
|
#include "rbs_extension.h"
|
2
|
+
#include "rbs/util/rbs_constant_pool.h"
|
2
3
|
|
3
4
|
#define RESET_TABLE_P(table) (table->size == 0)
|
4
5
|
|
@@ -8,7 +9,7 @@ id_table *alloc_empty_table(void) {
|
|
8
9
|
*table = (id_table) {
|
9
10
|
.size = 10,
|
10
11
|
.count = 0,
|
11
|
-
.ids = calloc(10, sizeof(
|
12
|
+
.ids = calloc(10, sizeof(rbs_constant_id_t)),
|
12
13
|
.next = NULL,
|
13
14
|
};
|
14
15
|
|
@@ -61,7 +62,7 @@ void parser_pop_typevar_table(parserstate *state) {
|
|
61
62
|
}
|
62
63
|
}
|
63
64
|
|
64
|
-
void parser_insert_typevar(parserstate *state,
|
65
|
+
void parser_insert_typevar(parserstate *state, rbs_constant_id_t id) {
|
65
66
|
id_table *table = state->vars;
|
66
67
|
|
67
68
|
if (RESET_TABLE_P(table)) {
|
@@ -70,17 +71,17 @@ void parser_insert_typevar(parserstate *state, ID id) {
|
|
70
71
|
|
71
72
|
if (table->size == table->count) {
|
72
73
|
// expand
|
73
|
-
|
74
|
+
rbs_constant_id_t *ptr = table->ids;
|
74
75
|
table->size += 10;
|
75
|
-
table->ids = calloc(table->size, sizeof(
|
76
|
-
memcpy(table->ids, ptr, sizeof(
|
76
|
+
table->ids = calloc(table->size, sizeof(rbs_constant_id_t));
|
77
|
+
memcpy(table->ids, ptr, sizeof(rbs_constant_id_t) * table->count);
|
77
78
|
free(ptr);
|
78
79
|
}
|
79
80
|
|
80
81
|
table->ids[table->count++] = id;
|
81
82
|
}
|
82
83
|
|
83
|
-
bool parser_typevar_member(parserstate *state,
|
84
|
+
bool parser_typevar_member(parserstate *state, rbs_constant_id_t id) {
|
84
85
|
id_table *table = state->vars;
|
85
86
|
|
86
87
|
while (table && !RESET_TABLE_P(table)) {
|
@@ -332,8 +333,30 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
|
|
332
333
|
|
333
334
|
.vars = NULL,
|
334
335
|
.last_comment = NULL,
|
336
|
+
|
337
|
+
.constant_pool = {},
|
335
338
|
};
|
336
339
|
|
340
|
+
// The parser's constant pool is mainly used for storing the names of type variables, which usually aren't many.
|
341
|
+
// Below are some statistics gathered from the current test suite. We can see that 56% of parsers never add to their
|
342
|
+
// constant pool at all. The initial capacity needs to be a power of 2. Picking 2 means that we won't need to realloc
|
343
|
+
// in 85% of cases.
|
344
|
+
//
|
345
|
+
// TODO: recalculate these statistics based on a real world codebase, rather than the test suite.
|
346
|
+
//
|
347
|
+
// | Size | Count | Cumulative | % Coverage |
|
348
|
+
// |------|-------|------------|------------|
|
349
|
+
// | 0 | 7,862 | 7,862 | 56% |
|
350
|
+
// | 1 | 3,196 | 11,058 | 79% |
|
351
|
+
// | 2 | 778 | 12,719 | 85% |
|
352
|
+
// | 3 | 883 | 11,941 | 91% |
|
353
|
+
// | 4 | 478 | 13,197 | 95% |
|
354
|
+
// | 5 | 316 | 13,513 | 97% |
|
355
|
+
// | 6 | 288 | 13,801 | 99% |
|
356
|
+
// | 7 | 144 | 13,945 | 100% |
|
357
|
+
const size_t initial_pool_capacity = 2;
|
358
|
+
rbs_constant_pool_init(&parser->constant_pool, initial_pool_capacity);
|
359
|
+
|
337
360
|
parser_advance(parser);
|
338
361
|
parser_advance(parser);
|
339
362
|
parser_advance(parser);
|
@@ -348,9 +371,16 @@ parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_
|
|
348
371
|
parser_push_typevar_table(parser, true);
|
349
372
|
|
350
373
|
for (long i = 0; i < rb_array_len(variables); i++) {
|
351
|
-
VALUE
|
352
|
-
VALUE
|
353
|
-
|
374
|
+
VALUE symbol = rb_ary_entry(variables, i);
|
375
|
+
VALUE name = rb_sym2str(symbol);
|
376
|
+
|
377
|
+
rbs_constant_id_t id = rbs_constant_pool_insert_shared(
|
378
|
+
&parser->constant_pool,
|
379
|
+
(const uint8_t *) RSTRING_PTR(name),
|
380
|
+
RSTRING_LEN(name)
|
381
|
+
);
|
382
|
+
|
383
|
+
parser_insert_typevar(parser, id);
|
354
384
|
}
|
355
385
|
}
|
356
386
|
|
@@ -362,5 +392,6 @@ void free_parser(parserstate *parser) {
|
|
362
392
|
if (parser->last_comment) {
|
363
393
|
free_comment(parser->last_comment);
|
364
394
|
}
|
395
|
+
rbs_constant_pool_free(&parser->constant_pool);
|
365
396
|
free(parser);
|
366
397
|
}
|
@@ -7,13 +7,13 @@
|
|
7
7
|
#include "location.h"
|
8
8
|
|
9
9
|
/**
|
10
|
-
* id_table represents a set of IDs.
|
10
|
+
* id_table represents a set of RBS constant IDs.
|
11
11
|
* This is used to manage the set of bound variables.
|
12
12
|
* */
|
13
13
|
typedef struct id_table {
|
14
14
|
size_t size;
|
15
15
|
size_t count;
|
16
|
-
|
16
|
+
rbs_constant_id_t *ids;
|
17
17
|
struct id_table *next;
|
18
18
|
} id_table;
|
19
19
|
|
@@ -55,6 +55,8 @@ typedef struct {
|
|
55
55
|
|
56
56
|
id_table *vars; /* Known type variables */
|
57
57
|
comment *last_comment; /* Last read comment */
|
58
|
+
|
59
|
+
rbs_constant_pool_t constant_pool;
|
58
60
|
} parserstate;
|
59
61
|
|
60
62
|
comment *alloc_comment(token comment_token, comment *last_comment);
|
@@ -84,14 +86,14 @@ void parser_pop_typevar_table(parserstate *state);
|
|
84
86
|
/**
|
85
87
|
* Insert new type variable into the latest table.
|
86
88
|
* */
|
87
|
-
void parser_insert_typevar(parserstate *state,
|
89
|
+
void parser_insert_typevar(parserstate *state, rbs_constant_id_t id);
|
88
90
|
|
89
91
|
/**
|
90
92
|
* Returns true if given type variable is recorded in the table.
|
91
93
|
* If not found, it goes one table up, if it's not a reset table.
|
92
94
|
* Or returns false, if it's a reset table.
|
93
95
|
* */
|
94
|
-
bool parser_typevar_member(parserstate *state,
|
96
|
+
bool parser_typevar_member(parserstate *state, rbs_constant_id_t id);
|
95
97
|
|
96
98
|
/**
|
97
99
|
* Allocate new lexstate object.
|
data/include/rbs/ruby_objs.h
CHANGED
@@ -14,13 +14,13 @@ VALUE rbs_ast_annotation(VALUE string, VALUE location);
|
|
14
14
|
VALUE rbs_ast_comment(VALUE string, VALUE location);
|
15
15
|
VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
16
16
|
VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
|
17
|
-
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
18
|
-
VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
|
19
|
-
VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment);
|
17
|
+
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
|
18
|
+
VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
|
19
|
+
VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
|
20
20
|
VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
21
21
|
VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
22
22
|
VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
|
23
|
-
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
23
|
+
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
|
24
24
|
VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
|
25
25
|
VALUE rbs_ast_directives_use(VALUE clauses, VALUE location);
|
26
26
|
VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location);
|
@@ -39,12 +39,12 @@ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method
|
|
39
39
|
VALUE rbs_ast_members_prepend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
|
40
40
|
VALUE rbs_ast_members_private(VALUE location);
|
41
41
|
VALUE rbs_ast_members_public(VALUE location);
|
42
|
-
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE location);
|
42
|
+
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location);
|
43
43
|
VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
|
44
44
|
VALUE rbs_namespace(VALUE path, VALUE absolute);
|
45
45
|
VALUE rbs_type_name(VALUE namespace, VALUE name);
|
46
46
|
VALUE rbs_alias(VALUE name, VALUE args, VALUE location);
|
47
|
-
VALUE rbs_bases_any(VALUE location);
|
47
|
+
VALUE rbs_bases_any(VALUE todo, VALUE location);
|
48
48
|
VALUE rbs_bases_bool(VALUE location);
|
49
49
|
VALUE rbs_bases_bottom(VALUE location);
|
50
50
|
VALUE rbs_bases_class(VALUE location);
|
@@ -0,0 +1,219 @@
|
|
1
|
+
/**
|
2
|
+
* @file rbs_constant_pool.h
|
3
|
+
*
|
4
|
+
* A data structure that stores a set of strings.
|
5
|
+
*
|
6
|
+
* Each string is assigned a unique id, which can be used to compare strings for
|
7
|
+
* equality. This comparison ends up being much faster than strcmp, since it
|
8
|
+
* only requires a single integer comparison.
|
9
|
+
*/
|
10
|
+
#ifndef RBS_CONSTANT_POOL_H
|
11
|
+
#define RBS_CONSTANT_POOL_H
|
12
|
+
|
13
|
+
#include <assert.h>
|
14
|
+
#include <stdbool.h>
|
15
|
+
#include <stdint.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <string.h>
|
18
|
+
|
19
|
+
/**
|
20
|
+
* When we allocate constants into the pool, we reserve 0 to mean that the slot
|
21
|
+
* is not yet filled. This constant is reused in other places to indicate the
|
22
|
+
* lack of a constant id.
|
23
|
+
*/
|
24
|
+
#define RBS_CONSTANT_ID_UNSET 0
|
25
|
+
|
26
|
+
/**
|
27
|
+
* A constant id is a unique identifier for a constant in the constant pool.
|
28
|
+
*/
|
29
|
+
typedef uint32_t rbs_constant_id_t;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* A list of constant IDs. Usually used to represent a set of locals.
|
33
|
+
*/
|
34
|
+
typedef struct {
|
35
|
+
/** The number of constant ids in the list. */
|
36
|
+
size_t size;
|
37
|
+
|
38
|
+
/** The number of constant ids that have been allocated in the list. */
|
39
|
+
size_t capacity;
|
40
|
+
|
41
|
+
/** The constant ids in the list. */
|
42
|
+
rbs_constant_id_t *ids;
|
43
|
+
} rbs_constant_id_list_t;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Initialize a list of constant ids.
|
47
|
+
*
|
48
|
+
* @param list The list to initialize.
|
49
|
+
*/
|
50
|
+
void rbs_constant_id_list_init(rbs_constant_id_list_t *list);
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Initialize a list of constant ids with a given capacity.
|
54
|
+
*
|
55
|
+
* @param list The list to initialize.
|
56
|
+
* @param capacity The initial capacity of the list.
|
57
|
+
*/
|
58
|
+
void rbs_constant_id_list_init_capacity(rbs_constant_id_list_t *list, size_t capacity);
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Append a constant id to a list of constant ids. Returns false if any
|
62
|
+
* potential reallocations fail.
|
63
|
+
*
|
64
|
+
* @param list The list to append to.
|
65
|
+
* @param id The id to append.
|
66
|
+
* @return Whether the append succeeded.
|
67
|
+
*/
|
68
|
+
bool rbs_constant_id_list_append(rbs_constant_id_list_t *list, rbs_constant_id_t id);
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Insert a constant id into a list of constant ids at the specified index.
|
72
|
+
*
|
73
|
+
* @param list The list to insert into.
|
74
|
+
* @param index The index at which to insert.
|
75
|
+
* @param id The id to insert.
|
76
|
+
*/
|
77
|
+
void rbs_constant_id_list_insert(rbs_constant_id_list_t *list, size_t index, rbs_constant_id_t id);
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Checks if the current constant id list includes the given constant id.
|
81
|
+
*
|
82
|
+
* @param list The list to check.
|
83
|
+
* @param id The id to check for.
|
84
|
+
* @return Whether the list includes the given id.
|
85
|
+
*/
|
86
|
+
bool rbs_constant_id_list_includes(rbs_constant_id_list_t *list, rbs_constant_id_t id);
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Free the memory associated with a list of constant ids.
|
90
|
+
*
|
91
|
+
* @param list The list to free.
|
92
|
+
*/
|
93
|
+
void rbs_constant_id_list_free(rbs_constant_id_list_t *list);
|
94
|
+
|
95
|
+
/**
|
96
|
+
* The type of bucket in the constant pool hash map. This determines how the
|
97
|
+
* bucket should be freed.
|
98
|
+
*/
|
99
|
+
typedef unsigned int rbs_constant_pool_bucket_type_t;
|
100
|
+
|
101
|
+
/** By default, each constant is a slice of the source. */
|
102
|
+
static const rbs_constant_pool_bucket_type_t RBS_CONSTANT_POOL_BUCKET_DEFAULT = 0;
|
103
|
+
|
104
|
+
/** An owned constant is one for which memory has been allocated. */
|
105
|
+
static const rbs_constant_pool_bucket_type_t RBS_CONSTANT_POOL_BUCKET_OWNED = 1;
|
106
|
+
|
107
|
+
/** A constant constant is known at compile time. */
|
108
|
+
static const rbs_constant_pool_bucket_type_t RBS_CONSTANT_POOL_BUCKET_CONSTANT = 2;
|
109
|
+
|
110
|
+
/** A bucket in the hash map. */
|
111
|
+
typedef struct {
|
112
|
+
/** The incremental ID used for indexing back into the pool. */
|
113
|
+
unsigned int id: 30;
|
114
|
+
|
115
|
+
/** The type of the bucket, which determines how to free it. */
|
116
|
+
rbs_constant_pool_bucket_type_t type: 2;
|
117
|
+
|
118
|
+
/** The hash of the bucket. */
|
119
|
+
uint32_t hash;
|
120
|
+
} rbs_constant_pool_bucket_t;
|
121
|
+
|
122
|
+
/** A constant in the pool which effectively stores a string. */
|
123
|
+
typedef struct {
|
124
|
+
/** A pointer to the start of the string. */
|
125
|
+
const uint8_t *start;
|
126
|
+
|
127
|
+
/** The length of the string. */
|
128
|
+
size_t length;
|
129
|
+
} rbs_constant_t;
|
130
|
+
|
131
|
+
/** The overall constant pool, which stores constants found while parsing. */
|
132
|
+
typedef struct {
|
133
|
+
/** The buckets in the hash map. */
|
134
|
+
rbs_constant_pool_bucket_t *buckets;
|
135
|
+
|
136
|
+
/** The constants that are stored in the buckets. */
|
137
|
+
rbs_constant_t *constants;
|
138
|
+
|
139
|
+
/** The number of buckets in the hash map. */
|
140
|
+
uint32_t size;
|
141
|
+
|
142
|
+
/** The number of buckets that have been allocated in the hash map. */
|
143
|
+
uint32_t capacity;
|
144
|
+
} rbs_constant_pool_t;
|
145
|
+
|
146
|
+
// A global constant pool for storing permenant keywords, such as the names of location children in `parser.c`.
|
147
|
+
extern rbs_constant_pool_t *RBS_GLOBAL_CONSTANT_POOL;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Initialize a new constant pool with a given capacity.
|
151
|
+
*
|
152
|
+
* @param pool The pool to initialize.
|
153
|
+
* @param capacity The initial capacity of the pool.
|
154
|
+
* @return Whether the initialization succeeded.
|
155
|
+
*/
|
156
|
+
bool rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity);
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Return a pointer to the constant indicated by the given constant id.
|
160
|
+
*
|
161
|
+
* @param pool The pool to get the constant from.
|
162
|
+
* @param constant_id The id of the constant to get.
|
163
|
+
* @return A pointer to the constant.
|
164
|
+
*/
|
165
|
+
rbs_constant_t * rbs_constant_pool_id_to_constant(const rbs_constant_pool_t *pool, rbs_constant_id_t constant_id);
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Find a constant in a constant pool. Returns the id of the constant, or 0 if
|
169
|
+
* the constant is not found.
|
170
|
+
*
|
171
|
+
* @param pool The pool to find the constant in.
|
172
|
+
* @param start A pointer to the start of the constant.
|
173
|
+
* @param length The length of the constant.
|
174
|
+
* @return The id of the constant.
|
175
|
+
*/
|
176
|
+
rbs_constant_id_t rbs_constant_pool_find(const rbs_constant_pool_t *pool, const uint8_t *start, size_t length);
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Insert a constant into a constant pool that is a slice of a source string.
|
180
|
+
* Returns the id of the constant, or 0 if any potential calls to resize fail.
|
181
|
+
*
|
182
|
+
* @param pool The pool to insert the constant into.
|
183
|
+
* @param start A pointer to the start of the constant.
|
184
|
+
* @param length The length of the constant.
|
185
|
+
* @return The id of the constant.
|
186
|
+
*/
|
187
|
+
rbs_constant_id_t rbs_constant_pool_insert_shared(rbs_constant_pool_t *pool, const uint8_t *start, size_t length);
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Insert a constant into a constant pool from memory that is now owned by the
|
191
|
+
* constant pool. Returns the id of the constant, or 0 if any potential calls to
|
192
|
+
* resize fail.
|
193
|
+
*
|
194
|
+
* @param pool The pool to insert the constant into.
|
195
|
+
* @param start A pointer to the start of the constant.
|
196
|
+
* @param length The length of the constant.
|
197
|
+
* @return The id of the constant.
|
198
|
+
*/
|
199
|
+
rbs_constant_id_t rbs_constant_pool_insert_owned(rbs_constant_pool_t *pool, uint8_t *start, size_t length);
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Insert a constant into a constant pool from memory that is constant. Returns
|
203
|
+
* the id of the constant, or 0 if any potential calls to resize fail.
|
204
|
+
*
|
205
|
+
* @param pool The pool to insert the constant into.
|
206
|
+
* @param start A pointer to the start of the constant.
|
207
|
+
* @param length The length of the constant.
|
208
|
+
* @return The id of the constant.
|
209
|
+
*/
|
210
|
+
rbs_constant_id_t rbs_constant_pool_insert_constant(rbs_constant_pool_t *pool, const uint8_t *start, size_t length);
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Free the memory associated with a constant pool.
|
214
|
+
*
|
215
|
+
* @param pool The pool to free.
|
216
|
+
*/
|
217
|
+
void rbs_constant_pool_free(rbs_constant_pool_t *pool);
|
218
|
+
|
219
|
+
#endif
|
data/lib/rbs/ast/declarations.rb
CHANGED
@@ -349,12 +349,14 @@ module RBS
|
|
349
349
|
attr_reader :type
|
350
350
|
attr_reader :location
|
351
351
|
attr_reader :comment
|
352
|
+
attr_reader :annotations
|
352
353
|
|
353
|
-
def initialize(name:, type:, location:, comment:)
|
354
|
+
def initialize(name:, type:, location:, comment:, annotations: [])
|
354
355
|
@name = name
|
355
356
|
@type = type
|
356
357
|
@location = location
|
357
358
|
@comment = comment
|
359
|
+
@annotations = annotations || []
|
358
360
|
end
|
359
361
|
|
360
362
|
def ==(other)
|
@@ -385,12 +387,14 @@ module RBS
|
|
385
387
|
attr_reader :type
|
386
388
|
attr_reader :location
|
387
389
|
attr_reader :comment
|
390
|
+
attr_reader :annotations
|
388
391
|
|
389
|
-
def initialize(name:, type:, location:, comment:)
|
392
|
+
def initialize(name:, type:, location:, comment:, annotations: [])
|
390
393
|
@name = name
|
391
394
|
@type = type
|
392
395
|
@location = location
|
393
396
|
@comment = comment
|
397
|
+
@annotations = annotations
|
394
398
|
end
|
395
399
|
|
396
400
|
def ==(other)
|
@@ -417,13 +421,14 @@ module RBS
|
|
417
421
|
end
|
418
422
|
|
419
423
|
class AliasDecl < Base
|
420
|
-
attr_reader :new_name, :old_name, :location, :comment
|
424
|
+
attr_reader :new_name, :old_name, :location, :comment, :annotations
|
421
425
|
|
422
|
-
def initialize(new_name:, old_name:, location:, comment:)
|
426
|
+
def initialize(new_name:, old_name:, location:, comment:, annotations: [])
|
423
427
|
@new_name = new_name
|
424
428
|
@old_name = old_name
|
425
429
|
@location = location
|
426
430
|
@comment = comment
|
431
|
+
@annotations = annotations
|
427
432
|
end
|
428
433
|
|
429
434
|
def ==(other)
|
data/lib/rbs/ast/directives.rb
CHANGED
data/lib/rbs/ast/members.rb
CHANGED
data/lib/rbs/ast/type_param.rb
CHANGED
@@ -5,13 +5,13 @@ module RBS
|
|
5
5
|
class TypeParam
|
6
6
|
attr_reader :name, :variance, :location, :upper_bound_type, :default_type
|
7
7
|
|
8
|
-
def initialize(name:, variance:, upper_bound:, location:, default_type: nil)
|
8
|
+
def initialize(name:, variance:, upper_bound:, location:, default_type: nil, unchecked: false)
|
9
9
|
@name = name
|
10
10
|
@variance = variance
|
11
11
|
@upper_bound_type = upper_bound
|
12
12
|
@location = location
|
13
|
-
@unchecked = false
|
14
13
|
@default_type = default_type
|
14
|
+
@unchecked = unchecked
|
15
15
|
end
|
16
16
|
|
17
17
|
def upper_bound
|
data/lib/rbs/cli/validate.rb
CHANGED
@@ -196,6 +196,7 @@ EOU
|
|
196
196
|
end
|
197
197
|
InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
|
198
198
|
when AST::Members::Var
|
199
|
+
@validator.validate_variable(member)
|
199
200
|
void_type_context_validator(member.type)
|
200
201
|
if member.is_a?(AST::Members::ClassVariable)
|
201
202
|
no_self_type_validator(member.type)
|
data/lib/rbs/cli.rb
CHANGED
@@ -587,7 +587,7 @@ EOU
|
|
587
587
|
merge = true
|
588
588
|
end
|
589
589
|
opts.on("--todo", "Generates only undefined methods compared to objects") do
|
590
|
-
Warning.warn("
|
590
|
+
Warning.warn("Generating prototypes with `--todo` option is experimental\n", category: :experimental)
|
591
591
|
todo = true
|
592
592
|
end
|
593
593
|
opts.on("--method-owner CLASS", "Generate method prototypes if the owner of the method is [CLASS]") do |klass|
|
@@ -1155,7 +1155,7 @@ EOB
|
|
1155
1155
|
# Generate RBS files from the codebase.
|
1156
1156
|
$ rbs prototype rb lib/ > generated.rbs
|
1157
1157
|
|
1158
|
-
# Write more
|
1158
|
+
# Write more descriptive types by hand.
|
1159
1159
|
$ $EDITOR handwritten.rbs
|
1160
1160
|
|
1161
1161
|
# Remove hand-written method definitions from generated.rbs.
|
@@ -1163,7 +1163,7 @@ EOB
|
|
1163
1163
|
|
1164
1164
|
Options:
|
1165
1165
|
HELP
|
1166
|
-
opts.on('-w', '--write', 'Overwrite files
|
1166
|
+
opts.on('-w', '--write', 'Overwrite files directory') { write_to_file = true }
|
1167
1167
|
opts.on('--subtrahend=PATH', '') { |path| subtrahend_paths << path }
|
1168
1168
|
opts.parse!(args)
|
1169
1169
|
end
|
@@ -4,7 +4,17 @@ module RBS
|
|
4
4
|
module Collection
|
5
5
|
class Config
|
6
6
|
class LockfileGenerator
|
7
|
-
ALUMNI_STDLIBS = {
|
7
|
+
ALUMNI_STDLIBS = {
|
8
|
+
"mutex_m" => ">= 0.3.0",
|
9
|
+
"abbrev" => nil,
|
10
|
+
"base64" => nil,
|
11
|
+
"bigdecimal" => nil,
|
12
|
+
"csv" => nil,
|
13
|
+
"minitest" => nil,
|
14
|
+
"net-smtp" => nil,
|
15
|
+
"nkf" => nil,
|
16
|
+
"observer" => nil,
|
17
|
+
}
|
8
18
|
|
9
19
|
class GemfileLockMismatchError < StandardError
|
10
20
|
def initialize(expected:, actual:)
|
@@ -161,17 +171,24 @@ module RBS
|
|
161
171
|
return if lockfile.gems.key?(name)
|
162
172
|
|
163
173
|
case name
|
164
|
-
when '
|
165
|
-
|
166
|
-
|
167
|
-
|
174
|
+
when 'bigdecimal-math'
|
175
|
+
# The `bigdecimal-math` is never released as a gem.
|
176
|
+
# Therefore, `assign_gem` should not be called.
|
177
|
+
RBS.logger.info {
|
178
|
+
from = from_gem || "rbs_collection.yaml"
|
179
|
+
"`#{name}` is included in the RBS dependencies of `#{from}`, but the type definition as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies of `#{from}`."
|
180
|
+
}
|
181
|
+
source = find_source(name: name)
|
182
|
+
if source&.is_a?(Sources::Stdlib)
|
183
|
+
lockfile.gems[name] = { name: name, version: "0", source: source }
|
184
|
+
end
|
168
185
|
return
|
169
186
|
when *ALUMNI_STDLIBS.keys
|
170
187
|
version = ALUMNI_STDLIBS.fetch(name)
|
171
188
|
if from_gem
|
172
189
|
# From `dependencies:` of a `manifest.yaml` of a gem
|
173
190
|
source = find_source(name: name) or raise
|
174
|
-
if source.is_a?(Sources::Stdlib)
|
191
|
+
if source.is_a?(Sources::Stdlib) && version
|
175
192
|
RBS.logger.warn {
|
176
193
|
"`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
|
177
194
|
}
|
@@ -185,7 +202,11 @@ module RBS
|
|
185
202
|
else
|
186
203
|
# From `gems:` of a `rbs_collection.yaml`
|
187
204
|
RBS.logger.warn {
|
188
|
-
|
205
|
+
if version
|
206
|
+
"`#{name}` as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
|
207
|
+
else
|
208
|
+
"`#{name}` as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies in your rbs_collection.yaml."
|
209
|
+
end
|
189
210
|
}
|
190
211
|
end
|
191
212
|
end
|