Commit 782c0bd3 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] improve lookup and error messages for branching context calls

This removes error messages about missing _True labels, and instead tries
find overloads for the branch protocol and a normal function call at the
same time. The branch protocol is only considered if there are _True and
_False in the context and the overload returns never.
In addition, it prints all macro names of operator overloads if none
was matching.


Bug: v8:7793
Change-Id: Id81712f5b7f2af6765e23bb1f37438f141a79316
Reviewed-on: https://chromium-review.googlesource.com/1109839Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53943}
parent d64e9908
......@@ -65,6 +65,10 @@ class Declarations {
Builtin* LookupBuiltin(const std::string& name);
Label* TryLookupLabel(const std::string& name) {
Declarable* d = TryLookup(name);
return d && d->IsLabel() ? Label::cast(d) : nullptr;
}
Label* LookupLabel(const std::string& name);
GenericList* LookupGeneric(const std::string& name);
......
......@@ -30,7 +30,7 @@ namespace {
void PrintMacroSignatures(std::stringstream& s,
const std::vector<Macro*>& macros) {
for (Macro* m : macros) {
s << "\n " << m->signature();
s << "\n " << m->name() << m->signature();
}
}
......@@ -49,10 +49,22 @@ Callable* FileVisitor::LookupCall(const std::string& name,
std::vector<Macro*> candidates;
std::vector<Macro*> macros_with_same_name;
for (Macro* m : MacroList::cast(declarable)->list()) {
bool try_bool_context =
arguments.labels.size() == 0 &&
m->signature().return_type == TypeOracle::GetNeverType();
Label* true_label = nullptr;
Label* false_label = nullptr;
if (try_bool_context) {
true_label = declarations()->TryLookupLabel(kTrueLabelName);
false_label = declarations()->TryLookupLabel(kFalseLabelName);
}
if (IsCompatibleSignature(m->signature(), parameter_types,
arguments.labels)) {
arguments.labels) ||
(true_label && false_label &&
IsCompatibleSignature(m->signature(), parameter_types,
{true_label, false_label}))) {
candidates.push_back(m);
} else if (m->name() == name) {
} else {
macros_with_same_name.push_back(m);
}
}
......
......@@ -1344,25 +1344,19 @@ VisitResult ImplementationVisitor::GeneratePointerCall(
VisitResult ImplementationVisitor::GenerateCall(
const std::string& callable_name, Arguments arguments, bool is_tailcall) {
Callable* callable = LookupCall(callable_name, arguments);
// Operators used in a bit context can also be function calls that never
if (callable == nullptr) {
std::stringstream stream;
stream << "no matching declaration found for " << callable_name;
ReportError(stream.str());
}
// Operators used in a branching context can also be function calls that never
// return but have a True and False label
if (callable == nullptr && arguments.labels.size() == 0) {
if (arguments.labels.size() == 0 &&
callable->signature().labels.size() == 2) {
Label* true_label = declarations()->LookupLabel(kTrueLabelName);
arguments.labels.push_back(true_label);
Label* false_label = declarations()->LookupLabel(kFalseLabelName);
arguments.labels.push_back(false_label);
callable = LookupCall(callable_name, arguments);
if (callable == nullptr) {
std::stringstream stream;
stream << "no matching declaration found for callable " << callable_name;
ReportError(stream.str());
}
if (!callable->signature().return_type->IsNever()) {
std::stringstream stream;
stream << "macthing macro declaration for " << callable_name
<< " matches if-branch protocol but isn't of type 'never'";
ReportError(stream.str());
}
}
const Type* result_type = callable->signature().return_type;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment