2022-01-18 20:59:05 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
|
|
|
and social benefits computation rules. Copyright (C) 2022 Inria, contributor:
|
|
|
|
Aymeric Fromherz <aymeric.fromherz@inria.fr>, Denis Merigoux
|
|
|
|
<denis.merigoux@inria.fr>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing permissions and limitations under
|
|
|
|
the License. *)
|
|
|
|
|
|
|
|
(** Common code for handling the IO of all proof backends supported *)
|
|
|
|
|
2022-08-12 18:59:49 +03:00
|
|
|
open Shared_ast
|
2022-07-28 11:36:36 +03:00
|
|
|
|
2022-01-18 20:59:05 +03:00
|
|
|
module type Backend = sig
|
2022-01-19 12:12:20 +03:00
|
|
|
val init_backend : unit -> unit
|
|
|
|
|
2022-01-18 20:59:05 +03:00
|
|
|
type backend_context
|
|
|
|
|
2022-11-16 23:59:48 +03:00
|
|
|
val make_context : decl_ctx -> backend_context
|
2022-01-19 12:12:20 +03:00
|
|
|
|
2022-01-18 20:59:05 +03:00
|
|
|
type vc_encoding
|
|
|
|
|
|
|
|
val print_encoding : vc_encoding -> string
|
|
|
|
|
|
|
|
type model
|
|
|
|
type solver_result = ProvenTrue | ProvenFalse of model option | Unknown
|
|
|
|
|
|
|
|
val solve_vc_encoding : backend_context -> vc_encoding -> solver_result
|
|
|
|
val print_model : backend_context -> model -> string
|
|
|
|
val is_model_empty : model -> bool
|
2022-01-19 11:47:08 +03:00
|
|
|
|
|
|
|
val translate_expr :
|
2022-08-25 20:46:13 +03:00
|
|
|
backend_context -> typed Dcalc.Ast.expr -> backend_context * vc_encoding
|
2022-11-09 00:09:35 +03:00
|
|
|
|
|
|
|
val encode_asserts :
|
|
|
|
backend_context -> typed Dcalc.Ast.expr -> backend_context
|
2022-01-18 20:59:05 +03:00
|
|
|
end
|
|
|
|
|
2022-01-19 12:17:19 +03:00
|
|
|
module type BackendIO = sig
|
|
|
|
val init_backend : unit -> unit
|
2022-01-19 11:47:08 +03:00
|
|
|
|
|
|
|
type backend_context
|
|
|
|
|
2022-11-16 23:59:48 +03:00
|
|
|
val make_context : decl_ctx -> backend_context
|
2022-01-19 12:17:19 +03:00
|
|
|
|
|
|
|
type vc_encoding
|
|
|
|
|
|
|
|
val translate_expr :
|
2022-08-25 20:46:13 +03:00
|
|
|
backend_context -> typed Dcalc.Ast.expr -> backend_context * vc_encoding
|
2022-01-19 12:17:19 +03:00
|
|
|
|
2022-11-09 00:09:35 +03:00
|
|
|
val encode_asserts :
|
|
|
|
backend_context -> typed Dcalc.Ast.expr -> backend_context
|
|
|
|
|
2022-01-19 11:47:08 +03:00
|
|
|
type model
|
|
|
|
|
|
|
|
type vc_encoding_result =
|
|
|
|
| Success of vc_encoding * backend_context
|
|
|
|
| Fail of string
|
2022-01-18 20:59:05 +03:00
|
|
|
|
|
|
|
val print_negative_result :
|
2022-07-12 16:57:50 +03:00
|
|
|
Conditions.verification_condition ->
|
2022-01-19 11:47:08 +03:00
|
|
|
backend_context ->
|
|
|
|
model option ->
|
|
|
|
string
|
2022-01-18 20:59:05 +03:00
|
|
|
|
|
|
|
val encode_and_check_vc :
|
2022-09-06 15:10:32 +03:00
|
|
|
decl_ctx -> Conditions.verification_condition * vc_encoding_result -> bool
|
|
|
|
(** [encode_and_check_vc] spawns a new Z3 solver and tries to solve the
|
|
|
|
expression [vc]. Returns [true] if the vs was proven true and [false]
|
|
|
|
otherwise. **)
|
2022-01-18 20:59:05 +03:00
|
|
|
end
|
2022-01-19 11:47:08 +03:00
|
|
|
|
2022-01-19 12:17:19 +03:00
|
|
|
module MakeBackendIO : functor (B : Backend) ->
|
|
|
|
BackendIO
|
2022-01-19 11:47:08 +03:00
|
|
|
with type vc_encoding = B.vc_encoding
|
|
|
|
and type backend_context = B.backend_context
|
|
|
|
and type model = B.model
|