aa
com.cliffc.aa.HM.HM3.HMVar Class Reference
Inheritance diagram for com.cliffc.aa.HM.HM3.HMVar:
[legend]
Collaboration diagram for com.cliffc.aa.HM.HM3.HMVar:
[legend]

Public Member Functions

SB _str (SB sb, VBitSet dups, boolean debug)
 
String str ()
 
final String toString ()
 
Type type ()
 

Package Functions

 HMVar ()
 
 HMVar (Type t)
 
boolean _eq (HMType v, BitSetSparse dups)
 
HMType _fresh (VStack vstk, HashMap< HMVar, HMVar > vars, HashMap< Oper, Oper > opers)
 
final boolean eq (HMType v)
 
HMType find ()
 
HMType fresh (VStack vstk)
 
boolean is_top ()
 
boolean occurs_in (HMType[] args, VBitSet dups)
 
boolean occurs_in (VStack vstk, VBitSet dups)
 
boolean occurs_in_type (HMType v, VBitSet dups)
 
HMType union (HMType that, Worklist work)
 

Static Package Functions

static void reset ()
 

Package Attributes

Ary< Ident_ids
 
HMType _u
 
final int _uid
 

Static Package Attributes

static final HashMap< HMVar, HMVarEQS = new HashMap<>()
 

Private Attributes

Type _t
 

Static Private Attributes

static int CNT
 

Detailed Description

Definition at line 323 of file HM3.java.

Constructor & Destructor Documentation

◆ HMVar() [1/2]

com.cliffc.aa.HM.HM3.HMVar.HMVar ( )
package

Definition at line 325 of file HM3.java.

325 { this(Type.ANY); }

References com.cliffc.aa.type.Type< T extends Type< T >.ANY.

Referenced by com.cliffc.aa.HM.HM3.HMVar._fresh(), and com.cliffc.aa.HM.HM3.HMVar.union().

Here is the caller graph for this function:

◆ HMVar() [2/2]

com.cliffc.aa.HM.HM3.HMVar.HMVar ( Type  t)
package

Definition at line 326 of file HM3.java.

326 { _t=t; }

References com.cliffc.aa.HM.HM3.HMVar._t.

Member Function Documentation

◆ _eq()

boolean com.cliffc.aa.HM.HM3.HMVar._eq ( HMType  v,
BitSetSparse  dups 
)
package

Reimplemented from com.cliffc.aa.HM.HM3.HMType.

Definition at line 375 of file HM3.java.

375  {
376  if( this==v ) return true;
377  if( v==null ) return false;
378  HMType v2 = v.find();
379  if( !(v2 instanceof HMVar) ) return false;
380  assert _u==null && v2._u==null;
381  if( _t != ((HMVar)v2)._t) return false;
382  HMVar v3 = EQS.computeIfAbsent(this,k -> (HMVar)v2);
383  return v2 == v3;
384  }

References com.cliffc.aa.HM.HM3.HMVar._t, com.cliffc.aa.HM.HM3.HMType._u, com.cliffc.aa.HM.HM3.HMType.EQS, and com.cliffc.aa.HM.HM3.HMType.find().

Here is the call graph for this function:

◆ _fresh()

HMType com.cliffc.aa.HM.HM3.HMVar._fresh ( VStack  vstk,
HashMap< HMVar, HMVar vars,
HashMap< Oper, Oper opers 
)
package

Reimplemented from com.cliffc.aa.HM.HM3.HMType.

Definition at line 386 of file HM3.java.

386  {
387  assert is_top();
388  return occurs_in(vstk, new VBitSet()) // If in the lexical Stack
389  ? this // Keep same var
390  : vars.computeIfAbsent(this, e -> new HMVar(_t));
391  }

References com.cliffc.aa.HM.HM3.HMVar._t, com.cliffc.aa.HM.HM3.HMVar.HMVar(), com.cliffc.aa.HM.HM3.HMType.is_top(), and com.cliffc.aa.HM.HM3.HMType.occurs_in().

Here is the call graph for this function:

◆ _str()

SB com.cliffc.aa.HM.HM3.HMVar._str ( SB  sb,
VBitSet  dups,
boolean  debug 
)

Reimplemented from com.cliffc.aa.HM.HM3.HMType.

Definition at line 328 of file HM3.java.

328  {
329  if( _u!=null && !debug ) return _u._str(sb,dups,debug); // Clean print; skip to U-F root & print
330  sb.p("v").p(_uid);
331  if( dups.tset(_uid) ) return sb.p("$"); // Stop infinite print loops
332  if( _t!=Type.ANY ) _t.str(sb.p(":"),dups,null,false);
333  if( _u!=null ) _u._str(sb.p(">>"),dups,debug);
334  return sb;
335  }

References com.cliffc.aa.HM.HM3.HMType._str(), com.cliffc.aa.HM.HM3.HMVar._t, com.cliffc.aa.HM.HM3.HMType._u, com.cliffc.aa.HM.HM3.HMType._uid, com.cliffc.aa.type.Type< T extends Type< T >.ANY, com.cliffc.aa.util.SB.p(), com.cliffc.aa.type.Type< T extends Type< T >.str(), and com.cliffc.aa.util.VBitSet.tset().

Referenced by com.cliffc.aa.HM.HM3.VStack.str().

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

◆ eq()

final boolean com.cliffc.aa.HM.HM3.HMType.eq ( HMType  v)
packageinherited

Definition at line 291 of file HM3.java.

291 { EQS.clear(); return find()._eq(v, new BitSetSparse()); }

References com.cliffc.aa.HM.HM3.HMType._eq(), com.cliffc.aa.HM.HM3.HMType.EQS, and com.cliffc.aa.HM.HM3.HMType.find().

Referenced by com.cliffc.aa.HM.HM3.Lambda.progress(), com.cliffc.aa.HM.HM3.Let.progress(), and com.cliffc.aa.HM.HM3.Apply.progress().

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

◆ find()

HMType com.cliffc.aa.HM.HM3.HMVar.find ( )
package

Reimplemented from com.cliffc.aa.HM.HM3.HMType.

Definition at line 337 of file HM3.java.

337  {
338  HMType u = _u;
339  if( u==null ) return this; // Top of union tree
340  if( u._u==null ) return u; // One-step from top
341  // Classic U-F rollup
342  while( u._u!=null ) u = u._u; // Find the top
343  HMType x = this; // Collapse all to top
344  while( x._u!=u ) { HMType tmp = x._u; x._u=u; x=tmp;}
345  return u;
346  }

References com.cliffc.aa.HM.HM3.HMType._u.

Referenced by com.cliffc.aa.HM.HM3.HMVar.union().

Here is the caller graph for this function:

◆ fresh()

HMType com.cliffc.aa.HM.HM3.HMType.fresh ( VStack  vstk)
packageinherited

Definition at line 294 of file HM3.java.

294  {
295  HashMap<HMVar,HMVar> vars = new HashMap<>();
296  HashMap<Oper,Oper> opers = new HashMap<>();
297  return find()._fresh(vstk,vars,opers);
298  }

References com.cliffc.aa.HM.HM3.HMType._fresh(), and com.cliffc.aa.HM.HM3.HMType.find().

Referenced by com.cliffc.aa.HM.HM3.Ident.hm().

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

◆ is_top()

boolean com.cliffc.aa.HM.HM3.HMType.is_top ( )
packageinherited

Definition at line 289 of file HM3.java.

289 { return _u==null; }

References com.cliffc.aa.HM.HM3.HMType._u.

Referenced by com.cliffc.aa.HM.HM3.Oper._eq(), com.cliffc.aa.HM.HM3.HMVar._fresh(), com.cliffc.aa.HM.HM3.Oper._fresh(), com.cliffc.aa.HM.HM3.HMType.occurs_in_type(), and com.cliffc.aa.HM.HM3.HMVar.type().

Here is the caller graph for this function:

◆ occurs_in() [1/2]

boolean com.cliffc.aa.HM.HM3.HMType.occurs_in ( HMType[]  args,
VBitSet  dups 
)
packageinherited

Definition at line 306 of file HM3.java.

306  {
307  for( HMType x : args ) if( occurs_in_type(x,dups) ) return true;
308  return false;
309  }

References com.cliffc.aa.HM.HM3.HMType.occurs_in_type().

Here is the call graph for this function:

◆ occurs_in() [2/2]

boolean com.cliffc.aa.HM.HM3.HMType.occurs_in ( VStack  vstk,
VBitSet  dups 
)
packageinherited

Definition at line 301 of file HM3.java.

301  {
302  if( vstk==null ) return false;
303  for( HMVar x : vstk ) if( occurs_in_type(x,dups) ) return true;
304  return false;
305  }

References com.cliffc.aa.HM.HM3.HMType.occurs_in_type().

Referenced by com.cliffc.aa.HM.HM3.HMVar._fresh(), and com.cliffc.aa.HM.HM3.HMType.occurs_in_type().

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

◆ occurs_in_type()

boolean com.cliffc.aa.HM.HM3.HMType.occurs_in_type ( HMType  v,
VBitSet  dups 
)
packageinherited

Definition at line 310 of file HM3.java.

310  {
311  assert is_top();
312  if( dups.tset(v._uid) )
313  return false; // Been there, done that
314  HMType y = v.find(); // Find top
315  if( y==this ) // Occurs in type?
316  return true; // Yup, occurs in type right here
317  if( y instanceof Oper ) // Structural recursive test
318  return occurs_in(((Oper)y)._args,dups);
319  return false;
320  }

References com.cliffc.aa.HM.HM3.HMType._uid, com.cliffc.aa.HM.HM3.HMType.find(), com.cliffc.aa.HM.HM3.HMType.is_top(), com.cliffc.aa.HM.HM3.HMType.occurs_in(), and com.cliffc.aa.util.VBitSet.tset().

Referenced by com.cliffc.aa.HM.HM3.HMType.occurs_in(), and com.cliffc.aa.HM.HM3.HMVar.union().

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

◆ reset()

static void com.cliffc.aa.HM.HM3.HMType.reset ( )
staticpackageinherited

Definition at line 281 of file HM3.java.

281 { CNT=1; }

References com.cliffc.aa.HM.HM3.HMType.CNT.

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

Here is the caller graph for this function:

◆ str()

String com.cliffc.aa.HM.HM3.HMType.str ( )
inherited

Definition at line 287 of file HM3.java.

287 { return _str(new SB(),new VBitSet(),false).toString(); }

References com.cliffc.aa.HM.HM3.HMType._str(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ toString()

final String com.cliffc.aa.HM.HM3.HMType.toString ( )
inherited

Definition at line 286 of file HM3.java.

286 { return _str(new SB(),new VBitSet(),true).toString(); }

References com.cliffc.aa.HM.HM3.HMType._str(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ type()

Type com.cliffc.aa.HM.HM3.HMVar.type ( )

Definition at line 327 of file HM3.java.

327 { assert is_top(); return _t; }

References com.cliffc.aa.HM.HM3.HMVar._t, and com.cliffc.aa.HM.HM3.HMType.is_top().

Here is the call graph for this function:

◆ union()

HMType com.cliffc.aa.HM.HM3.HMVar.union ( HMType  that,
Worklist  work 
)
package

Reimplemented from com.cliffc.aa.HM.HM3.HMType.

Definition at line 347 of file HM3.java.

347  {
348  if( _u!=null ) return find().union(that,work);
349  if( that instanceof HMVar ) that = that.find();
350  if( this==that ) return this; // Do nothing
351  if( occurs_in_type(that, new VBitSet()) )
352  //throw new RuntimeException("recursive unification");
353  System.out.println("recursive unification");
354 
355  if( that instanceof HMVar ) {
356  HMVar v2 = (HMVar)that;
357  // Order, so keep smaller _uids by default
358  if( _uid < v2._uid ) return that.union(this,work);
359  v2._t = _t.meet(v2._t); // Lattice MEET instead of unification failure
360  }
361  else if( _t!=Type.ANY ) // Else this var is un-MEETd with any Con
362  throw new RuntimeException("Cannot unify "+this+" and "+that);
363  if( _ids!=null ) { // Move this ids into that ids
364  if( that._ids==null ) that._ids = _ids;
365  else that._ids.addAll(_ids);
366  _ids=null; // No longer here
367  }
368  if( that._ids!=null ) { // All that ids onto worklist
369  for( Ident id : that._ids ) id._hm=null; // Flag as 1-shot re-freshen
370  work.addAll(that._ids); // On to worklist
371  }
372  return _u = that; // Classic U-F union this into that.
373  }

References com.cliffc.aa.HM.HM3.HMType._ids, com.cliffc.aa.HM.HM3.HMVar._t, com.cliffc.aa.HM.HM3.HMType._u, com.cliffc.aa.HM.HM3.HMType._uid, com.cliffc.aa.type.Type< T extends Type< T >.ANY, com.cliffc.aa.HM.HM3.HMType.find(), com.cliffc.aa.HM.HM3.HMVar.find(), com.cliffc.aa.HM.HM3.HMVar.HMVar(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.HM.HM3.HMType.occurs_in_type(), com.cliffc.aa.HM.HM3.HMType.union(), and com.cliffc.aa.HM.HM3.HMVar.union().

Referenced by com.cliffc.aa.HM.HM3.HMVar.union().

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

Member Data Documentation

◆ _ids

Ary<Ident> com.cliffc.aa.HM.HM3.HMType._ids
packageinherited

◆ _t

◆ _u

◆ _uid

◆ CNT

int com.cliffc.aa.HM.HM3.HMType.CNT
staticprivateinherited

◆ EQS

final HashMap<HMVar,HMVar> com.cliffc.aa.HM.HM3.HMType.EQS = new HashMap<>()
staticpackageinherited

Definition at line 290 of file HM3.java.

Referenced by com.cliffc.aa.HM.HM3.HMVar._eq(), and com.cliffc.aa.HM.HM3.HMType.eq().


The documentation for this class was generated from the following file:
com.cliffc.aa.HM.HM3.HMType.HMType
HMType()
Definition: HM3.java:282
com.cliffc.aa.HM.HM3.HMType.occurs_in
boolean occurs_in(VStack vstk, VBitSet dups)
Definition: HM3.java:301
com.cliffc.aa.HM.HM3.HMVar.HMVar
HMVar()
Definition: HM3.java:325
com.cliffc.aa.HM.HM3.HMType.union
abstract HMType union(HMType t, Worklist work)
com.cliffc.aa.HM.HM3.HMType._u
HMType _u
Definition: HM3.java:278
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.HM.HM3.HMVar._t
Type _t
Definition: HM3.java:324
com.cliffc.aa.type.Type.ANY
static final Type ANY
Definition: Type.java:325
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.type.Type.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: Type.java:131
com.cliffc.aa.util.BitSetSparse
Definition: BitSetSparse.java:4
com.cliffc.aa.HM.HM3.HMType.find
abstract HMType find()
com.cliffc.aa.HM.HM3.HMType._ids
Ary< Ident > _ids
Definition: HM3.java:283
com.cliffc.aa.util.VBitSet.tset
boolean tset(int idx)
Definition: VBitSet.java:7
com.cliffc.aa.HM.HM3.HMType._uid
final int _uid
Definition: HM3.java:279
com.cliffc.aa.HM.HM3.HMVar.find
HMType find()
Definition: HM3.java:337
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.HM3.HMType._eq
abstract boolean _eq(HMType v, BitSetSparse dups)
com.cliffc.aa.HM.HM3.HMType.is_top
boolean is_top()
Definition: HM3.java:289
com.cliffc.aa.HM.HM3.HMType.CNT
static int CNT
Definition: HM3.java:280
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.HM.HM3.HMType._str
abstract SB _str(SB sb, VBitSet vbs, boolean debug)
com.cliffc.aa.HM.HM3.HMType._fresh
abstract HMType _fresh(VStack vstk, HashMap< HMVar, HMVar > vars, HashMap< Oper, Oper > opers)
com.cliffc.aa.HM.HM3.HMType.EQS
static final HashMap< HMVar, HMVar > EQS
Definition: HM3.java:290
com.cliffc.aa.util.SB.toString
String toString()
Definition: SB.java:62
com.cliffc.aa.HM.HM3.HMType.occurs_in_type
boolean occurs_in_type(HMType v, VBitSet dups)
Definition: HM3.java:310