diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-04-11 16:18:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-11 16:18:29 -0700 |
| commit | baf194e7456ba4568dcf11249896af35b3ce18cc (patch) | |
| tree | f75e20db450100d41bfa9c384a8bab0fdc28a749 /source/slang/type-defs.h | |
| parent | 6322983fa4dc84ef1e9dd8fad54d4c1580436e67 (diff) | |
Introduce an IR-level type system (#481)
* Introduce an IR-level type system
Up to this point, the Slang IR has used the front-end type system to represent types in the IR.
As a result (but ultimately more importantly) the IR representation of generics and specialization has used AST-level concepts embedded in the IR.
For example, to express the specialization of `vector<T,N>` to a concrete type `float` for `T`, we needed an IR operation that could represent the specialization, with operands that somehow represented the type argument `float`.
The whole thing was very complicated.
The big idea of this change is to introduce a new representation in which types in the IR are just ordinary instructions, so that using them as operands makes sense. The hierarchy of IR types closely mirrors the AST-side hierarchy for now, and that will probably be something we should maintain going forward.
In order to make these changes work, though, I also had to do major overhauls of things like the way substitutions are performed, how we check interface conformances, the way lookup through interface types is done, etc. etc. This is a big change, and unfortunately any attempt to summarize it in the commit message wouldn't do it justice.
* Fix 64-bit build warning
* Fix up some clang warnings/errors
Diffstat (limited to 'source/slang/type-defs.h')
| -rw-r--r-- | source/slang/type-defs.h | 111 |
1 files changed, 24 insertions, 87 deletions
diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index 433c5e15c..14e9c0066 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -42,20 +42,6 @@ protected: ) END_SYNTAX_CLASS() -// The type of a reference to a basic block -// in our IR -SYNTAX_CLASS(IRBasicBlockType, Type) -RAW( -public: - virtual String ToString() override; - -protected: - virtual bool EqualsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; -) -END_SYNTAX_CLASS() - // A type that takes the form of a reference to some declaration SYNTAX_CLASS(DeclRefType, Type) DECL_FIELD(DeclRef<Decl>, declRef) @@ -107,9 +93,20 @@ protected: ) END_SYNTAX_CLASS() -// Base type for things we think of as "resources" -ABSTRACT_SYNTAX_CLASS(ResourceTypeBase, DeclRefType) +// Base type for things that are built in to the compiler, +// and will usually have special behavior or a custom +// mapping to the IR level. +ABSTRACT_SYNTAX_CLASS(BuiltinType, DeclRefType) +END_SYNTAX_CLASS() + +// Resources that contain "elements" that can be fetched +ABSTRACT_SYNTAX_CLASS(ResourceType, BuiltinType) + // The type that results from fetching an element from this resource + SYNTAX_FIELD(RefPtr<Type>, elementType) + + // Shape and access level information for this resource type FIELD(TextureFlavor, flavor) + RAW( TextureFlavor::Shape GetBaseShape() { @@ -123,12 +120,6 @@ ABSTRACT_SYNTAX_CLASS(ResourceTypeBase, DeclRefType) ) END_SYNTAX_CLASS() -// Resources that contain "elements" that can be fetched -ABSTRACT_SYNTAX_CLASS(ResourceType, ResourceTypeBase) - // The type that results from fetching an element from this resource - SYNTAX_FIELD(RefPtr<Type>, elementType) -END_SYNTAX_CLASS() - ABSTRACT_SYNTAX_CLASS(TextureTypeBase, ResourceType) RAW( TextureTypeBase() @@ -182,13 +173,13 @@ RAW( ) END_SYNTAX_CLASS() -SYNTAX_CLASS(SamplerStateType, DeclRefType) +SYNTAX_CLASS(SamplerStateType, BuiltinType) // What flavor of sampler state is this FIELD(SamplerStateFlavor, flavor) END_SYNTAX_CLASS() // Other cases of generic types known to the compiler -SYNTAX_CLASS(BuiltinGenericType, DeclRefType) +SYNTAX_CLASS(BuiltinGenericType, BuiltinType) SYNTAX_FIELD(RefPtr<Type>, elementType) RAW(Type* getElementType() { return elementType; }) @@ -206,14 +197,18 @@ SIMPLE_SYNTAX_CLASS(HLSLStructuredBufferType, HLSLStructuredBufferTypeBase) SIMPLE_SYNTAX_CLASS(HLSLRWStructuredBufferType, HLSLStructuredBufferTypeBase) // TODO: need raster-ordered case here -SIMPLE_SYNTAX_CLASS(UntypedBufferResourceType, DeclRefType) +SIMPLE_SYNTAX_CLASS(UntypedBufferResourceType, BuiltinType) SIMPLE_SYNTAX_CLASS(HLSLByteAddressBufferType, UntypedBufferResourceType) SIMPLE_SYNTAX_CLASS(HLSLRWByteAddressBufferType, UntypedBufferResourceType) +SIMPLE_SYNTAX_CLASS(RaytracingAccelerationStructureType, UntypedBufferResourceType) SIMPLE_SYNTAX_CLASS(HLSLAppendStructuredBufferType, HLSLStructuredBufferTypeBase) SIMPLE_SYNTAX_CLASS(HLSLConsumeStructuredBufferType, HLSLStructuredBufferTypeBase) -SYNTAX_CLASS(HLSLPatchType, DeclRefType) +SIMPLE_SYNTAX_CLASS(RayDescType, BuiltinType) +SIMPLE_SYNTAX_CLASS(BuiltInTriangleIntersectionAttributesType, BuiltinType) + +SYNTAX_CLASS(HLSLPatchType, BuiltinType) RAW( Type* getElementType(); IntVal* getElementCount(); @@ -231,7 +226,7 @@ SIMPLE_SYNTAX_CLASS(HLSLLineStreamType, HLSLStreamOutputType) SIMPLE_SYNTAX_CLASS(HLSLTriangleStreamType, HLSLStreamOutputType) // -SIMPLE_SYNTAX_CLASS(GLSLInputAttachmentType, DeclRefType) +SIMPLE_SYNTAX_CLASS(GLSLInputAttachmentType, BuiltinType) // Base class for types used when desugaring parameter block // declarations, includeing HLSL `cbuffer` or GLSL `uniform` blocks. @@ -272,64 +267,6 @@ protected: ) END_SYNTAX_CLASS() -// A type that has a rate qualifier applied. Conceptually `@R T` where `R` -// represents a rate, and `T` represents a data type. -SYNTAX_CLASS(RateQualifiedType, Type) - - // The rate `R` at which the value is computed/stored - SYNTAX_FIELD(RefPtr<Type>, rate); - - // The underlying data type `T` of the value - SYNTAX_FIELD(RefPtr<Type>, valueType); - -RAW( - virtual Slang::String ToString() override; - -protected: - virtual bool EqualsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual RefPtr<Val> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; - virtual int GetHashCode() override; - ) -END_SYNTAX_CLASS() - -// A representation of the `ConstExpr` rate, to be used -// in defining `@ConstExpr T` for particular data types `T` -SYNTAX_CLASS(ConstExprRate, Type) - -RAW( - virtual Slang::String ToString() override; - -protected: - virtual bool EqualsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual RefPtr<Val> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; - virtual int GetHashCode() override; - ) -END_SYNTAX_CLASS() - -// The effective type of a variable declared with `groupshared` storage qualifier. -// -// TODO: this should be converted to a `GroupSharedRate`, which then gets used -// in conjunction with `RateQualifiedType`. -SYNTAX_CLASS(GroupSharedType, Type) - SYNTAX_FIELD(RefPtr<Type>, valueType); - -RAW( - virtual ~GroupSharedType() - { - } - - virtual Slang::String ToString() override; - -protected: - virtual bool EqualsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; - ) - -END_SYNTAX_CLASS() - // The "type" of an expression that resolves to a type. // For example, in the expression `float(2)` the sub-expression, // `float` would have the type `TypeType(float)`. @@ -389,11 +326,11 @@ protected: END_SYNTAX_CLASS() // The built-in `String` type -SIMPLE_SYNTAX_CLASS(StringType, DeclRefType) +SIMPLE_SYNTAX_CLASS(StringType, BuiltinType) // Base class for types that map down to // simple pointers as part of code generation. -SYNTAX_CLASS(PtrTypeBase, DeclRefType) +SYNTAX_CLASS(PtrTypeBase, BuiltinType) RAW( // Get the type of the pointed-to value. Type* getValueType(); |
