hegeltest 0.4.1 → 0.5.1
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 +4 -4
- data/CHANGELOG.md +55 -0
- data/lib/hegel/lib_hegel/real.rb +78 -68
- data/lib/hegel/lib_hegel.rb +2 -1
- data/lib/hegel/libhegel_version.rb +1 -1
- data/lib/hegel/runner.rb +2 -2
- data/lib/hegel/stateful.rb +18 -7
- data/lib/hegel/test_case.rb +22 -4
- data/lib/hegel/version.rb +1 -1
- data/sig/hegel.rbs +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4d64e49f806952b3c95f8f6d163d87c8ed718e9d5f4feee6307c28ad17c2db5
|
|
4
|
+
data.tar.gz: 89f510f4cc4c9f3e59c5e48ed38735d96fe79a98ea0b7579a5a1f7cdda1ac8aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6eb6d9b2a9c54caa3f428bfd543b775ec84c8f894b472cd68bf0daa5b4ffd00393a5724e7091082558f949e80512681632bd5519b8e3a9dba7039cdd6326255
|
|
7
|
+
data.tar.gz: 6c56ccf4cc4d76d5b6841d5a691f742ae840efe099e488a9421c1435be230b01f7f2ece41de71ed1d783d527303c040ddbc92d01530d8fbb61832c9ded53f5dc
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.5.1] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Engine: libhegel 0.51.1 (was 0.50.0)
|
|
8
|
+
|
|
9
|
+
The [libhegel 0.51.1 release notes](https://github.com/hegeldev/hegel/releases/tag/libhegel/0.51.1)
|
|
10
|
+
describe 0.51.1. The move also includes 0.51.0, and the
|
|
11
|
+
[libhegel changelog at 0.51.1](https://github.com/hegeldev/hegel/blob/libhegel/0.51.1/libhegel/CHANGELOG.md)
|
|
12
|
+
describes both releases.
|
|
13
|
+
|
|
14
|
+
Each platform gem carries `libhegel` 0.51.1. A caller has nothing to
|
|
15
|
+
change. The public methods keep their signatures and return values.
|
|
16
|
+
|
|
17
|
+
In 0.51.0, the engine lets a state machine redraw its configuration
|
|
18
|
+
between rounds, and to do this it changes one function that these
|
|
19
|
+
bindings call: `hegel_state_machine_next_group` takes a new out-parameter
|
|
20
|
+
for the concurrency level of the round. These bindings pass it.
|
|
21
|
+
`Hegel::Stateful.run` and `Hegel::StateMachine` keep a sequential
|
|
22
|
+
machine, so the level is always 1. At the start of each round, the engine
|
|
23
|
+
now redraws, with probability 1/50, which rules the machine enables and
|
|
24
|
+
how it distributes drawn values, as the engine release notes say. A long
|
|
25
|
+
run can so explore more than one configuration.
|
|
26
|
+
|
|
27
|
+
In 0.51.1, a run of one test case (`test_cases: 1`) inside Antithesis
|
|
28
|
+
(`ANTITHESIS_OUTPUT_DIR` is set) with no `database_key` does not record
|
|
29
|
+
the choices of its test case. Its failure is reported from its one
|
|
30
|
+
execution: `Hegel.test` raises the exception of the body, but the engine
|
|
31
|
+
does not shrink or replay the failure, the report shows no drawn values,
|
|
32
|
+
and it has no reproduce blob. A run outside Antithesis, or with a
|
|
33
|
+
`database_key`, does not change.
|
|
34
|
+
|
|
35
|
+
## [0.5.0] - 2026-11-04
|
|
36
|
+
|
|
37
|
+
### Engine: libhegel 0.50.0 (was 0.49.0)
|
|
38
|
+
|
|
39
|
+
The [libhegel 0.50.0 release notes](https://github.com/hegeldev/hegel/releases/tag/libhegel/0.50.0)
|
|
40
|
+
describe 0.50.0.
|
|
41
|
+
|
|
42
|
+
Each platform gem carries `libhegel` 0.50.0. The engine changes how a caller
|
|
43
|
+
declares a state machine: `hegel_new_state_machine` now opens an empty
|
|
44
|
+
machine, and new calls declare each rule and each invariant and then start
|
|
45
|
+
the machine. These bindings make the new calls. A caller of
|
|
46
|
+
`Hegel::Stateful.run` and `Hegel::StateMachine` has nothing to change, and
|
|
47
|
+
gets the same rules, weights, and invariants as before.
|
|
48
|
+
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- `Hegel::TestCase#new_state_machine` takes only the step count. The new
|
|
52
|
+
methods `#state_machine_add_rule`, `#state_machine_add_invariant`, and
|
|
53
|
+
`#state_machine_start` declare the rules and invariants and start the
|
|
54
|
+
machine, in the same order as the engine calls. `Hegel::Stateful.run`
|
|
55
|
+
uses them. A caller who called `#new_state_machine` directly must change
|
|
56
|
+
to the new methods.
|
|
57
|
+
|
|
5
58
|
## [0.4.1] - 2026-10-29
|
|
6
59
|
|
|
7
60
|
### Engine: libhegel 0.49.0 (was 0.48.0)
|
|
@@ -492,6 +545,8 @@ The engine is called through the `ffi` gem. Each platform gem carries the
|
|
|
492
545
|
matching `libhegel` 0.32.5 build. The platform-independent gem carries none,
|
|
493
546
|
so a run on it needs `HEGEL_LIBHEGEL_PATH` pointing at a local build.
|
|
494
547
|
|
|
548
|
+
[0.5.1]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.1
|
|
549
|
+
[0.5.0]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.0
|
|
495
550
|
[0.4.1]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.4.1
|
|
496
551
|
[0.4.0]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.4.0
|
|
497
552
|
[0.3.4]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.3.4
|
data/lib/hegel/lib_hegel/real.rb
CHANGED
|
@@ -215,14 +215,20 @@ module Hegel
|
|
|
215
215
|
@hegel_recursion_free_fn = bind("hegel_recursion_free", [:pointer, :pointer], :int32)
|
|
216
216
|
|
|
217
217
|
@hegel_new_state_machine_fn = bind(
|
|
218
|
-
"hegel_new_state_machine",
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
], :int32
|
|
218
|
+
"hegel_new_state_machine", [:pointer, :pointer, :int64, :int64, :int64, :pointer], :int32
|
|
219
|
+
)
|
|
220
|
+
@hegel_state_machine_add_rule_fn = bind(
|
|
221
|
+
"hegel_state_machine_add_rule",
|
|
222
|
+
[:pointer, :pointer, :pointer, StringStruct.by_value, :double, :pointer, :size_t], :int32
|
|
223
|
+
)
|
|
224
|
+
@hegel_state_machine_add_invariant_fn = bind(
|
|
225
|
+
"hegel_state_machine_add_invariant", [:pointer, :pointer, :pointer, StringStruct.by_value, :bool], :int32
|
|
226
|
+
)
|
|
227
|
+
@hegel_state_machine_start_fn = bind(
|
|
228
|
+
"hegel_state_machine_start", [:pointer, :pointer, :pointer, :pointer], :int32
|
|
223
229
|
)
|
|
224
230
|
@hegel_state_machine_next_group_fn = bind(
|
|
225
|
-
"hegel_state_machine_next_group", [:pointer, :pointer, :pointer, :pointer], :int32
|
|
231
|
+
"hegel_state_machine_next_group", [:pointer, :pointer, :pointer, :pointer, :pointer], :int32
|
|
226
232
|
)
|
|
227
233
|
@hegel_state_machine_next_rule_fn = bind(
|
|
228
234
|
"hegel_state_machine_next_rule", [:pointer, :pointer, :pointer, :int64, :pointer], :int32
|
|
@@ -944,59 +950,79 @@ module Hegel
|
|
|
944
950
|
end
|
|
945
951
|
|
|
946
952
|
# Returns a caller-owned state-machine handle, released separately
|
|
947
|
-
# with #state_machine_free.
|
|
948
|
-
#
|
|
949
|
-
#
|
|
950
|
-
#
|
|
951
|
-
#
|
|
952
|
-
#
|
|
953
|
-
# of labor #new_collection leaves to the caller for its own
|
|
954
|
-
# min_size/max_size ordering.
|
|
953
|
+
# with #state_machine_free. The machine is empty: declare each rule
|
|
954
|
+
# with #state_machine_add_rule and each invariant with
|
|
955
|
+
# #state_machine_add_invariant, then seal it with
|
|
956
|
+
# #state_machine_start. Since libhegel 0.50.0 these are separate
|
|
957
|
+
# calls. Before 0.50.0, hegel_new_state_machine took every rule and
|
|
958
|
+
# invariant in one call.
|
|
955
959
|
#
|
|
956
|
-
#
|
|
957
|
-
#
|
|
958
|
-
#
|
|
959
|
-
#
|
|
960
|
-
#
|
|
961
|
-
# and
|
|
962
|
-
|
|
963
|
-
# needs one worker thread per drawn level. For the same reason the
|
|
964
|
-
# rule calls below pass worker index 0, the only worker there is.
|
|
965
|
-
def new_state_machine(ctx, tc, rule_names, rule_weights, invariant_names, always_check, step_count)
|
|
960
|
+
# The machine is always sequential: a concurrency of exactly 1, so
|
|
961
|
+
# every concurrency level the engine draws is 1. These bindings drive
|
|
962
|
+
# the engine from one thread, and a concurrent machine needs one
|
|
963
|
+
# worker thread for each of max_concurrency workers. For the same
|
|
964
|
+
# reason the rule calls below pass worker index 0, the only worker
|
|
965
|
+
# there is, and that worker is active in every round.
|
|
966
|
+
def new_state_machine(ctx, tc, step_count)
|
|
966
967
|
out = FFI::MemoryPointer.new(:pointer)
|
|
967
|
-
|
|
968
|
-
# _rule_pointers / _invariant_pointers are unread past the call
|
|
969
|
-
# below, the same shape #generate_integer_big's own
|
|
970
|
-
# min_value_ptr/max_value_ptr already have; keeping them as local
|
|
971
|
-
# variables here, not discarded inside #pack_name_array, is what
|
|
972
|
-
# keeps the native buffers each one owns live through the call.
|
|
973
|
-
# The leading underscore tells the linter that on purpose, the
|
|
974
|
-
# same way it would for a block argument the block never reads.
|
|
975
|
-
rule_names_ptr, _rule_pointers = pack_name_array(rule_names)
|
|
976
|
-
invariant_names_ptr, _invariant_pointers = pack_name_array(invariant_names)
|
|
977
|
-
# A fresh MemoryPointer is zero-filled, which puts every rule in
|
|
978
|
-
# group 0.
|
|
979
|
-
rule_groups = FFI::MemoryPointer.new(:int64, rule_names.size)
|
|
980
|
-
weights = FFI::MemoryPointer.new(:double, rule_weights.size)
|
|
981
|
-
weights.write_array_of_double(rule_weights.map(&:to_f))
|
|
982
|
-
|
|
983
|
-
code = @hegel_new_state_machine_fn.call(
|
|
984
|
-
ctx, tc, rule_names_ptr, rule_groups, weights, rule_names.size,
|
|
985
|
-
invariant_names_ptr, pack_flags(always_check), invariant_names.size,
|
|
986
|
-
1, 1, step_count, out, out_concurrency
|
|
987
|
-
)
|
|
968
|
+
code = @hegel_new_state_machine_fn.call(ctx, tc, 1, 1, step_count, out)
|
|
988
969
|
LibHegel.check!(self, ctx, code)
|
|
989
970
|
out.read_pointer
|
|
990
971
|
end
|
|
991
972
|
|
|
973
|
+
# Declares the next rule. The engine numbers rules in declaration
|
|
974
|
+
# order from 0, and #state_machine_next_rule hands out that number.
|
|
975
|
+
# The engine rejects a +weight+ that is not finite and positive, and a
|
|
976
|
+
# +name+ that is not UTF-8.
|
|
977
|
+
#
|
|
978
|
+
# Every rule is in group 0, the one group a sequential machine needs.
|
|
979
|
+
def state_machine_add_rule(ctx, tc, state_machine, name, weight)
|
|
980
|
+
# A fresh MemoryPointer is zero-filled, so this holds group id 0.
|
|
981
|
+
groups = FFI::MemoryPointer.new(:int64, 1)
|
|
982
|
+
code = @hegel_state_machine_add_rule_fn.call(
|
|
983
|
+
ctx, tc, state_machine, string_view(name), weight.to_f, groups, 1
|
|
984
|
+
)
|
|
985
|
+
LibHegel.check!(self, ctx, code)
|
|
986
|
+
nil
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
# Declares the next invariant, numbered in declaration order from 0
|
|
990
|
+
# as #state_machine_should_check_invariant reads it. With
|
|
991
|
+
# +always_check+, the engine answers true for it at every join point.
|
|
992
|
+
def state_machine_add_invariant(ctx, tc, state_machine, name, always_check)
|
|
993
|
+
code = @hegel_state_machine_add_invariant_fn.call(ctx, tc, state_machine, string_view(name), always_check)
|
|
994
|
+
LibHegel.check!(self, ctx, code)
|
|
995
|
+
nil
|
|
996
|
+
end
|
|
997
|
+
|
|
998
|
+
# Seals the declared rules and invariants, and returns the number of
|
|
999
|
+
# workers the caller must run: max_concurrency, since libhegel
|
|
1000
|
+
# 0.51.0. Before 0.51.0, it was the concurrency level the engine drew.
|
|
1001
|
+
# For the machine #new_state_machine opens, both are always 1.
|
|
1002
|
+
def state_machine_start(ctx, tc, state_machine)
|
|
1003
|
+
out = FFI::MemoryPointer.new(:int64)
|
|
1004
|
+
code = @hegel_state_machine_start_fn.call(ctx, tc, state_machine, out)
|
|
1005
|
+
LibHegel.check!(self, ctx, code)
|
|
1006
|
+
out.read_int64
|
|
1007
|
+
end
|
|
1008
|
+
|
|
992
1009
|
# Starts the machine's next round. Returns the round's group id, or
|
|
993
1010
|
# HEGEL_STATE_MACHINE_DONE once the machine is done, as the raw
|
|
994
1011
|
# value: the caller compares against the sentinel, the same way
|
|
995
1012
|
# #run_result_status hands back its raw HEGEL_RUN_STATUS_* value
|
|
996
1013
|
# unexamined.
|
|
1014
|
+
#
|
|
1015
|
+
# Since libhegel 0.51.0, the call also writes the round's concurrency
|
|
1016
|
+
# level, which the engine can redraw between rounds. This method
|
|
1017
|
+
# discards it: for the machine #new_state_machine opens, the level is
|
|
1018
|
+
# always 1, so worker 0 gets rules in every round. The sequential
|
|
1019
|
+
# path of the Rust frontend (frontends/rust/src/stateful.rs) also
|
|
1020
|
+
# ignores the level. The engine writes through both pointers, so the
|
|
1021
|
+
# binding must pass a valid one for each.
|
|
997
1022
|
def state_machine_next_group(ctx, tc, state_machine)
|
|
998
1023
|
out = FFI::MemoryPointer.new(:int64)
|
|
999
|
-
|
|
1024
|
+
concurrency = FFI::MemoryPointer.new(:int64)
|
|
1025
|
+
code = @hegel_state_machine_next_group_fn.call(ctx, tc, state_machine, out, concurrency)
|
|
1000
1026
|
LibHegel.check!(self, ctx, code)
|
|
1001
1027
|
out.read_int64
|
|
1002
1028
|
end
|
|
@@ -1449,9 +1475,8 @@ module Hegel
|
|
|
1449
1475
|
end
|
|
1450
1476
|
|
|
1451
1477
|
# Packs +names+ (an Array of Ruby Strings) into a contiguous array of
|
|
1452
|
-
# hegel_string_t
|
|
1453
|
-
#
|
|
1454
|
-
# its own slot of a single buffer.
|
|
1478
|
+
# hegel_string_t: one StringStruct per name, each written in place
|
|
1479
|
+
# over its own slot of a single buffer.
|
|
1455
1480
|
#
|
|
1456
1481
|
# Returns [pointer, kept_alive]. #write_string copies each name into
|
|
1457
1482
|
# a fresh native buffer -- nothing here depends on the original
|
|
@@ -1461,17 +1486,11 @@ module Hegel
|
|
|
1461
1486
|
# structs) as a live local for the length of the call is what keeps
|
|
1462
1487
|
# the buffers each one owns from being garbage-collected first.
|
|
1463
1488
|
#
|
|
1464
|
-
# Empty +names+ maps to [nil, []]
|
|
1465
|
-
#
|
|
1466
|
-
# invariants" case. #new_state_machine reuses this same packing for
|
|
1467
|
-
# rule_names too, whose own documented non-empty requirement this
|
|
1468
|
-
# method does not enforce; that validation belongs one layer up, in
|
|
1469
|
-
# a caller that can raise Hegel::Error with a message naming the
|
|
1470
|
-
# factory method, not in a method whose only job is packing an
|
|
1471
|
-
# Array into a buffer.
|
|
1489
|
+
# Empty +names+ maps to [nil, []]. #optional_name_array then gives
|
|
1490
|
+
# the caller a non-NULL pointer for it.
|
|
1472
1491
|
def pack_name_array(names)
|
|
1473
|
-
#
|
|
1474
|
-
#
|
|
1492
|
+
# Removing this guard only allocates a zero-length buffer, which
|
|
1493
|
+
# #optional_name_array passes on in place of its own.
|
|
1475
1494
|
return [nil, []] if names.empty? # mutineer:disable-line statement_removal
|
|
1476
1495
|
|
|
1477
1496
|
array = FFI::MemoryPointer.new(StringStruct, names.size)
|
|
@@ -1491,15 +1510,6 @@ module Hegel
|
|
|
1491
1510
|
[array || FFI::MemoryPointer.new(StringStruct), slots]
|
|
1492
1511
|
end
|
|
1493
1512
|
|
|
1494
|
-
# Packs +flags+ (an Array of true/false) into a const bool * buffer,
|
|
1495
|
-
# one byte each. An empty Array packs to a zero-length buffer, which the
|
|
1496
|
-
# engine reads zero flags from.
|
|
1497
|
-
def pack_flags(flags)
|
|
1498
|
-
buffer = FFI::MemoryPointer.new(:uint8, flags.size)
|
|
1499
|
-
buffer.write_array_of_uint8(flags.map { |flag| flag ? 1 : 0 })
|
|
1500
|
-
buffer
|
|
1501
|
-
end
|
|
1502
|
-
|
|
1503
1513
|
# Writes +value+ (a [year, month, day] Array) into +struct+'s own
|
|
1504
1514
|
# :year/:month/:day fields. Shared by #date_struct, which builds a
|
|
1505
1515
|
# standalone DateStruct, and #datetime_struct, which writes the same
|
data/lib/hegel/lib_hegel.rb
CHANGED
|
@@ -151,7 +151,8 @@ module Hegel
|
|
|
151
151
|
settings_set_backend settings_set_test_location
|
|
152
152
|
target event event_value
|
|
153
153
|
new_pool pool_add pool_generate pool_restore pool_free
|
|
154
|
-
new_state_machine
|
|
154
|
+
new_state_machine state_machine_add_rule state_machine_add_invariant state_machine_start
|
|
155
|
+
state_machine_next_group state_machine_next_rule state_machine_rule_rejected
|
|
155
156
|
state_machine_should_check_invariant state_machine_free
|
|
156
157
|
grammar_builder_new grammar_builder_file grammar_builder_provide grammar_builder_free
|
|
157
158
|
grammar_new grammar_placeholder grammar_free generate_grammar
|
|
@@ -5,5 +5,5 @@ module Hegel
|
|
|
5
5
|
# Hegel::VERSION (the gem's own release): hegel-go and hegel-typescript keep
|
|
6
6
|
# the two separate too, so bumping the pinned engine can land as its own
|
|
7
7
|
# commit without also releasing a new gem version.
|
|
8
|
-
LIBHEGEL_VERSION = "0.
|
|
8
|
+
LIBHEGEL_VERSION = "0.51.1"
|
|
9
9
|
end
|
data/lib/hegel/runner.rb
CHANGED
|
@@ -202,9 +202,9 @@ module Hegel
|
|
|
202
202
|
# Pulls test cases from +run+ until hegel_next_test_case reports none
|
|
203
203
|
# left (a nil out-parameter, not an error). Never counts iterations
|
|
204
204
|
# itself: test_cases bounds generation, not how many times shrinking
|
|
205
|
-
# and rejected cases call the body. Measured against libhegel 0.
|
|
205
|
+
# and rejected cases call the body. Measured against libhegel 0.51.1, a
|
|
206
206
|
# run configured for 20 test cases whose body rejected nearly every case
|
|
207
|
-
# took
|
|
207
|
+
# took 858 to 1842 iterations over 30 runs. +stats+ does its own, different counting
|
|
208
208
|
# -- see GenerationStats above.
|
|
209
209
|
def drive(impl, ctx, run, grammars, stats, captures, &block)
|
|
210
210
|
loop do
|
data/lib/hegel/stateful.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative "stateful/pool"
|
|
|
6
6
|
|
|
7
7
|
module Hegel
|
|
8
8
|
# Runs one stateful (model-based) test: drives libhegel's own state-machine
|
|
9
|
-
# loop (hegel_new_state_machine and the
|
|
9
|
+
# loop (hegel_new_state_machine and the calls that go with it) against
|
|
10
10
|
# a Hegel::StateMachine instance's declared rules and invariants. Call it
|
|
11
11
|
# from inside an ordinary Hegel.test block, the same way any other draw
|
|
12
12
|
# happens:
|
|
@@ -34,18 +34,17 @@ module Hegel
|
|
|
34
34
|
# rejects it.
|
|
35
35
|
#
|
|
36
36
|
# Raises Hegel::Error before making any libhegel call when +machine+
|
|
37
|
-
# declares no rules: hegel.h documents
|
|
38
|
-
#
|
|
39
|
-
#
|
|
37
|
+
# declares no rules: hegel.h documents that hegel_state_machine_start
|
|
38
|
+
# refuses a machine with no rule, and there is nothing useful to run
|
|
39
|
+
# without one.
|
|
40
40
|
def run(machine, tc, step_count: DEFAULT_STEP_COUNT)
|
|
41
41
|
rules = machine.class.rule_definitions
|
|
42
42
|
raise Hegel::Error, "hegel: #{machine.class} has no rules; declare at least one with `rule`" if rules.empty?
|
|
43
43
|
|
|
44
44
|
invariants = machine.class.invariant_definitions
|
|
45
|
-
state_machine = tc.new_state_machine(
|
|
46
|
-
rules.keys, rules.values.map(&:weight), invariants.keys, invariants.values.map(&:always_run), step_count
|
|
47
|
-
)
|
|
45
|
+
state_machine = tc.new_state_machine(step_count)
|
|
48
46
|
begin
|
|
47
|
+
declare(rules, invariants, state_machine, tc)
|
|
49
48
|
tc.note { "Initial invariant check." }
|
|
50
49
|
run_invariants(machine, invariants.values, tc)
|
|
51
50
|
drive(machine, rules, invariants.values, state_machine, tc)
|
|
@@ -56,6 +55,18 @@ module Hegel
|
|
|
56
55
|
end
|
|
57
56
|
end
|
|
58
57
|
|
|
58
|
+
# Declares every rule and invariant in declaration order, so the
|
|
59
|
+
# engine's rule and invariant indices are positions in +rules+ and
|
|
60
|
+
# +invariants+, then starts the machine. #run calls this inside its
|
|
61
|
+
# begin block, so the handle is freed when a declaration fails.
|
|
62
|
+
def declare(rules, invariants, state_machine, tc)
|
|
63
|
+
rules.each { |name, rule| tc.state_machine_add_rule(state_machine, name, rule.weight) }
|
|
64
|
+
invariants.each do |name, invariant|
|
|
65
|
+
tc.state_machine_add_invariant(state_machine, name, invariant.always_run)
|
|
66
|
+
end
|
|
67
|
+
tc.state_machine_start(state_machine)
|
|
68
|
+
end
|
|
69
|
+
|
|
59
70
|
# Runs rounds until libhegel ends the machine. Each round asks for a
|
|
60
71
|
# group first, which the header requires before the first rule too, then
|
|
61
72
|
# pulls rules until the round ends. Between rounds, each invariant runs
|
data/lib/hegel/test_case.rb
CHANGED
|
@@ -509,8 +509,26 @@ module Hegel
|
|
|
509
509
|
# here rather than on that module, the same reason every other native
|
|
510
510
|
# call is a method on this class: Hegel::Stateful never touches @impl or
|
|
511
511
|
# @ctx directly, only this handle-scoped surface.
|
|
512
|
-
def new_state_machine(
|
|
513
|
-
@impl.new_state_machine(@ctx, live_handle,
|
|
512
|
+
def new_state_machine(step_count)
|
|
513
|
+
@impl.new_state_machine(@ctx, live_handle, step_count)
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# hegel_state_machine_add_rule: declares the next rule, numbered in
|
|
517
|
+
# declaration order from 0.
|
|
518
|
+
def state_machine_add_rule(state_machine, name, weight)
|
|
519
|
+
@impl.state_machine_add_rule(@ctx, live_handle, state_machine, name, weight)
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
# hegel_state_machine_add_invariant: declares the next invariant,
|
|
523
|
+
# numbered in declaration order from 0.
|
|
524
|
+
def state_machine_add_invariant(state_machine, name, always_check)
|
|
525
|
+
@impl.state_machine_add_invariant(@ctx, live_handle, state_machine, name, always_check)
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
# hegel_state_machine_start: seals the declarations and returns the
|
|
529
|
+
# number of workers to run. No round may start before this call.
|
|
530
|
+
def state_machine_start(state_machine)
|
|
531
|
+
@impl.state_machine_start(@ctx, live_handle, state_machine)
|
|
514
532
|
end
|
|
515
533
|
|
|
516
534
|
# hegel_state_machine_next_group: starts the next round, or returns
|
|
@@ -519,8 +537,8 @@ module Hegel
|
|
|
519
537
|
@impl.state_machine_next_group(@ctx, live_handle, state_machine)
|
|
520
538
|
end
|
|
521
539
|
|
|
522
|
-
# hegel_state_machine_next_rule: the index (
|
|
523
|
-
# #
|
|
540
|
+
# hegel_state_machine_next_rule: the index (in the order of the
|
|
541
|
+
# #state_machine_add_rule calls) of the next rule to run this round, or
|
|
524
542
|
# LibHegel::HEGEL_STATE_MACHINE_DONE once the round is over.
|
|
525
543
|
def state_machine_next_rule(state_machine)
|
|
526
544
|
@impl.state_machine_next_rule(@ctx, live_handle, state_machine)
|
data/lib/hegel/version.rb
CHANGED
data/sig/hegel.rbs
CHANGED
|
@@ -76,7 +76,10 @@ module Hegel
|
|
|
76
76
|
def pool_restore: (untyped pool, Integer variable_id) -> nil
|
|
77
77
|
def pool_free: (untyped pool) -> nil
|
|
78
78
|
def free_pools: () -> void
|
|
79
|
-
def new_state_machine: (
|
|
79
|
+
def new_state_machine: (Integer step_count) -> untyped
|
|
80
|
+
def state_machine_add_rule: (untyped state_machine, String name, Numeric weight) -> nil
|
|
81
|
+
def state_machine_add_invariant: (untyped state_machine, String name, bool always_check) -> nil
|
|
82
|
+
def state_machine_start: (untyped state_machine) -> Integer
|
|
80
83
|
def state_machine_next_group: (untyped state_machine) -> Integer
|
|
81
84
|
def state_machine_next_rule: (untyped state_machine) -> Integer
|
|
82
85
|
def state_machine_rule_rejected: (untyped state_machine) -> nil
|
|
@@ -473,6 +476,7 @@ module Hegel
|
|
|
473
476
|
DEFAULT_STEP_COUNT: Integer
|
|
474
477
|
|
|
475
478
|
def self.run: (StateMachine machine, TestCase tc, ?step_count: Integer) -> void
|
|
479
|
+
def self.declare: (Hash[String, StateMachine::Rule] rules, Hash[String, StateMachine::Invariant] invariants, untyped state_machine, TestCase tc) -> Integer
|
|
476
480
|
def self.drive: (StateMachine machine, Hash[String, StateMachine::Rule] rules, Array[StateMachine::Invariant] invariants, untyped state_machine, TestCase tc) -> void
|
|
477
481
|
def self.apply_rule: (StateMachine machine, Proc block, untyped state_machine, TestCase tc) -> bool
|
|
478
482
|
def self.run_invariants: (StateMachine machine, Array[StateMachine::Invariant] invariants, TestCase tc) -> void
|
|
@@ -778,7 +782,10 @@ module Hegel
|
|
|
778
782
|
def pool_generate: (untyped ctx, untyped tc, untyped pool, bool consume) -> Integer
|
|
779
783
|
def pool_restore: (untyped ctx, untyped tc, untyped pool, Integer variable_id) -> nil
|
|
780
784
|
def pool_free: (untyped ctx, untyped pool) -> nil
|
|
781
|
-
def new_state_machine: (untyped ctx, untyped tc,
|
|
785
|
+
def new_state_machine: (untyped ctx, untyped tc, Integer step_count) -> untyped
|
|
786
|
+
def state_machine_add_rule: (untyped ctx, untyped tc, untyped state_machine, String name, Numeric weight) -> nil
|
|
787
|
+
def state_machine_add_invariant: (untyped ctx, untyped tc, untyped state_machine, String name, bool always_check) -> nil
|
|
788
|
+
def state_machine_start: (untyped ctx, untyped tc, untyped state_machine) -> Integer
|
|
782
789
|
def state_machine_next_group: (untyped ctx, untyped tc, untyped state_machine) -> Integer
|
|
783
790
|
def state_machine_next_rule: (untyped ctx, untyped tc, untyped state_machine) -> Integer
|
|
784
791
|
def state_machine_rule_rejected: (untyped ctx, untyped tc, untyped state_machine) -> nil
|