Repository navigation
verify: Verify member functions as functions of this - #73
Open
SwayamInSync wants to merge 93 commits into
Open
SwayamInSync wants to merge 93 commits into
SwayamInSync wants to merge 93 commits into
Conversation
…r does not represent.
…the release notes.
…the address passed to a callee.
…reseated, and members named whole in modifies as their bytes.
…nts in the release notes.
…nd name a class template for its members.
…ject at a member call.
…n the architecture.
… to report, so no header's is mangled.
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.
Member functions were not verified: contracts written in a class were skipped with a warning (
contracts on member functions are not yet supported and are ignored), and a contracted member function defined outside its class was an error (member function verification is unsupported). Now a member function of a class without bases or virtual functions is a function ofthis:Stacked on #72 (B3-1 of plan item B3: member functions; constructors, class invariants, and member operators follow).
Design
Plan B3's design, from Dafny's
thiswithmodifies this, Verus's&self/&mut self, and C++26's contracts, on top of B3a:thisis a parameter. A non-static member function's first parameter isthis, a pointer togetFunctionObjectParameterType()(to const in a const member function), with the generated validity of a reference (non-null, valid, initialized at entry).CXXThisExprconverts to it, sothis->nand an implicitnare places through a pointer exactly asp->n(3b), andmodifies(*this)is its object's region. It joins the default separation (AddressEntry);cppverify::aliases(this, o)names it (aliasesListed). Its class is aRecordParamsentry, so a local object is lent to a member function under verify: Lend local records and addresses to callees that keep no address of them #71's rules.modifiesmay write*this; a const one only its own storage,mutablefields only when listed; an explicitmodifiesreplaces the default; a trusted or bodiless one keeps the trusted-contract rule.convertExecCallArgs):p->m()passesp,this->m()andm()passthis, andobj.m()bindsobjas a reference argument (address discovery promotes the local). A static member function is a free function. A member call inside an expression is unsupported as a free call is.ParseLexedMethodDeclarationwith the parameters andthisin scope, before the late-parsed body (ParseFunctionContractClauseListisParseFunctionContractClausesafter the declarator's scopes). An out-of-line definition's clauses enter its class's scope andthis, as its trailing requires-clause does.unsupportedMemberFunction), each an error of its function when it is contracted: virtual functions, member functions of a class with bases (or polymorphic), constructors and destructors (next), conversion functions, explicit object parameters, rvalue- and volatile-qualified ones, lambdas. A member of a class template keeps the template warning, now naming the class template.Tests
suite/member_functions.cpp(Z3, BMC, a Lean export):bump, a constget,resetwithoutmodifies(the default frame),twicethrough implicitthiscalls,copy_fromandaliases(this, o), a store outsidemodifies(frame), a const member function writing amutablefield without and withmodifies, a static member function, a declaration's contract with an out-of-line definition, a member call inside an expression (the free-call error); callers on a local object, through a pointer, through a reference, on a member of an object; a caller frame narrower than the default (frame);thisand a parameter one object (aliasing, and withaliases); a const member function sharing its object with a read-only parameter; the located errors of a virtual function, a derived class, a constructor, a destructor, and a conversion function.member_function_contracts.cpp(-verify): in-class clauses name later members andthis, an undeclared name is an error there, an out-of-line definition's clauses name members andthis, and a contract on two declarations is an error.located_errors.cppnow locates a virtual function's error;template_contracts.cppexpects the class template's warning on its member.The warning for contracts on member functions is gone, since it is no longer issued.
Mutants, each built and run on
member_functions.cpp,member_function_contracts.cpp,template_contracts.cpp,located_errors.cpp, andlocal_record_arguments.cpp: 15 of 15 killed.member_functionsthismember_functionsthisnot in the separationmember_functionsthismutable in a const member functionmember_functions(self_plus)member_functionsmember_functions(peek_bad)member_functionsmember_functionsmember_functions,located_errorsmember_functionsaliasescannot namethismember_functionsmember_functions,member_function_contracts,template_contractsmember_functions,member_function_contractstemplate_contractsthisin out-of-line clausesmember_functions,member_function_contractsDocs
Checked