mit-plv / bedrock2

A work-in-progress language and compiler for verified low-level programming

Home Page:http://adam.chlipala.net/papers/LightbulbPLDI21/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does bedrock2 use `Load`?

JasonGross opened this issue · comments

LiveVerif.v ends in the middle of a section:

Require Import coqutil.Z.Lia.
Require Import coqutil.Byte coqutil.Datatypes.HList.
Require Import coqutil.Datatypes.PropSet.
Require Import coqutil.Tactics.letexists coqutil.Tactics.Tactics coqutil.Tactics.rewr coqutil.Tactics.rdelta.
Require Import coqutil.Map.Interface coqutil.Map.Properties.
Require Import coqutil.Word.Interface coqutil.Word.Properties.
Require Import bedrock2.Syntax bedrock2.Semantics.
Require Import bedrock2.Lift1Prop.
Require Import bedrock2.Map.Separation bedrock2.Map.SeparationLogic bedrock2.Array.
Require Import bedrock2.ZnWords.
Require Import bedrock2.ptsto_bytes bedrock2.Scalars.
Require Import bedrock2.WeakestPrecondition bedrock2.ProgramLogic bedrock2.Loops.
Require Import coqutil.Word.Bitwidth32.
Require coqutil.Datatypes.String coqutil.Map.SortedList coqutil.Map.SortedListString.
Infix "^+" := word.add (at level 50, left associativity).
Infix "^-" := word.sub (at level 50, left associativity).
Infix "^*" := word.mul (at level 40, left associativity).
Infix "^<<" := word.slu (at level 37, left associativity).
Infix "^>>" := word.sru (at level 37, left associativity).
Notation "/[ x ]" := (word.of_Z x) (* squeeze a Z into a word (beat it with a / to make it smaller) *)
(format "/[ x ]").
Notation "\[ x ]" := (word.unsigned x) (* \ is the open (removed) lid of the modulo box imposed by words, *)
(format "\[ x ]"). (* let a word fly into the large Z space *)
Section LiveVerif.
Import Syntax BinInt String List.ListNotations ZArith.
Context {word: word.word 32} {mem: map.map word byte}.
Context {word_ok: word.ok word} {mem_ok: map.ok mem}.
Local Set Implicit Arguments.
Local Open Scope string_scope. Local Open Scope Z_scope. Local Open Scope list_scope.
Coercion Z.of_nat : nat >-> Z.
Coercion byte.unsigned : byte >-> Z.
Notation len := List.length.
Notation "'bytetuple' sz" := (HList.tuple byte (@Memory.bytes_per 32 sz)) (at level 10).
Add Ring wring : (Properties.word.ring_theory (word := word))
(preprocess [autorewrite with rew_word_morphism],
morphism (Properties.word.ring_morph (word := word)),
constants [Properties.word_cst]).
(* TODO should we remove this an require users to specify their own each time? *)
Context {ext_spec: ExtSpec} {ext_spec_ok : ext_spec.ok ext_spec}.
Instance locals: Interface.map.map String.string word := SortedListString.map _.
Instance env: Interface.map.map String.string (list String.string * list String.string * cmd) :=
SortedListString.map _.
Instance locals_ok: Interface.map.ok locals := SortedListString.ok _.
Instance env_ok: Interface.map.ok env := SortedListString.ok _.
Arguments locals: simpl never.
Arguments env: simpl never.

This exposed a bug in my bug minimizer / coq (JasonGross/coq-tools#104, coq/coq#15497), but I'm confused why bedrock2 is set up this way.

LiveVerif.v ends in the middle of a section:

This is intended, and therefore LifeVerif.v is excluded from the build. You should never try to build LifeVerif.v on its own.

LifeVerif.v contains a lot of setup code (such as setting up a Ring that depends on section variables) that I don't want to repeat in every file, and setup code that depends on section variables also can't be put into a file that other files then Import, so I use Load. The files (currently only 1) doing Load LiveVerif. are not syntactically balanced wrt Section and End: The opening of the Section LiveVerif happens through the Load, whereas the End LiveVerif is directly in the file, so I guess tools which want to parse or analyze this file and care about well-balanced Section/End need to inline Loaded files, sorry for breaking your tool Jason... 😉

sorry for breaking your tool Jason... 😉

The biggest problem is that coqc will dump locations from the loaded file into the glob file for the file doing the loading, and of course using locations from LiveVerif.v when dealing with swap.v makes no sense. The secondary problem is that my tool doesn't know how to inline Load, in large part because the .glob file contains no information about which file Coq actually picked up to inline.