1
2
3
4
5 package specdoc
6
7 import (
8 "simd/archsimd/_gen/sgutil"
9 "simd/archsimd/_gen/specgen"
10 "simd/archsimd/_gen/specgen/specexpr"
11 )
12
13
14
15
16
17
18 func (f *filler) detectUnknown(decl Decl, specFn *specgen.Func, specType *specgen.TypeDecl) {
19 if !f.opts.RejectUnknown || f.test {
20 return
21 }
22 allowed, apiReason := f.allowedPhases(decl, specFn, specType)
23 if allowed.has(f.phase) {
24 return
25 }
26 if apiReason == "" {
27
28
29 f.report.UnknownDecls = append(f.report.UnknownDecls, UnknownDecl{decl})
30 return
31 }
32 var fileReason string
33 switch f.phase {
34 case 0:
35 fileReason = "the file builds without GOEXPERIMENT=simdstable or simd"
36 case sgutil.PhaseStable:
37 fileReason = "the file is generally available (goexperiment.simdstable)"
38 case sgutil.PhaseExperiment:
39 fileReason = "the file is experimental (goexperiment.simd)"
40 }
41 f.report.PhaseViolations = append(f.report.PhaseViolations, PhaseViolation{D: decl, Phase: f.phase, Reason: apiReason + ", but " + fileReason})
42 }
43
44
45 type phaseSet uint8
46
47
48 func phases(ps ...sgutil.Phase) phaseSet {
49 var s phaseSet
50 for _, p := range ps {
51 s |= 1 << p
52 }
53 return s
54 }
55
56
57 func (s phaseSet) has(p sgutil.Phase) bool { return s&(1<<p) != 0 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 func (f *filler) allowedPhases(decl Decl, specFn *specgen.Func, specType *specgen.TypeDecl) (allowed phaseSet, reason string) {
82 stable, experimental := phases(sgutil.PhaseStable), phases(sgutil.PhaseExperiment)
83
84
85
86 if sgutil.NonSpecAPI(f.pkg, decl.Recv, decl.Name) {
87 return stable | experimental, "listed in sgutil.NonSpecAPI"
88 }
89
90
91
92 if specFn == nil && specType == nil {
93 return experimental, ""
94 }
95
96
97
98 if specFn != nil && specFn.Experiment {
99 return experimental, "marked //specgen:experiment in spec"
100 }
101 if f.pkg == "archsimd" {
102 if specType != nil && isScalable(specType.Shape) || specFn != nil && hasScalable(specFn) {
103 return experimental, "archsimd API with scalable vectors, which is experimental"
104 }
105 if !f.stableArchOnly {
106 return experimental, "archsimd API in a file that can build for architectures other than amd64, arm64 and wasm"
107 }
108 }
109 return stable, "generally available in spec"
110 }
111
112
113 func isScalable(t specexpr.Type) bool {
114 v, ok := t.(specexpr.Vector)
115 if !ok {
116 return false
117 }
118 _, fixed := v.Width.(specexpr.Int)
119 return !fixed
120 }
121
122
123
124 func hasScalable(fn *specgen.Func) bool {
125 if fn.Recv.Type != nil && isScalable(fn.Recv.Type) {
126 return true
127 }
128 for _, args := range [][]specgen.Arg{fn.In, fn.Out} {
129 for _, a := range args {
130 if isScalable(a.Type) {
131 return true
132 }
133 }
134 }
135 return false
136 }
137
View as plain text