Go to the documentation of this file. 1 package com.cliffc.aa.tvar;
9 import org.jetbrains.annotations.
NotNull;
25 private static int UID=1;
60 static private final HashMap<String,ACnts>
ALLOCS =
new HashMap<>();
90 if(
_args==
null )
return null;
92 if( tv==
null )
return null;
110 return old.
unify(tv2,test);
111 if( test )
return true;
131 TV2 tv2 =
new TV2(
"Leaf",
null,
null,ns,alloc_site);
137 if( type instanceof
TypeObj ) {
138 return make(
"Obj",n,alloc_site);
142 TV2 tv2 =
new TV2(
"Base",
null,type,ns,alloc_site);
166 for(
int i=0; i<ntvs.length; i++ )
168 args.
put(i,ntvs[i].tvar());
169 return make(
name,n,alloc_site,args);
180 public static TV2 DEAD =
new TV2(
"Dead",
null,
null,
null,
"static");
181 public static TV2 NIL =
new TV2(
"Nil" ,
null,
null,
null,
"static");
200 public final boolean eq(
TV2 that ) {
201 if( that==
null )
return false;
202 assert
VARS.isEmpty() &&
DUPS.isEmpty();
203 boolean eq =
_eq(that);
208 if(
this==that )
return true;
213 TV2 eq2 =
VARS.computeIfAbsent(
this,k -> that);
217 if(
_args.size() != that.
_args.size() )
return false;
219 long luid = ((long)
_uid<<32)|that.
_uid;
220 if(
DUPS.get(luid)!=null )
return true;
225 if( !
get(key)._eq(that.
get(key)) )
232 for(
int i=0; i<args.length; i++ )
233 if( args[i]!=
null && args[i].tvar()!=
get(i) )
249 while( v != top ) v = v.
_union(top);
255 public boolean union(
TV2 that) {
256 if(
this==that )
return true;
261 if(
_ns!=
null && that._ns!=
null &&
_ns.
size()==1 ) {
302 if(
this==that )
return false;
306 if( this.
is_nil () )
return false;
307 if( that.
is_nil () )
return false;
309 if( test )
return true;
312 if( that.
is_dead() )
return this.
union(that);
316 if( that.
is_err() )
return union(that);
319 if( this.
is_leaf() )
return this.
union(that);
325 long luid = ((long)
_uid<<32)|that.
_uid;
327 if( rez!=
null )
return false;
332 return union_err(that,
"Cannot unify "+
this+
" and "+that);
338 TV2 vthis =
get(key); assert vthis!=
null;
339 TV2 vthat = that.
get(key);
340 if( vthat==
null ) that.
args_put(key,vthis);
341 else { vthis.
_unify(vthat,test); that = that.
find(); }
359 if( con==that.
_type )
return false;
360 if( !test ) that.
_type = con;
366 private static final HashMap<TV2,TV2>
VARS =
new HashMap<>();
388 if(
this==that )
return false;
389 if( that.
is_dead() )
return false;
416 boolean progress =
vput(that,
false);
418 TV2 lhs =
get(key); assert lhs!=
null;
429 if( progress && test )
return true;
434 private boolean vput(
TV2 that,
boolean progress) {
VARS.put(
this,that);
return progress; }
442 if( t!=
null )
return t;
462 assert
VARS.isEmpty() &&
DUPS.isEmpty();
469 if(
DUPS.get(
_uid) !=
null )
return;
471 if(
this==tv )
return;
472 assert tv.
_ns==
null && tv.
_deps==
null;
477 _args.get(key)._rename(tv.
get(key),map);
491 boolean progress=
false;
492 for(
int alias : aliases ) {
496 TV2 tobj =
get(alias);
498 if( test )
return true;
500 TV2 tvo =
make(
"Obj",ldst,alloc_site);
503 }
else if( tobj.
isa(
"Obj") ) {
505 }
else if( tobj.
is_dead() || tobj.
isa(
"Err") ) {
509 if( progress && test )
return progress;
516 if(
this==mem )
return false;
518 boolean progress =
false;
520 for(
int alias : aliases ) {
522 if( tv==
null )
continue;
523 if( tobj==
null ) tobj=tv;
524 else assert tobj==tv;
525 progress |=
unify_at(alias,tv,test);
526 if( progress && test )
return true;
536 assert
DUPS.isEmpty();
580 for(
int i=0; i<tt.
len(); i++ )
581 rez =
get(i)._find_tvar(tt.
at(i),tv,rez);
600 if( vs==
null )
return false;
601 assert
ODUPS.isEmpty();
621 if( x==
this )
return true;
633 return vs[i]==tv ? tv : (vs[i]=tv);
639 static private final HashMap<TV2,TV2>
CDUPS =
new HashMap<>();
641 assert
CDUPS.isEmpty();
648 if(
this==that )
return true;
654 if(
_args.size() != that.
_args.size() )
return false;
659 CDUPS.put(
this,that);
661 TV2 lhs =
get(key); assert lhs!=
null;
684 if(
isa(
"Dead") )
return;
705 return str(
new SB(),bs.
clr(),dups,
true,0,0).toString();
707 public final String
str(
int d) {
711 return str(
new SB(),bs.
clr(),dups,
true,0,d).toString();
724 dups.
put(
_uid,
new String(
new char[]{(char)(
'A'+scnt)}));
732 scnt = tv.find_dups(bs,dups,scnt);
737 @SuppressWarnings(
"unchecked")
739 if(
is_dead() )
return sb.p(
"Dead");
740 if(
is_nil() )
return sb.p(
"Nil" );
743 String stv = dups.get(
_uid);
746 if( bs.tset(
_uid) )
return sb;
751 if( debug ) sb.p(
"V").p(
_uid).p(
">>");
759 if( !tn.is_dead() ) {
760 sb.p(
'N').p(tn._uid).p(
':');
765 if(
is_prim() )
return sb.p(
":PRIMS");
768 if(
_args !=
null ) {
769 final int min = Math.min(d+1,max);
773 if( d < max ) sb.nl().i(min);
775 if( args==
null ) sb.p(
"Args");
776 else args.
str(sb,bs,dups,debug,d+1,max);
777 if( d < max ) sb.nl().i(min);
779 if( d < max ) sb.nl().i(min);
781 if( ret ==
null ) sb.p(
"Ret" );
782 else ret .
str(sb,bs,dups,debug,d+1,max);
783 if( d < max ) sb.nl().i(d);
791 if( x==
"^" )
return -1;
792 if( y==
"^" )
return -1;
793 return x.compareTo(y);
796 if( d < max ) sb.nl().i(min);
797 sb.p(key.toString()).p(
':');
798 _args.get(key).str(sb,bs,dups,debug,d+1,max);
801 if( d < max ) sb.nl().i(d);
NonBlockingHashMap< Comparable, TV2 > _args
boolean unify_at(Comparable key, TV2 tv2, boolean test)
static final VBitSet DEPS_VISIT
boolean unify(TV2 that, boolean test)
boolean _unify(TV2 that, boolean test)
static TV2 make_base(Node n, Type type, @NotNull String alloc_site)
boolean _cycle_equals(TV2 that)
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with better scaling pr...
static final HashMap< String, ACnts > ALLOCS
Memory type; the state of all of memory; memory edges order memory ops.
static boolean eq(String s0, String s1)
static final VBitSet ODUPS
void args_put(Comparable key, TV2 tv)
an implementation of language AA
boolean vput(TV2 that, boolean progress)
UQNodes addAll(UQNodes uq)
boolean union_err(TV2 that, String msg)
int size()
Returns the number of key-value mappings in this map.
static final NonBlockingHashMapLong< TV2 > DUPS
A memory-based collection of optionally named fields.
static RuntimeException unimpl()
static TV2 make_leaf_ns(UQNodes ns, @NotNull String alloc_site)
TV2 push_dep(CallEpiNode dep)
static void reset_to_init0()
boolean _occurs_in_type(TV2 x)
static TV2 make(@NotNull String name, Node n, @NotNull String alloc_site)
boolean unify_alias_fld(Node ldst, BitsAlias aliases, String fld, TV2 tv, boolean test, String alloc_site)
void _rename(TV2 tv, HashMap< Node, Node > map)
TV2(@NotNull String name, NonBlockingHashMap< Comparable, TV2 > args, Type type, UQNodes ns, @NotNull String alloc_site)
static final HashMap< TV2, TV2 > CDUPS
boolean occurs_in(TV2[] vs)
final TypeV get(long key)
Returns the value to which the specified key is mapped, or.
static TV2 make(@NotNull String name, Node n, @NotNull String alloc_site, NonBlockingHashMap< Comparable, TV2 > args)
final boolean eq(TV2 that)
boolean unify_alias(BitsAlias aliases, TV2 mem, boolean test)
static final TypeObj UNUSED
static TV2 make_mem(Node n, @NotNull String alloc_site)
boolean cycle_equals(TV2 that)
void merge_deps(TV2 that)
static final TypeObj ISUSED
static TV2 make_leaf(Node n, @NotNull String alloc_site)
TypeV put(TypeK key, TypeV val)
Maps the specified key to the specified value in the table.
static TypeStr con(String con)
boolean _fresh_unify(TV2 that, TV2[] vs, boolean test)
final int find_dups(VBitSet bs, NonBlockingHashMapLong< String > dups, int scnt)
static UQNodes make(Node tn)
UQNodes rename(HashMap< Node, Node > map)
Type find_tvar(Type t, TV2 tv)
boolean _occurs_in(TV2[] vs)
boolean unify_base(TV2 that)
static TV2 make(@NotNull String name, Node n, @NotNull String alloc_site, Node... ntvs)
Tight/tiny StringBuilder wrapper.
an implementation of language AA
void _push_update(CallEpiNode dep)
boolean containsKey(long key)
Tests if the key in the table.
static TV2 make_err(Node n, String msg, @NotNull String alloc_site)
void sort_update(Comparator<? super E > c)
Sorts in-place.
public< N extends Node > N add_reduce(N n)
TV2 repl_rename(TV2[]vs, HashMap< Node, Node > map)
A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with primitive long ke...
static TV2 make(@NotNull String name, UQNodes ns, @NotNull String alloc_site)
boolean fresh_base(TV2 that, boolean test)
TypeV put(long key, TypeV val)
Maps the specified key to the specified value in the table.
public< N extends Node > N add_flow(N n)
boolean fresh_unify(TV2 that, TV2[] vs, boolean test)
Type _find_tvar(Type t, TV2 tv, Type rez)
Collection< TypeV > values()
Returns a Collection view of the values contained in this map.
TypeV remove(long key)
Removes the key (and its corresponding value) from this map.
static final HashMap< TV2, TV2 > VARS