Changeset 3145
- Timestamp:
- 12/03/08 21:39:21 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 12 modified
-
astgen/Fortress.ast (modified) (1 diff)
-
src/com/sun/fortress/compiler/disambiguator/TypeDisambiguator.java (modified) (1 diff)
-
src/com/sun/fortress/compiler/typechecker/FnTypeEnv.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/typechecker/ObjectTypeEnv.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/typechecker/SubtypeChecker.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeAnalyzer.java (modified) (3 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (4 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeCheckerTestCase.java (modified) (1 diff)
-
src/com/sun/fortress/compiler/typechecker/TypeEnv.java (modified) (3 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypesUtil.java (modified) (15 diffs)
-
src/com/sun/fortress/interpreter/Driver.java (modified) (1 diff)
-
src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3144 r3145 1347 1347 /** 1348 1348 * arrow type 1349 */ 1350 abstract AbstractArrowType(Type domain, Type range, 1351 Effect effect = FortressUtil.emptyEffect()); 1352 /** 1353 * arrow type 1354 * Type ::= Type -> Type Throws? 1355 * e.g.) (String, NN..., p = Printer) -> NN throws IOException 1356 */ 1357 ArrowType(); 1358 /** 1359 * type of a generic function, used during static checking 1360 */ 1361 _RewriteGenericArrowType(List<StaticParam> staticParams 1362 = Collections.<StaticParam>emptyList(), 1363 Option<WhereClause> whereClause 1364 = Option.<WhereClause>none()); 1349 * Type ::= Type -> Type Throws? 1350 * e.g.) (String, NN..., p = Printer) -> NN throws IOException 1351 * 1352 * <staticParams> 1353 * <whereClause> 1354 * type of a generic function, used during static checking 1355 */ 1356 ArrowType(Type domain, Type range, 1357 Effect effect = FortressUtil.emptyEffect(), 1358 List<StaticParam> staticParams 1359 = Collections.<StaticParam>emptyList(), 1360 Option<WhereClause> whereClause 1361 = Option.<WhereClause>none()); 1365 1362 /** 1366 1363 * inferred type -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TypeDisambiguator.java
r3144 r3145 197 197 Type rangeResult = (Type) that.getRange().accept(this); 198 198 Effect effectResult = (Effect) that.getEffect().accept(this); 199 return forArrowTypeOnly(that, domainResult, rangeResult, effectResult); 199 return forArrowTypeOnly(that, domainResult, rangeResult, effectResult, 200 that.getStaticParams(), that.getWhereClause()); 200 201 } 201 202 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/FnTypeEnv.java
r3123 r3145 49 49 import com.sun.fortress.nodes.VarType; 50 50 import com.sun.fortress.nodes._InferenceVarType; 51 import com.sun.fortress.nodes. _RewriteGenericArrowType;51 import com.sun.fortress.nodes.ArrowType; 52 52 import com.sun.fortress.nodes_util.NodeFactory; 53 53 import com.sun.fortress.nodes_util.Span; … … 148 148 // Invariant: _fn.params().isSome() 149 149 // Otherwise, _fn should not have been in entries. 150 overloadedTypes.add(new _RewriteGenericArrowType(loc,151 domainFromParams(_fn.parameters()),152 selfType,153 makeEffect(loc.getEnd(), CollectUtil.makeList(_fn.thrownTypes())),154 _fn.staticParameters(),155 _fn.where()));150 overloadedTypes.add(new ArrowType(loc, 151 domainFromParams(_fn.parameters()), 152 selfType, 153 makeEffect(loc.getEnd(), CollectUtil.makeList(_fn.thrownTypes())), 154 _fn.staticParameters(), 155 _fn.where())); 156 156 } 157 157 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/ObjectTypeEnv.java
r3122 r3145 33 33 import com.sun.fortress.nodes.Type; 34 34 import com.sun.fortress.nodes._InferenceVarType; 35 import com.sun.fortress.nodes. _RewriteGenericArrowType;35 import com.sun.fortress.nodes.ArrowType; 36 36 import com.sun.fortress.nodes_util.NodeFactory; 37 37 … … 89 89 // Some static params, some normal params 90 90 // TODO: handle type variables bound in where clause 91 type = 92 new _RewriteGenericArrowType(decl.getSpan(), 93 domainFromParams(decl.getParams().unwrap()), 94 NodeFactory.makeTraitType(_var, TypeEnv.staticParamsToArgs(decl.getStaticParams())), 95 decl.getStaticParams(), 96 decl.getWhereClause()); 91 type = new ArrowType(decl.getSpan(), 92 domainFromParams(decl.getParams().unwrap()), 93 NodeFactory.makeTraitType(_var, TypeEnv.staticParamsToArgs(decl.getStaticParams())), 94 decl.getStaticParams(), 95 decl.getWhereClause()); 97 96 } 98 97 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/SubtypeChecker.java
r3123 r3145 376 376 } 377 377 private boolean isArrow(Type t) { 378 return (t instanceof A bstractArrowType);378 return (t instanceof ArrowType); 379 379 } 380 380 private boolean isTuple(Type t) { … … 693 693 if (isArrow(s) && isArrow(t)) { 694 694 if (s instanceof ArrowType) { 695 if (t instanceof ArrowType) { 696 ArrowType ss = (ArrowType)s; 697 ArrowType tt = (ArrowType)t; 698 return (subdomain(tt.getDomain(), ss.getDomain(), h) && 699 subtype(ss.getRange(), tt.getRange(), h)); 700 } else { // t instanceof _RewriteGenericArrowType 701 return FALSE; 702 } 703 } else { // s instanceof _RewriteGenericArrowType 704 if (t instanceof ArrowType) { 705 return FALSE; 706 } else { // t instanceof _RewriteGenericArrowType 707 _RewriteGenericArrowType ss = (_RewriteGenericArrowType)s; 708 _RewriteGenericArrowType tt = (_RewriteGenericArrowType)t; 709 return (subdomain(tt.getDomain(), ss.getDomain(), h) && 710 subtype(ss.getRange(), tt.getRange(), h) && 711 equivalentStaticParams(ss.getStaticParams(), 712 tt.getStaticParams(), h)); 713 } 695 ArrowType ss = (ArrowType)s; 696 ArrowType tt = (ArrowType)t; 697 return (subdomain(tt.getDomain(), ss.getDomain(), h) && 698 subtype(ss.getRange(), tt.getRange(), h) && 699 equivalentStaticParams(ss.getStaticParams(), 700 tt.getStaticParams(), h)); 714 701 } 715 702 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzer.java
r3144 r3145 319 319 320 320 @Override public Type forArrowTypeOnly(ArrowType t, Type normalDomain, Type normalRange, 321 final Effect normalEffect) { 321 final Effect normalEffect, 322 List<StaticParam> staticParams, 323 Option<WhereClause> whereClause) { 322 324 Type domainArg = stripKeywords(normalDomain); 323 325 final Map<Id, Type> domainKeys = extractKeywords(normalDomain); … … 560 562 else { return FALSE; } 561 563 } 562 @Override public ConstraintFormula forA bstractArrowType(AbstractArrowType s) {563 if (t instanceof A bstractArrowType) {564 return arrowSubArrow(s, (A bstractArrowType) t, h);564 @Override public ConstraintFormula forArrowType(ArrowType s) { 565 if (t instanceof ArrowType) { 566 return arrowSubArrow(s, (ArrowType) t, h); 565 567 } 566 568 else { return FALSE; } … … 644 646 } 645 647 646 private ConstraintFormula arrowSubArrow(A bstractArrowType s, AbstractArrowType t, SubtypeHistory h) {648 private ConstraintFormula arrowSubArrow(ArrowType s, ArrowType t, SubtypeHistory h) { 647 649 ConstraintFormula f = sub(t.getDomain(), s.getDomain(), h); 648 650 if (!f.isFalse()) { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3144 r3145 821 821 cur_type.accept(new TypeAbstractVisitor_void() { 822 822 @Override 823 public void forA bstractArrowType(final AbstractArrowType cur_type) {823 public void forArrowType(final ArrowType cur_type) { 824 824 if( most_applicable.value().isNone() ) { 825 825 most_applicable.set(some(Pair.<FunctionalRef,Type>make(pruned_fn.first(), cur_type))); … … 829 829 most_applicable.value().unwrap().second().accept(new TypeAbstractVisitor_void() { 830 830 @Override 831 public void forA bstractArrowType(AbstractArrowType most_appl) {831 public void forArrowType(ArrowType most_appl) { 832 832 // Where is arg of cur_type <: arg of most_appl? 833 833 ConstraintFormula sub = … … 2460 2460 overloading.accept(new TypeAbstractVisitor<Option<Pair<Pair<Type,ConstraintFormula>,List<StaticArg>>>>() { 2461 2461 @Override 2462 public Option<Pair<Pair<Type,ConstraintFormula>, List<StaticArg>>> for _RewriteGenericArrowType(2463 _RewriteGenericArrowType gen_arr_type) {2462 public Option<Pair<Pair<Type,ConstraintFormula>, List<StaticArg>>> forArrowType( 2463 ArrowType gen_arr_type) { 2464 2464 // If the arrow type is generic, it needs static args, so make up inference variables 2465 2465 List<StaticArg> new_args = … … 3669 3669 overloading.accept(new TypeAbstractVisitor<Option<Pair<Pair<Type,ConstraintFormula>,List<StaticArg>>>>() { 3670 3670 @Override 3671 public Option<Pair<Pair<Type,ConstraintFormula>, List<StaticArg>>> for _RewriteGenericArrowType(3672 _RewriteGenericArrowType gen_arr_type) {3671 public Option<Pair<Pair<Type,ConstraintFormula>, List<StaticArg>>> forArrowType( 3672 ArrowType gen_arr_type) { 3673 3673 // If the arrow type is generic, it needs static args, so make up inference variables 3674 3674 List<StaticArg> new_args = -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeCheckerTestCase.java
r3114 r3145 46 46 import com.sun.fortress.nodes.Type; 47 47 import com.sun.fortress.nodes.WhereClause; 48 import com.sun.fortress.nodes._RewriteGenericArrowType;49 48 import com.sun.fortress.nodes_util.NodeFactory; 50 49 import com.sun.fortress.nodes_util.Span; -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnv.java
r3132 r3145 53 53 import com.sun.fortress.nodes.IntParam; 54 54 import com.sun.fortress.nodes.IntRef; 55 import com.sun.fortress.nodes.ArrowType; 55 56 import com.sun.fortress.nodes.IntersectionType; 56 57 import com.sun.fortress.nodes.KeywordType; … … 77 78 import com.sun.fortress.nodes.UnitRef; 78 79 import com.sun.fortress.nodes._InferenceVarType; 79 import com.sun.fortress.nodes._RewriteGenericArrowType;80 80 import com.sun.fortress.nodes_util.ExprFactory; 81 81 import com.sun.fortress.nodes_util.NodeFactory; … … 139 139 } 140 140 141 protected static _RewriteGenericArrowType genericArrowFromDecl(FnDecl decl) {142 return new _RewriteGenericArrowType(decl.getSpan(),143 domainFromParams(decl.getParams()),144 // all types have been filled in at this point145 decl.getReturnType().unwrap(),146 makeEffect(decl.getSpan().getEnd(),147 decl.getThrowsClause()),148 decl.getStaticParams(),149 decl.getWhereClause());141 protected static ArrowType genericArrowFromDecl(FnDecl decl) { 142 return new ArrowType(decl.getSpan(), 143 domainFromParams(decl.getParams()), 144 // all types have been filled in at this point 145 decl.getReturnType().unwrap(), 146 makeEffect(decl.getSpan().getEnd(), 147 decl.getThrowsClause()), 148 decl.getStaticParams(), 149 decl.getWhereClause()); 150 150 } 151 151 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypesUtil.java
r3123 r3145 29 29 30 30 import com.sun.fortress.compiler.Types; 31 import com.sun.fortress.nodes.AbstractArrowType;32 31 import com.sun.fortress.nodes.AnyType; 33 32 import com.sun.fortress.nodes.ArrowType; … … 40 39 import com.sun.fortress.nodes.NodeDepthFirstVisitor_void; 41 40 import com.sun.fortress.nodes.ObjectExpr; 41 import com.sun.fortress.nodes.WhereClause; 42 42 import com.sun.fortress.nodes.StaticArg; 43 43 import com.sun.fortress.nodes.StaticParam; … … 50 50 import com.sun.fortress.nodes.UnionType; 51 51 import com.sun.fortress.nodes._InferenceVarType; 52 import com.sun.fortress.nodes._RewriteGenericArrowType;53 52 import com.sun.fortress.nodes_util.NodeFactory; 54 53 import com.sun.fortress.useful.NI; … … 137 136 final ConstraintFormula existingConstraint) { 138 137 // List of arrow types that statically match 139 List<A bstractArrowType> matching_types = new ArrayList<AbstractArrowType>();138 List<ArrowType> matching_types = new ArrayList<ArrowType>(); 140 139 // The constraint formed from all matching arrows 141 140 ConstraintFormula result_constraint = ConstraintFormula.TRUE; 142 141 for( Type arrow : conjuncts(fn_type) ) { 143 142 // create instantiated arrow types using visitor 144 Pair<Option<A bstractArrowType>,ConstraintFormula> pair =145 arrow.accept(new NodeDepthFirstVisitor<Pair<Option<A bstractArrowType>,ConstraintFormula>>() {143 Pair<Option<ArrowType>,ConstraintFormula> pair = 144 arrow.accept(new NodeDepthFirstVisitor<Pair<Option<ArrowType>,ConstraintFormula>>() { 146 145 @Override 147 public Pair<Option<A bstractArrowType>, ConstraintFormula> defaultCase(146 public Pair<Option<ArrowType>, ConstraintFormula> defaultCase( 148 147 Node that) { 149 return Pair.make(Option.<A bstractArrowType>none(), ConstraintFormula.FALSE);148 return Pair.make(Option.<ArrowType>none(), ConstraintFormula.FALSE); 150 149 } 151 150 152 151 // apply (inferring if necessary) static arguments and checking sub-typing 153 private Pair<Option<A bstractArrowType>,ConstraintFormula>154 arrowTypeHelper(A bstractArrowType that, List<StaticParam> static_params) {152 private Pair<Option<ArrowType>,ConstraintFormula> 153 arrowTypeHelper(ArrowType that, List<StaticParam> static_params) { 155 154 int num_static_params = static_params.size(); 156 155 int num_static_args = staticArgs.size(); … … 163 162 // how to infer it yet. 164 163 for( StaticParam p : static_params ) 165 if( !(p instanceof TypeParam) ) return Pair.make(Option.<A bstractArrowType>none(), ConstraintFormula.FALSE);164 if( !(p instanceof TypeParam) ) return Pair.make(Option.<ArrowType>none(), ConstraintFormula.FALSE); 166 165 167 166 static_args_to_apply = … … 176 175 else if( num_static_params != num_static_args ) { 177 176 // just not the right method 178 return Pair.make(Option.<A bstractArrowType>none(), ConstraintFormula.FALSE);177 return Pair.make(Option.<ArrowType>none(), ConstraintFormula.FALSE); 179 178 } 180 179 // now apply the static arguments, 181 that = (A bstractArrowType)180 that = (ArrowType) 182 181 that.accept(new StaticTypeReplacer(static_params,static_args_to_apply)); 183 182 // and then check parameter sub-typing … … 186 185 } 187 186 @Override 188 public Pair<Option<A bstractArrowType>, ConstraintFormula> for_RewriteGenericArrowType(189 _RewriteGenericArrowType that) {187 public Pair<Option<ArrowType>, ConstraintFormula> forArrowType( 188 ArrowType that) { 190 189 return this.arrowTypeHelper(that, that.getStaticParams()); 191 }192 @Override193 public Pair<Option<AbstractArrowType>, ConstraintFormula> forArrowType(194 ArrowType that) {195 return this.arrowTypeHelper(that, Collections.<StaticParam>emptyList());196 190 } 197 191 }); … … 210 204 // Now, take all the matching ones and join their ranges to be the result range type. 211 205 Iterable<Type> ranges = 212 IterUtil.map(matching_types, new Lambda<A bstractArrowType, Type>(){213 public Type value(A bstractArrowType arg0) {206 IterUtil.map(matching_types, new Lambda<ArrowType, Type>(){ 207 public Type value(ArrowType arg0) { 214 208 return arg0.getRange(); 215 209 }}); … … 230 224 valid&=t.accept(new NodeDepthFirstVisitor<Boolean>(){ 231 225 @Override public Boolean defaultCase(Node that) {return false; } 232 @Override public Boolean for_RewriteGenericArrowType(_RewriteGenericArrowType that) {return true;}233 226 @Override public Boolean forArrowType(ArrowType that) {return true;} 234 227 }); … … 244 237 * return a ConstraintFormula instead of a type. 245 238 * @param checker the SubtypeChecker to use for any type comparisons 246 * @param fn the type of the function, which can be some A bstractArrowType,239 * @param fn the type of the function, which can be some ArrowType, 247 240 * or an intersection of such (in the case of an overloaded 248 241 * function) … … 265 258 * Figure out the static type of a non-generic function application. 266 259 * @param checker the SubtypeChecker to use for any type comparisons 267 * @param fn the type of the function, which can be some A bstractArrowType,260 * @param fn the type of the function, which can be some ArrowType, 268 261 * or an intersection of such (in the case of an overloaded 269 262 * function) … … 299 292 return valid ? some(that) : Option.<ArrowType>none(); 300 293 } 301 @Override public Option<ArrowType> for_RewriteGenericArrowType(_RewriteGenericArrowType that) {302 return NI.nyi();303 }304 294 @Override public Option<ArrowType> defaultCase(Node that) { 305 295 return none(); … … 434 424 435 425 @Override 436 public Option<Pair<Type,ConstraintFormula>> for_RewriteGenericArrowType( 437 _RewriteGenericArrowType that) { 426 public Option<Pair<Type,ConstraintFormula>> forArrowType(ArrowType that) { 438 427 439 428 Option<ConstraintFormula> constraints = StaticTypeReplacer.argsMatchParams(static_args,that.getStaticParams(), subtype_checker); 440 429 441 430 if(constraints.isSome()) { 442 _RewriteGenericArrowType temp = (_RewriteGenericArrowType) that.accept(new StaticTypeReplacer(that.getStaticParams(),static_args)); 443 Type new_type = new ArrowType(temp.getSpan(),temp.isParenthesized(),temp.getDomain(),temp.getRange(), temp.getEffect()); 431 ArrowType temp = (ArrowType) that.accept(new StaticTypeReplacer(that.getStaticParams(),static_args)); 432 Type new_type = new ArrowType(temp.getSpan(),temp.isParenthesized(), 433 temp.getDomain(),temp.getRange(), temp.getEffect(), 434 Collections.<StaticParam>emptyList(), 435 Option.<WhereClause>none()); 444 436 return Option.some(Pair.make(new_type,constraints.unwrap())); 445 437 } … … 447 439 return Option.none(); 448 440 } 449 }450 @Override451 public Option<Pair<Type,ConstraintFormula>> forArrowType(ArrowType that) {452 return Option.none();453 441 } 454 442 }); … … 511 499 for( Type conj : conjuncts(overloaded_type) ) { 512 500 Boolean b = conj.accept(new TypeAbstractVisitor<Boolean>(){ 513 @Override public Boolean for _RewriteGenericArrowType(_RewriteGenericArrowType that) { return !that.getStaticParams().isEmpty(); }501 @Override public Boolean forArrowType(ArrowType that) { return !that.getStaticParams().isEmpty(); } 514 502 @Override public Boolean forType(Type that) { return Boolean.FALSE; } 515 503 }); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java
r3141 r3145 58 58 import com.sun.fortress.interpreter.glue.WellKnownNames; 59 59 import com.sun.fortress.nodes.APIName; 60 import com.sun.fortress.nodes.AbstractArrowType;61 60 import com.sun.fortress.nodes.AliasedAPIName; 62 61 import com.sun.fortress.nodes.AliasedSimpleName; -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3144 r3145 2166 2166 String domain_result, 2167 2167 String range_result, 2168 String effect_result) { 2168 String effect_result, 2169 List<String> staticParams_result, 2170 Option<String> whereClause_result) { 2169 2171 StringBuilder s = new StringBuilder(); 2170 2172 … … 2176 2178 return handleParen( s.toString(), 2177 2179 that.isParenthesized() ); 2178 }2179 2180 @Override public String for_RewriteGenericArrowTypeOnly(_RewriteGenericArrowType that,2181 String domain_result,2182 String range_result,2183 String effect_result,2184 List<String> staticParams_result,2185 Option<String> where_result) {2186 StringBuilder s = new StringBuilder();2187 2188 inOxfordBrackets(s, staticParams_result );2189 s.append( domain_result );2190 s.append( " -> " );2191 s.append( range_result );2192 s.append( effect_result );2193 2194 return "(* " + handleParen( s.toString(),2195 that.isParenthesized() ) + " *)";2196 2180 } 2197 2181

