Skip to content

fix: preserve JavaScript numbers in numeric enums - #12788

Merged
proggeramlug merged 6 commits into
mainfrom
enf
Oct 18, 2026
Merged

proggeramlug merged 6 commits into
mainfrom
enf

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Numeric enums stored values as i64, so fractional initializers such as 1.5 became incorrect integers. Keep numbers as f64 through constant evaluation, HIR, enum images, and constant emission. Reverse mappings use JavaScript number formatting for fractions, large values, NaN, and infinities.

Computed initializers evaluate once in declaration order, and reverse mappings consume the forward assignment result, including when an inherited setter intercepts the store. TS constant -0 emits +0 like tsc, while dependent constant expressions retain its sign during evaluation and computed members preserve runtime negative zero.

Validation:

  • HIR enum tests: 25 passed; codegen enum tests: 3 passed; number emission tests: 4 passed.
  • Fractional/large/non-finite, const-enum, merged-enum, keys, signed-zero, and computed-setter fixtures match unmodified TypeScript 5.8.2 transpilation executed by Node 26.8.1.
  • Controlled tscwork A/B on qb8: medians 12,174,515,045 → 12,174,526,168 instructions:u (n=3, +0.000091%, within run variance). Both link the same runtime; linked .text is byte-identical at 59,780,386 bytes. Baseline is main 44874ef with build metadata aligned to 0.5.1661 (790ac7562), compared with compiler 81a0ae7.
  • Final pmcheck.sh enf -p perry-hir -p perry-codegen --lib enum passed at c1f7f40 after rebasing onto the module-identity and class-family changes: build, sidecars, zod/tsc smoke, and 25 HIR + 3 codegen enum tests. Both enum fixtures also match Node in fast and auto-optimized modes on that compiler.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5acd453c-27cd-44d8-ba66-ffd5d2fe4c0f
📥 Commits

Reviewing files that changed from the base of the PR and between 05cfd2d and c1f7f40.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 37
  • CLAUDE.md
  • Cargo.toml
  • changelog.d/12788-numeric-enum-numbers.md
  • crates/perry-codegen-js/src/emit/decls.rs
  • crates/perry-codegen-wasm/src/emit/string_collection.rs
  • crates/perry-codegen/src/expr/bigint_set.rs
  • crates/perry-codegen/src/expr/literal_descriptor.rs
  • crates/perry-codegen/src/type_analysis_facts.rs
  • crates/perry-hir/Cargo.toml
  • crates/perry-hir/src/analysis/value_types.rs
  • crates/perry-hir/src/analysis/value_types_tests.rs
  • crates/perry-hir/src/enums.rs
  • crates/perry-hir/src/ir/decl.rs
  • crates/perry-hir/src/lib.rs
  • crates/perry-hir/src/lower/const_fold_fn.rs
  • crates/perry-hir/src/lower/context_new.rs
  • crates/perry-hir/src/lower/enum_image.rs
  • crates/perry-hir/src/lower/enum_image/tests.rs
  • crates/perry-hir/src/lower/expr_member.rs
  • crates/perry-hir/src/lower/expr_object.rs
  • crates/perry-hir/src/lower/lower_expr/arm_ident.rs
  • crates/perry-hir/src/lower/lowering_context.rs
  • crates/perry-hir/src/lower/module_decl.rs
  • crates/perry-hir/src/lower/module_decl/namespace.rs
  • crates/perry-hir/src/lower/module_decl/typescript.rs
  • crates/perry-hir/src/lower/stmt.rs
  • crates/perry-hir/src/lower/tests.rs
  • crates/perry-hir/src/lower_decl/body_stmt.rs
  • crates/perry-hir/src/lower_decl/enum_decl.rs
  • crates/perry-hir/src/number.rs
  • crates/perry-hir/src/stable_hash/decls.rs
  • crates/perry-hir/src/stable_hash/expr.rs
  • crates/perry-hir/src/stable_hash/primitives.rs
  • crates/perry-hir/src/stable_hash/tests.rs
  • crates/perry-wpfacts/src/gen_expr.rs
  • test-files/test_gap_enum_computed_setter.ts
  • test-files/test_gap_enum_fractional.ts
+-------------------------------------------------------------------------------------------------------------+
| Hello, it's me. I was wondering if after all these reviews you'd like to meet...to celebrate bug-free code. |
+-------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug marked this pull request as ready for review October 18, 2026 10:16
@proggeramlug
proggeramlug merged commit bc00158 into main Oct 18, 2026
103 of 115 checks passed
@proggeramlug
proggeramlug deleted the enf branch October 18, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant