From 1bdcb6ffdf92382597706ca1f0a2bc4c22d80b77 Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Sat, 29 Aug 2026 18:41:50 +0200 Subject: [PATCH 1/2] Isolate mutable state in copied environments --- lib/rbs/environment.rb | 3 ++- lib/rbs/environment/class_entry.rb | 4 ++++ lib/rbs/environment/module_entry.rb | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rbs/environment.rb b/lib/rbs/environment.rb index 0fb4347142..777e46de31 100644 --- a/lib/rbs/environment.rb +++ b/lib/rbs/environment.rb @@ -58,12 +58,13 @@ def initialize def initialize_copy(other) @sources = other.sources.dup - @class_decls = other.class_decls.dup + @class_decls = other.class_decls.transform_values(&:dup) @interface_decls = other.interface_decls.dup @type_alias_decls = other.type_alias_decls.dup @constant_decls = other.constant_decls.dup @global_decls = other.global_decls.dup @class_alias_decls = other.class_alias_decls.dup + @normalize_module_name_cache = other.instance_variable_get(:@normalize_module_name_cache).dup end def self.from_loader(loader) diff --git a/lib/rbs/environment/class_entry.rb b/lib/rbs/environment/class_entry.rb index 73762330a5..cff8ad87e0 100644 --- a/lib/rbs/environment/class_entry.rb +++ b/lib/rbs/environment/class_entry.rb @@ -12,6 +12,10 @@ def initialize(name) @context_decls = [] end + def initialize_copy(other) + @context_decls = other.context_decls.dup + end + def <<(context_decl) context_decls << context_decl @primary_decl = nil diff --git a/lib/rbs/environment/module_entry.rb b/lib/rbs/environment/module_entry.rb index 1f65cf4905..71bda093d0 100644 --- a/lib/rbs/environment/module_entry.rb +++ b/lib/rbs/environment/module_entry.rb @@ -12,6 +12,10 @@ def initialize(name) @context_decls = [] end + def initialize_copy(other) + @context_decls = other.context_decls.dup + end + def <<(context_decl) context_decls << context_decl self From d9933ddf46aa4dc6084c668213f010416463bc0d Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Sat, 29 Aug 2026 18:51:39 +0200 Subject: [PATCH 2/2] Satisfy environment copy typecheck --- lib/rbs/environment/class_entry.rb | 1 + lib/rbs/environment/module_entry.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/rbs/environment/class_entry.rb b/lib/rbs/environment/class_entry.rb index cff8ad87e0..03fe326dc1 100644 --- a/lib/rbs/environment/class_entry.rb +++ b/lib/rbs/environment/class_entry.rb @@ -14,6 +14,7 @@ def initialize(name) def initialize_copy(other) @context_decls = other.context_decls.dup + self end def <<(context_decl) diff --git a/lib/rbs/environment/module_entry.rb b/lib/rbs/environment/module_entry.rb index 71bda093d0..47356c1b2a 100644 --- a/lib/rbs/environment/module_entry.rb +++ b/lib/rbs/environment/module_entry.rb @@ -14,6 +14,7 @@ def initialize(name) def initialize_copy(other) @context_decls = other.context_decls.dup + self end def <<(context_decl)