@@ -1329,9 +1329,9 @@ function initSearch(rawSearchIndex) {
13291329 */
13301330 function unifyFunctionTypes ( fnTypesIn , queryElems , whereClause , mgensIn , solutionCb ) {
13311331 /**
1332- * @type Map<integer, integer>
1332+ * @type Map<integer, integer>|null
13331333 */
1334- let mgens = new Map ( mgensIn ) ;
1334+ let mgens = mgensIn === null ? null : new Map ( mgensIn ) ;
13351335 if ( queryElems . length === 0 ) {
13361336 return ! solutionCb || solutionCb ( mgens ) ;
13371337 }
@@ -1382,12 +1382,14 @@ function initSearch(rawSearchIndex) {
13821382 fnTypesOffset,
13831383 unbox,
13841384 } = backtracking . pop ( ) ;
1385- mgens = new Map ( mgensScratch ) ;
1385+ mgens = mgensScratch !== null ? new Map ( mgensScratch ) : null ;
13861386 const fnType = fnTypesScratch [ fnTypesOffset ] ;
13871387 const queryElem = queryElems [ queryElemsOffset ] ;
13881388 if ( unbox ) {
13891389 if ( fnType . id < 0 ) {
1390- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1390+ if ( mgens === null ) {
1391+ mgens = new Map ( ) ;
1392+ } else if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
13911393 continue ;
13921394 }
13931395 mgens . set ( fnType . id , 0 ) ;
@@ -1401,7 +1403,9 @@ function initSearch(rawSearchIndex) {
14011403 i = queryElemsOffset - 1 ;
14021404 } else {
14031405 if ( fnType . id < 0 ) {
1404- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1406+ if ( mgens === null ) {
1407+ mgens = new Map ( ) ;
1408+ } else if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
14051409 continue ;
14061410 }
14071411 mgens . set ( fnType . id , queryElem . id ) ;
@@ -1456,7 +1460,7 @@ function initSearch(rawSearchIndex) {
14561460 if ( ! fnTypesScratch ) {
14571461 fnTypesScratch = fnTypes . slice ( ) ;
14581462 }
1459- if ( ! mgensScratch ) {
1463+ if ( ! mgensScratch && mgens !== null ) {
14601464 mgensScratch = new Map ( mgens ) ;
14611465 }
14621466 backtracking . push ( {
@@ -1478,10 +1482,19 @@ function initSearch(rawSearchIndex) {
14781482 // use the current candidate
14791483 const { fnTypesOffset : candidate , mgensScratch : mgensNew } = matchCandidates . pop ( ) ;
14801484 if ( fnTypes [ candidate ] . id < 0 && queryElems [ i ] . id < 0 ) {
1485+ if ( mgens === null ) {
1486+ mgens = new Map ( ) ;
1487+ }
14811488 mgens . set ( fnTypes [ candidate ] . id , queryElems [ i ] . id ) ;
14821489 }
1483- for ( const [ fid , qid ] of mgensNew ) {
1484- mgens . set ( fid , qid ) ;
1490+ if ( mgensNew !== null ) {
1491+ if ( mgens === null ) {
1492+ mgens = mgensNew ;
1493+ } else {
1494+ for ( const [ fid , qid ] of mgensNew ) {
1495+ mgens . set ( fid , qid ) ;
1496+ }
1497+ }
14851498 }
14861499 // `i` and `j` are paired off
14871500 // `queryElems[i]` is left in place
@@ -1514,15 +1527,17 @@ function initSearch(rawSearchIndex) {
15141527 // or, if mgens[fnType.id] = 0, then we've matched this generic with a bare trait
15151528 // and should make that same decision everywhere it appears
15161529 if ( fnType . id < 0 && queryElem . id < 0 ) {
1517- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1518- return false ;
1519- }
1520- for ( const [ fid , qid ] of mgens . entries ( ) ) {
1521- if ( fnType . id !== fid && queryElem . id === qid ) {
1530+ if ( mgens !== null ) {
1531+ if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
15221532 return false ;
15231533 }
1524- if ( fnType . id === fid && queryElem . id !== qid ) {
1525- return false ;
1534+ for ( const [ fid , qid ] of mgens . entries ( ) ) {
1535+ if ( fnType . id !== fid && queryElem . id === qid ) {
1536+ return false ;
1537+ }
1538+ if ( fnType . id === fid && queryElem . id !== qid ) {
1539+ return false ;
1540+ }
15261541 }
15271542 }
15281543 } else {
@@ -1575,7 +1590,7 @@ function initSearch(rawSearchIndex) {
15751590 }
15761591 // mgens[fnType.id] === 0 indicates that we committed to unboxing this generic
15771592 // mgens[fnType.id] === null indicates that we haven't decided yet
1578- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1593+ if ( mgens !== null && mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
15791594 return false ;
15801595 }
15811596 // This is only a potential unbox if the search query appears in the where clause
0 commit comments