MCPcopy
hub / github.com/google/mangle / EvalProgramNaive

Function EvalProgramNaive

engine/naivebottomup.go:37–57  ·  view source on GitHub ↗

EvalProgramNaive evaluates a given program on the given facts, modifying the fact store in the process.

(program []ast.Clause, store factstore.SimpleInMemoryStore)

Source from the content-addressed store, hash-verified

35
36// EvalProgramNaive evaluates a given program on the given facts, modifying the fact store in the process.
37func EvalProgramNaive(program []ast.Clause, store factstore.SimpleInMemoryStore) error {
38 preds := store.ListPredicates()
39 knownPredicates := make(map[ast.PredicateSym]ast.Decl, len(preds))
40 for _, sym := range preds {
41 knownPredicates[sym] = ast.NewSyntheticDeclFromSym(sym)
42 }
43 programInfo, err := analysis.AnalyzeOneUnit(parse.SourceUnit{Clauses: program}, knownPredicates)
44 if err != nil {
45 return fmt.Errorf("analysis: %w", err)
46 }
47 strata, predToStratum, err := analysis.Stratify(analysis.Program{
48 EdbPredicates: programInfo.EdbPredicates,
49 IdbPredicates: programInfo.IdbPredicates,
50 Rules: programInfo.Rules,
51 })
52 if err != nil {
53 return fmt.Errorf("stratification: %w", err)
54 }
55 naiveEngine{store, *programInfo, strata, predToStratum}.evalStrata()
56 return nil
57}
58
59func (e naiveEngine) evalStrata() {
60 for _, fact := range e.programInfo.InitialFacts {

Callers 3

TestSimpleEvalNaiveFunction · 0.85
TestManyPathsNaiveFunction · 0.85
TestBuiltinNaiveFunction · 0.85

Calls 5

NewSyntheticDeclFromSymFunction · 0.92
AnalyzeOneUnitFunction · 0.92
StratifyFunction · 0.92
ListPredicatesMethod · 0.65
evalStrataMethod · 0.45

Tested by 3

TestSimpleEvalNaiveFunction · 0.68
TestManyPathsNaiveFunction · 0.68
TestBuiltinNaiveFunction · 0.68