Functional programming 在另一个模块中调用函数时不满足前提条件

Functional programming 在另一个模块中调用函数时不满足前提条件,functional-programming,formal-verification,fstar,Functional Programming,Formal Verification,Fstar,我试图调用另一个模块中的函数,该模块负责确保保留堆上的前置/后置条件。具体来说,它确保传入的字符串在调用read之前是“可读的”: val readableFiles : ref fileList let readableFiles = ST.alloc [] let checkedRead f = if canRead !readableFiles f then read f else failwith "unreadable" 这允许它满足如下定义的读取前提条件: let c

我试图调用另一个模块中的函数,该模块负责确保保留堆上的前置/后置条件。具体来说,它确保传入的字符串在调用read之前是“可读的”:

val readableFiles : ref fileList
let readableFiles = ST.alloc []

let checkedRead f =
  if canRead !readableFiles f
  then read f
  else failwith "unreadable"
这允许它满足如下定义的读取前提条件:

let canRead (readList : fileList) (f : filename) =
  Some? (tryFind (function x -> x = f) readList)
type canRead_t f h = canRead (sel h readableFiles) f == true

val read : f:filename -> All string
  (requires (canRead_t f)) (ensures (fun h x h' -> True))
let read f = FStar.IO.print_string ("Dummy read of file " ^ f ^ "\n"); f
当我创建一个main函数并调用
checkedRead“file”
时,它工作正常,但是当我尝试在另一个模块中使用此模块时,它会出现以下错误:

TestAccess.fst(34,11-34,19): (Error 19) assertion failed (see also <fstar_path>/fstar/ulib/FStar.All.fst(36,40-36,45))
Verified module: TestAccess (3912 milliseconds)
TestAccess.fst(34,11-34,19):(错误19)断言失败(另请参见/fstar/ulib/fstar.All.fst(36,40-36,45))
已验证模块:TestAccess(3912毫秒)
如果您试图直接调用
read
,而不使用
checkedRead
(在主文件中),则会看到相同的错误,这意味着编译器不相信满足了前提条件

如果我在另一个文件中复制了
checkedRead
(并且只有该函数),它将正常工作。因此,编译器似乎无法推断这是否满足跨模块边界的条件


如何使用另一个文件中的
checkedRead
函数,而不必在本地重新定义它?

请发布一个完整的示例


提示:注释顶级函数的类型是一种很好的做法。这将有助于您确认F*推断的类型是您期望的类型,这在诊断此类验证失败时会很有帮助。

您能发布一个完整的示例吗


提示:注释顶级函数的类型是一种很好的做法。这将帮助您确认F*推断的类型是您期望的类型,这在诊断此类验证失败时可能会有所帮助。

根据Nik Swamy的建议,我在
checkedRead
中添加了一个类型注释,解决了此问题:

val checkedRead : filename -> All string
  (requires (fun h -> True)) (ensures (fun h x h' -> True))
let checkedRead f =
  if canRead !readableFiles f
  then read f
  else failwith "unreadable"

按照Nik Swamy的建议,我在checkedRead中添加了一个类型注释,解决了这个问题:

val checkedRead : filename -> All string
  (requires (fun h -> True)) (ensures (fun h x h' -> True))
let checkedRead f =
  if canRead !readableFiles f
  then read f
  else failwith "unreadable"

键入注释
checkedRead
为我解决了这个问题!我已经发布了一个带有修复的答案。键入注释
checkedRead
为我解决了这个问题!我已经发布了一个带有修正的答案。