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

[move-compiler-v2] Print a better error message for a string without b or x #14687

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

brmataptos
Copy link
Contributor

@brmataptos brmataptos commented Sep 18, 2024

Description

Fixes #14364.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Other (Compiler)

How Has This Been Tested?

Run by hand.

Key Areas to Review

There doesn't seem to be any way to recover from this sort of error. But at least we can help inform people when
they type "foo" instead of b"foo".

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Sep 18, 2024

⏱️ 5h 27m total CI duration on this PR
Job Cumulative Duration Recent Runs
execution-performance / single-node-performance 44m 🟩🟩
forge-compat-test / forge 21m 🟩
rust-move-unit-coverage 20m 🟩
forge-framework-upgrade-test / forge 19m 🟩
rust-move-unit-coverage 17m
rust-move-unit-coverage 17m 🟩
forge-e2e-test / forge 16m 🟩
rust-move-unit-coverage 16m 🟩
general-lints 14m 🟩🟩🟩 (+3 more)
rust-cargo-deny 13m 🟩🟩🟩🟩 (+3 more)
rust-move-unit-coverage 10m 🟩
rust-move-tests 10m 🟩
check 9m 🟩🟩
rust-move-tests 9m 🟩
rust-move-unit-coverage 9m 🟩
rust-move-tests 9m 🟩
rust-move-tests 9m 🟩
rust-move-tests 9m 🟩
test-target-determinator 9m 🟩🟩
rust-move-tests 9m 🟩
execution-performance / test-target-determinator 9m 🟩🟩
check-dynamic-deps 8m 🟩🟩🟩🟩🟩 (+3 more)
rust-doc-tests 5m 🟩
rust-doc-tests 5m 🟩
semgrep/ci 3m 🟩🟩🟩🟩🟩 (+3 more)
rust-move-tests 2m
file_change_determinator 1m 🟩🟩🟩🟩🟩 (+3 more)
file_change_determinator 1m 🟩🟩🟩🟩🟩 (+3 more)
rust-move-tests 1m
permission-check 32s 🟩🟩🟩🟩🟩 (+3 more)
permission-check 32s 🟩🟩🟩🟩🟩 (+3 more)
file_change_determinator 25s 🟩🟩
permission-check 24s 🟩🟩🟩🟩🟩 (+3 more)
permission-check 24s 🟩🟩🟩🟩🟩 (+3 more)
permission-check 7s 🟩🟩
determine-docker-build-metadata 6s 🟩🟩
Backport PR 5s 🟥
permission-check 2s 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.8%. Comparing base (2b208e5) to head (0d30d79).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #14687     +/-   ##
=========================================
- Coverage    59.8%    59.8%   -0.1%     
=========================================
  Files         851      851             
  Lines      207246   207266     +20     
=========================================
+ Hits       124055   124056      +1     
- Misses      83191    83210     +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

