-
Notifications
You must be signed in to change notification settings - Fork 26
Vtable Metadata #840
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
Vtable Metadata #840
Conversation
Drop shims are correctly implemented with recursion to handle both Array & Tuple cases. * Initial plan * Initial analysis and planning for vtable metadata computation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Initial analysis and plan for vtable metadata computation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement basic drop case analysis in vtable metadata computation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Improve drop case analysis with proper Drop trait detection Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Successfully implement null drop operands for types that don't need drop Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Refactor vtable metadata computation to use struct-based approach Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Changes before error encountered Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Changes before error encountered Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Improve drop shim generation with better structured naming and case distinction Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement actual drop shim function generation for vtable metadata Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix drop shim function generation with proper lifetime handling Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement proper dyn trait types and Concretize cast for drop shims Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Set drop shim functions as transparent for better naming display Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement generics handling for drop shim functions - first iteration Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix drop shim parameter types and implement proper dyn trait handling Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement generics handling for drop shim function references Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Refactor code organization and fix drop shim parameter types from pointers to references Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix generics handling with proper region variables and minimal generic parameters Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Complete vtable drop shim implementation with proper reference types and simplified generics Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * re-implemented layout info * Delete vtables * minor adjust * Implement create_dyn_trait_param_type by extracting from drop field type and handle Unknown case Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * fixd drop receiver * Add drop_glue field to TypeDecl for tracking drop implementations (#14) * Initial plan * Add drop_glue field to TypeDecl and implement translation logic Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix test case ordering after adding drop_glue field Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix panic in combine_span_iter when handling empty iterators Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * new ml & no-enqueue --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> Co-authored-by: ssyram <liguany126@126.com> * types fixed * Implement proper generics handling for drop shim functions Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * revised drop case * Implement comprehensive drop case analysis with array, tuple, and Box support Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * minor * minor * Implement concretize casting for array, tuple, and Box drop shims Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Enhance drop shim generation with structured drop case analysis Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Implement tuple field access with projections for drop shims Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Complete comprehensive drop shim logic implementation with detailed case analysis Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Simplify and combine DropShimKind and DropCase enums, simplify Box handling Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * fixed drop field * Implement complete tuple and array drop shim logic with CFG blocks and function calls Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix unused block_id assignment and add tuple/array drop test cases Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * new example added * Complete Box drop shim generics fix with proper trait clauses Fix Box drop shim generics - provide T and A type parameters correctly Co-Authored-By: ssyram <23273765+ssyram@users.noreply.github.com> * Revert "Complete Box drop shim generics fix with proper trait clauses" This reverts commit b889ebb. * Initial analysis and understanding of Box drop generics issue Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * fixed the case * Initial analysis and planning for Box drop generics and region binder fixes Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix region binders and partial Box generics handling Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Changes before error encountered Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix compilation errors and add missing Box detection methods Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Major progress on Box generics extraction and region variable fixes Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Initial analysis and planning for Box drop generics and region binder fixes Fix compilation errors and add missing Box detection methods Changes before error encountered Fix region binders and partial Box generics handling Co-Authored-By: ssyram <23273765+ssyram@users.noreply.github.com> * Revert "Initial analysis and planning for Box drop generics and region binder fixes" This reverts commit 2802a90. * Revert "Merge branch 'copilot/fix-95d3f204-c7e2-4956-8a71-c4a3988443ca' of https://github.com/ssyram/charon into copilot/fix-95d3f204-c7e2-4956-8a71-c4a3988443ca" This reverts commit 048ec8f, reversing changes made to eb84c07. * name & generic some fix * Implement region binder fix and Box built-in detection for drop shim generation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix generics mismatch and improve Box built-in detection for drop shims Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * fixed test region mismatch * Fix tuple drop shim generation to create proper field-by-field drop logic Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Complete array and tuple drop shim implementation with proper traversal logic Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * init-reform * Refactor drop shim generation with proper constant expressions and utility methods - Use `new_var()` and `place_for_var()` utilities instead of manual local creation - Use `ConstantExpr` directly instead of casting to primitive types - Fix scoping issues with concrete place by using `clone()` in loops - Clean up code organization and use `return_place()` utility - Remove unused variables to eliminate warnings - All vtables tests now pass Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix array drop shim counter types to match array length expression type Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * example changed * Implement comprehensive drop shim generation with proper array/tuple traversal and drop calls Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix Vec<T> drop detection by bypassing needs_drop for ADT types Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Fix recursive drop case analysis to handle primitive types correctly Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Simplify analyze_drop_case and fix projection issues in drop shim generation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * fixed box issue & new box example * Extract helper structures and simplify constant creation Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Refactor analyze_drop_case into smaller focused functions and organize code sections Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * Clean up verbose comments, remove unused code, and simplify function structure Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> * new example * more cleanup * new framework * debug done with new complex example --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ssyram <23273765+ssyram@users.noreply.github.com> Co-authored-by: ssyram <liguany126@126.com>
|
At least the Maybe I'm wrong and dismissing your PR too quickly. If that's the case, please explain in the top of your PR why you chose to do things like this, what other options you considered, and how you made sure that the logic you generated is correct as per rust semantics. |
|
Well, no, I put much time in implementing the drop logic myself -- AI generates the framework, which could not be used. So I hand implemented the recursion logic. I would quite strongly disagree with that you denied my efforts so quickly and this strongly and claimed it to be made by AI without even trying to understand. I myself tried quite hard to avoid troubles from AI and checked these parts myself. At least I made sure the test cases reflected correctly. This should show my efforts. As for the drop, the main part is about dropping the arrays and tuples. There is no logic for this right? We are now implementing the shim, which does not exist in the Rustc. So it could split the logic clearly in a pass instead of working during the translation, which requires the Charon, but actually we cannot rely on. Recall that Rustc does not have vtable method shims and we have to generate the shims ourselves. This is likewise the case for drop shims? Or, is there chances we get the drop function for the actual array or tuple types directly? If so, we can get rid of the drop logic, which essentially traverses the array or tuple types recursively and calls drop on those with drop functions. |
|
After lengthy discussion in DMs, I would like to publicly apologize for dimissing your PR out of hand, and I will also close this PR for not being acceptable for the various reasons I mentioned in DMs. #844 provides a lot of the functionality you were implementing here, except for the drops. The drop impls for arrays and tuples you add here look valuable, I'd welcome a PR that adds them in a robust way. |
Following #839 , this PR is also split from #762 . It contains the part of vtable support series for computing the meta-fields of vtable, i.e., the
size,alignanddropfields. This PR adds a new passcompute_vtable_metadatafor this purpose.The former two fields read the data from the
layoutof the type definition (possibly unavailable).The tough part is the
dropfield, where for some built-in data, e.g., arrays & tuples, the drop functions are newly implemented to recursively traverse the internal data to call the potential drop functions.