refactor(beam): give string x and x.ToString() one dispatch#4816
Merged
Conversation
The 14-line to-string dispatch was duplicated byte-for-byte between the `operators` and `conversions` tables, differing only in whether the type variable was spelled `_t` or `t`. Both handle `ToString`; they are just reached by different routes. Nothing warned that there were two copies, so a fix applied to one spelling and not the other would be invisible until someone happened to test the neglected one. #4814 is the near miss: it had to add the same boxed-char peel, with the same rationale, to both — and did, but only because the duplication was noticed. Now `ToString.toStringByType` in Beam/Prelude.fs, next to the `Chars` helpers it uses, with the peel folded in and the rationale stated once. Pure refactor: all 82 generated Erlang files under temp/tests/Beam/src are byte-identical before and after. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
The to-string dispatch was duplicated byte-for-byte between two replacement tables, differing only in whether the type variable was spelled
_tort:operators,| "ToString", [ arg ]string xconversions,| "ToString", _x.ToString()Both branch on
arg.Typethrough the same six cases (String,Char,Decimal, the floats, other numerics,Boolean, and a generic fallback) and emit the same code for each.Why it is worth removing
Nothing marked the two as copies, so a fix applied to one spelling and not the other stays invisible until someone happens to test the neglected one —
string xcorrect andx.ToString()wrong, or the reverse.#4814 is the near miss. It had to add the same boxed-char peel to both sites, with the same five-line rationale paraphrased twice:
It got both, but only because the duplication happened to be noticed.
What changed
Extracted to
ToString.toStringByTypeinBeam/Prelude.fs, next to theCharshelpers it depends on, with the peel folded in and its rationale stated once. Both call sites become one line each.Testing
./build.sh test beamgreen: .NET 2614 passed / 0 failed, Erlang 2633 PASS / 0 FAIL, entry-point program tests passed.No new tests, because there is no new behaviour to cover. What is checked instead is that there is none: all 82 generated Erlang files under
temp/tests/Beam/srcare byte-identical before and after the change (diff -r), so nothing about the emitted code moved.🤖 Generated with Claude Code