-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Segfault on loop with implicit type conversion on late variable #46141
Comments
/cc @alexmarkov |
I see this stacktrace
|
Flow graph before a3767f7:
Similarly to flutter/flutter#83094, crash happens because speculative Flow graph after a3767f7 which converted UnboxInt64 to non-speculative:
While this example no longer crashes after a3767f7, it still doesn't look correct as The following slightly modified example should throw LateInitializationError, but it prints garbage instead (after a3767f7): final values = List.filled(100, 0.0);
double? fn(double day) {
double? last;
late int lastDay;
int i = 0;
while (i < values.length) {
final t = values[i];
if (day > 95) {
print(lastDay);
break;
}
last = t;
lastDay = i;
i++;
}
return last;
}
void main() {
for (int i = 0; i < values.length; i++) {
fn(i.toDouble());
}
} I think we shouldn't unbox Phi which may take sdk/runtime/vm/compiler/backend/flow_graph.cc Lines 2057 to 2065 in f81de15
For late local variables we always check if value is a sentinel before using it, so I think this problem only affects phis. I see the following options for fixing this:
@mraleph @rmacnak-google @mkustermann What do you think? |
I think the real problem here is that |
Sentinel value is actually assignable to any Dart static type (as late variable of any type can be initialized with sentinel). The only type which has this property across all modes is Having said that, I agree that it would be cleaner to reflect the extension of Dart type system with I'll go ahead and try this approach (extending |
I strongly disagree with this. I'd like to contrast this with The story with sentinels is different because it departs from normal Dart semantics somewhat. We could ignore this somewhat in pre-NNDB world because sentinels were hiding in the It is somewhat unclear to me why sentinels have to be instances of |
Why? This is still a part of Dart language.
Sentinel can appear in a variable of any Dart type, if that variable is declared late. So, sentinel value should be assignable to any Dart type.
That is true. Sentinel is an implementation detail, and so is the extension of Dart type system used in the compiler. I think we're just discussing how exactly the type system should be extended - either with an extra value of type
They are stored using
I changed type of sentinel from
We can try that. I expect that making a separate VM class for sentinel would require special casing it in an unknown number of extra places. This may introduce some instability into the VM until we find all such places and fix them. I'm leaning towards a more cautious approach of extending CompileType with explicit |
This change adds a new VM-internal class for sentinel objects. Previously sentinel objects used class Never. TEST=existing tests Issue: #46141 Change-Id: Ibb3361092967132f4f1952d64fe0168659f3075e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202870 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This particular piece of code is causing a segfault for some reason:
The segfault occurs on when reaching the
while
line when the parameterday
reached the value of89
.The last logs are the following:
The error is not on the comparison since the
0 < 100 = true
is printed, but the followingwhile loop i = 0
is never reached.Interestingly, replacing the line
late int lastDay;
byint lastDay = 0;
fixes the issue.Also replacing
return last - lastDay;
byreturn last - lastDay.toDouble();
fixes it.I am not sure what the exact error is, but there are some shenanigans going on down there :)
The text was updated successfully, but these errors were encountered: