feat: auto-derive Hashable for payload-free enums#146
Merged
Conversation
Synthesize {Name}::hash and {Name}::eq for enums whose variants carry
no inner values, so they satisfy the Hashable trait without manual
impl blocks. Synth runs once per compile after resolve_identifiers_global,
skips any name the user already defined (silent override), and produces
inline bodies (cast-to-int for hash, == for eq) that need no std import.
Removes 5 manual impl blocks in compiler/common.casa now provided by
the synth.
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
Hashableautomatically — no manualimplblock needed.Color::hashis the discriminant cast toint(always non-negative).Color::eqis==. Synth runs once afterresolve_identifiers_global, before type-checking.{Name}::hashor{Name}::eq, the synthesized version is suppressed and the manual one wins.impl <Kind>blocks incompiler/common.casa(TokenKind,IntrinsicKind,KeywordKind,DelimiterKind,OperatorKind) — synth now provides them.int,bool,char,ptr,str,cstr) — tracked in Auto-derive Hashable for terminal builtin types #145.Test plan
tests/test_compiler.sh— 25/25 (incl.self_compilation+fixed_point)tests/test_examples.sh— 40/40 (incl. newexamples/enum_hashable_derive.casa)tests/test_formatter.sh— 64/64tests/compiler/test_enum.casacover:hash/eqare synthesized for payload-free enums, signatures are correct, payload-bearing enums are skipped, manualimploverrides synth..casafiles run through./casafmt.