Skip to content

Commit b38c23e

Browse files
committed
revert 9b6c3a5
1 parent d534894 commit b38c23e

File tree

3 files changed

+43
-81
lines changed

3 files changed

+43
-81
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public class Compiler implements Opcodes{
223223
static final public Var METHOD = Var.create(null).setDynamic();
224224

225225
//null or not
226-
static final public Var IN_TRY_BLOCK = Var.create(null).setDynamic();
227226
static final public Var IN_CATCH_FINALLY = Var.create(null).setDynamic();
228227

229228
static final public Var NO_RECUR = Var.create(null).setDynamic();
@@ -373,10 +372,6 @@ static boolean isSpecial(Object sym){
373372
return specials.containsKey(sym);
374373
}
375374

376-
static boolean inTailCall(C context) {
377-
return (context == C.RETURN) && (IN_TRY_BLOCK.deref() == null);
378-
}
379-
380375
static Symbol resolveSymbol(Symbol sym){
381376
//already qualified or classname?
382377
if(sym.name.indexOf('.') > 0)
@@ -1009,13 +1004,12 @@ else if(instance != null && instance.hasJavaClass() && instance.getJavaClass() !
10091004
Symbol sym = (Symbol) RT.first(call);
10101005
Symbol tag = tagOf(form);
10111006
PersistentVector args = PersistentVector.EMPTY;
1012-
boolean tailPosition = inTailCall(context);
10131007
for(ISeq s = RT.next(call); s != null; s = s.next())
10141008
args = args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, s.first()));
10151009
if(c != null)
1016-
return new StaticMethodExpr(source, line, column, tag, c, munge(sym.name), args, tailPosition);
1010+
return new StaticMethodExpr(source, line, column, tag, c, munge(sym.name), args);
10171011
else
1018-
return new InstanceMethodExpr(source, line, column, tag, instance, munge(sym.name), args, tailPosition);
1012+
return new InstanceMethodExpr(source, line, column, tag, instance, munge(sym.name), args);
10191013
}
10201014
}
10211015
}
@@ -1452,15 +1446,13 @@ static class InstanceMethodExpr extends MethodExpr{
14521446
public final int line;
14531447
public final int column;
14541448
public final Symbol tag;
1455-
public final boolean tailPosition;
14561449
public final java.lang.reflect.Method method;
14571450

14581451
final static Method invokeInstanceMethodMethod =
14591452
Method.getMethod("Object invokeInstanceMethod(Object,String,Object[])");
14601453

14611454

1462-
public InstanceMethodExpr(String source, int line, int column, Symbol tag, Expr target,
1463-
String methodName, IPersistentVector args, boolean tailPosition)
1455+
public InstanceMethodExpr(String source, int line, int column, Symbol tag, Expr target, String methodName, IPersistentVector args)
14641456
{
14651457
this.source = source;
14661458
this.line = line;
@@ -1469,7 +1461,6 @@ public InstanceMethodExpr(String source, int line, int column, Symbol tag, Expr
14691461
this.methodName = methodName;
14701462
this.target = target;
14711463
this.tag = tag;
1472-
this.tailPosition = tailPosition;
14731464
if(target.hasJavaClass() && target.getJavaClass() != null)
14741465
{
14751466
List methods = Reflector.getMethods(target.getJavaClass(), args.count(), methodName, false);
@@ -1563,10 +1554,10 @@ public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){
15631554
gen.checkCast(type);
15641555
MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args);
15651556
gen.visitLineNumber(line, gen.mark());
1566-
if(tailPosition)
1557+
if(context == C.RETURN)
15671558
{
15681559
ObjMethod method = (ObjMethod) METHOD.deref();
1569-
method.emitClearThis(gen);
1560+
method.emitClearLocals(gen);
15701561
}
15711562
Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method));
15721563
if(method.getDeclaringClass().isInterface())
@@ -1637,14 +1628,12 @@ static class StaticMethodExpr extends MethodExpr{
16371628
public final int column;
16381629
public final java.lang.reflect.Method method;
16391630
public final Symbol tag;
1640-
public final boolean tailPosition;
16411631
final static Method forNameMethod = Method.getMethod("Class classForName(String)");
16421632
final static Method invokeStaticMethodMethod =
16431633
Method.getMethod("Object invokeStaticMethod(Class,String,Object[])");
16441634
final static Keyword warnOnBoxedKeyword = Keyword.intern("warn-on-boxed");
16451635

1646-
public StaticMethodExpr(String source, int line, int column, Symbol tag, Class c,
1647-
String methodName, IPersistentVector args, boolean tailPosition)
1636+
public StaticMethodExpr(String source, int line, int column, Symbol tag, Class c, String methodName, IPersistentVector args)
16481637
{
16491638
this.c = c;
16501639
this.methodName = methodName;
@@ -1653,7 +1642,6 @@ public StaticMethodExpr(String source, int line, int column, Symbol tag, Class c
16531642
this.line = line;
16541643
this.column = column;
16551644
this.tag = tag;
1656-
this.tailPosition = tailPosition;
16571645

16581646
List methods = Reflector.getMethods(c, args.count(), methodName, true);
16591647
if(methods.isEmpty())
@@ -1792,10 +1780,10 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
17921780
MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args);
17931781
gen.visitLineNumber(line, gen.mark());
17941782
//Type type = Type.getObjectType(className.replace('.', '/'));
1795-
if(tailPosition)
1783+
if(context == C.RETURN)
17961784
{
17971785
ObjMethod method = (ObjMethod) METHOD.deref();
1798-
method.emitClearThis(gen);
1786+
method.emitClearLocals(gen);
17991787
}
18001788
Type type = Type.getType(c);
18011789
Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method));
@@ -2279,14 +2267,13 @@ public Expr parse(C context, Object frm) {
22792267
}
22802268
else
22812269
{
2282-
if(bodyExpr == null)
2283-
try {
2284-
Var.pushThreadBindings(RT.map(NO_RECUR, true, IN_TRY_BLOCK, RT.T));
2285-
bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body));
2286-
} finally {
2287-
Var.popThreadBindings();
2288-
}
2289-
2270+
if(bodyExpr == null)
2271+
try {
2272+
Var.pushThreadBindings(RT.map(NO_RECUR, true));
2273+
bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body));
2274+
} finally {
2275+
Var.popThreadBindings();
2276+
}
22902277
if(Util.equals(op, CATCH))
22912278
{
22922279
Class c = HostExpr.maybeClass(RT.second(f), false);
@@ -2334,21 +2321,17 @@ public Expr parse(C context, Object frm) {
23342321
}
23352322
}
23362323
}
2337-
if(bodyExpr == null)
2338-
{
2339-
// this codepath is hit when there is neither catch or finally, e.g. (try (expr))
2340-
// return a body expr directly
2341-
try
2342-
{
2343-
Var.pushThreadBindings(RT.map(NO_RECUR, true));
2344-
bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body));
2345-
}
2346-
finally
2347-
{
2348-
Var.popThreadBindings();
2349-
}
2350-
return bodyExpr;
2351-
}
2324+
if(bodyExpr == null) {
2325+
try
2326+
{
2327+
Var.pushThreadBindings(RT.map(NO_RECUR, true));
2328+
bodyExpr = (new BodyExpr.Parser()).parse(C.EXPRESSION, RT.seq(body));
2329+
}
2330+
finally
2331+
{
2332+
Var.popThreadBindings();
2333+
}
2334+
}
23522335

