EvalStratifiedProgramWithStats evaluates a given stratified program on the given facts, modifying the fact store in the process.
(programInfo *analysis.ProgramInfo, strata []analysis.Nodeset, predToStratum map[ast.PredicateSym]int, store factstore.FactStore, options ...EvalOption)
| 170 | // EvalStratifiedProgramWithStats evaluates a given stratified program on the given facts, |
| 171 | // modifying the fact store in the process. |
| 172 | func EvalStratifiedProgramWithStats(programInfo *analysis.ProgramInfo, |
| 173 | strata []analysis.Nodeset, predToStratum map[ast.PredicateSym]int, |
| 174 | store factstore.FactStore, options ...EvalOption) (Stats, error) { |
| 175 | |
| 176 | predToRules := make(map[ast.PredicateSym][]ast.Clause) |
| 177 | predToDecl := make(map[ast.PredicateSym]*ast.Decl) |
| 178 | for sym := range programInfo.Decls { |
| 179 | predToDecl[sym] = programInfo.Decls[sym] |
| 180 | } |
| 181 | for _, clause := range programInfo.Rules { |
| 182 | sym := clause.Head.Predicate |
| 183 | predToRules[sym] = append(predToRules[sym], clause) |
| 184 | } |
| 185 | stats := Stats{ |
| 186 | Strata: make([][]ast.PredicateSym, len(strata), len(strata)), |
| 187 | Duration: make([]time.Duration, len(strata), len(strata)), |
| 188 | PredToStratum: predToStratum, |
| 189 | } |
| 190 | for sym, stratum := range predToStratum { |
| 191 | stats.Strata[stratum] = append(stats.Strata[stratum], sym) |
| 192 | } |
| 193 | opts := newEvalOptions(options...) |
| 194 | for sym := range opts.externalPredicates { |
| 195 | decl := predToDecl[sym] |
| 196 | if decl == nil { |
| 197 | return Stats{}, fmt.Errorf("ext callback for a predicate %v without decl", sym) |
| 198 | } |
| 199 | if !decl.IsExternal() { |
| 200 | return Stats{}, fmt.Errorf("ext callback for predicate %v that is not marked as external()", sym) |
| 201 | } |
| 202 | } |
| 203 | if opts.createdFactLimit > 0 { |
| 204 | opts.totalFactLimit = store.EstimateFactCount() + opts.createdFactLimit |
| 205 | } |
| 206 | // Set default evaluation time if not specified |
| 207 | evalTime := opts.evalTime |
| 208 | if evalTime.IsZero() { |
| 209 | evalTime = time.Now() |
| 210 | } |
| 211 | var temporalDeltaStore factstore.TemporalFactStore |
| 212 | if opts.temporalStore != nil { |
| 213 | temporalDeltaStore = factstore.NewTemporalStore() |
| 214 | } |
| 215 | e := &engine{ |
| 216 | store: store, |
| 217 | deltaStore: factstore.NewMultiIndexedArrayInMemoryStore(), |
| 218 | temporalStore: opts.temporalStore, |
| 219 | temporalDeltaStore: temporalDeltaStore, |
| 220 | evalTime: evalTime, |
| 221 | programInfo: programInfo, |
| 222 | strata: strata, |
| 223 | predToStratum: predToStratum, |
| 224 | predToRules: predToRules, |
| 225 | predToDecl: predToDecl, |
| 226 | stats: stats, |
| 227 | options: opts, |
| 228 | } |
| 229 | if err := e.evalStrata(); err != nil { |