Skip to content

Various starlark cleanups #4010

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

Closed
wants to merge 2 commits into from

Conversation

DavidZbarsky-at
Copy link

What type of PR is this?
> Other

What does this PR do? Why is it needed?
Cleans up various Stalark inefficiencies. This saves around .5s analysis time in our repo, which does not have too much Go code yet. It is likely more noticeable in repos that have more go code

Which issues(s) does this PR fix?

Fixes #

Other notes for review

Copy link

google-cla bot commented Aug 6, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@@ -515,7 +515,7 @@ def _sdk_build_file(ctx, platform, version, experiments):
"{goarch}": goarch,
"{exe}": ".exe" if goos == "windows" else "",
"{version}": version,
"{experiments}": repr(experiments),
"{experiments}": ",".join(experiments),
Copy link
Member

Choose a reason for hiding this comment

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

Does this provide a meaningful performance boost? I'm doubtful of that as there shouldn't be that many go_sdk repos in a given project. Since repr is more obviously correct, I would prefer to keep it.

Copy link
Author

Choose a reason for hiding this comment

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

It allows this simplification which affects every go action

-        "GOEXPERIMENT": ",".join(toolchain.sdk.experiments),
+        "GOEXPERIMENT": toolchain.sdk.experiments,

@@ -82,7 +82,7 @@ def emit_compilepkg(
if bool(nogo) != bool(out_facts):
fail("nogo must be specified if and only if out_facts is specified")

inputs = (sources + embedsrcs + [go.package_list] +
inputs = (sources + embedsrcs + [go.sdk.package_list] +
Copy link
Member

Choose a reason for hiding this comment

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

Only vaguely related: I wonder what we could save if we used depsets here.

Copy link
Author

Choose a reason for hiding this comment

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

we can try in a follow-up :)

@@ -578,14 +570,9 @@ def go_context(ctx, attr = None):
root = goroot,
go = binary,
stdlib = stdlib,
Copy link
Member

Choose a reason for hiding this comment

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

Yay for making this smaller. It's technically public API, but I don't want to view it as such.

def get_mode(ctx, go_toolchain, cgo_context_info, go_config_info):
static = _ternary(go_config_info.static if go_config_info else "off")
static = go_config_info.static if go_config_info else False
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 a safe change?

Copy link
Author

Choose a reason for hiding this comment

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

I believe these values come from //go:config:static so they are already bools, though it's certainly possible that I am not fully following how this works. Tests seem to pass, not sure how our coverage is

@@ -90,6 +94,8 @@ def _proto_library_to_source(_go, attr, source, merge):
merge(source, compiler[GoSource])

def _go_proto_library_impl(ctx):
check_importpaths(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

This seems new?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah so one of the things bothering me is that there are some differences between the library (base, proto, tool) and binary/test attributes/codepaths, but they both funnel into go_context. Then we end up having a bunch of getattr/hasattr and fallbacks to handle both of these. I wonder if it would be cleaner to have a dedicated lib_context and bin_context that have a shared shape?

Absent that, this change hoists check_importpath calls to the library entrypoints, because these attrs don't exist on binaries, and this allows simplifying the check function to avoid hasattr which speeds it up.

Without:
image

With:
image

@DavidZbarsky-at
Copy link
Author

Added another commit from testing in @jbedard's private repo;
Before:
image

After:
image

@dzbarsky
Copy link
Contributor

dzbarsky commented Aug 7, 2024

I'm going to break this up into multiple PRs, starting with #4014

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