typelead / eta

The Eta Programming Language, a dialect of Haskell on the JVM
https://eta-lang.org
BSD 3-Clause "New" or "Revised" License
2.61k stars 141 forks source link

Automatic class splitting #942

Open rahulmutt opened 5 years ago

rahulmutt commented 5 years ago

When you have really large source files (2K+ lines), there's a chance that the generated class will be so huge that the constant pool size will exceed the 65,535 size limit. The compiler should change its code generation to avoid such problem - perhaps by shifting static methods definitions to individual classes instead of putting all the implementations into the Module class.

rahulmutt commented 5 years ago

I've tried the mentioned suggestion and it made very little difference for the particular example I was working on. It turns out that the more general solution to this problem is to distribute constants more deeply in the generated classes. What's happening is that all the classes are being initialized inside the module class itself when they can be instantiated in the required closures that are demanded by the user.

By distributing class constants this way, we avoid hitting the classfile limits and avoid having to do workaround patches in packages like pandoc.

jneira commented 5 years ago

Would it fix errors with too big methods?

rahulmutt commented 5 years ago

Nope, which is why this is a separate issue. Overflowing the constant pool is a serious problem since the entire class file is considered invalid and will cause issues with tools like Proguard. Overflowing the bytecode limit is not as much of a problem - the bytecode size can be specified in a Word32 so the classfile is "valid" but the method itself will fail verification when called.