HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.14k stars 653 forks source link

Regression: local variable compilation #4236

Closed ncannasse closed 7 years ago

ncannasse commented 9 years ago

When running some heaps samples in flash, I get the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert hxsl::VecType@690b9e1 to hxsl.Type.
    at hxsl::Eval/evalExpr()[D:\Projects\hxtools\heaps\hxsl/Eval.hx:375]
    at hxsl::Eval/evalExpr()[D:\Projects\hxtools\heaps\hxsl/Eval.hx:241]
    at hxsl::Eval/evalExpr()[D:\Projects\hxtools\heaps\hxsl/Eval.hx:229]
...

It seems to come from some invalid code compiled by Haxe, since it was compiling/running fine before I updated GIT :)

Simn commented 9 years ago

Which sample is that?

ncannasse commented 9 years ago

Ah, this seems to come from change in cache handling in haxe.Serializer

MSGhero commented 9 years ago

When I install nape on dev haxe, some of the variables in nape's source code (the actual .hx files) are being replaced with "null," which of course throws hundreds of errors. Is this the same issue?

It works fine on master 3.2.0. Breaks in the git build right after the master release.

ncannasse commented 9 years ago

@Simn if you try heaps/samples/2d with SWF you'll get a runtime error

I could investigate a bit further, here's some correct shader serialization output:

oy4:funsaoy4:argsahy4:exproy1:ejy13:hxsl.TExprDef:4:1aoR3jR4:7:2oy4:kindjy12:hxsl.VarKind:4:0y4:namey1:ay4:typejy9:hxsl.Type:5:2i4jy12:hxsl.VecType:1:0y2:idi-199goR3jR4:16:2oR3jR4:1:1oR5jR6:2:0R7y10:animFramesR9jR10:14:2r10jy13:hxsl.SizeDecl:1:1oR5r14R7y8:MaxAnimsR9jR10:1:0y10:qualifiersajy17:hxsl.VarQualifier:0:1nhR12i-196gR12i-197gy1:poy4:filey33:src%2Fmap%2Ffx%2FTileGroupAnim.hxy3:maxi357y3:mini347gy1:tr20goR3jR4:1:1oR5jR6:1:0R7y4:animR9jR10:3:0y6:parentoR5r25R7y5:inputR9jR10:12:1aoR5r25R7y8:positionR9jR10:5:2i2r9R25r27R12i-191goR5r25R7y2:uvR9jR10:5:2i2r9R25r27R12i-192goR5r25R7y5:colorR9jR10:5:2i4r9R25r27R12i-193gr24hR12i-190gR12i-194gR18oR19R20R21i368R22i358gR23r26gR18oR19R20R21i369R22i347gR23r10gR18oR19R20R21i370R22i339gR23jR10:0:0goR3jR4:5:3jy16:haxe.macro.Binop:4:0oR3jR4:9:2oR3jR4:1:1oR5r8R7y12:calculatedUVR9jR10:5:2i2r9R12i-195gR18oR19R20R21i387R22i375gR23r48gajy14:hxsl.Component:0:0hR18oR19R20R21i389R22i375gR23r26goR3jR4:5:3jR30:0:0oR3jR4:5:3jR30:19:0oR3jR4:3:1oR3jR4:5:3r56oR3jR4:3:1oR3jR4:5:3jR30:3:0oR3jR4:9:2oR3jR4:1:1r47R18oR19R20R21i406R22i394gR23r48gar52hR18oR19R20R21i408R22i394gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i412R22i411gR23r10gar52hR18oR19R20R21i414R22i411gR23r26gR18oR19R20R21i414R22i394gR23r26gR18oR19R20R21i415R22i393gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i419R22i418gR23r10gajR32:2:0hR18oR19R20R21i421R22i418gR23r26gR18oR19R20R21i421R22i393gR23r26gR18oR19R20R21i422R22i392gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i426R22i425gR23r10gajR32:1:0hR18oR19R20R21i428R22i425gR23r26gR18oR19R20R21i428R22i392gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i432R22i431gR23r10gar52hR18oR19R20R21i434R22i431gR23r26gR18oR19R20R21i434R22i392gR23r26gR18oR19R20R21i434R22i375gR23r26ghR18oR19R20R21i440R22i333gR23r42gR5jy17:hxsl.FunctionKind:0:0y3:refoR5jR6:6:0R7y6:vertexR9jR10:13:1aoR1ahy3:retr42ghR12i-198gR36r42ghR7y15:map.fx.TileAnimy4:varsar47r118r13r15r27hg

And the wrong one:

