From 85d33536e0f1602971f871800cd0aca156a03a06 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 11 Feb 2015 15:59:15 +1100 Subject: [PATCH] add deopt logging to tail call transformer --- lib/6to5/transformation/file.js | 4 +++ .../transformers/es6/tail-call.js | 28 +++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/6to5/transformation/file.js b/lib/6to5/transformation/file.js index 3c1cec6ff7..d7b496160d 100644 --- a/lib/6to5/transformation/file.js +++ b/lib/6to5/transformation/file.js @@ -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; diff --git a/lib/6to5/transformation/transformers/es6/tail-call.js b/lib/6to5/transformation/transformers/es6/tail-call.js index eb47c8253e..0704275fee 100644 --- a/lib/6to5/transformation/transformers/es6/tail-call.js +++ b/lib/6to5/transformation/transformers/es6/tail-call.js @@ -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)) {