rigortype 0.0.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 +7 -0
- data/LICENSE +373 -0
- data/README.md +152 -0
- data/exe/rigor +9 -0
- data/lib/rigor/analysis/check_rules.rb +503 -0
- data/lib/rigor/analysis/diagnostic.rb +35 -0
- data/lib/rigor/analysis/fact_store.rb +133 -0
- data/lib/rigor/analysis/result.rb +29 -0
- data/lib/rigor/analysis/runner.rb +119 -0
- data/lib/rigor/ast/type_node.rb +41 -0
- data/lib/rigor/ast.rb +22 -0
- data/lib/rigor/cli/type_of_command.rb +160 -0
- data/lib/rigor/cli/type_of_renderer.rb +88 -0
- data/lib/rigor/cli/type_scan_command.rb +160 -0
- data/lib/rigor/cli/type_scan_renderer.rb +165 -0
- data/lib/rigor/cli/type_scan_report.rb +32 -0
- data/lib/rigor/cli.rb +195 -0
- data/lib/rigor/configuration.rb +49 -0
- data/lib/rigor/environment/class_registry.rb +141 -0
- data/lib/rigor/environment/rbs_hierarchy.rb +64 -0
- data/lib/rigor/environment/rbs_loader.rb +244 -0
- data/lib/rigor/environment.rb +177 -0
- data/lib/rigor/inference/acceptance.rb +444 -0
- data/lib/rigor/inference/block_parameter_binder.rb +198 -0
- data/lib/rigor/inference/closure_escape_analyzer.rb +191 -0
- data/lib/rigor/inference/coverage_scanner.rb +85 -0
- data/lib/rigor/inference/expression_typer.rb +831 -0
- data/lib/rigor/inference/fallback.rb +35 -0
- data/lib/rigor/inference/fallback_tracer.rb +64 -0
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +102 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +169 -0
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +421 -0
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +336 -0
- data/lib/rigor/inference/method_dispatcher.rb +213 -0
- data/lib/rigor/inference/method_parameter_binder.rb +257 -0
- data/lib/rigor/inference/multi_target_binder.rb +143 -0
- data/lib/rigor/inference/narrowing.rb +1008 -0
- data/lib/rigor/inference/rbs_type_translator.rb +219 -0
- data/lib/rigor/inference/scope_indexer.rb +468 -0
- data/lib/rigor/inference/statement_evaluator.rb +1017 -0
- data/lib/rigor/rbs_extended.rb +98 -0
- data/lib/rigor/scope.rb +340 -0
- data/lib/rigor/source/node_locator.rb +104 -0
- data/lib/rigor/source/node_walker.rb +37 -0
- data/lib/rigor/source.rb +15 -0
- data/lib/rigor/testing.rb +65 -0
- data/lib/rigor/trinary.rb +108 -0
- data/lib/rigor/type/accepts_result.rb +109 -0
- data/lib/rigor/type/bot.rb +57 -0
- data/lib/rigor/type/combinator.rb +148 -0
- data/lib/rigor/type/constant.rb +90 -0
- data/lib/rigor/type/dynamic.rb +60 -0
- data/lib/rigor/type/hash_shape.rb +246 -0
- data/lib/rigor/type/nominal.rb +83 -0
- data/lib/rigor/type/singleton.rb +65 -0
- data/lib/rigor/type/top.rb +56 -0
- data/lib/rigor/type/tuple.rb +84 -0
- data/lib/rigor/type/union.rb +65 -0
- data/lib/rigor/type.rb +23 -0
- data/lib/rigor/version.rb +5 -0
- data/lib/rigor.rb +29 -0
- data/sig/rigor/analysis/fact_store.rbs +51 -0
- data/sig/rigor/ast.rbs +11 -0
- data/sig/rigor/environment.rbs +59 -0
- data/sig/rigor/inference.rbs +151 -0
- data/sig/rigor/rbs_extended.rbs +22 -0
- data/sig/rigor/scope.rbs +49 -0
- data/sig/rigor/source.rbs +20 -0
- data/sig/rigor/testing.rbs +9 -0
- data/sig/rigor/trinary.rbs +29 -0
- data/sig/rigor/type.rbs +171 -0
- data/sig/rigor.rbs +70 -0
- metadata +260 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module Analysis
|
|
3
|
+
module CheckRules
|
|
4
|
+
def self?.diagnose: (path: String, root: untyped, scope_index: Hash[untyped, Scope]) -> Array[Diagnostic]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class FactStore
|
|
8
|
+
type bucket = :local_binding | :captured_local | :object_content | :global_storage | :dynamic_origin | :relational
|
|
9
|
+
type polarity = :positive | :negative
|
|
10
|
+
type stability = :local_binding | :unstable | :pure | :immutable
|
|
11
|
+
|
|
12
|
+
BUCKETS: Array[bucket]
|
|
13
|
+
|
|
14
|
+
class Target
|
|
15
|
+
attr_reader kind: Symbol
|
|
16
|
+
attr_reader name: untyped
|
|
17
|
+
def self.local: (String | Symbol name) -> Target
|
|
18
|
+
def self.new: (kind: Symbol, name: untyped) -> Target
|
|
19
|
+
def initialize: (kind: Symbol, name: untyped) -> void
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Fact
|
|
23
|
+
attr_reader bucket: bucket
|
|
24
|
+
attr_reader target: Target | Array[Target]
|
|
25
|
+
attr_reader predicate: Symbol
|
|
26
|
+
attr_reader payload: untyped
|
|
27
|
+
attr_reader polarity: polarity
|
|
28
|
+
attr_reader stability: stability
|
|
29
|
+
def self.new: (bucket: bucket, target: Target | Array[Target], predicate: Symbol, ?payload: untyped, ?polarity: polarity, ?stability: stability) -> Fact
|
|
30
|
+
def initialize: (bucket: bucket, target: Target | Array[Target], predicate: Symbol, ?payload: untyped, ?polarity: polarity, ?stability: stability) -> void
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
attr_reader facts: Array[Fact]
|
|
34
|
+
|
|
35
|
+
def self.empty: () -> FactStore
|
|
36
|
+
|
|
37
|
+
def initialize: (?facts: Array[Fact]) -> void
|
|
38
|
+
def empty?: () -> bool
|
|
39
|
+
def with_fact: (Fact fact) -> FactStore
|
|
40
|
+
def with_local_fact: (String | Symbol name, predicate: Symbol, ?payload: untyped, ?bucket: bucket, ?polarity: polarity) -> FactStore
|
|
41
|
+
def facts_for: (?target: Target?, ?bucket: bucket?) -> Array[Fact]
|
|
42
|
+
def invalidate_target: (Target target, ?buckets: Array[bucket]?) -> FactStore
|
|
43
|
+
def join: (FactStore other) -> FactStore
|
|
44
|
+
def ==: (untyped other) -> bool
|
|
45
|
+
def eql?: (untyped other) -> bool
|
|
46
|
+
def hash: () -> Integer
|
|
47
|
+
def normalize: (Array[Fact] raw_facts) -> Array[Fact]
|
|
48
|
+
def fact_targets: (Fact fact) -> Array[Target]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/sig/rigor/ast.rbs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
class Environment
|
|
3
|
+
type ordering = :equal | :subclass | :superclass | :disjoint | :unknown
|
|
4
|
+
|
|
5
|
+
DEFAULT_LIBRARIES: Array[String]
|
|
6
|
+
|
|
7
|
+
attr_reader class_registry: ClassRegistry
|
|
8
|
+
attr_reader rbs_loader: RbsLoader?
|
|
9
|
+
|
|
10
|
+
def self.default: () -> Environment
|
|
11
|
+
def self.for_project: (?root: String, ?libraries: Array[String], ?signature_paths: Array[String | _ToPath]?) -> Environment
|
|
12
|
+
|
|
13
|
+
def initialize: (?class_registry: ClassRegistry, ?rbs_loader: RbsLoader?) -> void
|
|
14
|
+
def nominal_for_name: (String | Symbol name) -> Type::Nominal?
|
|
15
|
+
def singleton_for_name: (String | Symbol name) -> Type::Singleton?
|
|
16
|
+
def constant_for_name: (String | Symbol name) -> Type::t?
|
|
17
|
+
def class_known?: (String | Symbol name) -> bool
|
|
18
|
+
def class_ordering: (String | Symbol lhs, String | Symbol rhs) -> ordering
|
|
19
|
+
|
|
20
|
+
class ClassRegistry
|
|
21
|
+
def self.default: () -> ClassRegistry
|
|
22
|
+
def self.build_default: () -> ClassRegistry
|
|
23
|
+
def initialize: () -> void
|
|
24
|
+
def register: (Module class_object) -> void
|
|
25
|
+
def registered?: (Module class_object) -> bool
|
|
26
|
+
def nominal_for: (Module class_object) -> Type::Nominal
|
|
27
|
+
def nominal_for_name: (String | Symbol name) -> Type::Nominal?
|
|
28
|
+
def class_ordering: (String | Symbol lhs, String | Symbol rhs) -> ordering
|
|
29
|
+
def normalize_name: (Module | String | Symbol name) -> String
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class RbsLoader
|
|
33
|
+
attr_reader libraries: Array[String]
|
|
34
|
+
attr_reader signature_paths: Array[String | _ToPath]
|
|
35
|
+
|
|
36
|
+
def self.default: () -> RbsLoader
|
|
37
|
+
def self.reset_default!: () -> void
|
|
38
|
+
|
|
39
|
+
def initialize: (?libraries: Array[String], ?signature_paths: Array[String | _ToPath]) -> void
|
|
40
|
+
def class_known?: (String | Symbol name) -> bool
|
|
41
|
+
def instance_definition: (String | Symbol class_name) -> untyped
|
|
42
|
+
def instance_method: (class_name: String | Symbol, method_name: String | Symbol) -> untyped
|
|
43
|
+
def singleton_definition: (String | Symbol class_name) -> untyped
|
|
44
|
+
def singleton_method: (class_name: String | Symbol, method_name: String | Symbol) -> untyped
|
|
45
|
+
def class_type_param_names: (String | Symbol class_name) -> Array[Symbol]
|
|
46
|
+
def class_ordering: (String | Symbol lhs, String | Symbol rhs) -> ordering
|
|
47
|
+
def constant_type: (String name) -> Type::t?
|
|
48
|
+
def instance_definition: (String | Symbol class_name) -> untyped?
|
|
49
|
+
def singleton_definition: (String | Symbol class_name) -> untyped?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class RbsHierarchy
|
|
53
|
+
def initialize: (RbsLoader loader) -> void
|
|
54
|
+
def class_ordering: (String | Symbol lhs, String | Symbol rhs) -> ordering
|
|
55
|
+
def loader: () -> RbsLoader
|
|
56
|
+
def normalize_name: (String | Symbol name) -> String
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module Inference
|
|
3
|
+
type closure_classification = :non_escaping | :escaping | :unknown
|
|
4
|
+
|
|
5
|
+
class ExpressionTyper
|
|
6
|
+
def initialize: (scope: Scope, ?tracer: FallbackTracer?) -> void
|
|
7
|
+
def type_of: (untyped node) -> Type::t
|
|
8
|
+
def scope: () -> Scope
|
|
9
|
+
def tracer: () -> FallbackTracer?
|
|
10
|
+
def dynamic_top: () -> Type::Dynamic
|
|
11
|
+
def statements_or_nil: (untyped statements_node) -> Type::t
|
|
12
|
+
def fallback_for: (untyped node, family: Symbol) -> Type::t
|
|
13
|
+
def record_fallback: (untyped node, family: Symbol, inner_type: Type::t) -> void
|
|
14
|
+
def type_of_virtual: (untyped node) -> Type::t
|
|
15
|
+
def call_receiver_type_for: (untyped node) -> Type::t?
|
|
16
|
+
def call_arg_types: (untyped node) -> Array[Type::t]
|
|
17
|
+
def block_return_type_for: (untyped call_node, Type::t? receiver_type, Array[Type::t] arg_types) -> Type::t?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class StatementEvaluator
|
|
21
|
+
class ClassFrame
|
|
22
|
+
attr_reader name: String
|
|
23
|
+
attr_reader singleton: bool
|
|
24
|
+
def self.new: (name: String, singleton: bool) -> ClassFrame
|
|
25
|
+
def initialize: (name: String, singleton: bool) -> void
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def initialize: (scope: Scope, ?tracer: FallbackTracer?, ?on_enter: (^(untyped, Scope) -> void)?, ?class_context: Array[ClassFrame]) -> void
|
|
29
|
+
def evaluate: (untyped node) -> [Type::t, Scope]
|
|
30
|
+
def scope: () -> Scope
|
|
31
|
+
def tracer: () -> FallbackTracer?
|
|
32
|
+
def sub_eval: (untyped node, Scope with_scope, ?class_context: Array[ClassFrame]) -> [Type::t, Scope]
|
|
33
|
+
def eval_branch_or_nil: (untyped? branch_node, Scope branch_scope) -> [Type::t, Scope]
|
|
34
|
+
def join_with_nil_injection: (Scope scope_a, Scope scope_b) -> Scope
|
|
35
|
+
def reduce_scopes_with_nil_injection: (Array[Scope] scopes) -> Scope
|
|
36
|
+
def call_arg_types_for: (untyped call_node) -> Array[Type::t]
|
|
37
|
+
def expected_block_param_types_for: (untyped call_node) -> Array[Type::t]
|
|
38
|
+
def build_block_entry_scope: (untyped call_node, untyped block_node) -> Scope
|
|
39
|
+
def build_method_entry_scope: (untyped def_node) -> Scope
|
|
40
|
+
def current_class_path: () -> String?
|
|
41
|
+
def current_frame_singleton?: () -> bool
|
|
42
|
+
def singleton_def?: (untyped def_node) -> bool
|
|
43
|
+
def self_type_for_class_body: (Array[ClassFrame] class_context) -> Type::t?
|
|
44
|
+
def self_type_for_method_body: (singleton: bool) -> Type::t?
|
|
45
|
+
def qualified_name_for: (untyped constant_path_node) -> String?
|
|
46
|
+
def render_constant_path: (untyped node) -> String
|
|
47
|
+
def singleton_context_for: (untyped node) -> Array[ClassFrame]
|
|
48
|
+
def captured_local_writes: (untyped block_node, Scope base_scope) -> Array[Symbol]
|
|
49
|
+
def block_introduced_locals: (untyped block_node) -> Set[Symbol]
|
|
50
|
+
def drop_captured_narrowing: (untyped block_node, Scope base_scope) -> Scope
|
|
51
|
+
def classify_closure_escape: (untyped call_node) -> closure_classification
|
|
52
|
+
def record_closure_escape_if_any: (untyped node) -> Scope
|
|
53
|
+
def evaluate_block_if_present: (untyped node) -> void
|
|
54
|
+
def eval_class_body: (untyped node, Array[ClassFrame] new_context) -> [Type::t, Scope]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
module MethodDispatcher
|
|
58
|
+
def self?.dispatch: (receiver_type: Type::t?, method_name: Symbol, arg_types: Array[Type::t], ?block_type: Type::t?, ?environment: Environment?) -> Type::t?
|
|
59
|
+
def self?.expected_block_param_types: (receiver_type: Type::t?, method_name: Symbol, arg_types: Array[Type::t], ?environment: Environment?) -> Array[Type::t]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class MethodParameterBinder
|
|
63
|
+
def initialize: (environment: Environment, class_path: String, singleton: bool) -> void
|
|
64
|
+
def bind: (untyped def_node) -> Hash[Symbol, Type::t]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class BlockParameterBinder
|
|
68
|
+
def initialize: (?expected_param_types: Array[Type::t]) -> void
|
|
69
|
+
def bind: (untyped block_node) -> Hash[Symbol, Type::t]
|
|
70
|
+
def positional_type_at: (Integer index) -> Type::t
|
|
71
|
+
def bind_numbered_parameters: (untyped numbered_node) -> Hash[Symbol, Type::t]
|
|
72
|
+
def bind_block_parameters: (untyped params_root) -> Hash[Symbol, Type::t]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
module MultiTargetBinder
|
|
76
|
+
def self?.bind: (untyped target_node, Type::t rhs_type) -> Hash[Symbol, Type::t]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
module Narrowing
|
|
80
|
+
def self?.narrow_truthy: (Type::t type) -> Type::t
|
|
81
|
+
def self?.narrow_falsey: (Type::t type) -> Type::t
|
|
82
|
+
def self?.narrow_nil: (Type::t type) -> Type::t
|
|
83
|
+
def self?.narrow_non_nil: (Type::t type) -> Type::t
|
|
84
|
+
def self?.narrow_equal: (Type::t type, untyped literal) -> Type::t
|
|
85
|
+
def self?.narrow_not_equal: (Type::t type, untyped literal) -> Type::t
|
|
86
|
+
def self?.narrow_class: (Type::t type, String class_name, ?exact: bool, ?environment: Environment) -> Type::t
|
|
87
|
+
def self?.narrow_not_class: (Type::t type, String class_name, ?exact: bool, ?environment: Environment) -> Type::t
|
|
88
|
+
def self?.predicate_scopes: (untyped node, Scope scope) -> [Scope, Scope]
|
|
89
|
+
def self?.case_when_scopes: (untyped subject, Array[untyped] conditions, Scope scope) -> [Scope, Scope]
|
|
90
|
+
def self?.analyse: (untyped node, Scope scope) -> untyped
|
|
91
|
+
def self?.subclass_of?: (String rigor_class_name, String target_class_name, untyped context) -> bool
|
|
92
|
+
def self?.class_ordering: (String lhs, String rhs, untyped context) -> Symbol
|
|
93
|
+
def self?.trusted_equality_literal?: (untyped literal) -> bool
|
|
94
|
+
def self?.falsey_value?: (untyped value) -> bool
|
|
95
|
+
def self?.falsey_nominal?: (Type::Nominal nominal) -> bool
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
module ClosureEscapeAnalyzer
|
|
99
|
+
def self?.classify: (receiver_type: Type::t?, method_name: Symbol, ?environment: Environment?) -> closure_classification
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
module Acceptance
|
|
103
|
+
def self?.accepts: (Type::t self_type, Type::t other_type, ?mode: Type::accepts_mode) -> Type::AcceptsResult
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
module RbsTypeTranslator
|
|
107
|
+
def self.translate: (untyped rbs_type, ?self_type: Type::t?, ?instance_type: Type::t?, ?type_vars: Hash[Symbol, Type::t]) -> Type::t
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class Fallback
|
|
111
|
+
attr_reader node_class: Class
|
|
112
|
+
attr_reader location: untyped
|
|
113
|
+
attr_reader family: Symbol
|
|
114
|
+
attr_reader inner_type: Type::t
|
|
115
|
+
def initialize: (node_class: Class, location: untyped, family: Symbol, inner_type: Type::t) -> void
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class FallbackTracer
|
|
119
|
+
def initialize: () -> void
|
|
120
|
+
def events: () -> Array[Fallback]
|
|
121
|
+
def record_fallback: (Fallback event) -> void
|
|
122
|
+
def empty?: () -> bool
|
|
123
|
+
def size: () -> Integer
|
|
124
|
+
def each: () { (Fallback) -> void } -> self
|
|
125
|
+
| () -> Enumerator[Fallback, self]
|
|
126
|
+
def kinds: () -> Array[Class]
|
|
127
|
+
def families: () -> Array[Symbol]
|
|
128
|
+
def clear: () -> void
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
module ScopeIndexer
|
|
132
|
+
def self?.index: (untyped root, default_scope: Scope) -> Hash[untyped, Scope]
|
|
133
|
+
def self?.build_declaration_overrides: (untyped root) -> Hash[untyped, Type::t]
|
|
134
|
+
def self?.record_declarations: (untyped node, Array[String] qualified_prefix, Hash[untyped, Type::t] table) -> void
|
|
135
|
+
def self?.qualified_name_for: (untyped constant_path_node) -> String?
|
|
136
|
+
def self?.render_constant_path: (untyped node) -> String
|
|
137
|
+
def self?.propagate: (untyped node, Hash[untyped, Scope] table, Scope parent_scope) -> void
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
class CoverageScanner
|
|
141
|
+
class Stats
|
|
142
|
+
def visited_count: () -> Integer
|
|
143
|
+
def unrecognized_count: () -> Integer
|
|
144
|
+
def unrecognized_ratio: () -> Float
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def initialize: (?scope: Scope?) -> void
|
|
148
|
+
def scan: (untyped root) -> Stats
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module RbsExtended
|
|
3
|
+
DIRECTIVE_PREFIX: String
|
|
4
|
+
|
|
5
|
+
type predicate_edge = :truthy_only | :falsey_only
|
|
6
|
+
type target_kind = :parameter | :self
|
|
7
|
+
|
|
8
|
+
class PredicateEffect
|
|
9
|
+
attr_reader edge: predicate_edge
|
|
10
|
+
attr_reader target_kind: target_kind
|
|
11
|
+
attr_reader target_name: Symbol
|
|
12
|
+
attr_reader class_name: String
|
|
13
|
+
|
|
14
|
+
def self.new: (edge: predicate_edge, target_kind: target_kind, target_name: Symbol, class_name: String) -> PredicateEffect
|
|
15
|
+
def truthy_only?: () -> bool
|
|
16
|
+
def falsey_only?: () -> bool
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self?.read_predicate_effects: (untyped method_def) -> Array[PredicateEffect]
|
|
20
|
+
def self?.parse_predicate_annotation: (String string) -> PredicateEffect?
|
|
21
|
+
end
|
|
22
|
+
end
|
data/sig/rigor/scope.rbs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
class Scope
|
|
3
|
+
attr_reader environment: Environment
|
|
4
|
+
attr_reader locals: Hash[Symbol, Type::t]
|
|
5
|
+
attr_reader fact_store: Analysis::FactStore
|
|
6
|
+
attr_reader self_type: Type::t?
|
|
7
|
+
attr_reader declared_types: Hash[untyped, Type::t]
|
|
8
|
+
attr_reader ivars: Hash[Symbol, Type::t]
|
|
9
|
+
attr_reader cvars: Hash[Symbol, Type::t]
|
|
10
|
+
attr_reader globals: Hash[Symbol, Type::t]
|
|
11
|
+
attr_reader class_ivars: Hash[String, Hash[Symbol, Type::t]]
|
|
12
|
+
attr_reader class_cvars: Hash[String, Hash[Symbol, Type::t]]
|
|
13
|
+
attr_reader program_globals: Hash[Symbol, Type::t]
|
|
14
|
+
attr_reader discovered_classes: Hash[String, Type::Singleton]
|
|
15
|
+
attr_reader in_source_constants: Hash[String, Type::t]
|
|
16
|
+
attr_reader discovered_methods: Hash[String, Hash[Symbol, Symbol]]
|
|
17
|
+
|
|
18
|
+
def self.empty: (?environment: Environment) -> Scope
|
|
19
|
+
|
|
20
|
+
def initialize: (environment: Environment, locals: Hash[Symbol, Type::t], ?fact_store: Analysis::FactStore, ?self_type: Type::t?, ?declared_types: Hash[untyped, Type::t], ?ivars: Hash[Symbol, Type::t], ?cvars: Hash[Symbol, Type::t], ?globals: Hash[Symbol, Type::t]) -> void
|
|
21
|
+
def local: (String | Symbol name) -> Type::t?
|
|
22
|
+
def ivar: (String | Symbol name) -> Type::t?
|
|
23
|
+
def cvar: (String | Symbol name) -> Type::t?
|
|
24
|
+
def global: (String | Symbol name) -> Type::t?
|
|
25
|
+
def with_local: (String | Symbol name, Type::t type) -> Scope
|
|
26
|
+
def with_ivar: (String | Symbol name, Type::t type) -> Scope
|
|
27
|
+
def with_cvar: (String | Symbol name, Type::t type) -> Scope
|
|
28
|
+
def with_global: (String | Symbol name, Type::t type) -> Scope
|
|
29
|
+
def class_ivars_for: (String | Symbol? class_name) -> Hash[Symbol, Type::t]
|
|
30
|
+
def with_class_ivars: (Hash[String, Hash[Symbol, Type::t]] table) -> Scope
|
|
31
|
+
def class_cvars_for: (String | Symbol? class_name) -> Hash[Symbol, Type::t]
|
|
32
|
+
def with_class_cvars: (Hash[String, Hash[Symbol, Type::t]] table) -> Scope
|
|
33
|
+
def with_program_globals: (Hash[Symbol, Type::t] table) -> Scope
|
|
34
|
+
def with_discovered_classes: (Hash[String, Type::Singleton] table) -> Scope
|
|
35
|
+
def with_in_source_constants: (Hash[String, Type::t] table) -> Scope
|
|
36
|
+
def with_discovered_methods: (Hash[String, Hash[Symbol, Symbol]] table) -> Scope
|
|
37
|
+
def discovered_method?: (String | Symbol class_name, String | Symbol method_name, Symbol kind) -> bool
|
|
38
|
+
def with_fact: (Analysis::FactStore::Fact fact) -> Scope
|
|
39
|
+
def with_self_type: (Type::t? type) -> Scope
|
|
40
|
+
def with_declared_types: (Hash[untyped, Type::t] table) -> Scope
|
|
41
|
+
def facts_for: (?target: Analysis::FactStore::Target?, ?bucket: Symbol?) -> Array[Analysis::FactStore::Fact]
|
|
42
|
+
def local_facts: (String | Symbol name, ?bucket: Symbol?) -> Array[Analysis::FactStore::Fact]
|
|
43
|
+
def type_of: (untyped node, ?tracer: Inference::FallbackTracer?) -> Type::t
|
|
44
|
+
def evaluate: (untyped node, ?tracer: Inference::FallbackTracer?) -> [Type::t, Scope]
|
|
45
|
+
def join: (Scope other) -> Scope
|
|
46
|
+
def ==: (untyped other) -> bool
|
|
47
|
+
def hash: () -> Integer
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module Source
|
|
3
|
+
class NodeLocator
|
|
4
|
+
class OutOfRangeError < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.at_position: (source: String, root: untyped, line: Integer, column: Integer) -> untyped?
|
|
8
|
+
def self.at_offset: (root: untyped, offset: Integer) -> untyped?
|
|
9
|
+
def initialize: (source: String, root: untyped) -> void
|
|
10
|
+
def at_position: (line: Integer, column: Integer) -> untyped?
|
|
11
|
+
def at_offset: (Integer offset) -> untyped?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module NodeWalker
|
|
15
|
+
def self?.each: (untyped root) { (untyped) -> void } -> nil
|
|
16
|
+
| (untyped root) -> Enumerator[untyped, nil]
|
|
17
|
+
def self?.walk: (untyped node) { (untyped) -> void } -> void
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module Testing
|
|
3
|
+
def self?.dump_type: (untyped value) -> untyped
|
|
4
|
+
def self?.assert_type: (String expected, untyped value) -> untyped
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.dump_type: (untyped value) -> untyped
|
|
8
|
+
def self.assert_type: (String expected, untyped value) -> untyped
|
|
9
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
class Trinary
|
|
3
|
+
type value = :yes | :no | :maybe
|
|
4
|
+
|
|
5
|
+
VALUES: Array[value]
|
|
6
|
+
YES: Trinary
|
|
7
|
+
NO: Trinary
|
|
8
|
+
MAYBE: Trinary
|
|
9
|
+
|
|
10
|
+
attr_reader value: value
|
|
11
|
+
|
|
12
|
+
def self.yes: () -> Trinary
|
|
13
|
+
def self.no: () -> Trinary
|
|
14
|
+
def self.maybe: () -> Trinary
|
|
15
|
+
def self.from_symbol: (Symbol symbol) -> Trinary
|
|
16
|
+
|
|
17
|
+
def initialize: (value value) -> void
|
|
18
|
+
def yes?: () -> bool
|
|
19
|
+
def no?: () -> bool
|
|
20
|
+
def maybe?: () -> bool
|
|
21
|
+
def negate: () -> Trinary
|
|
22
|
+
def and: (Trinary other) -> Trinary
|
|
23
|
+
def or: (Trinary other) -> Trinary
|
|
24
|
+
def ==: (untyped other) -> bool
|
|
25
|
+
def hash: () -> Integer
|
|
26
|
+
def to_s: () -> String
|
|
27
|
+
def inspect: () -> String
|
|
28
|
+
end
|
|
29
|
+
end
|
data/sig/rigor/type.rbs
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
module Type
|
|
3
|
+
type t = Top | Bot | Dynamic | Constant | Nominal | Singleton | Union | Tuple | HashShape
|
|
4
|
+
|
|
5
|
+
type accepts_mode = :strict | :gradual | :loose
|
|
6
|
+
|
|
7
|
+
class Top
|
|
8
|
+
def self.instance: () -> Top
|
|
9
|
+
def describe: (?Symbol verbosity) -> String
|
|
10
|
+
def erase_to_rbs: () -> String
|
|
11
|
+
def top: () -> Top
|
|
12
|
+
def bot: () -> Bot
|
|
13
|
+
def dynamic: () -> Dynamic
|
|
14
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
15
|
+
def ==: (untyped other) -> bool
|
|
16
|
+
def hash: () -> Integer
|
|
17
|
+
def inspect: () -> String
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Bot
|
|
21
|
+
def self.instance: () -> Bot
|
|
22
|
+
def describe: (?Symbol verbosity) -> String
|
|
23
|
+
def erase_to_rbs: () -> String
|
|
24
|
+
def top: () -> Top
|
|
25
|
+
def bot: () -> Bot
|
|
26
|
+
def dynamic: () -> Dynamic
|
|
27
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
28
|
+
def ==: (untyped other) -> bool
|
|
29
|
+
def hash: () -> Integer
|
|
30
|
+
def inspect: () -> String
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Dynamic
|
|
34
|
+
attr_reader static_facet: Type::t
|
|
35
|
+
def initialize: (Type::t static_facet) -> void
|
|
36
|
+
def describe: (?Symbol verbosity) -> String
|
|
37
|
+
def erase_to_rbs: () -> String
|
|
38
|
+
def top: () -> Top
|
|
39
|
+
def bot: () -> Bot
|
|
40
|
+
def dynamic: () -> Dynamic
|
|
41
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
42
|
+
def ==: (untyped other) -> bool
|
|
43
|
+
def hash: () -> Integer
|
|
44
|
+
def inspect: () -> String
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Constant
|
|
48
|
+
attr_reader value: untyped
|
|
49
|
+
def initialize: (untyped value) -> void
|
|
50
|
+
def describe: (?Symbol verbosity) -> String
|
|
51
|
+
def erase_to_rbs: () -> String
|
|
52
|
+
def top: () -> Top
|
|
53
|
+
def bot: () -> Bot
|
|
54
|
+
def dynamic: () -> Dynamic
|
|
55
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
56
|
+
def ==: (untyped other) -> bool
|
|
57
|
+
def hash: () -> Integer
|
|
58
|
+
def inspect: () -> String
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Nominal
|
|
62
|
+
attr_reader class_name: String
|
|
63
|
+
attr_reader type_args: Array[Type::t]
|
|
64
|
+
def initialize: (String class_name, ?Array[Type::t] type_args) -> void
|
|
65
|
+
def describe: (?Symbol verbosity) -> String
|
|
66
|
+
def erase_to_rbs: () -> String
|
|
67
|
+
def top: () -> Top
|
|
68
|
+
def bot: () -> Bot
|
|
69
|
+
def dynamic: () -> Dynamic
|
|
70
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
71
|
+
def ==: (untyped other) -> bool
|
|
72
|
+
def hash: () -> Integer
|
|
73
|
+
def inspect: () -> String
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class Singleton
|
|
77
|
+
attr_reader class_name: String
|
|
78
|
+
def initialize: (String class_name) -> void
|
|
79
|
+
def describe: (?Symbol verbosity) -> String
|
|
80
|
+
def erase_to_rbs: () -> String
|
|
81
|
+
def top: () -> Top
|
|
82
|
+
def bot: () -> Bot
|
|
83
|
+
def dynamic: () -> Dynamic
|
|
84
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
85
|
+
def ==: (untyped other) -> bool
|
|
86
|
+
def hash: () -> Integer
|
|
87
|
+
def inspect: () -> String
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class Union
|
|
91
|
+
attr_reader members: Array[Type::t]
|
|
92
|
+
def initialize: (Array[Type::t] members) -> void
|
|
93
|
+
def describe: (?Symbol verbosity) -> String
|
|
94
|
+
def erase_to_rbs: () -> String
|
|
95
|
+
def top: () -> Top
|
|
96
|
+
def bot: () -> Bot
|
|
97
|
+
def dynamic: () -> Dynamic
|
|
98
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
99
|
+
def ==: (untyped other) -> bool
|
|
100
|
+
def hash: () -> Integer
|
|
101
|
+
def inspect: () -> String
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class Tuple
|
|
105
|
+
attr_reader elements: Array[Type::t]
|
|
106
|
+
def initialize: (Array[Type::t] elements) -> void
|
|
107
|
+
def describe: (?Symbol verbosity) -> String
|
|
108
|
+
def erase_to_rbs: () -> String
|
|
109
|
+
def top: () -> Top
|
|
110
|
+
def bot: () -> Bot
|
|
111
|
+
def dynamic: () -> Dynamic
|
|
112
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
113
|
+
def ==: (untyped other) -> bool
|
|
114
|
+
def hash: () -> Integer
|
|
115
|
+
def inspect: () -> String
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class HashShape
|
|
119
|
+
attr_reader pairs: Hash[untyped, Type::t]
|
|
120
|
+
attr_reader required_keys: Array[untyped]
|
|
121
|
+
attr_reader optional_keys: Array[untyped]
|
|
122
|
+
attr_reader read_only_keys: Array[untyped]
|
|
123
|
+
attr_reader extra_keys: Symbol
|
|
124
|
+
def initialize: (?Hash[untyped, Type::t]? pairs, **untyped keywords) -> void
|
|
125
|
+
def describe: (?Symbol verbosity) -> String
|
|
126
|
+
def erase_to_rbs: () -> String
|
|
127
|
+
def open?: () -> bool
|
|
128
|
+
def closed?: () -> bool
|
|
129
|
+
def required_key?: (untyped key) -> bool
|
|
130
|
+
def optional_key?: (untyped key) -> bool
|
|
131
|
+
def read_only_key?: (untyped key) -> bool
|
|
132
|
+
def top: () -> Top
|
|
133
|
+
def bot: () -> Bot
|
|
134
|
+
def dynamic: () -> Dynamic
|
|
135
|
+
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
|
136
|
+
def ==: (untyped other) -> bool
|
|
137
|
+
def hash: () -> Integer
|
|
138
|
+
def inspect: () -> String
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
class AcceptsResult
|
|
142
|
+
attr_reader trinary: Trinary
|
|
143
|
+
attr_reader mode: accepts_mode
|
|
144
|
+
attr_reader reasons: Array[String]
|
|
145
|
+
def self.yes: (?mode: accepts_mode, ?reasons: (Array[String] | String)?) -> AcceptsResult
|
|
146
|
+
def self.no: (?mode: accepts_mode, ?reasons: (Array[String] | String)?) -> AcceptsResult
|
|
147
|
+
def self.maybe: (?mode: accepts_mode, ?reasons: (Array[String] | String)?) -> AcceptsResult
|
|
148
|
+
def initialize: (Trinary trinary, ?mode: accepts_mode, ?reasons: (Array[String] | String)?) -> void
|
|
149
|
+
def yes?: () -> bool
|
|
150
|
+
def no?: () -> bool
|
|
151
|
+
def maybe?: () -> bool
|
|
152
|
+
def with_reason: (String reason) -> AcceptsResult
|
|
153
|
+
def ==: (untyped other) -> bool
|
|
154
|
+
def hash: () -> Integer
|
|
155
|
+
def inspect: () -> String
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
module Combinator
|
|
159
|
+
def self?.top: () -> Top
|
|
160
|
+
def self?.bot: () -> Bot
|
|
161
|
+
def self?.untyped: () -> Dynamic
|
|
162
|
+
def self?.dynamic: (Type::t static_facet) -> Dynamic
|
|
163
|
+
def self?.nominal_of: (Module | String class_name_or_object, ?type_args: Array[Type::t]) -> Nominal
|
|
164
|
+
def self?.singleton_of: (Module | String class_name_or_object) -> Singleton
|
|
165
|
+
def self?.constant_of: (untyped value) -> Constant
|
|
166
|
+
def self?.tuple_of: (*Type::t elements) -> Tuple
|
|
167
|
+
def self?.hash_shape_of: (?Hash[untyped, Type::t]? pairs, **untyped options) -> HashShape
|
|
168
|
+
def self?.union: (*Type::t types) -> Type::t
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
data/sig/rigor.rbs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Rigor
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
class Configuration
|
|
5
|
+
DEFAULT_PATH: String
|
|
6
|
+
DEFAULTS: Hash[String, untyped]
|
|
7
|
+
|
|
8
|
+
attr_reader target_ruby: String
|
|
9
|
+
attr_reader paths: Array[String]
|
|
10
|
+
attr_reader plugins: Array[String]
|
|
11
|
+
attr_reader cache_path: String
|
|
12
|
+
|
|
13
|
+
def self.load: (?String path) -> Configuration
|
|
14
|
+
def initialize: (?Hash[String, untyped] data) -> void
|
|
15
|
+
def to_h: () -> Hash[String, untyped]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class CLI
|
|
19
|
+
EXIT_USAGE: Integer
|
|
20
|
+
|
|
21
|
+
def self.start: (?Array[String] argv, ?out: untyped, ?err: untyped) -> Integer
|
|
22
|
+
|
|
23
|
+
def initialize: (?Array[String] argv, ?out: untyped, ?err: untyped) -> void
|
|
24
|
+
def run: () -> Integer
|
|
25
|
+
|
|
26
|
+
class TypeOfCommand
|
|
27
|
+
USAGE: String
|
|
28
|
+
|
|
29
|
+
def initialize: (argv: Array[String], out: untyped, err: untyped) -> void
|
|
30
|
+
def run: () -> Integer
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class TypeScanCommand
|
|
34
|
+
USAGE: String
|
|
35
|
+
|
|
36
|
+
def initialize: (argv: Array[String], out: untyped, err: untyped) -> void
|
|
37
|
+
def run: () -> Integer
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module Analysis
|
|
42
|
+
class Diagnostic
|
|
43
|
+
attr_reader path: String
|
|
44
|
+
attr_reader line: Integer
|
|
45
|
+
attr_reader column: Integer
|
|
46
|
+
attr_reader message: String
|
|
47
|
+
attr_reader severity: Symbol
|
|
48
|
+
|
|
49
|
+
def initialize: (path: String, line: Integer, column: Integer, message: String, ?severity: Symbol) -> void
|
|
50
|
+
def error?: () -> bool
|
|
51
|
+
def to_h: () -> Hash[String, untyped]
|
|
52
|
+
def to_s: () -> String
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Result
|
|
56
|
+
attr_reader diagnostics: Array[Diagnostic]
|
|
57
|
+
|
|
58
|
+
def initialize: (?diagnostics: Array[Diagnostic]) -> void
|
|
59
|
+
def success?: () -> bool
|
|
60
|
+
def error_count: () -> Integer
|
|
61
|
+
def to_h: () -> Hash[String, untyped]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class Runner
|
|
65
|
+
RUBY_GLOB: String
|
|
66
|
+
def initialize: (configuration: Configuration) -> void
|
|
67
|
+
def run: (?Array[String] paths) -> Result
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|