Skip to content

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

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

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

Conversation

@HT154
Copy link
Copy Markdown
Contributor

@HT154 HT154 commented Dec 6, 2025

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
Copy link
Copy Markdown
Member

@bioball bioball left a comment

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
external property: String(key == null)?

/// If the access is access via subscript.
external isSubscript: Boolean
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.

This is a binary condition; it's either property or entry access. Do we need two booleans?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is for ease/fluency of use: if a user is writing e.g. a function that transforms a Reference to a String, they may need to know whether each access is a subscript key or property; it may be necessary to check one way or the other and access.isSubscript is more meaningful than !access.isProperty (and vice versa).

Another alternative here is something like this:

type: "property" | "subscript"

But that makes usage sites pretty verbose!

Curious if you have thoughts or alternative suggestions here.

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.

Is two booleans helpful? I suspect most code will look something like this:

if (access.isProperty) ".\(access.property)"
else "[\(access.key)]"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, in the sense that the conditional may need to check if it's a subscript instead and

if (access.isSubscript)

is more legible than

if (!access.isProperty)

and both are preferable to

if (access.type == "subscript")

or

if (access.property == null)

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
Comment thread pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java
@HT154 HT154 force-pushed the reference-t branch 4 times, most recently from 2e0dc69 to aa42423 Compare May 21, 2026 18:40
Copy link
Copy Markdown
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

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

Did another pass!

Comment thread pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java Outdated
Comment thread stdlib/ref.pkl Outdated
external property: String(key == null)?

/// If the access is access via subscript.
external isSubscript: Boolean
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.

Is two booleans helpful? I suspect most code will look something like this:

if (access.isProperty) ".\(access.property)"
else "[\(access.key)]"

Comment thread docs/modules/bindings-specification/pages/binary-encoding.adoc Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/Reference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
Comment thread pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java Outdated
@HT154 HT154 requested a review from bioball May 21, 2026 19:26
@HT154 HT154 force-pushed the reference-t branch 5 times, most recently from 75ac5ff to 8615a4a Compare May 22, 2026 19:31
@HT154 HT154 force-pushed the reference-t branch 2 times, most recently from d4deef5 to af61e13 Compare May 22, 2026 23:06
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

3 participants