Skip to content

Implement auto for C++11-style type deduction#8452

Merged
llvm-beanz merged 7 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/auto
May 20, 2026
Merged

Implement auto for C++11-style type deduction#8452
llvm-beanz merged 7 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/auto

Conversation

@llvm-beanz
Copy link
Copy Markdown
Collaborator

Partial implementation of C++11-stlye type deduction added to HLSL under the 202x language mode.

This is still missing special handling for non-deducible special HLSL types. The main one that comes to mind is the type of the ResourceDescriptorHeap and SamplerDescriptorHeap.

I think this PR can stand on its own because using it to infer those special types won't technically break anything it just might expose some bits and pieces of the implementation that we don't want.

This is a partial proof of concept of C++11-stlye type deduction being
added to HLSL under the 202x language mode.

This is still missing special handling for non-deducable special HLSL
types. The main one that comes to mind is the type of the
`ResourceDescriptorHeap` and `SamplerDescriptorHeap`.
Copy link
Copy Markdown
Collaborator

@bob80905 bob80905 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is that this seems to add auto for all language modes, only emitting a warning for < 202x, like C++. But the description suggests that auto is only being added for >= 202x.
Should we, unlike the C++ scenario, emit a hard error for auto < 202x?

@llvm-beanz
Copy link
Copy Markdown
Collaborator Author

My only concern is that this seems to add auto for all language modes, only emitting a warning for < 202x, like C++. But the description suggests that auto is only being added for >= 202x. Should we, unlike the C++ scenario, emit a hard error for auto < 202x?

We followed the same pattern for the groupshared argument feature in 202x, where we exposed it in earlier versions with a warning. The subtle thing that makes this different from say the change in #8453, is that this isn't actually a change to the parsing grammar, it's an additive change to the semantics. The additive change doesn't break anything in existing because we always treated auto as a reserved word.

The benefit of adding this in older language modes is that users can start using it right away without needing to deal with any of the other behavioral changes in 202x, and we can start using it right away in library code and to make library code more readable without forcing users to move to 202x in order to use the libraries.

Copy link
Copy Markdown
Contributor

@tex3d tex3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we test auto with some HLSL-specific object types, plus make sure you can't use it to capture the hidden intermediate resource/sampler type from ResourceDescriptorHeap/SamplerDescriptorHeap used for dynamic resources?

Comment thread tools/clang/test/HLSL/cpp-errors-hv2015.hlsl Outdated
Comment thread tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-no-pointer.hlsl Outdated
Comment thread tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-no-reference.hlsl Outdated
../tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-no-pointer.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-no-reference.hlsl
@llvm-beanz
Copy link
Copy Markdown
Collaborator Author

Shouldn't we test auto with some HLSL-specific object types, plus make sure you can't use it to capture the hidden intermediate resource/sampler type from ResourceDescriptorHeap/SamplerDescriptorHeap used for dynamic resources?

I explicitly called this out in the description:

This is still missing special handling for non-deducible special HLSL types. The main one that comes to mind is the type of the ResourceDescriptorHeap and SamplerDescriptorHeap

I believe this change stands on its own and is fine to go in with the expectation that we'll prevent deducing some objects in a follow-up change. I think the correct design for marking some built-in types as non-deducible is likely a bigger change than just enabling auto so I thought it best to split the two up.

@hekota hekota assigned hekota and unassigned hekota May 18, 2026
Copy link
Copy Markdown
Member

@hekota hekota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-template.hlsl Outdated
../tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-template.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-variable-deduction.h
lsl
I realized none of the other tests covered SPIRV code generation, and
while there were no necessary code changes it is nice to have the
coverage for confidence.
@llvm-beanz llvm-beanz merged commit d9c0a26 into microsoft:main May 20, 2026
13 checks passed
@llvm-beanz llvm-beanz deleted the cbieneman/auto branch May 20, 2026 21:09
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants