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

Issue 11265020: Minifying renamer for classes, methods and instance variables. (Closed)

Created:
8 years, 2 months ago by erikcorry
Modified:
8 years ago
Reviewers:
floitsch, sra1
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Minifying renamer for classes, methods and instance variables. R=floitsch@google.com BUG= Committed: https://code.google.com/p/dart/source/detail?r=14132

Patch Set 1 #

Total comments: 55
Unified diffs Side-by-side diffs Delta from patch set Stats (+490 lines, -198 lines) Patch
M lib/compiler/implementation/js/printer.dart View 1 chunk +37 lines, -29 lines 4 comments Download
M lib/compiler/implementation/js_backend/backend.dart View 2 chunks +8 lines, -4 lines 0 comments Download
M lib/compiler/implementation/js_backend/emitter.dart View 15 chunks +73 lines, -33 lines 7 comments Download
M lib/compiler/implementation/js_backend/emitter_no_eval.dart View 2 chunks +5 lines, -3 lines 0 comments Download
M lib/compiler/implementation/js_backend/js_backend.dart View 1 chunk +1 line, -0 lines 0 comments Download
A lib/compiler/implementation/js_backend/minify_namer.dart View 1 chunk +95 lines, -0 lines 8 comments Download
M lib/compiler/implementation/js_backend/namer.dart View 13 chunks +126 lines, -64 lines 14 comments Download
M lib/compiler/implementation/lib/js_helper.dart View 1 chunk +3 lines, -0 lines 0 comments Download
M lib/compiler/implementation/lib/native_helper.dart View 4 chunks +32 lines, -9 lines 16 comments Download
M lib/compiler/implementation/ssa/codegen.dart View 1 chunk +1 line, -1 line 2 comments Download
M tests/compiler/dart2js/array_static_intercept_test.dart View 1 chunk +6 lines, -3 lines 2 comments Download
M tests/compiler/dart2js/boolified_operator_test.dart View 2 chunks +5 lines, -5 lines 0 comments Download
M tests/compiler/dart2js/boolify_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M tests/compiler/dart2js/class_codegen_test.dart View 1 chunk +43 lines, -10 lines 2 comments Download
M tests/compiler/dart2js/class_order_test.dart View 3 chunks +5 lines, -6 lines 0 comments Download
M tests/compiler/dart2js/closure_codegen_test.dart View 1 chunk +7 lines, -4 lines 0 comments Download
M tests/compiler/dart2js/constant_folding_test.dart View 1 chunk +3 lines, -2 lines 0 comments Download
M tests/compiler/dart2js/literal_list_test.dart View 1 chunk +3 lines, -3 lines 0 comments Download
M tests/compiler/dart2js/minify_many_locals_test.dart View 1 chunk +3 lines, -0 lines 0 comments Download
M tests/compiler/dart2js/no_constructor_body_test.dart View 1 chunk +3 lines, -2 lines 0 comments Download
M tests/compiler/dart2js/no_duplicate_constructor_body2_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M tests/compiler/dart2js/no_duplicate_constructor_body_test.dart View 1 chunk +3 lines, -1 line 0 comments Download
M tests/compiler/dart2js/rewrite_better_user_test.dart View 1 chunk +2 lines, -3 lines 0 comments Download
M tests/compiler/dart2js/ssa_phi_codegen_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M tests/compiler/dart2js/static_closure_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M tests/compiler/dart2js/type_guard_unuser_test.dart View 1 chunk +3 lines, -2 lines 0 comments Download
M tests/compiler/dart2js/type_inference_test.dart View 1 chunk +4 lines, -2 lines 0 comments Download
M tests/compiler/dart2js/value_range_test.dart View 2 chunks +5 lines, -4 lines 0 comments Download
M tests/compiler/dart2js_extra/to_string_test.dart View 2 chunks +4 lines, -1 line 0 comments Download
M utils/compiler/build_helper.dart View 1 chunk +6 lines, -3 lines 0 comments Download

