Changes in / [41cde266:c5a98f3]


Ignore:
Files:
3 added
1 deleted
61 edited

Legend:

Unmodified
Added
Removed
  • Jenkins/tools.groovy

    r41cde266 rc5a98f3  
    66import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
    77
     8// Global for the stage name
     9StageName = ''
     10
    811// wrapper around stage declaretion to be more verbose
    912// and allow showing as skipped in the UI
    1013def BuildStage(String name, boolean run, Closure block ) {
    11         echo " -------- ${name} -------- "
     14        StageName = name
     15        echo " -------- ${StageName} -------- "
    1216        if(run) {
    1317                stage(name, block)
  • Jenkinsfile

    r41cde266 rc5a98f3  
    5454        //attach the build log to the email
    5555        catch (Exception caughtError) {
    56                 // Store the result of the build log
    57                 currentBuild.result = "FAILURE"
    58 
    59                 // An error has occured, the build log is relevent
     56                //rethrow error later
     57                err = caughtError
     58
     59                echo err.toString()
     60
     61                //An error has occured, the build log is relevent
    6062                log_needed = true
    6163
    62                 // rethrow error later
    63                 err = caughtError
    64 
    65                 // print the error so it shows in the log
    66                 echo err.toString()
     64                //Store the result of the build log
     65                currentBuild.result = "${tools.StageName} FAILURE".trim()
    6766        }
    6867
  • libcfa/src/bits/collection.hfa

    r41cde266 rc5a98f3  
    11#pragma once
    2 #include <stdio.h> // REMOVE THIS AFTER DEBUGGING
    3 
    42
    53struct Colable {
    6         struct Colable * next;                                                                          // next node in the list
     4        Colable * next;                                                                         // next node in the list
    75        // invariant: (next != 0) <=> listed()
    86};
    9 #ifdef __cforall
    10 static inline {
     7
     8inline {
    119        // PUBLIC
    1210
     
    3028        }
    3129
    32         // // wrappers to make Collection have T
    33         // forall( dtype T ) {
    34         //      T *& Next( T * n ) {
    35         //              return (T *)Next( (Colable *)n );
    36         //      }
    37         // } // distribution
     30        // wrappers to make Collection have T
     31        forall( dtype T ) {
     32                T *& Next( T * n ) {
     33                        return (T *)Next( (Colable *)n );
     34                }
     35
     36                bool listed( T * n ) {
     37                        return Next( (Colable *)n ) != 0p;
     38                }
     39        } // distribution
    3840} // distribution
    3941
    40 forall( dtype T | { T *& Next ( T * ); } ) {
    41         bool listed( T * n ) {
    42                 return Next( n ) != 0p;
    43         }
    44 }
    4542
    4643struct Collection {
     
    4845};
    4946
    50 static inline {
     47inline {
    5148        // class invariant: root == 0 & empty() | *root in *this
    5249        void ?{}( Collection &, const Collection & ) = void; // no copy
     
    7168};
    7269
    73 static inline {
     70inline {
    7471        void ?{}( ColIter & colIter ) with( colIter ) {
    7572                curr = 0p;
     
    8279        } // distribution
    8380} // distribution
    84 #endif
  • libcfa/src/bits/containers.hfa

    r41cde266 rc5a98f3  
    3636        #define __small_array_t(T) __small_array(T)
    3737#else
    38         #define __small_array_t(T) __small_array
     38        #define __small_array_t(T) struct __small_array
    3939#endif
    4040
  • libcfa/src/bits/defs.hfa

    r41cde266 rc5a98f3  
    2929#define __cfa_anonymous_object(x) inline struct x
    3030#else
    31 #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
     31#define __cfa_anonymous_object(x) x __cfa_anonymous_object
    3232#endif
    3333
  • libcfa/src/bits/queue.hfa

    r41cde266 rc5a98f3  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T | { T *& Next ( T * ); } ) {
     5forall( dtype T ) {
    66        struct Queue {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    6464                        T & t = head( q );
    6565                        if ( root ) {
    66                                 root = Next( (T *)root );
     66                                root = Next( root );
    6767                                if ( &head( q ) == &t ) {
    6868                                        root = last = 0p;                                       // only one element
     
    142142} // distribution
    143143
    144 forall( dtype T | { T *& Next ( T * ); } ) {
     144forall( dtype T ) {
    145145        struct QueueIter {
    146146                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/bits/sequence.hfa

    r41cde266 rc5a98f3  
    22
    33#include "bits/collection.hfa"
    4 #include "bits/defs.hfa"
    54
    65struct Seqable {
    7         __cfa_anonymous_object(Colable);
    8         struct Seqable * back;                                                                          // pointer to previous node in the list
     6        inline Colable;
     7        Seqable * back;                                                                         // pointer to previous node in the list
    98};
    109
    11 #ifdef __cforall
    12 static inline {
     10inline {
    1311        // PUBLIC
    1412
     
    2826        }
    2927
    30         // // wrappers to make Collection have T
    31         // forall( dtype T ) {
    32         //      T *& Back( T * n ) {
    33         //              return (T *)Back( (Seqable *)n );
    34         //      }
    35         // } // distribution
     28        // wrappers to make Collection have T
     29        forall( dtype T ) {
     30                T *& Back( T * n ) {
     31                        return (T *)Back( (Seqable *)n );
     32                }
     33        } // distribution
    3634} // distribution
    3735
    38 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     36forall( dtype T ) {
    3937        struct Sequence {
    4038                inline Collection;                                                              // Plan 9 inheritance
    4139        };
    4240
    43         static inline {
     41        inline {
    4442                // wrappers to make Collection have T
    4543                T & head( Sequence(T) & s ) with( s ) {
     
    186184                                T * toEnd = Back( &head( s ) );
    187185                                T * fromEnd = Back( &head( from ) );
    188                                 Back( (T *)root ) = fromEnd;
     186                                Back( root ) = fromEnd;
    189187                                Next( fromEnd ) = &head( s );
    190                                 Back( (T *)from.root ) = toEnd;
     188                                Back( from.root ) = toEnd;
    191189                                Next( toEnd ) = &head( from );
    192190                        } // if
     
    216214} // distribution
    217215
    218 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     216forall( dtype T ) {
    219217        // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order.
    220218        struct SeqIter {
     
    226224        };
    227225
    228         static inline {
     226        inline {
    229227                void ?{}( SeqIter(T) & si ) with( si ) {
    230228                        ((ColIter &)si){};
     
    267265        };
    268266
    269         static inline {
     267        inline {
    270268                void ?{}( SeqIterRev(T) & si ) with( si ) {     
    271269                        ((ColIter &)si){};
     
    300298        } // distribution
    301299} // distribution
    302 
    303 #endif
  • libcfa/src/bits/stack.hfa

    r41cde266 rc5a98f3  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T | { T *& Next ( T * ); } ) {
     5forall( dtype T ) {
    66        struct Stack {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    4444                        T & t = head( s );
    4545                        if ( root ) {
    46                                 root = ( T *)Next( (T *)root );
     46                                root = ( T *)Next( root );
    4747                                if ( &head( s ) == &t ) root = 0p;              // only one element ?
    4848                                Next( &t ) = 0p;
     
    5858
    5959
    60 forall( dtype T | { T *& Next ( T * ); } ) {
     60forall( dtype T ) {
    6161        struct StackIter {
    6262                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/concurrency/coroutine.cfa

    r41cde266 rc5a98f3  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 12:06:04 2020
    13 // Update Count     : 23
     12// Last Modified On : Fri Oct 23 23:05:24 2020
     13// Update Count     : 22
    1414//
    1515
     
    8888static const size_t MinStackSize = 1000;
    8989extern size_t __page_size;                              // architecture pagesize HACK, should go in proper runtime singleton
    90 extern int __map_prot;
    9190
    9291void __stack_prepare( __stack_info_t * this, size_t create_size );
     
    207206                __cfaabi_dbg_debug_do(
    208207                        storage = (char*)(storage) - __page_size;
    209                         if ( mprotect( storage, __page_size, __map_prot ) == -1 ) {
     208                        if ( mprotect( storage, __page_size, PROT_READ | PROT_WRITE ) == -1 ) {
    210209                                abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
    211210                        }
  • libcfa/src/concurrency/invoke.h

    r41cde266 rc5a98f3  
    189189                struct __monitor_group_t monitors;
    190190
    191                 // used to put threads on user data structures
    192                 struct {
    193                         struct $thread * next;
    194                         struct $thread * back;
    195                 } seqable;
    196 
    197191                struct {
    198192                        struct $thread * next;
     
    224218                }
    225219
    226                 static inline $thread *& Back( $thread * this ) __attribute__((const)) {
    227                         return this->seqable.back;
    228                 }
    229 
    230                 static inline $thread *& Next( $thread * this ) __attribute__((const)) {
    231                         return this->seqable.next;
    232                 }
    233 
    234                 static inline bool listed( $thread * this ) {
    235                         return this->seqable.next != 0p;
    236                 }
    237 
    238220                static inline void ?{}(__monitor_group_t & this) {
    239221                        (this.data){0p};
  • libcfa/src/concurrency/kernel/startup.cfa

    r41cde266 rc5a98f3  
    117117}
    118118
    119 extern size_t __page_size;
    120 extern int __map_prot;
     119size_t __page_size = 0;
    121120
    122121//-----------------------------------------------------------------------------
     
    162161        /* paranoid */ verify( ! __preemption_enabled() );
    163162        __cfadbg_print_safe(runtime_core, "Kernel : Starting\n");
     163
     164        __page_size = sysconf( _SC_PAGESIZE );
    164165
    165166        __cfa_dbg_global_clusters.list{ __get };
     
    680681        #if CFA_PROCESSOR_USE_MMAP
    681682                stacksize = ceiling( stacksize, __page_size ) + __page_size;
    682                 stack = mmap(0p, stacksize, __map_prot, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
     683                stack = mmap(0p, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
    683684                if(stack == ((void*)-1)) {
    684685                        abort( "pthread stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) );
     
    726727                }
    727728        #else
    728                 __cfaabi_dbg_debug_do(
    729                         // pthread has no mechanism to create the guard page in user supplied stack.
    730                         if ( mprotect( stack, __page_size, __map_prot ) == -1 ) {
    731                                 abort( "mprotect : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) );
    732                         } // if
    733                 );
    734729                free( stack );
    735730        #endif
  • libcfa/src/concurrency/locks.cfa

    r41cde266 rc5a98f3  
    2929
    3030        void ^?{}( info_thread(L) & this ){ }
    31 
    32         info_thread(L) *& Back( info_thread(L) * this ) {
    33                 return (info_thread(L) *)Back( (Seqable *)this );
    34         }
    35 
    36         info_thread(L) *& Next( info_thread(L) * this ) {
    37                 return (info_thread(L) *)Next( (Colable *)this );
    38         }
    39 
    40         bool listed( info_thread(L) * this ) {
    41                 return Next( (Colable *)this ) != 0p;
    42         }
    4331}
    4432
     
    7058                abort("A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock.");
    7159        } else if ( owner != 0p && owner != active_thread() ) {
    72                 addTail( blocked_threads, *active_thread() );
     60                append( blocked_threads, active_thread() );
    7361                wait_count++;
    7462                unlock( lock );
     
    10896
    10997void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    110         $thread * t = &dropHead( blocked_threads );
     98        $thread * t = pop_head( blocked_threads );
    11199        owner = t;
    112100        recursion_count = ( t ? 1 : 0 );
     
    140128    lock( lock __cfaabi_dbg_ctx2 );
    141129        if ( owner != 0p ) {
    142                 addTail( blocked_threads, *t );
     130                append( blocked_threads, t );
    143131                wait_count++;
    144132                unlock( lock );
     
    269257                size_t recursion_count = 0;
    270258                if (i->lock) {
     259                        i->t->link.next = 1p;
    271260                        recursion_count = get_recursion_count(*i->lock);
    272261                        remove_( *i->lock );
  • libcfa/src/concurrency/locks.hfa

    r41cde266 rc5a98f3  
    4343        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info );
    4444        void ^?{}( info_thread(L) & this );
    45 
    46         info_thread(L) *& Back( info_thread(L) * this );
    47         info_thread(L) *& Next( info_thread(L) * this );
    48         bool listed( info_thread(L) * this );
    4945}
    5046
     
    6864
    6965        // List of blocked threads
    70         Sequence( $thread ) blocked_threads;
     66        __queue_t( $thread ) blocked_threads;
    7167
    7268        // Count of current blocked threads
  • libcfa/src/concurrency/thread.cfa

    r41cde266 rc5a98f3  
    4343                canary = 0x0D15EA5E0D15EA5Ep;
    4444        #endif
    45 
    46         seqable.next = 0p;
    47         seqable.back = 0p;
    4845
    4946        node.next = 0p;
  • libcfa/src/heap.cfa

    r41cde266 rc5a98f3  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 16 12:28:25 2020
    13 // Update Count     : 1023
     12// Last Modified On : Sun Dec 13 22:04:10 2020
     13// Update Count     : 984
    1414//
    1515
    1616#include <unistd.h>                                                                             // sbrk, sysconf
    17 #include <stdlib.h>                                                                             // EXIT_FAILURE
    1817#include <stdbool.h>                                                                    // true, false
    1918#include <stdio.h>                                                                              // snprintf, fileno
     
    7271        // Define the default extension heap amount in units of bytes. When the uC++ supplied heap reaches the brk address,
    7372        // the brk address is extended by the extension amount.
    74         __CFA_DEFAULT_HEAP_EXPANSION__ = (10 * 1024 * 1024),
     73        __CFA_DEFAULT_HEAP_EXPANSION__ = (1 * 1024 * 1024),
    7574
    7675        // Define the mmap crossover point during allocation. Allocations less than this amount are allocated from buckets;
     
    116115
    117116// statically allocated variables => zero filled.
    118 size_t __page_size;                                                                             // architecture pagesize
    119 int __map_prot;                                                                                 // common mmap/mprotect protection
     117static size_t pageSize;                                                                 // architecture pagesize
    120118static size_t heapExpand;                                                               // sbrk advance
    121119static size_t mmapStart;                                                                // cross over point for mmap
     
    251249#endif // FASTLOOKUP
    252250
    253 static const off_t mmapFd = -1;                                                 // fake or actual fd for anonymous file
     251static int mmapFd = -1;                                                                 // fake or actual fd for anonymous file
    254252#ifdef __CFA_DEBUG__
    255253static bool heapBoot = 0;                                                               // detect recursion during boot
     
    376374
    377375static inline bool setMmapStart( size_t value ) {               // true => mmapped, false => sbrk
    378   if ( value < __page_size || bucketSizes[NoBucketSizes - 1] < value ) return false;
     376  if ( value < pageSize || bucketSizes[NoBucketSizes - 1] < value ) return false;
    379377        mmapStart = value;                                                                      // set global
    380378
     
    438436        header = headerAddr( addr );
    439437
    440   if ( unlikely( addr < heapBegin || heapEnd < addr ) ) { // mmapped ?
     438  if ( unlikely( heapEnd < addr ) ) {                                   // mmapped ?
    441439                fakeHeader( header, alignment );
    442440                size = header->kind.real.blockSize & -3;                // mmap size
     
    445443
    446444        #ifdef __CFA_DEBUG__
    447         checkHeader( header < (HeapManager.Storage.Header *)heapBegin, name, addr ); // bad low address ?
     445        checkHeader( addr < heapBegin, name, addr );            // bad low address ?
    448446        #endif // __CFA_DEBUG__
    449447
     
    484482#endif // __CFA_DEBUG__
    485483
    486 
    487484#define NO_MEMORY_MSG "insufficient heap memory available for allocating %zd new bytes."
    488485
     
    493490                // If the size requested is bigger than the current remaining storage, increase the size of the heap.
    494491
    495                 size_t increase = ceiling2( size > heapExpand ? size : heapExpand, __page_size );
    496                 // Do not call abort or strerror( errno ) as they may call malloc.
     492                size_t increase = ceiling2( size > heapExpand ? size : heapExpand, pageSize );
    497493                if ( sbrk( increase ) == (void *)-1 ) {                 // failed, no memory ?
    498494                        unlock( extlock );
    499                         __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size );
    500                         _exit( EXIT_FAILURE );
    501                 } // if
    502                 if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) {
    503                         unlock( extlock );
    504                         __cfaabi_bits_print_nolock( STDERR_FILENO, "extend() : internal error, mprotect failure, heapEnd:%p size:%zd, errno:%d.\n", heapEnd, increase, errno );
    505                         _exit( EXIT_FAILURE );
     495                        abort( NO_MEMORY_MSG, size );                           // give up
     496                } // if
     497                if ( mprotect( (char *)heapEnd + heapRemaining, increase, PROT_READ | PROT_WRITE | PROT_EXEC ) ) {
     498                        enum { BufferSize = 128 };
     499                        char helpText[BufferSize];
     500                        // Do not call strerror( errno ) as it may call malloc.
     501                        int len = snprintf( helpText, BufferSize, "internal error, extend(), mprotect failure, heapEnd:%p size:%zd, errno:%d.", heapEnd, increase, errno );
     502                        __cfaabi_bits_write( STDERR_FILENO, helpText, len );
    506503                } // if
    507504                #ifdef __STATISTICS__
     
    511508                #ifdef __CFA_DEBUG__
    512509                // Set new memory to garbage so subsequent uninitialized usages might fail.
    513                 memset( (char *)heapEnd + heapRemaining, '\xde', increase );
    514                 //Memset( (char *)heapEnd + heapRemaining, increase );
     510                //memset( (char *)heapEnd + heapRemaining, '\377', increase );
     511                Memset( (char *)heapEnd + heapRemaining, increase );
    515512                #endif // __CFA_DEBUG__
    516513                rem = heapRemaining + increase - size;
     
    571568                block->header.kind.real.home = freeElem;                // pointer back to free list of apropriate size
    572569        } else {                                                                                        // large size => mmap
    573   if ( unlikely( size > ULONG_MAX - __page_size ) ) return 0p;
    574                 tsize = ceiling2( tsize, __page_size );                 // must be multiple of page size
     570  if ( unlikely( size > ULONG_MAX - pageSize ) ) return 0p;
     571                tsize = ceiling2( tsize, pageSize );                    // must be multiple of page size
    575572                #ifdef __STATISTICS__
    576573                __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST );
     
    578575                #endif // __STATISTICS__
    579576
    580                 block = (HeapManager.Storage *)mmap( 0, tsize, __map_prot, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
     577                block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
    581578                if ( block == (HeapManager.Storage *)MAP_FAILED ) { // failed ?
    582579                        if ( errno == ENOMEM ) abort( NO_MEMORY_MSG, tsize ); // no memory
     
    586583                #ifdef __CFA_DEBUG__
    587584                // Set new memory to garbage so subsequent uninitialized usages might fail.
    588                 memset( block, '\xde', tsize );
    589                 //Memset( block, tsize );
     585                //memset( block, '\377', tsize );
     586                Memset( block, tsize );
    590587                #endif // __CFA_DEBUG__
    591588                block->header.kind.real.blockSize = tsize;              // storage size for munmap
     
    627624                #endif // __STATISTICS__
    628625                if ( munmap( header, size ) == -1 ) {
     626                        #ifdef __CFA_DEBUG__
    629627                        abort( "Attempt to deallocate storage %p not allocated or with corrupt header.\n"
    630628                                   "Possible cause is invalid pointer.",
    631629                                   addr );
     630                        #endif // __CFA_DEBUG__
    632631                } // if
    633632        } else {
    634633                #ifdef __CFA_DEBUG__
    635634                // Set free memory to garbage so subsequent usages might fail.
    636                 memset( ((HeapManager.Storage *)header)->data, '\xde', freeElem->blockSize - sizeof( HeapManager.Storage ) );
    637                 //Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) );
     635                //memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
     636                Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) );
    638637                #endif // __CFA_DEBUG__
    639638
     
    704703
    705704static void ?{}( HeapManager & manager ) with( manager ) {
    706         __page_size = sysconf( _SC_PAGESIZE );
    707         __map_prot = PROT_READ | PROT_WRITE | PROT_EXEC;
     705        pageSize = sysconf( _SC_PAGESIZE );
    708706
    709707        for ( unsigned int i = 0; i < NoBucketSizes; i += 1 ) { // initialize the free lists
     
    725723
    726724        char * end = (char *)sbrk( 0 );
    727         heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, __page_size ) - end ); // move start of heap to multiple of alignment
     725        heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, pageSize ) - end ); // move start of heap to multiple of alignment
    728726} // HeapManager
    729727
     
    743741        #ifdef __CFA_DEBUG__
    744742        if ( heapBoot ) {                                                                       // check for recursion during system boot
     743                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    745744                abort( "boot() : internal error, recursively invoked during system boot." );
    746745        } // if
     
    10291028        } // cmemalign
    10301029
    1031 
    10321030        // Same as memalign(), but ISO/IEC 2011 C11 Section 7.22.2 states: the value of size shall be an integral multiple
    10331031    // of alignment. This requirement is universally ignored.
     
    10471045        } // posix_memalign
    10481046
    1049 
    10501047        // Allocates size bytes and returns a pointer to the allocated memory. The memory address shall be a multiple of the
    10511048        // page size.  It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    10521049        void * valloc( size_t size ) {
    1053                 return memalign( __page_size, size );
     1050                return memalign( pageSize, size );
    10541051        } // valloc
    10551052
     
    10571054        // Same as valloc but rounds size to multiple of page size.
    10581055        void * pvalloc( size_t size ) {
    1059                 return memalign( __page_size, ceiling2( size, __page_size ) );
     1056                return memalign( pageSize, ceiling2( size, pageSize ) );
    10601057        } // pvalloc
    10611058
     
    11961193                choose( option ) {
    11971194                  case M_TOP_PAD:
    1198                         heapExpand = ceiling2( value, __page_size ); return 1;
     1195                        heapExpand = ceiling2( value, pageSize ); return 1;
    11991196                  case M_MMAP_THRESHOLD:
    12001197                        if ( setMmapStart( value ) ) return 1;
  • src/AST/Convert.cpp

    r41cde266 rc5a98f3  
    205205                ftype->parameters = get<DeclarationWithType>().acceptL(node->params);
    206206
    207                 ftype->forall = get<TypeDecl>().acceptL( node->type_params );
    208                 if (!node->assertions.empty()) {
    209                         assert(!ftype->forall.empty());
    210                         // find somewhere to place assertions back, for convenience it is the last slot
    211                         ftype->forall.back()->assertions = get<DeclarationWithType>().acceptL(node->assertions);
    212                 }
     207                ftype->forall = get<TypeDecl>().acceptL( node->type->forall );
    213208
    214209                visitType(node->type, ftype);
     
    607602
    608603                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
    609                         rslt->add( src_i->first.typeString(),
     604                        rslt->add( src_i->first,
    610605                                   get<Type>().accept1(src_i->second) );
     606                }
     607
     608                for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
     609                        rslt->addVar( src_i->first,
     610                                      get<Expression>().accept1(src_i->second) );
    611611                }
    612612
     
    12121212                // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    12131213                // ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    1214 
    1215                 auto types = get<TypeInstType>().acceptL( node->forall );
    1216                 for (auto t : types) {
    1217                         auto newT = new TypeDecl(*t->baseType);
    1218                         newT->name = t->name; // converted by typeString()
    1219                         for (auto asst : newT->assertions) delete asst;
    1220                         newT->assertions.clear();
    1221                         ty->forall.push_back(newT);
    1222                 }
    1223                 auto assts = get<VariableExpr>().acceptL( node->assertions );
    1224                 if (!assts.empty()) {
    1225                         assert(!types.empty());
    1226                         for (auto asst : assts) {
    1227                                 auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var));
    1228                                 delete newDecl->type;
    1229                                 newDecl->type = asst->result->clone();
    1230                                 newDecl->storageClasses.is_extern = true; // hack
    1231                                 ty->forall.back()->assertions.push_back(newDecl);
    1232                         }
    1233                 }
    1234 
     1214                ty->forall = get<TypeDecl>().acceptL( node->forall );
    12351215                return visitType( node, ty );
    12361216        }
     
    13191299                        ty = new TypeInstType{
    13201300                                cv( node ),
    1321                                 node->typeString(),
     1301                                node->name,
    13221302                                get<TypeDecl>().accept1( node->base ),
    13231303                                get<Attribute>().acceptL( node->attributes )
     
    13261306                        ty = new TypeInstType{
    13271307                                cv( node ),
    1328                                 node->typeString(),
     1308                                node->name,
    13291309                                node->kind == ast::TypeDecl::Ftype,
    13301310                                get<Attribute>().acceptL( node->attributes )
     
    14511431        /// at conversion stage, all created nodes are guaranteed to be unique, therefore
    14521432        /// const_casting out of smart pointers is permitted.
    1453         std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {};
     1433        std::unordered_map< const BaseSyntaxNode *, ast::ptr<ast::Node> > cache = {};
    14541434
    14551435        // Local Utilities:
     
    15851565                // can function type have attributes? seems not to be the case.
    15861566                // visitType(old->type, ftype);
    1587 
    1588                 // collect assertions and put directly in FunctionDecl
    1589                 std::vector<ast::ptr<ast::DeclWithType>> assertions;
    1590                 for (auto & param: forall) {
    1591                         for (auto & asst: param->assertions) {
    1592                                 assertf(asst->unique(), "newly converted decl must be unique");
    1593                                 assertions.emplace_back(asst);
    1594                         }
    1595                         auto mut = param.get_and_mutate();
    1596                         assertf(mut == param, "newly converted decl must be unique");
    1597                         mut->assertions.clear();
    1598                 }
    15991567
    16001568                auto decl = new ast::FunctionDecl{
     
    16161584                cache.emplace( old, decl );
    16171585
    1618                 decl->assertions = std::move(assertions);
    16191586                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    16201587                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    20992066        }
    21002067
    2101         // TypeSubstitution shouldn't exist yet in old.
    21022068        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
    2103                
     2069
    21042070                if (!old) return nullptr;
    2105                 if (old->empty()) return nullptr;
    2106                 assert(false);
    2107 
    2108                 /*
     2071
    21092072                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
    21102073
     
    21142077                }
    21152078
     2079                for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {
     2080                        rslt->addVar( old_i->first,
     2081                                      getAccept1<ast::Expr>(old_i->second) );
     2082                }
     2083
    21162084                return rslt;
    2117                 */
    21182085        }
    21192086
     
    26432610                        ty->params.emplace_back(v->get_type());
    26442611                }
    2645                 // xxx - when will this be non-null?
    2646                 // will have to create dangling (no-owner) decls to be pointed to
    2647                 auto foralls = GET_ACCEPT_V( forall, TypeDecl );
    2648 
    2649                 for (auto & param : foralls) {
    2650                         ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
    2651                         for (auto asst : param->assertions) {
    2652                                 ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
    2653                         }
    2654                 }
     2612                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26552613                visitType( old, ty );
    26562614        }
  • src/AST/Decl.cpp

    r41cde266 rc5a98f3  
    5050
    5151FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name,
    52         std::vector<ptr<TypeDecl>>&& forall,
    53         std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    54         CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
    55         std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, bool isVarArgs)
    56 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
    57         type_params(std::move(forall)), stmts( stmts ) {
    58         FunctionType * ftype = new FunctionType(static_cast<ArgumentFlag>(isVarArgs));
    59         for (auto & param : this->params) {
    60                 ftype->params.emplace_back(param->get_type());
    61         }
    62         for (auto & ret : this->returns) {
    63                 ftype->returns.emplace_back(ret->get_type());
    64         }
    65         for (auto & tp : this->type_params) {
    66                 ftype->forall.emplace_back(new TypeInstType(tp->name, tp));
    67         }
    68         this->type = ftype;
    69 }
     52                std::vector<ptr<TypeDecl>>&& forall,
     53                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     54                CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
     55                std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, bool isVarArgs)
     56        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
     57          stmts( stmts ) {
     58                  FunctionType * ftype = new FunctionType(static_cast<ArgumentFlag>(isVarArgs));
     59                  for (auto & param : this->params) {
     60                          ftype->params.emplace_back(param->get_type());
     61                  }
     62                  for (auto & ret : this->returns) {
     63                          ftype->returns.emplace_back(ret->get_type());
     64                  }
     65                  ftype->forall = std::move(forall);
     66                  this->type = ftype;
     67          }
    7068
    7169
  • src/AST/Decl.hpp

    r41cde266 rc5a98f3  
    127127        std::vector<ptr<DeclWithType>> params;
    128128        std::vector<ptr<DeclWithType>> returns;
    129         std::vector<ptr<TypeDecl>> type_params;
    130         std::vector<ptr<DeclWithType>> assertions;
    131129        // declared type, derived from parameter declarations
    132130        ptr<FunctionType> type;
    133131        ptr<CompoundStmt> stmts;
    134132        std::vector< ptr<Expr> > withExprs;
    135 
    136133
    137134        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
  • src/AST/Expr.cpp

    r41cde266 rc5a98f3  
    206206        assert( aggregate->result );
    207207
    208         result = mem->get_type();
     208        // Deep copy on result type avoids mutation on transitively multiply referenced object.
     209        //
     210        // Example, adapted from parts of builtins and bootloader:
     211        //
     212        // forall(dtype T)
     213        // struct __Destructor {
     214        //   T * object;
     215        //   void (*dtor)(T *);
     216        // };
     217        //
     218        // forall(dtype S)
     219        // void foo(__Destructor(S) &d) {
     220        //   if (d.dtor) {  // here
     221        //   }
     222        // }
     223        //
     224        // Let e be the "d.dtor" guard espression, which is MemberExpr after resolve.  Let d be the
     225        // declaration of member __Destructor.dtor (an ObjectDecl), as accessed via the top-level
     226        // declaration of __Destructor.  Consider the types e.result and d.type.  In the old AST, one
     227        // is a clone of the other.  Ordinary new-AST use would set them up as a multiply-referenced
     228        // object.
     229        //
     230        // e.result: PointerType
     231        // .base: FunctionType
     232        // .params.front(): ObjectDecl, the anonymous parameter of type T*
     233        // .type: PointerType
     234        // .base: TypeInstType
     235        // let x = that
     236        // let y = similar, except start from d.type
     237        //
     238        // Consider two code lines down, genericSubstitution(...).apply(result).
     239        //
     240        // Applying this chosen-candidate's type substitution means modifying x, substituting
     241        // S for T.  This mutation should affect x and not y.
     242
     243        result = deepCopy(mem->get_type());
    209244
    210245        // substitute aggregate generic parameters into member type
  • src/AST/Pass.hpp

    r41cde266 rc5a98f3  
    3434
    3535#include "AST/SymbolTable.hpp"
     36
     37#include "AST/ForallSubstitutionTable.hpp"
    3638
    3739// Private prelude header, needed for some of the magic tricks this class pulls off
     
    6466// | WithVisitorRef        - provides an pointer to the templated visitor wrapper
    6567// | WithSymbolTable       - provides symbol table functionality
     68// | WithForallSubstitutor - maintains links between TypeInstType and TypeDecl under mutation
    6669//
    6770// Other Special Members:
     
    255258        container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container );
    256259
     260        /// Mutate forall-list, accounting for presence of type substitution map
     261        template<typename node_t>
     262        void mutate_forall( const node_t *& );
     263
    257264public:
    258265        /// Logic to call the accept and mutate the parent if needed, delegates call to accept
     
    391398};
    392399
     400/// Use when the templated visitor needs to keep TypeInstType instances properly linked to TypeDecl
     401struct WithForallSubstitutor {
     402        ForallSubstitutionTable subs;
     403};
     404
    393405}
    394406
  • src/AST/Pass.impl.hpp

    r41cde266 rc5a98f3  
    367367        }
    368368
     369
     370        template< typename core_t >
     371        template< typename node_t >
     372        void ast::Pass< core_t >::mutate_forall( const node_t *& node ) {
     373                if ( auto subs = __pass::forall::subs( core, 0 ) ) {
     374                        // tracking TypeDecl substitution, full clone
     375                        if ( node->forall.empty() ) return;
     376
     377                        node_t * mut = __pass::mutate<core_t>( node );
     378                        mut->forall = subs->clone( node->forall, *this );
     379                        node = mut;
     380                } else {
     381                        // not tracking TypeDecl substitution, just mutate
     382                        maybe_accept( node, &node_t::forall );
     383                }
     384        }
    369385}
    370386
     
    488504                        __pass::symtab::addId( core, 0, func );
    489505                        VISIT(
    490                                 // parameter declarations
     506                                // parameter declarations are now directly here
    491507                                maybe_accept( node, &FunctionDecl::params );
    492508                                maybe_accept( node, &FunctionDecl::returns );
    493                                 // type params and assertions
    494                                 maybe_accept( node, &FunctionDecl::type_params );
    495                                 maybe_accept( node, &FunctionDecl::assertions );
     509                                // foralls are still in function type
     510                                maybe_accept( node, &FunctionDecl::type );
    496511                                // First remember that we are now within a function.
    497512                                ValueGuard< bool > oldInFunction( inFunction );
     
    17431758
    17441759        VISIT({
    1745                 // guard_forall_subs forall_guard { *this, node };
    1746                 // mutate_forall( node );
    1747                 maybe_accept( node, &FunctionType::assertions );
     1760                guard_forall_subs forall_guard { *this, node };
     1761                mutate_forall( node );
    17481762                maybe_accept( node, &FunctionType::returns );
    17491763                maybe_accept( node, &FunctionType::params  );
     
    19671981                {
    19681982                        bool mutated = false;
    1969                         std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
     1983                        std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
    19701984                        for ( const auto & p : node->typeEnv ) {
    19711985                                guard_symtab guard { *this };
     
    19801994                        }
    19811995                }
     1996
     1997                {
     1998                        bool mutated = false;
     1999                        std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
     2000                        for ( const auto & p : node->varEnv ) {
     2001                                guard_symtab guard { *this };
     2002                                auto new_node = p.second->accept( *this );
     2003                                if (new_node != p.second) mutated = true;
     2004                                new_map.insert({ p.first, new_node });
     2005                        }
     2006                        if (mutated) {
     2007                                auto new_node = __pass::mutate<core_t>( node );
     2008                                new_node->varEnv.swap( new_map );
     2009                                node = new_node;
     2010                        }
     2011                }
    19822012        )
    19832013
  • src/AST/Pass.proto.hpp

    r41cde266 rc5a98f3  
    413413                static inline auto leave( core_t &, long, const ast::FunctionType * ) {}
    414414
     415                // Get the substitution table, if present
     416                template<typename core_t>
     417                static inline auto subs( core_t & core, int ) -> decltype( &core.subs ) {
     418                        return &core.subs;
     419                }
     420
     421                template<typename core_t>
     422                static inline ast::ForallSubstitutionTable * subs( core_t &, long ) { return nullptr; }
     423
    415424                // Replaces a TypeInstType's base TypeDecl according to the table
    416425                template<typename core_t>
  • src/AST/Print.cpp

    r41cde266 rc5a98f3  
    155155        }
    156156
    157         void print( const ast::FunctionType::AssertionList & assts ) {
    158                 if (assts.empty()) return;
    159                 os << "with assertions" << endl;
    160                 ++indent;
    161                 printAll(assts);
    162                 os << indent;
    163                 --indent;
    164         }
    165 
    166157        void print( const std::vector<ptr<Attribute>> & attrs ) {
    167158                if ( attrs.empty() ) return;
     
    215206        void preprint( const ast::NamedTypeDecl * node ) {
    216207                if ( ! node->name.empty() ) {
    217                         os << node->name << ": ";
     208                        if( deterministic_output && isUnboundType(node->name) ) os << "[unbound]:";
     209                        else os << node->name << ": ";
    218210                }
    219211
     
    269261        void preprint( const ast::FunctionType * node ) {
    270262                print( node->forall );
    271                 print( node->assertions );
    272263                print( node->qualifiers );
    273264        }
     
    13841375        virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
    13851376                preprint( node );
    1386                 const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString();
     1377                const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->name;
    13871378                os << "instance of type " << _name
    13881379                   << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
     
    15111502                os << indent << "Types:" << endl;
    15121503                for ( const auto& i : *node ) {
    1513                         os << indent+1 << i.first.typeString() << " -> ";
     1504                        os << indent+1 << i.first << " -> ";
    15141505                        indent += 2;
    15151506                        safe_print( i.second );
     1507                        indent -= 2;
     1508                        os << endl;
     1509                }
     1510                os << indent << "Non-types:" << endl;
     1511                for ( auto i = node->beginVar(); i != node->endVar(); ++i ) {
     1512                        os << indent+1 << i->first << " -> ";
     1513                        indent += 2;
     1514                        safe_print( i->second );
    15161515                        indent -= 2;
    15171516                        os << endl;
  • src/AST/SymbolTable.cpp

    r41cde266 rc5a98f3  
    414414
    415415void SymbolTable::addFunction( const FunctionDecl * func ) {
    416         for (auto & td : func->type_params) {
    417                 addType(td);
    418         }
    419         for (auto & asst : func->assertions) {
    420                 addId(asst);
    421         }
    422         // addTypes( func->type->forall );
     416        addTypes( func->type->forall );
    423417        addIds( func->returns );
    424418        addIds( func->params );
  • src/AST/Type.cpp

    r41cde266 rc5a98f3  
    2121
    2222#include "Decl.hpp"
     23#include "ForallSubstitutor.hpp" // for substituteForall
    2324#include "Init.hpp"
    2425#include "Common/utility.h"      // for copy, move
     
    9192// GENERATED END
    9293
     94// --- ParameterizedType
     95
     96void FunctionType::initWithSub(
     97        const FunctionType & o, Pass< ForallSubstitutor > & sub
     98) {
     99        forall = sub.core( o.forall );
     100}
     101
    93102// --- FunctionType
     103
     104
     105FunctionType::FunctionType( const FunctionType & o )
     106: Type( o.qualifiers, copy( o.attributes ) ), returns(), params(),
     107  isVarArgs( o.isVarArgs ) {
     108        Pass< ForallSubstitutor > sub;
     109        initWithSub( o, sub );           // initialize substitution map
     110        returns = sub.core( o.returns ); // apply to return and parameter types
     111        params = sub.core( o.params );
     112}
     113
    94114namespace {
    95115        bool containsTtype( const std::vector<ptr<Type>> & l ) {
     
    179199                // TODO: once TypeInstType representation is updated, it should properly check
    180200                // if the context id is filled. this is a temporary hack for now
    181                 return typeInst->formal_usage > 0;
     201                return isUnboundType(typeInst->name);
     202        }
     203        return false;
     204}
     205
     206bool isUnboundType(const std::string & tname) {
     207        // xxx - look for a type name produced by renameTyVars.
     208
     209        // TODO: once TypeInstType representation is updated, it should properly check
     210        // if the context id is filled. this is a temporary hack for now
     211        if (std::count(tname.begin(), tname.end(), '_') >= 3) {
     212                return true;
    182213        }
    183214        return false;
  • src/AST/Type.hpp

    r41cde266 rc5a98f3  
    3636
    3737template< typename T > class Pass;
     38
     39struct ForallSubstitutor;
    3840
    3941class Type : public Node {
     
    270272/// Type of a function `[R1, R2](*)(P1, P2, P3)`
    271273class FunctionType final : public Type {
    272 public:
    273         using ForallList = std::vector<ptr<TypeInstType>>;
    274         using AssertionList = std::vector<ptr<VariableExpr>>;
     274        protected:
     275        /// initializes forall with substitutor
     276        void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub );
     277public:
     278        using ForallList = std::vector<ptr<TypeDecl>>;
    275279        ForallList forall;
    276         AssertionList assertions;
    277280
    278281        std::vector<ptr<Type>> returns;
     
    289292        : Type(q), returns(), params(), isVarArgs(va) {}
    290293
    291         FunctionType( const FunctionType & o ) = default;
     294        FunctionType( const FunctionType & o );
    292295
    293296        /// true if either the parameters or return values contain a tttype
     
    394397public:
    395398        readonly<TypeDecl> base;
    396         // previously from renameTyVars; now directly use integer fields instead of synthesized strings
    397         // a nonzero value of formal_usage indicates a formal type (only used in function type)
    398         // a zero value of formal_usage indicates an actual type (referenced inside body of parametric structs and functions)
    399399        TypeDecl::Kind kind;
    400         int formal_usage = 0;
    401         int expr_id = 0;
    402 
    403         // compact representation used for map lookups.
    404         struct TypeEnvKey {
    405                 const TypeDecl * base;
    406                 int formal_usage;
    407                 int expr_id;
    408 
    409                 TypeEnvKey() = default;
    410                 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0): base(base), formal_usage(formal_usage), expr_id(expr_id) {}
    411                 TypeEnvKey(const TypeInstType & inst): base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
    412                 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
    413                 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    414 
    415         };
    416 
    417         bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    418400
    419401        TypeInstType(
     
    427409        TypeInstType( const TypeInstType & o ) = default;
    428410
    429         TypeInstType( const TypeEnvKey & key )
    430         : BaseInstType(key.base->name), base(key.base), kind(key.base->kind), formal_usage(key.formal_usage), expr_id(key.expr_id) {}
    431 
    432411        /// sets `base`, updating `kind` correctly
    433412        void set_base( const TypeDecl * );
     
    439418
    440419        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    441 
    442         std::string typeString() const {
    443                 if (formal_usage > 0) return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + name;
    444                 else return name;
    445         }
    446420private:
    447421        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
     
    536510
    537511bool isUnboundType(const Type * type);
    538 
    539 }
    540 
    541 namespace std {
    542         template<>
    543         struct hash<typename ast::TypeInstType::TypeEnvKey> {
    544                 size_t operator() (const ast::TypeInstType::TypeEnvKey & x) const {
    545                         const size_t p = 1000007;
    546                         size_t res = reinterpret_cast<size_t>(x.base);
    547                         res = p * res + x.formal_usage;
    548                         res = p * res + x.expr_id;
    549                         return res;
    550                 }
    551         };
     512bool isUnboundType(const std::string & tname);
     513
    552514}
    553515
  • src/AST/TypeEnvironment.cpp

    r41cde266 rc5a98f3  
    5252        for ( const auto & i : open ) {
    5353                if ( first ) { first = false; } else { out << ' '; }
    54                 out << i.first.typeString() << "(" << i.second << ")";
     54                out << i.first << "(" << i.second << ")";
    5555        }
    5656}
     
    6262                if(first) first = false;
    6363                else out << " ";
    64 
    65                 if( deterministic_output ) out << "[unbound]";
    66                 else out << "_" << var.formal_usage << "_" << var.expr_id << "_";
    67 
    68                 out << var.base->name;
     64                if( deterministic_output && isUnboundType(var) ) out << "[unbound]";
     65                else out << var;
    6966        }
    7067        out << ")";
     
    8279}
    8380
    84 const EqvClass * TypeEnvironment::lookup( const TypeInstType::TypeEnvKey & var ) const {
     81const EqvClass * TypeEnvironment::lookup( const std::string & var ) const {
    8582        for ( ClassList::const_iterator i = env.begin(); i != env.end(); ++i ) {
    8683                if ( i->vars.find( var ) != i->vars.end() ) return &*i;
     
    109106
    110107void TypeEnvironment::add( const FunctionType::ForallList & tyDecls ) {
    111         for ( auto & tyDecl : tyDecls ) {
     108        for ( const TypeDecl * tyDecl : tyDecls ) {
    112109                env.emplace_back( tyDecl );
    113110        }
     
    122119void TypeEnvironment::writeToSubstitution( TypeSubstitution & sub ) const {
    123120        for ( const auto & clz : env ) {
    124                 TypeInstType::TypeEnvKey clzRep;
    125                 bool first = true;
     121                std::string clzRep;
    126122                for ( const auto & var : clz.vars ) {
    127123                        if ( clz.bound ) {
    128124                                sub.add( var, clz.bound );
    129                         } else if ( first ) {
     125                        } else if ( clzRep.empty() ) {
    130126                                clzRep = var;
    131                                 first = false;
    132127                        } else {
    133                                 sub.add( var, new TypeInstType{ clzRep } );
     128                                sub.add( var, new TypeInstType{ clzRep, clz.data.kind } );
    134129                        }
    135130                }
     
    146141        struct Occurs : public ast::WithVisitorRef<Occurs> {
    147142                bool result;
    148                 std::unordered_set< TypeInstType::TypeEnvKey > vars;
     143                std::set< std::string > vars;
    149144                const TypeEnvironment & tenv;
    150145
    151                 Occurs( const TypeInstType::TypeEnvKey & var, const TypeEnvironment & env )
     146                Occurs( const std::string & var, const TypeEnvironment & env )
    152147                : result( false ), vars(), tenv( env ) {
    153148                        if ( const EqvClass * clz = tenv.lookup( var ) ) {
     
    159154
    160155                void previsit( const TypeInstType * typeInst ) {
    161                         if ( vars.count( *typeInst ) ) {
     156                        if ( vars.count( typeInst->name ) ) {
    162157                                result = true;
    163                         } else if ( const EqvClass * clz = tenv.lookup( *typeInst ) ) {
     158                        } else if ( const EqvClass * clz = tenv.lookup( typeInst->name ) ) {
    164159                                if ( clz->bound ) {
    165160                                        clz->bound->accept( *visitor );
     
    170165
    171166        /// true if `var` occurs in `ty` under `env`
    172         bool occurs( const Type * ty, const TypeInstType::TypeEnvKey & var, const TypeEnvironment & env ) {
     167        bool occurs( const Type * ty, const std::string & var, const TypeEnvironment & env ) {
    173168                Pass<Occurs> occur{ var, env };
    174169                maybe_accept( ty, occur );
     
    285280        // remove references from bound type, so that type variables can only bind to value types
    286281        ptr<Type> target = bindTo->stripReferences();
    287         auto tyvar = open.find( *typeInst );
     282        auto tyvar = open.find( typeInst->name );
    288283        assert( tyvar != open.end() );
    289284        if ( ! tyVarCompatible( tyvar->second, target ) ) return false;
    290         if ( occurs( target, *typeInst, *this ) ) return false;
    291 
    292         auto it = internal_lookup( *typeInst );
     285        if ( occurs( target, typeInst->name, *this ) ) return false;
     286
     287        auto it = internal_lookup( typeInst->name );
    293288        if ( it != env.end() ) {
    294289                if ( it->bound ) {
     
    313308        } else {
    314309                env.emplace_back(
    315                         *typeInst, target, widen.first && widen.second, data );
     310                        typeInst->name, target, widen.first && widen.second, data );
    316311        }
    317312        return true;
     
    323318                WidenMode widen, const SymbolTable & symtab
    324319) {
    325         auto c1 = internal_lookup( *var1 );
    326         auto c2 = internal_lookup( *var2 );
     320        auto c1 = internal_lookup( var1->name );
     321        auto c2 = internal_lookup( var2->name );
    327322
    328323        // exit early if variables already bound together
     
    338333        if ( c1 != env.end() ) {
    339334                if ( c1->bound ) {
    340                         if ( occurs( c1->bound, *var2, *this ) ) return false;
     335                        if ( occurs( c1->bound, var2->name, *this ) ) return false;
    341336                        type1 = c1->bound;
    342337                }
     
    345340        if ( c2 != env.end() ) {
    346341                if ( c2->bound ) {
    347                         if ( occurs( c2->bound, *var1, *this ) ) return false;
     342                        if ( occurs( c2->bound, var1->name, *this ) ) return false;
    348343                        type2 = c2->bound;
    349344                }
     
    383378        } else if ( c1 != env.end() ) {
    384379                // var2 unbound, add to env[c1]
    385                 c1->vars.emplace( *var2 );
     380                c1->vars.emplace( var2->name );
    386381                c1->allowWidening = widen1;
    387382                c1->data.isComplete |= data.isComplete;
    388383        } else if ( c2 != env.end() ) {
    389384                // var1 unbound, add to env[c2]
    390                 c2->vars.emplace( *var1 );
     385                c2->vars.emplace( var1->name );
    391386                c2->allowWidening = widen2;
    392387                c2->data.isComplete |= data.isComplete;
    393388        } else {
    394389                // neither var bound, create new class
    395                 env.emplace_back( *var1, *var2, widen1 && widen2, data );
     390                env.emplace_back( var1->name, var2->name, widen1 && widen2, data );
    396391        }
    397392
     
    457452}
    458453
    459 TypeEnvironment::ClassList::iterator TypeEnvironment::internal_lookup( const TypeInstType::TypeEnvKey & var ) {
     454TypeEnvironment::ClassList::iterator TypeEnvironment::internal_lookup( const std::string & var ) {
    460455        for ( ClassList::iterator i = env.begin(); i != env.end(); ++i ) {
    461456                if ( i->vars.count( var ) ) return i;
  • src/AST/TypeEnvironment.hpp

    r41cde266 rc5a98f3  
    5555/// recorded. More investigation is needed.
    5656struct AssertCompare {
    57         bool operator()( const VariableExpr * d1, const VariableExpr * d2 ) const {
    58                 int cmp = d1->var->name.compare( d2->var->name );
    59                 return cmp < 0 || ( cmp == 0 && d1->result < d2->result );
     57        bool operator()( const DeclWithType * d1, const DeclWithType * d2 ) const {
     58                int cmp = d1->name.compare( d2->name );
     59                return cmp < 0 || ( cmp == 0 && d1->get_type() < d2->get_type() );
    6060        }
    6161};
     
    7070
    7171/// Set of assertions pending satisfaction
    72 using AssertionSet = std::map< const VariableExpr *, AssertionSetValue, AssertCompare >;
     72using AssertionSet = std::map< readonly<DeclWithType>, AssertionSetValue, AssertCompare >;
    7373
    7474/// Set of open variables
    75 using OpenVarSet = std::unordered_map< TypeInstType::TypeEnvKey, TypeDecl::Data >;
     75using OpenVarSet = std::unordered_map< std::string, TypeDecl::Data >;
    7676
    7777/// Merges one set of open vars into another
     
    8989/// they bind to.
    9090struct EqvClass {
    91         std::unordered_set< TypeInstType::TypeEnvKey > vars;
     91        std::set< std::string > vars;
    9292        ptr<Type> bound;
    9393        bool allowWidening;
     
    101101
    102102        /// Singleton class constructor from TypeDecl
    103         EqvClass( const TypeInstType * inst )
    104         : vars{ *inst }, bound(), allowWidening( true ), data( inst->base ) {}
     103        EqvClass( const TypeDecl * decl )
     104        : vars{ decl->name }, bound(), allowWidening( true ), data( decl ) {}
    105105
    106106        /// Singleton class constructor from substitution
    107         EqvClass( const TypeInstType::TypeEnvKey & v, const Type * b )
     107        EqvClass( const std::string & v, const Type * b )
    108108        : vars{ v }, bound( b ), allowWidening( false ), data( TypeDecl::Dtype, false ) {}
    109109
    110110        /// Single-var constructor (strips qualifiers from bound type)
    111         EqvClass( const TypeInstType::TypeEnvKey & v, const Type * b, bool w, const TypeDecl::Data & d )
     111        EqvClass( const std::string & v, const Type * b, bool w, const TypeDecl::Data & d )
    112112        : vars{ v }, bound( b ), allowWidening( w ), data( d ) {
    113113                reset_qualifiers( bound );
     
    115115
    116116        /// Double-var constructor
    117         EqvClass( const TypeInstType::TypeEnvKey & v, const TypeInstType::TypeEnvKey & u, bool w, const TypeDecl::Data & d )
     117        EqvClass( const std::string & v, const std::string & u, bool w, const TypeDecl::Data & d )
    118118        : vars{ v, u }, bound(), allowWidening( w ), data( d ) {}
    119119
     
    131131public:
    132132        /// Finds the equivalence class containing a variable; nullptr for none such
    133         const EqvClass * lookup( const TypeInstType::TypeEnvKey & var ) const;
     133        const EqvClass * lookup( const std::string & var ) const;
    134134
    135135        /// Add a new equivalence class for each type variable
     
    207207
    208208        /// Private lookup API; returns array index of string, or env.size() for not found
    209         ClassList::iterator internal_lookup( const TypeInstType::TypeEnvKey & );
     209        ClassList::iterator internal_lookup( const std::string & );
    210210};
    211211
  • src/AST/TypeSubstitution.cpp

    r41cde266 rc5a98f3  
    3939void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) {
    4040        dest.typeEnv.clear();
     41        dest.varEnv.clear();
    4142        dest.add( src );
    4243}
     
    4647                typeEnv[ i->first ] = i->second;
    4748        } // for
    48 }
    49 
    50 void TypeSubstitution::add( const TypeInstType * formalType, const Type *actualType ) {
    51         typeEnv[ *formalType ] = actualType;
    52 }
    53 
    54 void TypeSubstitution::add( const TypeInstType::TypeEnvKey & key, const Type * actualType) {
    55         typeEnv[ key ] = actualType;
    56 }
    57 
    58 void TypeSubstitution::remove( const TypeInstType * formalType ) {
    59         TypeEnvType::iterator i = typeEnv.find( *formalType );
     49        for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) {
     50                varEnv[ i->first ] = i->second;
     51        } // for
     52}
     53
     54void TypeSubstitution::add( std::string formalType, const Type *actualType ) {
     55        typeEnv[ formalType ] = actualType;
     56}
     57
     58void TypeSubstitution::addVar( std::string formalExpr, const Expr *actualExpr ) {
     59        varEnv[ formalExpr ] = actualExpr;
     60}
     61
     62void TypeSubstitution::remove( std::string formalType ) {
     63        TypeEnvType::iterator i = typeEnv.find( formalType );
    6064        if ( i != typeEnv.end() ) {
    61                 typeEnv.erase( *formalType );
    62         } // if
    63 }
    64 
    65 const Type *TypeSubstitution::lookup( const TypeInstType * formalType ) const {
    66         TypeEnvType::const_iterator i = typeEnv.find( *formalType );
     65                typeEnv.erase( formalType );
     66        } // if
     67}
     68
     69const Type *TypeSubstitution::lookup( std::string formalType ) const {
     70        TypeEnvType::const_iterator i = typeEnv.find( formalType );
    6771
    6872        // break on not in substitution set
     
    7175        // attempt to transitively follow TypeInstType links.
    7276        while ( const TypeInstType *actualType = i->second.as<TypeInstType>()) {
     77                const std::string& typeName = actualType->name;
     78
    7379                // break cycles in the transitive follow
    74                 if ( *formalType == *actualType ) break;
     80                if ( formalType == typeName ) break;
    7581
    7682                // Look for the type this maps to, returning previous mapping if none-such
    77                 i = typeEnv.find( *actualType );
     83                i = typeEnv.find( typeName );
    7884                if ( i == typeEnv.end() ) return actualType;
    7985        }
     
    8490
    8591bool TypeSubstitution::empty() const {
    86         return typeEnv.empty();
     92        return typeEnv.empty() && varEnv.empty();
    8793}
    8894
     
    9298                TypeSubstitution * newEnv;
    9399                EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
    94                 void previsit( FunctionType * ftype ) {
     100                void previsit( TypeDecl * tyDecl ) {
    95101                        // transfer known bindings for seen type variables
    96                         for (auto & formal : ftype->forall) {
    97                                 if ( const Type * t = env->lookup( formal ) ) {
    98                                         newEnv->add( formal, t );
    99                                 }
     102                        if ( const Type * t = env->lookup( tyDecl->name ) ) {
     103                                newEnv->add( tyDecl->name, t );
    100104                        }
    101105                }
     
    126130
    127131const Type * TypeSubstitution::Substituter::postvisit( const TypeInstType *inst ) {
    128         BoundVarsType::const_iterator bound = boundVars.find( *inst );
     132        BoundVarsType::const_iterator bound = boundVars.find( inst->name );
    129133        if ( bound != boundVars.end() ) return inst;
    130134
    131         TypeEnvType::const_iterator i = sub.typeEnv.find( *inst );
     135        TypeEnvType::const_iterator i = sub.typeEnv.find( inst->name );
    132136        if ( i == sub.typeEnv.end() ) {
    133137                return inst;
     
    137141                // TODO: investigate preventing type variables from being bound to themselves in the first place.
    138142                if ( const TypeInstType * replacement = i->second.as<TypeInstType>() ) {
    139                         if ( *inst == *replacement ) {
     143                        if ( inst->name == replacement->name ) {
    140144                                return inst;
    141145                        }
     
    152156}
    153157
     158const Expr * TypeSubstitution::Substituter::postvisit( const NameExpr * nameExpr ) {
     159        VarEnvType::const_iterator i = sub.varEnv.find( nameExpr->name );
     160        if ( i == sub.varEnv.end() ) {
     161                return nameExpr;
     162        } else {
     163                subCount++;
     164                return i->second;
     165        } // if
     166}
     167
    154168void TypeSubstitution::Substituter::previsit( const FunctionType * ptype ) {
    155169        GuardValue( boundVars );
    156170        // bind type variables from forall-qualifiers
    157171        if ( freeOnly ) {
    158                 for ( auto & tyvar : ptype->forall ) {
    159                                 boundVars.insert( *tyvar );
     172                for ( const TypeDecl * tyvar : ptype->forall ) {
     173                                boundVars.insert( tyvar->name );
    160174                } // for
    161175        } // if
    162176}
    163177
    164 /*
    165178void TypeSubstitution::Substituter::handleAggregateType( const BaseInstType * type ) {
    166179        GuardValue( boundVars );
     
    171184                        if ( ! type->params.empty() ) {
    172185                                for ( const TypeDecl * tyvar : decl->params ) {
    173                                         boundVars.insert( *tyvar );
     186                                        boundVars.insert( tyvar->name );
    174187                                } // for
    175188                        } // if
     
    185198        handleAggregateType( aggregateUseType );
    186199}
    187 */
    188200
    189201} // namespace ast
  • src/AST/TypeSubstitution.hpp

    r41cde266 rc5a98f3  
    6969        }
    7070
    71         void add( const TypeInstType * formalType, const Type *actualType );
    72         void add( const TypeInstType::TypeEnvKey & key, const Type *actualType );
     71        void add( std::string formalType, const Type *actualType );
    7372        void add( const TypeSubstitution &other );
    74         void remove( const TypeInstType * formalType );
    75         const Type *lookup( const TypeInstType * formalType ) const;
     73        void remove( std::string formalType );
     74        const Type *lookup( std::string formalType ) const;
    7675        bool empty() const;
     76
     77        void addVar( std::string formalExpr, const Expr *actualExpr );
    7778
    7879        template< typename FormalIterator, typename ActualIterator >
     
    100101        friend class Pass;
    101102
    102         typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeEnvType;
     103        typedef std::unordered_map< std::string, ptr<Type> > TypeEnvType;
     104        typedef std::unordered_map< std::string, ptr<Expr> > VarEnvType;
    103105        TypeEnvType typeEnv;
     106        VarEnvType varEnv;
    104107
    105108  public:
     
    110113        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
    111114
     115        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     116        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     117        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     118        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    112119};
    113120
    114 // this is the only place where type parameters outside a function formal may be substituted.
    115121template< typename FormalIterator, typename ActualIterator >
    116122void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {
     
    123129                        if ( const TypeExpr *actual = actualIt->template as<TypeExpr>() ) {
    124130                                if ( formal->name != "" ) {
    125                                         typeEnv[ formal ] = actual->type;
     131                                        typeEnv[ formal->name ] = actual->type;
    126132                                } // if
    127133                        } else {
     
    129135                        } // if
    130136                } else {
    131                        
     137                        // TODO: type check the formal and actual parameters
     138                        if ( (*formalIt)->name != "" ) {
     139                                varEnv[ (*formalIt)->name ] = *actualIt;
     140                        } // if
    132141                } // if
    133142        } // for
    134143}
    135 
    136 
    137144
    138145template< typename FormalIterator, typename ActualIterator >
     
    140147        add( formalBegin, formalEnd, actualBegin );
    141148}
    142 
    143149
    144150} // namespace ast
     
    158164
    159165                const Type * postvisit( const TypeInstType * aggregateUseType );
     166                const Expr * postvisit( const NameExpr * nameExpr );
    160167
    161168                /// Records type variable bindings from forall-statements
    162169                void previsit( const FunctionType * type );
    163170                /// Records type variable bindings from forall-statements and instantiations of generic types
    164                 // void handleAggregateType( const BaseInstType * type );
    165 
    166                 // void previsit( const StructInstType * aggregateUseType );
    167                 // void previsit( const UnionInstType * aggregateUseType );
     171                void handleAggregateType( const BaseInstType * type );
     172
     173                void previsit( const StructInstType * aggregateUseType );
     174                void previsit( const UnionInstType * aggregateUseType );
    168175
    169176                const TypeSubstitution & sub;
    170177                int subCount = 0;
    171178                bool freeOnly;
    172                 typedef std::unordered_set< TypeInstType::TypeEnvKey > BoundVarsType;
     179                typedef std::unordered_set< std::string > BoundVarsType;
    173180                BoundVarsType boundVars;
    174181
  • src/AST/module.mk

    r41cde266 rc5a98f3  
    3333        AST/Expr.cpp \
    3434        AST/Expr.hpp \
     35        AST/ForallSubstitutionTable.cpp \
     36        AST/ForallSubstitutionTable.hpp \
     37        AST/ForallSubstitutor.hpp \
    3538        AST/FunctionSpec.hpp \
    3639        AST/Fwd.hpp \
  • src/GenPoly/GenPoly.cc

    r41cde266 rc5a98f3  
    115115                if (!env) return type;
    116116                if (auto typeInst = dynamic_cast<const ast::TypeInstType*> (type)) {
    117                         auto newType = env->lookup(typeInst);
     117                        auto newType = env->lookup(typeInst->name);
    118118                        if (newType) return newType;
    119119                }
     
    172172
    173173                if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    174                         return tyVars.find(typeInst->typeString()) != tyVars.end() ? type : nullptr;
     174                        return tyVars.find(typeInst->name) != tyVars.end() ? type : nullptr;
    175175                } else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
    176176                        return isPolyType( arrayType->base, env );
     
    552552        }
    553553
    554         void addToTyVarMap( const ast::TypeInstType * tyVar, TyVarMap & tyVarMap) {
    555                 tyVarMap.insert(tyVar->typeString(), convData(ast::TypeDecl::Data{tyVar->base}));
     554        void addToTyVarMap( const ast::TypeDecl * tyVar, TyVarMap & tyVarMap) {
     555                tyVarMap.insert(tyVar->name, convData(ast::TypeDecl::Data{tyVar}));
    556556        }
    557557
  • src/ResolvExpr/AdjustExprType.cc

    r41cde266 rc5a98f3  
    133133                const ast::Type * postvisit( const ast::TypeInstType * inst ) {
    134134                        // replace known function-type-variables with pointer-to-function
    135                         if ( const ast::EqvClass * eqvClass = tenv.lookup( *inst ) ) {
     135                        if ( const ast::EqvClass * eqvClass = tenv.lookup( inst->name ) ) {
    136136                                if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
    137137                                        return new ast::PointerType{ inst };
  • src/ResolvExpr/CandidateFinder.cpp

    r41cde266 rc5a98f3  
    212212                // mark type variable and specialization cost of forall clause
    213213                convCost.incVar( function->forall.size() );
    214                 convCost.decSpec( function->assertions.size() );
     214                for ( const ast::TypeDecl * td : function->forall ) {
     215                        convCost.decSpec( td->assertions.size() );
     216                }
    215217
    216218                return convCost;
     
    221223                ast::AssertionSet & need
    222224        ) {
    223                 for ( auto & tyvar : type->forall ) {
    224                         unifiableVars[ *tyvar ] = ast::TypeDecl::Data{ tyvar->base };
    225                 }
    226                 for ( auto & assn : type->assertions ) {
    227                         need[ assn ].isUsed = true;
     225                for ( const ast::TypeDecl * tyvar : type->forall ) {
     226                        unifiableVars[ tyvar->name ] = ast::TypeDecl::Data{ tyvar };
     227                        for ( const ast::DeclWithType * assn : tyvar->assertions ) {
     228                                need[ assn ].isUsed = true;
     229                        }
    228230                }
    229231        }
     
    951953                                                auto inst = dynamic_cast< const ast::TypeInstType * >( funcResult )
    952954                                        ) {
    953                                                 if ( const ast::EqvClass * clz = func->env.lookup( *inst ) ) {
     955                                                if ( const ast::EqvClass * clz = func->env.lookup( inst->name ) ) {
    954956                                                        if ( auto function = clz->bound.as< ast::FunctionType >() ) {
    955957                                                                CandidateRef newFunc{ new Candidate{ *func } };
     
    10751077                        assert( toType );
    10761078                        toType = resolveTypeof( toType, symtab );
    1077                         // toType = SymTab::validateType( castExpr->location, toType, symtab );
     1079                        toType = SymTab::validateType( castExpr->location, toType, symtab );
    10781080                        toType = adjustExprType( toType, tenv, symtab );
    10791081
     
    11601162
    11611163                                        if(auto insttype = dynamic_cast<const ast::TypeInstType*>(expr)) {
    1162                                                 auto td = cand->env.lookup(*insttype);
     1164                                                auto td = cand->env.lookup(insttype->name);
    11631165                                                if(!td) { continue; }
    11641166                                                expr = td->bound.get();
     
    15661568                                // calculate target type
    15671569                                const ast::Type * toType = resolveTypeof( initAlt.type, symtab );
    1568                                 // toType = SymTab::validateType( initExpr->location, toType, symtab );
     1570                                toType = SymTab::validateType( initExpr->location, toType, symtab );
    15691571                                toType = adjustExprType( toType, tenv, symtab );
    15701572                                // The call to find must occur inside this loop, otherwise polymorphic return
  • src/ResolvExpr/CastCost.cc

    r41cde266 rc5a98f3  
    202202) {
    203203        if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    204                 if ( const ast::EqvClass * eqvClass = env.lookup( *typeInst ) ) {
     204                if ( const ast::EqvClass * eqvClass = env.lookup( typeInst->name ) ) {
    205205                        // check cast cost against bound type, if present
    206206                        if ( eqvClass->bound ) {
  • src/ResolvExpr/CommonType.cc

    r41cde266 rc5a98f3  
    713713                        const ast::Type * base = oPtr->base;
    714714                        if ( auto var = dynamic_cast< const ast::TypeInstType * >( base ) ) {
    715                                 auto entry = open.find( *var );
     715                                auto entry = open.find( var->name );
    716716                                if ( entry != open.end() ) {
    717717                                        ast::AssertionSet need, have;
  • src/ResolvExpr/ConversionCost.cc

    r41cde266 rc5a98f3  
    498498) {
    499499        if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    500                 if ( const ast::EqvClass * eqv = env.lookup( *inst ) ) {
     500                if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) {
    501501                        if ( eqv->bound ) {
    502502                                return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env );
     
    675675
    676676void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) {
    677         if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) {
     677        if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) {
    678678                cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env );
    679679        } else if ( const ast::TypeInstType * dstAsInst =
    680680                        dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    681                 if ( *typeInstType == *dstAsInst ) {
     681                if ( typeInstType->name == dstAsInst->name ) {
    682682                        cost = Cost::zero;
    683683                }
  • src/ResolvExpr/FindOpenVars.cc

    r41cde266 rc5a98f3  
    112112                                // mark open/closed variables
    113113                                if ( nextIsOpen ) {
    114                                         for ( auto & decl : type->forall ) {
    115                                                 open[ *decl ] = ast::TypeDecl::Data{ decl->base };
    116                                         }
    117                                         for ( auto & assert : type->assertions ) {
    118                                                 need[ assert ].isUsed = false;
     114                                        for ( const ast::TypeDecl * decl : type->forall ) {
     115                                                open[ decl->name ] = ast::TypeDecl::Data{ decl };
     116                                                for ( const ast::DeclWithType * assert : decl->assertions ) {
     117                                                        need[ assert ].isUsed = false;
     118                                                }
    119119                                        }
    120120                                } else {
    121                                         for ( auto & decl : type->forall ) {
    122                                                 closed[ *decl ] = ast::TypeDecl::Data{ decl->base };   
    123                                         }
    124                                         for ( auto & assert : type->assertions ) {
    125                                                 have[ assert ].isUsed = false;
     121                                        for ( const ast::TypeDecl * decl : type->forall ) {
     122                                                closed[ decl->name ] = ast::TypeDecl::Data{ decl };
     123                                                for ( const ast::DeclWithType * assert : decl->assertions ) {
     124                                                        have[ assert ].isUsed = false;
     125                                                }
    126126                                        }
    127127                                }
  • src/ResolvExpr/PolyCost.cc

    r41cde266 rc5a98f3  
    6868
    6969        void previsit( const ast::TypeInstType * type ) {
    70                 if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
     70                if ( const ast::EqvClass * eqv = env_.lookup( type->name ) ) /* && */ if ( eqv->bound ) {
    7171                        if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
    7272                                if ( symtab.lookupType( otherType->name ) ) {
  • src/ResolvExpr/PtrsAssignable.cc

    r41cde266 rc5a98f3  
    134134        }
    135135        void postvisit( const ast::TypeInstType * inst ) {
    136                 if ( const ast::EqvClass * eqv = typeEnv.lookup( *inst ) ) {
     136                if ( const ast::EqvClass * eqv = typeEnv.lookup( inst->name ) ) {
    137137                        if ( eqv->bound ) {
    138138                                // T * = S * for any S depends on the type bound to T
     
    146146                const ast::TypeEnvironment & env ) {
    147147        if ( const ast::TypeInstType * dstAsInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    148                 if ( const ast::EqvClass * eqv = env.lookup( *dstAsInst ) ) {
     148                if ( const ast::EqvClass * eqv = env.lookup( dstAsInst->name ) ) {
    149149                        return ptrsAssignable( src, eqv->bound, env );
    150150                }
  • src/ResolvExpr/PtrsCastable.cc

    r41cde266 rc5a98f3  
    180180                                        }
    181181                                }
    182                         } else if ( const ast::EqvClass * eqvClass = env.lookup( *inst ) ) {
     182                        } else if ( const ast::EqvClass * eqvClass = env.lookup( inst->name ) ) {
    183183                                if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
    184184                                        return -1;
     
    283283) {
    284284        if ( auto inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    285                 if ( const ast::EqvClass * eqvClass = env.lookup( *inst ) ) {
     285                if ( const ast::EqvClass * eqvClass = env.lookup( inst->name ) ) {
    286286                        return ptrsAssignable( src, eqvClass->bound, env );
    287287                }
  • src/ResolvExpr/RenameVars.cc

    r41cde266 rc5a98f3  
    1919#include <utility>                 // for pair
    2020
     21#include "AST/ForallSubstitutionTable.hpp"
    2122#include "AST/Pass.hpp"
    2223#include "AST/Type.hpp"
     
    3839                int level = 0;
    3940                int resetCount = 0;
     41                ScopedMap< std::string, std::string > nameMap;
     42        public:
     43                ast::ForallSubstitutionTable subs;
    4044
    41                 int next_expr_id = 1;
    42                 int next_usage_id = 1;
    43                 ScopedMap< std::string, std::string > nameMap;
    44                 ScopedMap< std::string, ast::TypeInstType::TypeEnvKey > idMap;
    45         public:
    4645                void reset() {
    4746                        level = 0;
     
    5453                                type->name = it->second;
    5554                        }
    56                 }
    57 
    58                 void nextUsage() {
    59                         ++next_usage_id;
    6055                }
    6156
     
    8378
    8479                const ast::TypeInstType * rename( const ast::TypeInstType * type ) {
     80                        // re-linking of base type handled by WithForallSubstitutor
     81
    8582                        // rename
    86                         auto it = idMap.find( type->name );
    87                         if ( it != idMap.end() ) {
    88                                 // unconditionally mutate because map will *always* have different name
    89                                 ast::TypeInstType * mut = ast::shallowCopy( type );
    90                                 // reconcile base node since some copies might have been made
    91                                 mut->base = it->second.base;
    92                                 mut->formal_usage = it->second.formal_usage;
    93                                 mut->expr_id = it->second.expr_id;
     83                        auto it = nameMap.find( type->name );
     84                        if ( it != nameMap.end() ) {
     85                                // unconditionally mutate because map will *always* have different name,
     86                                // if this mutates, will *always* have been mutated by ForallSubstitutor above
     87                                ast::TypeInstType * mut = ast::mutate( type );
     88                                mut->name = it->second;
    9489                    type = mut;
    9590                        }
     
    9893                }
    9994
    100                 const ast::FunctionType * openLevel( const ast::FunctionType * type, RenameMode mode ) {
     95                const ast::FunctionType * openLevel( const ast::FunctionType * type ) {
    10196                        if ( type->forall.empty() ) return type;
    102                         idMap.beginScope();
     97
     98                        nameMap.beginScope();
    10399
    104100                        // Load new names from this forall clause and perform renaming.
    105                         auto mutType = ast::shallowCopy( type );
    106                         // assert( type == mutType && "mutated type must be unique from ForallSubstitutor" );
    107                         for ( auto & td : mutType->forall ) {
    108                                 auto mut = ast::shallowCopy( td.get() );
    109                                 // assert( td == mutDecl && "mutated decl must be unique from ForallSubstitutor" );
     101                        auto mutType = ast::mutate( type );
     102                        assert( type == mutType && "mutated type must be unique from ForallSubstitutor" );
     103                        for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) {
     104                                assertf(dynamic_cast<ast::FunctionType *>(mutType), "renaming vars in non-function type");
     105                                std::ostringstream output;
     106                                output << "_" << resetCount << "_" << level << "_" << td->name;
     107                                std::string newname =  output.str();
     108                                nameMap[ td->name ] = newname;
     109                                ++level;
    110110
    111                                 if (mode == GEN_EXPR_ID) {
    112                                         mut->expr_id = next_expr_id;
    113                                         mut->formal_usage = -1;
    114                                         ++next_expr_id;
    115                                 }
    116                                 else if (mode == GEN_USAGE) {
    117                                         assertf(mut->expr_id, "unfilled expression id in generating candidate type");
    118                                         mut->formal_usage = next_usage_id;
    119                                 }
    120                                 else {
    121                                         assert(false);
    122                                 }
    123                                 idMap[ td->name ] = ast::TypeInstType::TypeEnvKey(*mut);
    124                                
    125                                 td = mut;
     111                                ast::TypeDecl * mutDecl = ast::mutate( td.get() );
     112                                assert( td == mutDecl && "mutated decl must be unique from ForallSubstitutor" );
     113                                mutDecl->name = newname;
     114                                // assertion above means `td = mutDecl;` is unnecessary
    126115                        }
     116                        // assertion above means `type = mutType;` is unnecessary
    127117
    128                         return mutType;
     118                        return type;
    129119                }
    130120
    131121                void closeLevel( const ast::FunctionType * type ) {
    132122                        if ( type->forall.empty() ) return;
    133                         idMap.endScope();
     123
     124                        nameMap.endScope();
    134125                }
    135126        };
     
    151142        };
    152143
    153         struct RenameVars_new : public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ {
    154                 RenameMode mode;
     144        struct RenameVars_new /*: public ast::WithForallSubstitutor*/ {
     145                #warning when old RenameVars goes away, replace hack below with global pass inheriting from WithForallSubstitutor
     146                ast::ForallSubstitutionTable & subs = renaming.subs;
    155147
    156148                const ast::FunctionType * previsit( const ast::FunctionType * type ) {
    157                         return renaming.openLevel( type, mode );
     149                        return renaming.openLevel( type );
    158150                }
    159151
     
    171163
    172164                const ast::TypeInstType * previsit( const ast::TypeInstType * type ) {
    173                         if (mode == GEN_USAGE && !type->formal_usage) return type; // do not rename an actual type
    174165                        return renaming.rename( type );
    175166                }
     
    186177}
    187178
    188 const ast::Type * renameTyVars( const ast::Type * t, RenameMode mode ) {
    189         // ast::Type *tc = ast::deepCopy(t);
     179const ast::Type * renameTyVars( const ast::Type * t ) {
     180        ast::Type *tc = ast::deepCopy(t);
    190181        ast::Pass<RenameVars_new> renamer;
    191         renamer.core.mode = mode;
    192         if (mode == GEN_USAGE) {
    193                 renaming.nextUsage();
    194         }
    195         return t->accept( renamer );
     182//      return t->accept( renamer );
     183        return tc->accept( renamer );
    196184}
    197185
  • src/ResolvExpr/RenameVars.h

    r41cde266 rc5a98f3  
    3030        /// Provides a consistent renaming of forall type names in a hierarchy by prefixing them with a unique "level" ID
    3131        void renameTyVars( Type * );
    32 
    33         enum RenameMode {
    34                 GEN_USAGE, // for type in VariableExpr
    35                 GEN_EXPR_ID // for type in decl
    36         };
    37         const ast::Type * renameTyVars( const ast::Type *, RenameMode mode = GEN_USAGE );
     32        const ast::Type * renameTyVars( const ast::Type * );
    3833
    3934        /// resets internal state of renamer to avoid overflow
    4035        void resetTyVarRenaming();
    41 
    42        
    4336} // namespace ResolvExpr
    4437
  • src/ResolvExpr/ResolveTypeof.cc

    r41cde266 rc5a98f3  
    1515
    1616#include "ResolveTypeof.h"
    17 #include "RenameVars.h"
    1817
    1918#include <cassert>               // for assert
     
    219218                        mutDecl->mangleName = Mangle::mangle(mutDecl); // do not mangle unnamed variables
    220219               
    221                 mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
    222220                mutDecl->isTypeFixed = true;
    223221                return mutDecl;
  • src/ResolvExpr/Resolver.cc

    r41cde266 rc5a98f3  
    986986                };
    987987        } // anonymous namespace
     988
    988989        /// Check if this expression is or includes a deleted expression
    989990        const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) {
     
    13741375                        }
    13751376
    1376                         // handle assertions
     1377                        // handle assertions. (seems deep)
    13771378
    13781379                        symtab.enterScope();
    1379                         mutType->forall.clear();
    1380                         mutType->assertions.clear();
    1381                         for (auto & typeParam : mutDecl->type_params) {
    1382                                 symtab.addType(typeParam);
    1383                                 mutType->forall.emplace_back(new ast::TypeInstType(typeParam->name, typeParam));
    1384                         }
    1385                         for (auto & asst : mutDecl->assertions) {
    1386                                 asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), symtab);
    1387                                 symtab.addId(asst);
    1388                                 mutType->assertions.emplace_back(new ast::VariableExpr(functionDecl->location, asst));
     1380                        for (auto & typeParam : mutType->forall) {
     1381                                auto mutParam = typeParam.get_and_mutate();
     1382                                symtab.addType(mutParam);
     1383                                for (auto & asst : mutParam->assertions) {
     1384                                        asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), symtab);
     1385                                        symtab.addId(asst);
     1386                                }
     1387                                typeParam = mutParam;
    13891388                        }
    13901389
     
    14081407                        mutType->returns = std::move(returnTypes);
    14091408
    1410                         auto renamedType = strict_dynamic_cast<const ast::FunctionType *>(renameTyVars(mutType, RenameMode::GEN_EXPR_ID));
    1411 
    14121409                        std::list<ast::ptr<ast::Stmt>> newStmts;
    14131410                        resolveWithExprs (mutDecl->withExprs, newStmts);
     
    14211418                        symtab.leaveScope();
    14221419
    1423                         mutDecl->type = renamedType;
    14241420                        mutDecl->mangleName = Mangle::mangle(mutDecl);
    14251421                        mutDecl->isTypeFixed = true;
     
    15381534        const PtrType * handlePtrType( const PtrType * type, const ast::SymbolTable & symtab ) {
    15391535                if ( type->dimension ) {
    1540                         ast::ptr< ast::Type > sizeType = ast::sizeType;
     1536                        #warning should use new equivalent to Validate::SizeType rather than sizeType here
     1537                        ast::ptr< ast::Type > sizeType = new ast::BasicType{ ast::BasicType::LongUnsignedInt };
    15411538                        ast::mutate_field(
    15421539                                type, &PtrType::dimension,
  • src/ResolvExpr/SatisfyAssertions.cpp

    r41cde266 rc5a98f3  
    6969        /// Reference to a single deferred item
    7070        struct DeferRef {
    71                 const ast::VariableExpr * expr;
     71                const ast::DeclWithType * decl;
    7272                const ast::AssertionSetValue & info;
    7373                const AssnCandidate & match;
     
    7777        /// Acts like an indexed list of DeferRef
    7878        struct DeferItem {
    79                 const ast::VariableExpr * expr;
     79                const ast::DeclWithType * decl;
    8080                const ast::AssertionSetValue & info;
    8181                AssnCandidateList matches;
    8282
    8383                DeferItem(
    84                         const ast::VariableExpr * d, const ast::AssertionSetValue & i, AssnCandidateList && ms )
    85                 : expr( d ), info( i ), matches( std::move( ms ) ) {}
     84                        const ast::DeclWithType * d, const ast::AssertionSetValue & i, AssnCandidateList && ms )
     85                : decl( d ), info( i ), matches( std::move( ms ) ) {}
    8686
    8787                bool empty() const { return matches.empty(); }
     
    8989                AssnCandidateList::size_type size() const { return matches.size(); }
    9090
    91                 DeferRef operator[] ( unsigned i ) const { return { expr, info, matches[i] }; }
     91                DeferRef operator[] ( unsigned i ) const { return { decl, info, matches[i] }; }
    9292        };
    9393
     
    138138        void addToSymbolTable( const ast::AssertionSet & have, ast::SymbolTable & symtab ) {
    139139                for ( auto & i : have ) {
    140                         if ( i.second.isUsed ) { symtab.addId( i.first->var ); }
     140                        if ( i.second.isUsed ) { symtab.addId( i.first ); }
    141141                }
    142142        }
     
    144144        /// Binds a single assertion, updating satisfaction state
    145145        void bindAssertion(
    146                 const ast::VariableExpr * expr, const ast::AssertionSetValue & info, CandidateRef & cand,
     146                const ast::DeclWithType * decl, const ast::AssertionSetValue & info, CandidateRef & cand,
    147147                AssnCandidate & match, InferCache & inferred
    148148        ) {
     
    156156
    157157                // place newly-inferred assertion in proper location in cache
    158                 inferred[ info.resnSlot ][ expr->var->uniqueId ] = ast::ParamEntry{
    159                         candidate->uniqueId, candidate, match.adjType, expr->result, varExpr };
     158                inferred[ info.resnSlot ][ decl->uniqueId ] = ast::ParamEntry{
     159                        candidate->uniqueId, candidate, match.adjType, decl->get_type(), varExpr };
    160160        }
    161161
     
    169169
    170170                std::vector<ast::SymbolTable::IdData> candidates;
    171                 auto kind = ast::SymbolTable::getSpecialFunctionKind(assn.first->var->name);
     171                auto kind = ast::SymbolTable::getSpecialFunctionKind(assn.first->name);
    172172                if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) {
    173173                        // prefilter special decls by argument type, if already known
    174                         ast::ptr<ast::Type> thisArgType = assn.first->result.strict_as<ast::PointerType>()->base
     174                        ast::ptr<ast::Type> thisArgType = strict_dynamic_cast<const ast::PointerType *>(assn.first->get_type())->base
    175175                                .strict_as<ast::FunctionType>()->params[0]
    176176                                .strict_as<ast::ReferenceType>()->base;
     
    184184                }
    185185                else {
    186                         candidates = sat.symtab.lookupId(assn.first->var->name);
     186                        candidates = sat.symtab.lookupId(assn.first->name);
    187187                }
    188188                for ( const ast::SymbolTable::IdData & cdata : candidates ) {
     
    200200                        ast::TypeEnvironment newEnv{ sat.cand->env };
    201201                        ast::OpenVarSet newOpen{ sat.cand->open };
    202                         ast::ptr< ast::Type > toType = assn.first->result;
     202                        ast::ptr< ast::Type > toType = assn.first->get_type();
    203203                        ast::ptr< ast::Type > adjType =
    204204                                renameTyVars( adjustExprType( candidate->get_type(), newEnv, sat.symtab ) );
     
    337337                                        // compute conversion cost from satisfying decl to assertion
    338338                                        cost += computeConversionCost(
    339                                                 assn.match.adjType, assn.expr->result, false, symtab, env );
     339                                                assn.match.adjType, assn.decl->get_type(), false, symtab, env );
    340340
    341341                                        // mark vars+specialization on function-type assertions
     
    350350                                        cost.incVar( func->forall.size() );
    351351
    352                                         cost.decSpec( func->assertions.size() );
     352                                        for ( const ast::TypeDecl * td : func->forall ) {
     353                                                cost.decSpec( td->assertions.size() );
     354                                        }
    353355                                }
    354356                        }
     
    449451                                ss << (tabs-1) << "Too many non-unique satisfying assignments for assertions:\n";
    450452                                for ( const auto & d : sat.deferred ) {
    451                                         ast::print( ss, d.expr, tabs );
     453                                        ast::print( ss, d.decl, tabs );
    452454                                }
    453455
     
    467469                                        ss << (tabs-1) << "No mutually-compatible satisfaction for assertions:\n";
    468470                                        for ( const auto& d : sat.deferred ) {
    469                                                 ast::print( ss, d.expr, tabs );
     471                                                ast::print( ss, d.decl, tabs );
    470472                                        }
    471473
     
    499501                                                nextNewNeed.insert( match.need.begin(), match.need.end() );
    500502
    501                                                 bindAssertion( r.expr, r.info, nextCand, match, nextInferred );
     503                                                bindAssertion( r.decl, r.info, nextCand, match, nextInferred );
    502504                                        }
    503505
  • src/ResolvExpr/Unify.cc

    r41cde266 rc5a98f3  
    773773
    774774                        const ast::Type * postvisit( const ast::TypeInstType * typeInst ) {
    775                                 if ( const ast::EqvClass * clz = tenv.lookup( *typeInst ) ) {
     775                                if ( const ast::EqvClass * clz = tenv.lookup( typeInst->name ) ) {
    776776                                        // expand ttype parameter into its actual type
    777777                                        if ( clz->data.kind == ast::TypeDecl::Ttype && clz->bound ) {
     
    888888                }
    889889
    890                 static void markAssertionSet( ast::AssertionSet & assns, const ast::VariableExpr * assn ) {
     890                static void markAssertionSet( ast::AssertionSet & assns, const ast::DeclWithType * assn ) {
    891891                        auto i = assns.find( assn );
    892892                        if ( i != assns.end() ) {
     
    900900                        const ast::FunctionType * type
    901901                ) {
    902                         for ( auto & assert : type->assertions ) {
    903                                 markAssertionSet( assn1, assert );
    904                                 markAssertionSet( assn2, assert );
     902                        for ( const auto & tyvar : type->forall ) {
     903                                for ( const ast::DeclWithType * assert : tyvar->assertions ) {
     904                                        markAssertionSet( assn1, assert );
     905                                        markAssertionSet( assn2, assert );
     906                                }
    905907                        }
    906908                }
     
    10281030
    10291031                void postvisit( const ast::TypeInstType * typeInst ) {
    1030                         assert( open.find( *typeInst ) == open.end() );
     1032                        assert( open.find( typeInst->name ) == open.end() );
    10311033                        handleRefType( typeInst, type2 );
    10321034                }
     
    11691171                auto var2 = dynamic_cast< const ast::TypeInstType * >( type2 );
    11701172                ast::OpenVarSet::const_iterator
    1171                         entry1 = var1 ? open.find( *var1 ) : open.end(),
    1172                         entry2 = var2 ? open.find( *var2 ) : open.end();
     1173                        entry1 = var1 ? open.find( var1->name ) : open.end(),
     1174                        entry2 = var2 ? open.find( var2->name ) : open.end();
    11731175                bool isopen1 = entry1 != open.end();
    11741176                bool isopen2 = entry2 != open.end();
  • src/SymTab/Mangler.cc

    r41cde266 rc5a98f3  
    671671                                        int dcount = 0, fcount = 0, vcount = 0, acount = 0;
    672672                                        mangleName += Encoding::forall;
    673                                         for ( auto & decl : ptype->forall ) {
     673                                        for ( const ast::TypeDecl * decl : ptype->forall ) {
    674674                                                switch ( decl->kind ) {
    675675                                                case ast::TypeDecl::Kind::Dtype:
     
    686686                                                } // switch
    687687                                                varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind );
    688                                         } // for
    689                                         for ( auto & assert : ptype->assertions ) {
    690                                                 ast::Pass<Mangler_new> sub_mangler(
    691                                                         mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
    692                                                 assert->var->accept( sub_mangler );
    693                                                 assertionNames.push_back( sub_mangler.core.get_mangleName() );
    694                                                 acount++;
     688                                                for ( const ast::DeclWithType * assert : decl->assertions ) {
     689                                                        ast::Pass<Mangler_new> sub_mangler(
     690                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
     691                                                        assert->accept( sub_mangler );
     692                                                        assertionNames.push_back( sub_mangler.core.get_mangleName() );
     693                                                        acount++;
     694                                                } // for
    695695                                        } // for
    696696                                        mangleName += std::to_string( dcount ) + "_" + std::to_string( fcount ) + "_" + std::to_string( vcount ) + "_" + std::to_string( acount ) + "_";
  • src/SymTab/Validate.cc

    r41cde266 rc5a98f3  
    14631463        }
    14641464
    1465         /*
    1466 
    14671465        /// Associates forward declarations of aggregates with their definitions
    14681466        class LinkReferenceToTypes_new final
     
    18461844                }
    18471845        };
    1848         */
    18491846} // anonymous namespace
    18501847
    1851 /*
    18521848const ast::Type * validateType(
    18531849                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) {
     
    18581854        return type->accept( lrt )->accept( fpd );
    18591855}
    1860 */
    18611856
    18621857} // namespace SymTab
  • src/Tuples/TupleAssignment.cc

    r41cde266 rc5a98f3  
    504504
    505505                        std::vector< ast::ptr< ast::Expr > > match() override {
    506                                 static UniqueName lhsNamer( "__massassign_L" );
    507                                 static UniqueName rhsNamer( "__massassign_R" );
     506                                // temporary workaround for new and old ast to coexist and avoid name collision
     507                                static UniqueName lhsNamer( "__massassign_Ln" );
     508                                static UniqueName rhsNamer( "__massassign_Rn" );
    508509                                // empty tuple case falls into this matcher
    509510                                assert( lhs.empty() ? rhs.empty() : rhs.size() <= 1 );
     
    534535
    535536                        std::vector< ast::ptr< ast::Expr > > match() override {
    536                                 static UniqueName lhsNamer( "__multassign_L" );
    537                                 static UniqueName rhsNamer( "__multassign_R" );
     537                                // temporary workaround for new and old ast to coexist and avoid name collision
     538                                static UniqueName lhsNamer( "__multassign_Ln" );
     539                                static UniqueName rhsNamer( "__multassign_Rn" );
    538540
    539541                                if ( lhs.size() != rhs.size() ) return {};
  • tests/.expect/KRfunctions.nast.x86.txt

    r41cde266 rc5a98f3  
    8686    __attribute__ ((unused)) signed int (*_X11_retval_f11PA0i_1)[];
    8787}
    88 signed int (*_X3f12FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned int )10)]{
    89     __attribute__ ((unused)) signed int (*_X11_retval_f12PA0A0i_1)[][((unsigned int )10)];
     88signed int (*_X3f12FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned long int )10)]{
     89    __attribute__ ((unused)) signed int (*_X11_retval_f12PA0A0i_1)[][((unsigned long int )10)];
    9090}
    91 signed int (*_X3f13FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned int )10)]{
    92     __attribute__ ((unused)) signed int (*_X11_retval_f13PA0A0i_1)[][((unsigned int )10)];
     91signed int (*_X3f13FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned long int )10)]{
     92    __attribute__ ((unused)) signed int (*_X11_retval_f13PA0A0i_1)[][((unsigned long int )10)];
    9393}
    94 signed int (*_X3f14FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned int )10)]{
    95     __attribute__ ((unused)) signed int (*_X11_retval_f14PA0A0i_1)[][((unsigned int )10)];
     94signed int (*_X3f14FPA0A0i_iPiPi__1(signed int _X1ai_1, signed int *_X1bPi_1, signed int *_X1cPi_1))[][((unsigned long int )10)]{
     95    __attribute__ ((unused)) signed int (*_X11_retval_f14PA0A0i_1)[][((unsigned long int )10)];
    9696}
    9797signed int _X3f15Fi_iii__1(signed int _X1ai_1, signed int _X1bi_1, signed int _X1ci_1){
  • tests/.expect/attributes.nast.x86.txt

    r41cde266 rc5a98f3  
    623623__attribute__ ((used,used,used,used)) const signed int *_X3vd3PKi_1;
    624624__attribute__ ((used,used,unused,used,unused)) const signed int *_X3vd4PKi_1;
    625 __attribute__ ((used,used,used)) const signed int _X3vd5A0Ki_1[((unsigned int )5)];
    626 __attribute__ ((used,used,unused,used)) const signed int _X3vd6A0Ki_1[((unsigned int )5)];
     625__attribute__ ((used,used,used)) const signed int _X3vd5A0Ki_1[((unsigned long int )5)];
     626__attribute__ ((used,used,unused,used)) const signed int _X3vd6A0Ki_1[((unsigned long int )5)];
    627627__attribute__ ((used,used,used,used)) const signed int (*_X3vd7Fi___1)();
    628628__attribute__ ((used,used,unused,used,used)) const signed int (*_X3vd8Fi___1)();
     
    647647    __attribute__ ((unused,unused,used)) signed int _X2t1i_2;
    648648    __attribute__ ((unused,unused,unused,unused,unused)) signed int **_X2t2PPi_2;
    649     __attribute__ ((unused,unused,unused)) signed int _X2t3A0i_2[((unsigned int )5)];
    650     __attribute__ ((unused,unused,unused,unused,unused)) signed int **_X2t4A0PPi_2[((unsigned int )5)];
     649    __attribute__ ((unused,unused,unused)) signed int _X2t3A0i_2[((unsigned long int )5)];
     650    __attribute__ ((unused,unused,unused,unused,unused)) signed int **_X2t4A0PPi_2[((unsigned long int )5)];
    651651    __attribute__ ((unused,unused,unused)) signed int _X2t5Fi___2();
    652652    __attribute__ ((unused,unused,unused,unused)) signed int *_X2t6FPi___2();
     
    671671signed int _X4tpr2Fi_PPi__1(__attribute__ ((unused,unused,unused,unused,unused,unused)) signed int **_X3FooPPi_1);
    672672signed int _X4tpr3Fi_Pi__1(__attribute__ ((unused,unused,unused)) signed int *_X3FooPi_1);
    673 signed int _X4tpr4Fi_Fi_Pi___1(__attribute__ ((unused,unused)) signed int (*__anonymous_object1)(signed int __param_0[((unsigned int )5)]));
     673signed int _X4tpr4Fi_Fi_Pi___1(__attribute__ ((unused,unused)) signed int (*__anonymous_object1)(signed int __param_0[((unsigned long int )5)]));
    674674signed int _X4tpr5Fi_Fi____1(__attribute__ ((unused,unused,unused)) signed int (*_X3FooFi___1)());
    675675signed int _X4tpr6Fi_Fi____1(__attribute__ ((unused,unused,unused)) signed int (*_X3FooFi___1)());
     
    679679    __attribute__ ((used,unused)) signed int _X3ad1i_2;
    680680    __attribute__ ((unused,unused,unused)) signed int *_X3ad2Pi_2;
    681     __attribute__ ((unused,unused,unused)) signed int _X3ad3A0i_2[((unsigned int )5)];
    682     __attribute__ ((unused,unused,unused,unused,unused)) signed int (*_X3ad4PA0i_2)[((unsigned int )10)];
     681    __attribute__ ((unused,unused,unused)) signed int _X3ad3A0i_2[((unsigned long int )5)];
     682    __attribute__ ((unused,unused,unused,unused,unused)) signed int (*_X3ad4PA0i_2)[((unsigned long int )10)];
    683683    __attribute__ ((unused,unused,unused,unused,used)) signed int _X3ad5i_2;
    684684    __attribute__ ((unused,unused,unused,unused,unused)) signed int _X3ad6Fi___2();
  • tests/.expect/functions.nast.x86.txt

    r41cde266 rc5a98f3  
    4646    __attribute__ ((unused)) signed int (*_X11_retval_f10PA0i_1)[];
    4747}
    48 signed int (*_X3f11FPA0A0i___1())[][((unsigned int )3)]{
    49     __attribute__ ((unused)) signed int (*_X11_retval_f11PA0A0i_1)[][((unsigned int )3)];
    50 }
    51 signed int (*_X3f12FPA0A0i___1())[][((unsigned int )3)]{
    52     __attribute__ ((unused)) signed int (*_X11_retval_f12PA0A0i_1)[][((unsigned int )3)];
     48signed int (*_X3f11FPA0A0i___1())[][((unsigned long int )3)]{
     49    __attribute__ ((unused)) signed int (*_X11_retval_f11PA0A0i_1)[][((unsigned long int )3)];
     50}
     51signed int (*_X3f12FPA0A0i___1())[][((unsigned long int )3)]{
     52    __attribute__ ((unused)) signed int (*_X11_retval_f12PA0A0i_1)[][((unsigned long int )3)];
    5353}
    5454signed int _X4fII1Fi_i__1(signed int _X1ii_1){
     
    250250signed int _X1fFi_Fi_ii_Fi_i___1(__attribute__ ((unused)) signed int (*__anonymous_object20)(signed int __param_0, signed int __param_1), __attribute__ ((unused)) signed int (*__anonymous_object21)(signed int __param_0)){
    251251    __attribute__ ((unused)) signed int _X9_retval_fi_1;
    252     signed int (*(*_X2pcPA0A0PA0A0i_2)[][((unsigned int )10)])[][((unsigned int )3)];
    253     signed int (*(*_X1pPA0A0PA0A0i_2)[][((unsigned int )10)])[][((unsigned int )3)];
     252    signed int (*(*_X2pcPA0A0PA0A0i_2)[][((unsigned long int )10)])[][((unsigned long int )3)];
     253    signed int (*(*_X1pPA0A0PA0A0i_2)[][((unsigned long int )10)])[][((unsigned long int )3)];
    254254    signed int (*(*_X1pPA0Fi_i__2)[])(signed int __param_0);
    255255}
  • tests/errors/.expect/completeType.nast.x64.txt

    r41cde266 rc5a98f3  
    1212      Application of
    1313        Variable Expression: *?: forall
    14           instance of type DT (not function type)
     14          DT: data type
    1515          function
    1616        ... with parameters
     
    2121        ... with resolved type:
    2222          pointer to forall
    23             instance of type [unbound] (not function type)
     23            [unbound]:data type
    2424            function
    2525          ... with parameters
     
    4141    void
    4242  )
    43   Environment:([unbound]DT) -> instance of struct A without body (no widening)
     43  Environment:([unbound]) -> instance of struct A without body (no widening)
    4444
    4545
     
    4747      Application of
    4848        Variable Expression: *?: forall
    49           instance of type DT (not function type)
     49          DT: data type
    5050          function
    5151        ... with parameters
     
    5656        ... with resolved type:
    5757          pointer to forall
    58             instance of type [unbound] (not function type)
     58            [unbound]:data type
    5959            function
    6060          ... with parameters
     
    7676    void
    7777  )
    78   Environment:([unbound]DT) -> instance of struct B with body (no widening)
     78  Environment:([unbound]) -> instance of struct B with body (no widening)
    7979
    8080
     
    113113Cost ( 0, 1, 0, 0, 1, -5, 0 ): Application of
    114114            Variable Expression: baz: forall
    115               instance of type T (not function type)
    116               with assertions
    117               Variable Expression: ?=?: pointer to function
    118               ... with parameters
    119                 reference to instance of type T (not function type)
    120                 instance of type T (not function type)
    121               ... returning
    122                 instance of type T (not function type)
    123 
    124               ... with resolved type:
    125                 pointer to function
     115              T: sized data type
     116              ... with assertions
     117                ?=?: pointer to function
    126118                ... with parameters
    127119                  reference to instance of type T (not function type)
     
    130122                  instance of type T (not function type)
    131123
    132               Variable Expression: ?{}: pointer to function
    133               ... with parameters
    134                 reference to instance of type T (not function type)
    135               ... returning nothing
    136 
    137               ... with resolved type:
    138                 pointer to function
     124                ?{}: pointer to function
    139125                ... with parameters
    140126                  reference to instance of type T (not function type)
    141127                ... returning nothing
    142128
    143               Variable Expression: ?{}: pointer to function
    144               ... with parameters
    145                 reference to instance of type T (not function type)
    146                 instance of type T (not function type)
    147               ... returning nothing
    148 
    149               ... with resolved type:
    150                 pointer to function
     129                ?{}: pointer to function
    151130                ... with parameters
    152131                  reference to instance of type T (not function type)
     
    154133                ... returning nothing
    155134
    156               Variable Expression: ^?{}: pointer to function
    157               ... with parameters
    158                 reference to instance of type T (not function type)
    159               ... returning nothing
    160 
    161               ... with resolved type:
    162                 pointer to function
     135                ^?{}: pointer to function
    163136                ... with parameters
    164137                  reference to instance of type T (not function type)
    165138                ... returning nothing
     139
    166140
    167141              function
     
    172146            ... with resolved type:
    173147              pointer to forall
    174                 instance of type [unbound] (not function type)
    175                 with assertions
    176                 Variable Expression: ?=?: pointer to function
    177                 ... with parameters
    178                   reference to instance of type T (not function type)
    179                   instance of type T (not function type)
    180                 ... returning
    181                   instance of type T (not function type)
    182 
    183                 ... with resolved type:
    184                   pointer to function
     148                [unbound]:sized data type
     149                ... with assertions
     150                  ?=?: pointer to function
    185151                  ... with parameters
    186152                    reference to instance of type [unbound] (not function type)
     
    189155                    instance of type [unbound] (not function type)
    190156
    191                 Variable Expression: ?{}: pointer to function
    192                 ... with parameters
    193                   reference to instance of type T (not function type)
    194                 ... returning nothing
    195 
    196                 ... with resolved type:
    197                   pointer to function
     157                  ?{}: pointer to function
    198158                  ... with parameters
    199159                    reference to instance of type [unbound] (not function type)
    200160                  ... returning nothing
    201161
    202                 Variable Expression: ?{}: pointer to function
    203                 ... with parameters
    204                   reference to instance of type T (not function type)
    205                   instance of type T (not function type)
    206                 ... returning nothing
    207 
    208                 ... with resolved type:
    209                   pointer to function
     162                  ?{}: pointer to function
    210163                  ... with parameters
    211164                    reference to instance of type [unbound] (not function type)
     
    213166                  ... returning nothing
    214167
    215                 Variable Expression: ^?{}: pointer to function
    216                 ... with parameters
    217                   reference to instance of type T (not function type)
    218                 ... returning nothing
    219 
    220                 ... with resolved type:
    221                   pointer to function
     168                  ^?{}: pointer to function
    222169                  ... with parameters
    223170                    reference to instance of type [unbound] (not function type)
    224171                  ... returning nothing
     172
    225173
    226174                function
     
    240188          void
    241189        )
    242         Environment:([unbound]T) -> instance of type T (not function type) (no widening)
     190        Environment:([unbound]) -> instance of type T (not function type) (no widening)
    243191
    244192      Could not satisfy assertion:
    245 Variable Expression: ?=?: pointer to function
     193?=?: pointer to function
    246194        ... with parameters
    247           reference to instance of type T (not function type)
    248           instance of type T (not function type)
     195          reference to instance of type [unbound] (not function type)
     196          instance of type [unbound] (not function type)
    249197        ... returning
    250           instance of type T (not function type)
     198          instance of type [unbound] (not function type)
    251199
    252         ... with resolved type:
    253           pointer to function
    254           ... with parameters
    255             reference to instance of type [unbound] (not function type)
    256             instance of type [unbound] (not function type)
    257           ... returning
    258             instance of type [unbound] (not function type)
    259 
  • tests/errors/.expect/completeType.nast.x86.txt

    r41cde266 rc5a98f3  
    1212      Application of
    1313        Variable Expression: *?: forall
    14           instance of type DT (not function type)
     14          DT: data type
    1515          function
    1616        ... with parameters
     
    2121        ... with resolved type:
    2222          pointer to forall
    23             instance of type [unbound] (not function type)
     23            [unbound]:data type
    2424            function
    2525          ... with parameters
     
    4141    void
    4242  )
    43   Environment:([unbound]DT) -> instance of struct A without body (no widening)
     43  Environment:([unbound]) -> instance of struct A without body (no widening)
    4444
    4545
     
    4747      Application of
    4848        Variable Expression: *?: forall
    49           instance of type DT (not function type)
     49          DT: data type
    5050          function
    5151        ... with parameters
     
    5656        ... with resolved type:
    5757          pointer to forall
    58             instance of type [unbound] (not function type)
     58            [unbound]:data type
    5959            function
    6060          ... with parameters
     
    7676    void
    7777  )
    78   Environment:([unbound]DT) -> instance of struct B with body (no widening)
     78  Environment:([unbound]) -> instance of struct B with body (no widening)
    7979
    8080
     
    113113Cost ( 0, 1, 0, 0, 1, -5, 0 ): Application of
    114114            Variable Expression: baz: forall
    115               instance of type T (not function type)
    116               with assertions
    117               Variable Expression: ?=?: pointer to function
    118               ... with parameters
    119                 reference to instance of type T (not function type)
    120                 instance of type T (not function type)
    121               ... returning
    122                 instance of type T (not function type)
    123 
    124               ... with resolved type:
    125                 pointer to function
     115              T: sized data type
     116              ... with assertions
     117                ?=?: pointer to function
    126118                ... with parameters
    127119                  reference to instance of type T (not function type)
     
    130122                  instance of type T (not function type)
    131123
    132               Variable Expression: ?{}: pointer to function
    133               ... with parameters
    134                 reference to instance of type T (not function type)
    135               ... returning nothing
    136 
    137               ... with resolved type:
    138                 pointer to function
     124                ?{}: pointer to function
    139125                ... with parameters
    140126                  reference to instance of type T (not function type)
    141127                ... returning nothing
    142128
    143               Variable Expression: ?{}: pointer to function
    144               ... with parameters
    145                 reference to instance of type T (not function type)
    146                 instance of type T (not function type)
    147               ... returning nothing
    148 
    149               ... with resolved type:
    150                 pointer to function
     129                ?{}: pointer to function
    151130                ... with parameters
    152131                  reference to instance of type T (not function type)
     
    154133                ... returning nothing
    155134
    156               Variable Expression: ^?{}: pointer to function
    157               ... with parameters
    158                 reference to instance of type T (not function type)
    159               ... returning nothing
    160 
    161               ... with resolved type:
    162                 pointer to function
     135                ^?{}: pointer to function
    163136                ... with parameters
    164137                  reference to instance of type T (not function type)
    165138                ... returning nothing
     139
    166140
    167141              function
     
    172146            ... with resolved type:
    173147              pointer to forall
    174                 instance of type [unbound] (not function type)
    175                 with assertions
    176                 Variable Expression: ?=?: pointer to function
    177                 ... with parameters
    178                   reference to instance of type T (not function type)
    179                   instance of type T (not function type)
    180                 ... returning
    181                   instance of type T (not function type)
    182 
    183                 ... with resolved type:
    184                   pointer to function
     148                [unbound]:sized data type
     149                ... with assertions
     150                  ?=?: pointer to function
    185151                  ... with parameters
    186152                    reference to instance of type [unbound] (not function type)
     
    189155                    instance of type [unbound] (not function type)
    190156
    191                 Variable Expression: ?{}: pointer to function
    192                 ... with parameters
    193                   reference to instance of type T (not function type)
    194                 ... returning nothing
    195 
    196                 ... with resolved type:
    197                   pointer to function
     157                  ?{}: pointer to function
    198158                  ... with parameters
    199159                    reference to instance of type [unbound] (not function type)
    200160                  ... returning nothing
    201161
    202                 Variable Expression: ?{}: pointer to function
    203                 ... with parameters
    204                   reference to instance of type T (not function type)
    205                   instance of type T (not function type)
    206                 ... returning nothing
    207 
    208                 ... with resolved type:
    209                   pointer to function
     162                  ?{}: pointer to function
    210163                  ... with parameters
    211164                    reference to instance of type [unbound] (not function type)
     
    213166                  ... returning nothing
    214167
    215                 Variable Expression: ^?{}: pointer to function
    216                 ... with parameters
    217                   reference to instance of type T (not function type)
    218                 ... returning nothing
    219 
    220                 ... with resolved type:
    221                   pointer to function
     168                  ^?{}: pointer to function
    222169                  ... with parameters
    223170                    reference to instance of type [unbound] (not function type)
    224171                  ... returning nothing
     172
    225173
    226174                function
     
    240188          void
    241189        )
    242         Environment:([unbound]T) -> instance of type T (not function type) (no widening)
     190        Environment:([unbound]) -> instance of type T (not function type) (no widening)
    243191
    244192      Could not satisfy assertion:
    245 Variable Expression: ?=?: pointer to function
     193?=?: pointer to function
    246194        ... with parameters
    247           reference to instance of type T (not function type)
    248           instance of type T (not function type)
     195          reference to instance of type [unbound] (not function type)
     196          instance of type [unbound] (not function type)
    249197        ... returning
    250           instance of type T (not function type)
     198          instance of type [unbound] (not function type)
    251199
    252         ... with resolved type:
    253           pointer to function
    254           ... with parameters
    255             reference to instance of type [unbound] (not function type)
    256             instance of type [unbound] (not function type)
    257           ... returning
    258             instance of type [unbound] (not function type)
    259 
  • tests/heap.cfa

    r41cde266 rc5a98f3  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 12:11:51 2020
    13 // Update Count     : 79
     12// Last Modified On : Fri Sep 25 15:21:52 2020
     13// Update Count     : 73
    1414//
    1515
     
    2727// }
    2828
    29 size_t default_heap_expansion() {
    30         return 10 * 1024 * 1024;
    31 } // default_heap_expansion
    32 
    33 size_t default_mmap_start() {
    34         return 512 * 1024 + 1;
     29#define __U_DEFAULT_MMAP_START__ (512 * 1024 + 1)
     30size_t default_mmap_start() __attribute__(( weak )) {
     31        return __U_DEFAULT_MMAP_START__;
    3532} // default_mmap_start
    3633
  • tests/multi_list.cfa

    r41cde266 rc5a98f3  
    1919}
    2020
    21 TaskDL *& Back( TaskDL * n ) {
    22         return (TaskDL *)Back( (Seqable *)n );
    23 }
    24 
    25 TaskDL *& Next( TaskDL * n ) {
    26         return (TaskDL *)Next( (Colable *)n );
    27 }
    28 
    2921struct TaskSL {
    3022        inline Colable;
     
    3729Task & task( TaskSL & this ) with( this ) {                             // getter routine for containing node
    3830        return node;
    39 }
    40 
    41 TaskSL *& Next( TaskSL * n ) {
    42         return (TaskSL *)Next( (Colable *)n );
    4331}
    4432
  • tests/queue.cfa

    r41cde266 rc5a98f3  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16         Fred *& Next( Fred * n ) {
    17                 return (Fred *)Next( (Colable *)n );
    1815        }
    1916
     
    7168        }
    7269
    73         Mary *& Next( Mary * n ) {
    74                 return (Mary *)Next( (Fred *)n );
    75         }
    76 
    7770        Queue(Mary) mary;
    7871        QueueIter(Mary) maryIter = { mary };
  • tests/raii/.expect/ctor-autogen-ERR1.nast.txt

    r41cde266 rc5a98f3  
    7070            ... with environment:
    7171              Types:
     72              Non-types:
    7273
    7374
  • tests/sequence.cfa

    r41cde266 rc5a98f3  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16 
    17         Fred *& Back( Fred * n ) {
    18                 return (Fred *)Back( (Seqable *)n );
    19         }
    20 
    21         Fred *& Next( Fred * n ) {
    22                 return (Fred *)Next( (Colable *)n );
    2315        }
    2416
     
    8476        }
    8577
    86         Mary *& Back( Mary * n ) {
    87                 return (Mary *)Back( (Fred *)n );
    88         }
    89 
    90         Mary *& Next( Mary * n ) {
    91                 return (Mary *)Next( (Fred *)n );
    92         }
    93 
    9478        Sequence(Mary) mary;
    9579        Sequence(Mary) baz;
  • tests/stack.cfa

    r41cde266 rc5a98f3  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16         Fred *& Next( Fred * n ) {
    17                 return (Fred *)Next( (Colable *)n );
    1815        }
    1916
     
    7168        }
    7269
    73         Mary *& Next( Mary * n ) {
    74                 return (Mary *)Next( (Fred *)n );
    75         }
    76 
    7770        Stack(Mary) mary;
    7871        StackIter(Mary) maryIter = { mary };
Note: See TracChangeset for help on using the changeset viewer.