Sunday, March 31, 2013

Pitfalls of shared structure, or: fixing XPATH compilation

In recent blog posts, Hans Hübner mentions how ABCL starts to be usable by the average Common Lisp programmer. Yet he also ran into the longer standing issue that the XPATH library doesn't want to be compiled by ABCL 1.1.1. (This is where his remark how the CXML-STP library doesn't work comes from.)

Last weekend I finally found out what the underlying problem was that XPATH triggered: shared structure in forms being compiled. Even though it's quite easy to generate code with shared structure, apparently few projects use it in a way which triggered ABCL into incorrect behaviour.

Case in point was a compiler macro expansion containing a literal list. After expansion, the literal became part of the code being compiled and the compiler modified the literal in place, resulting in problems on all subsequent expansions.

The cause of the issue dates all the way back to even before I started working on ABCL. Back then the compiler used to modify the CARs and CDRs of the forms it was compiling. Much of this behaviour was already replaced before last week as my intuition told me this is undesirable, with the replacement being nice side-effect-free functional code. Even though the reason for this behaviour isn't documented, I'll assume it was to reduce consing and thereby reduce pressure on the JVM's garbage collector. In today's world with new garbage collectors and much improved JIT compilers in the JVM, this issue isn't an issue anymore.

To cut a long story short: XPATH compilation fixed, compiler changed to functional style and libraries depending on XPATH (like CXML-STP) also fixed.

On to the next cl-test-grid failure...

2 comments:

  1. Just a minor correction. The spelling is "literal" (only one t).

    ReplyDelete
  2. Thanks. Corrected. At least I was consistent: 3 misspellings, all the same error.

    ReplyDelete