Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

[move-prover] preliminary support for type reflection #451

Merged
merged 1 commit into from
Sep 7, 2022

Conversation

meng-xu-cs
Copy link
Collaborator

This commit introduces preliminary support on verifying code that uses reflection to obtain type information at runtime.

We use a hyperthetical (and intrinsic) call
fun extension::type_info::type_name<T>(): String that returns the type name of T.

Being a pure function, this reflection function can be called from the spec context as well.

In handling reflection, the high-level idea is:

  • if T is statically known when type_name<T> is called, replace this call with a constant
  • if T is unknown, full or partially, when this call is invoked, replace the type_name for T with a fresh variable var #T_name: Vec int, in particular:
    • if T is fully unknown, type_name<T> will be #T_name
    • if T is partially unknown (e.g., type_name<vector<T>>), then the type_name call will be replaced as ConcatVec(ConcatVec("vector<", #T_name), ">")

This instrumentation happens at the translation phase, on the way to Boogie.

Motivation

Reasoning with a reflection context

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  • CI
  • new test case added

This commit introduces preliminary support on verifying code that
uses reflection to obtain type information at runtime.

We use a hyperthetical (and intrinsic) call
`fun extension::type_info::type_name<T>(): String`
that returns the type name of `T`.

Being a pure function, this reflection function can be called
from the spec context as well.

In handling reflection, the high-level idea is:
- if `T` is statically known when `type_name<T>` is called, replace this
  call with a constant
- if `T` is unknown, full or partially, when this call is invoked,
  replace the `type_name` for `T` with a fresh variable
  `var #T_name: Vec int`, in particular:
  - if `T` is fully unknown, `type_name<T>` will be `#T_name`
  - if `T` is partially unknown (e.g., `type_name<vector<T>>`), then
    the `type_name` call will be replaced as
    `ConcatVec(ConcatVec("vector<", #T_name), ">")`

This instrumentation happens at the translation phase, on the way to
Boogie.
@meng-xu-cs meng-xu-cs marked this pull request as ready for review September 7, 2022 09:19
@meng-xu-cs meng-xu-cs merged commit f982b26 into move-language:main Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants