Add #cpp_heap_allocated directive, deprecate #cpp_value - #145
Merged
Conversation
#cpp_value's first argument is parsed but never used by codegen (it's overwritten before reaching generated code) — see hkalbasi#143. This adds #cpp_heap_allocated as a replacement without that dead parameter, deprecates #cpp_value (still functional, forwards to the same logic, emits an ariadne-rendered deprecation warning pointing at the directive), and updates the internal representation, docs, and examples to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cspell flagged "Allocateds" (an invented plural of CppHeapAllocated) as an unknown word, unlike "CppRefs" nearby, whose "Refs" is a real word. Reworded to avoid pluralizing the type name. Co-Authored-By: Claude Sonnet 5 <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.
Non-AI synopsis
I added
#cpp_heap_allocatedto replace#cpp_valueto address #143.I left
#cpp_valuein for backward compatibility. If you use it, you get a warning.There wasn't an effective warning mechanism in place, so I added one as well. There was some complexity because I wanted to ensure "cargo:warning=" is prefixed, so you get warnings when you use zngur through cargo. I'm not happy with the
add_errors,add_error_str, andadd_warning_strset of functions. It doesn't feel like a very good API, but fixing it would require deeper refactors, I fear.What's below is AI commentary...
Summary
#cpp_heap_allocated "CppType";as a replacement for#cpp_value "field" "CppType";, dropping thefieldparameter thatis parsed but never used by codegen (closes #cpp_value's first argument (field) is parsed but never used #143).
#cpp_valueremains supported for backward compatibility: it nowforwards to the same internal logic as
#cpp_heap_allocatedandemits a deprecation warning (rendered as an ariadne diagnostic
pointing at the directive's location, including across imported
.zngfiles).Zngur::with_warning_sink()(defaultingto Cargo's
cargo:warning=convention when used from a buildscript) and via plain
eprintln!inzngur-cli.CppValue/cpp_valuetoCppHeapAllocated/cpp_heap_allocatedthroughoutzngur-def,zngur-parser, andzngur-generator, following the sameparse-time-struct-plus-generator-produced-struct convention already
used for
ZngurField/ZngurFieldData..zngfiles updated to use thenew directive.
Test plan
cargo testacrosszngur-def,zngur-parser,zngur-generator,zngur,zngur-cli(37 parser tests, all passing)examples/tutorial_cpp(build.rs path) builds and runs correctlywith the new directive, and with
#cpp_valuetemporarilyreintroduced, correctly shows the
cargo:warning=-rendereddeprecation diagnostic
examples/multiple_modules(CLI path via its Makefile) buildsand runs correctly, matching
expected_output.txtcargo fmt --checkclean on all touched crates🤖 Generated with Claude Code