From 83004a94a74c60a4cf1ecccd9d335f1b45a37a27 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 12 Mar 2025 10:22:11 +0100 Subject: [PATCH] Cut down usage of dag.ExistingObjectContentsWalker Use TMetadata everywhere, and only convert to dag.ObjectContentsWalker at the point where we actually return the results of the function. This will be necessary if we want to flush data to storage asynchronously. --- pkg/evaluation/generate_computer/main.go | 7 +- pkg/model/analysis/base_computer.go | 44 +++--- .../compatible_toolchains_for_type.go | 2 +- pkg/model/analysis/compiled_bzl_file.go | 23 ++- pkg/model/analysis/configured_target.go | 84 +++++----- pkg/model/analysis/file_properties_value.go | 15 +- pkg/model/analysis/http_archive_contents.go | 8 +- pkg/model/analysis/http_file_contents.go | 8 +- .../analysis/module_dot_bazel_contents.go | 29 ++-- pkg/model/analysis/module_extension_repo.go | 9 +- pkg/model/analysis/module_extension_repos.go | 8 +- .../analysis/modules_with_remote_overrides.go | 8 +- pkg/model/analysis/package.go | 8 +- .../registered_execution_platforms.go | 2 +- .../analysis/registered_repo_platform.go | 2 +- pkg/model/analysis/registered_toolchains.go | 2 +- pkg/model/analysis/repo.go | 144 +++++++++--------- pkg/model/analysis/resolved_toolchains.go | 14 +- pkg/model/analysis/stable_input_root_path.go | 34 +++-- pkg/model/analysis/target.go | 9 +- .../analysis/target_pattern_expansion.go | 28 ++-- pkg/model/analysis/used_module_extension.go | 15 +- pkg/model/analysis/user_defined_transition.go | 8 +- pkg/model/analysis/visible_target.go | 28 ++-- pkg/model/command/local_executor.go | 8 +- pkg/model/core/patched_message.go | 15 +- .../filesystem/create_file_merkle_tree.go | 8 +- 27 files changed, 262 insertions(+), 308 deletions(-) diff --git a/pkg/evaluation/generate_computer/main.go b/pkg/evaluation/generate_computer/main.go index baf713a..1d4f86b 100644 --- a/pkg/evaluation/generate_computer/main.go +++ b/pkg/evaluation/generate_computer/main.go @@ -33,7 +33,7 @@ func (fd functionDefinition) getKeyType(functionName string, isPatched bool) str func (fd functionDefinition) keyToPatchedMessage() string { if fd.KeyContainsReferences { - return "model_core.PatchedMessage[proto.Message, dag.ObjectContentsWalker]{Message: key.Message, Patcher: key.Patcher}" + return "model_core.NewPatchedMessage[proto.Message](key.Message, key.Patcher)" } else { return "model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, proto.Message](key)" } @@ -203,10 +203,7 @@ func main() { if functionDefinition.NativeValueType == nil { fmt.Printf("\tcase *pb.%s_Key:\n", functionName) fmt.Printf("\t\tm, err := c.base.Compute%sValue(ctx, %s, &typedE)\n", functionName, functionDefinition.typedKeyToArgument(functionName)) - fmt.Printf("\t\treturn model_core.PatchedMessage[proto.Message, dag.ObjectContentsWalker]{\n") - fmt.Printf("\t\t\tMessage: m.Message,\n") - fmt.Printf("\t\t\tPatcher: m.Patcher,\n") - fmt.Printf("\t\t}, err\n") + fmt.Printf("\t\treturn model_core.NewPatchedMessage[proto.Message](m.Message, m.Patcher), err\n") } } fmt.Printf("\tdefault:\n") diff --git a/pkg/model/analysis/base_computer.go b/pkg/model/analysis/base_computer.go index 0508cb1..c516ba3 100644 --- a/pkg/model/analysis/base_computer.go +++ b/pkg/model/analysis/base_computer.go @@ -367,29 +367,25 @@ func (c *baseComputer[TReference, TMetadata]) ComputeBuildResultValue(ctx contex var iterErr error for canonicalTargetLabel := range c.expandCanonicalTargetPattern(ctx, e, canonicalTargetPattern, &iterErr) { - visibleTargetPatcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() visibleTargetValue := e.GetVisibleTargetValue( - model_core.PatchedMessage[*model_analysis_pb.VisibleTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.VisibleTarget_Key{ + model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker]( + &model_analysis_pb.VisibleTarget_Key{ FromPackage: canonicalTargetLabel.GetCanonicalPackage().String(), ToLabel: canonicalTargetLabel.String(), }, - Patcher: visibleTargetPatcher, - }, + ), ) if !visibleTargetValue.IsSet() { missingDependencies = true continue } - targetCompletionPatcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() targetCompletionValue := e.GetTargetCompletionValue( - model_core.PatchedMessage[*model_analysis_pb.TargetCompletion_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.TargetCompletion_Key{ + model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker]( + &model_analysis_pb.TargetCompletion_Key{ Label: visibleTargetValue.Message.Label, }, - Patcher: targetCompletionPatcher, - }, + ), ) if !targetCompletionValue.IsSet() { missingDependencies = true @@ -414,18 +410,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeBuildSpecificationValue(ctx return PatchedBuildSpecificationValue{}, err } - patchedBuildSpecification := model_core.NewPatchedMessageFromExisting( + patchedBuildSpecification := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, buildSpecification, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedBuildSpecificationValue{ - Message: &model_analysis_pb.BuildSpecification_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.BuildSpecification_Value{ BuildSpecification: patchedBuildSpecification.Message, }, - Patcher: patchedBuildSpecification.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(patchedBuildSpecification.Patcher), + ), nil } func (c *baseComputer[TReference, TMetadata]) ComputeBuiltinsModuleNamesValue(ctx context.Context, key *model_analysis_pb.BuiltinsModuleNames_Key, e BuiltinsModuleNamesEnvironment[TReference]) (PatchedBuiltinsModuleNamesValue, error) { @@ -503,20 +497,18 @@ func (c *baseComputer[TReference, TMetadata]) ComputeRepoDefaultAttrsValue(ctx c } func (c *baseComputer[TReference, TMetadata]) ComputeTargetCompletionValue(ctx context.Context, key model_core.Message[*model_analysis_pb.TargetCompletion_Key, TReference], e TargetCompletionEnvironment[TReference]) (PatchedTargetCompletionValue, error) { - configurationReference := model_core.NewPatchedMessageFromExisting( + configurationReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(key, key.Message.ConfigurationReference), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) configuredTarget := e.GetConfiguredTargetValue( - model_core.PatchedMessage[*model_analysis_pb.ConfiguredTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.ConfiguredTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.ConfiguredTarget_Key{ Label: key.Message.Label, ConfigurationReference: configurationReference.Message, }, - Patcher: configurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), + ), ) if !configuredTarget.IsSet() { return PatchedTargetCompletionValue{}, evaluation.ErrMissingDependency diff --git a/pkg/model/analysis/compatible_toolchains_for_type.go b/pkg/model/analysis/compatible_toolchains_for_type.go index f3d881e..fc577b9 100644 --- a/pkg/model/analysis/compatible_toolchains_for_type.go +++ b/pkg/model/analysis/compatible_toolchains_for_type.go @@ -91,7 +91,7 @@ func (c *baseComputer[TReference, TMetadata]) ComputeCompatibleToolchainsForType platformInfoProvider, err := getProviderFromConfiguredTarget( e, platformLabel, - model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, *model_core_pb.Reference](nil), + model_core.NewSimplePatchedMessage[model_core.WalkableReferenceMetadata, *model_core_pb.Reference](nil), platformInfoProviderIdentifier, ) if err != nil { diff --git a/pkg/model/analysis/compiled_bzl_file.go b/pkg/model/analysis/compiled_bzl_file.go index ce7fe2d..cc91f66 100644 --- a/pkg/model/analysis/compiled_bzl_file.go +++ b/pkg/model/analysis/compiled_bzl_file.go @@ -13,7 +13,6 @@ import ( model_filesystem "github.com/buildbarn/bonanza/pkg/model/filesystem" model_starlark "github.com/buildbarn/bonanza/pkg/model/starlark" model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" - "github.com/buildbarn/bonanza/pkg/storage/dag" "go.starlark.net/starlark" "go.starlark.net/syntax" @@ -89,12 +88,12 @@ func (c *baseComputer[TReference, TMetadata]) ComputeCompiledBzlFileValue(ctx co if err != nil { return PatchedCompiledBzlFileValue{}, err } - return PatchedCompiledBzlFileValue{ - Message: &model_analysis_pb.CompiledBzlFile_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.CompiledBzlFile_Value{ CompiledProgram: compiledProgram.Message, }, - Patcher: model_core.MapReferenceMetadataToWalkers(compiledProgram.Patcher), - }, nil + model_core.MapReferenceMetadataToWalkers(compiledProgram.Patcher), + ), nil } func (c *baseComputer[TReference, TMetadata]) ComputeCompiledBzlFileDecodedGlobalsValue(ctx context.Context, key *model_analysis_pb.CompiledBzlFileDecodedGlobals_Key, e CompiledBzlFileDecodedGlobalsEnvironment[TReference]) (starlark.StringDict, error) { @@ -183,18 +182,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeCompiledBzlFileGlobalValue( return PatchedCompiledBzlFileGlobalValue{}, err } - patchedGlobal := model_core.NewPatchedMessageFromExisting( + patchedGlobal := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, global, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedCompiledBzlFileGlobalValue{ - Message: &model_analysis_pb.CompiledBzlFileGlobal_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.CompiledBzlFileGlobal_Value{ Global: patchedGlobal.Message, }, - Patcher: patchedGlobal.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(patchedGlobal.Patcher), + ), nil } var exportsBzlTargetName = label.MustNewTargetName("exports.bzl") diff --git a/pkg/model/analysis/configured_target.go b/pkg/model/analysis/configured_target.go index 6ef2b2d..e36530a 100644 --- a/pkg/model/analysis/configured_target.go +++ b/pkg/model/analysis/configured_target.go @@ -70,7 +70,7 @@ func (c *baseComputer[TReference, TMetadata]) constraintValuesToConstraints(ctx constrainValueInfoProvider, err := getProviderFromConfiguredTarget( e, visibleTarget.Message.Label, - model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, *model_core_pb.Reference](nil), + model_core.NewSimplePatchedMessage[model_core.WalkableReferenceMetadata, *model_core_pb.Reference](nil), constraintValueInfoProviderIdentifier, ) if err != nil { @@ -380,20 +380,18 @@ func (c *baseComputer[TReference, TMetadata]) ComputeConfiguredTargetValue(ctx c // edge transition is specified, apply it. configurationReference := model_core.NewNestedMessage(key, key.Message.ConfigurationReference) if cfgTransitionIdentifier := ruleDefinition.Message.CfgTransitionIdentifier; cfgTransitionIdentifier != "" { - patchedConfigurationReference := model_core.NewPatchedMessageFromExisting( + patchedConfigurationReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) incomingEdgeTransitionValue := e.GetUserDefinedTransitionValue( - model_core.PatchedMessage[*model_analysis_pb.UserDefinedTransition_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.UserDefinedTransition_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.UserDefinedTransition_Key{ TransitionIdentifier: cfgTransitionIdentifier, InputConfigurationReference: patchedConfigurationReference.Message, }, - Patcher: patchedConfigurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(patchedConfigurationReference.Patcher), + ), ) if !incomingEdgeTransitionValue.IsSet() { return PatchedConfiguredTargetValue{}, evaluation.ErrMissingDependency @@ -920,13 +918,13 @@ func (rc *ruleContext[TReference, TMetadata]) configureAttr(thread *starlark.Thr // TODO: Should we cache this in the ruleContext? configurationReference := rc.getPatchedConfigurationReference() transitionValue := rc.environment.GetUserDefinedTransitionValue( - model_core.PatchedMessage[*model_analysis_pb.UserDefinedTransition_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.UserDefinedTransition_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.UserDefinedTransition_Key{ TransitionIdentifier: tr.UserDefined, InputConfigurationReference: configurationReference.Message, }, - Patcher: configurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), + ), ) if !transitionValue.IsSet() { return nil, evaluation.ErrMissingDependency @@ -979,21 +977,19 @@ func (rc *ruleContext[TReference, TMetadata]) configureAttr(thread *starlark.Thr if err != nil { return nil, err } - patchedConfigurationReference1 := model_core.NewPatchedMessageFromExisting( + patchedConfigurationReference1 := model_core.NewPatchedMessageFromExistingCaptured( + rc.computer.objectCapturer, configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) resolvedLabelValue := rc.environment.GetVisibleTargetValue( - model_core.PatchedMessage[*model_analysis_pb.VisibleTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.VisibleTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.VisibleTarget_Key{ FromPackage: visibilityFromPackage.String(), ToLabel: canonicalLabel.String(), ConfigurationReference: patchedConfigurationReference1.Message, }, - Patcher: patchedConfigurationReference1.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(patchedConfigurationReference1.Patcher), + ), ) if !resolvedLabelValue.IsSet() { missingDependencies = true @@ -1006,20 +1002,18 @@ func (rc *ruleContext[TReference, TMetadata]) configureAttr(thread *starlark.Thr } // Obtain the providers of the target. - patchedConfigurationReference2 := model_core.NewPatchedMessageFromExisting( + patchedConfigurationReference2 := model_core.NewPatchedMessageFromExistingCaptured( + rc.computer.objectCapturer, configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) configuredTarget := rc.environment.GetConfiguredTargetValue( - model_core.PatchedMessage[*model_analysis_pb.ConfiguredTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.ConfiguredTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.ConfiguredTarget_Key{ Label: resolvedLabelStr, ConfigurationReference: patchedConfigurationReference2.Message, }, - Patcher: patchedConfigurationReference2.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(patchedConfigurationReference2.Patcher), + ), ) if !configuredTarget.IsSet() { missingDependencies = true @@ -1239,14 +1233,12 @@ func (rc *ruleContext[TReference, TMetadata]) getAttrValueParts(namedAttr *model nil } -func (rc *ruleContext[TReference, TMetadata]) getPatchedConfigurationReference() model_core.PatchedMessage[*model_core_pb.Reference, dag.ObjectContentsWalker] { +func (rc *ruleContext[TReference, TMetadata]) getPatchedConfigurationReference() model_core.PatchedMessage[*model_core_pb.Reference, TMetadata] { // TODO: This function should likely not exist, as we need to // take transitions into account. - return model_core.NewPatchedMessageFromExisting( + return model_core.NewPatchedMessageFromExistingCaptured( + rc.computer.objectCapturer, rc.configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) } @@ -1749,7 +1741,7 @@ func (rce *ruleContextExecutable[TReference, TMetadata]) Attr(thread *starlark.T ToLabel: labelValue.Label, ConfigurationReference: configurationReference.Message, }, - configurationReference.Patcher, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), ), ) if !visibleTarget.IsSet() { @@ -1876,7 +1868,7 @@ func (rcf *ruleContextFile[TReference, TMetadata]) Attr(thread *starlark.Thread, ToLabel: labelValue.Label, ConfigurationReference: configurationReference.Message, }, - configurationReference.Patcher, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), ), ) if !visibleTarget.IsSet() { @@ -2030,7 +2022,7 @@ func (rcf *ruleContextFiles[TReference, TMetadata]) Attr(thread *starlark.Thread ToLabel: labelElement.Label, ConfigurationReference: configurationReference.Message, }, - configurationReference.Patcher, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), ), ) if !visibleTarget.IsSet() { @@ -2316,14 +2308,14 @@ func (tc *toolchainContext[TReference, TMetadata]) Get(thread *starlark.Thread, } configurationReference := rc.getPatchedConfigurationReference() resolvedToolchains := rc.environment.GetResolvedToolchainsValue( - model_core.PatchedMessage[*model_analysis_pb.ResolvedToolchains_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.ResolvedToolchains_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.ResolvedToolchains_Key{ ExecCompatibleWith: execCompatibleWith, ConfigurationReference: configurationReference.Message, Toolchains: execGroupDefinition.Toolchains, }, - Patcher: configurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), + ), ) if !resolvedToolchains.IsSet() { return nil, true, evaluation.ErrMissingDependency @@ -2389,15 +2381,15 @@ type getProviderFromConfiguredTargetEnvironment[TReference any] interface { // getProviderFromConfiguredTarget looks up a single provider that is // provided by a configured target -func getProviderFromConfiguredTarget[TReference any](e getProviderFromConfiguredTargetEnvironment[TReference], targetLabel string, configurationReference model_core.PatchedMessage[*model_core_pb.Reference, dag.ObjectContentsWalker], providerIdentifier label.CanonicalStarlarkIdentifier) (model_core.Message[*model_starlark_pb.Struct_Fields, TReference], error) { +func getProviderFromConfiguredTarget[TReference any, TMetadata model_core.WalkableReferenceMetadata](e getProviderFromConfiguredTargetEnvironment[TReference], targetLabel string, configurationReference model_core.PatchedMessage[*model_core_pb.Reference, TMetadata], providerIdentifier label.CanonicalStarlarkIdentifier) (model_core.Message[*model_starlark_pb.Struct_Fields, TReference], error) { configuredTargetValue := e.GetConfiguredTargetValue( - model_core.PatchedMessage[*model_analysis_pb.ConfiguredTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.ConfiguredTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.ConfiguredTarget_Key{ Label: targetLabel, ConfigurationReference: configurationReference.Message, }, - Patcher: configurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), + ), ) if !configuredTargetValue.IsSet() { return model_core.Message[*model_starlark_pb.Struct_Fields, TReference]{}, evaluation.ErrMissingDependency diff --git a/pkg/model/analysis/file_properties_value.go b/pkg/model/analysis/file_properties_value.go index 1e89f44..a3169a4 100644 --- a/pkg/model/analysis/file_properties_value.go +++ b/pkg/model/analysis/file_properties_value.go @@ -15,7 +15,6 @@ import ( model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" model_core_pb "github.com/buildbarn/bonanza/pkg/proto/model/core" model_filesystem_pb "github.com/buildbarn/bonanza/pkg/proto/model/filesystem" - "github.com/buildbarn/bonanza/pkg/storage/dag" "github.com/buildbarn/bonanza/pkg/storage/object" ) @@ -219,16 +218,14 @@ func (c *baseComputer[TReference, TMetadata]) ComputeFilePropertiesValue(ctx con return PatchedFilePropertiesValue{}, errors.New("path resolves to a directory") } - patchedFileProperties := model_core.NewPatchedMessageFromExisting( + patchedFileProperties := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, resolver.fileProperties, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedFilePropertiesValue{ - Message: &model_analysis_pb.FileProperties_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.FileProperties_Value{ Exists: patchedFileProperties.Message, }, - Patcher: patchedFileProperties.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(patchedFileProperties.Patcher), + ), nil } diff --git a/pkg/model/analysis/http_archive_contents.go b/pkg/model/analysis/http_archive_contents.go index f7abdad..56f3963 100644 --- a/pkg/model/analysis/http_archive_contents.go +++ b/pkg/model/analysis/http_archive_contents.go @@ -425,8 +425,8 @@ func (c *baseComputer[TReference, TMetadata]) ComputeHttpArchiveContentsValue(ct patcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() rootReference := createdRootDirectoryObject.Contents.GetReference() - return PatchedHttpArchiveContentsValue{ - Message: &model_analysis_pb.HttpArchiveContents_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.HttpArchiveContents_Value{ Exists: createdRootDirectory.ToDirectoryReference( patcher.AddReference( rootReference, @@ -434,6 +434,6 @@ func (c *baseComputer[TReference, TMetadata]) ComputeHttpArchiveContentsValue(ct ), ), }, - Patcher: patcher, - }, nil + patcher, + ), nil } diff --git a/pkg/model/analysis/http_file_contents.go b/pkg/model/analysis/http_file_contents.go index 959d25c..7329433 100644 --- a/pkg/model/analysis/http_file_contents.go +++ b/pkg/model/analysis/http_file_contents.go @@ -93,14 +93,14 @@ ProcessURLs: Exists: &model_analysis_pb.HttpFileContents_Value_Exists{}, }), nil } - return PatchedHttpFileContentsValue{ - Message: &model_analysis_pb.HttpFileContents_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.HttpFileContents_Value{ Exists: &model_analysis_pb.HttpFileContents_Value_Exists{ Contents: fileMerkleTree.Message, }, }, - Patcher: fileMerkleTree.Patcher, - }, nil + fileMerkleTree.Patcher, + ), nil } // File not found. diff --git a/pkg/model/analysis/module_dot_bazel_contents.go b/pkg/model/analysis/module_dot_bazel_contents.go index 612be8a..446c6cf 100644 --- a/pkg/model/analysis/module_dot_bazel_contents.go +++ b/pkg/model/analysis/module_dot_bazel_contents.go @@ -14,7 +14,6 @@ import ( model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" model_filesystem_pb "github.com/buildbarn/bonanza/pkg/proto/model/filesystem" pg_starlark "github.com/buildbarn/bonanza/pkg/starlark" - "github.com/buildbarn/bonanza/pkg/storage/dag" "github.com/buildbarn/bonanza/pkg/storage/object" ) @@ -225,18 +224,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeModuleDotBazelContentsValue if !filePropertiesValue.IsSet() { return PatchedModuleDotBazelContentsValue{}, evaluation.ErrMissingDependency } - fileContents := model_core.NewPatchedMessageFromExisting( + fileContents := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(filePropertiesValue, filePropertiesValue.Message.Exists.Contents), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedModuleDotBazelContentsValue{ - Message: &model_analysis_pb.ModuleDotBazelContents_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.ModuleDotBazelContents_Value{ Contents: fileContents.Message, }, - Patcher: fileContents.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(fileContents.Patcher), + ), nil } // See if the module instance is one of the resolved modules @@ -286,18 +283,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeModuleDotBazelContentsValue if fileContentsValue.Message.Exists == nil { return PatchedModuleDotBazelContentsValue{}, fmt.Errorf("file at URL %#v does not exist", moduleFileURL) } - fileContents := model_core.NewPatchedMessageFromExisting( + fileContents := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(fileContentsValue, fileContentsValue.Message.Exists.Contents), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedModuleDotBazelContentsValue{ - Message: &model_analysis_pb.ModuleDotBazelContents_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.ModuleDotBazelContents_Value{ Contents: fileContents.Message, }, - Patcher: fileContents.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(fileContents.Patcher), + ), nil } } diff --git a/pkg/model/analysis/module_extension_repo.go b/pkg/model/analysis/module_extension_repo.go index 7ad7ce3..693350d 100644 --- a/pkg/model/analysis/module_extension_repo.go +++ b/pkg/model/analysis/module_extension_repo.go @@ -12,7 +12,6 @@ import ( "github.com/buildbarn/bonanza/pkg/model/core/btree" model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" model_core_pb "github.com/buildbarn/bonanza/pkg/proto/model/core" - "github.com/buildbarn/bonanza/pkg/storage/dag" ) func (c *baseComputer[TReference, TMetadata]) ComputeModuleExtensionRepoValue(ctx context.Context, key *model_analysis_pb.ModuleExtensionRepo_Key, e ModuleExtensionRepoEnvironment[TReference]) (PatchedModuleExtensionRepoValue, error) { @@ -62,16 +61,14 @@ func (c *baseComputer[TReference, TMetadata]) ComputeModuleExtensionRepoValue(ct if definition == nil { return PatchedModuleExtensionRepoValue{}, errors.New("repo does not have a definition") } - patchedDefinition := model_core.NewPatchedMessageFromExisting( + patchedDefinition := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(repo, definition), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) return model_core.NewPatchedMessage( &model_analysis_pb.ModuleExtensionRepo_Value{ Definition: patchedDefinition.Message, }, - patchedDefinition.Patcher, + model_core.MapReferenceMetadataToWalkers(patchedDefinition.Patcher), ), nil } diff --git a/pkg/model/analysis/module_extension_repos.go b/pkg/model/analysis/module_extension_repos.go index 3c95f65..0ebd9f9 100644 --- a/pkg/model/analysis/module_extension_repos.go +++ b/pkg/model/analysis/module_extension_repos.go @@ -380,10 +380,10 @@ func (c *baseComputer[TReference, TMetadata]) ComputeModuleExtensionReposValue(c return PatchedModuleExtensionReposValue{}, err } - return PatchedModuleExtensionReposValue{ - Message: &model_analysis_pb.ModuleExtensionRepos_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.ModuleExtensionRepos_Value{ Repos: reposList.Message, }, - Patcher: model_core.MapReferenceMetadataToWalkers(reposList.Patcher), - }, nil + model_core.MapReferenceMetadataToWalkers(reposList.Patcher), + ), nil } diff --git a/pkg/model/analysis/modules_with_remote_overrides.go b/pkg/model/analysis/modules_with_remote_overrides.go index cb33241..2e790ea 100644 --- a/pkg/model/analysis/modules_with_remote_overrides.go +++ b/pkg/model/analysis/modules_with_remote_overrides.go @@ -52,12 +52,12 @@ func (c *baseComputer[TReference, TMetadata]) ComputeModulesWithRemoteOverridesV } // Set any overrides coming from a remote location. - return PatchedModulesWithRemoteOverridesValue{ - Message: &model_analysis_pb.ModulesWithRemoteOverrides_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.ModulesWithRemoteOverrides_Value{ ModuleOverrides: overrideModules, }, - Patcher: model_core.MapReferenceMetadataToWalkers(handler.patcher), - }, nil + model_core.MapReferenceMetadataToWalkers(handler.patcher), + ), nil } // overrideExtractingModuleDotBazelHandler is capable of capturing the paths diff --git a/pkg/model/analysis/package.go b/pkg/model/analysis/package.go index 3f91585..5cc6dc3 100644 --- a/pkg/model/analysis/package.go +++ b/pkg/model/analysis/package.go @@ -209,12 +209,12 @@ func (c *baseComputer[TReference, TMetadata]) ComputePackageValue(ctx context.Co return PatchedPackageValue{}, err } - return PatchedPackageValue{ - Message: &model_analysis_pb.Package_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.Package_Value{ Targets: targetsList.Message, }, - Patcher: model_core.MapReferenceMetadataToWalkers(targetsList.Patcher), - }, nil + model_core.MapReferenceMetadataToWalkers(targetsList.Patcher), + ), nil } return PatchedPackageValue{}, errors.New("BUILD.bazel does not exist") diff --git a/pkg/model/analysis/registered_execution_platforms.go b/pkg/model/analysis/registered_execution_platforms.go index 44d5e68..b83328a 100644 --- a/pkg/model/analysis/registered_execution_platforms.go +++ b/pkg/model/analysis/registered_execution_platforms.go @@ -90,7 +90,7 @@ func (h *registeredExecutionPlatformExtractingModuleDotBazelHandler[TReference, platformInfoProvider, err := getProviderFromConfiguredTarget( h.environment, canonicalPlatformLabelStr, - model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, *model_core_pb.Reference](nil), + model_core.NewSimplePatchedMessage[model_core.WalkableReferenceMetadata, *model_core_pb.Reference](nil), platformInfoProviderIdentifier, ) if err != nil { diff --git a/pkg/model/analysis/registered_repo_platform.go b/pkg/model/analysis/registered_repo_platform.go index 0759465..50405a5 100644 --- a/pkg/model/analysis/registered_repo_platform.go +++ b/pkg/model/analysis/registered_repo_platform.go @@ -81,7 +81,7 @@ func (c *baseComputer[TReference, TMetadata]) ComputeRegisteredRepoPlatformValue platformInfoProvider, err := getProviderFromConfiguredTarget( e, repoPlatformLabelStr, - model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, *model_core_pb.Reference](nil), + model_core.NewSimplePatchedMessage[model_core.WalkableReferenceMetadata, *model_core_pb.Reference](nil), platformInfoProviderIdentifier, ) if err != nil { diff --git a/pkg/model/analysis/registered_toolchains.go b/pkg/model/analysis/registered_toolchains.go index ba32b4c..7036939 100644 --- a/pkg/model/analysis/registered_toolchains.go +++ b/pkg/model/analysis/registered_toolchains.go @@ -106,7 +106,7 @@ func (h *registeredToolchainExtractingModuleDotBazelHandler[TReference, TMetadat declaredToolchainInfoProvider, err := getProviderFromConfiguredTarget( h.environment, toolchainLabelStr, - model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker, *model_core_pb.Reference](nil), + model_core.NewSimplePatchedMessage[model_core.WalkableReferenceMetadata, *model_core_pb.Reference](nil), declaredToolchainInfoProviderIdentifier, ) if err != nil { diff --git a/pkg/model/analysis/repo.go b/pkg/model/analysis/repo.go index 4cc2df2..a74d438 100644 --- a/pkg/model/analysis/repo.go +++ b/pkg/model/analysis/repo.go @@ -1550,18 +1550,20 @@ func (mrc *moduleOrRepositoryContext[TReference, TMetadata]) doExecute(thread *s // Execute the command. keyPatcher := inputRootReference.Patcher - actionResult := mrc.environment.GetActionResultValue(PatchedActionResultKey{ - Message: &model_analysis_pb.ActionResult_Key{ - PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, - CommandReference: keyPatcher.AddReference( - createdCommand.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), - ), - InputRootReference: inputRootReference.Message.Reference, - ExecutionTimeout: &durationpb.Duration{Seconds: timeout}, - }, - Patcher: keyPatcher, - }) + actionResult := mrc.environment.GetActionResultValue( + model_core.NewPatchedMessage( + &model_analysis_pb.ActionResult_Key{ + PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, + CommandReference: keyPatcher.AddReference( + createdCommand.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), + ), + InputRootReference: inputRootReference.Message.Reference, + ExecutionTimeout: &durationpb.Duration{Seconds: timeout}, + }, + keyPatcher, + ), + ) if !actionResult.IsSet() { return nil, evaluation.ErrMissingDependency } @@ -1855,19 +1857,21 @@ func (mrc *moduleOrRepositoryContext[TReference, TMetadata]) doRead(thread *star // Execute the command. keyPatcher := inputRootReference.Patcher - actionResult := mrc.environment.GetActionResultValue(PatchedActionResultKey{ - Message: &model_analysis_pb.ActionResult_Key{ - PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, - CommandReference: keyPatcher.AddReference( - createdCommand.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), - ), - InputRootReference: inputRootReference.Message.Reference, - ExecutionTimeout: &durationpb.Duration{Seconds: 300}, - ExitCodeMustBeZero: true, - }, - Patcher: keyPatcher, - }) + actionResult := mrc.environment.GetActionResultValue( + model_core.NewPatchedMessage( + &model_analysis_pb.ActionResult_Key{ + PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, + CommandReference: keyPatcher.AddReference( + createdCommand.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), + ), + InputRootReference: inputRootReference.Message.Reference, + ExecutionTimeout: &durationpb.Duration{Seconds: 300}, + ExitCodeMustBeZero: true, + }, + keyPatcher, + ), + ) if !actionResult.IsSet() { return nil, evaluation.ErrMissingDependency } @@ -2004,21 +2008,23 @@ func (mrc *moduleOrRepositoryContext[TReference, TMetadata]) doWhich(thread *sta // Invoke command. keyPatcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() - actionResult := mrc.environment.GetActionResultValue(PatchedActionResultKey{ - Message: &model_analysis_pb.ActionResult_Key{ - PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, - CommandReference: keyPatcher.AddReference( - createdCommand.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), - ), - InputRootReference: keyPatcher.AddReference( - createdInputRoot.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdInputRoot.Contents, createdInputRoot.Metadata), - ), - ExecutionTimeout: &durationpb.Duration{Seconds: 60}, - }, - Patcher: keyPatcher, - }) + actionResult := mrc.environment.GetActionResultValue( + model_core.NewPatchedMessage( + &model_analysis_pb.ActionResult_Key{ + PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, + CommandReference: keyPatcher.AddReference( + createdCommand.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), + ), + InputRootReference: keyPatcher.AddReference( + createdInputRoot.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdInputRoot.Contents, createdInputRoot.Metadata), + ), + ExecutionTimeout: &durationpb.Duration{Seconds: 60}, + }, + keyPatcher, + ), + ) if !actionResult.IsSet() { return nil, evaluation.ErrMissingDependency } @@ -2169,18 +2175,20 @@ func (mrc *moduleOrRepositoryContext[TReference, TMetadata]) Exists(p *model_sta // Execute the command. keyPatcher := inputRootReference.Patcher - actionResult := mrc.environment.GetActionResultValue(PatchedActionResultKey{ - Message: &model_analysis_pb.ActionResult_Key{ - PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, - CommandReference: keyPatcher.AddReference( - createdCommand.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), - ), - InputRootReference: inputRootReference.Message.Reference, - ExecutionTimeout: &durationpb.Duration{Seconds: 300}, - }, - Patcher: keyPatcher, - }) + actionResult := mrc.environment.GetActionResultValue( + model_core.NewPatchedMessage( + &model_analysis_pb.ActionResult_Key{ + PlatformPkixPublicKey: mrc.repoPlatform.Message.ExecPkixPublicKey, + CommandReference: keyPatcher.AddReference( + createdCommand.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), + ), + InputRootReference: inputRootReference.Message.Reference, + ExecutionTimeout: &durationpb.Duration{Seconds: 300}, + }, + keyPatcher, + ), + ) if !actionResult.IsSet() { return false, evaluation.ErrMissingDependency } @@ -2883,11 +2891,13 @@ func (c *baseComputer[TReference, TMetadata]) createMerkleTreeFromChangeTracking if r := rootDirectory.currentReference; r.IsSet() { // Directory remained completely unmodified. Simply // return the original directory. - return model_core.NewPatchedMessageFromExisting( + m := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, r, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, + ) + return model_core.NewPatchedMessage( + m.Message, + model_core.MapReferenceMetadataToWalkers(m.Patcher), ), nil } @@ -2969,12 +2979,12 @@ func (c *baseComputer[TReference, TMetadata]) returnRepoMerkleTree(ctx context.C if err != nil { return PatchedRepoValue{}, err } - return PatchedRepoValue{ - Message: &model_analysis_pb.Repo_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.Repo_Value{ RootDirectoryReference: rootDirectoryReference.Message, }, - Patcher: rootDirectoryReference.Patcher, - }, nil + rootDirectoryReference.Patcher, + ), nil } func (c *baseComputer[TReference, TMetadata]) ComputeRepoValue(ctx context.Context, key *model_analysis_pb.Repo_Key, e RepoEnvironment[TReference]) (PatchedRepoValue, error) { @@ -3006,18 +3016,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeRepoValue(ctx context.Conte func(i int) int { return strings.Compare(moduleName, modules[i].Name) }, ); ok { // Found matching module. - rootDirectoryReference := model_core.NewPatchedMessageFromExisting( + rootDirectoryReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(buildSpecification, modules[i].RootDirectoryReference), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedRepoValue{ - Message: &model_analysis_pb.Repo_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.Repo_Value{ RootDirectoryReference: rootDirectoryReference.Message, }, - Patcher: rootDirectoryReference.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(rootDirectoryReference.Patcher), + ), nil } // Check to see if there is a MODULE.bazel override for this module. diff --git a/pkg/model/analysis/resolved_toolchains.go b/pkg/model/analysis/resolved_toolchains.go index 3e86f9b..c5b2396 100644 --- a/pkg/model/analysis/resolved_toolchains.go +++ b/pkg/model/analysis/resolved_toolchains.go @@ -58,20 +58,18 @@ func (c *baseComputer[TReference, TMetadata]) ComputeResolvedToolchainsValue(ctx } compatibleToolchainsByType := make([][]*model_analysis_pb.RegisteredToolchain, 0, len(key.Message.Toolchains)) for _, toolchain := range key.Message.Toolchains { - configurationReference := model_core.NewPatchedMessageFromExisting( + configurationReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(key, key.Message.ConfigurationReference), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) compatibleToolchainsForTypeValue := e.GetCompatibleToolchainsForTypeValue( - model_core.PatchedMessage[*model_analysis_pb.CompatibleToolchainsForType_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.CompatibleToolchainsForType_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.CompatibleToolchainsForType_Key{ ToolchainType: toolchain.ToolchainType, ConfigurationReference: configurationReference.Message, }, - Patcher: configurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(configurationReference.Patcher), + ), ) if !compatibleToolchainsForTypeValue.IsSet() { missingDependencies = true diff --git a/pkg/model/analysis/stable_input_root_path.go b/pkg/model/analysis/stable_input_root_path.go index 023d6d6..ba25826 100644 --- a/pkg/model/analysis/stable_input_root_path.go +++ b/pkg/model/analysis/stable_input_root_path.go @@ -88,22 +88,24 @@ func (c *baseComputer[TReference, TMetadata]) ComputeStableInputRootPathValue(ct // Invoke "pwd". keyPatcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() - actionResult := e.GetActionResultValue(PatchedActionResultKey{ - Message: &model_analysis_pb.ActionResult_Key{ - PlatformPkixPublicKey: repoPlatform.Message.ExecPkixPublicKey, - CommandReference: keyPatcher.AddReference( - createdCommand.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), - ), - InputRootReference: keyPatcher.AddReference( - createdInputRoot.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdInputRoot.Contents, createdInputRoot.Metadata), - ), - ExecutionTimeout: &durationpb.Duration{Seconds: 60}, - ExitCodeMustBeZero: true, - }, - Patcher: keyPatcher, - }) + actionResult := e.GetActionResultValue( + model_core.NewPatchedMessage( + &model_analysis_pb.ActionResult_Key{ + PlatformPkixPublicKey: repoPlatform.Message.ExecPkixPublicKey, + CommandReference: keyPatcher.AddReference( + createdCommand.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdCommand.Contents, createdCommand.Metadata), + ), + InputRootReference: keyPatcher.AddReference( + createdInputRoot.Contents.GetReference(), + dag.NewSimpleObjectContentsWalker(createdInputRoot.Contents, createdInputRoot.Metadata), + ), + ExecutionTimeout: &durationpb.Duration{Seconds: 60}, + ExitCodeMustBeZero: true, + }, + keyPatcher, + ), + ) if !actionResult.IsSet() { return PatchedStableInputRootPathValue{}, evaluation.ErrMissingDependency } diff --git a/pkg/model/analysis/target.go b/pkg/model/analysis/target.go index 55a2e39..021be8f 100644 --- a/pkg/model/analysis/target.go +++ b/pkg/model/analysis/target.go @@ -13,7 +13,6 @@ import ( model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" model_core_pb "github.com/buildbarn/bonanza/pkg/proto/model/core" model_starlark_pb "github.com/buildbarn/bonanza/pkg/proto/model/starlark" - "github.com/buildbarn/bonanza/pkg/storage/dag" ) func (c *baseComputer[TReference, TMetadata]) lookupTargetDefinitionInTargetList(ctx context.Context, targetList model_core.Message[[]*model_analysis_pb.Package_Value_Target, TReference], targetName label.TargetName) (model_core.Message[*model_starlark_pb.Target_Definition, TReference], error) { @@ -75,16 +74,14 @@ func (c *baseComputer[TReference, TMetadata]) ComputeTargetValue(ctx context.Con return PatchedTargetValue{}, errors.New("target does not exist") } - patchedDefinition := model_core.NewPatchedMessageFromExisting( + patchedDefinition := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, definition, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) return model_core.NewPatchedMessage( &model_analysis_pb.Target_Value{ Definition: patchedDefinition.Message, }, - patchedDefinition.Patcher, + model_core.MapReferenceMetadataToWalkers(patchedDefinition.Patcher), ), nil } diff --git a/pkg/model/analysis/target_pattern_expansion.go b/pkg/model/analysis/target_pattern_expansion.go index c34683c..56f025d 100644 --- a/pkg/model/analysis/target_pattern_expansion.go +++ b/pkg/model/analysis/target_pattern_expansion.go @@ -13,7 +13,6 @@ import ( model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" model_core_pb "github.com/buildbarn/bonanza/pkg/proto/model/core" model_starlark_pb "github.com/buildbarn/bonanza/pkg/proto/model/starlark" - "github.com/buildbarn/bonanza/pkg/storage/dag" ) type expandCanonicalTargetPatternEnvironment[TReference any] interface { @@ -82,15 +81,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeTargetPatternExpansionValue btree.NewObjectCreatingNodeMerger( c.getValueObjectEncoder(), c.getReferenceFormat(), - /* parentNodeComputer = */ func(createdObject model_core.CreatedObject[dag.ObjectContentsWalker], childNodes []*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel) (model_core.PatchedMessage[*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel, dag.ObjectContentsWalker], error) { - patcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() + /* parentNodeComputer = */ func(createdObject model_core.CreatedObject[TMetadata], childNodes []*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel) (model_core.PatchedMessage[*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel, TMetadata], error) { + patcher := model_core.NewReferenceMessagePatcher[TMetadata]() return model_core.NewPatchedMessage( &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel{ Level: &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel_Parent_{ Parent: &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel_Parent{ Reference: patcher.AddReference( createdObject.Contents.GetReference(), - dag.NewSimpleObjectContentsWalker(createdObject.Contents, createdObject.Metadata)), + c.objectCapturer.CaptureCreatedObject(createdObject), + ), }, }, }, @@ -128,7 +128,7 @@ func (c *baseComputer[TReference, TMetadata]) ComputeTargetPatternExpansionValue // named "all", "all-targets" or "*". Prefer // matching just that target, as opposed to // performing actual wildcard expansion. - if err := treeBuilder.PushChild(model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker]( + if err := treeBuilder.PushChild(model_core.NewSimplePatchedMessage[TMetadata]( &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel{ Level: &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel_Leaf{ Leaf: initialTarget.String(), @@ -182,11 +182,9 @@ func (c *baseComputer[TReference, TMetadata]) ComputeTargetPatternExpansionValue for _, targetLabel := range childTargetPatternExpansion.Message.TargetLabels { if err := treeBuilder.PushChild( - model_core.NewPatchedMessageFromExisting( + model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(childTargetPatternExpansion, targetLabel), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ), ); err != nil { return PatchedTargetPatternExpansionValue{}, err @@ -206,12 +204,12 @@ func (c *baseComputer[TReference, TMetadata]) ComputeTargetPatternExpansionValue return PatchedTargetPatternExpansionValue{}, err } - return PatchedTargetPatternExpansionValue{ - Message: &model_analysis_pb.TargetPatternExpansion_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.TargetPatternExpansion_Value{ TargetLabels: targetLabelsList.Message, }, - Patcher: targetLabelsList.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(targetLabelsList.Patcher), + ), nil } func (c *baseComputer[TReference, TMetadata]) addPackageToTargetPatternExpansion( @@ -219,7 +217,7 @@ func (c *baseComputer[TReference, TMetadata]) addPackageToTargetPatternExpansion canonicalPackage label.CanonicalPackage, packageValue model_core.Message[*model_analysis_pb.Package_Value, TReference], includeFileTargets bool, - treeBuilder btree.Builder[*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel, dag.ObjectContentsWalker], + treeBuilder btree.Builder[*model_analysis_pb.TargetPatternExpansion_Value_TargetLabel, TMetadata], ) error { var errIter error for entry := range btree.AllLeaves( @@ -260,7 +258,7 @@ func (c *baseComputer[TReference, TMetadata]) addPackageToTargetPatternExpansion if err != nil { return fmt.Errorf("invalid target name %#v: %w", level.Leaf.Name, err) } - if err := treeBuilder.PushChild(model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker]( + if err := treeBuilder.PushChild(model_core.NewSimplePatchedMessage[TMetadata]( &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel{ Level: &model_analysis_pb.TargetPatternExpansion_Value_TargetLabel_Leaf{ Leaf: canonicalPackage.AppendTargetName(targetName).String(), diff --git a/pkg/model/analysis/used_module_extension.go b/pkg/model/analysis/used_module_extension.go index ce43aa7..abe3e03 100644 --- a/pkg/model/analysis/used_module_extension.go +++ b/pkg/model/analysis/used_module_extension.go @@ -10,7 +10,6 @@ import ( "github.com/buildbarn/bonanza/pkg/label" model_core "github.com/buildbarn/bonanza/pkg/model/core" model_analysis_pb "github.com/buildbarn/bonanza/pkg/proto/model/analysis" - "github.com/buildbarn/bonanza/pkg/storage/dag" ) func (c *baseComputer[TReference, TMetadata]) ComputeUsedModuleExtensionValue(ctx context.Context, key *model_analysis_pb.UsedModuleExtension_Key, e UsedModuleExtensionEnvironment[TReference]) (PatchedUsedModuleExtensionValue, error) { @@ -32,18 +31,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeUsedModuleExtensionValue(ct return PatchedUsedModuleExtensionValue{}, fmt.Errorf("invalid module extensions Starlark identifier %#v: %w", extension.Identifier, err) } if identifier.ToModuleExtension().String() == key.ModuleExtension { - patchedExtension := model_core.NewPatchedMessageFromExisting( + patchedExtension := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, model_core.NewNestedMessage(usedModuleExtensions, extension), - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) - return PatchedUsedModuleExtensionValue{ - Message: &model_analysis_pb.UsedModuleExtension_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.UsedModuleExtension_Value{ ModuleExtension: patchedExtension.Message, }, - Patcher: patchedExtension.Patcher, - }, nil + model_core.MapReferenceMetadataToWalkers(patchedExtension.Patcher), + ), nil } } return PatchedUsedModuleExtensionValue{}, errors.New("module extension not found") diff --git a/pkg/model/analysis/user_defined_transition.go b/pkg/model/analysis/user_defined_transition.go index 5029808..2b4bb1e 100644 --- a/pkg/model/analysis/user_defined_transition.go +++ b/pkg/model/analysis/user_defined_transition.go @@ -565,16 +565,16 @@ func (c *baseComputer[TReference, TMetadata]) ComputeUserDefinedTransitionValue( }) patcher.Merge(outputConfigurationReference.Patcher) } - return model_core.PatchedMessage[*model_analysis_pb.UserDefinedTransition_Value, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.UserDefinedTransition_Value{ + return model_core.NewPatchedMessage( + &model_analysis_pb.UserDefinedTransition_Value{ Result: &model_analysis_pb.UserDefinedTransition_Value_Success_{ Success: &model_analysis_pb.UserDefinedTransition_Value_Success{ Entries: entries, }, }, }, - Patcher: model_core.MapReferenceMetadataToWalkers(patcher), - }, nil + model_core.MapReferenceMetadataToWalkers(patcher), + ), nil } type stubbedTransitionAttr struct{} diff --git a/pkg/model/analysis/visible_target.go b/pkg/model/analysis/visible_target.go index f0b0827..7516f98 100644 --- a/pkg/model/analysis/visible_target.go +++ b/pkg/model/analysis/visible_target.go @@ -192,23 +192,21 @@ func (c *baseComputer[TReference, TMetadata]) ComputeVisibleTargetValue(ctx cont } // The actual target may also be an alias. - patchedConfigurationReference := model_core.NewPatchedMessageFromExisting( + patchedConfigurationReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) actualVisibleTargetValue := e.GetVisibleTargetValue( - model_core.PatchedMessage[*model_analysis_pb.VisibleTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.VisibleTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.VisibleTarget_Key{ FromPackage: toLabel.GetCanonicalPackage().String(), ToLabel: actualCanonicalLabel.String(), PermitAliasNoMatch: key.Message.PermitAliasNoMatch, StopAtLabelSetting: key.Message.StopAtLabelSetting, ConfigurationReference: patchedConfigurationReference.Message, }, - Patcher: patchedConfigurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(patchedConfigurationReference.Patcher), + ), ) if !actualVisibleTargetValue.IsSet() { return PatchedVisibleTargetValue{}, evaluation.ErrMissingDependency @@ -289,22 +287,20 @@ func (c *baseComputer[TReference, TMetadata]) ComputeVisibleTargetValue(ctx cont } } - patchedConfigurationReference := model_core.NewPatchedMessageFromExisting( + patchedConfigurationReference := model_core.NewPatchedMessageFromExistingCaptured( + c.objectCapturer, configurationReference, - func(index int) dag.ObjectContentsWalker { - return dag.ExistingObjectContentsWalker - }, ) actualVisibleTargetValue := e.GetVisibleTargetValue( - model_core.PatchedMessage[*model_analysis_pb.VisibleTarget_Key, dag.ObjectContentsWalker]{ - Message: &model_analysis_pb.VisibleTarget_Key{ + model_core.NewPatchedMessage( + &model_analysis_pb.VisibleTarget_Key{ FromPackage: nextFromPackage, ToLabel: nextToLabel, PermitAliasNoMatch: key.Message.PermitAliasNoMatch, ConfigurationReference: patchedConfigurationReference.Message, }, - Patcher: patchedConfigurationReference.Patcher, - }, + model_core.MapReferenceMetadataToWalkers(patchedConfigurationReference.Patcher), + ), ) if !actualVisibleTargetValue.IsSet() { return PatchedVisibleTargetValue{}, evaluation.ErrMissingDependency diff --git a/pkg/model/command/local_executor.go b/pkg/model/command/local_executor.go index 7047b3a..2cb8b73 100644 --- a/pkg/model/command/local_executor.go +++ b/pkg/model/command/local_executor.go @@ -766,13 +766,13 @@ func (f *prepopulatedCapturableFile) CreateFileMerkleTree(ctx context.Context) ( return model_core.PatchedMessage[*model_filesystem_pb.FileContents, dag.ObjectContentsWalker]{}, nil } patcher := model_core.NewReferenceMessagePatcher[dag.ObjectContentsWalker]() - return model_core.PatchedMessage[*model_filesystem_pb.FileContents, dag.ObjectContentsWalker]{ - Message: &model_filesystem_pb.FileContents{ + return model_core.NewPatchedMessage( + &model_filesystem_pb.FileContents{ TotalSizeBytes: getFileContents.FileContents.EndBytes, Reference: patcher.AddReference(getFileContents.FileContents.Reference, dag.ExistingObjectContentsWalker), }, - Patcher: patcher, - }, nil + patcher, + ), nil } // Mutable files created during execution. diff --git a/pkg/model/core/patched_message.go b/pkg/model/core/patched_message.go index 32a9f0d..22be9e2 100644 --- a/pkg/model/core/patched_message.go +++ b/pkg/model/core/patched_message.go @@ -46,10 +46,7 @@ func NewPatchedMessageFromExisting[ ) PatchedMessage[TMessagePtr, TMetadata] { patcher := NewReferenceMessagePatcher[TMetadata]() if existing.Message == nil || existing.OutgoingReferences.GetDegree() == 0 { - return PatchedMessage[TMessagePtr, TMetadata]{ - Message: existing.Message, - Patcher: patcher, - } + return NewPatchedMessage(existing.Message, patcher) } clonedMessage := proto.Clone(existing.Message) @@ -59,19 +56,13 @@ func NewPatchedMessageFromExisting[ createMetadata: createMetadata, } a.addReferenceMessagesRecursively(clonedMessage.ProtoReflect()) - return PatchedMessage[TMessagePtr, TMetadata]{ - Message: clonedMessage.(TMessagePtr), - Patcher: patcher, - } + return NewPatchedMessage(clonedMessage.(TMessagePtr), patcher) } // NewSimplePatchedMessage is a helper function for creating instances // of PatchedMessage for messages that don't contain any references. func NewSimplePatchedMessage[TMetadata ReferenceMetadata, TMessage any](v TMessage) PatchedMessage[TMessage, TMetadata] { - return PatchedMessage[TMessage, TMetadata]{ - Message: v, - Patcher: NewReferenceMessagePatcher[TMetadata](), - } + return NewPatchedMessage(v, NewReferenceMessagePatcher[TMetadata]()) } // IsSet returns true if the PatchedMessage is assigned to a message diff --git a/pkg/model/filesystem/create_file_merkle_tree.go b/pkg/model/filesystem/create_file_merkle_tree.go index 9693f32..60dfa95 100644 --- a/pkg/model/filesystem/create_file_merkle_tree.go +++ b/pkg/model/filesystem/create_file_merkle_tree.go @@ -121,9 +121,9 @@ func CreateChunkDiscardingFileMerkleTree(ctx context.Context, parameters *FileCr return model_core.PatchedMessage[*model_filesystem_pb.FileContents, dag.ObjectContentsWalker]{}, err } - return model_core.PatchedMessage[*model_filesystem_pb.FileContents, dag.ObjectContentsWalker]{ - Message: fileContents.Message, - Patcher: model_core.MapReferenceMessagePatcherMetadata( + return model_core.NewPatchedMessage( + fileContents.Message, + model_core.MapReferenceMessagePatcherMetadata( fileContents.Patcher, func(reference object.LocalReference, metadata model_core.CreatedObjectTree) dag.ObjectContentsWalker { return NewCapturedFileWalker( @@ -135,5 +135,5 @@ func CreateChunkDiscardingFileMerkleTree(ctx context.Context, parameters *FileCr ) }, ), - }, nil + ), nil }