Problem
Multiple near-identical helpers shipped across recent compiler work:
Compiler — IrExpressionTreeExtractor.cs
TryFoldIntArith / TryFoldLongArith / TryFoldDoubleArith / TryFoldFloatArith / TryFoldDecimalArith — five 20-LOC switches differing only in numeric type and divide-by-zero/overflow guard.
TryFoldUnary mixes + identity (numeric-only), Negate, BitwiseNot, logical !.
Dart bridges
ToSnakeCase duplicated in Bridge/IrToDartTypeMapper.cs:132 and IrToDartNamingPolicy.cs:45.
ConvertTypeParameters wrapper duplicated in IrToDartInterfaceBridge.cs:85 and IrToDartClassBridge.cs:481 (both thin one-liners around IrToDartTypeParameterMapper.Map).
Fix
Compiler
- One generic
TryFoldArith<T> with delegate-keyed ops + INumber<T> constraint, or a single dispatch via dynamic (acceptable at build time).
- Split
TryFoldUnary into TryFoldNegate / TryFoldBitwiseNot / TryFoldLogicalNot / TryFoldUnaryPlus with a 4-arm dispatcher.
Dart
- Hoist
ToSnakeCase to IrToDartNamingPolicy (make internal), delete the private copy in the type mapper.
- Delete
ConvertTypeParameters wrappers; call IrToDartTypeParameterMapper.Map(...) at the 4 call sites directly. The delegate bridge already does this (line 51).
Motivation
Drive-by inconsistencies pile up with every numeric edge case (overflow, IEEE-754 semantics, decimal exceptions). One shared helper means one place to audit + fix.
Pure refactor.
Problem
Multiple near-identical helpers shipped across recent compiler work:
Compiler —
IrExpressionTreeExtractor.csTryFoldIntArith/TryFoldLongArith/TryFoldDoubleArith/TryFoldFloatArith/TryFoldDecimalArith— five 20-LOC switches differing only in numeric type and divide-by-zero/overflow guard.TryFoldUnarymixes+identity (numeric-only),Negate,BitwiseNot, logical!.Dart bridges
ToSnakeCaseduplicated inBridge/IrToDartTypeMapper.cs:132andIrToDartNamingPolicy.cs:45.ConvertTypeParameterswrapper duplicated inIrToDartInterfaceBridge.cs:85andIrToDartClassBridge.cs:481(both thin one-liners aroundIrToDartTypeParameterMapper.Map).Fix
Compiler
TryFoldArith<T>with delegate-keyed ops +INumber<T>constraint, or a single dispatch viadynamic(acceptable at build time).TryFoldUnaryintoTryFoldNegate/TryFoldBitwiseNot/TryFoldLogicalNot/TryFoldUnaryPluswith a 4-arm dispatcher.Dart
ToSnakeCasetoIrToDartNamingPolicy(makeinternal), delete the private copy in the type mapper.ConvertTypeParameterswrappers; callIrToDartTypeParameterMapper.Map(...)at the 4 call sites directly. The delegate bridge already does this (line 51).Motivation
Drive-by inconsistencies pile up with every numeric edge case (overflow, IEEE-754 semantics, decimal exceptions). One shared helper means one place to audit + fix.
Pure refactor.