none
PowerShell 5.0 and Dynamic Language Runtime DLR for compiled scripts and functions RRS feed

  • General discussion

  • Hello All:

    PowerShell 3.0/4.0 did not fully utilize the Dynamic Language Runtime (DLR) like IronPython did.  To what extent does PowerShell 5.0 use or rely on the DLR?  Fully the same as IronPython? What are the DLR changes from PoSh 4.0 to 5.0?

    For example, how can we know that a script or function in PowerShell 5.0 has been JIT-compiled?  What can we do to write or refactor our scripts to help ensure compilation?  Do we have control or visibility into compilation?

    (Related: And when will Visual Studio have built-in support for PowerShell without having to install an add-on/extension?  It's a little embarrassing...  Visual Studio 2015 should have had built-in support for PowerShell and the ability to compile PowerShell to an EXE....assuming PowerShell 5.0 fully utilizes the DLR...hence these questions.) 

    I'm hoping to find official guidance here with the details and exceptions, not general impressions or what was heard around the water cooler.  If you have whitepapers, Channel 9 references or other URLs, that would be great!

    Thank You!!!

    Saturday, July 4, 2015 3:16 AM

All replies

  • PowerShell DLR? The DLR is not available until Net Framework 4.0 and PowerShell was designed on Net Framework 1.1.

    https://msdn.microsoft.com/en-us/library/dd233052%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    The DLR documented by MS may be hidden under earlier PowerShell but it appears to only be surfaced with Net 4.0.  I suppose it is possible that WMF 4.0 and later may be built on the DLR.


    \_(ツ)_/


    • Edited by jrv Saturday, July 4, 2015 4:22 AM
    Saturday, July 4, 2015 4:18 AM
  • PowerShell was refactored to take advantage of the parts of the DLR that shipped with the operating system / Core CLR starting with PowerShell 3.0.  I haven't found any official documentation from Microsoft on this, but did find this snippet from a third-party article written by a PowerShell MVP: https://dzone.com/articles/powershell-3-finally-dlr

    "PowerShell 3 takes advantage of all (or most) of what shipped in the CLR, but since the PowerShell team wasn’t willing to be responsible for shipping the rest of the DLR in the operating system, they didn’t implement the rest of it. Which is to say, PowerShell 3 is using the DLR Language Implementation code, with Shared AST and Expression trees, as well as the DynamicObject and Call Site Caching portions of the runtime, but none of the Common Hosting pieces like ScriptRuntime, ScriptScope, ScriptSource, or CompiledCode"

    I didn't become an MVP until 2014, so I don't have logs of the MVP mailing list going back that far, but I suspect that the source of Joel's information was comments made on that list by the PowerShell team.

    As far as I know, this information is still accurate.

    Saturday, July 4, 2015 3:15 PM
  • Wow!  My guess wasn't all that far off.

    Thanks for the details.


    \_(ツ)_/

    Saturday, July 4, 2015 3:54 PM
  • Thank you David, but that Joel Bennett article (2012) is what I had in mind when I mentioned that the DLR was not being fully utilized by PoSh 3.0/4.0.  I was hoping to find something more up-to-date for PoSh 5.0.  But thank you for your response, I should have mentioned that article in my original question. 

    There must be someone on the PowerShell Team at Microsoft who visits these forums every once in a while?  Though I suppose they might be kind of busy right now getting ready for the Windows 10 release...     :-)

    Sunday, July 5, 2015 11:52 AM
  • Btw, I found another article related to DLR compilation (March 2012):

    http://csharpening.net/?p=989

    Apparently, some PowerShell scriptblocks are being converted to LINQ lambda expressions and then compiled to IL (???)  

    Sunday, July 12, 2015 9:23 PM
  • Btw, I found another article related to DLR compilation (March 2012):

    http://csharpening.net/?p=989

    Apparently, some PowerShell scriptblocks are being converted to LINQ lambda expressions and then compiled to IL (???)  


    Excellent.  I was wondering when "Linq" would surface into PS.

    \_(ツ)_/

    Sunday, July 12, 2015 10:05 PM