sa.c 138 KB
Newer Older
clean's avatar
clean committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
       Concurrent Clean Compiler: sa.c
       ===============================

       This file contains the strictness analyser. It can handle tuples
       as well as list strictness. The file is divided in the following
       parts:
       
       General support, including a local storage allocator
       Support for storage of strictness information
       Operations on expressions
       Converions for the internal representation of the syntax tree
       The abstract reducer
       Main (external) functions
       Debugging support
       
       Author: Eric Nocker
       At: Department of Computer Science
19
       University of Nijmegen
clean's avatar
clean committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
       Version: 0.9
       Date:    Januari, 1995
*/

#undef _DB_
/*
#define CHECK_STACK_OVERFLOW
#define _DB_STACK_
*/

#define DIVIDE_FUEL
#define SHOW_STRICT_EXPORTED_TUPLE_ELEMENTS
#define MORE_ANNOTS 1

34
35
#include "compiledefines.h"
#include "types.t"
clean's avatar
clean committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "system.h"
#include "settings.h"
#include "sizes.h"
#include "syntaxtr.t"
#include "comsupport.h"
#include "sa.t"
#include "sa.h"
#ifdef _DB_TEST_
# include "saprint.h"
#endif
#include "statesgen.h"
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
#include "codegen_types.h"
#endif

#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n)

53
54
55
56
#define NR_BLOCKS_FOR_ANALYSIS 100

#define BLOCK_SIZE (unsigned long) (16 * KBYTE)

57
#ifdef CHECK_STACK_OVERFLOW
clean's avatar
clean committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
char *min_stack;
int stack_source = 0;
#endif

#if MORE_ANNOTS
# define MaxNrAnnots 100
#else
# define MaxNrAnnots 10					/* the maximum nr of strict rhs annots	*/
#endif

typedef int MyBool;
#define MyFalse 0
#define MyTrue 1
#define MyMightBeTrue 2
#define AreRelated 3
#define False MyFalse
#define True MyTrue
#define MightBeTrue MyMightBeTrue

Bool DoStrictExportChecks = False;
Bool DoStrictRelated      = False;

#define Bool MyBool

static Bool StrictWarning		= False;	/* general warnings					*/
83
static Bool StrictAllWarning	= True;		/* warnings per function			*/
clean's avatar
clean committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
static Bool StrictChecks      	= False;	/* warns for strange strictness		*/
static Bool StrictExportChecks	= False;	/* do export checks					*/

static unsigned StrictFuel		= 60; /* 20; */      /* amount of reductions to do 		*/

static unsigned min_d;
static unsigned max_memuse;				/* the maximum memory use				*/

static char		*CurrentName;			/* current function name				*/

#ifdef _DB_
static Bool DBPrinting = False;
Exp infp, botmemp, topmemp;
#endif

#ifdef _DB_
Fun
#else
static Fun
#endif
	* conssym,					/* the cons id							*/
105
106
107
#if STRICT_LISTS
	*lazy_cons_sym0,*strict_cons_sym0,*tail_strict_cons_sym0,*strict_tail_strict_cons_sym0,
#endif
clean's avatar
clean committed
108
109
110
111
112
113
114
	* nilsym,					/* the nil id							*/
	* apsym,					/* the apply id							*/
	* if_sym,					/* the if id							*/
	* true_sym,					/* the true id							*/
	* false_sym,				/* the false id							*/
	* selectsym[MaxNodeArity],	/* the select ids						*/
	* tuplesym[MaxNodeArity],	/* the tuple ids						*/
115
116
	* lazy_just_sym0,
	* strict_just_sym0,
117
	* none_sym,
clean's avatar
clean committed
118
119
120
	* strict_sym[MaxNrAnnots],	/* the strict ids						*/
	* fail_sym,					/* the fail id							*/
	* inffunct_sym,				/* the E2 id							*/
121
122
	* botmemfunct_sym,			/* the E3 id							*/
	* strictapsym;				/* the strict apply id					*/
clean's avatar
clean committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

static ExpRepr top;
static ExpRepr bottom;
static ExpRepr inf;
static ExpRepr botmem;
static ExpRepr topmem;

/*
General Support
Containing:

	- Debugging options
	  The following debugging options are available:
	      _DB_		general option, should always be set for the others
	      _DB_RED_	set on if reductions should be traced
	      _DB_EQ_	set on if comparison on expressions should be traced
	  output of the tracing is sent to the file "uit".

	- Warnings Generation

	- Storage allocator
	  In principle the storage allocator is quite simple: it supports a
	  fast allocation by allocating some large blocks if necessary. With
	  the functions 'Freeze..' and 'UnFreeze..' a basic part of the
	  storage (used for the function table and syntax tree) can be frozen.
	  Unfreezing releases all the other memory. The function 'MemUse' can
	  be used for obtaining the current memory usage.

*/

#ifdef _DB_
 File outfile;
# define Assume ProcAssume
# define Assume2 ProcAssume
	static void ProcAssume (Bool cond, char *err, char *proc)
	{
		if (! cond)
160
			FPrintF (StdError, "FATAL ERROR: %s in %s\n", err, proc);
clean's avatar
clean committed
161
162
163
164
165
166
167
168
	}
#else
# ifdef _DB_TEST_
#  define Assume(A,B,C)
#  define Assume2 ProcAssume
	static void ProcAssume (Bool cond, char *err, char *proc)
	{
		if (! cond)
169
			FPrintF (StdError, "FATAL ERROR: %s in %s\n", err, proc);
clean's avatar
clean committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	}
# else
#  define Assume2(A,B,C)
#  define Assume(A,B,C)
# endif
#endif

/*
Warnings
	Warnings can be given during or after the analysis. If after, some
	warnings that would be given during the analysis should be collected
	into one warning. This is indicated by 'depth_warning' and 
	'mem_warning'.
*/

static void error_in_function (char *m)
{
	ErrorInCompiler ("sa.c",m,"");
}

static Bool depth_warning;			/* set True if a depth warning is given		*/
static Bool mem_warning;			/* set True if a memory warning is given	*/
static Bool time_warning;			/* set True if a time warning is given		*/
static Bool export_warning;			/* set True if an export warning is given	*/
static Bool max_depth_reached;		/* set True if max depth reached, no more
									   such warnings should be given			*/
static Bool max_time_reached;		/* set True if max time reached, no more
									   such warnings should be given			*/
static Bool initialising = True;	/* set True when building function table
									   this results in other warnings			*/
static Bool instantiating = False;	/* set True when copying an expression		*/

static void GiveStrictWarning (char *f, char *msg)
{
	CurrentLine=0;
	if (f)
206
		StaticMessage_s_s (False,f,msg);
clean's avatar
clean committed
207
	else
208
		StaticMessage_s_s (False,"",msg);
clean's avatar
clean committed
209
210
211
212
213
214
}

/*******************************************************************************
 * The Storage Allocator for the strictness analysis                           *
 ******************************************************************************/

215
216
static char		**SA_store;					/* the memory blocks				*/
static int		SA_store_size = 0;
clean's avatar
clean committed
217
218
static unsigned n_allocated_blocks = 0;		/* the nr of allocated blocks		*/
static unsigned usedblocks   = 0;			/* the nr of blocks in use			*/
219
220
static char		*high        = NULL;		/* current end position in block	*/
static char		*free_pos    = NULL;		/* current free position in block	*/
clean's avatar
clean committed
221
static unsigned fblocks      = 0;			/* the freezed nr of blocks			*/
222
static char		*ffree       = NULL;		/* the freezed free position		*/
clean's avatar
clean committed
223
224
225
226

static void NewBlock (void)
{
	if (usedblocks < n_allocated_blocks)
227
		++usedblocks;
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
	else if (fblocks==0 || n_allocated_blocks<fblocks+NR_BLOCKS_FOR_ANALYSIS){
		if (n_allocated_blocks>=SA_store_size){
			if (SA_store_size==0){
				SA_store = malloc (100 * (sizeof (char*)));
				if (SA_store==NULL){
					free_pos=NULL;
					return;
				}
				SA_store_size = 100;
			}
			while (SA_store_size<=n_allocated_blocks){
				char **new_SA_store;
				
				new_SA_store = realloc (SA_store,(SA_store_size<<1) * sizeof(char*));
				if (new_SA_store==NULL){
					free_pos=NULL;
					return;
				}
				SA_store=new_SA_store;
				SA_store_size=SA_store_size<<1;
			}
		}

251
		if (! (free_pos = (char *) malloc (BLOCK_SIZE)))
clean's avatar
clean committed
252
253
254
255
256
257
258
			return;
		
		SA_store[n_allocated_blocks] = free_pos;
	
		n_allocated_blocks++;
		usedblocks++;
	} else {
259
		free_pos = NULL;
clean's avatar
clean committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
		return;
	}

	free_pos = SA_store[usedblocks - 1];
	high     = free_pos + BLOCK_SIZE;
}

static jmp_buf SAEnv, SAEnv2, SAEnv3;

#define SAllocType(t) ((t*)SAlloc(sizeof(t)))
#define SAllocArrayType(n,t) ((t*)SAlloc((n)*sizeof(t)))

static char *SAlloc (unsigned n)
{
	/* be sure to return an even address */
	n = ReSize (n);
		
	if (free_pos!=NULL && free_pos + n < high){
		char *m;
		
		m=free_pos;
		free_pos = m+n;

		return m;
	} else
		NewBlock ();
	
	if (free_pos!=NULL && free_pos + n < high){
		free_pos += n;

		return (free_pos - n);
	} else {
		if (initialising)
			longjmp (SAEnv, 1);
		
		if (StrictAllWarning)
			GiveStrictWarning (CurrentName, "out of memory (result approximated)");
		else
			mem_warning = True;
		
		if (instantiating)
			longjmp (SAEnv3, 1);
		else
			longjmp (SAEnv2, 1);
		
		return NULL;
	}
}

static void FreezeAlloc (void)
{
	ffree   = free_pos;
	fblocks = usedblocks;
}

static void FreeUnFreezedBlocks (void)
{
	usedblocks = fblocks;
	free_pos   = ffree;
	high       = SA_store[fblocks-1] + BLOCK_SIZE;
}

void free_unused_sa_blocks (void)
{
	int i;
	
	for (i=usedblocks; i<n_allocated_blocks; ++i){
		if (SA_store[i]!=NULL){
328
			free ((void *) SA_store[i]);
clean's avatar
clean committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
			SA_store[i]=NULL;
		}
	}
	
	n_allocated_blocks = usedblocks;
}

static unsigned MemUse (void)
{
	long l;
	
	if (n_allocated_blocks==0)
		return 0;
	
	if (! free_pos)
		l = (long) (usedblocks-1) * BLOCK_SIZE;
	else
John van Groningen's avatar
John van Groningen committed
346
		l = (long) (usedblocks-1) * BLOCK_SIZE + (long) ((size_t) free_pos - (size_t) SA_store[usedblocks-1]);
clean's avatar
clean committed
347
348
349
350
351
352
353
354
355
356

	return (unsigned) ((l-1) / KBYTE) + 1;
}

static void FreeBlocks (void)
{
	unsigned i;

	for (i = 0; i < n_allocated_blocks; i++){
		if (SA_store[i]!=NULL){
357
			free ((void *) SA_store[i]);
clean's avatar
clean committed
358
359
360
361
			SA_store[i]=NULL;
		}
	}
	
362
	n_allocated_blocks = usedblocks = fblocks = 0;
363
	free_pos   = ffree   = NULL;
clean's avatar
clean committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
}

#define NewExpArgs(n) SAllocArrayType(n,Exp)

static Exp NewExp (ExpKind kind, unsigned sym, Bool hnf, unsigned arity)
{
	Exp e;

	e = SAllocType (ExpRepr);
	
	e->e_kind   = kind;
	e->e_sym    = sym;
	e->e_hnf    = hnf;
	e->e_spechnf= hnf;
	e->e_hasind = False;
	e->e_red    = False;
	e->e_mark   = False;
	e->e_mark2  = False;
	e->e_imark  = False;
383
384
	e->e_fwd    = NULL;
	e->e_deps   = NULL;
clean's avatar
clean committed
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
	
	if (arity == 0)
		e->e_args = NULL;
	else
		e->e_args = NewExpArgs (arity);
	
#ifdef _DB_
	e->e_mmark  = False;
	e->e_dmark  = False;
	e->e_shared = False;
	e->e_add    = 0;
#endif

	return e;
}

static Exp NewValueExp (Fun *fun, Bool hnf, unsigned arity)
{
	Exp e;

	e = SAllocType (ExpRepr);
	
	e->e_kind   = Value;
	e->e_fun    = fun;
	e->e_hnf    = hnf;
	e->e_spechnf= hnf;
	e->e_hasind = False;
	e->e_red    = False;
	e->e_mark   = False;
	e->e_mark2  = False;
	e->e_imark  = False;
416
417
	e->e_fwd    = NULL;
	e->e_deps   = NULL;
clean's avatar
clean committed
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
	
	if (arity == 0)
		e->e_args = NULL;
	else
		e->e_args = NewExpArgs (arity);
	
#ifdef _DB_
	e->e_mmark  = False;
	e->e_dmark  = False;
	e->e_shared = False;
	e->e_add    = 0;
#endif

	return e;
}

#define NewTop()  (NewExp (Top, 0, True, 0))

static void InitExp (Exp e, ExpKind kind, unsigned sym, Bool hnf)
{
	e->e_kind   = kind;
	e->e_sym    = sym;
	e->e_hnf    = hnf;
	e->e_spechnf= hnf;
	e->e_hasind = False;
	e->e_red    = False;
	e->e_mark   = False;
	e->e_mark2  = False;
	e->e_imark  = False;
447
448
	e->e_fwd    = NULL;
	e->e_deps   = NULL;
clean's avatar
clean committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
	
#ifdef _DB_
	e->e_mmark  = False;
	e->e_dmark  = False;
	e->e_shared = False;
	e->e_add    = 0;
#endif
}

static void InitValueExp (Exp e,Fun *fun,Bool hnf)
{
	e->e_kind   = Value;
	e->e_fun    = fun;
	e->e_hnf    = hnf;
	e->e_spechnf= hnf;
	e->e_hasind = False;
	e->e_red    = False;
	e->e_mark   = False;
	e->e_mark2  = False;
	e->e_imark  = False;
469
470
	e->e_fwd    = NULL;
	e->e_deps   = NULL;
clean's avatar
clean committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
	
#ifdef _DB_
	e->e_mmark  = False;
	e->e_dmark  = False;
	e->e_shared = False;
	e->e_add    = 0;
#endif
}

static unsigned start_fuel;

static void SetStartFuel (void)
{
	start_fuel = StrictFuel;
}

static Bool OutOfFuel (void)
488
{
clean's avatar
clean committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
	if (start_fuel == 0)
		return True;

	--start_fuel;
	return False;
}

/* Operations on StrictInfos and contexts */

static StrictKind MaxStrict (StrictKind s1, StrictKind s2)
{
	if (s1 < s2)
		return s2;
	else
		return s1;
}

static Context SimpleContext (Context context, StrictKind kind, Bool spec)
507
{
clean's avatar
clean committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
	if (! context)
		context = SAllocType (ContextRepr);

	context->context_arity       = 1;
	context->context_speculative = spec;
	context->context_kind        = kind;
	context->context_args        = NULL;

	return context;
}

static Context NewSimpleContext (StrictKind kind, Bool spec)
{
	Context context;
	
	context = SAllocType (ContextRepr);

	context->context_arity       = 1;
	context->context_speculative = spec;
	context->context_kind        = kind;
	context->context_args        = NULL;

	return context;
}

static Context StrictInfoToContext (StrictInfo *s, Context curcontext, Bool resultinfo)
{
	Context context;

	if (! resultinfo && curcontext->context_kind == NotStrict)
		return curcontext;
	
	if (IsTupleInfo (s)){
		StrictKind info_kind = GetTupleStrictKind (s);
		
		if (info_kind == NotStrict){
			if (resultinfo)
				return curcontext;

			context = SAllocType (ContextRepr);
			context->context_arity       = 1;
			context->context_speculative = curcontext->context_speculative;
			context->context_kind        = NotStrict;
551
			context->context_args        = (Context *) NULL;
clean's avatar
clean committed
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
		}
		else {
			unsigned i, n;
			Bool has_strict_arg = False;
			Context subcontext;
			
			n = s->strict_arity;
			
			context = SAllocType (ContextRepr);
			context->context_arity       = s->strict_arity;
			context->context_speculative = curcontext->context_speculative;
			context->context_kind        = HnfStrict;
			context->context_args        = SAllocArrayType (n,Context);
		
			for (i = 0; i < n; i++)
			{	if (! resultinfo)
					subcontext = curcontext;
				else if (curcontext->context_arity > 1)
					subcontext = curcontext->context_args[i];
				else
					subcontext = NewSimpleContext (NotStrict, curcontext->context_speculative);
					
				context->context_args[i] = StrictInfoToContext (& GetTupleInfo (s, i), subcontext, resultinfo);
				if (context->context_args[i]->context_kind != NotStrict)
					has_strict_arg = True;
			}
			
			if (! has_strict_arg)
				context->context_arity = 1;
		}
	}
	else {
		StrictKind info_kind = GetStrictKind (s, ContextToIndex (curcontext->context_kind));
	
		if (resultinfo){
			if (info_kind <= curcontext->context_kind)
				return curcontext;
		
			context = SAllocType (ContextRepr);
			context->context_arity       = 1;
			context->context_speculative = curcontext->context_speculative;
			context->context_kind        = info_kind;
			context->context_args        = NULL;
		} else {
			if (info_kind == curcontext->context_kind && curcontext->context_arity == 1)
				return curcontext;
				
			context = SAllocType (ContextRepr);
			context->context_arity       = 1;
			context->context_speculative = curcontext->context_speculative;
			context->context_kind        = info_kind;
			context->context_args        = NULL;
		}
	}
	
	return context;
}

610
static Context copy_context (Context curcontext)
clean's avatar
clean committed
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
{
	Context context;

	if (! curcontext || curcontext->context_kind == NotStrict)
		return NULL;
	
	context = SAllocType (ContextRepr);
	context->context_arity       = curcontext->context_arity;
	context->context_speculative = False;
	context->context_kind        = curcontext->context_kind;
	
	if (context->context_arity > 1){
		unsigned i, n;
		
		n = context->context_arity;
		context->context_args = SAllocArrayType (n,Context);
	
		for (i = 0; i < n; i++)
629
			context->context_args[i] = copy_context (curcontext->context_args[i]);
clean's avatar
clean committed
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
	} else
		context->context_args  = NULL;
	
	return context;
}

/* Operations on expressions */

static void InitValues (void)
{
	static ExpRepr	botmem1;
	static ExpRepr	botmem2;
	static Exp		infargs[2];
	static Exp		botmem1args[2];
	static Exp		botmem2args[2];
	static Exp		botmemargs[2];
	static ExpRepr	topmem1;
	static ExpRepr	topmem2;
	static Exp		topmem1args[2];
	static Exp		topmemargs[2];

#ifdef _DB_
	infp    = & inf;
	botmemp = & botmem;
	topmemp = & topmem;
#endif

	InitValueExp (&inf, conssym, True);
	inf.e_args    = infargs;
	inf.e_args[0] = & top;
	inf.e_args[1] = & inf;

	InitValueExp (&topmem1,  nilsym,  True);
	InitValueExp (&topmem2,  conssym, True);

	InitExp (&topmem, Lub, 2, True);

	topmem.e_kind = Top;			
	topmem.e_args    = topmemargs;
	topmem.e_args[0] = & topmem1;
	topmem.e_args[1] = & topmem2;

	topmem2.e_args    = topmem1args;
	topmem2.e_args[0] = & top;
	topmem2.e_args[1] = & topmem;
	
	InitValueExp (&botmem1,  conssym, True);
	InitValueExp (&botmem2,  conssym, True);

	InitExp (&botmem, Lub, 2, True);

	botmem.e_args    = botmemargs;
	botmem.e_args[0] = & botmem1;
	botmem.e_args[1] = & botmem2;
	
	botmem1.e_args    = botmem1args;
	botmem1.e_args[0] = & top;
	botmem1.e_args[1] = & botmem;
	
	botmem2.e_args    = botmem2args;
	botmem2.e_args[0] = & bottom;
	botmem2.e_args[1] = & topmem;
}

static void RemoveMark (Exp e)
{
	unsigned n,i;
	
	if (! e->e_mark)
		return;
	
	e->e_mark = False;
	switch (e->e_kind){
		case Top:
		case Bottom:
		case FunValue:
			return;
		case Ind:
			RemoveMark (e->e_args[0]);
			return;
		case Argument:
			return;
		case Value:
			n = e->e_fun->fun_arity;
			break;
		case Dep:
		case Lub:
			n = e->e_sym;
			break;
		default:
			Assume (False, "unknown case", "RemoveMark");
			return;
	}
	
	for (i = 0; i < n; i++)
		RemoveMark (e->e_args[i]);
}

static Exp InstantiateExp2 (Exp e)
{
	unsigned arity, i;
	Exp new_e;

	if (e->e_mark)
		return e->e_fwd;

	e->e_mark = True;
	switch (e->e_kind){
		case Top:
			new_e    = NewTop();
			e->e_fwd = new_e;
			break;
		case Dep:
		{
			unsigned j;
			Exp arg_e;
746

clean's avatar
clean committed
747
748
749
750
751
752
			arity    = e->e_sym;
			new_e    = NewExp (Dep, e->e_sym, e->e_hnf, arity);
			e->e_fwd = new_e;
			for (i = 0, j = 0; i < arity; i++){
				arg_e = InstantiateExp2 (e->e_args[i]);
				if (arg_e->e_kind == Bottom){
753
754
755
756
					new_e->e_kind = Bottom;
					new_e->e_hnf = True;
					new_e = &bottom;
					e->e_fwd = new_e;
clean's avatar
clean committed
757
758
759
760
761
762
763
764
765
766
767
768
769
					return new_e;
				} else if (arg_e->e_kind == Top) /* || arg_e->e_hnf) */
					/* simply skip it */
					;
				else {
					new_e->e_args[j] = arg_e;
					j++;
				}
			}
			if (j == 0){
				new_e    = NewTop();
				e->e_fwd = new_e;
			} else
770
				new_e->e_sym = j;
clean's avatar
clean committed
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
			break;
		}
		case Bottom:
			e->e_fwd = & bottom;
			new_e    = & bottom;
			break;
		case FunValue:
			e->e_mark = False;
			e->e_fwd  = e;
			new_e     = e;
			break;
		case Ind:
			new_e            = NewExp (Ind, 0, False, 1);
			e->e_fwd         = new_e;
			new_e->e_args[0] = e->e_args[0];
			break;
		case Argument:
#ifndef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
789
			Assume2 (e->e_args[0] != NULL, "argument not bound", "InstantiateExp");
clean's avatar
clean committed
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
#endif
			e->e_fwd     = new_e = e->e_args[0];
#ifndef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
			e->e_args[0] = NULL;
#endif
			break;
		case Value:
			arity = e->e_fun->fun_arity;
			new_e = NewValueExp (e->e_fun, e->e_hnf, arity);
			e->e_fwd = new_e;
			for (i = 0; i < arity; i++)
				new_e->e_args[i] = InstantiateExp2 (e->e_args[i]);
			break;
		case Lub:
			arity    = e->e_sym;
			new_e    = NewExp (Lub, e->e_sym, True, arity);
			e->e_fwd = new_e;
			for (i = 0; i < arity; i++)
				new_e->e_args[i] = InstantiateExp2 (e->e_args[i]);
			break;
		default:
			Assume (False, "unknown case", "InstantiateExp");
			return &top;
	}

	return new_e;
}

