-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgen: add codegen for auto free methods for interface type #22555
Merged
spytheman
merged 8 commits into
vlang:master
from
felipensp:fix_free_method_for_interface
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
695dcb2
fix
felipensp c3cc8ff
fix
felipensp 6577374
fix test
felipensp 0740929
fix
felipensp cf11ddc
fix
felipensp 9824633
fix
felipensp 86d59fd
cleanup
felipensp 0cbe036
Merge remote-tracking branch 'origin' into fix_free_method_for_interface
felipensp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void main__IFoo_free(main__IFoo* it) { | ||
if (it->_typ == _main__IFoo_main__Foo_index) { main__Foo_free(it->_main__Foo); return; } | ||
if (it->_typ == _main__IFoo_array_index) { array_free(it->_array); return; } | ||
if (it->_typ == _main__IFoo_map_index) { map_free(it->_map); return; } | ||
if (it->_typ == _main__IFoo_VAssertMetaInfo_index) { VAssertMetaInfo_free(it->_VAssertMetaInfo); return; } | ||
if (it->_typ == _main__IFoo_MessageError_index) { MessageError_free(it->_MessageError); return; } | ||
} | ||
felipensp marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// vtest vflags: -autofree | ||
module main | ||
|
||
interface IFoo { | ||
free() | ||
} | ||
|
||
struct Bar { | ||
a int | ||
} | ||
|
||
struct Foo implements IFoo { | ||
Bar | ||
} | ||
|
||
fn (f &Foo) free() {} | ||
|
||
fn main() { | ||
a := IFoo(Foo{}) | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could also generate
it->_main__Foo = NULL;
right after the free call, before the return.That will make use after frees easier to detect, and simplify the work of the mark stage of the GC, if used in combination with -autofree.