Skip to content

Conversation

@dcbaker
Copy link
Member

@dcbaker dcbaker commented Jan 30, 2026

We effectively do this multiple times otherwise, even though we have all of the information to do it up front once. This simplifies a bunch of code later, and should allow us to do more cleanups later on.

@dcbaker dcbaker requested a review from jpakkane as a code owner January 30, 2026 19:10
@dcbaker dcbaker changed the title calculate link_langauge if it's not set in the DSL build: calculate BuildTarget.link_langauge if it's not set in the DSL Jan 30, 2026
@dcbaker dcbaker force-pushed the submit/calculate-link-langauge-once branch 4 times, most recently from 9c95570 to 644a28c Compare January 30, 2026 22:54
self.builddir, name, self.type_suffix())

def _calculcate_link_language(self) -> Language:
def calculate() -> Language:
Copy link
Member

Choose a reason for hiding this comment

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

Why is this logic defined as a function? It looks like it could be simply executed inline.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because doing it inline requires a lot of null checking, while using a closure makes it much cleaner, the closure can just return when language is found instead.

lang: T.Optional[Language] = None

if self.uses_rust():
    ...
    lang = 'rust'

if lang is None and not languages:
    ...

if lang is None:
    lang = languages[0]

if lang not in self.all_compilers:
    ...
return lang

@sp1ritCS
Copy link
Contributor

sp1ritCS commented Feb 2, 2026

Is #15450 still going to be needed after this?

@dcbaker
Copy link
Member Author

dcbaker commented Feb 2, 2026

@sp1ritCS: I think it still is. This mainly is optimizing the situation where we basically do the same calculation multiple times in multiple places, and what you're doing is orthogonal to that, and what you're doing will help make some of the work I want to do as follow up to this much easier. So, I will go review that.

We more-or-less calculate the link_language several times if the user
doesn't pass it, so let's calculate it ourselves.
@dcbaker dcbaker force-pushed the submit/calculate-link-langauge-once branch from 644a28c to 37bbb9e Compare February 2, 2026 18:22
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