Skip to content

Commit

Permalink
feat: attach basic descriptions and links to HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanstraten committed Oct 6, 2022
1 parent 14c3012 commit 0f15619
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 39 deletions.
4 changes: 2 additions & 2 deletions rs/src/export/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl From<&extension::simple::type_class::Reference> for validator::data_type::U
extension_id: node
.definition
.as_ref()
.map(|x| x.extension_id)
.map(|x| x.identifier.extension_id)
.unwrap_or_default(),
}
}
Expand All @@ -369,7 +369,7 @@ impl From<&data::Variation> for validator::data_type::Variation {
extension_id: variation
.definition
.as_ref()
.map(|x| x.extension_id)
.map(|x| x.identifier.extension_id)
.unwrap_or_default(),
},
)
Expand Down
16 changes: 1 addition & 15 deletions rs/src/input/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn resolve_with_curl(uri: &str) -> Result<Vec<u8>, curl::Error> {
}

/// Configuration structure.
#[derive(Default)]
pub struct Config {
/// When set, do not generate warnings for unknown protobuf fields that are
/// set to their protobuf-defined default value.
Expand Down Expand Up @@ -86,21 +87,6 @@ pub struct Config {
pub max_uri_resolution_depth: Option<usize>,
}

// TODO: enable URI resolution by default once all that works. Then this can
// be derived again. Also still need to expose the depth option in extensions.
impl Default for Config {
fn default() -> Self {
Self {
ignore_unknown_fields: Default::default(),
allowed_proto_any_urls: Default::default(),
diagnostic_level_overrides: Default::default(),
uri_overrides: Default::default(),
uri_resolver: Default::default(),
max_uri_resolution_depth: Some(0),
}
}
}

impl Config {
/// Creates a default configuration.
pub fn new() -> Self {
Expand Down
8 changes: 8 additions & 0 deletions rs/src/output/extension/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,12 @@ impl<T> ResolutionResult<T> {
.next()
.flatten()
}

/// Calls the given function for each visible item.
pub fn for_each_visible_item<F: FnMut(&T)>(&self, mut f: F) {
self.visible
.iter()
.filter_map(|x| x.1.as_item())
.for_each(|x| f(&x))
}
}
5 changes: 5 additions & 0 deletions rs/src/output/extension/simple/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Module for the common types involved with representing extension
//! definitions.

use crate::output;

/// Identifying information associated with an extension, that can be used to
/// refer to the extension from elsewhere.
#[derive(Clone, Debug)]
Expand All @@ -18,6 +20,9 @@ pub struct Identifier {
/// number is only unique within the scope of a single run of the
/// validator, and may change between runs.
pub extension_id: u64,

/// The path that the extension is defined in.
pub definition_path: output::path::PathBuf,
}

/// Non-functional metadata common to all extension types.
Expand Down
8 changes: 5 additions & 3 deletions rs/src/output/extension/simple/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ use std::sync::Arc;
/// The definition of a function implementation.
#[derive(Clone, Debug)]
pub struct Definition {
/// Unique number within the tree that can be used to refer to this
/// extension when exporting in protobuf form.
pub extension_id: u64,
/// Identifier for the extension.
pub identifier: extension::simple::common::Identifier,

/// Common metadata for the extension.
pub metadata: extension::simple::common::Metadata,

/// Link to information common to a set of function implementations going by
/// the same name.
Expand Down
26 changes: 19 additions & 7 deletions rs/src/output/extension/simple/type_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use crate::output::type_system::meta;
use crate::output::type_system::meta::pattern::Pattern;

/// A definition of a user-defined type class.
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Debug)]
pub struct Definition {
/// Unique number within the tree that can be used to refer to this
/// extension when exporting in protobuf form.
pub extension_id: u64,
/// Identifier for the extension.
pub identifier: extension::simple::common::Identifier,

/// Description of the type class.
pub description: String,
/// Common metadata for the extension.
pub metadata: extension::simple::common::Metadata,

/// The parameters expected by the data type.
pub parameter_slots: Vec<ParameterSlot>,
Expand All @@ -32,8 +31,21 @@ pub struct Definition {
pub structure: Option<meta::pattern::Value>,
}

impl From<extension::simple::common::Identifier> for Definition {
fn from(identifier: extension::simple::common::Identifier) -> Self {
Definition {
identifier,
metadata: Default::default(),
parameter_slots: Default::default(),
parameters_variadic: Default::default(),
contraints: Default::default(),
structure: Default::default(),
}
}
}

/// A parameter slot for a user-defined data type.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, Default)]
pub struct ParameterSlot {
/// Name of the parameter.
pub name: String,
Expand Down
10 changes: 6 additions & 4 deletions rs/src/output/extension/simple/type_variation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use crate::output::extension;
use crate::output::type_system::data;

/// Type variation extension.
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Debug)]
pub struct Definition {
/// Unique number within the tree that can be used to refer to this
/// extension when exporting in protobuf form.
pub extension_id: u64,
/// Identifier for the extension.
pub identifier: extension::simple::common::Identifier,

/// Common metadata for the extension.
pub metadata: extension::simple::common::Metadata,

/// Description of the type variation.
pub description: String,
Expand Down
1 change: 1 addition & 0 deletions rs/src/parse/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ impl<'a> Context<'a> {
uri: Default::default(),
names: Default::default(),
extension_id: self.state.extension_id_counter,
definition_path: self.path_buf(),
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions rs/src/parse/extensions/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ fn parse_extension_mapping_data(
extension::namespace::ResolutionResult::new(reference_data)
});

// Link to YAML definitions.
resolution_result.for_each_visible_item(|item| {
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
});

// If the specified anchor is valid, insert a mapping for it.
if let Some(anchor) = anchor {
if let Err((prev_data, prev_path)) = y.define_type(anchor, resolution_result) {
Expand Down Expand Up @@ -300,6 +305,11 @@ fn parse_extension_mapping_data(
extension::namespace::ResolutionResult::new(reference_data)
});

// Link to YAML definitions.
resolution_result.for_each_visible_item(|item| {
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
});

// If the specified anchor is valid, insert a mapping for it.
if let Some(anchor) = anchor {
if let Err((prev_data, prev_path)) = y.define_type_variation(anchor, resolution_result) {
Expand Down Expand Up @@ -367,6 +377,11 @@ fn parse_extension_mapping_data(
extension::namespace::ResolutionResult::new(reference_data)
});

// Link to YAML definitions.
resolution_result.for_each_visible_item(|item| {
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
});

// If the specified anchor is valid, insert a mapping for it.
if let Some(anchor) = anchor {
if let Err((prev_data, prev_path)) = y.define_function(anchor, resolution_result) {
Expand Down
73 changes: 65 additions & 8 deletions rs/src/parse/extensions/simple/type_classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use crate::parse::context;
use crate::parse::extensions::simple::common;
use crate::parse::extensions::simple::derivations;
use crate::parse::extensions::simple::modules;
use crate::util;
use std::collections::HashSet;
use std::fmt::Write;
use std::sync::Arc;

/// Builder for type classes.
Expand Down Expand Up @@ -286,11 +288,6 @@ pub fn parse_type_class(
y: &mut context::Context,
z: &mut modules::Builder,
) -> Result<()> {
let mut builder = Builder {
definition: Default::default(),
analysis_context: derivations::AnalysisContext::new(Some(z)),
};

// Parse name.
let name = yaml_required_field!(
x,
Expand All @@ -307,6 +304,17 @@ pub fn parse_type_class(
.expect_not_yet_defined(y);
}

// Make identifier and builder.
let mut identifier = y.make_extension_id();
if let Some(name) = &name {
identifier.names.push(name.to_string());
}
identifier.uri = z.identifier.uri.clone();
let mut builder = Builder {
definition: identifier.into(),
analysis_context: derivations::AnalysisContext::new(Some(z)),
};

// Parse parameters.
builder.definition.parameter_slots =
yaml_repeated_field!(x, y, "parameters", parse_parameter, 0, &mut builder)?
Expand All @@ -333,14 +341,63 @@ pub fn parse_type_class(
// Parse structure.
yaml_field!(x, y, "structure", parse_structure, &mut builder)?;

// Describe the type class.
let mut description = if builder.definition.structure.is_none() {
if builder.definition.parameter_slots.is_empty() {
"Opaque simple"
} else {
"Opaque compound"
}
} else if builder.definition.parameter_slots.is_empty() {
"Simple"
} else {
"Compound"
}
.to_string();
write!(description, " type class declaration: ").unwrap();
if let Some(name) = &name {
write!(description, "{name}").unwrap();
} else {
write!(description, "!").unwrap();
}
if !builder.definition.parameter_slots.is_empty() {
let mut parameters = builder
.definition
.parameter_slots
.iter()
.map(|slot| {
let mut description = String::new();
if !slot.name.is_empty() {
write!(
description,
"{}: ",
util::string::as_ident_or_string(&slot.name)
)
.unwrap();
};
if slot.optional {
write!(description, "opt ").unwrap();
};
if let meta::pattern::Value::Intersection(isec) = &slot.pattern {
write!(description, "{}", isec.last().unwrap()).unwrap();
} else {
write!(description, "{}", slot.pattern).unwrap();
};
description
})
.join(", ");
if builder.definition.parameters_variadic {
write!(parameters, "...").unwrap();
}
write!(description, "<{parameters}>").unwrap();
}
describe!(y, Misc, "{description}");

// Register the type class.
if let Some(name) = name {
z.type_classes
.define_item(name, Arc::new(builder.definition), true);
}

// Describe the type class.
// TODO

Ok(())
}
35 changes: 35 additions & 0 deletions tests/tests/extensions/simple/type_class/core_yamls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: core-type-extensions
plan:
__test:
- level: i
extensionUris:
- extensionUriAnchor: 1
uri: /extension_types.yaml
extensions:
- extensionType:
extensionUriReference: 1
typeAnchor: 1
name: point
- extensionType:
extensionUriReference: 1
typeAnchor: 2
name: line
relations:
- rel:
read:
common:
direct: {}
baseSchema:
names: [x, y]
struct:
nullability: NULLABILITY_REQUIRED
types:
- user_defined:
typeReference: 1
nullability: NULLABILITY_REQUIRED
- user_defined:
typeReference: 2
nullability: NULLABILITY_REQUIRED
namedTable:
names: ["test"]
__test: [ type: "NSTRUCT<x: /extension_types.yaml::point, y: /extension_types.yaml::line>" ]

0 comments on commit 0f15619

Please sign in to comment.