SY-3482: Add Boolean Support to Arc#2230
Open
emilbon99 wants to merge 3 commits intosy-3272-add-boolean-data-type-channelfrom
Open
SY-3482: Add Boolean Support to Arc#2230emilbon99 wants to merge 3 commits intosy-3272-add-boolean-data-type-channelfrom
emilbon99 wants to merge 3 commits intosy-3272-add-boolean-data-type-channelfrom
Conversation
Introduces a dedicated Bool kind in the Arc type system rather than overloading u8 for boolean signals. Comparisons and logical operators now return bool; stage activation, select, set_authority, stat.reset, channel.write, time.interval, and time.wait inputs/outputs are typed bool; numeric literals assign to bool via implicit normalization (nonzero -> 1) and bool(x) casts normalize runtime numeric values to canonical 0/1 via double-eqz (integers) or != 0 (floats). Adds op.AndBool/OrBool/NotBool (logical NOT, not bitwise), channel and series bool host functions in both Go and C++ runtimes, and routes comparison results through BOOL_T series at the telem layer so the data type tag matches the Arc-level type. Grammar picks up a bool keyword; analyzer, compiler, and constraint unification all understand bool as a distinct non-numeric primitive with bidirectional casts to every numeric type.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## sy-3272-add-boolean-data-type-channel #2230 +/- ##
=========================================================================
+ Coverage 63.37% 63.40% +0.02%
=========================================================================
Files 2106 2107 +1
Lines 106370 106563 +193
Branches 8318 8315 -3
=========================================================================
+ Hits 67414 67561 +147
- Misses 33056 33090 +34
- Partials 5900 5912 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Pull Request
Linear Issue
SY-3482
Description
Introduces a dedicated
boolkind in the Arc type system rather than overloadingu8for boolean signals. Comparisons (==,!=,<,>,<=,>=), logical operators (and,or,not), and string equality now returnbool; stage activation,select,set_authority,stat.reset,channel.write,time.interval, andtime.waitinputs/outputs are typedbool; numeric literals assign toboolvia implicit normalization (nonzero → 1) andbool(x)casts normalize runtime numeric values to canonical 0/1 via double-eqz (integers) or!= 0(floats).Adds
op.AndBool/op.OrBool/op.NotBool(logical NOT, not bitwise), channel and series bool host functions in both Go and C++ runtimes, and routes comparison results throughBOOL_Tseries at the telem layer so the data type tag matches the Arc-level type. TheArcLexergrammar picks up aboolkeyword; analyzer, compiler, and constraint unification all understandboolas a distinct non-numeric primitive with bidirectional casts to every numeric type.Breaking change for Arc programs: channels that previously used
u8as boolean signals (stage triggers, reset lines, activation sources) must now be declaredbool. Functions returning comparisons must declareboolreturn type instead ofu8.Basic Readiness
Greptile Summary
This PR introduces
boolas a first-class type in Arc's type system, distinct fromu8. Comparisons, logical operators, stage triggers, and channel operations now return or acceptbool; bidirectional casts to/from all numeric types are provided via double-eqz (int) or!= 0(float) normalization. The change touches the parser, type-checker, compiler, Go/C++ WASM runtimes, telem op layer, and the TypeScript codec (which gains bit-packing for bool series on the wire).bindI64Type(line 552) andbindFloatType(line 680) inarc/go/stl/series/series.gostill initialize scalar comparison result series withtelem.Uint8Tinstead oftelem.BoolT. Every other comparison path (bindCompareScalarI32,bindCompareOps) was updated toBoolT, so comparisons oni64/u64/f32/f64series against a scalar will return a series tagged asu8rather thanbool.Confidence Score: 4/5
Safe to merge after fixing the two scalar-comparison DataType lines in arc/go/stl/series/series.go.
The core type-system additions (new KindBool, EmitCast, logical ops, constraint unification, codec) are well-structured. Two P1 lines in bindI64Type and bindFloatType produce Uint8T-tagged series from scalar comparisons on i64/u64/f32/f64 types, which is a clear oversight compared to the consistently correct BoolT usage everywhere else.
arc/go/stl/series/series.go — lines 552 and 680 in bindI64Type and bindFloatType scalar comparison loops.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Arc source: x > 5] --> B[Parser / Lexer\nbool keyword added] B --> C[Analyzer\ncomparison → Bool type\nIntegerConstant accepts Bool] C --> D[Compiler\nbinary.go: returns Bool\nlogical.go: returns Bool\nunary.go: returns Bool\ncast.go: EmitCastToBool / FromBool] D --> E[WASM bytecode] E --> F{Runtime} F --> G[Go runtime\nstl/series/series.go\nbindBool / bindCompareScalarI32 ✓\nbindI64Type scalar ❌ Uint8T\nbindFloatType scalar ❌ Uint8T] F --> H[C++ runtime\narc/cpp/stl/series/series.cpp\nBIND_SERIES_OPS bool ✓\nlogical_not ✓] G --> I[telem.Series\nDataType: BoolT\nop.AndBool / OrBool / NotBool] H --> I I --> J[Wire codec\nTS: bit-pack 8 samples/byte\nGo: 1 byte/sample in memory]Comments Outside Diff (2)
arc/go/stl/series/series.go, line 552 (link)Uint8Tinstead ofBoolTbindI64Type's scalar comparison loop initializes the result series withtelem.Uint8T, butbindCompareScalarI32(line 338) andbindCompareOps(series-vs-series, line 411) both correctly usetelem.BoolT. Anycompare_*_scalar_u64orcompare_*_scalar_i64host call will return a series whoseDataTypeisu8, contradicting the PR's goal of having all comparison results carryBoolT. Code that inspectsseries.DataTypeto determine the Arc type will seeu8instead ofbooland may mismatch.arc/go/stl/series/series.go, line 680 (link)Uint8Tinstead ofBoolTSame issue as
bindI64Type(line 552) —bindFloatType's scalar comparison loop usestelem.Uint8Tfor the result while series-vs-series comparisons inbindCompareOps(line 411) and the i32-family scalar comparisons inbindCompareScalarI32(line 338) both usetelem.BoolT. Float scalar comparisons (compare_gt_scalar_f32,compare_gt_scalar_f64, etc.) will return series tagged asu8.Reviews (1): Last reviewed commit: "add copyright headers and pnpm format" | Re-trigger Greptile