lutaml-model 0.8.207 → 0.8.209

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d100be5e75a2c176f69d9367bc66bf67ea65655ca6c181047b9aa97b1b985ac2
4
- data.tar.gz: '09942944fdc1ef7e16a229e56d88e07c4304307748dd6fe0cafc846f688299e2'
3
+ metadata.gz: c396586c2729a6d9858da3c633b98c574358efdb100964340d531f20545a618b
4
+ data.tar.gz: 8833a24a372af34a4cdcaf82ff7921ada9fe9053140609e1a89d6180de2b6c6d
5
5
  SHA512:
6
- metadata.gz: 8474edf89b9345787bc78e804d8b1495cdb144a3d0e8c4821a11e1943634dc8b7d2c32ba5dc1d17e25d40290a2ed83691a668f472c34d537195ba9367ddc4b72
7
- data.tar.gz: fbedc7fb3cee383cd5351cbd35f4205af91f052331be46eceba41839bc1dd14451176a73ba30b20c583592f5e4b039fa40f7da802f9856b3d279243a930b99a3
6
+ metadata.gz: b5748f05813b63d2b93c7957a07aba9ff3faa5bcd770c0609aaded9e38ecbc6eb5e246eaaf188654cb75679e9dae582fce48580947f91204558a34ffa22c6bf3
7
+ data.tar.gz: bcd7c3a604633dc61fdfbe8007c39dc09545d3f27bbf83b7a26218576279bf69af5582f3e76a2022413510a7fbc219bc25134525f353785eb7ec052b7626803c
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "complex1-46KB": {
3
- "avg_time": 0.035969980333324734,
4
- "min_time": 0.03559261399999514,
5
- "max_time": 0.036185082999992346,
6
- "allocations": 50994,
7
- "ips": 27.800960432373113
3
+ "avg_time": 0.0364748943333287,
4
+ "min_time": 0.035120398999993085,
5
+ "max_time": 0.037068958999995516,
6
+ "allocations": 48203,
7
+ "ips": 27.41611780589194
8
8
  },
9
9
  "complex4-50KB": {
10
- "avg_time": 0.04991650399999988,
11
- "min_time": 0.04966256299999827,
12
- "max_time": 0.050061231000000816,
13
- "allocations": 71837,
14
- "ips": 20.03345426594784
10
+ "avg_time": 0.05115535466666188,
11
+ "min_time": 0.04903352099999836,
12
+ "max_time": 0.05247602199999335,
13
+ "allocations": 67781,
14
+ "ips": 19.548295706601824
15
15
  },
16
16
  "size1000-245KB": {
17
- "avg_time": 0.28591416999999336,
18
- "min_time": 0.2818747909999786,
19
- "max_time": 0.2920046950000028,
20
- "allocations": 406438,
21
- "ips": 3.4975531293185758
17
+ "avg_time": 0.2900418076666635,
18
+ "min_time": 0.2876202389999918,
19
+ "max_time": 0.29324903599999175,
20
+ "allocations": 382265,
21
+ "ips": 3.447778815215738
22
22
  },
23
23
  "complex3-567KB": {
24
- "avg_time": 0.40071153599999815,
25
- "min_time": 0.3966769870000064,
26
- "max_time": 0.4045028329999809,
27
- "allocations": 584888,
28
- "ips": 2.49556079663253
24
+ "avg_time": 0.42179371233333995,
25
+ "min_time": 0.4200932080000115,
26
+ "max_time": 0.42285213400001,
27
+ "allocations": 560055,
28
+ "ips": 2.370827185801453
29
29
  }
30
30
  }
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "metrology-4KB": {
3
- "avg_time": 0.008145603666662282,
4
- "min_time": 0.007795773999987432,
5
- "max_time": 0.008779492999906324,
6
- "allocations": 7544,
7
- "ips": 122.76560963710097
3
+ "avg_time": 0.013732422666663524,
4
+ "min_time": 0.013354440000000523,
5
+ "max_time": 0.01399934799999869,
6
+ "allocations": 6644,
7
+ "ips": 72.8203627483426
8
8
  },
9
9
  "bmj-49KB": {
10
- "avg_time": 0.0723875503333223,
11
- "min_time": 0.07129628399991361,
12
- "max_time": 0.07395147099998667,
13
- "allocations": 72378,
14
- "ips": 13.814530197462258
10
+ "avg_time": 0.11612695866666438,
11
+ "min_time": 0.11488018500000408,
12
+ "max_time": 0.11780903400000398,
13
+ "allocations": 61486,
14
+ "ips": 8.611264873218985
15
15
  },
