tarantool / avro-schema

Apache Avro schema tools for Tarantool
57 stars 4 forks source link

LuajitError: <schema-jit>:<LINE>: function at line <LINE> has more than 200 local variables #124

Closed Totktonada closed 5 years ago

Totktonada commented 5 years ago

Reproducer (reduced here for readability):

local avro_schema = require('avro_schema')

local ok, schema = avro_schema.create(<large schema>)
print("========================================> schema created: " .. tostring(ok))

local ok, methods = avro_schema.compile({schema, debug = true, dump_il = "output.il", dump_src = "output.lua"})

return {
    schema = schema,
    methods = methods
}

Full code: case.lua.txt

Expected: no error. Got: LuajitError: :: function at line has more than 200 local variables

Bisect log:

bad  bbcf5fc fix: allow to reload module
     30fa5fb travis-ci: update distributives and repositories
     461f1ce (tag: 3.0.3) Fix validation of non-number keys in array validation (#118)
     597458c travis: rename 2_0 to 2x
     126b886 (tag: 3.0.2) Fix nil-union validate
     083b4a4 (tag: 3.0.1) Fix temp_msgpack_gc/flatten race bug
     bd8b6b3 Fix most luacheck warnings
     6bcd2a4 Get rig of debug && fix stack collapse bug
     cbba1ff Implement efficient stack data structure
     ddc894b Fix schema evolution for nullable fields
     972d308 Add more comments to the code
     ccbcc48 Add docs on default values
     49ac170 compiler: delete unused ripv variable
     1f2ed59 Add logo, TOC, crosslinks; fix markup
     0f167f4 Changed README.md (#100)
     9d853a7 Improve evolution: allow new default record value
     595fe70 Fix default union value emission
     c607736 Fix nullable default values
     19e0582 Merge pull request #61 from tarantool/add-references-and-nullability-to-readme
     740777c Update README with several features
     35e20ad Add references and nullability to the README
     d113c8f Convert README from DOS to Unix newlines format
     194cbf1 Merge pull request #97 from tarantool/deploy-new-versions
     534875c Add deploy of new versions
     6fbd4d6 fix intalling via luarocks
bad  60eac4b (tag: 3.0.0) Improve get_names get_types
     6f8d05c Prohibit nullable record xflatten by default
     d2b154d Add error opcode
     ffa445a Improve flatten for record* inside of array/union
     d51696a Implement xflatten for nullable types
     cf711a8 Small code cleanup
     a276177 Fix flatten for nullable types with a variable size
bad  63e7e8a Implement flatten/unflatten for record*
bad  e2f6f3d Fix tests to respect new flatten/unflatten
bad  3379b4a Reimplement flatten/unflatten for nullable
bad  5c7c991 Fix nullable field is not mandatory
bad  c122bd1 Give variables the same names in ir and in lua
good cac5df2 Minor refactoring
good 2b3f6a0 (tag: 2.3.2) Fix boolean fied validation

The reason of the issue is that commit c122bd1 breaks reusing of local variables in a generated code.

sergos commented 5 years ago

from https://www.lua.org/pil/4.2.html A common idiom in Lua is

local foo = foo

This code creates a local variable, foo, and initializes it with the value of the global variable foo. That idiom is useful when the chunk needs to preserve the original value of foo even if later some other function changes the value of the global foo; it also speeds up access to foo.

Totktonada commented 5 years ago

@sergos See more here (don't sure how much it matters for LuaJIT). But it is not relevant to this issue.

Totktonada commented 5 years ago

My proposal is to revert the commit to fix the customer's problem. Maybe it would be good to reimplement the ability to save variable names under an option for debugging purposes.

Totktonada commented 5 years ago

BTW, I wrote a small script to obfuscate customer's avro-schema: https://gist.github.com/Totktonada/4158f63b99bbca19a6f0d1a0c9a26717