-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Define the resources.json
format from @ResourceIdentifier
s and @pragma('dart2js:resource-identifier')
#55494
Comments
We don't have fully qualified name but be somewhat created using the import uri (aka canonical uri) of the library and the qualified name from within the library (taking getter/setter into account) similar to how we create canonical names for serialization. |
Thanks @rakudrama for the good chat! Some notes:
|
After a discussion offline with @dcharkes, we came up with: A recordedReference consists of
{
"metadata": {
"comment": "Recorded references at compile time and their argument values, as far as known, to definitions annotated with @RecordReference",
"version": "1.6.2-wip+5.-.2.z",
"timestamp": 321432153,
"hashes": {
"noPositions": "dasdsadfasfwagwraf",
"noPositionsNoLoadingUnits": "fdsfdsafdsagh"
}
},
"staticFunctionReferences": [
{
"annotations": [
{
"identifier": {
"uri": "file://lib/_internal/js_runtime/lib/js_helper.dart",
"name": "RecordReference"
},
"fields": {
"_metadata": {
"key": true
}
}
}
],
"definition": {
"identifier": {
"uri": "file://lib/_internal/js_runtime/lib/js_helper.dart",
"parent": "MyClass",
"name": "get:loadDeferredLibrary"
},
"@": {
"uri": "file://lib/_internal/js_runtime/lib/js_helper.dart",
"line": 12,
"column": 67
},
"loadingUnit": "part_15.js"
},
"references": [
{
"arguments": {
"const": {
"positional": {
"0": "lib_SHA1",
"1": false,
"2": 1
},
"named": {
"leroy": "jenkins",
"freddy": "mercury"
}
},
"nonConst": {
"positional": [],
"named": []
}
},
"loadingUnit": "o.js",
"@": {
"uri": "file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 14,
"column": 48
}
},
{
"arguments": {
"const": {
"positional": {
"0": "lib_SHA1",
"2": 0
},
"named": {
"leroy": "jenkins"
}
},
"nonConst": {
"positional": [
"1"
],
"named": [
"freddy"
]
}
},
"loadingUnit": "o.js",
"@": {
"uri": "file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 14,
"column": 48
}
}
]
}
]
} Any thoughts or input @rakudrama? |
This PR adds support invoking `link.dart` hooks. Link hooks can add new assets. Link hooks can transform assets sent to link hook from build hooks. This PR does not yet add support for getting tree-shake information in the link hooks. This is pending on defining the `resources.json` format (dart-lang/sdk#55494). Issue: * #146263 ## Implementation considerations The build hooks could be run before Dart compilation and the link hooks after Dart compilation. (This is how it's done in Dart standalone.) However, due to the way the `Target`s are set up, this would require two targets and serializing and deserializing the `BuildResult` in between these. This would lead to more code but no benefits. Currently there is nothing that mandates running build hooks before Dart compilation. ## Testing * The unit tests verify that the native_assets_builder `link` and `linkDryRun` would be invoked with help of the existing fake. * The native assets integration test now also invokes an FFI call of a package that adds the asset during the link hook instead of the build hook. * In order to keep coverage of the `flutter create --template=package_ffi`, `flutter create` is still run and the extra dependency is added and an extra ffi call is added. (Open to alternative suggestions.)
@mkustermann Asked if there is something we could do to make this format smaller.
The question is whether we should optimize for size. This file will only live on host machines, it's not part of a compiled app bundle. Also, since the contents of this format are filtered on the annotations, maybe they won't grow so big. (If we decide we want to tackle size later, we'd have to go with @mkustermann You mentioned some other AOT treeshaking format in the SDK that is size optimized. Do you have a reference to it? |
RE: hashes: We are looking into more sophisticated caching schemes for depending on part of the
|
This PR adds support invoking `link.dart` hooks. Link hooks can add new assets. Link hooks can transform assets sent to link hook from build hooks. This PR does not yet add support for getting tree-shake information in the link hooks. This is pending on defining the `resources.json` format (dart-lang/sdk#55494). Issue: * flutter#146263 ## Implementation considerations The build hooks could be run before Dart compilation and the link hooks after Dart compilation. (This is how it's done in Dart standalone.) However, due to the way the `Target`s are set up, this would require two targets and serializing and deserializing the `BuildResult` in between these. This would lead to more code but no benefits. Currently there is nothing that mandates running build hooks before Dart compilation. ## Testing * The unit tests verify that the native_assets_builder `link` and `linkDryRun` would be invoked with help of the existing fake. * The native assets integration test now also invokes an FFI call of a package that adds the asset during the link hook instead of the build hook. * In order to keep coverage of the `flutter create --template=package_ffi`, `flutter create` is still run and the extra dependency is added and an extra ffi call is added. (Open to alternative suggestions.)
Last year the concept of resource identifiers was introduced.
Currently, there are some inconsistencies between the format output by the VM and by dart2js.
id
(TheResourceIdentifier.metadata
field in thepackage:meta
annotation.)nonconstant
vsnonConstant
spelling. (Shouldn't a bool just beconstant
? Why use the negation?)The current serialization is centered around loading units, but not all use cases might require loading units.
The current serialization contains source locations and loading units unconditionally, but this is fragile if the format is used for caching. So we should consider making these optional, depending on use case.
The format should be versioned.
A sketch of what the serialization could look like when addressing these issues:
@rakudrama I'd like to understand what the requirements are from dart2js. Then we can figure out if the requirements are compatible with the on for link hooks, so that we can settle on a single format. (Hopefully yes, if we make some things optional. I believe dart2js explicitly wants to use loading units for example.)
I have done a long write-up of the requirements for the
resources.json
in link hooks here:resources.json
format native#1093cc @mosuem @mkustermann @natebosch Feel free to chime in!
cc @johnniwinther Having a concept of fully qualified (unique) names would help us to avoid uri-containerType-container-name, but I believe we have no such thing in Dart?
The text was updated successfully, but these errors were encountered: