-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java type generics #4832
Merged
Merged
Java type generics #4832
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
19d83e3
Generify, needs some testing and review
addisoncrump da9c2ed
Remove unnecessary change
addisoncrump 7c30c50
Whoops, ? capture that type
addisoncrump c1096ad
Misread the docs, whoops
addisoncrump 9173296
More permissible arithmetic operations
addisoncrump 9ad727d
Implement believed Optimize generics
addisoncrump b6b42c9
Missed a few generics
addisoncrump 8904764
More permissible expr for arrays in parameters
addisoncrump 92f5f2d
More permissible expr for bitvecs in parameters
addisoncrump 9d4aa7c
More permissible expr for bools in parameters
addisoncrump dd80510
More permissible expr for fps in parameters
addisoncrump e154a47
More permissible expr for fprms in parameters
addisoncrump 37da41d
More permissible expr for ints in parameters
addisoncrump f7f43a8
More permissible expr for reals in parameters
addisoncrump e3d7a9b
Undo breaking name conflict due to type erasure; see notes
addisoncrump 372de12
Whoops, fix typing of ReExpr
addisoncrump 7894e69
Sort corrections for Re, Seq
addisoncrump 5f58655
More permissible expr for regular expressions in parameters
addisoncrump 67e4ef8
Fix name conflict between sequences and regular expressions; see notes
addisoncrump 714e8f7
Minor typo, big implications!
addisoncrump e47e996
Make Constructor consistent, associate captured types with other unkn…
addisoncrump d975295
More expressive; outputs of multiple datatype definitions are only kn…
addisoncrump cf0289e
Be less dumb and just type it a little differently
addisoncrump c5a1737
Update examples, make sure to type Expr and FuncDecl sort returns
addisoncrump ca8a595
General fixups
addisoncrump 4e14a1c
Downgrade java version, make it only for the generic support, remove …
addisoncrump 82a0d4f
Turns out Java 8 hadn't figured out how to do stream generics yet. Di…
addisoncrump File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ Nikolaj Bjorner (nbjorner) 2015-07-16 | |
/** | ||
* Object for managing optimization context | ||
**/ | ||
@SuppressWarnings("unchecked") | ||
public class Optimize extends Z3Object { | ||
|
||
/** | ||
|
@@ -75,7 +76,7 @@ public void Add(BoolExpr ... constraints) | |
/** | ||
* Handle to objectives returned by objective functions. | ||
**/ | ||
public static class Handle { | ||
public static class Handle<R extends Sort> { | ||
|
||
private final Optimize opt; | ||
private final int handle; | ||
|
@@ -89,15 +90,15 @@ public static class Handle { | |
/** | ||
* Retrieve a lower bound for the objective handle. | ||
**/ | ||
public Expr getLower() | ||
public Expr<R> getLower() | ||
{ | ||
return opt.GetLower(handle); | ||
} | ||
|
||
/** | ||
* Retrieve an upper bound for the objective handle. | ||
**/ | ||
public Expr getUpper() | ||
public Expr<R> getUpper() | ||
{ | ||
return opt.GetUpper(handle); | ||
} | ||
|
@@ -110,7 +111,7 @@ public Expr getUpper() | |
* and otherwise is represented by the expression {@code value + eps * EPSILON}, | ||
* where {@code EPSILON} is an arbitrarily small real number. | ||
*/ | ||
public Expr[] getUpperAsVector() | ||
public Expr<?>[] getUpperAsVector() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be typed to |
||
{ | ||
return opt.GetUpperAsVector(handle); | ||
} | ||
|
@@ -120,15 +121,15 @@ public Expr[] getUpperAsVector() | |
* | ||
* <p>See {@link #getUpperAsVector()} for triple semantics. | ||
*/ | ||
public Expr[] getLowerAsVector() | ||
public Expr<?>[] getLowerAsVector() | ||
{ | ||
return opt.GetLowerAsVector(handle); | ||
} | ||
|
||
/** | ||
* Retrieve the value of an objective. | ||
**/ | ||
public Expr getValue() | ||
public Expr<R> getValue() | ||
{ | ||
return getLower(); | ||
} | ||
|
@@ -243,42 +244,42 @@ public BoolExpr[] getUnsatCore() | |
* Return a handle to the objective. The handle is used as | ||
* to retrieve the values of objectives after calling Check. | ||
**/ | ||
public Handle MkMaximize(Expr e) | ||
public <R extends Sort> Handle<R> MkMaximize(Expr<R> e) | ||
{ | ||
return new Handle(this, Native.optimizeMaximize(getContext().nCtx(), getNativeObject(), e.getNativeObject())); | ||
return new Handle<>(this, Native.optimizeMaximize(getContext().nCtx(), getNativeObject(), e.getNativeObject())); | ||
} | ||
|
||
/** | ||
* Declare an arithmetical minimization objective. | ||
* Similar to MkMaximize. | ||
**/ | ||
public Handle MkMinimize(Expr e) | ||
public <R extends Sort> Handle<R> MkMinimize(Expr<R> e) | ||
{ | ||
return new Handle(this, Native.optimizeMinimize(getContext().nCtx(), getNativeObject(), e.getNativeObject())); | ||
return new Handle<>(this, Native.optimizeMinimize(getContext().nCtx(), getNativeObject(), e.getNativeObject())); | ||
} | ||
|
||
/** | ||
* Retrieve a lower bound for the objective handle. | ||
**/ | ||
private Expr GetLower(int index) | ||
private <R extends Sort> Expr<R> GetLower(int index) | ||
{ | ||
return Expr.create(getContext(), Native.optimizeGetLower(getContext().nCtx(), getNativeObject(), index)); | ||
return (Expr<R>) Expr.create(getContext(), Native.optimizeGetLower(getContext().nCtx(), getNativeObject(), index)); | ||
} | ||
|
||
/** | ||
* Retrieve an upper bound for the objective handle. | ||
**/ | ||
private Expr GetUpper(int index) | ||
private <R extends Sort> Expr<R> GetUpper(int index) | ||
{ | ||
return Expr.create(getContext(), Native.optimizeGetUpper(getContext().nCtx(), getNativeObject(), index)); | ||
return (Expr<R>) Expr.create(getContext(), Native.optimizeGetUpper(getContext().nCtx(), getNativeObject(), index)); | ||
} | ||
|
||
/** | ||
* @return Triple representing the upper bound for the objective handle. | ||
* | ||
* <p>See {@link Handle#getUpperAsVector}. | ||
*/ | ||
private Expr[] GetUpperAsVector(int index) { | ||
private Expr<?>[] GetUpperAsVector(int index) { | ||
return unpackObjectiveValueVector( | ||
Native.optimizeGetUpperAsVector( | ||
getContext().nCtx(), getNativeObject(), index | ||
|
@@ -291,20 +292,20 @@ private Expr[] GetUpperAsVector(int index) { | |
* | ||
* <p>See {@link Handle#getLowerAsVector}. | ||
*/ | ||
private Expr[] GetLowerAsVector(int index) { | ||
private Expr<?>[] GetLowerAsVector(int index) { | ||
return unpackObjectiveValueVector( | ||
Native.optimizeGetLowerAsVector( | ||
getContext().nCtx(), getNativeObject(), index | ||
) | ||
); | ||
} | ||
|
||
private Expr[] unpackObjectiveValueVector(long nativeVec) { | ||
private Expr<?>[] unpackObjectiveValueVector(long nativeVec) { | ||
ASTVector vec = new ASTVector( | ||
getContext(), nativeVec | ||
); | ||
return new Expr[] { | ||
(Expr) vec.get(0), (Expr) vec.get(1), (Expr) vec.get(2) | ||
(Expr<?>) vec.get(0), (Expr<?>) vec.get(1), (Expr<?>) vec.get(2) | ||
}; | ||
|
||
} | ||
|
@@ -355,7 +356,7 @@ public BoolExpr[] getAssertions() | |
/** | ||
* The set of asserted formulas. | ||
*/ | ||
public Expr[] getObjectives() | ||
public Expr<?>[] getObjectives() | ||
{ | ||
ASTVector objectives = new ASTVector(getContext(), Native.optimizeGetObjectives(getContext().nCtx(), getNativeObject())); | ||
return objectives.ToExprArray(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be more narrowly defined to
R extends ArithSort
?