rigortype 0.0.1 → 0.0.2
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/lib/rigor/analysis/check_rules.rb +212 -5
- data/lib/rigor/analysis/diagnostic.rb +13 -2
- data/lib/rigor/analysis/runner.rb +48 -5
- data/lib/rigor/cli/type_of_command.rb +11 -5
- data/lib/rigor/cli/type_scan_command.rb +13 -8
- data/lib/rigor/cli.rb +26 -6
- data/lib/rigor/configuration.rb +13 -2
- data/lib/rigor/environment.rb +3 -1
- data/lib/rigor/inference/acceptance.rb +31 -0
- data/lib/rigor/inference/expression_typer.rb +104 -0
- data/lib/rigor/inference/narrowing.rb +97 -6
- data/lib/rigor/inference/scope_indexer.rb +58 -0
- data/lib/rigor/inference/statement_evaluator.rb +94 -0
- data/lib/rigor/rbs_extended.rb +109 -13
- data/lib/rigor/scope.rb +30 -5
- data/lib/rigor/version.rb +1 -1
- data/sig/rigor/inference.rbs +5 -2
- data/sig/rigor/rbs_extended.rbs +22 -1
- data/sig/rigor/scope.rbs +3 -0
- metadata +1 -1
data/lib/rigor/scope.rb
CHANGED
|
@@ -19,7 +19,8 @@ module Rigor
|
|
|
19
19
|
attr_reader :environment, :locals, :fact_store, :self_type, :declared_types,
|
|
20
20
|
:ivars, :cvars, :globals,
|
|
21
21
|
:class_ivars, :class_cvars, :program_globals,
|
|
22
|
-
:discovered_classes, :in_source_constants, :discovered_methods
|
|
22
|
+
:discovered_classes, :in_source_constants, :discovered_methods,
|
|
23
|
+
:discovered_def_nodes
|
|
23
24
|
|
|
24
25
|
EMPTY_DECLARED_TYPES = {}.compare_by_identity.freeze
|
|
25
26
|
EMPTY_VAR_BINDINGS = {}.freeze
|
|
@@ -45,7 +46,8 @@ module Rigor
|
|
|
45
46
|
program_globals: EMPTY_VAR_BINDINGS,
|
|
46
47
|
discovered_classes: EMPTY_VAR_BINDINGS,
|
|
47
48
|
in_source_constants: EMPTY_VAR_BINDINGS,
|
|
48
|
-
discovered_methods: EMPTY_CLASS_BINDINGS
|
|
49
|
+
discovered_methods: EMPTY_CLASS_BINDINGS,
|
|
50
|
+
discovered_def_nodes: EMPTY_CLASS_BINDINGS
|
|
49
51
|
)
|
|
50
52
|
@environment = environment
|
|
51
53
|
@locals = locals
|
|
@@ -61,6 +63,7 @@ module Rigor
|
|
|
61
63
|
@discovered_classes = discovered_classes
|
|
62
64
|
@in_source_constants = in_source_constants
|
|
63
65
|
@discovered_methods = discovered_methods
|
|
66
|
+
@discovered_def_nodes = discovered_def_nodes
|
|
64
67
|
freeze
|
|
65
68
|
end
|
|
66
69
|
|
|
@@ -231,6 +234,26 @@ module Rigor
|
|
|
231
234
|
rebuild(discovered_methods: table)
|
|
232
235
|
end
|
|
233
236
|
|
|
237
|
+
# v0.0.2 #5 — per-class table mapping
|
|
238
|
+
# `method_name (Symbol) → Prism::DefNode`. Populated by
|
|
239
|
+
# `ScopeIndexer` alongside `discovered_methods` for
|
|
240
|
+
# instance-side defs only (singleton-side and
|
|
241
|
+
# `define_method`-introduced methods do not contribute a
|
|
242
|
+
# static body the engine can re-type). Consumed by
|
|
243
|
+
# `ExpressionTyper` to do inter-procedural return-type
|
|
244
|
+
# inference when the receiver class is user-defined and
|
|
245
|
+
# has no RBS sig.
|
|
246
|
+
def user_def_for(class_name, method_name)
|
|
247
|
+
table = @discovered_def_nodes[class_name.to_s]
|
|
248
|
+
return nil unless table
|
|
249
|
+
|
|
250
|
+
table[method_name.to_sym]
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def with_discovered_def_nodes(table)
|
|
254
|
+
rebuild(discovered_def_nodes: table)
|
|
255
|
+
end
|
|
256
|
+
|
|
234
257
|
def facts_for(target: nil, bucket: nil)
|
|
235
258
|
fact_store.facts_for(target: target, bucket: bucket)
|
|
236
259
|
end
|
|
@@ -297,7 +320,7 @@ module Rigor
|
|
|
297
320
|
declared_types: @declared_types, ivars: @ivars, cvars: @cvars, globals: @globals,
|
|
298
321
|
class_ivars: @class_ivars, class_cvars: @class_cvars, program_globals: @program_globals,
|
|
299
322
|
discovered_classes: @discovered_classes, in_source_constants: @in_source_constants,
|
|
300
|
-
discovered_methods: @discovered_methods
|
|
323
|
+
discovered_methods: @discovered_methods, discovered_def_nodes: @discovered_def_nodes
|
|
301
324
|
)
|
|
302
325
|
self.class.new(
|
|
303
326
|
environment: environment, locals: locals,
|
|
@@ -308,7 +331,8 @@ module Rigor
|
|
|
308
331
|
program_globals: program_globals,
|
|
309
332
|
discovered_classes: discovered_classes,
|
|
310
333
|
in_source_constants: in_source_constants,
|
|
311
|
-
discovered_methods: discovered_methods
|
|
334
|
+
discovered_methods: discovered_methods,
|
|
335
|
+
discovered_def_nodes: discovered_def_nodes
|
|
312
336
|
)
|
|
313
337
|
end
|
|
314
338
|
|
|
@@ -332,7 +356,8 @@ module Rigor
|
|
|
332
356
|
program_globals: program_globals,
|
|
333
357
|
discovered_classes: discovered_classes,
|
|
334
358
|
in_source_constants: in_source_constants,
|
|
335
|
-
discovered_methods: discovered_methods
|
|
359
|
+
discovered_methods: discovered_methods,
|
|
360
|
+
discovered_def_nodes: discovered_def_nodes
|
|
336
361
|
)
|
|
337
362
|
end
|
|
338
363
|
end
|
data/lib/rigor/version.rb
CHANGED
data/sig/rigor/inference.rbs
CHANGED
|
@@ -138,14 +138,17 @@ module Rigor
|
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
class CoverageScanner
|
|
141
|
-
class
|
|
141
|
+
class Result
|
|
142
|
+
attr_reader visits: Hash[Class, Integer]
|
|
143
|
+
attr_reader unrecognized: Hash[Class, Integer]
|
|
144
|
+
attr_reader events: Array[Fallback]
|
|
142
145
|
def visited_count: () -> Integer
|
|
143
146
|
def unrecognized_count: () -> Integer
|
|
144
147
|
def unrecognized_ratio: () -> Float
|
|
145
148
|
end
|
|
146
149
|
|
|
147
150
|
def initialize: (?scope: Scope?) -> void
|
|
148
|
-
def scan: (untyped root) ->
|
|
151
|
+
def scan: (untyped root) -> Result
|
|
149
152
|
end
|
|
150
153
|
end
|
|
151
154
|
end
|
data/sig/rigor/rbs_extended.rbs
CHANGED
|
@@ -10,13 +10,34 @@ module Rigor
|
|
|
10
10
|
attr_reader target_kind: target_kind
|
|
11
11
|
attr_reader target_name: Symbol
|
|
12
12
|
attr_reader class_name: String
|
|
13
|
+
attr_reader negative: bool
|
|
13
14
|
|
|
14
|
-
def self.new: (edge: predicate_edge, target_kind: target_kind, target_name: Symbol, class_name: String) -> PredicateEffect
|
|
15
|
+
def self.new: (edge: predicate_edge, target_kind: target_kind, target_name: Symbol, class_name: String, negative: bool) -> PredicateEffect
|
|
15
16
|
def truthy_only?: () -> bool
|
|
16
17
|
def falsey_only?: () -> bool
|
|
18
|
+
def negative?: () -> bool
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def self?.read_predicate_effects: (untyped method_def) -> Array[PredicateEffect]
|
|
20
22
|
def self?.parse_predicate_annotation: (String string) -> PredicateEffect?
|
|
23
|
+
|
|
24
|
+
type assert_condition = :always | :if_truthy_return | :if_falsey_return
|
|
25
|
+
|
|
26
|
+
class AssertEffect
|
|
27
|
+
attr_reader condition: assert_condition
|
|
28
|
+
attr_reader target_kind: target_kind
|
|
29
|
+
attr_reader target_name: Symbol
|
|
30
|
+
attr_reader class_name: String
|
|
31
|
+
attr_reader negative: bool
|
|
32
|
+
|
|
33
|
+
def self.new: (condition: assert_condition, target_kind: target_kind, target_name: Symbol, class_name: String, negative: bool) -> AssertEffect
|
|
34
|
+
def always?: () -> bool
|
|
35
|
+
def if_truthy_return?: () -> bool
|
|
36
|
+
def if_falsey_return?: () -> bool
|
|
37
|
+
def negative?: () -> bool
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self?.read_assert_effects: (untyped method_def) -> Array[AssertEffect]
|
|
41
|
+
def self?.parse_assert_annotation: (String string) -> AssertEffect?
|
|
21
42
|
end
|
|
22
43
|
end
|
data/sig/rigor/scope.rbs
CHANGED
|
@@ -14,6 +14,7 @@ module Rigor
|
|
|
14
14
|
attr_reader discovered_classes: Hash[String, Type::Singleton]
|
|
15
15
|
attr_reader in_source_constants: Hash[String, Type::t]
|
|
16
16
|
attr_reader discovered_methods: Hash[String, Hash[Symbol, Symbol]]
|
|
17
|
+
attr_reader discovered_def_nodes: Hash[String, Hash[Symbol, untyped]]
|
|
17
18
|
|
|
18
19
|
def self.empty: (?environment: Environment) -> Scope
|
|
19
20
|
|
|
@@ -35,6 +36,8 @@ module Rigor
|
|
|
35
36
|
def with_in_source_constants: (Hash[String, Type::t] table) -> Scope
|
|
36
37
|
def with_discovered_methods: (Hash[String, Hash[Symbol, Symbol]] table) -> Scope
|
|
37
38
|
def discovered_method?: (String | Symbol class_name, String | Symbol method_name, Symbol kind) -> bool
|
|
39
|
+
def with_discovered_def_nodes: (Hash[String, Hash[Symbol, untyped]] table) -> Scope
|
|
40
|
+
def user_def_for: (String | Symbol class_name, String | Symbol method_name) -> untyped?
|
|
38
41
|
def with_fact: (Analysis::FactStore::Fact fact) -> Scope
|
|
39
42
|
def with_self_type: (Type::t? type) -> Scope
|
|
40
43
|
def with_declared_types: (Hash[untyped, Type::t] table) -> Scope
|