Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a0d95a6
Expand unification in type solver
slyubomirsky Nov 29, 2018
746f7e0
Only register child type relations for incomplete child types
slyubomirsky Nov 29, 2018
bf8b362
Removed redundant registrations
slyubomirsky Nov 29, 2018
169e9ed
Be sure to copy linked list nodes for child types
slyubomirsky Nov 30, 2018
c7598e2
Add unifier tests
slyubomirsky Nov 30, 2018
aff240f
Add a negative test case
slyubomirsky Nov 30, 2018
00f7b7d
Check for recursive equalities when unifying
slyubomirsky Nov 30, 2018
e0affb1
Minor tweaks to error messages
slyubomirsky Nov 30, 2018
1d2734a
Improve recursive unification test
slyubomirsky Nov 30, 2018
0cb44f8
Do not copy relation list nodes if already resolved
slyubomirsky Nov 30, 2018
75f5d6a
Add visitor for type resolution, have more complicated unification te…
slyubomirsky Nov 30, 2018
5218371
Avoid catastrophic failure in Resolve() by only recursing in one bran…
slyubomirsky Nov 30, 2018
5d9a0fd
Add a null check before resolution
slyubomirsky Nov 30, 2018
ef6c40d
Move null check into resolution visitor
slyubomirsky Nov 30, 2018
acf0de5
Rename RecurrenceChecker to OccursChecker
slyubomirsky Dec 2, 2018
23fea28
Recursively propagate type relations to child types when a constraint…
slyubomirsky Dec 3, 2018
a534f66
Make use of new unification in type inference, add generalization, fi…
slyubomirsky Dec 7, 2018
e984af9
Intermediate progress on fixing the unifier (this breaks stuff)
slyubomirsky Dec 7, 2018
b8a24a7
Generalize only after all other type unification (still broken)
slyubomirsky Dec 7, 2018
b783665
Correct error in type var instantiation
slyubomirsky Dec 8, 2018
b3e3a12
Do not permit free type variables in tests
slyubomirsky Dec 10, 2018
53bc929
Remove commented-out function inference code
slyubomirsky Dec 10, 2018
fdfe249
Instantiate generalizer once in type inference
slyubomirsky Dec 10, 2018
f4ded1f
Fix error in type inference cpp test
slyubomirsky Dec 10, 2018
c94395a
Use alpha equality in cpp test
slyubomirsky Dec 10, 2018
0fd679e
Use free var pass for collecting type params in generalization. Fix d…
slyubomirsky Dec 11, 2018
9283e5f
Handle recursion in let, generalize early in that case
slyubomirsky Dec 11, 2018
159b277
Fix FreeVar pass doc
slyubomirsky Dec 11, 2018
1d9b8ab
Refactoring of free var visitors to ensure fixed order (mostly @jroes…
slyubomirsky Dec 12, 2018
d23ad59
Add tests for various variable collection passes, add Python handles …
slyubomirsky Dec 12, 2018
d6f0716
Unifier should not keep additional state, ensure that type params *ma…
slyubomirsky Dec 17, 2018
fd3f56a
Attempt at keeping type env in inferencer (broken)
slyubomirsky Dec 20, 2018
03bb517
Revert "Attempt at keeping type env in inferencer (broken)"
slyubomirsky Dec 21, 2018
6a1e422
Revert "Unifier should not keep additional state, ensure that type pa…
slyubomirsky Dec 21, 2018
b317cd3
Remove generalization and tests related to it for now; it needs to be…
slyubomirsky Dec 21, 2018
cb47fbc
Rename method Bounded() to MarkBounded()
slyubomirsky Dec 22, 2018
f67bd00
Require all type args to be specified or none (however, type arg test…
slyubomirsky Dec 22, 2018
3ff08c9
Whitespace
slyubomirsky Dec 22, 2018
5a98c1d
Remove redundant func type creation in instantiation in TypeSolver
slyubomirsky Dec 22, 2018
bd88309
Style change (variable rename)
slyubomirsky Dec 22, 2018
f905e73
Instantiate type vars in type_infer instead of unifier, do not expose…
slyubomirsky Dec 22, 2018
ff57fda
Whitespace fixes and redundant check
slyubomirsky Dec 22, 2018
1578b2a
Simplify function literal type inference case
slyubomirsky Dec 22, 2018
7edafe1
Style nitpick
slyubomirsky Dec 24, 2018
701a411
Don't drop type params in unifier
slyubomirsky Dec 24, 2018
f88c230
Clean up and better document type var instantiation hack
slyubomirsky Dec 24, 2018
503c56c
MergeFromTo gathers rel links recursively
slyubomirsky Dec 28, 2018
86ead4c
Copy links over to avoid circular links
slyubomirsky Dec 28, 2018
e5eb872
Use set for storing rels, propagate after merging typenodes
slyubomirsky Dec 28, 2018
d0d1fc0
Propagator should be able to propagate multiple relations at once
slyubomirsky Dec 28, 2018
fa59092
Correct description of AllVars() utility
slyubomirsky Jan 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions include/tvm/relay/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ bool AlphaEqual(const Type& t1, const Type& t2);
*/
bool WellFormed(const Expr& expr);

/*! \brief Get all bound variables from expression expr.
*
* Bound variables are all variables that are declared in the expr.
* They only have meaning inside that expr, and can only be used in it.
*
* \param expr the expression.
*
* \return List of bound vars, in the PostDFS order in the expression.
*/
tvm::Array<Var> BoundVars(const Expr& expr);

/*! \brief Get free type parameters from expression expr.
*
* Free variables are variables that are not bound by a
Expand All @@ -117,6 +128,14 @@ bool WellFormed(const Expr& expr);
*/
tvm::Array<Var> FreeVars(const Expr& expr);

/*! \brief Get all variables from expression expr.
*
* \param expr the expression.
*
* \return List of all vars, in the PostDFS order in the expression.
*/
tvm::Array<Var> AllVars(const Expr& expr);

/*! \brief Get free TypeVars from expression expr.
*
* Free type parameters are type parameters that are not bound by a function
Expand All @@ -128,6 +147,55 @@ tvm::Array<Var> FreeVars(const Expr& expr);
*/
tvm::Array<TypeVar> FreeTypeVars(const Expr& expr);

/*! \brief Get free TypeVars from type t.
*
* Free type parameters are type parameters that are not bound by a function
* type in the context.
*
* \param t the type.
*
* \return List of free type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> FreeTypeVars(const Type& t);

/*! \brief Get all bound type variables from expression expr.
*
* Bound variables are all type variables that are declared in the expr.
* They only have meaning inside that expr, and can only be used in it.
*
* \param expr the expression.
*
* \return List of bound type vars, in the PostDFS order in the expression.
*/
tvm::Array<TypeVar> BoundTypeVars(const Expr& expr);

/*! \brief Get all bound type variables from type t.
*
* Bound variables are all type variables that are declared in the type.
* They only have meaning inside that type, and can only be used in it.
*
* \param t the type
*
* \return List of bound type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> BoundTypeVars(const Type& t);

/*! \brief Get all type variables in expression expr.
*
* \param expr the expression.
*
* \return List of type vars, in the PostDFS order in the expression.
*/
tvm::Array<TypeVar> AllTypeVars(const Expr& expr);

/*! \brief Get all type variables in type t.
*
* \param t the type.
*
* \return List of type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> AllTypeVars(const Type& t);

/*! \brief Remove expressions which does not effect the program result.
*
* It will remove let bindings which are not referenced, and branches that will
Expand Down
68 changes: 66 additions & 2 deletions python/tvm/relay/ir_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ def free_vars(expr):
return _ir_pass.free_vars(expr)


def bound_vars(expr):
"""Get bound vars from expression expr in post-DFS order.

Parameters
----------
expr: tvm.relay.Expr
The input expression

Returns
-------
free : List[tvm.relay.Var]
The list of bound variables in post-DFS order.
"""
return _ir_pass.bound_vars(expr)


def all_vars(expr):
"""Get all vars from expression expr in post-DFS order.

Parameters
----------
expr: tvm.relay.Expr
The input expression

Returns
-------
free : List[tvm.relay.Var]
The list of all variables in post-DFS order.
"""
return _ir_pass.all_vars(expr)


def free_type_vars(expr):
"""Get free type variables from expression/type e

Expand All @@ -168,12 +200,44 @@ def free_type_vars(expr):

Returns
-------
free : List[tvm.relay.TypeParam]
The list of free type variables
free : List[tvm.relay.TypeVar]
The list of free type variables in post-DFS order
"""
return _ir_pass.free_type_vars(expr)


def bound_type_vars(expr):
"""Get bound type variables from expression/type e

Parameters
----------
expr: Union[tvm.relay.Expr,tvm.relay.Type]
The input expression/type

Returns
-------
free : List[tvm.relay.TypeVar]
The list of bound type variables in post-DFS order
"""
return _ir_pass.bound_type_vars(expr)


def all_type_vars(expr):
"""Get all type variables from expression/type e

Parameters
----------
expr: Union[tvm.relay.Expr,tvm.relay.Type]
The input expression/type

Returns
-------
free : List[tvm.relay.TypeVar]
The list of all type variables in post-DFS order
"""
return _ir_pass.all_type_vars(expr)


def simplify_inference(expr):
""" Simplify the data-flow graph for inference phase.

Expand Down
Loading