Source file src/cmd/compile/internal/contraire/shared.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package contraire
     6  
     7  // JSON encoding of messages emitted from both workers and the driver.
     8  type output struct {
     9  	TrialsDone  int         // The number of trials completed.
    10  	Next        *scoredProg // A write-ahead of the program about to be type-checked.
    11  	ParseErrors int         // The number of generated programs with parse errors.
    12  	TypeErrors  int         // The number of generated programs with type errors.
    13  	Successes   int         // The number of generated programs without errors.
    14  	Panic       *scoredProg // The lowest-score program with a panic failure.
    15  	Crash       *scoredProg // The lowest-score program with a crash failure.
    16  	Hang        *scoredProg // The lowest-score program with a hang failure.
    17  }
    18  
    19  type scoredProg struct {
    20  	Source string
    21  	Score  int
    22  }
    23  
    24  func (a *output) merge(b *output) {
    25  	a.TrialsDone += b.TrialsDone
    26  	if a.Next != nil || b.Next != nil {
    27  		panic("unexpected Next field")
    28  	}
    29  	a.ParseErrors += b.ParseErrors
    30  	a.TypeErrors += b.TypeErrors
    31  	a.Successes += b.Successes
    32  	a.Panic = min(a.Panic, b.Panic)
    33  	a.Crash = min(a.Crash, b.Crash)
    34  	a.Hang = min(a.Hang, b.Hang)
    35  }
    36  
    37  func min(a *scoredProg, b *scoredProg) *scoredProg {
    38  	switch {
    39  	case a == nil:
    40  		return b
    41  	case b == nil:
    42  		return a
    43  	case a.Score <= b.Score:
    44  		return a
    45  	default:
    46  		return b
    47  	}
    48  }
    49  

View as plain text