Changeset 3875
- Timestamp:
- 06/18/09 19:15:43 (5 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 3 added
- 15 modified
-
astgen/Fortress.ast (modified) (2 diffs)
-
compiler_tests/AfterTypeChecking.test (modified) (1 diff)
-
compiler_tests/XXX5j.test (added)
-
compiler_tests/nyi.Compiled6.t.fss (modified) (1 diff)
-
parser_tests/ioTests.fss (added)
-
src/com/sun/fortress/Shell.java (modified) (5 diffs)
-
src/com/sun/fortress/nodes_util/NodeFactory.java (modified) (1 diff)
-
src/com/sun/fortress/parser/Compilation.rats (modified) (1 diff)
-
src/com/sun/fortress/parser/NoNewlineType.rats (modified) (1 diff)
-
src/com/sun/fortress/parser/Type.rats (modified) (1 diff)
-
src/com/sun/fortress/parser/import_collector/Compilation.rats (modified) (1 diff)
-
src/com/sun/fortress/scala_src/typechecker/ExclusionOracle.scala (modified) (3 diffs)
-
src/com/sun/fortress/scala_src/typechecker/ExportChecker.scala (modified) (1 diff)
-
src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala (modified) (5 diffs)
-
src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala (modified) (19 diffs)
-
src/com/sun/fortress/scala_src/typechecker/TypeWellFormedChecker.scala (modified) (1 diff)
-
src/com/sun/fortress/tests/unit_tests/FileTests.java (modified) (8 diffs)
-
src/com/sun/fortress/tests/unit_tests/ScalaTypeCheckerJUTest.java (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3845 r3875 1065 1065 /** 1066 1066 * arrow type 1067 * Type ::= Type -> Type Throws?1067 * Type ::= io? Type -> Type Throws? 1068 1068 * e.g.) (String, NN..., p = Printer) -> NN throws IOException 1069 1069 * … … 1072 1072 * type of a generic function, used during static checking 1073 1073 */ 1074 ArrowType(Type domain, Type range, Effect effect );1074 ArrowType(Type domain, Type range, Effect effect, boolean io); 1075 1075 /** 1076 1076 * inferred type -
trunk/ProjectFortress/compiler_tests/AfterTypeChecking.test
r3871 r3875 14 14 # trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 15 15 16 tests=Compiled1.ag Compiled1.ah Compiled1.ai Compiled1.aj Compiled1.ak Compiled1.as Compiled1.au Compiled1.av Compiled2.g Compiled2.t Compiled3.b Compiled3.c Compiled3.d Compiled3.e Compiled3.f Compiled3.h Compiled3.i Compiled3.j Compiled3.k Compiled3.m Compiled3.p Compiled3.q Compiled3.t Compiled3.v Compiled3.x Compiled5.e Compiled5. j Compiled5.o Compiled5.q Compiled6 Compiled7 Compiled816 tests=Compiled1.ag Compiled1.ah Compiled1.ai Compiled1.aj Compiled1.ak Compiled1.as Compiled1.au Compiled1.av Compiled2.g Compiled2.t Compiled3.b Compiled3.c Compiled3.d Compiled3.e Compiled3.f Compiled3.h Compiled3.i Compiled3.j Compiled3.k Compiled3.m Compiled3.p Compiled3.q Compiled3.t Compiled3.v Compiled3.x Compiled5.e Compiled5.o Compiled5.q Compiled6 Compiled7 Compiled8 17 17 desugar -
trunk/ProjectFortress/compiler_tests/nyi.Compiled6.t.fss
r3832 r3875 19 19 export Executable 20 20 21 f(x:ZZ32) = x22 g(x:ZZ32) = x21 f(x:ZZ32):ZZ32 = x 22 g(x:ZZ32):ZZ32 = x 23 23 24 24 run(): () = printlnZZ32(g(3)) -
trunk/ProjectFortress/src/com/sun/fortress/Shell.java
r3873 r3875 312 312 setPhase( PhaseOrder.CODEGEN ); 313 313 return_code = compilerPhases(args, Option.<String>none(), what); 314 } else if (what.equals("compile-scala")) {315 WellKnownNames.useCompilerLibraries();316 Types.useCompilerLibraries();317 setTypeChecking(true);318 //setScala(true);319 setPhase( PhaseOrder.CODEGEN );320 return_code = compilerPhases(args, Option.<String>none(), what);321 314 } else if (what.equals("link")) { 322 315 WellKnownNames.useCompilerLibraries(); 323 316 Types.useCompilerLibraries(); 324 setTypeChecking(true);325 setPhase( PhaseOrder.CODEGEN );326 return_code = link(args);327 } else if (what.equals("link-scala")) {328 WellKnownNames.useCompilerLibraries();329 Types.useCompilerLibraries();330 setScala(true);331 317 setTypeChecking(true); 332 318 setPhase( PhaseOrder.CODEGEN ); … … 353 339 setPhase( PhaseOrder.DISAMBIGUATE ); 354 340 return_code = compilerPhases(args, Option.<String>none(), what); 355 } else if ( what.equals( "disambiguate-scala" ) ){356 setScala(true);357 setPhase( PhaseOrder.DISAMBIGUATE );358 return_code = compilerPhases(args, Option.<String>none(), what);359 341 } else if ( what.equals( "desugar" ) ){ 360 342 setTypeChecking(true); … … 371 353 setPhase( PhaseOrder.TYPECHECK ); 372 354 return_code = compilerPhases(args, Option.<String>none(), what); 373 } else if (what.equals("typecheck-scala")){374 WellKnownNames.useCompilerLibraries();375 Types.useCompilerLibraries();376 setTypeChecking(true);377 setScala(true);378 setPhase( PhaseOrder.TYPECHECK );379 return_code = compilerPhases(args, Option.<String>none(), what);380 355 } else if (what.equals("test-coercion")) { 381 356 setTypeChecking(true); 382 setScala(true);383 357 setPhase(PhaseOrder.TYPECHECK); 384 358 return_code = compilerPhases(args, Option.<String>none(), what); … … 749 723 Types.useCompilerLibraries(); 750 724 } 751 else if (s.equals("-typecheck- scala")) {752 setScala( true);725 else if (s.equals("-typecheck-java")) { 726 setScala(false); 753 727 } 754 728 else if (s.equals("-coercion")) { … … 940 914 if (s.equals("-debug")){ 941 915 rest = Debug.parseOptions(rest); 942 }943 else if (s.equals("-typecheck-scala")) {944 setScala(true);945 916 } 946 917 else -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java
r3855 r3875 743 743 Option<WhereClause> where) { 744 744 TypeInfo info = makeTypeInfo(span, parenthesized, sparams, where); 745 return new ArrowType(info, domain, range, effect );745 return new ArrowType(info, domain, range, effect, false); 746 746 } 747 747 -
trunk/ProjectFortress/src/com/sun/fortress/parser/Compilation.rats
r3845 r3875 100 100 101 101 /* Component ::= 102 (native w)? component w APIName w comprises w APINames 103 w end ((s component)? s APIName)? 104 | (native w)? component w APIName w ImportOrExports (w ;)? 102 (native w)? component w APIName w ImportOrExports (w ;)? 105 103 (w Decls (w ;)?)? w end ((s component)? s APIName)? 106 104 */ -
trunk/ProjectFortress/src/com/sun/fortress/parser/NoNewlineType.rats
r3456 r3875 36 36 /* NoNewlineType ::= NoNewlineTypePrimary (w in w NoNewlineExpr)? */ 37 37 Type NoNewlineType = 38 !(one) a1:TypePrimary a2:(w void:in w NoNewlineExpr)?38 !(one) (io w)? a1:TypePrimary a2:(w void:in w NoNewlineExpr)? 39 39 { Type ty = TypeResolver.resolveOps(a1); 40 40 if (a2 == null) -
trunk/ProjectFortress/src/com/sun/fortress/parser/Type.rats
r3822 r3875 34 34 /* Type ::= TypePrimary (w in w Expr)? */ 35 35 Type Type = 36 !(one) a1:TypePrimary a2:(w void:in w Expr)?36 !(one) (io w)? a1:TypePrimary a2:(w void:in w Expr)? 37 37 { Type ty = TypeResolver.resolveOps(a1); 38 38 Span span = NodeUtil.getSpan(ty); -
trunk/ProjectFortress/src/com/sun/fortress/parser/import_collector/Compilation.rats
r3845 r3875 65 65 66 66 /* Component ::= 67 (native w)? component w APIName w comprises w APINames 68 w end ((s component)? s APIName)? 69 | (native w)? component w APIName (w Imports w ;?)? w Exports w ;? 67 (native w)? component w APIName (w Imports w ;?)? w Exports w ;? 70 68 (w Decls w ;?)? w end ((s component)? s APIName)? 71 69 */ -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/ExclusionOracle.scala
r3783 r3875 56 56 * The following types are not yet supported: 57 57 * Types tagged with dimensions or units 58 * Effects on arrow types58 * Effects and io on arrow types 59 59 * Keyword parameters and varargs parameters 60 60 * Intersection types … … 134 134 false 135 135 } 136 case (SArrowType(_,_,_,_ ), SArrowType(_,_,_,_)) => false137 case (SArrowType(_,_,_,_ ), _) => true138 case (_, SArrowType(_,_,_,_ )) => true136 case (SArrowType(_,_,_,_,_), SArrowType(_,_,_,_,_)) => false 137 case (SArrowType(_,_,_,_,_), _) => true 138 case (_, SArrowType(_,_,_,_,_)) => true 139 139 case (f@STupleType(_,_,_,_), s@STupleType(_,_,_,_)) => 140 140 NodeUtil.differentArity(f, s) || { … … 215 215 case STraitType(i,n,a,p) => STraitType(i, n, a.map(saSubst), p.map(spSubst)) 216 216 case STupleType(i,e,v,k) => STupleType(i, e.map(tySubst), v, k) 217 case SArrowType(i,d,r,e ) => SArrowType(i, tySubst(d), tySubst(r), e)217 case SArrowType(i,d,r,e,b) => SArrowType(i, tySubst(d), tySubst(r), e, b) 218 218 case _ => tau 219 219 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/ExportChecker.scala
r3842 r3875 403 403 equalOptTypes(varargsL, varargsR) && 404 404 equalListKeywordTypes(kwdL, kwdR) 405 case (SArrowType(_, domL, ranL, effL ),406 SArrowType(_, domR, ranR, effR )) =>405 case (SArrowType(_, domL, ranL, effL, ioL), 406 SArrowType(_, domR, ranR, effR, ioR)) => 407 407 equalTypes(domL, domR) && 408 408 equalTypes(ranL, ranR) && 409 equalEffects(effL, effR) 409 equalEffects(effL, effR) && 410 ioL == ioR 410 411 case _ => false 411 412 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala
r3871 r3875 242 242 typeAnalyzer = typeAnalyzer.extend(staticParameters, none[WhereClause]) 243 243 var result = false 244 val meet = (reduce(typeAnalyzer.meet(first._1._2, second._1._2)), 245 reduce(typeAnalyzer.meet(first._1._3, second._1._3))) 244 val exclusionOracle = new ExclusionOracle(typeAnalyzer, new ErrorLog()) 245 val meet = (reduce(typeAnalyzer.meet(first._1._2, second._1._2), exclusionOracle), 246 reduce(typeAnalyzer.meet(first._1._3, second._1._3), exclusionOracle)) 246 247 for ( f <- set ; if ! result ) 247 248 if ( subtype(f._1._2, meet._1) && … … 262 263 * simplif "t" 263 264 */ 264 private def reduce(t: Type ): Type = t match {265 private def reduce(t: Type, exclusionOracle: ExclusionOracle): Type = t match { 265 266 case SIntersectionType(info, elements) => 266 267 val (tuples, nots) = elements.partition(NodeUtil.isTupleType) … … 269 270 // If all the "elements" have comprises clauses 270 271 // and they all include type "M", then "M" is the meet. 271 existComprisedMeet(elements ) match {272 existComprisedMeet(elements, exclusionOracle) match { 272 273 case Some(m) => m 273 274 case _ => t … … 292 293 293 294 /* If all the "types" have comprises clauses 294 * and they all include type "M", then "M" is the meet. 295 */ 296 private def existComprisedMeet(types: List[Type]): Option[TraitType] = { 297 var meet: List[TraitType] = null 295 * and they all include types "comprised", 296 * then if "comprised" = {"M"} and all the others are exclusive 297 * then "M" is the meet 298 */ 299 private def existComprisedMeet(types: List[Type], 300 exclusionOracle: ExclusionOracle): Option[TraitType] = { 301 var allComprises = List[(Id, List[TraitType])]() 302 var meets: List[TraitType] = null 298 303 for ( t <- types ) { 299 304 if ( t.isInstanceOf[TraitType] ) { 300 STypesUtil.getTypes(t.asInstanceOf[TraitType].getName,301 globalEnv, compilation_unit) match {305 val name = t.asInstanceOf[TraitType].getName 306 STypesUtil.getTypes(name, globalEnv, compilation_unit) match { 302 307 case ti:ProperTraitIndex => 303 308 var comprises = List[TraitType]() 304 for ( s <- toSet(ti.comprisesTypes) ) comprises = s::comprises 309 for ( s <- toSet(ti.comprisesTypes) ) comprises = s::comprises 310 allComprises = (name, comprises)::allComprises 305 311 if ( ! comprises.isEmpty ) { 306 if ( meet == null ) meet= comprises307 else meet = meet.intersect(comprises)312 if ( meets == null ) meets = comprises 313 else meets = meets.intersect(comprises) 308 314 } else return None // no comprises clause 309 315 case _ => return None // not a trait … … 311 317 } else return None 312 318 } 313 if ( meet.length == 1 ) Some(meet.head) 314 else None 319 if ( meets.length == 1 ) { 320 val meet = meets.head 321 def nonExclusive(pair: (List[TraitType], List[TraitType])): Boolean = { 322 for ( first <- pair._1 - meet ) { 323 for ( second <- pair._2 - meet ) { 324 if ( typeAnalyzer.equivalent(first, second).isFalse && 325 ! exclusionOracle.excludes(first, second) ) 326 return true 327 } 328 } 329 false 330 } 331 for ( first <- allComprises ) { 332 for ( second <- allComprises ; 333 if ! first._1.getText.equals(second._1.getText) ) { 334 if ( nonExclusive(first._2, second._2) ) return None 335 } 336 } 337 Some(meet) 338 } else None 315 339 } 316 340 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala
r3870 r3875 484 484 overloading2: (ArrowType, List[StaticArg])): Boolean = { 485 485 486 val SArrowType(_, domain1, range1, _ ) = overloading1._1487 val SArrowType(_, domain2, range2, _ ) = overloading2._1486 val SArrowType(_, domain1, range1, _, _) = overloading1._1 487 val SArrowType(_, domain2, range2, _, _) = overloading2._1 488 488 489 489 if (equivalentTypes(domain1, domain2)) false … … 699 699 signal(application, message) 700 700 } 701 701 702 702 /** 703 703 * Create an error message that will have type and expected type inserted. … … 706 706 private def errorString(message: String): String = 707 707 message + " has type %s, but it must have %s type." 708 708 709 709 /** 710 710 * Create an error message that will have type and expected type inserted. … … 856 856 analyzer.extend(statics, wheres)) 857 857 val newContract = contract.map(c => newChecker.check(c)) 858 858 859 859 // If setter decl and no return type given, make it void. 860 860 val returnType = … … 863 863 else 864 864 rType 865 865 866 866 // Get the new return type and body. 867 867 val (newReturnType, newBody) = returnType match { 868 868 869 869 // If there is a declared return type, check the body, expecting this 870 870 // type. If this is a setter, check that the return type is a void too. … … 874 874 (Some(rt), newChecker.checkExpr(body, rt, errorString("Function body", 875 875 "declared return"))) 876 876 877 877 case None => 878 878 val newBody = newChecker.checkExpr(body) … … 983 983 } 984 984 985 985 986 986 /** 987 987 * Check an expression and guarantee that its type is substitutable for the … … 991 991 * operators in it; the first is replaced with the actual type and the second 992 992 * with the expected type. 993 * 993 * 994 994 * @param expr The expression node to type check. 995 995 * @param expected The expected type of this expression. … … 1005 1005 val checkedExpr = checkExpr(expr, Some(expected)) 1006 1006 getType(checkedExpr) match { 1007 case Some(typ) => 1007 case Some(typ) => 1008 1008 isSubtype(typ, expected, expr, message.format(normalize(typ), normalize(expected))) 1009 1009 addType(checkedExpr, typ) … … 1027 1027 * Check an expression, returning the rewritten node. This overloading should 1028 1028 * be called whenever there is no expected type. 1029 * 1029 * 1030 1030 * @param expr The expression node to type check. 1031 1031 * @return The rewritten expression node. … … 1038 1038 * should only ever be called by the other two overloadings. That is, no cases 1039 1039 * in the implementation should call this method itself. 1040 * 1040 * 1041 1041 * @param expr The expression node to type check. 1042 1042 * @param expected The expected type of this expression, if there is one. … … 1047 1047 def checkExpr(expr: Expr, 1048 1048 expected: Option[Type]): Expr = expr match { 1049 1049 1050 1050 case o@SObjectExpr(SExprInfo(span,parenthesized,_), 1051 1051 STraitTypeHeader(sparams, mods, name, where, … … 1719 1719 bindIds, bindExpr, clauses, elseClause) => { 1720 1720 val (checkedExpr, checkedType) = bindExpr.map(checkExpr) match { 1721 1721 1722 1722 // If expr exists and was checked properly, make sure the bindIds are 1723 1723 // not shadowing. … … 1729 1729 }) 1730 1730 (Some(checkedE), getType(checkedE).getOrElse(return expr)) 1731 1731 1732 1732 // If expr does not exist, make sure thr bindIds are not mutable. 1733 1733 case _ => … … 1737 1737 "binding expression cannot be a mutable variable: %s"). 1738 1738 format(id))) 1739 1739 1740 1740 val idTypes = bindIds.map(getTypeFromName(_).getOrElse(return expr)) 1741 1741 (None, NodeFactory.makeMaybeTupleType(NodeUtil.getSpan(expr), 1742 1742 toJavaList(idTypes))) 1743 1743 } 1744 1744 1745 1745 // Check that the number of bindIds matches the size of the bindExpr. 1746 1746 val isMultipleIds = bindIds.size > 1 … … 1770 1770 return c 1771 1771 } 1772 1772 1773 1773 // Construct the types that correspond to each id. 1774 1774 val newType = … … 1780 1780 List[Type](normalize(NodeFactory.makeIntersectionType(checkedType, matchType.first))) 1781 1781 } 1782 1782 1783 1783 val checkedBody = 1784 1784 this.extend(bindIds, newType). 1785 1785 checkExpr(body).asInstanceOf[Block] 1786 1786 1787 1787 STypecaseClause(info, matchType, checkedBody) 1788 1788 } … … 1790 1790 val clauseTypes = 1791 1791 checkedClauses.map(c => getType(c.getBody).getOrElse(return expr)) 1792 1792 1793 1793 // Check the else clause with the new binding. 1794 1794 val newType = … … 1802 1802 checkExpr(e).asInstanceOf[Block]) 1803 1803 val elseType = checkedElse.map(getType(_).getOrElse(return expr)) 1804 1804 1805 1805 // Build union type of all clauses and else. 1806 1806 val allTypes = elseType match { -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/TypeWellFormedChecker.scala
r3805 r3875 129 129 } 130 130 // Effects are not yet supported... 131 case SArrowType(_, domain, range, effect ) => walk(domain); walk(range)131 case SArrowType(_, domain, range, effect, io) => walk(domain); walk(range) 132 132 case SIntersectionType(_, elements) => elements.foreach((t:Type) => walk(t)) 133 133 case SUnionType(_, elements) => elements.foreach((t:Type) => walk(t)) -
trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/FileTests.java
r3854 r3875 55 55 56 56 public class FileTests { 57 58 private static String option = "";59 57 60 58 public static class BaseTest extends TestCase { … … 624 622 protected int justTheTest() 625 623 throws FileNotFoundException, IOException, Throwable { 626 String[] tokens; 627 if ( option.equals("") ) 628 tokens = new String [] {"compile", dir+"/"+makeTestFileName(name)}; 629 else 630 tokens = new String [] {"compile", option, dir+"/"+makeTestFileName(name)}; 624 String[] tokens = new String [] {"compile", dir+"/"+makeTestFileName(name)}; 631 625 int rc = com.sun.fortress.Shell.subMain(tokens); 632 626 return rc; … … 660 654 throws FileNotFoundException, IOException, Throwable { 661 655 // might need to strip the .fss off f "f". 662 String[] tokens; 663 if ( option.equals("") ) 664 tokens = new String [] {"desugar", dir+"/"+makeTestFileName(name)}; 665 else 666 tokens = new String [] {"desugar", option, dir+"/"+makeTestFileName(name)}; 656 String[] tokens = new String [] {"desugar", dir+"/"+makeTestFileName(name)}; 667 657 int rc = com.sun.fortress.Shell.subMain(tokens); 668 658 return rc; … … 695 685 throws FileNotFoundException, IOException, Throwable { 696 686 // might need to strip the .fss off f "f". 697 String[] tokens; 698 if ( option.equals("") ) 699 tokens = new String [] {"link", dir+"/"+makeTestFileName(name)}; 700 else 701 tokens = new String [] {"link", option, dir+"/"+makeTestFileName(name)}; 687 String[] tokens = new String [] {"link", dir+"/"+makeTestFileName(name)}; 702 688 int rc = com.sun.fortress.Shell.subMain(tokens); 703 689 return rc; 704 705 706 690 } 707 691 … … 860 844 boolean failsOnly, 861 845 boolean expect_failure, 862 boolean scala_test) throws IOException { 863 864 if (scala_test) option = "-typecheck-scala"; 846 boolean typechecker_test) throws IOException { 865 847 866 848 TestSuite suite = new TestSuite("Runs all tests in " + dir_name) { … … 921 903 while (st.hasMoreTokens()) { 922 904 String token = st.nextToken(); 923 if (addTest( scala_test, token))905 if (addTest(typechecker_test, token)) 924 906 standardCompilerTests(props, dir, dirname, token, 925 907 expect_failure, shouldFail, failsOnly, … … 929 911 } 930 912 else { 931 if (addTest( scala_test, testname))913 if (addTest(typechecker_test, testname)) 932 914 standardCompilerTests(props, dir, dirname, testname, 933 915 expect_failure, shouldFail, failsOnly, … … 963 945 } 964 946 965 private static boolean addTest(boolean scala_test,947 private static boolean addTest(boolean typechecker_test, 966 948 String test_name) { 967 return ( ! scala_test949 return ( ! typechecker_test 968 950 || test_name.startsWith("Compiled0") 969 951 || test_name.startsWith("Compiled1")

