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/core/time.rbs
CHANGED
@@ -389,6 +389,26 @@
|
|
389
389
|
# You can define this method per subclasses, or on the toplevel Time class.
|
390
390
|
#
|
391
391
|
class Time < Object
|
392
|
+
# A type that's used for timeouts.
|
393
|
+
#
|
394
|
+
# All numeric types implement this, but custom classes can also implement it if desired.
|
395
|
+
#
|
396
|
+
# Usage of `Time::_Timeout` is fairly common throughout the stdlib, such as in `Kernel#sleep`,
|
397
|
+
# `IO#timeout=`, and `TCPSocket#new`'s `connet_timeout` field.
|
398
|
+
interface _Timeout
|
399
|
+
# Returns `[seconds, nanoseconds]`.
|
400
|
+
#
|
401
|
+
# The `seconds` should be a whole number of seconds, whereas the `nanoseconds` should be smaller
|
402
|
+
# than one. For example, `3.125.divmod(1)` would yield `[3, 0.125]`
|
403
|
+
def divmod: (1) -> [int, _TimeoutNSecs]
|
404
|
+
end
|
405
|
+
|
406
|
+
# The nanoseconds part of `Time::_Timeout`'s return value. See it for details
|
407
|
+
interface _TimeoutNSecs
|
408
|
+
# Convert `self` into a whole number of seconds.
|
409
|
+
def *: (1_000_000_000) -> int
|
410
|
+
end
|
411
|
+
|
392
412
|
include Comparable
|
393
413
|
|
394
414
|
# <!--
|
@@ -1083,8 +1103,8 @@ class Time < Object
|
|
1083
1103
|
# More digits will be truncated, as other operations of `Time`. Ignored
|
1084
1104
|
# unless the first argument is a string.
|
1085
1105
|
#
|
1086
|
-
def initialize: (?Integer
|
1087
|
-
| (?Integer
|
1106
|
+
def initialize: (?Integer year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, ?String | Integer | nil) -> void
|
1107
|
+
| (?Integer year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, in: String | Integer | nil) -> void
|
1088
1108
|
| (String, ?in: string | int | nil, ?precision: int) -> void
|
1089
1109
|
|
1090
1110
|
# <!--
|
@@ -1333,7 +1353,7 @@ class Time < Object
|
|
1333
1353
|
# The returned array is suitable for use as an argument to Time.utc or
|
1334
1354
|
# Time.local to create a new `Time` object.
|
1335
1355
|
#
|
1336
|
-
def to_a: () -> [ Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, bool, String ]
|
1356
|
+
def to_a: () -> [ Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, bool, String? ]
|
1337
1357
|
|
1338
1358
|
# <!--
|
1339
1359
|
# rdoc-file=time.c
|
@@ -1564,7 +1584,7 @@ class Time < Object
|
|
1564
1584
|
# Time.utc(2000, 1, 1).zone # => "UTC"
|
1565
1585
|
# Time.new(2000, 1, 1).zone # => "Central Standard Time"
|
1566
1586
|
#
|
1567
|
-
def zone: () -> String
|
1587
|
+
def zone: () -> String?
|
1568
1588
|
|
1569
1589
|
# <!-- rdoc-file=time.c -->
|
1570
1590
|
# Like Time.utc, except that the returned `Time` object has the local timezone,
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Architecture
|
2
|
+
|
3
|
+
This guide describes the outline of the architecture of RBS library. It helps you to understand the structure and key features of the library to start contributing to the library.
|
4
|
+
|
5
|
+
## Bird's Eye View
|
6
|
+
|
7
|
+
The goal of the library is simple: Read RBS files and generate the structure of Ruby programs.
|
8
|
+
|
9
|
+
```
|
10
|
+
RBS files
|
11
|
+
↓ -- RBS::Parser
|
12
|
+
Syntax tree
|
13
|
+
↓
|
14
|
+
Environment
|
15
|
+
↓ -- Definition builder
|
16
|
+
Definition
|
17
|
+
```
|
18
|
+
|
19
|
+
The input is RBS files. The gem ships with RBS type definitions of Ruby core library and some of the standard libraries. You write RBS files for your applications or gems.
|
20
|
+
|
21
|
+
Syntax tree is the next representation. `RBS::Parser` transforms the sequence of characters in RBS files into syntax trees.
|
22
|
+
|
23
|
+
Syntax tree objects are loaded to `RBS::Environment`. It collects loaded RBS objects, organizes the definitions, and provides some utilities, like resolving type names and finding the declarations.
|
24
|
+
|
25
|
+
`RBS::Definition` is the goal of the transformation steps. It is associated with a class singleton, a class object, or an interface. You can find the list of available methods and their types, instance variables, and class hierarchies.
|
26
|
+
|
27
|
+
## Core classes
|
28
|
+
|
29
|
+
### Types
|
30
|
+
|
31
|
+
Types are defined under `RBS::Types`, like `RBS::Types::ClassInstance` or `RBS::Types::Union`. You will find the definition of each type supported in RBS.
|
32
|
+
|
33
|
+
### Parsing RBS files
|
34
|
+
|
35
|
+
The RBS source code is loaded into `RBS::Buffer`, and `RBS::Parser` is the parser. The parser is implemented in C extension.
|
36
|
+
|
37
|
+
`RBS::Parser` provides three entrypoints.
|
38
|
+
|
39
|
+
- `RBS::Parser.parse_method_type` parsers a *method type*. (`[T] (String) { (IO) -> T } -> Array[T]`)
|
40
|
+
- `RBS::Parser.parse_type` parses a *type*. (`Hash[Symbol, untyped]`)
|
41
|
+
- `RBS::Parser.parse_signature` parses the whole RBS file.
|
42
|
+
|
43
|
+
### Environment
|
44
|
+
|
45
|
+
RBS AST is loaded to `RBS::Environment` by `RBS::EnvironmentLoader`. `Environment` gives *absolute names* to the declarations, and provides an index from the *absolute name* to their declarations.
|
46
|
+
|
47
|
+
Assume we have the following nested RBS declarations:
|
48
|
+
|
49
|
+
```rbs
|
50
|
+
module Hello
|
51
|
+
class World
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Hello::World
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
And the environment organizes the definitions as follows:
|
60
|
+
|
61
|
+
- There are two classes `::Hello` and `::Hello::World`
|
62
|
+
- It provides a mapping from `::Hello` to it's `module` declaration and `::Hello::World` to it's two `class` declarations
|
63
|
+
|
64
|
+
### Definition and DefinitionBuilder
|
65
|
+
|
66
|
+
`RBS::Definition` tells you:
|
67
|
+
|
68
|
+
- The set of available methods in a class/module/interface
|
69
|
+
- The set of instance variables in a class/module
|
70
|
+
- The ancestors in a class/module
|
71
|
+
|
72
|
+
Definition is constructed for:
|
73
|
+
|
74
|
+
- A singleton class of a class/module -- `singleton(String)`, `singleton(Array)`,
|
75
|
+
- An instance of a class -- `String`, `Array[T]`, or
|
76
|
+
- An interface -- `_ToS`
|
77
|
+
|
78
|
+
Note that generic class instances/interfaces are kept generic. We don't have a definition of `Array[String]` but of `Array[T]`.
|
79
|
+
|
80
|
+
`DefinitionBuilder` constructs `Definition` of given type names.
|
81
|
+
|
82
|
+
- `DefinitionBuilder#build_singleton` returns a definition of singleton classes of given class/module.
|
83
|
+
- `DefinitionBuilder#build_instance` returns a definition of instances of given class/module.
|
84
|
+
- `DefinitionBuilder#build_interface` returns a definition of interfaces.
|
85
|
+
|
86
|
+
It uses `AncestorBuilder` to construct ancestor chains of the type. `MethodBuilder` constructs sets of available methods based on the ancestor chains.
|
87
|
+
|
88
|
+
The `#build_singleton` calculates the type of `.new` methods based on the definition of `#initialize` method. This is different from Ruby's implementation -- it reused `Class#new` method but we need the custom implementation to give precise `.new` method type of each class.
|
89
|
+
|
90
|
+
#### Working with type aliases
|
91
|
+
|
92
|
+
`DefinitionBuilder#expand_alias` and its variants provide one step *unfold* operation of type aliases.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
builder.expand_alias2(TypeName("::int"), []) # => returns `::Integer | ::_ToInt`
|
96
|
+
```
|
97
|
+
|
98
|
+
We don't have *normalize* operation for type aliases, because RBS allows recursive type alias definition, which cannot be *fully* unfolded.
|
99
|
+
|
100
|
+
### Other utilities
|
101
|
+
|
102
|
+
`RBS::Validator` provides validation of RBS type declaration. It validates that all of the type name references can be resolved, all type applications have correct arity, and so on.
|
103
|
+
|
104
|
+
`RBS::Test` provides runtime type checking, which confirms if a Ruby object can have an RBS type. It also provides an integration to existing Ruby code so that we run Ruby code, assuming unit tests, with runtime type checking.
|
105
|
+
|
106
|
+
`RBS::UnitTest` provides utilities to help write unit tests for RBS type definitions. Use the tool to make sure your RBS type definition is consistent with implementation.
|
107
|
+
|
108
|
+
`RBS::Prototype` is the core of `rbs prototype` feature. It scans Ruby source code or uses reflection features, and it generates the prototype of RBS files.
|
109
|
+
|
110
|
+
`RBS::Collection` includes `rbs collection` features.
|
data/docs/gem.md
CHANGED
data/docs/syntax.md
CHANGED
@@ -45,6 +45,7 @@ _literal_ ::= _string-literal_
|
|
45
45
|
| `false`
|
46
46
|
|
47
47
|
_proc_ ::= `^` _parameters?_ _self-type-binding?_ _block?_ `->` _type_
|
48
|
+
| `^` `(` `?` `)` `->` _type_ # Proc type with untyped parameter
|
48
49
|
```
|
49
50
|
|
50
51
|
### Class instance type
|
@@ -310,6 +311,7 @@ end
|
|
310
311
|
|
311
312
|
```markdown
|
312
313
|
_method-type_ ::= _parameters?_ _block?_ `->` _type_ # Method type
|
314
|
+
| `(` `?` `)` `->` _type_ # Method type with untyped parameters
|
313
315
|
|
314
316
|
_parameters?_ ::= (Empty)
|
315
317
|
| _parameters_ (Parameters)
|
@@ -333,9 +335,11 @@ _var-name_ ::= /[a-z]\w*/
|
|
333
335
|
_self-type-binding?_ = (Empty)
|
334
336
|
| `[` `self` `:` _type_ `]` (Self type binding)
|
335
337
|
|
336
|
-
_block?_ =
|
338
|
+
_block?_ = (No block)
|
337
339
|
| `{` _parameters_ _self-type-binding?_ `->` _type_ `}` (Block)
|
340
|
+
| `{` `(` `?` `)` `->` _type_ `}` (Block with untyped parameters)
|
338
341
|
| `?` `{` _parameters_ _self-type-binding?_ `->` _type_ `}` (Optional block)
|
342
|
+
| `?` `{` `(` `?` `)` `->` _type_ `}` (Optional block with untyped parameters)
|
339
343
|
```
|
340
344
|
|
341
345
|
### Parameters
|
@@ -61,6 +61,7 @@ VALUE RBS_Types_ClassInstance;
|
|
61
61
|
VALUE RBS_Types_ClassSingleton;
|
62
62
|
VALUE RBS_Types_Function_Param;
|
63
63
|
VALUE RBS_Types_Function;
|
64
|
+
VALUE RBS_Types_UntypedFunction;
|
64
65
|
VALUE RBS_Types_Interface;
|
65
66
|
VALUE RBS_Types_Intersection;
|
66
67
|
VALUE RBS_Types_Literal;
|
@@ -138,6 +139,7 @@ void rbs__init_constants(void) {
|
|
138
139
|
IMPORT_CONSTANT(RBS_Types_ClassInstance, RBS_Types, "ClassInstance");
|
139
140
|
IMPORT_CONSTANT(RBS_Types_ClassSingleton, RBS_Types, "ClassSingleton");
|
140
141
|
IMPORT_CONSTANT(RBS_Types_Function, RBS_Types, "Function");
|
142
|
+
IMPORT_CONSTANT(RBS_Types_UntypedFunction, RBS_Types, "UntypedFunction");
|
141
143
|
IMPORT_CONSTANT(RBS_Types_Function_Param, RBS_Types_Function, "Param");
|
142
144
|
IMPORT_CONSTANT(RBS_Types_Interface, RBS_Types, "Interface");
|
143
145
|
IMPORT_CONSTANT(RBS_Types_Intersection, RBS_Types, "Intersection");
|
@@ -64,6 +64,7 @@ extern VALUE RBS_Types_ClassInstance;
|
|
64
64
|
extern VALUE RBS_Types_ClassSingleton;
|
65
65
|
extern VALUE RBS_Types_Function_Param;
|
66
66
|
extern VALUE RBS_Types_Function;
|
67
|
+
extern VALUE RBS_Types_UntypedFunction;
|
67
68
|
extern VALUE RBS_Types_Interface;
|
68
69
|
extern VALUE RBS_Types_Intersection;
|
69
70
|
extern VALUE RBS_Types_Literal;
|