Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check instgen interface #346

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions lib/hobbes/eval/cmodule.C
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ void compile(const ModulePtr& m, cc* e, const InstanceDef* id) {
} else {
c->insert(TCInstanceFnPtr(new TCInstanceFn(id->className(), id->constraints(), targs, ms, id->la())));
}
} catch (annotated_error&) {
throw;
} catch (std::exception& ex) {
throw annotated_error(*id, ex.what());
}
Expand Down
24 changes: 24 additions & 0 deletions lib/hobbes/lang/preds/class.C
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ void TClass::insert(const TCInstanceFnPtr& ifp) {
ss << "Arity mismatch between instance generator definition (" << ifp->arity() << ") and type class definition (" << this->tvs << ").";
throw annotated_error(*ifp, ss.str());
} else {
// make sure that this instance generator covers all required members
auto mm = ifp->members(MonoTypeSubst());

std::ostringstream ss;
size_t errors = 0;
for (const auto& tcm : this->tcmembers) {
if (!mm.count(tcm.first)) {
ss << (errors?", ":"") << "expected definition of '" << tcm.first << "'";
++errors;
}
}
for (const auto& m : mm) {
if (!this->tcmembers.count(m.first)) {
ss << (errors?", ":"") << "unexpected definition of '" << m.first << "'";
++errors;
}
}
if (errors) {
std::ostringstream ess;
ess << "Can't introduce instance generator for '" << this->tcname << "': " << ss.str();
throw annotated_error(*ifp, ess.str());
}

// insert the instance generator
ifp->order = this->tcinstancefns.size();
this->tcinstancefns.push_back(ifp);

Expand Down