Repository navigation
A18: std::min and std::max of two integers, and constexpr helpers taking const references - #82
Open
SwayamInSync wants to merge 64 commits into
Open
SwayamInSync wants to merge 64 commits into
SwayamInSync wants to merge 64 commits into
Conversation
…ependence of their type or operands.
…nd the checks it shares with the parser.
…y in Sema, for the parser and for instantiation.
…tracts with their loops, and trigger marks.
…and keep ghost variables ghost.
…e, named with its arguments.
…a template's type compared with a constant.
…wn, so each element of a pack expansion binds its own variable.
… and the pattern's checks already give.
…nd type invariants.
…ch instantiation can rebuild.
…lization, and report members none instantiates.
…are checked where instantiated.
…riant field rewriter's entry point.
… that Sema's own this->field made dead.
…mbers verified once.
…ces of lifted specs.
…ec's const references as values, and name a helper that cannot be lifted.
…texpr helpers taking references.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
std::minandstd::maxin a contract endedUnresolved: obligation lowering failed: f (missing spec definition: fn_...): they areconstexprtemplates of the standard library, which the converter applies as specs but never lifts. Now, of two integers, they mean what the standard says, whatever the library, in contracts and in code:On the base (#81):
Stacked on #81 (plan item A18, which the plan schedules with B2: lift constexpr template instantiations, or fail closed with a message that names the function).
Design
constexprhelper is lifted. But each library writes these functions its own way (libstdc++ with anifand two returns, under a concept-check macro), so a proof that lifted the library's code would rest on the platform's library, and a construct one library uses and the verifier does not support would cost that platform alone. The standard fixes their meaning instead ([alg.min.max]): for scalars,max(a, b)isa < b ? b : aandmin(a, b)isb < a ? b : a.stdMinOrMaxrecognizes the two-argumentstd::minandstd::maxof a const reference to an integer, an enumeration, orbool(not the comparison or initializer-list overloads, nor a class with its ownoperator<), andconvertMinOrMaxlowers a call to aVConditionalExprover the arguments, read once each, before the call would become a spec application; it has no definedness condition of its own. A reference bound to the result fails closed, as any reference to a call result does.constexprfunctions (std::clamp) is an error naming it,std::clamp is not modeled: of the standard library, the verifier knows std::min and std::max of two integers.constexpr const T &larger(const T &a, const T &b), could not be lifted (unsupported C++ type in verification: const int &). A spec is a function of values, and a reference to a const integer, which the helper only reads, stands for the value it refers to, as a parameter and as the result (constScalarReferent; the parameters inValueReferencesare read as values, not loaded). A reference the helper could write through (int &) is still unsupported.missing spec definition: fn_<hex>; and a helper reading memory through a pointer failed silently.convertConstexprSpecnow returns a placeholder that the lifting loop marks unsupported, reporting why at the helper, so the driver's existing check names it in each verdict that relies on it:Unresolved: reads [reason=construct.unsupported] (relies on first, which uses a construct the verifier does not support).Tests
suite/std_min_max.cpp(Z3, with a check that no proof is vacuous):std::maxandstd::minin contracts and in code, in an expression, with an explicit template argument, ofunsigned longand of an enumeration, and in a spec; a wrong use that fails with a counterexample;std::clamp,std::maxof a class with its ownoperator<, and a reference bound tostd::max's result, each an error; a user'sconstexpr const T &helper lifted and verified; a helper reading through a pointer and one takingint &, each named in its user's verdict.The test fails on the base: every function using
std::minorstd::maxendsmissing spec definition,std::clamptoo, andmymax<int>isunsupported C++ type in verification: const int &with its usermissing spec definition.Mutants, each built on an assertions build and run on
std_min_max.cpp,function_templates.cpp,z3_calls_fail_closed.cpp, andverify_constexpr_spec_e2e.cpp: 8 of 8 killed.std_min_maxstd_min_max(clamp3,wrong)std_min_max(newer)std_min_max(clamped)std_min_max(mine)std_min_max(mymax<int>)std_min_max(reads,bumps)std_min_max(bumped)Docs
std::minandstd::max, a checked example; what changed.stdMinOrMax,convertMinOrMax, unlifted helpers.Checked
docs_examples.testanddocs_coverage.testpass in the suite; the site builds with warnings as errors.