Skip to content

Commit

Permalink
lib: Requalify_Test: add example of requalify-hide-requalify
Browse files Browse the repository at this point in the history
Document/test surprising interactions of hide_const, locales and
requalify for the purposes of temporarily making arch-specific constants
visible in theory scope.

Signed-off-by: Rafal Kolanski <[email protected]>
  • Loading branch information
Xaphiosis committed Aug 27, 2024
1 parent 744af74 commit e949698
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/test/Requalify_Test.thy
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,53 @@ arch_requalify_consts (in Arch) (A) arch_specific_const_a
term Arch.arch_specific_const_a


section "Specific tests"

subsection \<open>Temporary requalification of, hiding of, and re-exposing of constants\<close>

(* This kind of approach can be used for tools such at the C Parser, which are not aware of the Arch
locale and might need to refer to constants directly in internal annotations. *)

context Arch begin arch_global_naming
datatype vmpage_size =
ARCHSmallPage
end
arch_requalify_types vmpage_size

context Arch begin global_naming vmpage_size
requalify_consts ARCHSmallPage
end

(* both now visible in generic context *)
typ vmpage_size

Check failure on line 290 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
term vmpage_size.ARCHSmallPage

Check failure on line 291 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
term ARCHSmallPage (* note: the direct constructor name is not accessible due to qualified export *)

Check failure on line 292 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.

(* temporary global exposure is done, hide vmpage sizes again *)
hide_const
vmpage_size.ARCHSmallPage

find_consts name:ARCHSmallPage

Check failure on line 298 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
(* finds one constant (despite it being hidden), e.g. on ARM:
Requalify.ARM.vmpage_size.ARMSmallPage :: "vmpage_size"
but note that this constant is inaccessible from theory scope:
term Requalify_Test.AARCH64.vmpage_size.ARCHSmallPage
will result in Inaccessible constant: "Requalify_Test.ARM.vmpage_size.ARCHSmallPage" *)

(* Arch-specific, in actual use replace ARCH with actual architecture such as ARM *)
context Arch begin
term vmpage_size.ARCHSmallPage (* despite being hidden in theory scope, it's still visible in Arch *)

Check failure on line 307 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
global_naming "ARCH.vmpage_size" requalify_consts ARCHSmallPage
global_naming "ARCH" requalify_consts ARCHSmallPage
end

term ARCH.ARCHSmallPage (* now accessible under specific qualified name *)

Check failure on line 312 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
term ARCH.vmpage_size.ARCHSmallPage (* now accessible under specific qualified name *)

Check failure on line 313 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
term Requalify_Test.ARCH.vmpage_size.ARCHSmallPage (* fully qualified name *)

Check failure on line 314 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.
(* but be aware, these are only aliases to the original constant! *)
find_consts name:ARCHSmallPage (* still only Requalify_Test.ARM.vmpage_size.ARCHSmallPage *)

Check failure on line 316 in lib/test/Requalify_Test.thy

View workflow job for this annotation

GitHub Actions / File annotations for theory linter

Interactive diagnostic command

This command is usually used interactively only and should only be checked in for demonstration purposes.


section "Misc tests / usage examples"

locale Requalify_Locale
Expand Down

0 comments on commit e949698

Please sign in to comment.