edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C457445
File: Loader.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C457445  (server)    6/5/2008 3:19 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;RubyPrecompilation
@@ -29,6 +29,7 @@
 using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Actions;
 using Microsoft.Scripting.Generation;
+using System.Threading;
 
 namespace Ruby.Runtime {
     [Flags]
@@ -61,10 +62,10 @@
         // files that were required but their execution haven't completed yet:
         private readonly Stack<string>/*!*/ _unfinishedFiles; 
 
-        // TODO: weak hash?
-        // TODO: modification timestamps
+        // TODO: static
         // maps full normalized path to compiled code:
-        private readonly Dictionary<string, CompiledFile>/*!*/ _compiledFiles;
+        private Dictionary<string, CompiledFile> _compiledFiles;
+        private readonly object/*!*/ _compiledFileMutex = new object();
 
         private struct CompiledFile {
             public readonly ScriptCode/*!*/ CompiledCode;
@@ -116,40 +117,74 @@
             _loadPaths = new RubyArray();
             _loadedFiles = new RubyArray();
             _unfinishedFiles = new Stack<string>();
-            _compiledFiles = new Dictionary<string, CompiledFile>(Platform.PathComparer);
+        }
 
-            LoadCompiledCode();
+        private Dictionary<string, CompiledFile>/*!*/ LoadCompiledCode() {
+            Debug.Assert(_executionContext.Context.EngineOptions.LoadFromDisk);
+
+            Dictionary<string, CompiledFile> result = new Dictionary<string, CompiledFile>();
+            Debug.WriteLine("LOADING", "LOADER");
+
+            ScriptCode[] codes = ScriptCode.LoadFromAssembly(_executionContext.Context.DomainManager,
+                Assembly.LoadFrom("IronRubyApplication.dll"));
+
+            for (int i = 0; i < codes.Length; i++) {
+                string path = codes[i].SourceUnit.Path;
+                string fullPath = Platform.GetFullPath(path);
+                result[fullPath] = new CompiledFile(codes[i]);
+            }
+
+            return result;
         }
 
-        internal void LoadCompiledCode() {
-            if (_executionContext.Context.EngineOptions.LoadFromDisk) {
-                Debug.WriteLine("LOADING", "LOADER");
+        internal void SaveCompiledCode() {
+            if (_executionContext.Context.EngineOptions.SaveToDisk) {
+                lock (_compiledFileMutex) {
+                    Debug.WriteLine("SAVING", "LOADER");
 
-                ScriptCode[] codes = ScriptCode.LoadFromAssembly(_executionContext.Context.DomainManager,
-                    Assembly.Load("IronRubyApplication"));
+                    // TODO: allocate eagerly (as soon as config gets fixed)
+                    if (_compiledFiles == null) {
+                        _compiledFiles = new Dictionary<string, CompiledFile>();
+                    }
 
-                for (int i = 0; i < codes.Length; i++) {
-                    string path = codes[i].SourceUnit.Path;
-                    string fullPath = Platform.GetFullPath(path);
-                    _compiledFiles[fullPath] = new CompiledFile(codes[i]);
+                    ScriptCode[] codes = new ScriptCode[_compiledFiles.Count];
+                    int i = 0;
+                    foreach (CompiledFile file in _compiledFiles.Values) {
+                        codes[i++] = file.CompiledCode;
+                    }
+
+                    ScriptCode.SaveToDisk("IronRubyApplication.dll", codes);
                 }
             }
         }
 
-        internal void SaveCompiledCode() {
-            if (_executionContext.Context.EngineOptions.SaveToDisk) {
-                Debug.WriteLine("SAVING", "LOADER");
+        private bool TryGetCompiledFile(string/*!*/ fullPath, out CompiledFile compiledFile) {
+            if (!_executionContext.Context.EngineOptions.LoadFromDisk) {
+                compiledFile = default(CompiledFile);
+                return false;
+            }
 
-                ScriptCode[] codes = new ScriptCode[_compiledFiles.Count];
-                int i = 0;
-                foreach (CompiledFile file in _compiledFiles.Values) {
-                    codes[i++] = file.CompiledCode;
+            lock (_compiledFileMutex) {
+                if (_compiledFiles == null) {
+                    _compiledFiles = LoadCompiledCode();
                 }
 
-                ScriptCode.SaveToDisk("IronRubyApplication.dll", codes);
+                return _compiledFiles.TryGetValue(fullPath, out compiledFile);
             }
         }
 
+        private void AddCompiledFile(string/*!*/ fullPath, ScriptCode/*!*/ compiledCode) {
+            if (_executionContext.Context.EngineOptions.SaveToDisk) {
+                lock (_compiledFileMutex) {
+                    // TODO: allocate eagerly (as soon as config gets fixed)
+                    if (_compiledFiles == null) {
+                        _compiledFiles = new Dictionary<string, CompiledFile>();
+                    }
+                    _compiledFiles[fullPath] = new CompiledFile(compiledCode);
+                }
+            }
+        }
+
         /// <summary>
         /// Returns <b>true</b> if a Ruby file is successfully loaded, <b>false</b> if it is already loaded.
         /// </summary>
@@ -305,15 +340,13 @@
         }
 
         private void ExecuteRubySourceUnit(SourceUnit/*!*/ sourceUnit, CodeContext/*!*/ context, LoadFlags flags) {
-            ScriptCode compiledCode;
 
             // TODO: check file timestamp
             string fullPath = Platform.GetFullPath(sourceUnit.Path);
             CompiledFile compiledFile;
-            if (_executionContext.Context.EngineOptions.LoadFromDisk && _compiledFiles.TryGetValue(fullPath, out compiledFile)) {
+            if (TryGetCompiledFile(fullPath, out compiledFile)) {
                 Debug.WriteLine(String.Format("{0}: {1}", ++_cacheHitCount, sourceUnit.Path), "LOAD CACHED");
-
-                compiledCode = compiledFile.CompiledCode;
+                compiledFile.CompiledCode.Run(context);
             } else {
                 Debug.WriteLine(String.Format("{0}: {1}", ++_compiledFileCount, sourceUnit.Path), "LOAD COMPILED");
 
@@ -322,15 +355,13 @@
                 options.IsWrapped = (flags & LoadFlags.LoadIsolated) != 0;
 
                 _totalAstGenerationTime.Start();
-                compiledCode = sourceUnit.Compile(options, _executionContext.RuntimeErrorSink);
+                ScriptCode compiledCode = sourceUnit.Compile(options, _executionContext.RuntimeErrorSink);
                 _totalAstGenerationTime.Stop();
-                
-                if (_executionContext.Context.EngineOptions.SaveToDisk) {
-                    _compiledFiles[fullPath] = new CompiledFile(compiledCode);
-                }
+
+                AddCompiledFile(fullPath, compiledCode);
+
+                RunScriptCode(context, compiledCode, false);
             }
-
-            RunScriptCode(context, compiledCode, false);
         }
 
         internal object RunScriptCode(CodeContext context, ScriptCode code, bool tryEvaluate) {
@@ -345,7 +376,6 @@
             return code.Run(context);
         }
 
-
         private ResolvedFile FindFile(CodeContext/*!*/ context, string/*!*/ path, bool appendExtensions) {
             Assert.NotNull(path);
             bool isAbsolutePath;
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;C438696
File: ProtocolConversionAction.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;C438696  (server)    6/5/2008 2:33 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;RubyPrecompilation
@@ -32,7 +32,7 @@
     using Ast = Microsoft.Scripting.Ast.Expression;
     using AstFactory = Ruby.Compiler.Ast.AstFactory;
 
-    public abstract class ProtocolConversionAction : DynamicAction {
+    public abstract class ProtocolConversionAction : DynamicAction, IExpressionSerializable {
         // TODO: ???
         public override DynamicActionKind Kind {
             get { return (DynamicActionKind)(-1); }
@@ -47,6 +47,10 @@
         }
 
         internal abstract void SetRule(RuleBuilder/*!*/ rule, CodeContext/*!*/ callerContext, object[]/*!*/ args);
+
+        public virtual Expression/*!*/ CreateExpression() {
+            return Ast.Call(GetType().GetMethod("Make"));
+        }
     }
 
     public abstract class ProtocolConversionAction<TTargetType> : ProtocolConversionAction where TTargetType : class {
@@ -157,6 +161,7 @@
             : base() {
         }
 
+        // emitted:
         public static ConvertToProcAction/*!*/ Make() {
             return Instance;
         }
@@ -177,6 +182,7 @@
             : base() {
         }
 
+        // emitted:
         public static ConvertToStrAction/*!*/ Make() {
             return Instance;
         }
@@ -197,6 +203,7 @@
             : base() {
         }
 
+        // emitted:
         public static ConvertToSAction/*!*/ Make() {
             return Instance;
         }
===================================================================
edit: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/DlrCachedCodeAttribute.cs;C454421
File: DlrCachedCodeAttribute.cs
===================================================================
--- $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/DlrCachedCodeAttribute.cs;C454421  (server)    6/5/2008 3:58 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/DlrCachedCodeAttribute.cs;RubyPrecompilation
@@ -15,6 +15,7 @@
 
 using System;
 using System.Collections.Generic;
+using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Runtime {
     /// <summary>
@@ -23,23 +24,28 @@
     /// </summary>
     [AttributeUsage(AttributeTargets.Method)]
     public sealed class DlrCachedCodeAttribute : Attribute {
-        private Type _lcType;
-        private string[] _names;
+        private readonly Type/*!*/ _lcType;
+        private readonly string[] _names;
 
+        // TODO: remove
         public DlrCachedCodeAttribute() {
         }
 
-        public DlrCachedCodeAttribute(Type languageContextType, string[] names) {
+        public DlrCachedCodeAttribute(Type/*!*/ languageContextType, string[] names) {
+            ContractUtils.RequiresNotNull(languageContextType, "languageContextType");
             _lcType = languageContextType;
             _names = names;
         }
 
-        public Type LanguageContextType {
+        public Type/*!*/ LanguageContextType {
             get {
                 return _lcType;
             }
         }
 
+        /// <summary>
+        /// Null means no optimized scope.
+        /// </summary>
         public IList<String> Names {
             get {
                 return _names;
===================================================================
edit: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.cs;C459317
File: ScriptCode.cs
===================================================================
--- $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.cs;C459317  (server)    6/5/2008 3:48 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.cs;RubyPrecompilation
@@ -43,9 +43,14 @@
         private Scope _optimizedScope;
 
         private ScriptCode(DlrMainCallTarget callTarget, LanguageContext context, Scope optimizedScope, CompilerContext compilerContext) {
-            _optimizedTarget = callTarget;
+            if (optimizedScope != null) {
+                _optimizedTarget = callTarget;
+            } else {
+                _simpleTarget = callTarget;
+            }
+
+            _optimizedScope = optimizedScope;
             _languageContext = context;
-            _optimizedScope = optimizedScope;
             _compilerContext = compilerContext;
         }
 
@@ -204,20 +209,27 @@
                     continue;
                 }
 
-                // create the storage for the global scope
-                GlobalsDictionary dict = new GlobalsDictionary(SymbolTable.StringsToIds(code[0].Names));
-                
-                // create the CodeContext for the code from the storage
-                Scope scope = new Scope(dict);
                 LanguageContext lc = runtime.GetLanguageContext(code[0].LanguageContextType);
-                CodeContext context = new CodeContext(scope, lc);
+                Scope scope;
 
-                // initialize the tuple
-                IModuleDictionaryInitialization ici = dict as IModuleDictionaryInitialization;
-                if (ici != null) {
-                    ici.InitializeModuleDictionary(context);
+                if (code[0].Names != null) {
+
+                    // create the storage for the global scope
+                    GlobalsDictionary dict = new GlobalsDictionary(SymbolTable.StringsToIds(code[0].Names));
+
+                    // create the CodeContext for the code from the storage
+                    scope = new Scope(dict);
+                    CodeContext context = new CodeContext(scope, lc);
+
+                    // initialize the tuple
+                    IModuleDictionaryInitialization ici = dict as IModuleDictionaryInitialization;
+                    if (ici != null) {
+                        ici.InitializeModuleDictionary(context);
+                    }
+                } else {
+                    scope = null;
                 }
-                
+
                 // create the CompilerContext for the ScriptCode
                 SourceUnit su = new SourceUnit(lc, NullTextContentProvider.Null, mi.Name, SourceCodeKind.File);
                 CompilerContext ctx = new CompilerContext(su, lc.GetCompilerOptions(), ErrorSink.Null);
===================================================================
edit: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.OptimizedScopes.cs;C459317
File: ScriptCode.OptimizedScopes.cs
===================================================================
--- $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.OptimizedScopes.cs;C459317  (server)    6/5/2008 3:57 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/ndp/fx/src/Core/Microsoft/Scripting/Runtime/ScriptCode.OptimizedScopes.cs;RubyPrecompilation
@@ -70,7 +70,7 @@
             return scope;
         }
         
-        private void CompileToDisk(TypeGen typeGen) {
+        private void CompileToDisk(TypeGen/*!*/ typeGen) {
 
             Type[] parameterTypes = new Type[] { typeof(CodeContext) };
             MethodBuilder mb = typeGen.TypeBuilder.DefineMethod(
@@ -90,7 +90,7 @@
 
             CustomAttributeBuilder cab = new CustomAttributeBuilder(
                 typeof(DlrCachedCodeAttribute).GetConstructor(new Type[] { typeof(Type), typeof(string[]) }),
-                new object[] {  _languageContext.GetType(), ArrayUtils.ToArray(rewriter.Names)}
+                new object[] {  _languageContext.GetType(), (_optimizedScope != null) ? ArrayUtils.ToArray(rewriter.Names) : null }
             );
 
             mb.SetCustomAttribute(cab);
===================================================================
