Skip to content

Commit a5458a8

Browse files
committed
Validate the type params of an entry once
`ClassEntry#type_params` and `ModuleEntry#type_params` validated the consistency of the type params across the declarations on every call, renaming and comparing the param lists each time, and the definition builder reads `type_params` of the same entries over and over while resolving ancestors. Record a successful validation and skip it until `<<` adds another declaration; a failed validation is not recorded and raises again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c2ae88f commit a5458a8

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/rbs/environment/class_entry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize(name)
1515
def <<(context_decl)
1616
context_decls << context_decl
1717
@primary_decl = nil
18+
@type_params_validated = nil
1819
self
1920
end
2021

@@ -50,6 +51,10 @@ def type_params
5051
end
5152

5253
def validate_type_params
54+
# The entry only changes with `<<`, which resets the memo -- a failed
55+
# validation is not recorded and raises again
56+
return if @type_params_validated
57+
5358
unless context_decls.empty?
5459
first_decl, *rest_decls = each_decl.to_a
5560
first_decl or raise
@@ -63,6 +68,8 @@ def validate_type_params
6368
end
6469
end
6570
end
71+
72+
@type_params_validated = true
6673
end
6774

6875
def align_params(decl)

lib/rbs/environment/module_entry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def initialize(name)
1414

1515
def <<(context_decl)
1616
context_decls << context_decl
17+
@type_params_validated = nil
1718
self
1819
end
1920

@@ -72,6 +73,10 @@ def align_params(decl)
7273
end
7374

7475
def validate_type_params
76+
# The entry only changes with `<<`, which resets the memo -- a failed
77+
# validation is not recorded and raises again
78+
return if @type_params_validated
79+
7580
unless context_decls.empty?
7681
first_decl, *rest_decls = each_decl.to_a
7782
first_decl or raise
@@ -85,6 +90,8 @@ def validate_type_params
8590
end
8691
end
8792
end
93+
94+
@type_params_validated = true
8895
end
8996
end
9097
end

sig/environment/class_entry.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module RBS
1818

1919
@primary_decl: declaration?
2020

21+
@type_params_validated: bool?
22+
2123
def initialize: (TypeName) -> void
2224

2325
def <<: (context_decl) -> self

sig/environment/module_entry.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module RBS
1717

1818
attr_reader context_decls: Array[context_decl]
1919

20+
@type_params_validated: bool?
21+
2022
def initialize: (TypeName) -> void
2123

2224
def <<: (context_decl) -> self

0 commit comments

Comments
 (0)