compiler: auto-derive blit for blittable sum types#1492
Open
sqrew wants to merge 2 commits intocarp-lang:masterfrom
Open
compiler: auto-derive blit for blittable sum types#1492sqrew wants to merge 2 commits intocarp-lang:masterfrom
sqrew wants to merge 2 commits intocarp-lang:masterfrom
Conversation
Sum types with only non-managed field types (primitives, pointers, other blittable types) are freely memcopyable but previously required users to manually implement the blit interface. This change automatically derives blit for such types at definition time. Changes: - Sumtypes.hs: add binderForBlit (identity fn template) and call it conditionally in generateBinders when all field types are non-managed and the type is not generic - Primitives.hs: add getSig "blit" case to autoDerive and conditionally register the blit interface when the module has a blit implementation - test/memory.carp: remove manual blit impl from BlitEnum (now auto-derived) - core/Binary.carp: remove manual blit impl from ByteOrder (now auto-derived) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests that blit is correctly auto-derived for: - Simple enums (all unit variants) - Enums with primitive-typed fields Co-Authored-By: Claude Sonnet 4.6 <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
Sum types where all fields are non-managed and the type is not generic are trivially memcopyable, but users had to manually implement
blit(an identity function +implementsdeclaration). This PR auto-derivesblitfor those types, consistent with howcopy,str, anddeleteare already auto-derived.Rules:
Changes
src/Sumtypes.hs:generateBindersnow conditionally appends a blit binder when the type is blittable.binderForBlitgenerates an identity C function ($p $NAME($p p) { return p; }).src/Primitives.hs:getSig "blit"added toautoDerive; bothdeftypecases conditionally include blit in the auto-derive list (checks for existing impl to avoid duplicates).test/memory.carp: removed manual blit impl fromBlitEnum(now auto-derived).core/Binary.carp: removed manual blit impl fromByteOrdermodule (now auto-derived).test/sumtypes.carp: two explicit blit tests added (Directionsimple enum,Axiswith Float fields).Tests
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com