Skip to content
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
90227a8
first draft of ast formalization
ahubanov-eth2 Mar 10, 2022
2d547dc
changed to small-step semantics, added a find_label function and adde…
ahubanov-eth2 Mar 13, 2022
e6a2754
added an ast reduction
ahubanov-eth2 Mar 14, 2022
857bf6e
added numbered breaks
ahubanov-eth2 Mar 14, 2022
897bf05
added invariants, fixed while_loop rule
ahubanov-eth2 Mar 17, 2022
e97e73a
minor syntactic tweaks + comments
ahubanov-eth2 Mar 23, 2022
4b68651
added Failure and Magic rule + invariants
ahubanov-eth2 Mar 24, 2022
f99dfca
added definitions for correctness of AST
ahubanov-eth2 Mar 30, 2022
cd33348
added an ast-to-cfg relation function (doesn't work for breaks and go…
ahubanov-eth2 Apr 2, 2022
b383517
refactored the code
ahubanov-eth2 Apr 5, 2022
c42b778
latest version of ast.thy
ahubanov-eth2 Apr 22, 2022
95f4947
saving before making some changes
ahubanov-eth2 Apr 28, 2022
6a97138
first draft of lemmas and proofs for the ast_cfg_phase
ahubanov-eth2 May 15, 2022
5ae8b6a
cleaned proofs + nested loop example done
ahubanov-eth2 May 22, 2022
3753ed4
annotated Ast_Cfg_Transformation.thy
ahubanov-eth2 Jun 1, 2022
2d30c01
fixed most of the concrete proofs + minor changes
ahubanov-eth2 Jun 2, 2022
02126da
changed nested loop2
ahubanov-eth2 Jun 3, 2022
a59e225
changed the definition of a procedure and of proc_is_correct
ahubanov-eth2 Jun 26, 2022
a4ef318
latest version
ahubanov-eth2 Jul 20, 2022
5ab0154
removing the examples folder
ahubanov-eth2 Aug 29, 2022
f5af8b1
parameterizing the red_cmd relation to take arbitrary procedure context
ahubanov-eth2 Aug 29, 2022
8e13211
resolving some pull request comments + a few smts removed
ahubanov-eth2 Oct 6, 2022
70f7b85
removed smts + fixed proc_context error, only slow metis remains
ahubanov-eth2 Oct 10, 2022
dba9e6a
changed the slow metis with a seemingly faster metis
ahubanov-eth2 Oct 10, 2022
334580a
decoupled the procedure type parameter from the proc_context type par…
ahubanov-eth2 Oct 11, 2022
91b6f22
add type synonym used in end-to-end lemma for AST-to-CFG phase
gauravpartha Oct 18, 2022
2841d8e
Merge branch 'master' into ast
gauravpartha Oct 18, 2022
f81f1fc
fix proofs that did not work for reals extension
gauravpartha Oct 18, 2022
92ede48
simplify proofs
gauravpartha Oct 18, 2022
589c327
style adjustments
gauravpartha Oct 18, 2022
68e5511
minor
gauravpartha Nov 10, 2022
2653a19
removed rev for AST and AST_CFG_Transformation
ahubanov-eth2 Nov 19, 2022
d8584a5
fix bug in goto semantics
gauravpartha Jan 10, 2023
26e3fbd
Merge branch 'master' into ast
gauravpartha Jan 11, 2023
58d1183
Merge branch 'master' into ast
gauravpartha Jan 15, 2023
8682774
start adding support for conditional expressions
gauravpartha Sep 14, 2022
a12a1c0
progress
gauravpartha Jan 16, 2023
31d7099
VC support for conditional expressions
gauravpartha Jan 16, 2023
5cfb456
Merge remote-tracking branch 'origin/conditional_expressions' into ad…
gauravpartha Jan 16, 2023
6694cda
add convert_ast_to_program_point
gauravpartha Jan 16, 2023
ec8695f
Merge branch 'ast' into adjust_interface
gauravpartha Jan 16, 2023
0be7851
Create CfgOptimizations.thy
Apr 20, 2023
812ce42
Update CfgOptimizations.thy
May 10, 2023
3593d64
Create CfgOptimizationsLoop.thy
May 31, 2023
adc52d8
Update CfgOptimizations.thy
May 31, 2023
da762b7
Change File Name CFGOptimizations
Jun 14, 2023
b67f4f5
Fix Main Lemma 4 (Wrong assumption)
Jun 15, 2023
20d38f5
New Document for Dead Variables Elimination
Jun 21, 2023
b63d4b4
Changed Definition of Global Block and Hybrid Block Lemma
Jun 26, 2023
caeeac6
Edited assumptions of Lemmas and changed the proof accordingly
Jun 29, 2023
6707e6c
Changed Hybrid Block Lemma to get rid of the last sorry statements
Jul 2, 2023
b0168f9
Changed sorry statements dead variables elimination
Jul 5, 2023
4bacb2a
get rid of sorry on line 651
gauravpartha Jul 9, 2023
8700b1a
Merge branch 'master' into cfg_optimizations
gauravpartha Jul 9, 2023
c6699cf
add CondExp cases (after merging master)
gauravpartha Jul 9, 2023
78ee660
Sorry statements conditional expressions
Jul 10, 2023
e87d56f
Removed sorry statement
Jul 11, 2023
832b1e7
add CFGOptimizationsLoop
gauravpartha Jul 11, 2023
4538f3d
Changed Pruning of Unreachable Blocks Lemma
Jul 12, 2023
6254cd7
Merge branch 'cfg_optimizations' of https://github.com/gauravpartha/f…
Jul 12, 2023
d526aa1
minor
gauravpartha Jul 18, 2023
007d58d
adjust procedure correctness definition to take unique constants into…
gauravpartha Oct 21, 2023
825300d
minor
gauravpartha Oct 21, 2023
6d64175
theories work again
gauravpartha Oct 21, 2023
99dbc48
Merge remote-tracking branch 'origin/int_to_real_conversion' into adj…
gauravpartha Oct 30, 2023
30e8c9c
Merge branch 'master' into adjust_interface
gauravpartha Oct 30, 2023
9826008
Merge branch 'adjust_interface' of https://github.com/gauravpartha/fo…
gauravpartha Oct 31, 2023
26871a8
Merge branch 'master' into adjust_interface
gauravpartha Oct 31, 2023
cf83439
remove Boogie_Lang session references
gauravpartha Nov 16, 2023
b054111
comment out file that does not type check
gauravpartha Nov 16, 2023
a326da1
add globals_locals_helper lemma
gauravpartha Dec 5, 2023
04cbf10
Merge branch 'adjust_interface' of https://github.com/gauravpartha/fo…
gauravpartha Dec 5, 2023
af1d8ec
fix break case
gauravpartha Dec 5, 2023
a12fd2c
Merge remote-tracking branch 'origin/adjust_interface' into cfg_optim…
gauravpartha Feb 10, 2024
b005c01
allow WhileWrapper around any control-flow construct in AST semantics
gauravpartha Apr 25, 2024
91cded0
add helper lemma for proof generation of CFG optimizations
gauravpartha Aug 21, 2024
63cb964
Updated files to work with Isabelle 2023
tdardinier Apr 24, 2024
9041134
Update README.md
gauravpartha Dec 8, 2024
7e24d26
move helper relations from Ast.thy (semantics) to Ast_Cfg_Transformat…
gauravpartha Dec 19, 2024
0bca52f
clean up
gauravpartha Dec 19, 2024
7f8f209
remove unused file
gauravpartha Dec 19, 2024
69e83f8
clean up
gauravpartha Dec 19, 2024
e59cb6c
remove unfinished dead variable elimination metatheory file
gauravpartha Dec 19, 2024
c4aafb6
add comment
gauravpartha Dec 19, 2024
b4058ce
clean up
gauravpartha Dec 19, 2024
a35a8c9
consistent order in ROOT (earlier transformations listed first)
gauravpartha Dec 19, 2024
7ee0531
typo
gauravpartha Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions BoogieLang/Ast.thy
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
section \<open>Semantics of the AST\<close>

theory Ast
imports Main Semantics Lang BackedgeElim

begin

subsection \<open>AST definition\<close>

type_synonym name = string
type_synonym label = string
type_synonym guard = expr
type_synonym invariant = expr

datatype transfer_cmd
= Goto label
| Return

datatype parsed_structured_cmd
= ParsedIf "guard option" "bigblock list" "bigblock list"
| ParsedWhile "guard option" "invariant list" "bigblock list"
| ParsedBreak nat
| WhileWrapper parsed_structured_cmd

and bigblock
= BigBlock "name option" "cmd list" "parsed_structured_cmd option" "transfer_cmd option"


text \<open>A Boogie statement represented as an AST is a list of \<^typ>\<open>bigblock\<close>\<close>

type_synonym ast = "bigblock list"

subsection \<open>AST semantics\<close>

text \<open>We define a continuation-based small-step semantics.\<close>

datatype cont
= KStop
| KSeq "bigblock" cont
| KEndBlock cont

type_synonym 'a ast_config = "bigblock * cont * ('a state)"

