DebugContext.TransformLambda and functions

Aug 28, 2009 at 10:37 AM

I've been looking at debugging support in the DLR and noticed that DebugLambdaBuilder stops at nested lambdas, which made me presume that it needs to be called for each lambda individually (correct me if I'm wrong here). So what I have in my outer scope is a lambda.HiddenVariable(typeof(GlobalObect), "$global"), that I use from nested lambdas. The expression compiler seems to be perfectly happy to use variables from outer scope without changes, however when I try to run DebugContext.TransformLambda it fails with:

{"variable '$global' of type 'RemObjects.Script.EcmaScript.GlobalObject' referenced from scope 'main', but it is not defined"}    System.Exception {System.InvalidOperationException}

But if I use the DebugContext.TransformLambda on the outside lambda it generates no function information for any of the nested lambdas. What do I need to do to get debugging working?

Code used:

  fOutside := Utils.Lambda(typeof(Object), 'EcmaScript');
  fOutside.Visible := false;

  var lScopeParam := Expression.Parameter(typeof(Scope), '$scope');
  var lLanguageContextParam := Expression.Parameter(typeof(LanguageContext), '$languagecontext');
  fOutside.AddParameters(lScopeParam, lLanguageContextParam);
  

  fGlobalObject := fOutside.HiddenVariable(typeof(GlobalObject), '$global');

  var lInside := IntParse(aElements);
	if fContext.EmitDebugSymbols then begin
	  if fOptions.GlobalObject.DebugCtx = nil then 
  	  fOptions.GlobalObject.DebugCtx := Microsoft.Scripting.Debugging.CompilerServices.DebugContext.CreateInstance();
		lInside := fOptions.GlobalObject.DebugCtx.TransformLambda(lInside);
  end;
   //new RuntimeScope(lang, scope, self)
  fOutside.Body := 
  Expression.Block(
    Expression.Assign(fGlobalObject, Expression.Constant(fGlobalObjectValue)),
    Expression.Call(fGlobalObject, fGlobalObject.Type.GetMethod('SetScope'), lScopeParam), 
  Expression.Invoke(lInside, 
    fGlobalObject,
    Expression.NewArrayInit(typeof(object), [])));
  result := foutside.MakeLambda;

 

 

Callstack for exception:

Microsoft.Linq.Expressions.Compiler.VariableBinder.Reference(Microsoft.Linq.Expressions.ParameterExpression node = {$global}, Microsoft.Linq.Expressions.Compiler.VariableStorageKind storage = Hoisted) Line 230
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitParameter(Microsoft.Linq.Expressions.ParameterExpression node = {$global}) Line 176 + 0x16 bytes
Microsoft.Linq.Expressions.ParameterExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 129 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {$global}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.VisitArguments(Microsoft.Linq.Expressions.IArgumentProvider nodes = {Call writeln($global, "test")}) Line 101 + 0x1b bytes
Microsoft.Linq.Expressions.ExpressionVisitor.VisitDynamic(Microsoft.Linq.Expressions.DynamicExpression node = {Call writeln($global, "test")}) Line 288 + 0xf bytes
Microsoft.Linq.Expressions.DynamicExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 147 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {Call writeln($global, "test")}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.VisitBinary(Microsoft.Linq.Expressions.BinaryExpression node = {(Param_0 = Call writeln($global, "test"))}) Line 206 + 0xf2 bytes
Microsoft.Linq.Expressions.BinaryExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 342 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {(Param_0 = Call writeln($global, "test"))}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 4) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 3) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 4) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitLambda<Microsoft.Scripting.Runtime.GeneratorNext<object>>(Microsoft.Linq.Expressions.Expression<Microsoft.Scripting.Runtime.GeneratorNext<object>> node = {(ref state, ref current) => {var $gotoRouter;var Param_0; ... }}) Line 86 + 0x3c bytes
Microsoft.Linq.Expressions.Expression<Microsoft.Scripting.Runtime.GeneratorNext<object>>.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 231 + 0xb9 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {(ref state, ref current) => {var $gotoRouter;var Param_0; ... }}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = {var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }) Line 115 + 0x42 bytes
Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.VisitArguments(Microsoft.Linq.Expressions.IArgumentProvider nodes = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 101 + 0x1b bytes
Microsoft.Linq.Expressions.ExpressionVisitor.VisitMethodCall(Microsoft.Linq.Expressions.MethodCallExpression node = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 423 + 0x15 bytes
Microsoft.Linq.Expressions.MethodCallExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 121 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitLambda<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>>(Microsoft.Linq.Expressions.Expression<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>> node = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 86 + 0x3c bytes
Microsoft.Linq.Expressions.Expression<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>>.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 231 + 0xb9 bytes
Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 65 + 0x18 bytes
Microsoft.Linq.Expressions.Compiler.VariableBinder.Bind(Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 48 + 0x15 bytes
Microsoft.Linq.Expressions.Compiler.LambdaCompiler.AnalyzeLambda(ref Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 253 + 0xd bytes
Microsoft.Linq.Expressions.Compiler.LambdaCompiler.Compile(Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}, Microsoft.Runtime.CompilerServices.DebugInfoGenerator debugInfoGenerator = null) Line 212 + 0xa bytes
Microsoft.Linq.Expressions.LambdaExpression.Compile() Line 138 + 0xc bytes
Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.CreateFunctionInfo(Microsoft.Linq.Expressions.LambdaExpression generatorFactoryLambda = {($frame, this, args) => [Microsoft.Scripting.Ast.GeneratorExpression]}) Line 391 + 0x28 bytes
Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.TransformLambda(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}) Line 179 + 0x10 bytes
Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.Transform(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}) Line 118 + 0x15 bytes
Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.CompilerServices.DebugContext.TransformLambda(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}, Microsoft.Scripting.Debugging.CompilerServices.DebugLambdaInfo lambdaInfo = {Microsoft.Scripting.Debugging.CompilerServices.DebugLambdaInfo}) Line 71 + 0x37 bytes
RemObjects.Script.dll!RemObjects.Script.EcmaScript.EcmaScriptCompiler.Parse(RemObjects.Script.EcmaScript.Internal.ProgramElement aElements = {RemObjects.Script.EcmaScript.Internal.ProgramElement}) Line 373 + 0x45 bytes    Unknown

     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.Reference(Microsoft.Linq.Expressions.ParameterExpression node = {$global}, Microsoft.Linq.Expressions.Compiler.VariableStorageKind storage = Hoisted) Line 230    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitParameter(Microsoft.Linq.Expressions.ParameterExpression node = {$global}) Line 176 + 0x16 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ParameterExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 129 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {$global}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.VisitArguments(Microsoft.Linq.Expressions.IArgumentProvider nodes = {Call writeln($global, "test")}) Line 101 + 0x1b bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.VisitDynamic(Microsoft.Linq.Expressions.DynamicExpression node = {Call writeln($global, "test")}) Line 288 + 0xf bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.DynamicExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 147 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {Call writeln($global, "test")}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.VisitBinary(Microsoft.Linq.Expressions.BinaryExpression node = {(Param_0 = Call writeln($global, "test"))}) Line 206 + 0xf2 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BinaryExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 342 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {(Param_0 = Call writeln($global, "test"))}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 4) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 3) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 2) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = { ... }) Line 111 + 0x39 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = { ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 4) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitLambda<Microsoft.Scripting.Runtime.GeneratorNext<object>>(Microsoft.Linq.Expressions.Expression<Microsoft.Scripting.Runtime.GeneratorNext<object>> node = {(ref state, ref current) => {var $gotoRouter;var Param_0; ... }}) Line 86 + 0x3c bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Expression<Microsoft.Scripting.Runtime.GeneratorNext<object>>.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 231 + 0xb9 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {(ref state, ref current) => {var $gotoRouter;var Param_0; ... }}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitBlock(Microsoft.Linq.Expressions.BlockExpression node = {var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }) Line 115 + 0x42 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.BlockExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 77 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.VisitArguments(Microsoft.Linq.Expressions.IArgumentProvider nodes = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 101 + 0x1b bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.VisitMethodCall(Microsoft.Linq.Expressions.MethodCallExpression node = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 423 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.MethodCallExpression.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 121 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Linq.Expressions.Expression> nodes = Count = 1) Line 79 + 0x43 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitLambda<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>>(Microsoft.Linq.Expressions.Expression<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>> node = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 86 + 0x3c bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Expression<Microsoft.Func<Microsoft.Scripting.Debugging.DebugFrame,object,object[],System.Collections.IEnumerator>>.Accept(Microsoft.Linq.Expressions.ExpressionVisitor visitor = {Microsoft.Linq.Expressions.Compiler.VariableBinder}) Line 231 + 0xb9 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.ExpressionVisitor.Visit(Microsoft.Linq.Expressions.Expression node = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 65 + 0x18 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.VariableBinder.Bind(Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 48 + 0x15 bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.LambdaCompiler.AnalyzeLambda(ref Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}) Line 253 + 0xd bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.Compiler.LambdaCompiler.Compile(Microsoft.Linq.Expressions.LambdaExpression lambda = {($frame, this, args) => MakeGenerator({var $caughtException;var $retVal;var parameters;var Param_0;var generatorTemp0; ... }, new [] {2147483647, 0, 2147483647})}, Microsoft.Runtime.CompilerServices.DebugInfoGenerator debugInfoGenerator = null) Line 212 + 0xa bytes    C#
     Microsoft.Scripting.Core.dll!Microsoft.Linq.Expressions.LambdaExpression.Compile() Line 138 + 0xc bytes    C#
     Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.CreateFunctionInfo(Microsoft.Linq.Expressions.LambdaExpression generatorFactoryLambda = {($frame, this, args) => [Microsoft.Scripting.Ast.GeneratorExpression]}) Line 391 + 0x28 bytes    C#
     Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.TransformLambda(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}) Line 179 + 0x10 bytes    C#
     Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.DebuggableLambdaBuilder.Transform(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}) Line 118 + 0x15 bytes    C#
     Microsoft.Scripting.Debugging.dll!Microsoft.Scripting.Debugging.CompilerServices.DebugContext.TransformLambda(Microsoft.Linq.Expressions.LambdaExpression lambda = {(this, args) => {var parameters; ... }}, Microsoft.Scripting.Debugging.CompilerServices.DebugLambdaInfo lambdaInfo = {Microsoft.Scripting.Debugging.CompilerServices.DebugLambdaInfo}) Line 71 + 0x37 bytes    C#
>    RemObjects.Script.dll!RemObjects.Script.EcmaScript.EcmaScriptCompiler.Parse(RemObjects.Script.EcmaScript.Internal.ProgramElement aElements = {RemObjects.Script.EcmaScript.Internal.ProgramElement}) Line 373 + 0x45 bytes    Unknown

Dec 24, 2009 at 12:36 AM

I too encounter the problem that TraceCallBack does not occur in nested lambda. TraceCallBack does happen in the top level lambda. I am using 0.92. I wonder if this problem has been fixed in later versions. 

I used two level lambda because I noticed that accessing parameter expression is far faster than accessing variables stored in a Scope object (about 3 times). Therefore, I use ParameterExpression as script scope variables in my script. I create functions in script as nested lambda so that they can access top level variables.

Thanks.

Jan 1, 2010 at 10:52 PM

I looked into the source code of Microsoft.Scripting.Debugging and have a better understanding of the problem. First of all, both LambdaWalker and DebugableLambdaBuilder does not handle Lambda expression. The comments said that they expect the lambda to have been transformed already. So we do not to transform each nexted lambda separately. Secondly a more severe problem, if the nested lambda reference parameter expressions in the parent lambda, the reference become invalid after the parent is transformed. Thirdly, if we transform the child that references parent parameters, the child cannot see the parent parameter after transform.

Coordinator
Jan 4, 2010 at 7:19 PM

This sounds like a bug – we should probably walk nested lambdas and transform them as well.  Currently IronPython and IronRuby don’t ever generate nested lambdas and instead create and maintain closures themselves to more closely get the language semantics right so we don’t have any use cases which are using this w/ nested lambdas.  I’ve opened a bug on this here: http://dlr.codeplex.com/WorkItem/View.aspx?WorkItemId=5029

From: dotneteer [mailto:notifications@codeplex.com]
Sent: Friday, January 01, 2010 2:53 PM
To: Dino Viehland
Subject: Re: DebugContext.TransformLambda and functions [dlr:67261]

From: dotneteer

I looked into the source code of Microsoft.Scripting.Debugging and have a better understanding of the problem. First of all, both LambdaWalker and DebugableLambdaBuilder does not handle Lambda expression. The comments said that they expect the lambda to have been transformed already. So we do not to transform each nexted lambda separately. Secondly a more severe problem, if the nested lambda reference parameter expressions in the parent lambda, the reference become invalid after the parent is transformed. Thirdly, if we transform the child that references parent parameters, the child cannot see the parent parameter after transform.

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jan 5, 2010 at 6:14 AM

Great if you can support the nested lambdas. Thanks a lot!