Skip to content

Commit

Permalink
[7.4.0] Remove unused code from Bzlmod package (#23359)
Browse files Browse the repository at this point in the history
Also avoids a pattern that could result in a class initialization
deadlock.

Closes #23229.

PiperOrigin-RevId: 660673482
Change-Id: Ie89ffc2e956b6e14b81cfe4462cd97241bf78be3

Closes #23346
  • Loading branch information
fmeum authored Aug 20, 2024
1 parent 0e5d7ff commit 694b280
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.repository.downloader.Checksum;
import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
import com.google.devtools.build.skyframe.SkyKey;
Expand All @@ -33,7 +32,7 @@
*/
@AutoValue
@GenerateTypeAdapter
public abstract class BazelLockFileValue implements SkyValue, Postable {
public abstract class BazelLockFileValue implements SkyValue {

// NOTE: See "HACK" note in BazelLockFileModule. While this hack exists, normal increments of the
// lockfile version need to be done by 2 at a time (i.e. keep LOCK_FILE_VERSION an odd number).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Key key(RepositoryName repositoryName) {
}

/** Represents an unsuccessful repository lookup. */
public static final class RepoRuleNotFoundValue extends BzlmodRepoRuleValue {
private static final class RepoRuleNotFoundValue extends BzlmodRepoRuleValue {
private RepoRuleNotFoundValue() {
super(/*pkg=*/ null, /*ruleName=*/ null);
}
Expand All @@ -58,7 +58,7 @@ public Rule getRule() {
}
}

public static final RepoRuleNotFoundValue REPO_RULE_NOT_FOUND_VALUE = new RepoRuleNotFoundValue();
public static final BzlmodRepoRuleValue REPO_RULE_NOT_FOUND_VALUE = new RepoRuleNotFoundValue();

/** Argument for the SkyKey to request a BzlmodRepoRuleValue. */
@AutoCodec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public GitRepoSpecBuilder setPatchCmds(List<String> patchCmds) {
return setAttr("patch_cmds", patchCmds);
}

@CanIgnoreReturnValue
public GitRepoSpecBuilder setPatchCmdsWin(List<String> patchCmdsWin) {
return setAttr("patch_cmds_win", patchCmdsWin);
}

public RepoSpec build() {
return RepoSpec.builder()
.setBzlFile(GIT_REPO_PATH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.ryanharter.auto.value.gson.GenerateTypeAdapter;
import java.util.Optional;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;
Expand All @@ -38,7 +37,6 @@
* each dep, the {@code compatibility_level}, the {@code registry} the module comes from, etc.
*/
@AutoValue
@GenerateTypeAdapter
public abstract class InterimModule extends ModuleBase {

/**
Expand Down Expand Up @@ -133,8 +131,6 @@ public abstract static class Builder {
/** Optional; defaults to {@link #setName}. */
public abstract Builder setRepoName(String value);

public abstract Builder setBazelCompatibility(ImmutableList<String> value);

abstract ImmutableList.Builder<String> bazelCompatibilityBuilder();

@CanIgnoreReturnValue
Expand All @@ -143,8 +139,6 @@ public final Builder addBazelCompatibilityValues(Iterable<String> values) {
return this;
}

public abstract Builder setExecutionPlatformsToRegister(ImmutableList<String> value);

abstract ImmutableList.Builder<String> executionPlatformsToRegisterBuilder();

@CanIgnoreReturnValue
Expand All @@ -153,8 +147,6 @@ public final Builder addExecutionPlatformsToRegister(Iterable<String> values) {
return this;
}

public abstract Builder setToolchainsToRegister(ImmutableList<String> value);

abstract ImmutableList.Builder<String> toolchainsToRegisterBuilder();

@CanIgnoreReturnValue
Expand All @@ -167,22 +159,6 @@ public final Builder addToolchainsToRegister(Iterable<String> values) {

public abstract Builder setDeps(ImmutableMap<String, DepSpec> value);

abstract ImmutableMap.Builder<String, DepSpec> depsBuilder();

@CanIgnoreReturnValue
public Builder addDep(String depRepoName, DepSpec depSpec) {
depsBuilder().put(depRepoName, depSpec);
return this;
}

abstract ImmutableMap.Builder<String, DepSpec> originalDepsBuilder();

@CanIgnoreReturnValue
public Builder addOriginalDep(String depRepoName, DepSpec depSpec) {
originalDepsBuilder().put(depRepoName, depSpec);
return this;
}

public abstract Builder setRegistry(Registry value);

public abstract Builder setExtensionUsages(ImmutableList<ModuleExtensionUsage> value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public static Builder builder() {
public abstract ImmutableTable<RepositoryName, String, RepositoryName>
getRecordedRepoMappingEntries();

public abstract Builder toBuilder();

public boolean shouldLockExtension() {
return getModuleExtensionMetadata().isEmpty()
|| !getModuleExtensionMetadata().get().getReproducible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.ryanharter.auto.value.gson.GenerateTypeAdapter;
import java.util.Map;
import javax.annotation.Nullable;

Expand All @@ -35,7 +34,6 @@
* <p>For the intermediate type used during module resolution, see {@link InterimModule}.
*/
@AutoValue
@GenerateTypeAdapter
public abstract class Module extends ModuleBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public abstract class ModuleExtensionUsage {
*/
public abstract Optional<ModuleExtensionId.IsolationKey> getIsolationKey();

/** The module that contains this particular extension usage. */
public abstract ModuleKey getUsingModule();

/** Represents one "proxy object" returned from one {@code use_extension} call. */
@AutoValue
@GenerateTypeAdapter
Expand Down Expand Up @@ -168,8 +165,6 @@ public abstract static class Builder {

public abstract Builder setIsolationKey(Optional<ModuleExtensionId.IsolationKey> value);

public abstract Builder setUsingModule(ModuleKey value);

public abstract Builder setProxies(ImmutableList<Proxy> value);

abstract ImmutableList.Builder<Proxy> proxiesBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.google.devtools.build.lib.skyframe.PackageLookupValue;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.PrecomputedValue.Precomputed;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -163,8 +162,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
return null;
}
getModuleFileResult.downloadEventHandler.replayOn(env.getListener());
String moduleFileHash =
new Fingerprint().addBytes(getModuleFileResult.moduleFile.getContent()).hexDigestAndReset();

CompiledModuleFile compiledModuleFile;
try {
Expand Down Expand Up @@ -224,7 +221,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)

return NonRootModuleFileValue.create(
module,
moduleFileHash,
RegistryFileDownloadEvent.collectToMap(
getModuleFileResult.downloadEventHandler.getPosts()));
}
Expand Down Expand Up @@ -420,10 +416,6 @@ public static RootModuleFileValue evaluateRootModuleFile(
StarlarkSemantics starlarkSemantics,
ExtendedEventHandler eventHandler)
throws ModuleFileFunctionException, InterruptedException {
String moduleFileHash =
new Fingerprint()
.addBytes(compiledRootModuleFile.moduleFile().getContent())
.hexDigestAndReset();
ModuleThreadContext moduleThreadContext =
execModuleFile(
compiledRootModuleFile,
Expand Down Expand Up @@ -487,7 +479,6 @@ public static RootModuleFileValue evaluateRootModuleFile(
.collect(toImmutableSet());
return RootModuleFileValue.create(
module,
moduleFileHash,
overrides,
nonRegistryOverrideCanonicalRepoNameLookup,
moduleFilePaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public abstract class ModuleFileValue implements SkyValue {
*/
public abstract InterimModule getModule();

/** The hash string of Module.bazel (using SHA256) */
public abstract String getModuleFileHash();

/**
* Hashes of files obtained (or known to be missing) from registries while obtaining this module
* file.
Expand All @@ -57,10 +54,8 @@ public abstract static class NonRootModuleFileValue extends ModuleFileValue {

public static NonRootModuleFileValue create(
InterimModule module,
String moduleFileHash,
ImmutableMap<String, Optional<Checksum>> registryFileHashes) {
return new AutoValue_ModuleFileValue_NonRootModuleFileValue(
module, moduleFileHash, registryFileHashes);
return new AutoValue_ModuleFileValue_NonRootModuleFileValue(module, registryFileHashes);
}
}

Expand Down Expand Up @@ -97,13 +92,11 @@ public ImmutableMap<String, Optional<Checksum>> getRegistryFileHashes() {

public static RootModuleFileValue create(
InterimModule module,
String moduleFileHash,
ImmutableMap<String, ModuleOverride> overrides,
ImmutableMap<RepositoryName, String> nonRegistryOverrideCanonicalRepoNameLookup,
ImmutableSet<PathFragment> moduleFilePaths) {
return new AutoValue_ModuleFileValue_RootModuleFileValue(
module,
moduleFileHash,
overrides,
nonRegistryOverrideCanonicalRepoNameLookup,
moduleFilePaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ ModuleExtensionUsage buildUsage() throws EvalException {
ModuleExtensionUsage.builder()
.setExtensionBzlFile(extensionBzlFile)
.setExtensionName(extensionName)
.setUsingModule(context.getModuleBuilder().getKey())
.setProxies(proxies)
.setTags(tags.build());
if (isolate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ static ModuleNameAndCompatibilityLevel create(String moduleName, int compatibili
moduleName, compatibilityLevel);
}

@SuppressWarnings("unused")
// Used in equals.
abstract String getModuleName();

@SuppressWarnings("unused")
// Used in equals.
abstract int getCompatibilityLevel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.starlarkbuildapi.repository.RepositoryModuleApi.TagClassApi;
import java.util.Optional;
import net.starlark.java.syntax.Location;

/**
* Represents a tag class, which is a "class" of {@link Tag}s that share the same attribute schema.
Expand All @@ -33,23 +32,18 @@ public abstract class TagClass implements TagClassApi {
/** Documentation about this tag class. */
public abstract Optional<String> getDoc();

/** The Starlark code location where this tag class was defined. */
public abstract Location getLocation();

/**
* A mapping from the <em>public</em> name of an attribute to the position of said attribute in
* {@link #getAttributes}.
*/
public abstract ImmutableMap<String, Integer> getAttributeIndices();

public static TagClass create(
ImmutableList<Attribute> attributes, Optional<String> doc, Location location) {
public static TagClass create(ImmutableList<Attribute> attributes, Optional<String> doc) {
ImmutableMap.Builder<String, Integer> attributeIndicesBuilder =
ImmutableMap.builderWithExpectedSize(attributes.size());
for (int i = 0; i < attributes.size(); i++) {
attributeIndicesBuilder.put(attributes.get(i).getPublicName(), i);
}
return new AutoValue_TagClass(
attributes, doc, location, attributeIndicesBuilder.buildOrThrow());
return new AutoValue_TagClass(attributes, doc, attributeIndicesBuilder.buildOrThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ public Object moduleExtension(
@Override
public TagClass tagClass(
Dict<?, ?> attrs, // Dict<String, StarlarkAttrModule.Descriptor>
Object doc, // <String> or Starlark.NONE
StarlarkThread thread)
throws EvalException {
Object doc // <String> or Starlark.NONE
) throws EvalException {
ImmutableList.Builder<Attribute> attrBuilder = ImmutableList.builder();
for (Map.Entry<String, Descriptor> attr :
Dict.cast(attrs, String.class, Descriptor.class, "attrs").entrySet()) {
Expand All @@ -343,7 +342,6 @@ public TagClass tagClass(
}
return TagClass.create(
attrBuilder.build(),
Starlark.toJavaOptional(doc, String.class).map(Starlark::trimDocString),
thread.getCallerLocation());
Starlark.toJavaOptional(doc, String.class).map(Starlark::trimDocString));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ Object moduleExtension(
+ " generating tools.",
named = true,
positional = false)
},
useStarlarkThread = true)
})
TagClassApi tagClass(
Dict<?, ?> attrs, // Dict<String, StarlarkAttrModuleApi.Descriptor>
Object doc,
StarlarkThread thread)
Object doc)
throws EvalException;

/** Represents a tag class, which is a "class" of tags that share the same attribute schema. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Object moduleExtension(
}

@Override
public TagClassApi tagClass(Dict<?, ?> attrs, Object doc, StarlarkThread thread)
public TagClassApi tagClass(Dict<?, ?> attrs, Object doc)
throws EvalException {
return new TagClassApi() {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ private static ModuleExtensionUsage createModuleExtensionUsage(
.setImports(importsBuilder.buildOrThrow())
.setContainingModuleFilePath(LabelConstants.MODULE_DOT_BAZEL_FILE_NAME)
.build())
.setUsingModule(ModuleKey.ROOT)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static RepositoryMapping createRepositoryMapping(ModuleKey key, String...
}

public static TagClass createTagClass(Attribute... attrs) {
return TagClass.create(ImmutableList.copyOf(attrs), Optional.of("doc"), Location.BUILTIN);
return TagClass.create(ImmutableList.copyOf(attrs), Optional.of("doc"));
}

/** A builder for {@link Tag} for testing purposes. */
Expand Down
Loading

0 comments on commit 694b280

Please sign in to comment.