-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Failures on [tests] Remove triple shift test skips from status files #45376
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
Comments
This looks like an analyzer bug:
What might be happening is that
|
cc @srawlins |
I just landed a change for >> in const evaluation. e267fb2 |
Actually I think this might be a CFE error because there is a missing compile time error. The code in question is: ...
class MyClass {
final int a;
const MyClass(i1, i2) : a = (i1 >>> i2);
}
main() {
const MyClass c1 = MyClass(1.0, 1); //# 01: compile-time error
... The VM gets a compile time error because the constant double 1.0 does not have the triple shift operator. Both of the web backends are not getting that compile time error. @johnniwinther Is there some check for constants that should be applied to the |
The numbers in constants are treated wrt. runtime semantics so I would assume that @fishythefish Do you agree? |
No, I think the CFE should be producing consistent compile-time behavior across the backends here, as we do for other operations. Consider: void main() {
// Error:
/*
const x = 1.0 << 1;
print(x);
*/
print(foo(1.0)); // 2
}
@pragma('dart2js:noInline')
int foo(x) => x << 1; |
FWIW, perhaps this should be part of a larger discussion on web number semantics. My understanding is that, historically, we attempted to conform to the spec/VM wherever possible, and any deviations at runtime were seen as unavoidable compromises in the name of performance or because we can't distinguish between Now that we have separate constant evaluation for web backends and we've revised how the spec/documentation specify number semantics across platforms, maybe we should revisit this? |
For me, it would be confusing to see a compile time error (red squiggles) in your IDE but no error when you actually compile. I think that is what would happen because the analyzer would treat this as an error but if it happens to be in a web project then it would be allowed at compile time. Can the analyzer know what type of project is being viewed and give different errors? |
I don't think we have any mechanism for doing that. And most (perhaps?) code is agnostic; could be compiled with VM or dart2js or DDC. |
@fishythefish Do note that the choice of using runtime number semantics in constant evaluation is not for producing (or not producing) compile-time error but to ensure that constant expressions evaluate to the same value as their runtime equivalent. In this case the omitted compile-time error is just a side effect of that. One could rewrite the program so it doesn't have a compile-time error (in neither CFE nor analyzer) but needs the JavaScript semantics in the constant evaluator to match that of the runtime: const bool isWeb = identical(1, 1.0);
const dynamic a = 1;
const dynamic b = 1.0;
class MyClass {
final int a;
const MyClass(i1, i2) : a = (i1 >>> i2);
}
main() {
print(identical(1, 1.0)); // This will be true at runtime, `isWeb` needs to be true at compile-time.
const MyClass c1 = MyClass(isWeb ? b : a, 1);
MyClass c2 = MyClass(a, 1);
print(identical(c1.a, c2.a));
} |
@johnniwinther I agree that we want to get the same result from compile-time constant evaluation as we do from runtime evaluation, provided that the code compiles. (Side note: we still have some holes in this. For example, Per #45438, which summarizes a discussion from the web team meeting yesterday, I think the consensus is that |
Have we decided who own this? |
I've added https://dart-review.googlesource.com/c/sdk/+/193406 to document the current behavior. |
Uh oh!
There was an error while loading. Please reload this page.
There are new test failures on [tests] Remove triple shift test skips from status files.
The test
is failing on configurations
cc @rakudrama @johnniwinther
The text was updated successfully, but these errors were encountered: