direct linking -- Q on implementing

75 views
Skip to first unread message

David Miller

unread,
Nov 18, 2015, 1:20:21 AM11/18/15
to Clojure Dev
This topic is related to the CLR, so you may avert your eyes.  I do need some input for those-that-decide-things.

Direct linking causes some challenges over in CLR-land, primarily because ClojureCLR compiles into assemblies and assemblies can't have duplicate type names.  This becomes an issue because direct linking relies on fixed class names; redeclaring a function defines a new class with the same name.

This actually occurs when compiling core.  dotimes and assert-valid-fdecl each are defined twice.  I can work around dotimes, because it is a macro, by renaming the first definition and all mentions prior to the second definition.  Mentions macroexpand away and all is good.  Not so for assert-valid-fdecl.

A StaticInvokeExpr is not generated if the Var being invoked has isDynamic=true.  It is notable that assert-valid-decl has meta {:dynamic true} -- I'm guessing that is an artifact of the first, short-lived attempt at direct linking.

Q1:  Are there any problems making FnExpr.CanBeDirect depend on the Var not being dynamic? (Assuming I can find a good way to pass it in.)   (The JVM version would gain some reduction in bytecode size by doing this.)



This really only solved my problem compiling core.  More generally, I do not have a good solution for direct linking in the case of redefining functions.  I may have to say a dynamic declaration is necessary for the general case.  There might be a halfway solution (halfway between Var lookup and direct method invocation) involving storing delegates in a static field somewhere -- in this case I'll need some indication that a redeclaration is going to happen.


Q2: Any suggestions on a standard way to signal this?


The simpler case of a forward declaration I can handle more directly-- I think.  (Ugly detail: Define a MethodBuilder that can be referenced in statically-linked calls, but don't define its body until the real definition is seen -- not fun, but possible.)

Q3: Any suggestions? Anyone?

Thanks.

-David





Reply all
Reply to author
Forward
0 new messages