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

Remove MacroRef from user-facing APIs #937

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

popematt
Copy link
Contributor

Issue #, if available:

Follow up to #934 (comment)

Description of changes:

Removes MacroRef from the Expression model and the macro writer APIs so that we don't have to deal with potentially stale references, and so that we can automatically add macro dependencies to the macro table.

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

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 82.60870% with 12 lines in your changes missing coverage. Please review.

Please upload report for BASE (ion-11-encoding@cc4cf2c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...va/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt 75.00% 3 Missing and 8 partials ⚠️
...in/java/com/amazon/ion/impl/macro/MacroCompiler.kt 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             ion-11-encoding     #937   +/-   ##
==================================================
  Coverage                   ?   69.99%           
  Complexity                 ?     6795           
==================================================
  Files                      ?      193           
  Lines                      ?    26876           
  Branches                   ?     4876           
==================================================
  Hits                       ?    18813           
  Misses                     ?     6565           
  Partials                   ?     1498           

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

@@ -117,6 +117,9 @@ class IonReaderContinuableCoreBinary extends IonCursorBinary implements IonReade
// The core MacroEvaluator that this core reader delegates to when evaluating a macro invocation.
private MacroEvaluator macroEvaluator = null;

// The encoding context (macro table) that is currently active.
private EncodingContext encodingContext = null;
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 moved EncodingContext out of MacroEvaluator since the evaluator no longer needs to look up macros by name/address.

@@ -149,6 +149,7 @@ public IonWriter build(Appendable out) {
_Private_IonTextWriterBuilder_1_1 b = fillDefaults();
ManagedWriterOptions_1_1 options = new ManagedWriterOptions_1_1(
false,
true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Whether to invoke macros by name in TDL. See ManagedWriterOptions_1_1.

* Indicates whether a particular [SymbolToken] should be written inline (as opposed to writing as a SID).
* Symbols with unknown text must always be written as SIDs.
*/
private fun SymbolInliningStrategy.shouldWriteInline(symbolKind: SymbolKind, symbol: SymbolToken): Boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ This was unused.

@@ -139,6 +139,7 @@ public IonWriter build(OutputStream out) {
}
ManagedWriterOptions_1_1 options = new ManagedWriterOptions_1_1(
true,
false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Whether to invoke TDL macros by name (rather than by address). See ManagedWriterOptions_1_1.

Comment on lines +519 to +520
body = { string("abc") },
expectedBody = "\"abc\""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Changed this so that it wouldn't have "foo" like so many of the symbols and macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ This ended up being a large change as I ripped out all of the macro names and the MacroEvaluator no longer needs to be set up with a macro table, so I went ahead and converted it to use the expression dsl as well for (IMO) better readability.

@popematt popematt marked this pull request as ready for review September 12, 2024 23:05
@popematt popematt changed the title Implement a topological sort for macros Remove MacroRef from user-facing APIs Sep 16, 2024
@popematt popematt merged commit 047e37a into amazon-ion:ion-11-encoding Sep 17, 2024
18 of 36 checks passed
@popematt popematt deleted the topo-sort-macros branch September 17, 2024 00:25
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