src/vs/platform/contextkey/common/contextkey.ts/implies
export function implies(p: ContextKeyExpression, q: ContextKeyExpression): boolean {

	if (q.type === ContextKeyExprType.And && (p.type !== ContextKeyExprType.Or && p.type !== ContextKeyExprType.And)) {
		// covers the case: A implies A && B
		for (const qTerm of q.expr) {
			if (p.equals(qTerm)) {
				return true;
			}
		}
	}

	const notP = p.negate();
	const expr = getTerminals(notP).concat(getTerminals(q));
	expr.sort(cmp);

	for (let i = 0; i < expr.length; i++) {
		const a = expr[i];
		const notA = a.negate();
		for (let j = i + 1; j < expr.length; j++) {
			const b = expr[j];
			if (notA.equals(b)) {
				return true;
			}
		}
	}

	return false;
}