|
7 | 7 | type Snippet, |
8 | 8 | } from '../../data/snippet.ts'; |
9 | 9 | import { |
| 10 | + isNaturallyEphemeral, |
10 | 11 | isPtr, |
11 | 12 | isWgslData, |
12 | 13 | isWgslStruct, |
@@ -196,39 +197,49 @@ export function createFnCore( |
196 | 197 | // of the argument based on the argument's referentiality. |
197 | 198 | // In other words, if we pass a reference to a function, it's typed as a pointer, |
198 | 199 | // otherwise it's typed as a value. |
199 | | - const ref = isPtr(argType) |
| 200 | + const origin = isPtr(argType) |
200 | 201 | ? argType.addressSpace === 'storage' |
201 | 202 | ? argType.access === 'read' ? 'readonly' : 'mutable' |
202 | 203 | : argType.addressSpace |
| 204 | + : isNaturallyEphemeral(argType) |
| 205 | + ? 'runtime' |
203 | 206 | : 'argument'; |
204 | 207 |
|
205 | 208 | switch (astParam?.type) { |
206 | 209 | case FuncParameterType.identifier: { |
207 | 210 | const rawName = astParam.name; |
208 | | - const snippet = snip(ctx.makeNameValid(rawName), argType, ref); |
| 211 | + const snippet = snip(ctx.makeNameValid(rawName), argType, origin); |
209 | 212 | args.push(snippet); |
210 | 213 | if (snippet.value !== rawName) { |
211 | 214 | argAliases.push([rawName, snippet]); |
212 | 215 | } |
213 | 216 | break; |
214 | 217 | } |
215 | 218 | case FuncParameterType.destructuredObject: { |
216 | | - args.push(snip(`_arg_${i}`, argType, ref)); |
217 | | - argAliases.push(...astParam.props.map(({ name, alias }) => |
218 | | - [ |
| 219 | + args.push(snip(`_arg_${i}`, argType, origin)); |
| 220 | + argAliases.push(...astParam.props.map(({ name, alias }) => { |
| 221 | + // Undecorating, as the struct type can contain builtins |
| 222 | + const destrType = undecorate( |
| 223 | + (argTypes[i] as WgslStruct).propTypes[name], |
| 224 | + ); |
| 225 | + |
| 226 | + const destrOrigin = isPtr(destrType) |
| 227 | + ? destrType.addressSpace === 'storage' |
| 228 | + ? destrType.access === 'read' ? 'readonly' : 'mutable' |
| 229 | + : destrType.addressSpace |
| 230 | + : isNaturallyEphemeral(destrType) |
| 231 | + ? 'runtime' |
| 232 | + : 'argument'; |
| 233 | + |
| 234 | + return [ |
219 | 235 | alias, |
220 | | - snip( |
221 | | - `_arg_${i}.${name}`, |
222 | | - (argTypes[i] as WgslStruct) |
223 | | - .propTypes[name], |
224 | | - ref, |
225 | | - ), |
226 | | - ] as [string, Snippet] |
227 | | - )); |
| 236 | + snip(`_arg_${i}.${name}`, destrType, destrOrigin), |
| 237 | + ] as [string, Snippet]; |
| 238 | + })); |
228 | 239 | break; |
229 | 240 | } |
230 | 241 | case undefined: |
231 | | - args.push(snip(`_arg_${i}`, argType, ref)); |
| 242 | + args.push(snip(`_arg_${i}`, argType, origin)); |
232 | 243 | } |
233 | 244 | } |
234 | 245 |
|
|
0 commit comments