nice-commit Mailing List for The Nice Programming Language (Page 16)
Brought to you by:
bonniot
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
(60) |
Mar
(125) |
Apr
(183) |
May
(140) |
Jun
(227) |
Jul
(141) |
Aug
(181) |
Sep
(75) |
Oct
(89) |
Nov
(187) |
Dec
(162) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(69) |
Feb
(197) |
Mar
(98) |
Apr
(26) |
May
(10) |
Jun
(85) |
Jul
(88) |
Aug
(79) |
Sep
(80) |
Oct
(81) |
Nov
(53) |
Dec
(109) |
| 2005 |
Jan
(68) |
Feb
(77) |
Mar
(232) |
Apr
(79) |
May
(37) |
Jun
(37) |
Jul
(3) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
(10) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(9) |
| 2007 |
Jan
(2) |
Feb
(8) |
Mar
(2) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
|
Nov
(17) |
Dec
(6) |
| 2008 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Arjan B. <ar...@us...> - 2005-03-09 14:48:05
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4762/F:/nice/stdlib/nice/lang/inline Modified Files: Instanceof.java Log Message: Implemented instanceof on option types. Index: Instanceof.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/Instanceof.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Instanceof.java 11 Aug 2004 09:06:04 -0000 1.5 --- Instanceof.java 9 Mar 2005 14:47:48 -0000 1.6 *************** *** 29,38 **** public class Instanceof extends Procedure2 implements Inlineable { public static Instanceof create(String param) { return instance; } ! public final static Instanceof instance = new Instanceof(); public void compile (ApplyExp exp, Compilation comp, Target target) --- 29,49 ---- public class Instanceof extends Procedure2 implements Inlineable { + private final boolean option; + public static Instanceof create(String param) { + if ("option".equals(param)) + return optionInstance; + return instance; } ! private Instanceof(boolean option) ! { ! this.option = option; ! } ! ! public final static Instanceof instance = new Instanceof(false); ! public final static Instanceof optionInstance = new Instanceof(true); public void compile (ApplyExp exp, Compilation comp, Target target) *************** *** 73,84 **** sure it is not null. */ ! code.emitIfNull(); ! code.emitPushBoolean(false); ! code.emitElse(); ! code.emitPushBoolean(true); ! code.emitFi(); } else ! code.emitInstanceof(type); } --- 84,114 ---- sure it is not null. */ ! if (option) ! code.emitPushBoolean(true); ! else ! { ! code.emitIfNull(); ! code.emitPushBoolean(false); ! code.emitElse(); ! code.emitPushBoolean(true); ! code.emitFi(); ! } } else ! { ! if (option) ! { ! code.emitDup(); ! code.emitIfNull(); ! code.emitPop(1); ! code.emitPushBoolean(true); ! code.emitElse(); ! } ! ! code.emitInstanceof(type); ! ! if (option) ! code.emitFi(); ! } } *************** *** 87,94 **** --- 117,136 ---- gnu.bytecode.CodeAttr code = comp.getCode(); + if (option) + { + code.emitDup(); + code.emitIfNull(); + code.emitPop(1); + code.emitPushBoolean(true); + code.emitElse(); + } + type.compile(comp, Target.pushObject); value.compile(comp, Target.pushObject); code.emitInvoke (ClassType.make("java.lang.Class").getDeclaredMethod("isInstance", 1)); + + if (option) + code.emitFi(); } |
|
From: Arjan B. <ar...@us...> - 2005-03-09 14:48:04
|
Update of /cvsroot/nice/Nice/testsuite/compiler/expressions/operators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4762/F:/nice/testsuite/compiler/expressions/operators Modified Files: null.testsuite Log Message: Implemented instanceof on option types. Index: null.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/expressions/operators/null.testsuite,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** null.testsuite 13 Oct 2004 18:28:49 -0000 1.6 --- null.testsuite 9 Mar 2005 14:47:49 -0000 1.7 *************** *** 46,47 **** --- 46,55 ---- /// PASS int[] i = [1,2] || [3,4]; + + /// PASS + ?String x = null; + assert x instanceof ?String; + + /// PASS + ?String x = "abc"; + assert x instanceof ?String; |
|
From: Arjan B. <ar...@us...> - 2005-03-09 14:48:02
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4762/F:/nice/stdlib/nice/lang Modified Files: native.nice Log Message: Implemented instanceof on option types. Index: native.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/native.nice,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** native.nice 8 Aug 2004 10:45:36 -0000 1.10 --- native.nice 9 Mar 2005 14:47:48 -0000 1.11 *************** *** 40,42 **** */ <T,U> boolean `instanceof`(T value, Class<U>) = ! inline nice.lang.inline.Instanceof(); --- 40,48 ---- */ <T,U> boolean `instanceof`(T value, Class<U>) = ! inline nice.lang.inline.Instanceof("sure"); ! ! /** ! Tests whether a value is either null or an instance of a given class. ! */ ! <T,U> boolean `optionInstanceof`(?T value, Class<U>) = ! inline nice.lang.inline.Instanceof("option"); |
|
From: Arjan B. <ar...@us...> - 2005-03-09 14:47:58
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4762/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Implemented instanceof on option types. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.313 retrieving revision 1.314 diff -C2 -d -r1.313 -r1.314 *** Parser.jj 8 Mar 2005 19:12:13 -0000 1.313 --- Parser.jj 9 Mar 2005 14:47:46 -0000 1.314 *************** *** 2067,2073 **** { res=RelationalExpression() ! [ { Token t; TypeConstantExp type; } ! t="instanceof" type=typeExpression() ! { type.isLiteral = true; return bossa.syntax.dispatch.createCallExp(symb(t), res, type); } ] { return res; } --- 2067,2081 ---- { res=RelationalExpression() ! [ { Token t; TypeConstantExp type; boolean option = false;} ! t="instanceof" ! [ "?" {option = true;} ] ! type=typeExpression() ! { type.isLiteral = true; ! Expression sym; ! if (option) ! sym = symb("optionInstanceof", t, true); ! else ! sym = symb(t); ! return bossa.syntax.dispatch.createCallExp(symb(t), res, type); } ] { return res; } |
|
From: Arjan B. <ar...@us...> - 2005-03-08 23:08:33
|
Update of /cvsroot/nice/Nice/testsuite/compiler/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30132/F:/nice/testsuite/compiler/syntax Added Files: generics.testsuite Log Message: New generics syntax tests. --- NEW FILE: generics.testsuite --- /// PASS /// Toplevel <T, U | T extends U> U foo(T x) = x; /// PASS foo(["abc"]); /// Toplevel <T extends Collection> void foo(T<String> x) {} /// PASS bug foo(["abc"]); /// Toplevel <T extends Collection<String>> void foo(T x) {} |
|
From: Artem Gr K. <ar...@us...> - 2005-03-08 20:11:56
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13375/src/bossa/modules Modified Files: DirectoryCompiledContent.java Log Message: Wrap FileInputStream with BufferedInputStream. Index: DirectoryCompiledContent.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/DirectoryCompiledContent.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DirectoryCompiledContent.java 13 Feb 2004 17:43:36 -0000 1.9 --- DirectoryCompiledContent.java 8 Mar 2005 20:11:36 -0000 1.10 *************** *** 66,70 **** return null; ! ClassType res = null; try{ res = gnu.bytecode.ClassFileInput.readClassType(name, s); } catch(LinkageError e){} --- 66,71 ---- return null; ! ClassType res = null; ! s = new BufferedInputStream( s ); try{ res = gnu.bytecode.ClassFileInput.readClassType(name, s); } catch(LinkageError e){} |
|
From: Artem Gr K. <ar...@us...> - 2005-03-08 19:34:05
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1907/testsuite/compiler/typing Modified Files: dti.testsuite Log Message: Type merging works (for IfExp). Index: dti.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/dti.testsuite,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dti.testsuite 8 Mar 2005 12:45:52 -0000 1.8 --- dti.testsuite 8 Mar 2005 19:33:20 -0000 1.9 *************** *** 57,61 **** s. /*/// FAIL HERE*/ substring(1); ! /// PASS bug ?String s = maybeString(); if (maybeTrue()) --- 57,61 ---- s. /*/// FAIL HERE*/ substring(1); ! /// PASS ?String s = maybeString(); if (maybeTrue()) *************** *** 78,82 **** } ! /// PASS bug ?String s = null; if(maybeTrue()) --- 78,82 ---- } ! /// PASS ?String s = null; if(maybeTrue()) *************** *** 279,283 **** assert a.y == 1; ! /// PASS bug ?C a = new D(); if (maybeTrue()) --- 279,283 ---- assert a.y == 1; ! /// PASS ?C a = new D(); if (maybeTrue()) |
|
From: Artem Gr K. <ar...@us...> - 2005-03-08 19:34:04
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1907/src/bossa/syntax Modified Files: tools.nice typecheck.nice Log Message: Type merging works (for IfExp). Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.105 retrieving revision 1.106 diff -C2 -d -r1.105 -r1.106 *** tools.nice 6 Mar 2005 12:55:57 -0000 1.105 --- tools.nice 8 Mar 2005 19:33:19 -0000 1.106 *************** *** 196,199 **** --- 196,200 ---- ?mlsub.typing.TypeConstructor TypeConstructor_fromTypeSymbol(mlsub.typing.TypeSymbol) = native mlsub.typing.TypeConstructor mlsub.typing.TypeConstructor.fromTypeSymbol(mlsub.typing.TypeSymbol); ?gnu.bytecode.Type TypeImport_lookup(String, ?Location) = native gnu.bytecode.Type nice.tools.code.TypeImport.lookup(String, Location); + ?mlsub.typing.Monotype Types_merge(mlsub.typing.Monotype, mlsub.typing.Monotype) = native mlsub.typing.Monotype nice.tools.typing.Types.merge(mlsub.typing.Monotype, mlsub.typing.Monotype); // Retypings needed since java types are not strict. Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** typecheck.nice 7 Mar 2005 20:52:53 -0000 1.128 --- typecheck.nice 8 Mar 2005 19:33:19 -0000 1.129 *************** *** 533,555 **** } /** * Collect inference information from branches, * so that it can be propagated outwards. */ - class DeepMemoryRec { - MonoSymbol variable; - mlsub.typing.Monotype type; - toString() = "(" variable "," type ")"; - } - var Stack<Stack<DeepMemoryRec>> deepMemory = new Stack(); - equals( DeepMemoryRec a, DeepMemoryRec b ) = a.variable == b.variable; - void populateDeepMemory(MonoSymbol variable, mlsub.typing.Monotype type) { if(deepMemory.size() == 0) return; let branch = deepMemory.peek(); ! let rec = new DeepMemoryRec(variable: variable, type: type); ! while( branch.removeElement( rec ) ){} ! branch.push(rec); } --- 533,547 ---- } + var Stack<Map<MonoSymbol,mlsub.typing.Monotype>> deepMemory = new Stack(); + /** * Collect inference information from branches, * so that it can be propagated outwards. */ void populateDeepMemory(MonoSymbol variable, mlsub.typing.Monotype type) { if(deepMemory.size() == 0) return; let branch = deepMemory.peek(); ! branch.put( variable, type ); } *************** *** 566,571 **** enterBlock(); ! let Stack<DeepMemoryRec> ifBranchInference = new Stack(); ! let Stack<DeepMemoryRec> elseBranchInference = new Stack(); deepMemory.push( elseBranchInference ); --- 558,563 ---- enterBlock(); ! let Map<MonoSymbol,mlsub.typing.Monotype> thenBranchInference = new HashMap(); ! let Map<MonoSymbol,mlsub.typing.Monotype> elseBranchInference = new HashMap(); deepMemory.push( elseBranchInference ); *************** *** 575,579 **** ?List<(MonoSymbol, mlsub.typing.Monotype)> instanceofInElse; ! deepMemory.push( ifBranchInference ); try { --- 567,571 ---- ?List<(MonoSymbol, mlsub.typing.Monotype)> instanceofInElse; ! deepMemory.push( thenBranchInference ); try { *************** *** 602,606 **** // which is good when calling the compiler repeatedly from the same JVM. enterElse(); ! let got = deepMemory.pop(); assert got == ifBranchInference; } --- 594,598 ---- // which is good when calling the compiler repeatedly from the same JVM. enterElse(); ! let got = deepMemory.pop(); assert got == thenBranchInference; } *************** *** 635,655 **** // Check if we can propagate some of the type inference information outwards. ! if(ifBranchInference.size() != 0 || elseBranchInference.size() != 0) ! ifPropagation(e, ifBranchInference, elseBranchInference); } ! void ifPropagation(IfExp e, Stack<DeepMemoryRec> ifBranchInference, Stack<DeepMemoryRec> elseBranchInference){ ! let condition = e.condition; ! if(! (condition instanceof bossa.syntax.CallExp) || ! condition.isCallTo("==")) return; ! if(condition.arguments.size() != 2) return; ! let argle = condition.arguments.get(0); let leNull = argle.value.isNull(); ! let argri = condition.arguments.get(1); let riNull = argri.value.isNull(); ! if((leNull || riNull) && leNull != riNull){ ! if(e.elseExp instanceof bossa.syntax.VoidConstantExp && ifBranchInference.size() != 0){ ! let arg = leNull ? argri.value : argle.value; ! let variable = localVariable( arg ); if( null == variable ) return; ! for(rec : ifBranchInference) if(variable == rec.variable) ! variable.setVarType( rec.type, otherBranch: variable.type, out: variable.type ); ! } } } --- 627,645 ---- // Check if we can propagate some of the type inference information outwards. ! if(thenBranchInference.size() != 0 || elseBranchInference.size() != 0) ! ifMerging(e, thenBranchInference, elseBranchInference); } ! void ifMerging(IfExp e, ! Map<MonoSymbol,mlsub.typing.Monotype> thenBranchInference, ! Map<MonoSymbol,mlsub.typing.Monotype> elseBranchInference){ ! let entryIt = thenBranchInference.entrySet().iterator(); ! while( entryIt.hasNext() ){ ! Map$Entry<MonoSymbol,mlsub.typing.Monotype> leEntry = entryIt.next(); ! MonoSymbol variable = leEntry.getKey(); ! ?mlsub.typing.Monotype riType = elseBranchInference.get( variable ); if(riType == null) continue; ! mlsub.typing.Monotype leType = leEntry.getValue(); ! ?mlsub.typing.Monotype merged = Types_merge( leType, riType ); if(merged == null) continue; ! variable.setVarType( merged, otherBranch: variable.type, out: variable.type ); } } |
|
From: Artem Gr K. <ar...@us...> - 2005-03-08 19:33:36
|
Update of /cvsroot/nice/Nice/src/nice/tools/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1907/src/nice/tools/typing Modified Files: Types.java Log Message: Type merging works (for IfExp). Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/typing/Types.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Types.java 8 Mar 2005 16:03:26 -0000 1.13 --- Types.java 8 Mar 2005 19:33:22 -0000 1.14 *************** *** 389,391 **** --- 389,444 ---- return false; } + + /**************************************************************** + * Merging + ****************************************************************/ + + // <bonniot> this merge is not optimal since it does not search of a common supertype, + // <bonniot> only if one is smaller than the other + // <bonniot> but it should be useful already, and enough to test an algo that needs it + // <arjanb> yeah it would handle 95% of the cases + public static Monotype merge(Monotype m1, Monotype m2) + { + if (m1 == m2) + return m1; + + Monotype raw1 = equivalent(m1); + Monotype raw2 = equivalent(m2); + + TypeConstructor head; + if (Typing.testRigidLeq(raw1.head(), raw2.head())) + head = raw2.head(); + else if (Typing.testRigidLeq(raw2.head(), raw1.head())) + head = raw1.head(); + else + return null; + + Monotype[] args1 = ((MonotypeConstructor) raw1).getTP(); + Monotype[] args2 = ((MonotypeConstructor) raw2).getTP(); + Monotype[] args; + if (args1 == null && args2 == null) + // no-arg type constructors + args = null; + else + { + // Resursively merge the type parameters. + args = new Monotype[args1.length]; + for (int i = 0; i < args.length; i++) + { + args[i] = merge(args1[i], args2[i]); + if (args[i] == null) + return null; + } + } + + Monotype raw = new MonotypeConstructor(head, args); + + TypeConstructor marker; + if (isSure(m1) && isSure(m2)) + marker = PrimitiveType.sureTC; + else + marker = PrimitiveType.maybeTC; + + return new MonotypeConstructor(marker, new Monotype[]{raw}); + } } |
|
From: Arjan B. <ar...@us...> - 2005-03-08 19:12:23
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28925/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Make 'extends' an alternative for '<:' and allow <T extends Foo> constraints. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.312 retrieving revision 1.313 diff -C2 -d -r1.312 -r1.313 *** Parser.jj 7 Mar 2005 17:10:52 -0000 1.312 --- Parser.jj 8 Mar 2005 19:12:13 -0000 1.313 *************** *** 574,592 **** TypeSymbol binder(Collection atomics): ! { ! TypeIdent first; ! TypeConstructor second; ! MonotypeVar id; ! Token t; } { LOOKAHEAD( typeIdent() typeConstructor() ) ! first=typeIdent() ! second=typeConstructor() { ! atomics.add(new TypeConstructorLeqCst(second,first)); ! return second; } ! | { boolean sure = false; } [ "!" { sure = true; } ] id=monotypeVar() --- 574,607 ---- TypeSymbol binder(Collection atomics): ! { TypeIdent ti; ! TypeConstructor typevar; } { + ( LOOKAHEAD( typeConstructor() "extends" ) + { TypeIdent typevarid; Monotype m2; } + typevarid=typeIdent() "extends" + { typevar = new TypeConstructor(typevarid.getName().toString()); } + ( LOOKAHEAD(typeIdent() ( "," | "|" | ">")) + ti=typeIdent() + { + atomics.add(new TypeConstructorLeqCst(typevar, ti)); + return typevar; + } + | + m2=monotype() + { + atomics.add(new MonotypeLeqCst(typevarid, m2)); + return typevar; + } + ) + | LOOKAHEAD( typeIdent() typeConstructor() ) ! ti=typeIdent() ! typevar=typeConstructor() { ! atomics.add(new TypeConstructorLeqCst(typevar,ti)); ! return typevar; } ! | { MonotypeVar id; boolean sure = false; } [ "!" { sure = true; } ] id=monotypeVar() *************** *** 596,599 **** --- 611,615 ---- return id; } + ) } *************** *** 616,627 **** { ( LOOKAHEAD(2) ! m1=monotype() "<:" m2=monotype() { list.add(new MonotypeLeqCst(m1,m2)); } ! ( "<:" { m1 = m2; } m2 = monotype() { list.add(new MonotypeLeqCst(m1,m2)); } )* | ! t=typeConstructorIdent() ":" i=typeIdent() { list.add(new ImplementsCst(t,i)); } ) --- 632,643 ---- { ( LOOKAHEAD(2) ! m1=monotype() ("<:" | "extends") m2=monotype() { list.add(new MonotypeLeqCst(m1,m2)); } ! ( ("<:" | "extends") { m1 = m2; } m2 = monotype() { list.add(new MonotypeLeqCst(m1,m2)); } )* | ! t=typeConstructorIdent() (":" | "implements") i=typeIdent() { list.add(new ImplementsCst(t,i)); } ) |
|
From: Daniel B. <bo...@us...> - 2005-03-08 16:04:05
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10143/testsuite/compiler/methods Modified Files: generalization.testsuite Log Message: Handle methods that are partly specialized by existing imported methods. Index: generalization.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/generalization.testsuite,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** generalization.testsuite 13 Oct 2004 15:44:08 -0000 1.4 --- generalization.testsuite 8 Mar 2005 16:03:24 -0000 1.5 *************** *** 35,38 **** --- 35,88 ---- /// PASS + /// package a + /// Toplevel + class Top {} class Bot extends Top {} + + class A + { + boolean ran = false; + + void foo(Top x) { ran = true; } + } + + /// package b import a + let a = new a.A(); + doIt(a); + assert a.ran; + + /// Toplevel + abstract interface Fooable + { + void foo(Bot b); + } + + class a.A implements Fooable; + + <Fooable F> void doIt(F fooable) = fooable.foo(new Bot()); + + + /// PASS + // Real-world situation for the above. + doIt(System.out); + + using(let w = new PrintWriter(new OutputStreamWriter(System.out))) { + doIt(w); + } + + /// Toplevel + import java.io.*; + + abstract interface Printer + { + void print(String); + } + + class java.io.PrintStream implements Printer; + class java.io.PrintWriter implements Printer; + + <Printer P> void doIt(P printer) = printer.print("hello\n"); + + + /// PASS let c = new ArrayList(); c.addTwice("A"); |
|
From: Daniel B. <bo...@us...> - 2005-03-08 16:03:39
|
Update of /cvsroot/nice/Nice/src/nice/tools/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10143/src/nice/tools/typing Modified Files: Types.java Log Message: Handle methods that are partly specialized by existing imported methods. Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/typing/Types.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Types.java 12 Jan 2005 18:50:35 -0000 1.12 --- Types.java 8 Mar 2005 16:03:26 -0000 1.13 *************** *** 307,310 **** --- 307,345 ---- /** + @returns true if functional types t1 and t2 have a partly common domain. + that is, there exists some types that belong to both domains. + */ + public static boolean domainsIntersect(Polytype t1, Polytype t2) + { + Typing.enter(); + + try { + + try { + + Constraint.enter(t1.getConstraint()); + Constraint.enter(t2.getConstraint()); + + // There exists argument types ... + Monotype[] args = MonotypeVar.news(parameters(t2).length); + Typing.introduce(args); + + // ... that can be used for both methods ... + Typing.leq(args, parameters(t1)); + Typing.leq(args, parameters(t2)); + } + finally { + Typing.leave(); + } + } + catch (TypingEx ex) { + return false; + } + + // OK, there is an intersection + return true; + } + + /** @returns true if the spec type specializes type parameters of the original type (which can not be checked at runtime during dispatch, and therefore |
|
From: Daniel B. <bo...@us...> - 2005-03-08 16:03:39
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10143/src/bossa/syntax Modified Files: niceMethod.nice Log Message: Handle methods that are partly specialized by existing imported methods. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** niceMethod.nice 8 Mar 2005 10:50:59 -0000 1.23 --- niceMethod.nice 8 Mar 2005 16:03:28 -0000 1.24 *************** *** 152,156 **** return ! mlsub.typing.Typing.smaller(itsDomain, ourDomain, true) && ! nice.tools.typing.Types.typeParameterDispatch(s.getType(), this.getType()); } --- 152,160 ---- return ! // if the two domains have some types in common (they intersect) ! // then we can consider this is specialized by d ! // (provided we already know d it not more general than this, in which ! // we would have said that this specializes d). ! nice.tools.typing.Types.domainsIntersect(this.getType(), s.getType()) && ! nice.tools.typing.Types.typeParameterDispatch(s.getType(), this.getType()); } |
|
From: Arjan B. <ar...@us...> - 2005-03-08 12:46:03
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21243/F:/nice/testsuite/compiler/typing Modified Files: dti.testsuite Log Message: Additional testcases for merging and instanceof type inference. Index: dti.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/dti.testsuite,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dti.testsuite 7 Mar 2005 23:02:44 -0000 1.7 --- dti.testsuite 8 Mar 2005 12:45:52 -0000 1.8 *************** *** 4,7 **** --- 4,11 ---- void maybeThrow() = throw new Exception(); boolean maybeTrue() = true; + class A {} + class B extends A { int x = 0; } + class C extends A { int y = 1; } + class D extends C {} /// PASS *************** *** 197,198 **** --- 201,294 ---- func(); } + + /// PASS bug + ?String s = maybeString(); + try { + s = "abc"; + maybeThrow(); + } catch (Exception e) { + s = "abc"; + } + s.substring(1); + + /// PASS bug + ?String s = maybeString(); + try { + s = null; + maybeThrow(); + } catch (Exception e) { + s = null; + } finally { + s = "abc"; + } + s.substring(1); + + /// PASS bug + A a = new A(); + a = new B(); + assert a.x == 0; + + /// PASS bug + A a = new A(); + a = new B(); + a = new C(); + assert a.y == 1; + + /// PASS bug + A a = new A(); + if (a instanceof B) + a = a; + else + a = new B(); + + assert a.x == 0; + + /// FAIL + A a = new A(); + if (! (a instanceof B)) + a = new B(); + + a = new A(); + assert a. /*/// FAIL HERE*/ x == 0; + + /// PASS bug + A a = new A(); + if (! (a instanceof B)) + a = new B(); + else + a = a; + + assert a.x == 0; + + /// FAIL + A a = new A(); + if (maybeTrue()) + a = new B(); + else + a = new C(); + + assert a. /*/// FAIL HERE*/ x == 0; + + /// PASS bug + A a = new A(); + if (maybeTrue()) + a = new C(); + else + a = new D(); + + assert a.y == 1; + + /// PASS bug + ?C a = new D(); + if (maybeTrue()) + { + if (a == null) + a = new C(); + } + else + { + if (!(a instanceof D)) + a = new D(); + } + + assert a.y == 1; |
|
From: Daniel B. <bo...@us...> - 2005-03-08 10:51:18
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23136/src/bossa/syntax Modified Files: niceMethod.nice Log Message: Factored out the specialization predicates. Finally under one pagefull. Hopefully the logics is clear now. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** niceMethod.nice 8 Mar 2005 10:11:09 -0000 1.22 --- niceMethod.nice 8 Mar 2005 10:50:59 -0000 1.23 *************** *** 107,150 **** let itsDomain = nice.tools.typing.Types.domain(s.getType()); ! // Do we have a smaller domain? ! if (! (mlsub.typing.Typing.smaller(ourDomain, itsDomain, true)) ! || nice.tools.typing.Types.typeParameterDispatch(this.getType(), s.getType())) { ! // If the method is imported, ! // check if the reverse relation holds with that method ! if (d.module != null && d.module.compiled() && ! mlsub.typing.Typing.smaller(itsDomain, ourDomain, true) && ! ! nice.tools.typing.Types.typeParameterDispatch(s.getType(), this.getType())) ! { ! if (! nice.tools.typing.Types.covariantSpecialization(s.getType(), this.getType())) ! this.reportReturnTypeError(shouldBeLess: true, than: d); ! // d is a specialized version of this. ! if (d instanceof NiceMethod) ! d.addSpecializedMethod(this); ! // Therefore, all its implementations also belong to this. ! addAllAlternatives(d, this); ! } ! continue; ! } ! // In a compiled package, we don't need checking. ! if (! module.compiled()) ! if (! this.checkOverride(s, d, ourDomain, itsDomain)) ! // Ignore. Errors are reported by checkOverride. ! continue; ! this.addSpecializedMethod(d); ! } ! homonyms = null; } private UserError reportReturnTypeError ! (boolean shouldBeLess, MethodDeclaration than) { ! let message = shouldBeLess ? "This return type should be less precise than the return type of method" : "This return type is less precise than the original return type of method"; --- 107,163 ---- let itsDomain = nice.tools.typing.Types.domain(s.getType()); ! if (this.specializes(s, ourDomain, itsDomain)) ! { ! // In a compiled package, we don't need checking. ! if (! module.compiled()) ! if (! this.checkOverride(s, d, ourDomain, itsDomain)) ! // Ignore. Errors are reported by checkOverride. ! continue; ! ! this.addSpecializedMethod(d); ! } ! else if (this.isSpecializedBy(d, s, ourDomain, itsDomain)) { ! if (! nice.tools.typing.Types.covariantSpecialization(s.getType(), this.getType())) ! this.reportReturnTypeError(shouldBeLessPrecise: true, than: d); ! // d is a specialized version of this. ! if (d instanceof NiceMethod) ! d.addSpecializedMethod(this); ! // Therefore, all its implementations also belong to this. ! addAllAlternatives(d, this); ! } ! } ! homonyms = null; ! } ! private boolean specializes ! (VarSymbol s, ! mlsub.typing.Domain ourDomain, mlsub.typing.Domain itsDomain) ! = ! mlsub.typing.Typing.smaller(ourDomain, itsDomain, true) ! && ! nice.tools.typing.Types.typeParameterDispatch(this.getType(), s.getType()); ! private boolean isSpecializedBy ! (MethodDeclaration d, VarSymbol s, ! mlsub.typing.Domain ourDomain, mlsub.typing.Domain itsDomain) ! { ! // Only consider imported methods. ! // Methods being compiled will be found in the direct way ! // if they override this method. ! if (d.module == null || ! d.module.compiled()) ! return false; ! return ! mlsub.typing.Typing.smaller(itsDomain, ourDomain, true) && ! ! nice.tools.typing.Types.typeParameterDispatch(s.getType(), this.getType()); } private UserError reportReturnTypeError ! (boolean shouldBeLessPrecise, MethodDeclaration than) { ! let message = shouldBeLessPrecise ? "This return type should be less precise than the return type of method" : "This return type is less precise than the original return type of method"; *************** *** 163,167 **** { if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) ! this.reportReturnTypeError(shouldBeLess: false, than: d); // Check if we are a proper specialization, or if we actually have --- 176,180 ---- { if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) ! this.reportReturnTypeError(shouldBeLessPrecise: false, than: d); // Check if we are a proper specialization, or if we actually have |
|
From: Daniel B. <bo...@us...> - 2005-03-08 10:11:38
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11694/src/bossa/syntax Modified Files: niceMethod.nice Log Message: Further refactoring for simplification. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** niceMethod.nice 8 Mar 2005 09:48:54 -0000 1.21 --- niceMethod.nice 8 Mar 2005 10:11:09 -0000 1.22 *************** *** 91,95 **** return; ! mlsub.typing.Domain ourDomain = nice.tools.typing.Types.domain(this.getType()); for (s : notNull(homonyms)) --- 91,95 ---- return; ! let ourDomain = nice.tools.typing.Types.domain(this.getType()); for (s : notNull(homonyms)) *************** *** 105,109 **** continue; ! mlsub.typing.Domain itsDomain = nice.tools.typing.Types.domain(s.getType()); // Do we have a smaller domain? --- 105,109 ---- continue; ! let itsDomain = nice.tools.typing.Types.domain(s.getType()); // Do we have a smaller domain? *************** *** 118,126 **** { if (! nice.tools.typing.Types.covariantSpecialization(s.getType(), this.getType())) ! User.error ! (returnTypeLocation!=null ? returnTypeLocation : this.location(), ! "The return type should be less precise than the return type of method\n" + ! d + "\ndefined in:\n" + ! d.location()); // d is a specialized version of this. --- 118,122 ---- { if (! nice.tools.typing.Types.covariantSpecialization(s.getType(), this.getType())) ! this.reportReturnTypeError(shouldBeLess: true, than: d); // d is a specialized version of this. *************** *** 147,150 **** --- 143,158 ---- } + private UserError reportReturnTypeError + (boolean shouldBeLess, MethodDeclaration than) + { + let message = shouldBeLess ? + "This return type should be less precise than the return type of method" : + "This return type is less precise than the original return type of method"; + + return User.error + (returnTypeLocation != null ? returnTypeLocation : this.location(), + message + "\n" than "\ndefined in:\n" + than.location()); + } + /** Return true if the override of d by this is OK. Return false if the override should be ignored. *************** *** 155,165 **** { if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) ! { ! User.error ! (returnTypeLocation != null ? returnTypeLocation : this.location(), ! "The return type is less precise than the original return type of method\n" + ! d + "\ndefined in:\n" + ! d.location()); ! } // Check if we are a proper specialization, or if we actually have --- 163,167 ---- { if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) ! this.reportReturnTypeError(shouldBeLess: false, than: d); // Check if we are a proper specialization, or if we actually have |
|
From: Daniel B. <bo...@us...> - 2005-03-08 09:49:03
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5461/src/bossa/syntax Modified Files: niceMethod.nice Log Message: Factored checkOverride out to simplify the logics of findSpecializedMethods. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** niceMethod.nice 6 Mar 2005 01:34:26 -0000 1.20 --- niceMethod.nice 8 Mar 2005 09:48:54 -0000 1.21 *************** *** 136,168 **** // In a compiled package, we don't need checking. ! if (module.compiled()) ! { ! this.addSpecializedMethod(d); continue; - } - - if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) - { - User.error - (returnTypeLocation != null ? returnTypeLocation : this.location(), - "The return type is less precise than the original return type of method\n" + - d + "\ndefined in:\n" + - d.location()); - } - - // Check if we are a proper specialization, or if we actually have - // the same domain. - if (mlsub.typing.Typing.smaller(itsDomain, ourDomain)) - { - if (module == d.module) - User.error(this, "This method has a domain identical to " + - d + ", which is defined at " + d.location()); - else - // Methods with identical domains in different packages are - // accepted, but they do not specialize each other. - // They can be refered to unambiguously by using their - // fully qualified name. - continue; - } this.addSpecializedMethod(d); --- 136,143 ---- // In a compiled package, we don't need checking. ! if (! module.compiled()) ! if (! this.checkOverride(s, d, ourDomain, itsDomain)) ! // Ignore. Errors are reported by checkOverride. continue; this.addSpecializedMethod(d); *************** *** 172,175 **** --- 147,184 ---- } + /** Return true if the override of d by this is OK. + Return false if the override should be ignored. + */ + private boolean checkOverride + (VarSymbol s, MethodDeclaration d, + mlsub.typing.Domain ourDomain, mlsub.typing.Domain itsDomain) + { + if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) + { + User.error + (returnTypeLocation != null ? returnTypeLocation : this.location(), + "The return type is less precise than the original return type of method\n" + + d + "\ndefined in:\n" + + d.location()); + } + + // Check if we are a proper specialization, or if we actually have + // the same domain. + if (mlsub.typing.Typing.smaller(itsDomain, ourDomain)) + { + if (module == d.module) + User.error(this, "This method has a domain identical to " + + d + ", which is defined at " + d.location()); + else + // Methods with identical domains in different packages are + // accepted, but they do not specialize each other. + // They can be refered to unambiguously by using their + // fully qualified name. + return false; + } + + return true; + } + private void addSpecializedMethod(MethodDeclaration method) { |
|
From: Arjan B. <ar...@us...> - 2005-03-07 23:02:58
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17660/F:/nice/testsuite/compiler/typing Modified Files: dti.testsuite Log Message: Additional testcases for nullness inference. Index: dti.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/dti.testsuite,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dti.testsuite 7 Mar 2005 20:52:52 -0000 1.6 --- dti.testsuite 7 Mar 2005 23:02:44 -0000 1.7 *************** *** 7,10 **** --- 7,23 ---- /// PASS ?String s = maybeString(); + s = "abc"; + s.substring(1); + + /// FAIL + ?String s = maybeString(); + if (s == null) + s = "abc"; + + s = null; + s. /*/// FAIL HERE*/ substring(1); + + /// PASS + ?String s = maybeString(); if (s == null) s = "abc"; *************** *** 13,16 **** --- 26,69 ---- /// PASS + ?String s = maybeString(); + s = "abc"; + if (s != null) + s = null; + + /// FAIL + ?String s = "abc"; + if (s != null) + s = null; + + s. /*/// FAIL HERE*/ substring(1); + + /// FAIL + ?String s = maybeString(); + s = "abc"; + if (maybeTrue()) + { + if (maybeTrue()) + s = null; + else + s = "abc"; + } + else + s = "abc"; + + s. /*/// FAIL HERE*/ substring(1); + + /// PASS bug + ?String s = maybeString(); + if (maybeTrue()) + { + if (s == null) + s = "abc"; + } + else + s = "abc"; + + s.substring(1); + + /// PASS // Nullness analysis on assignments. RFE# 681385 func( null ).append( "123" ); |
|
From: Artem Gr K. <ar...@us...> - 2005-03-07 20:53:36
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11965/src/bossa/syntax Modified Files: typecheck.nice Log Message: RFE 681385 implemented. Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.127 retrieving revision 1.128 diff -C2 -d -r1.127 -r1.128 *** typecheck.nice 7 Mar 2005 17:10:50 -0000 1.127 --- typecheck.nice 7 Mar 2005 20:52:53 -0000 1.128 *************** *** 54,58 **** // RFE 681385 - // To debug in jdb use "stop at bossa.syntax.fun:LINE". if( variable != null ){ let valueType = e.value.type, toType = to.type, varType = variable.type; --- 54,57 ---- *************** *** 534,537 **** --- 533,557 ---- } + /** + * Collect inference information from branches, + * so that it can be propagated outwards. + */ + class DeepMemoryRec { + MonoSymbol variable; + mlsub.typing.Monotype type; + toString() = "(" variable "," type ")"; + } + var Stack<Stack<DeepMemoryRec>> deepMemory = new Stack(); + equals( DeepMemoryRec a, DeepMemoryRec b ) = a.variable == b.variable; + + void populateDeepMemory(MonoSymbol variable, mlsub.typing.Monotype type) + { + if(deepMemory.size() == 0) return; + let branch = deepMemory.peek(); + let rec = new DeepMemoryRec(variable: variable, type: type); + while( branch.removeElement( rec ) ){} + branch.push(rec); + } + typecheck(IfExp e) { *************** *** 546,549 **** --- 566,573 ---- enterBlock(); + let Stack<DeepMemoryRec> ifBranchInference = new Stack(); + let Stack<DeepMemoryRec> elseBranchInference = new Stack(); + deepMemory.push( elseBranchInference ); + try{ ?List<MonoSymbol> notNullInThen, notNullInElse; *************** *** 551,554 **** --- 575,580 ---- ?List<(MonoSymbol, mlsub.typing.Monotype)> instanceofInElse; + deepMemory.push( ifBranchInference ); + try { (notNullInThen, notNullInElse) = nullnessInfo(condition); *************** *** 576,579 **** --- 602,606 ---- // which is good when calling the compiler repeatedly from the same JVM. enterElse(); + let got = deepMemory.pop(); assert got == ifBranchInference; } *************** *** 598,601 **** --- 625,629 ---- finally{ exitIf(); + let got = deepMemory.pop(); assert got == elseBranchInference; } *************** *** 605,608 **** --- 633,656 ---- "\nthen: " + thenExp.getType() + "\nelse: " + elseExp.getType()); + + // Check if we can propagate some of the type inference information outwards. + if(ifBranchInference.size() != 0 || elseBranchInference.size() != 0) + ifPropagation(e, ifBranchInference, elseBranchInference); + } + + void ifPropagation(IfExp e, Stack<DeepMemoryRec> ifBranchInference, Stack<DeepMemoryRec> elseBranchInference){ + let condition = e.condition; + if(! (condition instanceof bossa.syntax.CallExp) || ! condition.isCallTo("==")) return; + if(condition.arguments.size() != 2) return; + let argle = condition.arguments.get(0); let leNull = argle.value.isNull(); + let argri = condition.arguments.get(1); let riNull = argri.value.isNull(); + if((leNull || riNull) && leNull != riNull){ + if(e.elseExp instanceof bossa.syntax.VoidConstantExp && ifBranchInference.size() != 0){ + let arg = leNull ? argri.value : argle.value; + let variable = localVariable( arg ); if( null == variable ) return; + for(rec : ifBranchInference) if(variable == rec.variable) + variable.setVarType( rec.type, otherBranch: variable.type, out: variable.type ); + } + } } *************** *** 622,625 **** --- 670,674 ---- { variable.type = now; + populateDeepMemory( variable, now ); if (overrideOut != null) { |
|
From: Artem Gr K. <ar...@us...> - 2005-03-07 20:53:32
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11965/testsuite/compiler/typing Modified Files: dti.testsuite Log Message: RFE 681385 implemented. Index: dti.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/dti.testsuite,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dti.testsuite 7 Mar 2005 08:16:52 -0000 1.5 --- dti.testsuite 7 Mar 2005 20:52:52 -0000 1.6 *************** *** 5,9 **** boolean maybeTrue() = true; ! /// PASS bug ?String s = maybeString(); if (s == null) --- 5,9 ---- boolean maybeTrue() = true; ! /// PASS ?String s = maybeString(); if (s == null) *************** *** 12,16 **** s.substring(1); ! /// PASS bug // Nullness analysis on assignments. RFE# 681385 func( null ).append( "123" ); --- 12,16 ---- s.substring(1); ! /// PASS // Nullness analysis on assignments. RFE# 681385 func( null ).append( "123" ); |
|
From: Artem Gr K. <ar...@us...> - 2005-03-07 20:53:23
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11965 Modified Files: NEWS Log Message: RFE 681385 implemented. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** NEWS 7 Mar 2005 17:10:54 -0000 1.67 --- NEWS 7 Mar 2005 20:52:55 -0000 1.68 *************** *** 6,19 **** // Test if a bad implementation has returned null instead of exception. if(maybeNull(prng) == null) workaround(); ! * Nullness analysis of assignments (RFE 681385) is partially implemented. It is now possible to write: ! class Foo {} ! var ?Foo FOO_INSTANCE = null; ! Foo getFooInstance(){ ! var instance = FOO_INSTANCE; if( null != instance ) return instance; ! instance = new Foo(); FOO_INSTANCE = instance; return instance; } ! becouse Nice will detect that "instance" is of a "sure type" ! after the "instance = new Foo();" assignment. * Allow value returns in void methods. It's useful when exiting from the method in a branch after doing a single operation. For instance, --- 6,20 ---- // Test if a bad implementation has returned null instead of exception. if(maybeNull(prng) == null) workaround(); ! * Nullness analysis of assignments (RFE 681385) is implemented. It is now possible to write: ! Foo func( ?Foo foo ) { ! if( foo == null ) { ! foo = new Foo(); ! } ! // Do some operations ! return foo; } ! since Nice will detect that foo can't be null after the "foo = new Foo()", ! and will propagate this information outside of "if( foo == null )" checks. * Allow value returns in void methods. It's useful when exiting from the method in a branch after doing a single operation. For instance, |
|
From: Artem Gr K. <ar...@us...> - 2005-03-07 20:44:43
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9651 Modified Files: build.xml Log Message: Enable assertions when bootstrapping (-ea argument in jvmArgs). Index: build.xml =================================================================== RCS file: /cvsroot/nice/Nice/build.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** build.xml 7 Mar 2005 13:39:53 -0000 1.6 --- build.xml 7 Mar 2005 20:44:33 -0000 1.7 *************** *** 4,8 **** <property environment="env" /> <property name="compiler" value="modern" description="example: ant -Dcompiler=gcj" /> ! <property name="jvmArgs" value="-Xms64m -Xmx128m" description="JVM options for speed" /> <property name="build" value="classes" /> <property name="javaccVersion" value="javacc-3.2" /> --- 4,8 ---- <property environment="env" /> <property name="compiler" value="modern" description="example: ant -Dcompiler=gcj" /> ! <property name="jvmArgs" value="-Xms64m -Xmx128m -ea" description="JVM options" /> <property name="build" value="classes" /> <property name="javaccVersion" value="javacc-3.2" /> |
|
From: Daniel B. <bo...@us...> - 2005-03-07 17:11:37
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18310/src/bossa/parser Modified Files: Parser.jj Log Message: Allow value returns in void methods. We don't need to distinguish between real and "fake" (sugared) returns. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.311 retrieving revision 1.312 diff -C2 -d -r1.311 -r1.312 *** Parser.jj 22 Feb 2005 12:53:16 -0000 1.311 --- Parser.jj 7 Mar 2005 17:10:52 -0000 1.312 *************** *** 1350,1354 **** ( exp=Expression() ";" ! { code = bossa.syntax.dispatch.createReturnStmt(exp, /* fake */ true); } | {Statement res;} --- 1350,1354 ---- ( exp=Expression() ";" ! { code = bossa.syntax.dispatch.createReturnStmt(exp); } | {Statement res;} |
|
From: Daniel B. <bo...@us...> - 2005-03-07 17:11:37
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18310/src/bossa/syntax Modified Files: typecheck.nice return.nice enum.nice Log Message: Allow value returns in void methods. We don't need to distinguish between real and "fake" (sugared) returns. Index: return.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/return.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** return.nice 1 Dec 2004 02:00:32 -0000 1.4 --- return.nice 7 Mar 2005 17:10:51 -0000 1.5 *************** *** 22,26 **** { Expression value; - boolean fake = false; mlsub.typing.Polytype returnType() --- 22,25 ---- *************** *** 61,77 **** public Statement createReturnStmt(?Expression value) { - return createReturnStmt(value, false); - } - - /** - @param fake This return was not explicitely written, but is the result - of syntactic sugar. - */ - public Statement createReturnStmt(?Expression value, boolean fake) - { if (value == null) return new VoidReturnStmt(); ! let res = new ReturnStmt(value: value, fake: fake); res.setLocation(value.location()); return res; --- 60,67 ---- public Statement createReturnStmt(?Expression value) { if (value == null) return new VoidReturnStmt(); ! let res = new ReturnStmt(value: value); res.setLocation(value.location()); return res; Index: enum.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/enum.nice,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** enum.nice 6 Mar 2005 01:34:26 -0000 1.19 --- enum.nice 7 Mar 2005 17:10:51 -0000 1.20 *************** *** 82,86 **** globalDefs.add(createMethodBodyDefinition(impl, new LocatedString("family"), null, new LinkedList(), createReturnStmt(createLiteralArrayExp( ! elements.map(createIdentExp)), true))); //generate the prettyprint string --- 82,86 ---- globalDefs.add(createMethodBodyDefinition(impl, new LocatedString("family"), null, new LinkedList(), createReturnStmt(createLiteralArrayExp( ! elements.map(createIdentExp))))); //generate the prettyprint string Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.126 retrieving revision 1.127 diff -C2 -d -r1.126 -r1.127 *** typecheck.nice 7 Mar 2005 08:16:53 -0000 1.126 --- typecheck.nice 7 Mar 2005 17:10:50 -0000 1.127 *************** *** 914,923 **** r.value = r.value.noOverloading(); else ! { ! if (! r.fake && nice.tools.typing.Types.isVoid(expectedType)) ! throw bossa.util.User.error(r, "Cannot return a value here"); ! ! r.value = r.value.resolveOverloading(new mlsub.typing.Polytype(expectedType)); ! } try { typecheck(r.value); } --- 914,918 ---- r.value = r.value.noOverloading(); else ! r.value = r.value.resolveOverloading(new mlsub.typing.Polytype(expectedType)); try { typecheck(r.value); } *************** *** 925,929 **** try{ ! if (! (r.fake && expectedType != null && nice.tools.typing.Types.isVoid(expectedType))) function.checkReturnedType(r.returnType()); } --- 920,924 ---- try{ ! if (! (expectedType != null && nice.tools.typing.Types.isVoid(expectedType))) function.checkReturnedType(r.returnType()); } |
|
From: Daniel B. <bo...@us...> - 2005-03-07 17:11:29
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18310/testsuite/compiler/typing Modified Files: void.testsuite Log Message: Allow value returns in void methods. We don't need to distinguish between real and "fake" (sugared) returns. Index: void.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/void.testsuite,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** void.testsuite 8 Nov 2003 14:59:48 -0000 1.4 --- void.testsuite 7 Mar 2005 17:10:49 -0000 1.5 *************** *** 10,17 **** assert buffer.toString().equals("foobar"); ! /// FAIL /// Toplevel ! void goo() { ! /* /// FAIL HERE */ return 1; } --- 10,43 ---- assert buffer.toString().equals("foobar"); ! /// PASS ! foo(0); ! foo(1); /// Toplevel ! void fooZero() {} ! ! void foo(int x) ! { ! if (x == 0) ! return fooZero(); ! ! // do something else ! } ! ! /// PASS ! let a = new A(); ! a.add(1); ! a.add(0); ! /// Toplevel ! class A ! { ! StringBuffer s = new StringBuffer(); ! ! void add(int x) ! { ! if (x == 0) ! return s.append("ZERO\n"); ! ! // do something complex ! } } *************** *** 59,62 **** --- 85,93 ---- ?String bar() = "abc"; + /// PASS + /// Toplevel + void foo() { if (1 == 2) return bar(); } + ?String bar() = "abc"; + /// FAIL let x = foo(); |