Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f3b58c3
First pass on ADTs
MarisaKirisame Jan 16, 2019
485889d
Add doc string for tag field
slyubomirsky Jan 16, 2019
54e5196
Visit constructors in TypeVisitor for TypeData
slyubomirsky Jan 16, 2019
671f615
Add to description of type call
slyubomirsky Jan 16, 2019
f9e48e8
Add type call to type solving and unification
slyubomirsky Jan 17, 2019
94748c1
Make type mutator for typecall consistent with others (only create ne…
slyubomirsky Jan 17, 2019
7b1126f
Ensure kindchecking can handle type calls and typedata
slyubomirsky Jan 17, 2019
f2d36d6
Fix bad nesting in module constructor
slyubomirsky Jan 21, 2019
7dc26ef
Correctly construct call in typecall test
slyubomirsky Jan 22, 2019
0c949c7
Add call override for ordinary vars (do we want this?)
slyubomirsky Jan 22, 2019
9443bdc
Remove generalization hack from type inference because it was breakin…
slyubomirsky Jan 22, 2019
33fc344
Check that there are no free type vars in exprs after inferring type
slyubomirsky Jan 22, 2019
c208071
Free var checks need module because of ADT constructors
slyubomirsky Jan 22, 2019
af7da11
Typecall test can't have unbound type var, make it global
slyubomirsky Jan 22, 2019
4968b48
Uncomment tmap test and remove comments about failing to infer ret ty…
slyubomirsky Jan 22, 2019
87f82b7
Put in dummy visits for ADTs in graph runtime codegen to placate pylint
slyubomirsky Jan 22, 2019
e0f4c08
Fix Relay type infer test module constructor
slyubomirsky Jan 22, 2019
b646740
Mark override for TypeCallNode in type solver
slyubomirsky Jan 22, 2019
e11f58e
Ensure free vars check treats patern vars as bound
slyubomirsky Jan 23, 2019
ec56e4a
Run interpreter in more ADT test cases
slyubomirsky Jan 23, 2019
4f74545
Refactor kind check to return the kind, like typechecking
slyubomirsky Jan 23, 2019
276e028
Fix invalid typecall in test
slyubomirsky Jan 23, 2019
7963e7e
Add kind check to type inference, do not use nulls in func_type_annot…
slyubomirsky Jan 23, 2019
e2d6219
Redundant whitespace
slyubomirsky Jan 23, 2019
40c7410
Make TypeData a separate kind
slyubomirsky Jan 23, 2019
673bcd6
Make ADT handles a separate kind too, document calling convention better
slyubomirsky Jan 23, 2019
5e61378
Remove nats and tree from prelude, move to test, document prelude
slyubomirsky Jan 23, 2019
3db3c64
Restore and document nat and tree to prelude, add more tree tests
slyubomirsky Jan 23, 2019
0041b46
Add alpha equality tests for match cases, fix variable binding bug
slyubomirsky Jan 24, 2019
d232beb
Add more kind check tests for ADTs
slyubomirsky Jan 24, 2019
7c6d737
Add more tests for finding free or bound vars in match exprs
slyubomirsky Jan 24, 2019
7322866
Add unification tests for type call
slyubomirsky Jan 24, 2019
5f3a2f4
Update main() for alpha equality tests
slyubomirsky Jan 24, 2019
90ee405
Add simple type inference test cases for match exprs and ADT construc…
slyubomirsky Jan 24, 2019
d4a54a1
Add more ADT interpreter tests
slyubomirsky Jan 24, 2019
609f56e
Allow incomplete types when typechecking match cases
slyubomirsky Jan 24, 2019
089813a
Type inference for pattern vars should use the type annotation if it'…
slyubomirsky Jan 24, 2019
ebec99c
Two more specific test cases for ADT matching
slyubomirsky Jan 24, 2019
00963de
Add option ADT to prelude
slyubomirsky Jan 24, 2019
47babdb
Fix broken reference to kind enum
slyubomirsky Jan 25, 2019
a37d927
Fix rebase snags
slyubomirsky Jan 28, 2019
0c660aa
Do not attach checked types to constructors
slyubomirsky Jan 31, 2019
f5cec3e
More docstrings for module fields
slyubomirsky Feb 1, 2019
b56bc36
Use proper wrapper for indexing into module type data
slyubomirsky Feb 1, 2019
6b8dbb8
checked_type for constructors is not populated
slyubomirsky Feb 1, 2019
07ea915
Expand type call docstring
slyubomirsky Feb 1, 2019
b7cfc59
Rename PatternConstructor con field
slyubomirsky Feb 1, 2019
8cd15f2
Use error reporter for pattern constructor case
slyubomirsky Feb 4, 2019
1d9ae48
Condense error reporting in kind check, use error reporter
slyubomirsky Feb 4, 2019
acc2ec0
Expand docstrings and rename ADT fields
slyubomirsky Feb 4, 2019
737514b
Rename 'option' ADT to 'optional' for consistency with Python
slyubomirsky Feb 11, 2019
1a6e48a
Add various list iterators and utility functions to prelude
slyubomirsky Feb 15, 2019
511a931
Add smoke tests for new iterators in prelude
slyubomirsky Feb 15, 2019
3eeca4c
Add concat to prelude
slyubomirsky Feb 15, 2019
868f76e
Add smoke test for concat
slyubomirsky Feb 15, 2019
5a85aa8
Correct docstrings in prelude
slyubomirsky Feb 15, 2019
bd9bfc7
Ensure that type defs are written in module initialization
slyubomirsky Feb 15, 2019
de7ea6e
Various requested renamings
slyubomirsky Feb 15, 2019
8909e18
Correct rebase snags
slyubomirsky Feb 15, 2019
ffd5c80
Add kind check tests for ref types
slyubomirsky Feb 15, 2019
7a6eff0
Update the main() for kind checking tests
slyubomirsky Feb 15, 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
Prev Previous commit
Next Next commit
Add type call to type solving and unification
  • Loading branch information
slyubomirsky committed Feb 15, 2019
commit f9e48e805eb2a0e84babae2da5c01351f825e78b
10 changes: 5 additions & 5 deletions src/relay/pass/type_infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ class TypeInferencer : private ExprFunctor<Type(const Expr&)>,
}

for (auto type_param : ft->type_params) {
instantiation_map_.Set(type_param, IncompleteTypeNode::make(TypeVarNode::Kind::kType));
instantiation_map_.Set(type_param, IncompleteTypeNode::make(Kind::kType));
}

Type ret_type = ft->ret_type;
if (!ret_type.defined()) {
ret_type = IncompleteTypeNode::make(TypeVarNode::Kind::kType);
ret_type = IncompleteTypeNode::make(Kind::kType);
}

auto strip_tvs = FuncTypeNode::make(ft->arg_types, ret_type, {}, ft->type_constraints);
Expand Down Expand Up @@ -277,7 +277,7 @@ class TypeInferencer : private ExprFunctor<Type(const Expr&)>,
// if the definition is a function literal, permit recursion
bool is_functional_literal = let->value.as<FunctionNode>() != nullptr;
if (is_functional_literal) {
type_map_[let->var].checked_type = IncompleteTypeNode::make(TypeVarNode::Kind::kType);
type_map_[op->var].checked_type = IncompleteTypeNode::make(Kind::kType);
}

Type vtype = GetType(let->value);
Expand Down Expand Up @@ -380,7 +380,7 @@ class TypeInferencer : private ExprFunctor<Type(const Expr&)>,
// incomplete type => it must be a function taking the arg types
// with an unknown return type
if (inc_ty_node != nullptr) {
Type ret_type = IncompleteTypeNode::make(TypeVarNode::Kind::kType);
Type ret_type = IncompleteTypeNode::make(Kind::kType);
Type func_type = FuncTypeNode::make(arg_types, ret_type, {}, {});
Type unified = this->Unify(ftype, func_type, GetRef<Call>(call));
fn_ty_node = unified.as<FuncTypeNode>();
Expand All @@ -389,7 +389,7 @@ class TypeInferencer : private ExprFunctor<Type(const Expr&)>,
Array<Type> type_args = call->type_args;
if (type_args.size() == 0) {
for (size_t i = 0; i < fn_ty_node->type_params.size(); i++) {
type_args.push_back(IncompleteTypeNode::make(TypeVarNode::Kind::kType));
type_args.push_back(IncompleteTypeNode::make(Kind::kType));
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/relay/pass/type_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ class TypeSolver::Unifier : public TypeFunctor<Type(const Type&, const Type&)> {
return RefTypeNode::make(Unify(op->value, rtn->value));
}

Type VisitType_(const TypeCallNode* op, const Type& tn) {
const auto* tcn = tn.as<TypeCallNode>();
if (!tcn || tcn->args.size() != op->args.size()) {
return Type();
}

Type func = Unify(op->func, tcn->func);
tvm::Array<Type> args;
for (size_t i = 0; i < op->args.size(); i++) {
args.push_back(Unify(op->args[i], tcn->args[i]));
}
return TypeCallNode::make(func, args);
}

private:
TypeSolver* solver_;
};
Expand Down Expand Up @@ -266,6 +280,16 @@ class TypeSolver::Propagator : public TypeFunctor<void(const Type&)> {
}
}

void VisitType_(const TypeCallNode* op) override {
TypeCall tc = GetRef<TypeCall>(op);
UpdateRelSet(tc);

Propagate(tc->func);
for (auto arg : tc->args) {
Propagate(arg);
}
}

private:
TypeSolver* solver_;
const std::unordered_set<RelationNode*>* rels_;
Expand Down