Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
package org.pkl.core.ast;

import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.member.DefaultPropertyBodyNode;
import org.pkl.core.runtime.VmExceptionBuilder;
Expand Down Expand Up @@ -46,7 +47,8 @@ protected final VmExceptionBuilder exceptionBuilder() {
return new VmExceptionBuilder().withSourceSection(getHeaderSection());
}

public boolean isUndefined() {
return bodyNode instanceof DefaultPropertyBodyNode propBodyNode && propBodyNode.isUndefined();
public boolean isUndefined(VirtualFrame frame) {
return bodyNode instanceof DefaultPropertyBodyNode propBodyNode
&& propBodyNode.isUndefined(frame);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,7 +67,7 @@ public Object executeGeneric(VirtualFrame frame) {

var returnTypeDefaultValue =
returnTypeNode.createDefaultValue(
language, method.getHeaderSection(), method.getQualifiedName());
frame, language, method.getHeaderSection(), method.getQualifiedName());
if (returnTypeDefaultValue != null) {
inferredParent = returnTypeDefaultValue;
ownerNode = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,7 +75,7 @@ public Object executeGeneric(VirtualFrame frame) {

Object defaultReturnTypeValue =
returnTypeNode.createDefaultValue(
language, member.getHeaderSection(), member.getQualifiedName());
frame, language, member.getHeaderSection(), member.getQualifiedName());
if (defaultReturnTypeValue != null) {
inferredParent = defaultReturnTypeValue;
ownerNode = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ExpressionNode;
import org.pkl.core.runtime.*;
Expand All @@ -35,9 +36,9 @@ protected InferParentWithinPropertyNode(SourceSection sourceSection, Identifier
}

@Specialization(guards = "!owner.isPrototype()")
protected Object evalTypedObject(VmTyped owner) {
protected Object evalTypedObject(VirtualFrame frame, VmTyped owner) {
if (isLocalProperty) {
return getLocalPropertyDefaultValue(owner);
return getLocalPropertyDefaultValue(frame, owner);
}

try {
Expand All @@ -51,7 +52,7 @@ protected Object evalTypedObject(VmTyped owner) {
}

@Specialization(guards = "owner.isPrototype()")
protected Object evalPrototype(VmTyped owner) {
protected Object evalPrototype(VirtualFrame frame, VmTyped owner) {
var property =
isLocalProperty
?
Expand All @@ -66,7 +67,7 @@ protected Object evalPrototype(VmTyped owner) {
var typeNode = property.getTypeNode();
if (typeNode == null || typeNode.isUnknownType()) return VmDynamic.empty();

var result = typeNode.getDefaultValue();
var result = typeNode.getDefaultValue(frame);
if (result != null) return result;

// no default exists for this property type
Expand All @@ -76,18 +77,18 @@ protected Object evalPrototype(VmTyped owner) {
}

@Specialization
protected Object eval(@SuppressWarnings("unused") VmDynamic owner) {
protected Object eval(VirtualFrame frame, @SuppressWarnings("unused") VmDynamic owner) {
if (isLocalProperty) {
return getLocalPropertyDefaultValue(owner);
return getLocalPropertyDefaultValue(frame, owner);
}

return VmDynamic.empty();
}

@Specialization
protected Object eval(@SuppressWarnings("unused") VmListing owner) {
protected Object eval(VirtualFrame frame, @SuppressWarnings("unused") VmListing owner) {
if (isLocalProperty) {
return getLocalPropertyDefaultValue(owner);
return getLocalPropertyDefaultValue(frame, owner);
}

assert ownPropertyName == Identifier.DEFAULT;
Expand All @@ -96,23 +97,23 @@ protected Object eval(@SuppressWarnings("unused") VmListing owner) {
}

@Specialization
protected Object eval(@SuppressWarnings("unused") VmMapping owner) {
protected Object eval(VirtualFrame frame, @SuppressWarnings("unused") VmMapping owner) {
if (isLocalProperty) {
return getLocalPropertyDefaultValue(owner);
return getLocalPropertyDefaultValue(frame, owner);
}

assert ownPropertyName == Identifier.DEFAULT;
// return `VmMapping.default`
return VmUtils.readMember(BaseModule.getMappingClass().getPrototype(), ownPropertyName);
}

private Object getLocalPropertyDefaultValue(VmObjectLike owner) {
private Object getLocalPropertyDefaultValue(VirtualFrame frame, VmObjectLike owner) {
assert isLocalProperty;

var member = owner.getMember(ownPropertyName);
assert member != null;

var defaultValue = member.getLocalPropertyDefaultValue();
var defaultValue = member.getLocalPropertyDefaultValue(frame);
if (defaultValue != null) return defaultValue;

// no default exists for this property type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,14 +38,14 @@ public DefaultPropertyBodyNode(
this.typeNode = typeNode;
}

public boolean isUndefined() {
return typeNode == null || typeNode.getDefaultValue() == null;
public boolean isUndefined(VirtualFrame frame) {
return typeNode == null || typeNode.getDefaultValue(frame) == null;
}

@Override
public Object executeGeneric(VirtualFrame frame) {
if (typeNode != null) {
var defaultValue = typeNode.getDefaultValue();
var defaultValue = typeNode.getDefaultValue(frame);
if (defaultValue != null) return defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,11 +45,11 @@ public LocalTypedPropertyNode(
this.unresolvedTypeNode = unresolvedTypeNode;
}

public @Nullable Object getDefaultValue() {
public @Nullable Object getDefaultValue(VirtualFrame frame) {
if (!defaultValueInitialized) {
defaultValue =
typeNode.createDefaultValue(
language, member.getHeaderSection(), member.getQualifiedName());
frame, language, member.getHeaderSection(), member.getQualifiedName());
defaultValueInitialized = true;
}
return defaultValue;
Expand Down
11 changes: 6 additions & 5 deletions pkl-core/src/main/java/org/pkl/core/ast/member/ObjectMember.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ConstantNode;
import org.pkl.core.ast.MemberNode;
Expand Down Expand Up @@ -102,14 +103,14 @@ assert getMemberNode() != null
return callTarget;
}

public boolean isUndefined() {
return getMemberNode() != null && getMemberNode().isUndefined();
public boolean isUndefined(VirtualFrame frame) {
return getMemberNode() != null && getMemberNode().isUndefined(frame);
}

public @Nullable Object getLocalPropertyDefaultValue() {
public @Nullable Object getLocalPropertyDefaultValue(VirtualFrame frame) {
assert isProp() && isLocal();
return getMemberNode() instanceof LocalTypedPropertyNode propertyNode
? propertyNode.getDefaultValue()
? propertyNode.getDefaultValue(frame)
: VmDynamic.empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,11 +64,11 @@ protected Object executeImpl(VirtualFrame frame) {
return typeNode.execute(frame, frame.getArguments()[2]);
}

public @Nullable Object getDefaultValue() {
public @Nullable Object getDefaultValue(VirtualFrame frame) {
if (!defaultValueInitialized) {
defaultValue =
typeNode.createDefaultValue(
VmLanguage.get(this), getSourceSection(), qualifiedPropertyName);
frame, VmLanguage.get(this), getSourceSection(), qualifiedPropertyName);
defaultValueInitialized = true;
}
return defaultValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@
/** Resolves `<type>` to the type's default value in `new <type> { ... }`. */
public final class GetParentForTypeNode extends ExpressionNode {
@Child private UnresolvedTypeNode unresolvedTypeNode;
@Child private TypeNode typeNode;
private final String qualifiedName;

@CompilationFinal @LateInit Object defaultValue;
Expand All @@ -37,14 +38,24 @@ public GetParentForTypeNode(
this.qualifiedName = qualifiedName;
}

private TypeNode getTypeNode(VirtualFrame frame) {
if (typeNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
typeNode = unresolvedTypeNode.execute(frame);
adoptChildren();
}
return typeNode;
}

@Override
public Object executeGeneric(VirtualFrame frame) {
if (defaultValue != null) return defaultValue;

CompilerDirectives.transferToInterpreterAndInvalidate();

var typeNode = unresolvedTypeNode.execute(frame);
defaultValue = typeNode.createDefaultValue(VmLanguage.get(this), sourceSection, qualifiedName);
var typeNode = getTypeNode(frame);
defaultValue =
typeNode.createDefaultValue(frame, VmLanguage.get(this), sourceSection, qualifiedName);

if (defaultValue != null) {
unresolvedTypeNode = null;
Expand Down
Loading
Loading