-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/compiler] Fix TypeTestingStub -> SubtypeTestCache fallback code i…
…f dst_type = TypeParameter If the dst_type of an AssertAssignable is a type parameter, the AssertAssignable implementation will load the value of the type parameter using the (instantiator or function) type arguments. It will then call the type testing stub (TTS) of that type. If the TTS is not exhaustive (e.g. because `T = X<..>` wher `X` is implemented), it can fall back to the slower SubTypeTestCache implementation. Right now the STC fallback will get the loaded value of the type parameter for `dst_type` instead of the type parameter. Doing so is incorrect. => This CL ensures we preserve dst_type = TypeParameter for the STC fallback. Issue #39716 Change-Id: Idea2405efbdc01c031ee68dbb345820e721533eb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127640 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Régis Crelier <regis@google.com>
- Loading branch information
1 parent
1aeff32
commit 20ec71d
Showing
13 changed files
with
79 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2019, 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. | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
main() { | ||
// Ensure all classes are used. | ||
final l = <dynamic>[Base(), A<int>(), B<int>(), I<int>()]; | ||
print(l); | ||
|
||
// Call `add(T)` with `T = A<int/String>` (the VM will not generate an | ||
// optimized TTS for `A<int>` because there's two classes implementing | ||
// `A`, both have type argument vector at a different offset, so it wouldn't | ||
// know where to load it from) | ||
|
||
// Populate the SubtypeTestCache with successfull `add(I<String>())`. | ||
final x = <dynamic>[<A<String>>[]]; | ||
x.single.add(I<String>()); | ||
|
||
// Ensure type check fails if list type is now `A<int>`. | ||
final y = <dynamic>[<A<int>>[]]; | ||
String exception = ''; | ||
try { | ||
y.single.add(I<String>()); | ||
} catch (e) { | ||
exception = e.toString(); | ||
} | ||
print(exception); | ||
Expect.isTrue(exception.contains('is not a subtype of')); | ||
} | ||
|
||
// Ensure depth-first preorder cid numbering will have the cid for [A] in the | ||
// middle and ensure type argument vector will be second field. | ||
class Base { | ||
final int baseField = int.parse('1'); | ||
} | ||
|
||
class A<T> extends Base { | ||
T foo(T arg) => arg; | ||
} | ||
|
||
class B<T> extends A<T> {} | ||
|
||
// Make another implementation of A<T> where type argument vector is first | ||
// field. | ||
class I<T> implements A<T> { | ||
int get baseField => int.parse('2'); | ||
T foo(T arg) => arg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters