-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #665 from hacspec/more-package-metadata
More package metadata
- Loading branch information
Showing
14 changed files
with
101 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# hax adt into | ||
|
||
This crate provides the `adt_into` procedural macro, allowing for | ||
mirroring data types with small variations. | ||
|
||
This crate is used by the frontend of hax, where we need to mirror a | ||
big part of the data types defined by the Rust compiler. While the | ||
abstract syntax trees (ASTs) from the Rust compiler expose a lot of | ||
indirections (identifiers one should lookup, additional informations | ||
reachable only via interactive queries), hax exposes the same ASTs, | ||
removing indirections and inlining additional informations. | ||
|
||
The `adt_into` derive macro can be used on `struct`s and `enum`s. `adt_into` then looks for another `#[args(<GENERICS>, from: FROM_TYPE, state: STATE_TYPE as SOME_NAME)]` attribute. Such an attribute means that the `struct` or `enum` mirrors the type `FROM_TYPE`, and that the transformation is carried along with a state of type `STATE_TYPE` that will be accessible via the name `SOME_NAME`. | ||
|
||
An example is available in the `tests` folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// For the example, let's assume we are working with `Literal`, an | ||
/// ADT that represents literal values. Suppose strings are | ||
/// represented via an identifier stored in a state `State`. | ||
pub mod source { | ||
use std::collections::HashMap; | ||
#[derive(Clone, Debug)] | ||
pub struct State(pub HashMap<StringId, String>); | ||
|
||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | ||
pub struct StringId(u32); | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Literal { | ||
Integer(u32), | ||
String(StringId), | ||
} | ||
} | ||
|
||
/// Here, we mirror the same data type `Literal`, but with a small | ||
/// difference: there is no `StringId` any longer: we define a `impl` | ||
/// of `SInto` specifically for `StringId`, that ships with a stateful | ||
/// lookup. Magically, everytime a mirrored datatype annotated with | ||
/// `AdtInto` will have a field or a variant of type String while the | ||
/// original type was `StringId`, the lookup will be done | ||
/// automatically. | ||
mod mirrored { | ||
use super::{sinto::*, source}; | ||
use hax_adt_into::*; | ||
|
||
#[derive(AdtInto)] | ||
#[args(<>, from: source::Literal, state: source::State as s)] | ||
pub enum Literal { | ||
Integer(u32), | ||
String(String), | ||
} | ||
|
||
impl SInto<source::State, String> for source::StringId { | ||
fn sinto(&self, s: &source::State) -> String { | ||
s.0.get(self).unwrap().clone() | ||
} | ||
} | ||
} | ||
|
||
/// Definition of the `sinto` trait used by the `AdtInto` macro | ||
pub mod sinto { | ||
pub trait SInto<S, To> { | ||
fn sinto(&self, s: &S) -> To; | ||
} | ||
|
||
/// Default implementation for type implementing Copy | ||
impl<S, T: Copy> SInto<S, T> for T { | ||
fn sinto(&self, _s: &S) -> T { | ||
*self | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters