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

fix: fix several issues with JS bindings #131

Merged
merged 6 commits into from
Oct 16, 2024
Merged

fix: fix several issues with JS bindings #131

merged 6 commits into from
Oct 16, 2024

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Oct 16, 2024

See commits for details.

Summary by CodeRabbit

  • New Features
    • Introduced a new function to handle asynchronous generator functions.
  • Improvements
    • Enhanced the logging mechanism for better efficiency and clarity.
    • Updated the PositiveFloat struct for custom deserialization logic.
  • Changes
    • Removed the transpile-min target and integrated its functionality into the transpile target.
    • Updated the publish target to depend on the modified transpile target.

sd2k added 5 commits October 16, 2024 14:11
These are just the header row but we parse the rows and emit
them as structured logs anyway.
When I tried to use the existing module within a Webpack project
I found that the generator was continuing with promises and trying
to initialize WebAssembly using them, which obviously failed.
This function seems to work a lot better for some reason, although
I haven't digged into why, exactly.
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces several changes across multiple files. The GitHub Actions workflow configuration is updated to include ripgrep in the installation step. A new function run is added to handle generator functions as promises. The justfile is modified to remove the transpile-min target and integrate its functionality into the transpile target. Changes in the prophet.rs file enhance logging efficiency and enforce stricter type constraints for optimization parameters. Lastly, the PositiveFloat struct is updated to include custom deserialization logic while retaining serialization capabilities.

Changes

File Change Summary
.github/workflows/wasmstan.yml Updated tool parameter to include ripgrep in the taiki-e/install-action@v2 step.
components/js/prophet-wasmstan/run.js Added function run(g) to convert generator functions into promises.
components/justfile Removed transpile-min target; updated transpile to use rg for processing and modified publish to depend on transpile.
crates/augurs-js/src/prophet.rs Refactored emit method for logging; removed emitted_header; updated sigma_obs to PositiveFloat.
crates/augurs-prophet/src/positive_float.rs Removed serde::Deserialize derive; added custom deserialize method for PositiveFloat.

Possibly related PRs

  • feat: add Prophet functionality to augurs-js #125: The changes in the crates/augurs-js/src/prophet.rs file involve enhancements for integrating the Prophet functionality, which may relate to the updates in the .github/workflows/wasmstan.yml file regarding tool installations, particularly if ripgrep is used in the context of processing or optimizing the Prophet model.

🐇 In the meadow, tools now grow,
With ripgrep's might, our code will flow.
Promises bloom where generators play,
As logs are clear, in a simpler way.
From min to transpile, we streamline the quest,
In the land of code, we strive for the best! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
components/js/prophet-wasmstan/run.js (2)

1-9: Appreciate the detailed comment block and consider creating an issue for jco transpile.

The comment block provides valuable context about the function's origin and implementation. It's great to see the attribution to the Stack Overflow source and the explanation of how this function is integrated into the build process.

However, the note about jco transpile not working as expected is concerning.

Would you like me to create a GitHub issue to track the investigation of why the jco transpile generated function didn't work as expected? This could help improve the tooling and potentially remove the need for this custom implementation in the future.


10-16: Approve the implementation with a minor suggestion for readability.

The run function effectively converts a generator function into a promise, handling both synchronous and asynchronous yields. The implementation is concise and follows good practices for working with generators and promises.

For improved readability, consider adding a comment explaining the purpose of the step function and how it processes the generator's yields.

Here's a suggested addition to improve the documentation:

  function run(g) {
+   // `step` function: Recursively processes each yield from the generator
+   // and returns a promise that resolves to the generator's final value
    return Promise.resolve(function step(v) {
      const res = g.next(v);
      if (res.done) return res.value;
      return res.value.then(step);
    }());
  }
crates/augurs-prophet/src/positive_float.rs (1)

51-61: LGTM: Custom deserialization logic is well-implemented, with a minor suggestion.

The custom serde::Deserialize implementation for PositiveFloat is well-designed:

  1. It correctly deserializes the input as an f64.
  2. It uses the try_new method to create a PositiveFloat, ensuring proper validation.
  3. It maps any errors to a custom serde error, preventing invalid states.

This implementation maintains the type's invariants during deserialization, which is crucial for PositiveFloat.

Consider preserving the original error message from TryFromFloatError in the deserialization error for improved debugging. You could modify the error mapping as follows:

Self::try_new(f).map_err(|e| serde::de::Error::custom(format!("Failed to create PositiveFloat: {}", e)))

This change would provide more detailed error information during deserialization, potentially easing debugging in the future.

components/justfile (1)

Line range hint 1-89: Overall assessment of changes to the build process

The modifications to the justfile appear to streamline the build and publish process by consolidating the transpilation and minification steps. While these changes can lead to a more efficient workflow, they also introduce some potential risks that should be addressed:

  1. The new post-processing step in the transpile target adds complexity and a dependency on ripgrep.
  2. The removal of the transpile-min target might have unintended consequences if it performed any crucial operations not captured in the new process.

To ensure the integrity and reliability of the build process, consider the following recommendations:

  1. Document the new build process thoroughly, explaining the rationale behind the changes and any new dependencies (like ripgrep).
  2. Create a comprehensive test suite that verifies the output of the new build process, ensuring it matches expectations in terms of functionality, file size, and content.
  3. Consider containerizing the build environment to ensure consistency across different systems and to manage dependencies like ripgrep more effectively.
  4. Implement a staged rollout of these changes, perhaps maintaining the old build process in parallel for a short period to allow for easy rollback if issues are discovered.
  5. Update any CI/CD pipelines to accommodate the new build process and include checks for the presence of required tools like ripgrep.

