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

Implements make_symbol system macro #868

Merged
merged 3 commits into from
Dec 4, 2024
Merged

Implements make_symbol system macro #868

merged 3 commits into from
Dec 4, 2024

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Dec 3, 2024

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor Author

@zslayton zslayton left a comment

Choose a reason for hiding this comment

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

🗺️ PR Tour 🧭

// the `make_value_writer` method.
/// A writer which can encode nested values.
///
/// Implementors include top-level writers, container writers, and e-expression writers.
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 had this doc comment in my workspace as part of #867 but didn't push it. 🤦 Slipping it into this PR.

Comment on lines 985 to 987
/// Evaluation logic shared by the `make_string` and `make_symbol` macros.
#[derive(Copy, Clone, Debug)]
pub struct MakeStringExpansion<'top, D: Decoder> {
pub struct MakeTextExpansion<'top, D: Decoder> {
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 extracted the logic common to both make_string and make_symbol into its own type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to have separate implementations that extend/wrap this? The only difference is at the end where it constructs either a Symbol or a String. Could you just have two different constructors that set it up to use either
|constructed_text| ValueRef::String(StrRef::from(constructed_text)) or |constructed_text| ValueRef::Symbol(SymbolRef::from(constructed_text)) depending on which one you need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I could do that. I was trying to keep the doc comments for make_string, but I guess that's not worth too much.

context: EncodingContextRef<'top>,
_environment: Environment<'top, D>,
) -> IonResult<MacroExpansionStep<'top, D>> {
let constructed_text = self.arguments.concatenate_text_arguments(context)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ make_string now just calls MakeTextExpansion::concatenate_text_arguments and then massages the resulting &'bump str into a ValueRef.

context: EncodingContextRef<'top>,
_environment: Environment<'top, D>,
) -> IonResult<MacroExpansionStep<'top, D>> {
let constructed_text = self.arguments.concatenate_text_arguments(context)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ The new make_symbol impl calls MakeTextExpansion::concatenate_text_arguments and then massages the resulting &'bump str into a ValueRef.

'first name'
'Hello, world!'
"#,
)
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 are many corner cases untested here (empty args, discarding annotations, etc) as I believe ion-tests covers them.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.86%. Comparing base (1aaa40e) to head (6feb3e6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/lazy/expanded/macro_evaluator.rs 95.65% 1 Missing and 1 partial ⚠️
src/lazy/expanded/template.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #868      +/-   ##
==========================================
+ Coverage   77.84%   77.86%   +0.01%     
==========================================
  Files         136      136              
  Lines       34235    34273      +38     
  Branches    34235    34273      +38     
==========================================
+ Hits        26650    26685      +35     
- Misses       5629     5631       +2     
- Partials     1956     1957       +1     

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

@zslayton zslayton merged commit 81038b6 into main Dec 4, 2024
25 of 33 checks passed
@zslayton zslayton deleted the make-symbol branch December 4, 2024 15:28
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.

2 participants