Welcome! Please see the About page for a little more info on how this works.

0 votes
in Compiler by

Minimal example, using 1.9.0-alpha11:

`
user=> (set! warn-on-reflection true)
true
user=> (defn foo ^String [^long x] "")

'user/foo

user=> (.length (foo 10))
Reflection warning, (...) - reference to field length on java.lang.Object can't be resolved.
0
`

The warning is present only if direct linking is disabled.

Explanation:
this is another manifestation of CLJ-1533 -- because of the lexical transformation the compiler is doing when routing the invoke through invokePrim, the arglists type hints are lost. This doesn't happen when DL is on because invokeStatic isn't compiled via a lexical transformation but through StaticInvokeExpr which properly tracks the original var's type hints

Patch: 0001-CLJ-2005-assoc-arglist-ret-tag-as-tag-in-constructed.patch

3 Answers

0 votes
by

Comment made by: bronsa

With DL on:
public static java.lang.Object invokeStatic();  descriptor: ()Ljava/lang/Object;    flags: ACC_PUBLIC, ACC_STATIC    Code:      stack=2, locals=0, args_size=0         0: ldc2_w        #12                 // long 10l         3: invokestatic  #18                 // Method test$foo.invokeStatic:(J)Ljava/lang/Object;         6: checkcast     #20                 // class java/lang/String         9: invokevirtual #24                 // Method java/lang/String.length:()I        12: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;        15: areturn      LineNumberTable:        line 5: 0        line 5: 9

with DL off:

public static java.lang.Object invokeStatic();    descriptor: ()Ljava/lang/Object;    flags: ACC_PUBLIC, ACC_STATIC    Code:      stack=3, locals=0, args_size=0         0: getstatic     #15                 // Field const__0:Lclojure/lang/Var;         3: invokevirtual #20                 // Method clojure/lang/Var.getRawRoot:()Ljava/lang/Object;         6: checkcast     #22                 // class clojure/lang/IFn$LO         9: ldc2_w        #23                 // long 10l        12: invokeinterface #28,  3           // InterfaceMethod clojure/lang/IFn$LO.invokePrim:(J)Ljava/lang/Object;        17: ldc           #30                 // String length        19: iconst_0        20: invokestatic  #36                 // Method clojure/lang/Reflector.invokeNoArgInstanceMember:(Ljava/lang/Object;Ljava/lang/String;Z)Ljava/lang/Object;        23: areturn      LineNumberTable:        line 5: 0        line 5: 12        line 5: 17

0 votes
by

Comment made by: bronsa

bytecode with DL off and current patch:

`

public static java.lang.Object invokeStatic();

descriptor: ()Ljava/lang/Object;
flags: ACC_PUBLIC, ACC_STATIC
Code:
  stack=3, locals=0, args_size=0
     0: getstatic     #15                 // Field const__0:Lclojure/lang/Var;
     3: invokevirtual #20                 // Method clojure/lang/Var.getRawRoot:()Ljava/lang/Object;
     6: checkcast     #22                 // class clojure/lang/IFn$LO
     9: ldc2_w        #23                 // long 10l
    12: invokeinterface #28,  3           // InterfaceMethod clojure/lang/IFn$LO.invokePrim:(J)Ljava/lang/Object;
    17: checkcast     #30                 // class java/lang/String
    20: invokevirtual #34                 // Method java/lang/String.length:()I
    23: invokestatic  #40                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    26: areturn
  LineNumberTable:
    line 5: 0
    line 5: 12
    line 5: 20

`

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2005 (reported by moxaj)
...