fun convert_list_to_cont :: "bigblock list \<Rightarrow> cont \<Rightarrow> cont" where
"convert_list_to_cont [] cont0 = cont0"
| "convert_list_to_cont (x#xs) cont0 = KSeq x (convert_list_to_cont xs cont0)"

text\<open>auxillary function to find the label a Goto statement is referring to\<close>
fun find_label :: "label \<Rightarrow> bigblock list \<Rightarrow> cont \<Rightarrow> ((bigblock * cont) option)" where
"find_label lbl [] cont = None"
| "find_label lbl ((BigBlock bb_name cmds None None) # []) cont =
(if (Some lbl = bb_name) then (Some ((BigBlock bb_name cmds None None), cont)) else (None))"
| "find_label lbl ((BigBlock bb_name cmds None None) # bbs) cont =
(if (Some lbl = bb_name)
then (Some ((BigBlock bb_name cmds None None), (convert_list_to_cont ( bbs) cont)))
else (find_label lbl bbs cont))"
| "find_label lbl ((BigBlock bb_name cmds (Some (ParsedIf guard then_bbs else_bbs)) None) # bbs) cont =
(if (Some lbl = bb_name)
then (Some ((BigBlock bb_name cmds (Some (ParsedIf guard then_bbs else_bbs)) None), (convert_list_to_cont ( bbs) cont)))
else (if (find_label lbl then_bbs cont \<noteq> None)
then (find_label lbl (then_bbs @ bbs) cont)
else (find_label lbl (else_bbs @ bbs) cont)))"
| "find_label lbl ((BigBlock bb_name cmds (Some (ParsedWhile guard invariants body_bbs)) None) # bbs) cont =
(if (Some lbl = bb_name)
then (Some ((BigBlock bb_name cmds (Some (ParsedWhile guard invariants body_bbs)) None), (convert_list_to_cont ( bbs) cont)))
else (if (find_label lbl body_bbs cont \<noteq> None)
then (find_label lbl body_bbs (convert_list_to_cont ((bbs)@[(BigBlock None [] (Some (ParsedWhile guard invariants body_bbs)) None)]) cont))
else (find_label lbl bbs cont)))"
| "find_label lbl ((BigBlock bb_name cmds (Some (ParsedBreak n)) None) # bbs) cont =
(if (Some lbl = bb_name)
then (Some ((BigBlock bb_name cmds (Some (ParsedBreak n)) None), (convert_list_to_cont ( bbs) cont)))
else (find_label lbl bbs cont))"
| "find_label lbl ((BigBlock bb_name cmds (Some (WhileWrapper while_loop)) None) # bbs) cont =
find_label lbl ((BigBlock bb_name cmds (Some while_loop) None) # bbs) cont"
| "find_label lbl ((BigBlock bb_name cmds None (Some transfer_stmt)) # bbs) cont =
(if (Some lbl = bb_name)
then (Some ((BigBlock bb_name cmds None (Some transfer_stmt)), (convert_list_to_cont ( bbs) cont)))
else (find_label lbl bbs cont))"
| "find_label lbl ((BigBlock bb_name cmds (Some s) (Some t)) # bbs) cont = None"

fun get_state :: "'a ast_config \<Rightarrow> 'a state"
where
"get_state (bb, cont, s1) = s1"

fun is_final :: "'a ast_config \<Rightarrow> bool"
where
"is_final ((BigBlock bb_name [] None None), KStop, s1) = True"
| "is_final other = False"

text \<open>Small-step semantics\<close>

inductive red_bigblock :: "'a absval_ty_fun \<Rightarrow> 'm proc_context \<Rightarrow> var_context \<Rightarrow> 'a fun_interp \<Rightarrow> rtype_env \<Rightarrow> ast \<Rightarrow> 'a ast_config \<Rightarrow> 'a ast_config \<Rightarrow> bool"
("_,_,_,_,_,_ \<turnstile> (\<langle>_\<rangle> \<longrightarrow>/ _)" [51,0,0,0] 81)
for A :: "'a absval_ty_fun" and M :: "'m proc_context" and \<Lambda> :: var_context and \<Gamma> :: "'a fun_interp" and \<Omega> :: rtype_env and T :: ast
where
RedSimpleCmds:
"\<lbrakk>(A,M,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>cs, (Normal n_s)\<rangle> [\<rightarrow>] s1) \<and> (cs \<noteq> Nil) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name cs str_cmd tr_cmd), cont0, Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] str_cmd tr_cmd), cont0, s1)"

| RedFailure_or_Magic:
"\<lbrakk> (s1 = Magic) \<or> (s1 = Failure); \<not> (is_final ((BigBlock bb_name [] str_cmd tr_cmd), cont0, s1)) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name [] str_cmd tr_cmd), cont0, s1)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), KStop, s1)"

| RedSkip:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name [] None None), (KSeq b cont0), Normal n_s)\<rangle> \<longrightarrow>
(b, cont0, Normal n_s)"

| RedSkipEndBlock:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name [] None None), (KEndBlock cont0), Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), cont0, Normal n_s)"

| RedReturn:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>(BigBlock bb_name [] None (Some Return), cont0, Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), KStop, Normal n_s)"

| RedParsedIfTrue:
"\<lbrakk>\<And> b. bb_guard = (Some b) \<Longrightarrow> A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>b, n_s\<rangle> \<Down> LitV (LBool True) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name []
(Some (ParsedIf bb_guard (then_hd # then_bbs) elsebigblocks)) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
(then_hd, (convert_list_to_cont ( then_bbs) cont0), Normal n_s)"

| RedParsedIfFalse:
"\<lbrakk>\<And>b. bb_guard = (Some b) \<Longrightarrow> A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>b, n_s\<rangle> \<Down> LitV (LBool False) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name []
(Some (ParsedIf bb_guard thenbigblocks (else_hd # else_bbs))) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
(else_hd, (convert_list_to_cont ( else_bbs) cont0), Normal n_s)"

| RedParsedWhileWrapper:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile>
\<langle>((BigBlock bb_name []
(Some (WhileWrapper str)) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name []
(Some str) None), (KEndBlock cont0), Normal n_s)"

| RedParsedWhile_InvFail:
"\<lbrakk>\<And> b. bb_guard = (Some b) \<Longrightarrow> A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>b, n_s\<rangle> \<Down> LitV (LBool True);
bb_invariants = invs1@[I]@invs2;
expr_all_sat A \<Lambda> \<Gamma> \<Omega> n_s invs1;
A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>I, n_s\<rangle> \<Down> BoolV False \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile>
\<langle>((BigBlock bb_name []
(Some (ParsedWhile bb_guard bb_invariants (bb_hd # body_bbs))) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), KStop, Failure)"

| RedParsedWhileTrue:
"\<lbrakk>\<And> b. bb_guard = (Some b) \<Longrightarrow> A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>b, n_s\<rangle> \<Down> LitV (LBool True);
(expr_all_sat A \<Lambda> \<Gamma> \<Omega> n_s bb_invariants) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile>
\<langle>((BigBlock bb_name []
(Some (ParsedWhile bb_guard bb_invariants (bb_hd # body_bbs))) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
(bb_hd, convert_list_to_cont ((body_bbs)@[(BigBlock bb_name [] (Some (ParsedWhile bb_guard bb_invariants (bb_hd # body_bbs))) None)]) cont0, Normal n_s)"


| RedParsedWhileFalse:
"\<lbrakk>\<And> b. bb_guard = (Some b) \<Longrightarrow> A,\<Lambda>,\<Gamma>,\<Omega> \<turnstile> \<langle>b, n_s\<rangle> \<Down> LitV (LBool False);
(expr_all_sat A \<Lambda> \<Gamma> \<Omega> n_s bb_invariants) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name []
(Some (ParsedWhile bb_guard bb_invariants bigblocks)) None), cont0, Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), cont0, Normal n_s)"

| RedBreak0:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name [] (Some (ParsedBreak 0)) None), (KEndBlock cont0), Normal n_s)\<rangle> \<longrightarrow>
((BigBlock bb_name [] None None), cont0, Normal n_s)"

| RedBreakN:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile>
\<langle>((BigBlock bb_name [] (Some (ParsedBreak n)) None), (KSeq b cont0), Normal n_s)\<rangle> \<longrightarrow>
((BigBlock None [] (Some (ParsedBreak n)) None), cont0, Normal n_s)"

| RedBreakNPlus1:
"A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile>
\<langle>((BigBlock bb_name [] (Some (ParsedBreak (n + 1))) None), (KEndBlock cont0), Normal n_s)\<rangle> \<longrightarrow>
((BigBlock None [] (Some (ParsedBreak n)) None), cont0, Normal n_s)"

| RedGoto:
"\<lbrakk> (find_label label T KStop) = Some (found_bigblock, found_cont) \<rbrakk>
\<Longrightarrow> A,M,\<Lambda>,\<Gamma>,\<Omega>,T \<turnstile> \<langle>((BigBlock bb_name [] None (Some (Goto label))), cont0, Normal n_s)\<rangle> \<longrightarrow>
(found_bigblock, found_cont, (Normal n_s))"

abbreviation red_bigblock_k_step :: "'a absval_ty_fun \<Rightarrow> 'm proc_context \<Rightarrow> var_context \<Rightarrow> 'a fun_interp \<Rightarrow> rtype_env \<Rightarrow> ast \<Rightarrow> 'a ast_config \<Rightarrow> nat \<Rightarrow> 'a ast_config \<Rightarrow> bool"
("_,_,_,_,_,_ \<turnstile>_ -n\<longrightarrow>^_/ _" [51,0,0,0,0] 81)
where "red_bigblock_k_step A M \<Lambda> \<Gamma> \<Omega> T c1 n c2 \<equiv> ((red_bigblock A M \<Lambda> \<Gamma> \<Omega> T)^^n) c1 c2"

subsection \<open>Procedure Correctness\<close>

text\<open>defining correctness of the AST\<close>

fun convert_ast_to_program_point :: "ast \<Rightarrow> bigblock \<times> cont" where
"convert_ast_to_program_point [] = ((BigBlock None [] None None), KStop)"
| "convert_ast_to_program_point (b#bs) = (b, convert_list_to_cont bs KStop)"

fun init_ast :: "ast \<Rightarrow> 'a nstate \<Rightarrow> 'a ast_config"
where
"init_ast [] ns1 = ((BigBlock None [] None None), KStop, Normal ns1)"
| "init_ast (b#bbs) ns1 = (b, convert_list_to_cont ( bbs) KStop, Normal ns1)"

definition valid_configuration
where "valid_configuration A \<Lambda> \<Gamma> \<Omega> posts bb cont state \<equiv>
state \<noteq> Failure \<and>
(is_final (bb, cont, state) \<longrightarrow> (\<forall>ns'. state = Normal ns' \<longrightarrow> expr_all_sat A \<Lambda> \<Gamma> \<Omega> ns' posts))"

definition proc_body_satisfies_spec :: "'a absval_ty_fun \<Rightarrow> 'm proc_context \<Rightarrow> var_context \<Rightarrow> 'a fun_interp \<Rightarrow> rtype_env \<Rightarrow> expr list \<Rightarrow> expr list \<Rightarrow> ast \<Rightarrow> 'a nstate \<Rightarrow> bool"
where "proc_body_satisfies_spec A M \<Lambda> \<Gamma> \<Omega> pres posts ast ns \<equiv>
expr_all_sat A \<Lambda> \<Gamma> \<Omega> ns pres \<longrightarrow>
(\<forall> bb cont state. (rtranclp (red_bigblock A M \<Lambda> \<Gamma> \<Omega> ast) (init_ast ast ns) (bb, cont, state)) \<longrightarrow>
valid_configuration A \<Lambda> \<Gamma> \<Omega> posts bb cont state)"

fun proc_all_pres :: "ast procedure \<Rightarrow> expr list"
where "proc_all_pres p = map fst (proc_pres p)"

fun proc_checked_posts :: "ast procedure \<Rightarrow> expr list"
where "proc_checked_posts p = map fst (filter (\<lambda>x. \<not> snd(x)) (proc_posts p))"

end

Loading
Loading