23532336
return new TryExpr(bodyExpr, catches, finallyExpr, retLocal,
23542337
finallyLocal);
@@ -2596,13 +2579,23 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
25962579
gen.newInstance(type);
25972580
gen.dup();
25982581
MethodExpr.emitTypedArgs(objx, gen, ctor.getParameterTypes(), args);
2582+
if(context == C.RETURN)
2583+
{
2584+
ObjMethod method = (ObjMethod) METHOD.deref();
2585+
method.emitClearLocals(gen);
2586+
}
25992587
gen.invokeConstructor(type, new Method("<init>", Type.getConstructorDescriptor(ctor)));
26002588
}
26012589
else
26022590
{
26032591
gen.push(destubClassName(c.getName()));
26042592
gen.invokeStatic(RT_TYPE, forNameMethod);
26052593
MethodExpr.emitArgsAsArray(args, objx, gen);
2594+
if(context == C.RETURN)
2595+
{
2596+
ObjMethod method = (ObjMethod) METHOD.deref();
2597+
method.emitClearLocals(gen);
2598+
}
26062599
gen.invokeStatic(REFLECTOR_TYPE, invokeConstructorMethod);
26072600
}
26082601
if(context == C.STATEMENT)
@@ -3570,7 +3563,6 @@ static class InvokeExpr implements Expr{
35703563
public final IPersistentVector args;
35713564
public final int line;
35723565
public final int column;
3573-
public final boolean tailPosition;
35743566
public final String source;
35753567
public boolean isProtocol = false;
35763568
public boolean isDirect = false;
@@ -3593,14 +3585,12 @@ static Object sigTag(int argcount, Var v){
35933585
return null;
35943586
}
35953587

3596-
public InvokeExpr(String source, int line, int column, Symbol tag, Expr fexpr, IPersistentVector args, boolean tailPosition) {
3588+
public InvokeExpr(String source, int line, int column, Symbol tag, Expr fexpr, IPersistentVector args) {
35973589
this.source = source;
35983590
this.fexpr = fexpr;
35993591
this.args = args;
36003592
this.line = line;
36013593
this.column = column;
3602-
this.tailPosition = tailPosition;
3603-
36043594
if(fexpr instanceof VarExpr)
36053595
{
36063596
Var fvar = ((VarExpr)fexpr).var;
@@ -3744,10 +3734,10 @@ void emitArgsAndCall(int firstArgToEmit, C context, ObjExpr objx, GeneratorAdapt
37443734
}
37453735
gen.visitLineNumber(line, gen.mark());
37463736

3747-
if(tailPosition)
3737+
if(context == C.RETURN)
37483738
{
37493739
ObjMethod method = (ObjMethod) METHOD.deref();
3750-
method.emitClearThis(gen);
3740+
method.emitClearLocals(gen);
37513741
}
37523742

37533743
gen.invokeInterface(IFN_TYPE, new Method("invoke", OBJECT_TYPE, ARG_TYPES[Math.min(MAX_POSITIONAL_ARITY + 1,
@@ -3763,7 +3753,6 @@ public Class getJavaClass() {
37633753
}
37643754

37653755
static public Expr parse(C context, ISeq form) {
3766-
boolean tailPosition = inTailCall(context);
37673756
if(context != C.EVAL)
37683757
context = C.EXPRESSION;
37693758
Expr fexpr = analyze(context, form.first());
@@ -3840,7 +3829,7 @@ static public Expr parse(C context, ISeq form) {
38403829
// throw new IllegalArgumentException(
38413830
// String.format("No more than %d args supported", MAX_POSITIONAL_ARITY));
38423831

3843-
return new InvokeExpr((String) SOURCE.deref(), lineDeref(), columnDeref(), tagOf(form), fexpr, args, tailPosition);
3832+
return new InvokeExpr((String) SOURCE.deref(), lineDeref(), columnDeref(), tagOf(form), fexpr, args);
38443833
}
38453834
}
38463835

@@ -5865,11 +5854,6 @@ void emitClearLocalsOld(GeneratorAdapter gen){
58655854
}
58665855
}
58675856
}
5868-
5869-
void emitClearThis(GeneratorAdapter gen) {
5870-
gen.visitInsn(Opcodes.ACONST_NULL);
5871-
gen.visitVarInsn(Opcodes.ASTORE, 0);
5872-
}
58735857
}
58745858

58755859
public static class LocalBinding{
@@ -6295,14 +6279,14 @@ public Expr parse(C context, Object frm) {
62956279
{
62966280
if(recurMismatches != null && RT.booleanCast(recurMismatches.nth(i/2)))
62976281
{
6298-
init = new StaticMethodExpr("", 0, 0, null, RT.class, "box", RT.vector(init), false);
6282+
init = new StaticMethodExpr("", 0, 0, null, RT.class, "box", RT.vector(init));
62996283
if(RT.booleanCast(RT.WARN_ON_REFLECTION.deref()))
63006284
RT.errPrintWriter().println("Auto-boxing loop arg: " + sym);
63016285
}
63026286
else if(maybePrimitiveType(init) == int.class)
6303-
init = new StaticMethodExpr("", 0, 0, null, RT.class, "longCast", RT.vector(init), false);
6287+
init = new StaticMethodExpr("", 0, 0, null, RT.class, "longCast", RT.vector(init));
63046288
else if(maybePrimitiveType(init) == float.class)
6305-
init = new StaticMethodExpr("", 0, 0, null, RT.class, "doubleCast", RT.vector(init), false);
6289+
init = new StaticMethodExpr("", 0, 0, null, RT.class, "doubleCast", RT.vector(init));
63066290
}
63076291
//sequential enhancement of env (like Lisp let*)
63086292
try

test/clojure/test_clojure/compilation.clj

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,3 @@
342342
(deftest clj-1399
343343
;; throws an exception on failure
344344
(is (eval `(fn [] ~(CLJ1399. 1)))))
345-
346-
(deftest CLJ-1250-this-clearing
347-
(let [closed-over-in-catch (let [x :foo]
348-
(fn []
349-
(try
350-
(throw (Exception. "boom"))
351-
(catch Exception e
352-
x)))) ;; x should remain accessible to the fn
353-
354-
a (atom nil)
355-
closed-over-in-finally (fn []
356-
(try
357-
:ret
358-
(finally
359-
(reset! a :run))))]
360-
(is (= :foo (closed-over-in-catch)))
361-
(is (= :ret (closed-over-in-finally)))
362-
(is (= :run @a))))

test/clojure/test_clojure/reducers.clj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,3 @@
8989
([ret k v] (when (= k k-fail)
9090
(throw (IndexOutOfBoundsException.)))))
9191
(zipmap (range test-map-count) (repeat :dummy)))))))
92-
93-
(deftest test-closed-over-clearing
94-
;; this will throw OutOfMemory without proper reference clearing
95-
(is (number? (reduce + 0 (r/map identity (range 1e8))))))

0 commit comments

Comments
 (0)