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

Resolve a compiler hang when reporting a split init error #21692

Merged
merged 2 commits into from
Feb 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/AST/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ const char* toString(VarSymbol* var, bool withType) {
SymExpr* dstSe = toSymExpr(c->get(1));
SymExpr* srcSe = toSymExpr(c->get(2));
if (dstSe && srcSe && dstSe->symbol() == sym) {
sym = singleDef->symbol();
sym = srcSe->symbol();
continue;
}
}
Expand Down
16 changes: 14 additions & 2 deletions compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4762,14 +4762,24 @@ static bool obviousMismatch(CallExpr* call, FnSymbol* fn) {
return (isMethodCall != isMethodFn);
}

static bool isSymExprTypeVar(Expr* e) {
if (SymExpr* se = toSymExpr(e)) {
return se->symbol()->hasFlag(FLAG_TYPE_VARIABLE);
}

return false;
}

// returns true if the error was issued
static bool maybeIssueSplitInitMissingTypeError(CallInfo& info,
Vec<FnSymbol*>& visibleFns) {
// Check for uninitialized values (with type dtSplitInitType)
bool foundUnknownTypeActual = false;
for_actuals(actual, info.call) {
bool isTypeVariable = isSymExprTypeVar(actual);
Type* t = actual->getValType();
if (t == dtSplitInitType || t->symbol->hasFlag(FLAG_GENERIC)) {
if (t == dtSplitInitType ||
(!isTypeVariable && t->symbol->hasFlag(FLAG_GENERIC))) {
foundUnknownTypeActual = true;
}
}
Expand All @@ -4790,8 +4800,10 @@ static bool maybeIssueSplitInitMissingTypeError(CallInfo& info,
if (anyTypeNotEstablished) {
bool printedError = false;
for_actuals(actual, info.call) {
bool isTypeVariable = isSymExprTypeVar(actual);
Type* t = actual->getValType();
if (t == dtSplitInitType || t->symbol->hasFlag(FLAG_GENERIC)) {
if (t == dtSplitInitType ||
(!isTypeVariable && t->symbol->hasFlag(FLAG_GENERIC))) {
if (SymExpr* se = toSymExpr(actual)) {
CallExpr* call = userCall(info.call);
splitInitMissingTypeError(se->symbol(), call, false);
Expand Down
7 changes: 7 additions & 0 deletions test/types/records/split-init/split-init-error-bug/Foo.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Foo {
class foo {
var size : int(64);
param isWeighted : bool;
var arrDom : domain(1) = {1..(if isWeighted then size else 0)};
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module FooUser {
use Foo;
proc Use_Foo(type inType : foo, in data : inType, type outType : real(?), outWeights : [] outType) {
//Do stuff
}
}
Empty file.
11 changes: 11 additions & 0 deletions test/types/records/split-init/split-init-error-bug/Reproducer.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Reproducer {
use Foo;
use FooUser;
proc main() {
var myFoo : foo(false);
var retDom : domain(1) = {1..10};
var retArr : [retDom] real(32);
//There is only one CallExpr in Reproducer.main, so the loop seems to trigger on this
Use_Foo(foo(false), myFoo, real(32), retArr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Reproducer.chpl:4: In function 'main':
Reproducer.chpl:5: error: cannot default-initialize a variable with generic type
Reproducer.chpl:5: note: 'myFoo' has generic type 'foo(false)'
Reproducer.chpl:5: note: cannot find initialization point to split-init this variable
Reproducer.chpl:9: note: 'myFoo' is used here before it is initialized