By addressing these points, you can mitigate the risks associated with these changes while benefiting from the streamlined build process.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7877fde and e539ae7.

📒 Files selected for processing (5)
  • .github/workflows/wasmstan.yml (1 hunks)
  • components/js/prophet-wasmstan/run.js (1 hunks)
  • components/justfile (1 hunks)
  • crates/augurs-js/src/prophet.rs (4 hunks)
  • crates/augurs-prophet/src/positive_float.rs (2 hunks)
🧰 Additional context used
🪛 Biome
components/js/prophet-wasmstan/run.js

[error] 17-17: Illegal return statement outside of a function

(parse)

🔇 Additional comments (7)
.github/workflows/wasmstan.yml (1)

23-23: LGTM! Verify ripgrep usage in the project.

The addition of ripgrep to the tool installation list is a good improvement. It's a powerful search tool that can enhance the workflow's capabilities.

To ensure this addition is utilized effectively, let's verify its usage in the project:

This will help confirm that ripgrep is being utilized in the project, justifying its inclusion in the workflow.

components/js/prophet-wasmstan/run.js (1)

17-17: ⚠️ Potential issue

Clarify the context for the standalone return statement.

There's a return statement return run(gen); outside of any function context, which is syntactically incorrect in JavaScript. This suggests that this file might be intended to be part of a larger function or module.

Could you please clarify the intended context for this code? If this file is meant to be a module, consider wrapping the entire content in a function or removing this line if it's not needed.

To help understand the usage of this file, let's check for its imports across the project:

🧰 Tools
🪛 Biome

[error] 17-17: Illegal return statement outside of a function

(parse)

crates/augurs-prophet/src/positive_float.rs (1)

5-5: LGTM: Removal of automatic deserialization is appropriate.

The removal of the serde::Deserialize derive macro is a good decision. This change allows for the implementation of custom deserialization logic, which is necessary for types like PositiveFloat that require validation during deserialization. The serde::Serialize derive macro is retained, ensuring that serialization behavior remains unchanged.

components/justfile (2)

77-84: Consider the implications of post-processing the transpiled JavaScript

The new lines in the transpile target introduce a post-processing step using ripgrep (rg) to modify the transpiled JavaScript file. While this approach can be effective for injecting custom code or fixing issues, it has several implications:

  1. It may alter the behavior of the transpiled code in ways that are not immediately obvious.
  2. It introduces a dependency on ripgrep, which might not be available in all build environments.
  3. The use of complex regex patterns in build scripts can be error-prone and challenging to maintain.

Consider the following suggestions:

  1. Document the purpose of this post-processing step to ensure future maintainers understand its importance.
  2. Ensure that ripgrep is installed as part of the build environment setup.
  3. If possible, address the root cause of why this post-processing is necessary. Could the issue be resolved in the original source code or the transpilation process?
  4. If this post-processing is absolutely necessary, consider creating a separate script (e.g., in Python or Node.js) to handle this transformation. This would make the logic easier to test and maintain.

To ensure ripgrep is available in the build environment, you can run:

✅ Verification successful

Dependency Check Passed: ripgrep is installed

ripgrep version 13.0.0 is installed in the build environment as required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if ripgrep is installed
if ! command -v rg &> /dev/null
then
    echo "ripgrep is not installed. Please install it to proceed with the build."
    exit 1
else
    echo "ripgrep is installed. Version: $(rg --version | head -n 1)"
fi

Length of output: 145


89-89: Verify the impact of removing the transpile-min step

The publish target now depends on transpile instead of transpile-min. This change, along with the removal of the transpile-min target (as mentioned in the AI summary), simplifies the build process. However, it's important to ensure that all necessary steps are still being performed.

Please confirm the following:

  1. Does the new transpile target include all necessary optimization or minification steps that were previously in transpile-min?
  2. Are there any differences in the output files (size, content, structure) compared to the previous build process?
  3. Have you tested the published package to ensure it functions correctly with these changes?

To help verify the impact, you can run the following script to compare the output of the old and new build processes:

This script will help identify any significant changes in the build output and ensure that all references to the removed transpile-min target have been updated.

crates/augurs-js/src/prophet.rs (2)

477-478: Great improvement in type safety!

The change from f64 to PositiveFloat for the sigma_obs field is an excellent improvement. It enforces that sigma_obs is always positive, which is likely a domain-specific requirement. The #[tsify(type = "number")] attribute ensures that the TypeScript type remains a number, maintaining compatibility with the JavaScript/TypeScript interface while improving type safety in Rust.


Line range hint 420-453: LGTM! Clarification needed on emitted_header removal.

The refactoring of the emit method improves code clarity and efficiency. The direct iteration over log lines and inline filtering of "Iter" messages are good improvements. However, could you please clarify the intention behind removing the emitted_header field? Was this intentional, and does it affect the logging behavior in any way?

To verify the impact of removing the emitted_header field, please run the following script:

✅ Verification successful

Removal of emitted_header Confirmed

The emitted_header field has been successfully removed from the codebase, and no further usages were found. This refactoring enhances code clarity without affecting logging behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other usages of `emitted_header` in the codebase

rg --type rust 'emitted_header'

Length of output: 31


Script:

#!/bin/bash
# Description: Perform a comprehensive search for any occurrences of `emitted_header`, including case variations and within comments.

rg --type rust --ignore-case 'emitted_header'

Length of output: 45

@sd2k sd2k enabled auto-merge (squash) October 16, 2024 14:45
@sd2k sd2k merged commit 1a360b7 into main Oct 16, 2024
21 checks passed
@sd2k sd2k deleted the js-fixes branch October 16, 2024 14:49
@sd2k sd2k mentioned this pull request Oct 16, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant