add deopt logging to tail call transformer

This commit is contained in:
Sebastian McKenzie
2015-02-11 15:59:15 +11:00
parent a4932e0e0f
commit 85d33536e0
2 changed files with 23 additions and 9 deletions

View File

@@ -328,6 +328,10 @@ File.prototype.addHelper = function (name) {
}
};
File.prototype.logDeopt = function () {
// todo, (node, msg)
};
File.prototype.errorWithNode = function (node, msg, Error) {
Error = Error || SyntaxError;

View File

@@ -1,10 +1,11 @@
"use strict";
var util = require("../../../util");
var t = require("../../../types");
var map = require("lodash/collection/map");
var flatten = require("lodash/array/flatten");
var reduceRight = require("lodash/collection/reduceRight");
var messages = require("../../../messages");
var flatten = require("lodash/array/flatten");
var util = require("../../../util");
var map = require("lodash/collection/map");
var t = require("../../../types");
function returnBlock(expr) {
return t.blockStatement([t.returnStatement(expr)]);
@@ -60,6 +61,13 @@ TailCallTransformer.prototype.getParams = function () {
return this.params = params;
};
TailCallTransformer.prototype.hasDeopt = function () {
// check if the ownerId has been reassigned, if it has then it's not safe to
// perform optimisations
var ownerIdInfo = this.scope.getBindingInfo(this.ownerId.name);
return ownerIdInfo && !ownerIdInfo.reassigned;
};
TailCallTransformer.prototype.run = function () {
var scope = this.scope;
var node = this.node;
@@ -69,16 +77,16 @@ TailCallTransformer.prototype.run = function () {
var ownerId = this.ownerId;
if (!ownerId) return;
// check if the ownerId has been reassigned, if it has then it's not safe to
// perform optimisations
var ownerIdInfo = this.scope.getBindingInfo(ownerId.name);
if (!ownerIdInfo || ownerIdInfo.reassigned) return;
// traverse the function and look for tail recursion
scope.traverse(node, firstPass, this);
if (!this.hasTailRecursion) return;
if (this.hasDeopt()) {
this.file.logDeopt(node, messages.get("tailCallReassignmentDeopt"));
return;
}
//
scope.traverse(node, secondPass, this);
@@ -228,6 +236,8 @@ TailCallTransformer.prototype.subTransformCallExpression = function (node) {
this.hasTailRecursion = true;
if (this.hasDeopt()) return;
var body = [];
if (!t.isThisExpression(thisBinding)) {