Skip to content
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

Allow serializing all cranelift-module data structures #6172

Merged
merged 4 commits into from
Apr 21, 2023

Conversation

bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Apr 7, 2023

This allows a Module implementation to serialize it's internal state and deserialize it in another compilation session. For example to implement LTO or to load the module into cranelift-interpreter.

This is the last PR in the series for now. The actual implementation of a module that can be serialized is in cg_clif. I may extract it in the future, but for now these are almost all the changes that need to be made on the cranelift side. The previous PR's in this series are #6169 and #6170.

@bjorn3 bjorn3 requested review from a team as code owners April 7, 2023 10:40
@bjorn3 bjorn3 requested review from fitzgen and removed request for a team April 7, 2023 10:40
@bjorn3 bjorn3 force-pushed the bsc-unwinding-module-serialize2 branch from 6a5811e to 436ffb8 Compare April 7, 2023 10:42

struct ModuleDeclarationsFieldVisitor;

impl<'de> serde::de::Visitor<'de> for ModuleDeclarationsFieldVisitor {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Deserialize impl is based on serde-derive's macro expansion, but it has been cleaned up a lot and modified to run get_names instead of expecting a names field. This should be license technically, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you can use one of the facilities provided by serde, e.g. #[serde(serialize_with = ...)] on the names field, instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When applied to the names field that doesn't give access to the functions and data_objects fields to reconstruct the names field from from what I can tell.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:module labels Apr 7, 2023
@fitzgen fitzgen requested review from bnjbvr and removed request for a team and fitzgen April 10, 2023 19:23
@fitzgen
Copy link
Member

fitzgen commented Apr 10, 2023

Redirecting review to @bnjbvr who has touched these files recently (I've never messed with cranelift-module or cranelift-object)

@bjorn3 bjorn3 force-pushed the bsc-unwinding-module-serialize2 branch from 436ffb8 to 0f1fbe2 Compare April 11, 2023 17:41
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really just happened to touch this file, but I'm really not a code owner of it, sorry. Just a few small comments while skimming the code.

cranelift/jit/src/backend.rs Outdated Show resolved Hide resolved

struct ModuleDeclarationsFieldVisitor;

impl<'de> serde::de::Visitor<'de> for ModuleDeclarationsFieldVisitor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you can use one of the facilities provided by serde, e.g. #[serde(serialize_with = ...)] on the names field, instead?

@bjorn3 bjorn3 force-pushed the bsc-unwinding-module-serialize2 branch from 3760b5f to 6784ad9 Compare April 12, 2023 14:29
@bjorn3
Copy link
Contributor Author

bjorn3 commented Apr 17, 2023

This is ready for review again.

bjorn3 added 4 commits April 21, 2023 10:40
The same information can be retrieved using

ctx.compiled_code().unwrap().code_info().total_size

In addition for Module implementations that don't immediately compile the
given function there is no correct value that can be returned.
This internal name can conflict if a module is serialized and then
deserialized into another module. It also wasn't used by any of the
Module implementations anyway.
This allows a Module implementation to serialize it's internal state and
deserialize it in another compilation session. For example to implement
LTO or to load the module into cranelift-interpreter.
@bjorn3 bjorn3 force-pushed the bsc-unwinding-module-serialize2 branch from 6784ad9 to 32580fb Compare April 21, 2023 10:43
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@bnjbvr bnjbvr added this pull request to the merge queue Apr 21, 2023
Merged via the queue into bytecodealliance:main with commit 91d1d24 Apr 21, 2023
@bjorn3 bjorn3 deleted the bsc-unwinding-module-serialize2 branch April 21, 2023 13:33
afonso360 pushed a commit to afonso360/wasmtime that referenced this pull request Apr 24, 2023
…nce#6172)

* Remove ModuleCompiledFunction

The same information can be retrieved using

ctx.compiled_code().unwrap().code_info().total_size

In addition for Module implementations that don't immediately compile the
given function there is no correct value that can be returned.

* Don't give anonymous functions and data objects an internal name

This internal name can conflict if a module is serialized and then
deserialized into another module. It also wasn't used by any of the
Module implementations anyway.

* Allow serializing all cranelift-module data structures

This allows a Module implementation to serialize it's internal state and
deserialize it in another compilation session. For example to implement
LTO or to load the module into cranelift-interpreter.

* Use expect
eduardomourar pushed a commit to eduardomourar/wasmtime that referenced this pull request Apr 28, 2023
…nce#6172)

* Remove ModuleCompiledFunction

The same information can be retrieved using

ctx.compiled_code().unwrap().code_info().total_size

In addition for Module implementations that don't immediately compile the
given function there is no correct value that can be returned.

* Don't give anonymous functions and data objects an internal name

This internal name can conflict if a module is serialized and then
deserialized into another module. It also wasn't used by any of the
Module implementations anyway.

* Allow serializing all cranelift-module data structures

This allows a Module implementation to serialize it's internal state and
deserialize it in another compilation session. For example to implement
LTO or to load the module into cranelift-interpreter.

* Use expect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:module cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants