lutaml-model 0.8.201 → 0.8.203

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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/dependent-tests.yml +59 -2
  4. data/.github/workflows/downstream-performance.yml +1 -22
  5. data/.github/workflows/performance.yml +1 -33
  6. data/.github/workflows/rake.yml +2 -6
  7. data/.rubocop.yml +0 -10
  8. data/.rubocop_todo.yml +0 -4
  9. data/Gemfile +0 -23
  10. data/README.adoc +25 -86
  11. data/Rakefile +2 -167
  12. data/docs/_guides/advanced-mapping.adoc +6 -6
  13. data/docs/_guides/character-encoding.adoc +0 -3
  14. data/docs/_guides/gem-integration.adoc +1 -1
  15. data/docs/_guides/index.adoc +0 -4
  16. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  17. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  18. data/docs/_guides/xml-namespaces.adoc +2 -3
  19. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  20. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  21. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  22. data/docs/_pages/comparison-with-shale.adoc +1 -1
  23. data/docs/_pages/configuration.adoc +6 -40
  24. data/docs/_pages/index.adoc +0 -1
  25. data/docs/_pages/serialization_adapters.adoc +4 -16
  26. data/docs/_references/architecture.adoc +1 -1
  27. data/docs/_references/lutaml-namespace-planning.md +1 -1
  28. data/docs/_references/plan-schema-spec.adoc +45 -18
  29. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  30. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  31. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  32. data/docs/architecture.md +7 -11
  33. data/docs/conversion_caching.adoc +1 -1
  34. data/docs/index.adoc +0 -1
  35. data/docs/key_value_data_model.adoc +1 -1
  36. data/docs/namespace-management.adoc +4 -10
  37. data/lib/lutaml/json/format.rb +0 -1
  38. data/lib/lutaml/json/generator_options.rb +0 -1
  39. data/lib/lutaml/key_value/transform.rb +149 -37
  40. data/lib/lutaml/lml/document_builder.rb +2 -2
  41. data/lib/lutaml/lml/entity_types.rb +2 -2
  42. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  43. data/lib/lutaml/model/attribute.rb +11 -6
  44. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  45. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  46. data/lib/lutaml/model/global_context.rb +3 -5
  47. data/lib/lutaml/model/instrumentation.rb +0 -3
  48. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  49. data/lib/lutaml/model/register.rb +20 -31
  50. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  51. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  52. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  53. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  54. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  55. data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
  56. data/lib/lutaml/model/serialize/initialization.rb +19 -9
  57. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  58. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  59. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  60. data/lib/lutaml/model/store.rb +10 -17
  61. data/lib/lutaml/model/toml.rb +0 -2
  62. data/lib/lutaml/model/transformation_registry.rb +3 -7
  63. data/lib/lutaml/model/version.rb +1 -1
  64. data/lib/lutaml/model.rb +3 -19
  65. data/lib/lutaml/toml/format.rb +4 -8
  66. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  67. data/lib/lutaml/xml/adapter.rb +0 -4
  68. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  69. data/lib/lutaml/xml/builder/base.rb +0 -3
  70. data/lib/lutaml/xml/builder.rb +0 -8
  71. data/lib/lutaml/xml/data_model.rb +1 -1
  72. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  73. data/lib/lutaml/xml/format.rb +22 -74
  74. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  75. data/lib/lutaml/xml/model_transform.rb +14 -24
  76. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  77. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  78. data/lib/lutaml/xml/schema/builder.rb +6 -9
  79. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  80. data/lib/lutaml/xml/xml_element.rb +3 -2
  81. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  82. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  83. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  84. data/lib/tasks/performance_comparator.rb +1 -1
  85. data/lutaml-model.gemspec +3 -8
  86. data/spec/address_person_spec.rb +8 -0
  87. data/spec/address_spec.rb +4 -0
  88. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  89. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  90. data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
  91. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  92. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  93. data/spec/lutaml/model/cdata_spec.rb +2 -15
  94. data/spec/lutaml/model/encoding_spec.rb +0 -9
  95. data/spec/lutaml/model/except_spec.rb +0 -7
  96. data/spec/lutaml/model/json_spec.rb +0 -14
  97. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  98. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  99. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  100. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  101. data/spec/lutaml/model/serializable_spec.rb +0 -2
  102. data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
  103. data/spec/lutaml/model/toml_spec.rb +0 -23
  104. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  105. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  106. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  107. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  108. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  109. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  110. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  111. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  112. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  113. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  114. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  115. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  116. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  117. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  118. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  119. data/spec/lutaml/xml/xml_spec.rb +2 -88
  120. data/spec/spec_helper.rb +8 -28
  121. data/spec/support/test_adapter_config.rb +6 -6
  122. metadata +2 -32
  123. data/.github/workflows/js-pr-check.yml +0 -106
  124. data/.github/workflows/js-sync.yml +0 -55
  125. data/.github/workflows/opal.yml +0 -65
  126. data/.gitmodules +0 -6
  127. data/.rspec-opal +0 -5
  128. data/docs/_guides/opal.adoc +0 -232
  129. data/lib/compat/opal/generate_boot.rb +0 -137
  130. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  131. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  132. data/lib/compat/opal/monitor.rb +0 -31
  133. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  134. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  135. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  136. data/lib/compat/opal/moxml_boot.rb +0 -68
  137. data/lib/compat/opal/objectspace_shim.rb +0 -23
  138. data/lib/compat/opal/rexml/namespace.rb +0 -59
  139. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  140. data/lib/compat/opal/rexml/source.rb +0 -214
  141. data/lib/compat/opal/rexml/text.rb +0 -426
  142. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  143. data/lib/compat/opal/rexml_compat.rb +0 -85
  144. data/lib/compat/opal/yaml_compat.rb +0 -32
  145. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  146. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  147. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  148. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  149. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  150. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  151. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  152. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  153. data/spec/support/opal.rb +0 -9
@@ -155,8 +155,6 @@ module Lutaml
155
155
  #
156
156
  # @return [Float] the current monotonic time in seconds
157
157
  def monotonic_time
158
- return Time.now.to_f if Lutaml::Model.opal?
159
-
160
158
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
161
159
  end
162
160
 
@@ -164,7 +162,6 @@ module Lutaml
164
162
  #
165
163
  # @return [Integer, nil] memory in bytes, or nil if not available
166
164
  def memory_usage
167
- return nil if Lutaml::Model.opal?
168
165
  return nil unless defined?(GC)
169
166
 
170
167
  GC.start if RUBY_VERSION >= "2.7"
@@ -487,16 +487,12 @@ context = nil, pre_cast: false)
487
487
  # that class's attribute, or nil when only a casting writer
488
488
  # exists (custom writers, reflective names, enum shorthands).
489
489
  # Class-level because mapping rules may be frozen (see the
490
- # name-string note above TRANSFORM_DISPATCH). Concurrent::Map
491
- # under threaded MRI, plain identity Hash under Opal — writes are
492
- # idempotent (the same verdict is recomputed).
493
- PARSED_ASSIGN_WRITERS = if Lutaml::Model.opal?
494
- {}.compare_by_identity
495
- else
496
- Lutaml::Model::RuntimeCompatibility
497
- .require_native("concurrent")
498
- Concurrent::Map.new
499
- end
490
+ # name-string note above TRANSFORM_DISPATCH). Concurrent::Map —
491
+ # writes are idempotent (the same verdict is recomputed).
492
+ PARSED_ASSIGN_WRITERS = begin
493
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
494
+ Concurrent::Map.new
495
+ end
500
496
 
501
497
  def self.transform_dispatch(rule, attr)
502
498
  per_attr = TRANSFORM_DISPATCH[rule]
@@ -52,13 +52,10 @@ module Lutaml
52
52
  # require is still in flight makes concurrent-ruby's optional
53
53
  # native-extension requires raise inside RubyGems' unresolved-tree
54
54
  # resolution, which walks every installed gem on gem-heavy machines.
55
- RESOLVE_CACHE = if Lutaml::Model.opal?
56
- {}
57
- else
58
- Lutaml::Model::RuntimeCompatibility
59
- .require_native("concurrent")
60
- Concurrent::Map.new
61
- end
55
+ RESOLVE_CACHE = begin
56
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
57
+ Concurrent::Map.new
58
+ end
62
59
 
63
60
  # Clear the resolve_for_child cache.
64
61
  # Called from add_fallback and GlobalContext.clear_caches.
@@ -86,30 +83,22 @@ module Lutaml
86
83
  # @param parent_register [Symbol, String, nil] The parent's register/context ID
87
84
  # @return [Symbol, nil] The register ID to use for the child
88
85
  def self.resolve_for_child(child_class, parent_register)
89
- if Lutaml::Model.opal?
90
- per_class = RESOLVE_CACHE[child_class] # rubocop:todo Style/IdenticalConditionalBranches
91
- return per_class[parent_register] if per_class&.key?(parent_register)
92
-
93
- (RESOLVE_CACHE[child_class] ||= {})[parent_register] =
94
- _resolve_for_child_uncached(child_class, parent_register)
95
- else
96
- # Read-first: Concurrent::Map#compute_if_absent takes the mutex
97
- # on EVERY call, hits included — 1.35 M synchronized blocks per
98
- # ISO-13849 parse for answers that never change. The plain #[]
99
- # read is lock-free; nil is a valid cached answer, hence key?.
100
- # Nested maps: class → register → result. Every hop keys on a
101
- # stable object (Class / Symbol), so the hot lookup allocates
102
- # nothing — the flat [object_id, register] array key cost one
103
- # Array per call, six per parsed element.
104
- per_class = RESOLVE_CACHE[child_class] # rubocop:todo Style/IdenticalConditionalBranches
105
- return per_class[parent_register] if per_class&.key?(parent_register)
106
-
107
- per_class = RESOLVE_CACHE.compute_if_absent(child_class) do
108
- Concurrent::Map.new
109
- end
110
- per_class.compute_if_absent(parent_register) do
111
- _resolve_for_child_uncached(child_class, parent_register)
112
- end
86
+ # Read-first: Concurrent::Map#compute_if_absent takes the mutex
87
+ # on EVERY call, hits included — 1.35 M synchronized blocks per
88
+ # ISO-13849 parse for answers that never change. The plain #[]
89
+ # read is lock-free; nil is a valid cached answer, hence key?.
90
+ # Nested maps: class → register → result. Every hop keys on a
91
+ # stable object (Class / Symbol), so the hot lookup allocates
92
+ # nothing — the flat [object_id, register] array key cost one
93
+ # Array per call, six per parsed element.
94
+ per_class = RESOLVE_CACHE[child_class]
95
+ return per_class[parent_register] if per_class&.key?(parent_register)
96
+
97
+ per_class = RESOLVE_CACHE.compute_if_absent(child_class) do
98
+ Concurrent::Map.new
99
+ end
100
+ per_class.compute_if_absent(parent_register) do
101
+ _resolve_for_child_uncached(child_class, parent_register)
113
102
  end
114
103
  end
115
104
 
@@ -3,38 +3,22 @@
3
3
  module Lutaml
4
4
  module Model
5
5
  module RuntimeCompatibility
6
- def self.opal?
7
- return @opal if defined?(@opal)
8
-
9
- @opal = RUBY_ENGINE == "opal"
10
- end
11
-
12
6
  def self.windows?
13
7
  defined?(Gem) &&
14
8
  Gem.win_platform?
15
9
  end
16
10
 
17
- def self.native?
18
- !opal?
19
- end
20
-
21
11
  def self.autoload_native(namespace, constant_paths)
22
- return unless native?
23
-
24
12
  constant_paths.each do |constant_name, path|
25
13
  namespace.autoload(constant_name, path)
26
14
  end
27
15
  end
28
16
 
29
17
  def self.require_native(*paths)
30
- return unless native?
31
-
32
18
  paths.each { |path| require path }
33
19
  end
34
20
 
35
21
  def self.define_native_aliases(namespace, constant_targets)
36
- return unless native?
37
-
38
22
  constant_targets.each do |constant_name, target_name|
39
23
  namespace.const_set(constant_name, constantize(target_name))
40
24
  end
@@ -66,79 +50,3 @@ module Lutaml
66
50
  end
67
51
  end
68
52
  end
69
-
70
- if Lutaml::Model::RuntimeCompatibility.opal?
71
- unless defined?(Mutex)
72
- class ::Mutex
73
- def synchronize
74
- yield
75
- end
76
- end
77
- end
78
-
79
- unless defined?(ConditionVariable)
80
- class ::ConditionVariable
81
- def wait(*); end
82
-
83
- def broadcast; end
84
- end
85
- end
86
-
87
- unless defined?(Thread)
88
- class ::Thread
89
- def self.current
90
- @current ||= {}
91
- end
92
- end
93
- end
94
-
95
- # Opal has no `weakref` stdlib. Store uses WeakRef to let go of
96
- # registered instances automatically once they go out of scope.
97
- # Under Opal (browser JS GC) we substitute a strong reference —
98
- # correct behavior, weaker memory profile, no API surface change.
99
- unless defined?(WeakRef)
100
- class ::WeakRef
101
- class RefError < ::StandardError; end
102
-
103
- def initialize(obj)
104
- @__target__ = obj
105
- end
106
-
107
- def __getobj__
108
- @__target__
109
- end
110
-
111
- def weakref_alive?
112
- true
113
- end
114
-
115
- # Minimal method_missing so the WeakRef quacks like its target
116
- # for the Store's index lookups.
117
- def method_missing(name, ...)
118
- @__target__.public_send(name, ...)
119
- end
120
-
121
- def respond_to_missing?(name, include_private = false)
122
- @__target__.respond_to?(name, include_private)
123
- end
124
- end
125
- end
126
-
127
- # Opal's Module#prepend raises "Prepending a module multiple times
128
- # is not supported" when a module is already in the target's ancestor
129
- # chain. MRI's prepend is idempotent in that case (no-op, no error).
130
- #
131
- # Our top-level lib files (lib/lutaml/model.rb, lib/lutaml/xml.rb)
132
- # can be re-evaluated under Opal's eager loader, which would trigger
133
- # the raise on the second pass. Align Opal with MRI by making prepend
134
- # a no-op when the module is already present.
135
- class ::Module
136
- unless method_defined?(:__lm_original_prepend__)
137
- alias_method :__lm_original_prepend__, :prepend
138
-
139
- def prepend(mod)
140
- __lm_original_prepend__(mod) unless self <= mod
141
- end
142
- end
143
- end
144
- end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- unless RUBY_ENGINE == "opal"
4
- require "fileutils"
5
- require "tmpdir"
6
- end
3
+ require "fileutils"
4
+ require "tmpdir"
7
5
 
8
6
  module Lutaml
9
7
  module Model
@@ -149,9 +149,8 @@ module Lutaml
149
149
  values.public_send(:"#{method}_by") { |v| comparable_bound(v) }
150
150
  end
151
151
 
152
- # Lazy, guarded require (mirrors Type::Decimal) so this Opal-booted
153
- # file has no load-time bigdecimal dependency; the XSD compiler is a
154
- # native-only path, so this only runs under MRI.
152
+ # Lazy, guarded require (mirrors Type::Decimal) so this file
153
+ # has no load-time bigdecimal dependency.
155
154
  def comparable_bound(value)
156
155
  require "bigdecimal" unless defined?(BigDecimal)
157
156
  BigDecimal(value.to_s)
@@ -8,23 +8,9 @@ module Lutaml
8
8
  # Extracted from serialize.rb to improve code organization.
9
9
  # Provides methods for defining and validating model attributes.
10
10
  module AttributeDefinition
11
- # Whether the per-class accessors and the state-defaults seed are
12
- # compiled from Ruby source with a String class_eval (the fast
13
- # path). Opal has no runtime compiler unless opal-parser is
14
- # bundled, so there every such method is defined from a block
15
- # with define_method instead.
16
- # Core dispatch for the block-form methods, bound per call so an
17
- # attribute or method a model defines with one of these names
18
- # (send, __send__, instance_variable_get, const_get, ...) is never invoked;
19
- # the compiled form reads ivars and calls methods directly.
20
- IVAR_GET = ::Kernel.instance_method(:instance_variable_get)
21
- IVAR_SET = ::Kernel.instance_method(:instance_variable_set)
22
- SEND = ::BasicObject.instance_method(:__send__)
23
- CONST_GET = ::Module.instance_method(:const_get)
24
-
25
- def self.source_compilation?
26
- !Lutaml::Model.opal?
27
- end
11
+ # The per-class accessors and the state-defaults seed are
12
+ # compiled from Ruby source with a String class_eval: the
13
+ # compiled form reads ivars and calls methods directly.
28
14
 
