[code-reflection] RFR: 8324789: Add line number information to code models [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Apr 25 10:53:38 UTC 2024


On Tue, 23 Apr 2024 23:15:06 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Enable operations to have originating source location information, specifically source reference, line and column information.
>> 
>> The location information may be set (one or more times) on an operation while it is unbound. Once it is bound, when it is a member of a block and that block is bound, it can no longer be set. Copying an operation will also copy the location. This enables preservation when transforming, especially for lowering.
>> 
>> The compiler generates location information from a tree node, and sets it on the associated operation(s). For the operations associated with a reflected method (FuncOp) or quoted lambda expression (LambdaOp or ClosureOp) the source reference (a URI) is added to the location, whereas for all other operations the source reference is absent.
>> 
>> Example:
>> 
>> 
>>     @CodeReflection                          // 47
>>     static int f(int n) {                    // 48
>>         int sum = 0;                         // 49
>>         for (int i = 0; i < n; i++)  {       // 50
>>             sum += i;                        // 51
>>         }                                    // 52
>>         return sum;                          // 53
>>     }                                        // 54
>> 
>> 
>> Model:
>> 
>> 
>> func @"f" @loc="47:5:file:///Users/sandoz/Projects/jdk/test/babylon-test/src/test/java/T.java" (%0 : int)int -> {
>>     %1 : Var<int> = var %0 @"n" @loc="47:5";
>>     %2 : int = constant @"0" @loc="49:19";
>>     %3 : Var<int> = var %2 @"sum" @loc="49:9";
>>     java.for @loc="50:9"
>>         ()Var<int> -> {
>>             %4 : int = constant @"0" @loc="50:22";
>>             %5 : Var<int> = var %4 @"i" @loc="50:14";
>>             yield %5 @loc="50:9";
>>         }
>>         (%6 : Var<int>)boolean -> {
>>             %7 : int = var.load %6 @loc="50:25";
>>             %8 : int = var.load %1 @loc="50:29";
>>             %9 : boolean = lt %7 %8 @loc="50:25";
>>             yield %9 @loc="50:9";
>>         }
>>         (%10 : Var<int>)void -> {
>>             %11 : int = var.load %10 @loc="50:32";
>>             %12 : int = constant @"1" @loc="50:32";
>>             %13 : int = add %11 %12 @loc="50:32";
>>             var.store %10 %13 @loc="50:32";
>>             yield @loc="50:9";
>>         }
>>         (%14 : Var<int>)void -> {
>>             %15 : int = var.load %3 @loc="51:13";
>>             %16 : int = var.load %14 @loc="51:20";
>>             %17 : int = add %15 %16 @loc="51:13";
>>             var.store %3 %17 @loc="51:13";
>>           ...
>
> Paul Sandoz has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Cleanup

Marked as reviewed by mcimadamore (Reviewer).

-------------

PR Review: https://git.openjdk.org/babylon/pull/54#pullrequestreview-2022169053


More information about the babylon-dev mailing list