elm-fuse icon indicating copy to clipboard operation
elm-fuse copied to clipboard

Function collision

Open knewter opened this issue 7 years ago • 3 comments

Regarding: https://github.com/eeue56/elm-fuse/blob/c131491bea4387ce35e503609060381d864d1a0b/src/Fuse.elm#L431

So I added this code:

functionToString : (a -> b) -> String
functionToString fn =
    FFI.sync "console.log(_0.toString());return 'func' + _0.toString().length.toString();" [ FFI.asIs fn ]
        |> FFI.intoElm

This function:

        reflectString active .activeTab

Yielded this output:

function (_p31) {
				return _elm_lang$core$Json_Encode$string(
					view(_p31));
			}

As did this function:

        reflectString layoutMaster (\model -> model.activeTab ++ "Tab")

The point being, regardless of the fact that 'length' is going to lead to collisions (I know it's super alpha), the function this is being called on in FFI is identical for basically anything I pass to it. No clue why, but I'm digging in. The moral of the story is: I'm getting the wrong function called once I add a second reflection. Looking at it, will update with details later hopefully.

knewter avatar Apr 12 '17 05:04 knewter

That function that's being lengthd is actually from elm-fuse itself. From my elm.js:

var _user$project$Fuse$reflectString = F2(
	function (attributeMake, view) {
		return A2(
			_user$project$Fuse$reflect,
			function (_p30) {
				return attributeMake(
					_eeue56$elm_ffi$FFI$intoElm(_p30));
			},
			function (_p31) {
				return _elm_lang$core$Json_Encode$string(
					view(_p31));
			});
	});

knewter avatar Apr 12 '17 05:04 knewter

EDIT: I previously was wrong here.

Here's the culprit:

reflectString : (String -> Attribute msg model) -> (model -> String) -> Attribute msg model
reflectString attributeMake view =
    reflect (FFI.intoElm >> attributeMake) (view >> Json.string)

It would appear that that's the reason these are identical. Woops! I guess it doesn't work with two reflectStrings at the moment since they have the exact same body. I'll fiddle some and see if I can find a nicer hash

knewter avatar Apr 12 '17 05:04 knewter

I just confirmed that using a reflect rather than reflectString works, for reasons that are now obvious to me. In general, at present you cannot use more than one reflectString in an application because they all hash to the same function name, and a 'smarter' hashing function than length wouldn't fix it either.

knewter avatar Apr 12 '17 05:04 knewter