29
15
  # Define attribute methods on the model class
30
16
  #
@@ -62,26 +48,6 @@ module Lutaml
62
48
  return
63
49
  end
64
50
 
65
- unless AttributeDefinition.source_compilation?
66
- seeds = attrs.map do |name, attr|
67
- sentinel = if attr.collection?
68
- Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION
69
- else
70
- Lutaml::Model::UninitializedClass.instance
71
- end
72
- [:"@#{name}", sentinel]
73
- end
74
- # Raw readers for every attribute the register sees, as the
75
- # compiled form below does (#933).
76
- attrs.each_key { |name| define_raw_state_reader(name) }
77
- define_method(method_name) do
78
- # Returns the last seeded value, as the compiled form's final
79
- # assignment does.
80
- seeds.reduce(nil) { |_, (ivar, sentinel)| IVAR_SET.bind_call(self, ivar, sentinel) }
81
- end
82
- return
83
- end
84
-
85
51
  lines = attrs.map do |name, attr|
86
52
  if attr.collection?
87
53
  "@#{name} = Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION"
@@ -188,25 +154,6 @@ module Lutaml
188
154
  "Serialize::DEFAULT_VALUE_MAP)"
189
155
  end
190
156
 
191
- unless AttributeDefinition.source_compilation?
192
- define_method(method_name) do
193
- @using_default = marks
194
- simple.each { |n| IVAR_SET.bind_call(self, :"@#{n}", nil) }
195
- lazy.each do |n|
196
- IVAR_SET.bind_call(
197
- self, :"@#{n}", Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION
198
- )
199
- end
200
- complex.each do |n|
201
- initialize_single_attribute(
202
- {}, n, self.class.attributes(@lutaml_register)[n],
203
- Serialize::DEFAULT_VALUE_MAP
204
- )
205
- end
206
- end
207
- return
208
- end
209
-
210
157
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1) # rubocop:disable Style/DocumentDynamicEvalDefinition
211
158
  def #{method_name}
212
159
  #{marks_line}
@@ -217,14 +164,6 @@ module Lutaml
217
164
  RUBY
218
165
  end
219
166
 
220
- # Block-form raw-state reader (no String eval), defined on self.
221
- def define_raw_state_reader(name)
222
- ivar = :"@#{name}"
223
- define_method(:"__lutaml_raw_#{name}") do
224
- IVAR_GET.bind_call(self, ivar)
225
- end
226
- end
227
-
228
167
  # Historical getter shape for punctuation-named attributes and
229
168
  # any name the compiled form cannot express.
230
169
  def define_reflective_attribute_methods(name, attr)
@@ -255,15 +194,8 @@ module Lutaml
255
194
  end
256
195
 
257
196
  def invalidate_state_defaults!
258
- # Opal's method_defined? takes no inherit flag (see the
259
- # setter_defined check in define_regular_attribute_methods).
260
197
  (@state_defaults_names ||= {}).each_key do |compiled|
261
- defined_now = if Lutaml::Model.opal?
262
- method_defined?(compiled)
263
- else
264
- method_defined?(compiled, false)
265
- end
266
- remove_method(compiled) if defined_now
198
+ remove_method(compiled) if method_defined?(compiled, false)
267
199
  end
268
200
  # The names cache must go with the methods: the memoized
269
201
  # lookup answers stale names for removed methods otherwise.
@@ -288,16 +220,11 @@ module Lutaml
288
220
  # the state-defaults compilation) so late declarations get it
289
221
  # too -- XMI's extension loader declares attributes after
290
222
  # first parse.
291
- # Without a source compiler, compile_state_defaults! defines
292
- # its raw readers from blocks; define one for every name here
293
- # too (define_method takes any name, not only plain ones).
294
- # Both forms define on self: a bare `model` receiver resolves
223
+ # Defined on self: a bare `model` receiver resolves
295
224
  # through the host class's own namespace (omml's Base answers
296
225
  # a Store model) and defined the reader on the wrong object
297
226
  # (#933).
