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

#381 Move Scope ValueExpressions as parameter of Ref. #411

Merged
merged 7 commits into from
Mar 15, 2024

Conversation

mvanaken
Copy link
Contributor

The Scope value expression makes no sense without a Ref.
The Scope class is removed and the scopeLevel is moved to a parameter for Ref instead.
Changed tests accordingly.

Since the scope level and the limit level are now both available within a Ref, we only have to traverse the ParseGraph once and keep track of both parameters when collecting values. This may have a slight performance gain.
Also note, that previously the ParseValueCache was never used in combination with Scope class. Now, we can check the value of the scopeLevel to determine if we can use the cache or not.

mvanaken and others added 6 commits February 9, 2024 17:38
The scope only makes sense in combination with ref. It has no function
for other value expressions. When it is included within the ref, we can
also make it more efficient, because we can check the scopeDepth while
traversing the parseGraph for the values in a single run.

Co-authored-by: jvdb <[email protected]>
The previous commit contains API breaking changes.
These seem to be redundant, since the limit can be specified using a
variant of `ref` instead.
Also included test for refs with limit 0, which return an empty list
immediately in the new getAllScopedValues. If limit is 0, not need to go
find the correct scope and we can return immediately.
@mvanaken mvanaken requested review from rdvdijk, jvdb and Carly-1 February 10, 2024 16:43
Copy link

codecov bot commented Feb 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d7527dd) 100.00% compared to head (e45c527) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #411   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity      1153      1150    -3     
===========================================
  Files             99        98    -1     
  Lines           1536      1537    +1     
  Branches         157       159    +2     
===========================================
+ Hits            1536      1537    +1     

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

The static import already existed apparently...
@@ -349,7 +348,11 @@ private Shorthand() {}
public static BinaryValueExpression mapRight(final BiFunction<ValueExpression, ValueExpression, BinaryValueExpression> func, final SingleValueExpression leftExpand, final ValueExpression right) { return func.apply(exp(leftExpand, count(right)), right); }

/** @see Bytes */ public static ValueExpression bytes(final ValueExpression operand) { return new Bytes(operand); }
/** @see Scope */ public static ValueExpression scope(final ValueExpression scopedValueExpression, final SingleValueExpression scopeSize) { return new Scope(scopedValueExpression, scopeSize); }

/** @see Ref */ public static NameRef scope(final NameRef operand) { return scope(operand, con(0)); }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we think these shorthands (with the default scope of 0) could be useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, but I'm not sure about the name, maybe scopedRef? But maybe all Refs that have the scopeSize-argument should be called that? I haven't given it much thought yet, but it might be worth considering.

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be a typical use case for a Ref with scope of 0?

Copy link
Contributor Author

@mvanaken mvanaken Feb 19, 2024

Choose a reason for hiding this comment

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

That means the most local scope that is possible, e.g. only values in the current seq.
I think it is the scope level that will be used most, hence the shorthand for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but I'm not sure about the name, maybe scopedRef? But maybe all Refs that have the scopeSize-argument should be called that? I haven't given it much thought yet, but it might be worth considering.

If we would call it scopedRef, then usage would look like scopedRef(ref("name")). I like to keep it scope shorthand, especially since it is now always a ref, so including Ref is redundant to me.

Copy link
Contributor

@jvdb jvdb left a comment

Choose a reason for hiding this comment

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

Looks good. Also worth noting: we've been using this change at Infix for quite a while now and it works really well!

@mvanaken mvanaken linked an issue Feb 12, 2024 that may be closed by this pull request

public ParseState(final ParseGraph order, final ParseValueCache cache, final Source source, final BigInteger offset, final ImmutableList<ImmutablePair<Token, BigInteger>> iterations, final ImmutableList<ParseReference> references) {
public ParseState(final ParseGraph order, final ParseValueCache cache, final Source source, final BigInteger offset, final ImmutableList<ImmutablePair<Token, BigInteger>> iterations, final ImmutableList<ParseReference> references, final int scopeDepth) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A constructor with seven arguments, oof 😅

I don't think we should address this now, but we should discuss this when/if we refactor the ParseGraph implementation.

Copy link
Contributor Author

@mvanaken mvanaken Mar 15, 2024

Choose a reason for hiding this comment

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

I just created #415 , where we are going to move the scopeDepth to the ParseGraph instead. This way, the withOrder method can be used correctly and the ParseState will not hold an incorrect scopeDepth. I developed it in our fork for now, but will create a separate PR here soon.

Copy link
Contributor

@rdvdijk rdvdijk left a comment

Choose a reason for hiding this comment

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

Nice!

@mvanaken mvanaken self-assigned this Feb 19, 2024
@mvanaken mvanaken added this to the 11.0.0 milestone Mar 15, 2024
@mvanaken mvanaken merged commit 16cc984 into master Mar 15, 2024
10 checks passed
@mvanaken mvanaken deleted the #381_scope_to_ref branch March 15, 2024 08:18
@mvanaken mvanaken removed this from the 11.0.0 milestone Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Using scope makes ref inefficient
3 participants