Late name-resolution disambiguation, non-namespace based resolution
In Alloy name resolution for fields is not based on namespaces.
module debug sig Singer {band: Band} sig RadioStation {band: Frequency} sig Band, Frequency {} pred show () { all b:Band | some b.~band all b:Band | some band.b all b:Band | some s:Singer | s->b in band } run show for 3Declares 4 basic types:
Singer,RadioStation,BandandFrequencyand 2 fieldsbandof typesSinger -> BandandRadioStation -> Frequency.The predicate
showcontains 3 equivalent constraints. The fieldbandis in all cases resolved to the field inSinger.
band:Singer -> BandorRadioStation -> Frequency
~band:Band -> SingerorFrequency -> RadioStation
b:Band
s:Singer
s->b:Singer -> Bandthus
b.~bandreads asb:Band.~band:Band->Singer(since reading~band:Frequency->RadioStationwould fail to join ‘.’ withb)
band.breads asband:Singer->Band.b:Band(same reason)
s->b in bandreads ass->b:Singer->Bandinband:Singer->Band(same reason)So basically disambiguation is done further up the AST.
If disambiguation fails
all b:Object | some b.~band(Objectis supertype of all basic types, sobandcan now refer to both fields), then an error is shownIf no field survives after disambiguation, then it is an unresolved reference.
This means that a lookup now basically gets multiple stages: (1) do a lookup without constraints and find all possible values, (2) propagate all possible values up through the AST until you reach a point where one or more alternatives can be discarded (3) discard the alternatives also back down the tree s.t. the name is only resolved to the correct declaration.
Submitted by Daco Harkes on 9 February 2015 at 15:31
Log in to post comments