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

display class of record in custom formatter #242

Merged
merged 6 commits into from
Apr 16, 2024
Merged

display class of record in custom formatter #242

merged 6 commits into from
Apr 16, 2024

Conversation

tiye
Copy link
Member

@tiye tiye commented Apr 1, 2024

make difference of value with/without class more obvious.

Summary by CodeRabbit

  • New Features
    • None.
  • Enhancements
    • Improved performance and readability in data processing functions.
  • Bug Fixes
    • Fixed logic related to equality checks and tuple counts.
  • Refactor
    • Updated package versions for better compatibility and performance.
    • Optimized loop iteration logic in several functions to enhance efficiency.
  • Dependencies
    • Updated dependencies for @calcit/procs and @cirru/writer.ts to newer versions.

@tiye tiye requested a review from a team April 1, 2024 18:12
Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Walkthrough

The updates bring about significant changes across configuration and source files, focusing on version increments, performance optimization, and code readability enhancements. These changes cover updating package versions in Cargo.toml and package.json, refactoring code in ts-src/calcit-data.mts for improved logic and control flow, aiming to enhance software efficiency and maintain reliability through meticulous adjustments.

Changes

File(s) Summary
Cargo.toml, package.json Version bumped from "0.8.45" to "0.8.50" in both files.
package.json Updated @calcit/procs to "0.8.50" and @cirru/writer.ts dependency to "^0.1.5".
ts-src/calcit-data.mts Refactored destructuring assignments in loops for hash function computation, data conversion, and comparisons.

