Repository navigation
Store a Bool a cppia script puts in a Map as a Bool - #487
Merged
Merged
Conversation
The Haxe standard library gives scriptable hosts a setBool on StringMap, IntMap and ObjectMap, and the cppia generator calls it for map.set(key, value) with a Bool value. It calls the Int setter with a C++ bool, so the value was stored as an Int: read back as a Dynamic it was 1, Std.isOfType(value, Bool) was false, map.get(key) == true was false and toString printed 1. Compiled code was right, since the classes' own set(key, bool) overloads call the untyped setter. The three Int setters get an overload that takes exactly a bool and stores it through the untyped setter, as compiled code does. It is a template on a trait rather than a plain bool parameter, which made the classes' own set(key, unsigned int) ambiguous. HaxeFoundation/haxe#13246
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.
Fixes #485.
A
Boolthat cppia script code puts in aMapwas stored as anInt. A read typedBoolconverted it back, but read asDynamicit was1:Std.isOfType(value, Bool)wasfalse,map.get(key) == truewasfalse, andtoStringprinted1. It was the same interpreted and under the JIT, forStringMap,IntMapandObjectMap, and for aMap<String, Dynamic>given aBool. Compiled code was right.Cause
The Haxe standard library gives scriptable hosts a
setBoolon the three classes, and a script'smap.set(key, value)with aBoolvalue is compiled to a call to it. It calls the Int setter with a C++bool:The classes' own
set(key, bool)overloads, which compiled code uses, call the untyped setter. This is reported as HaxeFoundation/haxe#13246, and the runtime can absorb it for every Haxe it supports.The change
__int_hash_set_int,__string_hash_set_intand__object_hash_set_inteach get an overload ininclude/hx/StdLibs.hthat takes exactly abooland stores it through the untyped setter, as compiled code does. The standard library'ssetBoolpasses abool, so it reaches the overload, and every other caller still reaches the Int setter. It is a template on a trait and not a plainboolparameter, which made the classes' ownset(key, unsigned int)ambiguous.This changes what a script observes: it now reads
trueorfalsewhere it read1or0.Tests
test/regression/CppiaMapBoolruns one script interpreted and jitted: String, Int and object keys,trueandfalse, read asDynamic, compared, throughtoString, into a typedBool, and beside Int and mixed values that must stay what they are. Before the change 32 of its 56 lines were wrong.Run on 64-bit Windows with MSVC and Haxe 4.3.7:
CppiaMapBool, also built with-D HXCPP_GC_GENERATIONAL, where the setters take an owner.test/cppia, interpreted and with-jit: 56 assertions each.test/haxe: 2698 assertions.CppiaBoolBoxing,CppiaBoolBuiltins,CppiaJitBoolField,IntMapHashSwitch,Int64HashDynamicValues,GenerationalMapEdges,GenerationalMapYoungLog,ObjectMapMixedInt64Float,MapFormattingCycles,MapShrinkRegrow,WeakMapValueStorage,GcFreezeObjectMap.Those ran before the branch was rebased onto the commit that opens 6.0.1, which changes only the version and
Changes.md.CppiaMapBoolandCppiaBoolBoxingran again after it.Not run here: the whole of
test/regression,test/std, and the other platforms.