Add haxe.ds.WeakRef and expand WeakMap target coverage#12765
Open
jdonaldson wants to merge 3 commits intoHaxeFoundation:developmentfrom
Open
Add haxe.ds.WeakRef and expand WeakMap target coverage#12765jdonaldson wants to merge 3 commits intoHaxeFoundation:developmentfrom
jdonaldson wants to merge 3 commits intoHaxeFoundation:developmentfrom
Conversation
5 tasks
Add WeakRef<T> for holding weak references across 6 targets: - Lua: setmetatable with __mode='v' - Python: weakref.ref() - JS: js.lib.WeakRef - C++: __hxcpp_weak_ref_create/get - JVM: java.lang.ref.WeakReference - PHP: \WeakReference (PHP 7.4+) Add WeakMap<K,V> for Lua (__mode='k'), Python (WeakKeyDictionary), JS (js.lib.WeakMap, enumeration throws), and PHP (\WeakMap, PHP 8.0+). C++, JVM, and Flash implementations already existed. Unsupported targets fall through to the default stub which throws NotImplementedException.
Python WeakRef: use python.Syntax.code instead of @:selfCall which generates broken .call() on Python target. JVM WeakMap: fix NPE by initializing hash table arrays in constructor, use explicit java.lang.Object casts for hashCode()/equals() instead of untyped which fails JVM field resolution on inherited methods. Tests: add target-conditional gates for platforms with/without WeakRef and WeakMap support, add strong reference assertions to prevent compiler from inlining away weak reference targets on refcount-GC platforms.
fab8f18 to
6589e85
Compare
Member
Author
|
Rebased onto current development (picks up GcFinalizer merge, native bit ops, etc.) and added a couple of fixes:
CI is green, all targets pass. Now that GcFinalizer (#12766) has landed, this is a natural companion — together they cover the core GC-aware primitives ( |
noAssert() fallback guard used bare `cpp` which excluded cppia entirely, meaning zero test functions would run on cppia (empty class = CI warning). Changed to (cpp && !cppia) to match the other guards in the file.
6589e85 to
a5dd9a9
Compare
Member
Author
|
Removed the changes to Changes.txt. Bad Claude! |
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
haxe.ds.WeakRef<T>— a cross-platform weak reference type with implementations for 6 targetshaxe.ds.WeakMap<K,V>implementations for Lua, Python, JS, and PHP (C++, JVM, Flash already existed)NotImplementedExceptionWeakRef target coverage
setmetatable({[1]=target}, {__mode='v'})weakref.ref()js.lib.WeakRef__hxcpp_weak_ref_create/getjava.lang.ref.WeakReference\WeakReference::create()(PHP 7.4+)New WeakMap implementations
setmetatable({}, {__mode='k'})— fullIMapsupportweakref.WeakKeyDictionary— fullIMapsupportjs.lib.WeakMap— enumeration methods throwNotImplementedException(spec limitation)\WeakMap(PHP 8.0+) — fullIMapsupportTest plan
WeakRef.get(), identity preservation,WeakMapset/get/exists/remove/overwrite/clear, iteration (#if !js), JS enumeration throws (#if js)