🐇✨
In the land of code and byte,
Where changes gleam in moon's soft light,
We hop through lines, with care, we write,
For speed and grace in our website.
🌟 Each version new, a leap, a flight!
🐾🌿

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2dc419e and 55bc987.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/*.lock
Files selected for processing (6)
  • Cargo.toml (1 hunks)
  • package.json (2 hunks)
  • src/cirru/calcit-core.cirru (1 hunks)
  • ts-src/custom-formatter.mts (2 hunks)
  • ts-src/js-cirru.mts (5 hunks)
  • ts-src/js-list.mts (4 hunks)
Files skipped from review due to trivial changes (1)
  • Cargo.toml
Additional comments not posted (11)
package.json (2)

3-3: The version update is appropriate for the changes described.


26-26: Ensure compatibility with the updated @cirru/writer.ts dependency.

ts-src/custom-formatter.mts (2)

109-110: Optimizing loop iteration by pre-storing the length of the object is a good performance improvement.


184-196: The adjustments in conditional branching for CalcitRecord instances based on the presence of obj.klass enhance the visibility and differentiation of values.

ts-src/js-list.mts (3)

110-111: Using a variable to store the length of the list before iterating through it in the nestedDataInChildren method is a good performance optimization.


297-298: Optimizing the foldl function by pre-storing the length of the list improves performance.


341-342: Pre-storing the length of the list in the foldl_shortcut function is a beneficial performance optimization.

ts-src/js-cirru.mts (3)

85-96: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [76-93]

Refactoring in the to_cirru_edn function, including the use of template literals and optimized array processing, improves performance and readability.


171-181: The introduction of the recordFieldOrder function for consistent sorting of record fields enhances readability and maintainability.


335-335: Ensure the change in how baseClass is initialized in the extract_cirru_edn function effectively improves tuple handling.

src/cirru/calcit-core.cirru (1)

462-462: Ensure the use of identical? instead of &= aligns with the intended behavior for tag matching in tuples. This change shifts from equality to identity checking, which might affect pattern matching outcomes.

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: 12

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 55bc987 and c8ab377.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (8)
  • Cargo.toml (1 hunks)
  • package.json (2 hunks)
  • ts-src/calcit-data.mts (4 hunks)
  • ts-src/calcit.procs.mts (3 hunks)
  • ts-src/custom-formatter.mts (4 hunks)
  • ts-src/js-cirru.mts (5 hunks)
  • ts-src/js-map.mts (4 hunks)
  • ts-src/js-record.mts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • Cargo.toml
  • package.json
  • ts-src/custom-formatter.mts
  • ts-src/js-cirru.mts

Comment on lines 440 to 441
for (let k in a.listeners) {
let f = a.listeners.get(k);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a.listeners.forEach for iterating over listeners for improved readability and performance.

-  for (let k in a.listeners) {
-    let f = a.listeners.get(k);
+  a.listeners.forEach((f, k) => {
     f(v, prev);
-  }
+  });

This change leverages the Map.forEach method, which is more idiomatic for iterating over entries in a Map object. It directly provides access to both the key and value, eliminating the need for a separate get call.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
for (let k in a.listeners) {
let f = a.listeners.get(k);
a.listeners.forEach((f, k) => {
f(v, prev);
});

Comment on lines +764 to +765
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

When destructuring arrays, consider using more descriptive variable names for readability.

-        let k = pairs[idx][0];
-        let v = pairs[idx][1];
+        let [key, value] = pairs[idx];

This change makes the code more readable by clearly indicating the purpose of the variables. It also simplifies the assignment by using array destructuring.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];
let [key, value] = pairs[idx];

Comment on lines +1377 to +1378
let klass = pair[0];
let tag = pair[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the destructuring of the pair into klass and tag is correctly handling cases where lookup_class might return null.

-  let pair = lookup_class(obj);
-  if (pair == null) {
+  let [klass, tag] = lookup_class(obj) || [];
+  if (!klass || !tag) {
     throw new Error(`No class for ${obj?.toString() || JSON.stringify(obj)} to lookup .${p}`);
   }

This change adds a fallback to an empty array when lookup_class returns null, preventing potential runtime errors when attempting to destructure null or undefined. It also checks for the presence of both klass and tag before proceeding, ensuring that the method does not proceed with undefined values.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let klass = pair[0];
let tag = pair[1];
let [klass, tag] = lookup_class(obj) || [];
if (!klass || !tag) {

Comment on lines +191 to +192
let k = pairs[i][0];
let v = pairs[i][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) enhances clarity and may improve performance by avoiding the creation of temporary arrays.

- let [k, v] = pairs[i];
+ let k = pairs[i][0];
+ let v = pairs[i][1];

This change aligns with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[i][0];
let v = pairs[i][1];
let k = pairs[i][0];
let v = pairs[i][1];

Comment on lines +73 to +74
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the toString method of CalcitMap class enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];

Comment on lines +391 to +392
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the nestedDataInChildren method of CalcitSliceMap class enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];
let k = pairs[idx][0];
let v = pairs[idx][1];

Comment on lines +293 to +294
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the hashFunction for CalcitSliceMap enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];

Comment on lines +307 to +308
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the hashFunction for CalcitMap enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];

Comment on lines +461 to +462
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the to_js_data function for CalcitMap and CalcitSliceMap enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];
let k = pairs[idx][0];
let v = pairs[idx][1];

Comment on lines +575 to +576
let k = pairs[idx][0];
let v = pairs[idx][1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring the destructuring assignment to individual assignments for key (k) and value (v) in the _$n__$e_ comparison function for CalcitMap and CalcitSliceMap enhances clarity and may improve performance.

- let [k, v] = pairs[idx];
+ let k = pairs[idx][0];
+ let v = pairs[idx][1];

This change is consistent with the PR's objective to improve readability and performance. Ensure similar changes are consistently applied across the codebase for uniformity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let k = pairs[idx][0];
let v = pairs[idx][1];
let k = pairs[idx][0];
let v = pairs[idx][1];

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c8ab377 and 6abe008.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • calcit/test.cirru (2 hunks)
  • package.json (2 hunks)
  • ts-src/calcit-data.mts (5 hunks)
  • ts-src/calcit.procs.mts (5 hunks)
Files skipped from review as they are similar to previous changes (4)
  • Cargo.toml
  • package.json
  • ts-src/calcit-data.mts
  • ts-src/calcit.procs.mts
Additional comments not posted (2)
calcit/test.cirru (2)

205-205: Ensure the new parameter order in the add-watch function call is correct and aligns with its expected signature.


222-229: The addition of atoms *b and *c, along with the watch functionality and assertions, appears logically sound. Ensure thorough testing is conducted to validate the expected behavior.

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6abe008 and 556fb6b.
Files selected for processing (4)
  • src/bin/cr.rs (3 hunks)
  • src/cli_args.rs (1 hunks)
  • src/codegen.rs (2 hunks)
  • src/codegen/emit_js.rs (2 hunks)
Additional comments not posted (8)
src/codegen.rs (3)

10-10: LGTM! Using AtomicBool for thread-safe global flags is appropriate.


25-30: Consider adding documentation to set_code_gen_skip_arity_check to explain its purpose and the implications of skipping arity checks.


33-35: LGTM! The skip_arity_check function is implemented correctly.

src/cli_args.rs (1)

33-38: LGTM! The addition of the skip-arity-check CLI argument is implemented correctly. Consider enhancing the help text to include guidance on when it might be appropriate to use this flag.

src/bin/cr.rs (3)

33-33: LGTM! The addition of the skip_arity_check field to the CLIOptions struct is clear and follows Rust conventions.


52-52: LGTM! The skip_arity_check field is correctly initialized based on the CLI argument.


161-163: LGTM! The conditional check for skip_arity_check is implemented correctly. Consider adding a comment explaining the purpose of this check for future maintainers.

src/codegen/emit_js.rs (1)

1046-1048: Consider adding a fallback mechanism or configuration option for skip_arity_check to ensure flexibility in arity checking behavior.

While the current implementation allows for skipping arity checks based on the skip_arity_check function, it might be beneficial to provide a way to configure this behavior more granularly. This could involve passing a parameter to gen_js_func or using a configuration setting that can be adjusted based on the needs of different environments or debugging scenarios.

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 556fb6b and 008fae1.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/*.lock
Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • package.json (2 hunks)
  • ts-src/calcit-data.mts (7 hunks)
Files skipped from review as they are similar to previous changes (3)
  • Cargo.toml
  • package.json
  • ts-src/calcit-data.mts

@NoEgAm NoEgAm merged commit fd8b5be into main Apr 16, 2024
2 checks passed
@NoEgAm NoEgAm deleted the record-formatter branch April 16, 2024 05:29
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.

None yet

2 participants