diff --git a/src/Apps/Kernel/RexlKernel/Builtins.cs b/src/Apps/Kernel/RexlKernel/Builtins.cs index 49a5d48..c16cb05 100644 --- a/src/Apps/Kernel/RexlKernel/Builtins.cs +++ b/src/Apps/Kernel/RexlKernel/Builtins.cs @@ -6,21 +6,18 @@ using Microsoft.Rexl.Bind; using Microsoft.Rexl.Code; +using Microsoft.Rexl.Onnx; using Microsoft.Rexl.Private; +using Microsoft.Rexl.Solve; namespace Microsoft.Rexl.Kernel; internal sealed class KernelBuiltins : OperationRegistry { public KernelBuiltins(Func setShowIL = null) - : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance, FlowProcs.Instance) + : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance, FlowProcs.Instance, + SolverFunctions.Instance, ModelFunctions.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverFunctions.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFunctions.Instance); -#endif if (setShowIL != null) AddOne(new ShowILFunc(setShowIL)); } @@ -29,14 +26,8 @@ public KernelBuiltins(Func setShowIL = null) internal sealed class KernelGenerators : GeneratorRegistry { public KernelGenerators() - : base(BuiltinGenerators.Instance) + : base(BuiltinGenerators.Instance, SolverGenerators.Instance, ModelFuncGenerators.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverGenerators.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFuncGenerators.Instance); -#endif Add(ShowILFunc.MakeGen()); } } diff --git a/src/Apps/Kernel/RexlKernel/Exec.cs b/src/Apps/Kernel/RexlKernel/Exec.cs index 126920a..ec85a26 100644 --- a/src/Apps/Kernel/RexlKernel/Exec.cs +++ b/src/Apps/Kernel/RexlKernel/Exec.cs @@ -78,18 +78,6 @@ public async Task ExecAsync(ExecuteMessage msg, int min, int lim) } } -#if WITH_SOLVE - protected override bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - return Solve.MipSolver.TryOptimize(Sink, _codeGen, isMax, modSrc, imsr, solver, out score, out symValues); - } -#endif - private void PublishText(ExecuteMessage msg, string text) { Validation.AssertValue(msg); diff --git a/src/Apps/Kernel/RexlKernel/RexlKernel.csproj b/src/Apps/Kernel/RexlKernel/RexlKernel.csproj index 9f4ef71..243cc71 100644 --- a/src/Apps/Kernel/RexlKernel/RexlKernel.csproj +++ b/src/Apps/Kernel/RexlKernel/RexlKernel.csproj @@ -4,7 +4,6 @@ Exe net6.0 RexlKernel - $(DefineConstants);WITH_ONNX;WITH_SOLVE diff --git a/src/Apps/RexlBench/Exec.cs b/src/Apps/RexlBench/Exec.cs index 87a8d52..73d31df 100644 --- a/src/Apps/RexlBench/Exec.cs +++ b/src/Apps/RexlBench/Exec.cs @@ -7,9 +7,11 @@ using Microsoft.Rexl; using Microsoft.Rexl.Bind; using Microsoft.Rexl.Code; +using Microsoft.Rexl.Onnx; using Microsoft.Rexl.Parse; using Microsoft.Rexl.Private; using Microsoft.Rexl.Sink; +using Microsoft.Rexl.Solve; namespace Microsoft.Rexl.RexlBench; @@ -65,14 +67,9 @@ protected override void WriteValueCore(DType type, object? value, int max) sealed class Operations : OperationRegistry { public Operations() - : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance, FlowProcs.Instance) + : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance, FlowProcs.Instance, + SolverFunctions.Instance, ModelFunctions.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverFunctions.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFunctions.Instance); -#endif AddOne(WrapFunc.Instance); } } @@ -80,14 +77,8 @@ public Operations() sealed class Generators : GeneratorRegistry { public Generators() - : base(BuiltinGenerators.Instance) + : base(BuiltinGenerators.Instance, SolverGenerators.Instance, ModelFuncGenerators.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverGenerators.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFuncGenerators.Instance); -#endif Add(WrapFunc.MakeGenerator()); } } diff --git a/src/Apps/RexlBench/MainForm.cs b/src/Apps/RexlBench/MainForm.cs index 69446ba..0705de9 100644 --- a/src/Apps/RexlBench/MainForm.cs +++ b/src/Apps/RexlBench/MainForm.cs @@ -782,16 +782,4 @@ public SimpleHarness(IHarnessConfig config, OperationRegistry opers, CodeGenerat : base(config, opers, codeGen, storage) { } - -#if WITH_SOLVE - protected override bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - return Solve.MipSolver.TryOptimize(Sink, _codeGen, isMax, modSrc, imsr, solver, out score, out symValues); - } -#endif } diff --git a/src/Apps/RexlBench/RexlBench.csproj b/src/Apps/RexlBench/RexlBench.csproj index a17fc81..308b076 100644 --- a/src/Apps/RexlBench/RexlBench.csproj +++ b/src/Apps/RexlBench/RexlBench.csproj @@ -5,7 +5,6 @@ WinExe true Microsoft.Rexl.RexlBench - $(DefineConstants);WITH_ONNX;WITH_SOLVE diff --git a/src/Apps/RexlRun/Builtins.cs b/src/Apps/RexlRun/Builtins.cs index 808a13d..25edd8c 100644 --- a/src/Apps/RexlRun/Builtins.cs +++ b/src/Apps/RexlRun/Builtins.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using Microsoft.Rexl.Code; +using Microsoft.Rexl.Onnx; +using Microsoft.Rexl.Solve; namespace Microsoft.Rexl.RexlRun; @@ -11,27 +13,16 @@ namespace Microsoft.Rexl.RexlRun; internal sealed class RexlRunOperations : OperationRegistry { public RexlRunOperations() - : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance) + : base(BuiltinFunctions.Instance, BuiltinProcedures.Instance, + SolverFunctions.Instance, ModelFunctions.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverFunctions.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFunctions.Instance); -#endif } } internal sealed class RexlRunGenerators : GeneratorRegistry { public RexlRunGenerators() - : base(BuiltinGenerators.Instance) + : base(BuiltinGenerators.Instance, SolverGenerators.Instance, ModelFuncGenerators.Instance) { -#if WITH_SOLVE - AddParent(Solve.SolverGenerators.Instance); -#endif -#if WITH_ONNX - AddParent(Onnx.ModelFuncGenerators.Instance); -#endif } } diff --git a/src/Apps/RexlRun/Main.cs b/src/Apps/RexlRun/Main.cs index d344041..ba3fc0b 100644 --- a/src/Apps/RexlRun/Main.cs +++ b/src/Apps/RexlRun/Main.cs @@ -192,16 +192,4 @@ public SimpleHarness(IHarnessConfig config, OperationRegistry opers, CodeGenerat : base(config, opers, codeGen, storage) { } - -#if WITH_SOLVE - protected override bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - return Solve.MipSolver.TryOptimize(Sink, _codeGen, isMax, modSrc, imsr, solver, out score, out symValues); - } -#endif } diff --git a/src/Apps/RexlRun/RexlRun.csproj b/src/Apps/RexlRun/RexlRun.csproj index 4f5f87b..22b581e 100644 --- a/src/Apps/RexlRun/RexlRun.csproj +++ b/src/Apps/RexlRun/RexlRun.csproj @@ -3,7 +3,6 @@ Exe net6.0 - $(DefineConstants);WITH_ONNX;WITH_SOLVE diff --git a/src/Core/Rexl.Code/Code/CodeGenerator.Module.cs b/src/Core/Rexl.Code/Code/CodeGenerator.Module.cs index dab6b6a..60812bb 100644 --- a/src/Core/Rexl.Code/Code/CodeGenerator.Module.cs +++ b/src/Core/Rexl.Code/Code/CodeGenerator.Module.cs @@ -144,7 +144,7 @@ protected override bool PreVisitModule(BndModuleNode bmod, int idx) // For item ifma: // * If ifma is the value for symbol isym and the symbol is "settable" (parameter or free variable) // and flags[citem + isym] is true, then the value comes from rec. - // * Otherwise, if flags[csym + ifma] is true, then the item slot is not set (assumed to be valid). + // * Otherwise, if flags[ifma] is true, then the item slot is not set (assumed to be valid). // * Otherwise, the value is computed from its formula. int isym = 0; for (int ifma = 0; ifma < citem; ifma++) @@ -291,6 +291,77 @@ protected override bool PreVisitModule(BndModuleNode bmod, int idx) } PopType(stMakeRec); + // Get the set_module_value_item function. The function takes an items tuple (being built), + // item index (for the value item of a parameter or free variable), and the value to be + // set (as an object). + frame = StartFunctionDisjoint("set_module_value_item", stItems, stItems, typeof(int), typeof(object)); + Type stSetValueItem = frame.DelegateType; + + { + var laiItems = LocArgInfo.FromArg(1, stItems); + + // Do this first so the default label has the smallest index in IL dumps. + var labDef = IL.DefineLabel(); + + var labels = new Label[bmod.Items.Length]; + for (int isym = 0; isym < bmod.Symbols.Length; isym++) + { + var sym = bmod.Symbols[isym]; + switch (sym.SymKind) + { + case ModSymKind.Parameter: + case ModSymKind.FreeVariable: + labels[sym.IfmaValue] = IL.DefineLabel(); + break; + } + } + + for (int ifma = 0; ifma < labels.Length; ifma++) + { + if (labels[ifma] == default) + labels[ifma] = labDef; + } + + IL + .Ldarg(2) + .Switch(labels); + + for (int isym = 0; isym < bmod.Symbols.Length; isym++) + { + var sym = bmod.Symbols[isym]; + switch (sym.SymKind) + { + default: + continue; + case ModSymKind.Parameter: + case ModSymKind.FreeVariable: + break; + } + + // REVIEW: TypeManager should support emitting the proper instructions + // to set the field. This code shouldn't know about the field layout of + // the tuple system type. + int ifma = sym.IfmaValue; + Validation.Assert(labels[ifma] != labDef); + var fld = stItems.GetField("_F" + ifma).VerifyValue(); + + IL + .Br_Non(labDef) + .MarkLabel(labels[ifma]) + .Ldarg(1) + .Ldarg(3) + .Unbox_Any(fld.FieldType) + .Stfld(fld); + } + + IL + .MarkLabel(labDef) + .Ldarg(1); + PushType(stItems); + EndFunctionCore(); + } + PopType(stSetValueItem); + GenLoadConst(bmod); // Instantiate the runtime module. @@ -299,7 +370,8 @@ protected override bool PreVisitModule(BndModuleNode bmod, int idx) { IL.Ldloc(locExt); Type stModImpl = typeof(RuntimeModule<,,>).MakeGenericType(stRec, stItems, stExt); - ctor = stModImpl.GetConstructor(new Type[] { stSetItems, stItems, stMakeRec, typeof(BndModuleNode), stExt }); + ctor = stModImpl.GetConstructor( + new Type[] { stSetItems, stItems, stMakeRec, stSetValueItem, typeof(BndModuleNode), stExt }); if (ctor is null) throw Unexpected("Ctor for runtime module with externals"); } @@ -307,7 +379,8 @@ protected override bool PreVisitModule(BndModuleNode bmod, int idx) { // Construct the module instance. Type stModImpl = typeof(RuntimeModule<,>).MakeGenericType(stRec, stItems); - ctor = stModImpl.GetConstructor(new Type[] { stSetItems, stItems, stMakeRec, typeof(BndModuleNode) }); + ctor = stModImpl.GetConstructor( + new Type[] { stSetItems, stItems, stMakeRec, stSetValueItem, typeof(BndModuleNode) }); if (ctor is null) throw Unexpected("Ctor for runtime module"); } diff --git a/src/Core/Rexl.Code/Code/ILWriter.cs b/src/Core/Rexl.Code/Code/ILWriter.cs index 8a18dde..b1caf6e 100644 --- a/src/Core/Rexl.Code/Code/ILWriter.cs +++ b/src/Core/Rexl.Code/Code/ILWriter.cs @@ -498,8 +498,20 @@ private void Log(OpCode op, Label arg) [Conditional("LOG_IL")] private void Log(OpCode op, Label[] arg) { - // REVIEW: Should do something better, if we ever use switch. - Log(op, (object)arg); +#if LOG_IL + if (_lines != null) + { + var sink = StartLine().TWrite("{0,5}) {1} [", LogPrefix(), op); + var pre = ""; + foreach (var lab in arg) + { + sink.TWrite(pre).TWrite(lab.GetHashCode() - 1); + pre = ","; + } + sink.Write("]"); + AddLine(sink); + } +#endif } private void Emit(OpCode op, Type arg) diff --git a/src/Core/Rexl.Code/Module/RuntimeModule.cs b/src/Core/Rexl.Code/Module/RuntimeModule.cs index 24687bf..ff172a0 100644 --- a/src/Core/Rexl.Code/Module/RuntimeModule.cs +++ b/src/Core/Rexl.Code/Module/RuntimeModule.cs @@ -76,6 +76,8 @@ public sealed override RuntimeModule UpdateRaw(RecordBase values, HashSet } public abstract RuntimeModule Update(TRec values, HashSet names); + + public abstract RuntimeModule Update(List<(DName name, object value)> symValues); } /// @@ -90,6 +92,12 @@ public abstract class RuntimeModuleBase : RuntimeModule /// protected readonly Func _makeRec; + /// + /// Sets a single item in the items tuple. The item index (2nd arg) will be for the + /// value slot of a parameter or free variable. + /// + protected readonly Func _setValueItem; + /// /// The items tuple. /// @@ -105,12 +113,16 @@ public abstract class RuntimeModuleBase : RuntimeModule /// private volatile TRec _rec; - private protected RuntimeModuleBase(BndModuleNode bnd, Func makeRec, TItems items, BitSet locked) + private protected RuntimeModuleBase(BndModuleNode bnd, + Func makeRec, Func setValueItem, TItems items, BitSet locked) : base(bnd) { Validation.AssertValue(makeRec); + Validation.AssertValue(setValueItem); Validation.AssertValue(items); + _makeRec = makeRec; + _setValueItem = setValueItem; _items = items; _locked = locked; } @@ -163,6 +175,13 @@ protected bool[] GetFlags(HashSet names, out BitSet locked) } } + CloseFlags(flags, locked); + return flags; + } + + private void CloseFlags(bool[] flags, BitSet locked) + { + int citem = Bnd.Items.Length; var chgs = new BitSet(flags.AsSpan(0, citem)); var deps = Bnd.GetItemDependencies(); for (int i = 0; i < citem; i++) @@ -180,7 +199,61 @@ protected bool[] GetFlags(HashSet names, out BitSet locked) else flags[i] = true; } + } + + protected bool[] SetSlots(List<(DName name, object value)> symValues, + out TItems items, out BitSet locked, out int count) + { + int citem = Bnd.Items.Length; + var flags = new bool[Bnd.Items.Length + Bnd.Symbols.Length]; + + items = (TItems)_items.Clone(); + locked = _locked; + count = 0; + foreach (var (name, value) in symValues) + { + if (!Bnd.NameToIndex.TryGetValue(name, out int isym)) + { + // Bad name. + Validation.Assert(false); + continue; + } + + Validation.AssertIndex(isym, Bnd.Symbols.Length); + var sym = Bnd.Symbols[isym]; + int ifma = sym.IfmaValue; + Validation.AssertIndex(ifma, Bnd.Items.Length); + + if (flags[ifma]) + { + // Duplicate entry. + continue; + } + switch (sym.SymKind) + { + case ModSymKind.Parameter: + case ModSymKind.FreeVariable: + flags[ifma] = true; + locked = locked.SetBit(ifma); + count++; + break; + default: + // Not settable. + Validation.Assert(false); + continue; + } + + _setValueItem(items, ifma, value); + } + + if (count == 0) + { + items = _items; + return flags; + } + + CloseFlags(flags, locked); return flags; } } @@ -205,15 +278,15 @@ public sealed class RuntimeModule : RuntimeModuleBase setItems, TItems items, - Func makeRec, BndModuleNode bnd) - : this(setItems, items, default, makeRec, bnd) + Func makeRec, Func setValueItem, BndModuleNode bnd) + : this(setItems, items, default, makeRec, setValueItem, bnd) { } private RuntimeModule( Func setItems, TItems items, BitSet locked, - Func makeRec, BndModuleNode bnd) - : base(bnd, makeRec, items, locked) + Func makeRec, Func setValueItem, BndModuleNode bnd) + : base(bnd, makeRec, setValueItem, items, locked) { Validation.AssertValue(setItems); _setItems = setItems; @@ -225,9 +298,22 @@ public override RuntimeModule Update(TRec recVals, HashSet { Validation.AssertValue(recVals); Validation.AssertValue(names); + var flags = GetFlags(names, out var locked); var items = _setItems(flags, (TItems)_items.Clone(), recVals); - return new RuntimeModule(_setItems, items, locked, _makeRec, Bnd); + return new RuntimeModule(_setItems, items, locked, _makeRec, _setValueItem, Bnd); + } + + public override RuntimeModule Update(List<(DName name, object value)> symValues) + { + Validation.AssertValue(symValues); + + var flags = SetSlots(symValues, out var items, out var locked, out int count); + if (count == 0) + return this; + + items = _setItems(flags, items, null); + return new RuntimeModule(_setItems, items, locked, _makeRec, _setValueItem, Bnd); } } @@ -251,15 +337,15 @@ public sealed class RuntimeModule : RuntimeModuleBase setItems, TItems items, - Func makeRec, BndModuleNode bnd, TExt ext) - : this(setItems, items, default, makeRec, bnd, ext) + Func makeRec, Func setValueItem, BndModuleNode bnd, TExt ext) + : this(setItems, items, default, makeRec, setValueItem, bnd, ext) { } private RuntimeModule( Func setItems, TItems items, BitSet locked, - Func makeRec, BndModuleNode bnd, TExt ext) - : base(bnd, makeRec, items, locked) + Func makeRec, Func setValueItem, BndModuleNode bnd, TExt ext) + : base(bnd, makeRec, setValueItem, items, locked) { Validation.AssertValue(setItems); Validation.AssertValue(ext); @@ -275,6 +361,18 @@ public override RuntimeModule Update(TRec recVals, HashSet(_setItems, items, locked, _makeRec, Bnd, Externals); + return new RuntimeModule(_setItems, items, locked, _makeRec, _setValueItem, Bnd, Externals); + } + + public override RuntimeModule Update(List<(DName name, object value)> symValues) + { + Validation.AssertValue(symValues); + + var flags = SetSlots(symValues, out var items, out var locked, out int count); + if (count == 0) + return this; + + items = _setItems(flags, items, null, Externals); + return new RuntimeModule(_setItems, items, locked, _makeRec, _setValueItem, Bnd, Externals); } } diff --git a/src/Core/Rexl.Code/Operations/ExecCtx.cs b/src/Core/Rexl.Code/Operations/ExecCtx.cs index a2218fb..2e2b742 100644 --- a/src/Core/Rexl.Code/Operations/ExecCtx.cs +++ b/src/Core/Rexl.Code/Operations/ExecCtx.cs @@ -7,6 +7,7 @@ using Microsoft.Rexl.Bind; using Microsoft.Rexl.Private; +using Microsoft.Rexl.Sink; namespace Microsoft.Rexl.Code; @@ -183,16 +184,21 @@ public virtual void Ping(int id) public abstract void Log(int id, string fmt, params object[] args); /// - /// Optimize the given measure in the given module. - /// REVIEW: This is a temporary hack. Optimization should really use a task. + /// Produces an if one is available to the context. /// - public virtual RuntimeModule Optimize(int id, RuntimeModule src, DName measure, bool isMax, DName solver) + public virtual bool TryGetSink(out EvalSink sink) { - if (src is null) - return null; + sink = null; + return false; + } - Log(id, "Optimization not supported"); - return null; + /// + /// Produces a if one is available to the context. + /// + public virtual bool TryGetCodeGen(out CodeGeneratorBase codeGen) + { + codeGen = null; + return false; } /// diff --git a/src/Core/Rexl.Harness/Harness.cs b/src/Core/Rexl.Harness/Harness.cs index 23c6873..38e9006 100644 --- a/src/Core/Rexl.Harness/Harness.cs +++ b/src/Core/Rexl.Harness/Harness.cs @@ -198,4 +198,43 @@ public void PostDiagnostic(DiagSource src, BaseDiagnostic diag, RexlNode nodeCtx if (diag is not null) Sink.PostDiagnostic(src, diag, nodeCtx); } + + /// + /// Base execution context class that knows about a harness and script context link. + /// + protected abstract class HarnessExecCtx : ExecCtx + where THarness : HarnessBase + { + protected readonly THarness _harness; + protected readonly Link _linkCtx; + + protected HarnessExecCtx(THarness harness, Link linkCtx) + : base() + { + Validation.AssertValue(harness); + Validation.AssertValueOrNull(linkCtx); + _harness = harness; + _linkCtx = linkCtx; + } + + public override void Log(int id, string msg) + { + } + + public override void Log(int id, string fmt, params object[] args) + { + } + + public override bool TryGetSink(out EvalSink sink) + { + sink = _harness.Sink; + return true; + } + + public override bool TryGetCodeGen(out CodeGeneratorBase codeGen) + { + codeGen = _harness._codeGen; + return true; + } + } } diff --git a/src/Core/Rexl.Harness/SimpleHarness.BlockRunner.cs b/src/Core/Rexl.Harness/SimpleHarness.BlockRunner.cs index 53e24b0..7c10aa1 100644 --- a/src/Core/Rexl.Harness/SimpleHarness.BlockRunner.cs +++ b/src/Core/Rexl.Harness/SimpleHarness.BlockRunner.cs @@ -231,12 +231,6 @@ protected override bool HandleExecException(Exception ex, RexlFormula fma) } #endregion From Harness.Handlers.cs - - protected override bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - return _outer.TryOptimizeMip(isMax, modSrc, imsr, solver, out score, out symValues); - } } private sealed class InnerSink : BlankEvalSink diff --git a/src/Core/Rexl.Harness/SimpleHarness.Module.cs b/src/Core/Rexl.Harness/SimpleHarness.Module.cs deleted file mode 100644 index ba46a96..0000000 --- a/src/Core/Rexl.Harness/SimpleHarness.Module.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Collections.Generic; - -using Microsoft.Rexl; -using Microsoft.Rexl.Code; -using Microsoft.Rexl.Private; -using Microsoft.Rexl.Sink; - -namespace Microsoft.Rexl.Harness; - -// This partial handles module related functionality. -partial class SimpleHarnessBase -{ - /// - /// Optimize the given measure in the given module. - /// REVIEW: This is a temporary hack. Optimization should really use a task. - /// - protected virtual RuntimeModule Optimize(int id, RuntimeModule modSrc, DName measure, bool isMax, DName solver) - { - if (modSrc is null) - return null; - - modSrc.Bnd.NameToIndex.TryGetValue(measure, out int imsr).Verify(); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - if (!TryOptimizeMip(isMax, modSrc, imsr, solver, out var score, out var symValues)) - return null; - - // REVIEW: Is there a good way that doesn't use reflection? - var typeRec = modSrc.Bnd.TypeRec; - var fact = _codeGen.TypeManager.CreateRecordFactory(typeRec); - var bldr = fact.Create().Open(partial: true); - var names = new HashSet(); - foreach (var pair in symValues) - { - names.Add(pair.name).Verify(); - if (pair.value is null) - continue; - var setter = fact.GetFieldSetter(pair.name, out _, out var stFld); - Validation.Assert(stFld.IsAssignableFrom(pair.value.GetType())); - setter(bldr, pair.value); - } - var rec = bldr.Close(); - - var modDst = modSrc.UpdateRaw(rec, names); - return modDst; - } - - protected virtual bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - var strSolver = solver.IsValid ? solver.Value : ""; - Sink.PostDiagnostic(DiagSource.Solver, MessageDiag.Error(ErrorStrings.ErrSolverUnkown_Name, strSolver)); - score = double.NaN; - symValues = null; - return false; - } -} diff --git a/src/Core/Rexl.Harness/SimpleHarness.cs b/src/Core/Rexl.Harness/SimpleHarness.cs index 28d7c0e..bd1fc18 100644 --- a/src/Core/Rexl.Harness/SimpleHarness.cs +++ b/src/Core/Rexl.Harness/SimpleHarness.cs @@ -49,7 +49,7 @@ protected override void ResetCoreInfo(bool init) protected override ExecCtx CreateExecCtx(CodeGenResult resCodeGen) { - return new OptExecCtx(this, SourceCur?.LinkCtx); + return new SimpleHarnessExecCtx(this, SourceCur?.LinkCtx); } /// @@ -138,35 +138,12 @@ protected override bool ProcessExpr(BoundNode bnd, object value, ExecCtx ctx) return _storage.LoadStreamAsync(linkCtx, link); } - protected class OptExecCtx : ExecCtx + protected class SimpleHarnessExecCtx : HarnessExecCtx + where THarness : SimpleHarnessBase { - protected readonly SimpleHarnessBase _harness; - protected readonly Link _linkCtx; - - public OptExecCtx(SimpleHarnessBase harness, Link linkCtx) - : base() - { - Validation.AssertValue(harness); - Validation.AssertValueOrNull(linkCtx); - _harness = harness; - _linkCtx = linkCtx; - } - - public override void Log(int id, string msg) - { - } - - public override void Log(int id, string fmt, params object[] args) - { - } - - /// - /// Optimize the given measure in the given module. - /// REVIEW: This is a temporary hack. Optimization should really use a task. - /// - public override RuntimeModule Optimize(int id, RuntimeModule src, DName measure, bool isMax, DName solver) + public SimpleHarnessExecCtx(THarness harness, Link linkCtx) + : base(harness, linkCtx) { - return _harness.Optimize(id, src, measure, isMax, solver); } public override Stream LoadStream(Link link, int id) diff --git a/src/Core/Rexl.Solve/Functions/Module.Gen.cs b/src/Core/Rexl.Solve/Functions/Module.Gen.cs index 3123452..ed6c8f8 100644 --- a/src/Core/Rexl.Solve/Functions/Module.Gen.cs +++ b/src/Core/Rexl.Solve/Functions/Module.Gen.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Reflection; using Microsoft.Rexl.Bind; @@ -60,12 +61,28 @@ public static RuntimeModule Exec( Validation.Assert(solver is null || DName.IsValidDName(solver)); Validation.AssertValue(ctx); - // REVIEW: Going through the exec ctx is a temporary hack. - var res = ctx.Optimize(id, src, new DName(measure), isMax, solver is null ? default : new DName(solver)); - if (res is null) + if (!ctx.TryGetSink(out var sink)) + { + ctx.Log(id, "Optimization not supported"); return null; + } - Validation.Assert(res is RuntimeModule); - return (RuntimeModule)res; + if (!ctx.TryGetCodeGen(out var codeGen)) + { + ctx.Log(id, "Optimization not supported"); + return null; + } + + src.Bnd.NameToIndex.TryGetValue(new DName(measure), out int imsr).Verify(); + Validation.AssertIndex(imsr, src.Bnd.Symbols.Length); + Validation.Assert(src.Bnd.Symbols[imsr].IsMeasureSym); + + if (!Solve.MipSolver.TryOptimize(sink, codeGen, isMax, src, imsr, + solver is null ? default : new DName(solver), out var score, out var symValues)) + { + return null; + } + + return src.Update(symValues); } } diff --git a/src/Test/Baseline/Code/CodeGen/Module/IL/Basic.txt b/src/Test/Baseline/Code/CodeGen/Module/IL/Basic.txt index 89b94da..8f972d7 100644 --- a/src/Test/Baseline/Code/CodeGen/Module/IL/Basic.txt +++ b/src/Test/Baseline/Code/CodeGen/Module/IL/Basic.txt @@ -64,6 +64,20 @@ make_module_record(Arr, (i8,i8)):{i8,i8} 1) ret Total Size: 52 +set_module_value_item(Arr, (i8,i8), i4, obj):(i8,i8) + 1) ldarg.2 [i4] + 13) switch [1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8)::_F0:i8 + Label [0]: + 1) ldarg.1 [(i8,i8)] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -79,10 +93,13 @@ top(Arr, Arr):obj 5) ldelem [Func<(i8,i8),{i8,i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(i8,i8),i4,obj,(i8,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, Func<(i8,i8),i4,obj,(i8,i8)>, BndModuleNode) 1) ret - Total Size: 45 + Total Size: 52 Func sig: () to M{param A:i8, const B:i8} Type: RuntimeModule<{i8,i8},(i8,i8)>, Value: module symbols: @@ -277,6 +294,32 @@ make_module_record(Arr, (i8,i8,i8,i8,i8,i8,i8,i8,bool)):{i8,i8,bool,i8,i8,i 1) ret Total Size: 113 +set_module_value_item(Arr, (i8,i8,i8,i8,i8,i8,i8,i8,bool), i4, obj):(i8,i8,i8,i8,i8,i8,i8,i8,bool) + 1) ldarg.2 [i4] + 41) switch [1,2,0,0,0,3,0,0,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,i8,i8,i8,i8,i8,i8,i8,bool)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8,i8,i8,i8,i8,i8,i8,bool)::_F0:i8 + 5) br [0] + Label [2]: + 1) ldarg.1 [(i8,i8,i8,i8,i8,i8,i8,i8,bool)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8,i8,i8,i8,i8,i8,i8,bool)::_F1:i8 + 5) br [0] + Label [3]: + 1) ldarg.1 [(i8,i8,i8,i8,i8,i8,i8,i8,bool)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8,i8,i8,i8,i8,i8,i8,bool)::_F5:i8 + Label [0]: + 1) ldarg.1 [(i8,i8,i8,i8,i8,i8,i8,i8,bool)] + 1) ret + Total Size: 95 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -292,10 +335,13 @@ top(Arr, Arr):obj 5) ldelem [Func<(i8,i8,i8,i8,i8,i8,i8,i8,bool),{i8,i8,bool,i8,i8,i8,i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(i8,i8,i8,i8,i8,i8,i8,i8,bool),i4,obj,(i8,i8,i8,i8,i8,i8,i8,i8,bool)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8,bool,i8,i8,i8,i8},(i8,i8,i8,i8,i8,i8,i8,i8,bool)>(Func,(i8,i8,i8,i8,i8,i8,i8,i8,bool),{i8,i8,bool,i8,i8,i8,i8},(i8,i8,i8,i8,i8,i8,i8,i8,bool)>, (i8,i8,i8,i8,i8,i8,i8,i8,bool), Func<(i8,i8,i8,i8,i8,i8,i8,i8,bool),{i8,i8,bool,i8,i8,i8,i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8,bool,i8,i8,i8,i8},(i8,i8,i8,i8,i8,i8,i8,i8,bool)>(Func,(i8,i8,i8,i8,i8,i8,i8,i8,bool),{i8,i8,bool,i8,i8,i8,i8},(i8,i8,i8,i8,i8,i8,i8,i8,bool)>, (i8,i8,i8,i8,i8,i8,i8,i8,bool), Func<(i8,i8,i8,i8,i8,i8,i8,i8,bool),{i8,i8,bool,i8,i8,i8,i8}>, Func<(i8,i8,i8,i8,i8,i8,i8,i8,bool),i4,obj,(i8,i8,i8,i8,i8,i8,i8,i8,bool)>, BndModuleNode) 1) ret - Total Size: 46 + Total Size: 53 Func sig: () to M{param A:i8, param B:i8, con C:b, const K:i8, msr M:i8, var X:i8, let Y:i8} Type: RuntimeModule<{i8,i8,bool,i8,i8,i8,i8},(i8,i8,i8,i8,i8,i8,i8,i8,bool)>, Value: module symbols: @@ -382,6 +428,20 @@ make_module_record(Arr, (Seq,Seq,i8)):{i8,Seq} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,Seq,i8), i4, obj):(Seq,Seq,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq] + 5) stfld (Seq,Seq,i8)::_F1:Seq + Label [0]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ret + Total Size: 37 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -411,12 +471,15 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq,Seq,i8),{i8,Seq}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8)>(Func,(Seq,Seq,i8),{i8,Seq},(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8)>(Func,(Seq,Seq,i8),{i8,Seq},(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>, BndModuleNode) 5) callvirt RuntimeModule<{i8,Seq}>::GetRecord():{i8,Seq} 5) ldfld {i8,Seq}::_F1:Seq 1) ret - Total Size: 93 + Total Size: 100 Func sig: (:x) to i8* Sequence: Seq @@ -507,6 +570,20 @@ make_module_record(Arr, (Seq,Seq,i8)):{i8,Seq} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,Seq,i8), i4, obj):(Seq,Seq,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq] + 5) stfld (Seq,Seq,i8)::_F1:Seq + Label [0]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ret + Total Size: 37 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -536,8 +613,11 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq,Seq,i8),{i8,Seq}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8)>(Func,(Seq,Seq,i8),{i8,Seq},(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8)>(Func,(Seq,Seq,i8),{i8,Seq},(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>, BndModuleNode) 1) stloc.1 [RuntimeModule<{i8,Seq}>] 5) newobj (Seq,i8)() 1) dup @@ -551,7 +631,7 @@ top(Arr, Arr):obj 5) ldfld {i8,Seq}::_F0:i8 5) stfld (Seq,i8)::_F1:i8 1) ret - Total Size: 123 + Total Size: 130 Func sig: (:x) to (i8*, i8) Type: (Seq,i8), Value: (Sequence: Seq @@ -644,6 +724,20 @@ make_module_record(Arr, (Seq,i8,i8)):{i8,i8} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,i8,i8), i4, obj):(Seq,i8,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (Seq,i8,i8)::_F1:i8 + Label [0]: + 1) ldarg.1 [(Seq,i8,i8)] + 1) ret + Total Size: 37 + set_module_items(Arr, Arr, (i8,i8), {i8,i8}):(i8,i8) 1) ldarg.1 [Arr] 1) ldc.i4.2 @@ -703,6 +797,20 @@ make_module_record(Arr, (i8,i8)):{i8,i8} 1) ret Total Size: 52 +set_module_value_item(Arr, (i8,i8), i4, obj):(i8,i8) + 1) ldarg.2 [i4] + 13) switch [1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8)::_F0:i8 + Label [0]: + 1) ldarg.1 [(i8,i8)] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -718,11 +826,14 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq,i8,i8),{i8,i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,i8,i8),i4,obj,(Seq,i8,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8},(Seq,i8,i8)>(Func,(Seq,i8,i8),{i8,i8},(Seq,i8,i8)>, (Seq,i8,i8), Func<(Seq,i8,i8),{i8,i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8},(Seq,i8,i8)>(Func,(Seq,i8,i8),{i8,i8},(Seq,i8,i8)>, (Seq,i8,i8), Func<(Seq,i8,i8),{i8,i8}>, Func<(Seq,i8,i8),i4,obj,(Seq,i8,i8)>, BndModuleNode) 1) stloc.0 [RuntimeModule<{i8,i8}>] 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [Func,(i8,i8),{i8,i8},(i8,i8)>] 1) dup 1) ldc.i4.4 @@ -731,12 +842,15 @@ top(Arr, Arr):obj 1) ldnull 5) callvirt Func,(i8,i8),{i8,i8},(i8,i8)>::Invoke(Arr, (i8,i8), {i8,i8}):(i8,i8) 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [Func<(i8,i8),{i8,i8}>] 1) ldarg.0 [Arr] - 1) ldc.i4.5 + 1) ldc.i4.6 + 5) ldelem [Func<(i8,i8),i4,obj,(i8,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.7 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, Func<(i8,i8),i4,obj,(i8,i8)>, BndModuleNode) 1) stloc.1 [RuntimeModule<{i8,i8}>] 5) newobj (RuntimeModule<{i8,i8}>,RuntimeModule<{i8,i8}>,Seq>)() 1) dup @@ -758,7 +872,7 @@ top(Arr, Arr):obj 5) stelem [RuntimeModule<{i8,i8}>] 5) stfld (RuntimeModule<{i8,i8}>,RuntimeModule<{i8,i8}>,Seq>)::_F2:Seq> 1) ret - Total Size: 138 + Total Size: 152 Func sig: () to (M{var X:i8, let Y:i8}, M{var X:i8, let Y:i8}, M{var X:i8, let Y:i8}*) Type: (RuntimeModule<{i8,i8}>,RuntimeModule<{i8,i8}>,Seq>), Value: (module symbols: @@ -861,6 +975,20 @@ make_module_record(Arr, (Seq,i8)):{i8} 1) ret Total Size: 40 +set_module_value_item(Arr, (Seq,i8), i4, obj):(Seq,i8) + 1) ldarg.2 [i4] + 13) switch [0,1] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (Seq,i8)::_F1:i8 + Label [0]: + 1) ldarg.1 [(Seq,i8)] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -876,8 +1004,11 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq,i8),{i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,i8),i4,obj,(Seq,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8},(Seq,i8)>(Func,(Seq,i8),{i8},(Seq,i8)>, (Seq,i8), Func<(Seq,i8),{i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8},(Seq,i8)>(Func,(Seq,i8),{i8},(Seq,i8)>, (Seq,i8), Func<(Seq,i8),{i8}>, Func<(Seq,i8),i4,obj,(Seq,i8)>, BndModuleNode) 1) stloc.0 [RuntimeModule<{i8}>] 5) newobj {i8}() 1) dup @@ -891,7 +1022,7 @@ top(Arr, Arr):obj 1) ldloc.1 [{i8}] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 1) stloc.1 [{i8}] @@ -916,7 +1047,7 @@ top(Arr, Arr):obj 5) stelem [{i8}] 5) stfld (RuntimeModule<{i8}>,{i8},Seq<{i8}>)::_F2:Seq<{i8}> 1) ret - Total Size: 135 + Total Size: 142 Func sig: () to (M{var X:i8}, {X:i8}, {X:i8}*) Type: (RuntimeModule<{i8}>,{i8},Seq<{i8}>), Value: (module symbols: @@ -1040,6 +1171,26 @@ make_module_record(Arr, (Seq,i8,r8,r8,r8)):{i8,r8} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,i8,r8,r8,r8), i4, obj):(Seq,i8,r8,r8,r8) + 1) ldarg.2 [i4] + 25) switch [0,1,0,0,2] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,i8,r8,r8,r8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (Seq,i8,r8,r8,r8)::_F1:i8 + 5) br [0] + Label [2]: + 1) ldarg.1 [(Seq,i8,r8,r8,r8)] + 1) ldarg.3 [obj] + 5) unbox.any [r8] + 5) stfld (Seq,i8,r8,r8,r8)::_F4:r8 + Label [0]: + 1) ldarg.1 [(Seq,i8,r8,r8,r8)] + 1) ret + Total Size: 62 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -1055,8 +1206,11 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq,i8,r8,r8,r8),{i8,r8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,i8,r8,r8,r8),i4,obj,(Seq,i8,r8,r8,r8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,r8},(Seq,i8,r8,r8,r8)>(Func,(Seq,i8,r8,r8,r8),{i8,r8},(Seq,i8,r8,r8,r8)>, (Seq,i8,r8,r8,r8), Func<(Seq,i8,r8,r8,r8),{i8,r8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,r8},(Seq,i8,r8,r8,r8)>(Func,(Seq,i8,r8,r8,r8),{i8,r8},(Seq,i8,r8,r8,r8)>, (Seq,i8,r8,r8,r8), Func<(Seq,i8,r8,r8,r8),{i8,r8}>, Func<(Seq,i8,r8,r8,r8),i4,obj,(Seq,i8,r8,r8,r8)>, BndModuleNode) 1) stloc.0 [RuntimeModule<{i8,r8}>] 5) newobj {i8,str}() 1) dup @@ -1073,7 +1227,7 @@ top(Arr, Arr):obj 1) ldloc.1 [{i8,str}] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 1) stloc.1 [{i8,str}] @@ -1114,7 +1268,7 @@ top(Arr, Arr):obj 1) ldloc.3 [{i8,str,r8}] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 5) stelem [{i8,str,r8}] @@ -1136,13 +1290,13 @@ top(Arr, Arr):obj 1) ldloc.3 [{i8,str,r8}] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 5) stelem [{i8,str,r8}] 5) stfld (RuntimeModule<{i8,r8}>,{i8,str},Seq<{i8,str,r8}>)::_F2:Seq<{i8,str,r8}> 1) ret - Total Size: 262 + Total Size: 269 Func sig: () to (M{var X:i8, var Z:r8}, {X:i8, Y:s}, {X:i8, Y:s, Z:r8?}*) Type: (RuntimeModule<{i8,r8}>,{i8,str},Seq<{i8,str,r8}>), Value: (module symbols: @@ -1230,6 +1384,20 @@ make_module_record(Arr, (i8,i8)):{i8,i8} 1) ret Total Size: 52 +set_module_value_item(Arr, (i8,i8), i4, obj):(i8,i8) + 1) ldarg.2 [i4] + 13) switch [1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8)::_F0:i8 + Label [0]: + 1) ldarg.1 [(i8,i8)] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -1245,8 +1413,11 @@ top(Arr, Arr):obj 5) ldelem [Func<(i8,i8),{i8,i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(i8,i8),i4,obj,(i8,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8},(i8,i8)>(Func,(i8,i8),{i8,i8},(i8,i8)>, (i8,i8), Func<(i8,i8),{i8,i8}>, Func<(i8,i8),i4,obj,(i8,i8)>, BndModuleNode) 1) stloc.0 [RuntimeModule<{i8,i8}>] 1) ldloc.0 [RuntimeModule<{i8,i8}>] 5) newobj {i8,i8}() @@ -1260,11 +1431,11 @@ top(Arr, Arr):obj 5) stfld {i8,i8}::_F0:i8 1) ldloc.1 [{i8,i8}] 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [HashSet] 5) callvirt RuntimeModule<{i8,i8}>::Update({i8,i8}, HashSet):RuntimeModule<{i8,i8}> 1) ret - Total Size: 82 + Total Size: 89 Func sig: () to M{param A:i8, const B:i8} Type: RuntimeModule<{i8,i8},(i8,i8)>, Value: module symbols: @@ -1384,6 +1555,26 @@ make_module_record(Arr, (i8,i8,{bool})):{i8,i8,{bool}} 1) ret Total Size: 91 +set_module_value_item(Arr, (i8,i8,{bool}), i4, obj):(i8,i8,{bool}) + 1) ldarg.2 [i4] + 17) switch [1,0,2] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,i8,{bool})] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,i8,{bool})::_F0:i8 + 5) br [0] + Label [2]: + 1) ldarg.1 [(i8,i8,{bool})] + 1) ldarg.3 [obj] + 5) unbox.any [{bool}] + 5) stfld (i8,i8,{bool})::_F2:{bool} + Label [0]: + 1) ldarg.1 [(i8,i8,{bool})] + 1) ret + Total Size: 54 + top(Arr, Arr):obj 1) ldarg.0 [Arr] 1) ldc.i4.0 @@ -1399,8 +1590,11 @@ top(Arr, Arr):obj 5) ldelem [Func<(i8,i8,{bool}),{i8,i8,{bool}}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(i8,i8,{bool}),i4,obj,(i8,i8,{bool})>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] - 5) newobj RuntimeModule<{i8,i8,{bool}},(i8,i8,{bool})>(Func,(i8,i8,{bool}),{i8,i8,{bool}},(i8,i8,{bool})>, (i8,i8,{bool}), Func<(i8,i8,{bool}),{i8,i8,{bool}}>, BndModuleNode) + 5) newobj RuntimeModule<{i8,i8,{bool}},(i8,i8,{bool})>(Func,(i8,i8,{bool}),{i8,i8,{bool}},(i8,i8,{bool})>, (i8,i8,{bool}), Func<(i8,i8,{bool}),{i8,i8,{bool}}>, Func<(i8,i8,{bool}),i4,obj,(i8,i8,{bool})>, BndModuleNode) 1) stloc.0 [RuntimeModule<{i8,i8,{bool}}>] 1) ldloc.0 [RuntimeModule<{i8,i8,{bool}}>] 5) newobj {i8,i8,{bool}}() @@ -1414,11 +1608,11 @@ top(Arr, Arr):obj 5) stfld {i8,i8,{bool}}::_F0:i8 1) ldloc.1 [{i8,i8,{bool}}] 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [HashSet] 5) callvirt RuntimeModule<{i8,i8,{bool}}>::Update({i8,i8,{bool}}, HashSet):RuntimeModule<{i8,i8,{bool}}> 1) ret - Total Size: 82 + Total Size: 89 Func sig: () to M{param A:i8, const B:i8, param C:{X:b}} Type: RuntimeModule<{i8,i8,{bool}},(i8,i8,{bool})>, Value: module symbols: diff --git a/src/Test/Baseline/Code/CodeGen/Module/IL/Externals.txt b/src/Test/Baseline/Code/CodeGen/Module/IL/Externals.txt index 7a13966..2ffb008 100644 --- a/src/Test/Baseline/Code/CodeGen/Module/IL/Externals.txt +++ b/src/Test/Baseline/Code/CodeGen/Module/IL/Externals.txt @@ -75,6 +75,20 @@ make_module_record(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8)):{i8,Seq<{r8,str}> 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8), i4, obj):(Seq<{r8,str}>,Seq<{r8,str}>,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq<{r8,str}>] + 5) stfld (Seq<{r8,str}>,Seq<{r8,str}>,i8)::_F1:Seq<{r8,str}> + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ret + Total Size: 37 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -115,11 +129,14 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.2 [(Seq<{r8,str}>)] - 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, BndModuleNode, (Seq<{r8,str}>)) + 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, BndModuleNode, (Seq<{r8,str}>)) 1) ret - Total Size: 107 + Total Size: 114 Func sig: (:x, T:{A:r8, B:s}*) to M{let Num:i8, var X:{A:r8, B:s}*} Type: RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>)>, Value: module symbols: @@ -255,6 +272,26 @@ make_module_record(Arr, (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)):{i8,i8,Seq<{r8 1) ret Total Size: 64 +set_module_value_item(Arr, (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8), i4, obj):(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8) + 1) ldarg.2 [i4] + 21) switch [1,0,2,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)::_F0:i8 + 5) br [0] + Label [2]: + 1) ldarg.1 [(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq<{r8,str}>] + 5) stfld (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)::_F2:Seq<{r8,str}> + Label [0]: + 1) ldarg.1 [(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ret + Total Size: 58 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -295,9 +332,12 @@ top(Arr, Arr):obj 5) ldelem [Func<(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,i8,Seq<{r8,str}>}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.2 [(Seq<{r8,str}>)] - 5) newobj RuntimeModule<{i8,i8,Seq<{r8,str}>},(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>)>(Func,(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,i8,Seq<{r8,str}>},(Seq<{r8,str}>),(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,i8,Seq<{r8,str}>}>, BndModuleNode, (Seq<{r8,str}>)) + 5) newobj RuntimeModule<{i8,i8,Seq<{r8,str}>},(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>)>(Func,(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,i8,Seq<{r8,str}>},(Seq<{r8,str}>),(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (i8,Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,i8,Seq<{r8,str}>}>, Func<(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(i8,Seq<{r8,str}>,Seq<{r8,str}>,i8)>, BndModuleNode, (Seq<{r8,str}>)) 1) stloc.3 [RuntimeModule<{i8,i8,Seq<{r8,str}>}>] 5) newobj (RuntimeModule<{i8,i8,Seq<{r8,str}>}>,RuntimeModule<{i8,i8,Seq<{r8,str}>}>)() 1) dup @@ -316,12 +356,12 @@ top(Arr, Arr):obj 5) stfld {i8,i8,Seq<{r8,str}>}::_F0:i8 2) ldloc.s [{i8,i8,Seq<{r8,str}>} (4)] 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [HashSet] 5) callvirt RuntimeModule<{i8,i8,Seq<{r8,str}>}>::Update({i8,i8,Seq<{r8,str}>}, HashSet):RuntimeModule<{i8,i8,Seq<{r8,str}>}> 5) stfld (RuntimeModule<{i8,i8,Seq<{r8,str}>}>,RuntimeModule<{i8,i8,Seq<{r8,str}>}>)::_F1:RuntimeModule<{i8,i8,Seq<{r8,str}>}> 1) ret - Total Size: 164 + Total Size: 171 Func sig: (:x, T:{A:r8, B:s}*) to (M{param N:i8, let Num:i8, var X:{A:r8, B:s}*}, M{param N:i8, let Num:i8, var X:{A:r8, B:s}*}) Type: (RuntimeModule<{i8,i8,Seq<{r8,str}>}>,RuntimeModule<{i8,i8,Seq<{r8,str}>}>), Value: (module symbols: @@ -430,6 +470,20 @@ make_module_record(Arr, (Seq,Seq,i8)):{i8,Seq} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,Seq,i8), i4, obj):(Seq,Seq,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq] + 5) stfld (Seq,Seq,i8)::_F1:Seq + Label [0]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ret + Total Size: 37 + ForEach_1(Arr, i8):RuntimeModule<{i8,Seq}> 5) newobj (i8)() 1) stloc.0 [(i8)] @@ -468,11 +522,16 @@ ForEach_1(Arr, i8):RuntimeModule<{i8,Seq}> 1) ldc.i4.0 5) ldelem [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.0 + 5) ldelem [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.0 [(i8)] - 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8),(i8)>(Func,(Seq,Seq,i8),{i8,Seq},(i8),(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, BndModuleNode, (i8)) + 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8),(i8)>(Func,(Seq,Seq,i8),{i8,Seq},(i8),(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>, BndModuleNode, (i8)) 1) ret - Total Size: 113 + Total Size: 126 top(Arr, Arr):obj 1) ldarg.1 [Arr] @@ -720,6 +779,20 @@ make_module_record(Arr, (Seq,Seq,i8)):{i8,Seq} 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq,Seq,i8), i4, obj):(Seq,Seq,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq] + 5) stfld (Seq,Seq,i8)::_F1:Seq + Label [0]: + 1) ldarg.1 [(Seq,Seq,i8)] + 1) ret + Total Size: 37 + ForEach_1(Arr, i8):RuntimeModule<{i8,Seq}> 5) newobj ({i8,str})() 1) stloc.0 [({i8,str})] @@ -779,11 +852,16 @@ ForEach_1(Arr, i8):RuntimeModule<{i8,Seq}> 1) ldc.i4.0 5) ldelem [Arr] 1) ldc.i4.3 + 5) ldelem [Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.0 + 5) ldelem [Arr] + 1) ldc.i4.4 5) ldelem [BndModuleNode] 1) ldloc.0 [({i8,str})] - 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8),({i8,str})>(Func,(Seq,Seq,i8),{i8,Seq},({i8,str}),(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, BndModuleNode, ({i8,str})) + 5) newobj RuntimeModule<{i8,Seq},(Seq,Seq,i8),({i8,str})>(Func,(Seq,Seq,i8),{i8,Seq},({i8,str}),(Seq,Seq,i8)>, (Seq,Seq,i8), Func<(Seq,Seq,i8),{i8,Seq}>, Func<(Seq,Seq,i8),i4,obj,(Seq,Seq,i8)>, BndModuleNode, ({i8,str})) 1) ret - Total Size: 167 + Total Size: 180 top(Arr, Arr):obj 1) ldarg.1 [Arr] @@ -1033,6 +1111,20 @@ make_module_record(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8)):{i8,Seq<{r8,str}> 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8), i4, obj):(Seq<{r8,str}>,Seq<{r8,str}>,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq<{r8,str}>] + 5) stfld (Seq<{r8,str}>,Seq<{r8,str}>,i8)::_F1:Seq<{r8,str}> + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ret + Total Size: 37 + ForEach_1(Arr, i8):RuntimeModule<{i8,Seq<{r8,str}>}> 5) newobj (Seq<{r8,str}>,i8)() 1) stloc.0 [(Seq<{r8,str}>,i8)] @@ -1077,11 +1169,16 @@ ForEach_1(Arr, i8):RuntimeModule<{i8,Seq<{r8,str}>}> 1) ldc.i4.0 5) ldelem [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.0 + 5) ldelem [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.0 [(Seq<{r8,str}>,i8)] - 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>,i8)>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>,i8),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, BndModuleNode, (Seq<{r8,str}>,i8)) + 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>,i8)>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>,i8),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, BndModuleNode, (Seq<{r8,str}>,i8)) 1) ret - Total Size: 131 + Total Size: 144 top(Arr, Arr):obj 1) ldarg.1 [Arr] @@ -1345,6 +1442,20 @@ make_module_record(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8)):{i8,Seq<{r8,str}> 1) ret Total Size: 52 +set_module_value_item(Arr, (Seq<{r8,str}>,Seq<{r8,str}>,i8), i4, obj):(Seq<{r8,str}>,Seq<{r8,str}>,i8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [Seq<{r8,str}>] + 5) stfld (Seq<{r8,str}>,Seq<{r8,str}>,i8)::_F1:Seq<{r8,str}> + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,Seq<{r8,str}>,i8)] + 1) ret + Total Size: 37 + ForEach_1(Arr, i8):RuntimeModule<{i8,Seq<{r8,str}>}> 5) newobj (Seq<{r8,str}>,{i8,str})() 1) stloc.0 [(Seq<{r8,str}>,{i8,str})] @@ -1410,11 +1521,16 @@ ForEach_1(Arr, i8):RuntimeModule<{i8,Seq<{r8,str}>}> 1) ldc.i4.0 5) ldelem [Arr] 1) ldc.i4.3 + 5) ldelem [Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.0 + 5) ldelem [Arr] + 1) ldc.i4.4 5) ldelem [BndModuleNode] 1) ldloc.0 [(Seq<{r8,str}>,{i8,str})] - 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>,{i8,str})>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>,{i8,str}),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, BndModuleNode, (Seq<{r8,str}>,{i8,str})) + 5) newobj RuntimeModule<{i8,Seq<{r8,str}>},(Seq<{r8,str}>,Seq<{r8,str}>,i8),(Seq<{r8,str}>,{i8,str})>(Func,(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>},(Seq<{r8,str}>,{i8,str}),(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, (Seq<{r8,str}>,Seq<{r8,str}>,i8), Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),{i8,Seq<{r8,str}>}>, Func<(Seq<{r8,str}>,Seq<{r8,str}>,i8),i4,obj,(Seq<{r8,str}>,Seq<{r8,str}>,i8)>, BndModuleNode, (Seq<{r8,str}>,{i8,str})) 1) ret - Total Size: 185 + Total Size: 198 top(Arr, Arr):obj 1) ldarg.1 [Arr] @@ -1685,6 +1801,20 @@ make_module_record(Arr, (Seq<{r8,str}>,{r8,str},r8)):{{r8,str},r8} 1) ret Total Size: 79 +set_module_value_item(Arr, (Seq<{r8,str}>,{r8,str},r8), i4, obj):(Seq<{r8,str}>,{r8,str},r8) + 1) ldarg.2 [i4] + 17) switch [0,1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str},r8)] + 1) ldarg.3 [obj] + 5) unbox.any [{r8,str}] + 5) stfld (Seq<{r8,str}>,{r8,str},r8)::_F1:{r8,str} + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str},r8)] + 1) ret + Total Size: 37 + set_module_items_ext(Arr, Arr, ({r8,str},r8), {{r8,str},r8}, ({r8,str})):({r8,str},r8) 1) ldarg.1 [Arr] 1) ldc.i4.2 @@ -1757,6 +1887,20 @@ make_module_record(Arr, ({r8,str},r8)):{{r8,str},r8} 1) ret Total Size: 79 +set_module_value_item(Arr, ({r8,str},r8), i4, obj):({r8,str},r8) + 1) ldarg.2 [i4] + 13) switch [1,0] + 5) br [0] + Label [1]: + 1) ldarg.1 [({r8,str},r8)] + 1) ldarg.3 [obj] + 5) unbox.any [{r8,str}] + 5) stfld ({r8,str},r8)::_F0:{r8,str} + Label [0]: + 1) ldarg.1 [({r8,str},r8)] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -1788,9 +1932,12 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq<{r8,str}>,{r8,str},r8),{{r8,str},r8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq<{r8,str}>,{r8,str},r8),i4,obj,(Seq<{r8,str}>,{r8,str},r8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.2 [(Seq<{r8,str}>)] - 5) newobj RuntimeModule<{{r8,str},r8},(Seq<{r8,str}>,{r8,str},r8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str},r8),{{r8,str},r8},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str},r8)>, (Seq<{r8,str}>,{r8,str},r8), Func<(Seq<{r8,str}>,{r8,str},r8),{{r8,str},r8}>, BndModuleNode, (Seq<{r8,str}>)) + 5) newobj RuntimeModule<{{r8,str},r8},(Seq<{r8,str}>,{r8,str},r8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str},r8),{{r8,str},r8},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str},r8)>, (Seq<{r8,str}>,{r8,str},r8), Func<(Seq<{r8,str}>,{r8,str},r8),{{r8,str},r8}>, Func<(Seq<{r8,str}>,{r8,str},r8),i4,obj,(Seq<{r8,str}>,{r8,str},r8)>, BndModuleNode, (Seq<{r8,str}>)) 1) stloc.3 [RuntimeModule<{{r8,str},r8}>] 5) newobj ({r8,str})() 2) stloc.s [({r8,str}) (4)] @@ -1798,7 +1945,7 @@ top(Arr, Arr):obj 1) ldloc.1 [{r8,str}] 5) stfld ({r8,str})::_F0:{r8,str} 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [Func,({r8,str},r8),{{r8,str},r8},({r8,str}),({r8,str},r8)>] 1) dup 1) ldc.i4.4 @@ -1808,13 +1955,16 @@ top(Arr, Arr):obj 2) ldloc.s [({r8,str}) (4)] 5) callvirt Func,({r8,str},r8),{{r8,str},r8},({r8,str}),({r8,str},r8)>::Invoke(Arr, ({r8,str},r8), {{r8,str},r8}, ({r8,str})):({r8,str},r8) 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [Func<({r8,str},r8),{{r8,str},r8}>] 1) ldarg.0 [Arr] - 1) ldc.i4.5 + 1) ldc.i4.6 + 5) ldelem [Func<({r8,str},r8),i4,obj,({r8,str},r8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.7 5) ldelem [BndModuleNode] 2) ldloc.s [({r8,str}) (4)] - 5) newobj RuntimeModule<{{r8,str},r8},({r8,str},r8),({r8,str})>(Func,({r8,str},r8),{{r8,str},r8},({r8,str}),({r8,str},r8)>, ({r8,str},r8), Func<({r8,str},r8),{{r8,str},r8}>, BndModuleNode, ({r8,str})) + 5) newobj RuntimeModule<{{r8,str},r8},({r8,str},r8),({r8,str})>(Func,({r8,str},r8),{{r8,str},r8},({r8,str}),({r8,str},r8)>, ({r8,str},r8), Func<({r8,str},r8),{{r8,str},r8}>, Func<({r8,str},r8),i4,obj,({r8,str},r8)>, BndModuleNode, ({r8,str})) 2) stloc.s [RuntimeModule<{{r8,str},r8}> (5)] 5) newobj (RuntimeModule<{{r8,str},r8}>,RuntimeModule<{{r8,str},r8}>,Seq>)() 1) dup @@ -1836,7 +1986,7 @@ top(Arr, Arr):obj 5) stelem [RuntimeModule<{{r8,str},r8}>] 5) stfld (RuntimeModule<{{r8,str},r8}>,RuntimeModule<{{r8,str},r8}>,Seq>)::_F2:Seq> 1) ret - Total Size: 193 + Total Size: 207 Func sig: (T:{A:r8, B:s}*, R:{A:r8, B:s}) to (M{var X:{A:r8, B:s}, let Y:r8}, M{var X:{A:r8, B:s}, let Y:r8}, M{var X:{A:r8, B:s}, let Y:r8}*) Type: (RuntimeModule<{{r8,str},r8}>,RuntimeModule<{{r8,str},r8}>,Seq>), Value: (module symbols: @@ -1949,6 +2099,20 @@ make_module_record(Arr, (Seq<{r8,str}>,{r8,str})):{{r8,str}} 1) ret Total Size: 60 +set_module_value_item(Arr, (Seq<{r8,str}>,{r8,str}), i4, obj):(Seq<{r8,str}>,{r8,str}) + 1) ldarg.2 [i4] + 13) switch [0,1] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str})] + 1) ldarg.3 [obj] + 5) unbox.any [{r8,str}] + 5) stfld (Seq<{r8,str}>,{r8,str})::_F1:{r8,str} + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str})] + 1) ret + Total Size: 33 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -1980,9 +2144,12 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq<{r8,str}>,{r8,str}),{{r8,str}}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq<{r8,str}>,{r8,str}),i4,obj,(Seq<{r8,str}>,{r8,str})>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.2 [(Seq<{r8,str}>)] - 5) newobj RuntimeModule<{{r8,str}},(Seq<{r8,str}>,{r8,str}),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str}),{{r8,str}},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str})>, (Seq<{r8,str}>,{r8,str}), Func<(Seq<{r8,str}>,{r8,str}),{{r8,str}}>, BndModuleNode, (Seq<{r8,str}>)) + 5) newobj RuntimeModule<{{r8,str}},(Seq<{r8,str}>,{r8,str}),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str}),{{r8,str}},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str})>, (Seq<{r8,str}>,{r8,str}), Func<(Seq<{r8,str}>,{r8,str}),{{r8,str}}>, Func<(Seq<{r8,str}>,{r8,str}),i4,obj,(Seq<{r8,str}>,{r8,str})>, BndModuleNode, (Seq<{r8,str}>)) 1) stloc.3 [RuntimeModule<{{r8,str}}>] 5) newobj {{r8,str}}() 2) stloc.s [{{r8,str}} (4)] @@ -2005,7 +2172,7 @@ top(Arr, Arr):obj 2) ldloc.s [{{r8,str}} (4)] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 2) stloc.s [{{r8,str}} (4)] @@ -2030,7 +2197,7 @@ top(Arr, Arr):obj 5) stelem [{{r8,str}}] 5) stfld (RuntimeModule<{{r8,str}}>,{{r8,str}},Seq<{{r8,str}}>)::_F2:Seq<{{r8,str}}> 1) ret - Total Size: 193 + Total Size: 200 Func sig: (T:{A:r8, B:s}*, R:{A:r8, B:s}) to (M{var X:{A:r8, B:s}}, {X:{A:r8, B:s}}, {X:{A:r8, B:s}}*) Type: (RuntimeModule<{{r8,str}}>,{{r8,str}},Seq<{{r8,str}}>), Value: (module symbols: @@ -2169,6 +2336,26 @@ make_module_record(Arr, (Seq<{r8,str}>,{r8,str},i8,i8,i8)):{{r8,str},i8} 1) ret Total Size: 79 +set_module_value_item(Arr, (Seq<{r8,str}>,{r8,str},i8,i8,i8), i4, obj):(Seq<{r8,str}>,{r8,str},i8,i8,i8) + 1) ldarg.2 [i4] + 25) switch [0,1,0,0,2] + 5) br [0] + Label [1]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str},i8,i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [{r8,str}] + 5) stfld (Seq<{r8,str}>,{r8,str},i8,i8,i8)::_F1:{r8,str} + 5) br [0] + Label [2]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str},i8,i8,i8)] + 1) ldarg.3 [obj] + 5) unbox.any [i8] + 5) stfld (Seq<{r8,str}>,{r8,str},i8,i8,i8)::_F4:i8 + Label [0]: + 1) ldarg.1 [(Seq<{r8,str}>,{r8,str},i8,i8,i8)] + 1) ret + Total Size: 62 + top(Arr, Arr):obj 1) ldarg.1 [Arr] 1) ldc.i4.0 @@ -2200,9 +2387,12 @@ top(Arr, Arr):obj 5) ldelem [Func<(Seq<{r8,str}>,{r8,str},i8,i8,i8),{{r8,str},i8}>] 1) ldarg.0 [Arr] 1) ldc.i4.2 + 5) ldelem [Func<(Seq<{r8,str}>,{r8,str},i8,i8,i8),i4,obj,(Seq<{r8,str}>,{r8,str},i8,i8,i8)>] + 1) ldarg.0 [Arr] + 1) ldc.i4.3 5) ldelem [BndModuleNode] 1) ldloc.2 [(Seq<{r8,str}>)] - 5) newobj RuntimeModule<{{r8,str},i8},(Seq<{r8,str}>,{r8,str},i8,i8,i8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str},i8,i8,i8),{{r8,str},i8},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str},i8,i8,i8)>, (Seq<{r8,str}>,{r8,str},i8,i8,i8), Func<(Seq<{r8,str}>,{r8,str},i8,i8,i8),{{r8,str},i8}>, BndModuleNode, (Seq<{r8,str}>)) + 5) newobj RuntimeModule<{{r8,str},i8},(Seq<{r8,str}>,{r8,str},i8,i8,i8),(Seq<{r8,str}>)>(Func,(Seq<{r8,str}>,{r8,str},i8,i8,i8),{{r8,str},i8},(Seq<{r8,str}>),(Seq<{r8,str}>,{r8,str},i8,i8,i8)>, (Seq<{r8,str}>,{r8,str},i8,i8,i8), Func<(Seq<{r8,str}>,{r8,str},i8,i8,i8),{{r8,str},i8}>, Func<(Seq<{r8,str}>,{r8,str},i8,i8,i8),i4,obj,(Seq<{r8,str}>,{r8,str},i8,i8,i8)>, BndModuleNode, (Seq<{r8,str}>)) 1) stloc.3 [RuntimeModule<{{r8,str},i8}>] 5) newobj {{r8,str},r8}() 1) dup @@ -2231,7 +2421,7 @@ top(Arr, Arr):obj 2) ldloc.s [{{r8,str},r8} (4)] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.3 + 1) ldc.i4.4 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 2) stloc.s [{{r8,str},r8} (4)] @@ -2282,7 +2472,7 @@ top(Arr, Arr):obj 2) ldloc.s [{{r8,str},r8,i8} (6)] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 5) stelem [{{r8,str},r8,i8}] @@ -2320,13 +2510,13 @@ top(Arr, Arr):obj 2) ldloc.s [{{r8,str},r8,i8} (6)] 1) dup 1) ldarg.0 [Arr] - 1) ldc.i4.4 + 1) ldc.i4.5 5) ldelem [RecordRuntimeTypeInfo] 5) stfld {}::_rrti:RecordRuntimeTypeInfo 5) stelem [{{r8,str},r8,i8}] 5) stfld (RuntimeModule<{{r8,str},i8}>,{{r8,str},r8},Seq<{{r8,str},r8,i8}>)::_F2:Seq<{{r8,str},r8,i8}> 1) ret - Total Size: 402 + Total Size: 409 Func sig: (T:{A:r8, B:s}*, R:{A:r8, B:s}) to (M{var X:{A:r8, B:s}, var Z:i8}, {X:{A:r8, B:s}, Y:r8}, {X:{A:r8, B:s}, Y:r8?, Z:i8?}*) Type: (RuntimeModule<{{r8,str},i8}>,{{r8,str},r8},Seq<{{r8,str},r8,i8}>), Value: (module symbols: diff --git a/src/Test/Rexl.Code.TestBase/BlockTestsBase.cs b/src/Test/Rexl.Code.TestBase/BlockTestsBase.cs index 36da565..7396449 100644 --- a/src/Test/Rexl.Code.TestBase/BlockTestsBase.cs +++ b/src/Test/Rexl.Code.TestBase/BlockTestsBase.cs @@ -349,9 +349,16 @@ public override void Log(int id, string fmt, params object[] args) { } - public override RuntimeModule Optimize(int id, RuntimeModule src, DName measure, bool isMax, DName solver) + public override bool TryGetSink(out EvalSink sink) { - return _harness.Optimize(id, src, measure, isMax, solver); + sink = _harness.Sink; + return true; + } + + public override bool TryGetCodeGen(out CodeGeneratorBase codeGen) + { + codeGen = _harness._codeGen; + return true; } public override Stream LoadStream(Link link, int id) @@ -569,16 +576,6 @@ protected override DateTimeOffset Now() return new DateTimeOffset(2022, 9, 21, 22, 25, 34, 877, new TimeSpan(3, 15, 0)); } - protected override bool TryOptimizeMip(bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - return _parent.TryOptimizeMip(Sink, _codeGen, isMax, modSrc, imsr, solver, out score, out symValues); - } - private sealed class SinkImpl : FlushEvalSink { private readonly TestHarness _parent; @@ -676,23 +673,6 @@ protected virtual bool TryHandleValue(EvalSink sink, CodeGeneratorBase codeGen, return false; } - protected virtual bool TryOptimizeMip(EvalSink sink, CodeGeneratorBase codeGen, - bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(sink); - Validation.AssertValue(codeGen); - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - var strSolver = solver.IsValid ? solver.Value : ""; - sink.PostDiagnostic(DiagSource.Solver, MessageDiag.Error(ErrorStrings.ErrSolverUnkown_Name, strSolver)); - score = double.NaN; - symValues = null; - return false; - } - protected Task ProcessFileWithIL(string pathHead, string pathTail, string text, TOpts options) { return ProcessFileCoreAsync(pathHead, pathTail, text, withIL: true); diff --git a/src/Test/Rexl.Solve.Test/ModuleTests.cs b/src/Test/Rexl.Solve.Test/ModuleTests.cs index c22f69f..566c5cd 100644 --- a/src/Test/Rexl.Solve.Test/ModuleTests.cs +++ b/src/Test/Rexl.Solve.Test/ModuleTests.cs @@ -107,19 +107,6 @@ public override void Warn(BoundNode bnd, StringId msg) } } - protected override bool TryOptimizeMip(EvalSink sink, CodeGeneratorBase codeGen, - bool isMax, RuntimeModule modSrc, int imsr, DName solver, - out double score, out List<(DName name, object value)> symValues) - { - Validation.AssertValue(sink); - Validation.AssertValue(codeGen); - Validation.AssertValue(modSrc); - Validation.AssertIndex(imsr, modSrc.Bnd.Symbols.Length); - Validation.Assert(modSrc.Bnd.Symbols[imsr].IsMeasureSym); - - return MipSolver.TryOptimize(sink, codeGen, isMax, modSrc, imsr, solver, out score, out symValues); - } - [TestMethod] public async Task ModuleReduceBaselineTests() {