Messages

Total messages: 6 (0 generated)
erikcorry
8 years, 2 months ago (2012-10-25 08:06:22 UTC) #1
floitsch
initial comments. https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/js/printer.dart File lib/compiler/implementation/js/printer.dart (right): https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/js/printer.dart#newcode988 lib/compiler/implementation/js/printer.dart:988: // since those are the ones we ...
8 years, 2 months ago (2012-10-25 08:42:40 UTC) #2
erikcorry
https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/js/printer.dart File lib/compiler/implementation/js/printer.dart (right): https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/js/printer.dart#newcode988 lib/compiler/implementation/js/printer.dart:988: // since those are the ones we can generate. ...
8 years, 2 months ago (2012-10-25 09:09:28 UTC) #3
floitsch
LGTM. Please talk to the remaining dart2js about the tests before you submit. https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/js/printer.dart File ...
8 years, 1 month ago (2012-10-25 12:58:38 UTC) #4
sra1
https://chromiumcodereview.appspot.com/11265020/diff/1/lib/compiler/implementation/lib/native_helper.dart File lib/compiler/implementation/lib/native_helper.dart (right): https://chromiumcodereview.appspot.com/11265020/diff/1/lib/compiler/implementation/lib/native_helper.dart#newcode192 lib/compiler/implementation/lib/native_helper.dart:192: String className = getTypeNameOf(obj); Don't call this 'className', it ...
8 years, 1 month ago (2012-10-26 06:41:45 UTC) #5
erikcorry
8 years ago (2012-12-06 09:38:07 UTC) #6
Message was sent while issue was closed.
https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
File lib/compiler/implementation/js/printer.dart (right):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js/printer.dart:990: return name == "I";  //
Minified version of Isolate.
On 2012/10/25 12:58:38, floitsch wrote:
> Is there a way to get this set from the namer?

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
File lib/compiler/implementation/js_backend/emitter.dart (right):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/emitter.dart:111: String
needsGetter(String variable) => '($variable & 3) > 0';
On 2012/10/25 12:58:38, floitsch wrote:
> needsGetterCode or something to indicate that this is just the code to do this
> check dynamically.
> other possibility: needsGetterExpression

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/emitter.dart:842:
buffer.addCharCode(GETTER_SETTER_CODE + flag);
On 2012/10/25 12:58:38, floitsch wrote:
> I would prefer "|" to indicate that this is a bit-operation.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
File lib/compiler/implementation/js_backend/minify_namer.dart (right):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/minify_namer.dart:13: bool get minify =>
true;
On 2012/10/25 12:58:38, floitsch wrote:
> I think I prefer "shouldMinify" or "isMinifying", but I agree that there is no
> good name.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/minify_namer.dart:41: // Try other
n-character names based on the hash.
On 2012/10/25 12:58:38, floitsch wrote:
> Give a small description maybe mentioning that:
> - we try 1 to 3 character identifiers.
> - we use the hash to create n characters.
> - if we don't succeed we try again with a slightly perturbed hash.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/minify_namer.dart:45: var codes =
<int>[_letterNumber(h)];
On 2012/10/25 12:58:38, floitsch wrote:
> It probably doesn't matter, but you could allocate the array outside the loop
> and just clear it at the beginning of the loop.

I tried it and it got uglier, so I'll leave it as it was for now.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/minify_namer.dart:46: var divisor = 26;
On 2012/10/25 12:58:38, floitsch wrote:
> 62.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
File lib/compiler/implementation/js_backend/namer.dart (right):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:47: usedGlobalNames.add('p'); 
// ISOLATE_PROPERTIES.
On 2012/10/25 12:58:38, floitsch wrote:
> The ISOLATE_PROPERTIES for the non-minifying namer is not "p".
> Iirc the isolate-properties live on the Isolate-function itself and not in its
> prototype. They should not be able to clash with global names.

Removed this line.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:69: longName =
stringConstant.value.slowToString();
On 2012/10/25 12:58:38, floitsch wrote:
> Are you sure this can happen? Strings are normally inlined at their use-sites.
> Still a good idea.

This can happen.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:71: longName = "C";
On 2012/10/25 12:58:38, floitsch wrote:
> not for this CL, but this basically means that we run out of short (3-char)
> names for constants if there are more than 30, right?

Yes, after the first 30 non-string constants we start naming them U1, U2, U3,
etc.  If we get better at inlining them this won't matter so much.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:83: return
On 2012/10/25 12:58:38, floitsch wrote:
> one line?

nope.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:110: String private;
On 2012/10/25 12:58:38, floitsch wrote:
> s/private/result

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/j...
lib/compiler/implementation/js_backend/namer.dart:119: if (identical(owner, lib)
&&
On 2012/10/25 12:58:38, floitsch wrote:
> owner == lib

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
File lib/compiler/implementation/lib/native_helper.dart (left):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:251: if (f != null &&
JS('bool', '!!#.methods', f)) {
On 2012/10/25 12:58:38, floitsch wrote:
> While I agree that it probably works, this is "cheating". It's just two
> characters...
> I would prefer this to be eventually parsed into JS where it then gets rid of
> the !!.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
File lib/compiler/implementation/lib/native_helper.dart (right):

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:192: String className =
getTypeNameOf(obj);
On 2012/10/26 06:41:45, sra1 wrote:
> Don't call this 'className', it will lead to confusion.
> It is not the name of the class.
> E.g. the dart:html class '_ButtonElement' has the tag 'HTMLButtonElement'
> 
> It is a token or tag that is hopefully unique to the underlying JavsScript  or
> DOM object that can be used to look up the method (and hopefully cache the
> method on the prototype to avoid repeated lookups).
> 
> getTypeNameOf is misnamed.  It should be call getTypeTag.
> I does not return the name of any Dart type.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:197: // Look up the
inheritance chain, getting the class names and using them
On 2012/10/25 12:58:38, floitsch wrote:
> thanks for the comments. makes it much easier to understand.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:197: // Look up the
inheritance chain, getting the class names and using them
On 2012/10/26 06:41:45, sra1 wrote:
> It is not really a chain, since it is inverted (parent -> children).  It is
> possible to use the current structure for multiple inheritance provided all
> classes agree on a order.  This might be useful for implementing mixins
without
> huge code duplication.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:248: JS('var', 'void 0');
On 2012/10/25 12:58:38, floitsch wrote:
> null

Done.  I just used dart null rather than JS null.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:269: if (f != null &&
JS('bool', '#.methods', f)) {
On 2012/10/26 06:41:45, sra1 wrote:
> I agree the !! is safer.  In the conditional context V8 should eliminate it
> completely.  It is possible that checked mode might assert the result is
> boolean.

Done.

https://codereview.chromium.org/11265020/diff/1/lib/compiler/implementation/l...
lib/compiler/implementation/lib/native_helper.dart:283: JS('void', '#[#] = #',
methods, getTypeNameOf(const Object()), dartMethod);
On 2012/10/26 06:41:45, sra1 wrote:
> Do we have any reason to believe getTypeNameOf(const Object()) is not
'Object'?

No.

https://codereview.chromium.org/11265020/diff/1/tests/compiler/dart2js/array_...
File tests/compiler/dart2js/array_static_intercept_test.dart (right):

https://codereview.chromium.org/11265020/diff/1/tests/compiler/dart2js/array_...
tests/compiler/dart2js/array_static_intercept_test.dart:17:
Expect.isTrue(generated.contains(r'.add$1(') ||
On 2012/10/25 12:58:38, floitsch wrote:
> wouldn't it make sense to copy the test and invoke a minifying compiler
instead?

Yes.

Powered by Google App Engine
This is Rietveld 408576698