298
- if !AttributeDefinition.source_compilation?
299
- define_raw_state_reader(name)
300
- elsif name.to_s.match?(PLAIN_NAME)
227
+ if name.to_s.match?(PLAIN_NAME)
301
228
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1) # rubocop:disable Style/DocumentDynamicEvalDefinition
302
229
  def __lutaml_raw_#{name}
303
230
  @#{name}
@@ -411,9 +338,7 @@ module Lutaml
411
338
  # Array on EVERY read — the largest per-call allocation source
412
339
  # on instance-heavy parses (TODO.max-perf/06). The optional-arg
413
340
  # form allocates nothing, and the read is a direct @ivar.
414
- if !AttributeDefinition.source_compilation?
415
- define_block_attribute_getter(name, attr)
416
- elsif attr.collection?
341
+ if attr.collection?
417
342
  # class_eval interpolates, e.g.:
418
343
  # def items(arg = Lutaml::Model::Serialize::NO_ARG)
419
344
  # if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
@@ -449,29 +374,16 @@ module Lutaml
449
374
  end
450
375
 
451
376
  enum_shorthand_names = instance_variable_get(:@__enum_shorthand_names__) || Set.new
452
- # Opal's Module#method_defined? only accepts 1 arg (MRI accepts
453
- # the optional `inherit` flag). Skip the flag there — the
454
- # difference only matters for inherited-method filtering.
455
- setter_defined = if Lutaml::Model.opal?
456
- method_defined?(:"#{name}=")
457
- else
458
- method_defined?(:"#{name}=", false)
459
- end
377
+ setter_defined = method_defined?(:"#{name}=", false)
460
378
  return if setter_defined && !enum_shorthand_names.include?(name.to_s)
461
379
 
462
380
  # class_eval'd bodies cannot close over locals; a hidden
463
381
  # define_method accessor holds the Attribute handle.
464
382
  attr_reader_method = :"__attribute_definition_#{name}"
465
- reader_defined = if Lutaml::Model.opal?
466
- method_defined?(attr_reader_method)
467
- else
468
- method_defined?(attr_reader_method, false)
469
- end
383
+ reader_defined = method_defined?(attr_reader_method, false)
470
384
  define_method(attr_reader_method) { attr } unless reader_defined
471
385
 
472
- if !AttributeDefinition.source_compilation?
473
- define_block_attribute_setters(name, attr)
474
- elsif attr.collection? && !attr.lazy_collection_default?
386
+ if attr.collection? && !attr.lazy_collection_default?
475
387
  # class_eval interpolates, e.g.:
476
388
  # def items=(value)
477
389
  # value_set_for(:items)
@@ -550,92 +462,6 @@ module Lutaml
550
462
  end
551
463
  end
552
464
 
553
- # Block form of the compiled getter in define_regular_attribute_methods,
554
- # for runtimes without a source compiler (see source_compilation?).
555
- def define_block_attribute_getter(name, attr)
556
- name = name.to_sym # the compiled form passes :name literals
557
- ivar = :"@#{name}"
558
- if attr.collection?
559
- # The compiled getter resolves Array in the model class's scope.
560
- scope = self
561
- define_method(name) do |arg = Lutaml::Model::Serialize::NO_ARG|
562
- if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
563
- materialize_lazy_collection(name)
564
- else
565
- current = IVAR_GET.bind_call(self, ivar) || []
566
- new_value = current.is_a?(CONST_GET.bind_call(scope, :Array)) ? current + [arg] : arg
567
- IVAR_SET.bind_call(self, ivar, new_value)
568
- record_mutation(name, arg)
569
- arg
570
- end
571
- end
572
- else
573
- define_method(name) do |arg = Lutaml::Model::Serialize::NO_ARG|
574
- if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
575
- IVAR_GET.bind_call(self, ivar)
576
- else
577
- public_send(:"#{name}=", arg)
578
- arg
579
- end
580
- end
581
- end
582
- end
583
-
584
- # Block form of the compiled setters in define_regular_attribute_methods.
585
- # The Attribute is read through the same hidden accessor the
586
- # compiled form calls, not captured: a setter redefined over an
587
- # enum shorthand keeps casting with the accessor's Attribute.
588
- def define_block_attribute_setters(name, attr)
589
- name = name.to_sym # the compiled form passes :name literals
590
- ivar = :"@#{name}"
591
- handle = :"__attribute_definition_#{name}"
592
- if attr.collection? && !attr.lazy_collection_default?
593
- assign = lambda do |model, value|
594
- current = IVAR_GET.bind_call(model, ivar)
595
- unless current.equal?(Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION) &&
596
- (value.nil? || Lutaml::Model::Utils.uninitialized?(value))
597
- IVAR_SET.bind_call(model, ivar, value)
598
- end
599
- SEND.bind_call(model, :record_mutation_collection, name, value)
600
- end
601
- define_method(:"#{name}=") do |value|
602
- value_set_for(name)
603
- assign.call(self, SEND.bind_call(self, handle).cast_value(value, lutaml_register))
604
- end
605
- define_method(:"__assign_parsed_#{name}=") do |value|
606
- value_set_for(name)
607
- assign.call(self, value)
608
- end
609
- elsif attr.collection?
610
- # Lazy-seeded default collections (#1010): nil lands over the
611
- # sentinel — see the source-compiled branch.
612
- assign = lambda do |model, value|
613
- IVAR_SET.bind_call(model, ivar, value)
614
- SEND.bind_call(model, :record_mutation_collection, name, value)
615
- end
616
- define_method(:"#{name}=") do |value|
617
- value_set_for(name)
618
- assign.call(self, SEND.bind_call(self, handle).cast_value(value, lutaml_register))
619
- end
620
- define_method(:"__assign_parsed_#{name}=") do |value|
621
- value_set_for(name)
622
- assign.call(self, value)
623
- end
624
- else
625
- define_method(:"#{name}=") do |value|
626
- value_set_for(name)
627
- value = SEND.bind_call(self, handle).cast_value(value, lutaml_register)
628
- IVAR_SET.bind_call(self, ivar, value)
629
- record_mutation(name, value)
630
- end
631
- define_method(:"__assign_parsed_#{name}=") do |value|
632
- value_set_for(name)
633
- IVAR_SET.bind_call(self, ivar, value)
634
- record_mutation(name, value)
635
- end
636
- end
637
- end
638
-
639
465
  # Class-level documentation metadata (#356): `desc "text"` on
640
466
  # the model class; a zero-argument call reads it back.
641
467
  # Subclasses inherit the nearest ancestor's description — an
@@ -42,10 +42,7 @@ module Lutaml
42
42
  # - A hit returns before the wrapped body runs, so option-hash
43
43
  # mutations the body performs on a miss (e.g. consuming :adapter)
44
44
  # do not happen on a hit.
45
- # - Caching is disabled under Opal: keys need native Marshal/Digest.
46
45
  module ConversionCaching
47
- NATIVE_RUNTIME = !Lutaml::Model::RuntimeCompatibility.opal?
48
-
49
46
  UNMARSHALABLE_IVAR = :@__lutaml_conversion_cache_unmarshalable
50
47
 
51
48
  def cache_conversions
@@ -75,8 +72,7 @@ module Lutaml
75
72
  end
76
73
 
77
74
  def conversion_cache_store(options)
78
- unless NATIVE_RUNTIME && conversion_caching_enabled? &&
79
- options.is_a?(::Hash)
75
+ unless conversion_caching_enabled? && options.is_a?(::Hash)
80
76
  return
81
77
  end
82
78
 
@@ -45,6 +45,27 @@ module Lutaml
45
45
  def self.propagate(options)
46
46
  options.slice(*PROPAGATION_KEYS)
47
47
  end
48
+
49
+ # Memo key for the per-node propagated options (#1311). The
50
+ # propagable keys and the register are identical for every child
51
+ # value of one node, so deriving the child options hash per
52
+ # attribute built and discarded duplicate hashes — `Hash#merge`
53
+ # 7.5% plus `Hash#slice` 3.9% self on the KV walk profile. The
54
+ # key is deliberately not in PROPAGATION_KEYS, so a child never
55
+ # receives the parent's memo as context.
56
+ CHILD_OPTIONS_KEY = :__lutaml_child_options__
57
+
58
+ # The propagated child options for one node's cast-options hash.
59
+ # Reused across that node's attributes; recomputed when the
60
+ # register differs (an options hash can outlive one node).
61
+ def self.child_options(options, register)
62
+ cached = options[CHILD_OPTIONS_KEY]
63
+ return cached if cached && cached[:register] == register
64
+
65
+ propagated = propagate(options).merge(register: register)
66
+ options[CHILD_OPTIONS_KEY] = propagated unless options.frozen?
67
+ propagated
68
+ end
48
69
  end
