NEXTGEN

Requirements: Java 1.5
              Ant

1. Check out Code
2. Setup environment
    export NGC_HOME=/path/to/nextgen
    soruce etc/bashrc 
1. Compiling: 
  ant clean compile
2. Compile Tests
  ant compile-tests
3. Execute Tests
  ant simpletests
  
Compiling nextgen sources: bin/ngc
Executing nextgen binaries: bin/nextgen

======== OLD RANDOM DEVELOPER SCRIBBLING BELOW =============
TODO
1. finish cleaning up generic signature stuff.. src/tools/Search.java (rename file too) and add to source
2. dynamic polymorphic method invokes dynamic inner class
3. check to see if dynamic inner class can be invoked from other generic type
==> both of these require passing this.
4. relative directory paths for methods
5. issue with template files.. e.g., compiling class A<T> with template A$$L{0}$$R
   if the file exists in '/', then it overrides somehow.. even though '/' is not
   on the classpath. This occurs even when '.' is the most immediate

in ant files use:
   compiler="edu.rice.cs.nextgen2.anttools.NextGenCompilerAdapter"


Compilation Process:
parse
enter
attr
flow
lower
flatten
transtypes

---saves---
2004.03.08: has working zip. improper collection of snippets for overloads and overrides.
2004.03.21: rewrote SP code for better method collect across matching methds
    : still need to rewrite VE.newMethodEnv to match (so snippets are unique)
    : then still need mves to genereate mves and refl

2004.06.27: almost fully functional. still dont have reflection. also
    having problems with current snippet env during invocations. 
    current snippet envs only have 1 parent. will refactor to ensure
    snippet envs follow heirarchy that parallels class structure. this
    allows more correct invocation
2004.08.09: working on SnippetProcessor: i think that methodgen.copy works
   except that it excludes attributes. going to simplify code and copy attrs
2004.09.03: working ngc. problem with correct snippet env
   tried to do based on implementation/definition. problem is that
   we need a lot of bridge methods.. ie interface + class defn
   => so going to move to impl based on introduction of typvars
   this will solve problems with interfaces (with same vars)
   ==> will still need some bridge methods when new typvars introduced
      (and subsequent reflection if they are called)
2004.09.16:reworking whole apply snippets.. transition. visitor envs screwed up,
    code in Flat, SnippetProcessor, still ok..
2004.10.02:full working implementation used for thesis. note:
   1. multiple compiles not completely handled
   2. multiple compiles require using base dir (no easy catch)
   3. parametric methods use S or D to prefix type
   4. reflection has not been tested yet.
  => reworking code to support basic mixins
2004.10.12: basic support for reflection (one test so far)
       : refl in bridge method in tpl class
todo:
+1. check if interfaces use supertype or interfaces? --> use interfaces
+2. need to copy resource to dest: todo in build.xml
/3. need to move flattening of grounded super classes to after erasure
   [current setup works. change symbol, preserve scope. (at end of meth)
+4. class snippets need to be stored. HashList<ClassSym, SnippetClosure>
/5. check VisitorEnv.toSnippets has correct types in 
    TypeCast, TypeTest, NewArray  [think so.]
+6. need to prefix snips with introduced class? A$$new$A$T or $new$A$T
    : case A<T>                 :A.new A<T> bound correctly
    : B<T> extends A<String>    :A.new A<String B.new A<T>
    : C<T> extends B<Integer>   :...   B.new A<Integer> C.new A<T>
     ==> need to prefix
+7. B extends A<String> needs correct name in symbol extends
      this is b/c type.supertype needs to be the flattened type
      was originally in SP. Might have questionable effects *CHECK*
   --> 1. invokespecial super calls have to be routed through the templ
       A<String>.fetch() rather than A.fetch() 
+8. super call needs invokespecial.
     super call methodSym has name "<init>" but ident uses Names._super
     so TreeMaker.Ident(...) does not work
9.  A<String>.fetch() rather than A.fetch() on supercalls
+10. check for need of class prefix on snips (same as 6)
+11. place template files in right directory
12. add in method param / singleton propagation
      static: create env, put snippets in env, fix up function calls
      dynamic: + check typarams, prefix method at call site,
   =need environment b/c method call may introduce addt'l typarams
+13. fix up class/field error in classfiles
   :this was b/c ONLY was defined as having ClassSymbol, rather than VarSymbol
+14. error with super call trying to be accessed
   : need to make sure supercall is PUBLIC (rather than private)
+14. check out class nextgen ground typing bug
   : need to short circuit copying of snippets

+15. figure out how to dynamic dispatch on method (reflection)
   meth { 
      String snip = this.getClass().toString() + "###hardcoded method name###"
      return Class.forName(snip).getField("ONLY").get(null).invoke(params);
   }

     > method snippets shouldnt have class prefix? cant do refl
          => class name cannot, but methods must
   Dynamic dispatch     [2004.03.08]
      List$$L{0}$$R.class
      List$$L{0}$$R$$E$$L{1}$$R
      String snip = ((List)this).getClass().toString() + #hardcoded
      return Class.forName(name).getField("ONLY").get(null).invoke(params);
    opts: 1. mve is inner class of param classes => no go. b/c not an instance
          2. param class is passed as param
       
       MVE.genSnippet: detect ctyparam snippet with free tvar => reqReflect
           => store SC.reflect  ->genSnippet    [meth body]
       MVE.<init>: reqRefl, free vars  =>
             => MVE.constructSnippet 
    Dynamic dispatch in mve snippet:
     snippet_meth(Ob src, ...)  { 
        String snip = src.getClass().toString() + "###hardcoded method name###"
        return Class.forName(snip).getField("ONLY")
            .get(null).getClass().getMethod("insert name here", Class[] param_types)
                   .invoke(params);
     }
        1. benefits: only refl if needed
        2. downside: refl on every call
     bridge_method(ParentEnv env0, ....) {
        String snip = ((List)this).getClass().toString() + 
                      env0.getClasS().toString().startsWith($$E);
        
        return real_method(Class.forName(snip).getField("ONLY").get(null), ...);
     }

         
16. if super class is completely flattened, 
    flattened superclass propagates substitutions  (ngc1 doesnt do that)
   => partial instantiations might be problematic:
   B<T> extends A<T, Foo>
+17. final methods ok for class? not ok for meths!
    b/c meth ones will overlap. class ones share if super flattened
18. figuring out typaram changes
     B<T> extends A<String>
     -- final Linked List  : only add in replacement
      A<T> extend Z
      B<X,Y> extends A<Y>
      C<S> extends B<S, String>

        --parsed by superType--  --real?--  --class-
        .                         <T>          A    : T->Y
        <Y>                       <X,Y>        B    : (X->S, Y->String)
        <S, String>               <S>          C    :
  :start with 
   -parsed by superType
   -meth -> methOwner: B<X,Y>
+ >>class: snippets collected from above
 >>method: snippets collected from below
     a. snippets based on meth typarams  => stored in MVE, can be collected
     b. snippets based on class typarams => stored in class, specialized
     c. snippets based on class/meth => 
          -> req MVE to incl class typarams. 
            -> can be collected, as long as no new typarams in subclass
              ->otherwise req reflection

+19. funny bug on A.Inner empty classes b/c this$0 incorrectly def
    => fixed when corrected NG code that wasnt spsed to be called
       check for list is null, list.isEmpty
/20. redo VisitorEnv to correct reflect snippets..
    owner, snippet prefix, etc..  MVE: uses containg class for owner
    which is overridden in SP.
   => pass the name in by hand. 
+21. propogate method snippets through heirarchy
   : method snippets short circuited by new defn.. 
   : but needs to be propagated to non-defn ones that override super
22. method snippet reflection: in cases where info not avail
    (related to 21. where typarams not avail)
+23. List<A> as param problem in jsr14?
      => used TreeInfo support class
+24. resolve conflicting snippets: overrides, same typarams, diff # of args
     => need to change snippets => name ok, but change hash
     List$make$$LA$$R    $$l java.lang.Object $$C Pair $$r [CLASS]
+25. need to rewrite snippet env gen code to use hash   [METH]
   to make sure 1 snippet env can work against many meths
+26. look for any other uses of snippetString
+27.   =>put cheeck to if env already made.. dontmake it (make around where snippets.length>0.
  just use hash to check?
    ==>2004.03.15: i think is already done since recursive short-circuite checks to see if menv is same
/28. no snippets short circuit: typarams just used to constrict args
  => not sure if this is possible. b/c parametric method calls require refl (recursive flow)
+29. recursive short circuiting
30. reconcile instantiation snippets: correct names. dynamic fixed,
    fix static ones? 
    +fix interfaces: b/c different meths need to hash to the same 
      (based on # typarams)
31. fix up implicit typaram inference: SnippetPatcher:709
     : need to check this one? this might work
     : this depends on if poly params can be passed
     : to param meths that are not rewriten, or have a different
     : set of typarams, that I dont recreate
+32. fix up Nextgen Class Loader to support <A>$$ENV<B>
    => $$ENV => $E
+33. same mve/different meth  short circuiting
    =>done. uses SP.snippetEnvEncode to translate
+34. fix bizzare aload_0 bug
     need ot make sure Symbols of vars in methods are VarSymbol not ClassSym
35. new array?
 : casting to A<T>, A<String> limited to A (GJ compatability?)
 - not sure if jsr14 supports many parametric array ops
36. figure out multiple aload_1? is that right? dynamic2
37. figureo ut aload_1 of mve + always checkcast
38. maybe need more sophisticated heirarchy marking for poly meths
    that reflects subclasses without overrides
    - must also incl partial overrides. (only some methods override)
39. quark is that Flat.genSnippet prefixes MVE snippets with mve sym that is discarded
40. different mve. maybe need snippet for visitApply to generate correct envs
**TODO**
   figure procedure to:
 + 1. collect snippets: 25, 27,28
 / 2. propagate snippets: 21, 38
  3. reflection: 22, 31
41. Parametric template class needs to be able to create snippet env
     this occurs when we have a dynamic method call a static method
   List<A> {
      public List<A> append(A x) { 
      	  return this.<A>make(x).prepend(this);
      }
   }
   => this.make(A$Env$$, x);
   tempClass.newA$env

   case if have mixture of class and method. 
42. problem when have poly meths call other w/o explicit params
    throws Exception, should use javac error mechanism
43. fix stack dump if no typvars specified on polymorphic method invocation (no dump!)
44. need to generate appropriate bridge meothods
    problem is: need to know if method override:
       method -> argtypes -> override
       argtypes depend on env types, env types need correct heirarchy to check them
       having correct heiarchy => knowing method types
       (this was optimization based on method definition/implementation)
          ::shouldnt this be able to be calculated in the compiler (Flat)
          ::if not, then bridge methods need to be done in SnippetProcessor
          ::otherwise have to go from string -> symbol.. no good
      
brdige method dont need new env if typevars the same
push up to pts where new vars incl


+Constants
+Util
+ListHash
-Flat   (only basic funcs, no flatten funcs)
TypeFlattener
SnippetPatcher
SnippetClosure
VisitorEnv
+TreeSnippeter  (didnt do array.. dont really understand it yet)


mixin notes
1. mixin meths prefixed by class
   issue with same class in diff packages
   this issue affects synthetic methods in different classes
   x.y.z.List extends a.b.c.List
2. meths defined in the interface bounds cannot be changed
3. b/c mixins can redef interfaces, interface meths need to be
   prefixed similiar to mixins.. hygiene...
4. 
qs: mixins
1. Assuming TS implements I.. what happens for TS<TS<A>>
  - should I be obscured? If so, need interface forwarding.
  - to do this, need to have a seperate instantation class to hold
    interface methods.. b/c they would overlap
  - also, if distinguished, can do upcast method execution
    this would be somewhat confusing for the option below?
    - if given an higher type, how do we downcast? 
2. Support TS<?>. if so then all TS instances must support same
  interface. req'd to analyze uniform extensions
  - if support TS<?> can we distinguish between TS<?> and TS<TS<?>>
3. How do we handle Magic<Locked<?>> and Key<Locked<?>> 

1. should distinguish diff in M<M<T>>
2. no TS<?>, should acces interface case M<T> extends T implements I<T>


     n-level..  Magic<?> Magic<Locked<?>>
qs: modules
1. modules should import/export types
2. syntax.. how would it work



>>notes to convert static to incl dynamic support
1. dynamic method envs:
   [select] A.exec: get type of A
   [      ] exec:  implicit this =>reflection

=> if recursive call
     ? type of receiver is same as this
     ? type of arguments same asthis
   optimization => pass already locally generated env

2. propagate snippets: method snippets go up

> assuming no  new typarams all snippets will be valid
   type at call site is the parent env
   (all envs can theoretically be collapsable to parent env)

> if allow new parameterization, 
  parent env snippet must use refl to find correct env.


Flat: 
  1. track methods
  2. process snippets
  3. process Apply calls

Snippet Patcher
  1. generate environments
  2. etc
----------------------------
Flat:
  1.track methods
  2. process snippets
  3. track Apply calls

Snippet Patcher
  1. process Apply calls:
  if recv type + arg types same:
     pass localEnv through
  else if (static forall): process like currently
  else if (dynamic forall): 
    else if have receiver type:
      generate mew snippet env
    else if not: b/c of this:
      reflection on this to get name (kinda like snippet one)
      or maybe can just call generic one => calls snippet one


Dynamic ME:
  1. class lowest: adj flatten in TF.genPolyTemplate
  2. class highest: move MVE tyyparams (constructor) Visitor.newMethodVisitorEnv
* no snippets => short circuit
  - none in def, or any in heirarchy (to preserve method overriding)
  => avoids bridge methods. => must calculate all snippets before rewrite


Method Environmnts: 
  Naming based on typarams
  Use/rewrite dependent on heirarchy => meth search reflects overwriting



mves:
1. collect: all same class overrides collected (if same typarams)
2. heirarchy: heirarchy based on class/method overrides
3. collect: subclass overrides halt collection
4. collect: subclass no override duplicates collection?
   => maybe not. if subclass not in hash => go to parent? 

parent: used for mve interfaces
parent: used on Apply mve (if need to move up)
child: used to collect snippets

1. record all methods
2. record parent

call site
  - always pass this
  - on need
     MVE.<init>  requires refl
    => MVE.constructSnippet
       :returns new Apply, and creates Snippetclosure
meth body
SC.<init> => Sc.genSnippet
  - record classes that req refl
  - record classes that dont
  - calculate on call

Resolve 665

 ----- notes ----
1. java.lang.reflect.InvocationTargetException
   -API states that this is thrown when interface/abstract class is called
   => reason is that code is instantiating *now* abstract base class. 
      rather than being parametric (jsr14 unchecked exception)
   Soln: make sure all types are parameterized
    [maybe make base class non-abstract for backward compatibility?
     or make it be objects]
java.lang.reflect.InvocationTargetException
Caused by: java.lang.InstantiationError: List

2. Static call rather than dynamic call:
   java.lang.reflect.InvocationTargetException
   Caused by: java.lang.IncompatibleClassChangeError

This is because one class is being invoked as another. Usually this is because
we are using the wrong var as the base class of method invocation
ie: 
(aload_0) A$$Env.make(), but if the method is dynamic, we need:
(aload_1) A$$Env.make()
A ClassSymbol (TYP) causes a static call, while a VarSymbol(VAR) is req for 
dynamic vars


3. invokespecial: used for super vs. invokevirtual (normal meths)

Same thing: invokation in this req VarSymbol
tree.selected (the selected AST in a Select) must
have a VarSymbol...
variables all use VarSymbols


0:    aload_0
1:    invokevirtual     java.lang.Object.getClass ()Ljava/lang/Class; (2)       
4:    pop

---- should be----
0:    aload_0
1:    invokevirtual     java.lang.Object.getClass ()Ljava/lang/Class; (4)
4:    pop

NOTES
1. if method defs are created and can be printed out during compilation, but
do not show in the bytecode, the symbol is not entered into the class symbol



1. figure out new casting test case..
  a.  Pair<?, String>
  b. remove double cast for (A<String>)(Object) new A<Integer>()


==== mixin steps.. start with basics
2. mixin issue: remove unneccessary check casts
1. check mixin instantiations for base types. ensure not final
   Caused by: java.lang.VerifyError: Cannot inherit from final class
.. similiar to check for class declarations

------------------ 
=== from to_read.txt
===
problem: mixin class: 
 rename identifier to template class name.
 prob is that unqualified var accesses must be checked 
 this causes problems since currentclass is mutated, but sym.owner  is not
===
===

===2. call site instantiations not dealt correctly as normal
      ListBuffer.toArray.. this issue relates to legacy class. no env
      what env to use?  1. prevent legacy support. ie cant use simply as 
      comparable. 2. l

3.  and also what i was looking at before.. call site instantiations
    envs have to track the recv type, but follow the chain to the correct name
4. abstract interfaces? see Aabonly

NOTE: if change debug flag and recompile NGUtil only, debug is not
   propagated.. maybe optimization of static final
================

------------------
x. use of a rawtype can cause this error.
x. maybe default ngc to compile -warnunchecked. or something.. maybe put an
x. error msg in the compiler
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at edu.rice.cs.nextgen2.classloader.Runner.runProgram(Runner.java:41)
        at edu.rice.cs.nextgen2.classloader.Runner.main(Runner.java:15)
Caused by: java.lang.InstantiationError: Iboth2
        at BridgeCheck2.main(BridgeCheck2.java:122)
        ... 6 more
java edu.rice.cs.nextgen2.classloader.Runner BridgeCheck2

svn copy svn+ssh://javaplt@greenland.cs.rice.edu/home/javaplt/.svnroot/nextgen2/trunk svn+ssh://javaplt@greenland.cs.rice.edu/home/javaplt/.svnroot/nextgen2/tags/release-1.0 -m "Stable version before new mixin work"