You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "uschindler (via GitHub)" <gi...@apache.org> on 2025/05/01 17:33:24 UTC

[PR] Refactors the Expressions compiler to use the official ClassData BSM for indexed lookup [lucene]

uschindler opened a new pull request, #14602:
URL: https://github.com/apache/lucene/pull/14602

   With more review of the code, I thought that it would be better to use one of the default Bootstrap methods available for ClassData. This allows to get rid of our custom BSM method and just use the same. By default it is possible to supply a `List` as ClassData and the bootstrap gets the MethodHandle by index. The code for that index was already there and is now reused. Like for the variables, the index is incremented on each new constant (like on each variable) and the index used for lookup.
   
   As this change is simple it can also be backported, in the backport I just need to adapt the ASM 'Handle` to point to the default ClassData bootstrap method.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Refactor the expressions compiler to use official ClassData BSM with indexed lookup [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #14602:
URL: https://github.com/apache/lucene/pull/14602#issuecomment-2845434333

   The backport is the following commit: 6fb9dee0e2078a6044dd3a5c0020736f14fb2f5a


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Refactor the expressions compiler to use official ClassData BSM with indexed lookup [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #14602:
URL: https://github.com/apache/lucene/pull/14602#issuecomment-2845371799

   @s1monw it should be same function, not similar!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Refactors the Expressions compiler to use the official ClassData BSM for indexed lookup [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #14602:
URL: https://github.com/apache/lucene/pull/14602#issuecomment-2845328503

   I also added a new test to make sure that using the same function two times works correct.
   
   ```java
     public void testSameFunctionTwoTimes() throws Exception {
       Expression expr = compile("sqrt(20)+abs(-7)+sqrt(30)");
       assertEquals(Math.sqrt(20) + 7 + Math.sqrt(30), expr.evaluate(null), DELTA);
     }
   ```
   
   I also verified the bytecode, now looks like this:
   
   ```
   //  (version 24 : 68.0, no super bit)
   public final class org.apache.lucene.expressions.js.JavascriptCompiler$CompiledExpression extends org.apache.lucene.expressions.Expression {
     
     // Method descriptor #6 (Ljava/lang/String;[Ljava/lang/String;)V
     // Stack: 3, Locals: 3
     public JavascriptCompiler$CompiledExpression(java.lang.String arg0, java.lang.String[] arg1);
       0  aload_0 [this]
       1  aload_1 [arg0]
       2  aload_2 [arg1]
       3  invokespecial org.apache.lucene.expressions.Expression(java.lang.String, java.lang.String[]) [8]
       6  return
   
     
     // Method descriptor #10 ([Lorg/apache/lucene/search/DoubleValues;)D
     // Stack: 5, Locals: 2
     public double evaluate(org.apache.lucene.search.DoubleValues[] arg0) throws java.io.IOException;
        0  ldc <Dynamic> 0 _ java.lang.invoke.MethodHandle [22]
        2  ldc2_w <Double 20.0> [23]
        5  invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) : double [30]
        8  ldc <Dynamic> 1 _ java.lang.invoke.MethodHandle [32]
       10  ldc2_w <Double 7.0> [33]
       13  dneg
       14  invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) : double [30]
       17  dadd
       18  ldc <Dynamic> 0 _ java.lang.invoke.MethodHandle [22]
       20  ldc2_w <Double 30.0> [35]
       23  invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) : double [30]
       26  dadd
       27  dreturn
       28  aload_0 [this]
       29  invokestatic org.apache.lucene.expressions.js.JavascriptCompiler.patchStackTrace(java.lang.Throwable, org.apache.lucene.expressions.Expression) : java.lang.Throwable [44]
       32  athrow
         Exception Table:
           [pc: 0, pc: 28] -> 28 when : java.lang.Throwable
         Stack map table: number of frames 1
           [pc: 28, same_locals_1_stack_item, stack: {java.lang.Throwable}]
   
   Bootstrap methods:
     0 : # 18 invokestatic java/lang/invoke/MethodHandles.classDataAt:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;I)Ljava/lang/Object;
   	Method arguments:
   		#11 0,
     1 : # 18 invokestatic java/lang/invoke/MethodHandles.classDataAt:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;I)Ljava/lang/Object;
   	Method arguments:
   		#31 1
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Refactor the expressions compiler to use official ClassData BSM with indexed lookup [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler merged PR #14602:
URL: https://github.com/apache/lucene/pull/14602


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org