-
-
Notifications
You must be signed in to change notification settings - Fork 670
Automatically export runtime when necessary #2383
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
Conversation
I think make export runtime only when we have lowering managed types. When managed types just lifted |
That's true for most types, except for what we call internrefs. These require a |
yeah. But will be great to don't export full runtime when this doesn't really necessary. |
A bit of a hen and egg problem, in that the exact lifts and lowers are only computed once bindings are generated. Need to check. |
I wonder if it is possible to just run the recompilation? If it requires serious refactoring, but it's probably not worth the hassle. |
Looked into this a little, and figured that checking during compile can become quite expensive. For example, if the lifted type is considered to be a plain object, there might be fields that lift as internref, but recursively checking every field seems wasteful. Would need some caching and whatnot. Recompiling seems wasteful as well, but at least doesn't require a bunch of extra code hmm. |
how about fast approximation checks? If module have exported function which has well known input types that required runtime like |
Approximate checks are about static liftRequiresRuntime(type: Type): bool {
let clazz = type.classReference;
if (!clazz) {
assert(type.signatureReference);
return true; // lifts using __pin
}
let program = clazz.program;
// lifts via memory copy
if (clazz.extends(program.arrayPrototype)) {
return JSBuilder.liftRequiresRuntime(clazz.getArrayValueType());
}
return !(
clazz.extends(program.arrayBufferInstance.prototype) ||
clazz.extends(program.stringInstance.prototype) ||
clazz.extends(program.staticArrayPrototype) ||
clazz.extends(program.arrayBufferViewInstance.prototype)
);
}
static lowerRequiresRuntime(type: Type): bool {
let clazz = type.classReference;
if (!clazz) {
assert(type.signatureReference);
return false; // lowers as Internref
}
// lowers using __new
let program = clazz.program;
return (
clazz.extends(program.arrayBufferInstance.prototype) ||
clazz.extends(program.stringInstance.prototype) ||
clazz.extends(program.arrayPrototype) ||
clazz.extends(program.staticArrayPrototype) ||
clazz.extends(program.arrayBufferViewInstance.prototype)
);
} |
Looks good |
LGTM. Could also add couple simple tests which may prevent some regressions in future? It could be just 2 tests:
|
Tests here are rather clumsy I figured. The test for "don't export runtime" is OKish while not adding much value, while the inverse tests require one file per type with basically a single line of code that then produces a full runtime-enabled fixture that can only be reasonably checked visually and is likely to change frequently due to unrelated changes. Seems to produce more inconvenience than it takes away. |
Ok, could you add that test which doesn't trigger exportRuntime. And just remove explicit |
Also add warning about |
Hmm, won't we still need it for other cases, i.e. where bindings are not desired? |
I guess in this case we could add tip in docs which suggest explicitly export |
Seems like a good goal to make this all explicit, yet gets into breaking change territory I think. Will need to let this sink a little, and suggest to leave further changes to a follow-up. Perhaps there's even more we can remove on this basis. |
No, if it will only deprecation warning |
Right, a deprecation warning for a breaking change we don't yet know for sure whether (or when) to make. Seems too early to me. |
Alright |
Are you OK with the tests? Is a little clumsy I admit :) |
Well, it's better than nothing =) |
Could you sync the pr with main? |
Looks at whether
and if both is the case, automatically enables
--exportRuntime
.