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)
- [DAP] `--pause-isolates-on-start` and `--pause-isolates-on-exit` flags are not set for attach workflows HOT 4
- [DAP] `--pause-isolates-on-start` flag is not respected for web refreshes HOT 1
- Switch Expressions conversion assist should use logical-or when multiple cases share a body HOT 1
- [Wildcard Variables] Update `UNUSED_FIELD` reporting
- `Import library with prefix` assist HOT 1
- Dart fuzzer found a crash in Assembler::AddressCanHoldConstantIndex on debug ARM builds
- Failures on [tests] Use asyncStart/asyncEnd for two language tests HOT 3
- CFE macros, annotations, file offsets and file uri
- [CP] Revert "[vm, gc] Incremental compaction, take 2." HOT 1
- [WASM] RuntimeError: illegal cast HOT 5
- Add full support for service ID zones
- System for making changes to package:macros without breaking the flutter engine roll HOT 4
- Macro does not execute if the annotation is a const variable reference.
- CompileError: WebAssembly.compileStreaming(): Requested length 14592 for array.new_fixed too large, maximum is 10000 @+692248 HOT 1
- [CP] [dart2wasm] Fix array.new_fixed calls with too large size HOT 4
- [CP] Release DevTools 2.36.0
- Unexpected non-zero index in CalculateElementAddressInstr
- Removed unnecessary dependencies from `ddc_stable_test` and `ddc_canary_test`
- Divergent execution with Float32x4 HOT 4
- Macros: Static types are broken HOT 4
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.