From 7771ed34cf0938d2deeb77726feb5bb6d8cecd3e Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Mon, 31 Jan 2022 15:34:24 +0000 Subject: [PATCH] [CFE] Fix crash in expression compilation caused by having dill builders in source builders scope This should fix https://github.com/flutter/flutter/issues/97500 and the reproducable part of https://github.com/flutter/devtools/issues/3599 Change-Id: I16b45e4cc8074e0b0a62ae3220d91ae1424bacf3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231004 Reviewed-by: Johnni Winther Commit-Queue: Jens Johansen --- .../lib/src/fasta/incremental_compiler.dart | 20 +++++++++++++++++++ .../test/spell_checking_list_code.txt | 1 + pkg/front_end/testcases/expression.status | 2 -- .../platform_isandroid.expression.yaml.expect | 4 ++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 pkg/front_end/testcases/expression/platform_isandroid.expression.yaml.expect diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart index 2aabaff1867..5e0c376779a 100644 --- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart +++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart @@ -1731,6 +1731,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator { } } + // Setup scope first in two-step process: + // 1) Create a new SourceLibraryBuilder, add imports and setup (import) + // scope. + // 2) Create a new SourceLibraryBuilder, using a nested scope of the scope + // we just created as the scope. The import scopes have been setup via + // the parent chain. + // This is done to create the correct "layering" (i.e. definitions from + // the "self" library first, then imports while not having dill builders + // directly in the scope of a source builder (which can crash things in + // some circumstances). SourceLibraryBuilder debugLibrary = new SourceLibraryBuilder( importUri: libraryUri, fileUri: debugExprUri, @@ -1784,6 +1794,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator { debugLibrary.addImportsToScope(); _ticker.logMs("Added imports"); } + debugLibrary = new SourceLibraryBuilder( + importUri: libraryUri, + fileUri: debugExprUri, + packageLanguageVersion: + new ImplicitLanguageVersion(libraryBuilder.library.languageVersion), + loader: lastGoodKernelTarget.loader, + scope: debugLibrary.scope.createNestedScope("expression"), + nameOrigin: libraryBuilder, + isUnsupported: libraryBuilder.isUnsupported, + ); HybridFileSystem hfs = lastGoodKernelTarget.fileSystem as HybridFileSystem; diff --git a/pkg/front_end/test/spell_checking_list_code.txt b/pkg/front_end/test/spell_checking_list_code.txt index b338dd608f2..2fe783e09ad 100644 --- a/pkg/front_end/test/spell_checking_list_code.txt +++ b/pkg/front_end/test/spell_checking_list_code.txt @@ -671,6 +671,7 @@ launched launcher layer layered +layering layers layout lc diff --git a/pkg/front_end/testcases/expression.status b/pkg/front_end/testcases/expression.status index 76b0665066c..e9ab4a8a2bb 100644 --- a/pkg/front_end/testcases/expression.status +++ b/pkg/front_end/testcases/expression.status @@ -1,5 +1,3 @@ # Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file # 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. - -platform_isandroid.expression: Crash diff --git a/pkg/front_end/testcases/expression/platform_isandroid.expression.yaml.expect b/pkg/front_end/testcases/expression/platform_isandroid.expression.yaml.expect new file mode 100644 index 00000000000..872d5f9024b --- /dev/null +++ b/pkg/front_end/testcases/expression/platform_isandroid.expression.yaml.expect @@ -0,0 +1,4 @@ +Errors: { +} +static method /*isLegacy, from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic + return dart.io::Platform::isAndroid;