Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Issue 10280007: Check upper bounds of type arguments when allocating objects of a generic type (Closed)

Created:
8 years, 7 months ago by regis
Modified:
8 years, 7 months ago
Reviewers:
srdjan
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Check upper bounds of type arguments when allocating objects of a generic type at run time when they cannot be checked at compile time. Committed: https://code.google.com/p/dart/source/detail?r=7211

Patch Set 1 #

Total comments: 10

Patch Set 2 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+297 lines, -186 lines) Patch
D runtime/tests/vm/src/GenericTest.dart View 1 1 chunk +0 lines, -85 lines 0 comments Download
M runtime/vm/code_generator.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M runtime/vm/code_generator.cc View 1 1 chunk +72 lines, -0 lines 0 comments Download
M runtime/vm/code_generator_ia32.cc View 1 9 chunks +50 lines, -29 lines 0 comments Download
M runtime/vm/code_generator_x64.cc View 1 9 chunks +50 lines, -29 lines 0 comments Download
M runtime/vm/flow_graph_builder.cc View 1 2 chunks +36 lines, -4 lines 0 comments Download
M runtime/vm/flow_graph_compiler_x64.cc View 1 8 chunks +36 lines, -24 lines 0 comments Download
M runtime/vm/intermediate_language.h View 1 2 chunks +26 lines, -0 lines 0 comments Download
M runtime/vm/object.cc View 1 3 chunks +20 lines, -5 lines 0 comments Download
M runtime/vm/parser.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M tests/language/generic_test.dart View 1 1 chunk +2 lines, -7 lines 0 comments Download
M tests/language/language.status View 1 1 chunk +1 line, -0 lines 0 comments Download
M tests/language/type_variable_bounds_test.dart View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 3 (0 generated)
regis
8 years, 7 months ago (2012-05-01 23:15:47 UTC) #1
srdjan
LGTM (you can explain to me in person the one point that I do not ...
8 years, 7 months ago (2012-05-01 23:30:51 UTC) #2
regis
8 years, 7 months ago (2012-05-02 01:34:16 UTC) #3
Thanks!

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/tests/vm/src/G...
File runtime/tests/vm/src/GenericTest.dart (left):

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/tests/vm/src/G...
runtime/tests/vm/src/GenericTest.dart:2: // for details. All rights reserved.
Use of this source code is governed by a
On 2012/05/01 23:30:51, srdjan wrote:
> 2012

This test is being deleted. There is an almost identical test now called
generic_test.dart.

The part of this test that was VM specific is not relevant anymore, because the
fields srcType, dstType, and dstName of a TypeError are not set for malformed
type errors and failed bound checks.

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/tests/vm/src/G...
runtime/tests/vm/src/GenericTest.dart:4: // VMOptions=--enable_type_checks
--enable_asserts
On 2012/05/01 23:30:51, srdjan wrote:
> You don't need asserts, do you?

No.

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/tests/vm/src/G...
runtime/tests/vm/src/GenericTest.dart:10: }
On 2012/05/01 23:30:51, srdjan wrote:
> Would it be good to have a similar test in the shared code (just do not test
> details of TypeError)?

We have one.

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/vm/code_genera...
File runtime/vm/code_generator.cc (right):

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/vm/code_genera...
runtime/vm/code_generator.cc:197: // Return value: newly allocated object.
On 2012/05/01 23:30:51, srdjan wrote:
> Can you measure if there is any performance impact of the correct allocation
> with bounds (e.g., running dart2js)

Yes, I will measure (I'll check with you for the procedure), but we do not
really have the choice. Of course, type propagation will help here as well.

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/vm/object.cc
File runtime/vm/object.cc (right):

https://chromiumcodereview.appspot.com/10280007/diff/1/runtime/vm/object.cc#n...
runtime/vm/object.cc:2207: (Index() == other.Index());
On 2012/05/01 23:30:51, srdjan wrote:
> I do not understand this change.

The previous test was too lenient. You can imagine comparing two signatures, one
returning K, the other one returning V, both type parameters. They should
differ.

Previously, we only encountered type parameters when testing signatures,
because, beside uninstantiated function result types and uninstantiated function
parameter types, we only tested instantiated types. With this change, we can
also test uninstantiated types. This is how we decide whether a run time bounds
check is necessary or not. We perform a subtype check of the uninstantiated
bounds and only return true if the test is guaranteed to succeed.
For example, with class A<K, V extends K>, new A<T, T> called from with a class
<T> will never require a run time bounds check, even it T is uninstantiated at
compile time.

I have added a comment.

Powered by Google App Engine
This is Rietveld 408576698