(exc_path: str)
We are doing the stupidest thing possible: For each batch of conflicts, we pick the most likely
    result baed on a set of predefined rules.

    TODO: Add caller-callee-based de-duplication.
We are doing the stupidest thing possible: For each batch of conflicts, we pick the most likely
    result baed on a set of predefined rules.
We are doing the stupidest thing possible : For each batch of conflicts we pick the most likely result baed on a set of predefined rules .
def process_exc_file(exc_path: str):
    """
    We are doing the stupidest thing possible: For each batch of conflicts, we pick the most likely
    result baed on a set of predefined rules.

    TODO: Add caller-callee-based de-duplication.
    """
    with open(exc_path, "r") as f:
        data = f.read()
        lines = data.split("\n")

    # parse groups
    ctr = itertools.count()
    idx = 0
    groups = defaultdict(dict)

    for line in lines:
        if line.startswith(";"):
            continue
        if not line:
            idx = next(ctr)
        else:
            # parse the function name
            func_name = line[:line.index("\t")].strip(" ")
            groups[idx][func_name] = line

    # for each group, decide the one to keep
    for idx in list(groups.keys()):
        g = groups[idx]

        if len(g) == 1:
            # don't pick anything. This is a weird case that I don't understand
            continue

        if all(func_name.endswith(".cold") for func_name in g):
            # .cold functions. doesn't matter what we pick
            continue

        non_cold_names = [ ]
        for func_name in g:
            if func_name.endswith(".cold"):
                continue
            non_cold_names.append(func_name)

        # sort it
        non_cold_names = list(sorted(non_cold_names, key=len))

        # pick the top one
        the_chosen_one = non_cold_names[0]
        line = g[the_chosen_one]
        g[the_chosen_one] = "+" + line

    # output
    with open(exc_path, "w") as f:
        for g in groups.values():
            for line in g.values():
                f.write(line + "\n")
            f.write("\n")
def process_exc_file ( exc_path : str ) : with open ( exc_path , "r" ) as f : data = f . read ( ) lines = data . split ( "\n" ) # parse groups ctr = itertools . count ( ) idx = 0 groups = defaultdict ( dict ) for line in lines : if line . startswith ( ";" ) : continue if not line : idx = next ( ctr ) else : # parse the function name func_name = line [ : line . index ( "\t" ) ] . strip ( " " ) groups [ idx ] [ func_name ] = line # for each group, decide the one to keep for idx in list ( groups . keys ( ) ) : g = groups [ idx ] if len ( g ) == 1 : # don't pick anything. This is a weird case that I don't understand continue if all ( func_name . endswith ( ".cold" ) for func_name in g ) : # .cold functions. doesn't matter what we pick continue non_cold_names = [ ] for func_name in g : if func_name . endswith ( ".cold" ) : continue non_cold_names . append ( func_name ) # sort it non_cold_names = list ( sorted ( non_cold_names , key = len ) ) # pick the top one the_chosen_one = non_cold_names [ 0 ] line = g [ the_chosen_one ] g [ the_chosen_one ] = "+" + line # output with open ( exc_path , "w" ) as f : for g in groups . values ( ) : for line in g . values ( ) : f . write ( line + "\n" ) f . write ( "\n" )