- Timestamp:
- Oct 23, 2023, 11:13:00 AM (2 years ago)
- Branches:
- master
- Children:
- cb94e41
- Parents:
- 4d2d7e27 (diff), abb04a4 (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. - Location:
- src
- Files:
-
- 5 edited
-
CodeTools/DeclStats.cc (modified) (1 diff)
-
GenPoly/BoxNew.cpp (modified) (16 diffs)
-
GenPoly/GenPoly.cc (modified) (2 diffs)
-
GenPoly/GenPoly.h (modified) (1 diff)
-
GenPoly/SpecializeNew.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeTools/DeclStats.cc
r4d2d7e27 r278e162 25 25 #include "Common/PassVisitor.h" 26 26 #include "Common/VectorMap.h" // for VectorMap 27 #include "GenPoly/GenPoly.h" // for hasPolyBase28 27 #include "SynTree/LinkageSpec.h" // for ::NoOfSpecs, Spec 29 28 #include "SynTree/Declaration.h" // for FunctionDecl, TypeDecl, Declaration -
src/GenPoly/BoxNew.cpp
r4d2d7e27 r278e162 39 39 40 40 namespace { 41 42 /// Common field of several sub-passes of box.43 struct BoxPass {44 TypeVarMap scopeTypeVars;45 BoxPass() : scopeTypeVars( ast::TypeData() ) {}46 };47 48 // TODO: Could this be a common helper somewhere?49 ast::FunctionType * makeFunctionType( ast::FunctionDecl const * decl ) {50 ast::FunctionType * type = new ast::FunctionType(51 decl->type->isVarArgs, decl->type->qualifiers52 );53 for ( auto type_param : decl->type_params ) {54 type->forall.emplace_back( new ast::TypeInstType( type_param ) );55 }56 for ( auto assertion : decl->assertions ) {57 type->assertions.emplace_back( new ast::VariableExpr(58 assertion->location, assertion ) );59 }60 for ( auto param : decl->params ) {61 type->params.emplace_back( param->get_type() );62 }63 for ( auto retval : decl->returns ) {64 type->returns.emplace_back( retval->get_type() );65 }66 return type;67 }68 41 69 42 // -------------------------------------------------------------------------- … … 359 332 /// * Adds appropriate type variables to the function calls. 360 333 struct CallAdapter final : 361 public BoxPass,362 334 public ast::WithConstTypeSubstitution, 363 335 public ast::WithGuards, … … 438 410 CodeLocation const & location, ast::Type const * type ); 439 411 440 /// Set of adapter functions in the current scope.412 TypeVarMap scopeTypeVars; 441 413 ScopedMap< std::string, ast::DeclWithType const * > adapters; 442 414 std::map< ast::ApplicationExpr const *, ast::Expr const * > retVals; … … 659 631 ptrdiff_t initArgCount = mutExpr->args.size(); 660 632 661 TypeVarMap exprTypeVars = { ast::TypeData() };633 TypeVarMap exprTypeVars; 662 634 // TODO: Should this take into account the variables already bound in 663 635 // scopeTypeVars ([ex] remove them from exprTypeVars)? … … 1410 1382 1411 1383 ast::FunctionDecl const * DeclAdapter::previsit( ast::FunctionDecl const * decl ) { 1412 TypeVarMap localTypeVars = { ast::TypeData() };1384 TypeVarMap localTypeVars; 1413 1385 makeTypeVarMap( decl, localTypeVars ); 1414 1386 … … 1441 1413 layoutParams.emplace_back( alignParam ); 1442 1414 } 1443 // TODO: These should possibly all be gone. 1444 // More all assertions into parameter list. 1445 for ( ast::ptr<ast::DeclWithType> & assert : mutParam->assertions ) { 1446 // Assertion parameters may not be used in body, 1447 // pass along with unused attribute. 1448 assert.get_and_mutate()->attributes.push_back( 1449 new ast::Attribute( "unused" ) ); 1450 inferredParams.push_back( assert ); 1451 } 1452 mutParam->assertions.clear(); 1415 // Assertions should be stored in the main list. 1416 assert( mutParam->assertions.empty() ); 1453 1417 typeParam = mutParam; 1454 1418 } 1455 // TODO: New version of inner loop.1456 1419 for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) { 1457 1420 // Assertion parameters may not be used in body, … … 1468 1431 spliceBegin( mutDecl->params, layoutParams ); 1469 1432 addAdapters( mutDecl, localTypeVars ); 1433 1434 // Now have to update the type to match the declaration. 1435 ast::FunctionType * type = new ast::FunctionType( 1436 mutDecl->type->isVarArgs, mutDecl->type->qualifiers ); 1437 for ( auto type_param : mutDecl->type_params ) { 1438 type->forall.emplace_back( new ast::TypeInstType( type_param ) ); 1439 } 1440 for ( auto param : mutDecl->params ) { 1441 type->params.emplace_back( param->get_type() ); 1442 } 1443 for ( auto retval : mutDecl->returns ) { 1444 type->returns.emplace_back( retval->get_type() ); 1445 } 1446 mutDecl->type = type; 1470 1447 1471 1448 return mutDecl; … … 1501 1478 } 1502 1479 } 1503 // TODO: Can this be updated as we go along?1504 mutDecl->type = makeFunctionType( mutDecl );1505 1480 return mutDecl; 1506 1481 } … … 1558 1533 assertf( it != adapters.end(), "Could not correct floating node." ); 1559 1534 return ast::mutate_field( expr, &ast::VariableExpr::var, it->second ); 1560 1561 1535 } 1562 1536 … … 1570 1544 /// * Inserts dynamic calculation of polymorphic type layouts where needed. 1571 1545 struct PolyGenericCalculator final : 1572 public BoxPass,1573 1546 public ast::WithConstTypeSubstitution, 1574 1547 public ast::WithDeclsToAdd<>, … … 1615 1588 /// C sizeof(). 1616 1589 ast::Expr const * genSizeof( CodeLocation const &, ast::Type const * ); 1617 1618 1590 /// Enters a new scope for type-variables, 1619 1591 /// adding the type variables from the provided type. 1620 1592 void beginTypeScope( ast::Type const * ); 1621 1593 1594 /// The type variables and polymorphic parameters currently in scope. 1595 TypeVarMap scopeTypeVars; 1622 1596 /// Set of generic type layouts known in the current scope, 1623 1597 /// indexed by sizeofName. … … 1668 1642 ast::TypeDecl const * decl ) { 1669 1643 ast::Type const * base = decl->base; 1670 if ( nullptr == base ) return decl;1644 if ( nullptr == base ) return decl; 1671 1645 1672 1646 // Add size/align variables for opaque type declarations. … … 1693 1667 alignDecl->accept( *visitor ); 1694 1668 1695 // Can't use [makeVar], because it inserts into stmtsToAdd and TypeDecls1696 // can occur at global scope.1669 // A little trick to replace this with two declarations. 1670 // Adding after makes sure that there is no conflict with adding stmts. 1697 1671 declsToAddAfter.push_back( alignDecl ); 1698 // replace with sizeDecl.1699 1672 return sizeDecl; 1700 1673 } … … 1721 1694 1722 1695 // Change initialization of a polymorphic value object to allocate via a 1723 // variable-length-array (alloca was previouly used, but it cannot be 1724 // safely used in loops). 1696 // variable-length-array (alloca cannot be safely used in loops). 1725 1697 ast::ObjectDecl * newBuf = new ast::ObjectDecl( decl->location, 1726 1698 bufNamer.newName(), … … 2210 2182 /// * Strips fields from generic structure declarations. 2211 2183 struct Eraser final : 2212 public BoxPass,2213 2184 public ast::WithGuards { 2214 2185 void guardTypeVarMap( ast::Type const * type ) { … … 2225 2196 void previsit( ast::PointerType const * type ); 2226 2197 void previsit( ast::FunctionType const * type ); 2198 public: 2199 TypeVarMap scopeTypeVars; 2227 2200 }; 2228 2201 -
src/GenPoly/GenPoly.cc
r4d2d7e27 r278e162 273 273 if ( func->returns.empty() ) return nullptr; 274 274 275 TypeVarMap forallTypes = { ast::TypeData() };275 TypeVarMap forallTypes; 276 276 makeTypeVarMap( func, forallTypes ); 277 277 return isDynType( func->returns.front(), forallTypes ); … … 801 801 const ast::FunctionType * function = getFunctionType( expr->func->result ); 802 802 assertf( function, "ApplicationExpr has non-function type: %s", toString( expr->func->result ).c_str() ); 803 TypeVarMap exprTyVars = { ast::TypeData() };803 TypeVarMap exprTyVars; 804 804 makeTypeVarMap( function, exprTyVars ); 805 805 return needsBoxing( param, arg, exprTyVars, subst ); -
src/GenPoly/GenPoly.h
r4d2d7e27 r278e162 33 33 34 34 typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap; 35 using TypeVarMap = ErasableScopedMap< ast::TypeEnvKey, ast::TypeData >; 35 struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> { 36 TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {} 37 }; 36 38 37 39 /// Replaces a TypeInstType by its referrent in the environment, if applicable -
src/GenPoly/SpecializeNew.cpp
r4d2d7e27 r278e162 81 81 } 82 82 83 // The number of elements in a type if it is a flattened tuple.84 size_t flatT upleSize( const ast::Type * type) {85 if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {86 size_t sum = 0;87 for ( auto t : *tuple) {88 sum += flatT upleSize( t);89 } 90 return sum;91 } else {92 return 1;93 }83 // The number of elements in a list, if all tuples had been flattened. 84 size_t flatTypeListSize( const std::vector<ast::ptr<ast::Type>> & types ) { 85 size_t sum = 0; 86 for ( const ast::ptr<ast::Type> & type : types ) { 87 if ( const ast::TupleType * tuple = type.as<ast::TupleType>() ) { 88 sum += flatTypeListSize( tuple->types ); 89 } else { 90 sum += 1; 91 } 92 } 93 return sum; 94 94 } 95 95 96 96 // Find the total number of components in a parameter list. 97 97 size_t functionParameterSize( const ast::FunctionType * type ) { 98 size_t sum = 0; 99 for ( auto param : type->params ) { 100 sum += flatTupleSize( param ); 101 } 102 return sum; 98 return flatTypeListSize( type->params ); 103 99 } 104 100
Note:
See TracChangeset
for help on using the changeset viewer.