Changeset 8135d4c for src/GenPoly/Specialize.cc
- Timestamp:
- Aug 22, 2017, 7:31:52 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9aaac6e9
- Parents:
- fc56cdbf (diff), b3d413b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Specialize.cc
rfc56cdbf r8135d4c 14 14 // 15 15 16 #include <cassert> 17 16 #include <cassert> // for assert, assertf 17 #include <iterator> // for back_insert_iterator, back_i... 18 #include <map> // for _Rb_tree_iterator, _Rb_tree_... 19 #include <memory> // for unique_ptr 20 #include <string> // for string 21 #include <tuple> // for get 22 #include <utility> // for pair 23 24 #include "Common/SemanticError.h" // for SemanticError 25 #include "Common/UniqueName.h" // for UniqueName 26 #include "Common/utility.h" // for group_iterate 27 #include "GenPoly.h" // for getFunctionType 28 #include "InitTweak/InitTweak.h" // for isIntrinsicCallExpr 29 #include "Parser/LinkageSpec.h" // for C 30 #include "PolyMutator.h" // for PolyMutator 31 #include "ResolvExpr/FindOpenVars.h" // for findOpenVars 32 #include "ResolvExpr/TypeEnvironment.h" // for OpenVarSet, AssertionSet 18 33 #include "Specialize.h" 19 #include "GenPoly.h" 20 #include "PolyMutator.h" 21 22 #include "Parser/ParseNode.h" 23 24 #include "SynTree/Expression.h" 25 #include "SynTree/Statement.h" 26 #include "SynTree/Type.h" 27 #include "SynTree/Attribute.h" 28 #include "SynTree/TypeSubstitution.h" 29 #include "SynTree/Mutator.h" 30 #include "ResolvExpr/FindOpenVars.h" 31 #include "Common/UniqueName.h" 32 #include "Common/utility.h" 33 #include "InitTweak/InitTweak.h" 34 #include "Tuples/Tuples.h" 34 #include "SynTree/Attribute.h" // for Attribute 35 #include "SynTree/Declaration.h" // for FunctionDecl, DeclarationWit... 36 #include "SynTree/Expression.h" // for ApplicationExpr, Expression 37 #include "SynTree/Label.h" // for Label, noLabels 38 #include "SynTree/Mutator.h" // for mutateAll 39 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, Expr... 40 #include "SynTree/Type.h" // for FunctionType, TupleType, Type 41 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 42 #include "SynTree/Visitor.h" // for Visitor 35 43 36 44 namespace GenPoly { … … 93 101 } 94 102 103 // walk into tuple type and find the number of components 104 size_t singleParameterSize( Type * type ) { 105 if ( TupleType * tt = dynamic_cast< TupleType * >( type ) ) { 106 size_t sz = 0; 107 for ( Type * t : *tt ) { 108 sz += singleParameterSize( t ); 109 } 110 return sz; 111 } else { 112 return 1; 113 } 114 } 115 116 // find the total number of components in a parameter list 117 size_t functionParameterSize( FunctionType * ftype ) { 118 size_t sz = 0; 119 for ( DeclarationWithType * p : ftype->get_parameters() ) { 120 sz += singleParameterSize( p->get_type() ); 121 } 122 return sz; 123 } 124 95 125 bool needsTupleSpecialization( Type *formalType, Type *actualType ) { 96 126 // Needs tuple specialization if the structure of the formal type and actual type do not match. … … 103 133 FunctionType * aftype = getFunctionType( actualType->stripReferences() ); 104 134 assertf( aftype, "formal type is a function type, but actual type is not: %s", toString( actualType ).c_str() ); 135 // Can't tuple specialize if parameter sizes deeply-differ. 136 if ( functionParameterSize( fftype ) != functionParameterSize( aftype ) ) return false; 137 // tuple-parameter sizes are the same, but actual parameter sizes differ - must tuple specialize 105 138 if ( fftype->get_parameters().size() != aftype->get_parameters().size() ) return true; 139 // total parameter size can be the same, while individual parameters can have different structure 106 140 for ( auto params : group_iterate( fftype->get_parameters(), aftype->get_parameters() ) ) { 107 141 DeclarationWithType * formal = std::get<0>(params);
Note: See TracChangeset
for help on using the changeset viewer.