kumi 0.0.29 → 0.0.30

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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +5 -6
  5. data/docs/DEVELOPMENT.md +23 -1
  6. data/docs/GOLDEN_QUICK_START.md +141 -0
  7. data/docs/GOLDEN_TESTS.md +240 -0
  8. data/golden/array_element/expected/schema_ruby.rb +1 -1
  9. data/golden/array_index/expected/schema_ruby.rb +1 -1
  10. data/golden/array_operations/expected/schema_ruby.rb +1 -1
  11. data/golden/cascade_logic/expected/schema_ruby.rb +1 -1
  12. data/golden/chained_fusion/expected/schema_ruby.rb +1 -1
  13. data/golden/decimal_explicit/expected/schema_ruby.rb +1 -1
  14. data/golden/element_arrays/expected/schema_ruby.rb +1 -1
  15. data/golden/empty_and_null_inputs/expected/schema_ruby.rb +1 -1
  16. data/golden/function_overload/expected/schema_ruby.rb +1 -1
  17. data/golden/game_of_life/expected/schema_ruby.rb +1 -1
  18. data/golden/hash_keys/expected/schema_ruby.rb +1 -1
  19. data/golden/hash_value/expected/schema_ruby.rb +1 -1
  20. data/golden/hierarchical_complex/expected/schema_ruby.rb +1 -1
  21. data/golden/inline_rename_scope_leak/expected/schema_ruby.rb +1 -1
  22. data/golden/input_reference/expected/schema_ruby.rb +1 -1
  23. data/golden/interleaved_fusion/expected/schema_ruby.rb +1 -1
  24. data/golden/let_inline/expected/schema_ruby.rb +1 -1
  25. data/golden/loop_fusion/expected/schema_ruby.rb +1 -1
  26. data/golden/min_reduce_scope/expected/schema_ruby.rb +1 -1
  27. data/golden/mixed_dimensions/expected/schema_ruby.rb +1 -1
  28. data/golden/multirank_hoisting/expected/schema_ruby.rb +1 -1
  29. data/golden/nested_hash/expected/schema_ruby.rb +1 -1
  30. data/golden/reduction_broadcast/expected/schema_ruby.rb +1 -1
  31. data/golden/roll/expected/schema_ruby.rb +1 -1
  32. data/golden/shift/expected/schema_ruby.rb +1 -1
  33. data/golden/shift_2d/expected/schema_ruby.rb +1 -1
  34. data/golden/simple_math/expected/schema_ruby.rb +1 -1
  35. data/golden/streaming_basics/expected/schema_ruby.rb +1 -1
  36. data/golden/tuples/expected/schema_ruby.rb +1 -1
  37. data/golden/tuples_and_arrays/expected/schema_ruby.rb +1 -1
  38. data/golden/us_tax_2024/expected/schema_ruby.rb +1 -1
  39. data/golden/with_constants/expected/schema_ruby.rb +1 -1
  40. data/lib/kumi/analyzer.rb +39 -79
  41. data/lib/kumi/core/analyzer/analysis_state.rb +2 -0
  42. data/lib/kumi/core/analyzer/constant_evaluator.rb +0 -2
  43. data/lib/kumi/core/analyzer/execution_phase.rb +24 -0
  44. data/lib/kumi/core/analyzer/execution_result.rb +38 -0
  45. data/lib/kumi/core/analyzer/pass_failure.rb +26 -0
  46. data/lib/kumi/core/analyzer/pass_manager.rb +136 -0
  47. data/lib/kumi/core/analyzer/passes/codegen/js/declaration_emitter.rb +1 -1
  48. data/lib/kumi/core/analyzer/passes/codegen/js_pass.rb +1 -1
  49. data/lib/kumi/core/analyzer/passes/codegen/ruby/declaration_emitter.rb +1 -1
  50. data/lib/kumi/core/analyzer/passes/codegen/ruby_pass.rb +1 -1
  51. data/lib/kumi/core/analyzer/passes/constant_folding_pass.rb +1 -1
  52. data/lib/kumi/core/analyzer/passes/formal_constraint_propagator.rb +13 -31
  53. data/lib/kumi/core/analyzer/passes/input_access_planner_pass.rb +1 -1
  54. data/lib/kumi/core/analyzer/passes/input_collector.rb +1 -1
  55. data/lib/kumi/core/analyzer/passes/input_form_schema_pass.rb +1 -1
  56. data/lib/kumi/core/analyzer/passes/lir/loop_invariant_code_motion_pass.rb +1 -1
  57. data/lib/kumi/core/analyzer/passes/lir/stencil_emitter.rb +0 -2
  58. data/lib/kumi/core/analyzer/passes/normalize_to_nast_pass.rb +5 -1
  59. data/lib/kumi/core/analyzer/passes/output_schema_pass.rb +2 -1
  60. data/lib/kumi/core/analyzer/passes/snast_pass.rb +1 -1
  61. data/lib/kumi/core/analyzer/passes/unsat_detector.rb +8 -10
  62. data/lib/kumi/core/compiler/access_planner_v2.rb +1 -2
  63. data/lib/kumi/core/functions/overload_resolver.rb +15 -19
  64. data/lib/kumi/core/functions/type_categories.rb +3 -3
  65. data/lib/kumi/core/functions/type_error_reporter.rb +1 -3
  66. data/lib/kumi/core/input/type_matcher.rb +1 -1
  67. data/lib/kumi/core/types/normalizer.rb +8 -10
  68. data/lib/kumi/core/types/validator.rb +1 -1
  69. data/lib/kumi/core/types/value_objects.rb +5 -2
  70. data/lib/kumi/core/types.rb +2 -4
  71. data/lib/kumi/dev/codegen.rb +1 -1
  72. data/lib/kumi/dev/golden/generator.rb +14 -10
  73. data/lib/kumi/dev/golden/reporter.rb +5 -5
  74. data/lib/kumi/dev/golden/representation.rb +1 -3
  75. data/lib/kumi/dev/golden/result.rb +1 -1
  76. data/lib/kumi/dev/golden/runtime_test.rb +0 -2
  77. data/lib/kumi/dev/golden/suite.rb +20 -4
  78. data/lib/kumi/dev/golden/value_normalizer.rb +1 -3
  79. data/lib/kumi/doc_generator/formatters/json.rb +11 -11
  80. data/lib/kumi/doc_generator/formatters/markdown.rb +35 -37
  81. data/lib/kumi/doc_generator/loader.rb +8 -6
  82. data/lib/kumi/doc_generator/merger.rb +12 -12
  83. data/lib/kumi/frontends/text.rb +4 -6
  84. data/lib/kumi/registry_v2/loader.rb +32 -33
  85. data/lib/kumi/schema.rb +2 -2
  86. data/lib/kumi/version.rb +1 -1
  87. metadata +13 -14
  88. data/debug_ordering.rb +0 -52
  89. data/examples/deep_schema_compilation_and_evaluation_benchmark.rb +0 -106
  90. data/examples/federal_tax_calculator_2024.rb +0 -115
  91. data/examples/game_of_life.rb +0 -95
  92. data/examples/simple_rpg_game.rb +0 -1000
  93. data/examples/static_analysis_errors.rb +0 -178
  94. data/examples/wide_schema_compilation_and_evaluation_benchmark.rb +0 -80
@@ -1,178 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Static Analysis Error Examples
4
- # This file demonstrates various errors that Kumi catches during schema definition
5
-
6
- require_relative "../lib/kumi"
7
-
8
- puts "=== Kumi Static Analysis Examples ===\n"
9
- puts "All errors caught during schema definition, before any data processing!\n\n"
10
-
11
- # Example 1: Circular Dependency Detection
12
- puts "1. Circular Dependency Detection:"
13
- puts " Code with circular references between values..."
14
- begin
15
- module CircularDependency
16
- extend Kumi::Schema
17
-
18
- schema do
19
- input { float :base }
20
-
21
- value :monthly_rate, yearly_rate / 12
22
- value :yearly_rate, monthly_rate * 12
23
- end
24
- end
25
- rescue Kumi::Core::Errors::SemanticError => e
26
- puts " → #{e.message}"
27
- end
28
-
29
- puts "\n" + "="*60 + "\n"
30
-
31
- # Example 2: Impossible Logic Detection (UnsatDetector)
32
- puts "2. Impossible Logic Detection:"
33
- puts " Code with contradictory conditions..."
34
- begin
35
- module ImpossibleLogic
36
- extend Kumi::Schema
37
-
38
- schema do
39
- input { integer :age }
40
-
41
- trait :child, input.age < 13
42
- trait :adult, input.age >= 18
43
-
44
- # This combination can never be true
45
- value :status do
46
- on child & adult, "Impossible!"
47
- base "Normal"
48
- end
49
- end
50
- end
51
- rescue Kumi::Core::Errors::SemanticError => e
52
- puts " → #{e.message}"
53
- end
54
-
55
- puts "\n" + "="*60 + "\n"
56
-
57
- # Example 3: Type System Validation
58
- puts "3. Type Mismatch Detection:"
59
- puts " Code trying to add incompatible types..."
60
- begin
61
- module TypeMismatch
62
- extend Kumi::Schema
63
-
64
- schema do
65
- input do
66
- string :name
67
- integer :age
68
- end
69
-
70
- # String + Integer type mismatch
71
- value :invalid_sum, input.name + input.age
72
- end
73
- end
74
- rescue Kumi::Core::Errors::TypeError => e
75
- puts " → #{e.message}"
76
- end
77
-
78
- puts "\n" + "="*60 + "\n"
79
-
80
- # Example 4: Domain Constraint Analysis
81
- puts "4. Domain Constraint Violations:"
82
- puts " Code using values outside declared domains..."
83
- begin
84
- module DomainViolation
85
- extend Kumi::Schema
86
-
87
- schema do
88
- input do
89
- integer :score, domain: 0..100
90
- string :grade, domain: %w[A B C D F]
91
- end
92
-
93
- # 150 is outside the domain 0..100
94
- trait :impossible_score, input.score == 150
95
- end
96
- end
97
- rescue Kumi::Core::Errors::SemanticError => e
98
- puts " → #{e.message}"
99
- end
100
-
101
- puts "\n" + "="*60 + "\n"
102
-
103
- # Example 5: Undefined Reference Detection
104
- puts "5. Undefined Reference Detection:"
105
- puts " Code referencing non-existent declarations..."
106
- begin
107
- module UndefinedReference
108
- extend Kumi::Schema
109
-
110
- schema do
111
- input { integer :amount }
112
-
113
- # References a trait that doesn't exist
114
- value :result, ref(:nonexistent_trait) ? 100 : 0
115
- end
116
- end
117
- rescue Kumi::Core::Errors::SemanticError => e
118
- puts " → #{e.message}"
119
- end
120
-
121
- puts "\n" + "="*60 + "\n"
122
-
123
- # Example 6: Invalid Function Usage
124
- puts "6. Invalid Function Detection:"
125
- puts " Code using non-existent functions..."
126
- begin
127
- module InvalidFunction
128
- extend Kumi::Schema
129
-
130
- schema do
131
- input { string :text }
132
-
133
- # Function doesn't exist in registry
134
- value :result, fn(:nonexistent_function, input.text)
135
- end
136
- end
137
- rescue Kumi::Core::Errors::TypeError => e
138
- puts " → #{e.message}"
139
- end
140
-
141
- puts "\n" + "="*60 + "\n"
142
-
143
- # Example 7: Complex Schema with Multiple Issues
144
- puts "7. Multiple Issues Detected:"
145
- puts " Complex schema with several problems..."
146
- begin
147
- module MultipleIssues
148
- extend Kumi::Schema
149
-
150
- schema do
151
- input { integer :value, domain: 1..10 }
152
-
153
- # Issue 1: Circular dependency
154
- value :a, b + 1
155
- value :b, c + 1
156
- value :c, a + 1
157
-
158
- # Issue 2: Impossible domain condition
159
- trait :impossible, (input.value > 10) & (input.value < 5)
160
-
161
- # Issue 3: Undefined reference
162
- value :result, ref(:undefined_declaration)
163
- end
164
- end
165
- rescue Kumi::Core::Errors::SemanticError => e
166
- puts " → " + e.message.split("\n").join("\n → ")
167
- end
168
-
169
- puts "\n" + "="*60 + "\n"
170
- puts "Summary:"
171
- puts "• Circular dependencies caught before infinite loops"
172
- puts "• Impossible logic detected through constraint analysis"
173
- puts "• Type mismatches found during type inference"
174
- puts "• Domain violations identified through static analysis"
175
- puts "• Undefined references caught during name resolution"
176
- puts "• Invalid functions detected during compilation"
177
- puts "• Multiple issues reported together with precise locations"
178
- puts "\nAll validation happens during schema definition - no runtime surprises!"
@@ -1,80 +0,0 @@
1
- # Wide Schema Compilation and Evaluation Benchmark
2
- #
3
- # This benchmark measures Kumi's performance with increasingly wide schemas
4
- # to understand how compilation and evaluation times scale with schema complexity.
5
- #
6
- # What it tests:
7
- # - Compilation time for schemas with 1k, 5k, and 10k value declarations
8
- # - Evaluation performance for computing aggregated results from many values
9
- # - Memory efficiency through memoized schema compilation
10
- #
11
- # Schema structure:
12
- # - input: single integer seed
13
- # - values: v1 = seed + 1, v2 = seed + 2, ..., v_n = seed + n
14
- # - aggregations: sum_all, avg_all
15
- # - trait: large_total (conditional logic)
16
- # - cascade: final_total (depends on trait evaluation)
17
- #
18
- # Usage: bundle exec ruby examples/wide_schema_compilation_and_evaluation_benchmark.rb
19
- require "benchmark"
20
- require "benchmark/ips"
21
- require_relative "../lib/kumi"
22
-
23
- # ------------------------------------------------------------------
24
- # 1. Helper that builds a *sugar‑free* wide‑but‑shallow schema
25
- # ------------------------------------------------------------------
26
- def build_wide_schema(width)
27
- Class.new do
28
- extend Kumi::Schema
29
-
30
- schema do
31
- input { integer :seed }
32
-
33
- # width independent leaf nodes: v_i = seed + i
34
- 1.upto(width) { |i| value :"v#{i}", fn(:add, input.seed, i) }
35
-
36
- # Aggregations
37
- value :sum_all, fn(:sum, (1..width).map { |i| ref(:"v#{i}") })
38
- value :avg_all, fn(:divide, ref(:sum_all), width)
39
-
40
- trait :large_total,
41
- ref(:sum_all), :>, (width * (width + 1) / 2)
42
-
43
- value :final_total do
44
- on large_total, fn(:add, ref(:sum_all), ref(:avg_all))
45
- base ref(:sum_all)
46
- end
47
- end
48
- end
49
- end
50
-
51
- WIDTHS = [1_000, 5_000, 10_000]
52
-
53
- # ------------------------------------------------------------------
54
- # 2. Measure compilation once per width
55
- # ------------------------------------------------------------------
56
- compile_times = {}
57
- schemas = {}
58
-
59
- WIDTHS.each do |w|
60
- t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
61
- schemas[w] = build_wide_schema(w)
62
- compile_times[w] = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0
63
- end
64
-
65
- puts "=== compilation times ==="
66
- compile_times.each do |w, t|
67
- puts format("compile %5d‑wide: %6.1f ms", w, t * 1_000)
68
- end
69
- puts
70
-
71
- # ------------------------------------------------------------------
72
- # 3. Pure evaluation benchmark – no compilation inside the loop
73
- # ------------------------------------------------------------------
74
- Benchmark.ips do |x|
75
- schemas.each do |w, schema|
76
- runner = schema.from(seed: 0) # memoised runner
77
- x.report("eval #{w}-wide") { runner[:final_total] }
78
- end
79
- x.compare!
80
- end