From 90127334ea4aab5267135b959e361229dfac6bc9 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Fri, 7 May 2021 22:50:27 +0000 Subject: [PATCH] [dart2js] Pass box to inlined generative constructor body There was a rare mismatch between arguments and parameters when inlining a constructor body. The full arguments at the call site of a constructor body (always in a generative constructor factory) and the parameters at inlining would not agree on needing a 'box' for the constructor's closed-over mutated variables (parameters and locals) when the box was needed only for locals closed over in an assertion. The fix is to make the condition for accepting a box match the test for generating the box in the caller. Bug: 45943 Change-Id: I3b056cb710ffac72bec6943809e04472a838e5bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198741 Reviewed-by: Mayank Patke Commit-Queue: Stephen Adams --- pkg/compiler/lib/src/ssa/builder_kernel.dart | 4 +--- tests/web/regress/45943_test.dart | 2 +- tests/web_2/regress/45943_test.dart | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart index 498c686dafe..60a464a5791 100644 --- a/pkg/compiler/lib/src/ssa/builder_kernel.dart +++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart @@ -6130,7 +6130,6 @@ class KernelSsaGraphBuilder extends ir.Visitor with ir.VisitorVoidMixin { } ir.Member memberContextNode = _elementMap.getMemberContextNode(function); - bool hasBox = false; KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(function); forEachOrderedParameter(_elementMap, function, (ir.VariableDeclaration variable, {bool isElided}) { @@ -6144,14 +6143,13 @@ class KernelSsaGraphBuilder extends ir.Visitor with ir.VisitorVoidMixin { scopeData.isBoxedVariable(_localsMap, local)) { // The parameter will be a field in the box passed as the last // parameter. So no need to have it. - hasBox = true; return; } HInstruction argument = compiledArguments[argumentIndex++]; localsHandler.updateLocal(local, argument); }); - if (hasBox) { + if (forGenerativeConstructorBody && scopeData.requiresContextBox) { HInstruction box = compiledArguments[argumentIndex++]; assert(box is HCreateBox); // TODO(sra): Make inlining of closures work. We should always call diff --git a/tests/web/regress/45943_test.dart b/tests/web/regress/45943_test.dart index 52315f57a60..4b40c44a22d 100644 --- a/tests/web/regress/45943_test.dart +++ b/tests/web/regress/45943_test.dart @@ -12,7 +12,7 @@ class _InspectorOverlayLayer { return true; }()); if (inDebugMode == false) { - throw Error(); + print('Error'); } } } diff --git a/tests/web_2/regress/45943_test.dart b/tests/web_2/regress/45943_test.dart index 52315f57a60..4b40c44a22d 100644 --- a/tests/web_2/regress/45943_test.dart +++ b/tests/web_2/regress/45943_test.dart @@ -12,7 +12,7 @@ class _InspectorOverlayLayer { return true; }()); if (inDebugMode == false) { - throw Error(); + print('Error'); } } }