Documentation ¶
Overview ¶
Package builder describes a set of types and methods for building corpora asynchronously.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadTarget occurs when the target request count for a Builder is non-positive. ErrBadTarget = errors.New("number of builder requests must be positive") // ErrBadBuilderName occurs when a builder request specifies a name that isn't in the builder's corpus. ErrBadBuilderName = errors.New("requested subject name not in builder") // ErrBadBuilderRequest occurs when a builder request has an unknown body type. ErrBadBuilderRequest = errors.New("unhandled builder request type") )
Functions ¶
func ParBuild ¶
func ParBuild(ctx context.Context, nworkers int, src corpus.Corpus, cfg Config, f func(context.Context, subject.Named, chan<- Request) error) (corpus.Corpus, error)
ParBuild runs f in a parallelised manner across the subjects in src. It uses the responses from f in a Builder, and returns the resulting corpus. Note that src may be different from cfg.Init; this is useful when building a new corpus from scratch.
Types ¶
type Builder ¶
type Builder struct { // SendCh is the channel to which requests for the builder should be sent. SendCh chan<- Request // contains filtered or unexported fields }
Builder handles the assembly of corpora from asynchronously-constructed subjects.
type Compile ¶
type Compile struct { // CompilerID is the ID of the compiler that produced this result. CompilerID id.ID `json:"compiler_id,omitempty"` // Result is the compile result. Result compilation.CompileResult `json:"result,omitempty"` }
Compile is a request to add the given compiler result to the named subject.
type Config ¶
type Config struct { // Init is the initial corpus. // If nil, the Builder starts with a new corpus with capacity equal to NReqs. // Otherwise, it copies this corpus. Init corpus.Corpus // Manifest gives us the name of the task and the number of requests in it. Manifest // Obs is the list of observers to notify as the builder performs various tasks. Observers []Observer }
Config is a configuration for a Builder.
type Manifest ¶
type Manifest struct { // Name describes the build task that is starting. Name string `json:"name"` // NReqs is the number of requests in the build task. // The corpus builder will wait for this number of requests to arrive. NReqs int `json:"nreqs"` }
Manifest describes the layout of a corpus build task.
type Message ¶
type Message struct { observing.Batch // Manifest carries the name of the subject being (re-)built, if we're on a build-start. Name string `json:"name,omitempty"` // Request carries a builder request, if we're on a build-step. Request *Request `json:"request,omitempty"` }
Message is the type of builder observation messages.
func StartMessage ¶
StartMessage creates an build-start message using manifest m.
func StepMessage ¶
StepMessage creates a build-step message for step i and request r.
type Observer ¶
type Observer interface { // OnBuild sends a builder observation message. OnBuild(Message) }
Observer is the interface for things that observe a builder.
type Recipe ¶
type Recipe struct { // Arch is the ID of the architecture for which this lifting is occurring. Arch id.ID `json:"arch,omitempty"` // Recipe is the produced recipe. Recipe recipe.Recipe `json:"recipe,omitempty"` }
Recipe is a request to add the given recipe to the named subject, under the named architecture.
type Request ¶
type Request struct { // Name is the name of the subject to add or modify Name string `json:"name"` // Add is populated if this request is an Add. Add *Add `json:"add,omitempty"` // Compile is populated if this request is a Compile. Compile *Compile `json:"compile,omitempty"` // Recipe is populated if this request is a Recipe. Recipe *Recipe `json:"recipe,omitempty"` // Run is populated if this request is a Run. Run *Run `json:"run,omitempty"` }
Request is the type of requests to a Builder.
func AddRequest ¶
AddRequest constructs an add-subject request for subject s.
func CompileRequest ¶
func CompileRequest(name compilation.Name, r compilation.CompileResult) Request
CompileRequest constructs an add-compile request for the compilation with name name and result r.
func RecipeRequest ¶
RecipeRequest constructs an add-recipe request for the subject with name sname, arch ID arch, and recipe r.
func RunRequest ¶
func RunRequest(name compilation.Name, r compilation.RunResult) Request
RunRequest constructs an add-run request for the compilation with name name and result r.