// Copyright 2026 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package specdoc import ( "simd/archsimd/_gen/sgutil" "simd/archsimd/_gen/specgen" "simd/archsimd/_gen/specgen/specexpr" ) // detectUnknown implements [Options.RejectUnknown] for the exported // declaration decl, with the matching spec function specFn or spec type // specType (or neither). It reports decl if it doesn't belong in the file, // either because it's unknown or because it isn't allowed in a file of the // file's phase. func (f *filler) detectUnknown(decl Decl, specFn *specgen.Func, specType *specgen.TypeDecl) { if !f.opts.RejectUnknown || f.test { return } allowed, apiReason := f.allowedPhases(decl, specFn, specType) if allowed.has(f.phase) { return } if apiReason == "" { // decl is in neither spec nor sgutil.NonSpecAPI, and the file isn't // experimental, so report it as unknown. f.report.UnknownDecls = append(f.report.UnknownDecls, UnknownDecl{decl}) return } var fileReason string switch f.phase { case 0: fileReason = "the file builds without GOEXPERIMENT=simdstable or simd" case sgutil.PhaseStable: fileReason = "the file is generally available (goexperiment.simdstable)" case sgutil.PhaseExperiment: fileReason = "the file is experimental (goexperiment.simd)" } f.report.PhaseViolations = append(f.report.PhaseViolations, PhaseViolation{D: decl, Phase: f.phase, Reason: apiReason + ", but " + fileReason}) } // A phaseSet is a set of [sgutil.Phase]s. type phaseSet uint8 // phases returns the set of ps. func phases(ps ...sgutil.Phase) phaseSet { var s phaseSet for _, p := range ps { s |= 1 << p } return s } // has reports whether s contains p. func (s phaseSet) has(p sgutil.Phase) bool { return s&(1<