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

Span unification #146

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/lib/ast/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ast::NodeId,
helpers::*,
infer::trait_solver::TraitSolver,
parser::span2::Span,
parser::span::Span,
resolver::ResolutionMap,
ty::{FuncType, Type},
};
Expand Down
13 changes: 5 additions & 8 deletions src/lib/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use crate::parser::Parser;
use crate::{diagnostics::DiagnosticType, parser::span::Span, parser::span2::Span as Span2};
use crate::{diagnostics::DiagnosticType, parser::span::Span};
use crate::{
hir::HirId,
parser::SourceFile,
Expand Down Expand Up @@ -287,8 +287,7 @@ impl Display for DiagnosticKind {

impl<'a> From<Parser<'a>> for Diagnostic {
fn from(err: Parser<'a>) -> Self {
let span2 = Span2::from(err);
let span = Span::from(span2);
let span = Span::from(err);

let msg = "Syntax error".to_string();

Expand All @@ -300,8 +299,7 @@ impl<'a> From<VerboseError<Parser<'a>>> for Diagnostic {
fn from(err: VerboseError<Parser<'a>>) -> Self {
let (input, _kind) = err.errors.iter().next().unwrap().clone();

let span2 = Span2::from(input);
let span = Span::from(span2);
let span = Span::from(input);

let msg = err.to_string();

Expand All @@ -311,11 +309,10 @@ impl<'a> From<VerboseError<Parser<'a>>> for Diagnostic {

impl<I> From<(I, VerboseErrorKind)> for Diagnostic
where
Span2: From<I>,
Span: From<I>,
{
fn from((input, _kind): (I, VerboseErrorKind)) -> Self {
let span2 = Span2::from(input);
let span = Span::from(span2);
let span = Span::from(input);

let msg = "Syntax error".to_string();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/hir/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
ast_lowering::HirMap,
hir::hir_id::*,
infer::{trait_solver::TraitSolver, Envs},
parser::span2::Span,
parser::span::Span,
resolver::ResolutionMap,
ty::{FuncType, StructType, Type},
};
Expand Down
5 changes: 2 additions & 3 deletions src/lib/infer/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
hir::visit::*,
hir::*,
infer::Envs,
parser::Span,
resolver::ResolutionMap,
ty::{FuncType, PrimitiveType, Type},
};
Expand Down Expand Up @@ -114,7 +113,7 @@ impl<'a> ConstraintContext<'a> {
self.envs
.spans
.get(&call_hir_id.clone())
.unwrap_or(&Span::default())
.unwrap()
.clone()
.into(),
call_hir_id.clone(),
Expand Down Expand Up @@ -187,7 +186,7 @@ impl<'a> ConstraintContext<'a> {
self.envs
.spans
.get(&fc.op.get_hir_id())
.unwrap_or(&Span::default())
.unwrap()
.clone()
.into(),
fc.to_func_type(self.envs.get_current_env().unwrap()).into(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/infer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap};
use crate::{
diagnostics::{Diagnostic, Diagnostics},
hir::*,
parser::span2::Span,
parser::span::Span,
ty::*,
};

Expand Down
6 changes: 3 additions & 3 deletions src/lib/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ pub mod default_impl_populator;
pub mod parsing_context;
pub mod source_file;
pub mod span;
pub mod span2;

pub use parsing_context::ParsingCtx;
pub use source_file::SourceFile;
pub use span::Span as OldSpan;
pub use span2::Span;
pub use span::Span;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -1359,5 +1357,7 @@ pub fn parse(parsing_ctx: &mut ParsingCtx) -> Result<tree::Root, Diagnostic> {

parsing_ctx.return_if_error()?;

println!("ast {:#?}", ast);

Ok(ast)
}
11 changes: 6 additions & 5 deletions src/lib/parser/parsing_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use colored::*;
use crate::{
ast::{Identifier, NodeId},
diagnostics::{Diagnostic, DiagnosticType, Diagnostics},
parser::span2::Span,
parser::span::Span,
Config,
};

Expand Down Expand Up @@ -127,11 +127,11 @@ impl ParsingCtx {
Ok(())
}

pub fn new_span(&self, start: usize, _end: usize) -> Span {
pub fn new_span(&self, start: usize, end: usize) -> Span {
Span {
file_path: self.get_current_file().file_path,
offset: start,
..Default::default()
start,
end,
}
}

Expand All @@ -143,7 +143,8 @@ impl ParsingCtx {
Diagnostic::new_module_not_found(
Span {
file_path: current_file.file_path.clone(),
..Default::default()
start: 0,
end: 0,
}
.into(),
m,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/parser/span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::span2::Span as Span2;
use crate::parser::Parser;
use std::path::PathBuf;

#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -26,12 +26,12 @@ impl Span {
}
}

impl From<Span2> for Span {
fn from(span: Span2) -> Self {
impl<'a> From<Parser<'a>> for Span {
fn from(source: Parser<'a>) -> Self {
Self {
start: span.offset,
end: span.txt.len() + span.offset,
file_path: span.file_path,
start: source.location_offset(),
end: source.to_string().len() + source.location_offset(),
file_path: source.extra.current_file_path().clone(),
}
}
}
26 changes: 0 additions & 26 deletions src/lib/parser/span2.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/resolver/resolve_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
diagnostics::Diagnostic,
helpers::scopes::*,
infer::trait_solver::TraitSolver,
parser::span2::Span as Span2,
parser::span::Span,
parser::ParsingCtx,
resolver::ResolutionMap,
};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> ResolveCtx<'a> {
}
}

pub fn get_span2(&self, node_id: NodeId) -> Span2 {
pub fn get_span2(&self, node_id: NodeId) -> Span {
self.parsing_ctx.identities.get(&node_id).unwrap().clone()
}
}
Expand Down