oy4:funsaoy4:argsahy4:exproy1:ejy13:hxsl.TExprDef:4:1aoR3jR4:7:2oy4:kindjy12:hxsl.VarKind:4:0y4:namey1:ay4:typejy9:hxsl.Type:5:2i4jy12:hxsl.VecType:1:0y2:idi-199goR3jR4:16:2oR3jR4:1:1oR5jR6:2:0R7y10:animFramesR9jR10:14:2r9jy13:hxsl.SizeDecl:1:1oR5r14R7y8:MaxAnimsR9jR10:1:0y10:qualifiersajy17:hxsl.VarQualifier:0:1nhR12i-196gR12i-197gy1:poy4:filey33:src%2Fmap%2Ffx%2FTileGroupAnim.hxy3:maxi357y3:mini347gy1:tr15goR3jR4:1:1oR5jR6:1:0R7y4:animR9jR10:3:0y6:parentoR5r25R7y5:inputR9jR10:12:1aoR5r25R7y8:positionR9jR10:5:2i2r9R25r27R12i-191goR5r25R7y2:uvR9jR10:5:2i2r9R25r27R12i-192goR5r25R7y5:colorR9jR10:5:2i4r9R25r27R12i-193gr24hR12i-190gR12i-194gR18oR19R20R21i368R22i358gR23r26gR18oR19R20R21i369R22i347gR23r9gR18oR19R20R21i370R22i339gR23jR10:0:0goR3jR4:5:3jy16:haxe.macro.Binop:4:0oR3jR4:9:2oR3jR4:1:1oR5r8R7y12:calculatedUVR9jR10:5:2i2r9R12i-195gR18oR19R20R21i387R22i375gR23r48gajy14:hxsl.Component:0:0hR18oR19R20R21i389R22i375gR23r26goR3jR4:5:3jR30:0:0oR3jR4:5:3jR30:19:0oR3jR4:3:1oR3jR4:5:3r56oR3jR4:3:1oR3jR4:5:3jR30:3:0oR3jR4:9:2oR3jR4:1:1r47R18oR19R20R21i406R22i394gR23r48gar52hR18oR19R20R21i408R22i394gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i412R22i411gR23r9gar52hR18oR19R20R21i414R22i411gR23r26gR18oR19R20R21i414R22i394gR23r26gR18oR19R20R21i415R22i393gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i419R22i418gR23r9gajR32:2:0hR18oR19R20R21i421R22i418gR23r26gR18oR19R20R21i421R22i393gR23r26gR18oR19R20R21i422R22i392gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i426R22i425gR23r9gajR32:1:0hR18oR19R20R21i428R22i425gR23r26gR18oR19R20R21i428R22i392gR23r26goR3jR4:9:2oR3jR4:1:1r7R18oR19R20R21i432R22i431gR23r9gar52hR18oR19R20R21i434R22i431gR23r26gR18oR19R20R21i434R22i392gR23r26gR18oR19R20R21i434R22i375gR23r26ghR18oR19R20R21i440R22i333gR23r42gR5jy17:hxsl.FunctionKind:0:0y3:refoR5jR6:6:0R7y6:vertexR9jR10:13:1aoR1ahy3:retr42ghR12i-198gR36r42ghR7y15:map.fx.TileAnimy4:varsar47r118r13r15r27hg

There's a difference shortly after the beginning related to references.

If you unserialize + trace, you get the following:

good shader:

