Changeset 2163

Show
Ignore:
Timestamp:
07/01/08 15:01:57 (3 months ago)
Author:
nbeckman
Message:

[Disambiguator] There are a lot of changes in this revision.
- I found this bug where tests would sometimes fail if they were run out of order. Added reset method to FTypeGeneric.
- The disambiguator now actually reports errors. This caused me to change a number of tests in very small ways.
- Most tests now run in a random order.
- We can disambiguate methods that are inherited.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Library/FortressLibrary.fss

    r2155 r2163  
    13551355immutableArray[\E\](x:ZZ32):ImmutableArray[\E,ZZ32\] = 
    13561356    __imm1(__Proxy[\E\],reflect(x)) 
     1357(* 
    13571358immutableArray[\E\](x:ZZ32,y:ZZ32):ImmutableArray[\E,(ZZ32,ZZ32)\] = 
    13581359    __imm2(__Proxy[\E\],reflect(x), reflect(y)) 
    13591360immutableArray[\E\](x:ZZ32,y:ZZ32,z:ZZ32):ImmutableArray[\E,(ZZ32,ZZ32,ZZ32)\] = 
    13601361    __imm3(__Proxy[\E\],reflect(x), reflect(y), reflect(z)) 
     1362*) 
    13611363 
    13621364(* This should be local to immutableArray, but we don't support local 
     
    17821784  opr |self| : ZZ32 = s0 s1 
    17831785  (* Translate from b0,b1-indexing to 0-indexing, checking bounds. *) 
    1784   offset(t:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do 
    1785     (a0,a1) = t 
     1786  offset(t_1:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do 
     1787    (a0,a1) = t_1 
    17861788    c0 = a0 - b0 
    17871789    c1 = a1 - b1 
     
    17941796    end 
    17951797  end 
    1796   toIndex(t:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do (a0,a1)=t; (a0+b0,a1+b1) end 
     1798  toIndex(t_1:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do (a0,a1)=t_1; (a0+b0,a1+b1) end 
    17971799  opr[x:ZZ32,y:ZZ32]:=(v:T):() = do self[ (x,y) ] := v end 
    17981800  opr[r:Range[\(ZZ32,ZZ32)\]]: Array[\T,(ZZ32,ZZ32)\] = do 
     
    18071809  opr[_:OpenRange[\Any\]] : Array2[\T,0,s0,0,s1\] = 
    18081810      subarray[\0,s0,0,s1,0,0\]() 
    1809   shift(t:(ZZ32,ZZ32)): Array[\T,(ZZ32,ZZ32)\] = do 
    1810       (o0,o1)=t 
     1811  shift(t_1:(ZZ32,ZZ32)): Array[\T,(ZZ32,ZZ32)\] = do 
     1812      (o0,o1)=t_1 
    18111813      if o0=0 AND o1=0 then 
    18121814          self 
     
    18611863        extends Array2[\T, b0, s0, b1, s1\] 
    18621864    mem:PrimitiveArray[\T, (s0 s1) \] = PrimitiveArray[\T, (s0 s1) \]() 
    1863     init0(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0(i s1 + j, v) end 
    1864     put(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put(i s1 + j, v) end 
    1865     get(t:(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(i s1 + j) end 
     1865    init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0(i s1 + j, v) end 
     1866    put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put(i s1 + j, v) end 
     1867    get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(i s1 + j) end 
    18661868end 
    18671869 
     
    18731875  replica[\U\]():Array2[\U,b0,s0,b1,s1\] = mem.replica[\U\]().t() 
    18741876 
    1875   init0(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0((j,i),v) end 
    1876   put(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put((j,i),v) end 
    1877   get(t:(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(j,i) end 
     1877  init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0((j,i),v) end 
     1878  put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put((j,i),v) end 
     1879  get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(j,i) end 
    18781880  t() = mem 
    18791881end 
     
    18921894        extends Array2[\T,b0,s0,b1,s1\] 
    18931895    index(a0:ZZ32, a1:ZZ32): (ZZ32,ZZ32) = (m0 a0 + o0, m1 a1 + o1) 
    1894     init0(t:(ZZ32,ZZ32), v:T): () = mem.init0(index(t),v) 
    1895     put(t:(ZZ32,ZZ32), v:T): () = mem.put(index(t),v) 
    1896     get(t:(ZZ32,ZZ32)): T = mem.get(index(t)) 
     1896    init0(t_1:(ZZ32,ZZ32), v:T): () = mem.init0(index(t_1),v) 
     1897    put(t_1:(ZZ32,ZZ32), v:T): () = mem.put(index(t_1),v) 
     1898    get(t_1:(ZZ32,ZZ32)): T = mem.get(index(t_1)) 
    18971899end 
    18981900 
     
    19051907        ivmap[\T\](fn (i:(ZZ32,ZZ32),e:T):T => e - v.get(i)) 
    19061908    opr -(self): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => - e) 
    1907     scale(t: T): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => t e) 
     1909    scale(t_1: T): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => t_1 e) 
    19081910    mul[\ nat s2 \](other: Matrix[\T,s1,s2\]): Matrix[\T,s0,s2\] = do 
    19091911        res = matrix[\T,s0,s2\]() 
     
    19661968    extends Matrix[\T, s0, s1\] 
    19671969  mem:PrimitiveArray[\T, (s0 s1) \] = PrimitiveArray[\T, (s0 s1) \]() 
    1968   init0(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0(i s1 + j, v) end 
    1969   put(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put(i s1 + j, v) end 
    1970   get(t:(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(i s1 + j) end 
     1970  init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0(i s1 + j, v) end 
     1971  put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put(i s1 + j, v) end 
     1972  get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(i s1 + j) end 
    19711973end 
    19721974 
     
    19751977    replica[\U\]():Array2[\U,0,s0,0,s1\] = mem.replica[\U\]().t() 
    19761978 
    1977     init0(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0((j,i),v) end 
    1978     put(t:(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put((j,i),v) end 
    1979     get(t:(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(j,i) end 
     1979    init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0((j,i),v) end 
     1980    put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put((j,i),v) end 
     1981    get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(j,i) end 
    19801982    t(): Matrix[\T,s1,s0\] = mem 
    19811983    add(v:TransposedMatrix[\T,s0,s1\]): Matrix[\T,s0,s1\] = mem.add(v.t()).t() 
     
    31693171opr :[\I extends Integral\](lo:I, hi:I): ParRange[\I\] = 
    31703172        ParRange[\I\](lo,hi-lo+1) 
    3171 opr :(lo:IntLiteral, ex:IntLiteral): ParRange[\ZZ32\] = 
     3173opr :(lo:IntLiteral, hi:IntLiteral): ParRange[\ZZ32\] = 
    31723174        ParRange[\ZZ32\](lo,hi-lo+1) 
    31733175opr :[\I extends Integral, J extends Integral\] 
  • trunk/Library/List.fss

    r2155 r2163  
    379379            fresh.appendR[\T\](other) 
    380380        end 
    381     appendL[\T\](left:List[\T\]): List[\E\] = do 
    382         lsz = |left
     381    appendL[\T\](left_1:List[\T\]): List[\E\] = do 
     382        lsz = |left_1
    383383        fstUsed = firstUsed - lsz 
    384         left.fill[\E\](fstUsed,underlying) 
     384        left_1.fill[\E\](fstUsed,underlying) 
    385385        ArrayList(underlying,fstUsed,oneShot(),firstUnused,canExtendRight) 
    386386      end 
    387     appendLC[\T\](left:List[\T\]): List[\E\] = 
    388         if leftSpace() >= |left| AND: canExtendLeft.tryOnce() then 
    389             appendL[\T\](left
    390         else 
    391             fresh = enlargeLeft[\E\](|left|) 
    392             fresh.appendL[\T\](left
     387    appendLC[\T\](left_1:List[\T\]): List[\E\] = 
     388        if leftSpace() >= |left_1| AND: canExtendLeft.tryOnce() then 
     389            appendL[\T\](left_1
     390        else 
     391            fresh = enlargeLeft[\E\](|left_1|) 
     392            fresh.appendL[\T\](left_1
    393393        end 
    394394 
  • trunk/Library/PureList.fss

    r2155 r2163  
    151151      it.generate[\R\](r,body) 
    152152  seq(self): SequentialGenerator[\E\] = SeqListGenerator[\E\](it) 
    153   opr ||(self, other:List[\E\]): List[\E\] = 
     153  opr ||(self, f:List[\E\]): List[\E\] = 
    154154      self || f.generate[\PureList[\E\]\](PLConcat[\E\],singleton[\E\]) 
    155155  opr ||(self, f:PureList[\E\]): PureList[\E\] = 
  • trunk/Library/Sparse.fss

    r1756 r2163  
    177177    replica[\U\]() = fail("Csc replica undefined") 
    178178    indexValuePairs():Generator[\((ZZ32,ZZ32),N)\] = 
    179         SparseGen[\N,((ZZ32,ZZ32),N)\](rows, 
     179        SparseGen[\N,((ZZ32,ZZ32),N)\](cols, 
    180180            fn (i:ZZ32,j:ZZ32,n:N):((ZZ32,ZZ32),N) => ((j,i),n)) 
    181181    zeroIndices():Generator[\(ZZ32,ZZ32)\] = 
    182         SparseGen[\N,(ZZ32,ZZ32)\](rows, 
     182        SparseGen[\N,(ZZ32,ZZ32)\](cols, 
    183183            fn (i:ZZ32,j:ZZ32,n:N):((ZZ32,ZZ32),N) => (j,i)) 
    184184    t() = Csr[\N,m,n\](cols) 
  • trunk/ProjectFortress/LibraryBuiltin/FortressBuiltin.fss

    r2155 r2163  
    185185    getter toString() : String = 
    186186        builtinPrimitive("com.sun.fortress.interpreter.glue.prim.String$ToString") 
    187     getter indices() : FullRange[\ZZ32\] = bounds() 
     187    getter indices() : FullRange[\ZZ32\] = self.bounds() 
    188188    getter generator() : Generator[\Char\] = 
    189189        indices().map[\Char\](fn (i:ZZ32):Char => self[i]) 
     
    208208        builtinPrimitive("com.sun.fortress.interpreter.glue.prim.String$Index") 
    209209    opr[r0:Range[\ZZ32\]] : String = do 
    210         r1 = (bounds())[r0] 
     210        r1 = (self.bounds())[r0] 
    211211        l = r1.lower() 
    212212        self.substr(l, l + |r1|) 
  • trunk/ProjectFortress/src/com/sun/fortress/Shell.java

    r2160 r2163  
    469469        // step, the rawApiEnv is stale and needs to be rebuilt with the new API ASTs. 
    470470        Disambiguator.ApiResult apiDR = 
    471             Disambiguator.disambiguateApis(apis, rawApiEnv); 
     471            Disambiguator.disambiguateApis(apis, rawApiEnv, _repository.apis()); 
    472472        if (!apiDR.isSuccessful()) { return apiDR.errors(); } 
    473  
    474         Disambiguator.ComponentResult componentDR = 
    475             Disambiguator.disambiguateComponents(components, env, 
    476                                                  rawComponentIR.components()); 
    477         if (!componentDR.isSuccessful()) { return componentDR.errors(); } 
    478  
    479         if (phase.equals("disambiguate")) 
    480             return IterUtil.empty(); 
    481473 
    482474        // Rebuild ApiIndices. 
     
    484476            IndexBuilder.buildApis(apiDR.apis(), System.currentTimeMillis()); 
    485477        if (!apiIR.isSuccessful()) { return apiIR.errors(); } 
     478         
     479        // Rebuild GlobalEnvironment. 
     480        GlobalEnvironment apiEnv = 
     481            new GlobalEnvironment.FromMap(CollectUtil.union(_repository.apis(), 
     482                                                            apiIR.apis())); 
     483         
     484        Disambiguator.ComponentResult componentDR = 
     485            Disambiguator.disambiguateComponents(components, apiEnv, 
     486                                                 rawComponentIR.components()); 
     487        if (!componentDR.isSuccessful()) { return componentDR.errors(); } 
     488 
     489        if (phase.equals("disambiguate")) 
     490            return IterUtil.empty(); 
    486491 
    487492        // Rebuild ComponentIndices. 
     
    490495                                         System.currentTimeMillis()); 
    491496        if (!componentIR.isSuccessful()) { return componentIR.errors(); } 
    492  
    493         // Rebuild GlobalEnvironment. 
    494         GlobalEnvironment apiEnv = 
    495             new GlobalEnvironment.FromMap(CollectUtil.union(_repository.apis(), 
    496                                                             apiIR.apis())); 
    497497 
    498498        // Rewrite grammars, see GrammarRewriter for more details. 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/Disambiguator.java

    r1912 r2163  
    3030 
    3131import edu.rice.cs.plt.collect.CollectUtil; 
     32import edu.rice.cs.plt.collect.Relation; 
    3233import edu.rice.cs.plt.iter.IterUtil; 
    3334 
     
    8283 */ 
    8384public class Disambiguator { 
    84  
    85     /** Result of {@link #disambiguateApis}. */ 
    86     public static class ApiResult extends StaticPhaseResult { 
    87         private final Iterable<Api> _apis; 
    88  
    89         public ApiResult(Iterable<Api> apis,  
    90                 Iterable<? extends StaticError> errors) { 
    91             super(errors); 
    92             _apis = apis; 
    93         } 
    94  
    95         public Iterable<Api> apis() { return _apis; } 
    96     } 
    97  
    98     /** 
    99      * Disambiguate the given apis. To support circular references, 
    100      * the apis should appear in the given environment. 
    101      */ 
    102     public static ApiResult disambiguateApis(Iterable<Api> apis, 
    103             GlobalEnvironment globalEnv) { 
    104         List<Api> results = new ArrayList<Api>(); 
    105         List<StaticError> errors = new ArrayList<StaticError>(); 
    106         for (Api api : apis) { 
    107             ApiIndex index = globalEnv.api(api.getName()); 
    108             NameEnv env = new TopLevelEnv(globalEnv, index, errors); 
    109             Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 
    110              
    111             SelfParamDisambiguator self_disambig = new SelfParamDisambiguator(); 
    112             Api spd_result = (Api)api.accept(self_disambig); 
    113              
    114             List<StaticError> newErrs = new ArrayList<StaticError>(); 
    115             TypeDisambiguator td =  
    116                 new TypeDisambiguator(env, onDemandImports, newErrs); 
    117             Api tdResult = (Api) spd_result.accept(td); 
    118             if (newErrs.isEmpty()) { 
    119                 ExprDisambiguator ed =  
    120                     new ExprDisambiguator(env, onDemandImports, newErrs); 
    121                 Api edResult = (Api) tdResult.accept(ed); 
    122                 if (newErrs.isEmpty()) { results.add(edResult); } 
    123             } 
    124  
    125             if (!newErrs.isEmpty()) {  
    126                 errors.addAll(newErrs);  
    127             } 
    128         } 
    129         results = disambiguateGrammarMembers(results, errors, globalEnv); 
    130         return new ApiResult(results, errors); 
    131     } 
    132  
    133  
    13485    /** 
    13586     * Disambiguate the names of nonterminals. 
     
    153104    } 
    154105 
     106    /** Result of {@link #disambiguateApis}. */ 
     107    public static class ApiResult extends StaticPhaseResult { 
     108        private final Iterable<Api> _apis; 
     109 
     110        public ApiResult(Iterable<Api> apis,  
     111                Iterable<? extends StaticError> errors) { 
     112            super(errors); 
     113            _apis = apis; 
     114        } 
     115 
     116        public Iterable<Api> apis() { return _apis; } 
     117    } 
     118 
     119    /** 
     120     * Disambiguate the given apis. To support circular references, 
     121     * the apis should appear in the given environment. 
     122     * @param apis_to_disambiguate Apis currently being disambiguated. 
     123     * @param globalEnv The current global environment. 
     124     * @param repository_apis Apis that already exist in the repository. 
     125     */ 
     126    public static ApiResult disambiguateApis(Iterable<Api> apis_to_disambiguate, 
     127            GlobalEnvironment globalEnv, Map<APIName, ApiIndex> repository_apis) { 
     128         
     129        List<StaticError> errors = new ArrayList<StaticError>(); 
     130         
     131        // First, loop through apis disambiguating types. 
     132        List<Api> new_apis = new ArrayList<Api>(); 
     133        for( Api api : apis_to_disambiguate ) { 
     134                 ApiIndex index = globalEnv.api(api.getName()); 
     135             NameEnv env = new TopLevelEnv(globalEnv, index, errors); 
     136             Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 
     137              
     138             SelfParamDisambiguator self_disambig = new SelfParamDisambiguator(); 
     139             Api spd_result = (Api)api.accept(self_disambig); 
     140              
     141             List<StaticError> newErrs = new ArrayList<StaticError>(); 
     142             TypeDisambiguator td =  
     143                 new TypeDisambiguator(env, onDemandImports, newErrs); 
     144             Api tdResult = (Api) spd_result.accept(td); 
     145              
     146             if( newErrs.isEmpty() ) 
     147                 new_apis.add(tdResult); 
     148             else  
     149                errors.addAll(newErrs); 
     150        } 
     151         
     152        // then, rebuild the indices 
     153        IndexBuilder.ApiResult rebuilt_indx = IndexBuilder.buildApis(new_apis, System.currentTimeMillis()); 
     154        GlobalEnvironment new_global_env = new GlobalEnvironment.FromMap(CollectUtil.union(repository_apis, 
     155                        rebuilt_indx.apis())); 
     156 
     157        // Finally, disambiguate the expressions using the rebuild indices. 
     158        List<Api> results = new ArrayList<Api>(); 
     159        for( Api api : new_apis ) { 
     160                ApiIndex index = new_global_env.api(api.getName()); 
     161                NameEnv env = new TopLevelEnv(new_global_env, index, errors); 
     162                Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 
     163                 
     164                List<StaticError> newErrs = new ArrayList<StaticError>(); 
     165                ExprDisambiguator ed =  
     166                new ExprDisambiguator(env, onDemandImports, newErrs); 
     167            Api edResult = (Api) api.accept(ed); 
     168            if (newErrs.isEmpty()) 
     169                results.add(edResult); 
     170            else  
     171                errors.addAll(newErrs); 
     172        } 
     173      
     174        results = disambiguateGrammarMembers(results, errors, globalEnv); 
     175        return new ApiResult(results, errors); 
     176    } 
    155177 
    156178    /** Result of {@link #disambiguateComponents}. */ 
     
    166188 
    167189    /** Disambiguate the given components. */ 
    168     public static ComponentResult 
    169     disambiguateComponents(Iterable<Component> components, 
    170             GlobalEnvironment globalEnv, 
    171             Map<APIName, ComponentIndex> indices) { 
     190    public static ComponentResult disambiguateComponents(Iterable<Component> components, 
     191                                                         GlobalEnvironment globalEnv, 
     192                                                         Map<APIName, ComponentIndex> indices) { 
     193         
     194         
    172195        List<Component> results = new ArrayList<Component>(); 
    173196        List<StaticError> errors = new ArrayList<StaticError>(); 
     197         
     198        // First, disambiguate the types 
     199        List<Component> new_comps = new ArrayList<Component>(); 
    174200        for (Component comp : components) { 
    175201            ComponentIndex index = indices.get(comp.getName()); 
     
    187213                new TypeDisambiguator(env, onDemandImports, newErrs); 
    188214            Component tdResult = (Component) spdResult.accept(td); 
    189             if (newErrs.isEmpty()) { 
    190                 ExprDisambiguator ed =  
    191                     new ExprDisambiguator(env, onDemandImports, newErrs); 
    192                 Component edResult = (Component) tdResult.accept(ed); 
    193                 if (newErrs.isEmpty()) { results.add(edResult); } 
     215            if (newErrs.isEmpty()) 
     216                new_comps.add(tdResult); 
     217            else 
     218                errors.addAll(newErrs); 
     219        } 
     220         
     221        // Then, rebuild the component indices based on disambiguated types 
     222        IndexBuilder.ComponentResult new_comp_ir = 
     223                IndexBuilder.buildComponents(new_comps, System.currentTimeMillis()); 
     224         
     225        // Finall, disambiguate the expressions 
     226        for( Component comp : new_comps ) { 
     227                ComponentIndex index = new_comp_ir.components().get(comp.getName()); 
     228                if (index == null) { 
     229                throw new IllegalArgumentException("Missing component index"); 
    194230            } 
    195  
    196             if (!newErrs.isEmpty()) {  
    197                 errors.addAll(newErrs);  
    198             } 
     231                NameEnv env = new TopLevelEnv(globalEnv, index, errors); 
     232            Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 
     233             
     234            List<StaticError> newErrs = new ArrayList<StaticError>(); 
     235            ExprDisambiguator ed =  
     236                new ExprDisambiguator(env, onDemandImports, newErrs); 
     237            Component edResult = (Component) comp.accept(ed); 
     238            if (newErrs.isEmpty()) 
     239                results.add(edResult); 
     240            else  
     241                errors.addAll(newErrs); 
    199242        } 
    200243        return new ComponentResult(results, errors); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticJUTest.java

    r2119 r2163  
    2929     
    3030    private final static String STATIC_TESTS_DIR = ProjectProperties.BASEDIR + "static_tests/"; 
    31     private final static List<String> FAILING_DISAMBIGUATOR = Arrays.asList( 
    32         "XXXMultipleRefErrors.fss", 
    33         "XXXUndefinedArrayRef.fss", 
    34         "XXXUndefinedInitializer.fss", 
    35         "XXXUndefinedNestedRef.fss", 
    36         "XXXUndefinedRefInLoop.fss", 
    37         "XXXUndefinedVar.fss", 
    38         "XXXUndefinedTopLevelVar.fss" 
    39     ); 
     31    private final static List<String> FAILING_DISAMBIGUATOR = Arrays.asList(); 
    4032    private final static List<String> FAILING_TYPE_CHECKER = Arrays.asList( 
     33        /* "XXXMultipleRefErrors.fss", 
    4134        "GenericFunctionCall.fss", 
    4235        "CrossOverloaded.fss", 
     
    4740        "CaseExpr.fss", 
    4841        "DXXMutualSeparateLetFn.fss", 
    49         "XXXMultipleRefErrors.fss", 
    50         "XXXUndefinedArrayRef.fss", 
    51         "XXXUndefinedInitializer.fss", 
    52         "XXXUndefinedNestedRef.fss", 
    53         "XXXUndefinedRefInLoop.fss", 
    54         "XXXUndefinedVar.fss", 
    55         "XXXUndefinedTopLevelVar.fss", 
     42        "XXXMultipleRefErrors.fss", */ 
    5643        // This test the accumulator which is not desugared yet 
    5744         "Sum.fss", 
     
    7057    } 
    7158} 
    72 //"GenericSingleton.fss"      // FIXME 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticTestSuite.java

    r2151 r2163  
    2222import java.io.IOException; 
    2323import java.util.ArrayList; 
     24import java.util.Arrays; 
    2425import java.util.List; 
    2526import java.util.Set; 
     
    6465        }; 
    6566 
    66         for (String filename : new File(testCase.getTestDir()).list(fssFilter)) { 
     67        //Permute filenames for randomness 
     68        String[] files = new File(testCase.getTestDir()).list(fssFilter); 
     69        Iterable<String> shuffled = IterUtil.shuffle(Arrays.asList(files)); 
     70        for (String filename : shuffled) { 
    6771            File f = new File(testCase.getTestDir() + filename); 
    6872 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java

    r2112 r2163  
    1818package com.sun.fortress.compiler.disambiguator; 
    1919 
     20import static edu.rice.cs.plt.tuple.Option.wrap; 
     21 
     22import java.util.Collections; 
     23import java.util.HashSet; 
     24import java.util.LinkedList; 
    2025import java.util.List; 
    21 import java.util.ArrayList; 
    2226import java.util.Set; 
    23 import java.util.HashSet; 
    24 import edu.rice.cs.plt.iter.IterUtil; 
    25 import edu.rice.cs.plt.tuple.Option; 
    26 import edu.rice.cs.plt.collect.ConsList; 
    27 import edu.rice.cs.plt.collect.CollectUtil; 
    28  
    29 import com.sun.fortress.nodes.*; 
     27 
     28import com.sun.fortress.compiler.index.TraitIndex; 
     29import com.sun.fortress.compiler.index.TypeConsIndex; 
     30import com.sun.fortress.exceptions.StaticError; 
     31import com.sun.fortress.nodes.APIName; 
     32import com.sun.fortress.nodes.AbsDecl; 
     33import com.sun.fortress.nodes.AbsFnDecl; 
     34import com.sun.fortress.nodes.AbsObjectDecl; 
     35import com.sun.fortress.nodes.AbsTraitDecl; 
     36import com.sun.fortress.nodes.AbsVarDecl; 
     37import com.sun.fortress.nodes.Accumulator; 
     38import com.sun.fortress.nodes.BaseType; 
     39import com.sun.fortress.nodes.Block; 
     40import com.sun.fortress.nodes.BoolParam; 
     41import com.sun.fortress.nodes.Catch; 
     42import com.sun.fortress.nodes.Contract; 
     43import com.sun.fortress.nodes.Decl; 
     44import com.sun.fortress.nodes.DimDecl; 
     45import com.sun.fortress.nodes.Do; 
     46import com.sun.fortress.nodes.DoFront; 
     47import com.sun.fortress.nodes.Exit; 
     48import com.sun.fortress.nodes.Expr; 
     49import com.sun.fortress.nodes.FnDef; 
     50import com.sun.fortress.nodes.FnExpr; 
     51import com.sun.fortress.nodes.FnRef; 
     52import com.sun.fortress.nodes.For; 
     53import com.sun.fortress.nodes.GeneratedExpr; 
     54import com.sun.fortress.nodes.GeneratorClause; 
     55import com.sun.fortress.nodes.GrammarDef; 
     56import com.sun.fortress.nodes.Id; 
     57import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 
     58import com.sun.fortress.nodes.IdStaticParam; 
     59import com.sun.fortress.nodes.IfClause; 
     60import com.sun.fortress.nodes.IntParam; 
     61import com.sun.fortress.nodes.LValue; 
     62import com.sun.fortress.nodes.LValueBind; 
     63import com.sun.fortress.nodes.Label; 
     64import com.sun.fortress.nodes.LetFn; 
     65import com.sun.fortress.nodes.LocalVarDecl; 
     66import com.sun.fortress.nodes.Modifier; 
     67import com.sun.fortress.nodes.ModifierGetter; 
     68import com.sun.fortress.nodes.ModifierSetter; 
     69import com.sun.fortress.nodes.NatParam; 
     70import com.sun.fortress.nodes.Node; 
     71import com.sun.fortress.nodes.NodeDepthFirstVisitor; 
     72import com.sun.fortress.nodes.NodeUpdateVisitor; 
     73import com.sun.fortress.nodes.ObjectDecl; 
     74import com.sun.fortress.nodes.ObjectExpr; 
     75import com.sun.fortress.nodes.OpName; 
     76import com.sun.fortress.nodes.OpRef; 
     77import com.sun.fortress.nodes.Param; 
     78import com.sun.fortress.nodes.StaticParam; 
     79import com.sun.fortress.nodes.TaggedDimType; 
     80import com.sun.fortress.nodes.TaggedUnitType; 
     81import com.sun.fortress.nodes.TraitDecl; 
     82import com.sun.fortress.nodes.TraitType; 
     83import com.sun.fortress.nodes.TraitTypeWhere; 
     84import com.sun.fortress.nodes.Type; 
     85import com.sun.fortress.nodes.Typecase; 
     86import com.sun.fortress.nodes.UnitDecl; 
     87import com.sun.fortress.nodes.UnitParam; 
     88import com.sun.fortress.nodes.UnpastingBind; 
     89import com.sun.fortress.nodes.UnpastingSplit; 
     90import com.sun.fortress.nodes.VarDecl; 
     91import com.sun.fortress.nodes.VarRef; 
     92import com.sun.fortress.nodes.VarType; 
     93import com.sun.fortress.nodes.VoidLiteralExpr; 
     94import com.sun.fortress.nodes.WhereClause; 
     95import com.sun.fortress.nodes.While; 
     96import com.sun.fortress.nodes._RewriteObjectRef; 
     97import com.sun.fortress.nodes_util.ExprFactory; 
     98import com.sun.fortress.nodes_util.NodeFactory; 
     99import com.sun.fortress.nodes_util.NodeUtil; 
     100import com.sun.fortress.nodes_util.Span; 
    30101import com.sun.fortress.useful.HasAt; 
    31102import com.sun.fortress.useful.NI; 
    32 import com.sun.fortress.nodes_util.NodeUtil; 
    33 import com.sun.fortress.nodes_util.ExprFactory; 
    34 import com.sun.fortress.nodes_util.NodeFactory; 
    35 import com.sun.fortress.nodes_util.Span; 
    36 import com.sun.fortress.compiler.GlobalEnvironment; 
    37 import com.sun.fortress.compiler.index.ApiIndex; 
    38 import com.sun.fortress.compiler.typechecker.TypeEnv; 
    39 import com.sun.fortress.exceptions.StaticError; 
    40  
    41 import static edu.rice.cs.plt.tuple.Option.*; 
     103import com.sun.fortress.useful.Useful; 
     104 
     105import edu.rice.cs.plt.collect.CollectUtil; 
     106import edu.rice.cs.plt.collect.ConsList; 
     107import edu.rice.cs.plt.iter.IterUtil; 
     108import edu.rice.cs.plt.lambda.Lambda2; 
     109import edu.rice.cs.plt.tuple.Option; 
     110import edu.rice.cs.plt.tuple.Pair; 
    42111 
    43112/** 
     
    65134public class ExprDisambiguator extends NodeUpdateVisitor { 
    66135 
    67     private NameEnv _env; 
    68     private Set<IdOrOpOrAnonymousName> _onDemandImports; 
    69     private List<StaticError> _errors; 
    70     private Option<Id> _innerMostLabel; 
    71  
    72     public ExprDisambiguator(NameEnv env, Set<IdOrOpOrAnonymousName> onDemandImports, 
    73                              List<StaticError> errors) { 
    74         _env = env; 
    75         _onDemandImports = onDemandImports; 
    76         _errors = errors; 
    77         _innerMostLabel = Option.<Id>none(); 
    78     } 
    79  
    80     private ExprDisambiguator(NameEnv env, Set<IdOrOpOrAnonymousName> onDemandImports, 
    81                                List<StaticError> errors, Option<Id> innerMostLabel) { 
    82         this(env, onDemandImports, errors); 
    83         _innerMostLabel = innerMostLabel; 
    84     } 
    85  
    86     private ExprDisambiguator extend(Set<Id> vars) { 
    87         NameEnv newEnv = new LocalVarEnv(_env, vars); 
    88         return new ExprDisambiguator(newEnv, _onDemandImports, _errors); 
    89     } 
    90  
    91     private ExprDisambiguator extendWithSelf(Span span) { 
    92         Set<Id> selfSet = new HashSet<Id>(); 
    93         selfSet.add(new Id(span, "self")); 
    94         return extend(selfSet); 
    95     } 
    96  
    97     private void error(String msg, HasAt loc) { 
    98         _errors.add(StaticError.make(msg, loc)); 
    99     } 
    100  
    101     /** LocalVarDecls introduce local variables while visiting the body. */ 
    102     @Override public Node forLocalVarDecl(LocalVarDecl that) { 
    103       List<LValue> lhsResult = recurOnListOfLValue(that.getLhs()); 
    104       Option<Expr> rhsResult = recurOnOptionOfExpr(that.getRhs()); 
    105       Set<Id> definedNames = extractDefinedVarNames(lhsResult); 
    106       NameEnv newEnv = new LocalVarEnv(_env, definedNames); 
    107       ExprDisambiguator v = new ExprDisambiguator(newEnv, _onDemandImports, _errors); 
    108       List<Expr> bodyResult = v.recurOnListOfExpr(that.getBody()); 
    109       return forLocalVarDeclOnly(that, bodyResult, lhsResult, rhsResult); 
    110     } 
    111  
    112     private Set<Id> extractDefinedVarNames(Iterable<? extends LValue> lvalues) { 
    113       Set<Id> result = new HashSet<Id>(); 
    114       extractDefinedVarNames(lvalues, result); 
    115       return result; 
    116     } 
    117  
    118     private void extractDefinedVarNames(Iterable<? extends LValue> lvalues, 
    119                                         Set<Id> result) { 
    120       for (LValue lv : lvalues) { 
    121         boolean valid = true; 
    122         if (lv instanceof LValueBind) { 
    123             Id id = ((LValueBind)lv).getName(); 
    124             valid = (result.add(id) || id.getText().equals("_")); 
    125         } 
    126         else if (lv instanceof UnpastingBind) { 
    127             Id id = ((UnpastingBind)lv).getName(); 
    128             valid = (result.add(id) || id.getText().equals("_")); 
    129         } 
    130         else { // lv instanceof UnpastingSplit 
    131           extractDefinedVarNames(((UnpastingSplit)lv).getElems(), result); 
    132         } 
    133         if (!valid) { error("Duplicate local variable name", lv); } 
    134       } 
    135     } 
    136  
    137     /** 
    138      * Pull out all static variables that can be used in expression contexts, 
    139      * and return them as a Set<Id>. 
    140      * TODO: Collect OpParams as well. 
    141      */ 
    142     private Set<Id> extractStaticExprVars(List<StaticParam> staticParams) { 
    143         Set<Id> result = new HashSet<Id>(); 
    144         for (StaticParam staticParam: staticParams) { 
    145             if (staticParam instanceof BoolParam || 
    146                 staticParam instanceof NatParam  || 
    147                 staticParam instanceof IntParam  || 
    148                 staticParam instanceof UnitParam) 
    149             { 
    150                 result.add(((IdStaticParam)staticParam).getName()); 
    151             } 
    152         } 
    153         return result; 
    154     } 
    155  
    156     /** 
    157      * Convenience method that unwraps its argument and passes it 
    158      * to the overloaded definition of extractParamNames on lists. 
    159      */ 
    160     private Set<Id> extractParamNames(Option<List<Param>> params) { 
    161         Set<Id> result = new HashSet<Id>(); 
    162         if (params.isNone()) { return new HashSet<Id>(); } 
    163         else { return extractParamNames(params.unwrap()); } 
    164     } 
    165  
    166     /** 
    167      * Returns a list of Ids of the given list of Params. 
    168      */ 
    169     private Set<Id> extractParamNames(List<Param> params) { 
    170         Set<Id> result = new HashSet<Id>(); 
    171  
    172         for (Param param: params) { 
    173             result.add(param.getName()); 
    174         } 
    175         return result; 
    176     } 
    177  
    178     /** 
    179      * When recurring on an AbsTraitDecl, we first need to extend the 
    180      * environment with all the newly bound static parameters that can 
    181      * be used in an expression context. 
    182      * TODO: Handle variables bound in where clauses. 
    183      * TODO: Insert inherited method names into the environment. 
    184      */ 
    185     @Override public Node forAbsTraitDecl(final AbsTraitDecl that) { 
    186         ExprDisambiguator v = this.extend(extractStaticExprVars 
    187                                               (that.getStaticParams())). 
    188                                   extendWithSelf(that.getSpan()); 
    189  
    190         return forAbsTraitDeclOnly(that, 
    191                                    v.recurOnListOfModifier(that.getMods()), 
    192                                    (Id) that.getName().accept(v), 
    193                                    v.recurOnListOfStaticParam(that.getStaticParams()), 
    194                                    v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 
    195                                    (WhereClause) that.getWhere().accept(v), 
    196                                    v.recurOnListOfBaseType(that.getExcludes()), 
    197                                    v.recurOnOptionOfListOfBaseType(that.getComprises()), 
    198                                    v.recurOnListOfAbsDecl(that.getDecls())); 
    199     } 
    200  
    201     /** 
    202      * When recurring on a TraitDecl, we first need to extend the 
    203      * environment with all the newly bound static parameters that 
    204      * can be used in an expression context. 
    205      * TODO: Handle variables bound in where clauses. 
    206      * TODO: Insert inherited method names into the environment. 
    207      */ 
    208     @Override public Node forTraitDecl(final TraitDecl that) { 
    209   ExprDisambiguator v = this.extend(extractStaticExprVars 
    210                                           (that.getStaticParams())). 
    211                                   extendWithSelf(that.getSpan()); 
    212  
    213         return forTraitDeclOnly(that, 
    214                                 v.recurOnListOfModifier(that.getMods()), 
    215                                 (Id) that.getName().accept(v), 
    216                                 v.recurOnListOfStaticParam(that.getStaticParams()), 
    217                                 v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 
    218                                 (WhereClause) that.getWhere().accept(v), 
    219                                 v.recurOnListOfBaseType(that.getExcludes()), 
    220                                 v.recurOnOptionOfListOfBaseType(that.getComprises()), 
    221                                 v.recurOnListOfDecl(that.getDecls())); 
    222     } 
    223  
    224  
    225     /** 
    226      * When recurring on an AbsObjectDecl, we first need to extend the 
    227      * environment with all the newly bound static parameters that can 
    228      * be used in an expression context. 
    229      * TODO: Handle variables bound in where clauses. 
    230      * TODO: Insert inherited method names into the environment. 
    231      */ 
    232     @Override public Node forAbsObjectDecl(final AbsObjectDecl that) { 
    233   Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 
    234         Set<Id> params = extractParamNames(that.getParams()); 
    235         ExprDisambiguator v = extend(staticExprVars). 
    236                                   extendWithSelf(that.getSpan()). 
    237                                       extend(params); 
    238  
    239         return forAbsObjectDeclOnly(that, 
    240                                    v.recurOnListOfModifier(that.getMods()), 
    241                                    (Id) that.getName().accept(v), 
    242                                    v.recurOnListOfStaticParam(that.getStaticParams()), 
    243                                    v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 
    244                                    (WhereClause) that.getWhere().accept(v), 
    245                                    v.recurOnOptionOfListOfParam(that.getParams()), 
    246                                    v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 
    247                                    (Contract) that.getContract().accept(v), 
    248                                    v.recurOnListOfAbsDecl(that.getDecls())); 
    249     } 
    250  
    251     /** 
    252      * When recurring on an ObjectDecl, we first need to extend the 
    253      * environment with all the newly bound static parameters that can 
    254      * be used in an expression context, along with all the object parameters. 
    255      * TODO: Handle variables bound in where clauses. 
    256      * TODO: Insert inherited method names into the environment. 
    257      */ 
    258     @Override public Node forObjectDecl(final ObjectDecl that) { 
    259   Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 
    260         Set<Id> params = extractParamNames(that.getParams()); 
    261         ExprDisambiguator v = extend(staticExprVars). 
    262                                   extendWithSelf(that.getSpan()). 
    263                                       extend(params); 
    264  
    265         return forObjectDeclOnly(that, 
    266                                    v.recurOnListOfModifier(that.getMods()), 
    267                                    (Id) that.getName().accept(v), 
    268                                    v.recurOnListOfStaticParam(that.getStaticParams()), 
    269                                    v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 
    270                                    (WhereClause) that.getWhere().accept(v), 
    271                                    v.recurOnOptionOfListOfParam(that.getParams()), 
    272                                    v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 
    273                                    (Contract) that.getContract().accept(v), 
    274                                    v.recurOnListOfDecl(that.getDecls())); 
    275     } 
    276  
    277  
    278     /** 
    279      * When recurring on an AbsFnDecl, we first need to extend the 
    280      * environment with all the newly bound static parameters that 
    281      * can be used in an expression context, along with all function 
    282      * parameters and 'self'. 
    283      * TODO: Handle variables bound in where clauses. 
    284      */ 
    285     @Override public Node forAbsFnDecl(final AbsFnDecl that) { 
    286         Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 
    287         Set<Id> params = extractParamNames(that.getParams()); 
    288         ExprDisambiguator v = extend(staticExprVars).extend(params); 
    289  
    290         return forAbsFnDeclOnly(that, 
    291                                 v.recurOnListOfModifier(that.getMods()), 
    292                                 (IdOrOpOrAnonymousName) that.getName().accept(v), 
    293                                 v.recurOnListOfStaticParam(that.getStaticParams()), 
    294                                 v.recurOnListOfParam(that.getParams()), 
    295                                 v.recurOnOptionOfType(that.getReturnType()), 
    296                                 v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 
    297                                 (WhereClause) that.getWhere().accept(v), 
    298                                 (Contract) that.getContract().accept(v)); 
    299     } 
    300  
    301  
    302     /** 
    303      * When recurring on a FnDef, we first need to extend the 
    304      * environment with all the newly bound static parameters that 
    305      * can be used in an expression context, along with all function 
    306      * parameters and