3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 02:45:51 +00:00

NativeContext, NativeSolver, NativeModel - updates for Pex (#5878)

* WiP:  Disposable, MkAdd, MkApp, MkBool, MkBoolSort, MkBound, MkBvSort, MkFalse, MkTrue, MkIntSort

* WiP: Native z3 mk_ functions

* WiP: mk_ functions for NativeContext

* WiP: add utility functions for getting values

* WiP: Adding more native utility functions

* native model pull

* WiP: NativeContext additions for array access

* WiP: use Z3_symbol in place of managed Symbol

* WiP: add solver, model, and array methods

* WiP: MkSimpleSolver, MkReal

* WiP: GetDomain GetRange

* WiP: MkExists

* Override for MkFuncDecl

* MkConstArray, MkSelect

* WiP: code cleanup

* migrate Context reference to NativeContext

* remove local signing from PR

* minor code cleanup

Co-authored-by: jfleisher <jofleish@microsoft.com>
This commit is contained in:
John Fleisher 2022-03-03 13:41:12 -05:00 committed by GitHub
parent 811cd9d48d
commit a08be497f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1361 additions and 310 deletions

View file

@ -231,7 +231,6 @@ namespace Microsoft.Z3
return new BitVecSort(this, Native.Z3_mk_bv_sort(nCtx, size));
}
/// <summary>
/// Create a new sequence sort.
/// </summary>
@ -485,7 +484,7 @@ namespace Microsoft.Z3
/// The function performs a record update at t. The field
/// that is passed in as argument is updated with value v,
/// the remaining fields of t are unchanged.
/// </summary>
/// </summary>
public Expr MkUpdateField(FuncDecl field, Expr t, Expr v)
{
return Expr.Create(this, Native.Z3_datatype_update_field(
@ -560,14 +559,14 @@ namespace Microsoft.Z3
/// MkRecFuncDecl. The body may contain recursive uses of the function or
/// other mutually recursive functions.
/// </summary>
public void AddRecDef(FuncDecl f, Expr[] args, Expr body)
{
CheckContextMatch(f);
CheckContextMatch<Expr>(args);
CheckContextMatch(body);
public void AddRecDef(FuncDecl f, Expr[] args, Expr body)
{
CheckContextMatch(f);
CheckContextMatch<Expr>(args);
CheckContextMatch(body);
IntPtr[] argsNative = AST.ArrayToNative(args);
Native.Z3_add_rec_def(nCtx, f.NativeObject, (uint)args.Length, argsNative, body.NativeObject);
}
Native.Z3_add_rec_def(nCtx, f.NativeObject, (uint)args.Length, argsNative, body.NativeObject);
}
/// <summary>
/// Creates a new function declaration.
@ -811,7 +810,7 @@ namespace Microsoft.Z3
public Expr MkApp(FuncDecl f, IEnumerable<Expr> args)
{
Debug.Assert(f != null);
Debug.Assert(args == null || args.All( a => a != null));
Debug.Assert(args == null || args.All(a => a != null));
CheckContextMatch(f);
CheckContextMatch(args);
@ -949,14 +948,15 @@ namespace Microsoft.Z3
Debug.Assert(ts.All(a => a != null));
CheckContextMatch<BoolExpr>(ts);
BoolExpr r = null;
foreach (var t in ts) {
if (r == null)
r = t;
foreach (var t in ts)
{
if (r == null)
r = t;
else
r = MkXor(r, t);
r = MkXor(r, t);
}
if (r == null)
r = MkTrue();
if (r == null)
r = MkTrue();
return r;
}
@ -2343,7 +2343,7 @@ namespace Microsoft.Z3
CheckContextMatch(elem);
CheckContextMatch(set);
return (BoolExpr) Expr.Create(this, Native.Z3_mk_set_member(nCtx, elem.NativeObject, set.NativeObject));
return (BoolExpr)Expr.Create(this, Native.Z3_mk_set_member(nCtx, elem.NativeObject, set.NativeObject));
}
/// <summary>
@ -2356,7 +2356,7 @@ namespace Microsoft.Z3
CheckContextMatch(arg1);
CheckContextMatch(arg2);
return (BoolExpr) Expr.Create(this, Native.Z3_mk_set_subset(nCtx, arg1.NativeObject, arg2.NativeObject));
return (BoolExpr)Expr.Create(this, Native.Z3_mk_set_subset(nCtx, arg1.NativeObject, arg2.NativeObject));
}
#endregion
@ -2366,7 +2366,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create the empty sequence.
/// </summary>
public SeqExpr MkEmptySeq(Sort s)
public SeqExpr MkEmptySeq(Sort s)
{
Debug.Assert(s != null);
return new SeqExpr(this, Native.Z3_mk_seq_empty(nCtx, s.NativeObject));
@ -2375,7 +2375,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create the singleton sequence.
/// </summary>
public SeqExpr MkUnit(Expr elem)
public SeqExpr MkUnit(Expr elem)
{
Debug.Assert(elem != null);
return new SeqExpr(this, Native.Z3_mk_seq_unit(nCtx, elem.NativeObject));
@ -2384,7 +2384,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a string constant.
/// </summary>
public SeqExpr MkString(string s)
public SeqExpr MkString(string s)
{
Debug.Assert(s != null);
return new SeqExpr(this, Native.Z3_mk_string(nCtx, s));
@ -2393,7 +2393,7 @@ namespace Microsoft.Z3
/// <summary>
/// Convert an integer expression to a string.
/// </summary>
public SeqExpr IntToString(Expr e)
public SeqExpr IntToString(Expr e)
{
Debug.Assert(e != null);
Debug.Assert(e is ArithExpr);
@ -2413,7 +2413,8 @@ namespace Microsoft.Z3
/// <summary>
/// Convert a bit-vector expression, represented as an signed number, to a string.
/// </summary>
public SeqExpr SbvToString(Expr e) {
public SeqExpr SbvToString(Expr e)
{
Debug.Assert(e != null);
Debug.Assert(e is ArithExpr);
return new SeqExpr(this, Native.Z3_mk_sbv_to_str(nCtx, e.NativeObject));
@ -2422,7 +2423,7 @@ namespace Microsoft.Z3
/// <summary>
/// Convert an integer expression to a string.
/// </summary>
public IntExpr StringToInt(Expr e)
public IntExpr StringToInt(Expr e)
{
Debug.Assert(e != null);
Debug.Assert(e is SeqExpr);
@ -2449,13 +2450,13 @@ namespace Microsoft.Z3
public IntExpr MkLength(SeqExpr s)
{
Debug.Assert(s != null);
return (IntExpr) Expr.Create(this, Native.Z3_mk_seq_length(nCtx, s.NativeObject));
return (IntExpr)Expr.Create(this, Native.Z3_mk_seq_length(nCtx, s.NativeObject));
}
/// <summary>
/// Check for sequence prefix.
/// </summary>
public BoolExpr MkPrefixOf(SeqExpr s1, SeqExpr s2)
public BoolExpr MkPrefixOf(SeqExpr s1, SeqExpr s2)
{
Debug.Assert(s1 != null);
Debug.Assert(s2 != null);
@ -2466,7 +2467,7 @@ namespace Microsoft.Z3
/// <summary>
/// Check for sequence suffix.
/// </summary>
public BoolExpr MkSuffixOf(SeqExpr s1, SeqExpr s2)
public BoolExpr MkSuffixOf(SeqExpr s1, SeqExpr s2)
{
Debug.Assert(s1 != null);
Debug.Assert(s2 != null);
@ -2477,7 +2478,7 @@ namespace Microsoft.Z3
/// <summary>
/// Check for sequence containment of s2 in s1.
/// </summary>
public BoolExpr MkContains(SeqExpr s1, SeqExpr s2)
public BoolExpr MkContains(SeqExpr s1, SeqExpr s2)
{
Debug.Assert(s1 != null);
Debug.Assert(s2 != null);
@ -2488,7 +2489,7 @@ namespace Microsoft.Z3
/// <summary>
/// Check if the string s1 is lexicographically strictly less than s2.
/// </summary>
public BoolExpr MkStringLt(SeqExpr s1, SeqExpr s2)
public BoolExpr MkStringLt(SeqExpr s1, SeqExpr s2)
{
Debug.Assert(s1 != null);
Debug.Assert(s2 != null);
@ -2499,7 +2500,7 @@ namespace Microsoft.Z3
/// <summary>
/// Check if the string s1 is lexicographically less or equal to s2.
/// </summary>
public BoolExpr MkStringLe(SeqExpr s1, SeqExpr s2)
public BoolExpr MkStringLe(SeqExpr s1, SeqExpr s2)
{
Debug.Assert(s1 != null);
Debug.Assert(s2 != null);
@ -2568,10 +2569,10 @@ namespace Microsoft.Z3
/// <summary>
/// Convert a regular expression that accepts sequence s.
/// </summary>
public ReExpr MkToRe(SeqExpr s)
public ReExpr MkToRe(SeqExpr s)
{
Debug.Assert(s != null);
return new ReExpr(this, Native.Z3_mk_seq_to_re(nCtx, s.NativeObject));
return new ReExpr(this, Native.Z3_mk_seq_to_re(nCtx, s.NativeObject));
}
@ -2583,7 +2584,7 @@ namespace Microsoft.Z3
Debug.Assert(s != null);
Debug.Assert(re != null);
CheckContextMatch(s, re);
return new BoolExpr(this, Native.Z3_mk_seq_in_re(nCtx, s.NativeObject, re.NativeObject));
return new BoolExpr(this, Native.Z3_mk_seq_in_re(nCtx, s.NativeObject, re.NativeObject));
}
/// <summary>
@ -2592,7 +2593,7 @@ namespace Microsoft.Z3
public ReExpr MkStar(ReExpr re)
{
Debug.Assert(re != null);
return new ReExpr(this, Native.Z3_mk_re_star(nCtx, re.NativeObject));
return new ReExpr(this, Native.Z3_mk_re_star(nCtx, re.NativeObject));
}
/// <summary>
@ -2601,7 +2602,7 @@ namespace Microsoft.Z3
public ReExpr MkLoop(ReExpr re, uint lo, uint hi = 0)
{
Debug.Assert(re != null);
return new ReExpr(this, Native.Z3_mk_re_loop(nCtx, re.NativeObject, lo, hi));
return new ReExpr(this, Native.Z3_mk_re_loop(nCtx, re.NativeObject, lo, hi));
}
/// <summary>
@ -2610,7 +2611,7 @@ namespace Microsoft.Z3
public ReExpr MkPlus(ReExpr re)
{
Debug.Assert(re != null);
return new ReExpr(this, Native.Z3_mk_re_plus(nCtx, re.NativeObject));
return new ReExpr(this, Native.Z3_mk_re_plus(nCtx, re.NativeObject));
}
/// <summary>
@ -2619,7 +2620,7 @@ namespace Microsoft.Z3
public ReExpr MkOption(ReExpr re)
{
Debug.Assert(re != null);
return new ReExpr(this, Native.Z3_mk_re_option(nCtx, re.NativeObject));
return new ReExpr(this, Native.Z3_mk_re_option(nCtx, re.NativeObject));
}
/// <summary>
@ -2628,7 +2629,7 @@ namespace Microsoft.Z3
public ReExpr MkComplement(ReExpr re)
{
Debug.Assert(re != null);
return new ReExpr(this, Native.Z3_mk_re_complement(nCtx, re.NativeObject));
return new ReExpr(this, Native.Z3_mk_re_complement(nCtx, re.NativeObject));
}
/// <summary>
@ -2670,7 +2671,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a difference regular expression.
/// </summary>
public ReExpr MkDiff(ReExpr a, ReExpr b)
public ReExpr MkDiff(ReExpr a, ReExpr b)
{
Debug.Assert(a != null);
Debug.Assert(b != null);
@ -2682,7 +2683,7 @@ namespace Microsoft.Z3
/// Create the empty regular expression.
/// The sort s should be a regular expression.
/// </summary>
public ReExpr MkEmptyRe(Sort s)
public ReExpr MkEmptyRe(Sort s)
{
Debug.Assert(s != null);
return new ReExpr(this, Native.Z3_mk_re_empty(nCtx, s.NativeObject));
@ -2692,7 +2693,7 @@ namespace Microsoft.Z3
/// Create the full regular expression.
/// The sort s should be a regular expression.
/// </summary>
public ReExpr MkFullRe(Sort s)
public ReExpr MkFullRe(Sort s)
{
Debug.Assert(s != null);
return new ReExpr(this, Native.Z3_mk_re_full(nCtx, s.NativeObject));
@ -2702,7 +2703,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a range expression.
/// </summary>
public ReExpr MkRange(SeqExpr lo, SeqExpr hi)
public ReExpr MkRange(SeqExpr lo, SeqExpr hi)
{
Debug.Assert(lo != null);
Debug.Assert(hi != null);
@ -2713,7 +2714,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create less than or equal to between two characters.
/// </summary>
public BoolExpr MkCharLe(Expr ch1, Expr ch2)
public BoolExpr MkCharLe(Expr ch1, Expr ch2)
{
Debug.Assert(ch1 != null);
Debug.Assert(ch2 != null);
@ -2723,7 +2724,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create an integer (code point) from character.
/// </summary>
public IntExpr CharToInt(Expr ch)
public IntExpr CharToInt(Expr ch)
{
Debug.Assert(ch != null);
return new IntExpr(this, Native.Z3_mk_char_to_int(nCtx, ch.NativeObject));
@ -2732,7 +2733,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a bit-vector (code point) from character.
/// </summary>
public BitVecExpr CharToBV(Expr ch)
public BitVecExpr CharToBV(Expr ch)
{
Debug.Assert(ch != null);
return new BitVecExpr(this, Native.Z3_mk_char_to_bv(nCtx, ch.NativeObject));
@ -2741,7 +2742,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a character from a bit-vector (code point).
/// </summary>
public Expr CharFromBV(BitVecExpr bv)
public Expr CharFromBV(BitVecExpr bv)
{
Debug.Assert(bv != null);
return new Expr(this, Native.Z3_mk_char_from_bv(nCtx, bv.NativeObject));
@ -2750,7 +2751,7 @@ namespace Microsoft.Z3
/// <summary>
/// Create a check if the character is a digit.
/// </summary>
public BoolExpr MkIsDigit(Expr ch)
public BoolExpr MkIsDigit(Expr ch)
{
Debug.Assert(ch != null);
return new BoolExpr(this, Native.Z3_mk_char_is_digit(nCtx, ch.NativeObject));
@ -2768,7 +2769,7 @@ namespace Microsoft.Z3
Debug.Assert(args != null);
CheckContextMatch<BoolExpr>(args);
var ts = args.ToArray();
return new BoolExpr(this, Native.Z3_mk_atmost(nCtx, (uint) ts.Length,
return new BoolExpr(this, Native.Z3_mk_atmost(nCtx, (uint)ts.Length,
AST.ArrayToNative(ts), k));
}
@ -2780,7 +2781,7 @@ namespace Microsoft.Z3
Debug.Assert(args != null);
CheckContextMatch<BoolExpr>(args);
var ts = args.ToArray();
return new BoolExpr(this, Native.Z3_mk_atleast(nCtx, (uint) ts.Length,
return new BoolExpr(this, Native.Z3_mk_atleast(nCtx, (uint)ts.Length,
AST.ArrayToNative(ts), k));
}
@ -2789,13 +2790,13 @@ namespace Microsoft.Z3
/// </summary>
public BoolExpr MkPBLe(int[] coeffs, BoolExpr[] args, int k)
{
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pble(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pble(nCtx, (uint)args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
/// <summary>
@ -2803,26 +2804,26 @@ namespace Microsoft.Z3
/// </summary>
public BoolExpr MkPBGe(int[] coeffs, BoolExpr[] args, int k)
{
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbge(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbge(nCtx, (uint)args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
/// <summary>
/// Create a pseudo-Boolean equal constraint.
/// </summary>
public BoolExpr MkPBEq(int[] coeffs, BoolExpr[] args, int k)
{
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbeq(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
Debug.Assert(args != null);
Debug.Assert(coeffs != null);
Debug.Assert(args.Length == coeffs.Length);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbeq(nCtx, (uint)args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
#endregion
@ -4085,7 +4086,7 @@ namespace Microsoft.Z3
/// <param name="negative">indicates whether the result should be negative.</param>
public FPNum MkFPZero(FPSort s, bool negative)
{
return new FPNum(this, Native.Z3_mk_fpa_zero(nCtx, s.NativeObject, (byte)(negative ? 1 : 0)));
return new FPNum(this, Native.Z3_mk_fpa_zero(nCtx, s.NativeObject, (byte)(negative ? 1 : 0)));
}
/// <summary>
@ -4127,7 +4128,7 @@ namespace Microsoft.Z3
/// <param name="s">FloatingPoint sort.</param>
public FPNum MkFPNumeral(bool sgn, uint sig, int exp, FPSort s)
{
return new FPNum(this, Native.Z3_mk_fpa_numeral_int_uint(nCtx, (byte)(sgn ? 1 : 0), exp, sig, s.NativeObject));
return new FPNum(this, Native.Z3_mk_fpa_numeral_int_uint(nCtx, (byte)(sgn ? 1 : 0), exp, sig, s.NativeObject));
}
/// <summary>
@ -4139,7 +4140,7 @@ namespace Microsoft.Z3
/// <param name="s">FloatingPoint sort.</param>
public FPNum MkFPNumeral(bool sgn, Int64 exp, UInt64 sig, FPSort s)
{
return new FPNum(this, Native.Z3_mk_fpa_numeral_int64_uint64(nCtx, (byte)(sgn ? 1 : 0), exp, sig, s.NativeObject));
return new FPNum(this, Native.Z3_mk_fpa_numeral_int64_uint64(nCtx, (byte)(sgn ? 1 : 0), exp, sig, s.NativeObject));
}
/// <summary>
@ -4825,12 +4826,12 @@ namespace Microsoft.Z3
/// <summary>
/// ASTVector DRQ
/// </summary>
public IDecRefQueue ASTVector_DRQ { get { return m_ASTVector_DRQ; } }
public IDecRefQueue ASTVector_DRQ { get { return m_ASTVector_DRQ; } }
/// <summary>
/// ApplyResult DRQ
/// </summary>
public IDecRefQueue ApplyResult_DRQ { get { return m_ApplyResult_DRQ; } }
public IDecRefQueue ApplyResult_DRQ { get { return m_ApplyResult_DRQ; } }
/// <summary>
/// FuncEntry DRQ
@ -4937,7 +4938,7 @@ namespace Microsoft.Z3
m_ctx = IntPtr.Zero;
Native.Z3_del_context(ctx);
}
else
else
GC.ReRegisterForFinalize(this);
}
#endregion