Repository navigation
A @cpp class works under -mm=rc and -mm=own - #627
Merged
Merged
Conversation
A @cpp class's reference is a C++ pointer. Under rc and own an object's count is the word before it, which in front of a C++ object is the C++ heap's (or a neighbour's), so these models were refused. Now no model counts a @cpp reference: ClassStorageType carries a cpp flag, set where the class type is made, and MLIRTypeHelper::ownsHeapMemory answers no for it. MLIRGen, the ownership passes and the release routines all ask that, so copies into locals, fields, arrays and arguments retain nothing and release nothing, and a holder's destroy skips the field. The object stays C++'s to free; one made by `new` (a class implementing C++ methods) is never freed by tslang. Tests: the @cpp test files join the rc/none corpus and run under own; memory_model.ts compiles under rc, own and none; test-jit-cppvtable-abi runs under rc and own too, with --verify-ownership, against a C++ object that sits right after a guard word of C++'s own, checked while tslang holds copies and then deleted by C++. With the exemption turned off the rc run fails that check and the own runs fail to compile. Co-Authored-By: Claude Opus 5.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.
Why it was refused
Under rc and own an object's count is the word before it. A
@cppclass's reference is a C++ pointer, and the word before a C++ object belongs to the C++ heap (or a neighbour), so a retain or release would write into C++ memory.Change
No model counts a
@cppreference now:ClassStorageTypecarries acppflag, set right where the class type is made (MLIRGenClasses.cpp), before anything of the type is generated.MLIRTypeHelper::ownsHeapMemoryanswers no for it. MLIRGen, the ownership passes and the release/retain routines all ask that, so copies into locals, fields, arrays and arguments retain and release nothing, and a holder's destroy skips a@cppfield.The object stays C++'s to free. An object of a class implementing C++ methods made with
newis never freed by tslang under rc/own (documented in docs/cpp-classes.md, new "Memory models" section).Tests
00cppvtable_class.ts,00cpp_slot.ts,00cpp_overloads.tsjoin the rc/none corpus (and the ownership verifier over it), and run under own (AOT + JIT).cppvtable/memory_model.tscompiles under rc, own and none.test-jit-cppvtable-abialso runs under rc and own, plus--verify-ownership. abi_host.cpp's new heap object sits right after a guard word of C++'s own; the guard is checked while tslang holds copies (field, array, local) and after, then C++ deletes the object.🤖 Generated with Claude Code