Detect and throw on layer.ref cycles