-
Notifications
You must be signed in to change notification settings - Fork 34
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
[Feature Request] Define language features in the specs #102
Comments
I'm going to try to walk through all your points here, but this is a bit tricky because it isn't really a single issue, but a whole host of issues that you're walking through. We need a proper specHLSL has never had a proper specification. We have two reference implementations (FXC & DXC), and we're working on a third (Clang). That is made much more difficult by not having a specification, which is why I started writing one: https://github.com/microsoft/hlsl-specs/tree/main/specs/language It is going to be a lot of work and take a lot of time to get that to be what you're asking for here, so you'll just have to be patient. We should document our grammarI've also been trying to write grammar annotations for new features as we add them so that we can get this right for features moving forward: The MSDN documentation is woefully out of date, and that's seriously unfortunate. KeywordsPrecise
C/C++ KeywordsWe're not going to deprecate We do have a bunch of undocumented but reserved keywords in HLSL (__is_signed, __declspec, __forceinline, auto, catch, const_cast, delete, dynamic_cast, explicit, friend, goto, mutable, new, operator, protected, private, public, reinterpret_cast, static_cast, throw, try, union, and virtual). Additionally there are C/C++ reserved words and keywords that have leaked into HLSL through the implementation of DXC which we don't have well scoped or defined. Built-in typesThe long-term goal for built-in types is to not really make them built-in. We want to be able to represent the HLSL data types in HLSL, and make them proper well-formed data types. Due to bugs in the compiler things get really wonky if you try to define new types with matching names (#5738). We do have a proposal to move built-in types into the Deprecating Old StuffI agree that we need to be better about deprecating old keywords and I appreciate your list here. That's a good list to hit. We've also talked about depreciating the Sooner on the chopping block are:
HLSL PreprocessorIn the future I expect HLSL to adopt the C preprocessor explicitly with only a few additions and no differing behavior. Right now HLSL is in an odd space. FXC's preprocessor wasn't built to the C standard, and DXC's adopted some of the behaviors of the older MSVC preprocessor and some of FXC's behavior. Sans compiler bugs, our goal is to adopt the C specifications preprocessor support, but that won't be codified for a while. String and character typesYea, this is super messy in HLSL, and we need to do something better. We don't really have an answer here yet because DXIL doesn't really support strings either. DeclarationsI don't think we want to deviate from the C grammar for declarations. I get that the C grammar is dated and subjectively unappealing, but our stated goal for HLSL is to become more C/C++-like not less. DocumentationA few times you've made a point about how bad our documentation is. You're right, it is not great. We have a lot of work to do. SummaryI appreciate all the feedback here and the time you took to put this together. My high level takeaways here are:
Besides these points I don't think there is a specific and actionable request here that we can work on other than continuing to work on the things we're already doing. Since I don't think there is anything specific to track here, I'm going to close this issue as not planned. If I missed something specific please let me know. |
Is your feature request related to a problem? Please describe.
The best grammar documentation available for HLSL is MSDN documentation. However, currently it is incomplete and outdated.
Describe the solution you'd like
A complete or partial grammatical definition of the language. Clarification/comprehensive list of keywords, identifiers with special meaning, built-in types, and functions. As much as HLSL is similar to C++, it is crucial to highlight the differences. Grammar for most important statements - primarily expanded declarations syntax, should be included in the standard.
Keywords, intrinsics, and identifiers with special meaning
It's important to formalize this because it determines whether stuff like this is allowed:
Identifiers with special meaning and built-in types act like regular identifiers, keywords are reserved for specific contexts.
I've noticed an inconsistency (according to MSDN) on what is considered a keyword, what is considered a builtin-type/intrinsic, and what is considered an "identifier with special meaning" (official C++ term
[tab:lex.name.special]
). The general trend is thatsnake_case
identifiers are keywords, andCamelCase
identifiers are built-in types. This is just a rule of thumb though. Here is a simple test program on Compiler Explorer that checks the kind of built-in type (identifier with special meaning).I propose the following formalization of identifier/builtin-type/keyword classifications:
Distinguish between keywords and identifiers with special meaning. Consider built-ins a subcategory of the latter.
Keywords:
Reserved C++ keywords:
Identifiers with special meaning
Built-in types
I propose that
precise
is made a keyword just like the rest of the storage class specifiers. In this way, "identifiers with special meaning" category does not have to exist.Keyword
unsigned
is redundant and an outlier. HLSL has built-in sign-qualified types, signess modifier applied onint
types yields an already existing built-in types.Additionally for the sake of consistency vector, matrix, string, min16float, min10float, min16int, min12int, min16uint, uint64_t, int64_t, float16_t, uint16_t, int16_t, should also be made keywords.
I do acknowledge that these proposed changes do not make much sense from the practical point of view and might as well be left unimplemented however I believe it is important to formalize this in a language and do it consistently rather than rely on already existing DXC grammar implementation.
Deprecated keywords
Deprecated special meaning identifiers:
Deprecated keywords and identifiers should be marked as so in the specs and removed in the subsequent HLSL releases.
Preprocessor
HLSL's current preprocessor is somewhat inconsistent with C++'s.
This is a compiler bug, but the preprocessor's behavior should be clarified in the standard.
String and char-literals
The grammar of string and char literals differs from the C++ grammar. HLSL does not allow encoding prefixes, multichar literals, and raw string literals.
Declarations grammar
Currently, C-inherited (static, extern, unsigned) modifiers can appear after the type inside variable declarations. Other modifiers cannot. Mandate that all modifiers must appear before the type.
Propose a grammar notation convention and include the grammar for the HLSL declarations.
Example: The standard notation for C++(Chomsky normal form):
Example: An already existing MSDN documentation.
Built-in types/functions
Provide a category-sorted documentation of all available intrinsic types and functions.
The comprehensive and complete list of currently available intrinsics can be found here in the DXC implementation.
The text was updated successfully, but these errors were encountered: