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

Eagerly check listing/mapping in iterables #752

Merged
merged 7 commits into from
Oct 31, 2024

Conversation

bioball
Copy link
Contributor

@bioball bioball commented Oct 30, 2024

When we introduced lazy listing/mapping typechecking, we widened an existing bug around resolving for-generator variables in #741.

To prevent this bug from being widened, this introduces logic to eagerly evaluate any Listing<V> or Mapping<K, V> found in the iterable.

We're not sure what the best approach is yet to fix the bug. In the meantime, this prevents the existing bug from being any more prevalent than it currently is.

Copy link
Contributor

@holzensp holzensp left a comment

Choose a reason for hiding this comment

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

Sad, but true.

Copy link
Contributor

@holzensp holzensp left a comment

Choose a reason for hiding this comment

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

Sorry, wasn't paying attention when I reviewed that. As discussed off-line; this surfacing another bug, I think close it out and have a go at tracking a marker in AstBuilder.

There is currently a bug around resolving variables within the iterable of a for
generator or spread syntax (apple#741)

Normally, mappings/listings are type-checked lazily. However, this results in the said
bug getting widened, for any object members declared in the iterable.

As a workaround for now, prevent the bug from being any worse by ensuring that these
object members are eagerly typechecked.
@bioball bioball force-pushed the eager-check-iterables branch from f705df9 to c2f7879 Compare October 30, 2024 21:33
@bioball
Copy link
Contributor Author

bioball commented Oct 30, 2024

Okay, this is now using the AstBuilder approach. This works a lot better; take another look!

Copy link
Contributor

@holzensp holzensp left a comment

Choose a reason for hiding this comment

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

No blockers, but I'd profile a bit before adding a member to every object member.

createSourceSection(ctx),
expr,
ctx.QSPREAD() != null,
symbolTable.getCurrentScope().isVisitingIterable());
Copy link
Contributor

Choose a reason for hiding this comment

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

If this scope is not aligned with the above, something went wrong, no?

Suggested change
symbolTable.getCurrentScope().isVisitingIterable());
visitingIterable);

@@ -27,6 +27,9 @@
import org.pkl.core.util.Nullable;

public final class ObjectMember extends Member {

private final boolean isInIterable;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems costly... not worth rolling it into the member's modifiers? Probably worth profiling (both jpkl and native) on large corpora.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Will make this a modifier instead.

@@ -26,6 +26,7 @@
/** A property definition that has a type annotation. */
public final class TypedPropertyNode extends RegularMemberNode {
@Child private DirectCallNode typeCheckCallNode;
private final ObjectMember member;
Copy link
Contributor

Choose a reason for hiding this comment

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

If booleans can be tightly packed, the cost concern in ObjectMember (above) goes away. In that case, I'd also just grab the single boolean here, because a pointer won't be.

@@ -35,9 +38,11 @@ public ObjectMember(
SourceSection headerSection,
int modifiers,
@Nullable Identifier name,
String qualifiedName) {
String qualifiedName,
boolean isInIterable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's quite a lot of extra code throughout, all with a default false case. I don't care much, considering it's likely rather temporary, but might it be worth an extra constructor that defaults this to false?

@bioball bioball force-pushed the eager-check-iterables branch from 1d03f34 to 3e00f3f Compare October 31, 2024 20:32
@bioball bioball force-pushed the eager-check-iterables branch from 76007bb to aa38373 Compare October 31, 2024 20:33
@bioball bioball merged commit 66d751f into apple:main Oct 31, 2024
5 checks passed
@bioball bioball deleted the eager-check-iterables branch October 31, 2024 21:22
bioball added a commit to bioball/pkl that referenced this pull request Nov 4, 2024
This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to apple#752.
bioball added a commit to bioball/pkl that referenced this pull request Nov 4, 2024
This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to apple#752.
bioball added a commit that referenced this pull request Nov 5, 2024
This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to #752.
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