Skip to content

shorthands for var and const declarations, and infer types #1289

@dneto0

Description

@dneto0

This is for post-MVP.

We have a principle that expressions be (mostly) strongly typed.
We are also a bit hung up on possibly renaming 'const' and introducing 'constexpr' for closely related concepts. See #1272

I have been hoping to reduce wordiness along the following lines, for code inside a function body:

Before:

   var a : i32 = 12;
   var b : i32 = 13;
   const expr  : i32 = 1+2;
   const acopy : i32 = a;                //   Gets the value stored in a.
   const aptr : ptr<function,i32> =  a;  //   Gets the the pointer to a's storage.

After:

   var a: i32  = 12;   // same as before
   var b = 13;        // type inference
   expr := 1+2;        // introduces new name 'expr' for the evaluation of 1+2.  Infer type.
   acopy := a;         // gets the value stored in a.
   aptr  ~= a;         // gets reference to the storage for a. Think of ~ as rope "tying" you to the storage.

Note that expr, acopy, aptr, are still 'const'. They are not re-assignable.

Also, variables can't store pointers, so there is no desire/need/use-case for var a ~= ...


fix typo var b : = 13; -> var b = 13; per @mehmetoguzderin suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions