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

Issue 10232011: Implement simple dynamic type check. (Closed)

Created:
8 years, 8 months ago by karlklose
Modified:
8 years, 7 months ago
Reviewers:
ngeoffray, kasperl
CC:
reviews_dartlang.org, ngeoffray
Visibility:
Public.

Description

Implement simple dynamic type check. The generated code for the test is: (before) $.isTrue(typeof x === 'object' && !!x.is$Hest, (void 0)); $.isFalse(typeof x === 'object' && !!x.is$Hest, (void 0)); (with patch) $.setRuntimeTypeInfo(x, ({X: 'int'})); var t0 = $.getRuntimeTypeInfo(x); $.isTrue(typeof x === 'object' && !!x.is$Hest && typeof t0 === 'object' && t0.X === 'int', (void 0)); var t1 = $.getRuntimeTypeInfo(x); $.isFalse(typeof x === 'object' && !!x.is$Hest && typeof t1 === 'object' && t1.X === 'String', (void 0)); Committed: https://code.google.com/p/dart/source/detail?r=7184

Patch Set 1 #

Patch Set 2 : #

Patch Set 3 : #

Patch Set 4 : Minor edits. #

Total comments: 35
Unified diffs Side-by-side diffs Delta from patch set Stats (+198 lines, -43 lines) Patch
M frog/tests/leg/mock_compiler.dart View 1 2 3 1 chunk +3 lines, -1 line 0 comments Download
M frog/tests/leg/parser_helper.dart View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
A frog/tests/leg_only/src/GenericsIsCheck1Test.dart View 1 chunk +12 lines, -0 lines 7 comments Download
M lib/compiler/implementation/elements/elements.dart View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M lib/compiler/implementation/lib/js_helper.dart View 1 2 3 1 chunk +10 lines, -0 lines 0 comments Download
M lib/compiler/implementation/ssa/builder.dart View 1 2 3 6 chunks +97 lines, -23 lines 14 comments Download
M lib/compiler/implementation/ssa/codegen.dart View 1 2 3 2 chunks +17 lines, -4 lines 2 comments Download
M lib/compiler/implementation/ssa/nodes.dart View 1 2 3 1 chunk +10 lines, -4 lines 8 comments Download
M lib/compiler/implementation/ssa/optimize.dart View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M lib/compiler/implementation/ssa/ssa.dart View 1 2 1 chunk +27 lines, -0 lines 4 comments Download
M lib/compiler/implementation/ssa/tracer.dart View 1 2 1 chunk +1 line, -1 line 0 comments Download
M lib/compiler/implementation/typechecker.dart View 2 chunks +2 lines, -2 lines 0 comments Download
M lib/compiler/implementation/universe.dart View 1 2 2 chunks +3 lines, -1 line 0 comments Download
M tests/co19/co19-leg.status View 1 2 3 chunks +10 lines, -3 lines 0 comments Download
M tests/utils/dummy_compiler_test.dart View 1 2 3 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
karlklose
8 years, 7 months ago (2012-04-30 08:12:52 UTC) #1
kasperl
LGTM, but somehow it feels silly to always have a call to getRuntimeTypeInformation and then ...
8 years, 7 months ago (2012-04-30 08:48:31 UTC) #2
ngeoffray
DBC https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only/src/GenericsIsCheck1Test.dart File frog/tests/leg_only/src/GenericsIsCheck1Test.dart (right): https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only/src/GenericsIsCheck1Test.dart#newcode4 frog/tests/leg_only/src/GenericsIsCheck1Test.dart:4: // Test that parameters keep their names in ...
8 years, 7 months ago (2012-04-30 08:51:12 UTC) #3
ahe
On 2012/04/30 08:48:31, kasperl wrote: > $.isTrue($.is$Hest$int(x)); Unfortunately, that doesn't work in general. The "value" ...
8 years, 7 months ago (2012-04-30 10:45:06 UTC) #4
karlklose
8 years, 7 months ago (2012-05-01 11:20:55 UTC) #5
Thanks for the reviews.

I will leave the inlined checks for now. I will implement checks involving type
variables next and optimize the type checks after that.

https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only...
File frog/tests/leg_only/src/GenericsIsCheck1Test.dart (right):

https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only...
frog/tests/leg_only/src/GenericsIsCheck1Test.dart:1: // Copyright (c) 2012, the
Dart project authors.  Please see the AUTHORS file
On 2012/04/30 08:48:32, kasperl wrote:
> Maybe rename this file? Didn't Siggi change the naming convention for these
> files recently?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only...
frog/tests/leg_only/src/GenericsIsCheck1Test.dart:4: // Test that parameters
keep their names in the output.
Done, removed.

https://chromiumcodereview.appspot.com/10232011/diff/6018/frog/tests/leg_only...
frog/tests/leg_only/src/GenericsIsCheck1Test.dart:10: Expect.isTrue(x is
Hest<int>);
It does not work currently.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
File lib/compiler/implementation/ssa/builder.dart (right):

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:1810:
<HInstruction>[typeInfoGetter, expression]);
On 2012/04/30 08:48:32, kasperl wrote:
> Line too long.

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:1810:
<HInstruction>[typeInfoGetter, expression]);
On 2012/04/30 08:51:12, ngeoffray wrote:
> line too long

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:1821: if
(compiler.universe.rti.hasTypeArguments(type)) {
On 2012/04/30 08:48:32, kasperl wrote:
> Change this check to typeInfo != null?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:2198: HType elementType =
HType.UNKNOWN;
On 2012/04/30 08:48:32, kasperl wrote:
> Factor out the computation of elementType?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:2216: if
(compiler.universe.rti.hasTypeArguments(type)) {
On 2012/04/30 08:48:32, kasperl wrote:
> Factor out the code in this if?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:2299: if
(send.selector.asTypeAnnotation() !== null) {
Changed to is-checks.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/builder.dart:2307:
compiler.internalError("malformed send in new expression");
We use both variants.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
File lib/compiler/implementation/ssa/codegen.dart (right):

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/codegen.dart:1785:
cls.typeParameters.forEach((name, _) {
typeParameters is a Map<SourceString, TypeVariableElement>, so the first
argument to the closure is actually a SourceString.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
File lib/compiler/implementation/ssa/nodes.dart (right):

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/nodes.dart:2092: final Type typeExpression;
This is actually reverting a renaming from an earlier CL.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/nodes.dart:2095:
HIs.withTypeInfo(this.typeExpression, HInstruction expression,
On 2012/04/30 08:51:12, ngeoffray wrote:
> withTypeInfoCall?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/nodes.dart:2096: HInstruction typeInfo, [nullOk
= false])
On 2012/04/30 08:48:32, kasperl wrote:
> Can't we use this.nullOk in the parameter list?

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/nodes.dart:2104: HInstruction get typeInfo() =>
inputs[1];
On 2012/04/30 08:51:12, ngeoffray wrote:
> ditto

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
File lib/compiler/implementation/ssa/ssa.dart (right):

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/ssa.dart:42: return buffer.toString();
On 2012/04/30 08:48:32, kasperl wrote:
> How about adding the { } as part of the return:
> 
>    return "{$buffer}";
> 
> That looks pretty nice to me.

Done.

https://chromiumcodereview.appspot.com/10232011/diff/6018/lib/compiler/implem...
lib/compiler/implementation/ssa/ssa.dart:45: bool hasTypeArguments(Type type) {
On 2012/04/30 08:51:12, ngeoffray wrote:
> Why is that not on the Type class?

It isn't really used elsewhere, so I did not want to pollute Type's interface.

Powered by Google App Engine
This is Rietveld 408576698