Main.hx:5: { funs => [{ args => [], expr => { e => TBlock([{ e => TVarDecl({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 },{ e => TArray({ e => TVar({ kind => Param, name => animFrames, type => TArray(TVec(4,VFloat),SVar({ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 })), id => -197 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 357, min => 347 }, t => TArray(TVec(4,VFloat),SVar({ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 })) },{ e => TVar({ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => TStruct([{ kind => Input, name => position, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -191 },{ kind => Input, name => uv, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -192 },{ kind => Input, name => color, type => TVec(4,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -193 },{ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -194 }]), id => -190 }, id => -194 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 368, min => 358 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 369, min => 347 }, t => TVec(4,VFloat) }), p => { file => src/map/fx/TileGroupAnim.hx, max => 370, min => 339 }, t => TVoid },{ e => TBinop(OpAssign,{ e => TSwiz({ e => TVar({ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 387, min => 375 }, t => TVec(2,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 389, min => 375 }, t => TFloat },{ e => TBinop(OpAdd,{ e => TBinop(OpMod,{ e => TParenthesis({ e => TBinop(OpAdd,{ e => TParenthesis({ e => TBinop(OpSub,{ e => TSwiz({ e => TVar({ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 406, min => 394 }, t => TVec(2,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 408, min => 394 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 412, min => 411 }, t => TVec(4,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 414, min => 411 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 414, min => 394 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 415, min => 393 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 419, min => 418 }, t => TVec(4,VFloat) },[Z]), p => { file => src/map/fx/TileGroupAnim.hx, max => 421, min => 418 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 421, min => 393 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 422, min => 392 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 426, min => 425 }, t => TVec(4,VFloat) },[Y]), p => { file => src/map/fx/TileGroupAnim.hx, max => 428, min => 425 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 428, min => 392 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 432, min => 431 }, t => TVec(4,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 431 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 392 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 375 }, t => TFloat }]), p => { file => src/map/fx/TileGroupAnim.hx, max => 440, min => 333 }, t => TVoid }, kind => Vertex, ref => { kind => Function, name => vertex, type => TFun([{ args => [], ret => TVoid }]), id => -198 }, ret => TVoid }], name => map.fx.TileAnim, vars => [{ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 },{ kind => Function, name => vertex, type => TFun([{ args => [], ret => TVoid }]), id => -198 },{ kind => Param, name => animFrames, type => TArray(TVec(4,VFloat),SVar({ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 })), id => -197 },{ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 },{ kind => Input, name => input, type => TStruct([{ kind => Input, name => position, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -191 },{ kind => Input, name => uv, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -192 },{ kind => Input, name => color, type => TVec(4,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -193 },{ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -194 }]), id => -190 }] }

Bad shader:

Main.hx:5: { funs => [{ args => [], expr => { e => TBlock([{ e => TVarDecl({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 },{ e => TArray({ e => TVar({ kind => Param, name => animFrames, type => TArray(VFloat,SVar({ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 })), id => -197 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 357, min => 347 }, t => { kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 } },{ e => TVar({ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => TStruct([{ kind => Input, name => position, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -191 },{ kind => Input, name => uv, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -192 },{ kind => Input, name => color, type => TVec(4,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -193 },{ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -194 }]), id => -190 }, id => -194 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 368, min => 358 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 369, min => 347 }, t => VFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 370, min => 339 }, t => TVoid },{ e => TBinop(OpAssign,{ e => TSwiz({ e => TVar({ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 387, min => 375 }, t => TVec(2,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 389, min => 375 }, t => TFloat },{ e => TBinop(OpAdd,{ e => TBinop(OpMod,{ e => TParenthesis({ e => TBinop(OpAdd,{ e => TParenthesis({ e => TBinop(OpSub,{ e => TSwiz({ e => TVar({ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 406, min => 394 }, t => TVec(2,VFloat) },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 408, min => 394 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 412, min => 411 }, t => VFloat },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 414, min => 411 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 414, min => 394 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 415, min => 393 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 419, min => 418 }, t => VFloat },[Z]), p => { file => src/map/fx/TileGroupAnim.hx, max => 421, min => 418 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 421, min => 393 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 422, min => 392 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 426, min => 425 }, t => VFloat },[Y]), p => { file => src/map/fx/TileGroupAnim.hx, max => 428, min => 425 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 428, min => 392 }, t => TFloat },{ e => TSwiz({ e => TVar({ kind => Local, name => a, type => TVec(4,VFloat), id => -199 }), p => { file => src/map/fx/TileGroupAnim.hx, max => 432, min => 431 }, t => VFloat },[X]), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 431 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 392 }, t => TFloat }), p => { file => src/map/fx/TileGroupAnim.hx, max => 434, min => 375 }, t => TFloat }]), p => { file => src/map/fx/TileGroupAnim.hx, max => 440, min => 333 }, t => TVoid }, kind => Vertex, ref => { kind => Function, name => vertex, type => TFun([{ args => [], ret => TVoid }]), id => -198 }, ret => TVoid }], name => map.fx.TileAnim, vars => [{ kind => Local, name => calculatedUV, type => TVec(2,VFloat), id => -195 },{ kind => Function, name => vertex, type => TFun([{ args => [], ret => TVoid }]), id => -198 },{ kind => Param, name => animFrames, type => TArray(VFloat,SVar({ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 })), id => -197 },{ kind => Param, name => MaxAnims, type => TInt, qualifiers => [Const(null)], id => -196 },{ kind => Input, name => input, type => TStruct([{ kind => Input, name => position, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -191 },{ kind => Input, name => uv, type => TVec(2,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -192 },{ kind => Input, name => color, type => TVec(4,VFloat), parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -193 },{ kind => Input, name => anim, type => TFloat, parent => { kind => Input, name => input, type => <...>, id => -190 }, id => -194 }]), id => -190 }] }

As you can see, the TArray(TVec(4,VFloat),... was replaced by a TArray(VFloat,... which is incorrect. I guess it comes down to an issue with ObjectMap and enums in Flash but I could not come with a reproducible example.

I'll revert Serializer changes for now until we address the issue.

deltaluca commented 9 years ago

@MSGhero https://github.com/deltaluca/nape/issues/92

ncannasse commented 7 years ago

Unless we are planning to bring back Serializer changes we can close this.