Go to the documentation of this file. 1 package com.cliffc.aa.type;
6 import org.jetbrains.annotations.
NotNull;
9 import java.util.function.Predicate;
56 super.
init(TSTRUCT, name, any, any);
67 int hash1 = super.compute_hash(), hash = hash1 +(
_open?1023:0);
71 return hash == 0 ? hash1 : hash;
77 if( !super.equals(t) )
return 0;
80 for(
int i=0; i<
_flds.length; i++ )
83 for(
int i=0; i<
_flds.length; i++ )
89 @Override
public boolean equals( Object o ) {
90 if(
this==o )
return true;
98 if( x != -1 )
return x == 1;
107 int idx =
CYCLES.find(
this);
108 return idx != -1 ?
CYCLES.at(idx^1) :
null;
111 if(
this==o )
return true;
112 if( !(o instanceof
TypeStruct) )
return false;
115 if( t2 !=
null )
return t2==t ;
117 if( t3 !=
null )
return t3==
this;
119 if( x != -1 )
return x == 1;
129 for(
int i=0; i<
_flds.length; i++ ) {
133 (t0==
null || t1==
null ||
140 static boolean isDigit(
char c) {
return '0' <= c && c <=
'9'; }
142 if(
_flds.length<=1 )
return true;
146 if( dups.
tset(_uid) )
return sb.
p(
'$');
147 if(
_any ) sb.
p(
'~');
155 ? (((
TypeFunPtr)t1)._fidxs.above_center() ?
"PRIMS" :
"LOW_PRIMS")
158 boolean field_sep=
false;
159 for(
int i=0; i<
_flds.length; i++ ) {
174 static {
new Pool(TSTRUCT,
new TypeStruct()); }
180 return hashcons_free();
202 for(
int i=0; i<ts.length; i++ )
253 if( _dual !=
null )
return _dual;
256 for(
int i=0; i<
_flds.length; i++ )
264 for(
int i=0; i<
_flds.length; i++ )
285 case TSTR:
return OBJ;
286 case TOBJ:
return t.
xmeet(
this);
294 case TMEM:
return ALL;
295 default:
throw typerr(t);
300 assert RECURSIVE_MEET > 0 || (thsi.interned() && that.interned());
303 assert RECURSIVE_MEET > 0 || (
MEETS0.isEmpty());
321 for(
int i=0; i<
_flds.length; i++ )
327 for(
int i=
_flds.length; i<
len; i++ )
342 @Override
public boolean equals(Object o) {
346 private static final HashMap<TPair,TypeStruct>
MEETS0 =
new HashMap<>();
365 if( mt !=
null )
return mt;
377 for(
int i=0; i<
len; i++ )
379 mt._name = mt.mtname(mx,mt);
391 for(
int i=0; i<
len; i++ ) {
392 Type lfi = i<this._flds.length ? this._flds[i].
_t :
null;
394 Type mti = (lfi==
null) ? rti : (rti==
null ? lfi : lfi.
meet(rti));
396 Type mts = mtx==
null ? mti : mtx.
meet(mti);
401 if( ts!=mt && ts.
equals(mt) )
406 if( --RECURSIVE_MEET > 0 )
435 assert t._hash==0 || t._hash==t.compute_hash();
436 if( t.interned() )
return false;
437 if( t.retern() != t._dual ) t._dual.retern();
455 if( bs.
tset(_uid) )
return null;
456 if(
this!=head &&
equals(head) )
return this;
459 if( ts!=
null )
return ts;
478 boolean shallow=
true;
480 if(
fld.
_t.
_type == TMEMPTR ) { shallow=
false;
break; }
481 if( shallow )
return this;
498 assert this.isa(rez);
508 assert old.interned();
514 if( nt !=
null )
return ufind(nt);
521 assert cutoffs ==
null;
531 for(
int i=0; i<old.
_flds.length; i++ )
536 if( isnews && d==cutoff ) {
553 if( nt !=
null )
return ufind(nt);
576 if( nt !=
null )
return ufind(nt);
596 if( nt == old )
return old;
607 return union(nt,old);
620 return union(nt,old);
636 if(
len != nts._flds.length )
637 nts._flds = Arrays.copyOf(nts._flds,
len);
638 int clen = Math.min(
len,ots.
_flds.length);
640 nts._any &= ots.
_any ; nts._use = nts._any;
641 nts._open|= ots.
_open;
642 for(
int i=0; i<clen; i++ )
643 nts._flds[i].cmeet(ots.
_flds[i]);
645 for(
int i=0; i<clen; i++ )
660 for(
int i=0; i<reaches.
_len; i++ ) {
666 for(
int i=0; i<reaches.
_len; i++ ) {
672 for(
int i=0; i<reaches.
_len; i++ ) {
680 boolean progress =
true;
684 for(
int j=0; j<reaches.
_len; j++ ) {
688 if( t1==
null ) t1 =
DUPS.
get(t0);
689 if( t1 !=
null ) t1 =
ufind(t1);
690 if( t1 == t0 )
continue;
691 if( t1 !=
null ) {
union(t0,t1); progress =
true;
continue; }
716 for(
int i=0; i<ts.
_flds.length; i++ ) {
718 if( tfld != tfld2 ) {
739 return ufind(tstart);
750 @SuppressWarnings(
"unchecked")
752 T t0 = (T)
UF.get(t._uid), tu;
753 if( t0 ==
null )
return t;
755 while( (tu = (T)
UF.get(t0._uid)) != null ) t0=tu;
757 while( (tu = (T)
UF.get(t ._uid)) != null ) { assert t._uid != t0._uid;
UF.put(t._uid,t0); t=tu; }
760 private static <T extends Type> T
union( T lost, T kept) {
761 if( lost == kept )
return kept;
762 assert lost._hash==0 || !lost.interned();
763 assert
UF.get(lost._uid)==
null &&
UF.get(kept._uid)==
null;
764 assert lost._uid != kept._uid;
765 UF.put(lost._uid,kept);
771 for(
Type t : reachs )
772 if( t.intern_lookup() !=
null )
783 while( idx < work.
_len ) {
797 if( (y==TMEMPTR || y==TFUNPTR || y==TSTRUCT || y==TFLD) &&
806 HashMap<Type,Type> ss =
new HashMap<>();
807 for(
Type t : reaches ) {
809 if( ss.get(t) !=
null ||
831 while( i >= 0 && stack.
at(i)!=t ) i--;
832 if( i== -1 )
return bcs;
833 for( ; i < stack.
_len; i++ )
834 bcs.set(stack.
at(i)._uid);
848 @SuppressWarnings(
"unchecked")
850 for(
Type t : reaches ) {
851 if( bcs.get(t._uid) ) {
852 assert t.intern_lookup()==
null;
879 HashMap<BitsAlias,TypeMemPtr> dull_cache =
new HashMap<>();
880 _dull(mem,dull,dull_cache);
884 assert sharp.
interned() == dull_cache.isEmpty();
886 if( dull_cache.isEmpty() )
898 return mem.
sharput(dull,sharp);
911 if( mem.
sharp_get(dull) !=
null )
return;
912 if( dull_cache.get(dull.
_aliases) !=
null )
return;
913 if( dull==NO_DISP || dull==NO_DISP.
dual() ) { mem.
sharput(dull,dull);
return; }
965 if( sharp !=
null )
return sharp;
973 dull_cache.put(dull.
_aliases,dptr2);
975 for(
int i=0; i<dts2.
_flds.length; i++ ) {
995 for(
int i=0; i<dts2.
_flds.length; i++ )
1004 if(
this==t2 )
return this;
1005 if( !(t2 instanceof
TypeStruct) )
return meet(t2);
1048 if( idx == -1 )
return this;
1062 for(
int i=0; i<
_flds.length; i++ )
1071 if( idx == -1 )
return UNUSED;
1073 for(
int i=0; i<
_flds.length; i++ ) {
1093 if(
_any )
return this;
1098 for(
int i=1; i<
_flds.length; i++ ) {
1108 boolean widen=
false;
1111 {
widen=
true;
break; }
1112 if( !
widen )
return this;
1114 for(
int i=0; i<
_flds.length; i++ )
1121 if( isa(t) )
return 0;
1122 if( t.
isa(
this) )
return 0;
1129 if( bs==
null ) bs=
new VBitSet();
1130 if( bs.
tset(_uid) )
return false;
1135 @Override
public void walk( Predicate<Type> p ) {
1142 if( visit.
tset(_uid) )
return null;
1144 for(
int i=0; i<
flds.length; i++ )
static TypeStruct ax_impl_struct(int alias, boolean isnews, int cutoff, Ary< TypeStruct > cutoffs, int d, TypeStruct dold, TypeStruct old)
static TypeMemPtr ax_impl_ptr(int alias, int cutoff, Ary< TypeStruct > cutoffs, int d, TypeStruct dold, TypeMemPtr old)
boolean tset(int b0, int b1)
static TypeMemPtr sharpen(TypeMem mem, TypeMemPtr dull)
void push(Ary< Type > work, Type t)
static final Type NO_DISP
static boolean check_uf(Ary< Type > reaches)
int len0(TypeStruct tmax)
TypeStruct repeats_in_cycles()
static TypeStruct make(Type... ts)
static TypeFld make_tup(Type t, int order)
E push(E e)
Add element in amortized constant time.
TypeMemPtr sharp_get(TypeMemPtr tmp)
Memory type; the state of all of memory; memory edges order memory ops.
static boolean eq(String s0, String s1)
static final NonBlockingHashMapLong< Type > UF
static final Type XSCALAR
static< T extends Type > T ufind(T t)
TypeStruct make_from(Type head, TypeMem mem, VBitSet visit)
static Type ax_meet(BitSetSparse bs, Type nt, Type old)
an implementation of language AA
static final TypeStruct ALLSTRUCT
static final TypeStruct POINT
static final TypeStruct TFLT64
static final TypeStruct A
static final TypeFld NO_DISP
static TypeFld[] copyOf(TypeFld[] flds, int len)
boolean cycle_equals(Type o)
static TypeFld cmeet(TypeFld f0, TypeFld f1)
TypeStruct make_from(TypeFld[] flds)
TypeStruct install_cyclic(Ary< Type > reachs)
TypeStruct hashcons_freeS()
A memory-based collection of optionally named fields.
static TypeFld make(String fld, Type t, int order)
static RuntimeException unimpl()
static boolean test(long[] bits, int i)
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
boolean cycle_equals(Type t)
static int next_kid(int alias, int kid)
static final TypeStruct INT64_INT64
static final TypeInt INT64
static boolean _is_sharp(Type t)
static final String fldBot
TypeObj remove_other_flds(String fld, Type live)
static final IHashMap OLD2APX
static final TypeStruct DISPLAY
static final TypeObj XOBJ
TypeStruct repeats_in_cycles(TypeStruct head, VBitSet bs)
final boolean contains(Type t)
TypeStruct init(String name, boolean any, TypeFld[] flds, boolean open)
static final TypeObj UNUSED
static boolean post_mod(Type t)
static TypeMemPtr _sharp(TypeMem mem, TypeMemPtr dull, HashMap< BitsAlias, TypeMemPtr > dull_cache)
static boolean isDigit(char c)
static final TypeObj ISUSED
static final String fldTop
static TypeFld[] flds(Type t1, Type t2)
static final IHashMap DUPS
static TypeStruct open(Type tdisp)
static TypeFld[] flds(Type t1)
boolean contains(Type t, VBitSet bs)
static final TypeStruct ARW
TPair(TypeStruct ts0, TypeStruct ts1)
static TypeFld[] tups(Type t1, Type t2)
TypeFunPtr _sharpen_clone(TypeMemPtr disp)
static TypeStruct make(String name, boolean any, TypeFld[] flds, boolean open)
Tight/tiny StringBuilder wrapper.
static final TypeStruct FLT64
void walk(Predicate< Type > p)
static Type ax_impl_fptr(int alias, int cutoff, Ary< TypeStruct > cutoffs, int d, TypeStruct dold, TypeFunPtr old)
void walk(Predicate< Type > p)
TypeStruct update(Access fin, String fld, Type val, boolean precise)
an implementation of language AA
static final TypeStruct D1
TypeStruct approx(int cutoff, int alias)
TypeStruct set_fld(int i, Type t, Access ff)
static TypeFld[] clone(TypeFld[] ts)
TypeStruct make_from(String name)
TypeStruct add_fld(String name, Access mutable, Type tfld)
boolean cycle_equals0(TypeStruct t)
static final TypeStruct C0
static boolean check_interned(Ary< Type > reachs)
static TypeStruct make(String fld_name, Type t, Access a)
TypeStruct xmeet1(TypeStruct tmax, boolean is_loop)
static final TypeStruct[] TYPES
TypeStruct make_from_flds(TypeStruct ts)
void mark_cyclic(BitSet bcs, Ary< Type > reaches)
TypeStruct add_fld(String name, Access mutable)
static TypeFld[] hash_cons(TypeFld[] ts)
TypeMemPtr sharput(TypeMemPtr dull, TypeMemPtr sharp)
static TypeStruct make(String fld_name, Type t)
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with primitive long ke...
static TypeStruct shrink(Ary< Type > reaches, TypeStruct tstart)
Type ax_meet_nil(Type nil)
static TypeStruct malloc(String name, boolean any, TypeFld[] flds, boolean open)
int find(E e)
Find the first matching element using ==, or -1 if none.
Type ax_meet_nil(Type nil)
static final TypeInt TRUE
static final TypeStruct NAMEPT
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
static BitSet get_cyclic(BitSet bcs, VBitSet bs, Ary< Type > stack, Type t)
TypeStruct cyclic_meet(TypeStruct that)
static TypeFld make_arg(Type t, int order)
static final TypeStruct ANYSTRUCT
static int fld_find(TypeFld[] flds, String fld)
static TypeFld[] ts(TypeFld t0)
static void _dull(TypeMem mem, TypeMemPtr dull, HashMap< BitsAlias, TypeMemPtr > dull_cache)
TypeMemPtr make_from(TypeObj obj)
static TypeFld[] tups(Type t1, Type t2, Type t3)
static final Ary< TypeStruct > CYCLES
static final TypeFlt FLT64
static TypeStruct make(TypeFld... flds)
TypeStruct update(Access fin, String fld, Type val)
TypeFunPtr make_from(TypeMemPtr disp)
static final HashMap< TPair, TypeStruct > MEETS0
static TPair set(TypeStruct ts0, TypeStruct ts1)