28.01.2015 Views

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

initialized.Attheendofthethenclause,aftertheassignmentstoA<strong>and</strong>B, thediscussion,wewilllookonlyattypestateattributesrelatingtothe initializedstateofvariablesA,B,C,<strong>and</strong>L. isempty.AfterthecalltoGetLine,thetypestateisfinit(L)g|onlyLis Letusfollowtheanalysisoftypestatesintheaboveexample.Tosimplify Onentrytotheblock,noneofthevariablesisinitialized,sothetypestate 3.Type<strong>and</strong>TypestateChecking57<br />

clause,thetypestateisfinit(L),init(A),init(C)g. thetypestateisfinit(L),init(A),init(B)g.Attheendoftheelse<br />

toberun-timetestsofinitializedness|avariablemusteitherbeknownto werepossiblyinitialized,<strong>and</strong>possiblynot.In<strong>Hermes</strong>,wedonotwishthere entrytothemerge.SoallyouwouldknowaboutB<strong>and</strong>Cwouldbethatthey analysis,youalwaysknowlessinformationatamergepointthanateither thiscase,thattypestateisfinit(L),init(A)g|variablesL<strong>and</strong>Awill atthemergepointiscomputedastheintersectionofthetypestates.1In beinitialized,B<strong>and</strong>Cuninitialized. Attheendoftheifstatement,thetwopathsmerge.Thetypestate<br />

beinitializedorknowntobeuninitialized.Theintersectionruleimplies <strong>and</strong>Careinfactuninitializedatthispointregardlessoftheexecutionpath taken,thecompilerinsertscoercionoperations.Inthiscase,thecompiler thatB<strong>and</strong>Cwillbeuninitializedatthemergepoint.TomakesurethatB Hereiswheretypestateanalysisgoesbeyonddataowanalysis.Indataow<br />

statementaftertheelseclause. willinsertadiscardBstatementafterthethenclause<strong>and</strong>adiscardC issaidtobelower.Coercionoperationsalwaysconvertfromahighertypestatetoalowerone.<br />

finit(L)g(thirdcall).Theintersectionisthetypestatefg.Thecompiler secondcalltoGetLinetotheh<strong>and</strong>ler,<strong>and</strong>itinsertsanoperationtodiscard automaticallyinsertsoperationstodiscardL<strong>and</strong>Aintothepathfromthe Atypestatewithastrictsubsetoftheattributesofasecondtypestate Therearethreepathstothath<strong>and</strong>ler|onefromeachcalltoGetLine.The threetypestatesarefg(rstcall),finit(L),init(A)g(secondcall),<strong>and</strong> Lintothepathfromthethirdcall. Asimilarsituationprevailsattheexceptionh<strong>and</strong>leron(GetLineInterface.Endstream).<br />

Parms.GetLine(A),theGetLineIndenitionrequirestheargumenttobe ment,itischeckedthatbothL<strong>and</strong>Aareinitialized.Inthestatementcall italsochecksforlegalityofprograms.Forinstance,attheinsertstate-<br />

operationdiscardAisinsertedsothatAwillbeuninitializedasexpected uninitialized,yetAisinitialized.Here,thetypestateistoohigh.Acoercion Typestateanalysisnotonlytracksthetypestate<strong>and</strong>performscoercions,<br />

typestateislowerthantheotherifitisasubsetoftheother;themeetoftwo structurewheretheelements(typestatesinthiscase)arepartiallyordered,<strong>and</strong> typestatesistheirintersection. whereeverypairofelementshasameetorgreatestlowerbound.In<strong>Hermes</strong>,one 1Mathematically,thesetoftypestatesisasemilattice|thatis,amathematical

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!