Skip to content

Commit

Permalink
bzlmod: use env.getValues() instead of getValue() in DiscoveryFunction
Browse files Browse the repository at this point in the history
    (bazelbuild/bazel#13316)

    Before we were requesting the ModuleFileValues one by one. This does not result in things being slow per se (since the individual ModuleFileFunction calls should be parallelized by Skyframe) but technically using getValues() can make SkyValue dependencies cleaner (since there is no dependency between the same "level" of SkyKeys being requested here).

    PiperOrigin-RevId: 382700697
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent a936f04 commit a654891
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
if (env.valuesMissing()) {
return null;
}
return DiscoveryValue.create(root.getModule().getName(), ImmutableMap.copyOf(depGraph));
return DiscoveryValue.create(
root.getModule().getName(), ImmutableMap.copyOf(depGraph), overrides);
}

private static Module rewriteDepKeys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import javax.annotation.Nullable;

/** The result of {@link ModuleFileFunction}. */
@AutoValue
public abstract class ModuleFileValue implements SkyValue {

public static final ModuleKey ROOT_MODULE_KEY = ModuleKey.create("", Version.EMPTY);
public static final ModuleKey ROOT_MODULE_KEY = ModuleKey.create("", "");

/**
* The module resulting from the module file evaluation. Note, in particular, that the version of
Expand All @@ -39,40 +40,15 @@ public abstract class ModuleFileValue implements SkyValue {
*/
public abstract Module getModule();

/** The {@link ModuleFileValue} for non-root modules. */
@AutoValue
public abstract static class NonRootModuleFileValue extends ModuleFileValue {

public static NonRootModuleFileValue create(Module module) {
return new AutoValue_ModuleFileValue_NonRootModuleFileValue(module);
}
}

/**
* The {@link ModuleFileValue} for the root module, containing additional information about
* overrides.
* The overrides specified by the evaluated module file. The key is the module name and the value
* is the override itself.
*/
@AutoValue
public abstract static class RootModuleFileValue extends ModuleFileValue {
/**
* The overrides specified by the evaluated module file. The key is the module name and the
* value is the override itself.
*/
public abstract ImmutableMap<String, ModuleOverride> getOverrides();
public abstract ImmutableMap<String, ModuleOverride> getOverrides();

/**
* A mapping from a canonical repo name to the name of the module. Only works for modules with
* non-registry overrides.
*/
public abstract ImmutableMap<String, String> getNonRegistryOverrideCanonicalRepoNameLookup();

public static RootModuleFileValue create(
Module module,
ImmutableMap<String, ModuleOverride> overrides,
ImmutableMap<String, String> nonRegistryOverrideCanonicalRepoNameLookup) {
return new AutoValue_ModuleFileValue_RootModuleFileValue(
module, overrides, nonRegistryOverrideCanonicalRepoNameLookup);
}
public static ModuleFileValue create(
Module module, ImmutableMap<String, ModuleOverride> overrides) {
return new AutoValue_ModuleFileValue(module, overrides);
}

public static Key key(ModuleKey moduleKey, @Nullable ModuleOverride override) {
Expand Down

0 comments on commit a654891

Please sign in to comment.