* The value every call of `method` passes `parameter`, or why there is none. * `path` holds the parameters being followed: a call passing one of them on * adds nothing, as a walk over a tree passes its own `context` to itself, so * only the calls from outside the cycle decide. `through` col
(method: FlowMethod, parameter: FlowParameter, path: string[], through: Set<string>)
| 312 | * names the answer rests on. |
| 313 | */ |
| 314 | private flow(method: FlowMethod, parameter: FlowParameter, path: string[], through: Set<string>): FlowValue | Abstention { |
| 315 | const name = method.name; |
| 316 | if (this.writtenElsewhere.has(name)) return WRITTEN_ELSEWHERE; |
| 317 | const signature = this.adapter.signature(method); |
| 318 | if (!signature) return UNREAD_DECLARATION; |
| 319 | if (this.adapter.rebinds(parameter.name, method)) return REBOUND; |
| 320 | const here = [...path, `${method.id}\0${parameter.name}`]; |
| 321 | let value: FlowValue | null = null; |
| 322 | const passedBy = (site: FlowSite): Abstention | null => { |
| 323 | const passed = this.adapter.argumentValue(site, parameter, (m, p) => { |
| 324 | if (here.includes(`${m.id}\0${p.name}`)) return CYCLE; |
| 325 | if (here.length >= MAX_FLOW_DEPTH) return TOO_DEEP; |
| 326 | return this.flow(m, p, here, through); |
| 327 | }); |
| 328 | if (passed === CYCLE) return null; |
| 329 | if (!isFlowValue(passed)) return passed; |
| 330 | if (value && (value.type !== passed.type || value.isClass !== passed.isClass)) return DISAGREE; |
| 331 | value = passed; |
| 332 | return null; |
| 333 | }; |
| 334 | // The calls of this very method first: most flows end at their first argument. |
| 335 | for (const site of this.callsInto(method)) { |
| 336 | if (!this.adapter.isKnown(site)) continue; |
| 337 | const stop = passedBy(site); |
| 338 | if (stop !== null) return stop; |
| 339 | } |
| 340 | if (!value) return NO_CALLER; |
| 341 | // Counted together: an answer a flow gave, which a sync finds as an edge, |
| 342 | // is a failed call in a fresh index, and the two have to agree. |
| 343 | const { known, unknown, failed } = this.callsNamed(name); |
| 344 | if (unknown.length + failed.length > MAX_UNKNOWN_CALLS) return TOO_MANY_CALLS; |
| 345 | for (const site of unknown) { |
| 346 | if (!this.adapter.cannotCall(site, signature)) return UNTYPED_CALL; |
| 347 | } |
| 348 | for (const site of failed) { |
| 349 | if (!this.adapter.cannotCall(site, signature)) return UNTYPED_CALL; |
| 350 | } |
| 351 | if (this.handsOn(name)) return HANDED_ON; |
| 352 | const others = known.filter((site) => site.targetId !== method.id); |
| 353 | if (others.length > 0) { |
| 354 | const family = this.family(method); |
| 355 | for (const site of others) { |
| 356 | if (!family.has(site.targetId!)) continue; |
| 357 | const stop = passedBy(site); |
| 358 | if (stop !== null) return stop; |
| 359 | } |
| 360 | } |
| 361 | through.add(name); |
| 362 | return value; |
| 363 | } |
| 364 | |
| 365 | /** The names of the calls `method` makes that may pass a parameter of its on. */ |
| 366 | private callsPassingOn(method: FlowMethod): string[] { |
no test coverage detected