From b54269e2551608a388f11eb6ccd21a7c41d9b529 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Tue, 24 Aug 2021 10:37:49 +0000 Subject: [PATCH] [cfe] Updates cf. equivalence visitors comments Change-Id: Ib5990cf1434ce07019e9602150df66b359476095 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210863 Reviewed-by: Jens Johansen Commit-Queue: Johnni Winther --- .../test/spell_checking_list_code.txt | 2 +- .../test/spell_checking_list_tests.txt | 2 +- pkg/front_end/tool/ast_model.dart | 8 ++++- .../tool/generate_ast_equivalence.dart | 2 +- pkg/kernel/lib/src/equivalence.dart | 2 +- pkg/kernel/lib/src/union_find.dart | 5 +++ pkg/kernel/test/equivalence_test.dart | 34 ++++++++++--------- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/pkg/front_end/test/spell_checking_list_code.txt b/pkg/front_end/test/spell_checking_list_code.txt index 1e568ba1461..ea6bf68ce43 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 @@ rpc 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 6ec4b57493b..89c8686770d 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 @@ row 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 a0708e46790..ae209a2c6a8 100644 --- a/pkg/front_end/tool/ast_model.dart +++ b/pkg/front_end/tool/ast_model.dart @@ -505,17 +505,24 @@ class AstModel { /// /// If [printDump] is `true`, a dump of the model printed to stdout. Future 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 @@ Future deriveAstModel(Uri repoDir, {bool printDump: false}) async { 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 9be6f4ec9f6..22af2767ae7 100644 --- a/pkg/front_end/tool/generate_ast_equivalence.dart +++ b/pkg/front_end/tool/generate_ast_equivalence.dart @@ -432,7 +432,7 @@ part 'equivalence_helpers.dart'; /// 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 2f9fab4b4db..a8edddbb28d 100644 --- a/pkg/kernel/lib/src/equivalence.dart +++ b/pkg/kernel/lib/src/equivalence.dart @@ -18,7 +18,7 @@ part 'equivalence_helpers.dart'; /// 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 { final EquivalenceStrategy strategy; diff --git a/pkg/kernel/lib/src/union_find.dart b/pkg/kernel/lib/src/union_find.dart index 4dffab07e0a..bab7fc6f77e 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 { @@ -46,6 +50,7 @@ class UnionFind { UnionFindNode findNode(UnionFindNode 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 de5ec47bef6..f57f2a0758e 100644 --- a/pkg/kernel/test/equivalence_test.dart +++ b/pkg/kernel/test/equivalence_test.dart @@ -67,23 +67,22 @@ Values true and false are not equivalent '''), 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 @@ class IgnoreIntLiteralValue extends EquivalenceStrategy { 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;