|
|
|
|
@ -1,10 +1,9 @@
|
|
|
|
|
//! A graph representation for computing tree diffs.
|
|
|
|
|
|
|
|
|
|
use bumpalo::Bump;
|
|
|
|
|
use rpds::Stack;
|
|
|
|
|
use rustc_hash::FxHashMap;
|
|
|
|
|
use std::{
|
|
|
|
|
cell::RefCell,
|
|
|
|
|
cell::{Cell, RefCell},
|
|
|
|
|
cmp::min,
|
|
|
|
|
fmt,
|
|
|
|
|
hash::{Hash, Hasher},
|
|
|
|
|
@ -12,7 +11,10 @@ use std::{
|
|
|
|
|
use strsim::normalized_levenshtein;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
diff::changes::{insert_deep_unchanged, ChangeKind, ChangeMap},
|
|
|
|
|
diff::{
|
|
|
|
|
changes::{insert_deep_unchanged, ChangeKind, ChangeMap},
|
|
|
|
|
stack::Stack,
|
|
|
|
|
},
|
|
|
|
|
parse::syntax::{AtomKind, Syntax, SyntaxId},
|
|
|
|
|
};
|
|
|
|
|
use Edge::*;
|
|
|
|
|
@ -48,7 +50,7 @@ use Edge::*;
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Vertex<'a, 'b> {
|
|
|
|
|
pub neighbours: RefCell<Option<Vec<(Edge, &'b Vertex<'a, 'b>)>>>,
|
|
|
|
|
pub predecessor: RefCell<Option<(u64, &'b Vertex<'a, 'b>)>>,
|
|
|
|
|
pub predecessor: Cell<Option<(u64, &'b Vertex<'a, 'b>)>>,
|
|
|
|
|
pub lhs_syntax: Option<&'a Syntax<'a>>,
|
|
|
|
|
pub rhs_syntax: Option<&'a Syntax<'a>>,
|
|
|
|
|
parents: Stack<EnteredDelimiter<'a>>,
|
|
|
|
|
@ -258,7 +260,7 @@ impl<'a, 'b> Vertex<'a, 'b> {
|
|
|
|
|
let parents = Stack::new();
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax,
|
|
|
|
|
rhs_syntax,
|
|
|
|
|
parents,
|
|
|
|
|
@ -442,7 +444,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_parent.next_sibling(),
|
|
|
|
|
rhs_syntax: rhs_parent.next_sibling(),
|
|
|
|
|
can_pop_either: can_pop_either_parent(&parents_next),
|
|
|
|
|
@ -467,7 +469,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_parent.next_sibling(),
|
|
|
|
|
rhs_syntax: v.rhs_syntax,
|
|
|
|
|
can_pop_either: can_pop_either_parent(&parents_next),
|
|
|
|
|
@ -492,7 +494,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: v.lhs_syntax,
|
|
|
|
|
rhs_syntax: rhs_parent.next_sibling(),
|
|
|
|
|
can_pop_either: can_pop_either_parent(&parents_next),
|
|
|
|
|
@ -519,7 +521,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_syntax.next_sibling(),
|
|
|
|
|
rhs_syntax: rhs_syntax.next_sibling(),
|
|
|
|
|
parents: v.parents.clone(),
|
|
|
|
|
@ -565,7 +567,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_next,
|
|
|
|
|
rhs_syntax: rhs_next,
|
|
|
|
|
parents: parents_next,
|
|
|
|
|
@ -603,7 +605,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_syntax.next_sibling(),
|
|
|
|
|
rhs_syntax: rhs_syntax.next_sibling(),
|
|
|
|
|
parents: v.parents.clone(),
|
|
|
|
|
@ -633,7 +635,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_syntax.next_sibling(),
|
|
|
|
|
rhs_syntax: v.rhs_syntax,
|
|
|
|
|
parents: v.parents.clone(),
|
|
|
|
|
@ -659,7 +661,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: lhs_next,
|
|
|
|
|
rhs_syntax: v.rhs_syntax,
|
|
|
|
|
parents: parents_next,
|
|
|
|
|
@ -687,7 +689,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: v.lhs_syntax,
|
|
|
|
|
rhs_syntax: rhs_syntax.next_sibling(),
|
|
|
|
|
parents: v.parents.clone(),
|
|
|
|
|
@ -713,7 +715,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
allocate_if_new(
|
|
|
|
|
Vertex {
|
|
|
|
|
neighbours: RefCell::new(None),
|
|
|
|
|
predecessor: RefCell::new(None),
|
|
|
|
|
predecessor: Cell::new(None),
|
|
|
|
|
lhs_syntax: v.lhs_syntax,
|
|
|
|
|
rhs_syntax: rhs_next,
|
|
|
|
|
parents: parents_next,
|
|
|
|
|
@ -729,7 +731,7 @@ pub fn get_set_neighbours<'syn, 'b>(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(
|
|
|
|
|
res.len() > 0,
|
|
|
|
|
!res.is_empty(),
|
|
|
|
|
"Must always find some next steps if node is not the end"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|