Shinmera / plump

Practically Lenient and Unimpressive Markup Parser for Common Lisp
https://shinmera.github.io/plump
zlib License
119 stars 21 forks source link

Change parent ftype declamation? #9

Closed ohnoitsavram closed 8 years ago

ohnoitsavram commented 8 years ago

Currently parent is declaimed

(declaim (ftype (function (child-node) nesting-node) parent))

However, the type of %parent is

(or null node)

The main issue is that, at least on SBCL,

(let ((parent (parent (make-instance 'child-node :parent nil)))) (if parent 'foo 'bar))

returns foo, when you'd expect bar. This is because SBCL assumes parent will be a nested-node, due to the declamation, and optimizes the branch away.

My particular use case is that I'm subclassing plump's dom classes, but am representing the root node as just another element that happens to have no parent. I think this is fairly reasonable.

As a work around I've done:

(declaim (ftype (function (child-node) (or node null)) parent))

So the declaimed type of the accessor matches the type of the slot.

Shinmera commented 8 years ago

Right, the declarations being off is definitely wrong. However, I'm going to change both declarations to (or null nesting-node) as that seems the only sensible choice in the context of a DOM, where only a nesting-node can contain other nodes.