Repository navigation
new C() of a local class allocates in place instead of calling C..new - #610
Merged
Merged
Conversation
For a class defined in the module, `new C()` now emits the body `C..new` would run - the ts.New and the vtable store - instead of a call. The ts.New carries __owned_result, as the call did, and under rc the block starts with that one reference (NewOpLowering stores 1 into the header), so the caller sees no ts.Retain the ownership passes would have to account for: the same ownership shape the call had. A visible retain broke -mm=own: the global-initializer check rejected it, and two own-err tests stopped reporting their errors. C..new is still generated for the vtable's .new slot and for other modules. Declarations, imports, dynamic imports and @cpp classes keep the call. Stack promotion no longer inlines C..new bodies: every local `new C()` site is a ts.New, so newMethodOf, newMethodBody and the call branch of promote() go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
new C()now emits whatC..new's body would run: thets.Newand the vtable store. Before, it emitted a call toC..new.ts.Newcarries__owned_result, as the call did. Under rc,NewOpLoweringstores a count of 1 into the block header for such ats.New. So the caller sees nots.Retain, which is the same ownership shape the call had.C..newcall. That covers declarations, imports, dynamic imports and@cppclasses.C..newis still generated for the vtable's.newslot and for other modules.C..newbodies, because every localnew C()site is now ats.New.newMethodOf,newMethodBodyand the call branch ofpromote()are removed.new C()as always aC..newcall are updated.Why no visible retain
A first version emitted
ts.Retainafter thets.New. That broke-mm=ownin two ways. The global-initializer check reported "takes a second reference" forlet g = new H(). Two own-err tests also stopped reporting their expected errors. Making the +1 part of the allocation keeps the IR identical in ownership terms to the old call result.ABI
There is no ABI change. The header layout and the count semantics seen by consumers are unchanged. The prebuilt DefaultLib and the CI LLVM artifact do not need rebuilding.
Testing
-no-stack-promotion, which exercises the heap path. The 12 nonzero exits there are tests that expect an error by pass regex.🤖 Generated with Claude Code