16
16
  "pnas-152KB": {
17
- "avg_time": 0.34388590966667226,
18
- "min_time": 0.3415666549999514,
19
- "max_time": 0.34598907000008694,
20
- "allocations": 259437,
21
- "ips": 2.9079411859860658
17
+ "avg_time": 0.4207894683333298,
18
+ "min_time": 0.4172780809999779,
19
+ "max_time": 0.4247577579999984,
20
+ "allocations": 233115,
21
+ "ips": 2.3764853335346467
22
22
  }
23
23
  }
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "feature-doc-23KB": {
3
- "avg_time": 0.05333307866665867,
4
- "min_time": 0.05320582799998874,
5
- "max_time": 0.05343820699999924,
6
- "allocations": 33278,
7
- "ips": 18.750089531680324
3
+ "avg_time": 0.04404333933335162,
4
+ "min_time": 0.04362466399999221,
5
+ "max_time": 0.0444422120000354,
6
+ "allocations": 29387,
7
+ "ips": 22.70490873617193
8
8
  },
9
9
  "tbx-nisosts-101KB": {
10
- "avg_time": 0.1555278476666615,
11
- "min_time": 0.15451645799998914,
12
- "max_time": 0.15693985299998303,
13
- "allocations": 134268,
14
- "ips": 6.429716703488832
10
+ "avg_time": 0.15528667266666693,
11
+ "min_time": 0.15354131700001972,
12
+ "max_time": 0.15623446500001137,
13
+ "allocations": 114125,
14
+ "ips": 6.43970266622021
15
15
  },
16
16
  "iso-13849-1MB": {
17
- "avg_time": 5.377177922666665,
18
- "min_time": 5.361418570000012,
19
- "max_time": 5.4017619889999935,
20
- "allocations": 1735227,
21
- "ips": 0.1859711570607798
17
+ "avg_time": 2.9371749226666943,
18
+ "min_time": 2.9121822650000126,
19
+ "max_time": 2.9545246739999698,
20
+ "allocations": 1419414,
21
+ "ips": 0.34046320914795525
22
22
  },
23
23
  "din-iso-1.1MB": {
24
- "avg_time": 0.5874012496666694,
25
- "min_time": 0.5822755989999848,
26
- "max_time": 0.5889298150000002,
27
- "allocations": 877606,
28
- "ips": 1.7024138109468896
24
+ "avg_time": 0.6223951049999906,
25
+ "min_time": 0.6178283360000023,
26
+ "max_time": 0.6269072419999588,
27
+ "allocations": 846514,
28
+ "ips": 1.606696440840445
29
29
  }
30
30
  }
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "800-expressions": {
3
- "avg_time": 0.544940995666669,
4
- "min_time": 0.5414146770000059,
5
- "max_time": 0.5454735960000079,
6
- "allocations": 138102,
7
- "ips": 1.835061057897877
3
+ "avg_time": 0.13142044666666663,
4
+ "min_time": 0.12954049200000384,
5
+ "max_time": 0.13376315700000418,
6
+ "allocations": 139002,
7
+ "ips": 7.60916604199641
8
8
  }
9
9
  }
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "ea251": {
3
- "avg_time": 0.17969961900000916,
4
- "min_time": 0.17811001200001897,
5
- "max_time": 0.18114700399999606,
6
- "allocations": 182292,
7
- "ips": 5.564842071256417
3
+ "avg_time": 0.15194719033331694,
4
+ "min_time": 0.15037986999999475,
5
+ "max_time": 0.15446484799997506,
6
+ "allocations": 175969,
7
+ "ips": 6.581233899793496
8
8
  },
9
9
  "medium": {
10
- "avg_time": 0.44894484466666046,
11
- "min_time": 0.43719278499997927,
12
- "max_time": 0.45557199699999273,
13
- "allocations": 471852,
14
- "ips": 2.2274451124224304
10
+ "avg_time": 0.397459121333308,
11
+ "min_time": 0.39441433599995435,
12
+ "max_time": 0.401802325999995,
13
+ "allocations": 460164,
14
+ "ips": 2.515982012553696
15
15
  },
16
16
  "citygml": {
17
- "avg_time": 0.506995725666665,
18
- "min_time": 0.503759285000001,
19
- "max_time": 0.5088972249999983,
20
- "allocations": 583260,
21
- "ips": 1.972403216388201
17
+ "avg_time": 0.4615553376666715,
18
+ "min_time": 0.45299937200002205,
19
+ "max_time": 0.4655662110000094,
20
+ "allocations": 571585,
21
+ "ips": 2.1665874455170644
22
22
  },
23
23
  "large": {
24
- "avg_time": 4.185453844333334,
25
- "min_time": 4.1155831300000045,
26
- "max_time": 4.230669285999994,
27
- "allocations": 4506877,
28
- "ips": 0.23892271595681203
24
+ "avg_time": 3.8421088003333352,
25
+ "min_time": 3.769278003000011,
26
+ "max_time": 3.8997934000000214,
27
+ "allocations": 4399032,
28
+ "ips": 0.26027373298570866
29
29
  }
30
30
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.207"
5
+ VERSION = "0.8.209"
6
6
  end
7
7
  end
@@ -350,6 +350,7 @@ module Lutaml
350
350
  # refuse here: the doc takes the DOM lane.
351
351
  child_plan = PlanCompiler.compile(item.class, register)
352
352
  return false unless child_plan
353
+ return false if blank_opt_out_unspellable?(child_plan, item)
353
354
  return false unless subtree_gate_ok?(child_plan, item,
354
355
  register)
355
356
  end
@@ -379,6 +380,26 @@ module Lutaml
379
380
  !PlanCompiler.compile(child_type, register).nil?
380
381
  end
381
382
 
383
+ # A nested island in default-namespace form (an EXACT tree ns
384
+ # without a prefix) over an item that recorded no prefix carries
385
+ # :blank rows — its local elements, in no namespace — that must
386
+ # opt out with xmlns="" (the island's own declaration would
387
+ # put them in its namespace). The ops spelling has no opt-out:
388
+ # ns_emittable? refuses the shape on the root, the DOM lane
389
+ # mints it for the island (a MathML island under a
390
+ # namespace-less root, #1342's family).
391
+ def blank_opt_out_unspellable?(child_plan, item)
392
+ return false if item.is_a?(::Lutaml::Model::Serialize) &&
393
+ prefixed_source?(item)
394
+
395
+ ns = child_plan.dig(:tree, :ns)
396
+ return false unless ns.is_a?(::Hash) && ns[:prefix].to_s.empty?
397
+
398
+ (child_plan.dig(:tree, :children) || []).any? do |r|
399
+ r[:ns] == :blank
400
+ end
401
+ end
402
+
382
403
  # Namespace-emittability for ORDERED trees: content and
383
404
  # wildcard rows carry no spelling of their own (content
384
405
  # emits text; wildcards bail in subtree_gate_ok?), so the
@@ -19,8 +19,40 @@ module Lutaml
19
19
  # child_row_plans).
20
20
  CHILD_ROW_KINDS = %i[nested ordered_deferred].freeze
21
21
  XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"
22
+ # Fiber-local bridge context and its nesting depth (see call).
23
+ BRIDGE_CONTEXT_KEY = :lutaml_plan_hydrator_bridge_context
24
+ BRIDGE_DEPTH_KEY = :lutaml_plan_hydrator_bridge_depth
22
25
 
23
26
  class << self
27
+ # Wrappers for deferred islands bridge leptris nodes into one
28
+ # moxml context per top-level deserialization, never for the
29
+ # process: on Ruby >= 4.0 (and < 3.4) moxml's wrapper registry
30
+ # is a strong Hash (moxml#303), and a context kept any longer
31
+ # pins every bridged document's whole tree for the life of the
32
+ # process — one registered wrapper references its native, the
33
+ # native its document, the document every node
34
+ # (lutaml-model#1335). Wrappers a model keeps stay alive
35
+ # through the model's own references; the registry's go when
36
+ # the deserialization returns.
37
+ def call(model_class, plan, value, **kwargs)
38
+ depth = (Thread.current[BRIDGE_DEPTH_KEY] || 0) + 1
39
+ Thread.current[BRIDGE_DEPTH_KEY] = depth
40
+ begin
41
+ hydrate(model_class, plan, value, **kwargs)
42
+ ensure
43
+ release_bridge_context(depth)
44
+ end
45
+ end
46
+
47
+ def release_bridge_context(depth)
48
+ if depth > 1
49
+ Thread.current[BRIDGE_DEPTH_KEY] = depth - 1
50
+ else
51
+ Thread.current[BRIDGE_DEPTH_KEY] = nil
52
+ Thread.current[BRIDGE_CONTEXT_KEY] = nil
53
+ end
54
+ end
55
+
24
56
  # plan: the compiled plan entry for model_class
25
57
  # value: the walk root PlanValue (element)
26
58
  # node: the parsed source element (leptris); ordered/mixed
@@ -31,8 +63,25 @@ module Lutaml
31
63
  # :lazy is honored as :eager — the lazy variant pins the
32
64
  # raw engine DOM, the retention the eager default exists
33
65
  # to avoid)
34
- def call(model_class, plan, value, parent: nil, node: nil,
35
- register: nil, declaration_plan_mode: :eager, intern: nil)
66
+ # parent_prefix: the enclosing instance's recorded source prefix
67
+ # (nil for the root) — a nested instance records its own only
68
+ # under a parent that recorded none, the interpretive reader's
69
+ # rule
70
+ def hydrate(model_class, plan, value, parent: nil, node: nil,
71
+ register: nil, declaration_plan_mode: :eager, intern: nil,
72
+ parent_prefix: nil)
73
+ # Prefix fidelity (the interpretive transform records it from
74
+ # the source element): prefixed sources keep their prefixes
75
+ # through the serialize lane's format preservation — on the
76
+ # root, and on a nested instance whose parent recorded none
77
+ # (the interpretive reader's rule; a nested island spelled
78
+ # `<p:leaf>` under a default-namespace root re-emits with its
79
+ # prefix, #1342).
80
+ source_prefix = if node.respond_to?(:prefix) then node.prefix end
81
+ own_prefix = if parent_prefix.to_s.empty? && source_prefix &&
82
+ !source_prefix.empty?
83
+ source_prefix
84
+ end
36
85
  # The child model's declared lutaml_default_register takes
37
86
  # precedence over the ambient register — the same
38
87
  # resolve_for_child contract the interpretive path applies.
@@ -55,7 +104,7 @@ module Lutaml
55
104
  child_kwargs, children, delegates, run_children,
56
105
  element_children =
57
106
  children_kwargs(model_class, plan, value, buckets, register,
58
- intern, node: node)
107
+ intern, node: node, parent_prefix: own_prefix)
59
108
  # A collection absent from the document keeps the
60
109
  # deserialization seed's lazy sentinel and its default mark
61
110
  # — the interpretive parse's state. The reader materializes
@@ -68,14 +117,7 @@ module Lutaml
68
117
  instance = model_class.instantiate(attr_kwargs, register)
69
118
  instance.lutaml_parent = parent if parent
70
119
  instance.lutaml_root ||= parent&.lutaml_root || parent
71
- # Root prefix fidelity (the interpretive transform records
72
- # it from the source element): prefixed sources keep their
73
- # prefixes through the serialize lane's format
74
- # preservation.
75
- if parent.nil? && node.respond_to?(:prefix) && node.prefix &&
76
- !node.prefix.empty?
77
- instance.xml_namespace_prefix = node.prefix
78
- end
120
+ instance.xml_namespace_prefix = own_prefix if own_prefix
79
121
  # #909: order summaries are per-instance pinned records —
80
122
  # read-only consumers skip them via the config. Ordered and
81
123
  # sequence models record them: the ordered walk replays
@@ -108,6 +150,8 @@ module Lutaml
108
150
  instance
109
151
  end
110
152
 
153
+ private :hydrate, :release_bridge_context
154
+
111
155
  # leptris#1874: snapshot rows -> the ns_data hash
112
156
  # ({path => {prefix_key => {uri:, prefix:, format:}}}), the
113
157
  # exact shape the recursion builds. Public: it is the
@@ -405,7 +449,8 @@ module Lutaml
405
449
  # parent/root links once the parent exists; delegate values
406
450
  # wait for the instance (their target object must exist).
407
451
  def children_kwargs(_model_class, plan, value, buckets = nil,
408
- register = nil, intern = {}, node: nil)
452
+ register = nil, intern = {}, node: nil,
453
+ parent_prefix: nil)
409
454
  register ||= Lutaml::Model::Config.default_register
410
455
  grouped, tagged, run_children = group_children(value,
411
456
  plan[:row_tags])
@@ -506,7 +551,8 @@ module Lutaml
506
551
  items = (selected || []).map do |n|
507
552
  call(child_type, child_plan,
508
553
  child_plan[:descriptor].walk(n), node: n,
509
- register: child_register, intern: intern)
554
+ register: child_register, intern: intern,
555
+ parent_prefix: parent_prefix)
510
556
  end
511
557
  unless items.empty?
512
558
  children.concat(items)
@@ -576,7 +622,8 @@ module Lutaml
576
622
  items = selected.map do |n|
577
623
  call(child_type, child_plan,
578
624
  child_plan[:descriptor].walk(n), node: n,
579
- register: child_register, intern: intern)
625
+ register: child_register, intern: intern,
626
+ parent_prefix: parent_prefix)
580
627
  end
581
628
  else
582
629
  values = grouped.fetch(name, [])
@@ -591,7 +638,8 @@ module Lutaml
591
638
  while pos < count
592
639
  items[pos] = call(child_type, child_plan, values[pos],
593
640
  node: cursor && cursor[pos],
594
- register: child_register, intern: intern)
641
+ register: child_register, intern: intern,
642
+ parent_prefix: parent_prefix)
595
643
  pos += 1
596
644
  end
597
645
  end
@@ -804,7 +852,7 @@ module Lutaml
804
852
  end
805
853
 
806
854
  def bridge_context
807
- @bridge_context ||= Moxml::Context.new(:leptris)
855
+ Thread.current[BRIDGE_CONTEXT_KEY] ||= Moxml::Context.new(:leptris)
808
856
  end
809
857
 
810
858
  # Rows carry the delegate NAME (the interpretive