Add negative number parsing into `@test_value`

This CL updates the intrinsics lexer to allow negative values for int
and float numerics. This allows doing `@test_value(-2)` in the def file.

Change-Id: I2cad9b25a2932057ce9bc51dec6c32231e06f0a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107440
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-10-27 18:44:50 +00:00 committed by Dawn LUCI CQ
parent 91ed6f7289
commit c3cbc35650
15 changed files with 162 additions and 94 deletions

View File

@ -405,8 +405,11 @@ type generator struct {
// eval executes the sub-template with the given name and arguments, returning
// the generated output
// args can be a single argument:
//
// arg[0]
//
// or a list of name-value pairs:
//
// (args[0]: name, args[1]: value), (args[2]: name, args[3]: value)...
func (g *generator) eval(template string, args ...interface{}) (string, error) {
target := g.t.Lookup(template)

View File

@ -20,6 +20,7 @@
// and 'global-scope' or 'function-scope' HTML class types.
//
// To run:
//
// go get golang.org/x/net/html # Only required once
// go run tools/check-spec-examples/main.go --compiler=<path-to-tint>
package main

View File

@ -37,6 +37,7 @@ func reEscape(s string) string {
// UpdateCTSHashInDeps replaces the CTS hashes in 'deps' with 'newCTSHash'.
// Returns:
//
// newDEPS - the new DEPS content
// oldCTSHash - the old CTS hash in the 'deps'
func UpdateCTSHashInDeps(deps, newCTSHash string) (newDEPS, oldCTSHash string, err error) {

View File

@ -246,8 +246,10 @@ func parseSection(in string) ([]int, error) {
}
// concatRules concatenate rules slice to make two string outputs;
//
// txt, a human-readable string
// tsv, a tab separated string
//
// If testNameFilter is a non-empty string, then only rules whose TestName
// contains the string are included
func concatRules(rules []rule, testNameFilter string) (string, string) {
@ -679,6 +681,7 @@ var (
// example in:
// ` float abs:
// T is f32 or vecN<f32>
//
// abs(e: T ) -> T
// Returns the absolute value of e (e.g. e with a positive sign bit). Component-wise when T is a vector.
// (GLSLstd450Fabs)`
@ -703,6 +706,7 @@ var (
// cleanUpStartEnd creates a string by removing all extra spaces,
// newlines and tabs form the start and end of the input string.
// Example:
//
// input: "\s\t\nHello\s\n\t\Bye\s\s\s\t\n\n\n"
// output: "Hello\s\n\tBye"
// input2: "\nbye\n\n"
@ -721,13 +725,17 @@ var (
// testName creates a test name given a rule id (ie. section name), description and section
// returns for a builtin rule:
//
// testName:${section name} + "," + ${builtin name}
// builtinName: ${builtin name}
// err: nil
//
// returns for a other rules:
//
// testName: ${section name} + "_rule_ + " + ${string(counter)}
// builtinName: ""
// err: nil
//
// if it cannot create a unique name it returns "", "", err.
func testName(id string, desc string, section string) (testName, builtinName string, err error) {
// regex for every thing other than letters and numbers
@ -838,6 +846,7 @@ func getUnimplementedTestPlan(p Parser, path string) error {
// getTestPlanFilePath returns a sort friendly path
// example: if we have 10 sections, and generate filenames naively, this will be the sorted result:
//
// section1.spec.ts -> section10.spec.ts -> section2.spec.ts -> ...
// if we make all the section numbers have the same number of digits, we will get:
// section01.spec.ts -> section02.spec.ts -> ... -> section10.spec.ts

View File

@ -234,9 +234,11 @@ func (e Expectation) Clone() Expectation {
}
// Compare compares the relative order of a and b, returning:
//
// -1 if a should come before b
// 1 if a should come after b
// 0 if a and b are identical
//
// Note: Only comparing bug, query, and tags (in that order).
func (a Expectation) Compare(b Expectation) int {
switch strings.Compare(a.Bug, b.Bug) {

View File

@ -29,11 +29,11 @@ import (
// results.
//
// Update will:
// Remove any expectation lines that have a query where no results match.
// Remove expectations lines that are in a chunk which is not annotated with
// - Remove any expectation lines that have a query where no results match.
// - Remove expectations lines that are in a chunk which is not annotated with
// 'KEEP', and all test results have the status 'Pass'.
// Remove chunks that have had all expectation lines removed.
// Appends new chunks for flaky and failing tests which are not covered by
// - Remove chunks that have had all expectation lines removed.
// - Appends new chunks for flaky and failing tests which are not covered by
// existing expectation lines.
//
// Update returns a list of diagnostics for things that should be addressed.
@ -539,8 +539,8 @@ func (u *updater) resultsToExpectations(results result.List, bug, comment string
}
// cleanupTags returns a copy of the provided results with:
// All tags not found in the expectations list removed
// All but the highest priority tag for any tag-set.
// - All tags not found in the expectations list removed
// - All but the highest priority tag for any tag-set.
// The tag sets are defined by the `BEGIN TAG HEADER` / `END TAG HEADER`
// section at the top of the expectations file.
func (u *updater) cleanupTags(results result.List) result.List {
@ -570,10 +570,10 @@ func (u *updater) cleanupTags(results result.List) result.List {
// treeReducer is a function that can be used by StatusTree.Reduce() to reduce
// tree nodes with the same status.
// treeReducer will collapse trees nodes if any of the following are true:
// All child nodes have the same status
// More than 75% of the child nodes have a non-pass status, and none of the
// - All child nodes have the same status
// - More than 75% of the child nodes have a non-pass status, and none of the
// children are consumed.
// There are more than 20 child nodes with a non-pass status, and none of the
// - There are more than 20 child nodes with a non-pass status, and none of the
// children are consumed.
func treeReducer(statuses []result.Status) *result.Status {
counts := map[result.Status]int{}

View File

@ -37,6 +37,7 @@ import (
// Query represents a WebGPU test query
// Example queries:
//
// 'suite'
// 'suite:*'
// 'suite:file'
@ -269,6 +270,7 @@ func (q Query) String() string {
}
// Compare compares the relative order of q and o, returning:
//
// -1 if q should come before o
// 1 if q should come after o
// 0 if q and o are identical
@ -335,6 +337,7 @@ func (q Query) Contains(o Query) bool {
}
// Callback function for Query.Walk()
//
// q is the query for the current segment.
// t is the target of the query q.
// n is the name of the new segment.

View File

@ -414,10 +414,10 @@ func (t *Tree[Data]) List() []QueryData[Data] {
// Glob returns a list of QueryData's for every node that is under the given
// query, which holds data.
// Glob handles wildcards as well as non-wildcard queries:
// * A non-wildcard query will match the node itself, along with every node
// - A non-wildcard query will match the node itself, along with every node
// under the query. For example: 'a:b' will match every File and Test
// node under 'a:b', including 'a:b' itself.
// * A wildcard Query will include every node under the parent node with the
// - A wildcard Query will include every node under the parent node with the
// matching Query target. For example: 'a:b:*' will match every Test
// node (excluding File nodes) under 'a:b', 'a:b' will not be included.
func (t *Tree[Data]) Glob(q Query) ([]QueryData[Data], error) {

View File

@ -43,7 +43,9 @@ type Result struct {
// Format writes the Result to the fmt.State
// The Result is printed as a single line, in the form:
//
// <query> <tags> <status>
//
// This matches the order in which results are sorted.
func (r Result) Format(f fmt.State, verb rune) {
if len(r.Tags) > 0 {
@ -61,9 +63,11 @@ func (r Result) String() string {
}
// Compare compares the relative order of r and o, returning:
//
// -1 if r should come before o
// 1 if r should come after o
// 0 if r and o are identical
//
// Note: Result.Duration is not considered in comparison.
func (r Result) Compare(o Result) int {
a, b := r, o
@ -89,7 +93,9 @@ func (r Result) Compare(o Result) int {
}
// Parse parses the result from a string of the form:
//
// <query> <tags> <status>
//
// <tags> may be omitted if there were no tags.
func Parse(in string) (Result, error) {
line := in

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows
// Package fileutils contains utility functions for files

View File

@ -30,6 +30,7 @@ type Test func(path string) bool
//
// pattern uses forward-slashes for directory separators '/', and may use the
// following wildcards:
//
// ? - matches any single non-separator character
// * - matches any sequence of non-separator characters
// ** - matches any sequence of characters including separators

View File

@ -219,6 +219,7 @@ func (o MatcherOptions) Format(w fmt.State, verb rune) {
// TemplatedNames is a list of TemplatedName
// Example:
//
// a<b>, c<d, e>
type TemplatedNames []TemplatedName
@ -234,6 +235,7 @@ func (l TemplatedNames) Format(w fmt.State, verb rune) {
// TemplatedName is an identifier with optional templated arguments
// Example:
//
// vec<N, T>
type TemplatedName struct {
Source tok.Source
@ -253,6 +255,7 @@ func (t TemplatedName) Format(w fmt.State, verb rune) {
// MemberNames is a list of MemberName
// Example:
//
// a.b, c.d
type MemberNames []MemberName
@ -298,6 +301,7 @@ func (p TypeDecl) Format(w fmt.State, verb rune) {
// TemplateParams is a list of TemplateParam
// Example:
//
// <A, B : TyB>
type TemplateParams []TemplateParam
@ -317,6 +321,7 @@ func (p TemplateParams) Format(w fmt.State, verb rune) {
// TemplateParam describes a template parameter with optional type
// Example:
//
// <Name>
// <Name: Type>
type TemplateParam struct {
@ -336,6 +341,7 @@ func (t TemplateParam) Format(w fmt.State, verb rune) {
// Attributes is a list of Attribute
// Example:
//
// [[a(x), b(y)]]
type Attributes []Attribute
@ -363,6 +369,7 @@ func (l *Attributes) Take(name string) *Attribute {
// Attribute describes a single attribute
// Example:
//
// @a(x)
type Attribute struct {
Source tok.Source

View File

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/// Package gen holds types and helpers for generating templated code from the
/// intrinsic.def file.
///
/// Used by tools/src/cmd/gen/main.go
// Package gen holds types and helpers for generating templated code from the
// intrinsic.def file.
//
// Used by tools/src/cmd/gen/main.go
package gen
import (
@ -338,8 +338,11 @@ func (b *overloadBuilder) matcherIndex(n sem.Named) (int, error) {
// The order of returned matcher indices is always the order of the fully
// qualified name as read from left to right.
// For example, calling collectMatcherIndices() for the fully qualified name:
//
// A<B<C, D>, E<F, G<H>, I>
//
// Would return the matcher indices:
//
// A, B, C, D, E, F, G, H, I
func (b *overloadBuilder) collectMatcherIndices(fqn sem.FullyQualifiedName) ([]int, error) {
idx, err := b.matcherIndex(fqn.Target)
@ -416,8 +419,11 @@ func BuildIntrinsicTable(s *sem.Sem) (*IntrinsicTable, error) {
// SplitDisplayName splits displayName into parts, where text wrapped in {}
// braces are not quoted and the rest is quoted. This is used to help process
// the string value of the [[display()]] decoration. For example:
//
// SplitDisplayName("vec{N}<{T}>")
//
// would return the strings:
//
// [`"vec"`, `N`, `"<"`, `T`, `">"`]
func SplitDisplayName(displayName string) []string {
parts := []string{}

View File

@ -93,7 +93,6 @@ func (l *lexer) lex() error {
case l.match("/", tok.Divide):
case l.match(".", tok.Dot):
case l.match("->", tok.Arrow):
case l.match("-", tok.Minus):
case l.match("fn", tok.Function):
case l.match("op", tok.Operator):
case l.match("enum", tok.Enum):
@ -103,12 +102,22 @@ func (l *lexer) lex() error {
case l.match("match", tok.Match):
case unicode.IsLetter(l.peek(0)) || l.peek(0) == '_':
l.tok(l.count(alphaNumericOrUnderscore), tok.Identifier)
case unicode.IsNumber(l.peek(0)):
case unicode.IsNumber(l.peek(0)) || l.peek(0) == '-':
isFloat := false
isNegative := false
isFirst := true
pred := func(r rune) bool {
if isFirst && r == '-' {
isNegative = true
isFirst = false
return true
}
isFirst = false
if unicode.IsNumber(r) {
return true
}
if !isFloat && r == '.' {
isFloat = true
return true
@ -116,7 +125,9 @@ func (l *lexer) lex() error {
return false
}
n := l.count(pred)
if isFloat {
if isNegative && n == 1 {
l.tok(1, tok.Minus)
} else if isFloat {
l.tok(n, tok.Float)
} else {
l.tok(n, tok.Integer)

View File

@ -47,9 +47,15 @@ func TestLexTokens(t *testing.T) {
{"123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 10, 9),
}}}},
{"-123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("-123456789"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 11, 10),
}}}},
{"1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("1234.56789"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 11, 10),
}}}},
{"-1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("-1234.56789"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 12, 11),
}}}},
{"123.456.789", []tok.Token{
{Kind: tok.Float, Runes: []rune("123.456"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 8, 7),
@ -61,6 +67,14 @@ func TestLexTokens(t *testing.T) {
S: loc(1, 9, 8), E: loc(1, 12, 11),
}},
}},
{"-123.456-789", []tok.Token{
{Kind: tok.Float, Runes: []rune("-123.456"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 9, 8),
}},
{Kind: tok.Integer, Runes: []rune("-789"), Source: tok.Source{
S: loc(1, 9, 8), E: loc(1, 13, 12),
}},
}},
{"match", []tok.Token{{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 6, 5),
}}}},
@ -88,6 +102,9 @@ func TestLexTokens(t *testing.T) {
{",", []tok.Token{{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 2, 1),
}}}},
{"-", []tok.Token{{Kind: tok.Minus, Runes: []rune("-"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 2, 1),
}}}},
{"<", []tok.Token{{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{
S: loc(1, 1, 0), E: loc(1, 2, 1),
}}}},