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

Issue 11364213: Rename classes, methods and fields when minifying (Closed)

Created:
8 years, 1 month ago by erikcorry
Modified:
8 years, 1 month ago
Reviewers:
floitsch, ngeoffray
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Rename classes, methods and fields when minifying This is a retry of a change that was reverted due to test failures. The difference to last time you saw this is: diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart index 9de758e..19fb966 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart @@ -689,9 +689,9 @@ class JavaScriptBackend extends Backend { } static Namer determineNamer(Compiler compiler) { - // TODO(erikcorry): Use the MinifyNamer depending on - // compiler.enableMinification. - return new Namer(compiler); + return compiler.enableMinification ? + new MinifyNamer(compiler) : + new Namer(compiler); } Element get cyclicThrowHelper { diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart index 9056858..9485bc1 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart @@ -795,7 +795,7 @@ function(prototype, staticName, fieldName, getterName, lazyValue) { additionalArgument = ", '${namer.operatorIs(type.element)}'"; } String setterName = - namer.setterName(member.getLibrary(), new SourceString(accessorName)); + namer.publicSetterName(new SourceString(accessorName)); buffer.add("$setterName: function(v) { " "this.$fieldName = $helperName(v$additionalArgument); }"); } @@ -1348,11 +1348,14 @@ $classesCollector.$mangledName = {'': } String internalName = namer.instanceMethodInvocationName( selector.library, new SourceString(methodName), selector); + Element createInvocationMirror = + compiler.findHelper(const SourceString('createInvocationMirror')); CodeBuffer buffer = new CodeBuffer(); buffer.add('function($args) {\n'); buffer.add(' return this.$noSuchMethodName(' - '\$.createInvocationMirror("$methodName", "$internalName",' - ' $type, [$args], [$argNames]));\n'); + '${namer.isolateAccess(createInvocationMirror)}(' + '"$methodName", "$internalName",' + '$type, [$args], [$argNames]));\n'); buffer.add(' }'); return buffer; } diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart index 4ca0554..cd0529f 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart @@ -16,7 +16,14 @@ class MinifyNamer extends Namer { const ALPHANUMERIC_CHARACTERS = 62; // a-zA-Z0-9. String getFreshName(String proposedName, Set<String> usedNames) { - var freshName = _getUnusedName(proposedName, usedNames); + var freshName; + if (proposedName.startsWith(r'call$')) { + // We don't mangle the closure invoking function name because it is + // generated in applyFunction. + freshName = proposedName; + } else { + freshName = _getUnusedName(proposedName, usedNames); + } usedNames.add(freshName); return freshName; } diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart index c8522a0..9f5b65d 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart @@ -211,6 +211,13 @@ class Namer { return 'get\$$fieldName'; } + String publicSetterName(SourceString name) { + // We dynamically create setter from the field-name. The setter name must + // therefore be derived from the instance field-name. + String fieldName = name.slowToString(); + return 'set\$$fieldName'; + } + String getMappedGlobalName(String proposedName) { var newName = globalNameMap[proposedName]; if (newName == null) { diff --git a/sdk/lib/_internal/compiler/implementation/lib/isolate_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/isolate_patch.dart index 1c9d772..1d50aa4 100644 --- a/sdk/lib/_internal/compiler/implementation/lib/isolate_patch.dart +++ b/sdk/lib/_internal/compiler/implementation/lib/isolate_patch.dart @@ -188,9 +188,9 @@ class _Manager { } void _nativeDetectEnvironment() { - JS("void", r"#.isWorker = $isWorker", this); - JS("void", r"#.supportsWorkers = $supportsWorkers", this); - JS("void", r"#.fromCommandLine = typeof(window) == 'undefined'", this); + JS("void", r"# = $isWorker", isWorker); + JS("void", r"# = $supportsWorkers", supportsWorkers); + JS("void", r"# = typeof(window) == 'undefined'", fromCommandLine); } void _nativeInitWorkerMessageHandler() { R=floitsch@google.com BUG= Committed: https://code.google.com/p/dart/source/detail?r=15005

Patch Set 1 #

Total comments: 14

Messages

Total messages: 4 (0 generated)
erikcorry
8 years, 1 month ago (2012-11-13 10:10:07 UTC) #1
ngeoffray
DBC https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart File sdk/lib/_internal/compiler/implementation/lib/native_helper.dart (right): https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart#newcode119 sdk/lib/_internal/compiler/implementation/lib/native_helper.dart:119: propertyGet(var object, String property) { Should you remove ...
8 years, 1 month ago (2012-11-13 10:51:49 UTC) #2
floitsch
LGTM. https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart File sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart (right): https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart#newcode18 sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart:18: String getFreshName(String proposedName, Set<String> usedNames) { Add comment ...
8 years, 1 month ago (2012-11-13 13:35:01 UTC) #3
erikcorry
8 years, 1 month ago (2012-11-16 10:08:30 UTC) #4
https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
File sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart
(right):

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart:18:
String getFreshName(String proposedName, Set<String> usedNames) {
On 2012/11/13 13:35:02, floitsch wrote:
> Add comment that the proposedName does not need to be a valid identifier
> (neither JavaScript nor Dart). This is currently used by the constantName
> function.

Done.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart:20: if
(proposedName.startsWith(r'call$')) {
On 2012/11/13 13:35:02, floitsch wrote:
> This won't work if we mangle constantNames. If the constant holds a string we
> use the string as proposedName. const x = r"call$ foo" would use the string as
> identifier.

Good catch.  I moved the special handling of the call$ names so that it happens
earlier and is not affected by this issue.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
File sdk/lib/_internal/compiler/implementation/js_backend/namer.dart (right):

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/js_backend/namer.dart:71: longName =
stringConstant.value.slowToString();
On 2012/11/13 13:35:02, floitsch wrote:
> add comment that the minifier doesn't require the longName to be a valid
> identifier.

Done.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/js_backend/namer.dart:86:
instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, selector);
On 2012/11/13 13:35:02, floitsch wrote:
> one line?

Doesn't fit.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/js_backend/namer.dart:147: String
methodName =
On 2012/11/13 13:35:02, floitsch wrote:
> one line?

Doesn't fit.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
File sdk/lib/_internal/compiler/implementation/lib/native_helper.dart (right):

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/lib/native_helper.dart:119:
propertyGet(var object, String property) {
On 2012/11/13 10:51:49, ngeoffray wrote:
> Should you remove this helper?

Done.

https://codereview.chromium.org/11364213/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/lib/native_helper.dart:300: JS('void',
'#["Object"] = #', methods, dartMethod);
On 2012/11/13 10:51:49, ngeoffray wrote:
> Why this change?

Undone (2nd part).

Powered by Google App Engine
This is Rietveld 408576698