Skip to content

SPICE-0020: Deferred, type-safe references#1354

Open
HT154 wants to merge 11 commits into
apple:mainfrom
HT154:reference-t
Open

SPICE-0020: Deferred, type-safe references#1354
HT154 wants to merge 11 commits into
apple:mainfrom
HT154:reference-t

Conversation

@HT154

@HT154 HT154 commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

SPICE: apple/pkl-evolution#27

Resolves #912

[native-pkl-cli]

@HT154 HT154 force-pushed the reference-t branch 4 times, most recently from 6bd5bfc to 14a7c24 Compare December 6, 2025 08:13
@HT154 HT154 changed the title Add Reference<T> SPICE-0020: Reference<T> Jan 8, 2026
@HT154 HT154 force-pushed the reference-t branch 4 times, most recently from d7663a8 to 09ac8d7 Compare February 9, 2026 17:53
@HT154 HT154 force-pushed the reference-t branch 9 times, most recently from c61ce90 to 0085962 Compare April 17, 2026 00:01
@HT154 HT154 force-pushed the reference-t branch 4 times, most recently from ce06670 to 98a918f Compare May 8, 2026 16:51
@HT154 HT154 changed the title SPICE-0020: Reference<T> SPICE-0020: Deferred, type-safe references May 14, 2026
@HT154 HT154 marked this pull request as ready for review May 15, 2026 19:10

@bioball bioball left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did a first pass!

Comment thread stdlib/ref.pkl Outdated
Comment thread stdlib/ref.pkl Outdated
Comment thread docs/modules/bindings-specification/pages/binary-encoding.adoc Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java Outdated
Comment thread docs/modules/bindings-specification/pages/binary-encoding.adoc Outdated
Comment thread stdlib/ref.pkl Outdated
Comment thread stdlib/ref.pkl Outdated
Comment thread stdlib/ref.pkl Outdated
Comment thread stdlib/ref.pkl Outdated
Comment thread stdlib/ref.pkl Outdated
@HT154 HT154 requested a review from bioball May 21, 2026 01:38
@HT154 HT154 force-pushed the reference-t branch 7 times, most recently from ad9f40a to f141580 Compare May 23, 2026 07:34
@HT154 HT154 force-pushed the reference-t branch 7 times, most recently from 6fe701c to 17a09a0 Compare June 5, 2026 04:03

@bioball bioball left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving to unblock; just some minor comments!

Comment thread stdlib/ref.pkl Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread stdlib/ref.pkl Outdated
@@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No changes here.


/** Returns the class's containing module's class, or this class if it is a module class. */
public PClass getModuleClass() {
return moduleClass != null ? moduleClass : this;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we are returning this we should assert it's a module class.

return domain.equals(that.domain)
&& data.equals(that.data)
&& path.equals(that.path)
&& referentType.equals(that.referentType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PType doesn't implement equals (or hashcode). So this would compare by reference. Not sure this would always be safe.

refInterpolation = "${a.outputs.someListing[1]}"
kInterpolation = "new K { aId = Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).id; bId = Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).id; aProperties = Reference(new D {}, reference#AProperties, new A { name = \"a\"; id = \"some-a-value\" }).outputs; bProperties = Reference(new D {}, reference#BProperties, new B { name = \"b\"; id = \"some-b-value\" }).outputs; aValues { Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.foo; Reference(new D {}, Int | Null, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someListing[0]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, Int, new B { name = \"b\"; id = \"some-b-value\" }).outputs.nonString }; bValues { Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.foo; Reference(new D {}, Null | String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someListing[0]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).outputs.nonInt }; splitUnion = null }"
aValuesJoined = """
org.pkl.core.runtime.VmReference@<addr>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it intended that VmReference has no toString?

// * dereferencing aliases (except for well-known stdlib alias types)
// * flattening unions
// * when moduleClass is supplied, replace PType.MODULE with appropriate PType.Class
// * drop PType.NOTHING, PType.Function, and PType.TypeVariable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mentioned NOTHING is dropped, but normalizeTypes add it to the result.

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.

Reference<T>: Type safe "deferred" references

4 participants