Commit Graph

44 Commits

Author SHA1 Message Date
Jim Blandy
89bed99bcc Forbid returning pointers and atomics from functions.
Introduce a new `TypeFlags::CONSTRUCTIBLE` flag, corresponding to
WGSL's "constructible types". Set this on the appropriate types.
Check for this flag on function return types.
2022-06-01 14:20:55 -07:00
Connor Fitzgerald
ad28396851 Implement Binding Arrays (#1845) 2022-04-19 14:23:07 -04:00
Teodor Tanasoaia
7ce98dcc7d Make use of new language features (#1841)
* use strip_prefix

* make fn const (resolving TODO)

* make use of nested OR patterns in match arms

* warn on clippy::missing_const_for_fn

* constify functions

* ignore clippy::missing_const_for_fn for into_inner functions
2022-04-17 03:39:54 -04:00
Dzmitry Malyshau
9b89c5fa89 Improve error messages about address space 2022-02-02 12:42:29 -05:00
Dzmitry Malyshau
2ddc8d1929 Rename StorageClass to AddressSpace 2022-01-31 16:25:06 -05:00
Dzmitry Malyshau
d468e1512f Introduce BadHandle error 2022-01-14 12:44:27 -05:00
Dzmitry Malyshau
ab02ec7904 layouter: rich and careful errors 2022-01-14 12:44:27 -05:00
Dzmitry Malyshau
a069361bf4 validate: check local var type to be in range 2022-01-14 12:44:27 -05:00
Dzmitry Malyshau
fee69774a3 validate: check function argument type to be in range 2022-01-14 12:44:27 -05:00
Dzmitry Malyshau
a4ea9ce68d typifier: check local vars, global vars, and function arguments to exist 2022-01-14 12:44:27 -05:00
Jim Blandy
cc930180d9 Tighten checks on pointers to unsized values, and pointer arguments.
Pointers should not be `DATA`: they can never be stored in anything. (Function
arguments are not storage; they're like `let` bindings.)

Un-`SIZED` values may only live in the `Storage` storage class, so creating
pointers to them in other storage classes is meaningless.

The `ARGUMENT` flag should be set only on pointers in those storage classes that
are permitted to be passed to functions.

See comments in code for details.

Fixes #1513.
2021-11-18 17:39:56 -05:00
Jim Blandy
ce18eba695 Check that stores are permitted by the pointer's storage access.
Fixes #1533.
2021-11-16 23:40:56 -05:00
Boris-Chengbiao Zhou
1dcde48d09 [valid] Check that switches have a default case (#1529)
From the WGSL spec: "Each switch statement must have exactly one default clause."
2021-11-15 00:07:55 +00:00
Dzmitry Malyshau
323999fcb9 Fix span includes into function validation (#1500) 2021-10-31 23:58:58 -04:00
João Capucho
0458f0a404 [valid] Check that the last switch case isn't falltrough (#1485) 2021-10-26 21:33:49 -04:00
João Capucho
63dbd38edc Make default a switch case (#1477)
* Make default a switch case

Previously the default case of a switch statement was encoded as a block
in the statement but the wgsl spec defines it in such a way that the
default case ordering matters.

* [spv-out] Support for the new switch IR

* [dot-out] Use different labels for default cases
2021-10-26 13:31:54 -04:00
Jim Blandy
5cf11ab734 Make use of AddSpan and MapErrWithSpan conditional.
This avoids warnings in default-feature builds, like `cargo test -p naga`.
2021-10-25 19:35:59 +01:00
Alex Es
ec001c3ead Use span information in analyzer errors (proof of concept) (#1470)
* Proof-of-concept for adding spans to validation errors.

Still missing: actually printing the damn stuff.

* Emit errors from analyzer in the CLI.

TODO: tests, I guess!

* Simplification refactoring: avoid avoiding allocations so vehemently.

* Mask helper traits with `as _`.

* Fix block iterator throwing up when span feature is disabled.

* Nest use statements.

* Add basic docs.

* Axe AddSpanResult.
2021-10-24 22:47:03 -04:00
Igor Shaposhnik
3e1244c5cb Make shader validation under a separate feature (#1437) 2021-10-05 15:11:32 -04:00
Dzmitry Malyshau
21324b8fea Update WGSL grammar for pointer access. (#1312)
* Update WGSL grammar for pointer access.

Comes with a small test, which revealed a number of issues in the backends.

* Validate pointer arguments to functions to only have function/private/workgroup classes.

Comes with a small test. Also, "pointer-access.spv" test is temporarily disabled.
2021-09-27 18:49:28 -04:00
Jim Blandy
f3ea2130a4 [wgsl-in]: Correctly compare pointer types.
Treat `TypeInner::ValuePointer` and `TypeInner::Pointer` as equivalent by
converting them to a canonical form before comparison.

Support `ValuePointer` in WGSL type output.

Fixes #1318.
2021-09-27 16:01:43 -04:00
Jim Blandy
944a693ae5 Use UniqueArena for types.
Ensure that each distinct type occurs only once in `Module::types`, so that we
can use `Eq` on `Type` or `TypeInner` for type equivalence, without being
confused by differing `Handle<Type>` values that point to identical types.

This removes a number of duplicate types from the ir snapshots.

Fixes #1385.
2021-09-27 15:17:41 -04:00
João Capucho
d5fc05e8a4 Allow unsigned integers in switch 2021-09-21 17:16:51 -04:00
João Capucho
98944bb7a6 Track finished across compound statements 2021-09-20 12:00:22 -04:00
Dzmitry Malyshau
67dd604b0c [wgsl-out] atomic load/stores, [glsl-out] revert the prefix 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
1121a815ac Separate enum for atomic binary operations 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
bc4576c0a2 Make atomic operations to be statements 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
8c371e8063 Atomic expressions, support in backends except HLSL and the validator. 2021-08-10 21:48:02 -04:00
pyrotechnick
2f516c0932 [wgsl] Storage buffer/texture access (#1142)
* Resurrect texture_storage_* tests
* Test parsing of `var<storage,write>`
* Default storage textures to READ
* Restore default features
* Fix glsl/hlsl/msl/spv front and back ends
* Add missing test outputs
* All-around fixes for the storage access

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
2021-07-28 01:47:18 -04:00
João Capucho
7df4a52af9 [valid] Handle texture/sampler function argument 2021-07-01 11:19:28 -04:00
Dzmitry Malyshau
064263272c Refactor control flow validation, allow break in switches 2021-06-22 00:24:50 -04:00
Jim Blandy
548cde4701 Clear Validator::valid_expression_list before validating each function.
If validation fails, `Validator` may be left with entries in
`valid_expression_list` and `valid_expression_set`. The validator does clear the
set before examining a function's body, but not the list, which means a
long-lived `Validator` could accumulate an unbounded amount of garbage in the
list.

(Minor cleanup: use structural update syntax where appropriate.)
2021-06-21 14:53:20 -04:00
Jim Blandy
1d0b3f3a75 Functions can take pointers to unsized structs, but no other unsized types. 2021-06-18 20:44:07 -04:00
Jim Blandy
48363fcef1 Don't accept unsized types as function arguments. 2021-05-26 12:27:29 -04:00
Dzmitry Malyshau
9fe75ed7f1 Barriers 2021-05-04 22:16:24 -04:00
Dzmitry Malyshau
4a5ff9a053 Validate that used expressions are emitted 2021-04-26 09:59:54 -04:00
Dzmitry Malyshau
e87f57d82c Fix expression validation check 2021-03-25 09:32:55 -04:00
Dzmitry Malyshau
a0b5717fed Validate image stores 2021-03-24 12:32:32 -04:00
Dzmitry Malyshau
7a246f6a14 Validate image queries and valid shader stages for derivatives 2021-03-24 12:32:32 -04:00
Dzmitry Malyshau
970b77abaf Make type a part of ExpressionInfo 2021-03-22 15:17:00 -04:00
Dzmitry Malyshau
1d3f2bbdb1 Merge FunctionAnalysisError into FunctionError 2021-03-22 15:17:00 -04:00
Dzmitry Malyshau
1ddea0fdbb Validate layouts 2021-03-21 22:27:32 -04:00
Dzmitry Malyshau
e3ae5904ba Move AnalysisFlags into ValidationFlags, add bits for expressions and blocks 2021-03-20 22:25:49 -04:00
Dzmitry Malyshau
c992e638fe Move all the validation into a separate meta-module 2021-03-20 22:25:49 -04:00