@@ -92,7 +92,10 @@ public class IRBuilderPrism extends IRBuilder<Node, DefNode, WhenNode, RescueNod
9292 byte [] source ;
9393 Nodes .Source nodeSource ;
9494 StaticScope staticScope ;
95- IdentityHashMap <byte [], RubySymbol > symbols = new IdentityHashMap <>();
95+ // This is originally sourced from ParseResult so that we only resolve symbols once per result instead of
96+ // one per scope. There is a little dance to set this ... we keep getting it from the parent scope
97+ // unless it is a method definition then we get reference from the lazymethoddefinition.
98+ IdentityHashMap <byte [], RubySymbol > symbols = null ;
9699 ThreadContext context ;
97100
98101 public IRBuilderPrism (IRManager manager , IRScope scope , IRBuilder parent , IRBuilder variableBuilder , Encoding encoding ) {
@@ -101,12 +104,19 @@ public IRBuilderPrism(IRManager manager, IRScope scope, IRBuilder parent, IRBuil
101104 if (parent != null ) {
102105 source = ((IRBuilderPrism ) parent ).source ;
103106 nodeSource = ((IRBuilderPrism ) parent ).nodeSource ;
107+ symbols = ((IRBuilderPrism ) parent ).symbols ;
108+ } else { // For END which is made without a parent and not setup by lazy method def.
109+ symbols = new IdentityHashMap <>();
104110 }
105111 staticScope = scope .getStaticScope ();
106112 staticScope .setFile (scope .getFile ()); // staticScope and IRScope contain the same field.
107113 context = manager .getRuntime ().getCurrentContext ();
108114 }
109115
116+ public void setSymbols (IdentityHashMap <byte [], RubySymbol > symbols ) {
117+ this .symbols = symbols ;
118+ }
119+
110120 // FIXME: Delete once we are no longer depedent on source code
111121 public void setSourceFrom (IRBuilderPrism other ) {
112122 if (other .nodeSource == null ) throw new RuntimeException ("WETF" );
@@ -130,6 +140,7 @@ public Operand build(ParseResult result) {
130140 this .executesOnce = false ;
131141 this .source = ((ParseResultPrism ) result ).getSource ();
132142 this .nodeSource = ((ParseResultPrism ) result ).getSourceNode ();
143+ this .symbols = ((ParseResultPrism ) result ).getSymbols ();
133144
134145// System.out.println("NAME: " + fileName);
135146// System.out.println(((ParseResultPrism) result).getRoot());
@@ -899,7 +910,7 @@ private Operand buildDef(DefNode node) {
899910 // FIXME: due to how lazy methods work we need this set on method before we actually parse the method.
900911 StaticScope staticScope = createStaticScopeFrom (node .locals , StaticScope .Type .LOCAL );
901912 staticScope .setSignature (calculateSignature (node .parameters ));
902- LazyMethodDefinition def = new LazyMethodDefinitionPrism (getManager ().getRuntime (), source , nodeSource , encoding , node );
913+ LazyMethodDefinition def = new LazyMethodDefinitionPrism (getManager ().getRuntime (), source , nodeSource , encoding , node , symbols );
903914
904915 if (node .receiver == null ) {
905916 return buildDefn (defineNewMethod (def , symbol (node .name ).getBytes (), getLine (node ), staticScope , true ));
@@ -2860,6 +2871,21 @@ private Operand buildModuleParent(Node parent) {
28602871 }
28612872
28622873 private RubySymbol symbol (byte [] bytes ) {
2874+ /*
2875+ var hit = symbols.get(bytes);
2876+
2877+ if (hit == null) {
2878+ hit = asSymbol(context, new ByteList(bytes, encoding));
2879+ if (hit.idString().charAt(0) == 'R') {
2880+ System.out.println("SAVING: " + hit + ", ENC: " + encoding);
2881+ }
2882+ symbols.put(bytes, hit);
2883+ } else {
2884+ //System.out.println("ALREADY FOUND: " + hit);
2885+ }
2886+
2887+ return hit;
2888+ */
28632889 return symbols .computeIfAbsent (bytes , (_b ) -> asSymbol (context , new ByteList (bytes , encoding )));
28642890 }
28652891
0 commit comments