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
Inconsistent behavior when modifying during iteration #35605
Comments
We don't generally promise to report all concurrent modifications. In many cases, it's a "best effort" approach, and some compilers remove the concurrent modification checks to improve performance. That does lead to situations like this, where one platform lets a concurrent modification pass, and another catches it. I can't see why the dev-compiler should not throw in this situation. If the compiler somehow rewrites the iteration to not use the iterator, then it probably decided to not insert the modification check in that case. |
This seems to be the output code for a non-release build: define(['dart_sdk'], function(dart_sdk) {
'use strict';
const core = dart_sdk.core;
const _interceptors = dart_sdk._interceptors;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const _root = Object.create(null);
const main = Object.create(_root);
const $remove = dartx.remove;
let JSArrayOfint = () => (JSArrayOfint = dart.constFn(_interceptors.JSArray$(core.int)))();
main.main = function() {
let x = JSArrayOfint().of([1, 2, 3]);
for (let y of x) {
core.print(y);
if (y === 2) {
x[$remove](y);
}
}
};
dart.trackLibraries(/* lots of unimportant stuff */);
// Exports:
return {
main: main
};
}); By the way it has sort of bugged me about Dart that there are two compilers, one for development and a completely different one for release. Wouldn't these kind of issues be alot less common if there was only a single compiler for development and release? |
@matanui159 https://webdev.dartlang.org/tools/dartdevc might provide the info to make it more clear why there are two Dart-to-JS compilers. |
there's another example in #36349 |
I believe this only happens when iterating on a |
@lrhn It appears that the behavior is unspecified sdk/sdk/lib/core/iterator.dart Lines 12 to 13 in 40dfd1b
Should this test in the corelib suite be updated or removed? |
While behavior for iteration in general is unspecified, it's OK for us to decide how the platform libraries should behave. Or at least keep regression tests to show us if we change it inadvertently. I wouldn't remove the test. I believe some compilers might have moved concurrent modification checks into asserts, in which case we should perhaps just always enable asserts for the test. Development compilers should generally not disable checks, they should always be stricter than production mode. |
Info:
"windows_x64"
Given the example code:
On
webdev serve
/dartdevc
it outputs:and it skips 3
On
webdev build
/webdev serve --release
/dart2js
it outputs:This sort of inconsistent behavior is an issue during development as it makes bugs and crashes go pass into production unnoticed (which happened to me while developing/releasing a game).
The text was updated successfully, but these errors were encountered: