Comments (3)
I'm curious why this inconsistency became visible :)
FWIW, dart2js does preserve the evaluation order, but will introduce temporary variables if needed to ensure that expressions are evaluated as expected.
import 'dart:js_interop';
extension type Foo._(JSObject o) {
external Foo({int a, int c, int b});
}
@pragma('dart2js:never-inline')
int effect(int i) {
print('see $i');
return i;
}
main() {
Foo(b: effect(0), c: effect(1), a: effect(2));
}
Prints see 0
, see 1
and see 2
in order, even though it does create an object literal with keys in the declaration order a, c, b
in this case.
from sdk.
I saw some devtools code caring about the order of procedure parameters, and it had me looking at some dart2wasm code and making sure it's consistent with every other compiler. So, it's not a real issue anyone filed. :) You can observe this inconsistency with Object.keys
.
The evaluation order is interesting here. I'm not quite sure if we can keep that consistent in every compiler. In dart2wasm, due to the indirection/trampolining, it maintains the same order as the procedure i.e. see 2, see 1, see 0
, because it directly transforms the call to a call to a trampoline whose parameters are ordered according to the procedure. This then has the effect that the arguments are evaluated in the procedure order and not the invocation order. DDC does the same, but because its order is invocation-dependent, it follows dart2js' evaluation order currently i.e. see 0, see 1, see 2
. If we change the order of the keys to correspond to the behavior in dart2js and dart2wasm like in https://dart-review.googlesource.com/c/sdk/+/365924, this would then become see 2, see 1, see 0
.
In general, the order may matter for dictionaries: https://webidl.spec.whatwg.org/#idl-dictionaries.
Dictionaries need to have their members ordered because in some language bindings the behavior observed when passing a dictionary value to a platform object depends on the order the dictionary members are fetched.
So, it seems we're in a weird inconsistency matrix today:
dart2wasm: object key order corresponds to the procedure, and so does the evaluation order
dart2js: object key order corresponds to the procedure, but evaluation order corresponds to the invocation
dartdevc: object key order corresponds to the invocation, and so does the evaluation order
Of course, we could just document this as undefined behavior and recommend users always pass arguments in the order of the parameters.
from sdk.
Ha! That's interesting. I think we can make this consistent among all there, but it requires adding temporaries before the call is made. In essence the dart2js behavior is similar to a kernel transformation of the form:
let t0 = effect(0) in
let t1 = effect(1) in
let t2 = effect(2) in
Foo(a: t2, c: t1, b: t0);
We could do this in a kernel transformation, but I'd be inclined to do it at the codegen stage (DDC already has logic to introduce temporaries and I assume dart2wasm must have a similar mechanism as well).
from sdk.
Related Issues (20)
- analysis_options.yaml "include:" not working for nested folders unless workspace root has a package config for the referenced package HOT 15
- Some javascript error are caught with an opaque JavascriptError type when using wasm HOT 3
- Network paths don't work after 3.4.0 HOT 4
- Intersection type soundness issue HOT 1
- language/nnbd/late/covariant_instance_field_test fails with inlining disabled HOT 4
- `Uint8List.fromList([...])` is ~10x slower than `Uint8List(length)..[0] = #..[1] = #` HOT 8
- [native_assets] Spaces in paths HOT 2
- Unreliable network connection timeout parameters HOT 4
- A simple code that break dart fix HOT 3
- Code completion doesn't suggest enum values when imported aliased HOT 1
- Allow DTD clients to know when a service/method is available/unavailable HOT 6
- [ffi] Varargs should give an error on uint8, int8, uint16, int16 and float HOT 2
- Failures on Expose CommentToken as analyzer public API...[analyzer] Prioritize errors in analysis_options/pubspec errors when running "dart analyze" HOT 1
- ffi/callback_unwind_error_test was flaky, turned Crash on vm-aot-linux-release-arm-qemu HOT 1
- Failures on Expose CommentToken as analyzer public API...[analyzer] HOT 3
- [dart2js] dart2js should do better inlining of `@Native` method stubs
- Docs on how to access and use the test status database HOT 6
- Isolate-local native callables create spurious exception in debugger when returning null HOT 3
- [breaking change] Change the context for the operand of `throw` to `Object`. HOT 1
- Create a method to know if a type is a Built-in type HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.