source: src/ResolvExpr/PolyCost.cc @ 6c2dc00

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 6c2dc00 was fcd0b9d7, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

PolyCost? calculation result becomes 0 or 1 per type, avoiding double-couting. Fixes #235?

PolyCost? calculation is documented as "Count of parameters and return values bound to some poly type." Before this fix, the cost calculation, looking inside one parameter or return, counted each occurrence of a poly type that it found there. This caused an incorrect increase in PolyCost? on cases like #235 where several type variables are used in the declaration of one parameter.

libcfa/src/concurrency/thread.cfa: Changing a decl-use pattern to keep resolution consistent (no behaviour is changed). The management of defaultResumptionHandler in the thread constructor was benefitting from bug #235 to disambiguate assignment to local variable vs assignment to declared function (due to #234). After this change, the code works around that false ambiguity by using a different name for the local variable.

tests/avl*: Adding a missing assertion on the custom destructor definition. Previously, the destructor definition was benefiting from bug #235 to avoid the missing-assertion-on-custom-dtor problem described in #227.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[a32b204]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[b0837e4]7// PolyCost.cc --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 09:50:12 2015
[5aa4656]11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Jun 19 10:45:00 2019
13// Update Count     : 4
[a32b204]14//
[51b7345]15
[9d5089e]16#include "AST/SymbolTable.hpp"
17#include "AST/Type.hpp"
18#include "AST/TypeEnvironment.hpp"
[a180ded]19#include "Common/PassVisitor.h"
[ea6332d]20#include "SymTab/Indexer.h"   // for Indexer
21#include "SynTree/Type.h"     // for TypeInstType, Type
22#include "TypeEnvironment.h"  // for EqvClass, TypeEnvironment
[51b7345]23
24namespace ResolvExpr {
[a180ded]25        struct PolyCost {
[a32b204]26                PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
[a180ded]27
28                void previsit( TypeInstType * aggregateUseType );
[a32b204]29                int result;
[a180ded]30                const TypeEnvironment &tenv;
[a32b204]31                const SymTab::Indexer &indexer;
32        };
[51b7345]33
[b0837e4]34        int polyCost( Type *type, const TypeEnvironment & env, const SymTab::Indexer &indexer ) {
[a180ded]35                PassVisitor<PolyCost> coster( env, indexer );
[a32b204]36                type->accept( coster );
[fcd0b9d7]37                return (coster.pass.result > 0) ? 1 : 0;
[a32b204]38        }
[51b7345]39
[a180ded]40        PolyCost::PolyCost( const TypeEnvironment & env, const SymTab::Indexer & indexer ) : result( 0 ), tenv( env ), indexer( indexer ) {
[a32b204]41        }
[51b7345]42
[a180ded]43        void PolyCost::previsit(TypeInstType * typeInst) {
[00ac42e]44                if ( const EqvClass *eqvClass = tenv.lookup( typeInst->name ) ) {
45                        if ( eqvClass->type ) {
46                                if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass->type ) ) {
[b0837e4]47                                        if ( indexer.lookupType( otherTypeInst->name ) ) {
48                                                // bound to opaque type
[a32b204]49                                                result += 1;
50                                        } // if
51                                } else {
[b0837e4]52                                        // bound to concrete type
[a32b204]53                                        result += 1;
54                                } // if
55                        } // if
56                } // if
57        }
[51b7345]58
[5aa4656]59// TODO: When the old PolyCost is torn out get rid of the _new suffix.
[9ea38de]60class PolyCost_new {
[5aa4656]61        const ast::SymbolTable &symtab;
[9ea38de]62public:
63        int result;
[5aa4656]64        const ast::TypeEnvironment &env_;
65
[9ea38de]66        PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 
67        : symtab( symtab ), result( 0 ), env_( env ) {}
[5aa4656]68
69        void previsit( const ast::TypeInstType * type ) {
[3e5dd913]70                if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
[5aa4656]71                        if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
72                                if ( symtab.lookupType( otherType->name ) ) {
73                                        // Bound to opaque type.
74                                        result += 1;
75                                }
76                        } else {
77                                // Bound to concrete type.
78                                result += 1;
79                        }
80                }
[9d5089e]81        }
[5aa4656]82};
83
84int polyCost(
85        const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
86) {
87        ast::Pass<PolyCost_new> costing( symtab, env );
88        type->accept( costing );
[fcd0b9d7]89        return (costing.core.result > 0) ? 1 : 0;
[5aa4656]90}
[9d5089e]91
[51b7345]92} // namespace ResolvExpr
[a32b204]93
94// Local Variables: //
95// tab-width: 4 //
96// mode: c++ //
97// compile-command: "make install" //
98// End: //
Note: See TracBrowser for help on using the repository browser.