Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict lifted vars/keywords to functions that actually use them #176

Open
nasser opened this issue Jul 7, 2020 · 0 comments
Open

Restrict lifted vars/keywords to functions that actually use them #176

nasser opened this issue Jul 7, 2020 · 0 comments
Assignees

Comments

@nasser
Copy link
Owner

nasser commented Jul 7, 2020

Right now the following

(defn xx [a]
  (fn []
    (inc a)))

compiles into

public class <magic>foo$<fn>__17 : AFunction
{
	internal static Var clojure_core$inc;
	internal object a;

	static <magic>foo$<fn>__17()
	{
		<magic>foo$<fn>__17.clojure_core$inc = RT.var("clojure.core", "inc");
	}

	public override object invoke()
	{
		return ((IFn)<magic>foo$<fn>__17.clojure_core$inc.getRawRoot()).invoke(this.a);
	}
}
public class <magic>foo$xx__18 : AFunction
{
	internal static Var clojure_core$inc; // <== should not be here

	static <magic>foo$xx__18()
	{
		<magic>foo$xx__18.clojure_core$inc = RT.var("clojure.core", "inc");
	}

	public override IFn invokeTyped(object a)
	{
		return new <magic>foo$<fn>__17
		{
			a = a
		};
	}

	public override object invoke(object a)
	{
		return this.invokeTyped(a);
	}
}

The var inc is lifted into the function xx despite the fact that it is only used in its nested function. Lifted keywords are similarly affected. Var and keyword collection should be more like closures.

@nasser nasser self-assigned this Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant