def inline_functions(dsk, output, fast_functions=None, inline_constants=False, dependencies=None):
    """Inline cheap functions into larger operations.

    Examples
    --------
    >>> from flash.core.serve.dag.utils_test import add, inc
    >>> double = lambda x: x*2
    >>> dsk = {'out': (add, 'i', 'd'),
    ...        'i': (inc, 'x'),
    ...        'd': (double, 'y'),
    ...        'x': 1, 'y': 1}
    >>> inline_functions(dsk, [], [inc])  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    {'x': 1,
     'out': (<function add at ...>, (<function inc at ...>, 'x'), 'd'),
     'd': (<function <lambda> at ...>, 'y'),
     'y': 1}

    Protect output keys.  In the example below ``i`` is not inlined because it
    is marked as an output key.

    >>> inline_functions(dsk, ['i', 'out'], [inc, double])  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    {'y': 1,
     'out': (<function add at ...>, 'i', (<function <lambda> at ...>, 'y')),
     'i': (<function inc at ...>, 'x'),
     'x': 1}

    """
    if not fast_functions:
        return dsk

    output = set(output)

    fast_functions = set(fast_functions)

    if dependencies is None:
        dependencies = {k: get_dependencies(dsk, k) for k in dsk}
    dependents = reverse_dict(dependencies)

    def inlinable(v):
        try:
            return functions_of(v).issubset(fast_functions)
        except TypeError:
            return False

    keys = [k for k, v in dsk.items() if istask(v) and dependents[k] and k not in output and inlinable(v)]

    if keys:
        dsk = inline(dsk, keys, inline_constants=inline_constants, dependencies=dependencies)
        for k in keys:
            del dsk[k]
    return dsk
Inline cheap functions into larger operations.

    Examples
    --------
    >>> from flash.core.serve.dag.utils_test import add, inc
    >>> double = lambda x: x*2
    >>> dsk = {'out': (add, 'i', 'd'),
    ...        'i': (inc, 'x'),
    ...        'd': (double, 'y'),
    ...        'x': 1, 'y': 1}
    >>> inline_functions(dsk, [], [inc])  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    {'x': 1,
     'out': (<function add at ...>, (<function inc at ...>, 'x'), 'd'),
     'd': (<function <lambda> at ...>, 'y'),
     'y': 1}

    Protect output keys.  In the example below ``i`` is not inlined because it
    is marked as an output key.

    >>> inline_functions(dsk, ['i', 'out'], [inc, double])  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    {'y': 1,
     'out': (<function add at ...>, 'i', (<function <lambda> at ...>, 'y')),
     'i': (<function inc at ...>, 'x'),
     'x': 1}

    
src/flash/core/serve/dag/optimization.py