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

Method checkClauses

analysis/validation.go:1063–1100  ·  view source on GitHub ↗

checkRelTypes takes a pred that has a declaration supplied by the user. It checks every clause, including unit clauses ("initial facts").

(decl *ast.Decl)

Source from the content-addressed store, hash-verified

1061// checkRelTypes takes a pred that has a declaration supplied by the user.
1062// It checks every clause, including unit clauses ("initial facts").
1063func (bc *BoundsAnalyzer) checkClauses(decl *ast.Decl) error {
1064 pred := decl.DeclaredAtom.Predicate
1065 clauses := bc.RulesMap[pred]
1066
1067 declaredRelTypeExpr, err := symbols.RelTypeExprFromDecl(*decl)
1068 if err != nil {
1069 return err
1070 }
1071
1072 // Handle unit clauses (initial facts). We inferred some relation types, each must
1073 // conform to the declaration (at least one alternative among declared ones).
1074 if initialFactRelTypes, ok := bc.initialFactMap[pred]; ok {
1075 for _, inferred := range symbols.RelTypeAlternatives(initialFactRelTypes) {
1076 typeCtx := symbols.GetTypeContext(declaredRelTypeExpr)
1077 if !symbols.SetConforms(typeCtx, inferred, declaredRelTypeExpr) {
1078 return fmt.Errorf("found unit clause with %v that does not conform to any decl %v", inferred, declaredRelTypeExpr)
1079 }
1080 }
1081 }
1082
1083 for _, clause := range clauses {
1084 ic := newInferContext(bc, decl, &clause)
1085 inferredRelTypeExpr, err := ic.inferRelTypesFromClause()
1086 if err != nil {
1087 return err
1088 }
1089 typeCtx := symbols.GetTypeContext(declaredRelTypeExpr)
1090 if !symbols.SetConforms(typeCtx, inferredRelTypeExpr, declaredRelTypeExpr) {
1091 var rules strings.Builder
1092 for _, r := range bc.RulesMap[pred] {
1093 rules.WriteString(r.String() + "\n")
1094 }
1095 return fmt.Errorf("type mismatch for pred %v rule: %s \n inferred: %v\nvs declared %v",
1096 decl.DeclaredAtom, clause, inferredRelTypeExpr, declaredRelTypeExpr)
1097 }
1098 }
1099 return nil
1100}
1101
1102// feasibleAlternatives returns feasible alternatives for a subgoal p(e1...eN).
1103// We consider a relation type expression (from decl), the given list of

Callers 1

inferAndCheckBoundsMethod · 0.95

Calls 7

RelTypeExprFromDeclFunction · 0.92
RelTypeAlternativesFunction · 0.92
GetTypeContextFunction · 0.92
SetConformsFunction · 0.92
newInferContextFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected