Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: codeframe report #123

Merged
merged 23 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
562b92d
docs: add d2 diagrams
effervescentia Jul 26, 2024
8ee0b58
chore: cleanup
effervescentia Jul 26, 2024
cd1a655
feat: break up error definition
effervescentia Jul 29, 2024
44ed681
feat: engine errors working
effervescentia Jul 29, 2024
090e8f5
refactor: cleanup imports
effervescentia Jul 29, 2024
16bf333
feat: command layer working with new errors
effervescentia Jul 29, 2024
97212f5
feat: working error report
effervescentia Jul 30, 2024
a44c2ee
refactor: rename to assertions
effervescentia Jul 30, 2024
5ee1f6a
fix: working reporter logic
effervescentia Jul 30, 2024
736afc2
fix: working report container
effervescentia Aug 1, 2024
d98087a
refactor: rename build_with to fail
effervescentia Aug 1, 2024
355f141
feat: enrich error reports
effervescentia Aug 2, 2024
64a6efa
feat: mostly working codeframe
effervescentia Aug 8, 2024
902ab2c
fix: working codeframe ranges
effervescentia Aug 12, 2024
4e5d581
refactor: better code frames
effervescentia Aug 13, 2024
ada3a13
feat: really nice NotFound error details
effervescentia Aug 14, 2024
467f641
feat: dual target code frame (temporary)
effervescentia Aug 14, 2024
6651278
feat: improve more error reports
effervescentia Aug 15, 2024
ad5f9df
feat: more detailed error reports
effervescentia Aug 16, 2024
b2cd128
test: fix all unit tests
effervescentia Aug 19, 2024
6a7c939
test: re-use examples for analysis tests
effervescentia Aug 20, 2024
91ecf60
ci: update rust version for github workflow
effervescentia Aug 20, 2024
3ef5fed
test: fix test environment differences
effervescentia Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/[email protected]
with:
toolchain: "1.72.1"
toolchain: "1.80.1"
- run: cargo test

# # Check formatting with rustfmt
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
"clippy::verbose_file_reads",
],
"cSpell.words": [
"kore"
"kore",
"renderable",
"stdext"
],
}
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions analyze/docs/architecture.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
semantic_analysis: Semantic Analysis
semantic_analysis.shape: oval

input: Input {
raw: Raw AST
context: Context
}

output: Output {
typed: Typed AST
types: Types
}

infer: Type Inference {
infer_weak: Weak Inference
infer_weak.shape: oval
infer_strong: Strong Inference
infer_strong.shape: oval
weak_output: Weak Output
strong_output: Strong Output

into_typed: Resolve Types
into_typed.shape: oval
canonicalize: Canonicalize
canonicalize.shape: oval

infer_weak -> weak_output
weak_output -> infer_strong
infer_strong -> infer_strong: incremental
infer_strong -> strong_output
strong_output -> into_typed
strong_output -> canonicalize
}

input.raw -> infer.infer_weak
input.raw -> infer.into_typed
input.context -> infer.infer_strong
input.context -> infer.into_typed
input.context -> infer.canonicalize
infer.into_typed -> output.typed
infer.canonicalize -> output.types
output.typed -> semantic_analysis
102 changes: 82 additions & 20 deletions analyze/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use lang::{ast, types::Kind, CanonicalId};
use lang::{
ast,
types::{self, Kind},
CanonicalId,
};

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Error {
/* inference */
NotInferrable(
Expand All @@ -17,6 +21,8 @@ pub enum Error {
VariantNotFound(
// id of the enum declaration
CanonicalId,
// names of the valid variants
Vec<String>,
// name of the expected variant
String,
),
Expand All @@ -25,6 +31,8 @@ pub enum Error {
DeclarationNotFound(
// id of the enum declaration
CanonicalId,
// names of the valid declarations
Vec<String>,
// name of the expected declaration
String,
),
Expand All @@ -40,6 +48,8 @@ pub enum Error {
PropertyNotFound(
// id of the object
CanonicalId,
// names of the valid properties
Vec<String>,
// name of the expected property
String,
),
Expand All @@ -56,11 +66,21 @@ pub enum Error {

/* callable-related */
/// temporary solution until deeper type inference is implemented
UntypedParameter,
UntypedParameter(String),

DefaultValueRejected(
// id of the default value
CanonicalId,
(
// id of the type definition
CanonicalId,
// the type of the parameter
types::Shape,
),
(
// id of the default value
CanonicalId,
// the type of the default value
types::Shape,
),
),

/* function-related */
Expand All @@ -72,18 +92,30 @@ pub enum Error {
UnexpectedArgument(
// id of the argument
CanonicalId,
// number of arguments expected
usize,
),

MissingArgument(
// id of the unfulfilled parameter
CanonicalId,
// the type of the parameter
types::Shape,
),

ArgumentRejected(
// id of the parameter
CanonicalId,
// id of the argument
CanonicalId,
(
// id of the parameter
CanonicalId,
// the type of the parameter
types::Shape,
),
(
// id of the argument
CanonicalId,
// the type of the argument
types::Shape,
),
),

/* component-related */
Expand All @@ -95,6 +127,8 @@ pub enum Error {
InvalidComponent(
// tag name
String,
// the type of the value
types::Shape,
),

ComponentTypo(
Expand All @@ -110,37 +144,65 @@ pub enum Error {
),

UnexpectedAttribute(
// id of the unexpected attribute
CanonicalId,
// name of the attribute
String,
),

MissingAttribute(
// id of the unfulfilled parameter
// id of the unfulfilled attribute
CanonicalId,
// name of the attribute
String,
// the type of the attribute
types::Shape,
),

AttributeRejected(
// id of the parameter
CanonicalId,
// id of the argument
CanonicalId,
(
// id of the parameter
CanonicalId,
// name of the attribute
String,
// the type of the parameter
types::Shape,
),
(
// id of the argument
CanonicalId,
// the type of the argument
types::Shape,
),
),

/* mismatch */
BinaryOperationNotSupported(
// operation being performed
ast::BinaryOperator,
// id of the left-hand side
CanonicalId,
// id of the right-hand side
CanonicalId,
(
// id of the left-hand side
CanonicalId,
// the type of the left-hand side
Option<types::Shape>,
),
(
// id of the right-hand side
CanonicalId,
// the type of the right-hand side
Option<types::Shape>,
),
),

UnaryOperationNotSupported(
// operation being performed
ast::UnaryOperator,
// id of the right-hand side
CanonicalId,
(
// id of the right-hand side
CanonicalId,
// the type of the right-hand side
Option<types::Shape>,
),
),

UnexpectedKind(
Expand Down
6 changes: 4 additions & 2 deletions analyze/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
AmbientScope, TypeMap as StrongTypes,
};
use kore::str;
pub use lang::test::fixture::*;
use lang::{
ast,
types::{Enumerated, Kind, Type},
Expand Down Expand Up @@ -170,7 +169,10 @@ pub mod function {
HashMap::from_iter(vec![
(
NodeId(0),
(Kind::Value, weak::Type::Infer(Inference::Parameter)),
(
Kind::Value,
weak::Type::Infer(Inference::Parameter(str!("first"))),
),
),
(NodeId(1), (Kind::Type, weak::Type::Value(Type::Integer))),
(
Expand Down
10 changes: 7 additions & 3 deletions analyze/src/infer/strong/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub fn infer(state: &State, op: ast::BinaryOperator, lhs: CanonicalId, rhs: Cano
(Some(Err(_)), _) => Action::Raise(Error::NotInferrable(vec![lhs])),
(_, Some(Err(_))) => Action::Raise(Error::NotInferrable(vec![rhs])),

(Some(_), Some(_)) => Action::Raise(Error::BinaryOperationNotSupported(op, lhs, rhs)),
(Some(_), Some(_)) => Action::Raise(Error::BinaryOperationNotSupported(
op,
(lhs, None),
(rhs, None),
)),
}
}

Expand Down Expand Up @@ -133,8 +137,8 @@ mod tests {
super::infer(&state, OP, CanonicalId::mock(1), CanonicalId::mock(1)),
Action::Raise(Error::BinaryOperationNotSupported(
OP,
CanonicalId::mock(1),
CanonicalId::mock(1)
(CanonicalId::mock(1), None),
(CanonicalId::mock(1), None)
))
);
}
Expand Down
4 changes: 2 additions & 2 deletions analyze/src/infer/strong/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const FRAGMENTS: &BTreeMap<NodeId, (ScopeId, Fragment)> = &BTreeMap::new();

impl<'a> State<'a> {
#[allow(clippy::type_complexity)]
pub fn mock(context: &'a Context) -> State<'a> {
pub fn mock(context: &'a Context) -> Self {
State {
context,
fragments: FRAGMENTS,
Expand All @@ -22,7 +22,7 @@ impl<'a> State<'a> {
pub fn from_types(
context: &'a Context,
types: Vec<(NodeId, (Kind, Result<Type, Error>))>,
) -> State<'a> {
) -> Self {
State {
types: BTreeMap::from_iter(types),
..Self::mock(context)
Expand Down
4 changes: 2 additions & 2 deletions analyze/src/infer/strong/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ pub fn infer_types<'a>(ctx: &Context, prev: State<'a>) -> State<'a> {
} => import::infer(ctx, source, path),

NodeDescriptor {
weak: weak::Type::Infer(Inference::Parameter),
weak: weak::Type::Infer(Inference::Parameter(name)),
..
} => {
// TODO: replace this with actual type inference
Action::Raise(Error::UntypedParameter)
Action::Raise(Error::UntypedParameter(name.to_owned()))
}
};

Expand Down
Loading