Add a position-independent digest of the AST (#2962)
Each AST node contains an Option<Digest> which can be optionally set by running compute_digest() over the AST. This will mutate the AST and set the Digest. Fundamentally, the digest is computed from the digest of AST children nodes (using compute_digest) or the explicit raw underlying value. The underlying hash is changeable by modifying the macro and Digest type alias, and should enable us to determine when an AST -- or fragment of AST -- is the same. This won't hash the start/end of the AST fragment, so it's, to some extent, position independent. It will hash newlines, comments, etc, which may change in the future depending on how we wind up using this.
This commit is contained in:
@ -22,17 +22,22 @@ fn basic() {
|
||||
start: 6,
|
||||
end: 7,
|
||||
name: "y".to_owned(),
|
||||
digest: None,
|
||||
},
|
||||
init: Value::Literal(Box::new(Literal {
|
||||
start: 10,
|
||||
end: 11,
|
||||
value: LiteralValue::IInteger(4),
|
||||
raw: "4".to_owned(),
|
||||
digest: None,
|
||||
})),
|
||||
digest: None,
|
||||
}],
|
||||
kind: VariableKind::Const,
|
||||
digest: None,
|
||||
})],
|
||||
non_code_meta: NonCodeMeta::default(),
|
||||
digest: None,
|
||||
};
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
Reference in New Issue
Block a user