-
-
Notifications
You must be signed in to change notification settings - Fork 72
feat: More comprehensive tracking of possible side effects #2695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 24 commits
fed3aa2
89e4f5d
59ebd23
faee545
5bc6920
6538f87
0d6d656
3b6467e
c797858
2dca023
96cd096
8660054
e9c7882
5c29027
a878f01
bbb2dfc
6d5ee16
731cb19
1bc02b3
c6ee8ec
ad575e8
81a30b1
b58883a
f62da06
df3997a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { $gpuCallable, $internal, $ownSnippet, $resolve } from '../shared/symbol | |
| import type { DualFn, SelfResolvable } from '../types.ts'; | ||
| import { UnknownData } from './dataTypes.ts'; | ||
| import { createPtrFromOrigin, explicitFrom } from './ptr.ts'; | ||
| import { isAlias, type ResolvedSnippet, snip, type Snippet } from './snippet.ts'; | ||
| import { isAlias, type ResolvedSnippet, snip, type Snippet, withDataType } from './snippet.ts'; | ||
| import { isNaturallyEphemeral, isPtr, type Ptr, type StorableData } from './wgslTypes.ts'; | ||
|
|
||
| // ---------- | ||
|
|
@@ -77,7 +77,7 @@ export const _ref = (() => { | |
| if (isPtr(value.dataType)) { | ||
| // This can happen if we take a reference of an *implicit* pointer, one | ||
| // made by assigning a reference to a `const`. | ||
| return snip(value.value, explicitFrom(value.dataType), value.origin); | ||
| return withDataType(explicitFrom(value.dataType), value); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -90,7 +90,12 @@ export const _ref = (() => { | |
| * ``` | ||
| */ | ||
| const ptrType = createPtrFromOrigin(value.origin, value.dataType as StorableData); | ||
| return snip(new RefOperator(value, ptrType), ptrType ?? UnknownData, /* origin */ 'runtime'); | ||
| return snip( | ||
| new RefOperator(value, ptrType), | ||
| ptrType ?? UnknownData, | ||
| /* origin */ 'runtime', | ||
| value.possibleSideEffects, | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -175,14 +180,19 @@ export class RefOperator implements SelfResolvable { | |
| if (!this.#ptrType) { | ||
| throw new Error(stitch`Cannot take a reference of ${this.snippet}`); | ||
| } | ||
| return snip(this, this.#ptrType, this.snippet.origin); | ||
| return snip(this, this.#ptrType, this.snippet.origin, this.snippet.possibleSideEffects); | ||
| } | ||
|
|
||
| [$resolve](): ResolvedSnippet { | ||
| if (!this.#ptrType) { | ||
| throw new Error(stitch`Cannot take a reference of ${this.snippet}`); | ||
| } | ||
| return snip(stitch`(&${this.snippet})`, this.#ptrType, this.snippet.origin); | ||
| return snip( | ||
| stitch`(&${this.snippet})`, | ||
| this.#ptrType, | ||
| this.snippet.origin, | ||
| this.snippet.possibleSideEffects, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -194,8 +204,13 @@ export function derefSnippet(snippet: Snippet): Snippet { | |
| const innerType = snippet.dataType.inner; | ||
|
|
||
| if (snippet.value instanceof RefOperator) { | ||
| return snip(stitch`${snippet.value.snippet}`, innerType, snippet.origin); | ||
| return snip( | ||
| stitch`${snippet.value.snippet}`, | ||
| innerType, | ||
| snippet.origin, | ||
| snippet.possibleSideEffects, | ||
| ); | ||
| } | ||
|
|
||
| return snip(stitch`(*${snippet})`, innerType, snippet.origin); | ||
| return snip(stitch`(*${snippet})`, innerType, snippet.origin, false); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this always an identifier? why not repeat the snippet possibleSideEffects?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it is not let ptr = *(&(array[impureInt()])) |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -180,6 +180,12 @@ export function withDataType(dataType: BaseData | UnknownData, snippet: Snippet) | |||||
| return new SnippetImpl(snippet.value, dataType, snippet.origin, snippet.possibleSideEffects); | ||||||
| } | ||||||
|
|
||||||
| export function withValue(value: string, snippet: Snippet): ResolvedSnippet; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be that
Suggested change
|
||||||
| export function withValue(value: unknown, snippet: Snippet): Snippet; | ||||||
| export function withValue(value: unknown, snippet: Snippet): Snippet { | ||||||
| return new SnippetImpl(value, snippet.dataType, snippet.origin, snippet.possibleSideEffects); | ||||||
| } | ||||||
|
|
||||||
| export function withSideEffects( | ||||||
| possibleSideEffects: boolean, | ||||||
| snippet: ResolvedSnippet, | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.