[cfe] Updates cf. equivalence visitors comments

Change-Id: Ib5990cf1434ce07019e9602150df66b359476095
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210863
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/test/spell_checking_list_code.txt b/pkg/front_end/test/spell_checking_list_code.txt
index 1e568ba..ea6bf68 100644
--- a/pkg/front_end/test/spell_checking_list_code.txt
+++ b/pkg/front_end/test/spell_checking_list_code.txt
@@ -1079,7 +1079,7 @@
 rs
 runnable
 s
-sand
+sandboxed
 sanitizing
 saw
 say
diff --git a/pkg/front_end/test/spell_checking_list_tests.txt b/pkg/front_end/test/spell_checking_list_tests.txt
index 6ec4b57..89c8686 100644
--- a/pkg/front_end/test/spell_checking_list_tests.txt
+++ b/pkg/front_end/test/spell_checking_list_tests.txt
@@ -820,7 +820,7 @@
 rows
 runtimes
 rv
-sand
+sandboxed
 saves
 scans
 scheduler
diff --git a/pkg/front_end/tool/ast_model.dart b/pkg/front_end/tool/ast_model.dart
index a0708e4..ae209a2 100644
--- a/pkg/front_end/tool/ast_model.dart
+++ b/pkg/front_end/tool/ast_model.dart
@@ -505,17 +505,24 @@
 ///
 /// If [printDump] is `true`, a dump of the model printed to stdout.
 Future<AstModel> deriveAstModel(Uri repoDir, {bool printDump: false}) async {
+  bool errorsFound = false;
   CompilerOptions options = new CompilerOptions();
   options.sdkRoot = computePlatformBinariesLocation(forceBuildDir: true);
   options.packagesFileUri = computePackageConfig(repoDir);
   options.onDiagnostic = (DiagnosticMessage message) {
     printDiagnosticMessage(message, print);
+    if (message.severity == Severity.error) {
+      errorsFound = true;
+    }
   };
 
   InternalCompilerResult compilerResult = (await kernelForProgramInternal(
       astLibraryUri, options,
       retainDataForTesting: true,
       requireMain: false)) as InternalCompilerResult;
+  if (errorsFound) {
+    throw 'Errors found';
+  }
   ClassHierarchy classHierarchy = compilerResult.classHierarchy!;
   CoreTypes coreTypes = compilerResult.coreTypes!;
   TypeEnvironment typeEnvironment =
@@ -524,7 +531,6 @@
   Library astLibrary = compilerResult.component!.libraries
       .singleWhere((library) => library.importUri == astLibraryUri);
 
-  bool errorsFound = false;
   void reportError(String message) {
     print(message);
     errorsFound = true;
diff --git a/pkg/front_end/tool/generate_ast_equivalence.dart b/pkg/front_end/tool/generate_ast_equivalence.dart
index 9be6f4ec..22af276 100644
--- a/pkg/front_end/tool/generate_ast_equivalence.dart
+++ b/pkg/front_end/tool/generate_ast_equivalence.dart
@@ -432,7 +432,7 @@
 /// current assumptions. The current state has two modes. In the asserting mode,
 /// the default, inequivalences are registered when found. In the non-asserting
 /// mode, inequivalences are _not_ registered. The latter is used to compute
-/// equivalences in sand boxed state, for instance to determine which elements
+/// equivalences in sandboxed state, for instance to determine which elements
 /// to pair when checking equivalence of two sets.
 class $visitorName$visitorTypeParameters
     implements Visitor1<$returnType, $argumentType> {
diff --git a/pkg/kernel/lib/src/equivalence.dart b/pkg/kernel/lib/src/equivalence.dart
index 2f9fab4..a8edddb 100644
--- a/pkg/kernel/lib/src/equivalence.dart
+++ b/pkg/kernel/lib/src/equivalence.dart
@@ -18,7 +18,7 @@
 /// current assumptions. The current state has two modes. In the asserting mode,
 /// the default, inequivalences are registered when found. In the non-asserting
 /// mode, inequivalences are _not_ registered. The latter is used to compute
-/// equivalences in sand boxed state, for instance to determine which elements
+/// equivalences in sandboxed state, for instance to determine which elements
 /// to pair when checking equivalence of two sets.
 class EquivalenceVisitor implements Visitor1<bool, Node> {
   final EquivalenceStrategy strategy;
diff --git a/pkg/kernel/lib/src/union_find.dart b/pkg/kernel/lib/src/union_find.dart
index 4dffab0..bab7fc6 100644
--- a/pkg/kernel/lib/src/union_find.dart
+++ b/pkg/kernel/lib/src/union_find.dart
@@ -2,6 +2,10 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+/// Implementation of a union-find algorithm.
+///
+/// See https://en.wikipedia.org/wiki/Disjoint-set_data_structure
+
 import 'dart:collection';
 
 class UnionFindNode<T> {
@@ -46,6 +50,7 @@
 
   UnionFindNode<T> findNode(UnionFindNode<T> node) {
     if (node.parent != null) {
+      // Perform path compression by updating to the effective target.
       return node.parent = findNode(node.parent!);
     }
     return node;
diff --git a/pkg/kernel/test/equivalence_test.dart b/pkg/kernel/test/equivalence_test.dart
index de5ec47..f57f2a0 100644
--- a/pkg/kernel/test/equivalence_test.dart
+++ b/pkg/kernel/test/equivalence_test.dart
@@ -67,23 +67,22 @@
 '''),
   Test(component1, component2),
   Test(component1.libraries[0], component2.libraries[0]),
-  Test(component1.libraries[0], component2.libraries[0]),
   Test(component1.libraries[0], component2.libraries[1], inequivalence: '''
 Inequivalent nodes
-1: library file://uri1/
-2: library file://uri2/
+1: library import://uri1
+2: library import://uri2
 .root
 '''),
   Test(component1.libraries[1], component2.libraries[2], inequivalence: '''
 Inequivalent nodes
-1: library file://uri2/
-2: library file://uri3/
+1: library import://uri2
+2: library import://uri3
 .root
 '''),
   Test(component1.libraries[1], component2.libraries[3], inequivalence: '''
 Values file://uri2/ and file://uri3/ are not equivalent
 .root
- Library(library file://uri2/).fileUri
+ Library(library import://uri2).fileUri
 '''),
   Test(component1.libraries[0].procedures[0],
       component2.libraries[0].procedures[1],
@@ -173,31 +172,34 @@
 
 Component createComponent() {
   Component component = new Component();
-  Uri uri1 = Uri.parse('file://uri1');
-  Uri uri2 = Uri.parse('file://uri2');
-  Uri uri3 = Uri.parse('file://uri3');
-  Library library1 = new Library(uri1, fileUri: uri1);
+  Uri fileUri1 = Uri.parse('file://uri1');
+  Uri fileUri2 = Uri.parse('file://uri2');
+  Uri fileUri3 = Uri.parse('file://uri3');
+  Uri importUri1 = Uri.parse('import://uri1');
+  Uri importUri2 = Uri.parse('import://uri2');
+  Uri importUri3 = Uri.parse('import://uri3');
+  Library library1 = new Library(importUri1, fileUri: fileUri1);
   component.libraries.add(library1);
   Procedure procedure1foo = new Procedure(
       new Name('foo'), ProcedureKind.Method, new FunctionNode(null),
-      fileUri: uri1);
+      fileUri: fileUri1);
   library1.addProcedure(procedure1foo);
   Procedure procedure1bar = new Procedure(
       new Name('bar'), ProcedureKind.Method, new FunctionNode(null),
-      fileUri: uri1);
+      fileUri: fileUri1);
   library1.addProcedure(procedure1bar);
 
-  Library library2 = new Library(uri2, fileUri: uri2);
+  Library library2 = new Library(importUri2, fileUri: fileUri2);
   component.libraries.add(library2);
 
-  Library library3 = new Library(uri3, fileUri: uri2);
+  Library library3 = new Library(importUri3, fileUri: fileUri2);
   component.libraries.add(library3);
   Procedure procedure3foo = new Procedure(
       new Name('foo'), ProcedureKind.Method, new FunctionNode(null),
-      fileUri: uri1);
+      fileUri: fileUri1);
   library3.addProcedure(procedure3foo);
 
-  Library library4 = new Library(uri2, fileUri: uri3);
+  Library library4 = new Library(importUri2, fileUri: fileUri3);
   component.libraries.add(library4);
 
   return component;