┌─ tests/move_check/parser/constants_simple.move:16:29
16 │ const C12: vector<u8> = "<empty>";
│ ^ String literal must begin with b" (for a byte string) or h" (for a hex string)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should break this test up, so that this new blocking (parse) error does not shadow the compile errors being showcased before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let loc = make_loc(file_hash, start_offset, start_offset);
return Err(Box::new(diag!(
Syntax::InvalidByteString,
(loc, "String literal must begin with b\" (for a byte string) or h\" (for a hex string)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hex strings are x"255" according to the Move book, not h"255". Fix here if this was a typo, else, we need to fix the Move book to say we also allow h"255".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


const C10: vector<u8> = b"<empty>";
const C11: vector<u8> = x"deadbeef";
const C12: vector<u8> = "<empty>";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also add one case of strings with some escape characters, e.g., "\"\x48".

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 did better than that, I added a case with a non-UTF character. We'll see how portable that one is.

│ │
│ Invalid call or operation in constant
error: invalid byte string
┌─ tests/folding/constants_simple.move:16:29
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as before: split test to retain old error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@brmataptos brmataptos left a comment

Choose a reason for hiding this comment

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

Sorry for rebase, but PTAL.


const C10: vector<u8> = b"<empty>";
const C11: vector<u8> = x"deadbeef";
const C12: vector<u8> = "<empty>";
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 did better than that, I added a case with a non-UTF character. We'll see how portable that one is.

┌─ tests/move_check/parser/constants_simple.move:16:29
16 │ const C12: vector<u8> = "<empty>";
│ ^ String literal must begin with b" (for a byte string) or h" (for a hex string)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let loc = make_loc(file_hash, start_offset, start_offset);
return Err(Box::new(diag!(
Syntax::InvalidByteString,
(loc, "String literal must begin with b\" (for a byte string) or h\" (for a hex string)")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

│ │
│ Invalid call or operation in constant
error: invalid byte string
┌─ tests/folding/constants_simple.move:16:29
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@brmataptos brmataptos changed the title Print a better error message for a string without b or x [move-compiler-v2] Print a better error message for a string without b or x Sep 20, 2024
Copy link
Contributor

@wrwg wrwg left a comment

Choose a reason for hiding this comment

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

Nice!

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

✅ Forge suite realistic_env_max_load success on fb0b70575652ca305d2a4293bcfd0b08eb79db73

two traffics test: inner traffic : committed: 14431.65 txn/s, latency: 2753.10 ms, (p50: 2700 ms, p70: 2700, p90: 3000 ms, p99: 3300 ms), latency samples: 5487360
two traffics test : committed: 99.97 txn/s, latency: 1646.96 ms, (p50: 1500 ms, p70: 1500, p90: 1700 ms, p99: 11000 ms), latency samples: 1820
Latency breakdown for phase 0: ["QsBatchToPos: max: 0.239, avg: 0.224", "QsPosToProposal: max: 1.094, avg: 1.069", "ConsensusProposalToOrdered: max: 0.316, avg: 0.292", "ConsensusOrderedToCommit: max: 0.423, avg: 0.407", "ConsensusProposalToCommit: max: 0.714, avg: 0.699"]
Max non-epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 0.94s no progress at version 3084990 (avg 0.20s) [limit 15].
Max epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 8.61s no progress at version 3084988 (avg 8.61s) [limit 15].
Test Ok

Copy link
Contributor

✅ Forge suite framework_upgrade success on 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73

Compatibility test results for 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73 (PR)
Upgrade the nodes to version: fb0b70575652ca305d2a4293bcfd0b08eb79db73
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1240.03 txn/s, submitted: 1242.68 txn/s, failed submission: 2.66 txn/s, expired: 2.66 txn/s, latency: 2401.09 ms, (p50: 2400 ms, p70: 2700, p90: 3400 ms, p99: 4500 ms), latency samples: 112080
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1209.56 txn/s, submitted: 1211.10 txn/s, failed submission: 1.54 txn/s, expired: 1.54 txn/s, latency: 2439.65 ms, (p50: 2400 ms, p70: 2400, p90: 3600 ms, p99: 5400 ms), latency samples: 109840
5. check swarm health
Compatibility test for 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73 passed
Upgrade the remaining nodes to version: fb0b70575652ca305d2a4293bcfd0b08eb79db73
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1307.87 txn/s, submitted: 1310.08 txn/s, failed submission: 2.21 txn/s, expired: 2.21 txn/s, latency: 2347.79 ms, (p50: 2100 ms, p70: 2400, p90: 3600 ms, p99: 5400 ms), latency samples: 118560
Test Ok

Copy link
Contributor

✅ Forge suite compat success on 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73

Compatibility test results for 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73 (PR)
1. Check liveness of validators at old version: 25a081116546670e62ca927ba90478de78557056
compatibility::simple-validator-upgrade::liveness-check : committed: 15628.98 txn/s, latency: 2168.43 ms, (p50: 2100 ms, p70: 2200, p90: 2600 ms, p99: 4100 ms), latency samples: 508100
2. Upgrading first Validator to new version: fb0b70575652ca305d2a4293bcfd0b08eb79db73
compatibility::simple-validator-upgrade::single-validator-upgrading : committed: 7727.86 txn/s, latency: 3595.59 ms, (p50: 3700 ms, p70: 4200, p90: 4800 ms, p99: 5300 ms), latency samples: 141680
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 7757.54 txn/s, latency: 4108.97 ms, (p50: 4200 ms, p70: 4400, p90: 6000 ms, p99: 6200 ms), latency samples: 257960
3. Upgrading rest of first batch to new version: fb0b70575652ca305d2a4293bcfd0b08eb79db73
compatibility::simple-validator-upgrade::half-validator-upgrading : committed: 7848.06 txn/s, latency: 3529.82 ms, (p50: 3600 ms, p70: 4100, p90: 4700 ms, p99: 5100 ms), latency samples: 143340
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 7730.12 txn/s, latency: 4123.53 ms, (p50: 4200 ms, p70: 4400, p90: 6000 ms, p99: 6200 ms), latency samples: 254920
4. upgrading second batch to new version: fb0b70575652ca305d2a4293bcfd0b08eb79db73
compatibility::simple-validator-upgrade::rest-validator-upgrading : committed: 12035.79 txn/s, latency: 2264.92 ms, (p50: 2500 ms, p70: 2600, p90: 2700 ms, p99: 2800 ms), latency samples: 209660
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 10612.40 txn/s, latency: 2926.69 ms, (p50: 2600 ms, p70: 2700, p90: 5800 ms, p99: 7700 ms), latency samples: 367760
5. check swarm health
Compatibility test for 25a081116546670e62ca927ba90478de78557056 ==> fb0b70575652ca305d2a4293bcfd0b08eb79db73 passed
Test Ok

@brmataptos brmataptos merged commit 208988e into main Sep 23, 2024
90 of 95 checks passed
@brmataptos brmataptos deleted the brm-issue-14364 branch September 23, 2024 17:44
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.

[compiler] Error message when wrongly using string constants is not useful
3 participants