rbs 3.4.4 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +12 -4
- data/.github/workflows/dependabot.yml +26 -0
- data/.github/workflows/ruby.yml +14 -1
- data/CHANGELOG.md +87 -1
- data/README.md +5 -3
- data/Rakefile +20 -3
- data/Steepfile +1 -1
- data/core/enumerator.rbs +1 -1
- data/core/float.rbs +2 -1
- data/core/gc.rbs +272 -150
- data/core/integer.rbs +6 -4
- data/core/io/wait.rbs +4 -4
- data/core/io.rbs +10 -3
- data/core/kernel.rbs +8 -7
- data/core/module.rbs +17 -4
- data/core/proc.rbs +1 -1
- data/core/range.rbs +2 -2
- data/core/rational.rbs +2 -1
- data/core/regexp.rbs +101 -90
- data/core/ruby_vm.rbs +107 -103
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/set.rbs +13 -7
- data/core/string.rbs +3 -3
- data/core/symbol.rbs +2 -1
- data/core/thread.rbs +1 -1
- data/core/time.rbs +24 -4
- data/docs/architecture.md +110 -0
- data/docs/gem.md +0 -1
- data/docs/syntax.md +5 -1
- data/ext/rbs_extension/constants.c +2 -0
- data/ext/rbs_extension/constants.h +1 -0
- data/ext/rbs_extension/lexer.c +1338 -1341
- data/ext/rbs_extension/lexer.h +2 -0
- data/ext/rbs_extension/lexer.re +2 -3
- data/ext/rbs_extension/lexstate.c +5 -1
- data/ext/rbs_extension/location.c +80 -70
- data/ext/rbs_extension/location.h +25 -5
- data/ext/rbs_extension/parser.c +149 -43
- data/ext/rbs_extension/parserstate.c +12 -1
- data/ext/rbs_extension/parserstate.h +9 -0
- data/ext/rbs_extension/ruby_objs.c +13 -3
- data/ext/rbs_extension/ruby_objs.h +1 -0
- data/lib/rbs/cli/validate.rb +2 -2
- data/lib/rbs/cli.rb +4 -6
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +1 -6
- data/lib/rbs/definition_builder/method_builder.rb +1 -1
- data/lib/rbs/definition_builder.rb +8 -8
- data/lib/rbs/diff.rb +1 -1
- data/lib/rbs/environment_loader.rb +2 -1
- data/lib/rbs/errors.rb +0 -14
- data/lib/rbs/location_aux.rb +6 -1
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +12 -5
- data/lib/rbs/prototype/helpers.rb +22 -12
- data/lib/rbs/prototype/rb.rb +38 -4
- data/lib/rbs/prototype/rbi.rb +30 -20
- data/lib/rbs/test/errors.rb +19 -14
- data/lib/rbs/test/tester.rb +1 -1
- data/lib/rbs/test/type_check.rb +95 -16
- data/lib/rbs/types.rb +112 -13
- data/lib/rbs/unit_test/spy.rb +1 -1
- data/lib/rbs/version.rb +1 -1
- data/rbs.gemspec +7 -2
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +1 -1
- data/sig/manifest.yaml +0 -1
- data/sig/method_types.rbs +3 -3
- data/sig/parser.rbs +28 -0
- data/sig/prototype/helpers.rbs +4 -0
- data/sig/prototype/rbi.rbs +2 -0
- data/sig/types.rbs +54 -4
- data/sig/variance_calculator.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +4 -1
- data/stdlib/fileutils/0/fileutils.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +29 -27
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/timeout/0/timeout.rbs +6 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +84 -0
- metadata +7 -9
- data/Gemfile +0 -30
- data/Gemfile.lock +0 -117
- data/lib/rbs/parser_compat/lexer_error.rb +0 -6
- data/lib/rbs/parser_compat/located_value.rb +0 -7
- data/lib/rbs/parser_compat/semantics_error.rb +0 -6
- data/lib/rbs/parser_compat/syntax_error.rb +0 -6
data/ext/rbs_extension/lexer.h
CHANGED
data/ext/rbs_extension/lexer.re
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
token rbsparser_next_token(lexstate *state) {
|
4
4
|
lexstate backup;
|
5
5
|
|
6
|
-
start:
|
7
6
|
backup = *state;
|
8
7
|
|
9
8
|
/*!re2c
|
@@ -139,9 +138,9 @@ start:
|
|
139
138
|
|
140
139
|
"$" global_ident { return next_token(state, tGIDENT); }
|
141
140
|
|
142
|
-
skip = [ \t\n
|
141
|
+
skip = ([ \t]+|[\r\n]);
|
143
142
|
|
144
|
-
skip {
|
143
|
+
skip { return next_token(state, tTRIVIA); }
|
145
144
|
"\x00" { return next_token(state, pEOF); }
|
146
145
|
* { return next_token(state, ErrorToken); }
|
147
146
|
*/
|
@@ -77,6 +77,8 @@ static const char *RBS_TOKENTYPE_NAMES[] = {
|
|
77
77
|
"tCOMMENT",
|
78
78
|
"tLINECOMMENT",
|
79
79
|
|
80
|
+
"tTRIVIA",
|
81
|
+
|
80
82
|
"tDQSTRING", /* Double quoted string */
|
81
83
|
"tSQSTRING", /* Single quoted string */
|
82
84
|
"tINTEGER", /* Integer */
|
@@ -120,7 +122,9 @@ token next_token(lexstate *state, enum TokenType type) {
|
|
120
122
|
t.range.start = state->start;
|
121
123
|
t.range.end = state->current;
|
122
124
|
state->start = state->current;
|
123
|
-
|
125
|
+
if (type != tTRIVIA) {
|
126
|
+
state->first_token_of_line = false;
|
127
|
+
}
|
124
128
|
|
125
129
|
return t;
|
126
130
|
}
|
@@ -1,83 +1,77 @@
|
|
1
1
|
#include "rbs_extension.h"
|
2
2
|
|
3
|
+
#define RBS_LOC_REQUIRED_P(loc, i) ((loc)->children->required_p & (1 << (i)))
|
4
|
+
#define RBS_LOC_OPTIONAL_P(loc, i) (!RBS_LOC_REQUIRED_P((loc), (i)))
|
5
|
+
#define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1))
|
6
|
+
|
3
7
|
VALUE RBS_Location;
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
new->name = name;
|
9
|
-
new->rg = r;
|
10
|
-
return new;
|
9
|
+
position rbs_loc_position(int char_pos) {
|
10
|
+
position pos = { 0, char_pos, -1, -1 };
|
11
|
+
return pos;
|
11
12
|
}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
} else {
|
17
|
-
return NULL;
|
18
|
-
}
|
14
|
+
position rbs_loc_position3(int char_pos, int line, int column) {
|
15
|
+
position pos = { 0, char_pos, line, column };
|
16
|
+
return pos;
|
19
17
|
}
|
20
18
|
|
21
|
-
void
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
list = next;
|
19
|
+
static void check_children_max(unsigned short n) {
|
20
|
+
size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
|
21
|
+
if (n > max) {
|
22
|
+
rb_raise(rb_eRuntimeError, "Too many children added to location: %d", n);
|
26
23
|
}
|
27
24
|
}
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
if (list->name == name) {
|
32
|
-
*rg = list->rg;
|
33
|
-
return true;
|
34
|
-
}
|
26
|
+
void rbs_loc_alloc_children(rbs_loc *loc, unsigned short cap) {
|
27
|
+
check_children_max(cap);
|
35
28
|
|
36
|
-
|
37
|
-
|
29
|
+
size_t s = RBS_LOC_CHILDREN_SIZE(cap);
|
30
|
+
loc->children = malloc(s);
|
38
31
|
|
39
|
-
|
32
|
+
loc->children->len = 0;
|
33
|
+
loc->children->required_p = 0;
|
34
|
+
loc->children->cap = cap;
|
40
35
|
}
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
static void check_children_cap(rbs_loc *loc) {
|
38
|
+
if (loc->children == NULL) {
|
39
|
+
rbs_loc_alloc_children(loc, 1);
|
40
|
+
} else {
|
41
|
+
if (loc->children->len == loc->children->cap) {
|
42
|
+
check_children_max(loc->children->cap + 1);
|
43
|
+
size_t s = RBS_LOC_CHILDREN_SIZE(++loc->children->cap);
|
44
|
+
loc->children = realloc(loc->children, s);
|
45
|
+
}
|
48
46
|
}
|
49
|
-
|
50
|
-
return size;
|
51
47
|
}
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
return pos;
|
56
|
-
}
|
49
|
+
void rbs_loc_add_required_child(rbs_loc *loc, ID name, range r) {
|
50
|
+
check_children_cap(loc);
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
52
|
+
unsigned short i = loc->children->len++;
|
53
|
+
loc->children->entries[i].name = name;
|
54
|
+
loc->children->entries[i].rg = r;
|
62
55
|
|
63
|
-
|
64
|
-
loc->requireds = rbs_loc_list_add(loc->requireds, name, r);
|
56
|
+
loc->children->required_p |= 1 << i;
|
65
57
|
}
|
66
58
|
|
67
59
|
void rbs_loc_add_optional_child(rbs_loc *loc, ID name, range r) {
|
68
|
-
|
60
|
+
check_children_cap(loc);
|
61
|
+
|
62
|
+
unsigned short i = loc->children->len++;
|
63
|
+
loc->children->entries[i].name = name;
|
64
|
+
loc->children->entries[i].rg = r;
|
69
65
|
}
|
70
66
|
|
71
67
|
void rbs_loc_init(rbs_loc *loc, VALUE buffer, range rg) {
|
72
68
|
loc->buffer = buffer;
|
73
69
|
loc->rg = rg;
|
74
|
-
loc->
|
75
|
-
loc->requireds = NULL;
|
70
|
+
loc->children = NULL;
|
76
71
|
}
|
77
72
|
|
78
73
|
void rbs_loc_free(rbs_loc *loc) {
|
79
|
-
|
80
|
-
rbs_loc_list_free(loc->requireds);
|
74
|
+
free(loc->children);
|
81
75
|
ruby_xfree(loc);
|
82
76
|
}
|
83
77
|
|
@@ -89,7 +83,11 @@ static void rbs_loc_mark(void *ptr)
|
|
89
83
|
|
90
84
|
static size_t rbs_loc_memsize(const void *ptr) {
|
91
85
|
const rbs_loc *loc = ptr;
|
92
|
-
|
86
|
+
if (loc->children == NULL) {
|
87
|
+
return sizeof(rbs_loc);
|
88
|
+
} else {
|
89
|
+
return sizeof(rbs_loc) + RBS_LOC_CHILDREN_SIZE(loc->children->cap);
|
90
|
+
}
|
93
91
|
}
|
94
92
|
|
95
93
|
static rb_data_type_t location_type = {
|
@@ -130,8 +128,10 @@ static VALUE location_initialize_copy(VALUE self, VALUE other) {
|
|
130
128
|
|
131
129
|
self_loc->buffer = other_loc->buffer;
|
132
130
|
self_loc->rg = other_loc->rg;
|
133
|
-
|
134
|
-
|
131
|
+
if (other_loc->children != NULL) {
|
132
|
+
rbs_loc_alloc_children(self_loc, other_loc->children->cap);
|
133
|
+
memcpy(self_loc->children, other_loc->children, RBS_LOC_CHILDREN_SIZE(other_loc->children->cap));
|
134
|
+
}
|
135
135
|
|
136
136
|
return Qnil;
|
137
137
|
}
|
@@ -221,18 +221,19 @@ VALUE rbs_new_location(VALUE buffer, range rg) {
|
|
221
221
|
static VALUE location_aref(VALUE self, VALUE name) {
|
222
222
|
rbs_loc *loc = rbs_check_location(self);
|
223
223
|
|
224
|
-
range result;
|
225
224
|
ID id = SYM2ID(name);
|
226
225
|
|
227
|
-
if (
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
226
|
+
if (loc->children != NULL) {
|
227
|
+
for (unsigned short i = 0; i < loc->children->len; i++) {
|
228
|
+
if (loc->children->entries[i].name == id) {
|
229
|
+
range result = loc->children->entries[i].rg;
|
230
|
+
|
231
|
+
if (RBS_LOC_OPTIONAL_P(loc, i) && null_range_p(result)) {
|
232
|
+
return Qnil;
|
233
|
+
} else {
|
234
|
+
return rbs_new_location(loc->buffer, result);
|
235
|
+
}
|
236
|
+
}
|
236
237
|
}
|
237
238
|
}
|
238
239
|
|
@@ -244,11 +245,16 @@ static VALUE location_optional_keys(VALUE self) {
|
|
244
245
|
VALUE keys = rb_ary_new();
|
245
246
|
|
246
247
|
rbs_loc *loc = rbs_check_location(self);
|
247
|
-
|
248
|
+
rbs_loc_children *children = loc->children;
|
249
|
+
if (children == NULL) {
|
250
|
+
return keys;
|
251
|
+
}
|
248
252
|
|
249
|
-
|
250
|
-
|
251
|
-
|
253
|
+
for (unsigned short i = 0; i < children->len; i++) {
|
254
|
+
if (RBS_LOC_OPTIONAL_P(loc, i)) {
|
255
|
+
rb_ary_push(keys, ID2SYM(children->entries[i].name));
|
256
|
+
|
257
|
+
}
|
252
258
|
}
|
253
259
|
|
254
260
|
return keys;
|
@@ -258,11 +264,15 @@ static VALUE location_required_keys(VALUE self) {
|
|
258
264
|
VALUE keys = rb_ary_new();
|
259
265
|
|
260
266
|
rbs_loc *loc = rbs_check_location(self);
|
261
|
-
|
267
|
+
rbs_loc_children *children = loc->children;
|
268
|
+
if (children == NULL) {
|
269
|
+
return keys;
|
270
|
+
}
|
262
271
|
|
263
|
-
|
264
|
-
|
265
|
-
|
272
|
+
for (unsigned short i = 0; i < children->len; i++) {
|
273
|
+
if (RBS_LOC_REQUIRED_P(loc, i)) {
|
274
|
+
rb_ary_push(keys, ID2SYM(children->entries[i].name));
|
275
|
+
}
|
266
276
|
}
|
267
277
|
|
268
278
|
return keys;
|
@@ -9,17 +9,26 @@
|
|
9
9
|
* */
|
10
10
|
extern VALUE RBS_Location;
|
11
11
|
|
12
|
-
typedef struct
|
12
|
+
typedef struct {
|
13
13
|
ID name;
|
14
14
|
range rg;
|
15
|
-
|
16
|
-
|
15
|
+
} rbs_loc_entry;
|
16
|
+
|
17
|
+
typedef unsigned int rbs_loc_entry_bitmap;
|
18
|
+
|
19
|
+
// The flexible array always allocates, but it's okay.
|
20
|
+
// This struct is not allocated when the `rbs_loc` doesn't have children.
|
21
|
+
typedef struct {
|
22
|
+
unsigned short len;
|
23
|
+
unsigned short cap;
|
24
|
+
rbs_loc_entry_bitmap required_p;
|
25
|
+
rbs_loc_entry entries[1];
|
26
|
+
} rbs_loc_children;
|
17
27
|
|
18
28
|
typedef struct {
|
19
29
|
VALUE buffer;
|
20
30
|
range rg;
|
21
|
-
|
22
|
-
rbs_loc_list *optionals;
|
31
|
+
rbs_loc_children *children; // NULL when no children is allocated
|
23
32
|
} rbs_loc;
|
24
33
|
|
25
34
|
/**
|
@@ -32,13 +41,24 @@ VALUE rbs_new_location(VALUE buffer, range rg);
|
|
32
41
|
* */
|
33
42
|
rbs_loc *rbs_check_location(VALUE location);
|
34
43
|
|
44
|
+
/**
|
45
|
+
* Allocate memory for child locations.
|
46
|
+
*
|
47
|
+
* Do not call twice for the same location.
|
48
|
+
* */
|
49
|
+
void rbs_loc_alloc_children(rbs_loc *loc, unsigned short cap);
|
50
|
+
|
35
51
|
/**
|
36
52
|
* Add a required child range with given name.
|
53
|
+
*
|
54
|
+
* Allocate memory for children with rbs_loc_alloc_children before calling this function.
|
37
55
|
* */
|
38
56
|
void rbs_loc_add_required_child(rbs_loc *loc, ID name, range r);
|
39
57
|
|
40
58
|
/**
|
41
59
|
* Add an optional child range with given name.
|
60
|
+
*
|
61
|
+
* Allocate memory for children with rbs_loc_alloc_children before calling this function.
|
42
62
|
* */
|
43
63
|
void rbs_loc_add_optional_child(rbs_loc *loc, ID name, range r);
|
44
64
|
|