aa
com.cliffc.aa.HM.HM4.T2 Class Reference
Collaboration diagram for com.cliffc.aa.HM.HM4.T2:
[legend]

Public Member Functions

String p ()
 
String toString ()
 

Package Functions

boolean _cycle_equals (T2 t)
 
VBitSet _get_dups (VBitSet visit, VBitSet dups)
 
T2 _repl (HashMap< T2, T2 > vars, HashMap< T2, T2 > dups)
 
boolean cycle_equals (T2 t)
 
T2 find ()
 
T2 find (int i)
 
VBitSet get_dups (VBitSet dups)
 
T2 get_fresh ()
 
boolean is_base ()
 
boolean is_fresh ()
 
boolean is_leaf ()
 
boolean is_tvar ()
 
void live (IBitSet visit)
 
boolean no_uf ()
 
String p (VBitSet dups)
 
boolean progress (T2 t)
 
void push_update (Syntax a)
 
T2 repl (HashMap< T2, T2 > vars, HashMap< T2, T2 > dups)
 
SB str (SB sb, VBitSet visit, VBitSet dups)
 
T2 unify (T2 t, Ary< Syntax > work)
 
T2 union (T2 that, Ary< Syntax > work)
 

Static Package Functions

static T2 base (Type con)
 
static T2 fresh (String name, T2 t)
 
static T2 fun (T2... args)
 
static T2 prim (String name, T2... args)
 
static void reset ()
 
static T2 tnew ()
 

Package Attributes

T2[] _args
 
Type _con
 
String _fresh
 
final String _name
 
final int _uid
 
Ary< Syntax_updates
 

Static Package Attributes

static final VBitSet UPDATE_VISIT = new VBitSet()
 

Private Member Functions

 T2 (@NotNull String name, T2 @NotNull ... args)
 
T2 _fresh_unify (HashMap< T2, T2 > vars, T2 t, Ary< Syntax > work)
 
T2 _fresh_unify_impl (HashMap< T2, T2 > vars, T2 t, Ary< Syntax > work)
 
SB _p (SB sb, VBitSet visit, VBitSet dups)
 
T2 _unify (T2 t, Ary< Syntax > work)
 
T2 fresh_base (T2 t)
 
void push_update_impl (Syntax a)
 
T2 unify_base (T2 t, Ary< Syntax > work)
 

Static Private Member Functions

static SB str (SB sb, VBitSet visit, T2 t, VBitSet dups)
 

Static Private Attributes

static final HashMap< T2, T2CDUPS = new HashMap<>()
 
static int CNT =0
 
static final HashMap< Long, T2DUPS = new HashMap<>()
 

Detailed Description

Definition at line 324 of file HM4.java.

Constructor & Destructor Documentation

◆ T2()

com.cliffc.aa.HM.HM4.T2.T2 ( @NotNull String  name,
T2 @NotNull ...  args 
)
private

Definition at line 355 of file HM4.java.

355 { _name = name; _args= args; _uid=CNT++; }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2._uid, and com.cliffc.aa.HM.HM4.T2.CNT.

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.fresh(), com.cliffc.aa.HM.HM4.T2.fun(), com.cliffc.aa.HM.HM4.T2.prim(), and com.cliffc.aa.HM.HM4.T2.tnew().

Here is the caller graph for this function:

Member Function Documentation

◆ _cycle_equals()

boolean com.cliffc.aa.HM.HM4.T2._cycle_equals ( T2  t)
package

Definition at line 558 of file HM4.java.

558  {
559  assert no_uf() && t.no_uf();
560  if( this==t ) return true;
561  if( !is_tvar() || !t.is_tvar() || // Base-cases have to be completely identical
562  !Util.eq(_name,t._name) || // Wrong type-var names
563  _args.length != t._args.length ) // Mismatched sizes
564  return false;
565  if( _args==t._args ) return true;
566  // Cycles stall the equal/unequal decision until we see a difference.
567  T2 tc = CDUPS.get(this);
568  if( tc!=null )
569  return tc==t; // Cycle check; true if both cycling the same
570  CDUPS.put(this,t);
571  for( int i=0; i<_args.length; i++ )
572  if( !find(i)._cycle_equals(t.find(i)) )
573  return false;
574  return true;
575  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2.CDUPS, com.cliffc.aa.util.Util.eq(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.is_tvar(), and com.cliffc.aa.HM.HM4.T2.no_uf().

Referenced by com.cliffc.aa.HM.HM4.T2.cycle_equals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _fresh_unify()

T2 com.cliffc.aa.HM.HM4.T2._fresh_unify ( HashMap< T2, T2 vars,
T2  t,
Ary< Syntax work 
)
private

Definition at line 477 of file HM4.java.

477  {
478  assert no_uf() && t.no_uf();
479  assert this!=t || is_base(); // No overlap between LHS and RHS.
480  T2 prior = vars.get(this);
481  if( prior!=null ) // Been there, done that? Return prior mapping
482  return prior.find().unify(t,work);
483  assert !is_fresh(); // recursive fresh?
484  T2 rez = _fresh_unify_impl( vars, t, work );
485  vars.put(this,rez);
486  return rez;
487  }

References com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.no_uf(), and com.cliffc.aa.HM.HM4.T2.unify().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), and com.cliffc.aa.HM.HM4.T2.unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _fresh_unify_impl()

T2 com.cliffc.aa.HM.HM4.T2._fresh_unify_impl ( HashMap< T2, T2 vars,
T2  t,
Ary< Syntax work 
)
private

Definition at line 489 of file HM4.java.

489  {
490  // RHS is also a lazy clone, which if cloned, will not be part of any
491  // other structure. When unioned with the clone of the LHS, the result
492  // is not part of anything direct... but the structures still have to
493  // align for the returned T2. Make a replica & unify (e.g. stop being lazy).
494  if( t.is_fresh() ) t = t.get_fresh().repl(vars, new HashMap<>());
495 
496  if( is_base() && t.is_base() ) return fresh_base(t);
497  if( is_leaf() ) return t; // Lazy map LHS tvar to RHS
498  if( t.is_leaf() ) return t.union(repl(vars, new HashMap<>()),work); // RHS is a tvar; union with a copy of LHS
499 
500  if( !Util.eq(_name,t._name) )
501  throw com.cliffc.aa.AA.unimpl(); // unification error
502  if( _args.length != t._args.length )
503  throw new RuntimeException("Cannot unify "+this+" and "+t);
504  // Structural recursion unification, lazy on LHS
505  T2[] args = new T2[_args.length];
506  for( int i=0; i<_args.length; i++ )
507  args[i] = find(i)._fresh_unify(vars,t.find(i),work);
508 
509  return new T2(_name,args);
510  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.util.Util.eq(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.fresh_base(), com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.repl(), com.cliffc.aa.HM.HM4.T2.T2(), com.cliffc.aa.AA.unimpl(), and com.cliffc.aa.HM.HM4.T2.union().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _get_dups()

VBitSet com.cliffc.aa.HM.HM4.T2._get_dups ( VBitSet  visit,
VBitSet  dups 
)
package

Definition at line 600 of file HM4.java.

600  {
601  if( visit.tset(_uid) && no_uf() ) dups.set(_uid);
602  else
603  for( T2 t : _args )
604  if( t!=null )
605  t._get_dups(visit,dups);
606  return dups;
607  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._uid, com.cliffc.aa.HM.HM4.T2.no_uf(), and com.cliffc.aa.util.VBitSet.tset().

Referenced by com.cliffc.aa.HM.HM4.T2.get_dups().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _p()

SB com.cliffc.aa.HM.HM4.T2._p ( SB  sb,
VBitSet  visit,
VBitSet  dups 
)
private

Definition at line 639 of file HM4.java.

639  {
640  assert no_uf();
641  if( is_fresh() ) return get_fresh()._p(sb.p('#'),visit,dups);
642  if( is_base() ) return sb.p(_con instanceof TypeMemPtr ? "str" : _con.toString() );
643  if( is_leaf() ) return sb.p(_name);
644  boolean dup = dups.get(_uid);
645  if( dup ) sb.p('$').p(_uid);
646  if( visit.tset(_uid) && dup ) return sb;
647  if( dup ) sb.p(':');
648  if( _name.equals("->") ) {
649  sb.p("{ ");
650  for( int i=0; i<_args.length-1; i++ )
651  find(i)._p(sb,visit,dups).p(" ");
652  return find(_args.length-1)._p(sb.p("-> "),visit,dups).p(" }");
653  }
654  // Generic structural T2
655  sb.p("(").p(_name).p(" ");
656  for( int i=0; i<_args.length; i++ ) find(i)._p(sb,visit,dups).p(" ");
657  return sb.unchar().p(")");
658  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._con, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2._uid, com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.no_uf(), com.cliffc.aa.util.SB.p(), com.cliffc.aa.type.Type< T extends Type< T >.toString(), com.cliffc.aa.util.VBitSet.tset(), and com.cliffc.aa.util.SB.unchar().

Referenced by com.cliffc.aa.HM.HM4.T2._p(), and com.cliffc.aa.HM.HM4.T2.p().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _repl()

T2 com.cliffc.aa.HM.HM4.T2._repl ( HashMap< T2, T2 vars,
HashMap< T2, T2 dups 
)
package

Definition at line 521 of file HM4.java.

521  {
522  if( is_leaf() ) return tnew(); // LHS is a leaf, make a new one for RHS
523 
524  // Must replicate base's, because they are not really immutable:
525  // mismatched Types meet instead of error.
526  if( is_base() ) return base(_con);
527  T2[] args = new T2[_args.length];
528  T2 rez = new T2(_name,args);
529  vars.put(this,rez); // Insert in dups BEFORE structural recursion, to stop cycles
530  // Structural recursion replicate
531  for( int i=0; i<_args.length; i++ )
532  args[i] = find(i).repl(vars,dups);
533  return rez;
534  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._con, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2.base(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.repl(), com.cliffc.aa.HM.HM4.T2.T2(), and com.cliffc.aa.HM.HM4.T2.tnew().

Referenced by com.cliffc.aa.HM.HM4.T2.repl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _unify()

T2 com.cliffc.aa.HM.HM4.T2._unify ( T2  t,
Ary< Syntax work 
)
private

Definition at line 431 of file HM4.java.

431  {
432  assert no_uf() && t.no_uf();
433  if( this==t ) return this;
434  if( is_fresh() ) throw com.cliffc.aa.AA.unimpl(); // recursive fresh?
435  if( t.is_fresh() ) throw com.cliffc.aa.AA.unimpl(); // RHS is fresh?
436 
437  if( is_base() && t.is_base() ) return unify_base(t,work);
438  // two leafs union in either order, so keep lower uid
439  if( is_leaf() && t.is_leaf() && _uid<t._uid ) return t.union(this,work);
440  if( is_leaf() ) return union(t ,work);
441  if( t.is_leaf() ) return t.union(this,work);
442 
443  if( !Util.eq(_name,t._name) )
444  throw new RuntimeException("Cannot unify "+this+" and "+t);
445  if( _args==t._args ) return this; // Names are equal, args are equal
446  if( _args.length != t._args.length )
447  throw new RuntimeException("Cannot unify "+this+" and "+t);
448 
449  // Cycle check.
450  long luid = ((long)_uid<<32)|t._uid;
451  T2 rez = DUPS.get(luid), rez2;
452  if( rez!=null ) return rez; // Been there, done that
453  T2[] args = new T2[_args.length];
454  rez = rez2 = new T2(_name,args);
455  DUPS.put(luid,rez); // Close cycles
456 
457  // Structural recursion unification.
458  for( int i=0; i<_args.length; i++ )
459  args[i] = find(i)._unify(t.find(i),work);
460 
461  // Check for being equal, cyclic-ly, and return a prior if possible.
462  boolean eq0 = rez.cycle_equals(this);
463  boolean eq1 = rez.cycle_equals(t );
464  if( eq0 ) rez2 = this;
465  if( eq1 ) rez2 = t ;
466  if( eq0 && eq1 ) rez2 = _uid < t._uid ? this : t;
467  if( rez!=rez2 ) DUPS.put(luid,rez2);
468  // Return new unified T2
469  return rez2;
470  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2._uid, com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.cycle_equals(), com.cliffc.aa.HM.HM4.T2.DUPS, com.cliffc.aa.util.Util.eq(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.no_uf(), com.cliffc.aa.HM.HM4.T2.T2(), com.cliffc.aa.HM.HM4.T2.unify_base(), com.cliffc.aa.AA.unimpl(), and com.cliffc.aa.HM.HM4.T2.union().

Referenced by com.cliffc.aa.HM.HM4.T2._unify(), and com.cliffc.aa.HM.HM4.T2.unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ base()

static T2 com.cliffc.aa.HM.HM4.T2.base ( Type  con)
staticpackage

Definition at line 345 of file HM4.java.

345 { T2 t = tnew(); t._con=con; return t; }

References com.cliffc.aa.HM.HM4.T2._con, and com.cliffc.aa.HM.HM4.T2.tnew().

Referenced by com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.hm(), and com.cliffc.aa.HM.HM4.Con.prep_tree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycle_equals()

boolean com.cliffc.aa.HM.HM4.T2.cycle_equals ( T2  t)
package

Definition at line 552 of file HM4.java.

552  {
553  assert CDUPS.isEmpty();
554  boolean rez = _cycle_equals(t);
555  CDUPS.clear();
556  return rez;
557  }

References com.cliffc.aa.HM.HM4.T2._cycle_equals(), and com.cliffc.aa.HM.HM4.T2.CDUPS.

Referenced by com.cliffc.aa.HM.HM4.T2._unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/2]

T2 com.cliffc.aa.HM.HM4.T2.find ( )
package

Definition at line 378 of file HM4.java.

378  {
379  if( is_tvar() ) return this; // Shortcut
380  T2 u = _args[0];
381  if( u==null ) return this; // Shortcut
382  if( u.no_uf() ) return u; // Shortcut
383  // U-F fixup
384  while( !u.is_tvar() && u._args[0]!=null ) u = u._args[0];
385  T2 v = this, v2;
386  while( !v.is_tvar() && (v2=v._args[0])!=u ) { v._args[0]=u; v = v2; }
387  return u;
388  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2.is_tvar(), and com.cliffc.aa.HM.HM4.T2.no_uf().

Referenced by com.cliffc.aa.HM.HM4.T2._cycle_equals(), com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.Syntax.find(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.Apply.hm(), com.cliffc.aa.HM.HM4.T2.p(), com.cliffc.aa.HM.HM4.T2.progress(), com.cliffc.aa.HM.HM4.T2.push_update_impl(), com.cliffc.aa.HM.HM4.Lambda.targ(), com.cliffc.aa.HM.HM4.Let.targ(), com.cliffc.aa.HM.HM4.Lambda2.targ0(), and com.cliffc.aa.HM.HM4.Lambda2.targ1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [2/2]

T2 com.cliffc.aa.HM.HM4.T2.find ( int  i)
package

Definition at line 390 of file HM4.java.

390  {
391  T2 u = _args[i];
392  T2 uu = u.find();
393  return u==uu ? uu : (_args[i]=uu);
394  }

References com.cliffc.aa.HM.HM4.T2._args, and com.cliffc.aa.HM.HM4.T2.find().

Here is the call graph for this function:

◆ fresh()

static T2 com.cliffc.aa.HM.HM4.T2.fresh ( String  name,
T2  t 
)
staticpackage

Definition at line 347 of file HM4.java.

347  {
348  assert !t.is_fresh();
349  T2 t2 = new T2(name,t); // Points to non-fresh
350  t2._fresh=name;
351  assert t2.is_fresh();
352  return t2;
353  }

References com.cliffc.aa.HM.HM4.T2._fresh, com.cliffc.aa.HM.HM4.T2.is_fresh(), and com.cliffc.aa.HM.HM4.T2.T2().

Referenced by com.cliffc.aa.HM.HM4.hm(), and com.cliffc.aa.HM.HM4.Let.prep_tree_lookup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fresh_base()

T2 com.cliffc.aa.HM.HM4.T2.fresh_base ( T2  t)
private

Definition at line 472 of file HM4.java.

472 { t._con = _con.meet(t._con); return t; }

References com.cliffc.aa.HM.HM4.T2._con, and com.cliffc.aa.type.Type< T extends Type< T >.meet().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), and com.cliffc.aa.HM.HM4.T2.unify_base().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fun()

static T2 com.cliffc.aa.HM.HM4.T2.fun ( T2...  args)
staticpackage

Definition at line 343 of file HM4.java.

343 { return new T2("->",args); }

References com.cliffc.aa.HM.HM4.T2.T2().

Referenced by com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.hm(), com.cliffc.aa.HM.HM4.Lambda.hm(), com.cliffc.aa.HM.HM4.Lambda2.hm(), and com.cliffc.aa.HM.HM4.Apply.hm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_dups()

VBitSet com.cliffc.aa.HM.HM4.T2.get_dups ( VBitSet  dups)
package

Definition at line 599 of file HM4.java.

599 { return _get_dups(new VBitSet(),dups); }

References com.cliffc.aa.HM.HM4.T2._get_dups().

Referenced by com.cliffc.aa.HM.HM4.T2.p(), com.cliffc.aa.HM.HM4.Syntax.p0(), and com.cliffc.aa.HM.HM4.T2.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_fresh()

T2 com.cliffc.aa.HM.HM4.T2.get_fresh ( )
package

Definition at line 365 of file HM4.java.

365  {
366  assert is_fresh();
367  T2 fun = find(0);
368  assert Util.eq(fun._name,"->");
369  return fun;
370  }

References com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.util.Util.eq(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.fun(), and com.cliffc.aa.HM.HM4.T2.is_fresh().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.Apply.hm(), com.cliffc.aa.HM.HM4.T2.progress(), and com.cliffc.aa.HM.HM4.T2.unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_base()

boolean com.cliffc.aa.HM.HM4.T2.is_base ( )
package

Definition at line 362 of file HM4.java.

362 { return _con!=null; }

References com.cliffc.aa.HM.HM4.T2._con.

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.progress(), com.cliffc.aa.HM.HM4.T2.push_update_impl(), and com.cliffc.aa.HM.HM4.T2.str().

Here is the caller graph for this function:

◆ is_fresh()

boolean com.cliffc.aa.HM.HM4.T2.is_fresh ( )
package

◆ is_leaf()

boolean com.cliffc.aa.HM.HM4.T2.is_leaf ( )
package

Definition at line 360 of file HM4.java.

360 { return _name.charAt(0)=='V' && !is_base(); }

References com.cliffc.aa.HM.HM4.T2._name, and com.cliffc.aa.HM.HM4.T2.is_base().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.progress(), com.cliffc.aa.HM.HM4.T2.push_update_impl(), and com.cliffc.aa.HM.HM4.T2.str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_tvar()

boolean com.cliffc.aa.HM.HM4.T2.is_tvar ( )
package

Definition at line 364 of file HM4.java.

364 { return _name.charAt(0)!='V' && _con==null; }

References com.cliffc.aa.HM.HM4.T2._con, and com.cliffc.aa.HM.HM4.T2._name.

Referenced by com.cliffc.aa.HM.HM4.T2._cycle_equals(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.no_uf(), and com.cliffc.aa.HM.HM4.T2.push_update_impl().

Here is the caller graph for this function:

◆ live()

void com.cliffc.aa.HM.HM4.T2.live ( IBitSet  visit)
package

Definition at line 372 of file HM4.java.

372  {
373  if( visit.set(_uid) ) return;
374  for( T2 t : _args ) if( t!=null ) t.live(visit);
375  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._uid, and com.cliffc.aa.util.IBitSet.set().

Referenced by com.cliffc.aa.HM.HM4.Con.live(), com.cliffc.aa.HM.HM4.Ident.live(), com.cliffc.aa.HM.HM4.Lambda.live(), com.cliffc.aa.HM.HM4.Lambda2.live(), com.cliffc.aa.HM.HM4.Let.live(), and com.cliffc.aa.HM.HM4.Apply.live().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ no_uf()

boolean com.cliffc.aa.HM.HM4.T2.no_uf ( )
package

Definition at line 395 of file HM4.java.

395 { return is_tvar() || _args[0]==null; }

References com.cliffc.aa.HM.HM4.T2._args, and com.cliffc.aa.HM.HM4.T2.is_tvar().

Referenced by com.cliffc.aa.HM.HM4.T2._cycle_equals(), com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.T2._get_dups(), com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.progress(), com.cliffc.aa.HM.HM4.T2.push_update_impl(), com.cliffc.aa.HM.HM4.T2.repl(), and com.cliffc.aa.HM.HM4.T2.unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ p() [1/2]

String com.cliffc.aa.HM.HM4.T2.p ( )

Definition at line 637 of file HM4.java.

637 { return p(get_dups(new VBitSet())); }

References com.cliffc.aa.HM.HM4.T2.get_dups(), and com.cliffc.aa.HM.HM4.T2.p().

Referenced by com.cliffc.aa.HM.HM4.T2.p().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ p() [2/2]

String com.cliffc.aa.HM.HM4.T2.p ( VBitSet  dups)
package

Definition at line 638 of file HM4.java.

638 { return find()._p(new SB(), new VBitSet(), dups).toString(); }

References com.cliffc.aa.HM.HM4.T2._p(), com.cliffc.aa.HM.HM4.T2.find(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ prim()

static T2 com.cliffc.aa.HM.HM4.T2.prim ( String  name,
T2...  args 
)
staticpackage

Definition at line 346 of file HM4.java.

346 { return new T2(name,args); }

References com.cliffc.aa.HM.HM4.T2.T2().

Referenced by com.cliffc.aa.HM.HM4.hm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress()

boolean com.cliffc.aa.HM.HM4.T2.progress ( T2  t)
package

Definition at line 537 of file HM4.java.

537  {
538  assert no_uf() && t.no_uf();
539  if( this==t ) return false;
540  if( t.is_leaf() ) return false; // will be equal after unify
541  if( is_base() && t.is_base() && _con==t._con ) return false;
542  if( is_fresh() ) return get_fresh().progress(t);
543  if( !Util.eq(_name,t._name) || _args.length!=t._args.length )
544  return true; // Blatantly not-equal
545  for( int i=0; i<_args.length; i++ )
546  if( find(i).progress(t.find(i)) )
547  return true; // Recursive progress
548  return false;
549  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._con, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.util.Util.eq(), com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.no_uf(), and com.cliffc.aa.HM.HM4.T2.progress().

Referenced by com.cliffc.aa.HM.HM4.hm(), and com.cliffc.aa.HM.HM4.T2.progress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_update()

void com.cliffc.aa.HM.HM4.T2.push_update ( Syntax  a)
package

Definition at line 582 of file HM4.java.

582 { UPDATE_VISIT.clear(); push_update_impl(a); }

References com.cliffc.aa.HM.HM4.T2.push_update_impl(), and com.cliffc.aa.HM.HM4.T2.UPDATE_VISIT.

Referenced by com.cliffc.aa.HM.HM4.Let.hm(), and com.cliffc.aa.HM.HM4.Apply.hm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_update_impl()

void com.cliffc.aa.HM.HM4.T2.push_update_impl ( Syntax  a)
private

Definition at line 583 of file HM4.java.

583  {
584  assert no_uf();
585  if( is_leaf() ) {
586  if( _updates==null ) _updates = new Ary<>(Syntax.class);
587  if( _updates.find(a)==-1 ) _updates.push(a);
588  } else if( is_tvar() ) {
589  if( UPDATE_VISIT.tset(_uid) ) return;
590  for( int i=0; i<_args.length; i++ )
591  find(i).push_update_impl(a);
592  } else assert is_base();
593  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._uid, com.cliffc.aa.HM.HM4.T2._updates, com.cliffc.aa.HM.HM4.T2.find(), com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.HM.HM4.T2.is_tvar(), com.cliffc.aa.HM.HM4.T2.no_uf(), com.cliffc.aa.HM.HM4.T2.push_update_impl(), com.cliffc.aa.util.VBitSet.tset(), and com.cliffc.aa.HM.HM4.T2.UPDATE_VISIT.

Referenced by com.cliffc.aa.HM.HM4.T2.push_update(), and com.cliffc.aa.HM.HM4.T2.push_update_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ repl()

T2 com.cliffc.aa.HM.HM4.T2.repl ( HashMap< T2, T2 vars,
HashMap< T2, T2 dups 
)
package

Definition at line 513 of file HM4.java.

513  {
514  assert no_uf() && !is_fresh();
515  T2 t = vars.get(this);
516  if( t!=null ) return t; // Been there, done that, return prior answer
517  T2 rez = _repl(vars,dups);
518  vars.put(this,rez);
519  return rez;
520  }

References com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2.is_fresh(), and com.cliffc.aa.HM.HM4.T2.no_uf().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), and com.cliffc.aa.HM.HM4.T2._repl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

static void com.cliffc.aa.HM.HM4.T2.reset ( )
staticpackage

Definition at line 325 of file HM4.java.

325 { CNT=0; }

References com.cliffc.aa.HM.HM4.T2.CNT.

Referenced by com.cliffc.aa.HM.HM4.reset().

Here is the caller graph for this function:

◆ str() [1/2]

static SB com.cliffc.aa.HM.HM4.T2.str ( SB  sb,
VBitSet  visit,
T2  t,
VBitSet  dups 
)
staticprivate

Definition at line 634 of file HM4.java.

634 { return t==null ? sb.p("_") : t.str(sb,visit,dups); }

References com.cliffc.aa.util.SB.p(), and com.cliffc.aa.HM.HM4.T2.str().

Here is the call graph for this function:

◆ str() [2/2]

SB com.cliffc.aa.HM.HM4.T2.str ( SB  sb,
VBitSet  visit,
VBitSet  dups 
)
package

Definition at line 612 of file HM4.java.

612  {
613  if( is_fresh() ) return _args[0].str(sb.p('#'),visit,dups);
614  if( is_leaf() || is_base() ) {
615  if( is_base() ) sb.p(_con instanceof TypeMemPtr ? "str" : _con.toString()); else sb.p(_name);
616  return _args[0]==null ? sb : _args[0].str(sb.p(">>"), visit, dups);
617  }
618  boolean dup = dups.get(_uid);
619  if( dup ) sb.p('$').p(_uid);
620  if( visit.tset(_uid) && dup ) return sb;
621  if( dup ) sb.p(':');
622 
623  if( _name.equals("->") ) {
624  sb.p("{ ");
625  for( int i=0; i<_args.length-1; i++ )
626  str(sb,visit,_args[i],dups).p(" ");
627  return str(sb.p("-> "),visit,_args[_args.length-1],dups).p(" }");
628  }
629  // Generic structural T2
630  sb.p("(").p(_name).p(" ");
631  for( T2 t : _args ) str(sb,visit,t,dups).p(" ");
632  return sb.unchar().p(")");
633  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._con, com.cliffc.aa.HM.HM4.T2._name, com.cliffc.aa.HM.HM4.T2._uid, com.cliffc.aa.HM.HM4.T2.is_base(), com.cliffc.aa.HM.HM4.T2.is_fresh(), com.cliffc.aa.HM.HM4.T2.is_leaf(), com.cliffc.aa.util.SB.p(), com.cliffc.aa.HM.HM4.T2.str(), com.cliffc.aa.type.Type< T extends Type< T >.toString(), com.cliffc.aa.util.VBitSet.tset(), and com.cliffc.aa.util.SB.unchar().

Referenced by com.cliffc.aa.HM.HM4.Syntax.p0(), com.cliffc.aa.HM.HM4.T2.str(), and com.cliffc.aa.HM.HM4.T2.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tnew()

static T2 com.cliffc.aa.HM.HM4.T2.tnew ( )
staticpackage

Definition at line 344 of file HM4.java.

344 { return new T2("V"+CNT,new T2[1]); }

References com.cliffc.aa.HM.HM4.T2.CNT, and com.cliffc.aa.HM.HM4.T2.T2().

Referenced by com.cliffc.aa.HM.HM4.T2._repl(), com.cliffc.aa.HM.HM4.T2.base(), com.cliffc.aa.HM.HM4.hm(), com.cliffc.aa.HM.HM4.Apply.hm(), com.cliffc.aa.HM.HM4.Lambda.Lambda(), com.cliffc.aa.HM.HM4.Lambda2.Lambda2(), com.cliffc.aa.HM.HM4.Let.Let(), com.cliffc.aa.HM.HM4.Lambda.prep_tree(), com.cliffc.aa.HM.HM4.Lambda2.prep_tree(), com.cliffc.aa.HM.HM4.Let.prep_tree(), and com.cliffc.aa.HM.HM4.Apply.prep_tree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

String com.cliffc.aa.HM.HM4.T2.toString ( )

Definition at line 611 of file HM4.java.

611 { return str(new SB(), new VBitSet(), get_dups(new VBitSet()) ).toString(); }

References com.cliffc.aa.HM.HM4.T2.get_dups(), com.cliffc.aa.HM.HM4.T2.str(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ unify()

T2 com.cliffc.aa.HM.HM4.T2.unify ( T2  t,
Ary< Syntax work 
)
package

Definition at line 415 of file HM4.java.

415  {
416  if( this==t ) return this;
417  assert no_uf() && t.no_uf();
418  assert !t.is_fresh(); // Only can lazy-clone LHS
419  if( is_fresh() ) // Peel off fresh lazy & do a fresh-unify
420  return get_fresh()._fresh_unify(new HashMap<>(),t,work);
421  // Normal unification, with side-effects
422  assert DUPS.isEmpty();
423  T2 rez = _unify(t,work);
424  DUPS.clear();
425  return rez;
426  }

References com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.T2._unify(), com.cliffc.aa.HM.HM4.T2.DUPS, com.cliffc.aa.HM.HM4.T2.get_fresh(), com.cliffc.aa.HM.HM4.T2.is_fresh(), and com.cliffc.aa.HM.HM4.T2.no_uf().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify(), com.cliffc.aa.HM.HM4.Lambda.hm(), com.cliffc.aa.HM.HM4.Lambda2.hm(), com.cliffc.aa.HM.HM4.Let.hm(), com.cliffc.aa.HM.HM4.Apply.hm(), and com.cliffc.aa.HM.HM4.Syntax.more_work_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unify_base()

T2 com.cliffc.aa.HM.HM4.T2.unify_base ( T2  t,
Ary< Syntax work 
)
private

Definition at line 473 of file HM4.java.

473 { return union(fresh_base(t),work); }

References com.cliffc.aa.HM.HM4.T2.fresh_base().

Referenced by com.cliffc.aa.HM.HM4.T2._unify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ union()

T2 com.cliffc.aa.HM.HM4.T2.union ( T2  that,
Ary< Syntax work 
)
package

Definition at line 399 of file HM4.java.

399  {
400  assert _args[0]==null; // Cannot union twice
401  if( this==that ) return this;
402  // Worklist: put updates on the worklist for revisiting
403  if( work!=null ) work.addAll(_updates); // Re-Apply
404  // Merge update lists, for future unions
405  if( _updates != null ) {
406  if( that._updates==null ) that._updates = _updates;
407  else throw com.cliffc.aa.AA.unimpl();
408  }
409  return (_args[0] = that);
410  }

References com.cliffc.aa.HM.HM4.T2._args, com.cliffc.aa.HM.HM4.T2._updates, and com.cliffc.aa.AA.unimpl().

Referenced by com.cliffc.aa.HM.HM4.T2._fresh_unify_impl(), and com.cliffc.aa.HM.HM4.T2._unify().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _args

◆ _con

◆ _fresh

String com.cliffc.aa.HM.HM4.T2._fresh
package

Definition at line 336 of file HM4.java.

Referenced by com.cliffc.aa.HM.HM4.T2.fresh(), and com.cliffc.aa.HM.HM4.T2.is_fresh().

◆ _name

◆ _uid

◆ _updates

Ary<Syntax> com.cliffc.aa.HM.HM4.T2._updates
package

◆ CDUPS

final HashMap<T2,T2> com.cliffc.aa.HM.HM4.T2.CDUPS = new HashMap<>()
staticprivate

◆ CNT

int com.cliffc.aa.HM.HM4.T2.CNT =0
staticprivate

◆ DUPS

final HashMap<Long,T2> com.cliffc.aa.HM.HM4.T2.DUPS = new HashMap<>()
staticprivate

Definition at line 430 of file HM4.java.

Referenced by com.cliffc.aa.HM.HM4.T2._unify(), and com.cliffc.aa.HM.HM4.T2.unify().

◆ UPDATE_VISIT

final VBitSet com.cliffc.aa.HM.HM4.T2.UPDATE_VISIT = new VBitSet()
staticpackage

The documentation for this class was generated from the following file:
com.cliffc.aa.HM.HM4.T2.base
static T2 base(Type con)
Definition: HM4.java:345
com.cliffc.aa.HM.HM4.T2.str
SB str(SB sb, VBitSet visit, VBitSet dups)
Definition: HM4.java:612
com.cliffc.aa.HM.HM4.T2.p
String p()
Definition: HM4.java:637
com.cliffc.aa.HM.HM4.T2._p
SB _p(SB sb, VBitSet visit, VBitSet dups)
Definition: HM4.java:639
com.cliffc.aa.util.Util.eq
static boolean eq(String s0, String s1)
Definition: Util.java:16
com.cliffc.aa.HM.HM4.T2.progress
boolean progress(T2 t)
Definition: HM4.java:537
com.cliffc
com.cliffc.aa.type.Type.toString
final String toString()
Definition: Type.java:127
com.cliffc.aa.util.Ary.addAll
Ary< E > addAll(Collection<? extends E > c)
Definition: Ary.java:151
com.cliffc.aa.util.Ary
Definition: Ary.java:11
com.cliffc.aa.HM.HM4.T2.is_leaf
boolean is_leaf()
Definition: HM4.java:360
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.HM.HM4.T2.T2
T2(@NotNull String name, T2 @NotNull ... args)
Definition: HM4.java:355
com.cliffc.aa.AA.unimpl
static RuntimeException unimpl()
Definition: AA.java:10
com.cliffc.aa.HM.HM4.T2._unify
T2 _unify(T2 t, Ary< Syntax > work)
Definition: HM4.java:431
com.cliffc.aa.HM.HM4.T2.get_dups
VBitSet get_dups(VBitSet dups)
Definition: HM4.java:599
com.cliffc.aa.util.SB.unchar
SB unchar()
Definition: SB.java:58
com.cliffc.aa.util.VBitSet.tset
boolean tset(int idx)
Definition: VBitSet.java:7
com.cliffc.aa.HM.HM4.T2.get_fresh
T2 get_fresh()
Definition: HM4.java:365
com.cliffc.aa.HM.HM4.T2.fresh_base
T2 fresh_base(T2 t)
Definition: HM4.java:472
com.cliffc.aa.HM.HM4.T2.tnew
static T2 tnew()
Definition: HM4.java:344
com.cliffc.aa.util.Util
Definition: Util.java:5
com.cliffc.aa.HM.HM4.T2.CDUPS
static final HashMap< T2, T2 > CDUPS
Definition: HM4.java:551
com.cliffc.aa.HM.HM4.T2.fun
static T2 fun(T2... args)
Definition: HM4.java:343
com.cliffc.aa.HM.HM4.T2._get_dups
VBitSet _get_dups(VBitSet visit, VBitSet dups)
Definition: HM4.java:600
com.cliffc.aa.HM.HM4.T2.unify_base
T2 unify_base(T2 t, Ary< Syntax > work)
Definition: HM4.java:473
com.cliffc.aa.HM.HM4.T2.is_fresh
boolean is_fresh()
Definition: HM4.java:358
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.HM.HM4.T2.UPDATE_VISIT
static final VBitSet UPDATE_VISIT
Definition: HM4.java:581
com.cliffc.aa.HM.HM4.T2._cycle_equals
boolean _cycle_equals(T2 t)
Definition: HM4.java:558
com.cliffc.aa.HM.HM4.T2.push_update_impl
void push_update_impl(Syntax a)
Definition: HM4.java:583
com.cliffc.aa.HM.HM4.T2._fresh
String _fresh
Definition: HM4.java:336
com.cliffc.aa.HM.HM4.T2._repl
T2 _repl(HashMap< T2, T2 > vars, HashMap< T2, T2 > dups)
Definition: HM4.java:521
com.cliffc.aa.AA
an implementation of language AA
Definition: AA.java:9
com.cliffc.aa
Definition: AA.java:1
com.cliffc.aa.HM.HM4.T2.find
T2 find()
Definition: HM4.java:378
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.HM.HM4.T2._name
final String _name
Definition: HM4.java:330
com.cliffc.aa.HM.HM4.T2.is_base
boolean is_base()
Definition: HM4.java:362
com.cliffc.aa.HM.HM4.T2.cycle_equals
boolean cycle_equals(T2 t)
Definition: HM4.java:552
com.cliffc.aa.HM.HM4.T2._args
T2[] _args
Definition: HM4.java:331
com.cliffc.aa.HM.HM4.T2._updates
Ary< Syntax > _updates
Definition: HM4.java:341
com.cliffc.aa.HM.HM4.T2.no_uf
boolean no_uf()
Definition: HM4.java:395
com.cliffc.aa.HM.HM4.T2._fresh_unify_impl
T2 _fresh_unify_impl(HashMap< T2, T2 > vars, T2 t, Ary< Syntax > work)
Definition: HM4.java:489
com.cliffc.aa.HM.HM4.T2._uid
final int _uid
Definition: HM4.java:332
com.cliffc.aa.util.IBitSet.set
boolean set(int idx)
Definition: IBitSet.java:26
com
com.cliffc.aa.HM.HM4.T2._fresh_unify
T2 _fresh_unify(HashMap< T2, T2 > vars, T2 t, Ary< Syntax > work)
Definition: HM4.java:477
com.cliffc.aa.HM.HM4.T2.DUPS
static final HashMap< Long, T2 > DUPS
Definition: HM4.java:430
com.cliffc.aa.util.SB.toString
String toString()
Definition: SB.java:62
com.cliffc.aa.HM.HM4.T2.CNT
static int CNT
Definition: HM4.java:326
com.cliffc.aa.HM.HM4.T2._con
Type _con
Definition: HM4.java:338
com.cliffc.aa.type.TypeMemPtr
Definition: TypeMemPtr.java:14
com.cliffc.aa.HM.HM4.T2.repl
T2 repl(HashMap< T2, T2 > vars, HashMap< T2, T2 > dups)
Definition: HM4.java:513
com.cliffc.aa.HM.HM4.T2.is_tvar
boolean is_tvar()
Definition: HM4.java:364