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

refactor(developer): improve the callbacks for kmcmplib 🌋 #12031

Merged
merged 1 commit into from
Aug 3, 2024

Conversation

mcdurdin
Copy link
Member

@mcdurdin mcdurdin commented Jul 26, 2024

This is a significant rework of the callbacks from kmcmplib -- using std::vector and other C++ std classes to remove memory management calls and simplify the WASM bindings.

  • Removes redundant calls for loadFileProc (aka loadFile in the new pattern)
  • Uses C++ classes on the interface side
  • Removes global callbacks from the Javascript side

In preparation for cleanup of compiler messages.

Relates-to: #10866

@keymanapp-test-bot skip

* Removes redundant calls
* Uses C++ classes on the interface side
* Removes global callbacks from the Javascript side

In preparation for cleanup of compiler messages
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Jul 26, 2024
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Jul 26, 2024

User Test Results

Test specification and instructions

User tests are not required

@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S7 milestone Jul 26, 2024
@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-missing User tests have not yet been defined for the PR label Jul 28, 2024
@mcdurdin mcdurdin changed the title refactor(developer): improve the callbacks for kmcmplib refactor(developer): improve the callbacks for kmcmplib 🌋 Jul 28, 2024
@mcdurdin mcdurdin marked this pull request as ready for review July 28, 2024 23:33
@mcdurdin mcdurdin requested a review from darcywong00 as a code owner July 28, 2024 23:33
@mcdurdin mcdurdin requested a review from markcsinclair July 28, 2024 23:38
Copy link
Contributor

@jahorton jahorton left a comment

Choose a reason for hiding this comment

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

I have a few notes from my review so far. I don't understand enough of the changes yet to be comfortable giving an 'approve', but I can at least post these notes up for now.

Comment on lines +276 to +285
const compiler = this;
const wasm_callbacks = Module.WasmCallbackInterface.implement({
message: function(message: KmnCompilerResultMessage) {
compiler.callbacks.reportMessage(mapErrorFromKmcmplib(message.lineNumber, message.errorCode, message.message));
},
loadFile: function(filename: string, baseFilename: string): number[] {
const data: Uint8Array = compiler.callbacks.loadFile(compiler.callbacks.resolveFilename(baseFilename, filename));
return data ? Array.from(data) : null;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to not use arrow functions here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, no, but it's just syntactic sugar right?

Comment on lines +58 to 59
std::copy(bufvec.begin(), bufvec.end(), infile);
infile[sz] = 0; // zero-terminate for safety, not technically needed but helps avoid memory bugs
Copy link
Contributor

Choose a reason for hiding this comment

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

Null-termination after copying the string?

message: function(message: KmnCompilerResultMessage) {
compiler.callbacks.reportMessage(mapErrorFromKmcmplib(message.lineNumber, message.errorCode, message.message));
},
loadFile: function(filename: string, baseFilename: string): number[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was loadFileCallback. Obviously, it's been dramatically simplified from the original.

(I didn't realize this before; only learned via paired review. Documenting this for future reference.)

@darcywong00 darcywong00 modified the milestones: A18S7, A18S8 Aug 2, 2024
Base automatically changed from refactor/developer/kmcmplib-compiler-errors to master August 3, 2024 02:07
@mcdurdin mcdurdin merged commit bc4abad into master Aug 3, 2024
5 checks passed
@mcdurdin mcdurdin deleted the refactor/developer/kmcmplib-compiler-interfaces branch August 3, 2024 02:08
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.81-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants