dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

pkg:stacktrace has errors when run in strong mode #31764

Closed a-siva closed 6 years ago

a-siva commented 6 years ago

We get the following errors from pkg:stacktrace when running in strong mode

third_party/pkg/stack_trace/lib/src/chain.dart:249:25: Error: A value of type '<T extends dart.core::num>(dart.math::max::T, dart.math::max::T) → dart.math::max::T' can't be assigned to a variable of type '(dart.core::int, dart.core::int) → dart.core::int'.
Try changing the type of the left hand side, or casting the right hand side to '(dart.core::int, dart.core::int) → dart.core::int'.
          .fold(0, math.max);
                        ^
third_party/pkg/stack_trace/lib/src/trace.dart:323:67: Error: A value of type '<T extends dart.core::num>(dart.math::max::T, dart.math::max::T) → dart.math::max::T' can't be assigned to a variable of type '(dart.core::int, dart.core::int) → dart.core::int'.
Try changing the type of the left hand side, or casting the right hand side to '(dart.core::int, dart.core::int) → dart.core::int'.
        frames.map((frame) => frame.location.length).fold(0, math.max);

This is blocking us from running all the VM tests in strong mode.

a-siva commented 6 years ago

/cc @nex3 @vsmenon @leafpetersen

a-siva commented 6 years ago

The following changes in the strack trace package works around the issue

sivalinuxmach[sdk]>git diff lib/src/chain.dart
diff --git a/lib/src/chain.dart b/lib/src/chain.dart
index 8685a9e..334ec00 100644
--- a/lib/src/chain.dart
+++ b/lib/src/chain.dart
@@ -246,8 +246,8 @@ class Chain implements StackTrace {
     var longest = traces.map((trace) {
       return trace.frames
           .map((frame) => frame.location.length)
-          .fold(0, math.max);
-    }).fold(0, math.max);
+          .fold(0, (x, y) => math.max<int>(x, y));
+    }).fold(0, (x, y) => math.max<int>(x, y));

     // Don't call out to [Trace.toString] here because that doesn't ensure that
     // padding is consistent across all traces.
sivalinuxmach[sdk]>git stash
sivalinuxmach[sdk]>git branch -vv
* (HEAD detached at 1.9.1) e24e50c Avoid overwriting chain for trace if one exists (#37)
  master                   d18fff5 [origin/master: behind 62] Merge branch 'empty-stack-trace'
sivalinuxmach[sdk]>git diff lib/src/trace.dart
diff --git a/lib/src/trace.dart b/lib/src/trace.dart
index 972c33e..cbeb254 100644
--- a/lib/src/trace.dart
+++ b/lib/src/trace.dart
@@ -320,7 +320,8 @@ class Trace implements StackTrace {
   String toString() {
     // Figure out the longest path so we know how much to pad.
     var longest =
-        frames.map((frame) => frame.location.length).fold(0, math.max);
+        frames.map((frame) =>
+            frame.location.length).fold(0, (x, y) => math.max<int>(x, y));

     // Print out the stack trace nicely formatted.
     return frames.map((frame) {
nex3 commented 6 years ago

Some information from the internal thread for context:

I'll add @a-siva's workaround to stack_trace for now, but I think this bug should probably target the CFE work to fix the underlying issue.

nex3 commented 6 years ago

How can I reproduce this? All the stack_trace tests seem to be passing with 2.0.0-dev.15.0. Do I have to build bleeding edge?

a-siva commented 6 years ago

If you run the VM isolate tests in strong mode you should see a reproduction, here is a reproduction line for one isolate test

pkg/vm/tool/dart2 --no-background-compilation --ignore-unrecognized-flags --packages=/usr/local/google/home/asiva/workspace/dart-ws2/sdk/.packages /usr/local/google/home/asiva/workspace/dart-ws2/sdk/tests/isolate/timer_isolate_test.dart

nex3 commented 6 years ago

How do I build pkg/vm/tool/dart2?

a-siva commented 6 years ago

It is a shell script available at sdk/pkg/vm/tool/dart2 in the dart repo.

nex3 commented 6 years ago

But it must still rely on something being built... I'm getting this error when trying to run it:

kernel-service: Isolate creation error: Wrong full snapshot version, expected '41bd5eab5c21a0d6a57f3
da2d31d9545' found '531e2c5f5ffcd47fd1ba6fcf7fba109d'                                              
Error while initializing Kernel isolate
a-siva commented 6 years ago

Aah yes, you would have to do a VM build in the sdk directory tools/build.py runtime_kernel

nex3 commented 6 years ago

I can't seem to reproduce the error... I'm running on 747772b02d3fbcc82a5eb91b334c6f23073f4682.

$ ./pkg/vm/tool/dart2 --no-background-compilation --packages=.packages tests/isolate/timer_isolate_test.dart                                                      
unittest-suite-wait-for-done
PASS: timer in isolate

All 1 tests passed.
unittest-suite-success
kmillikin commented 6 years ago

I believe this issue was fixed by ae9b0c42d7098c81befe8d353f5eafa9a7ba1790 (a while ago). I was able to bisect it using Fasta itself like:

$ pkg/front_end/tool/fasta compile --target=none --strong third_party/pkg/stack_trace/lib/src/chain.dart
a-siva commented 6 years ago

closing as fixed.