• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
          • World
          • Io
            • Fmt
            • Msg
            • Cw
            • Set-evisc-tuple
            • Set-iprint
            • Print-control
            • Read-file-into-string
            • Std/io
            • Msgp
            • Printing-to-strings
            • Evisc-tuple
            • Output-controls
            • Observation
            • *standard-co*
            • Ppr-special-syms
            • Standard-oi
            • Standard-co
            • Without-evisc
            • Serialize
              • With-serialize-character
              • Unsound-read
                • Serialize-read
                • Serialize-in-books
                • Print-compressed
                • Print-legibly
                • Serialize-write
                • Set-serialize-character-system
                • Serialize-alternatives
              • Output-to-file
              • Fmt-to-comment-window
              • Princ$
              • Character-encoding
              • Open-output-channel!
              • Cw-print-base-radix
              • Set-print-case
              • Set-print-base
              • Print-object$
              • Extend-pathname
              • Print-object$+
              • Fmx-cw
              • Set-print-radix
              • Set-fmt-hard-right-margin
              • File-write-date$
              • Proofs-co
              • Set-print-base-radix
              • Print-base-p
              • *standard-oi*
              • Wof
              • File-length$
              • Fms!-lst
              • Delete-file$
              • *standard-ci*
              • Write-list
              • Trace-co
              • Fmt!
              • Fms
              • Cw!
              • Fmt-to-comment-window!
              • Fms!
              • Eviscerate-hide-terms
              • Fmt1!
              • Fmt-to-comment-window!+
              • Read-file-into-byte-array-stobj
              • Fmt1
              • Fmt-to-comment-window+
              • Cw-print-base-radix!
              • Read-file-into-character-array-stobj
              • Fmx
              • Cw!+
              • Read-objects-from-book
              • Newline
              • Cw+
              • Probe-file
              • Write-objects-to-file!
              • Write-objects-to-file
              • Read-objects-from-file
              • Read-object-from-file
              • Read-file-into-byte-list
              • Set-fmt-soft-right-margin
              • Read-file-into-character-list
              • Io-utilities
            • Wormhole
            • Programming-with-state
            • W
            • Set-state-ok
            • Random$
          • Mutual-recursion
          • Memoize
          • Mbe
          • Io
            • Fmt
            • Msg
            • Cw
            • Set-evisc-tuple
            • Set-iprint
            • Print-control
            • Read-file-into-string
            • Std/io
            • Msgp
            • Printing-to-strings
            • Evisc-tuple
            • Output-controls
            • Observation
            • *standard-co*
            • Ppr-special-syms
            • Standard-oi
            • Standard-co
            • Without-evisc
            • Serialize
              • With-serialize-character
              • Unsound-read
                • Serialize-read
                • Serialize-in-books
                • Print-compressed
                • Print-legibly
                • Serialize-write
                • Set-serialize-character-system
                • Serialize-alternatives
              • Output-to-file
              • Fmt-to-comment-window
              • Princ$
              • Character-encoding
              • Open-output-channel!
              • Cw-print-base-radix
              • Set-print-case
              • Set-print-base
              • Print-object$
              • Extend-pathname
              • Print-object$+
              • Fmx-cw
              • Set-print-radix
              • Set-fmt-hard-right-margin
              • File-write-date$
              • Proofs-co
              • Set-print-base-radix
              • Print-base-p
              • *standard-oi*
              • Wof
              • File-length$
              • Fms!-lst
              • Delete-file$
              • *standard-ci*
              • Write-list
              • Trace-co
              • Fmt!
              • Fms
              • Cw!
              • Fmt-to-comment-window!
              • Fms!
              • Eviscerate-hide-terms
              • Fmt1!
              • Fmt-to-comment-window!+
              • Read-file-into-byte-array-stobj
              • Fmt1
              • Fmt-to-comment-window+
              • Cw-print-base-radix!
              • Read-file-into-character-array-stobj
              • Fmx
              • Cw!+
              • Read-objects-from-book
              • Newline
              • Cw+
              • Probe-file
              • Write-objects-to-file!
              • Write-objects-to-file
              • Read-objects-from-file
              • Read-object-from-file
              • Read-file-into-byte-list
              • Set-fmt-soft-right-margin
              • Read-file-into-character-list
              • Io-utilities
            • Defpkg
            • Apply$
            • Loop$
            • Programming-with-state
            • Arrays
            • Characters
            • Time$
            • Defmacro
            • Loop$-primer
            • Fast-alists
            • Defconst
            • Evaluation
            • Guard
            • Equality-variants
            • Compilation
            • Hons
            • ACL2-built-ins
            • Developers-guide
            • System-attachments
            • Advanced-features
            • Set-check-invariant-risk
            • Numbers
            • Efficiency
            • Irrelevant-formals
            • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
            • Redefining-programs
            • Lists
            • Invariant-risk
            • Errors
            • Defabbrev
            • Conses
            • Alists
            • Set-register-invariant-risk
            • Strings
            • Program-wrapper
            • Get-internal-time
            • Basics
            • Packages
            • Oracle-eval
            • Defmacro-untouchable
            • <<
            • Primitive
            • Revert-world
            • Unmemoize
            • Set-duplicate-keys-action
            • Symbols
            • Def-list-constructor
            • Easy-simplify-term
            • Defiteration
            • Fake-oracle-eval
            • Defopen
            • Sleep
          • Operational-semantics
          • Real
          • Start-here
          • Debugging
          • Miscellaneous
          • Output-controls
          • Macros
          • Interfacing-tools
        • Interfacing-tools
        • Hardware-verification
        • Software-verification
        • Math
        • Testing-utilities
      • Std/io
      • Serialize

      Unsound-read

      A faster alternative to serialize-read, which is unsound in general, but may be fine in many common cases.

      The unsound-read is like serialize-read except that it does not take state. This means it works even in ordinary defconst events, which avoids the performance penalty of using make-event to read files, as described in serialize-in-books.

      As its name suggests, unsound-read is unsound and it can easily be used to prove nil; see below. Because of this, unlike the other serialize routines, it is not build it into ACL2; instead, to use it you must first include its book, which requires a trust tag:

      (include-book "std/io/unsound-read" :dir :system :ttags (:unsound-read))

      General form:

      (unsound-read filename
                    [:hons-mode {:always, :never, :smart}]
                    [:verbose   {t, nil}])
        -->
      obj

      The arguments are as in serialize-read.

      Explanation of Unsoundness

      The logical problem with unsound-read is that, like any other function, it is expected to satisfy the functional equality axiom schema, namely,

      (equal (unsound-read-fn filename hons-mode verbosep)
             (unsound-read-fn filename hons-mode verbosep))

      But we can easily violate this property by modifying the file system between calls of unsound-read. For instance, here is a proof of nil that is carried out in std/io/serialize-tests.lisp:

      (local
       (encapsulate
        ()
        ;; Write NIL to test.sao
        (make-event
         (let ((state (serialize-write "test.sao" nil)))
           (value '(value-triple :invisible))))
      
        ;; Prove that test.sao contains NIL.
        (defthm lemma-1
          (equal (unsound-read "test.sao") nil)
          :rule-classes nil)
      
        ;; Write T to test.sao
        (make-event
         (let ((state (serialize-write "test.sao" t)))
           (value '(value-triple :invisible))))
      
        ;; Prove that test.sao contains T.
        (defthm lemma-2
          (equal (unsound-read "test.sao") t)
          :rule-classes nil)
      
        ;; Arrive at our contradiction.
        (defthm qed
          nil
          :rule-classes nil
          :hints(("Goal"
                  :use ((:instance lemma-1)
                        (:instance lemma-2))
                  :in-theory (disable (unsound-read-fn)))))))

      Avoiding Unsoundness

      If you want to safely use unsound-read to read some file, foo.sao, then you should not change foo.sao after reading it.

      A common scenario is that you have some book, foo.lisp, that uses unsound-read to load foo.sao, using a defconst event. In this case, simply adding a depends-on line such as:

      ; (depends-on "foo.sao")
      (defconst *contents* (unsound-read "foo.sao"))

      May, at least for users of cert.pl, offer some minimal protection. (This depends-on line tells cert.pl to rebuild foo.cert any time that foo.sao changes.)