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

Break the cyclic dependency between BaseTarget and UntypedTarget. #2037

Conversation

bjaspan
Copy link
Contributor

@bjaspan bjaspan commented Nov 17, 2023

This PR factors createContinuousRangeTarget out of BaseTarget into a new function, createContinuousRangeOrUntypedTarget, which is used by a variety of target types. As a result, BaseTarget.ts no longer needs to import UntypedTarget (indirectly through createContinuousRange.ts).

@bjaspan bjaspan changed the title Break the cyclic dependency between BaseTarget, UntypedTarget, and PlainTarget. Break the cyclic dependency between BaseTarget and UntypedTarget. Nov 17, 2023
@auscompgeek
Copy link
Member

auscompgeek commented Nov 20, 2023

Hmm, there's a fair amount of copy paste here.

Is there a reason we keep createContinuousRange, BaseTarget, and UntypedTarget in separate files?

@pokey
Copy link
Member

pokey commented Nov 20, 2023

Yeah I'm thinking maybe the right answer is to just put those in the same file? That seems less onerous than this approach. Still don't love it, but at least better than this.

@auscompgeek what's your opinion on circular deps?

@bjaspan
Copy link
Contributor Author

bjaspan commented Nov 20, 2023

I tried merging BaseTarget and UntypedTarget as well. It turns out that UntypedTarget depends on PlainTarget (via TokenInsertionRemovalBehavior) which also depends on BaseTarget. So, to solve the problem that way, we'd have to merge BaseTarget.ts, UntypedTarget.ts, and PlainTarget.ts into a single file. I'm fine with that solution; I went with this one only because I guessed that you would all prefer it to merging three files.

@bjaspan
Copy link
Contributor Author

bjaspan commented Nov 20, 2023

Hold on. There is still a cyclic dependency between UntypedTarget.ts and createContinuousRange.ts.

@bjaspan
Copy link
Contributor Author

bjaspan commented Nov 20, 2023

I removed the cyclic dependency between UntypedTarget.ts and createContinuousRange.ts. It would be nice if we had a tool to create a dependency graph, but I believe what we have now is:

  • BaseTarget.ts depends on nothing relevant.
  • createContinuousRange.ts depends on nothing relevant.
  • UntypedTarget.ts depends on BaseTarget.ts and createContinuousRange.ts.
  • All target types depend on BaseTarget.ts, many depend on UntypedTarget.ts, and some depend directly on createContinuousRange.ts.

@bjaspan
Copy link
Contributor Author

bjaspan commented Nov 20, 2023

#2047 is the merging-files approach.

Barry Jaspan and others added 2 commits November 20, 2023 23:40
@bjaspan
Copy link
Contributor Author

bjaspan commented Nov 21, 2023

I've eliminated the copy-paste by introducing a new abstract base template class, CommonTarget, which provides the createContinuousRangeOrUntypedTarget functionality. By exporting it from UntypedTarget, the import graph described in my previous comment is preserved.

Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this looks fine modulo a couple comments. Would be great to get high-level feedback from @auscompgeek if possible, but if too busy we can move forward anyway

.vscode/settings.json Outdated Show resolved Hide resolved
* a createContinuousRange if this and endTarget have the same type or
* otherwise returns an UntypedTarget from this to endTarget.
*/
export abstract class CommonTarget<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I may call this CommonBaseTarget? Idk wdyt @auscompgeek

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommonBase sounds like a bit of a tautology to me 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about CommonContinuousRangeTarget? Any name is fine with me. :-)

@bjaspan bjaspan requested a review from pokey November 23, 2023 05:04
@pokey
Copy link
Member

pokey commented Nov 30, 2023

closing in favour of #2074

@pokey pokey closed this Nov 30, 2023
@bjaspan bjaspan deleted the remove-base-untyped-plain-target-cycle branch January 26, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants