internal/core/adt: use Closed for checking recursive closedness

Prepare for a structure sharing implementation.

Change-Id: I8ede77c9b5301377b47031e70e98d343ef5e3eb6
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9575
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/internal/core/adt/closed.go b/internal/core/adt/closed.go
index 045179c..f06abdb 100644
--- a/internal/core/adt/closed.go
+++ b/internal/core/adt/closed.go
@@ -82,15 +82,7 @@
 // IsRecursivelyClosed returns true if this value is either a definition or unified
 // with a definition.
 func (v *Vertex) IsRecursivelyClosed() bool {
-	if v.IsInOneOf(DefinitionSpan) {
-		return true
-	}
-	for p := v; p != nil; p = p.Parent {
-		if p.Label.IsDef() {
-			return true
-		}
-	}
-	return false
+	return v.Closed || v.IsInOneOf(DefinitionSpan)
 }
 
 type closeNodeType uint8
diff --git a/internal/core/adt/closed2.go b/internal/core/adt/closed2.go
index 23606e5..6f9a394 100644
--- a/internal/core/adt/closed2.go
+++ b/internal/core/adt/closed2.go
@@ -35,6 +35,8 @@
 	// TODO(perf): collect positions in error.
 	defer ctx.ReleasePositions(ctx.MarkPositions())
 
+	// Note: it is okay to use parent here as this only needs to be computed
+	// for the original location.
 	if ok, required := Accept(ctx, v.Parent, f); ok || (!required && !isClosed) {
 		return true, nil
 	}