mirror of
https://github.com/nix-community/noogle.git
synced 2024-10-26 10:28:06 +03:00
fix traceVal aliases and likewise aliases
This commit is contained in:
parent
af1e30100d
commit
50e35a47eb
@ -23,6 +23,7 @@ use crate::pasta::{AliasList, Docs, ValuePath};
|
|||||||
/// Match Non-Primop
|
/// Match Non-Primop
|
||||||
/// Eq position
|
/// Eq position
|
||||||
pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList {
|
pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList {
|
||||||
|
// dbg!("finding alias for", &item.path);
|
||||||
let res: AliasList = list
|
let res: AliasList = list
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|other| {
|
.filter_map(|other| {
|
||||||
@ -31,8 +32,13 @@ pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList {
|
|||||||
if item.path == other.path {
|
if item.path == other.path {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
// Both functions MUST have the same source position.
|
||||||
|
// Otherwise they CANNOT be a real alias.
|
||||||
|
if s_meta.position != o_meta.position {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
return match (o_meta.isPrimop, s_meta.isPrimop) {
|
return match (o_meta.isPrimop, s_meta.isPrimop) {
|
||||||
|
// Both PrimOp
|
||||||
(true, true) => {
|
(true, true) => {
|
||||||
let is_empty = match &s_meta.content {
|
let is_empty = match &s_meta.content {
|
||||||
Some(c) => c.is_empty(),
|
Some(c) => c.is_empty(),
|
||||||
@ -53,18 +59,25 @@ pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
// Both None PrimOp
|
||||||
(false, false) => {
|
(false, false) => {
|
||||||
|
// Both functions may be an alias only if at least one of them is not partially applied
|
||||||
|
if s_meta.countApplied == Some(0) || o_meta.countApplied == Some(0) {
|
||||||
|
return Some(other.path.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last resort try to find all functions with:
|
||||||
|
// - same source position
|
||||||
|
// - same isPrimop
|
||||||
|
// - same name
|
||||||
|
// It is very likely a real alias
|
||||||
if s_meta.countApplied != Some(0) {
|
if s_meta.countApplied != Some(0) {
|
||||||
if item.path.last() == other.path.last() {
|
if item.path.last() == other.path.last() {
|
||||||
|
// dbg!("ADDING Fallback ALIAS", &item.path);
|
||||||
return Some(other.path.clone());
|
return Some(other.path.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s_meta.position == o_meta.position
|
|
||||||
&& (s_meta.countApplied == Some(0) || o_meta.countApplied == Some(0))
|
|
||||||
{
|
|
||||||
return Some(other.path.clone());
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -81,6 +94,10 @@ pub struct FnCategories<'a> {
|
|||||||
pub casual: Vec<&'a Docs>,
|
pub casual: Vec<&'a Docs>,
|
||||||
pub partial: Vec<&'a Docs>,
|
pub partial: Vec<&'a Docs>,
|
||||||
}
|
}
|
||||||
|
/// TODO: Migrate to use a HashMap<SourcePosition, Vec<&Docs>>
|
||||||
|
/// Alias can only ever exist if they share the same lambda source position.
|
||||||
|
/// False positives can be filtered by using "findAlias" function
|
||||||
|
///
|
||||||
/// Build categories for efficiently finding aliases. (This is very expensive O(n^2). )
|
/// Build categories for efficiently finding aliases. (This is very expensive O(n^2). )
|
||||||
/// Aliases can only exist within one subgroup, iterating over other items is a waste of time.
|
/// Aliases can only exist within one subgroup, iterating over other items is a waste of time.
|
||||||
/// With the current value introspection, any value that is an alias of a builtin, also inherits the builtins docs and the isPrimop flag set.
|
/// With the current value introspection, any value that is an alias of a builtin, also inherits the builtins docs and the isPrimop flag set.
|
||||||
|
36
pesto/test_data/aliases/traceVal.expect
Normal file
36
pesto/test_data/aliases/traceVal.expect
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"aliases": [
|
||||||
|
[
|
||||||
|
"lib",
|
||||||
|
"debug",
|
||||||
|
"traceVal"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"lib",
|
||||||
|
"traceVal"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"aliases": [
|
||||||
|
[
|
||||||
|
"lib",
|
||||||
|
"traceVal"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"lib",
|
||||||
|
"debug",
|
||||||
|
"traceVal"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"aliases": [],
|
||||||
|
"path": [
|
||||||
|
"lib",
|
||||||
|
"fileset",
|
||||||
|
"traceVal"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
62
pesto/test_data/aliases/traceVal.json
Normal file
62
pesto/test_data/aliases/traceVal.json
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"docs": {
|
||||||
|
"attr": {
|
||||||
|
"position": {
|
||||||
|
"column": 25,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/default.nix",
|
||||||
|
"line": 153
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lambda": {
|
||||||
|
"isPrimop": false,
|
||||||
|
"position": {
|
||||||
|
"column": 5,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/debug.nix",
|
||||||
|
"line": 95
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"path": ["lib", "traceVal"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"docs": {
|
||||||
|
"attr": {
|
||||||
|
"position": {
|
||||||
|
"column": 3,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/debug.nix",
|
||||||
|
"line": 114
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lambda": {
|
||||||
|
"isPrimop": false,
|
||||||
|
"position": {
|
||||||
|
"column": 5,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/debug.nix",
|
||||||
|
"line": 95
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"path": ["lib", "debug", "traceVal"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"docs": {
|
||||||
|
"attr": {
|
||||||
|
"position": {
|
||||||
|
"column": 3,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/fileset/default.nix",
|
||||||
|
"line": 666
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lambda": {
|
||||||
|
"isPrimop": false,
|
||||||
|
"position": {
|
||||||
|
"column": 5,
|
||||||
|
"file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/fileset/default.nix",
|
||||||
|
"line": 672
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"path": ["lib", "fileset", "traceVal"]
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user