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 function arguments when called from inside iterable #778

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

bioball
Copy link
Contributor

@bioball bioball commented Nov 4, 2024

This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to #752.

Ideally, when we fix the scoping bug, we also revert this commit.

This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to apple#752.
* <p>If {@code value} is conforming, sets {@code slot} to {@code value}. Otherwise, throws a
* {@link VmTypeMismatchException}.
*/
public abstract Object executeEagerlyAndSet(VirtualFrame frame, Object value);
Copy link
Contributor Author

@bioball bioball Nov 4, 2024

Choose a reason for hiding this comment

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

This method is used when checking a function's arguments.

This node:

function foo(bar: Listing<Int>) =
                  ^^^^^^^^^^^^

We need to add the method because we need to capture the logic of:

  1. Run an eager typecheck
  2. Set that value on the frame.

@bioball bioball force-pushed the eager-check-iterables branch from f9e2984 to a23b8f8 Compare November 4, 2024 21:11
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 necessary, I guess :(

@@ -36,6 +36,7 @@
import org.pkl.core.runtime.VmFunction;

/** A virtual method call. */
@SuppressWarnings("DuplicatedCode")
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this overlap with?

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 various specializations here. Adding just one more line to each method triggered the duplicate code detection warning.

Copy link
Contributor

@stackoverflow stackoverflow 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. We can improve it once we have parse time variables.

@@ -44,7 +44,7 @@ public final class FunctionNode extends RegularMemberNode {
// For VmObject receivers, the owner is the same as or an ancestor of the receiver.
// For other receivers, the owner is the prototype of the receiver's class.
// The chain of enclosing owners forms a function/property's lexical scope.
private static final int IMPLICIT_PARAM_COUNT = 2;
private static final int IMPLICIT_PARAM_COUNT = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should update the docs which still state there are "two implicit arguments".

@bioball bioball merged commit b402463 into apple:main Nov 5, 2024
5 checks passed
@bioball bioball deleted the eager-check-iterables branch November 5, 2024 17:05
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.

3 participants