Commit a349653
authored
bigint (#3526)
Adds the `bigint` primitive type, which represents an
arbitrary-precision signed integer with sign-extended two's complement
bitwise semantics. Like `string`, it is an immutable heap-allocated
object.
- Includes `bigint` literals: like other popular languages with built-in
arbitrary-size integers, we use the `n` suffix as in `123n` or
`9999999999999999999999999n`
- `int` can always be safely widened into `bigint`. We only do this
implicitly for binary ops: `1n + 2 == 3n`
- Operations that can produce very large `bigint`s (such as left shift)
may throw an `AllocFailure` panic if the size of the `bigint` would
exceed `1 << 28` bits (about 33.6MB). For example: `1n << (1n << 29n)`
will panic. This allows programs to recover in BAML instead of crashing
from an out-of-memory error or other allocation problems.
- Helpful diagnostics for malformed `bigint` literals like `123N` or
`1.23n`
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
- Added Bigint primitive with literal syntax (e.g. 42n), int→bigint
widening, full arithmetic/bitwise/shift ops, comparisons, and typed
bytecode/VM support.
- Bigint standard library: parse, to_json,
abs/min/max/clamp/isqrt/pow/ilog/random.
* **Runtime / VM**
- Heap/object representation, allocation paths, serializers, and new
panics (negative-bit-shift, alloc failure) for bigint.
* **FFI / SDK / Protobuf**
- End-to-end bigint round‑trip support in bridges and SDKs (Python,
Node, protobufs).
* **Tests**
- Extensive new and updated tests covering syntax, coercion, ops,
serialization, edge cases.
* **Chores**
- Workspace dependencies and codegen/type mappings added for bigint
support.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/BoundaryML/baml/pull/3526)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent a6f67a4 commit a349653
258 files changed
Lines changed: 12369 additions & 1501 deletions
File tree
- baml_language
- crates
- baml_base
- src
- baml_builtins2_codegen/src
- baml_builtins2
- baml_std/baml
- ns_panics
- src
- baml_cli/src/snapshots
- baml_codegen_types/src
- baml_compiler2_ast
- src
- baml_compiler2_emit/src
- baml_compiler2_hir/src
- baml_compiler2_mir
- src
- baml_compiler2_ppir/src
- baml_compiler2_tir
- src
- baml_compiler2_visualization/src/control_flow
- baml_compiler_lexer/src
- baml_compiler_parser/src
- baml_compiler_syntax/src
- baml_lsp2_actions/src
- baml_project/src
- baml_tests
- projects
- compiles
- bigint_arith
- bigint_cmp
- bigint_literal
- numeric_invariance_ok
- diagnostic_errors/numeric_invariance
- snapshots
- compiles
- __baml_std__
- __testing_std__
- bigint_arith
- bigint_cmp
- bigint_literal
- byte_string_literals
- closure_loop_variable
- closures
- event_system
- function_call
- is_operator
- lambda_advanced
- lambda_fat_arrow
- lexical_scoping
- literal_union_arithmetic
- numeric_invariance_ok
- parser_expressions
- parser_statements
- patterns_class_destructure_namespaces
- patterns_new
- test_expr_basic
- test_expr_name_concat
- test_expr_throwing_body
- test_old_and_new
- test_raw_string_name
- test_with_not_keyword
- testset_basic
- testset_dynamic
- testset_nested
- testset_vibes_nested
- testset_with_setup
- diagnostic_errors
- numeric_invariance
- test_expr_name_type_error
- test_expr_with_runner
- test_expr_wrong_runner
- test_with_runner_ambiguity
- engine
- src/compiler2_tir
- snapshots
- tests
- bytecode_format/snapshots
- baml_type
- src
- bex_engine
- src
- bex_events/src
- bex_external_types
- src
- bex_heap
- src
- heap_debugger
- bex_project/src
- bex_lsp/multi_project
- bex_sap
- src
- deserializer
- coercer
- jsonish
- sap_model
- tests
- bex_vm_types
- src
- bex_vm
- src
- package_baml
- tests
- bridge_ctypes
- src
- types/baml_core/cffi/v1
- sys_jinja_types/src/evaluate_type
- sys_llm/src
- build_request
- jinja
- types
- tools_onionskin/src
- sdks
- go/bridge_go/cffi/proto/baml_core/cffi/v1
- nodejs/bridge_nodejs
- tests
- typescript_src
- proto
- python
- rust/codegen_python/src
- src/baml_core
- cffi/v1
- tests
- typescript2
- pkg-playground/src
- pkg-proto/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
| 255 | + | |
254 | 256 | | |
255 | 257 | | |
256 | 258 | | |
| |||
Lines changed: 188 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
0 commit comments