Skip to content

Commit b1fe352

Browse files
committed
Updates
1 parent 21776b3 commit b1fe352

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

packages/typegpu/src/data/ref.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export interface ref<T> {
4141
// TODO: Restrict calls to this function only from within TypeGPU functions
4242
export const ref: DualFn<<T>(value: T) => ref<T>> = (() => {
4343
const gpuImpl = (value: Snippet) => {
44+
/**
45+
* Pointer type only exists if the ref was created from a reference (buttery-butter).
46+
*
47+
* @example
48+
* ```ts
49+
* const life = ref(42); // created from a value
50+
* const boid = ref(layout.$.boids[0]); // created from a reference
51+
* ```
52+
*/
4453
const ptrType = createPtrFromOrigin(
4554
value.origin,
4655
value.dataType as StorableData,
@@ -116,35 +125,26 @@ export class RefOperator implements SelfResolvable {
116125
readonly [$internal]: true;
117126
readonly snippet: Snippet;
118127

119-
/**
120-
* Pointer params only exist if the ref was created from a reference (buttery-butter).
121-
*
122-
* @example
123-
* ```ts
124-
* const life = ref(42); // created from a value
125-
* const boid = ref(layout.$.boids[0]); // created from a reference
126-
* ```
127-
*/
128-
readonly ptrType: Ptr | undefined;
128+
readonly #ptrType: Ptr | undefined;
129129

130130
constructor(snippet: Snippet, ptrType: Ptr | undefined) {
131131
this[$internal] = true;
132132
this.snippet = snippet;
133-
this.ptrType = ptrType;
133+
this.#ptrType = ptrType;
134134
}
135135

136136
get [$ownSnippet](): Snippet {
137-
if (!this.ptrType) {
137+
if (!this.#ptrType) {
138138
throw new Error(stitch`Cannot take a reference of ${this.snippet}`);
139139
}
140-
return snip(this, this.ptrType, this.snippet.origin);
140+
return snip(this, this.#ptrType, this.snippet.origin);
141141
}
142142

143143
[$resolve](ctx: ResolutionCtx): ResolvedSnippet {
144-
if (!this.ptrType) {
144+
if (!this.#ptrType) {
145145
throw new Error(stitch`Cannot take a reference of ${this.snippet}`);
146146
}
147-
return snip(stitch`(&${this.snippet})`, this.ptrType, this.snippet.origin);
147+
return snip(stitch`(&${this.snippet})`, this.#ptrType, this.snippet.origin);
148148
}
149149
}
150150

packages/typegpu/src/tgsl/shellless.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export class ShelllessRepository {
5151

5252
const argTypes = (argSnippets ?? []).map((s, index) => {
5353
if (s.value instanceof RefOperator) {
54-
if (!s.value.ptrType) {
54+
if (s.dataType.type === 'unknown') {
5555
throw new WgslTypeError(
5656
`d.ref() created with primitive types must be stored in a variable before use`,
5757
);
5858
}
59-
return s.value.ptrType;
59+
return s.dataType;
6060
}
6161

6262
if (s.dataType.type === 'unknown') {

packages/typegpu/src/tgsl/wgslGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ ${this.ctx.pre}else ${alternate}`;
789789

790790
if (eq.value instanceof RefOperator) {
791791
// We're assigning a newly created `d.ref()`
792-
if (eq.value.ptrType) {
792+
if (eq.dataType.type !== 'unknown') {
793793
throw new WgslTypeError(
794794
`Cannot store d.ref() in a variable if it references another value. Copy the value passed into d.ref() instead.`,
795795
);

0 commit comments

Comments
 (0)