From 51a5fdfbd723dd1dd4f240565c0abe420ce98a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 2 Feb 2011 20:14:36 +0000 Subject: [PATCH 01/11] fix handling of SICStus style attributes (obs from Denys Duchier). --- C/attvar.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/C/attvar.c b/C/attvar.c index fb0249ce3..a27f4b925 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -569,6 +569,13 @@ p_put_atts(void) { } /* we may have a stack shift meanwhile!! */ tatts = Deref(ARG2); + if (IsVarTerm(tatts)) { + Yap_Error(INSTANTIATION_ERROR,tatts,"second argument of put_att/2"); + return FALSE; + } else if (!IsApplTerm(tatts)) { + Yap_Error(TYPE_ERROR_COMPOUND,tatts,"second argument of put_att/2"); + return FALSE; + } if (IsVarTerm(otatts = SearchAttsForModule(attv->Atts,mfun))) { AddNewModule(attv,tatts,new,FALSE); } else { From 8ab12ec680e07c1c763afbe58e64cac9daf220a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 2 Feb 2011 20:45:29 +0000 Subject: [PATCH 02/11] fix mix swi/sicstus --- library/atts.yap | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/atts.yap b/library/atts.yap index eccd31aa6..07e361e3f 100644 --- a/library/atts.yap +++ b/library/atts.yap @@ -49,8 +49,6 @@ new_attribute(Na/Ar) :- store_new_module(Mod,Ar,Position), assertz(existing_attribute(S,Mod,Ar,Position)). -existing_attribute(delay(_),prolog,1,2). - store_new_module(Mod,Ar,ArgPosition) :- ( retract(attributed_module(Mod,Position,_)) @@ -58,7 +56,7 @@ store_new_module(Mod,Ar,ArgPosition) :- true ; retract(modules_with_attributes(Mods)), - assert(modules_with_attributes([Mod|Mods])), Position = 1 + assert(modules_with_attributes([Mod|Mods])), Position = 2 ), ArgPosition is Position+1, ( Ar == 0 -> NOfAtts is Position+1 ; NOfAtts is Position+Ar), From 3efb549e0209332c1db812d5e283e58911f5fcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 2 Feb 2011 20:45:42 +0000 Subject: [PATCH 03/11] fix occur-check unification (obs from Jason Filippou). --- C/unify.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/C/unify.c b/C/unify.c index eb639ff69..4e4b7b81d 100644 --- a/C/unify.c +++ b/C/unify.c @@ -56,7 +56,7 @@ rtree_loop: } to_visit[0] = pt0; to_visit[1] = pt0_end; - to_visit[2] = (CELL *)d0; + to_visit[2] = (CELL *)*pt0; *pt0 = TermFoundVar; pt0_end = (pt0 = RepPair(d0) - 1) + 2; continue; @@ -78,7 +78,7 @@ rtree_loop: } to_visit[0] = pt0; to_visit[1] = pt0_end; - to_visit[2] = (CELL *)d0; + to_visit[2] = (CELL *)*pt0; *pt0 = TermFoundVar; d0 = ArityOfFunctor(f); pt0 = ap2; @@ -102,14 +102,13 @@ rtree_loop: cufail: /* we found an infinite term */ - while (to_visit < to_visit_max) { + while (to_visit < (CELL **)to_visit_base) { CELL *pt0; pt0 = to_visit[0]; *pt0 = (CELL)to_visit[2]; to_visit += 3; } return TRUE; - } static inline int From 7fd6faea64f23ebcb01a8142de8d0b90d96f4d2b Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 3 Feb 2011 17:20:42 +0100 Subject: [PATCH 04/11] flags: fixed an interval bug --- library/flags.yap | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/library/flags.yap b/library/flags.yap index 9e4b047e8..20d318bc1 100644 --- a/library/flags.yap +++ b/library/flags.yap @@ -10,8 +10,8 @@ % Contributions to this file: % Author: Theofrastos Mantadelis % Sugestions: Bernd Gutmann, Paulo Moura -% Version: 0.1 -% Date: 19/11/2010 +% $Date: 2011-02-03 17:19:26 +0100 (Thu, 03 Feb 2011) $ +% $Revision: 9 $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -337,26 +337,30 @@ in_interval_conj(Type, [Interval|Rest]):- in_interval_conj(Type, Rest). in_interval_single(Type, ([Min], [Max])):- - !, call(Type, Min), + !, call(Type, Min), call(Type, Max), Min =< Max. in_interval_single(Type, ([Min], Max)):- - !, call(Type, Min), - call(Type, Max), + !, call(Type, Min), + type_or_inf(Type, Max), Min < Max. in_interval_single(Type, (Min, [Max])):- - !, call(Type, Min), + !, type_or_inf(Type, Min), call(Type, Max), Min < Max. in_interval_single(Type, (Min, Max)):- - call(Type, Min), - call(Type, Max), + type_or_inf(Type, Min), + type_or_inf(Type, Max), Min < Max, Max - Min > 0.0. +type_or_inf(_Type, (+inf)):- !. +type_or_inf(_Type, (-inf)):- !. +type_or_inf(Type, Value):- call(Type, Value). + in_interval(Type, [Interval|_Rest], Value):- in_interval(Type, Interval, Value), !. in_interval(Type, [_Interval|Rest], Value):- From 9bdc7ca96e16c893ac3c134e41c83df675baeb85 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 4 Feb 2011 01:23:01 +0000 Subject: [PATCH 05/11] get rid of references to freed code. --- C/cdmgr.c | 8 ++------ H/clause.h | 1 - H/rheap.h | 3 +++ packages/jpl | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/C/cdmgr.c b/C/cdmgr.c index 33f063da4..aa58da3ff 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1258,6 +1258,8 @@ cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code case _switch_on_cons: case _if_cons: case _go_on_cons: + /* make sure we don't leave dangling references to memory that is going to be removed */ + ipc->u.sssl.l = NULL; ipc = NEXTOP(ipc,sssl); break; case _op_fail: @@ -1272,12 +1274,6 @@ cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code } } -void -Yap_cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *sc) -{ - cleanup_dangling_indices(ipc, beg, end, sc); -} - static void decrease_log_indices(LogUpdIndex *c, yamop *suspend_code) { diff --git a/H/clause.h b/H/clause.h index 484c4332d..09a7aa5aa 100644 --- a/H/clause.h +++ b/H/clause.h @@ -205,7 +205,6 @@ void STD_PROTO(Yap_IPred,(PredEntry *, UInt, yamop *)); int STD_PROTO(Yap_addclause,(Term,yamop *,int,Term,Term*)); void STD_PROTO(Yap_add_logupd_clause,(PredEntry *,LogUpdClause *,int)); void STD_PROTO(Yap_kill_iblock,(ClauseUnion *,ClauseUnion *,PredEntry *)); -void STD_PROTO(Yap_cleanup_dangling_indices,(yamop *,yamop *,yamop *,yamop *)); void STD_PROTO(Yap_EraseStaticClause,(StaticClause *, Term)); ClauseUnion *STD_PROTO(Yap_find_owner_index,(yamop *, PredEntry *)); diff --git a/H/rheap.h b/H/rheap.h index e69a712c0..deb009324 100755 --- a/H/rheap.h +++ b/H/rheap.h @@ -284,6 +284,9 @@ static void AdjustSwitchTable(op_numbers op, yamop *table, COUNT i) { CELL *startcode = (CELL *)table; + /* in case the table is already gone */ + if (!table) + return; switch (op) { case _switch_on_func: { diff --git a/packages/jpl b/packages/jpl index 73e4e086d..29151b2fe 160000 --- a/packages/jpl +++ b/packages/jpl @@ -1 +1 @@ -Subproject commit 73e4e086d06c54210100f0faaeccbea276c707eb +Subproject commit 29151b2fe68f2dc727cdc07040e1fa1ad4fcca20 From 94bdda200fba96b6eb950617ef35f54f5698dfa5 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 4 Feb 2011 01:41:01 +0000 Subject: [PATCH 06/11] make sure we have NULL pointers --- H/sshift.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/H/sshift.h b/H/sshift.h index 6ac683f0a..9263b366c 100755 --- a/H/sshift.h +++ b/H/sshift.h @@ -659,7 +659,8 @@ inline EXTERN yamop *PtoOpAdjust (yamop *); inline EXTERN yamop * PtoOpAdjust (yamop * ptr) { - return (yamop *) (CharP (ptr) + HDiff); + if (ptr) + return (yamop *) (CharP (ptr) + HDiff); } inline EXTERN struct operator_entry *OpListAdjust (struct operator_entry *); From c95134e94d00ea0722be27c8fab79d6a5b248407 Mon Sep 17 00:00:00 2001 From: Paulo Moura Date: Fri, 4 Feb 2011 12:38:05 +0000 Subject: [PATCH 07/11] Fixed a bug in the implementation of between/3. Reported by Bernd Gutmann. --- pl/arith.yap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl/arith.yap b/pl/arith.yap index 033e45599..b8708cf05 100644 --- a/pl/arith.yap +++ b/pl/arith.yap @@ -293,7 +293,7 @@ between(I,M,J) :- ( var(J) -> - '$between'(I,M,J) + I =< M, '$between'(I,M,J) ; integer(J) -> From b57859f28b8f6f13c1566bd61e9fd28939ecc2ed Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Fri, 4 Feb 2011 16:08:18 +0100 Subject: [PATCH 08/11] fixed some typos --- library/c_alarms.yap | 6 +++--- library/flags.yap | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/library/c_alarms.yap b/library/c_alarms.yap index e238f1dae..b1b33ba30 100644 --- a/library/c_alarms.yap +++ b/library/c_alarms.yap @@ -9,8 +9,8 @@ % % Contributions to this file: % Author: Theofrastos Mantadelis -% $Date: 2011-02-01 18:36:41 +0100 (Tue, 01 Feb 2011) $ -% $Revision: 7 $ +% $Date: 2011-02-04 16:04:49 +0100 (Fri, 04 Feb 2011) $ +% $Revision: 11 $ % Contributions: The timer implementation is inspired by Bernd Gutmann's timers % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -394,4 +394,4 @@ timer_pause(Name, Elapsed):- retract('$timer'(Name, _, StartTime)), statistics(walltime, [EndTime, _]), Elapsed is EndTime - StartTime, - assert('$timer'(Name, paused, Elapsed)). + assertz('$timer'(Name, paused, Elapsed)). diff --git a/library/flags.yap b/library/flags.yap index 20d318bc1..f2a825623 100644 --- a/library/flags.yap +++ b/library/flags.yap @@ -10,8 +10,8 @@ % Contributions to this file: % Author: Theofrastos Mantadelis % Sugestions: Bernd Gutmann, Paulo Moura -% $Date: 2011-02-03 17:19:26 +0100 (Thu, 03 Feb 2011) $ -% $Revision: 9 $ +% $Date: 2011-02-04 16:06:56 +0100 (Fri, 04 Feb 2011) $ +% $Revision: 12 $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -357,8 +357,12 @@ in_interval_single(Type, (Min, Max)):- Min < Max, Max - Min > 0.0. -type_or_inf(_Type, (+inf)):- !. -type_or_inf(_Type, (-inf)):- !. +type_or_inf(Type, Value):- + nonvar(Type), nonvar(Value), + Value == (+inf), !. +type_or_inf(Type, Value):- + nonvar(Type), nonvar(Value), + Value == (-inf), !. type_or_inf(Type, Value):- call(Type, Value). in_interval(Type, [Interval|_Rest], Value):- From 398d46fc4e014c8677eb0a2544f5f63902a793f4 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 5 Feb 2011 10:27:51 +0000 Subject: [PATCH 09/11] fix occur_check patch. --- C/unify.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/C/unify.c b/C/unify.c index 4e4b7b81d..fa202e011 100644 --- a/C/unify.c +++ b/C/unify.c @@ -36,6 +36,7 @@ int Yap_rational_tree_loop(CELL *pt0, CELL *pt0_end, CELL **to_visit, CELL **to_visit_max) { + CELL ** base = to_visit; rtree_loop: while (pt0 < pt0_end) { register CELL *ptd0; @@ -91,7 +92,7 @@ rtree_loop: derefa_body(d0, ptd0, rtree_loop_unk, rtree_loop_nvar); } /* Do we still have compound terms to visit */ - if (to_visit < (CELL **)to_visit_base) { + if (to_visit < base) { pt0 = to_visit[0]; pt0_end = to_visit[1]; *pt0 = (CELL)to_visit[2]; @@ -102,7 +103,7 @@ rtree_loop: cufail: /* we found an infinite term */ - while (to_visit < (CELL **)to_visit_base) { + while (to_visit < (CELL **)base) { CELL *pt0; pt0 = to_visit[0]; *pt0 = (CELL)to_visit[2]; From 89789e82326d423277c55889a5252180890db8da Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Tue, 8 Feb 2011 15:57:23 +0100 Subject: [PATCH 10/11] corrected an import bug --- packages/ProbLog/problog/flags.yap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ProbLog/problog/flags.yap b/packages/ProbLog/problog/flags.yap index 54a77fb93..438a8ca07 100644 --- a/packages/ProbLog/problog/flags.yap +++ b/packages/ProbLog/problog/flags.yap @@ -213,10 +213,10 @@ reset_problog_flags/0, problog_flag/2]). - :- use_module(gflags). :- use_module(os). :- use_module(logger). +:- use_module(library(system), [file_exists/1, delete_file/1]). problog_define_flag(Flag, Type, Description, DefaultValue):- flag_define(Flag, Type, DefaultValue, Description). From d0a5571900a48831198f618d35b375f89938632a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Tue, 8 Feb 2011 21:02:10 +0000 Subject: [PATCH 11/11] trace the total number of choice-points created in profiling mode. --- C/tracer.c | 12 ++++++++++++ H/absmi.h | 8 ++++++++ H/dglobals.h | 3 +++ H/hglobals.h | 3 +++ H/iglobals.h | 3 +++ H/rglobals.h | 3 +++ misc/GLOBALS | 4 ++++ 7 files changed, 36 insertions(+) diff --git a/C/tracer.c b/C/tracer.c index fe1004cce..7f7fbc012 100755 --- a/C/tracer.c +++ b/C/tracer.c @@ -372,6 +372,16 @@ static Int p_start_low_level_trace(void) return(TRUE); } +static Int p_total_choicepoints(void) +{ + return Yap_unify(MkIntegerTerm(Yap_total_choicepoints),ARG1); +} + +static Int p_reset_total_choicepoints(void) +{ + Yap_total_choicepoints = 0; +} + static Int p_show_low_level_trace(void) { fprintf(stderr,"Call counter=%lld\n",vsc_count); @@ -414,6 +424,8 @@ Yap_InitLowLevelTrace(void) #endif Yap_InitCPred("stop_low_level_trace", 0, p_stop_low_level_trace, SafePredFlag); Yap_InitCPred("show_low_level_trace", 0, p_show_low_level_trace, SafePredFlag); + Yap_InitCPred("total_choicepoints", 1, p_total_choicepoints, SafePredFlag); + Yap_InitCPred("reset_total_choicepoints", 0, p_reset_total_choicepoints, SafePredFlag); Yap_InitCPred("vsc_wait", 0, p_vsc_wait, SafePredFlag); } diff --git a/H/absmi.h b/H/absmi.h index 5427f460c..2310c6acb 100644 --- a/H/absmi.h +++ b/H/absmi.h @@ -731,6 +731,12 @@ Macros to check the limits of stacks while ( pt0 > XREGS ); \ ENDP(pt0) +#if LOW_LEVEL_TRACER +#define COUNT_CPS() Yap_total_choicepoints++ +#else +#define COUNT_CPS() +#endif + /*************************************************************** * Do the bulk of work in creating a choice-point * * AP: alternative pointer * @@ -747,6 +753,7 @@ Macros to check the limits of stacks #define store_yaam_regs(AP,I) \ { /* Jump to CP_BASE */ \ + COUNT_CPS(); \ S_YREG = (CELL *)((choiceptr)((S_YREG)-(I))-1); \ /* Save Information */ \ HBREG = H; \ @@ -760,6 +767,7 @@ Macros to check the limits of stacks } #define store_yaam_regs_for_either(AP,d0) \ + COUNT_CPS(); \ pt1 --; /* Jump to CP_BASE */ \ /* Save Information */ \ HBREG = H; \ diff --git a/H/dglobals.h b/H/dglobals.h index 17c514015..3e9b1de60 100644 --- a/H/dglobals.h +++ b/H/dglobals.h @@ -95,6 +95,9 @@ #define TotGcRecovered WL->tot_gc_recovered #define LastGcTime WL->last_gc_time #define LastSSTime WL->last_ss_time +#if LOW_LEVEL_TRACER +#define Yap_total_choicepoints WL->total_cps +#endif #if defined(YAPOR) || defined(THREADS) #define SignalLock WL->signal_lock diff --git a/H/hglobals.h b/H/hglobals.h index 87719458c..302f7ca9a 100644 --- a/H/hglobals.h +++ b/H/hglobals.h @@ -97,6 +97,9 @@ typedef struct worker_local { YAP_ULONG_LONG tot_gc_recovered; Int last_gc_time; Int last_ss_time; +#if LOW_LEVEL_TRACER + Int total_cps; +#endif #if defined(YAPOR) || defined(THREADS) lockvar signal_lock; diff --git a/H/iglobals.h b/H/iglobals.h index 4c6012a7e..1274d32fa 100644 --- a/H/iglobals.h +++ b/H/iglobals.h @@ -95,6 +95,9 @@ static void InitWorker(int wid) { FOREIGN_WL(wid)->tot_gc_recovered = 0L; FOREIGN_WL(wid)->last_gc_time = 0L; FOREIGN_WL(wid)->last_ss_time = 0L; +#if LOW_LEVEL_TRACER + FOREIGN_WL(wid)->total_cps = 0; +#endif #if defined(YAPOR) || defined(THREADS) INIT_LOCK(FOREIGN_WL(wid)->signal_lock); diff --git a/H/rglobals.h b/H/rglobals.h index 7aaa8d045..0eb573aa3 100644 --- a/H/rglobals.h +++ b/H/rglobals.h @@ -95,6 +95,9 @@ static void RestoreWorker(int wid) { +#if LOW_LEVEL_TRACER + +#endif #if defined(YAPOR) || defined(THREADS) REINIT_LOCK(FOREIGN_WL(wid)->signal_lock); diff --git a/misc/GLOBALS b/misc/GLOBALS index 1dcda6810..82bff09e1 100644 --- a/misc/GLOBALS +++ b/misc/GLOBALS @@ -104,6 +104,10 @@ YAP_ULONG_LONG tot_gc_recovered TotGcRecovered =0L Int last_gc_time LastGcTime =0L Int last_ss_time LastSSTime =0L +#if LOW_LEVEL_TRACER +Int total_cps Yap_total_choicepoints =0 +#endif + // global variables that cannot be global in a thread/or-p implementation #if defined(YAPOR) || defined(THREADS) lockvar signal_lock SignalLock MkLock