From 2d87a9b0e6f26c7a0fcf153feb1b9465371a96db Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Tue, 3 Jan 2012 18:26:24 -0800 Subject: [PATCH] Remove role memoization hack --- lib/Kernel.cs | 92 ++++++++++++++++--------------------------------- lib/ObjModel.cs | 2 -- 2 files changed, 29 insertions(+), 65 deletions(-) diff --git a/lib/Kernel.cs b/lib/Kernel.cs index 2571b9a4..3fa0a089 100644 --- a/lib/Kernel.cs +++ b/lib/Kernel.cs @@ -5363,9 +5363,6 @@ internal class MMDCandidate : MultiCandidate { public static Frame InstantiateRole(Frame th, Variable[] pcl) { STable prole = pcl[0].Fetch().mo; - string cache_key = ""; - bool cache_ok = true; - // get argument list - TODO make this saner P6any argv = pcl[1].Fetch(); Variable[] args = argv.mo == Kernel.ParcelMO ? @@ -5377,60 +5374,41 @@ internal class MMDCandidate : MultiCandidate { for (int i = 0; i < args.Length; i++) { P6any obj = args[i].Fetch(); to_pass[i] = NewROScalar(obj); - if (obj.mo == StrMO) { - string p = UnboxAny(obj); - cache_key += new string((char)p.Length, 1); - cache_key += p; - } else { - cache_ok = false; - } } - lock (prole) { - if (prole.mo.instCache == null) - prole.mo.instCache = new Dictionary(); - STable r; - if (cache_ok && - prole.mo.instCache.TryGetValue(cache_key, out r)) { + STable r; + Frame ifr = (Frame)RunInferior(prole.mo.roleFactory. + Invoke(GetInferiorRoot(), to_pass, null)).Fetch(); + + r = new STable(prole.name + "[...]"); + r.mo.type = P6how.ROLE; + r.mo.rtype = "role"; + r.mo.FillRole(prole.mo.superclasses.ToArray(), null); + r.typeObject = r.initObject = new P6opaque(r); + r.typeVar = r.initVar = NewROScalar(r.typeObject); + // Hack - reseat role to this closure-clone of methods + foreach (var mi in prole.mo.lmethods) { + var nmi = mi; + SubInfo orig = (SubInfo) nmi.impl.GetSlot("info"); + nmi.impl = ((Variable)ifr.info.dylex[orig.outervar]. + Get(ifr)).Fetch(); + r.mo.lmethods.Add(nmi); + } + foreach (var ai in prole.mo.local_attr) { + var nai = ai; + if (nai.init != null) { + SubInfo orig = (SubInfo) nai.init.GetSlot("info"); + nai.init = ((Variable)ifr.info. + dylex[orig.outervar].Get(ifr)).Fetch(); } - else { - Frame ifr = (Frame)RunInferior(prole.mo.roleFactory. - Invoke(GetInferiorRoot(), to_pass, null)).Fetch(); - - r = new STable(prole.name + "[...]"); - r.mo.type = P6how.ROLE; - r.mo.rtype = "role"; - r.mo.FillRole(prole.mo.superclasses.ToArray(), null); - r.typeObject = r.initObject = new P6opaque(r); - r.typeVar = r.initVar = NewROScalar(r.typeObject); - // Hack - reseat role to this closure-clone of methods - foreach (var mi in prole.mo.lmethods) { - var nmi = mi; - SubInfo orig = (SubInfo) nmi.impl.GetSlot("info"); - nmi.impl = ((Variable)ifr.info.dylex[orig.outervar]. - Get(ifr)).Fetch(); - r.mo.lmethods.Add(nmi); - } - foreach (var ai in prole.mo.local_attr) { - var nai = ai; - if (nai.init != null) { - SubInfo orig = (SubInfo) nai.init.GetSlot("info"); - nai.init = ((Variable)ifr.info. - dylex[orig.outervar].Get(ifr)).Fetch(); - } - r.mo.local_attr.Add(nai); - } - r.mo.Invalidate(); - if (cache_ok) - prole.mo.instCache[cache_key] = r; - } - th.resultSlot = r.typeVar; - return th; + r.mo.local_attr.Add(nai); } + r.mo.Invalidate(); + th.resultSlot = r.typeVar; + return th; } - private static STable DoRoleApply(STable b, - STable role) { + public static STable RoleApply(STable b, STable role) { STable n = new STable(b.name + " but " + role.name); if (role.mo.local_attr.Count != 0) throw new NieczaException("RoleApply with attributes NYI"); @@ -5454,18 +5432,6 @@ internal class MMDCandidate : MultiCandidate { return n; } - public static STable RoleApply(STable b, - STable role) { - lock (b) { - STable rs; - if (b.mo.butCache == null) - b.mo.butCache = new Dictionary(); - if (b.mo.butCache.TryGetValue(role, out rs)) - return rs; - return b.mo.butCache[role] = DoRoleApply(b, role); - } - } - internal static void SetTrace() { string trace = Environment.GetEnvironmentVariable("NIECZA_TRACE"); if (trace != null) { diff --git a/lib/ObjModel.cs b/lib/ObjModel.cs index 29799cba..45a186b9 100644 --- a/lib/ObjModel.cs +++ b/lib/ObjModel.cs @@ -166,8 +166,6 @@ public class P6how: IFreeze, IFixup { public HashSet isa = new HashSet(); internal SubscriberSet subclasses = new SubscriberSet(); Subscription[] mro_sub; - public Dictionary instCache; - public Dictionary butCache; // role type objects have an empty MRO cache so no methods can be // called against them; the fallback (NYI) is to pun. // }}}