namo.rb 0.32.9 → 0.32.11

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: 1ac4c2ed4449845cc475c09c946ae8af32b1ba977bed2353b1a665d597e108e5
4
- data.tar.gz: 6e221c9bbe2cfc562018b57fdbd4b8476868c203385bc3ca1d9dbd19c209dda0
3
+ metadata.gz: 1a779bff571ed33b0f11df7af1456c70212b0fde51552760b99abda949a3db57
4
+ data.tar.gz: f27816b28720d3d7c8d8b4511df430c4f12326c45a8fa3c17f9c64b36bfa6155
5
5
  SHA512:
6
- metadata.gz: f9331f7db05e3764548010efdc808f09b12f183a31ff6c6655f0a90644653128ce3696062b090921f47f941441a0a1d92f676a2b54a8c1e3c53aabbbeecafbcc
7
- data.tar.gz: 511c00d86f20a981154be910d1345d309c6fdd45636e33a7bceeee626803a69f46553fa969495210f264d1f7921e6f29d3c800f1cb8f5b23592cc02e8e996371
6
+ metadata.gz: ddcc73857b5a17493a633eac77df312f93f270c522f7c747bbe323335a90e9c7f3c63fd4693acffbf2b07cc718a45f7207a171f362dfe85194764c9787bcbbcc
7
+ data.tar.gz: 51f7c6b0ac40d6e07337ae9a797918eb1289c3cb97dd3d642408d185bd94383f3b5574376079492fe7472929f2683ecc04388462cfe580d4dcd1b5035614a3c0
data/CHANGELOG CHANGED
@@ -1,5 +1,21 @@
1
1
  # namo/CHANGELOG
2
2
 
3
+ ## 20261109
4
+
5
+ 0.32.11: ~ test/namo_test.rb: The two tests added in 0.32.10 pass under minitest 6.1.
6
+
7
+ 1. ~ test/namo_test.rb: The Hashes the two access-scope tests expect are in braces, since minitest 6.1.0 takes a Hash given to must_equal without them as keyword arguments, leaving the expected value nil.
8
+ 2. ~ Namo::VERSION: /0.32.10/0.32.11/
9
+
10
+ ## 20261103
11
+
12
+ 0.32.10: ~ Namo#materialising: A frozen Namo can be read again, and two threads reading one Namo no longer share a scope.
13
+
14
+ 1. ~ Namo#materialising, #values_for: + #materialised_scopes, - @materialised. An access's scope is held per fiber, keyed by the Namo, rather than on the Namo itself. Since 0.29.0, every read wrote to the Namo, so values, coordinates, and to_a raised FrozenError on a frozen Namo, and two threads reading one Namo shared a scope which either could clear while the other was using it.
15
+ 2. ~ test/namo_test.rb: Reading a frozen Namo through a two-arity formula is tested, as is an access keeping its scope when another thread's access to the same Namo ends part-way through it.
16
+ 3. ~ ROADMAP.md: The 0.32.10 change is described.
17
+ 4. ~ Namo::VERSION: /0.32.9/0.32.10/
18
+
3
19
  ## 20261102
4
20
 
5
21
  0.32.9: + comparison/setup: Builds the environments the comparison/*_claims scripts run in, at the versions COMPARISON.md names, or with --latest the newest releases.
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.32.9'
5
+ VERSION = '0.32.11'
6
6
  end
data/lib/namo.rb CHANGED
@@ -368,18 +368,25 @@ class Namo
368
368
  end
369
369
  end
370
370
 
371
+ # An access's scope is held per fiber, keyed by the Namo, rather than on the Namo
372
+ # itself, so as a frozen Namo can be read and two threads reading one Namo don't
373
+ # share a scope.
371
374
  def materialising
372
- return yield if @materialised
373
- @materialised = {}
375
+ return yield if materialised_scopes.key?(self)
376
+ materialised_scopes[self] = {}
374
377
  begin
375
378
  yield
376
379
  ensure
377
- @materialised = nil
380
+ materialised_scopes.delete(self)
378
381
  end
379
382
  end
380
383
 
384
+ def materialised_scopes
385
+ Thread.current[:namo_materialised_scopes] ||= {}.compare_by_identity
386
+ end
387
+
381
388
  def values_for(dim)
382
- @materialised[dim] ||= (
389
+ materialised_scopes[self][dim] ||= (
383
390
  if data_dimensions.include?(dim)
384
391
  @data.map{|row_data| row_data[dim]}
385
392
  else
data/test/namo_test.rb CHANGED
@@ -322,9 +322,33 @@ describe Namo do
322
322
  namo[:agg] = proc{|row, namo| namo.values(:base).first}
323
323
  # :agg's formula calls values(:base) mid-materialisation; that nested call must
324
324
  # reuse the open scope, not reset it, so the :x column that follows still builds.
325
- _(namo.values(:agg, :x)).must_equal(agg: [2, 2, 2], x: [1, 2, 3])
325
+ _(namo.values(:agg, :x)).must_equal({agg: [2, 2, 2], x: [1, 2, 3]})
326
326
  _(calls).must_equal 3
327
327
  end
328
+
329
+ it "reads a frozen Namo, the scope being held off the receiver" do
330
+ namo = Namo.new([{x: 1}, {x: 2}])
331
+ namo[:double] = proc{|row| row[:x] * 2}
332
+ namo[:total] = proc{|row, namo| namo.values(:double).sum}
333
+ namo.freeze
334
+ _(namo.values(:total)).must_equal [6, 6]
335
+ _(namo.coordinates(:double)).must_equal [2, 4]
336
+ _(namo.to_a).must_equal [{x: 1, double: 2, total: 6}, {x: 2, double: 4, total: 6}]
337
+ end
338
+
339
+ it "gives each thread reading one Namo a scope of its own" do
340
+ namo = Namo.new([{n: 1}])
341
+ entered, released = Queue.new, Queue.new
342
+ holder = nil
343
+ namo[:held] = proc{|row| entered << true; released.pop; row[:n]}
344
+ # :reader's formula lets the holding thread's access finish mid-way through this
345
+ # one, which must leave this access's scope standing for the :n that follows.
346
+ namo[:reader] = proc{|row| released << true; holder.join; row[:n]}
347
+ holder = Thread.new{namo.values(:held)}
348
+ entered.pop
349
+ _(namo.values(:reader, :n)).must_equal({reader: [1], n: [1]})
350
+ _(holder.value).must_equal [1]
351
+ end
328
352
  end
329
353
 
330
354
  describe "#to_h" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namo.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.9
4
+ version: 0.32.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran