polylith icon indicating copy to clipboard operation
polylith copied to clipboard

poly check treats :as-alias namespace as loaded

Open seancorfield opened this issue 3 years ago • 3 comments

Describe the bug A namespace referenced purely for an alias, via :as-alias, does not cause a circular reference, but poly check incorrectly treats it as fully-loading the namespace (it should not).

Will provide more details shortly, along with a PR since this is a critical blocker for us at work.

seancorfield avatar Sep 03 '22 02:09 seancorfield

Okay, thanks for the info. One idea is that you create a small workspace in examples, that reproduces the problem, which I can use to check my solution.

tengstrand avatar Sep 05 '22 04:09 tengstrand

I haven't had time to do this yet but might have time this weekend. I have a couple of other, very minor fixes to propose as well so I may send PRs for those soon too.

seancorfield avatar Oct 07 '22 06:10 seancorfield

Here's the change we made in our fork to simply "ignore" requires that use :as-alias (at least in terms of loaded libs).

This isn't ideal (per discussions on Slack) because it prevents poly from checking that only interfaces are used in this case. A complete solution is likely to involve quite a bit of rework in Polylith because it currently assumes that the list of required nses can be used for two purposes: checking the "rules" of component usage (good, still wanted in this case), and figuring out the dependency graph (not true in this case: :require [top-ns.component.interface :as-alias thing] does not contribute to the dependency graph -- it only introduces an alias, as if ns-alias were called).

seancorfield avatar Oct 11 '22 21:10 seancorfield

I may have a simple solution to this. Will look into this today @seancorfield.

tengstrand avatar Oct 25 '22 07:10 tengstrand

https://clojure.atlassian.net/browse/CLJ-2123

tengstrand avatar Oct 25 '22 11:10 tengstrand

I have hopefully fixed the problem, and you can have a look at the issue-247 branch, @seancorfield. If the code refers to another component interface using :as-alias then the :interface-deps will not be populated with that dependency, which solves the problem with circular dependencies. However, if the code refers to an implementing namespace using :as-alias then it will be included, and we will get both error 101 (Dependency on implementing namespace) and error 104 (circular dependency). The second error is in this case not correct, but you have to fix the error 101 first anyway, and it simplified the implementation a lot.

tengstrand avatar Oct 28 '22 07:10 tengstrand

That sounds like a pretty slick solution to the problem. I'll try to find time over the weekend to put together a branch based on issue-247 but with our classloader and GC patches applied and then try it on Monday at work.

seancorfield avatar Oct 29 '22 04:10 seancorfield

OK, I merged your issue-247 branch into a new branch in my fork (as-alias-247) and then cherry-picked my classloader and GC commits onto that, and I've set a reminder for Monday for me to test that as work. I should have feedback for you pretty quickly at that point.

seancorfield avatar Oct 29 '22 19:10 seancorfield

This fix seems to be working well. Thank you!

seancorfield avatar Nov 05 '22 18:11 seancorfield

The PR for this has been merged so this issue and #211 are both completed.

seancorfield avatar Dec 05 '22 18:12 seancorfield