49
70
  end
50
71
  end
@@ -518,17 +518,27 @@ module Lutaml
518
518
  def allocate_for_walk(register = nil)
519
519
  register_id = extract_register_id(register)
520
520
  ensure_imports!(register_id) if finalized? && deferred_imports_pending?(register_id)
521
- # Classes with their own initialize set up internal state the
522
- # compiled seed cannot know about (SchemaRepository's
523
- # @parsed_schemas/@namespace_registry/@type_index): construct
524
- # through the real constructor for them, exactly as the walk
525
- # did before the compiled seed existed, register included. The
526
- # seed stays the fast path for classes using the standard
527
- # initializer.
528
- return new(lutaml_register: register) if constructs_through_initialize?
529
-
530
521
  instance = allocate
531
522
  instance.init_walk_state(register_id)
523
+ return instance unless constructs_through_initialize?
524
+
525
+ # Classes with their own initialize set up internal state the
526
+ # compiled seed cannot know about (SchemaRepository's
527
+ # @parsed_schemas/@namespace_registry/@type_index): their
528
+ # constructor body still has to run. Run it against the
529
+ # compiled walk seed with the generic attribute walk stood
530
+ # down — the #1059 contract allocate_for_deserialization has
531
+ # used since the deserialization constructor landed: the walk
532
+ # only re-materializes state the seed already wrote, and on
533
+ # expression-model trees (75 classes, every node overriding
534
+ # initialize for parent wiring) that walk was half of the
535
+ # whole hydration cost (#1311). The register rides the call
536
+ # exactly as `new(lutaml_register:)` passed it: a constructor
537
+ # that tells a blank construction from a caller's by the
538
+ # keyword sees the same call either way.
539
+ instance.lutaml_constructor_seeded = true
540
+ instance.send(:initialize, lutaml_register: register_id)
541
+ instance.lutaml_constructor_seeded = nil
532
542
  instance
533
543
  end
534
544
 
@@ -305,11 +305,6 @@ module Lutaml
305
305
  # Uses TracePoint to detect when a class definition is complete,
306
306
  # allowing deferred import resolution.
307
307
  def setup_trace_point
308
- # Opal has no TracePoint. Symbol imports still resolve lazily
309
- # on first use (ensure_imports!), so there the class is marked
310
- # finalized at once instead of at the end of its body.
311
- return @finalized = true if Lutaml::Model.opal?
312
-
313
308
  @trace ||= TracePoint.new(:end) do |_tp|
314
309
  if include?(Lutaml::Model::Serialize)
315
310
  @finalized = true
@@ -108,9 +108,6 @@ module Lutaml
108
108
  def ensure_utf8(value)
109
109
  case value
110
110
  when String
111
- # Opal strings are JS strings with no per-string encoding;
112
- # String#encode there doesn't accept MRI's keyword options.
113
- return value if Lutaml::Model.opal?
114
111
  # The encode-with-options forces a fresh copy per value even
115
112
  # when the string is already valid UTF-8 — the overwhelming
116
113
  # case on parsed documents. Scan instead: no allocation on
@@ -5,13 +5,10 @@ module Lutaml
5
5
  # the name array rebuilt per node is pure churn (~145k
6
6
  # allocations per heroku.json parse). Rules are stable per
7
7
  # (class, register); the bounded cache tracks their arrays.
8
- RULE_NAMES_CACHE = if Lutaml::Model.opal?
9
- {}
10
- else
11
- Lutaml::Model::RuntimeCompatibility
12
- .require_native("concurrent")
13
- Concurrent::Map.new
14
- end
8
+ RULE_NAMES_CACHE = begin
9
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
10
+ Concurrent::Map.new
11
+ end
15
12
 
16
13
  # The extractor is pure stateless logic over its arguments; the
17
14
  # per-call `new(*args).call` instance (Services::Base's default)