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/syntax-base-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/syntax-base-defs.h')
| -rw-r--r-- | source/slang/syntax-base-defs.h | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h index 4fded014e..acc795d8b 100644 --- a/source/slang/syntax-base-defs.h +++ b/source/slang/syntax-base-defs.h @@ -81,8 +81,6 @@ public: Session* getSession() { return this->session; } void setSession(Session* s) { this->session = s; } - virtual String ToString() = 0; - bool Equals(Type * type); bool Equals(RefPtr<Type> type); @@ -131,10 +129,12 @@ END_SYNTAX_CLASS() // A substitution represents a binding of certain // type-level variables to concrete argument values ABSTRACT_SYNTAX_CLASS(Substitutions, RefObject) + // The next outer that this one refines. + FIELD(RefPtr<Substitutions>, outer) RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) = 0; + virtual RefPtr<Substitutions> applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) = 0; // Check if these are equivalent substitutiosn to another set virtual bool Equals(Substitutions* subst) = 0; @@ -151,12 +151,9 @@ SYNTAX_CLASS(GenericSubstitution, Substitutions) // The actual values of the arguments SYNTAX_FIELD(List<RefPtr<Val>>, args) - // Any further substitutions, relating to outer generic declarations - SYNTAX_FIELD(RefPtr<GenericSubstitution>, outer) - RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; + virtual RefPtr<Substitutions> applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) override; // Check if these are equivalent substitutiosn to another set virtual bool Equals(Substitutions* subst) override; @@ -178,11 +175,17 @@ SYNTAX_CLASS(GenericSubstitution, Substitutions) END_SYNTAX_CLASS() SYNTAX_CLASS(ThisTypeSubstitution, Substitutions) + // The declaration of the interface that we are specializing + FIELD_INIT(InterfaceDecl*, interfaceDecl, nullptr) + + // A witness that shows that the concrete type used to + // specialize the interface conforms to the interface. + FIELD(RefPtr<SubtypeWitness>, witness) + // The actual type that provides the lookup scope for an associated type - SYNTAX_FIELD(RefPtr<Val>, sourceType) RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; + virtual RefPtr<Substitutions> applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) override; // Check if these are equivalent substitutiosn to another set virtual bool Equals(Substitutions* subst) override; @@ -190,25 +193,31 @@ SYNTAX_CLASS(ThisTypeSubstitution, Substitutions) { return Equals(const_cast<Substitutions*>(&subst)); } - virtual int GetHashCode() const override - { - if (sourceType) - return sourceType->GetHashCode(); - return 0; - } + virtual int GetHashCode() const override; ) END_SYNTAX_CLASS() SYNTAX_CLASS(GlobalGenericParamSubstitution, Substitutions) // the __generic_param decl to be substituted DECL_FIELD(GlobalGenericParamDecl*, paramDecl) + // the actual type to substitute in - SYNTAX_FIELD(RefPtr<Val>, actualType) - // Any further global type parameter substitutions - SYNTAX_FIELD(RefPtr<GlobalGenericParamSubstitution>, outer) + SYNTAX_FIELD(RefPtr<Type>, actualType) + + RAW( + struct ConstraintArg + { + RefPtr<Decl> decl; + RefPtr<Val> val; + }; + ) + + // the values that satisfy any constraints on the type parameter + SYNTAX_FIELD(List<ConstraintArg>, constraintArgs) + RAW( // Apply a set of substitutions to the bindings in this substitution - virtual RefPtr<Substitutions> SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; + virtual RefPtr<Substitutions> applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) override; // Check if these are equivalent substitutiosn to another set virtual bool Equals(Substitutions* subst) override; @@ -219,17 +228,13 @@ RAW( virtual int GetHashCode() const override { int rs = actualType->GetHashCode(); - for (auto && v : witnessTables) + for (auto && a : constraintArgs) { - rs = combineHash(rs, v.Key->GetHashCode()); - rs = combineHash(rs, v.Value->GetHashCode()); + rs = combineHash(rs, a.val->GetHashCode()); } return rs; } - typedef List<KeyValuePair<RefPtr<Type>, RefPtr<Val>>> WitnessTableLookupTable; ) - // The witness tables for each interface this actual type implements - SYNTAX_FIELD(WitnessTableLookupTable, witnessTables) END_SYNTAX_CLASS() ABSTRACT_SYNTAX_CLASS(SyntaxNode, SyntaxNodeBase) |
