v8/test/mjsunit/compiler/rest-parameters.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.2 KiB
JavaScript
Raw Normal View History

[turbofan] escape analysis supports arguments object and rest elements The new NewUnmappedArgumentsElements node now takes two inputs: - the frame holding the arguments (current frame or arguments adaptor frame) - the length of the suffix of passed arguments to be copied into the backing store These inputs are computed with two new node types: ArgumentsFrame() ArgumentsLength[formal_parameter_count,is_rest_length](Node* arguments_frame) The node type NewRestParameterElements can now be expressed with NewUnmappedArgumentsElements and an appropriate length and is thus not needed anymore. In escape analysis, we lower loads from the length field of NewUnmappedArgumentsElements with its length input and if we find out that no write access to the arguments elements exists, we replace element loads with direct stack access and replace the NewUnmappedArgumentsElements node with a node of the new node type ArgumentsElementsState. This corresponds to an ObjectState node and gets translated into a deoptimizer instruction to allocate the backing store. Together with the already existing deoptimizer support for the actual arguments object/rest parameters, this allows to remove all allocations for arguments objects/rest parameters in this case. In the deoptimizer, we read the actual parameters from the stack while transforming the static deopt info into TranslatedValue objects. If escape analysis cannot remove the backing store allocation, NewUnmappedArgumentsElements gets lo BUG=v8:5726 Review-Url: https://codereview.chromium.org/2692753004 Cr-Commit-Position: refs/heads/master@{#43475}
2017-02-28 11:16:27 +00:00
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
[turbofan] escape analysis supports arguments object and rest elements The new NewUnmappedArgumentsElements node now takes two inputs: - the frame holding the arguments (current frame or arguments adaptor frame) - the length of the suffix of passed arguments to be copied into the backing store These inputs are computed with two new node types: ArgumentsFrame() ArgumentsLength[formal_parameter_count,is_rest_length](Node* arguments_frame) The node type NewRestParameterElements can now be expressed with NewUnmappedArgumentsElements and an appropriate length and is thus not needed anymore. In escape analysis, we lower loads from the length field of NewUnmappedArgumentsElements with its length input and if we find out that no write access to the arguments elements exists, we replace element loads with direct stack access and replace the NewUnmappedArgumentsElements node with a node of the new node type ArgumentsElementsState. This corresponds to an ObjectState node and gets translated into a deoptimizer instruction to allocate the backing store. Together with the already existing deoptimizer support for the actual arguments object/rest parameters, this allows to remove all allocations for arguments objects/rest parameters in this case. In the deoptimizer, we read the actual parameters from the stack while transforming the static deopt info into TranslatedValue objects. If escape analysis cannot remove the backing store allocation, NewUnmappedArgumentsElements gets lo BUG=v8:5726 Review-Url: https://codereview.chromium.org/2692753004 Cr-Commit-Position: refs/heads/master@{#43475}
2017-02-28 11:16:27 +00:00
(function Rest0Params() {
function f(x, y) {
return x+y;
}
function test(...rest) {
return [rest, f.apply(null, rest)];
}
assertEquals(test(), [[], NaN]);
assertEquals(test(1), [[1], NaN])
assertEquals(test(1, 2), [[1,2], 3]);
assertEquals(test(1, 2, 3), [[1,2,3], 3]);
%OptimizeFunctionOnNextCall(test);
assertEquals(test(), [[], NaN]);
assertEquals(test(1), [[1], NaN])
assertEquals(test(1, 2), [[1,2], 3]);
assertEquals(test(1, 2, 3), [[1,2,3], 3]);
})();
(function Rest1Params() {
function f(x, y) {
return x+y
}
function test(a, ...rest) {
return [rest, a, f.apply(null, rest)];
}
assertEquals(test(), [[], undefined, NaN]);
assertEquals(test(1), [[], 1, NaN]);
assertEquals(test(1, 2), [[2], 1, NaN]);
assertEquals(test(1, 2, 3), [[2,3], 1, 5]);
assertEquals(test(1, 2, 3, 4), [[2,3,4], 1, 5]);
%OptimizeFunctionOnNextCall(test);
assertEquals(test(), [[], undefined, NaN]);
assertEquals(test(1), [[], 1, NaN]);
assertEquals(test(1, 2), [[2], 1, NaN]);
assertEquals(test(1, 2, 3), [[2,3], 1, 5]);
assertEquals(test(1, 2, 3, 4), [[2,3,4], 1, 5]);
})();