Skip to content

chore: fix JSONEntry Eq and add documentation #61

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

jialinli98
Copy link
Contributor

@jialinli98 jialinli98 commented Aug 1, 2025

Description

Problem*

  1. remove unused functions
  2. add documentation
  3. set Field variable to boolean
  4. add literal validation

closes #53
closes #52
closes #60

Zac's commit to add documentation: f4edfab

Summary*

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@github-project-automation github-project-automation bot moved this to 👀 To Triage in Noir Libraries Aug 1, 2025
@jialinli98 jialinli98 force-pushed the jl/documentation branch 7 times, most recently from b4f1f9b to 0ac4c02 Compare August 4, 2025 08:16
@jialinli98 jialinli98 force-pushed the jl/documentation branch 4 times, most recently from 7dc7bda to e213651 Compare August 6, 2025 05:17
@jialinli98 jialinli98 force-pushed the jl/documentation branch 2 times, most recently from 1d59267 to 614278e Compare August 6, 2025 07:42
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'ACIR Opcodes'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.01.

Benchmark suite Current: a2487c0 Previous: 33bf554 Ratio
parse_json_from_string_JSON16kb_Bench.json/main 1121187 acir_opcodes 1098668 acir_opcodes 1.02
parse_json_from_string_JSON512b_Bench.json/main 38874 acir_opcodes 38179 acir_opcodes 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Circuit Size'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.01.

Benchmark suite Current: a2487c0 Previous: 33bf554 Ratio
parse_json_from_string_JSON16kb_Bench.json/main 1533190 circuit_size 1473490 circuit_size 1.04
parse_json_from_string_JSON512b_Bench.json/main 70594 circuit_size 68763 circuit_size 1.03

This comment was automatically generated by workflow using github-action-benchmark.

@TomAFrench TomAFrench mentioned this pull request Aug 6, 2025
2 tasks
src/json.nr Outdated
Comment on lines 562 to 564
let mut push_transcript = push_transcript;
let mut scan_token = scan_token;
let mut increase_length = increase_length;
Copy link
Member

Choose a reason for hiding this comment

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

These mutable variables are not used.

Comment on lines +461 to +464
// If the current token creates an object or array, subsequent entries will be a child of this object
// i.e. we need to assign them a new identifier so increase `next_identity_value`
next_identity_value = next_identity_value + is_start_of_object_or_array;
std::as_witness(next_identity_value);
Copy link
Member

Choose a reason for hiding this comment

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

next_identity_value is being unconditionally incremented here which doesn't match up with the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think next_identity_value is only incremented when is_start_of_object_or_array is 1, so only at the beginning of objects or arrays.

Copy link
Member

Choose a reason for hiding this comment

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

The comment implies that this should only happen if !preserve_num_entries which isn't the case here.

Copy link
Contributor Author

@jialinli98 jialinli98 Aug 11, 2025

Choose a reason for hiding this comment

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

The comment is correct but misleading. preserve_num_entries is mutually exclusive with is_start_of_object_or_array and is_end_of_object_or_array:
When is_start_of_object_or_array or is_end_of_object_or_array = 1 -> preserve_num_entries = 0
When preserve_num_entries = 1 -> is_start_of_object_or_array = 0, is_end_of_object_or_array = 0
So the if !preserve_num_entries check is redundant.
When preserve_num_entries = 1, both flags are 0, making this a no-op. I'll update the comment

@TomAFrench
Copy link
Member

I've fixed the merge that I busted.

Copy link
Member

@TomAFrench TomAFrench left a comment

Choose a reason for hiding this comment

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

This PR has a lot of innocuous changes (documentation, Eq impl change, etc.) mixed in with unexplained changes to business logic in create_json_entries. The large diff created by all the new documentation and restructuring of code into blocks makes it harder to see what's a meaningful change or just code reorganization.

src/json.nr Outdated
Comment on lines 384 to 407

// 3.5 gates
self.key_data[cast_num_to_u32(entry_ptr)] = new_key_data * create_json_entry;

// 3.5 gates
parent_context_stack[cast_num_to_u32(depth)] = new_context_stack_entry;

// 4.5 gates
self.json_entries_packed[cast_num_to_u32(entry_ptr)] =
JSONEntryPacked { value: new_entry * create_json_entry };
self.key_data[entry_ptr] = new_key_data * create_json_entry as Field;

// Update `entry_ptr` (points to the head of self.key_data and self.json_entries_packed)
// 1 gate
next_identity_value = next_identity_value + is_start_of_object_or_array;
std::as_witness(next_identity_value);
entry_ptr += create_json_entry as u32;

// 1 gate
depth = depth + is_start_of_object_or_array - is_end_of_object_or_array;

// 1 gate
// 2105 + 46.25
// subtotal 66.75?
entry_ptr += create_json_entry;
std::as_witness(entry_ptr);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this is changing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There’s no logic change in this function. Zac reorganized the code to group related lines together while adding comments for clarity. Some lines, like incrementing depth and setting parent_context_stack, were moved up. Let me know if anything still seems off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 To Triage
Development

Successfully merging this pull request may close these issues.

Suspicious Eq impl on JSONEntry invalid literals are accepted in object Remove unused function
3 participants