Scope type-aliases per module in blueprint.
Similarly to how we're already doing it for non-alias types. Fix #1074. Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
This commit is contained in:
parent
94246bdb2b
commit
58d782fa78
|
@ -193,6 +193,7 @@ impl Type {
|
||||||
ret: Type::option(Type::tuple(vec![Type::prng(), a])),
|
ret: Type::option(Type::tuple(vec![Type::prng(), a])),
|
||||||
alias: Some(
|
alias: Some(
|
||||||
TypeAliasAnnotation {
|
TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: FUZZER.to_string(),
|
alias: FUZZER.to_string(),
|
||||||
parameters: vec!["a".to_string()],
|
parameters: vec!["a".to_string()],
|
||||||
annotation: Annotation::Fn {
|
annotation: Annotation::Fn {
|
||||||
|
@ -234,6 +235,7 @@ impl Type {
|
||||||
ret: Type::fuzzer(a),
|
ret: Type::fuzzer(a),
|
||||||
alias: Some(
|
alias: Some(
|
||||||
TypeAliasAnnotation {
|
TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: SAMPLER.to_string(),
|
alias: SAMPLER.to_string(),
|
||||||
parameters: vec!["a".to_string()],
|
parameters: vec!["a".to_string()],
|
||||||
annotation: Annotation::Fn {
|
annotation: Annotation::Fn {
|
||||||
|
@ -276,6 +278,7 @@ impl Type {
|
||||||
args: vec![Type::pair(k, v)],
|
args: vec![Type::pair(k, v)],
|
||||||
alias: Some(
|
alias: Some(
|
||||||
TypeAliasAnnotation {
|
TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: PAIRS.to_string(),
|
alias: PAIRS.to_string(),
|
||||||
parameters: vec!["k".to_string(), "v".to_string()],
|
parameters: vec!["k".to_string(), "v".to_string()],
|
||||||
annotation: Annotation::Constructor {
|
annotation: Annotation::Constructor {
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub use environment::collapse_links;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct TypeAliasAnnotation {
|
pub struct TypeAliasAnnotation {
|
||||||
|
pub module: Option<String>,
|
||||||
pub alias: String,
|
pub alias: String,
|
||||||
pub parameters: Vec<String>,
|
pub parameters: Vec<String>,
|
||||||
pub annotation: Annotation,
|
pub annotation: Annotation,
|
||||||
|
|
|
@ -1160,6 +1160,7 @@ impl<'a> Environment<'a> {
|
||||||
.set_alias(Some(
|
.set_alias(Some(
|
||||||
TypeAliasAnnotation {
|
TypeAliasAnnotation {
|
||||||
alias: name.to_string(),
|
alias: name.to_string(),
|
||||||
|
module: Some(module.to_string()),
|
||||||
parameters: args.to_vec(),
|
parameters: args.to_vec(),
|
||||||
annotation: resolved_type.clone(),
|
annotation: resolved_type.clone(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ impl Printer {
|
||||||
alias,
|
alias,
|
||||||
parameters,
|
parameters,
|
||||||
annotation,
|
annotation,
|
||||||
|
module: _,
|
||||||
}) = typ.alias().as_deref()
|
}) = typ.alias().as_deref()
|
||||||
{
|
{
|
||||||
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, typ) {
|
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, typ) {
|
||||||
|
@ -551,6 +552,7 @@ mod tests {
|
||||||
alias: None,
|
alias: None,
|
||||||
}),
|
}),
|
||||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: "Fuzzer".to_string(),
|
alias: "Fuzzer".to_string(),
|
||||||
parameters: vec!["a".to_string(),],
|
parameters: vec!["a".to_string(),],
|
||||||
annotation: Annotation::Fn {
|
annotation: Annotation::Fn {
|
||||||
|
@ -621,6 +623,7 @@ mod tests {
|
||||||
alias: None,
|
alias: None,
|
||||||
}),
|
}),
|
||||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: "Fuzzer".to_string(),
|
alias: "Fuzzer".to_string(),
|
||||||
parameters: vec!["a".to_string(),],
|
parameters: vec!["a".to_string(),],
|
||||||
annotation: Annotation::Fn {
|
annotation: Annotation::Fn {
|
||||||
|
@ -675,6 +678,7 @@ mod tests {
|
||||||
alias: None,
|
alias: None,
|
||||||
}),
|
}),
|
||||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||||
|
module: None,
|
||||||
alias: "Identity".to_string(),
|
alias: "Identity".to_string(),
|
||||||
parameters: vec!["t".to_string()],
|
parameters: vec!["t".to_string()],
|
||||||
annotation: Annotation::Var {
|
annotation: Annotation::Var {
|
||||||
|
|
|
@ -349,12 +349,14 @@ impl Reference {
|
||||||
alias,
|
alias,
|
||||||
parameters,
|
parameters,
|
||||||
annotation,
|
annotation,
|
||||||
|
module,
|
||||||
}) = type_info.alias().as_deref()
|
}) = type_info.alias().as_deref()
|
||||||
{
|
{
|
||||||
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, type_info) {
|
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, type_info) {
|
||||||
return Self::from_type_alias(
|
return Self::from_type_alias(
|
||||||
type_info,
|
type_info,
|
||||||
alias.to_string(),
|
alias,
|
||||||
|
module.as_deref(),
|
||||||
resolved_parameters,
|
resolved_parameters,
|
||||||
type_parameters,
|
type_parameters,
|
||||||
);
|
);
|
||||||
|
@ -429,14 +431,20 @@ impl Reference {
|
||||||
|
|
||||||
fn from_type_alias(
|
fn from_type_alias(
|
||||||
type_info: &Type,
|
type_info: &Type,
|
||||||
alias: String,
|
alias: &str,
|
||||||
|
module: Option<&str>,
|
||||||
parameters: Vec<Rc<Type>>,
|
parameters: Vec<Rc<Type>>,
|
||||||
type_parameters: &HashMap<u64, Rc<Type>>,
|
type_parameters: &HashMap<u64, Rc<Type>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let prefix = match module {
|
||||||
|
Some(module) => format!("{module}/{alias}"),
|
||||||
|
None => alias.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
if !parameters.is_empty() {
|
if !parameters.is_empty() {
|
||||||
Reference {
|
Reference {
|
||||||
inner: format!(
|
inner: format!(
|
||||||
"{alias}${}",
|
"{prefix}${}",
|
||||||
parameters
|
parameters
|
||||||
.iter()
|
.iter()
|
||||||
.map(|param| {
|
.map(|param| {
|
||||||
|
@ -456,9 +464,7 @@ impl Reference {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Reference {
|
Reference { inner: prefix }
|
||||||
inner: alias.clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue