Skip to content

Commit 3291465

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Treat redirecting factories as ordinary factories
After https://dart-review.googlesource.com/c/sdk/+/208681 it is now possible to use bodies of redirecting factories in the VM and treat redirecting factories like ordinary factories. TEST=vm/cc/DartAPI_New TEST=vm/dart/redirection_type_shuffling_test TEST=co19/LanguageFeatures/Constructor-tear-offs Fixes #33041 Fixes #29201 Issue #46231 Change-Id: If410d2913704a33035800144699fd6e8a2570a19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208684 Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 7f5d1cc commit 3291465

File tree

12 files changed

+42
-74
lines changed

12 files changed

+42
-74
lines changed

pkg/front_end/testcases/strong.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ dart2js/late_statics: SemiFuzzFailure # dartbug.com/45854
1010

1111
constructor_tearoffs/call_instantiation: TypeCheckError
1212
constructor_tearoffs/const_tear_off: RuntimeError
13-
constructor_tearoffs/redirecting_constructors: RuntimeError
14-
constructor_tearoffs/redirecting_factory_tear_off: RuntimeError
1513
extension_types/extension_on_nullable: ExpectationFileMismatchSerialized # Expected.
1614
extension_types/issue45775: ExpectationFileMismatchSerialized # Expected.
1715
extension_types/simple: ExpectationFileMismatchSerialized # Expected.

pkg/front_end/testcases/text_serialization.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
constructor_tearoffs/call_instantiation: TypeCheckError
1010
constructor_tearoffs/const_tear_off: RuntimeError
11-
constructor_tearoffs/redirecting_constructors: RuntimeError
12-
constructor_tearoffs/redirecting_factory_tear_off: RuntimeError
1311
extension_types/extension_on_nullable: ExpectationFileMismatchSerialized # Expected.
1412
extension_types/issue45775: ExpectationFileMismatchSerialized # Expected.
1513
extension_types/simple: ExpectationFileMismatchSerialized # Expected.

pkg/front_end/testcases/weak.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ dart2js/late_statics: SemiFuzzFailure # dartbug.com/45854
1313

1414
constructor_tearoffs/call_instantiation: TypeCheckError
1515
constructor_tearoffs/const_tear_off: RuntimeError
16-
constructor_tearoffs/redirecting_constructors: RuntimeError
17-
constructor_tearoffs/redirecting_factory_tear_off: RuntimeError
1816
extension_types/extension_on_nullable: ExpectationFileMismatchSerialized # Expected.
1917
extension_types/issue45775: ExpectationFileMismatchSerialized # Expected.
2018
extension_types/simple: ExpectationFileMismatchSerialized # Expected.

pkg/vm/lib/transformations/type_flow/native_code.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'dart:core' hide Type;
88

99
import 'package:kernel/ast.dart';
1010
import 'package:kernel/library_index.dart' show LibraryIndex;
11-
import 'package:front_end/src/api_unstable/vm.dart'
12-
show getRedirectingFactoryBody;
1311

1412
import 'calls.dart';
1513
import 'types.dart';
@@ -74,26 +72,6 @@ class PragmaEntryPointsVisitor extends RecursiveVisitor {
7472
var type = _annotationsDefineRoot(proc.annotations);
7573
if (type == null) return;
7674

77-
if (proc.isRedirectingFactory) {
78-
if (type != PragmaEntryPointType.CallOnly &&
79-
type != PragmaEntryPointType.Default) {
80-
throw "Error: factory $proc doesn't have a setter or getter";
81-
}
82-
Member target = proc;
83-
while (target is Procedure && target.isRedirectingFactory) {
84-
target = getRedirectingFactoryBody(target)!.target!;
85-
assert(
86-
(target is Procedure && target.isFactory) || target is Constructor);
87-
}
88-
entryPoints
89-
.addRawCall(new DirectSelector(target, callKind: CallKind.Method));
90-
if (target is Constructor) {
91-
entryPoints.addAllocatedClass(target.enclosingClass);
92-
}
93-
nativeCodeOracle.setMemberReferencedFromNativeCode(target);
94-
return;
95-
}
96-
9775
void addSelector(CallKind ck) {
9876
entryPoints.addRawCall(proc.isInstanceMember
9977
? new InterfaceSelector(proc, callKind: ck)

pkg/vm/lib/transformations/type_flow/summary_collector.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ class SummaryCollector extends RecursiveResultVisitor<TypeExpr?> {
608608
"${member}${fieldSummaryType == FieldSummaryType.kFieldGuard ? " (guard)" : ""}";
609609
debugPrint("===== $summaryName =====");
610610
assert(!member.isAbstract);
611-
assert(!(member is Procedure && member.isRedirectingFactory));
612611

613612
_protobufHandler?.beforeSummaryCreation(member);
614613

@@ -2477,17 +2476,7 @@ class ConstantAllocationCollector extends ConstantVisitor<Type> {
24772476
return new ConcreteType(resultClass.cls, null, constant);
24782477
}
24792478

2480-
@override
2481-
Type visitStaticTearOffConstant(StaticTearOffConstant constant) {
2482-
final Procedure member = constant.target;
2483-
summaryCollector._entryPointsListener
2484-
.addRawCall(new DirectSelector(member));
2485-
summaryCollector._entryPointsListener.recordTearOff(member);
2486-
return _getStaticType(constant);
2487-
}
2488-
2489-
@override
2490-
Type visitConstructorTearOffConstant(ConstructorTearOffConstant constant) {
2479+
Type _visitTearOffConstant(TearOffConstant constant) {
24912480
final Member member = constant.target;
24922481
summaryCollector._entryPointsListener
24932482
.addRawCall(new DirectSelector(member));
@@ -2499,6 +2488,19 @@ class ConstantAllocationCollector extends ConstantVisitor<Type> {
24992488
return _getStaticType(constant);
25002489
}
25012490

2491+
@override
2492+
Type visitStaticTearOffConstant(StaticTearOffConstant constant) =>
2493+
_visitTearOffConstant(constant);
2494+
2495+
@override
2496+
Type visitConstructorTearOffConstant(ConstructorTearOffConstant constant) =>
2497+
_visitTearOffConstant(constant);
2498+
2499+
@override
2500+
Type visitRedirectingFactoryTearOffConstant(
2501+
RedirectingFactoryTearOffConstant constant) =>
2502+
_visitTearOffConstant(constant);
2503+
25022504
@override
25032505
Type visitInstantiationConstant(InstantiationConstant constant) {
25042506
constant.tearOffConstant.accept(this);

pkg/vm/lib/transformations/type_flow/transformer.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,12 @@ class _TreeShakerConstantVisitor extends ConstantVisitor<Null> {
19431943
shaker.addUsedMember(constant.target);
19441944
}
19451945

1946+
@override
1947+
visitRedirectingFactoryTearOffConstant(
1948+
RedirectingFactoryTearOffConstant constant) {
1949+
shaker.addUsedMember(constant.target);
1950+
}
1951+
19461952
@override
19471953
visitInstantiationConstant(InstantiationConstant constant) {
19481954
analyzeConstant(constant.tearOffConstant);

pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter57213.dart.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class A extends core::Object {
77
constructor •() → self::A
88
: super core::Object::•()
99
;
10+
@#C3
11+
static factory foo() → self::A
12+
return new self::B::•();
1013
}
1114
class B extends self::A {
1215
constructor •() → self::B
@@ -17,11 +20,16 @@ abstract class C extends core::Object {
1720
constructor •() → self::C
1821
: super core::Object::•()
1922
;
23+
@#C3
24+
static factory bar() → self::C
25+
return [@vm.inferred-type.metadata=#lib::E] self::D::baz();
2026
}
2127
abstract class D extends self::C {
2228
constructor •() → self::D
2329
: super self::C::•()
2430
;
31+
static factory baz() → self::D
32+
return new self::E::•();
2533
}
2634
class E extends self::D {
2735
constructor •() → self::E

runtime/tests/vm/dart/redirection_type_shuffling_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import "package:expect/expect.dart";
77

88
class G<A extends int, B extends String> {
99
G();
10-
factory G.swap() = G<B,A>; //# 00: compile-time error
11-
factory G.retain() = G<A,B>;
10+
factory G.swap() = G<B, A>; //# 00: compile-time error
11+
factory G.retain() = G<A, B>;
1212
}
1313

1414
main() {
1515
ClassMirror cm = reflect(new G<int, String>()).type;
1616

17-
Expect.isTrue(cm.newInstance(#retain, []).reflectee is G<int,String>);
17+
Expect.isTrue(cm.newInstance(#retain, []).reflectee is G<int, String>);
1818

19-
Expect.isTrue(cm.newInstance(#swap, []).reflectee is G<String,int>); //# 00: dynamic type error
19+
Expect.isTrue(cm.newInstance(#swap, []).reflectee is G<String, int>); //# 00: continued
2020
}

runtime/tests/vm/dart_2/redirection_type_shuffling_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import "package:expect/expect.dart";
99

1010
class G<A extends int, B extends String> {
1111
G();
12-
factory G.swap() = G<B,A>; //# 00: compile-time error
13-
factory G.retain() = G<A,B>;
12+
factory G.swap() = G<B, A>; //# 00: compile-time error
13+
factory G.retain() = G<A, B>;
1414
}
1515

1616
main() {
1717
ClassMirror cm = reflect(new G<int, String>()).type;
1818

19-
Expect.isTrue(cm.newInstance(#retain, []).reflectee is G<int,String>);
19+
Expect.isTrue(cm.newInstance(#retain, []).reflectee is G<int, String>);
2020

21-
Expect.isTrue(cm.newInstance(#swap, []).reflectee is G<String,int>); //# 00: dynamic type error
21+
Expect.isTrue(cm.newInstance(#swap, []).reflectee is G<String, int>); //# 00: continued
2222
}

runtime/tests/vm/vm.status

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,11 @@ dart_2/regress_40753_test: Skip # This test crashes on the bot, but not locally,
7171
dart_2/trigger_gc_in_native_test: Skip # This test crashes on the bot, but not locally, and infrastructure repeatly fails to locate its coredump.
7272

7373
[ $compiler == app_jitk ]
74-
dart/redirection_type_shuffling_test/none: RuntimeError
7574
dart/snapshot_version_test: RuntimeError
76-
dart_2/redirection_type_shuffling_test/none: RuntimeError
7775
dart_2/snapshot_version_test: RuntimeError
7876

7977
[ $compiler == dartk ]
80-
cc/DartAPI_New: Fail # Issue #33041
8178
cc/IsolateReload_LibraryLookup: Fail, Crash # Issue 32190
82-
dart/redirection_type_shuffling_test/00: RuntimeError, Pass
83-
dart/redirection_type_shuffling_test/none: RuntimeError
84-
dart_2/redirection_type_shuffling_test/00: RuntimeError, Pass
85-
dart_2/redirection_type_shuffling_test/none: RuntimeError
8679

8780
[ $compiler != dartk ]
8881
cc/IsolateReload_KernelIncrementalCompile: SkipByDesign
@@ -100,10 +93,12 @@ dart_2/isolates/reload_*: SkipByDesign # These tests only run on normal JIT.
10093
[ $compiler == dartkp ]
10194
dart/causal_stacks/async_throws_stack_no_causal_non_symbolic_test: SkipByDesign # --no-lazy... does nothing on precompiler.
10295
dart/causal_stacks/async_throws_stack_no_causal_test: SkipByDesign # --no-lazy... does nothing on precompiler.
96+
dart/redirection_type_shuffling_test: SkipByDesign # Uses dart:mirrors.
10397
dart/scavenger_abort_test: SkipSlow
10498
dart/v8_snapshot_profile_writer_test: Pass, Slow # Can be slow due to re-invoking the precompiler.
10599
dart_2/causal_stacks/async_throws_stack_no_causal_non_symbolic_test: SkipByDesign # --no-lazy... does nothing on precompiler.
106100
dart_2/causal_stacks/async_throws_stack_no_causal_test: SkipByDesign # --no-lazy... does nothing on precompiler.
101+
dart_2/redirection_type_shuffling_test: SkipByDesign # Uses dart:mirrors.
107102
dart_2/scavenger_abort_test: SkipSlow
108103
dart_2/v8_snapshot_profile_writer_test: Pass, Slow # Can be slow due to re-invoking the precompiler.
109104

@@ -141,9 +136,7 @@ cc/CoreSnapshotSize: SkipByDesign # Imports dart:mirrors
141136
cc/CreateMirrorSystem: SkipByDesign # Imports dart:mirrors
142137
cc/StandaloneSnapshotSize: SkipByDesign # Imports dart:mirrors
143138
dart/gen_snapshot_include_resolved_urls_test: SkipByDesign # Script URLs not included in product gen_snapshot
144-
dart/redirection_type_shuffling_test: SkipByDesign # Imports dart:mirrors
145139
dart_2/gen_snapshot_include_resolved_urls_test: SkipByDesign # Script URLs not included in product gen_snapshot
146-
dart_2/redirection_type_shuffling_test: SkipByDesign # Imports dart:mirrors
147140

148141
[ $nnbd == legacy ]
149142
dart/*: SkipByDesign # Migrated tests are not supposed to run on non-NNBD bots.
@@ -242,10 +235,6 @@ cc/IsolateReload_LibraryLookup: Fail, Crash
242235
[ $compiler == dartk && $system == windows ]
243236
cc/IsolateReload_LibraryLookup: Fail, Crash
244237

245-
[ $compiler == dartk && $checked ]
246-
dart/redirection_type_shuffling_test/00: Pass # Works in --checked mode but not in --strong mode.
247-
dart_2/redirection_type_shuffling_test/00: Pass # Works in --checked mode but not in --strong mode.
248-
249238
[ $compiler == dartk && ($arch == simarm || $arch == simarm64 || $arch == simarm64c) ]
250239
dart/appjit*: SkipSlow # DFE too slow
251240
dart/b162922506_test: SkipSlow # Generates large input file
@@ -287,9 +276,7 @@ dart_2/causal_stacks/async_throws_stack_lazy_non_symbolic_test: Pass, Slow
287276
dart_2/regress_45898_test: Pass, Slow
288277

289278
[ $compiler == dartkp && ($runtime == dart_precompiled || $runtime == vm) ]
290-
dart/redirection_type_shuffling_test: SkipByDesign # Includes dart:mirrors.
291279
dart/spawn_shutdown_test: SkipSlow
292-
dart_2/redirection_type_shuffling_test: SkipByDesign # Includes dart:mirrors.
293280
dart_2/spawn_shutdown_test: SkipSlow
294281

295282
[ $mode == debug && $system == windows ]

runtime/vm/compiler/frontend/constant_reader.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,9 @@ InstancePtr ConstantReader::ReadConstantInternal(intptr_t constant_index) {
345345
type_arguments, function, context, Heap::kOld);
346346
break;
347347
}
348-
case kStaticTearOffConstant: {
349-
const NameIndex index = reader.ReadCanonicalNameReference();
350-
Function& function =
351-
Function::Handle(Z, H.LookupStaticMethodByKernelProcedure(index));
352-
function = function.ImplicitClosureFunction();
353-
instance = function.ImplicitStaticClosure();
354-
break;
355-
}
356-
case kConstructorTearOffConstant: {
348+
case kStaticTearOffConstant:
349+
case kConstructorTearOffConstant:
350+
case kRedirectingFactoryTearOffConstant: {
357351
const NameIndex index = reader.ReadCanonicalNameReference();
358352
Function& function = Function::Handle(Z);
359353
if (H.IsConstructor(index)) {

runtime/vm/kernel_loader.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,8 +1946,7 @@ void KernelLoader::LoadProcedure(const Library& library,
19461946
// additional functions can cause strain on the VM. They are therefore skipped
19471947
// in jit mode and their associated origin function is used instead as
19481948
// interface call target.
1949-
if (procedure_helper.IsRedirectingFactory() ||
1950-
(!FLAG_precompiled_mode && procedure_helper.IsMemberSignature())) {
1949+
if (!FLAG_precompiled_mode && procedure_helper.IsMemberSignature()) {
19511950
helper_.SetOffset(procedure_end);
19521951
return;
19531952
}

0 commit comments

Comments
 (0)