~ubuntu-branches/ubuntu/gutsy/acl2/gutsy

« back to all changes in this revision

Viewing changes to other-events.lisp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-12-04 10:35:42 UTC
  • mfrom: (1.1.5 upstream) (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20061204103542-68nf4pkilci0018n
Tags: 3.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
; ACL2 Version 3.0.1 -- A Computational Logic for Applicative Common Lisp
 
1
; ACL2 Version 3.1 -- A Computational Logic for Applicative Common Lisp
2
2
; Copyright (C) 2006  University of Texas at Austin
3
3
 
4
4
; This version of ACL2 is a descendent of ACL2 Version 1.9, Copyright
596
596
                event-form ctx wrld1
597
597
                (er-let*
598
598
                 ((wrld2 (chk-just-new-name name 'macro nil ctx wrld1 state))
599
 
                  (ignored (value (get-declared-ignored-variables edcls)))
 
599
                  (ignored (value (ignore-vars edcls)))
 
600
                  (ignorables (value (ignorable-vars edcls)))
600
601
                  (doc-pair (translate-doc name doc ctx state)))
601
602
                 (er-progn
602
603
                  (chk-xargs-keywords1 edcls '(:guard) ctx state)
603
604
                  (chk-free-and-ignored-vars name (macro-vars args) tguard *0*
604
 
                                             ignored tbody ctx state)
 
605
                                             ignored ignorables tbody ctx
 
606
                                             state)
605
607
                  (er-let*
606
608
                   ((wrld3 (defmacro-fn1 name args doc doc-pair
607
609
                             tguard tbody wrld2 state)))
698
700
            'state
699
701
            (list 'quote event-form)))
700
702
    (defmacro defthm (&whole event-form
701
 
                      name term
702
 
                      &key (rule-classes '(:REWRITE))
703
 
                      instructions
704
 
                      hints
705
 
                      otf-flg
706
 
                      doc)
 
703
                             name term
 
704
                             &key (rule-classes '(:REWRITE))
 
705
                             instructions
 
706
                             hints
 
707
                             otf-flg
 
708
                             doc)
707
709
      (list 'defthm-fn
708
710
            (list 'quote name)
709
711
            (list 'quote term)
717
719
            #+:non-standard-analysis ; std-p
718
720
            nil))
719
721
    (defmacro defaxiom (&whole event-form
720
 
                        name term
721
 
                             &key (rule-classes '(:REWRITE))
722
 
                             doc)
 
722
                               name term
 
723
                               &key (rule-classes '(:REWRITE))
 
724
                               doc)
723
725
      (list 'defaxiom-fn
724
726
            (list 'quote name)
725
727
            (list 'quote term)
758
760
            'state
759
761
            (list 'quote doc)
760
762
            (list 'quote event-form)))
761
 
    (defmacro push-untouchable (&whole event-form name &key doc)
 
763
    (defmacro push-untouchable (&whole event-form name fn-p &key doc)
762
764
      (list 'push-untouchable-fn
763
765
            (list 'quote name)
764
766
            (list 'quote fn-p)
765
767
            'state
766
768
            (list 'quote doc)
767
769
            (list 'quote event-form)))
 
770
    (defmacro reset-prehistory (&whole event-form &optional permanent-p doc)
 
771
      (list 'reset-prehistory-fn
 
772
            (list 'quote permanent-p)
 
773
            'state
 
774
            (list 'quote doc)
 
775
            (list 'quote event-form)))
768
776
    (defmacro set-body (&whole event-form fn name-or-rune)
769
777
      (list 'set-body-fn
770
778
            (list 'quote fn)
793
801
                                   (uncertified-okp 't)
794
802
                                   (defaxioms-okp 't)
795
803
                                   (skip-proofs-okp 't)
 
804
                                   (ttags nil)
796
805
                                   dir
797
806
                                   doc)
798
807
      (list 'include-book-fn
803
812
            (list 'quote uncertified-okp)
804
813
            (list 'quote defaxioms-okp)
805
814
            (list 'quote skip-proofs-okp)
 
815
            (list 'quote ttags)
806
816
            (list 'quote doc)
807
817
            (list 'quote dir)
808
818
            (list 'quote event-form)))
816
826
                  (list 'state-global-let*
817
827
                        '((in-local-flg t))
818
828
                        (list 'when-logic "LOCAL" x)))))
819
 
))
 
829
    ))
820
830
 
821
831
; Because of the Important Boot-Strapping Invariant noted in axioms.lisp,
822
832
; we can compute from this list the following things for each event:
1137
1147
                  '((event-index nil)
1138
1148
                    (command-index nil)
1139
1149
                    (event-number-baseline 0)
1140
 
                    (command-number-baseline 0)
 
1150
                    (command-number-baseline-info
 
1151
                     (make command-number-baseline-info
 
1152
                           :current 0
 
1153
                           :permanent-p t
 
1154
                           :original 0))
1141
1155
                    (embedded-event-lst nil)
1142
1156
                    (cltl-command nil)
1143
1157
                    (include-book-alist nil)
1154
1168
                    (boot-strap-flg t)
1155
1169
                    (boot-strap-pass-2 nil)
1156
1170
                    (skip-proofs-seen nil)
 
1171
                    (redef-seen nil)
1157
1172
                    (free-var-runes-all nil)
1158
1173
                    (free-var-runes-once nil)
1159
1174
                    (chk-new-name-lst
1163
1178
                         defstobj defthm defaxiom progn encapsulate include-book 
1164
1179
                         deflabel defdoc deftheory
1165
1180
                         in-theory in-arithmetic-theory
1166
 
                         push-untouchable set-body table verify-guards
1167
 
                         verify-termination
 
1181
                         push-untouchable remove-untouchable set-body table
 
1182
                         reset-prehistory verify-guards verify-termination
1168
1183
                         local defchoose ld-skip-proofsp
1169
1184
                         in-package-fn defpkg-fn defun-fn defuns-fn
1170
1185
                         mutual-recursion-fn defmacro-fn defconst-fn
1172
1187
                         defthm-fn defaxiom-fn progn-fn encapsulate-fn
1173
1188
                         include-book-fn deflabel-fn defdoc-fn
1174
1189
                         deftheory-fn in-theory-fn in-arithmetic-theory-fn
1175
 
                         push-untouchable-fn set-body-fn table-fn
1176
 
                         verify-guards-fn verify-termination-fn defchoose-fn
1177
 
                         apply o-p o< default-defun-mode-from-state
1178
 
                         skip-when-logic
 
1190
                         push-untouchable-fn remove-untouchable-fn
 
1191
                         reset-prehistory-fn set-body-fn
 
1192
                         table-fn verify-guards-fn verify-termination-fn
 
1193
                         defchoose-fn apply o-p o<
 
1194
                         default-defun-mode-from-state skip-when-logic
1179
1195
 
1180
1196
; The following names are here simply so we can deflabel them for
1181
1197
; documentation purposes:
1187
1203
                         complex complex-rationalp
1188
1204
 
1189
1205
                         ))
 
1206
                    (ttags-seen nil)
1190
1207
                    (untouchable-fns nil)
1191
1208
                    (untouchable-vars nil))))
1192
1209
             (list* `(operating-system ,operating-system)
1572
1589
                   ((member-symbol-name *pkg-witness-name* imports)
1573
1590
                    (er soft ctx
1574
1591
                        "It is illegal to import symbol ~x0 because its name ~
1575
 
                         has been reserved to refer to a symbol whose ~
1576
 
                         package-name in the new package."
 
1592
                         has been reserved for a symbol in the package being ~
 
1593
                         defined."
1577
1594
                        (car (member-symbol-name *pkg-witness-name* imports))))
1578
1595
                   (conflict
1579
1596
                    (er soft ctx
1864
1881
    (intersection-augmented-theories-fn1 (cdr lst1) lst2 ans))
1865
1882
   (t (intersection-augmented-theories-fn1 lst1 (cdr lst2) ans))))
1866
1883
 
 
1884
(defmacro check-theory (lst wrld ctx form)
 
1885
  `(cond ((theoryp! ,lst ,wrld)
 
1886
          ,form)
 
1887
         (t (er hard ,ctx
 
1888
                "A theory function has been called on an argument that does ~
 
1889
                 not represent a theory.  See the **NOTE**s above and see ~
 
1890
                 :DOC theories."))))
 
1891
 
1867
1892
(defun intersection-theories-fn (lst1 lst2 wrld)
1868
 
  (assert$
1869
 
   (and (theoryp! lst1 wrld)
1870
 
        (theoryp! lst2 wrld))
1871
 
   (intersection-augmented-theories-fn1 (augment-theory lst1 wrld)
1872
 
                                        (augment-theory lst2 wrld)
1873
 
                                        nil)))
 
1893
  (check-theory
 
1894
   lst1 wrld 'intersection-theories-fn
 
1895
   (check-theory
 
1896
    lst2 wrld 'intersection-theories-fn
 
1897
    (intersection-augmented-theories-fn1 (augment-theory lst1 wrld)
 
1898
                                         (augment-theory lst2 wrld)
 
1899
                                         nil))))
1874
1900
 
1875
1901
(defmacro intersection-theories (lst1 lst2)
1876
1902
 
1955
1981
  (cond
1956
1982
   ((or lst1-known-to-be-runic
1957
1983
        (runic-theoryp lst1 wrld))
1958
 
    (assert$ (theoryp! lst2 wrld)
1959
 
             (union-theories-fn1 lst1
1960
 
                                 (augment-theory lst2 wrld)
1961
 
                                 nil
1962
 
                                 wrld
1963
 
                                 nil)))
 
1984
    (check-theory lst2 wrld 'union-theories-fn
 
1985
                  (union-theories-fn1 lst1
 
1986
                                      (augment-theory lst2 wrld)
 
1987
                                      nil
 
1988
                                      wrld
 
1989
                                      nil)))
1964
1990
   ((runic-theoryp lst2 wrld)
1965
 
    (assert$ (theoryp! lst1 wrld)
1966
 
             (union-theories-fn1 lst2
1967
 
                                 (augment-theory lst1 wrld)
1968
 
                                 nil
1969
 
                                 wrld
1970
 
                                 nil)))
 
1991
    (check-theory lst1 wrld 'union-theories-fn
 
1992
                  (union-theories-fn1 lst2
 
1993
                                      (augment-theory lst1 wrld)
 
1994
                                      nil
 
1995
                                      wrld
 
1996
                                      nil)))
1971
1997
   (t
1972
 
    (assert$ (let ((x (theoryp! lst1 wrld))
1973
 
                   (y (theoryp! lst2 wrld)))
1974
 
               (and x y))
1975
 
             (union-augmented-theories-fn1
 
1998
    (check-theory
 
1999
     lst1 wrld 'union-theories-fn
 
2000
     (check-theory
 
2001
      lst2 wrld 'union-theories-fn
 
2002
      (union-augmented-theories-fn1
1976
2003
 
1977
2004
; We know that lst1 is not a runic-theoryp, so we open-code for a call of
1978
2005
; augment-theory, which should be kept in sync with the code below.
1979
2006
 
1980
 
              (duplicitous-sort-car
1981
 
               nil
1982
 
               (convert-theory-to-unordered-mapping-pairs lst1 wrld))
1983
 
              (augment-theory lst2 wrld)
1984
 
              nil)))))
 
2007
       (duplicitous-sort-car
 
2008
        nil
 
2009
        (convert-theory-to-unordered-mapping-pairs lst1 wrld))
 
2010
       (augment-theory lst2 wrld)
 
2011
       nil))))))
1985
2012
 
1986
2013
(defmacro union-theories (lst1 lst2)
1987
2014
 
2077
2104
  (cond
2078
2105
   ((or lst1-known-to-be-runic
2079
2106
        (runic-theoryp lst1 wrld))
2080
 
    (assert$ (theoryp! lst2 wrld)
2081
 
             (set-difference-theories-fn1 lst1
2082
 
                                          (augment-theory lst2 wrld)
2083
 
                                          nil
2084
 
                                          wrld
2085
 
                                          nil)))
 
2107
    (check-theory lst2 wrld 'set-difference-theories-fn
 
2108
                  (set-difference-theories-fn1 lst1
 
2109
                                               (augment-theory lst2 wrld)
 
2110
                                               nil
 
2111
                                               wrld
 
2112
                                               nil)))
2086
2113
   (t
2087
 
    (assert$ (let ((x (theoryp! lst1 wrld))
2088
 
                   (y (theoryp! lst2 wrld)))
2089
 
               (and x y))
2090
 
             (set-difference-augmented-theories-fn1
 
2114
    (check-theory
 
2115
     lst1 wrld 'set-difference-theories-fn
 
2116
     (check-theory
 
2117
      lst2 wrld 'set-difference-theories-fn
 
2118
      (set-difference-augmented-theories-fn1
2091
2119
 
2092
2120
; We know that lst1 is not a runic-theoryp, so we open-code for a call of
2093
2121
; augment-theory, which should be kept in sync with the code below.
2094
2122
 
2095
 
              (duplicitous-sort-car
2096
 
               nil
2097
 
               (convert-theory-to-unordered-mapping-pairs lst1 wrld))
2098
 
              (augment-theory lst2 wrld)
2099
 
              nil)))))
 
2123
       (duplicitous-sort-car
 
2124
        nil
 
2125
        (convert-theory-to-unordered-mapping-pairs lst1 wrld))
 
2126
       (augment-theory lst2 wrld)
 
2127
       nil))))))
2100
2128
 
2101
2129
(defmacro set-difference-theories (lst1 lst2)
2102
2130
 
2621
2649
                             (standard-theories wrld))
2622
2650
                       (list 'boot-strap-flg nil)
2623
2651
                       (list 'boot-strap-pass-2 nil)
2624
 
                       (list 'command-number-baseline
2625
 
                             (next-absolute-command-number wrld))
 
2652
                       (list 'command-number-baseline-info
 
2653
                             (let ((command-number-baseline
 
2654
                                    (next-absolute-command-number wrld)))
 
2655
                               (make command-number-baseline-info
 
2656
                                     :current command-number-baseline
 
2657
                                     :permanent-p t
 
2658
                                     :original command-number-baseline)))
2626
2659
                       (list 'event-number-baseline
2627
2660
                             (next-absolute-event-number wrld))
2628
 
                       (list 'skip-proofs-seen nil))
 
2661
                       (list 'skip-proofs-seen nil)
 
2662
                       (list 'redef-seen nil))
2629
2663
                 (putprop 'acl2-defaults-table
2630
2664
                          'table-alist
2631
2665
                          *initial-acl2-defaults-table*
2797
2831
                                 name
2798
2832
                                 nil
2799
2833
                                 nil
2800
 
                                 nil ; handles its own invariants check
 
2834
                                 nil ; global theory is unchanged
2801
2835
                                 nil
2802
2836
                                 wrld2 state)))))))))
2803
2837
 
2840
2874
; Note:  We do not permit IN-THEORY to be made redundant.  If this
2841
2875
; is changed, change the text of the :doc for redundant-events.
2842
2876
 
2843
 
         (mv-let (erp val state)
2844
 
                 (install-event (length theory0)
 
2877
         (er-let*
 
2878
          ((val (install-event (length theory0)
2845
2879
                                event-form
2846
2880
                                'in-theory
2847
2881
                                0
2848
2882
                                nil
2849
2883
                                nil
2850
 
                                nil ; handles its own invariants check
 
2884
                                :protect
2851
2885
                                nil
2852
 
                                wrld1 state)
2853
 
                 (assert$
2854
 
                  (null erp)
2855
 
                  (pprogn (if (member-equal
2856
 
                               expr
2857
 
                               '((enable (:EXECUTABLE-COUNTERPART
2858
 
                                          force))
2859
 
                                 (disable (:EXECUTABLE-COUNTERPART
2860
 
                                           force))
2861
 
                                 (enable (:EXECUTABLE-COUNTERPART
2862
 
                                          immediate-force-modep))
2863
 
                                 (disable (:EXECUTABLE-COUNTERPART
2864
 
                                           immediate-force-modep))))
2865
 
                              state
2866
 
                            (maybe-warn-about-theory
2867
 
                             ens1 force-xnume-en1 imm-xnume-en1
2868
 
                             (ens state) ctx wrld state))
2869
 
                          (value val))))))))))
 
2886
                                wrld1 state)))
 
2887
          (pprogn (if (member-equal
 
2888
                       expr
 
2889
                       '((enable (:EXECUTABLE-COUNTERPART
 
2890
                                  force))
 
2891
                         (disable (:EXECUTABLE-COUNTERPART
 
2892
                                   force))
 
2893
                         (enable (:EXECUTABLE-COUNTERPART
 
2894
                                  immediate-force-modep))
 
2895
                         (disable (:EXECUTABLE-COUNTERPART
 
2896
                                   immediate-force-modep))))
 
2897
                      state
 
2898
                    (maybe-warn-about-theory
 
2899
                     ens1 force-xnume-en1 imm-xnume-en1
 
2900
                     (ens state) ctx wrld state))
 
2901
                  (value val)))))))))
2870
2902
 
2871
2903
(defun in-arithmetic-theory-fn (expr state doc event-form)
2872
2904
 
2906
2938
       (t
2907
2939
        (er-let*
2908
2940
          ((doc-pair (translate-doc nil doc ctx state))
2909
 
           (theory (translate-in-theory-hint expr t ctx wrld state)))
2910
 
          (let* ((ens1 (global-val 'global-arithmetic-enabled-structure wrld))
2911
 
                 (ens2 (load-theory-into-enabled-structure theory nil ens1 nil
2912
 
                                                           nil wrld))
2913
 
                 (wrld1 (global-set 'global-arithmetic-enabled-structure ens2 wrld)))
 
2941
           (theory (translate-in-theory-hint expr t ctx wrld state))
 
2942
           (ens (load-theory-into-enabled-structure
 
2943
                 expr theory nil
 
2944
                 (global-val 'global-arithmetic-enabled-structure wrld)
 
2945
                 nil nil wrld ctx state)))
 
2946
          (let ((wrld1 (global-set 'global-arithmetic-enabled-structure ens
 
2947
                                   wrld)))
2914
2948
 
2915
2949
; Note:  We do not permit IN-THEORY to be made redundant.  If this
2916
2950
; is changed, change the text of the :doc for redundant-events.
3004
3038
 
3005
3039
(table theory-invariant-table nil nil
3006
3040
       :guard (and (consp val)
3007
 
                   (termp (car val) world)
3008
 
                   (booleanp (cdr val))
3009
 
                   (subsetp-eq (all-vars (car val)) '(theory state))))
 
3041
                   (consp (cdr val))
 
3042
                   (let ((tterm (access theory-invariant-record val
 
3043
                                        :tterm)))
 
3044
                     (and (termp tterm world)
 
3045
                          (booleanp (access theory-invariant-record val
 
3046
                                            :error))
 
3047
                          (subsetp-eq (all-vars tterm) '(ens state))))))
3010
3048
 
3011
3049
(defmacro theory-invariant (&whole event-form term &key key (error 't))
3012
3050
 
3014
3052
 
3015
3053
  user-specified invariants on ~il[theories]~/
3016
3054
  ~bv[]
3017
 
  Example:
3018
 
  (theory-invariant (not (and (member-equal '(:rewrite left-to-right)
3019
 
                                             theory)
3020
 
                              (member-equal '(:rewrite right-to-left)
3021
 
                                            theory)))
 
3055
  Examples:
 
3056
  (theory-invariant (not (and (active-runep '(:rewrite left-to-right))
 
3057
                              (active-runep '(:rewrite right-to-left))))
 
3058
                    :key my-invariant
 
3059
                    :error nil)
 
3060
 
 
3061
  ; Equivalent to the above:
 
3062
  (theory-invariant (incompatible '(:rewrite left-to-right)
 
3063
                                  '(:rewrite right-to-left))
3022
3064
                    :key my-invariant
3023
3065
                    :error nil)~/
3024
3066
 
3027
3069
  ~ev[]
3028
3070
  where:~bq[]
3029
3071
 
3030
 
  o ~c[term] is a term that uses no variables other than ~ilc[theory] and
3031
 
  ~ilc[world];
 
3072
  o ~c[term] is a term that uses no variables other than ~c[ens] and
 
3073
  ~ilc[state];
3032
3074
 
3033
3075
  o ~c[key] is an arbitrary ``name'' for this invariant (if omitted, an integer
3034
3076
  is generated and used); and
3050
3092
  theory invariant by setting the invariant to ~c[t], or eliminate all theory
3051
3093
  invariants with the command ~c[(table theory-invariant-table nil nil :clear)].
3052
3094
 
3053
 
  ~c[Theory-invariant-table] maps arbitrary keys to terms mentioning, at
3054
 
  most, the variables ~ilc[theory] and ~ilc[world].  Every time an alleged theory
3055
 
  expression is evaluated, e.g., in the ~ilc[in-theory] event or ~c[:]~ilc[in-theory]
3056
 
  hint, each of the terms in ~c[theory-invariant-table] is evaluated with
3057
 
  ~ilc[theory] bound to the runic theory (~pl[theories]) obtained from
3058
 
  the theory expression and ~ilc[world] bound to the current ACL2 ~il[world]
3059
 
  (~pl[world]).  If the result is ~c[nil], a message is printed and an error
3060
 
  occurs (except, only a warning occurs if ~c[:error nil] is specified).  Thus,
3061
 
  the ~il[table] can be thought of as a list of conjuncts.  Each ~c[term] in
3062
 
  the ~il[table] has a ``name,'' which is just the key under which the term is
3063
 
  stored.  When a theory violates the restrictions specified by some term, both
3064
 
  the name and the term are printed.  By calling ~c[theory-invariant] with a
3065
 
  new term but the same name, you can overwrite that conjunct of the theory
3066
 
  invariant; but see the Local Redefinition Caveat at the end of this note.
3067
 
  You may want to avoid using explicit names, since otherwise the subsequent
3068
 
  inclusion of another book that defines a theory invariant with the same name
3069
 
  will override your theory invariant.
 
3095
  ~c[Theory-invariant-table] maps arbitrary keys to records containing terms
 
3096
  that mention, at most, the variables ~c[ens] and ~ilc[state].  Every time an
 
3097
  alleged theory expression is evaluated, e.g., in the ~ilc[in-theory] event or
 
3098
  ~c[:]~ilc[in-theory] hint, each of the terms in ~c[theory-invariant-table] is
 
3099
  evaluated with ~c[ens] bound to a so-called ``enabled structure'' obtained
 
3100
  from the theory expression and ~ilc[state] bound to the current ACL2 state
 
3101
  (~pl[state]).  Users generally need not know about the enabled structure,
 
3102
  other than that it can be accessed using the macros ~c[active-runep] and
 
3103
  ~c[incompatible]; ~pl[active-runep] and ~pl[incompatible].  If the result is
 
3104
  ~c[nil], a message is printed and an error occurs (except, only a warning
 
3105
  occurs if ~c[:error nil] is specified).  Thus, the ~il[table] can be thought
 
3106
  of as a list of conjuncts.  Each ~c[term] in the ~il[table] has a ``name,''
 
3107
  which is just the key under which the term is stored.  When a theory violates
 
3108
  the restrictions specified by some term, both the name and the term are
 
3109
  printed.  By calling ~c[theory-invariant] with a new term but the same name,
 
3110
  you can overwrite that conjunct of the theory invariant; but see the Local
 
3111
  Redefinition Caveat at the end of this note.  You may want to avoid using
 
3112
  explicit names, since otherwise the subsequent inclusion of another book that
 
3113
  defines a theory invariant with the same name will override your theory
 
3114
  invariant.
3070
3115
 
3071
 
  Theory invariants are particularly useful in the context of large
3072
 
  rule sets intended for re-use.  Such sets often contain conflicting
3073
 
  rules, e.g., rules that are to be ~il[enable]d when certain function
3074
 
  symbols are ~il[disable]d, rules that rewrite in opposite directions and
3075
 
  thus loop if simultaneously ~il[enable]d, groups of rules which should be
3076
 
  ~il[enable]d in concert, etc.  The developer of such rule sets
3077
 
  understands these restrictions and probably documents them.  The
3078
 
  theory invariant mechanism allows the developer to codify his
3079
 
  restrictions so that the user is alerted when they are violated.
 
3116
  Theory invariants are particularly useful in the context of large rule sets
 
3117
  intended for re-use.  Such sets often contain conflicting rules, e.g., rules
 
3118
  that are to be ~il[enable]d when certain function symbols are ~il[disable]d,
 
3119
  rules that rewrite in opposite directions and thus loop if simultaneously
 
3120
  ~il[enable]d, groups of rules which should be ~il[enable]d in concert, etc.
 
3121
  The developer of such rule sets understands these restrictions and probably
 
3122
  documents them.  The theory invariant mechanism allows the developer to
 
3123
  codify his restrictions so that the user is alerted when they are violated.
3080
3124
 
3081
3125
  Since theory invariants are arbitrary terms, macros may be used to
3082
3126
  express commonly used restrictions.  For example, executing the event
3093
3137
  value returned upon successful execution of the event is the key (whether
3094
3138
  user-supplied or generated).
3095
3139
 
3096
 
  Note: If the ~il[table] event is used directly to ~c[:put] a term into the
3097
 
  theory invariant ~il[table], be aware that the term must be in translated
3098
 
  form.  This is enforced by the ~c[value] invariant for
3099
 
  ~c[theory-invariant-table].  But the upshot of this is that you will be
3100
 
  unable to use macros in theory invariants stored directly with the
3101
 
  ~c[:put] ~il[table] event.
3102
 
 
3103
3140
  Local Redefinition Caveat.  Care needs to be taken when redefining a theory
3104
3141
  invariant in a ~il[local] context.  Consider the following example.
3105
3142
 
3106
3143
  ~bv[]
3107
3144
  (theory-invariant
3108
 
   (member-equal '(:definition binary-append) theory)
 
3145
   (active-runep '(:definition binary-append))
3109
3146
   :key app-inv)
3110
3147
 
3111
3148
  (encapsulate
3167
3204
                               `(quote ,key)
3168
3205
                             '(1+
3169
3206
                               (length inv-table)))))
3170
 
                (pprogn
3171
 
                 (cond ((assoc-equal key inv-table)
3172
 
                        (warning$ 'theory-invariant "Theory"
3173
 
                                  "An existing theory invariant, named ~x0, is ~
3174
 
                                  being overwritten by a new theory invariant ~
3175
 
                                  with that name.~@1"
3176
 
                                  key
3177
 
                                  (cond ((f-get-global 'in-local-flg state)
3178
 
                                         "  Moreover, this override is being ~
3179
 
                                          done LOCALly; see :DOC ~
3180
 
                                          theory-invariant (in particular, ~
3181
 
                                          the Local Redefinition Caveat ~
3182
 
                                          there), especially if an error ~
3183
 
                                          occurs.")
3184
 
                                        (t ""))))
3185
 
                       (t state))
3186
 
                 (er-progn
3187
 
                  (with-output
3188
 
                   :off summary
3189
 
                   (table-fn1 'theory-invariant-table
3190
 
                              key
3191
 
                              (cons tterm ',error)
3192
 
                              :put
3193
 
                              nil
3194
 
                              'theory-invariant
3195
 
                              (w state)
3196
 
                              state
3197
 
                              ',event-form))
3198
 
                  (mv-let (erp val state)
3199
 
                          (with-output
3200
 
                           :off summary
3201
 
                           (in-theory (current-theory :here)))
3202
 
                          (declare (ignore val))
3203
 
                          (cond
3204
 
                           (erp
3205
 
                            (er soft 'theory-invariant
3206
 
                                "The specified theory invariant fails for the ~
3207
 
                                current ACL2 world, and hence is rejected.  ~
3208
 
                                This failure can probably be overcome by ~
3209
 
                                supplying an appropriate in-theory event ~
3210
 
                                first."))
3211
 
                           (t (value key)))))))))))
 
3207
                (er-let*
 
3208
                 ((val
 
3209
                   (with-output
 
3210
                    :off summary
 
3211
                    (table-fn1 'theory-invariant-table
 
3212
                               key
 
3213
                               (make theory-invariant-record
 
3214
                                     :tterm tterm
 
3215
                                     :error ',error
 
3216
                                     :untrans-term ',term)
 
3217
                               :put
 
3218
                               nil
 
3219
                               'theory-invariant
 
3220
                               (w state)
 
3221
                               state
 
3222
                               ',event-form))))
 
3223
                 (cond
 
3224
                  ((eq val :redundant)
 
3225
                   (value val))
 
3226
                  (t
 
3227
                   (pprogn
 
3228
                    (cond ((assoc-equal key inv-table)
 
3229
                           (warning$ 'theory-invariant "Theory"
 
3230
                                     "An existing theory invariant, named ~
 
3231
                                      ~x0, is being overwritten by a new ~
 
3232
                                      theory invariant with that name.~@1"
 
3233
                                     key
 
3234
                                     (cond ((f-get-global 'in-local-flg state)
 
3235
                                            "  Moreover, this override is ~
 
3236
                                             being done LOCALly; see :DOC ~
 
3237
                                             theory-invariant (in particular, ~
 
3238
                                             the Local Redefinition Caveat ~
 
3239
                                             there), especially if an error ~
 
3240
                                             occurs.")
 
3241
                                           (t ""))))
 
3242
                          (t state))
 
3243
                    (mv-let (erp val state)
 
3244
                            (with-output
 
3245
                             :off summary
 
3246
                             (in-theory (current-theory :here)))
 
3247
                            (declare (ignore val))
 
3248
                            (cond
 
3249
                             (erp
 
3250
                              (er soft 'theory-invariant
 
3251
                                  "The specified theory invariant fails for ~
 
3252
                                   the current ACL2 world, and hence is ~
 
3253
                                   rejected.  This failure can probably be ~
 
3254
                                   overcome by supplying an appropriate ~
 
3255
                                   in-theory event first."))
 
3256
                             (t (value key)))))))))))))
3212
3257
 
3213
3258
(defmacro incompatible (rune1 rune2)
3214
3259
  ":Doc-Section Theories
3224
3269
  ~ev[]
3225
3270
  where ~c[rune1] and ~c[rune2] are two specific ~il[rune]s.  The arguments are
3226
3271
  not evaluated.  ~c[Invariant] is just a macro that expands into a term
3227
 
  that checks that ~ilc[theory] does not contain both ~il[rune]s.
3228
 
  ~l[theory-invariant].~/"
3229
 
 
3230
 
  `(not (and (member-equal ',rune1 theory)
3231
 
             (member-equal ',rune2 theory))))
 
3272
  that checks that not both ~il[rune]s are enabled.  ~l[theory-invariant].~/"
 
3273
 
 
3274
  (cond ((and (consp rune1)
 
3275
              (consp (cdr rune1))
 
3276
              (symbolp (cadr rune1))
 
3277
              (consp rune2)
 
3278
              (consp (cdr rune2))
 
3279
              (symbolp (cadr rune2)))
 
3280
 
 
3281
; The above condition is similar to conditions in runep and active-runep.
 
3282
 
 
3283
         `(not (and (active-runep ',rune1)
 
3284
                    (active-runep ',rune2))))
 
3285
        (t (er hard 'incompatible
 
3286
               "Each argument to ~x0 should have the shape of a rune, ~
 
3287
                (:KEYWORD BASE-SYMBOL), unlike ~x1."
 
3288
               'incompatible
 
3289
               (or (and (consp rune1)
 
3290
                        (consp (cdr rune1))
 
3291
                        (symbolp (cadr rune1))
 
3292
                        rune2)
 
3293
                   rune1)))))
3232
3294
 
3233
3295
; We now begin the development of the encapsulate event.  Often in this
3234
3296
; development we refer to the Encapsulate Essay.  See the comment in
3611
3673
              which might be a single signature.  Try writing ~x1."
3612
3674
             signatures
3613
3675
             (list signatures)))
3614
 
 
3615
 
 
3616
3676
        (t (er-let* ((pair1 (chk-signature (car signatures)
3617
3677
                                           ctx wrld state))
3618
3678
                     (pair2 (chk-signatures (cdr signatures)
3704
3764
     in-theory
3705
3765
     in-arithmetic-theory
3706
3766
     push-untouchable
 
3767
     remove-untouchable
 
3768
     reset-prehistory
3707
3769
     set-body
3708
3770
     table
3709
3771
     progn
 
3772
     progn!
3710
3773
     encapsulate
3711
3774
     include-book
3712
3775
     add-include-book-dir
3733
3796
     set-nu-rewriter-mode
3734
3797
     set-case-split-limitations
3735
3798
     set-default-hints!
3736
 
     set-rewrite-stack-limit))
 
3799
     set-rewrite-stack-limit
 
3800
     defttag))
3737
3801
 
3738
3802
; Warning: If a symbol is on this list then it is allowed into books.
3739
3803
; If it is allowed into books, it will be compiled.  Thus, if you add a
3816
3880
 
3817
3881
    ~c[x] is of the form ~c[(VALUE-TRIPLE &)], where ~c[&] is any term;
3818
3882
 
 
3883
    ~c[x] is a call of ~ilc[ENCAPSULATE], ~ilc[PROGN], ~ilc[PROGN!], or
 
3884
    ~ilc[INCLUDE-BOOK];
 
3885
 
3819
3886
    ~c[x] macroexpands to one of the forms above; or
3820
3887
 
3821
3888
    [intended only for the implementation] ~c[x] is
3822
 
    ~c[(RECORD-EXPANSION x1 x2), where ~c[x1] and ~c[x2] are embedded event
 
3889
    ~c[(RECORD-EXPANSION x1 x2)], where ~c[x1] and ~c[x2] are embedded event
3823
3890
    forms.
3824
3891
 
3825
3892
  ~eq[]
3834
3901
  example at the end of the discussion below illustrates why there is
3835
3902
  this restriction.
3836
3903
 
 
3904
  Only embedded event forms are allowed in a book after its initial
 
3905
  ~ilc[in-package] form.  ~l[books].  However, you may find that
 
3906
  ~ilc[make-event] allows you to get the effect you want for a form that is not
 
3907
  an embedded event form.  For example, you can put the following into a book,
 
3908
  which assigns the value 17 to ~ilc[state] global variable ~c[x]:
 
3909
  ~bv[]
 
3910
  (make-event (er-progn (assign x 17)
 
3911
                        (value '(value-triple nil)))
 
3912
              :check-expansion t)
 
3913
  ~ev[]
 
3914
 
3837
3915
  When an embedded event is executed while ~ilc[ld-skip-proofsp] is
3838
3916
  ~c[']~ilc[include-book], those parts of it inside ~ilc[local] forms are ignored.
3839
3917
  Thus,
3851
3929
  the kinds of forms that may be processed.  These restrictions ensure that the
3852
3930
  non-local ~il[events] are indeed admissible provided that the sequence of
3853
3931
  ~ilc[local] and non-local ~il[events] is admissible when proofs are done,
3854
 
  i.e., when ~c[ld-skip-proofs] is ~c[nil].
 
3932
  i.e., when ~c[ld-skip-proofs] is ~c[nil].  But ~ilc[progn!] places no such
 
3933
  restrictions, hence is potentially dangerous and should be avoided unless you
 
3934
  understand the ramifications; so it is illegal unless there is an active
 
3935
  trust tag (~pl[defttag]).
3855
3936
 
3856
3937
  ~ilc[Local] permits the hiding of an event or group of ~il[events] in the
3857
3938
  sense that ~ilc[local] ~il[events] are processed when we are trying to
3955
4036
; in-theory-fn               ---
3956
4037
; in-arithmetic-theory-fn    ---
3957
4038
; push-untouchable-fn        ---
 
4039
; remove-untouchable-fn      ---
 
4040
; reset-prehistory           ---
3958
4041
; set-body-fn                ---
3959
4042
; table-fn                   ---
3960
4043
; encapsulate-fn             --- [However, the signature functions
4004
4087
  (form orig-form wrld ctx state names portcullisp in-local-flg
4005
4088
        in-encapsulatep make-event-chk)
4006
4089
 
4007
 
; Note:  For a test of this function, see the reference to foo.lisp below.
4008
 
 
4009
 
; Orig-form is used for error reporting.  It is either nil, indicating that
4010
 
; errors should refer to form, or else it is a form from a superior call of
4011
 
; this function.
4012
 
 
4013
 
; This function checks that form is a tree whose tips are calls of
4014
 
; the symbols listed in names, and whose interior nodes are each of one of
 
4090
; Note: For a test of this function, see the reference to foo.lisp
 
4091
; below.
 
4092
 
 
4093
; Orig-form is used for error reporting.  It is either nil, indicating
 
4094
; that errors should refer to form, or else it is a form from a
 
4095
; superior call of this function.  So it is typical, though not
 
4096
; required, to call this with orig-form = nil at the top level.  If we
 
4097
; encounter a macro call and orig-form is nil, then we set orig-form
 
4098
; to the macro call so that the user can see that macro call if the
 
4099
; check fails.
 
4100
 
 
4101
; This function checks that form is a tree whose tips are calls of the
 
4102
; symbols listed in names, and whose interior nodes are each of one of
4015
4103
; the forms:
4016
4104
 
4017
4105
; (local &)
4020
4108
; (with-output ... &)
4021
4109
; (make-event #)
4022
4110
 
4023
 
; where each & is checked.  The # forms above are unrestricted, although the
4024
 
; the result of expanding the argument of make-event (by evaluation) is
4025
 
; checked.  Note that both 'encapsulate and 'progn are typically in names, and
4026
 
; their sub-events aren't checked by this function until evaluation time.
 
4111
; where each & is checked.  The # forms above are unrestricted,
 
4112
; although the the result of expanding the argument of make-event (by
 
4113
; evaluation) is checked.  Note that both 'encapsulate and 'progn are
 
4114
; typically in names, and their sub-events aren't checked by this
 
4115
; function until evaluation time.
4027
4116
 
4028
4117
; In addition, if portcullisp is t we are checking that the forms are
4029
 
; acceptable as the portcullis of some book and we enforce the additional
4030
 
; restriction noted below.
 
4118
; acceptable as the portcullis of some book and we enforce the
 
4119
; additional restriction noted below.
4031
4120
 
4032
4121
;   (local &) is illegal because such a command would be skipped
4033
4122
;   when executing the portcullis during the subsequent include-book.
4043
4132
; pathnames so that they use absolute pathnames instead, or cause an
4044
4133
; error trying.
4045
4134
 
4046
 
; We allow defaxioms and skip-proofs in the portcullis, but we mark the
4047
 
; book's certificate appropriately.
 
4135
; We allow defaxioms skip-proofs, and defttags in the portcullis, but
 
4136
; we mark the book's certificate appropriately.
4048
4137
 
4049
4138
; If in-local-flg is t, we enforce the restriction that (table
4050
4139
; acl2-defaults-table ...) is illegal, even if table is among names,
4051
4140
; because we do not permit acl2-defaults-table to be changed locally.
4052
 
; Similarly, defun-mode events and set-compile-fns events are illegal.  (We
4053
 
; used to make these restrictions when portcullisp is t, because we
4054
 
; restored the initial acl2-defaults-table before certification, and
4055
 
; hence it was misguided for the user to be setting the defun-mode or the
4056
 
; compile flag in the certification world since they were irrelevant
4057
 
; to the world in which the certification is done.)  Note that a value of
4058
 
; 'dynamic for in-local-flg means that we are locally including a book but are
4059
 
; not in the lexical scope of a local within that book, in which case it is
4060
 
; fine to set the acl2-defaults-table.
4061
 
 
4062
 
; Moreover, we do not allow local defaxiom events.  Imagine locally including a
4063
 
; book that has nil as a defaxiom.  You can prove anything you want in your
4064
 
; book, and then when you later include the book, there will be no trace of the
4065
 
; defaxiom in your logical world!
4066
 
 
4067
 
; We do not check that the tips are well-formed calls of the named functions
4068
 
; (though we do ensure that they are all true lists).
 
4141
; Similarly, defun-mode events and set-compile-fns events are illegal.
 
4142
; (We used to make these restrictions when portcullisp is t, because
 
4143
; we restored the initial acl2-defaults-table before certification,
 
4144
; and hence it was misguided for the user to be setting the defun-mode
 
4145
; or the compile flag in the certification world since they were
 
4146
; irrelevant to the world in which the certification is done.)  Note
 
4147
; that a value of 'dynamic for in-local-flg means that we are locally
 
4148
; including a book but are not in the lexical scope of a local within
 
4149
; that book, in which case it is fine to set the acl2-defaults-table.
 
4150
 
 
4151
; Moreover, we do not allow local defaxiom events.  Imagine locally
 
4152
; including a book that has nil as a defaxiom.  You can prove anything
 
4153
; you want in your book, and then when you later include the book,
 
4154
; there will be no trace of the defaxiom in your logical world!
 
4155
 
 
4156
; We do not check that the tips are well-formed calls of the named
 
4157
; functions (though we do ensure that they are all true lists).
4069
4158
 
4070
4159
; If names is *primitive-event-macros* and form can be translated and
4071
4160
; evaluated without error, then it is in fact an embedded event form
4077
4166
; If form is rejected, the error message is that printed by str, with
4078
4167
; #\0 bound to the subform (of form) that was rejected.
4079
4168
 
4080
 
; We return a value triple (mv erp val state).  If erp is nil then val is the
4081
 
; form to be evaluated.  Generally that is the result of macroexpanding the
4082
 
; input form.  However, if (perhaps after some macroexpansion) form is a call
4083
 
; of local that should be skipped, then val is nil.
4084
 
 
4085
 
  (let* ((str (if portcullisp
4086
 
                  "The command ~x0, used in the construction of the current ~
4087
 
                   world, cannot be included in the portcullis of a certified ~
4088
 
                   book~@1.  See :DOC portcullis.~@2"
4089
 
                "The form ~x0 is not an embedded event form~@1.  See :DOC ~
4090
 
                 embedded-event-form.~@2"))
 
4169
; We return a value triple (mv erp val state).  If erp is nil then val
 
4170
; is the form to be evaluated.  Generally that is the result of
 
4171
; macroexpanding the input form.  However, if (perhaps after some
 
4172
; macroexpansion) form is a call of local that should be skipped, then
 
4173
; val is nil.
 
4174
 
 
4175
  (let* ((er-str
 
4176
 
 
4177
; Below, the additional er arguments are as follows:
 
4178
; ~@1: a reason specific to the context, or "" if none is called for.
 
4179
; ~@2: original form message.
 
4180
; ~@3: additional explanation, or "".
 
4181
 
 
4182
          (if portcullisp
 
4183
              "The command ~x0, used in the construction of the current ~
 
4184
               world, cannot be included in the portcullis of a certified ~
 
4185
               book~@1.  See :DOC portcullis.~@2~@3"
 
4186
            "The form ~x0 is not an embedded event form~@1.  See :DOC ~
 
4187
             embedded-event-form.~@2~@3"))
4091
4188
         (local-str "The form ~x0 is not an embedded event form in the ~
4092
 
                     context of LOCAL~@1.  See :DOC embedded-event-form.~@2")
 
4189
                     context of LOCAL~@1.  See :DOC embedded-event-form.~@2~@3")
4093
4190
         (encap-str "The form ~x0 is not an embedded event form in the ~
4094
4191
                     context of ENCAPSULATE~@1.  See :DOC ~
4095
 
                     embedded-event-form.~@2"))
 
4192
                     embedded-event-form.~@2~@3"))
4096
4193
    (cond ((or (atom form)
4097
4194
               (not (symbolp (car form)))
4098
4195
               (not (true-listp (cdr form))))
4099
 
           (er soft ctx str
 
4196
           (er soft ctx er-str
4100
4197
               form
4101
4198
               ""
4102
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4199
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4200
               ""))
4103
4201
          ((and (eq (car form) 'local)
4104
4202
                (consp (cdr form))
4105
4203
                (null (cddr form)))
4110
4208
; (not (and (consp (cdr form)) (null (cddr form)))).  However, macroexpansion
4111
4209
; of local will fail later, so that isn't a problem.
4112
4210
 
4113
 
             (er soft ctx str
 
4211
             (er soft ctx er-str
4114
4212
                 form
4115
4213
                 " because LOCAL commands are not executed by include-book"
4116
 
                 (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4214
                 (chk-embedded-event-form-orig-form-msg orig-form state)
 
4215
                 ""))
4117
4216
            ((eq (ld-skip-proofsp state) 'include-book)
4118
4217
 
4119
4218
; Keep this in sync with the definition of the macro local; if we evaluate the
4138
4237
                the acl2-defaults-table is restored upon completion of ~
4139
4238
                encapsulate, include-book, and certify-book forms; that is, ~
4140
4239
                no changes to the acl2-defaults-table are exported" 
4141
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4240
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4241
               ""))
4142
4242
          ((and (eq in-local-flg t)
4143
4243
                (consp form)
4144
4244
                (member-eq (car form)
4164
4264
                             set-rewrite-stack-limit
4165
4265
                             set-state-ok
4166
4266
                             set-verify-guards-eagerness
4167
 
                             set-well-founded-relation)))
 
4267
                             set-well-founded-relation
 
4268
                             defttag)))
4168
4269
           (er soft ctx local-str
4169
4270
               form
4170
4271
               " because it implicitly sets the acl2-defaults-table in a ~
4173
4274
                completion of encapsulate, include-book, and certify-book ~
4174
4275
                forms; that is, no changes to the acl2-defaults-table are ~
4175
4276
                exported"
4176
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4277
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4278
               ""))
4177
4279
          ((and in-local-flg (eq (car form) 'defaxiom))
4178
4280
           (er soft ctx local-str
4179
4281
               form
4180
4282
               " because it adds an axiom whose traces will disappear"
4181
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4283
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4284
               ""))
4182
4285
          ((and in-encapsulatep (eq (car form) 'defaxiom))
4183
4286
           (er soft ctx encap-str
4184
4287
               form
4185
4288
               " because we do not permit defaxiom events in the scope of an ~
4186
4289
                encapsulate"
4187
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4290
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4291
               ""))
4188
4292
          ((and in-encapsulatep
4189
4293
 
4190
4294
; Note that in-local-flg could be 'dynamic from (encapsulate (local
4204
4308
                successful use of :functional-instance lemma instances.  ~
4205
4309
                Consider moving your include-book form outside the ~
4206
4310
                encapsulates, or else making it local"
4207
 
               (chk-embedded-event-form-orig-form-msg orig-form state)))
 
4311
               (chk-embedded-event-form-orig-form-msg orig-form state)
 
4312
               ""))
4208
4313
          ((member-eq (car form) names)
4209
4314
 
4210
4315
; Names is often *primitive-event-macros* or an extension, and hence
4248
4353
                                 (consp (cadr (member-eq :check-expansion
4249
4354
                                                         form))))))
4250
4355
                  (er soft ctx
4251
 
                      "Implementation Error: The :check-expansion argument of ~
4252
 
                       make-event should be a consp in the present context.  ~
4253
 
                       Please contact the ACL2 implementors.  Current ~
4254
 
                       form:~|~%~X01"
4255
 
                      `(chk-embedded-event-form ,form ,orig-form <wrld> ,ctx
4256
 
                                                <state> <names> portcullisp
4257
 
                                                ,in-local-flg ,in-encapsulatep
4258
 
                                                ,make-event-chk)
 
4356
                      "The :check-expansion argument of make-event should be ~
 
4357
                       a consp in the present context.  This error can occur ~
 
4358
                       when including an uncertified book.  If you see the ~
 
4359
                       error during other normal use of ACL2, then you may ~
 
4360
                       have uncovered an ACL2 bug; please contact the ACL2 ~
 
4361
                       implementors.  Current form:~|~%~X01"
 
4362
                      form
4259
4363
                      nil))
4260
4364
                 (t (value form))))
4261
4365
          ((eq (car form) 'record-expansion) ; a macro, but we handle specially
4264
4368
                            (null (cdddr form))))
4265
4369
                  (er soft ctx
4266
4370
                      "The macro ~x0 takes two arguments, so ~x1 is illegal."
4267
 
                      'record-expansion form))
 
4371
                      'record-expansion
 
4372
                      form))
4268
4373
                 (t (er-progn
4269
4374
                     (chk-embedded-event-form (cadr form)
4270
4375
                                              nil
4279
4384
          ((getprop (car form) 'macro-body nil 'current-acl2-world wrld)
4280
4385
           (cond
4281
4386
            ((member-eq (car form) (global-val 'untouchable-fns wrld))
4282
 
             (er soft ctx
4283
 
                 "The macro ~x0 may not be used to generate an event, because ~
4284
 
                  it has been placed on untouchable-fns.  See :DOC ~
4285
 
                  push-untouchable."
4286
 
                 (car form)))
 
4387
             (er soft ctx er-str
 
4388
                 form
 
4389
                 ""
 
4390
                 (chk-embedded-event-form-orig-form-msg orig-form state)
 
4391
                 (msg "~|The macro ~x0 may not be used to generate an event, ~
 
4392
                       because it has been placed on untouchable-fns.  See ~
 
4393
                       :DOC push-untouchable."
 
4394
                      (car form))))
4287
4395
            ((member-eq (car form)
4288
4396
                        '(mv mv-let translate-and-test with-local-stobj))
4289
 
             (er soft ctx
4290
 
                 "Calls of the macro ~x0 do not generate an event, because ~
4291
 
                  this macro has special meaning that is not handled by ~
4292
 
                  ACL2's event-generation mechanism.  Please contact the ~
4293
 
                  implementors if this seems to be a hardship."
4294
 
                 (car form)))
 
4397
             (er soft ctx er-str
 
4398
                 form
 
4399
                 ""
 
4400
                 (chk-embedded-event-form-orig-form-msg orig-form state)
 
4401
                 (msg "~|Calls of the macro ~x0 do not generate an event, ~
 
4402
                       because this macro has special meaning that is not ~
 
4403
                       handled by ACL2's event-generation mechanism.  Please ~
 
4404
                       contact the implementors if this seems to be a ~
 
4405
                       hardship."
 
4406
                      (car form))))
4295
4407
            (t
4296
4408
             (er-let*
4297
4409
              ((expansion (macroexpand1 form ctx state)))
4300
4412
                                       wrld ctx state names
4301
4413
                                       portcullisp in-local-flg
4302
4414
                                       in-encapsulatep make-event-chk)))))
4303
 
          (t (er soft ctx str
 
4415
          (t (er soft ctx er-str
4304
4416
                 form
4305
4417
                 ""
4306
 
                 (chk-embedded-event-form-orig-form-msg orig-form state))))))
4307
 
 
4308
 
(defun chk-embedded-event-form-lst
4309
 
  (forms wrld ctx state names portcullisp in-local-flg in-encapsulatep
4310
 
         make-event-chk)
4311
 
  (cond
4312
 
   ((null forms) (value nil))
4313
 
   (t (er-progn
4314
 
       (chk-embedded-event-form (car forms) nil wrld ctx state names
4315
 
                                portcullisp in-local-flg in-encapsulatep
4316
 
                                make-event-chk)
4317
 
       (chk-embedded-event-form-lst (cdr forms) wrld ctx state names
4318
 
                                    portcullisp in-local-flg
4319
 
                                    in-encapsulatep make-event-chk)))))
 
4418
                 (chk-embedded-event-form-orig-form-msg orig-form state)
 
4419
                 "")))))
4320
4420
 
4321
4421
; We have had a great deal of trouble correctly detecting embedded defaxioms!
4322
4422
; Tests for this have been incorporated into
4336
4436
        (t (append (car wrappers)
4337
4437
                   (list (rebuild-expansion (cdr wrappers) form))))))
4338
4438
 
4339
 
(defun eval-event-lst (index expansion-alist ev-lst orig-form quietp
4340
 
                             in-encapsulatep in-local-flg last-val
4341
 
                             make-event-chk ctx channel state)
 
4439
(defun set-raw-mode-on (state)
 
4440
  (pprogn
 
4441
   (cond ((raw-mode-p state)
 
4442
          (fms "No change: raw mode is already on.~|"
 
4443
               nil (standard-co state) state nil))
 
4444
         (t
 
4445
          (pprogn (fms "Entering raw-mode.~|" nil (standard-co state) state nil)
 
4446
                  (f-put-global 'acl2-raw-mode-p t state))))
 
4447
   (value :invisible)))
 
4448
 
 
4449
(defun set-raw-mode-off (state)
 
4450
  (pprogn
 
4451
   (cond ((raw-mode-p state)
 
4452
          (pprogn (fms "Leaving raw-mode.~|" nil (standard-co state) state nil)
 
4453
                  (f-put-global 'acl2-raw-mode-p nil state)))
 
4454
         (t
 
4455
          (fms "No change: raw mode is already off.~|"
 
4456
               nil (standard-co state) state nil)))
 
4457
   (value :invisible)))
 
4458
 
 
4459
(defmacro set-raw-mode-on! ()
 
4460
 
 
4461
  ":Doc-Section Other
 
4462
 
 
4463
  enter ``raw mode,'' a raw Lisp environment~/
 
4464
 
 
4465
  This is the same as ~c[(]~ilc[set-raw-mode]~c[ t)] except that it first
 
4466
  introduces a so-called ``trust tag'' (``ttag'') so that ~c[set-raw-mode] will
 
4467
  be legal.  ~l[defttag] for a discussion of ttags and how they affect
 
4468
  ~ilc[certify-book] and ~ilc[include-book].~/~/"
 
4469
 
 
4470
  '(er-progn (ld '((defttag :raw-mode-hack)
 
4471
                   (set-raw-mode-on state))
 
4472
                 :ld-prompt nil :ld-verbose nil :ld-post-eval-print nil)
 
4473
             (value :invisible)))
 
4474
 
 
4475
(defmacro set-raw-mode (flg)
 
4476
  (declare (xargs :guard (member-equal flg '(t 't nil 'nil))))
 
4477
 
 
4478
  ":Doc-Section Other
 
4479
 
 
4480
  enter or exit ``raw mode,'' a raw Lisp environment~/
 
4481
 
 
4482
  ACL2 users often find its careful syntax checking to be helpful during code
 
4483
  development.  Sometimes it is even useful to do code development in
 
4484
  ~c[:]~ilc[logic] mode, where ACL2 can be used to check termination of
 
4485
  (mutually) recursive functions, verify guards, or even prove properties of
 
4486
  the functions.
 
4487
 
 
4488
  However, loading code using ~ilc[include-book] is much slower than using
 
4489
  Common Lisp ~c[load] in raw Lisp, and in this sense ACL2 can get in the way
 
4490
  of efficient execution.  Unfortunately, it is error-prone to use ACL2 sources
 
4491
  (or their compilations) in raw Lisp, primarily because a number of ACL2
 
4492
  primitives will not let you do so.  Perhaps you have seen this error message
 
4493
  when trying to do so:
 
4494
  ~bv[]
 
4495
  HARD ACL2 ERROR in ACL2-UNWIND-PROTECT:  Apparently you have tried
 
4496
  to execute a form in raw Lisp that is only intended to be executed
 
4497
  inside the ACL2 loop.
 
4498
  ~ev[]
 
4499
  Even without this problem it is important to enter the ACL2 loop (~pl[lp]),
 
4500
  for example in order to set the ~ilc[cbd] and (to get more technical) the
 
4501
  readtable.
 
4502
 
 
4503
  ACL2 provides a ``raw mode'' for execution of raw Lisp forms.  In this mode,
 
4504
  ~ilc[include-book] reduces essentially to a Common Lisp ~c[load].  More
 
4505
  generally, the ACL2 logical ~ilc[world] is not routinely extended in raw mode
 
4506
  (some sneaky tricks are probably required to make that happen).  To turn raw
 
4507
  mode off or on:
 
4508
  ~bv[]
 
4509
  :set-raw-mode t   ; turn raw mode on
 
4510
  :set-raw-mode nil ; turn raw mode off
 
4511
  ~ev[]~/
 
4512
 
 
4513
  The way you can tell that you are in raw mode is by looking at the prompt
 
4514
  (~pl[default-print-prompt]), which uses a capital ``~c[P]'' (suggesting
 
4515
  something like program mode, but more so).
 
4516
  ~bv[]
 
4517
  ACL2 P>
 
4518
  ~ev[]
 
4519
 
 
4520
  Typical benefits of raw mode are fast loading of source and compiled files
 
4521
  and the capability to hack arbitrary Common Lisp code in an environment with
 
4522
  the ACL2 sources loaded (and hence with ACL2 primitives available).  In
 
4523
  addition, ACL2 hard errors will put you into the Lisp debugger, rather than
 
4524
  returning you to the ACL2 loop, and this may be helpful for debugging;
 
4525
  ~pl[hard-error] and ~pl[illegal], but also ~pl[break-on-error].  However, it
 
4526
  probably is generally best to avoid raw mode unless these advantages seem
 
4527
  important.  We expect the main benefit of raw mode to be in deployment of
 
4528
  applications, where load time is much faster than the time required for a
 
4529
  full-blown ~ilc[include-book], although in certain cases the fast loading of
 
4530
  books and treatment of hard errors discussed above may be useful during
 
4531
  development.
 
4532
 
 
4533
  Raw mode is also useful for those who want to build extensions of ACL2.  For
 
4534
  example, the following form can be put into a certifiable book to load an
 
4535
  arbitrary Common Lisp source or compiled file.
 
4536
  ~bv[]
 
4537
  (progn! (defttag my-application)
 
4538
          (set-raw-mode t)
 
4539
          (load \"some-file\"))
 
4540
  ~ev[]
 
4541
  Also see ~c[with-raw-mode] defined in ~c[books/misc/hacker.lisp],
 
4542
  ~pl[defttag], and ~pl[progn!].
 
4543
 
 
4544
  Below are several disadvantages to raw mode.  These should discourage users
 
4545
  from using it for general code development, as ~c[:]~ilc[program] mode is
 
4546
  generally preferable.
 
4547
  ~bf[]
 
4548
  -- Forms are in essence executed in raw Lisp.  Hence:
 
4549
     -- Syntax checking is turned off; and
 
4550
     -- Guard checking is completely disabled.
 
4551
  -- Table events, including ~ilc[logic], are ignored, as are many
 
4552
     other ~ilc[events], including ~ilc[defthm] and ~ilc[comp].
 
4553
  -- Soundness claims are weakened for any ACL2 session in which raw
 
4554
     mode was ever entered; ~pl[defttag].
 
4555
  -- The normal undoing mechanism (~pl[ubt]) is not supported.
 
4556
  ~ef[]
 
4557
 
 
4558
  We conclude with some details.
 
4559
 
 
4560
  ~em[Printing results].  The rules for printing results are unchanged for raw
 
4561
  mode, with one exception.  If the value to be printed would contain any Lisp
 
4562
  object that is not a legal ACL2 object, then the ~c[print] routine is used
 
4563
  from the host Lisp, rather than the usual ACL2 printing routine.  The
 
4564
  following example illustrates the printing used when an illegal ACL2 object
 
4565
  needs to be printed.  Notice how that ``command conventions'' are observed
 
4566
  (~pl[ld-post-eval-print]); the ``~c[[Note]'' occurs one space over in the
 
4567
  second example, and no result is printed in the third example.
 
4568
  ~bv[]
 
4569
  ACL2 P>(find-package \"ACL2\")
 
4570
  [Note:  Printing non-ACL2 result.]
 
4571
  #<The ACL2 package> 
 
4572
  ACL2 P>(mv nil (find-package \"ACL2\") state)
 
4573
   [Note:  Printing non-ACL2 result.]
 
4574
  #<The ACL2 package> 
 
4575
  ACL2 P>(mv t (find-package \"ACL2\") state)
 
4576
  ACL2 P>(mv 3 (find-package \"ACL2\"))
 
4577
  [Note:  Printing non-ACL2 result.]
 
4578
  (3 #<The ACL2 package>) 
 
4579
  ACL2 P>
 
4580
  ~ev[]
 
4581
  If you have trouble with large structures being printed out, you might want
 
4582
  to execute appropriate Common Lisp forms in raw mode, for example,
 
4583
  ~c[(setq *print-length* 5)] and ~c[(setq *print-level* 5)].
 
4584
 
 
4585
  ~em[Packages].  Raw mode disallows the use of ~ilc[defpkg].  If you want to
 
4586
  create a new package, first exit raw mode with ~c[:set-raw-mode nil];
 
4587
  you can subsequently re-enter raw mode with ~c[:set-raw-mode t] if you
 
4588
  wish.~/"
 
4589
 
 
4590
  (if (or (null flg)
 
4591
          (equal flg '(quote nil)))
 
4592
      '(set-raw-mode-off state)
 
4593
    '(set-raw-mode-on state)))
 
4594
 
 
4595
#-acl2-loop-only
 
4596
(defun-one-output stobj-out (val)
 
4597
 
 
4598
; Warning:  This function assumes that we are not in the context of a local
 
4599
; stobj.  As of this writing, it is only used in raw mode, so this does not
 
4600
; concern us too much.  With raw mode, there are no guarantees.
 
4601
 
 
4602
  (if (eq val *the-live-state*)
 
4603
      'state
 
4604
    (car (rassoc val *user-stobj-alist* :test 'eq))))
 
4605
 
 
4606
#-(or acl2-loop-only acl2-mv-as-values)
 
4607
(defun mv-ref! (i)
 
4608
 
 
4609
; This silly function is just mv-ref, but without the restriction that the
 
4610
; argument be an explicit number.
 
4611
 
 
4612
  (case i
 
4613
    (1 (mv-ref 1))
 
4614
    (2 (mv-ref 2))
 
4615
    (3 (mv-ref 3))
 
4616
    (4 (mv-ref 4))
 
4617
    (5 (mv-ref 5))
 
4618
    (6 (mv-ref 6))
 
4619
    (7 (mv-ref 7))
 
4620
    (8 (mv-ref 8))
 
4621
    (9 (mv-ref 9))
 
4622
    (10 (mv-ref 10))
 
4623
    (11 (mv-ref 11))
 
4624
    (12 (mv-ref 12))
 
4625
    (13 (mv-ref 13))
 
4626
    (14 (mv-ref 14))
 
4627
    (15 (mv-ref 15))
 
4628
    (16 (mv-ref 16))
 
4629
    (17 (mv-ref 17))
 
4630
    (18 (mv-ref 18))
 
4631
    (19 (mv-ref 19))
 
4632
    (20 (mv-ref 20))
 
4633
    (21 (mv-ref 21))
 
4634
    (22 (mv-ref 22))
 
4635
    (23 (mv-ref 23))
 
4636
    (24 (mv-ref 24))
 
4637
    (25 (mv-ref 25))
 
4638
    (26 (mv-ref 26))
 
4639
    (27 (mv-ref 27))
 
4640
    (28 (mv-ref 28))
 
4641
    (29 (mv-ref 29))
 
4642
    (30 (mv-ref 30))
 
4643
    (31 (mv-ref 31))
 
4644
    (otherwise (error "Illegal value for mv-ref!"))))
 
4645
 
 
4646
(defmacro add-raw-arity (name val)
 
4647
  (declare (xargs :guard (and (symbolp name)
 
4648
                              (or (and (integerp val) (<= 0 val))
 
4649
                                  (eq val :last)))))
 
4650
 
 
4651
  ":Doc-Section Set-raw-mode
 
4652
 
 
4653
  add arity information for raw mode~/
 
4654
 
 
4655
  Technical note: This macro is a no-op, and is not necessary, when ACL2 is
 
4656
  built with #-acl2-mv-as-values.
 
4657
 
 
4658
  Users of raw mode (~pl[set-raw-mode]) can use arbitrary raw Lisp functions
 
4659
  that are not known inside the usual ACL2 loop.  In such cases, ACL2 may not
 
4660
  know how to display a multiple value returned by ACL2's ~ilc[mv] macro.  The
 
4661
  following example should make this clear.
 
4662
  ~bv[]
 
4663
  ACL2 P>(defun foo (x y) (mv y x))
 
4664
  FOO
 
4665
  ACL2 P>(foo 3 4)
 
4666
 
 
4667
  Note: Unable to compute number of values returned by this evaluation
 
4668
  because function FOO is not known in the ACL2 logical world.  Presumably
 
4669
  it was defined in raw Lisp or in raw mode.  Returning the first (perhaps
 
4670
  only) value for calls of FOO.
 
4671
  4
 
4672
  ACL2 P>(add-raw-arity foo 2)
 
4673
   RAW-ARITY-ALIST
 
4674
  ACL2 P>(foo 3 4)
 
4675
  (4 3)
 
4676
  ACL2 P>
 
4677
  ~ev[]
 
4678
  The first argument of ~c[add-raw-arity] should be a symbol, representing the
 
4679
  name of a function, macro, or special form, and the second argument should
 
4680
  either be a non-negative integer (denoting the number of values returned by
 
4681
  ACL2) or else the symbol ~c[:LAST], meaning that the number of values
 
4682
  returned by the call is the number of values returned by the last
 
4683
  argument.~/
 
4684
 
 
4685
  The current arity assignments can be seen by evaluating
 
4686
  ~c[(@ raw-arity-alist)].  ~l[remove-raw-arity] for how to undo a call of
 
4687
  ~c[add-raw-arity].~/"
 
4688
 
 
4689
  #+acl2-mv-as-values (declare (ignore name val))
 
4690
  #+acl2-mv-as-values '(value nil)
 
4691
  #-acl2-mv-as-values
 
4692
  `(pprogn (f-put-global 'raw-arity-alist
 
4693
                         (put-assoc-eq ',name
 
4694
                                       ,val
 
4695
                                       (f-get-global 'raw-arity-alist state))
 
4696
                         state)
 
4697
           (value 'raw-arity-alist)))
 
4698
 
 
4699
(defmacro remove-raw-arity (name)
 
4700
  (declare (xargs :guard (symbolp name)))
 
4701
 
 
4702
  ":Doc-Section Set-raw-mode
 
4703
 
 
4704
  remove arity information for raw mode~/
 
4705
 
 
4706
  Technical note: This macro is a no-op, and is not necessary, when ACL2 is
 
4707
  built with #-acl2-mv-as-values.
 
4708
 
 
4709
  The form ~c[(remove-raw-arity fn)] undoes the effect of an earlier
 
4710
  ~c[(remove-raw-arity fn val)].  ~l[add-raw-arity].~/~/"
 
4711
 
 
4712
  #+acl2-mv-as-values (declare (ignore name))
 
4713
  #+acl2-mv-as-values '(value nil)
 
4714
  #-acl2-mv-as-values
 
4715
  `(pprogn (f-put-global 'raw-arity-alist
 
4716
                         (delete-assoc-eq ',name
 
4717
                                          (f-get-global 'raw-arity-alist
 
4718
                                                        state))
 
4719
                         state)
 
4720
           (value 'raw-arity-alist)))
 
4721
 
 
4722
#-(or acl2-loop-only acl2-mv-as-values)
 
4723
(defun raw-arity (form wrld state)
 
4724
  (cond
 
4725
   ((atom form) 1)
 
4726
   ((eq (car form) 'mv)
 
4727
    (length (cdr form)))
 
4728
   ((eq (car form) 'if)
 
4729
    (let ((arity1 (raw-arity (caddr form) wrld state)))
 
4730
      (if (cdddr form)
 
4731
          (let ((arity2 (raw-arity (cadddr form) wrld state)))
 
4732
            (if (eql arity1 arity2)
 
4733
                arity1
 
4734
              (let ((min-arity (min arity1 arity2)))
 
4735
                (prog2$
 
4736
                 (warning$ 'top-level "Raw"
 
4737
                           "Unable to compute arity of the following ~
 
4738
                            IF-expression in raw mode because the true branch ~
 
4739
                            has arity ~x0 but the false branch has arity ~x1, ~
 
4740
                            so we assume an arity of ~x2 ~
 
4741
                            (see :DOC add-raw-arity):~%  ~x3."
 
4742
                           arity1 arity2 min-arity form)
 
4743
                 min-arity))))
 
4744
        arity1)))
 
4745
   (t (let ((arity (cdr (assoc-eq (car form)
 
4746
                                  (f-get-global 'raw-arity-alist state)))))
 
4747
        (cond
 
4748
         ((eq arity :last)
 
4749
          (raw-arity (car (last form)) wrld state))
 
4750
         ((and (integerp arity)
 
4751
               (<= 0 arity))
 
4752
          arity)
 
4753
         (arity
 
4754
          (error "Ill-formed value of *raw-arity-alist*."))
 
4755
         (t
 
4756
          (let ((stobjs-out
 
4757
                 (getprop (car form) 'stobjs-out t 'current-acl2-world wrld)))
 
4758
            (cond
 
4759
             ((eq stobjs-out t)
 
4760
              (multiple-value-bind
 
4761
               (new-form flg)
 
4762
               (macroexpand-1 form)
 
4763
               (cond ((null flg)
 
4764
 
 
4765
; Remember that our notion of multiple value here is ACL2's notion, not Lisp's
 
4766
; notion.  So the arity is 1 for calls of Common Lisp functions.
 
4767
 
 
4768
                      (when (not (member-eq
 
4769
                                  (car form)
 
4770
                                  *common-lisp-symbols-from-main-lisp-package*))
 
4771
                        (fms "Note: Unable to compute number of values ~
 
4772
                              returned by this evaluation because function ~x0 ~
 
4773
                              is not known in the ACL2 logical world.  ~
 
4774
                              Presumably it was defined in raw Lisp or in raw ~
 
4775
                              mode.  Returning the first (perhaps only) value ~
 
4776
                              for calls of ~x0.  See :DOC add-raw-arity.~|"
 
4777
                             (list (cons #\0 (car form)))
 
4778
                             *standard-co* state nil))
 
4779
                      1)
 
4780
                     (t (raw-arity new-form wrld state)))))
 
4781
             (t (length stobjs-out))))))))))
 
4782
 
 
4783
(defun alist-to-bindings (alist)
 
4784
  (cond
 
4785
   ((endp alist) nil)
 
4786
   (t (cons (list (caar alist) (kwote (cdar alist)))
 
4787
            (alist-to-bindings (cdr alist))))))
 
4788
 
 
4789
#-acl2-loop-only
 
4790
(defun-one-output acl2-raw-eval-form-to-eval (form)
 
4791
  `(let ((state *the-live-state*)
 
4792
         ,@(alist-to-bindings *user-stobj-alist*))
 
4793
 
 
4794
; OpenMCL prints "Unused lexical variable" warnings unless we take some
 
4795
; measures, which we do now.  We notice that we need to include #+cmu for the
 
4796
; second form, so we might as well include it for the first, too.
 
4797
 
 
4798
     #+(or openmcl cmu sbcl)
 
4799
     ,@(mapcar #'(lambda (x) `(declare (ignorable ,(car x))))
 
4800
               *user-stobj-alist*)
 
4801
     #+(or openmcl cmu sbcl)
 
4802
     (declare (ignorable state))
 
4803
     ,(cond ((and (consp form)
 
4804
                  (eq (car form) 'in-package)
 
4805
                  (or (and (consp (cdr form))
 
4806
                           (null (cddr form)))
 
4807
                      (er hard 'top-level
 
4808
                          "IN-PACKAGE takes one argument.  The form ~p0 is ~
 
4809
                           thus illegal."
 
4810
                          form)))
 
4811
 
 
4812
; The package must be one that ACL2 knows about, or there are likely to be
 
4813
; problems involving the prompt and the ACL2 reader.  Also, we want the
 
4814
; in-package form to reflect in the prompt.
 
4815
 
 
4816
             (list 'in-package-fn (list 'quote (cadr form)) 'state))
 
4817
            (t form))))
 
4818
 
 
4819
#-(or acl2-loop-only acl2-mv-as-values)
 
4820
(defun acl2-raw-eval (form state)
 
4821
  (or (eq state *the-live-state*)
 
4822
      (error "Unexpected state in acl2-raw-eval!"))
 
4823
  (if (or (eq form :q) (equal form '(EXIT-LD STATE)))
 
4824
      (mv nil '((NIL NIL STATE) NIL :Q REPLACED-STATE) state)
 
4825
    (let ((val (eval (acl2-raw-eval-form-to-eval form)))
 
4826
          (index-bound (raw-arity form (w state) state)))
 
4827
      (if (<= index-bound 1)
 
4828
          (mv nil (cons (list (stobj-out val)) val) state)
 
4829
        (let ((ans nil)
 
4830
              (stobjs-out nil))
 
4831
          (do ((i (1- index-bound) (1- i)))
 
4832
              ((eql i 0))
 
4833
              (let ((x (mv-ref! i)))
 
4834
                (push x ans)
 
4835
                (push (stobj-out x)
 
4836
                      stobjs-out)))
 
4837
          (mv nil
 
4838
              (cons (cons (stobj-out val) stobjs-out)
 
4839
                    (cons val ans))
 
4840
              state))))))
 
4841
 
 
4842
#+(and (not acl2-loop-only) acl2-mv-as-values)
 
4843
(defun acl2-raw-eval (form state)
 
4844
  (or (eq state *the-live-state*)
 
4845
      (error "Unexpected state in acl2-raw-eval!"))
 
4846
  (if (or (eq form :q) (equal form '(EXIT-LD STATE)))
 
4847
      (mv nil '((NIL NIL STATE) NIL :Q REPLACED-STATE) state)
 
4848
    (let* ((vals (multiple-value-list
 
4849
                  (eval (acl2-raw-eval-form-to-eval form))))
 
4850
           (arity (length vals)))
 
4851
      (if (<= arity 1)
 
4852
          (let ((val (car vals)))
 
4853
            (mv nil (cons (list (stobj-out val)) val) state))
 
4854
        (mv nil
 
4855
            (loop for val in vals
 
4856
                  collect (stobj-out val) into stobjs-out
 
4857
                  finally (return (cons stobjs-out vals)))
 
4858
            state)))))
 
4859
 
 
4860
#+acl2-loop-only
 
4861
(defun acl2-raw-eval (form state)
 
4862
  (trans-eval form 'top-level state))
 
4863
 
 
4864
(defun get-and-chk-last-make-event-expansion (form wrld ctx state names)
 
4865
  (let ((expansion (f-get-global 'last-make-event-expansion state)))
 
4866
    (cond
 
4867
     (expansion
 
4868
      (mv-let
 
4869
       (erp val state)
 
4870
       (state-global-let*
 
4871
        ((inhibit-output-lst *valid-output-names*))
 
4872
        (chk-embedded-event-form form
 
4873
                                 nil ; orig-form
 
4874
                                 wrld ctx state names
 
4875
                                 nil ; portcullisp
 
4876
                                 nil ; in-local-flg
 
4877
                                 nil ; in-encapsulatep
 
4878
                                 nil ; make-event-chk
 
4879
                                 ))
 
4880
       (declare (ignore val))
 
4881
       (cond (erp (er soft ctx
 
4882
                      "Make-event is only legal in event contexts, where it ~
 
4883
                       can be tracked properly; see :DOC embedded-event-form.  ~
 
4884
                       The form ~p0 has thus generated an illegal call of ~
 
4885
                       make-event.  This form's evaluation will have no ~
 
4886
                       effect on the ACL2 logical world."
 
4887
                      form))
 
4888
             (t (value expansion)))))
 
4889
     (t (value nil)))))
 
4890
 
 
4891
(defun eval-event-lst (index expansion-alist ev-lst quietp in-encapsulatep
 
4892
                             in-local-flg last-val other-control ctx channel
 
4893
                             state)
4342
4894
 
4343
4895
; This function takes a true list of forms, ev-lst, and successively evals each
4344
4896
; one, cascading state through successive elements.  However, it insists that
4345
4897
; each form is an embedded-event-form.  We return a tuple (mv erp value
4346
 
; expansion-alist state): erp is 'non-event if some member of ev-lst is not an
4347
 
; embedded event form and is t or nil otherwise; and if erp is nil, then value
4348
 
; is the final value (or nil if ev-lst is empty), and expansion-alist
4349
 
; associates the (+ index n)th member E of ev-lst with its expansion if there
4350
 
; is was any make-event expansion subsidiary to E, and is ordered by index from
4351
 
; smallest to largest (accumulated in reverse order).
 
4898
; expansion-alist state), where erp is 'non-event if some member of ev-lst is
 
4899
; not an embedded event form and otherwise is as explained below.  If erp is
 
4900
; nil, then value is the final value (or nil if ev-lst is empty), and
 
4901
; expansion-alist associates the (+ index n)th member E of ev-lst with its
 
4902
; expansion if there was any make-event expansion subsidiary to E, ordered by
 
4903
; index from smallest to largest (accumulated in reverse order).  If erp is not
 
4904
; nil, then let n be the (zero-based) index of the event in ev-lst that
 
4905
; translated or evaluated to some (mv erp0 ...) with non-nil erp0.  Then we
 
4906
; return (mv t (+ index n) state) if the error was during translation, else (mv
 
4907
; (list erp0) (+ index n) state).  Except, in the special case that there is no
 
4908
; error but we find that make-event was called under some non-embedded-event
 
4909
; form, we return (mv 'make-event-problem (+ index n) state).
 
4910
 
 
4911
; Other-control is either :non-event-ok, used for progn!, or else t or nil for
 
4912
; the make-event-chk in chk-embedded-event-form.
4352
4913
 
4353
4914
; Channel is generally (proofs-co state), but doesn't have to be.
4354
4915
 
4355
 
; If orig-form is non-nil, then it will be mentioned in error reporting by
4356
 
; chk-embedded-event-form.  This is the only use of orig-form.
4357
 
 
4358
4916
; A non-nil value of quietp suppresses printing of the event and the result.
4359
4917
 
4360
4918
  (cond
4383
4941
                   channel state nil))))
4384
4942
       (mv-let
4385
4943
        (erp form state)
4386
 
        (chk-embedded-event-form (car ev-lst)
4387
 
                                 orig-form
4388
 
                                 (w state)
4389
 
                                 ctx state
4390
 
                                 *primitive-event-macros*
4391
 
                                 nil
4392
 
                                 in-local-flg
4393
 
                                 in-encapsulatep
4394
 
                                 make-event-chk)
 
4944
        (cond ((eq other-control :non-event-ok)
 
4945
               (mv nil (car ev-lst) state))
 
4946
              (t (chk-embedded-event-form (car ev-lst)
 
4947
                                          nil
 
4948
                                          (w state)
 
4949
                                          ctx state
 
4950
                                          *primitive-event-macros*
 
4951
                                          nil
 
4952
                                          in-local-flg
 
4953
                                          in-encapsulatep
 
4954
                                          other-control)))
4395
4955
        (cond
4396
4956
         (erp (mv 'non-event index nil state))
4397
4957
         ((null form)
4398
 
          (eval-event-lst (1+ index) expansion-alist (cdr ev-lst) orig-form
4399
 
                          quietp in-encapsulatep in-local-flg nil
4400
 
                          make-event-chk ctx channel state))
 
4958
          (eval-event-lst (1+ index) expansion-alist (cdr ev-lst) quietp
 
4959
                          in-encapsulatep in-local-flg nil other-control ctx
 
4960
                          channel state))
4401
4961
         (t
4402
4962
          (mv-let
4403
4963
           (erp trans-ans state)
4404
4964
           (pprogn (f-put-global 'last-make-event-expansion nil state)
4405
 
                   (trans-eval form ctx state))
 
4965
                   (if (raw-mode-p state)
 
4966
                       (acl2-raw-eval form state)
 
4967
                     (trans-eval form ctx state)))
4406
4968
 
4407
4969
; If erp is nil, trans-ans is 
4408
4970
; ((nil nil state) . (erp' val' replaced-state))
4409
4971
; because ev-lst contains nothing but embedded event forms.
4410
4972
 
4411
 
           (let ((erp-prime (car (cdr trans-ans)))
4412
 
                 (val-prime (cadr (cdr trans-ans))))
 
4973
           (let* ((tuple
 
4974
                   (cond ((eq other-control :non-event-ok)
 
4975
                          (let* ((stobjs-out (car trans-ans))
 
4976
                                 (result (replace-stobjs stobjs-out (cdr trans-ans))))
 
4977
                            (if (null (cdr stobjs-out)) ; single value
 
4978
                                (list nil result)
 
4979
                              result)))
 
4980
                         (t (cdr trans-ans))))
 
4981
                  (erp-prime (car tuple))
 
4982
                  (val-prime (cadr tuple)))
4413
4983
             (cond
4414
 
              ((or erp erp-prime)
4415
 
 
4416
 
; These two sources of errors might be distinguished as those that
4417
 
; arise from an unsuccessful attempt to translate and evaluate a form
4418
 
; (if erp is non-nil) and those from the successful translation and
4419
 
; evaluation of a form that led to a call of error (if erp' is
4420
 
; non-nil).
4421
 
 
 
4984
              (erp
4422
4985
               (mv t index nil state))
 
4986
              (erp-prime
 
4987
               (mv (list erp-prime) index nil state))
4423
4988
              (t
4424
4989
               (pprogn
4425
4990
                (cond (quietp state)
4426
4991
                      (t (pprogn (ppr val-prime 0 channel state nil)
4427
4992
                                 (newline channel state))))
4428
 
                (let ((expansion0 (f-get-global 'last-make-event-expansion
4429
 
                                                state)))
4430
 
                  (eval-event-lst
4431
 
                   (1+ index)
4432
 
                   (cond
4433
 
                    (expansion0
4434
 
                     (acons index
4435
 
                            (list 'record-expansion
4436
 
                                  (car ev-lst)
4437
 
                                  (mv-let (wrappers base-form)
4438
 
                                          (destructure-expansion form)
4439
 
                                          (declare (ignore base-form))
4440
 
                                          (rebuild-expansion wrappers
4441
 
                                                             expansion0)))
4442
 
                            expansion-alist))
4443
 
                    (t expansion-alist))
4444
 
                   (cdr ev-lst) orig-form quietp
4445
 
                   in-encapsulatep in-local-flg val-prime
4446
 
                   make-event-chk ctx channel
4447
 
                   state))))))))))))))
 
4993
                (mv-let
 
4994
                 (erp expansion0 state)
 
4995
 
 
4996
; We need to cause an error if we have an expansion but are not properly
 
4997
; tracking expansions.  For purposes of seeing if such tracking is being done,
 
4998
; it should suffice to do the check in the present world rather than the world
 
4999
; present before evaluating the form.
 
5000
 
 
5001
                 (get-and-chk-last-make-event-expansion
 
5002
                  (car ev-lst) (w state) ctx state *primitive-event-macros*)
 
5003
                 (cond
 
5004
                  (erp (mv 'make-event-problem index nil state))
 
5005
                  (t
 
5006
                   (eval-event-lst
 
5007
                    (1+ index)
 
5008
                    (cond
 
5009
                     (expansion0
 
5010
                      (acons index
 
5011
                             (list 'record-expansion
 
5012
                                   (car ev-lst)
 
5013
                                   (mv-let (wrappers base-form)
 
5014
                                           (destructure-expansion form)
 
5015
                                           (declare (ignore base-form))
 
5016
                                           (rebuild-expansion wrappers
 
5017
                                                              expansion0)))
 
5018
                             expansion-alist))
 
5019
                     (t expansion-alist))
 
5020
                    (cdr ev-lst) quietp
 
5021
                    in-encapsulatep in-local-flg val-prime
 
5022
                    other-control ctx channel
 
5023
                    state))))))))))))))))
4448
5024
 
4449
5025
; After we have evaluated the event list and obtained wrld2, we
4450
5026
; will scrutinize the signatures and exports to make sure they are
4454
5030
; paid a high price to get to wrld2 and it is a real pity that we'll
4455
5031
; blow him out of the water now.  The guilt!  It's enough to make us
4456
5032
; think about implementing some sort of interactive version of
4457
 
; encapsulate, when we don't have anything else to do.
 
5033
; encapsulate, when we don't have anything else to do.  (We have since
 
5034
; implemented redo-flat, which helps with the guilt.)
4458
5035
 
4459
5036
(defun equal-insig (insig1 insig2)
4460
5037
 
4943
5520
               0 nil
4944
5521
               `((table acl2-defaults-table nil
4945
5522
                        ',acl2-defaults-table :clear))
4946
 
               nil ; orig-form
4947
5523
               (ld-skip-proofsp state)
4948
5524
               t ; use strict value of in-encapsulatep, but shouldn't matter
4949
5525
               (f-get-global 'in-local-flg state)
5128
5704
                                        (pbt ',label)))))))))))
5129
5705
 
5130
5706
(defun process-embedded-events
5131
 
  (caller orig-form acl2-defaults-table skip-proofsp pkg ee-entry ev-lst index
5132
 
          make-event-chk ctx state)
 
5707
  (caller acl2-defaults-table skip-proofsp pkg ee-entry ev-lst index
 
5708
  make-event-chk ctx state)
5133
5709
 
5134
5710
; Warning: This function uses set-w and hence may only be called within a
5135
5711
; revert-world-on-error.  See the statement of policy in set-w.
5140
5716
; 'defstobj.  Note: There is no function encapsulate-pass-1, but it is still a
5141
5717
; ``caller.''
5142
5718
 
5143
 
; Acl2-defaults-table is a legal defaults alist.  That alist is installed as
5144
 
; the acl2-defaults-table (if it is not already there) after executing the
5145
 
; events in ev-lst.
 
5719
; Acl2-defaults-table is either a legal alist value for acl2-defaults-table or
 
5720
; else is :do-not-install.  If the former, then that alist is installed as the
 
5721
; acl2-defaults-table (if it is not already there) after executing the events
 
5722
; in ev-lst.
5146
5723
 
5147
5724
; The name ee-entry stands for ``embedded-event-lst'' entry.  It is
5148
5725
; consed onto the embedded-event-lst for the duration of the processing
5193
5770
; with this proto-wrld3.
5194
5771
 
5195
5772
; If an error is caused by the attempt to embed the events, we print a warning
5196
 
; message explaining and pass the error up.  If orig-form is non-nil, then it
5197
 
; will be mentioned in error reporting by chk-embedded-event-form.  This is the
5198
 
; only use of orig-form.
 
5773
; message explaining and pass the error up.
5199
5774
 
5200
5775
; The world names used here are consistent with the encapsulate essay.
5201
5776
 
5282
5857
                         (t state))
5283
5858
                   (eval-event-lst index nil
5284
5859
                                   ev-lst
5285
 
                                   orig-form
5286
5860
                                   (ld-skip-proofsp state)
5287
5861
                                   (in-encapsulatep new-embedded-event-lst nil)
5288
5862
                                   (f-get-global 'in-local-flg state)
5294
5868
                                    (t state))
5295
5869
                              (mv erp val state)))
5296
5870
                        (t (er-progn
5297
 
                            (maybe-install-acl2-defaults-table
5298
 
                             acl2-defaults-table ctx state)
 
5871
                            (if (eq acl2-defaults-table :do-not-install)
 
5872
                                (value nil)
 
5873
                              (maybe-install-acl2-defaults-table
 
5874
                               acl2-defaults-table ctx state))
5299
5875
                            (value expansion-alist)))))))
5300
5876
               (cond
5301
5877
                (erp
5309
5885
                 (cond
5310
5886
                  ((eq caller 'defstobj)
5311
5887
                   (value (er hard ctx
5312
 
                              "An error has occurred while DEFSTOBJ ~
5313
 
                               was defining the supporting functions. ~
5314
 
                                This is supposed to be impossible!  ~
5315
 
                               Please report this error to ~
5316
 
                               moore@cs.utexas.edu.")))
 
5888
                              "An error has occurred while DEFSTOBJ was ~
 
5889
                               defining the supporting functions.  This is ~
 
5890
                               supposed to be impossible!  Please report this ~
 
5891
                               error to the ACL2 implementors.")))
5317
5892
                  (t
5318
5893
                   (pprogn
5319
5894
                    (warning$ ctx nil
5445
6020
              (t (cons (cons names nil)
5446
6021
                       (collect-t-machines (cdr fns) wrld seen))))))))
5447
6022
 
5448
 
(defun collect-instantiables (fns wrld)
5449
 
  (cond ((endp fns) nil)
5450
 
        ((instantiablep (car fns) wrld)
5451
 
         (cons (car fns) (collect-instantiables (cdr fns) wrld)))
5452
 
        (t (collect-instantiables (cdr fns) wrld))))
5453
 
 
5454
6023
(defun subversivep (fns t-machine)
5455
6024
 
5456
6025
; See subversive-cliquep for conditions (1) and (2).
5465
6034
                               (fargs (access tests-and-call
5466
6035
                                              (car t-machine)
5467
6036
                                              :call))))
5468
 
 
5469
6037
               (subversivep fns (cdr t-machine))))))
5470
6038
 
5471
6039
(defun subversive-cliquep (fns t-machines)
5722
6290
; encountered a defun, or because some non-subversive definition is
5723
6291
; ancestral in the constraint.
5724
6292
 
5725
 
; We do not actually rearrange anything.   Instead, we compute the constraint
5726
 
; formula generated by this encapsulate as though we had pulled certain
5727
 
; defuns and defchooses out before generating it.
5728
 
 
 
6293
; We do not actually rearrange anything.  Instead, we compute the constraint
 
6294
; formula generated by this encapsulate as though we had pulled certain defuns
 
6295
; and defchooses out before generating it.
5729
6296
 
5730
6297
  (let* ((rearrange-eventsp
5731
6298
          (and (not (in-encapsulatep
5792
6359
                                  *acl2-property-unbound*
5793
6360
                                  wrld)))
5794
6361
 
5795
 
(defun encapsulate-pass-2 (insigs event-form ev-lst saved-acl2-defaults-table
5796
 
                                  only-pass-p ctx state)
 
6362
(defun encapsulate-pass-2 (insigs ev-lst saved-acl2-defaults-table only-pass-p
 
6363
                                  ctx state)
5797
6364
 
5798
6365
; Warning: This function uses set-w and hence may only be called
5799
6366
; within a revert-world-on-error.  See the statement of policy in
5853
6420
                  (and (f-get-global 'in-local-flg state)
5854
6421
                       'dynamic)))
5855
6422
                (process-embedded-events 'encapsulate-pass-2
5856
 
                                         event-form
5857
6423
                                         saved-acl2-defaults-table
5858
6424
                                         'include-book
5859
6425
                                         (current-package state)
7206
7772
 
7207
7773
                      (and (f-get-global 'in-local-flg state)
7208
7774
                           'dynamic)))
7209
 
                   (process-embedded-events 'encapsulate-pass-1
7210
 
                                            event-form
7211
 
                                            saved-acl2-defaults-table
7212
 
                                            (ld-skip-proofsp state)
7213
 
                                            (current-package state)
7214
 
                                            (list 'encapsulate insigs)
7215
 
                                            ev-lst 0 nil ctx state))))
7216
 
                 (let ((wrld2 (w state)))
 
7775
                    (process-embedded-events
 
7776
                     'encapsulate-pass-1
 
7777
                     saved-acl2-defaults-table
 
7778
                     (ld-skip-proofsp state)
 
7779
                     (current-package state)
 
7780
                     (list 'encapsulate insigs)
 
7781
                     ev-lst 0 nil ctx state))))
 
7782
                 (let* ((wrld2 (w state))
 
7783
                        (post-pass-1-ttags-seen (global-val 'ttags-seen
 
7784
                                                            wrld2)))
7217
7785
                   (pprogn
7218
7786
                    (print-encapsulate-msg2 insigs ev-lst state)
7219
7787
                    (er-progn
7230
7798
; error above.
7231
7799
                          (encapsulate-pass-2
7232
7800
                           insigs
7233
 
                           event-form
7234
7801
                           new-ev-lst
7235
7802
                           saved-acl2-defaults-table nil ctx state)))
7236
7803
                        (let ((wrld3 (w state))
7251
7818
                           (f-put-global 'last-make-event-expansion
7252
7819
                                         new-event-form
7253
7820
                                         state)
7254
 
                           (install-event t
7255
 
                                          (or new-event-form event-form)
7256
 
                                          'encapsulate
7257
 
                                          (strip-cars insigs)
7258
 
                                          nil nil
7259
 
                                          t
7260
 
                                          ctx
7261
 
                                          (encapsulate-fix-known-package-alist
7262
 
                                           pass1-known-package-alist
7263
 
                                           wrld3)
7264
 
                                          state)))))))))))))
 
7821
                           (install-event
 
7822
                            t
 
7823
                            (or new-event-form event-form)
 
7824
                            'encapsulate
 
7825
                            (strip-cars insigs)
 
7826
                            nil nil
 
7827
                            t
 
7828
                            ctx
 
7829
                            (let ((wrld4 (encapsulate-fix-known-package-alist
 
7830
                                          pass1-known-package-alist
 
7831
                                          wrld3)))
 
7832
                              (global-set? 'ttags-seen
 
7833
                                           post-pass-1-ttags-seen
 
7834
                                           wrld4
 
7835
                                           (global-val 'ttags-seen wrld3)))
 
7836
                            state)))))))))))))
7265
7837
 
7266
7838
           (t ; (ld-skip-proofsp state) = 'include-book
7267
7839
          ;;;                         'include-book-with-locals or
7282
7854
 
7283
7855
                 ((expansion-alist
7284
7856
                   (encapsulate-pass-2
7285
 
                    insigs event-form ev-lst saved-acl2-defaults-table t ctx
7286
 
                    state)))
 
7857
                    insigs ev-lst saved-acl2-defaults-table t ctx state)))
7287
7858
                 (let ((wrld3 (w state))
7288
7859
                       (new-event-form
7289
7860
                        (and expansion-alist
7316
7887
                                   wrld3
7317
7888
                                   state)))))))))))))))
7318
7889
 
7319
 
(defun progn-fn (ev-lst state)
 
7890
(defun progn-fn1 (ev-lst progn!p state)
7320
7891
 
7321
7892
; Important Note:  Don't change the formals of this function without reading
7322
7893
; the *initial-event-defmacros* discussion in axioms.lisp.
7323
7894
 
7324
7895
  (let ((ctx (cond (ev-lst
7325
 
                    (msg "( PROGN ~@0 ...)"
 
7896
                    (msg "( PROGN~s0 ~@1 ...)"
 
7897
                         (if progn!p "!" "")
7326
7898
                         (tilde-@-abbreviate-object-phrase (car ev-lst))))
7327
 
                   (t "( PROGN)")))
 
7899
                   (t (if progn!p "( PROGN~)" "( PROGN)"))))
7328
7900
        (in-encapsulatep
7329
7901
         (in-encapsulatep (global-val 'embedded-event-lst (w state)) nil)))
7330
7902
    (with-ctx-summarized
7338
7910
        (eval-event-lst
7339
7911
         0 nil
7340
7912
         ev-lst
7341
 
         (cons 'progn ev-lst)
7342
7913
         t ; quietp
7343
7914
         in-encapsulatep
7344
7915
         (f-get-global 'in-local-flg state)
7345
7916
         nil
 
7917
         (if progn!p
 
7918
             :non-event-ok
7346
7919
 
7347
7920
; It is unknown here whether make-event must have a consp :check-expansion, but
7348
7921
; if this progn is in such a context, chk-embedded-event-form will check that
7349
7922
; for us.
7350
7923
 
7351
 
         nil
 
7924
           nil)
7352
7925
         ctx (proofs-co state) state))
7353
7926
       (pprogn
7354
7927
        (if erp
7359
7932
                   "PROGN may only be used on legal event forms (see :DOC ~
7360
7933
                   embedded-event-form).  Consider using ER-PROGN instead."))
7361
7934
              (erp (er soft ctx
7362
 
                       "PROGN failed!"))
 
7935
                       "~x0 failed!~@1"
 
7936
                       (if progn!p 'progn! 'progn)
 
7937
                       (if (and progn!p
 
7938
                                (consp erp))
 
7939
                           (msg "  Note that the ~n0 form evaluated to a ~
 
7940
                                 multiple value (mv erp ...) with non-nil ~
 
7941
                                 erp, ~X12; see :DOC progn!."
 
7942
                                (list (1+ val))
 
7943
                                (car erp)
 
7944
                                (default-evisc-tuple state))
 
7945
                         "")))
7363
7946
              (t (pprogn (f-put-global 'last-make-event-expansion
7364
7947
                                       (and expansion-alist
7365
 
                                            (cons 'progn
 
7948
                                            (cons (if progn!p 'progn! 'progn)
7366
7949
                                                  (subst-by-position
7367
7950
                                                   expansion-alist
7368
7951
                                                   ev-lst
7370
7953
                                       state)
7371
7954
                         (value val))))))))))
7372
7955
 
 
7956
(defun progn-fn (ev-lst state)
 
7957
  (progn-fn1 ev-lst nil state))
 
7958
 
 
7959
(defun progn!-fn (ev-lst state)
 
7960
  (state-global-let* ((acl2-raw-mode-p (f-get-global 'acl2-raw-mode-p state)))
 
7961
                     (progn-fn1 ev-lst t state)))
 
7962
 
7373
7963
(defun make-event-ctx (event-form)
7374
7964
  (msg "( MAKE-EVENT ~@0~@1)"
7375
7965
       (tilde-@-abbreviate-object-phrase (cadr event-form))
7381
7971
        (t (cons `(,(car names) (f-get-global ',(car names) state))
7382
7972
                 (state-global-bindings (cdr names))))))
7383
7973
 
 
7974
(defconst *initial-ld-special-bindings*
 
7975
 
 
7976
; This alist is used by initialize-acl2 to set the initial values of the LD
 
7977
; specials.  It is assumed by reset-ld-specials that the first three are the
 
7978
; channels.
 
7979
 
 
7980
  `((standard-oi . ,*standard-oi*)
 
7981
    (standard-co . ,*standard-co*)
 
7982
    (proofs-co . ,*standard-co*)
 
7983
    (ld-skip-proofsp . nil)
 
7984
    (ld-redefinition-action . nil)
 
7985
    (ld-prompt . t)
 
7986
    (ld-keyword-aliases . nil)
 
7987
    (ld-pre-eval-filter . :all)
 
7988
    (ld-pre-eval-print . nil)
 
7989
    (ld-post-eval-print . :command-conventions)
 
7990
    (ld-evisc-tuple . nil)
 
7991
    (ld-error-triples . t)
 
7992
    (ld-error-action . :continue)
 
7993
    (ld-query-control-alist . nil)
 
7994
    (ld-verbose . "~sv.  Level ~Fl.  Cbd ~xc.~%Type :help for help.~%~
 
7995
                   Type (good-bye) to quit completely out of ACL2.~%~%")))
 
7996
 
7384
7997
(defconst *protected-state-globals-for-make-event*
7385
7998
  (let ((val
7386
7999
         (set-difference-eq
7387
 
          (union-eq '(main-timer)
 
8000
          (union-eq (strip-cars *initial-ld-special-bindings*)
7388
8001
                    (strip-cars *initial-global-table*))
7389
 
          '(raw-mode-restore-lst       ;;; disable certify-book after raw mode
 
8002
          '(acl2-raw-mode-p            ;;; keep raw mode status
 
8003
            certify-book-disabledp     ;;; preserve disable of certify-book
7390
8004
            bddnotes                   ;;; for feedback after expansion failure
7391
8005
 
7392
8006
; We handle world and enabled structure installation ourselves, with set-w! and
7399
8013
            packages-created-by-defpkg ;;; keep around traces of defpkg forms
7400
8014
            saved-output-reversed      ;;; for feedback after expansion failure
7401
8015
            saved-output-p             ;;; for feedback after expansion failure
 
8016
            ttags-allowed              ;;; propagate changes outside expansion
7402
8017
 
7403
8018
; Note that tainted-okp is deliberately omitted from this list of exceptions,
7404
8019
; since its global value is the one that should be used during event
7564
8179
                   (wrappers base)
7565
8180
                   (destructure-expansion expansion1)
7566
8181
                   (cond
7567
 
                    ((member-eq (car base) '(make-event progn encapsulate))
 
8182
                    ((member-eq (car base)
 
8183
                                '(make-event progn progn! encapsulate))
7568
8184
                     (rebuild-expansion
7569
8185
                      wrappers
7570
8186
                      (f-get-global 'last-make-event-expansion state)))
7765
8381
; (full-book-name     ; "/usr/home/moore/project/arith.lisp"
7766
8382
;  user-book-name     ; "project/arith.lisp"
7767
8383
;  familiar-name      ; "arith"
7768
 
;  cert-annotations   ; ((:SKIPPED-PROOFSP . sp) (:AXIOMSP . axp))
 
8384
;  cert-annotations   ; ((:SKIPPED-PROOFSP . sp)
 
8385
;                        (:AXIOMSP . axp)
 
8386
;                        (:TTAGS . ttag-alistp))
7769
8387
;  . ev-lst-chk-sum)  ; 12345678
7770
8388
 
7771
 
; The include-book-alist becomes part of the certificate for a book,
7772
 
; playing a role in both the pre-alist and the post-alist.  In the
7773
 
; latter role some elements may be marked (LOCAL &).  When we refer to
7774
 
; parts of the include-book-alist entries we have tried to use the
7775
 
; tedious names above, to help us figure out what is used where.
7776
 
; Please try to preserve this convention.
 
8389
; The include-book-alist becomes part of the certificate for a book, playing a
 
8390
; role in both the pre-alist and the post-alist.  In the latter role some
 
8391
; elements may be marked (LOCAL &).  When we refer to parts of the
 
8392
; include-book-alist entries we have tried to use the tedious names above, to
 
8393
; help us figure out what is used where.  Please try to preserve this
 
8394
; convention.
7777
8395
 
7778
 
; Cert-annotations is an alist.  As of this writing (ACL2 Version_2.5)
7779
 
; the alist has two possible keys, :SKIPPED-PROOFSP and :AXIOMSP.  The
7780
 
; possible values of both are t, nil, or ?, indicating the presence, absence,
7781
 
; or possible presence of skip-proof forms or defaxioms, respectively.  The
7782
 
; forms in question may be either LOCAL or non-LOCAL and are in the book
7783
 
; itself (not just in some subbook).  Even though the cert-annotations is an
7784
 
; alist, we compare include-book-alists with equality on that component, not
7785
 
; ``alist equality.''  So we are NOT free to drop or rearrange keys in these
7786
 
; annotations.
 
8396
; Cert-annotations is an alist.  The alist has three possible keys:
 
8397
; :SKIPPED-PROOFSP, :AXIOMSP, and :TTAGS.  The possible values of the first two
 
8398
; are t, nil, or ?, indicating the presence, absence, or possible presence of
 
8399
; skip-proof forms or defaxioms, respectively.  The forms in question may be
 
8400
; either LOCAL or non-LOCAL and are in the book itself (not just in some
 
8401
; subbook).  Even though the cert-annotations is an alist, we compare
 
8402
; include-book-alists with equality on that component, not ``alist equality.''
 
8403
; So we are NOT free to drop or rearrange keys in these annotations.
7787
8404
 
7788
8405
; If the book is uncertified, the chk-sum entry is nil.
7789
8406
 
7790
 
; Suppose the two alist arguments are each include-book-alists from
7791
 
; different times.  We check that the first is a subset of the second,
7792
 
; in the sense that the (familiar-name cert-annotations . chk-sum)
7793
 
; parts of the first are all among those of the second.  We ignore the
7794
 
; full names and the user names because they may change as the book or
7795
 
; connected book directory moves around.
 
8407
; Suppose the two alist arguments are each include-book-alists from different
 
8408
; times.  We check that the first is a subset of the second, in the sense that
 
8409
; the (familiar-name cert-annotations . chk-sum) parts of the first are all
 
8410
; among those of the second.  We ignore the full names and the user names
 
8411
; because they may change as the book or connected book directory moves around.
7796
8412
 
7797
8413
  (subsetp-equal (strip-cddrs alist1)
7798
8414
                 (strip-cddrs alist2)))
7799
8415
 
7800
 
(defun remove-after-last-directory-separator (p)
7801
 
  (let* ((p-rev (reverse p))
7802
 
         (posn (position *directory-separator* p-rev)))
7803
 
    (if posn
7804
 
        (subseq p 0 (1- (- (length p) posn)))
7805
 
      (er hard 'remove-after-last-directory-separator
7806
 
          "Implementation error!  Unable to handle a directory string."))))
7807
 
 
7808
 
(defun merge-using-dot-dot (p s)
7809
 
 
7810
 
; P is a directory pathname without the final "/".  S is a pathname (for a file
7811
 
; or a directory) that may start with any number of sequences "../" and "./".
7812
 
; We want to "cancel" the leading "../"s in s against directories at the end of
7813
 
; p, and eliminate leading "./"s from s (including leading "." if that is all
7814
 
; of s).  The result should syntactically represent a directory (end with a "/"
7815
 
; or "."  or be "") if and only if s syntactically represents a directory.
7816
 
 
7817
 
; This code is intended to be simple, not necessarily efficient.
7818
 
 
7819
 
  (cond
7820
 
   ((equal p "") s)
7821
 
   ((equal s "..")
7822
 
    (concatenate 'string
7823
 
                 (remove-after-last-directory-separator p)
7824
 
                 *directory-separator-string*))
7825
 
   ((equal s ".")
7826
 
    (concatenate 'string
7827
 
                 p
7828
 
                 *directory-separator-string*))
7829
 
   ((and (>= (length s) 3)
7830
 
         (eql (char s 0) #\.)
7831
 
         (eql (char s 1) #\.)
7832
 
         (eql (char s 2) #\/))
7833
 
    (merge-using-dot-dot (remove-after-last-directory-separator p)
7834
 
                         (subseq s 3 (length s))))
7835
 
   ((and (>= (length s) 2)
7836
 
         (eql (char s 0) #\.)
7837
 
         (eql (char s 1) #\/))
7838
 
    (merge-using-dot-dot p (subseq s 2 (length s))))
7839
 
   (t
7840
 
    (concatenate 'string p *directory-separator-string* s))))
7841
 
 
7842
 
(defun our-merge-pathnames (p s)
7843
 
 
7844
 
; This is something like the Common Lisp function merge-pathnames.  P and s are
7845
 
; (Unix-style) pathname strings, where s is a relative pathname.  (If s may be
7846
 
; an absolute pathname, use extend-pathname instead.)  We allow p to be nil,
7847
 
; which is a case that arises when p is (f-get-global 'connected-book-directory
7848
 
; state) during boot-strapping; otherwise p should be an absolute directory
7849
 
; pathname (though we allow "" as well).
7850
 
 
7851
 
  (cond
7852
 
   ((and (not (equal s ""))
7853
 
         (eql (char s 0) *directory-separator*))
7854
 
    (er hard 'our-merge-pathnames
7855
 
        "Attempt to merge with an absolute filename, ~p0.  Please contact the ~
7856
 
         ACL2 implementors."
7857
 
        s))
7858
 
   ((or (null p) (equal p ""))
7859
 
    s)
7860
 
   ((stringp p) ; checked because of structured pathnames before Version_2.5
7861
 
    (merge-using-dot-dot
7862
 
     (if (eql (char p (1- (length p)))
7863
 
              *directory-separator*)
7864
 
         (subseq p 0 (1- (length p)))
7865
 
       p)
7866
 
     s))
7867
 
   (t
7868
 
    (er hard 'our-merge-pathnames
7869
 
        "The first argument of our-merge-pathnames must be a string, ~
7870
 
         but the following is not:  ~p0."
7871
 
        p))))
7872
 
 
7873
8416
(defun get-portcullis-cmds (wrld ans wrld-segs wrld-list names ctx state)
7874
8417
 
7875
8418
; When certify-book is called, we scan down wrld to collect all the user
7892
8435
             (mv nil ans wrld-segs (cons wrld wrld-list) state))
7893
8436
            (t (mv-let
7894
8437
                (erp val state)
7895
 
                (chk-embedded-event-form form form
 
8438
                (chk-embedded-event-form form nil
7896
8439
                                         wrld ctx state names t nil nil t)
7897
 
                (declare (ignore erp val))
7898
 
                (get-portcullis-cmds
7899
 
                 (cdr wrld)
7900
 
                 (cons form ans)
7901
 
                 (cons (world-to-next-command (cdr wrld) nil)
7902
 
                       wrld-segs)
7903
 
                 (cons wrld wrld-list)
7904
 
                 names ctx state))))))
 
8440
                (declare (ignore val))
 
8441
                (cond
 
8442
                 (erp (mv erp nil nil nil state))
 
8443
                 (t
 
8444
                  (get-portcullis-cmds
 
8445
                   (cdr wrld)
 
8446
                   (cons form ans)
 
8447
                   (cons (world-to-next-command (cdr wrld) nil)
 
8448
                         wrld-segs)
 
8449
                   (cons wrld wrld-list)
 
8450
                   names ctx state))))))))
7905
8451
   (t (get-portcullis-cmds (cdr wrld) ans wrld-segs wrld-list names ctx
7906
8452
                           state))))
7907
8453
 
8776
9322
; books as uncertified, except when the user has evaluated (set-tainted-okp t),
8777
9323
 
8778
9324
; Two state globals support handling of tainted books.  State global
8779
 
; 'in-certify-book-flg is generally nil, but is set to t while certifying a
8780
 
; book and transitions from t to 'tainted if we encounter inclusion of a book
8781
 
; that is either explicitly tainted or has a version mismatch of its incrl
8782
 
; field.  State global 'tainted-okp is initially nil, which disallows
8783
 
; certification of tainted books and treates included tainted books as
8784
 
; uncertified.  The user may call set-tainted-okp to set this variable to t in
8785
 
; order to allow include-book and certify book to accept tainted books fully,
8786
 
; albeit with "Tainted" warnings.
 
9325
; 'certify-book-info is generally nil, but is set to the full book name while
 
9326
; certifying a book and transitions from that to (list full-book-name) if we
 
9327
; encounter inclusion of a book that is either explicitly tainted or has a
 
9328
; version mismatch of its incrl field.  State global 'tainted-okp is initially
 
9329
; nil, which disallows certification of tainted books and treates included
 
9330
; tainted books as uncertified.  The user may call set-tainted-okp to set this
 
9331
; variable to t in order to allow include-book and certify book to accept
 
9332
; tainted books fully, albeit with "Tainted" warnings.
8787
9333
 
8788
9334
(defun decimal-string-to-number (s bound expo)
8789
9335
 
8956
9502
    0)
8957
9503
   (t 1)))
8958
9504
 
 
9505
(defun ttag-alistp (x)
 
9506
 
 
9507
; We don't check that pathnames are absolute, but that isn't important here.
 
9508
 
 
9509
  (cond ((atom x)
 
9510
         (null x))
 
9511
        (t (and (consp (car x))
 
9512
                (symbolp (caar x))
 
9513
                (string-listp (remove1 nil (cdar x)))
 
9514
                (ttag-alistp (cdr x))))))
 
9515
 
8959
9516
(defun cert-annotationsp (x)
8960
9517
  (case-match x
8961
 
              (((':SKIPPED-PROOFSP . sp)
8962
 
                (':AXIOMSP . ap))
8963
 
               (and (member sp '(t nil ?))
8964
 
                    (member ap '(t nil ?))
8965
 
                    t))
8966
 
              (& nil)))
 
9518
    (((':SKIPPED-PROOFSP . sp)
 
9519
      (':AXIOMSP . ap)
 
9520
      . ttags-singleton)
 
9521
     (and (member-eq sp '(t nil ?))
 
9522
          (member-eq ap '(t nil ?))
 
9523
          (or (null ttags-singleton)
 
9524
              (case-match ttags-singleton
 
9525
                (((':TTAGS . ttags))
 
9526
                 (ttag-alistp ttags))
 
9527
                (& nil)))))
 
9528
    (& nil)))
8967
9529
 
8968
9530
(defun include-book-alist-entryp (era entry)
8969
9531
  (case era
9038
9600
              (cadr entry)              ;;; user-book-name
9039
9601
              (caddr entry)             ;;; familiar-name
9040
9602
              '((:SKIPPED-PROOFSP . ?)  ;;; cert-annotations
9041
 
                (:AXIOMSP . ?))
 
9603
                (:AXIOMSP . ?)
 
9604
                (:TTAGS))
9042
9605
              (cdddr entry)))           ;;; ev-lst-chk-sum
9043
9606
    (t entry)))
9044
9607
 
9290
9853
              ((or eofp (not (eq key :begin-portcullis-cmds)))
9291
9854
               (er soft ctx *ill-formed-certificate-msg* file1 file2))
9292
9855
              (t (er-let* ((cert-obj
9293
 
                            (chk-raise-portcullis version file1 file2 ch skip-pre-alist-chkp
 
9856
                            (chk-raise-portcullis version file1 file2 ch
 
9857
                                                  skip-pre-alist-chkp
9294
9858
                                                  ctx state
9295
9859
                                                  suspect-book-action-alist
9296
9860
                                                  evalp)))
9297
9861
                   (cond (version-okp-tainted
9298
 
                          (pprogn (if (eq (f-get-global 'in-certify-book-flg
9299
 
                                                        state)
9300
 
                                          t)
9301
 
                                      (f-put-global 'in-certify-book-flg
9302
 
                                                    'tainted
9303
 
                                                    state)
9304
 
                                    state)
 
9862
                          (pprogn (let ((certify-book-info (f-get-global
 
9863
                                                            'certify-book-info
 
9864
                                                            state)))
 
9865
                                    (if (stringp certify-book-info)
 
9866
                                        (f-put-global 'certify-book-info
 
9867
                                                      (list certify-book-info)
 
9868
                                                      state)
 
9869
                                      state))
9305
9870
                                  (warning$ ctx "Tainted"
9306
9871
                                            "The book ~x0 is being treated as ~
9307
9872
                                             certified even though ~
9523
10088
                                            (os wrld) ctx state)))
9524
10089
                     (value (cons fixed-cmds pre-alist)))))))))
9525
10090
 
 
10091
; We next develop chk-well-formed-ttags.  But first we need to develop
 
10092
; extend-pathname, which is called by translate-book-names, which supports
 
10093
; chk-well-formed-ttags.
 
10094
 
 
10095
(defun remove-after-last-directory-separator (p)
 
10096
  (let* ((p-rev (reverse p))
 
10097
         (posn (position *directory-separator* p-rev)))
 
10098
    (if posn
 
10099
        (subseq p 0 (1- (- (length p) posn)))
 
10100
      (er hard 'remove-after-last-directory-separator
 
10101
          "Implementation error!  Unable to handle a directory string."))))
 
10102
 
 
10103
(defun merge-using-dot-dot (p s)
 
10104
 
 
10105
; P is a directory pathname without the final "/".  S is a pathname (for a file
 
10106
; or a directory) that may start with any number of sequences "../" and "./".
 
10107
; We want to "cancel" the leading "../"s in s against directories at the end of
 
10108
; p, and eliminate leading "./"s from s (including leading "." if that is all
 
10109
; of s).  The result should syntactically represent a directory (end with a "/"
 
10110
; or "."  or be "") if and only if s syntactically represents a directory.
 
10111
 
 
10112
; This code is intended to be simple, not necessarily efficient.
 
10113
 
 
10114
  (cond
 
10115
   ((equal p "") s)
 
10116
   ((equal s "..")
 
10117
    (concatenate 'string
 
10118
                 (remove-after-last-directory-separator p)
 
10119
                 *directory-separator-string*))
 
10120
   ((equal s ".")
 
10121
    (concatenate 'string
 
10122
                 p
 
10123
                 *directory-separator-string*))
 
10124
   ((and (>= (length s) 3)
 
10125
         (eql (char s 0) #\.)
 
10126
         (eql (char s 1) #\.)
 
10127
         (eql (char s 2) #\/))
 
10128
    (merge-using-dot-dot (remove-after-last-directory-separator p)
 
10129
                         (subseq s 3 (length s))))
 
10130
   ((and (>= (length s) 2)
 
10131
         (eql (char s 0) #\.)
 
10132
         (eql (char s 1) #\/))
 
10133
    (merge-using-dot-dot p (subseq s 2 (length s))))
 
10134
   (t
 
10135
    (concatenate 'string p *directory-separator-string* s))))
 
10136
 
 
10137
(defun our-merge-pathnames (p s)
 
10138
 
 
10139
; This is something like the Common Lisp function merge-pathnames.  P and s are
 
10140
; (Unix-style) pathname strings, where s is a relative pathname.  (If s may be
 
10141
; an absolute pathname, use extend-pathname instead.)  We allow p to be nil,
 
10142
; which is a case that arises when p is (f-get-global 'connected-book-directory
 
10143
; state) during boot-strapping; otherwise p should be an absolute directory
 
10144
; pathname (though we allow "" as well).
 
10145
 
 
10146
  (cond
 
10147
   ((and (not (equal s ""))
 
10148
         (eql (char s 0) *directory-separator*))
 
10149
    (er hard 'our-merge-pathnames
 
10150
        "Attempt to merge with an absolute filename, ~p0.  Please contact the ~
 
10151
         ACL2 implementors."
 
10152
        s))
 
10153
   ((or (null p) (equal p ""))
 
10154
    s)
 
10155
   ((stringp p) ; checked because of structured pathnames before Version_2.5
 
10156
    (merge-using-dot-dot
 
10157
     (if (eql (char p (1- (length p)))
 
10158
              *directory-separator*)
 
10159
         (subseq p 0 (1- (length p)))
 
10160
       p)
 
10161
     s))
 
10162
   (t
 
10163
    (er hard 'our-merge-pathnames
 
10164
        "The first argument of our-merge-pathnames must be a string, ~
 
10165
         but the following is not:  ~p0."
 
10166
        p))))
 
10167
 
 
10168
(defun extend-pathname (dir file-name os)
 
10169
 
 
10170
; Dir is a string representing an absolute directory name, and file-name is a
 
10171
; string representing a file or directory name.  We want to extend dir by
 
10172
; file-name if subdir is relative, and otherwise return file-name.
 
10173
 
 
10174
  (cond
 
10175
   ((absolute-pathname-string-p file-name nil os)
 
10176
    file-name)
 
10177
   (t
 
10178
    (our-merge-pathnames dir file-name))))
 
10179
 
 
10180
(defun registered-full-book-name (filename ctx state)
 
10181
 
 
10182
; Returns an error triple whose value is the name of the file corresponding to
 
10183
; filename, a full book name, that is found in the filename's certificate file,
 
10184
; if such exists.  Otherwise the value is nil.
 
10185
 
 
10186
  (state-global-let*
 
10187
   ((inhibit-output-lst *valid-output-names*))
 
10188
   (mv-let (erp cert-obj state)
 
10189
           (chk-certificate-file filename t ctx state
 
10190
                                 '((:uncertified-okp . t)
 
10191
                                   (:defaxioms-okp t)
 
10192
                                   (:skip-proofs-okp t))
 
10193
                                 nil)
 
10194
           (value (and (null erp)
 
10195
                       cert-obj
 
10196
                       (caar (access cert-obj cert-obj :post-alist)))))))
 
10197
 
 
10198
(defun translate-book-names (filenames ctx cbd os state acc)
 
10199
  (declare (xargs :guard (true-listp filenames))) ; one member can be nil
 
10200
  (cond ((endp filenames)
 
10201
         (value (reverse acc)))
 
10202
        ((null (car filenames))
 
10203
         (translate-book-names (cdr filenames) ctx cbd os state
 
10204
                               (cons nil acc)))
 
10205
        (t (let ((file0 (extend-pathname cbd
 
10206
                                         (possibly-add-lisp-extension
 
10207
                                          (car filenames))
 
10208
                                         os)))
 
10209
             (er-let* ((file1 (registered-full-book-name file0 ctx state)))
 
10210
                      (translate-book-names (cdr filenames) ctx cbd os state
 
10211
                                            (cons (or file1 file0) acc)))))))
 
10212
 
 
10213
(defun fix-ttags (ttags ctx cbd os state seen acc)
 
10214
 
 
10215
; Seen is a list of symbols, nil at the top level.  We use this argument to
 
10216
; enforce the lack of duplicate ttags.  Acc is the accumulated list of ttags to
 
10217
; return, which may include symbols and lists (sym file1 ... filek).
 
10218
 
 
10219
  (declare (xargs :guard (true-listp ttags)))
 
10220
  (cond ((endp ttags)
 
10221
         (value (reverse acc)))
 
10222
        (t (let* ((ttag (car ttags))
 
10223
                  (sym (if (consp ttag) (car ttag) ttag)))
 
10224
             (cond
 
10225
              ((not (and (symbolp sym)
 
10226
                         sym
 
10227
                         (or (atom ttag)
 
10228
                             (string-listp (remove1-eq nil (cdr ttag))))))
 
10229
               (er soft ctx
 
10230
                   "A :ttags value for certify-book or include-book must ~
 
10231
                    either be the keyword :ALL or else a list, each of whose ~
 
10232
                    members is one of the following: a non-nil symbol, or the ~
 
10233
                    CONS of a non-nil symbol onto a true list consisting of ~
 
10234
                    strings and at most one nil.  The value ~x0 is thus an ~
 
10235
                    illegal member of such a list."
 
10236
                   ttag))
 
10237
              ((member-eq sym seen)
 
10238
               (er soft ctx
 
10239
                   "A :ttags list may not mention the same ttag symbol more ~
 
10240
                    than once, but the proposed list mentions ~x0 more than ~
 
10241
                    once."
 
10242
                   sym))
 
10243
              ((symbolp ttag)
 
10244
               (fix-ttags (cdr ttags) ctx cbd os state (cons sym seen)
 
10245
                          (cons sym acc)))
 
10246
              (t
 
10247
               (er-let* ((full-book-names
 
10248
                          (translate-book-names (cdr ttag) ctx cbd os state
 
10249
                                                nil)))
 
10250
                        (fix-ttags (cdr ttags) ctx cbd os state (cons sym seen)
 
10251
                                   (cons (cons sym full-book-names)
 
10252
                                         acc)))))))))
 
10253
 
 
10254
(defun chk-well-formed-ttags (ttags cbd ctx state)
 
10255
  (cond ((or (null ttags) ; optimization
 
10256
             (eq ttags :all))
 
10257
         (value ttags))
 
10258
        ((not (true-listp ttags))
 
10259
         (er soft ctx
 
10260
             "A valid list of ttags must be a true list, unlike: ~x0."
 
10261
             ttags))
 
10262
        (t (fix-ttags ttags ctx cbd (os (w state)) state nil nil))))
 
10263
 
 
10264
(defun cbd-fn (state)
 
10265
  (or (f-get-global 'connected-book-directory state)
 
10266
      (er hard 'cbd
 
10267
          "The connected book directory has apparently not yet been set.  ~
 
10268
           This could be a sign that the top-level ACL2 loop, generally ~
 
10269
           entered using (LP), has not yet been entered.")))
 
10270
 
 
10271
(defmacro cbd nil
 
10272
  ":Doc-Section Books
 
10273
 
 
10274
  connected book directory string~/
 
10275
  ~bv[]
 
10276
  Example:
 
10277
  ACL2 !>:cbd
 
10278
  \"/usr/home/smith/\"
 
10279
  ~ev[]
 
10280
  The connected book directory is a nonempty string that specifies a
 
10281
  directory as an absolute pathname.  (~l[pathname] for a
 
10282
  discussion of file naming conventions.)  When ~ilc[include-book] is given
 
10283
  a relative book name it elaborates it into a full book name,
 
10284
  essentially by appending the connected book directory string to the
 
10285
  left and ~c[\".lisp\"] to the right.  (For details,
 
10286
  ~pl[book-name] and also ~pl[full-book-name].)  Furthermore,
 
10287
  ~ilc[include-book] temporarily sets the connected book directory to the
 
10288
  directory string of the resulting full book name so that references
 
10289
  to inferior ~il[books] in the same directory may omit the directory.
 
10290
  ~l[set-cbd] for how to set the connected book directory string.~/
 
10291
  ~bv[]
 
10292
  General Form:
 
10293
  (cbd)
 
10294
  ~ev[]
 
10295
  This is a macro that expands into a term involving the single free
 
10296
  variable ~ilc[state].  It returns the connected book directory string.
 
10297
 
 
10298
  The connected book directory (henceforth called the ``~c[cbd]'') is
 
10299
  used by ~ilc[include-book] to elaborate the supplied book name into a
 
10300
  full book name (~pl[full-book-name]).  For example, if the ~c[cbd]
 
10301
  is ~c[\"/usr/home/smith/\"] then the elaboration of the ~il[book-name]
 
10302
  ~c[\"project/task-1/arith\"] (to the ~c[\".lisp\"] extension) is
 
10303
  ~c[\"/usr/home/smith/project/task-1/arith.lisp\"].  That
 
10304
  ~il[full-book-name] is what ~il[include-book] opens to read the
 
10305
  source text for the book.
 
10306
 
 
10307
  The ~c[cbd] may be changed using ~ilc[set-cbd] (~pl[set-cbd]).
 
10308
  Furthermore, during the processing of the ~il[events] in a book,
 
10309
  ~ilc[include-book] sets the ~c[cbd] to be the directory string of the
 
10310
  ~il[full-book-name] of the book.  Thus, if the ~c[cbd] is
 
10311
  ~c[\"/usr/home/smith/\"] then during the processing of ~il[events] by
 
10312
  ~bv[]
 
10313
  (include-book \"project/task-1/arith\")
 
10314
  ~ev[]
 
10315
  the ~c[cbd] will be set to ~c[\"/usr/home/smith/project/task-1/\"].
 
10316
  Note that if ~c[\"arith\"] recursively includes a subbook, say
 
10317
  ~c[\"naturals\"], that resides on the same directory, the
 
10318
  ~ilc[include-book] event for it may omit the specification of that
 
10319
  directory.  For example, ~c[\"arith\"] might contain the event
 
10320
  ~bv[]
 
10321
    (include-book \"naturals\").
 
10322
  ~ev[]
 
10323
  In general, suppose we have a superior book and several inferior
 
10324
  ~il[books] which are included by ~il[events] in the superior book.  Any
 
10325
  inferior book residing on the same directory as the superior book
 
10326
  may be referenced in the superior without specification of the
 
10327
  directory.
 
10328
 
 
10329
  We call this a ``relative'' as opposed to ``absolute'' naming.  The
 
10330
  use of relative naming is preferred because it permits ~il[books]
 
10331
  (and their accompanying inferiors) to be moved between directories
 
10332
  while maintaining their ~il[certificate]s and utility.  Certified
 
10333
  ~il[books] that reference inferiors by absolute file names are unusable
 
10334
  (and rendered uncertified) if the inferiors are moved to new
 
10335
  directories.
 
10336
 
 
10337
  ~em[Technical Note and a Challenge to Users:]
 
10338
 
 
10339
  After elaborating the book name to a full book name, ~ilc[include-book]
 
10340
  opens a channel to the file to process the ~il[events] in it.  In some
 
10341
  host Common Lisps, the actual file opened depends upon a notion of
 
10342
  ``connected directory'' similar to our connected book directory.
 
10343
  Our intention in always elaborating book names into absolute
 
10344
  filename strings (~pl[pathname] for terminology) is to
 
10345
  circumvent the sensitivity to the connected directory.  But we may
 
10346
  have insufficient control over this since the ultimate file naming
 
10347
  conventions are determined by the host operating system rather than
 
10348
  Common Lisp (though, we do check that the operating system
 
10349
  ``appears'' to be one that we ``know'' about).  Here is a question,
 
10350
  which we'll pose assuming that we have an operating system that
 
10351
  calls itself ``Unix.''  Suppose we have a file name, filename, that
 
10352
  begins with a slash, e.g., ~c[\"/usr/home/smith/...\"].  Consider two
 
10353
  successive invocations of CLTL's
 
10354
  ~bv[]
 
10355
  (open filename :direction :input)
 
10356
  ~ev[]
 
10357
  separated only by a change to the operating system's notion of
 
10358
  connected directory.  Must these two invocations produce streams to
 
10359
  the same file?  A candidate string might be something like
 
10360
  ~c[\"/usr/home/smith/*/usr/local/src/foo.lisp\"] which includes some
 
10361
  operating system-specific special character to mean ``here insert
 
10362
  the connected directory'' or, more generally, ``here make the name
 
10363
  dependent on some non-ACL2 aspect of the host's state.''  If such
 
10364
  ``tricky'' name strings beginning with a slash exist, then we have
 
10365
  failed to isolate ACL2 adequately from the operating system's file
 
10366
  naming conventions.  Once upon a time, ACL2 did not insist that the
 
10367
  ~c[cbd] begin with a slash and that allowed the string
 
10368
  ~c[\"foo.lisp\"] to be tricky because if one were connected to
 
10369
  ~c[\"/usr/home/smith/\"] then with the empty ~c[cbd] ~c[\"foo.lisp\"]
 
10370
  is a full book name that names the same file as
 
10371
  ~c[\"/usr/home/smith/foo.lisp\"].  If the actual file one reads is
 
10372
  determined by the operating system's state then it is possible for
 
10373
  ACL2 to have two distinct ``full book names'' for the same file, the
 
10374
  ``real'' name and the ``tricky'' name.  This can cause ACL2 to
 
10375
  include the same book twice, not recognizing the second one as
 
10376
  redundant."
 
10377
 
 
10378
  `(cbd-fn state))
 
10379
 
9526
10380
(defun chk-acceptable-certify-book (book-name full-book-name k ctx state
9527
10381
                                              suspect-book-action-alist)
9528
10382
 
9540
10394
; Warning: If you change the list of names below, be sure to change it
9541
10395
; in the call of note-certification-world in certify-book-fn.
9542
10396
 
9543
 
         (cons 'defpkg *primitive-event-macros*)))
9544
 
 
 
10397
         (cons 'defpkg *primitive-event-macros*))
 
10398
        (wrld (w state)))
9545
10399
    (er-progn
9546
10400
     (cond ((ld-skip-proofsp state)
9547
10401
            (er soft ctx
9549
10403
           ((f-get-global 'in-local-flg state)
9550
10404
            (er soft ctx
9551
10405
                "Certify-book may not be called inside a LOCAL command."))
9552
 
           ((global-val 'skip-proofs-seen (w state))
 
10406
           ((global-val 'skip-proofs-seen wrld)
9553
10407
            (er soft ctx
9554
10408
                "At least one command in the current ACL2 world was executed ~
9555
 
                 while the value of state global variable 'LD-SKIP-PROOFSP ~
9556
 
                 was not nil:~|~%  ~x0~|~%(If you did not explicitly use ~
 
10409
                 while the value of state global variable '~x0 was not ~
 
10410
                 nil:~|~%  ~y1~%(If you did not explicitly use ~
9557
10411
                 set-ld-skip-proofsp or call ld with :ld-skip-proofsp not ~
9558
10412
                 nil, then some other function did so, for example, rebuild.) ~
9559
 
                  Certification is therefore not allowed in this world.  If ~
 
10413
                 Certification is therefore not allowed in this world.  If ~
9560
10414
                 the intention was for proofs to be skipped for one or more ~
9561
10415
                 events in the certification world, consider wrapping those ~
9562
10416
                 events explicitly in skip-proofs forms.  See :DOC ~
9563
10417
                 skip-proofs."
9564
 
                (global-val 'skip-proofs-seen (w state))))
 
10418
                'ld-skip-proofsp
 
10419
                (global-val 'skip-proofs-seen wrld)))
 
10420
           ((global-val 'redef-seen wrld)
 
10421
            (er soft ctx
 
10422
                "At least one command in the current ACL2 world was executed ~
 
10423
                 while the value of state global variable '~x0 was not ~
 
10424
                 nil:~|~%  ~y1~%Certification is therefore not allowed in ~
 
10425
                 this world.  You can use :ubt to undo back through this ~
 
10426
                 command; see :DOC ubt."
 
10427
                'ld-redefinition-action
 
10428
                (global-val 'redef-seen wrld)))
 
10429
           ((ttag wrld)
 
10430
 
 
10431
; We disallow active ttag at certification time because we don't want to think
 
10432
; about certain oddly redundant defttag events.  Consider for example executing
 
10433
; (defttag foo), and then certifying a book containing the following forms,
 
10434
; (certify-book "foo" 1 nil :ttags ((foo nil))), indicating that ttag foo is
 
10435
; only active at the top level, not inside a book.
 
10436
 
 
10437
; (defttag foo)
 
10438
 
 
10439
; (defun f ()
 
10440
;   (declare (xargs :mode :program))
 
10441
;   (sys-call "ls" nil))
 
10442
 
 
10443
; The defttag expands to a redundant table event, hence would be allowed.
 
10444
; Perhaps this is OK, but it is rather scary since we then have a case of a
 
10445
; book containing a defttag of which there is no evidence of this in any "TTAG
 
10446
; NOTE" string or in the book's certificate.  While we see no real problem
 
10447
; here, since the defttag really is ignored, still it's very easy for the user
 
10448
; to work around this situation by executing (defttag nil) before
 
10449
; certification; so we take this conservative approach.
 
10450
 
 
10451
            (er soft ctx
 
10452
                "It is illegal to certify a book while there is an active ~
 
10453
                 ttag, in this case, ~x0.  Consider undoing the corresponding ~
 
10454
                 defttag event (see :DOC ubt) or else executing ~x1.  See ~
 
10455
                 :DOC defttag."
 
10456
                (ttag wrld)
 
10457
                '(defttag nil)))
9565
10458
           (t (value nil)))
9566
10459
     (chk-book-name book-name full-book-name ctx state)
9567
10460
     (er-let*
9568
10461
      ((certp (certificate-filep full-book-name state)))
9569
 
      (let ((wrld (w state)))
9570
 
        (mv-let
9571
 
         (erp cmds wrld-segs wrld-list state)
9572
 
         (get-portcullis-cmds wrld nil nil nil names ctx state)
 
10462
      (mv-let
 
10463
       (erp cmds wrld-segs wrld-list state)
 
10464
       (get-portcullis-cmds wrld nil nil nil names ctx state)
 
10465
       (cond
 
10466
        (erp (silent-error state))
 
10467
        ((eq k t)
9573
10468
         (cond
9574
 
          (erp (silent-error state))
9575
 
          ((eq k t)
9576
 
           (cond
9577
 
            (cmds
9578
 
             (er soft ctx
9579
 
                 "When you tell certify-book to recover the certification ~
9580
 
                  world from the old certificate, you must call certify-book ~
9581
 
                  in the initial ACL2 logical world -- so we don't have to ~
9582
 
                  worry about the certification world  clashing with the ~
9583
 
                  existing logical world.  But you are not in the initial ~
9584
 
                  logical world.  Use :pbt 1 to see the world."))
9585
 
            ((not certp)
9586
 
             (er soft ctx
9587
 
                 "There is no certificate on file for ~x0.  But you told ~
9588
 
                  certify-book to recover the certi~-fication world from the ~
9589
 
                  old certificate.  You will have to construct the ~
9590
 
                  certi~-fication world by hand (by executing the desired ~
9591
 
                  commands in the current logical world) and then call ~
9592
 
                  certify-book again."
9593
 
                 full-book-name))
9594
 
            (t
 
10469
          (cmds
 
10470
           (er soft ctx
 
10471
               "When you tell certify-book to recover the certification world ~
 
10472
                from the old certificate, you must call certify-book in the ~
 
10473
                initial ACL2 logical world -- so we don't have to worry about ~
 
10474
                the certification world  clashing with the existing logical ~
 
10475
                world.  But you are not in the initial logical world.  Use ~
 
10476
                :pbt 1 to see the world."))
 
10477
          ((not certp)
 
10478
           (er soft ctx
 
10479
               "There is no certificate on file for ~x0.  But you told ~
 
10480
                certify-book to recover the certi~-fication world from the ~
 
10481
                old certificate.  You will have to construct the ~
 
10482
                certi~-fication world by hand (by executing the desired ~
 
10483
                commands in the current logical world) and then call ~
 
10484
                certify-book again."
 
10485
               full-book-name))
 
10486
          (t
9595
10487
 
9596
10488
; So k is t, we are in the initial world, and there is a certificate file
9597
10489
; from which we can recover the portcullis.  Do it.
9598
10490
 
9599
 
             (er-let*
9600
 
              ((cert-obj
9601
 
                (chk-certificate-file full-book-name t ctx state
9602
 
                                      (cons '(:uncertified-okp . nil)
9603
 
                                            suspect-book-action-alist)
9604
 
                                      t))
9605
 
               (cert-obj-cmds (value (and cert-obj
9606
 
                                          (access cert-obj cert-obj :cmds)))))
9607
 
              (chk-acceptable-certify-book1 full-book-name
9608
 
                                            (length cert-obj-cmds) ;; k
9609
 
                                            cert-obj-cmds ;; cmds
9610
 
                                            :omitted ;; wrld-segs
9611
 
                                            wrld-list
9612
 
                                            names
9613
 
                                            (w state)
9614
 
                                            ctx state)))))
9615
 
          (t (chk-acceptable-certify-book1 full-book-name k cmds wrld-segs
9616
 
                                           wrld-list names wrld ctx
9617
 
                                           state)))))))))
 
10491
           (er-let*
 
10492
            ((cert-obj
 
10493
              (chk-certificate-file full-book-name t ctx state
 
10494
                                    (cons '(:uncertified-okp . nil)
 
10495
                                          suspect-book-action-alist)
 
10496
                                    t))
 
10497
             (cert-obj-cmds (value (and cert-obj
 
10498
                                        (access cert-obj cert-obj :cmds)))))
 
10499
            (chk-acceptable-certify-book1 full-book-name
 
10500
                                          (length cert-obj-cmds) ;; k
 
10501
                                          cert-obj-cmds ;; cmds
 
10502
                                          :omitted ;; wrld-segs
 
10503
                                          wrld-list
 
10504
                                          names
 
10505
                                          (w state)
 
10506
                                          ctx state)))))
 
10507
        (t (chk-acceptable-certify-book1 full-book-name k cmds wrld-segs
 
10508
                                         wrld-list names wrld ctx
 
10509
                                         state))))))))
9618
10510
 
9619
10511
(defun print-objects (lst ch state)
9620
10512
  (cond ((null lst) state)
9673
10565
             (pprogn
9674
10566
              (print-object$ '(in-package "ACL2") ch state)
9675
10567
              (print-object$
9676
 
               (if (eq (f-get-global 'in-certify-book-flg state)
9677
 
                       'tainted)
 
10568
               (if (consp (f-get-global 'certify-book-info state))
9678
10569
                   (taint-string (f-get-global 'acl2-version state))
9679
10570
                 (f-get-global 'acl2-version state))
9680
10571
               ch state)
9858
10749
                       (value (cons (list 'in-package new-current-package)
9859
10750
                                    lst)))))))
9860
10751
 
9861
 
(defun cbd-fn (state)
9862
 
  (or (f-get-global 'connected-book-directory state)
9863
 
      (er hard 'cbd
9864
 
          "The connected book directory has apparently not yet been set.  ~
9865
 
           This could be a sign that the top-level ACL2 loop, generally ~
9866
 
           entered using (LP), has not yet been entered.")))
9867
 
 
9868
 
(defmacro cbd nil
9869
 
  ":Doc-Section Books
9870
 
 
9871
 
  connected book directory string~/
9872
 
  ~bv[]
9873
 
  Example:
9874
 
  ACL2 !>:cbd
9875
 
  \"/usr/home/smith/\"
9876
 
  ~ev[]
9877
 
  The connected book directory is a nonempty string that specifies a
9878
 
  directory as an absolute pathname.  (~l[pathname] for a
9879
 
  discussion of file naming conventions.)  When ~ilc[include-book] is given
9880
 
  a relative book name it elaborates it into a full book name,
9881
 
  essentially by appending the connected book directory string to the
9882
 
  left and ~c[\".lisp\"] to the right.  (For details,
9883
 
  ~pl[book-name] and also ~pl[full-book-name].)  Furthermore,
9884
 
  ~ilc[include-book] temporarily sets the connected book directory to the
9885
 
  directory string of the resulting full book name so that references
9886
 
  to inferior ~il[books] in the same directory may omit the directory.
9887
 
  ~l[set-cbd] for how to set the connected book directory string.~/
9888
 
  ~bv[]
9889
 
  General Form:
9890
 
  (cbd)
9891
 
  ~ev[]
9892
 
  This is a macro that expands into a term involving the single free
9893
 
  variable ~ilc[state].  It returns the connected book directory string.
9894
 
 
9895
 
  The connected book directory (henceforth called the ``~c[cbd]'') is
9896
 
  used by ~ilc[include-book] to elaborate the supplied book name into a
9897
 
  full book name (~pl[full-book-name]).  For example, if the ~c[cbd]
9898
 
  is ~c[\"/usr/home/smith/\"] then the elaboration of the ~il[book-name]
9899
 
  ~c[\"project/task-1/arith\"] (to the ~c[\".lisp\"] extension) is
9900
 
  ~c[\"/usr/home/smith/project/task-1/arith.lisp\"].  That
9901
 
  ~il[full-book-name] is what ~il[include-book] opens to read the
9902
 
  source text for the book.
9903
 
 
9904
 
  The ~c[cbd] may be changed using ~ilc[set-cbd] (~pl[set-cbd]).
9905
 
  Furthermore, during the processing of the ~il[events] in a book,
9906
 
  ~ilc[include-book] sets the ~c[cbd] to be the directory string of the
9907
 
  ~il[full-book-name] of the book.  Thus, if the ~c[cbd] is
9908
 
  ~c[\"/usr/home/smith/\"] then during the processing of ~il[events] by
9909
 
  ~bv[]
9910
 
  (include-book \"project/task-1/arith\")
9911
 
  ~ev[]
9912
 
  the ~c[cbd] will be set to ~c[\"/usr/home/smith/project/task-1/\"].
9913
 
  Note that if ~c[\"arith\"] recursively includes a subbook, say
9914
 
  ~c[\"naturals\"], that resides on the same directory, the
9915
 
  ~ilc[include-book] event for it may omit the specification of that
9916
 
  directory.  For example, ~c[\"arith\"] might contain the event
9917
 
  ~bv[]
9918
 
    (include-book \"naturals\").
9919
 
  ~ev[]
9920
 
  In general, suppose we have a superior book and several inferior
9921
 
  ~il[books] which are included by ~il[events] in the superior book.  Any
9922
 
  inferior book residing on the same directory as the superior book
9923
 
  may be referenced in the superior without specification of the
9924
 
  directory.
9925
 
 
9926
 
  We call this a ``relative'' as opposed to ``absolute'' naming.  The
9927
 
  use of relative naming is preferred because it permits ~il[books]
9928
 
  (and their accompanying inferiors) to be moved between directories
9929
 
  while maintaining their ~il[certificate]s and utility.  Certified
9930
 
  ~il[books] that reference inferiors by absolute file names are unusable
9931
 
  (and rendered uncertified) if the inferiors are moved to new
9932
 
  directories.
9933
 
 
9934
 
  ~em[Technical Note and a Challenge to Users:]
9935
 
 
9936
 
  After elaborating the book name to a full book name, ~ilc[include-book]
9937
 
  opens a channel to the file to process the ~il[events] in it.  In some
9938
 
  host Common Lisps, the actual file opened depends upon a notion of
9939
 
  ``connected directory'' similar to our connected book directory.
9940
 
  Our intention in always elaborating book names into absolute
9941
 
  filename strings (~pl[pathname] for terminology) is to
9942
 
  circumvent the sensitivity to the connected directory.  But we may
9943
 
  have insufficient control over this since the ultimate file naming
9944
 
  conventions are determined by the host operating system rather than
9945
 
  Common Lisp (though, we do check that the operating system
9946
 
  ``appears'' to be one that we ``know'' about).  Here is a question,
9947
 
  which we'll pose assuming that we have an operating system that
9948
 
  calls itself ``Unix.''  Suppose we have a file name, filename, that
9949
 
  begins with a slash, e.g., ~c[\"/usr/home/smith/...\"].  Consider two
9950
 
  successive invocations of CLTL's
9951
 
  ~bv[]
9952
 
  (open filename :direction :input)
9953
 
  ~ev[]
9954
 
  separated only by a change to the operating system's notion of
9955
 
  connected directory.  Must these two invocations produce streams to
9956
 
  the same file?  A candidate string might be something like
9957
 
  ~c[\"/usr/home/smith/*/usr/local/src/foo.lisp\"] which includes some
9958
 
  operating system-specific special character to mean ``here insert
9959
 
  the connected directory'' or, more generally, ``here make the name
9960
 
  dependent on some non-ACL2 aspect of the host's state.''  If such
9961
 
  ``tricky'' name strings beginning with a slash exist, then we have
9962
 
  failed to isolate ACL2 adequately from the operating system's file
9963
 
  naming conventions.  Once upon a time, ACL2 did not insist that the
9964
 
  ~c[cbd] begin with a slash and that allowed the string
9965
 
  ~c[\"foo.lisp\"] to be tricky because if one were connected to
9966
 
  ~c[\"/usr/home/smith/\"] then with the empty ~c[cbd] ~c[\"foo.lisp\"]
9967
 
  is a full book name that names the same file as
9968
 
  ~c[\"/usr/home/smith/foo.lisp\"].  If the actual file one reads is
9969
 
  determined by the operating system's state then it is possible for
9970
 
  ACL2 to have two distinct ``full book names'' for the same file, the
9971
 
  ``real'' name and the ``tricky'' name.  This can cause ACL2 to
9972
 
  include the same book twice, not recognizing the second one as
9973
 
  redundant."
9974
 
 
9975
 
  `(cbd-fn state))
9976
 
 
9977
10752
(defun maybe-add-separator (str)
9978
10753
  (if (and (not (equal str ""))
9979
10754
           (eql (char str (1- (length str))) *directory-separator*))
10036
10811
 
10037
10812
  `(set-cbd-fn ,str state))
10038
10813
 
10039
 
(defun extend-pathname (dir file-name os)
10040
 
 
10041
 
; Dir is a string representing an absolute directory name, and file-name is a
10042
 
; string representing a file or directory name.  We want to extend dir by
10043
 
; file-name if subdir is relative, and otherwise return file-name.
10044
 
 
10045
 
  (cond
10046
 
   ((absolute-pathname-string-p file-name nil os)
10047
 
    file-name)
10048
 
   (t
10049
 
    (our-merge-pathnames dir file-name))))
10050
 
 
10051
10814
(defun parse-book-name (dir x extension os)
10052
10815
 
10053
10816
; This function takes a directory name, dir, and a user supplied book name, x,
10318
11081
                                       uncertified-okp
10319
11082
                                       defaxioms-okp
10320
11083
                                       skip-proofs-okp
 
11084
                                       ttags
10321
11085
                                       doc
10322
11086
                                       dir
10323
11087
                                       event-form)
10328
11092
  (with-ctx-summarized
10329
11093
   (if (output-in-infixp state) event-form (cons 'include-book user-book-name))
10330
11094
   (let* ((wrld0 (w state))
 
11095
          (active-book-name0 (active-book-name wrld0 state))
 
11096
          (old-ttags-seen (global-val 'ttags-seen wrld0))
10331
11097
          (behalf-of-certify-flg (not (eq expansion-alist :none)))
10332
11098
          #-acl2-loop-only (*inside-include-book-fn* t)
10333
11099
          (old-include-book-path
10367
11133
        (cond (dir (include-book-dir-with-chk soft ctx dir))
10368
11134
              (t (value (cbd))))))
10369
11135
      (mv-let
10370
 
        (full-book-name directory-name familiar-name)
10371
 
        (parse-book-name dir-value user-book-name ".lisp" (os (w state)))
 
11136
       (full-book-name directory-name familiar-name)
 
11137
       (parse-book-name dir-value user-book-name ".lisp" (os (w state)))
10372
11138
 
10373
11139
; If you add more keywords to the suspect-book-action-alist, make sure you do
10374
11140
; the same to the list constructed by certify-book-fn.  You might wish to
10375
11141
; handle the new warning summary in warning1.
10376
11142
 
10377
 
        (let ((suspect-book-action-alist
10378
 
               (list (cons :uncertified-okp
10379
 
                           (if (assoc-eq 'certify-book
10380
 
                                         (global-val 'embedded-event-lst
10381
 
                                                     wrld0))
10382
 
                               nil
10383
 
                             uncertified-okp))
10384
 
                     (cons :defaxioms-okp defaxioms-okp)
10385
 
                     (cons :skip-proofs-okp skip-proofs-okp))))
10386
 
          (er-progn
10387
 
           (chk-book-name user-book-name full-book-name ctx state)
10388
 
           (chk-input-object-file full-book-name ctx state)
10389
 
           (revert-world-on-error
10390
 
            (cond
10391
 
             ((and (not (global-val 'boot-strap-flg wrld0))
10392
 
                   full-book-name
10393
 
                   (assoc-equal full-book-name
10394
 
                                (global-val 'include-book-alist wrld0)))
10395
 
              (stop-redundant-event state))
10396
 
             (t
10397
 
              (let ((wrld1 (global-set
10398
 
                            'include-book-path
10399
 
                            (cons full-book-name old-include-book-path)
10400
 
                            wrld0)))
10401
 
                (pprogn
10402
 
                 (set-w 'extension wrld1 state)
10403
 
                 (er-let*
10404
 
                  ((redef (chk-new-stringp-name 'include-book full-book-name
10405
 
                                                ctx wrld1 state))
10406
 
                   (doc-pair (translate-doc full-book-name doc ctx state))
10407
 
                   (cert-obj (if behalf-of-certify-flg
10408
 
                                 (value nil)
10409
 
                               (chk-certificate-file full-book-name nil ctx state
10410
 
                                                     suspect-book-action-alist
10411
 
                                                     t)))
10412
 
                   (wrld-after-certificate (value (w state)))
10413
 
                   (expansion-alist (value (if behalf-of-certify-flg
10414
 
                                               expansion-alist
10415
 
                                             (and cert-obj
10416
 
                                                  (access cert-obj cert-obj
10417
 
                                                          :expansion-alist)))))
10418
 
                   (post-alist (value (and cert-obj
10419
 
                                           (access cert-obj cert-obj
10420
 
                                                   :post-alist))))
10421
 
                   (cert-full-book-name (value (car (car post-alist)))))
10422
 
                  (cond
 
11143
       (let ((suspect-book-action-alist
 
11144
              (list (cons :uncertified-okp
 
11145
                          (if (assoc-eq 'certify-book
 
11146
                                        (global-val 'embedded-event-lst
 
11147
                                                    wrld0))
 
11148
                              nil
 
11149
                            uncertified-okp))
 
11150
                    (cons :defaxioms-okp defaxioms-okp)
 
11151
                    (cons :skip-proofs-okp skip-proofs-okp)))
 
11152
             (include-book-alist0 (global-val 'include-book-alist wrld0)))
 
11153
         (er-progn
 
11154
          (chk-book-name user-book-name full-book-name ctx state)
 
11155
          (chk-input-object-file full-book-name ctx state)
 
11156
          (revert-world-on-error
 
11157
           (cond
 
11158
            ((and (not (global-val 'boot-strap-flg wrld0))
 
11159
                  full-book-name
 
11160
                  (assoc-equal full-book-name include-book-alist0))
 
11161
             (stop-redundant-event state))
 
11162
            (t
 
11163
             (let ((wrld1 (global-set
 
11164
                           'include-book-path
 
11165
                           (cons full-book-name old-include-book-path)
 
11166
                           wrld0)))
 
11167
               (pprogn
 
11168
                (set-w 'extension wrld1 state)
 
11169
                (er-let*
 
11170
                 ((redef (chk-new-stringp-name 'include-book full-book-name
 
11171
                                               ctx wrld1 state))
 
11172
                  (doc-pair (translate-doc full-book-name doc ctx state))
 
11173
                  (cert-obj (if behalf-of-certify-flg
 
11174
                                (value nil)
 
11175
                              (chk-certificate-file full-book-name nil ctx state
 
11176
                                                    suspect-book-action-alist
 
11177
                                                    t)))
 
11178
                  (wrld2 (value (w state)))
 
11179
                  (expansion-alist (value (if behalf-of-certify-flg
 
11180
                                              expansion-alist
 
11181
                                            (and cert-obj
 
11182
                                                 (access cert-obj cert-obj
 
11183
                                                         :expansion-alist)))))
 
11184
                  (post-alist (value (and cert-obj
 
11185
                                          (access cert-obj cert-obj
 
11186
                                                  :post-alist))))
 
11187
                  (cert-full-book-name (value (car (car post-alist)))))
 
11188
                 (cond
10423
11189
 
10424
11190
; We try the redundancy check again, because it will be cert-full-book-name
10425
11191
; that is stored on the world's include-book-alist, not full-book-name (if the
10426
11192
; two book names differ).
10427
11193
 
10428
 
                   ((and (not (equal full-book-name cert-full-book-name))
10429
 
                         (not (global-val 'boot-strap-flg wrld1))
10430
 
                         cert-full-book-name 
10431
 
                         (assoc-equal cert-full-book-name
10432
 
                                      (global-val 'include-book-alist wrld1)))
 
11194
                  ((and (not (equal full-book-name cert-full-book-name))
 
11195
                        (not (global-val 'boot-strap-flg wrld2))
 
11196
                        cert-full-book-name 
 
11197
                        (assoc-equal cert-full-book-name
 
11198
                                     include-book-alist0))
10433
11199
 
10434
11200
; Chk-certificate-file calls chk-certificate-file1, which calls
10435
11201
; chk-raise-portcullis, which calls chk-raise-portcullis1, which evaluates, for
10436
11202
; example, maybe-install-acl2-defaults-table.  So we need to revert the world
10437
11203
; here.
10438
11204
 
10439
 
                    (pprogn (set-w 'retraction wrld0 state)
10440
 
                            (stop-redundant-event state)))
10441
 
                   (t
10442
 
                    (er-let*
10443
 
                     ((ev-lst (read-object-file full-book-name ctx state)))
 
11205
                   (pprogn (set-w 'retraction wrld0 state)
 
11206
                           (stop-redundant-event state)))
 
11207
                  (t
 
11208
                   (er-let*
 
11209
                    ((ev-lst (read-object-file full-book-name ctx state)))
10444
11210
 
10445
11211
; Cert-obj above is either nil, indicating that the file is uncertified, or is
10446
11212
; a cert-obj record, which contains the now raised portcullis and the check sum
10452
11218
; resides now.  However, the familiar-name, cert-annotations and the
10453
11219
; ev-lst-chk-sum ought to be those for the current book.
10454
11220
 
10455
 
                     (mv-let
10456
 
                       (ev-lst-chk-sum state)
10457
 
                       (check-sum-obj (append expansion-alist ev-lst) state)
10458
 
                       (cond
10459
 
                        ((not (integerp ev-lst-chk-sum))
 
11221
                    (mv-let
 
11222
                     (ev-lst-chk-sum state)
 
11223
                     (check-sum-obj (append expansion-alist ev-lst) state)
 
11224
                     (cond
 
11225
                      ((not (integerp ev-lst-chk-sum))
10460
11226
 
10461
11227
; This error should never arise because check-sum-obj is only called on
10462
11228
; something produced by read-object, which checks that the object is ACL2
10463
11229
; compatible, and perhaps make-event expansion.  The next form causes a soft
10464
11230
; error, assigning proper blame.
10465
11231
 
10466
 
                         (mv-let
10467
 
                          (raw-ev-lst-chk-sum state)
10468
 
                          (check-sum-obj ev-lst state)
10469
 
                          (cond ((not (integerp raw-ev-lst-chk-sum))
10470
 
                                 (er soft ctx
10471
 
                                     "The file ~x0 is not a legal list of ~
10472
 
                                      embedded event forms because it ~
10473
 
                                      contains an object, ~x1, which check ~
10474
 
                                      sum was unable to handle."
10475
 
                                     full-book-name raw-ev-lst-chk-sum))
10476
 
                                (t
10477
 
                                 (mv-let
10478
 
                                  (expansion-chk-sum state)
10479
 
                                  (check-sum-obj expansion-alist state)
10480
 
                                  (cond
10481
 
                                   ((not (integerp expansion-chk-sum))
10482
 
                                    (er soft ctx
10483
 
                                        "The expansion-alist (from ~
10484
 
                                         make-event) for file ~x0 is not a ~
10485
 
                                         legal list of embedded event forms ~
10486
 
                                         because it contains an object, ~x1, ~
10487
 
                                         which check sum was unable to handle."
10488
 
                                        full-book-name expansion-chk-sum))
10489
 
                                   (t (er soft ctx
10490
 
                                          "The append of expansion-alist ~
10491
 
                                           (from make-event) and command for ~
10492
 
                                           file ~x0 is not a legal list of ~
10493
 
                                           embedded event forms because it ~
10494
 
                                           contains an object, ~x1, which ~
10495
 
                                           check sum was unable to handle.  ~
10496
 
                                           This is very surprising,because ~
10497
 
                                           check sums were computed ~
10498
 
                                           successfully for the ~
10499
 
                                           expansion-alist and the commands.  ~
10500
 
                                           It would be helpful for you to ~
10501
 
                                           send a replayable example of this ~
10502
 
                                           behavior to the ACL2 implementors."
10503
 
                                          full-book-name ev-lst-chk-sum))))))))
10504
 
                        (t (er-progn
 
11232
                       (mv-let
 
11233
                        (raw-ev-lst-chk-sum state)
 
11234
                        (check-sum-obj ev-lst state)
 
11235
                        (cond ((not (integerp raw-ev-lst-chk-sum))
 
11236
                               (er soft ctx
 
11237
                                   "The file ~x0 is not a legal list of ~
 
11238
                                    embedded event forms because it contains ~
 
11239
                                    an object, ~x1, which check sum was ~
 
11240
                                    unable to handle."
 
11241
                                   full-book-name raw-ev-lst-chk-sum))
 
11242
                              (t
 
11243
                               (mv-let
 
11244
                                (expansion-chk-sum state)
 
11245
                                (check-sum-obj expansion-alist state)
 
11246
                                (cond
 
11247
                                 ((not (integerp expansion-chk-sum))
 
11248
                                  (er soft ctx
 
11249
                                      "The expansion-alist (from make-event) ~
 
11250
                                       for file ~x0 is not a legal list of ~
 
11251
                                       embedded event forms because it ~
 
11252
                                       contains an object, ~x1, which check ~
 
11253
                                       sum was unable to handle."
 
11254
                                      full-book-name expansion-chk-sum))
 
11255
                                 (t (er soft ctx
 
11256
                                        "The append of expansion-alist (from ~
 
11257
                                         make-event) and command for file ~x0 ~
 
11258
                                         is not a legal list of embedded ~
 
11259
                                         event forms because it contains an ~
 
11260
                                         object, ~x1, which check sum was ~
 
11261
                                         unable to handle.  This is very ~
 
11262
                                         surprising,because check sums were ~
 
11263
                                         computed successfully for the ~
 
11264
                                         expansion-alist and the commands.  ~
 
11265
                                         It would be helpful for you to send ~
 
11266
                                         a replayable example of this ~
 
11267
                                         behavior to the ACL2 implementors."
 
11268
                                        full-book-name ev-lst-chk-sum))))))))
 
11269
                      (t (er-progn
10505
11270
 
10506
11271
; Notice that we are reaching inside the certificate object to retrieve
10507
11272
; information about the book from the post-alist.  (Car post-alist)) is in fact
10509
11274
; . ev-lst-chk-sum).
10510
11275
 
10511
11276
 
10512
 
                            (cond
10513
 
                             ((and cert-obj
10514
 
                                   (not (equal (caddr (car post-alist))
10515
 
                                               familiar-name)))
10516
 
                              (include-book-er
10517
 
                               full-book-name nil
10518
 
                               (cons
10519
 
                                "The cer~-ti~-fi~-cate on file for ~x0 lists ~
10520
 
                                 the book under the name ~x3 whereas we were ~
10521
 
                                 expecting it to give the name ~x4.  While we ~
10522
 
                                 allow a certified book to be moved from one ~
10523
 
                                 directory to another after ~
10524
 
                                 cer~-ti~-fi~-ca~-tion, we insist that it keep ~
10525
 
                                 the same familiar name.  This allows the ~
10526
 
                                 cer~-ti~-fi~-cate file to contain the ~
10527
 
                                 familiar name, making it easier to identify ~
10528
 
                                 which cer~-ti~-fi~-cates go with which files ~
10529
 
                                 and inspiring a little more confidence that ~
10530
 
                                 the cer~-ti~-fi~-cate really does describe ~
10531
 
                                 the alleged file.  In the present case, it ~
10532
 
                                 looks as though the familiar book name was ~
10533
 
                                 changed after cer~-ti~-fi~-ca~-tion.  For ~
10534
 
                                 what it is worth, the check sum of the file ~
10535
 
                                 at cer~-ti~-fi~-ca~-tion was ~x5.  Its check ~
10536
 
                                 sum now is ~x6."
10537
 
                                (list (cons #\3 (caddr (car post-alist)))
10538
 
                                      (cons #\4 familiar-name)
10539
 
                                      (cons #\5 (cddddr (car post-alist)))
10540
 
                                      (cons #\6 ev-lst-chk-sum)))
10541
 
                               :uncertified-okp
10542
 
                               suspect-book-action-alist
10543
 
                               ctx state))
10544
 
                             (t (value nil)))
10545
 
 
10546
 
                            (cond
10547
 
                             ((and cert-obj
10548
 
                                   (not (equal (cddddr (car post-alist))
10549
 
                                               ev-lst-chk-sum)))
10550
 
                              (include-book-er
10551
 
                               full-book-name nil
10552
 
                               (cons
10553
 
                                "The certificate on file for ~x0 lists the ~
10554
 
                                 check sum of the certified book as ~x3.  But ~
10555
 
                                 the check sum of the events now in the file ~
10556
 
                                 is ~x4. This generally indicates that the ~
10557
 
                                 file has been modified since it was last ~
10558
 
                                 certified."
10559
 
                                (list (cons #\3 (cddddr (car post-alist)))
10560
 
                                      (cons #\4 ev-lst-chk-sum)))
10561
 
                               :uncertified-okp
10562
 
                               suspect-book-action-alist
10563
 
                               ctx state))
10564
 
                             (t (value nil)))
10565
 
 
10566
 
                            (let ((cert-annotations (cadddr (car post-alist))))
10567
 
 
10568
 
; It is possible for cert-annotations to be nil now.  That is because cert-obj was
10569
 
; nil.  But we never use it if cert-obj is nil.
10570
 
 
10571
 
                              (cond
10572
 
                               ((and cert-obj
10573
 
                                     (or (cdr (assoc :skipped-proofsp
10574
 
                                                     cert-annotations))
10575
 
                                         (cdr (assoc :axiomsp
10576
 
                                                     cert-annotations))))
10577
 
 
10578
 
                                (chk-cert-annotations cert-annotations
10579
 
                                                      (access cert-obj cert-obj
10580
 
                                                              :cmds)
10581
 
                                                      full-book-name
10582
 
                                                      suspect-book-action-alist
10583
 
                                                      ctx state))
10584
 
                               (t (value nil))))
 
11277
                          (cond
 
11278
                           ((and cert-obj
 
11279
                                 (not (equal (caddr (car post-alist))
 
11280
                                             familiar-name)))
 
11281
                            (include-book-er
 
11282
                             full-book-name nil
 
11283
                             (cons
 
11284
                              "The cer~-ti~-fi~-cate on file for ~x0 lists ~
 
11285
                               the book under the name ~x3 whereas we were ~
 
11286
                               expecting it to give the name ~x4.  While we ~
 
11287
                               allow a certified book to be moved from one ~
 
11288
                               directory to another after ~
 
11289
                               cer~-ti~-fi~-ca~-tion, we insist that it keep ~
 
11290
                               the same familiar name.  This allows the ~
 
11291
                               cer~-ti~-fi~-cate file to contain the familiar ~
 
11292
                               name, making it easier to identify which ~
 
11293
                               cer~-ti~-fi~-cates go with which files and ~
 
11294
                               inspiring a little more confidence that the ~
 
11295
                               cer~-ti~-fi~-cate really does describe the ~
 
11296
                               alleged file.  In the present case, it looks ~
 
11297
                               as though the familiar book name was changed ~
 
11298
                               after cer~-ti~-fi~-ca~-tion.  For what it is ~
 
11299
                               worth, the check sum of the file at ~
 
11300
                               cer~-ti~-fi~-ca~-tion was ~x5.  Its check sum ~
 
11301
                               now is ~x6."
 
11302
                              (list (cons #\3 (caddr (car post-alist)))
 
11303
                                    (cons #\4 familiar-name)
 
11304
                                    (cons #\5 (cddddr (car post-alist)))
 
11305
                                    (cons #\6 ev-lst-chk-sum)))
 
11306
                             :uncertified-okp
 
11307
                             suspect-book-action-alist
 
11308
                             ctx state))
 
11309
                           (t (value nil)))
 
11310
 
 
11311
                          (cond
 
11312
                           ((and cert-obj
 
11313
                                 (not (equal (cddddr (car post-alist))
 
11314
                                             ev-lst-chk-sum)))
 
11315
                            (include-book-er
 
11316
                             full-book-name nil
 
11317
                             (cons
 
11318
                              "The certificate on file for ~x0 lists the ~
 
11319
                               check sum of the certified book as ~x3.  But ~
 
11320
                               the check sum of the events now in the file is ~
 
11321
                               ~x4. This generally indicates that the file ~
 
11322
                               has been modified since it was last certified."
 
11323
                              (list (cons #\3 (cddddr (car post-alist)))
 
11324
                                    (cons #\4 ev-lst-chk-sum)))
 
11325
                             :uncertified-okp
 
11326
                             suspect-book-action-alist
 
11327
                             ctx state))
 
11328
                           (t (value nil)))
 
11329
 
 
11330
                          (let* ((cert-annotations
 
11331
                                  (cadddr (car post-alist)))
 
11332
                                 (cert-ttags
 
11333
                                  (cdr (assoc-eq :ttags cert-annotations))))
 
11334
 
 
11335
; It is possible for cert-annotations to be nil now.  That is because cert-obj
 
11336
; was nil.  But we never use it if cert-obj is nil, except for cert-ttags.
 
11337
; Now, cert-obj is nil when we are including an uncertified book; so the fact
 
11338
; that the calls of chk-ttags-for-include-book and chk-acceptable-ttags are
 
11339
; trivial, in this case, is not a problem.
 
11340
 
 
11341
                            (er-let*
 
11342
                             ((ttags (chk-well-formed-ttags
 
11343
                                      ttags directory-name ctx state))
 
11344
                              (ttags-info
 
11345
                               (er-progn
 
11346
                                (cond
 
11347
                                 ((and cert-obj
 
11348
                                       (or (cdr (assoc-eq
 
11349
                                                 :skipped-proofsp
 
11350
                                                 cert-annotations))
 
11351
                                           (cdr (assoc-eq
 
11352
                                                 :axiomsp
 
11353
                                                 cert-annotations))))
 
11354
                                  (chk-cert-annotations
 
11355
                                   cert-annotations
 
11356
                                   (access cert-obj cert-obj :cmds)
 
11357
                                   full-book-name
 
11358
                                   suspect-book-action-alist
 
11359
                                   ctx state))
 
11360
                                 (t (value nil)))
 
11361
 
 
11362
; The following two calls of chk-acceptable-ttags1 can presumably be skipped if
 
11363
; state global 'skip-notify-on-defttag has a non-nil value.  However, they are
 
11364
; probably cheap so we go ahead and make them anyhow, for robustness.
 
11365
; 'Skip-notify-on-defttag will prevent needless subsidiary notification
 
11366
; messages.
 
11367
 
 
11368
                                (chk-acceptable-ttags1
 
11369
                                 cert-ttags
 
11370
                                 nil ; active-book-name is irrelevant
 
11371
                                 ttags
 
11372
                                 nil ; ttags-seen is irrelevant
 
11373
                                 :quiet ctx state)
 
11374
                                (chk-acceptable-ttags1
 
11375
                                 cert-ttags active-book-name0
 
11376
                                 (f-get-global 'ttags-allowed state)
 
11377
                                 old-ttags-seen t ctx state))))
10585
11378
 
10586
11379
; The following process-embedded-events is protected by the revert-world-
10587
11380
; on-error above.  See the Essay on Guard Checking for a discussion of the
10588
11381
; binding of guard-checking-on below.
10589
11382
 
10590
 
                            (state-global-let*
10591
 
                             ((skipped-proofsp nil)
10592
 
                              (axiomsp nil)
10593
 
                              (connected-book-directory directory-name)
10594
 
                              (match-free-error nil)
10595
 
                              (guard-checking-on nil)
10596
 
                              (in-local-flg
 
11383
                             (er-let*
 
11384
                              ((ttags-allowed1
 
11385
                                (state-global-let*
 
11386
                                 ((skipped-proofsp nil)
 
11387
                                  (axiomsp nil)
 
11388
                                  (ttags-allowed (car ttags-info))
 
11389
                                  (skip-notify-on-defttag cert-obj)
 
11390
                                  (connected-book-directory directory-name)
 
11391
                                  (match-free-error nil)
 
11392
                                  (guard-checking-on nil)
 
11393
                                  (in-local-flg
10597
11394
 
10598
11395
; As we start processing the events in the book, we are no longer in the
10599
11396
; lexical scope of LOCAL for purposes of disallowing setting of the
10600
11397
; acl2-defaults-table.
10601
11398
 
10602
 
                               (and (f-get-global 'in-local-flg state)
10603
 
                                    'dynamic)))
10604
 
                             (let ((skip-proofsp
 
11399
                                   (and (f-get-global 'in-local-flg state)
 
11400
                                        'dynamic)))
 
11401
                                 (let ((skip-proofsp
10605
11402
 
10606
11403
; At one time we bound this variable to 'initialize-acl2 if (or cert-obj
10607
11404
; behalf-of-certify-flg) is false.  But cert-obj is non-nil even if the
10619
11416
; treated by include-book much like certified books, in order to assist his
10620
11417
; development process.  That seems reasonable.
10621
11418
 
10622
 
                                    'include-book))
10623
 
                               (process-embedded-events
10624
 
                                'include-book
10625
 
                                event-form
10626
 
                                saved-acl2-defaults-table
10627
 
                                skip-proofsp
10628
 
                                (cadr (car ev-lst))
10629
 
                                (list 'include-book full-book-name)
10630
 
                                (subst-by-position expansion-alist
10631
 
                                                   (cdr ev-lst)
10632
 
                                                   1)
10633
 
                                1
10634
 
                                (eq skip-proofsp 'include-book)
10635
 
                                ctx state)))
10636
 
 
10637
 
; This function returns what might be called proto-wrld3, which is
10638
 
; equivalent to the current world of state before the
10639
 
; process-embedded-events (since the insigs argument is nil), but it has
10640
 
; an incremented embedded-event-depth.  We don't care about this
10641
 
; world.  The interesting world is the one current in the state
10642
 
; returned by by process-embedded-events.  It has all the embedded
10643
 
; events in it and we are done except for certification issues.
10644
 
 
10645
 
                            (let* ((wrld2 (w state))
10646
 
                                   (actual-alist (global-val 'include-book-alist
10647
 
                                                             wrld2)))
10648
 
                              (er-progn
10649
 
                               (cond
10650
 
                                ((and cert-obj
10651
 
                                      (not (include-book-alist-subsetp
10652
 
                                            (unmark-and-delete-local-included-books
10653
 
                                             (cdr post-alist))
10654
 
                                            actual-alist)))
10655
 
                                 (include-book-er
10656
 
                                  full-book-name nil
10657
 
                                  (cons "The certified book ~x0 requires ~*3 but ~
10658
 
                                      we have ~*4."
10659
 
                                        (list
10660
 
                                         (cons #\3
10661
 
                                               (tilde-*-book-check-sums-phrase
10662
 
                                                t
10663
 
                                                (unmark-and-delete-local-included-books
10664
 
                                                 (cdr post-alist))
10665
 
                                                actual-alist))
10666
 
                                         (cons #\4
10667
 
                                               (tilde-*-book-check-sums-phrase
10668
 
                                                nil
10669
 
                                                (unmark-and-delete-local-included-books
10670
 
                                                 (cdr post-alist))
10671
 
                                                actual-alist))))
10672
 
                                  :uncertified-okp
10673
 
                                  suspect-book-action-alist
10674
 
                                  ctx state))
10675
 
                                (t (value nil)))
 
11419
                                        'include-book))
 
11420
                                   (er-progn
 
11421
                                    (process-embedded-events
 
11422
                                     'include-book
 
11423
 
 
11424
; We do not allow process-embedded-events-to set the ACL2 defaults table at the
 
11425
; end.  For, consider the case that (defttag foo) has been executed just before
 
11426
; the (include-book "bar") being processed.  At the start of this
 
11427
; process-embedded-events we clear the acl2-defaults-table, removing any :ttag.
 
11428
; If we try to restore the acl2-defaults-table at the end of this
 
11429
; process-embedded-events, we will fail because the include-book-path was
 
11430
; extended above to include full-book-name (for "bar"), and the restoration
 
11431
; installs a :ttag of foo, yet in our example there is no :ttags argument for
 
11432
; (include-book "bar").  So, instead we directly set the 'table-alist property
 
11433
; of 'acl2-defaults-table directory for the install-event call below.
 
11434
 
 
11435
                                     :do-not-install
 
11436
                                     skip-proofsp
 
11437
                                     (cadr (car ev-lst))
 
11438
                                     (list 'include-book full-book-name)
 
11439
                                     (subst-by-position expansion-alist
 
11440
                                                        (cdr ev-lst)
 
11441
                                                        1)
 
11442
                                     1
 
11443
                                     (eq skip-proofsp 'include-book)
 
11444
                                     ctx state)
 
11445
                                    (value (f-get-global 'ttags-allowed
 
11446
                                                         state)))))))
 
11447
 
 
11448
; The above process-embedded-events call returns what might be called
 
11449
; proto-wrld3, which is equivalent to the current world of state before the
 
11450
; process-embedded-events (since the insigs argument is nil), but it has an
 
11451
; incremented embedded-event-depth.  We don't care about this world.  The
 
11452
; interesting world is the one current in the state returned by by
 
11453
; process-embedded-events.  It has all the embedded events in it and we are
 
11454
; done except for certification issues.
 
11455
 
 
11456
                              (let* ((wrld3 (w state))
 
11457
                                     (actual-alist (global-val 'include-book-alist
 
11458
                                                               wrld3)))
 
11459
                                (er-progn
 
11460
                                 (cond
 
11461
                                  ((and cert-obj
 
11462
                                        (not (include-book-alist-subsetp
 
11463
                                              (unmark-and-delete-local-included-books
 
11464
                                               (cdr post-alist))
 
11465
                                              actual-alist)))
 
11466
                                   (include-book-er
 
11467
                                    full-book-name nil
 
11468
                                    (cons "The certified book ~x0 requires ~
 
11469
                                           ~*3 but we have ~*4."
 
11470
                                          (list
 
11471
                                           (cons #\3
 
11472
                                                 (tilde-*-book-check-sums-phrase
 
11473
                                                  t
 
11474
                                                  (unmark-and-delete-local-included-books
 
11475
                                                   (cdr post-alist))
 
11476
                                                  actual-alist))
 
11477
                                           (cons #\4
 
11478
                                                 (tilde-*-book-check-sums-phrase
 
11479
                                                  nil
 
11480
                                                  (unmark-and-delete-local-included-books
 
11481
                                                   (cdr post-alist))
 
11482
                                                  actual-alist))))
 
11483
                                    :uncertified-okp
 
11484
                                    suspect-book-action-alist
 
11485
                                    ctx state))
 
11486
                                  (t (value nil)))
10676
11487
 
10677
11488
; Now we check that all the subbooks of this one are also compatible with the
10678
11489
; current settings of suspect-book-action-alist.  The car of post-alist is the
10680
11491
; which lists the subbooks.  The cert-obj may be nil, which makes the test
10681
11492
; below a no-op.
10682
11493
 
10683
 
                               (chk-cert-annotations-post-alist
10684
 
                                (cdr post-alist)
10685
 
                                (and cert-obj
10686
 
                                     (access cert-obj cert-obj :cmds))
10687
 
                                full-book-name
10688
 
                                suspect-book-action-alist
10689
 
                                ctx state)
 
11494
                                 (chk-cert-annotations-post-alist
 
11495
                                  (cdr post-alist)
 
11496
                                  (and cert-obj
 
11497
                                       (access cert-obj cert-obj :cmds))
 
11498
                                  full-book-name
 
11499
                                  suspect-book-action-alist
 
11500
                                  ctx state)
10690
11501
 
10691
 
                               (let* ((cert-annotations
10692
 
                                       (cadddr (car post-alist)))
 
11502
                                 (let* ((cert-annotations
 
11503
                                         (cadddr (car post-alist)))
10693
11504
 
10694
11505
; If cert-obj is nil, then cert-annotations is nil.  If cert-obj is
10695
11506
; non-nil, then cert-annotations is non-nil.  Cert-annotations came
10696
11507
; from a .cert file, and they are always non-nil.  But in the
10697
11508
; following, cert-annotations may be nil.
10698
11509
 
10699
 
                                      (certification-tuple
10700
 
                                       (cond
10701
 
                                        ((and cert-obj
10702
 
                                              (equal (caddr (car post-alist))
10703
 
                                                     familiar-name)
10704
 
                                              (equal (cddddr (car post-alist))
10705
 
                                                     ev-lst-chk-sum)
10706
 
                                              (include-book-alist-subsetp
10707
 
                                               (unmark-and-delete-local-included-books
10708
 
                                                (cdr post-alist))
10709
 
                                               actual-alist))
 
11510
                                        (certification-tuple
 
11511
                                         (cond
 
11512
                                          ((and cert-obj
 
11513
                                                (equal (caddr (car post-alist))
 
11514
                                                       familiar-name)
 
11515
                                                (equal (cddddr (car post-alist))
 
11516
                                                       ev-lst-chk-sum)
 
11517
                                                (include-book-alist-subsetp
 
11518
                                                 (unmark-and-delete-local-included-books
 
11519
                                                  (cdr post-alist))
 
11520
                                                 actual-alist))
10710
11521
 
10711
11522
; Below we use the full book name from the certificate, cert-full-book-name,
10712
11523
; rather than full-book-name (from the parse of the user-book-name), in
10825
11636
                                 (pprogn
10826
11637
                                  #-acl2-loop-only
10827
11638
                                  (progn
10828
 
                                    (load-compiled-file-if-more-recent
10829
 
                                     ctx
10830
 
                                     (and (eq load-compiled-file :comp!)
10831
 
                                          (newly-defined-top-level-fns
10832
 
                                           wrld-after-certificate wrld2))
10833
 
                                     load-compiled-file full-book-name
10834
 
                                     directory-name expansion-alist ev-lst)
 
11639
                                    (state-global-let*
 
11640
                                     ((ld-skip-proofsp 'include-book))
 
11641
                                     (progn
 
11642
                                       (load-compiled-file-if-more-recent
 
11643
                                        ctx
 
11644
                                        (and (eq load-compiled-file :comp!)
 
11645
                                             (newly-defined-top-level-fns
 
11646
                                              wrld2 wrld3))
 
11647
                                        load-compiled-file full-book-name
 
11648
                                        directory-name expansion-alist ev-lst)
 
11649
                                       (value nil)))
10835
11650
                                    state)
10836
11651
                                  (redefined-warning redef ctx state)
10837
11652
                                  (f-put-global 'include-book-alist-state
10843
11658
                                                   'include-book-alist-state
10844
11659
                                                   state)))
10845
11660
                                                state)
 
11661
                                  (f-put-global 'ttags-allowed
 
11662
                                                ttags-allowed1
 
11663
                                                state)
10846
11664
                                  (install-event
10847
11665
                                   (if behalf-of-certify-flg
10848
11666
                                       ev-lst-chk-sum
10864
11682
                                   'include-book
10865
11683
                                   full-book-name
10866
11684
                                   nil nil t ctx
10867
 
                                   (global-set
10868
 
                                    'include-book-path
10869
 
                                    old-include-book-path
10870
 
                                    (update-doc-data-base
10871
 
                                     full-book-name doc doc-pair
10872
 
                                     (global-set
10873
 
                                      'certification-tuple
10874
 
                                      certification-tuple
10875
 
                                      (global-set 'include-book-alist
10876
 
                                                  (add-to-set-equal
10877
 
                                                   certification-tuple
10878
 
                                                   (global-val
10879
 
                                                    'include-book-alist
10880
 
                                                    wrld2))
10881
 
                                                  wrld2))))
10882
 
                                   state)))))))))))))))))))))))))
 
11685
                                   (let ((wrld4
 
11686
                                          (global-set?
 
11687
                                           'ttags-seen
 
11688
                                           (cdr ttags-info)
 
11689
                                           (global-set
 
11690
                                            'include-book-path
 
11691
                                            old-include-book-path
 
11692
                                            (update-doc-data-base
 
11693
                                             full-book-name doc doc-pair
 
11694
                                             (global-set
 
11695
                                              'certification-tuple
 
11696
                                              certification-tuple
 
11697
                                              (global-set 'include-book-alist
 
11698
                                                          (add-to-set-equal
 
11699
                                                           certification-tuple
 
11700
                                                           (global-val
 
11701
                                                            'include-book-alist
 
11702
                                                            wrld3))
 
11703
                                                          wrld3))))
 
11704
                                           old-ttags-seen)))
 
11705
                                     (if (equal (table-alist
 
11706
                                                 'acl2-defaults-table
 
11707
                                                 wrld3)
 
11708
                                                saved-acl2-defaults-table)
 
11709
                                         wrld4
 
11710
                                       (putprop 'acl2-defaults-table
 
11711
                                                'table-alist
 
11712
                                                saved-acl2-defaults-table
 
11713
                                                wrld4)))
 
11714
                                   state))))))))))))))))))))))))))))
10883
11715
 
10884
11716
(defun spontaneous-decertificationp1 (ibalist alist files)
10885
11717
 
10937
11769
 
10938
11770
  (spontaneous-decertificationp1 alist1 (strip-cddrs alist2) nil))
10939
11771
 
10940
 
(defun raw-mode-ever-entered-p (state)
10941
 
  (consp (f-get-global 'raw-mode-restore-lst state)))
10942
 
 
10943
 
(defun raw-mode-error (ctx further-info state)
10944
 
  (er soft ctx
10945
 
      "Illegal use of ~x0: raw mode has been ~
10946
 
       entered during this ACL2 session.~s1"
10947
 
      (if (consp ctx) (car ctx) ctx)
10948
 
      (or further-info "")))
10949
 
 
10950
11772
; The following code is used to determine whether the portcullis
10951
11773
; contains a skip-proofs and to note include-books.
10952
11774
 
11274
12096
         (set-difference-eq-sorted (cdr lst1) lst2 (cons (car lst1) ans)))
11275
12097
        (t (set-difference-eq-sorted lst1 (cdr lst2) ans))))
11276
12098
 
 
12099
(defun certify-book-disabledp (state)
 
12100
  (f-get-global 'certify-book-disabledp state))
 
12101
 
11277
12102
(defun certify-book-fn (user-book-name k compile-flg
11278
12103
                                       defaxioms-okp
11279
12104
                                       skip-proofs-okp
 
12105
                                       ttags
11280
12106
                                       save-expansion
11281
12107
                                       state event-form)
11282
12108
 
11286
12112
; Note that we want to inhibit proof-tree output in the summary, which is why
11287
12113
; we bind inhibit-output-lst so early.
11288
12114
 
 
12115
  (declare (ignore event-form))
11289
12116
  (with-ctx-summarized
11290
12117
   (if (output-in-infixp state)
11291
12118
       (list* 'certify-book user-book-name
11294
12121
                '(irrelevant)))
11295
12122
     (cons 'certify-book user-book-name))
11296
12123
   (cond
11297
 
    ((raw-mode-ever-entered-p state)
11298
 
     (raw-mode-error ctx nil state))
 
12124
    ((certify-book-disabledp state)
 
12125
     (er soft ctx
 
12126
         "Certify-book has been disabled in this session because ~@0."
 
12127
         (certify-book-disabledp state)))
11299
12128
    ((and (stringp user-book-name)
11300
12129
          (let ((len (length user-book-name)))
11301
12130
            (and (<= 10 len) ; 10 = (length "@expansion")
11304
12133
     (er soft ctx
11305
12134
         "Book names may not end in \"@expansion\"."))
11306
12135
    (t
11307
 
     (state-global-let*
11308
 
      ((in-certify-book-flg t)
11309
 
       (inhibit-output-lst
11310
 
        (add-to-set-eq 'proof-tree
11311
 
                       (f-get-global 'inhibit-output-lst state)))
11312
 
       (match-free-error nil)
11313
 
       (defaxioms-okp-cert defaxioms-okp)
11314
 
       (skip-proofs-okp-cert skip-proofs-okp)
11315
 
       (guard-checking-on nil)) ; see the Essay on Guard Checking
11316
 
      (let ((saved-acl2-defaults-table
11317
 
             (table-alist 'acl2-defaults-table (w state)))
 
12136
     (er-let*
 
12137
      ((ttags (chk-well-formed-ttags ttags (cbd) ctx state))
 
12138
       (pair0 (let ((wrld (w state)))
 
12139
                (chk-acceptable-ttags1
 
12140
 
 
12141
; We check whether the ttags in the certification world are legal for the given
 
12142
; ttags, and if so we refine ttags, as described in chk-acceptable-ttag1.
 
12143
 
 
12144
                 (global-val 'ttags-seen wrld)
 
12145
                 nil ; correct active-book-name, but irrelevant
 
12146
                 ttags
 
12147
                 nil ; irrelevant value for ttags-seen
 
12148
                 :quiet ; defttags in certification world were already reported
 
12149
                 ctx state))))
 
12150
      (mv-let
 
12151
       (full-book-name directory-name familiar-name)
 
12152
       (parse-book-name (cbd) user-book-name ".lisp" (os (w state)))
 
12153
       (state-global-let*
 
12154
        ((certify-book-info full-book-name)
 
12155
         (inhibit-output-lst
 
12156
          (add-to-set-eq 'proof-tree
 
12157
                         (f-get-global 'inhibit-output-lst state)))
 
12158
         (match-free-error nil)
 
12159
         (defaxioms-okp-cert defaxioms-okp)
 
12160
         (skip-proofs-okp-cert skip-proofs-okp)
 
12161
         (guard-checking-on nil)) ; see the Essay on Guard Checking
 
12162
        (let ((saved-acl2-defaults-table
 
12163
               (table-alist 'acl2-defaults-table (w state)))
11318
12164
 
11319
12165
; If you add more keywords to this list, make sure you do the same to
11320
12166
; the list constructed by include-book-fn.  Also, you might wish to
11321
12167
; handle the new warning summary in warning1.
11322
12168
 
11323
 
            (suspect-book-action-alist
11324
 
             (list '(:uncertified-okp . nil)
11325
 
                   (cons :defaxioms-okp defaxioms-okp)
11326
 
                   (cons :skip-proofs-okp skip-proofs-okp)))
11327
 
            #-acl2-loop-only
11328
 
            (*inside-include-book-fn* t)
11329
 
            #+(and clisp (not acl2-loop-only))
11330
 
            (custom::*suppress-check-redefinition* t)
11331
 
            #+(and allegro (not acl2-loop-only))
11332
 
            (excl:*redefinition-warnings* nil))
11333
 
        (mv-let
11334
 
          (full-book-name directory-name familiar-name)
11335
 
          (parse-book-name (cbd) user-book-name ".lisp" (os (w state)))
 
12169
              (suspect-book-action-alist
 
12170
               (list '(:uncertified-okp . nil)
 
12171
                     (cons :defaxioms-okp defaxioms-okp)
 
12172
                     (cons :skip-proofs-okp skip-proofs-okp)))
 
12173
              #-acl2-loop-only
 
12174
              (*inside-include-book-fn* t)
 
12175
              #+(and clisp (not acl2-loop-only))
 
12176
              (custom::*suppress-check-redefinition* t)
 
12177
              #+(and allegro (not acl2-loop-only))
 
12178
              (excl:*redefinition-warnings* nil))
11336
12179
          (er-let*
11337
12180
           ((portcullis ; (cmds . pre-alist).
11338
 
             (chk-acceptable-certify-book user-book-name full-book-name k
11339
 
                                          ctx state
 
12181
             (chk-acceptable-certify-book user-book-name
 
12182
                                          full-book-name k ctx state
11340
12183
                                          suspect-book-action-alist)))
11341
 
           (let* ((wrld1 (w state)))
 
12184
           (let ((wrld1 (w state)))
11342
12185
             (pprogn
11343
12186
              (io? event nil state
11344
12187
                   (full-book-name)
11355
12198
              (er-let*
11356
12199
               ((ev-lst (read-object-file full-book-name ctx state)))
11357
12200
               (mv-let
11358
 
                 (ev-lst-chk-sum state) ; later we'll include
11359
 
                 (check-sum-obj ev-lst state)
11360
 
                 (cond
11361
 
                  ((not (integerp ev-lst-chk-sum))
11362
 
                   (er soft ctx
11363
 
                       "The file ~x0 is not a legal list of embedded event ~
 
12201
                (ev-lst-chk-sum state) ; later we'll include
 
12202
                (check-sum-obj ev-lst state)
 
12203
                (cond
 
12204
                 ((not (integerp ev-lst-chk-sum))
 
12205
                  (er soft ctx
 
12206
                      "The file ~x0 is not a legal list of embedded event ~
11364
12207
                        forms because it contains an object, ~x1, which check ~
11365
12208
                        sum was unable to handle."
11366
 
                       full-book-name ev-lst-chk-sum))
11367
 
                  (t (pprogn
11368
 
                      (io? event nil state
11369
 
                           (ev-lst)
11370
 
                           (fms "* Step 2:  There ~#0~[were no forms in the ~
11371
 
                                 file. Why are you making such a silly ~
11372
 
                                 book?~/was one form in the file.~/were ~n1 ~
11373
 
                                 forms in the file.~]  We now attempt to ~
11374
 
                                 establish that each form, whether local or ~
11375
 
                                 non-local, is indeed an admissible embedded ~
11376
 
                                 event form in the context of the previously ~
11377
 
                                 admitted ones.  Note that proof-tree output ~
11378
 
                                 is inhibited during this check; see :DOC ~
11379
 
                                 proof-tree.~%"
11380
 
                                (list (cons #\0 (zero-one-or-more ev-lst))
11381
 
                                      (cons #\1 (length ev-lst)))
11382
 
                                (proofs-co state) state nil))
11383
 
                      (er-let*
11384
 
                       ((pass1-result
11385
 
                         (state-global-let*
11386
 
                          (
 
12209
                      full-book-name ev-lst-chk-sum))
 
12210
                 (t
 
12211
                  (pprogn
 
12212
                   (io? event nil state
 
12213
                        (ev-lst)
 
12214
                        (fms "* Step 2:  There ~#0~[were no forms in the ~
 
12215
                              file. Why are you making such a silly ~
 
12216
                              book?~/was one form in the file.~/were ~n1 ~
 
12217
                              forms in the file.~]  We now attempt to ~
 
12218
                              establish that each form, whether local or ~
 
12219
                              non-local, is indeed an admissible embedded ~
 
12220
                              event form in the context of the previously ~
 
12221
                              admitted ones.  Note that proof-tree output is ~
 
12222
                              inhibited during this check; see :DOC ~
 
12223
                              proof-tree.~%"
 
12224
                             (list (cons #\0 (zero-one-or-more ev-lst))
 
12225
                                   (cons #\1 (length ev-lst)))
 
12226
                             (proofs-co state) state nil))
 
12227
                   (er-let*
 
12228
                    ((pass1-result
 
12229
                      (state-global-let*
 
12230
                       ((ttags-allowed (car pair0))
11387
12231
 
11388
12232
; We ``accumulate'' into the flag skipped-proofsp whether there are any
11389
12233
; skip-proofs in sight.  See the Essay on Skip-proofs.
11390
12234
 
11391
 
                           (skipped-proofsp nil)
11392
 
                           (include-book-alist-state nil)
 
12235
                        (skipped-proofsp nil)
 
12236
                        (include-book-alist-state nil)
11393
12237
 
11394
12238
; We will accumulate into the flag axiomsp whether any axioms have been added,
11395
12239
; starting with those in the portcullis.  We can identify axioms in the
11396
12240
; portcullis by asking if the current nonconstructive axioms are different from
11397
12241
; those at the end of boot-strap.
11398
12242
 
11399
 
                           (axiomsp (not
11400
 
                                     (equal
11401
 
                                      (global-val   ;;; axioms as of boot-strap
11402
 
                                       'nonconstructive-axiom-names
11403
 
                                       (scan-to-landmark-number
11404
 
                                        'event-landmark
11405
 
                                        (global-val 'event-number-baseline
11406
 
                                                    wrld1)
11407
 
                                        wrld1))
11408
 
                                      (global-val   ;;; axioms now.
11409
 
                                       'nonconstructive-axiom-names
11410
 
                                       wrld1))))
11411
 
 
11412
 
                           (ld-redefinition-action nil)
11413
 
                           (connected-book-directory directory-name))
11414
 
                          (revert-world-on-error
11415
 
                           (er-progn
11416
 
                            (note-certification-world-lst
11417
 
                             (car portcullis)
11418
 
                             (w state)
11419
 
                             ctx
11420
 
                             state
 
12243
                        (axiomsp (not
 
12244
                                  (equal
 
12245
                                   (global-val   ;;; axioms as of boot-strap
 
12246
                                    'nonconstructive-axiom-names
 
12247
                                    (scan-to-landmark-number
 
12248
                                     'event-landmark
 
12249
                                     (global-val 'event-number-baseline
 
12250
                                                 wrld1)
 
12251
                                     wrld1))
 
12252
                                   (global-val   ;;; axioms now.
 
12253
                                    'nonconstructive-axiom-names
 
12254
                                    wrld1))))
 
12255
                        (ld-redefinition-action nil)
 
12256
                        (connected-book-directory directory-name))
 
12257
                       (revert-world-on-error
 
12258
                        (er-progn
 
12259
                         (note-certification-world-lst
 
12260
                          (car portcullis)
 
12261
                          (w state)
 
12262
                          ctx
 
12263
                          state
11421
12264
 
11422
12265
; This list of names must be the same as in chk-acceptable-certify-book.
11423
12266
 
11424
 
                             (cons 'defpkg
11425
 
                                   *primitive-event-macros*)
11426
 
                             suspect-book-action-alist)
 
12267
                          (cons 'defpkg
 
12268
                                *primitive-event-macros*)
 
12269
                          suspect-book-action-alist)
11427
12270
 
11428
12271
; The fact that we are under 'certify-book means that all calls of
11429
12272
; include-book will insist that the :uncertified-okp action is nil, meaning
11430
12273
; errors will be caused if uncertified books are read.
11431
12274
 
11432
 
                            (er-let*
11433
 
                             ((expansion-alist
11434
 
                               (process-embedded-events
11435
 
                                'certify-book
11436
 
                                event-form
11437
 
                                saved-acl2-defaults-table
11438
 
                                nil (cadr (car ev-lst))
11439
 
                                (list 'certify-book full-book-name)
11440
 
                                (cdr ev-lst)
11441
 
                                1 nil 'certify-book state)))
11442
 
                             (value (list (f-get-global 'skipped-proofsp state)
11443
 
                                          (f-get-global 'axiomsp state)
11444
 
                                          (f-get-global
11445
 
                                           'include-book-alist-state
11446
 
                                           state)
11447
 
                                          expansion-alist))))))))
11448
 
                       (let* ((pass1-known-package-alist
11449
 
                               (global-val 'known-package-alist (w state)))
11450
 
                              (skipped-proofsp (car pass1-result))
11451
 
                              (axiomsp (cadr pass1-result))
11452
 
                              (new-include-book-alist-state
11453
 
                               (caddr pass1-result))
11454
 
                              (expansion-alist (cadddr pass1-result))
11455
 
                              (cert-annotations
11456
 
                               (list 
 
12275
                         (er-let*
 
12276
                          ((expansion-alist
 
12277
                            (process-embedded-events
 
12278
                             'certify-book
 
12279
                             saved-acl2-defaults-table
 
12280
                             nil (cadr (car ev-lst))
 
12281
                             (list 'certify-book full-book-name)
 
12282
                             (cdr ev-lst)
 
12283
                             1 nil 'certify-book state)))
 
12284
                          (value (list (f-get-global 'skipped-proofsp state)
 
12285
                                       (f-get-global 'axiomsp state)
 
12286
                                       (global-val 'ttags-seen (w state))
 
12287
                                       (f-get-global
 
12288
                                        'include-book-alist-state
 
12289
                                        state)
 
12290
                                       expansion-alist))))))))
 
12291
                    (let* ((pass1-known-package-alist
 
12292
                            (global-val 'known-package-alist (w state)))
 
12293
                           (skipped-proofsp (car pass1-result))
 
12294
                           (axiomsp (cadr pass1-result))
 
12295
                           (ttags-seen (caddr pass1-result))
 
12296
                           (new-include-book-alist-state
 
12297
                            (cadddr pass1-result))
 
12298
                           (expansion-alist (cadddr (cdr pass1-result)))
 
12299
                           (cert-annotations
 
12300
                            (list 
11457
12301
                                
11458
12302
; We set :skipped-proofsp in the certification annotations to t or nil
11459
12303
; according to whether there were any skipped proofs in either the
11460
12304
; portcullis or the body of this book.
11461
12305
 
11462
 
                                (cons :skipped-proofsp
11463
 
                                      skipped-proofsp)
 
12306
                             (cons :skipped-proofsp skipped-proofsp)
11464
12307
 
11465
12308
; We similarly set :axiomsp to t or nil.  Note that axioms in subbooks 
11466
12309
; are not counted as axioms in this one.
11467
12310
 
11468
 
                                (cons :axiomsp
11469
 
                                      axiomsp))))
 
12311
                             (cons :axiomsp axiomsp)
 
12312
                             (cons :ttags ttags-seen))))
 
12313
                      (er-let*
 
12314
                       ((chk-sum
 
12315
                         (cond
 
12316
                          (expansion-alist
 
12317
                           (mv-let
 
12318
                            (chk-sum state)
 
12319
                            (check-sum-obj (append expansion-alist
 
12320
                                                   ev-lst)
 
12321
                                           state)
 
12322
                            (value chk-sum)))
 
12323
                          (t (value ev-lst-chk-sum))))
 
12324
                        (post-alist1
 
12325
                         (value (cons (list* full-book-name
 
12326
                                             user-book-name
 
12327
                                             familiar-name
 
12328
                                             cert-annotations
 
12329
                                             chk-sum)
 
12330
                                      new-include-book-alist-state))))
 
12331
                       (er-progn
 
12332
                        (chk-cert-annotations cert-annotations
 
12333
                                              (car portcullis)
 
12334
                                              full-book-name
 
12335
                                              suspect-book-action-alist
 
12336
                                              ctx state)
 
12337
                        (pprogn
 
12338
                         (io? event nil state
 
12339
                              nil
 
12340
                              (fms "* Step 3:  That completes the ~
 
12341
                                    admissibility check.  Each form read was ~
 
12342
                                    an embedded event form and was ~
 
12343
                                    admissible. We now retract back to the ~
 
12344
                                    initial world and try to include the ~
 
12345
                                    book.  This may expose local ~
 
12346
                                    incompatibilities.~%"
 
12347
                                   nil
 
12348
                                   (proofs-co state) state nil))
 
12349
                         (set-w 'retraction wrld1 state)
11470
12350
                         (er-let*
11471
 
                          ((chk-sum
11472
 
                            (cond
11473
 
                             (expansion-alist
11474
 
                              (mv-let
11475
 
                               (chk-sum state)
11476
 
                               (check-sum-obj (append expansion-alist
11477
 
                                                      ev-lst)
11478
 
                                              state)
11479
 
                               (value chk-sum)))
11480
 
                             (t (value ev-lst-chk-sum))))
11481
 
                           (post-alist1
11482
 
                            (value (cons (list* full-book-name
11483
 
                                                user-book-name
11484
 
                                                familiar-name
11485
 
                                                cert-annotations
11486
 
                                                chk-sum)
11487
 
                                         new-include-book-alist-state))))
11488
 
                          (er-progn
11489
 
                           (chk-cert-annotations cert-annotations
11490
 
                                                 (car portcullis)
11491
 
                                                 full-book-name
11492
 
                                                 suspect-book-action-alist
11493
 
                                                 ctx state)
11494
 
                           (pprogn
11495
 
                            (io? event nil state
11496
 
                                 nil
11497
 
                                 (fms "* Step 3:  That completes the ~
11498
 
                                       admissibility check.  Each form read ~
11499
 
                                       was an embedded event form and was ~
11500
 
                                       admissible. We now retract back to the ~
11501
 
                                       initial world and try to include the ~
11502
 
                                       book.  This may expose local ~
11503
 
                                       incompatibilities.~%"
11504
 
                                      nil
11505
 
                                      (proofs-co state) state nil))
11506
 
                            (set-w 'retraction wrld1 state)
11507
 
                            (er-let*
11508
 
                             ((defpkg-items
11509
 
                                (defpkg-items
11510
 
                                  pass1-known-package-alist
11511
 
                                  ctx wrld1 state))
11512
 
                              (new-chk-sum
11513
 
                               (state-global-let*
11514
 
                                ((ld-redefinition-action nil))
 
12351
                          ((defpkg-items
 
12352
                             (defpkg-items
 
12353
                               pass1-known-package-alist
 
12354
                               ctx wrld1 state))
 
12355
                           (new-chk-sum
 
12356
                            (state-global-let*
 
12357
                             ((ld-redefinition-action nil))
11515
12358
 
11516
12359
; Note that we do not bind connected-book-directory before calling
11517
12360
; include-book-fn, because it will bind it for us.  We leave the directory set
11518
12361
; as it was when we parsed user-book-name to get full-book-name, so that
11519
12362
; include-book-fn will parse user-book-name the same way again.
11520
12363
 
11521
 
                                (include-book-fn user-book-name state nil
11522
 
                                                 expansion-alist
11523
 
                                                 nil
11524
 
                                                 defaxioms-okp skip-proofs-okp
11525
 
                                                 nil nil nil))))
11526
 
                             (let* ((wrld2 (w state))
11527
 
                                    (new-defpkg-list
11528
 
                                     (new-defpkg-list
11529
 
                                      defpkg-items
11530
 
                                      (global-val 'known-package-alist wrld2)))
11531
 
                                    (new-fns (and (or (not (warning-disabled-p
11532
 
                                                            "Guards"))
11533
 
                                                      (eq compile-flg :all))
 
12364
                             (include-book-fn user-book-name state nil
 
12365
                                              expansion-alist
 
12366
                                              nil
 
12367
                                              defaxioms-okp skip-proofs-okp
 
12368
                                              ttags-seen
 
12369
                                              nil nil nil))))
 
12370
                          (let* ((wrld2 (w state))
 
12371
                                 (new-defpkg-list
 
12372
                                  (new-defpkg-list
 
12373
                                   defpkg-items
 
12374
                                   (global-val 'known-package-alist wrld2)))
 
12375
                                 (new-fns (and (or (not (warning-disabled-p
 
12376
                                                         "Guards"))
 
12377
                                                   (eq compile-flg :all))
11534
12378
 
11535
12379
; The test above is an optimization; we don't need new-fns if it's false.
11536
12380
 
11537
 
                                                  (newly-defined-top-level-fns
11538
 
                                                   wrld1 wrld2)))
11539
 
                                    (new-fns-exec (and (eq compile-flg :all)
11540
 
                                                       new-fns))
11541
 
                                    (expansion-filename ; nil for "do not write it"
11542
 
                                     (and (or (eq save-expansion :save)
11543
 
                                              new-fns-exec
11544
 
                                              expansion-alist)
11545
 
                                          (expansion-filename full-book-name)))
11546
 
                                    (post-alist2
11547
 
                                     (cons (list* full-book-name
11548
 
                                                  user-book-name
11549
 
                                                  familiar-name
 
12381
                                               (newly-defined-top-level-fns
 
12382
                                                wrld1 wrld2)))
 
12383
                                 (new-fns-exec (and (eq compile-flg :all)
 
12384
                                                    new-fns))
 
12385
                                 (expansion-filename ; nil for "do not write it"
 
12386
                                  (and (or (eq save-expansion :save)
 
12387
                                           new-fns-exec
 
12388
                                           expansion-alist)
 
12389
                                       (expansion-filename full-book-name)))
 
12390
                                 (post-alist2
 
12391
                                  (cons (list* full-book-name
 
12392
                                               user-book-name
 
12393
                                               familiar-name
11550
12394
 
11551
12395
; We use the cert-annotations from the first pass.  They are the ones that
11552
12396
; include the LOCAL events too.
11553
12397
 
11554
 
                                                  cert-annotations
11555
 
                                                  new-chk-sum)
11556
 
                                           (cdr (global-val 'include-book-alist
11557
 
                                                            wrld2)))))
 
12398
                                               cert-annotations
 
12399
                                               new-chk-sum)
 
12400
                                        (cdr (global-val 'include-book-alist
 
12401
                                                         wrld2)))))
11558
12402
 
11559
12403
; The cdr above removes the certification tuple stored by the
11560
12404
; include-book-fn itself.  That pair is guaranteed to be last one
11567
12411
; we've included (and hence recognize as redundant) until after we've
11568
12412
; completed the processing.
11569
12413
 
 
12414
                            (pprogn
 
12415
                             (mv-let
 
12416
                              (new-bad-fns all-bad-fns)
 
12417
                              (cond ((not (warning-disabled-p "Guards"))
 
12418
                                     (mv (collect-ideals new-fns wrld2 nil)
 
12419
                                         (collect-ideal-user-defuns wrld2)))
 
12420
                                    (t (mv nil nil)))
 
12421
                              (cond
 
12422
                               ((or new-bad-fns all-bad-fns)
 
12423
                                (let* ((new-bad-fns
 
12424
                                        (sort-symbol-listp
 
12425
                                         new-bad-fns))
 
12426
                                       (all-bad-fns
 
12427
                                        (sort-symbol-listp
 
12428
                                         all-bad-fns))
 
12429
                                       (extra-bad-fns
 
12430
                                        (set-difference-eq-sorted
 
12431
                                         all-bad-fns
 
12432
                                         new-bad-fns
 
12433
                                         nil)))
 
12434
                                  (warning$
 
12435
                                   ctx ("Guards")
 
12436
                                   "~#1~[~/The book ~x0 defines the ~
 
12437
                                    function~#2~[ ~&2, which has not had ~
 
12438
                                    its~/s ~&2, which have not had their~] ~
 
12439
                                    guards verified.  ~]~#3~[~/~#1~[For the ~
 
12440
                                    book ~x0, its~/Moreover, this book's~] ~
 
12441
                                    included sub-books ~#4~[~/and/or its ~
 
12442
                                    certification world ~]define ~
 
12443
                                    function~#5~[ ~&5, which has not had ~
 
12444
                                    its~/s ~&5, which have not had their~] ~
 
12445
                                    guards verified.  ~]See :DOC guards."
 
12446
                                   full-book-name
 
12447
                                   (if new-bad-fns 1 0)
 
12448
                                   new-bad-fns
 
12449
                                   (if extra-bad-fns 1 0)
 
12450
                                   (if (eql k 0) 0 1)
 
12451
                                   extra-bad-fns)))
 
12452
                               (t state)))
 
12453
                             (cond
 
12454
                              ((not (include-book-alist-subsetp post-alist2
 
12455
                                                                post-alist1))
 
12456
                               (let ((files (spontaneous-decertificationp
 
12457
                                             post-alist2
 
12458
                                             post-alist1)))
 
12459
                                 (cond
 
12460
                                  (files
 
12461
                                   (er soft ctx
 
12462
                                       "During Step 3, we loaded the ~
 
12463
                                        uncertified ~#0~[book ~&0.  This book ~
 
12464
                                        was certified when we looked at ~
 
12465
                                        it~/books ~&0. These books were ~
 
12466
                                        certified when we looked at them~] in ~
 
12467
                                        Step 2!  The most likely explanation ~
 
12468
                                        is that some concurrent job, possibly ~
 
12469
                                        by another user of your file system, ~
 
12470
                                        is currently recertifying ~#0~[this ~
 
12471
                                        book~/these books~] (or subbooks of ~
 
12472
                                        ~#0~[it~/them~]).  That hypothetical ~
 
12473
                                        job might have deleted the ~
 
12474
                                        certificate files of the books in ~
 
12475
                                        question, rendering ~#0~[this ~
 
12476
                                        one~/these~] uncertified.  If this ~
 
12477
                                        explanation seems likely, we ~
 
12478
                                        recommend that you identify the other ~
 
12479
                                        job and wait until it has ~
 
12480
                                        successfully completed."
 
12481
                                       files))
 
12482
                                  (t
 
12483
                                   (er soft ctx
 
12484
                                       "During Step 3, we loaded different ~
 
12485
                                        books than were loaded by Step 2!  ~
 
12486
                                        Here are the tuples produced by Step ~
 
12487
                                        3 of the form ~X04 whose CDDRs are ~
 
12488
                                        not in the list of tuples produced by ~
 
12489
                                        Step 2:~|~%~X14~|~%Perhaps some other ~
 
12490
                                        user of your file system was editing ~
 
12491
                                        the books during our Step 3? You ~
 
12492
                                        might think that some other job is ~
 
12493
                                        recertifying the books (or subbooks) ~
 
12494
                                        and has deleted the certificate ~
 
12495
                                        files, rendering uncertified some of ~
 
12496
                                        the books needed here.  But more has ~
 
12497
                                        happened!  Some file has changed (as ~
 
12498
                                        indicated above)!~%~%DETAILS.  Here ~
 
12499
                                        is the include-book-alist as of the ~
 
12500
                                        end of Step 2:~%~X24.~|~%And here is ~
 
12501
                                           the alist as of the end of Step ~
 
12502
                                           3:~%~X34.~|~%Frequently, the former ~
 
12503
                                        has more entries than the latter ~
 
12504
                                        because the former includes LOCAL ~
 
12505
                                        books. So compare corresponding ~
 
12506
                                        entries, focusing on those in the ~
 
12507
                                        latter.  Each entry is of the form ~
 
12508
                                        (name1 name2 name3 alist . chk-sum). ~
 
12509
                                        Name1 is the full name, name2 is the ~
 
12510
                                        name as written in an include-book ~
 
12511
                                        event, and name3 is the ``familiar'' ~
 
12512
                                        name of the file. The alist indicates ~
 
12513
                                        the presence or absence of ~
 
12514
                                        problematic forms in the file, such ~
 
12515
                                        as DEFAXIOM events.  For example, ~
 
12516
                                        (:AXIOMSP . T) means there were ~
 
12517
                                        defaxiom events; (:AXIOMSP . NIL) -- ~
 
12518
                                        which actually prints as (:AXIOMSP) ~
 
12519
                                        -- means there were no defaxiom ~
 
12520
                                        events. Finally, chk-sum is either an ~
 
12521
                                        integer check sum based on the ~
 
12522
                                        contents of the file at the time it ~
 
12523
                                        was certified or else chk-sum is nil ~
 
12524
                                        indicating that the file is not ~
 
12525
                                        certified.  Note that if the chk-sum ~
 
12526
                                        is nil, the entry prints as (name1 ~
 
12527
                                        name2 name3 alist).  Go figure."
 
12528
                                       '(:full-book-name
 
12529
                                         :user-book-name
 
12530
                                         :familiar-name
 
12531
                                         :cert-annotations
 
12532
                                         . :chk-sum-for-events)
 
12533
                                       (include-book-alist-subsetp-failure-witnesses
 
12534
                                        post-alist2
 
12535
                                        (strip-cddrs post-alist1)
 
12536
                                        nil)
 
12537
                                       post-alist1
 
12538
                                       post-alist2
 
12539
                                       nil)))))
 
12540
                              (t
11570
12541
                               (pprogn
11571
 
                                (mv-let
11572
 
                                 (new-bad-fns all-bad-fns)
11573
 
                                 (cond ((not (warning-disabled-p "Guards"))
11574
 
                                        (mv (collect-ideals new-fns wrld2 nil)
11575
 
                                            (collect-ideal-user-defuns wrld2)))
11576
 
                                       (t (mv nil nil)))
11577
 
                                 (cond ((or new-bad-fns all-bad-fns)
11578
 
                                        (let* ((new-bad-fns
11579
 
                                                (sort-symbol-listp
11580
 
                                                 new-bad-fns))
11581
 
                                               (all-bad-fns
11582
 
                                                (sort-symbol-listp
11583
 
                                                 all-bad-fns))
11584
 
                                               (extra-bad-fns
11585
 
                                                (set-difference-eq-sorted
11586
 
                                                 all-bad-fns
11587
 
                                                 new-bad-fns
11588
 
                                                 nil)))
11589
 
                                          (warning$
11590
 
                                           ctx ("Guards")
11591
 
                                           "~#1~[~/The book ~x0 defines the ~
11592
 
                                             function~#2~[ ~&2, which has not ~
11593
 
                                             had its~/s ~&2, which have not ~
11594
 
                                             had their~] guards verified.  ~
11595
 
                                             ~]~#3~[~/~#1~[For the book ~x0, ~
11596
 
                                             its~/Moreover, this book's~] ~
11597
 
                                             included sub-books ~#4~[~/and/or ~
11598
 
                                             its certification world ~]define ~
11599
 
                                             function~#5~[ ~&5, which has not ~
11600
 
                                             had its~/s ~&5, which have not ~
11601
 
                                             had their~] guards verified.  ~
11602
 
                                             ~]See :DOC guards."
11603
 
                                           full-book-name
11604
 
                                           (if new-bad-fns 1 0)
11605
 
                                           new-bad-fns
11606
 
                                           (if extra-bad-fns 1 0)
11607
 
                                           (if (eql k 0) 0 1)
11608
 
                                           extra-bad-fns)))
11609
 
                                       (t state)))
11610
 
                                (cond
11611
 
                                 ((not (include-book-alist-subsetp post-alist2
11612
 
                                                                   post-alist1))
11613
 
                                  (let ((files (spontaneous-decertificationp
11614
 
                                                post-alist2
11615
 
                                                post-alist1)))
11616
 
                                    (cond
11617
 
                                     (files
11618
 
                                      (er soft ctx
11619
 
                                          "During Step 3, we loaded the ~
11620
 
                                           uncertified ~#0~[book ~&0.  This ~
11621
 
                                           book was certified when we looked ~
11622
 
                                           at it~/books ~&0. These books were ~
11623
 
                                           certified when we looked at them~] ~
11624
 
                                           in Step 2!  The most likely ~
11625
 
                                           explanation is that some ~
11626
 
                                           concurrent job, possibly by ~
11627
 
                                           another user of your file system, ~
11628
 
                                           is currently recertifying ~
11629
 
                                           ~#0~[this book~/these books~] (or ~
11630
 
                                           subbooks of ~#0~[it~/them~]).  ~
11631
 
                                           That hypothetical job might have ~
11632
 
                                           deleted the certificate files of ~
11633
 
                                           the books in question, rendering ~
11634
 
                                           ~#0~[this one~/these~] ~
11635
 
                                           uncertified.  If this explanation ~
11636
 
                                           seems likely, we recommend that ~
11637
 
                                           you identify the other job and ~
11638
 
                                           wait until it has successfully ~
11639
 
                                           completed."
11640
 
                                          files))
11641
 
                                     (t
11642
 
                                      (er soft ctx
11643
 
                                          "During Step 3, we loaded different ~
11644
 
                                           books than were loaded by Step 2!  ~
11645
 
                                           Here are the tuples produced by ~
11646
 
                                           Step 3 of the form ~X04 whose ~
11647
 
                                           CDDRs are not in the list of ~
11648
 
                                           tuples produced by Step ~
11649
 
                                           2:~|~%~X14~|~%Perhaps some other ~
11650
 
                                           user of your file system was ~
11651
 
                                           editing the books during our Step ~
11652
 
                                           3? You might think that some other ~
11653
 
                                           job is recertifying the books (or ~
11654
 
                                           subbooks) and has deleted the ~
11655
 
                                           certificate files, rendering ~
11656
 
                                           uncertified some of the books ~
11657
 
                                           needed here.  But more has ~
11658
 
                                           happened!  Some file has changed ~
11659
 
                                           (as indicated above)!~%~%DETAILS.  ~
11660
 
                                           Here is the include-book-alist as ~
11661
 
                                           of the end of Step ~
11662
 
                                           2:~%~X24.~|~%And here is the alist ~
11663
 
                                           as of the end of Step ~
11664
 
                                           3:~%~X34.~|~%Frequently, the ~
11665
 
                                           former has more entries than the ~
11666
 
                                           latter because the former includes ~
11667
 
                                           LOCAL books. So compare ~
11668
 
                                           corresponding entries, focusing on ~
11669
 
                                           those in the latter.  Each entry ~
11670
 
                                           is of the form (name1 name2 name3 ~
11671
 
                                           alist . chk-sum). Name1 is the ~
11672
 
                                           full name, name2 is the name as ~
11673
 
                                           written in an include-book event, ~
11674
 
                                           and name3 is the ``familiar'' name ~
11675
 
                                           of the file. The alist indicates ~
11676
 
                                           the presence or absence of ~
11677
 
                                           problematic forms in the file, ~
11678
 
                                           such as DEFAXIOM events.  For ~
11679
 
                                           example, (:AXIOMSP . T) means ~
11680
 
                                           there were defaxiom events; ~
11681
 
                                           (:AXIOMSP . NIL) -- which actually ~
11682
 
                                           prints as (:AXIOMSP) -- means ~
11683
 
                                           there were no defaxiom events. ~
11684
 
                                           Finally, chk-sum is either an ~
11685
 
                                           integer check sum based on the ~
11686
 
                                           contents of the file at the time ~
11687
 
                                           it was certified or else chk-sum ~
11688
 
                                           is nil indicating that the file is ~
11689
 
                                           not certified.  Note that if the ~
11690
 
                                           chk-sum is nil, the entry prints ~
11691
 
                                           as (name1 name2 name3 alist).  Go ~
11692
 
                                           figure."
11693
 
                                          '(:full-book-name
11694
 
                                            :user-book-name
11695
 
                                            :familiar-name
11696
 
                                            :cert-annotations
11697
 
                                            . :chk-sum-for-events)
11698
 
                                          (include-book-alist-subsetp-failure-witnesses
11699
 
                                           post-alist2
11700
 
                                           (strip-cddrs post-alist1)
11701
 
                                           nil)
11702
 
                                          post-alist1
11703
 
                                          post-alist2
11704
 
                                          nil)))))
11705
 
                                 (t (pprogn
 
12542
                                (io? event nil state
 
12543
                                     (post-alist1 full-book-name
 
12544
                                                  expansion-filename)
 
12545
                                     (fms "* Step 4:  Write the certificate ~
 
12546
                                           for ~x0 in ~x1~@2.  The final ~
 
12547
                                           check sum alist is ~x3.~%"
 
12548
                                          (list
 
12549
                                           (cons #\0 full-book-name)
 
12550
                                           (cons
 
12551
                                            #\1
 
12552
                                            (convert-book-name-to-cert-name
 
12553
                                             full-book-name))
 
12554
                                           (cons
 
12555
                                            #\2
 
12556
                                            (if expansion-filename
 
12557
                                                (msg ", as well as the ~
 
12558
                                                      expansion file, ~@0"
 
12559
                                                     expansion-filename)
 
12560
                                              ""))
 
12561
                                           (cons #\3 post-alist1))
 
12562
                                          (proofs-co state) state nil))
 
12563
                                (er-progn
 
12564
                                 (if expansion-filename
 
12565
                                     (write-expansion-file
 
12566
                                      new-fns-exec expansion-filename
 
12567
                                      expansion-alist ev-lst ctx state)
 
12568
                                   (value nil))
 
12569
                                 (make-certificate-file
 
12570
                                  full-book-name
 
12571
                                  (cons
 
12572
                                   (remove-duplicates-equal-from-end
 
12573
                                    (append (car portcullis) new-defpkg-list)
 
12574
                                    nil)
 
12575
                                   (cdr portcullis))
 
12576
                                  post-alist1
 
12577
                                  post-alist2
 
12578
                                  expansion-alist
 
12579
                                  ctx
 
12580
                                  state)
 
12581
                                 (pprogn
 
12582
                                  (cond
 
12583
                                   (compile-flg
 
12584
                                    (pprogn
11706
12585
                                     (io? event nil state
11707
 
                                          (post-alist1 full-book-name
11708
 
                                                       expansion-filename)
11709
 
                                          (fms "* Step 4:  Write the ~
11710
 
                                               certificate for ~x0 in ~x1~@2.  ~
11711
 
                                               The final check sum alist is ~
11712
 
                                               ~x3.~%"
11713
 
                                               (list
11714
 
                                                (cons #\0 full-book-name)
11715
 
                                                (cons
11716
 
                                                 #\1
11717
 
                                                 (convert-book-name-to-cert-name
11718
 
                                                  full-book-name))
11719
 
                                                (cons
11720
 
                                                 #\2
11721
 
                                                 (if expansion-filename
11722
 
                                                     (msg ", as well as the ~
11723
 
                                                           expansion file, ~@0"
11724
 
                                                          expansion-filename)
11725
 
                                                   ""))
11726
 
                                                (cons #\3 post-alist1))
 
12586
                                          (full-book-name)
 
12587
                                          (fms "* Step 5:  Compile the ~
 
12588
                                                functions defined in ~x0.~%"
 
12589
                                               (list (cons #\0 full-book-name))
11727
12590
                                               (proofs-co state) state nil))
11728
 
                                     (er-progn
11729
 
                                      (if expansion-filename
11730
 
                                          (write-expansion-file
11731
 
                                           new-fns-exec expansion-filename
11732
 
                                           expansion-alist ev-lst ctx state)
11733
 
                                        (value nil))
11734
 
                                      (make-certificate-file
11735
 
                                       full-book-name
11736
 
                                       (cons
11737
 
                                        (remove-duplicates-equal-from-end
11738
 
                                         (append (car portcullis) new-defpkg-list)
11739
 
                                         nil)
11740
 
                                        (cdr portcullis))
11741
 
                                       post-alist1
11742
 
                                       post-alist2
11743
 
                                       expansion-alist
11744
 
                                       ctx
 
12591
                                     #-acl2-loop-only
 
12592
                                     (compile-certified-file
 
12593
                                      new-fns-exec
 
12594
                                      expansion-filename
 
12595
                                      full-book-name expansion-alist
 
12596
                                      state)
 
12597
                                     state))
 
12598
                                   (t
 
12599
                                    (pprogn
 
12600
                                     #-acl2-loop-only
 
12601
                                     (progn
 
12602
                                       (delete-compiled-file
 
12603
                                        (pathname-unix-to-os full-book-name
 
12604
                                                             state))
11745
12605
                                       state)
11746
 
                                      (pprogn
11747
 
                                       (cond
11748
 
                                        (compile-flg
11749
 
                                         (pprogn
11750
 
                                          (io? event nil state
11751
 
                                               (full-book-name)
11752
 
                                               (fms "* Step 5:  Compile the ~
11753
 
                                                     functions defined in ~
11754
 
                                                     ~x0.~%"
11755
 
                                                    (list (cons #\0 full-book-name))
11756
 
                                                    (proofs-co state) state nil))
11757
 
                                          #-acl2-loop-only
11758
 
                                          (compile-certified-file
11759
 
                                           new-fns-exec
11760
 
                                           expansion-filename
11761
 
                                           full-book-name expansion-alist
11762
 
                                           state)
11763
 
                                          state))
11764
 
                                        (t
11765
 
                                         (pprogn
11766
 
                                          #-acl2-loop-only
11767
 
                                          (progn
11768
 
                                            (delete-compiled-file
11769
 
                                             (pathname-unix-to-os full-book-name
11770
 
                                                                  state))
11771
 
                                            state)
11772
 
                                          state)))
11773
 
                                       #-acl2-loop-only
11774
 
                                       (progn
11775
 
                                         (when (and expansion-filename
11776
 
                                                    (not save-expansion))
11777
 
                                           (delete-file expansion-filename)
11778
 
                                           (io? event nil state
11779
 
                                                (expansion-filename)
11780
 
                                                (fms "Note: Deleting book ~
11781
 
                                                      expansion file,~%~s0.~|"
11782
 
                                                     (list
11783
 
                                                      (cons
11784
 
                                                       #\0
11785
 
                                                       expansion-filename))
11786
 
                                                     (proofs-co state) state
11787
 
                                                     nil)))
11788
 
                                         state)
11789
 
                                       (value
11790
 
                                        full-book-name)))))))))))))))))))))))))))))
 
12606
                                     state)))
 
12607
                                  #-acl2-loop-only
 
12608
                                  (progn
 
12609
                                    (when (and expansion-filename
 
12610
                                               (not save-expansion))
 
12611
                                      (delete-file expansion-filename)
 
12612
                                      (io? event nil state
 
12613
                                           (expansion-filename)
 
12614
                                           (fms "Note: Deleting book ~
 
12615
                                                 expansion file,~%~s0.~|"
 
12616
                                                (list
 
12617
                                                 (cons
 
12618
                                                  #\0
 
12619
                                                  expansion-filename))
 
12620
                                                (proofs-co state) state
 
12621
                                                nil)))
 
12622
                                    state)
 
12623
                                  (value
 
12624
                                   full-book-name))))))))))))))))))))))))))))))
11791
12625
 
11792
12626
#+acl2-loop-only
11793
12627
(defmacro certify-book (&whole event-form
11798
12632
                               &key
11799
12633
                               (defaxioms-okp 'nil)
11800
12634
                               (skip-proofs-okp 'nil)
 
12635
                               (ttags 'nil)
11801
12636
                               (save-expansion 'nil))
11802
12637
 
11803
12638
  ":Doc-Section Books
11818
12653
                :defaxioms-okp t/nil        ; [default nil]
11819
12654
                :skip-proofs-okp t/nil      ; [default nil]
11820
12655
                :save-expansion :save/t/nil ; [default nil]
 
12656
                :ttags ttags                ; [default nil]
11821
12657
                )
11822
12658
  ~ev[]
11823
12659
  where ~c[book-name] is a book name (~pl[book-name]), ~c[k] is
11834
12670
  such events, but prints a warning message.  The value ~c[nil] is the default,
11835
12671
  and causes an error if such an event is found.
11836
12672
 
 
12673
  The keyword argument ~c[:ttags] may normally be omitted.  A few constructs,
 
12674
  used for example if you are building your own system based on ACL2, may
 
12675
  require it.  ~l[defttag] for an explanation of this argument.
 
12676
 
11837
12677
  To advanced users only: in the rare case that you are willing to add to
11838
12678
  compilation time in return for compiling the executable counterparts of
11839
12679
  functions defined in the book, you may supply a value of ~c[:all] for
11907
12747
  The ~c[k] argument to ~c[certify-book] must be either a nonnegative integer
11908
12748
  or else one of the symbols ~c[t] or ~c[?] in the ~c[ACL2] package.  If ~c[k]
11909
12749
  is an integer, then it must be the number of ~il[command]s that have been
11910
 
  executed to create the ~il[world] in which ~c[certify-book] was called.  One
11911
 
  way to obtain this number is by doing ~c[:pbt 1] to see all the ~il[command]s
11912
 
  back to the first one.  The last ~il[command] number printed in the
11913
 
  ~c[:]~ilc[pbt] display is the appropriate ~c[k].  This number is just the
11914
 
  maximum ~il[command] number, ~c[:]~ilc[max] ~-[] ~pl[command-descriptor] ~-[]
11915
 
  but unless ~c[:]~ilc[max] is ~c[0,] ~c[certify-book] requires that you
11916
 
  actually input the number as a way of reminding you to inspect the ~il[world]
11917
 
  before calling ~c[certify-book].
 
12750
  executed after the initial ACL2 ~il[world] to create the ~il[world] in which
 
12751
  ~c[certify-book] was called.  One way to obtain this number is by doing
 
12752
  ~c[:pbt :start] to see all the ~il[command]s back to the first one.
11918
12753
 
11919
12754
  If ~c[k] is ~c[t] it means that ~c[certify-book] should use the same
11920
 
  ~il[world] used in the last certification of this book.  ~c[K] may be
11921
 
  ~c[t] only if you call ~c[certify-book] in the initial ACL2 ~il[world]
11922
 
  (~c[:max = 0]) and there is a ~il[certificate] on file for the book being
11923
 
  certified.  (Of course, the ~il[certificate] is probably invalid.)  In
11924
 
  this case, ~c[certify-book] reads the old ~il[certificate] to obtain
11925
 
  the ~il[portcullis] ~il[command]s and executes them to recreate the
11926
 
  certification ~il[world].
 
12755
  ~il[world] used in the last certification of this book.  ~c[K] may be ~c[t]
 
12756
  only if you call ~c[certify-book] in the initial ACL2 ~il[world] and there is
 
12757
  a ~il[certificate] on file for the book being certified.  (Of course, the
 
12758
  ~il[certificate] is probably invalid.)  In this case, ~c[certify-book] reads
 
12759
  the old ~il[certificate] to obtain the ~il[portcullis] ~il[command]s and
 
12760
  executes them to recreate the certification ~il[world].
11927
12761
 
11928
12762
  Finally, ~c[k] may be ~c[?], in which case there is no check made on the
11929
12763
  certification world.  That is, if ~c[k] is ~c[?] then no action related to
11974
12808
        (list 'quote compile-flg)
11975
12809
        (list 'quote defaxioms-okp)
11976
12810
        (list 'quote skip-proofs-okp)
 
12811
        (list 'quote ttags)
11977
12812
        (list 'quote save-expansion)
11978
12813
        'state
11979
12814
        (list 'quote event-form)))
12636
13471
  ~c[(@ acl2-version)].  The value will be a string.  For example,
12637
13472
  ~bv[]
12638
13473
  ACL2 !>(@ acl2-version)
12639
 
  \"ACL2 Version 3.0.1\"
 
13474
  \"ACL2 Version 3.1\"
12640
13475
  ~ev[]
12641
13476
  ~/
12642
13477
 
12973
13808
; used to compute the ignored vars will not cause an error.  We return
12974
13809
; a true list.  The formals and body will be checked thoroughly by the
12975
13810
; encapsulate, provided we generate it!  Provided they check out, the
12976
 
; result returned are the ignored formals.
 
13811
; result returned is the list of ignored formals.
12977
13812
 
12978
13813
  (if (and (symbol-listp formals)
12979
13814
           (or (symbolp body)
13154
13989
 
13155
13990
; Next we implement defchoose and defun-sk.
13156
13991
 
13157
 
(defun redundant-defchoosep (name event-form len wrld)
13158
 
 
 
13992
(defun redundant-defchoosep (name event-form wrld)
13159
13993
  (let* ((old-ev (get-event name wrld)))
13160
 
    (and old-ev
13161
 
         (eq (car old-ev) 'defchoose)
13162
 
         (eq (nth 1 event-form) (nth 1 old-ev))
13163
 
         (equal (nth 2 event-form) (nth 2 old-ev))
13164
 
         (equal (nth 3 event-form) (nth 3 old-ev))
13165
 
         (equal (if (= len 5)
13166
 
                    (nth 5 event-form)
13167
 
                  (nth 4 event-form))
13168
 
                (if (= (length (cdr old-ev)) 5)
13169
 
                    (nth 5 old-ev)
13170
 
                  (nth 4 old-ev))))))
 
13994
    (and
 
13995
     old-ev
 
13996
     (case-match old-ev
 
13997
       (('defchoose !name old-bound-vars old-free-vars old-body . old-rest)
 
13998
        (case-match event-form
 
13999
          (('defchoose !name new-bound-vars new-free-vars new-body . new-rest)
 
14000
           (and (equal old-bound-vars new-bound-vars)
 
14001
                (equal old-free-vars new-free-vars)
 
14002
                (equal old-body new-body)
 
14003
                (eq (cadr (assoc-keyword :strengthen old-rest))
 
14004
                    (cadr (assoc-keyword :strengthen new-rest)))))))))))
13171
14005
 
13172
14006
(defun chk-arglist-for-defchoose (args bound-vars-flg ctx state)
13173
14007
  (cond ((arglistp args) (value nil))
13187
14021
                       (if bound-vars-flg 0 1)
13188
14022
                       args culprit explan)))))
13189
14023
 
13190
 
(defun defchoose-constraint (fn bound-vars formals tbody ctx wrld state)
 
14024
(defun defchoose-constraint-basic (fn bound-vars formals tbody ctx wrld state)
13191
14025
 
13192
14026
; It seems a pity to translate tbody, since it's already translated, but that
13193
14027
; seems much simpler than the alternatives.
13225
14059
              consequent)
13226
14060
             *nil*))))))
13227
14061
 
 
14062
(defun defchoose-constraint-extra (fn bound-vars formals tbody ctx wrld state)
 
14063
 
 
14064
; WARNING: If the following comment is removed, then eliminate the reference to
 
14065
; it in :doc defchoose.
 
14066
 
 
14067
; Note that :doc conservativity-of-defchoose contains an argument showing that
 
14068
; we may assume that there is a definable enumeration, enum, of the universe.
 
14069
; Thus, for any definable property that is not always false, there is a "least"
 
14070
; witness, i.e., a least n for which (enum n) satisfies that property.  Thus, a
 
14071
; function defined with defchoose is definable: pick the least witness if there
 
14072
; is one, else nil.  From this definition it is clear that the following
 
14073
; formula holds, where formals2 is a copy of formals that is disjoint both from
 
14074
; formals and from bound-vars, and where tbody2 is the result of replacing
 
14075
; formals by formals2 in tbody, the translated body of the defchoose.  (If
 
14076
; bound-vars is a list of length 1, then we use let rather than mv-let in this
 
14077
; formula.)
 
14078
 
 
14079
; (or (equal (fn . formals)
 
14080
;            (fn . formals2))
 
14081
;     (mv-let (bound-vars (fn . formals))
 
14082
;       (and tbody
 
14083
;            (not tbody2)))
 
14084
;     (mv-let (bound-vars (fn . formals2))
 
14085
;       (and tbody2
 
14086
;            (not tbody1))))
 
14087
 
 
14088
; We now outline an argument for the :non-standard-analysis case, which in fact
 
14089
; provides justification for both defchoose axioms.  The idea is to assume that
 
14090
; there is a suitable well-ordering for the ground-zero theory and that the
 
14091
; ground-zero theory contains enough "invisible" functions so that this
 
14092
; property is preserved by extensions (as discussed in the JAR paper "Theory
 
14093
; Extensions in ACL2(r) by Gamboa and Cowles).  Here is a little more detail,
 
14094
; but a nice challenge is to work this out completely.
 
14095
 
 
14096
; The idea of the proof is first to start with what the above paper calls an
 
14097
; "r-complete" GZ: basically, a ground-zero theory satisfying induction and
 
14098
; transfer that contains a function symbol for each defun and defun-std.  We
 
14099
; can preserve r-completeness as we add defun, defun-std, encapsulate, and
 
14100
; defchoose events (again, as in the above paper).  The key idea for defchoose
 
14101
; is that GZ should also have a binary symbol, <|, that is axiomatized to be a
 
14102
; total order.  That is, <| is a "definable well order", in the sense that
 
14103
; there are axioms that guarantee for each phi(x) that (exists x phi) implies
 
14104
; that (exists <|-least x phi).  The trick is to add the well-ordering after
 
14105
; taking a nonstandard elementary extension of the standard reals MS, where
 
14106
; every function over the reals is represented in MS as the interpretation of a
 
14107
; function symbol.
 
14108
 
 
14109
; Still as in the above paper, there is a definable fn for the above defchoose,
 
14110
; obtained by picking the least witness.  Moreover, if body is classical then
 
14111
; we can first conjoin it with (standard-p bound-var), choose the <|-least
 
14112
; bound-var with a classical function using defun-std, and then show by
 
14113
; transfer that this function witnesses the original defchoose.
 
14114
 
 
14115
  (let* ((formals2 (generate-variable-lst formals (append bound-vars formals)
 
14116
                                          nil (ens state) wrld))
 
14117
         (equality (fcons-term* 'equal (cons fn formals) (cons fn formals2)))
 
14118
         (tbody2 (subcor-var formals formals2 tbody))
 
14119
         (raw-disjunct
 
14120
 
 
14121
; It seems a pity to translate tbody, since it's already translated, but that
 
14122
; seems much simpler than the alternatives.
 
14123
 
 
14124
          (cond
 
14125
           ((null (cdr bound-vars))
 
14126
            `(or (let ((,(car bound-vars) (,fn ,@formals)))
 
14127
                   (and ,tbody
 
14128
                        (not ,tbody2)))
 
14129
                 (let ((,(car bound-vars) (,fn ,@formals2)))
 
14130
                   (and ,tbody2
 
14131
                        (not ,tbody)))))
 
14132
           (t
 
14133
            `(or (mv-let ,bound-vars
 
14134
                         (,fn ,@formals)
 
14135
                         (and ,tbody
 
14136
                              (not ,tbody2)))
 
14137
                 (mv-let ,bound-vars
 
14138
                         (,fn ,@formals2)
 
14139
                         (and ,tbody2
 
14140
                              (not ,tbody))))))))
 
14141
    (er-let* ((disjunct
 
14142
               (translate raw-disjunct t t t ctx wrld state)))
 
14143
             (value (disjoin2 equality disjunct)))))
 
14144
 
 
14145
(defun defchoose-constraint (fn bound-vars formals tbody strengthen ctx wrld state)
 
14146
  (er-let* ((basic (defchoose-constraint-basic fn bound-vars formals tbody ctx
 
14147
                     wrld state)))
 
14148
           (cond
 
14149
            (strengthen
 
14150
             (er-let* ((extra (defchoose-constraint-extra fn bound-vars formals
 
14151
                                tbody ctx wrld state)))
 
14152
                      (value (conjoin2 basic extra))))
 
14153
            (t (value basic)))))
 
14154
 
13228
14155
(defun defchoose-fn (def state event-form)
 
14156
  (declare (xargs :guard (true-listp def))) ; def comes from macro call
13229
14157
  (when-logic
13230
14158
   "DEFCHOOSE"
13231
14159
   (with-ctx-summarized
13232
14160
    (if (output-in-infixp state) event-form (cons 'defchoose (car def)))
13233
14161
    (let* ((wrld (w state))
13234
14162
           (event-form (or event-form (cons 'defchoose def)))
13235
 
           (len (length def)))
 
14163
           (raw-bound-vars (cadr def))
 
14164
           (valid-keywords '(:doc :strengthen))
 
14165
           (ka (nthcdr 4 def)) ; def is the argument list of a defchoose call
 
14166
           (doc (cadr (assoc-keyword :doc ka)))
 
14167
           (strengthen (cadr (assoc-keyword :strengthen def))))
13236
14168
      (er-progn
13237
14169
       (chk-all-but-new-name (car def) ctx 'constrained-function wrld state)
13238
14170
       (cond
13239
 
        ((not (and (true-listp def)
13240
 
                   (member len '(4 5))))
 
14171
        ((not (and (keyword-value-listp ka)
 
14172
                   (null (strip-keyword-list valid-keywords ka))))
13241
14173
         (er soft ctx
13242
14174
             "Defchoose forms must have the form (defchoose fn bound-vars ~
13243
 
              formals body), optionally with a doc-string before the body.  ~
13244
 
              However, ~x0 does not have this form."
13245
 
             event-form))
13246
 
        ((and (= len 5)
13247
 
              (not (doc-stringp (nth 3 def))))
13248
 
         (er soft ctx
13249
 
             "When a DEFCHOOSE form has five arguments, the fourth must be a ~
13250
 
              doc string.  The form ~x0 is thus illegal.  See :DOC doc-string."
13251
 
             event-form))
13252
 
        ((redundant-defchoosep (car def) event-form len wrld)
 
14175
              formals body), with optional keyword arguments ~&0. However, ~
 
14176
              ~x1 does not have this form.  See :DOC defchoose."
 
14177
             valid-keywords
 
14178
             event-form))
 
14179
        ((and doc
 
14180
              (not (doc-stringp doc)))
 
14181
         (er soft ctx
 
14182
             "Illegal doc string has been supplied in ~x0.  See :DOC ~
 
14183
              doc-string."
 
14184
             event-form))
 
14185
        ((not (booleanp strengthen))
 
14186
         (er soft ctx
 
14187
             "The :strengthen argument of a defchoose event must be t or nil. ~
 
14188
              The event ~x0 is thus illegal."
 
14189
             event-form))
 
14190
        ((redundant-defchoosep (car def) event-form wrld)
13253
14191
         (stop-redundant-event state))
13254
14192
        (t
13255
14193
         (enforce-redundancy
13256
14194
          event-form ctx wrld
13257
14195
          (cond
13258
 
           ((null (cadr def))
 
14196
           ((null raw-bound-vars)
13259
14197
            (er soft ctx
13260
 
                "The bound variables of a DEFCHOOSE form must be non-empty.  ~
 
14198
                "The bound variables of a defchoose form must be non-empty.  ~
13261
14199
                 The form ~x0 is therefore illegal."
13262
14200
                event-form))
13263
14201
           (t
13264
14202
            (let ((fn (car def))
13265
 
                  (bound-vars (if (atom (cadr def))
13266
 
                                  (list (cadr def))
13267
 
                                (cadr def)))
 
14203
                  (bound-vars (if (atom raw-bound-vars)
 
14204
                                  (list raw-bound-vars)
 
14205
                                raw-bound-vars))
13268
14206
                  (formals (caddr def))
13269
 
                  (doc (and (= len 5) (cadddr def)))
13270
 
                  (body (if (= len 5) (cadddr (cdr def)) (cadddr def))))
 
14207
                  (body (cadddr def)))
13271
14208
              (er-progn
13272
14209
               (chk-arglist-for-defchoose bound-vars t ctx state)
13273
14210
               (chk-arglist-for-defchoose formals nil ctx state)
13278
14215
                (cond
13279
14216
                 ((intersectp-eq bound-vars formals)
13280
14217
                  (er soft ctx
13281
 
                      "The bound and free variables of a DEFCHOOSE form must ~
 
14218
                      "The bound and free variables of a defchoose form must ~
13282
14219
                       not intersect, but their intersection for the form ~x0 ~
13283
14220
                       is ~x1."
13284
14221
                      event-form
13295
14232
                    (cond
13296
14233
                     ((not (subsetp-eq body-vars bound-and-free-vars))
13297
14234
                      (er soft ctx
13298
 
                          "All variables in the body of a DEFCHOOSE form must ~
 
14235
                          "All variables in the body of a defchoose form must ~
13299
14236
                           appear among the bound or free variables supplied ~
13300
14237
                           in that form.  However, the ~#0~[variable ~x0 ~
13301
14238
                           does~/variables ~&0 do~] not appear in the bound or ~
13321
14258
                         (warning$ ctx "Ignored-variables"
13322
14259
                                   "The variable~#0~[ ~&0 occurs~/s ~&0 ~
13323
14260
                                    occur~] in the body of the following ~
13324
 
                                    DEFCHOOSE form:~|~x1~|However, ~#0~[this ~
 
14261
                                    defchoose form:~|~x1~|However, ~#0~[this ~
13325
14262
                                    variable does~/these variables do~] not ~
13326
14263
                                    appear either in the bound variables or ~
13327
14264
                                    the formals of that form.  In order to ~
13350
14287
                         (er-let*
13351
14288
                          ((constraint
13352
14289
                            (defchoose-constraint
13353
 
                              fn bound-vars formals tbody
 
14290
                              fn bound-vars formals tbody strengthen
13354
14291
                              ctx wrld state)))
13355
14292
                          (install-event fn
13356
14293
                                         event-form
13372
14309
                                          fn 'defchoose-axiom constraint wrld)
13373
14310
                                         state))))))))))))))))))))))
13374
14311
 
13375
 
(defun non-acceptable-defun-sk-p (name args body doc quant-ok)
 
14312
(defun non-acceptable-defun-sk-p (name args body doc quant-ok rewrite exists-p)
13376
14313
 
13377
14314
; Since this is just a macro, we only do a little bit of vanilla checking,
13378
14315
; leaving it to the real events to implement the most rigorous checks.
13384
14321
                             (list (cadr body))
13385
14322
                           (cadr body)))))
13386
14323
    (cond
 
14324
     ((and rewrite exists-p)
 
14325
      (msg "It is illegal to supply a :rewrite argument for a defun-sk form ~
 
14326
            that uses the exists quantifier.  See :DOC defun-sk."))
 
14327
     ((and (keywordp rewrite)
 
14328
           (not (member-eq rewrite '(:direct :default))))
 
14329
      (msg "The only legal keyword values for the :rewrite argument of a ~
 
14330
            defun-sk are :direct and :default.  ~x0 is thus illegal."
 
14331
           rewrite))
13387
14332
     ((not (true-listp args))
13388
14333
      (msg "The second argument of DEFUN-SK must be a true list of legal ~
13389
14334
            variable names, but ~x0 is not a true-listp."
13445
14390
     (t nil))))
13446
14391
 
13447
14392
(defmacro defun-sk (name args body
13448
 
                         &key doc quant-ok skolem-name thm-name
 
14393
                         &key doc quant-ok skolem-name thm-name rewrite
13449
14394
                         (witness-dcls
13450
14395
                          '((declare (xargs :non-executable t)))))
13451
14396
 
13471
14416
 
13472
14417
  General Form:
13473
14418
  (defun-sk fn (var1 ... varn) body
13474
 
    &key doc quant-ok skolem-name thm-name witness-dcls)
 
14419
    &key rewrite doc quant-ok skolem-name thm-name witness-dcls)
13475
14420
  ~ev[]
13476
14421
  where ~c[fn] is the symbol you wish to define and is a new symbolic
13477
14422
  name (~pl[name]), ~c[(var1 ... varn)] is its list of formal
13547
14492
  indeed does introduce the quantified notions that it claims to
13548
14493
  introduce.
13549
14494
 
 
14495
  Notice that the ~ilc[defthm] event just above, ~c[forall-x-y-p0-and-q0-necc],
 
14496
  may not be of optimal form as a rewrite rule.  Users sometimes find that when
 
14497
  the quantifier is ~c[forall], it is useful to state this rule in a form where
 
14498
  the new quantified predicate is a hypothesis instead.  In this case that form
 
14499
  would be as follows:
 
14500
  ~bv[]
 
14501
  (defthm forall-x-y-p0-and-q0-necc
 
14502
    (implies (forall-x-y-p0-and-q0 z)
 
14503
             (and (p0 x y z) (q0 x y z))))
 
14504
  ~ev[]
 
14505
  ACL2 will turn this into one ~c[:]~ilc[rewrite] rule for each conjunct,
 
14506
  ~c[(p0 x y z)] and ~c[(q0 x y z)], with hypothesis
 
14507
  ~c[(forall-x-y-p0-and-q0 z)] in each case.  In order to get this effect, use
 
14508
  ~c[:rewrite :direct], in this case as follows.
 
14509
  ~bv[]
 
14510
  (defun-sk forall-x-y-p0-and-q0 (z)
 
14511
    (forall (x y)
 
14512
            (and (p0 x y z)
 
14513
                 (q0 x y z)))
 
14514
    :rewrite :direct)
 
14515
  ~ev[]
 
14516
 
13550
14517
  We now turn to a detailed description ~c[defun-sk], starting with a
13551
14518
  discussion of its arguments as shown in the \"General Form\" above.
13552
14519
 
13585
14552
    (implies (not term)
13586
14553
             (not (fn var1 ... varn))))
13587
14554
  ~ev[]
 
14555
 
 
14556
  In the ~c[forall] case, however, the keyword pair ~c[:rewrite :direct] may be
 
14557
  supplied after the body of the ~c[defun-sk] form, in which case the
 
14558
  contrapositive of the above form is used instead:
 
14559
  ~bv[]
 
14560
  (defthm fn-necc ;in case the quantifier is FORALL
 
14561
    (implies (fn var1 ... varn)
 
14562
             term))
 
14563
  ~ev[]
 
14564
  This is often a better choice for the \"-NECC\" rule, provided ACL2 can parse
 
14565
  ~c[term] as a ~c[:]~ilc[rewrite] rule.  A second possible value of the
 
14566
  ~c[:rewrite] argument of ~c[defun-sk] is ~c[:default], which gives the same
 
14567
  behavior as when ~c[:rewrite] is omitted.  Otherwise, the value of
 
14568
  ~c[:rewrite] should be the term to use as the body of the ~c[fn-necc] theorem
 
14569
  shown above; ACL2 will attempt to do the requisite proof in this case.  If
 
14570
  that term is weaker than the default, the properties introduced by
 
14571
  ~c[defun-sk] may of course be weaker than they would be otherwise.  Finally,
 
14572
  note that the ~c[:rewrite] keyword argument for ~c[defun-sk] only makes sense
 
14573
  if the quantifier is ~c[forall]; it is thus illegal if the quantifier is
 
14574
  ~c[exists].  Enough said about ~c[:rewrite]!
 
14575
 
13588
14576
  In the case that ~c[bound-vars] is a list of at least two variables, say
13589
 
  ~c[(bv1 ... bvk)], the definition above is the following instead, but
13590
 
  the theorem remains unchanged.
 
14577
  ~c[(bv1 ... bvk)], the definition above (with no keywords) is the following
 
14578
  instead, but the theorem remains unchanged.
13591
14579
  ~bv[]
13592
14580
  (defun fn (var1 ... varn)
13593
14581
    (declare (xargs :non-executable t))
13622
14610
  ~pl[defchoose].
13623
14611
 
13624
14612
  If you find that the rewrite rules introduced with a particular use of
13625
 
  ~c[defun-sk] are not ideal, then at least two reasonable courses of action
13626
 
  are available for you.  Perhaps the best option is to prove the ~ilc[rewrite]
13627
 
  rules you want.  If you see a pattern for creating rewrite rules from your
13628
 
  ~c[defun-sk] events, you might want to write a macro that executes a
13629
 
  ~c[defun-sk] followed by one or more ~ilc[defthm] events.  Another option is
13630
 
  to write your own variant of the ~c[defun-sk] macro, say, ~c[my-defun-sk],
13631
 
  for example by modifying a copy of the definition of ~c[defun-sk] from the
13632
 
  ACL2 sources.
 
14613
  ~c[defun-sk] are not ideal, even when using the ~c[:rewrite] keyword
 
14614
  discussed above (in the ~c[forall] case), then at least two reasonable
 
14615
  courses of action are available for you.  Perhaps the best option is to prove
 
14616
  the ~ilc[rewrite] rules you want.  If you see a pattern for creating rewrite
 
14617
  rules from your ~c[defun-sk] events, you might want to write a macro that
 
14618
  executes a ~c[defun-sk] followed by one or more ~ilc[defthm] events.  Another
 
14619
  option is to write your own variant of the ~c[defun-sk] macro, say,
 
14620
  ~c[my-defun-sk], for example by modifying a copy of the definition of
 
14621
  ~c[defun-sk] from the ACL2 sources.
13633
14622
 
13634
14623
  If you want to represent nested quantifiers, you can use more than one
13635
14624
  ~c[defun-sk] event.  For example, in order to represent
13648
14637
  Some distracting and unimportant warnings are inhibited during
13649
14638
  ~c[defun-sk].
13650
14639
 
13651
 
  Note that this way of implementing quantifiers is not a new idea.
13652
 
  Hilbert was certainly aware of it 60 years ago!  A paper by ACL2
13653
 
  authors Kaufmann and Moore, entitled ``Structured Theory Development
13654
 
  for a Mechanized Logic'' (Journal of Automated Reasoning 26, no. 2 (2001),
13655
 
  pp. 161-203) explains why our use of ~ilc[defchoose] is appropriate, even in
13656
 
  the presence of ~c[epsilon-0] induction.~/"
 
14640
  Note that this way of implementing quantifiers is not a new idea.  Hilbert
 
14641
  was certainly aware of it 60 years ago!  Also
 
14642
  ~pl[conservativity-of-defchoose] for a technical argument that justifies the
 
14643
  logical conservativity of the ~ilc[defchoose] event in the sense of the paper
 
14644
  by Kaufmann and Moore entitled ``Structured Theory Development for a
 
14645
  Mechanized Logic'' (Journal of Automated Reasoning 26, no. 2 (2001),
 
14646
  pp. 161-203).~/"
13657
14647
 
13658
14648
  (let* ((exists-p (and (true-listp body)
13659
14649
                        (symbolp (car body))
13676
14666
               (concatenate 'string (symbol-name name)
13677
14667
                            (if exists-p "-SUFF" "-NECC"))
13678
14668
               name)))
13679
 
         (msg (non-acceptable-defun-sk-p name args body doc quant-ok)))
 
14669
         (msg (non-acceptable-defun-sk-p name args body doc quant-ok rewrite
 
14670
                                         exists-p)))
13680
14671
    (if msg
13681
14672
        `(er soft '(defun-sk . ,name)
13682
14673
             "~@0"
13721
14712
                       ,body-guts)))
13722
14713
         (in-theory (disable (,name)))
13723
14714
         (defthm ,thm-name
13724
 
           ,(if exists-p
13725
 
                `(implies ,body-guts
13726
 
                           (,name ,@args))
13727
 
              `(implies (not ,body-guts)
13728
 
                        (not (,name ,@args))))
 
14715
           ,(cond (exists-p
 
14716
                   `(implies ,body-guts
 
14717
                             (,name ,@args)))
 
14718
                  ((eq rewrite :direct)
 
14719
                   `(implies (,name ,@args)
 
14720
                             ,body-guts))
 
14721
                  ((member-eq rewrite '(nil :default))
 
14722
                   `(implies (not ,body-guts)
 
14723
                             (not (,name ,@args))))
 
14724
                  (t rewrite))
13729
14725
           :hints (("Goal"
13730
 
                     :use ,skolem-name)))
 
14726
                     :use (,skolem-name ,name)
 
14727
                     :in-theory (theory 'minimal-theory))))
13731
14728
         ,@(if doc
13732
14729
               `((defdoc ,name ,doc))
13733
14730
             nil))))))
15530
16527
               (set-w 'extension wrld1 state)
15531
16528
               (er-progn
15532
16529
                (process-embedded-events 'defstobj
15533
 
                                         event-form
15534
16530
                                         (table-alist 'acl2-defaults-table wrld1)
15535
16531
                                         t                     ;;; skip-proofsp
15536
16532
                                         (current-package state)
17116
18112
  ~ev[]~/")
17117
18113
 
17118
18114
(defun push-untouchable-fn (name fn-p state doc event-form)
17119
 
  (when-logic
17120
 
   "PUSH-UNTOUCHABLE"
17121
 
   (with-ctx-summarized
17122
 
    (if (output-in-infixp state)
17123
 
        event-form
17124
 
      (cond ((symbolp name)
17125
 
             (cond ((null doc)
17126
 
                    (msg "( PUSH-UNTOUCHABLE ~x0 ~x1)" name fn-p))
17127
 
                   (t (msg "( PUSH-UNTOUCHABLE ~x0 ~x1 ...)" name fn-p))))
17128
 
            ((null doc) "( PUSH-UNTOUCHABLE ...)")
17129
 
            (t "( PUSH-UNTOUCHABLE ... ...)")))
17130
 
    (let ((wrld (w state))
17131
 
          (event-form (or event-form
17132
 
                          (list* 'push-untouchable name fn-p
17133
 
                                 (if doc
17134
 
                                     (list :doc doc)
17135
 
                                   nil))))
17136
 
          (names (if (symbolp name) (list name) name)))
17137
 
      (er-let*
17138
 
        ((doc-pair (translate-doc nil doc ctx state)))
 
18115
  (with-ctx-summarized
 
18116
   (if (output-in-infixp state)
 
18117
       event-form
 
18118
     (cond ((symbolp name)
 
18119
            (cond ((null doc)
 
18120
                   (msg "( PUSH-UNTOUCHABLE ~x0 ~x1)" name fn-p))
 
18121
                  (t (msg "( PUSH-UNTOUCHABLE ~x0 ~x1 ...)" name fn-p))))
 
18122
           ((null doc) "( PUSH-UNTOUCHABLE ...)")
 
18123
           (t "( PUSH-UNTOUCHABLE ... ...)")))
 
18124
   (let ((wrld (w state))
 
18125
         (event-form (or event-form
 
18126
                         (list* 'push-untouchable name fn-p
 
18127
                                (if doc
 
18128
                                    (list :doc doc)
 
18129
                                  nil))))
 
18130
         (names (if (symbolp name) (list name) name))
 
18131
         (untouchable-prop (cond (fn-p 'untouchable-fns)
 
18132
                                 (t 'untouchable-vars))))
 
18133
     (er-let*
 
18134
      ((doc-pair (translate-doc nil doc ctx state)))
17139
18135
 
17140
18136
; With no name to hang it on, we don't permit a formatted doc string.
17141
18137
; So the above causes an error if the string is formatted.  Otherwise,
17142
18138
; we ignore doc-pair.
17143
18139
 
17144
 
        (cond
17145
 
         ((not (symbol-listp names))
17146
 
          (er soft ctx
17147
 
              "The argument to push-untouchable must be either a non-nil
 
18140
      (cond
 
18141
       ((not (symbol-listp names))
 
18142
        (er soft ctx
 
18143
            "The argument to push-untouchable must be either a non-nil
17148
18144
              symbol or a non-empty true list of symbols and ~x0 is ~
17149
18145
              neither."
17150
 
              name))
17151
 
         ((subsetp-eq names (global-val 'untouchables wrld))
17152
 
          (stop-redundant-event state))
17153
 
         (t
17154
 
          (let ((wrld
17155
 
                 (cond
17156
 
                  (fn-p
17157
 
                   (global-set 'untouchable-fns
17158
 
                               (union-eq names (global-val 'untouchable-fns
17159
 
                                                           wrld))
17160
 
                               wrld))
17161
 
                  (t
17162
 
                   (global-set 'untouchable-vars
17163
 
                               (union-eq names (global-val 'untouchable-vars
17164
 
                                                           wrld))
17165
 
                               wrld)))))
17166
 
            (install-event name
17167
 
                           event-form
17168
 
                           'push-untouchable
17169
 
                           0
17170
 
                           nil
17171
 
                           nil
17172
 
                           nil
17173
 
                           nil
17174
 
                           wrld state)))))))))
 
18146
            name))
 
18147
       ((subsetp-eq names (global-val untouchable-prop wrld))
 
18148
        (stop-redundant-event state))
 
18149
       (t
 
18150
        (install-event name
 
18151
                       event-form
 
18152
                       'push-untouchable
 
18153
                       0
 
18154
                       nil
 
18155
                       nil
 
18156
                       nil
 
18157
                       nil
 
18158
                       (global-set
 
18159
                        untouchable-prop
 
18160
                        (union-eq names (global-val untouchable-prop wrld))
 
18161
                        wrld)
 
18162
                       state)))))))
 
18163
 
 
18164
(defun remove-untouchable-fn (name fn-p state doc event-form)
 
18165
  (with-ctx-summarized
 
18166
   (if (output-in-infixp state)
 
18167
       event-form
 
18168
     (cond ((symbolp name)
 
18169
            (cond ((null doc)
 
18170
                   (msg "( REMOVE-UNTOUCHABLE ~x0 ~x1)" name fn-p))
 
18171
                  (t (msg "( REMOVE-UNTOUCHABLE ~x0 ~x1 ...)" name fn-p))))
 
18172
           ((null doc) "( REMOVE-UNTOUCHABLE ...)")
 
18173
           (t "( REMOVE-UNTOUCHABLE ... ...)")))
 
18174
   (let ((wrld (w state))
 
18175
         (event-form (or event-form
 
18176
                         (list* 'remove-untouchable name fn-p
 
18177
                                (if doc
 
18178
                                    (list :doc doc)
 
18179
                                  nil))))
 
18180
         (names (if (symbolp name) (list name) name))
 
18181
         (untouchable-prop (cond (fn-p 'untouchable-fns)
 
18182
                                 (t 'untouchable-vars))))
 
18183
     (er-let*
 
18184
      ((doc-pair (translate-doc nil doc ctx state)))
 
18185
 
 
18186
; With no name to hang it on, we don't permit a formatted doc string.
 
18187
; So the above causes an error if the string is formatted.  Otherwise,
 
18188
; we ignore doc-pair.
 
18189
 
 
18190
      (cond
 
18191
       ((not (symbol-listp names))
 
18192
        (er soft ctx
 
18193
            "The argument to remove-untouchable must be either a non-nil
 
18194
              symbol or a non-empty true list of symbols and ~x0 is neither."
 
18195
            name))
 
18196
       ((not (intersectp-eq names (global-val untouchable-prop wrld)))
 
18197
        (stop-redundant-event state))
 
18198
       (t
 
18199
        (install-event name
 
18200
                       event-form
 
18201
                       'remove-untouchable
 
18202
                       0
 
18203
                       nil
 
18204
                       nil
 
18205
                       nil
 
18206
                       nil
 
18207
                       (global-set
 
18208
                        untouchable-prop
 
18209
                        (set-difference-eq (global-val untouchable-prop wrld)
 
18210
                                           names)
 
18211
                        wrld)
 
18212
                       state)))))))
17175
18213
 
17176
18214
(defun def-body-runes (def-bodies lemmas)
17177
18215
  (cond ((endp def-bodies)
17902
18940
  in some Lisp implementations, for compiled tail recursive functions), then
17903
18941
  you can quit into raw Lisp (~c[:q]) and execute your form there.
17904
18942
  Alternatively, you can avoid ~il[executable-counterpart] functions by using
17905
 
  ~c[:]~ilc[set-raw-mode] to enter a raw Lisp version of the ACL2 loop,
17906
 
  provided you do not intend to run ~ilc[certify-book] later in that session;
17907
 
  ~pl[set-raw-mode].
 
18943
  ~c[:]~ilc[set-raw-mode] to enter a raw Lisp version of the ACL2 loop;
 
18944
  ~pl[set-raw-mode] and ~pl[set-raw-mode-on!].
17908
18945
 
17909
18946
  Output from ~ilc[trace$] normally goes to the screen, i.e.,
17910
18947
  ~ilc[standard-co].  But it can be redirected to a file;
18256
19293
   ((endp dcls-and-strings)
18257
19294
    (cond
18258
19295
     ((null guard-p)
18259
 
      (mv "no :GUARD has been specified in the XARGS" nil nil nil nil nil))
 
19296
      (mv "no :GUARD has been specified in the XARGS.  The MBE proof ~
 
19297
           obligation is actually a guard condition -- we have to prove that ~
 
19298
           the guard ensures that the :LOGIC and :EXEC terms are equivalent ~
 
19299
           and that the guards are satisfied for the :EXEC term.  Please ~
 
19300
           specify a :GUARD.  Note also that you can delay the verification ~
 
19301
           of the MBE conditions by delaying guard verification, as with ~
 
19302
           :VERIFY-GUARDS NIL"
 
19303
          nil nil nil nil nil))
18260
19304
     (t
18261
19305
      (mv nil
18262
19306
          (reverse final)
18607
19651
           target-name-or-rune target-index wrld)))
18608
19652
    nil))
18609
19653
 
18610
 
(defun pc-relieve-hyp (hyp unify-subst type-alist wrld state ens ttree)
 
19654
(defun pc-relieve-hyp (rune hyp unify-subst type-alist wrld state ens ttree)
18611
19655
 
18612
19656
; This function is adapted from ACL2 function relieve-hyp, but it prevents
18613
19657
; backchaining, instead returning the new hypotheses.  Notice that there are no
18624
19668
              (eq (ffn-symb hyp) 'synp))
18625
19669
         (mv-let
18626
19670
          (wonp failure-reason unify-subst ttree)
18627
 
          (relieve-hyp-synp hyp unify-subst type-alist wrld
 
19671
          (relieve-hyp-synp rune hyp unify-subst type-alist wrld
18628
19672
                            state
18629
19673
                            nil ; fnstack
18630
19674
                            nil ; ancestors
18652
19696
                  (lookup-hyp-ans
18653
19697
                   (mv t unify-subst ttree))
18654
19698
                  ((free-varsp hyp unify-subst)
18655
 
                   (search-ground-units hyp unify-subst type-alist ens
 
19699
                   (search-ground-units` hyp unify-subst type-alist ens
18656
19700
                                        (ok-to-force-ens ens) wrld ttree))
18657
19701
                  (t
18658
19702
                   (let ((inst-hyp (sublis-var unify-subst hyp)))
18680
19724
                               (mv t unify-subst ttree)
18681
19725
                             (mv nil unify-subst ttree)))))))))))))))))))
18682
19726
 
18683
 
(defun pc-relieve-hyps1 (hyps unify-subst unify-subst0 ttree0 type-alist
 
19727
(defun pc-relieve-hyps1 (rune hyps unify-subst unify-subst0 ttree0 type-alist
18684
19728
                              keep-unify-subst wrld state ens ttree)
18685
19729
 
18686
19730
; This function is adapted from ACL2 function relieve-hyp.  Notice that there
18706
19750
 
18707
19751
; We avoid rewriting in this proof-checker code, so new-ttree = ttree.
18708
19752
 
18709
 
             (pc-relieve-hyp (car hyps) unify-subst type-alist wrld state ens ttree)
 
19753
             (pc-relieve-hyp rune (car hyps) unify-subst type-alist wrld state
 
19754
                             ens ttree)
18710
19755
             (cond
18711
19756
              ((or relieve-hyp-ans keep-unify-subst)
18712
 
               (pc-relieve-hyps1 (cdr hyps)
 
19757
               (pc-relieve-hyps1 rune
 
19758
                                 (cdr hyps)
18713
19759
                                 new-unify-subst
18714
19760
                                 unify-subst0 ttree0
18715
19761
                                 type-alist
18720
19766
                                 wrld state ens ttree))
18721
19767
              (t (mv nil unify-subst0 ttree0)))))))
18722
19768
 
18723
 
(defun pc-relieve-hyps (hyps unify-subst type-alist keep-unify-subst wrld state
18724
 
                             ens ttree)
 
19769
(defun pc-relieve-hyps (rune hyps unify-subst type-alist keep-unify-subst wrld
 
19770
                             state ens ttree)
18725
19771
 
18726
19772
; Adapted from ACL2 function relieve-hyp.  Notice that there are no arguments
18727
19773
; for obj, equiv, fnstack, ancestors, or simplify-clause-pot-lst.  Also notice
18730
19776
; We return t or nil indicating success, an extended unify-subst and
18731
19777
; a new ttree.  This function is a No-Change Loser.
18732
19778
 
18733
 
  (pc-relieve-hyps1 hyps unify-subst unify-subst ttree type-alist
 
19779
  (pc-relieve-hyps1 rune hyps unify-subst unify-subst ttree type-alist
18734
19780
                    keep-unify-subst wrld state ens ttree))
18735
19781
 
18736
19782
(defun remove-trivial-lits (lst type-alist alist wrld ens ttree)
18754
19800
                (mv (cons new-lit rest-list) ttree))))))
18755
19801
    (mv nil ttree)))
18756
19802
 
18757
 
(defun unrelieved-hyps (hyps unify-subst type-alist keep-unify-subst wrld state
18758
 
                             ens ttree)
 
19803
(defun unrelieved-hyps (rune hyps unify-subst type-alist keep-unify-subst wrld
 
19804
                             state ens ttree)
18759
19805
 
18760
19806
; Returns unrelieved hyps (with the appropriate substitution applied), an
18761
19807
; extended substitution, and a new tag tree.  Note: the substitution really has
18766
19812
; do not relieve all of the hypotheses.
18767
19813
 
18768
19814
  (mv-let (success-flg new-unify-subst new-ttree)
18769
 
    (pc-relieve-hyps hyps unify-subst type-alist keep-unify-subst wrld state
18770
 
                     ens ttree)
 
19815
    (pc-relieve-hyps rune hyps unify-subst type-alist keep-unify-subst wrld
 
19816
                     state ens ttree)
18771
19817
    (if success-flg
18772
19818
        (mv nil new-unify-subst new-ttree)
18773
19819
      (mv-let (unify-subst ttree)
18778
19824
          (remove-trivial-lits hyps type-alist unify-subst wrld ens ttree)
18779
19825
          (mv lits unify-subst ttree))))))
18780
19826
 
 
19827
(defun untranslate-subst-abb (sub abbreviations state)
 
19828
  (declare (xargs :guard (symbol-alistp sub)))
 
19829
  (if (consp sub)
 
19830
      (cons (list (caar sub) (untrans0 (cdar sub) nil abbreviations))
 
19831
            (untranslate-subst-abb (cdr sub) abbreviations state))
 
19832
    nil))
 
19833
 
18781
19834
(defun show-rewrite (index col rune nume show-more subst-hyps subst-hyps-2
18782
19835
                           unify-subst unify-subst-2 free free-2 rhs
18783
19836
                           abbreviations term-id-iff ens enabled-only-flg
18784
 
                           equiv show-unify-subst state)
 
19837
                           equiv pl-p state)
 
19838
 
 
19839
; Pl-p is true when we are calling this function on behalf of :pl, and is false
 
19840
; when we are calling it on behalf of the proof-checker.
 
19841
 
18785
19842
  (let ((enabledp (enabled-numep nume ens))
18786
19843
        (subst-rhs (sublis-var unify-subst rhs)))
18787
19844
    (if (and enabled-only-flg
18798
19855
                  (cons #\2 (if enabledp 0 1)))
18799
19856
            (standard-co state) state nil)
18800
19857
       (let ((fmt-string
18801
 
              "~ ~ New term: ~x3~%~
 
19858
              "~ ~ New term: ~y3~|~
18802
19859
               ~ ~ Hypotheses: ~#b~[<none>~/~y4~]~|~
18803
 
               ~ ~ Equiv: ~xe~|~
18804
 
               ~#s~[~/~ ~ Substitution: ~xa~|~]~
 
19860
               ~ ~ Equiv: ~ye~|~
 
19861
               ~#s~[~/~ ~ Substitution: ~ya~|~]~
18805
19862
               ~#5~[~/~
18806
19863
                    ~ ~ Remaining free variable: ~&6~/~
18807
19864
                    ~ ~ Remaining free variables: ~&6~sn~]~
18808
19865
               ~#7~[~/  WARNING:  One of the hypotheses is (equivalent to) NIL, ~
18809
19866
               and hence will apparently be impossible to relieve.~]~|"))
18810
 
         (pprogn (fms fmt-string
18811
 
                      (list (cons #\3 (untrans0 subst-rhs term-id-iff
18812
 
                                                abbreviations))
18813
 
                            (cons #\s (if show-unify-subst 1 0))
18814
 
                            (cons #\a unify-subst)
18815
 
                            (cons #\b (if subst-hyps 1 0))
18816
 
                            (cons #\e equiv)
18817
 
                            (cons #\4 (untrans0-lst subst-hyps t abbreviations))
18818
 
                            (cons #\5 (zero-one-or-more (length free)))
18819
 
                            (cons #\6 free)
18820
 
                            (cons #\n "")
18821
 
                            (cons #\7 (if (member-eq nil subst-hyps) 1 0)))
18822
 
                      (standard-co state) state nil)
18823
 
                 (cond (show-more
18824
 
                        (pprogn
18825
 
                         (fms0 "  -- IF REWRITE is called with ~
18826
 
                                     instantiate-free=t: --")
18827
 
                         (fms fmt-string
18828
 
                              (list (cons #\3 (untrans0
18829
 
                                               (sublis-var unify-subst-2 rhs)
18830
 
                                               term-id-iff abbreviations))
18831
 
                                    (cons #\b (if subst-hyps-2 1 0))
18832
 
                                    (cons #\4 (untrans0-lst subst-hyps-2 t
18833
 
                                                            abbreviations))
18834
 
                                    (cons #\5 (if (eql (length free-2) 1)
18835
 
                                                  1
18836
 
                                                2))
18837
 
                                    (cons #\6 free-2)
18838
 
                                    (cons #\n "[none]")
18839
 
                                    (cons #\7 (if (member-eq nil subst-hyps-2)
18840
 
                                                  1
18841
 
                                                0)))
18842
 
                              (standard-co state) state nil)))
18843
 
                       (t state))))))))
 
19867
         (pprogn
 
19868
          (cond
 
19869
           ((and show-more pl-p) ; then just show more
 
19870
            state)
 
19871
           (t
 
19872
            (fms fmt-string
 
19873
                 (list (cons #\3 (untrans0 subst-rhs term-id-iff
 
19874
                                           abbreviations))
 
19875
                       (cons #\s (if pl-p 1 0))
 
19876
                       (cons #\a (untranslate-subst-abb unify-subst
 
19877
                                                        abbreviations
 
19878
                                                        state))
 
19879
                       (cons #\b (if subst-hyps 1 0))
 
19880
                       (cons #\e equiv)
 
19881
                       (cons #\4 (untrans0-lst subst-hyps t abbreviations))
 
19882
                       (cons #\5 (zero-one-or-more (length free)))
 
19883
                       (cons #\6 free)
 
19884
                       (cons #\n "")
 
19885
                       (cons #\7 (if (member-eq nil subst-hyps) 1 0)))
 
19886
                 (standard-co state) state nil)))
 
19887
          (cond (show-more
 
19888
                 (pprogn
 
19889
                  (cond (pl-p state)
 
19890
                        (t (fms0 "  -- IF REWRITE is called with ~
 
19891
                                  instantiate-free=t: --")))
 
19892
                  (fms fmt-string
 
19893
                       (list (cons #\3 (untrans0
 
19894
                                        (sublis-var unify-subst-2 rhs)
 
19895
                                        term-id-iff abbreviations))
 
19896
                             (cons #\s (if pl-p 1 0))
 
19897
                             (cons #\a (untranslate-subst-abb unify-subst-2
 
19898
                                                              abbreviations
 
19899
                                                              state))
 
19900
                             (cons #\b (if subst-hyps-2 1 0))
 
19901
                             (cons #\e equiv)
 
19902
                             (cons #\4 (untrans0-lst subst-hyps-2 t
 
19903
                                                     abbreviations))
 
19904
                             (cons #\5 (if (eql (length free-2) 1)
 
19905
                                           1
 
19906
                                         2))
 
19907
                             (cons #\6 free-2)
 
19908
                             (cons #\n (if (null free-2)
 
19909
                                           "[none]"
 
19910
                                         ""))
 
19911
                             (cons #\7 (if (member-eq nil subst-hyps-2)
 
19912
                                           1
 
19913
                                         0)))
 
19914
                       (standard-co state) state nil)))
 
19915
                (t state))))))))
18844
19916
 
18845
19917
(defun show-rewrites (app-rewrite-rules col abbreviations term-id-iff ens
18846
19918
                                        type-alist enabled-only-flg
18847
 
                                        show-unify-subst w state)
 
19919
                                        pl-p w state)
 
19920
 
 
19921
; Pl-p is true when we are calling this function on behalf of :pl, and is false
 
19922
; when we are calling it on behalf of the proof-checker.
 
19923
 
18848
19924
  (if (null app-rewrite-rules)
18849
19925
      state
18850
19926
    (pprogn (let ((sar (car app-rewrite-rules)))
18852
19928
                    (alist (access sar sar :alist))
18853
19929
                    (index (access sar sar :index)))
18854
19930
                (let ((hyps (access rewrite-rule lemma :hyps))
18855
 
                      (rhs (access rewrite-rule lemma :rhs)))
 
19931
                      (rhs (access rewrite-rule lemma :rhs))
 
19932
                      (rune (access rewrite-rule lemma :rune)))
18856
19933
                  (mv-let (subst-hyps unify-subst ttree)
18857
 
                    (unrelieved-hyps hyps alist type-alist nil w state ens nil)
 
19934
                    (unrelieved-hyps rune hyps alist type-alist nil w state ens
 
19935
                                     nil)
18858
19936
                    (declare (ignore ttree))
18859
19937
                    (let* ((rhs-and-hyps-vars
18860
19938
                            (union-eq (all-vars rhs)
18869
19947
; eliminates some hypotheses.
18870
19948
 
18871
19949
                               (mv-let (subst-hyps-2 unify-subst-2 ttree)
18872
 
                                 (unrelieved-hyps hyps alist type-alist t w
18873
 
                                                  state ens nil)
 
19950
                                 (unrelieved-hyps rune hyps alist type-alist t
 
19951
                                                  w state ens nil)
18874
19952
                                 (declare (ignore ttree))
18875
19953
                                 (cond ((equal unify-subst-2 unify-subst)
18876
19954
                                        (assert$
18880
19958
                                        (mv t subst-hyps-2 unify-subst-2)))))
18881
19959
                              (t (mv  nil subst-hyps unify-subst)))
18882
19960
                        (show-rewrite index col
18883
 
                                      (access rewrite-rule lemma :rune)
 
19961
                                      rune
18884
19962
                                      (access rewrite-rule lemma :nume)
18885
19963
                                      show-more
18886
19964
                                      subst-hyps  subst-hyps-2
18892
19970
                                      rhs abbreviations term-id-iff ens
18893
19971
                                      enabled-only-flg
18894
19972
                                      (access sar sar :equiv)
18895
 
                                      show-unify-subst
 
19973
                                      pl-p
18896
19974
                                      state)))))))
18897
19975
            (show-rewrites (cdr app-rewrite-rules) col abbreviations
18898
19976
                           term-id-iff ens type-alist enabled-only-flg
18899
 
                           show-unify-subst w state))))
 
19977
                           pl-p w state))))
18900
19978
 
18901
19979
(defun expand-assumptions-1 (term) 
18902
19980
  (case-match term
18938
20016
 
18939
20017
(defun show-rewrites-fn (rule-id enabled-only-flg ens current-term
18940
20018
                                 abbreviations term-id-iff all-hyps geneqv
18941
 
                                 show-unify-subst state)
 
20019
                                 pl-p state)
 
20020
 
 
20021
; Pl-p is true when we are calling this function on behalf of :pl, and is false
 
20022
; when we are calling it on behalf of the proof-checker.
 
20023
 
18942
20024
  (let ((name (and (symbolp rule-id) rule-id))
18943
20025
        (index (and (integerp rule-id) (< 0 rule-id) rule-id))
18944
20026
        (rune (and (consp rule-id)
18986
20068
                             (floor (length app-rewrite-rules) 10)
18987
20069
                             abbreviations term-id-iff
18988
20070
                             ens hyps-type-alist
18989
 
                             enabled-only-flg show-unify-subst w state)))))))))
 
20071
                             enabled-only-flg pl-p w state)))))))))
 
20072
 
 
20073
(defun show-meta-lemmas1 (lemmas index term wrld ens state)
 
20074
  (cond ((endp lemmas) state)
 
20075
        (t
 
20076
         (mv-let
 
20077
          (new-index state)
 
20078
          (let ((lemma (car lemmas)))
 
20079
            (cond ((eq (access rewrite-rule lemma :subclass)
 
20080
                       'meta)
 
20081
                   (let* ((fn (access rewrite-rule lemma :lhs))
 
20082
                          (extendedp (access rewrite-rule lemma :rhs))
 
20083
                          (args (meta-fn-args term extendedp ens state)))
 
20084
                     (mv-let
 
20085
                      (erp new-term latches)
 
20086
                      (ev-fncall-meta fn args state)
 
20087
                      (declare (ignore latches))
 
20088
                      (cond ((or erp
 
20089
                                 (equal new-term term)
 
20090
                                 (not (termp new-term wrld)))
 
20091
                             (mv index state))
 
20092
                            (t
 
20093
                             (let ((hyp-fn (access rewrite-rule lemma :hyps)))
 
20094
                               (mv-let
 
20095
                                (erp hyp latches)
 
20096
                                (if hyp-fn
 
20097
                                    (ev-fncall-meta
 
20098
                                     hyp-fn
 
20099
                                     (meta-fn-args term extendedp ens state)
 
20100
                                     state)
 
20101
                                  (mv nil *t* nil))
 
20102
                                (declare (ignore latches))
 
20103
                                (cond
 
20104
                                 ((or erp (not (termp hyp wrld)))
 
20105
                                  (mv index state))
 
20106
                                 (t
 
20107
                                  (pprogn
 
20108
                                   (fms
 
20109
                                    "META ~x0. ~y1~|~
 
20110
                                     ~ ~ New term: ~y2~|~
 
20111
                                     ~ ~ Hypothesis: ~y3~|~
 
20112
                                     ~ ~ Equiv: ~y4~|"
 
20113
                                    (list (cons #\0 index)
 
20114
                                          (cons #\1
 
20115
                                                (let ((rune
 
20116
                                                       (access rewrite-rule
 
20117
                                                               lemma
 
20118
                                                               :rune)))
 
20119
                                                  (if (cddr rune)
 
20120
                                                      rune
 
20121
                                                    (base-symbol rune))))
 
20122
                                          (cons #\2 new-term)
 
20123
                                          (cons #\3 (untranslate hyp
 
20124
                                                                 nil
 
20125
                                                                 wrld))
 
20126
                                          (cons #\4 (access rewrite-rule lemma
 
20127
                                                            :equiv)))
 
20128
                                    (standard-co state) state nil)
 
20129
                                   (mv (1+ index) state)))))))))))
 
20130
                  (t (mv index state))))
 
20131
          (show-meta-lemmas1 (cdr lemmas) new-index term wrld ens state)))))
 
20132
 
 
20133
(defun show-meta-lemmas (term state)
 
20134
  (cond ((and (nvariablep term)
 
20135
              (not (fquotep term))
 
20136
              (not (flambdap (ffn-symb term))))
 
20137
         (let ((wrld (w state)))
 
20138
           (show-meta-lemmas1 (getprop (ffn-symb term) 'lemmas nil
 
20139
                                       'current-acl2-world wrld)
 
20140
                              1 term wrld (ens state) state)))
 
20141
        (t state)))
18990
20142
 
18991
20143
(defun pl-fn (name state)
18992
20144
  (if (symbolp name)
19012
20164
    (er-let* ((term (translate name t t nil 'pl (w state) state)))
19013
20165
      (pprogn (show-rewrites-fn nil nil (ens state) term
19014
20166
                                nil nil nil :none t state)
 
20167
              (show-meta-lemmas term state)
19015
20168
              (value :invisible)))))
19016
20169
 
19017
20170
(defmacro pl (name)
19031
20184
  ~c[:]~ilc[definition], and ~c[:]~ilc[meta] rules that rewrite some term whose
19032
20185
  top function symbol is the one specified.  Otherwise, ~c[:pl] displays the
19033
20186
  ~c[:]~ilc[rewrite] and ~c[:]~ilc[definition] rules that rewrite the specified
19034
 
  term, but not the ~c[:]~ilc[meta] rules, and also shows the substitution to
19035
 
  be applied to the left-hand side of the rule in order to obtain the specified
19036
 
  term.
 
20187
  term, followed by the applicable ~c[:]~ilc[meta] rules.  For
 
20188
  ~c[:]~ilc[rewrite] and ~c[:]~ilc[definition] rules, ~c[:pl] also shows the
 
20189
  substitution that, when applied to the left-hand side of the rule, yields the
 
20190
  specified term.  For ~c[:]~ilc[meta] rules, only those are displayed that
 
20191
  meet two conditions: the application of the metafunction returns a term
 
20192
  different from the input term, and if there is a hypothesis metafunction then
 
20193
  it also returns a term.  (A subtlety: In the case of extended metafunctions
 
20194
  (~pl[extended-metafunctions]), a trivial metafunction context is used for the
 
20195
  application of the metafunction.)
19037
20196
 
19038
 
  The kinds of rules printed by ~c[:pl] are rewrite rules, definition rules,
19039
 
  and ~il[meta] rules.~/"
 
20197
  The kinds of rules printed by ~c[:pl] are ~c[:]~ilc[rewrite] rules,
 
20198
  ~c[:]~ilc[definition] rules, and ~il[meta] rules (not, for example,
 
20199
  ~c[:]~ilc[forward-chaining] rules).~/"
19040
20200
 
19041
20201
  (list 'pl-fn name 'state))
19042
20202
 
19139
20299
  incremental release as the same as the corresponding (immediately preceding)
19140
20300
  normal release, in order to avoid recertification of existing certified
19141
20301
  books.  SUCH RECERTIFICATION IS LOGICALLY REQUIRED, but we provide
19142
 
  ~c[(set-tainted-okp t] as a mechanism to allow users to experiment with
 
20302
  ~c[(set-tainted-okp t)] as a mechanism to allow users to experiment with
19143
20303
  incremental releases.
19144
20304
 
19145
20305
  Below we describe how books can be certified even though their certification
19174
20334
         "The legal values of set-tainted-okp are ~x0 and ~x1.  Thus ~x2 is ~
19175
20335
          not a legal value.  See :DOC set-tainted-okp."
19176
20336
         t nil ,x)))
 
20337
 
 
20338
#-acl2-loop-only
 
20339
(defmacro reset-prehistory (&rest args)
 
20340
  (declare (ignore args))
 
20341
  nil)
 
20342
 
 
20343
#+acl2-loop-only
 
20344
(defmacro reset-prehistory (&whole event-form &optional permanent-p doc)
 
20345
 
 
20346
; Warning: See the Important Boot-Strapping Invariants before modifying!
 
20347
 
 
20348
  ":Doc-Section Events
 
20349
 
 
20350
  reset the prehistory~/
 
20351
  ~bv[]
 
20352
  Examples:
 
20353
  (reset-prehistory)   ; restart command numbering at 0
 
20354
  (reset-prehistory t) ; as above, and also disable ubt-prehistory~/
 
20355
 
 
20356
  General Forms:
 
20357
  (reset-prehistory)
 
20358
  (reset-prehistory permanent-p)
 
20359
  (reset-prehistory permanent-p doc-string)
 
20360
  ~ev[]
 
20361
  where ~c[permanent-p] is ~c[t] or ~c[nil], and ~c[doc-string] is an optional
 
20362
  ~il[documentation] string not beginning with ``~c[:doc-section] ...''.  After
 
20363
  execution of this command, ACL2 will change the numbering provided by its
 
20364
  ~il[history] utilities so that this ~c[reset-prehistory] command (or the
 
20365
  top-level compound ~il[command] containing it, which for example might be an
 
20366
  ~ilc[include-book]) is assigned the number 0.  The only way to undo this
 
20367
  command is with command ~ilc[ubt-prehistory].  However, even that is
 
20368
  disallowed if ~c[permanent-p] is ~c[t].
 
20369
 
 
20370
  Note that the second argument of ~ilc[certify-book], which specifies the
 
20371
  number of commands in the certification world (i.e., since ground-zero), is
 
20372
  not sensitive to ~c[reset-prehistory]; rather, it expects the number of
 
20373
  commands since ground-zero.  To see such commands,
 
20374
  ~c[:]~ilc[pbt]~c[ :start].
 
20375
 
 
20376
  ~l[ubt-prehistory] for how to undo a ~c[reset-prehistory] command that does
 
20377
  not have a ~c[permanent-p] of t.~/"
 
20378
 
 
20379
; Warning: See the Important Boot-Strapping Invariants before modifying!
 
20380
 
 
20381
  (declare (xargs :guard (member-eq permanent-p '(t nil))))
 
20382
  (list 'reset-prehistory-fn
 
20383
        (list 'quote permanent-p)
 
20384
        'state
 
20385
        (list 'quote doc)
 
20386
        (list 'quote event-form)))
 
20387
 
 
20388
(defun reset-prehistory-fn (permanent-p state doc event-form)
 
20389
  (with-ctx-summarized
 
20390
   (cond ((output-in-infixp state)
 
20391
          event-form)
 
20392
         ((null doc)
 
20393
          (msg "( RESET-PREHISTORY ~x0)" permanent-p))
 
20394
         (t
 
20395
          (msg "( RESET-PREHISTORY ~x0 ...)" permanent-p)))
 
20396
   (let* ((wrld (w state))
 
20397
          (event-form (or event-form
 
20398
                          (list* 'reset-prehistory
 
20399
                                 permanent-p
 
20400
                                 (if doc
 
20401
                                     (list :doc doc)
 
20402
                                   nil))))
 
20403
          (next-absolute-command-number (next-absolute-command-number wrld)))
 
20404
     (install-event :new-prehistory-set
 
20405
                    event-form
 
20406
                    'reset-prehistory
 
20407
                    0
 
20408
                    nil
 
20409
                    nil
 
20410
                    nil
 
20411
                    ctx
 
20412
                    (global-set 'command-number-baseline-info
 
20413
                                (change command-number-baseline-info
 
20414
                                        (global-val
 
20415
                                         'command-number-baseline-info
 
20416
                                         wrld)
 
20417
                                        :permanent-p permanent-p
 
20418
                                        :current next-absolute-command-number)
 
20419
                                wrld)
 
20420
                    state))))
 
20421
 
 
20422