@@ -1755,17 +1755,26 @@ function initSearch(rawSearchIndex) {
1755
1755
if ( mgens && mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1756
1756
return false ;
1757
1757
}
1758
+ // Where clauses can represent cyclical data.
1759
+ // `null` prevents it from trying to unbox in an infinite loop
1760
+ const mgensTmp = new Map ( mgens ) ;
1761
+ mgensTmp . set ( fnType . id , null ) ;
1758
1762
// This is only a potential unbox if the search query appears in the where clause
1759
1763
// for example, searching `Read -> usize` should find
1760
1764
// `fn read_all<R: Read>(R) -> Result<usize>`
1761
1765
// generic `R` is considered "unboxed"
1762
- return checkIfInList ( whereClause [ ( - fnType . id ) - 1 ] , queryElem , whereClause ) ;
1766
+ return checkIfInList (
1767
+ whereClause [ ( - fnType . id ) - 1 ] ,
1768
+ queryElem ,
1769
+ whereClause ,
1770
+ mgensTmp
1771
+ ) ;
1763
1772
} else if ( fnType . generics . length > 0 || fnType . bindings . size > 0 ) {
1764
1773
const simplifiedGenerics = [
1765
1774
...fnType . generics ,
1766
1775
...Array . from ( fnType . bindings . values ( ) ) . flat ( ) ,
1767
1776
] ;
1768
- return checkIfInList ( simplifiedGenerics , queryElem , whereClause ) ;
1777
+ return checkIfInList ( simplifiedGenerics , queryElem , whereClause , mgens ) ;
1769
1778
}
1770
1779
return false ;
1771
1780
}
@@ -1777,12 +1786,13 @@ function initSearch(rawSearchIndex) {
1777
1786
* @param {Array<FunctionType> } list
1778
1787
* @param {QueryElement } elem - The element from the parsed query.
1779
1788
* @param {[FunctionType] } whereClause - Trait bounds for generic items.
1789
+ * @param {Map<number,number>|null } mgens - Map functions generics to query generics.
1780
1790
*
1781
1791
* @return {boolean } - Returns true if found, false otherwise.
1782
1792
*/
1783
- function checkIfInList ( list , elem , whereClause ) {
1793
+ function checkIfInList ( list , elem , whereClause , mgens ) {
1784
1794
for ( const entry of list ) {
1785
- if ( checkType ( entry , elem , whereClause ) ) {
1795
+ if ( checkType ( entry , elem , whereClause , mgens ) ) {
1786
1796
return true ;
1787
1797
}
1788
1798
}
@@ -1796,10 +1806,11 @@ function initSearch(rawSearchIndex) {
1796
1806
* @param {Row } row
1797
1807
* @param {QueryElement } elem - The element from the parsed query.
1798
1808
* @param {[FunctionType] } whereClause - Trait bounds for generic items.
1809
+ * @param {Map<number,number>|null } mgens - Map functions generics to query generics.
1799
1810
*
1800
1811
* @return {boolean } - Returns true if the type matches, false otherwise.
1801
1812
*/
1802
- function checkType ( row , elem , whereClause ) {
1813
+ function checkType ( row , elem , whereClause , mgens ) {
1803
1814
if ( row . bindings . size === 0 && elem . bindings . size === 0 ) {
1804
1815
if ( elem . id < 0 ) {
1805
1816
return row . id < 0 || checkIfInList ( row . generics , elem , whereClause ) ;
@@ -1812,7 +1823,7 @@ function initSearch(rawSearchIndex) {
1812
1823
return row . id === elem . id || checkIfInList ( row . generics , elem , whereClause ) ;
1813
1824
}
1814
1825
}
1815
- return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause ) ;
1826
+ return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause , mgens ) ;
1816
1827
}
1817
1828
1818
1829
function checkPath ( contains , ty , maxEditDistance ) {
0 commit comments