Detect cyclic references to prevent infinite recursion

Prevents panics from stack overflow with a heuristic to detect cycles.
Alternatively, it may be more correct to increase the depth only in `case reflect.Ptr` and nowhere else, which produces the correct effect with the test cases I added.