static Exp InstantiateExp (Exp e)
{
	Exp new_e;

	instantiating = True;
	
	if (setjmp (SAEnv3) != 0){
		RemoveMark (e);
		instantiating = False;
		longjmp (SAEnv2, 1);
	}

	new_e = InstantiateExp2 (e);
	RemoveMark (e);
	instantiating = False;

	return new_e;
}

/*
	 During (Ext)LtExp2 a the addresses in Val/Dep expressions are determined for
     which an AreRelated relation exists
     
     the Bool CheckAreRelated should be (un)set before(after) LtExp is called
*/
 
static Bool CheckAreRelated = False;
static Exp *s_exp1, *s_exp2, *q_exp;

/* JVG */
#define MAX_LT_EXP2_CALLS 100000
static long lt_exp2_max_n_calls;
/* */

852
853
854
855
/* LtExp2 may take exponential time if expressions are shared,
   if CACHE_LT_EXP is defined extra code prevents this in most cases
   by storing previous results using e_lt_cached, e_fwd and e_lt_result */

clean's avatar
clean committed
856
857
858
859
static Bool LtExp2 (Exp e1, Exp e2)
{
	unsigned n, i;

860
#ifdef CHECK_STACK_OVERFLOW
clean's avatar
clean committed
861
862
863
864
865
866
867
868
869
870
871
872
	char x;

	if (&x < min_stack)
	{	printf ("Stack overflow in LtExp\n");
#ifdef _DB_
		FPrintF (outfile, "Stack overflow in LtExp\n");
#endif
		return False;
	}
#endif
	if (e1 == e2)
		return True;
873
874
875
876
#ifdef CACHE_LT_EXP
	if (e1->e_lt_cached && e1->e_fwd==e2)
		return e1->e_lt_result;
#endif
clean's avatar
clean committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
	if (e1->e_mark || e2->e_mark)
		return MightBeTrue;

	if (e2->e_kind == Top)
		return True;

	/* JVG */
	if (++lt_exp2_max_n_calls >= MAX_LT_EXP2_CALLS)
		return MightBeTrue;
	/* */

	switch (e1->e_kind){
		case Bottom:
			return True;
		case Top:
			return False;
		case FunValue:
			if (e2->e_kind == FunValue && e1->e_fun==e2->e_fun)
				return True;
			else
				break;
		case Ind:
			e1->e_mark = True;
			if (LtExp2 (e1->e_args[0], e2)){
				e1->e_mark = False;
902
903
904
905
906
#ifdef CACHE_LT_EXP
				e1->e_lt_cached = True;
				e1->e_fwd = e2;
				e1->e_lt_result = True;
#endif
clean's avatar
clean committed
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
				return True;
			}
			e1->e_mark = False;
			break;
		case Value:
		case Dep:
		{
			int s_index;
			
			s_index = -1;
					
			if (e1->e_kind==Value){
				if (e1->e_kind!=e2->e_kind || e1->e_fun!=e2->e_fun)
					break;
				
				n = e1->e_fun->fun_arity;
			} else {
				if (e1->e_kind!=e2->e_kind || e1->e_sym!=e2->e_sym)
925
					break;
clean's avatar
clean committed
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942

				n = e1->e_sym;
			}

			e1->e_mark = True;
			e2->e_mark = True;
			
			for (i = 0; i < n; i++){
				Bool b;
				
				b = LtExp2 (e1->e_args[i], e2->e_args[i]);
				switch (b){
					case True:
						continue;
					case MightBeTrue:
						e1->e_mark = False;
						e2->e_mark = False;
943
944
945
946
947
#ifdef CACHE_LT_EXP
						e1->e_lt_cached = True;
						e1->e_fwd = e2;
						e1->e_lt_result = MightBeTrue;
#endif
clean's avatar
clean committed
948
949
950
951
952
953
954
955
956
						return MightBeTrue;
					case False:
					case AreRelated:
						if (CheckAreRelated && s_index < 0){
							s_index = i;
							continue;
						} else {
							e1->e_mark = False;
							e2->e_mark = False;
957
958
959
960
961
#ifdef CACHE_LT_EXP
							e1->e_lt_cached = True;
							e1->e_fwd = e2;
							e1->e_lt_result = False;
#endif
clean's avatar
clean committed
962
963
964
965
966
967
968
969
970
							return False;
						}
				}
			}
			e1->e_mark = False;
			e2->e_mark = False;
			if (s_index >= 0){
				s_exp1 = & e1->e_args[s_index];
				s_exp2 = & e2->e_args[s_index];
971
972
973
974
975
#ifdef CACHE_LT_EXP
				e1->e_lt_cached = True;
				e1->e_fwd = e2;
				e1->e_lt_result = AreRelated;
#endif
clean's avatar
clean committed
976
				return AreRelated;
977
978
979
980
981
982
			} else {
#ifdef CACHE_LT_EXP
				e1->e_lt_cached = True;
				e1->e_fwd = e2;
				e1->e_lt_result = True;
#endif
clean's avatar
clean committed
983
				return True;
984
			}
clean's avatar
clean committed
985
986
987
988
989
990
991
992
993
994
		}
		case Lub:
			e1->e_mark = True;
			n = e1->e_sym;
			for (i = 0; i < n; i++){
				Bool b;
				
				b = LtExp2 (e1->e_args[i], e2);
				if (b != True){
					e1->e_mark = False;
995
996
997
998
999
#ifdef CACHE_LT_EXP
					e1->e_lt_cached = True;
					e1->e_fwd = e2;
					e1->e_lt_result = b;
#endif
clean's avatar
clean committed
1000
1001
1002
1003
					return b;
				}
			}
			e1->e_mark = False;
1004
1005
1006
1007
1008
#ifdef CACHE_LT_EXP
			e1->e_lt_cached = True;
			e1->e_fwd = e2;
			e1->e_lt_result = True;
#endif
clean's avatar
clean committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
			return True;
		default:
			Assume (False, "illegal case", "LtExp");
			return False;
	}
	
	/* check if e2 is a lub or Ind */
	if (e2->e_kind == Lub){
		Bool result;
		
		result = False;
		e2->e_mark = True;
		n = e2->e_sym;

		for (i = 0; i < n; i++){
			Bool b;
			
			b = LtExp2 (e1, e2->e_args[i]);
			if (b == True){
				e2->e_mark = False;
1029
1030
1031
1032
1033
#ifdef CACHE_LT_EXP
				e1->e_lt_cached = True;
				e1->e_fwd = e2;
				e1->e_lt_result = b;
#endif
clean's avatar
clean committed
1034
1035
1036
1037
1038
				return b;
			} else if (b == MightBeTrue)
				result = MightBeTrue;
		}
		e2->e_mark = False;
1039
1040
1041
1042
1043
#ifdef CACHE_LT_EXP
		e1->e_lt_cached = True;
		e1->e_fwd = e2;
		e1->e_lt_result = result;
#endif
clean's avatar
clean committed
1044
1045
1046
1047
1048
1049
		return result;
	} else if (e2->e_kind == Ind){
		e2->e_mark = True;

		if (LtExp2 (e1, e2->e_args[0])){
			e2->e_mark = False;
1050
1051
1052
1053
1054
#ifdef CACHE_LT_EXP
			e1->e_lt_cached = True;
			e1->e_fwd = e2;
			e1->e_lt_result = True;
#endif
clean's avatar
clean committed
1055
1056
1057
1058
			return True;
		}
		e2->e_mark = False;
	}
1059
1060
1061
1062
1063
#ifdef CACHE_LT_EXP
	e1->e_lt_cached = True;
	e1->e_fwd = e2;
	e1->e_lt_result = False;
#endif
clean's avatar
clean committed
1064
1065
1066
	return False;
}

1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
#ifdef CACHE_LT_EXP
static void remove_lt_cached (Exp e)
{
	unsigned n,i;

	if (! e->e_lt_cached)
		return;

	e->e_lt_cached = False;
	switch (e->e_kind){
		case Top:
		case Bottom:
		case FunValue:
			return;
		case Ind:
			remove_lt_cached (e->e_args[0]);
			return;
		case Argument:
			return;
		case Value:
			n = e->e_fun->fun_arity;
			break;
		case Dep:
		case Lub:
			n = e->e_sym;
			break;
		default:
			Assume (False, "unknown case", "remove_lt_cached");
			return;
	}

	for (i = 0; i < n; i++)
		remove_lt_cached (e->e_args[i]);
}
#endif

clean's avatar
clean committed
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
#ifdef _DB_
#undef Bool
Bool IsInAPath (Exp e1, Exp e2, APath p)
#define Bool MyBool
#else
static Bool IsInAPath (Exp e1, Exp e2, APath p)
#endif
{
	for ( ; p; p = p->ap_next){
		if (e1 == p->ap_e1 && e2 == p->ap_e2)
			return True;
	}
	return False;
}

1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
#ifdef CACHE_EXT_LT_EXP
/* yields depth<<2|(1 if in APath) */
static unsigned int IsInAPathAndDepth (Exp e1, Exp e2, APath path)
{
	APath p;
	unsigned int depth;

	for (p=path, depth=0; p!=NULL; p=p->ap_next, depth+=4)
		if (e1 == p->ap_e1 && e2 == p->ap_e2)
			return depth|1;

	return depth;
}
#endif

clean's avatar
clean committed
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
#ifdef _DB_
APath AddToAPath (Exp e1, Exp e2, APath p)
#else
static APath AddToAPath (Exp e1, Exp e2, APath p)
#endif
{
	APath new;

	new = SAllocType (APathRepr);

	new->ap_e1   = e1;
	new->ap_e2   = e2;
	new->ap_next = p;
	return new;
}

static Bool EqExp2 (Exp e1, Exp e2)
{
	unsigned n, i;

	if (e1 == e2)
		return True;

	if (e1->e_mark)
		return MightBeTrue;
	
	switch (e1->e_kind)
	{
	case Bottom:
		if (e2->e_kind == Bottom)
			return True;
		else
			return False;
	case Top:
		if (e2->e_kind == Top)
			return True;
		else
1170
			return False;
clean's avatar
clean committed
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
	case FunValue:
		if (e2->e_kind == FunValue && e1->e_fun==e2->e_fun)
			return True;
		else
			return False;
	case Argument:
		return False;
	case Ind:
		return (e2->e_kind == Ind && e1->e_args[0] == e2->e_args[0]);
	case Value:
	case Dep:
		if (e1->e_kind!=e2->e_kind)
			return False;
		
		if (e1->e_kind == Value){
			if (e1->e_fun != e2->e_fun)
				return False;

			n = e1->e_fun->fun_arity;
		} else {
			if (e1->e_sym != e2->e_sym)
				return False;
		
			n = e1->e_sym;
		}
		
		e1->e_mark = True;
		
		for (i = 0; i < n; i++)
		{	Bool b = EqExp2 (e1->e_args[i], e2->e_args[i]);
			if (b != True)
			{	e1->e_mark = False;
				return b;
			}
		}
		e1->e_mark = False;
		return True;
	case Lub:
		if (e2->e_kind != Lub || e1->e_sym != e2->e_sym)
			return False;
		e1->e_mark = True;
		n = e1->e_sym;
		for (i = 0; i < n; i++)
		{	Bool b = EqExp2 (e1->e_args[i], e2->e_args[i]);
/* JVG added: */
			if (b!=True)
/**/
			{	e1->e_mark = False;
				return b;
			}
		}
		e1->e_mark = False;
		return True;
	default:
		Assume (False, "illegal case", "EqExp");
		return False;
	}
} /* EqExp2 */

static Bool ExtEqExp2 (Exp e1, Exp e2, APath p)
{
	unsigned n, i;
	APath newp;
	
	if (e1 == e2)
		return True;
	
	if (IsInAPath (e1, e2, p))
		return True;
		
	if (e1->e_mark && e2->e_mark)
		return False;
	
	newp = AddToAPath (e1, e2, p);
		
	switch (e1->e_kind){
	case Bottom:
		if (e2->e_kind == Bottom)
			return True;
		else
			return False;
	case Top:
		if (e2->e_kind == Top)
			return True;
		else
			return False;
	case FunValue:
		if (e2->e_kind == FunValue && e1->e_fun==e2->e_fun)
			return True;
		else
			return False;
	case Argument:
		return False;
	case Ind:
		return (e2->e_kind == Ind && e1->e_args[0] == e2->e_args[0]);
	case Value:
	case Dep:
		if (e1->e_kind != e2->e_kind)
			return False;
		
		if (e1->e_kind == Value){
			if (e1->e_fun != e2->e_fun)
				return False;
				
			n = e1->e_fun->fun_arity;
		} else {
			if (e1->e_sym != e2->e_sym)
				return False;
			
			n = e1->e_sym;
		}

		e1->e_mark = True;
		e2->e_mark = True;

		for (i = 0; i < n; i++)
		{	if (! ExtEqExp2 (e1->e_args[i], e2->e_args[i], newp))
			{	e1->e_mark = False;
				e2->e_mark = False;
				return False;
			}
		}
		e1->e_mark = False;
		e2->e_mark = False;
		return True;
	case Lub:
		if (e2->e_kind != Lub || e1->e_sym != e2->e_sym)
			return False;
		e1->e_mark = True;
		e2->e_mark = True;
		n = e1->e_sym;
		for (i = 0; i < n; i++)
		{	if (! ExtEqExp2 (e1->e_args[i], e2->e_args[i], newp))
			{	e1->e_mark = False;
				e2->e_mark = False;
				return False;
			}
		}
		e1->e_mark = False;
		e2->e_mark = False;
		return True;
	default:
		Assume (False, "unknown case", "ExtEqExp2");
		return False;
	}
} /* ExtEqExp2 */

#ifdef _DB_
#undef Bool
static Bool EqExp (Exp e1, Exp e2)
#define Bool MyBool
#else
static Bool EqExp (Exp e1, Exp e2)
#endif /* _DB_ */
{
	Bool b;
	
	b = EqExp2 (e1, e2);
	
	if (b == MightBeTrue && StrictDoExtEq){
1331
		b = ExtEqExp2 (e1, e2, (APath) NULL);
clean's avatar
clean committed
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
		Assume (! ContainsMark (e1), "e1 is marked", "EqExp (Ext)");
		Assume (! ContainsMark (e2), "e2 is marked", "EqExp (Ext)");
	}
	else
	{	Assume (! ContainsMark (e1), "e1 is marked", "EqExp");
	}

	if (b == True)
		return True;
	else
		return False;
}

1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
/* ExtLtExp2 may take exponential time if expressions are shared,
   if CACHE_EXT_LT_EXP is defined extra code prevents this in most cases
   by storing previous results using e_lt_cached, e_fwd and e_lt_result
   for nodes that are not on a cycle. to detect nodes on a cycle the
   minimal depth of the reachable nodes is compared to the depth of the
   current node. if a cached node is encountered, IsInAPathAndDepth would not
   find node e1 e2 in the path, because that would mean the node is on a cycle */

#ifdef CACHE_EXT_LT_EXP
#define MaxDepth 0xfffffffcu

/* yields minimal depth<<2|result */
static unsigned int ExtLtExp2 (Exp e1, Exp e2, APath p)
{
	unsigned int depth,current_depth;

	if (e1 == e2)
		return MaxDepth|True;
	if (e1->e_kind == Bottom || e2->e_kind == Top)
		return MaxDepth|True;
	if (e1->e_kind == Top || e2->e_kind == Bottom)
		return MaxDepth|False;

	if (e1->e_lt_cached && e1->e_fwd==e2)
		return MaxDepth|e1->e_lt_result;

	current_depth = IsInAPathAndDepth (e1, e2, p);
	if (current_depth & 1)
		return current_depth; /* True */

	switch (e1->e_kind){
		case FunValue:
			if (e2->e_kind == FunValue && e1->e_fun == e2->e_fun)
				return MaxDepth|True;
			else {
				depth = MaxDepth;
				break;
			}
		case Ind:
		{
			APath newp;

			newp = AddToAPath (e1, e2, p);
			depth = ExtLtExp2 (e1->e_args[0], e2, newp);
			if (depth & 3){
				depth = depth & (~3u);
				if (depth > current_depth){
					e1->e_lt_cached=True;
					e1->e_lt_result=True;
					e1->e_fwd=e2;
				} else
					e1->e_mark=True;
				return depth|True;
			} else
				break;
		}
		case Value:
		case Dep:
		{
			unsigned n, i;
			int s_index;
			APath newp;
			unsigned int min_depth;

			if (e1->e_kind != e2->e_kind){
				depth = MaxDepth;
				break;
			}

			if (e1->e_kind==Value){
				if (e1->e_fun != e2->e_fun){
					depth = MaxDepth;
					break;
				}
				n=e1->e_fun->fun_arity;
			} else {
				if (e1->e_sym != e2->e_sym){
					depth = MaxDepth;
					break;
				}
				n=e1->e_sym;
			}

			s_index = -1;

			newp = AddToAPath (e1, e2, p);

			min_depth = MaxDepth;
			for (i = 0; i < n; i++){
				Bool b;

				depth = ExtLtExp2 (e1->e_args[i], e2->e_args[i], newp);
				b = depth & 3u;
				depth = depth & (~3u);
				if (depth < min_depth)
					min_depth = depth;

				switch (b){
					case True:
						continue;
					case False:
					case AreRelated:
						if (CheckAreRelated && s_index < 0){
							s_index = i;
							continue;
						}
						if (min_depth > current_depth){
							e1->e_lt_cached=True;
							e1->e_lt_result=False;
							e1->e_fwd=e2;
						} else
							e1->e_mark=True;
						return min_depth|False;
				}
			}
			if (s_index >= 0){
				s_exp1 = & e1->e_args[s_index];
				s_exp2 = & e2->e_args[s_index];
				e1->e_mark=True;
				return min_depth|AreRelated;
			}

			if (min_depth > current_depth){
				e1->e_lt_cached=True;
				e1->e_lt_result=True;
				e1->e_fwd=e2;
			} else
				e1->e_mark=True;
			return min_depth|True;
		}
		case Lub:
		{
			unsigned n, i;
			APath newp;
			unsigned int min_depth;

			n    = e1->e_sym;
			newp = AddToAPath (e1, e2, p);

			min_depth = MaxDepth;
			for (i = 0; i < n; i++){
				Bool b;

				depth = ExtLtExp2 (e1->e_args[i], e2, newp);
				b = depth & 3u;
				depth = depth & (~3u);
				if (depth < min_depth)
					min_depth = depth;

				if (b != True){
					if (min_depth > current_depth){
						e1->e_lt_cached=True;
						e1->e_lt_result=False;
						e1->e_fwd=e2;
					} else
						e1->e_mark=True;
					return min_depth|False;
				}
			}

			if (min_depth > current_depth){
				e1->e_lt_cached=True;
				e1->e_lt_result=True;
				e1->e_fwd=e2;
			} else
				e1->e_mark=True;
			return min_depth|True;
		}
		default:
			Assume (False, "illegal case", "LtExp");
			return False;
	}

	/* check if e2 is a lub */
	if (e2->e_kind == Lub){
		unsigned n, i;
		APath newp;
		unsigned int min_depth;

		n    = e2->e_sym;
		newp = AddToAPath (e1, e2, p);

		min_depth = depth;
		for (i = 0; i < n; i++){
			Bool b;

			depth = ExtLtExp2 (e1, e2->e_args[i], newp);
			b = depth & 3u;
			depth = depth & (~3u);
			if (depth < min_depth)
				min_depth = depth;

			if (b == True){
				if (depth > current_depth){
					e1->e_lt_cached=True;
					e1->e_lt_result=True;
					e1->e_fwd=e2;
				} else
					e1->e_mark=True;
				return min_depth|True;
			}
		}

		depth=min_depth;
	} else if (e2->e_kind == Ind){
		unsigned int min_depth;

		min_depth = depth;
		depth = ExtLtExp2 (e1, e2->e_args[0], p);

		if (depth & 3u){
			depth = depth & (~3u);
			if (depth < min_depth)
				min_depth = depth;
			return min_depth|True;
		}
		if (depth < min_depth)
			min_depth = depth;
		depth=min_depth;
	}

	if (depth > current_depth){
		e1->e_lt_cached=True;
		e1->e_lt_result=False;
		e1->e_fwd=e2;
	} else
		e1->e_mark=True;
	return depth|False;
}

static void remove_mark_or_lt_cached (Exp e)
{
	unsigned n,i;

	if (e->e_lt_cached==0 && e->e_mark==0)
		return;

	e->e_lt_cached = False;
	e->e_mark = False;

	switch (e->e_kind){
		case Top:
		case Bottom:
		case FunValue:
			return;
		case Ind:
			remove_mark_or_lt_cached (e->e_args[0]);
			return;
		case Argument:
			return;
		case Value:
			n = e->e_fun->fun_arity;
			break;
		case Dep:
		case Lub:
			n = e->e_sym;
			break;
		default:
			Assume (False, "unknown case", "remove_mark_or_lt_cached");
			return;
	}

	for (i = 0; i < n; i++)
		remove_mark_or_lt_cached (e->e_args[i]);
}
#else
clean's avatar
clean committed
1611
static Bool ExtLtExp2 (Exp e1, Exp e2, APath p)
1612
{
clean's avatar
clean committed
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
	if (e1 == e2)
		return True;
	if (e1->e_kind == Bottom || e2->e_kind == Top)
		return True;
	if (e1->e_kind == Top || e2->e_kind == Bottom)
		return False;

	if (IsInAPath (e1, e2, p))
		return True;
	
	switch (e1->e_kind){
		case FunValue:
			if (e2->e_kind == FunValue && e1->e_fun == e2->e_fun)
				return True;
			else
				break;
		case Ind:
		{
			APath newp;
			
			newp = AddToAPath (e1, e2, p);
			if (ExtLtExp2 (e1->e_args[0], e2, newp))
				return True;
			else
				break;
		}
1639
		case Value:
clean's avatar
clean committed
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
		case Dep:
		{
			unsigned n, i;
			int s_index;
			APath newp;

			if (e1->e_kind != e2->e_kind)
				break;
			
			if (e1->e_kind==Value){
				if (e1->e_fun != e2->e_fun)
					break;
				n=e1->e_fun->fun_arity;
			} else {
				if (e1->e_sym != e2->e_sym)
1655
					break;
clean's avatar
clean committed
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
				n=e1->e_sym;
			}

			s_index = -1;
						
			newp = AddToAPath (e1, e2, p);
			for (i = 0; i < n; i++){
				Bool b = ExtLtExp2 (e1->e_args[i], e2->e_args[i], newp);
				switch (b){
					case True:
						continue;
					case False:
					case AreRelated:
						if (CheckAreRelated && s_index < 0){
							s_index = i;
							continue;
						}
						return False;
				}
			}
			if (s_index >= 0){
				s_exp1 = & e1->e_args[s_index];
				s_exp2 = & e2->e_args[s_index];
				return AreRelated;
			} else
				return True;
			
			return True;
		}
		case Lub:
		{
			unsigned n, i;
			APath newp;
				
			n    = e1->e_sym;
			newp = AddToAPath (e1, e2, p);
		
			for (i = 0; i < n; i++){
				Bool b = ExtLtExp2 (e1->e_args[i], e2, newp);
				if (b != True)
					return False;
			}
			return True;
		}
		default:
			Assume (False, "illegal case", "LtExp");
			return False;
	}

	/* check if e2 is a lub */
	if (e2->e_kind == Lub){
		unsigned n, i;
		APath newp;

		n    = e2->e_sym;
		newp = AddToAPath (e1, e2, p);

		for (i = 0; i < n; i++){
			if (ExtLtExp2 (e1, e2->e_args[i], newp) == True)
				return True;
		}
	} else if (e2->e_kind == Ind){
		if (ExtLtExp2 (e1, e2->e_args[0], p))
			return True;
	}
	
	return False;
}
1724
#endif
clean's avatar
clean committed
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744

static Bool LtExp (Exp e1, Exp e2)
{
	Bool b;

#ifdef _DB_EQ_
	if (DBPrinting)
	{	FPrintF (outfile, "Less then e1: ");
		DumpExp (outfile, e1);
		FPrintF (outfile, "\n        e2: ");
		DumpExp (outfile, e2);
		FPutC ('\n', outfile);
	}
#endif

	/* JVG */
	lt_exp2_max_n_calls=0;
	/* */
	b = LtExp2 (e1, e2);

1745
1746
1747
1748
#ifdef CACHE_LT_EXP
	remove_lt_cached (e1);
#endif

clean's avatar
clean committed
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
#ifdef _DB_EQ_
	if (DBPrinting){
		if (b == True)
			FPrintF (outfile, "Result: True\n\n");
		else if (b == MightBeTrue)
			FPrintF (outfile, "Result: MightBeTrue\n\n");
		else
			FPrintF (outfile, "Result: False\n\n");
	}
#endif

1760
	if (b == MightBeTrue && StrictDoExtEq){
1761
		b = ExtLtExp2 (e1, e2, (APath) NULL);
clean's avatar
clean committed
1762

1763
1764
1765
1766
1767
#ifdef CACHE_EXT_LT_EXP
		b = b & 3u;
		remove_mark_or_lt_cached (e1);
#endif

clean's avatar
clean committed
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
#ifdef _DB_EQ_
		if (DBPrinting){
			if (b == True)
				FPrintF (outfile, "Result2: True\n\n");
			else if (b == MightBeTrue)
				FPrintF (outfile, "Result2: MightBeTrue\n\n");
			else
				FPrintF (outfile, "Result2: False\n\n");
		}
#endif
	}

	return b;
}

static Bool IsContainedIn (Exp e1, ExpP ep2)
{
	Exp e2;
	
	e2 = *ep2;

	if (e2->e_mark2)
		return False;
		
	if (EqExp (e1, e2)){
		q_exp = ep2;
		return True;
	}
	
	switch (e2->e_kind){
		case Value:
		{	unsigned n, i;
			
			e2->e_mark2 = True;
			n = e2->e_fun->fun_arity;
			for (i = 0; i < n; i++){
				if (IsContainedIn (e1, & e2->e_args[i])){
					e2->e_mark2 = False;
					return True;
				}
			}
			e2->e_mark2 = False;
			return False;
		}
		case Lub:
		{	unsigned n, i;
			e2->e_mark2 = True;
			n    = e2->e_sym;
			for (i = 0; i < n; i++){
				if (! IsContainedIn (e1, & e2->e_args[i])){
					e2->e_mark2 = False;
					return False;
				}
			}
			e2->e_mark2 = False;
			return True;
		}
		default:
			return False;
	}
}

static int SortLtExp (Exp e1,Exp e2)
{
	ExpKind kind1, kind2;
	
	kind1 = e1->e_kind;
	kind2 = e2->e_kind;
	if (kind1 == kind2){
		if (kind1 == Value){
			if (e1->e_hnf)
				return -1;
			else if (e2->e_hnf)
				return -1;
			else
				return (e1->e_fun < e2->e_fun);
		} else
			return False; 
	} else
		return (kind1 < kind2);
}

#define LESS(a,b)	(SortLtExp ((a),(b)))

static void  Sort (Exp *defs, unsigned high)
{
	unsigned low,father, son;
	Exp val;

	low = high / 2;
	while (high > 1){
		val = defs[father = low];
		for (;;){
			son = 2 * father + 1;
			if (son >= high)
			{	defs[father] = val;
				break;
			};
			if (son == high - 1){
				if (LESS (val, defs[son])){
					defs[father] = defs[son];
					defs[son] = val;
				} else {
					defs[father] = val;
				};
				break;
			};
			if (LESS (defs[son], defs[son + 1]))
				son++;
			if (!LESS (val, defs[son])){
				defs[father] = val;
				break;
			};
			defs[father] = defs[son];
			father = son;
		};
		if (low > 0){
			low--;
		} else {
			val = defs[0];
			defs[0] = defs[--high];
			defs[high] = val;
		}
	}
}

static Bool ContainsExpOfKind (Exp e, ExpKind kind)
{
	unsigned i;
	Bool result = False;
	
	for (i = 0; i < e->e_sym; i++)
	{	if (e->e_args[i]->e_kind == kind)
			result = True;
		else if (kind == Dep && e->e_args[i]->e_kind == Bottom)
		{	e->e_kind = Bottom;
			e->e_hnf  = True;
1905
			e->e_deps = NULL;
clean's avatar
clean committed
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
			return False;
		}
		else if (kind == Lub && e->e_args[i]->e_kind == Top)
		{	e->e_kind = Top;
			e->e_hnf  = True;
			return False;
		}
	}
	
	return result;
}

static Bool IsInArgs (Exp *args, unsigned n, Exp e)
{
	unsigned i;
	
	for (i = 0; i < n; i++)
		if (args[i] == e)
			return True;
	
	return False;
}

static void RemoveExpOfKind (Exp e, ExpKind kind)
1930
{	unsigned	i, j, k, n, new_n;
clean's avatar
clean committed
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
	Exp			*new_args;
	
	/* count the new number of 'kind' args (the current args + the new ones) */
	n     = e->e_sym;
	new_n = 0;
	for (i = 0; i < n; i++)
	{	if (e->e_args[i]->e_kind == kind)
			new_n += e->e_args[i]->e_sym;
		else
			new_n += 1;
	}
	
	new_args = NewExpArgs (new_n);
	
1945
1946
1947
1948
1949
1950
	for (i = 0, j = 0; i < n; i++){
		if (e->e_args[i]->e_kind == kind){
			int kind_n = e->e_args[i]->e_sym;
			for (k = 0; k < kind_n; k++){
				if (! IsInArgs (new_args, j, e->e_args[i]->e_args[k])){
					new_args[j] = e->e_args[i]->e_args[k];
clean's avatar
clean committed
1951
1952
1953
					j++;
				}
			}
1954
1955
1956
1957
1958
		} else
			if (! IsInArgs (new_args, j, e->e_args[i])){
				new_args[j] = e->e_args[i];
				j++;
			}
clean's avatar
clean committed
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
	}
	
	/* put new arguments in original expression */
	e->e_args = new_args;
	e->e_sym  = j;

	/* remove remaining subkind expressions */
	if (ContainsExpOfKind (e, kind))
		RemoveExpOfKind (e, kind);
}

1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
#define IsTupleExp(A) ((A)->e_kind==Value && ((A)->e_fun>=tuplesym[0] && (A)->e_fun<=tuplesym[MaxNodeArity-1]))

/* JVG: added 16-8-2000 */
static void remove_deps_from_tuple_arguments (Exp e)
{
	if (e->e_deps==NULL)
		return;
	
	if (IsTupleExp(e)){
		int n,arity;

		arity=e->e_fun->fun_arity;
		for (n=0; n<arity; ++n){
			remove_deps_from_tuple_arguments (e->e_args[n]);
			e->e_args[n]->e_deps=NULL;
		}
	}
}
/**/

clean's avatar
clean committed
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
static void UpdateExp (Exp src, Exp dst);

static void RemoveCycles (ExpP ep, ExpKind kind)
{	unsigned i, n;
	Exp e = *ep;
	
	if (e->e_mark)
	{	*ep       = & bottom;
		e->e_mark = False;
		return;
	}
	
	e->e_mark = True;
	
	n = e->e_sym;
	for (i = 0; i < n; i++)
	{	if (e->e_args[i]->e_kind == kind)
			RemoveCycles (& e->e_args[i], kind);
	}
	
	e->e_mark = False;
} /* RemoveCycles */

static void SortExpOfKind (Exp e, ExpKind kind)
{	unsigned n, j, i;
	Bool remove;
	Exp e2 = e;		/* temp pointer: the pointer can be changed by RemoveCycles */
	
	Assume2 (e->e_kind == kind, "No exp of right kind", "SortExpOfKind");

	RemoveCycles (& e2, kind);

	if (ContainsExpOfKind (e, kind))
		RemoveExpOfKind (e, kind);
	
	if (e->e_kind != kind)
		return;

	n = e->e_sym;

	Sort (e->e_args, e->e_sym);
	
	if (kind == Dep)
	{	for (i = n; i > 0; i--)
			if (e->e_args[i-1]->e_kind != Top)
				break;
		
		n = i;
	}
	
2040
2041
2042
2043
2044
2045
2046
	for (i = 0; i+1 < n; ){
		if (LtExp (e->e_args[i], e->e_args[i+1]) == True){
			remove = True;
#if 1
			/* JVG: added 16-8-2000 */
			if (kind==Lub)
				remove_deps_from_tuple_arguments (e->e_args[i]);
2047
#endif
clean's avatar
clean committed
2048
			e->e_args[i] = e->e_args[i+1];
2049
2050
2051
2052
2053
		} else if (LtExp (e->e_args[i+1], e->e_args[i]) == True){
#if 1
			/* JVG: added 16-8-2000 */
			if (kind==Lub)
				remove_deps_from_tuple_arguments (e->e_args[i+1]);
2054
#endif
clean's avatar
clean committed
2055
			remove = True;
2056
		} else
clean's avatar
clean committed
2057
2058
			remove = False;
		
2059
2060
		if (remove){
			for (j = i+1; j+1 < n; j++)
clean's avatar
clean committed
2061
2062
				e->e_args[j] = e->e_args[j+1];
			n--;
2063
		} else
clean's avatar
clean committed
2064
2065
2066
2067
2068
			i++;
	}
	e->e_sym = n;

	if (n > 20)
2069
2070
	{
#ifdef _DB_
clean's avatar
clean committed
2071
2072
2073
2074
2075
		FPrintF (StdOut, "SortLub %d:", n);
		DumpExp (StdOut, e);
		FPutC ('\n', StdOut);
#endif /* _DB_ */
		e->e_kind = Top;
2076
		return;
clean's avatar
clean committed
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
	}
	
	if (n == 1 && kind == Lub)
		UpdateExp (e->e_args[0], e);
	else if (n == 0 && kind == Dep)
		e->e_kind = Top;
}

static void CopyDeps (Dependency fromdep,Dependency *newdeps)
{
	Dependency new;

2089
	for (;fromdep; fromdep = fromdep->dep_next){
clean's avatar
clean committed
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
		new = SAllocType (DependencyRepr);
		new->dep_exp     = fromdep->dep_exp;
		new->dep_next    = *newdeps;
		*newdeps         = new;
	}
}

static Dependency AddDeps (Dependency fromdep, Dependency taildeps)
{	Dependency new;

	for (;fromdep; fromdep = fromdep->dep_next)
2101
	{
clean's avatar
clean committed
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
		new = SAllocType (DependencyRepr);
		new->dep_exp     = fromdep->dep_exp;
		new->dep_next    = taildeps;
		taildeps         = new;
	}
	
	return taildeps;
} /* AddDeps */

static Dependency CombineDependencies (Dependency deps1, Dependency deps2)
{
	Dependency new;

	new = NULL;

	if (! deps1 || ! deps2)
		return NULL;

	CopyDeps (deps1,&new);
	CopyDeps (deps2,&new);
2122
/*
clean's avatar
clean committed
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
	for (; deps1; deps1 = deps1->dep_next)
	{	Dependency dep;
		Exp e;
		
		e = deps1->dep_exp;
		
		for (dep = deps2; dep; dep = dep->dep_next)
		{	if (e == dep->dep_exp)
			{	Dependency new2;
			
				new2 = SAllocType (DependencyRepr);
				new2->dep_exp     = e;
				new2->dep_next    = new;
				new = new2;
			}
		}
	}
2140
*/
clean's avatar
clean committed
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
	return new;
}

static Exp TakeLub (Exp e1, Exp e2)
{
	Exp new_e;
	unsigned n, i, j;
	Dependency newdeps;
	
	if (! e1 && ! e2)
		return & bottom;
	if (! e1 || e1->e_kind == Bottom)
		return e2;
	if (! e2 || e2->e_kind == Bottom)
		return e1;
	
	newdeps = CombineDependencies (e1->e_deps, e2->e_deps);
	
	/* create a new Lub expression and copy all the elements */
	if (e1->e_kind == Lub && e2->e_kind == Lub)
	{	new_e = NewExp (Lub, 0, True, e1->e_sym + e2->e_sym);
		j = 0;
		for (i = 0; i < e1->e_sym; i++)
		{	if (e1->e_args[i]->e_kind == Bottom)
				continue;
			else if (e1->e_args[i]->e_kind == Top)
				return NewTop();
			else
			{	new_e->e_args[j] = e1->e_args[i];
				j++;
			}
		}
		for (i = 0; i < e2->e_sym; i++)
		{	if (e2->e_args[i]->e_kind == Bottom)
				continue;
			else if (e2->e_args[i]->e_kind == Top)
				return NewTop();
			else
			{	new_e->e_args[j] = e2->e_args[i];
				j++;
			}
		}
		new_e->e_sym = j;
	}
	else if (e1->e_kind == Lub)
	{	n = e1->e_sym;
		new_e = NewExp (Lub, 0, True, n + 1);
		j = 0;
		for (i = 0; i < n; i++)
		{	if (e1->e_args[i]->e_kind == Bottom)
				continue;
			else if (e1->e_args[i]->e_kind == Top)
				return NewTop();
			else
			{	new_e->e_args[j] = e1->e_args[i];
				j++;
			}
		}
		new_e->e_args[j] = e2;
		new_e->e_sym     = j + 1;
	}
	else if (e2->e_kind == Lub)
	{	n = e2->e_sym;
		new_e = NewExp (Lub, 0, True, 1 + n);
		j = 0;
		for (i = 0; i < n; i++)
		{	if (e2->e_args[i]->e_kind == Bottom)
				continue;
			else if (e2->e_args[i]->e_kind == Top)
				return NewTop();
			else
			{	new_e->e_args[j] = e2->e_args[i];
				j++;
			}
		}
		new_e->e_args[j] = e1;
		new_e->e_sym     = j + 1;
	}
	else
	{	new_e = NewExp (Lub, 2, True, 2);
		new_e->e_args[0] = e1;
		new_e->e_args[1] = e2;
	}

	SortExpOfKind (new_e, Lub);
	new_e->e_deps = newdeps;
	return new_e;
}

static void UpdateExp (Exp src, Exp dst)
{	unsigned arity, i;

	if (src == dst)
		return;
	
	dst->e_kind    = src->e_kind;
	dst->e_hnf     = src->e_hnf;
	dst->e_spechnf = src->e_spechnf;
	dst->e_red     = False;
	
	switch (src->e_kind)
	{
	case Top:
		dst->e_sym = src->e_sym;
		arity = 0;
		break;
	case FunValue:
		dst->e_fun = src->e_fun;
		arity = 0;
		break;
	case Bottom:
		dst->e_sym = src->e_sym;
2253
2254
		dst->e_args = NULL;
		dst->e_deps = NULL;
clean's avatar
clean committed
2255
2256
		return;
	case Ind:
2257
2258
2259
#ifdef _DB_
		FPrintF (outfile, "Update with indirection %u %u\n", src->e_add,dst->e_add);
#endif
clean's avatar
clean committed
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
		dst->e_sym = src->e_sym;
		arity = 1;
		break;
	case Value:
		dst->e_fun = src->e_fun;
		arity = src->e_fun->fun_arity;
		break;
	case Lub:
	case Dep:
		dst->e_sym = src->e_sym;
		arity = src->e_sym;
		break;
	default:
		Assume (False, "unknown case", "UpdateExp");
		dst->e_sym = src->e_sym;
		arity = 0;
		break;