What does shell_session_history_check do in the default PROMPT_COMMAND? I'm using terminal on MacOS High Sierra.

I added echo PROMPT_COMMAND to the top of my .bash_profile to see the default and I got:

'shell_session_history_check; update_terminal_cwd'



I don't fully understand what the shell_session_history_check actually does. I can't really find a difference with/without it (history from closed shells still show up in history in a new shell).
shell_session_history_check calls shell_session_history_enable which creates a unique log file for each shell session.
NOTE: shell_session_history_check is a Mac specific function.

Let's break it down.
$ declare -f shell_session_history_check
shell_session_history_check () 
{ 
    if [ ${SHELL_SESSION_DID_HISTORY_CHECK:-0} -eq 0 ]; then
        SHELL_SESSION_DID_HISTORY_CHECK=1;
        if shell_session_history_allowed; then
            shell_session_history_enable;
        fi;
        if [ &quot;$PROMPT_COMMAND&quot; = &quot;shell_session_history_check&quot; ]; then
            unset PROMPT_COMMAND;
        else
            if [[ $PROMPT_COMMAND =~ (.*)(; *shell_session_history_check *| *shell_session_history_check *; *)(.*) ]]; then
                PROMPT_COMMAND=&quot;${BASH_REMATCH[1]}${BASH_REMATCH[3]}&quot;;
            fi;
        fi;
    fi
}

The last if/else removes shell_session_history_check from the PROMPT_COMMAND (assuming your PROMPT_COMMAND starts with shell_session_history_check;) so that it only runs on the first prompt.
shell_session_history_allowed is true by default so basically the real behavior is calling shell_session_history_enable.
$ declare -f shell_session_history_enable
shell_session_history_enable () 
{ 
    ( umask 077;
    /usr/bin/touch &quot;$SHELL_SESSION_HISTFILE_NEW&quot; );
    HISTFILE=&quot;$SHELL_SESSION_HISTFILE_NEW&quot;;
    SHELL_SESSION_HISTORY=1
}

This function overwrites the default value of HISTFILE (~/.bash_history) and sets the SHELL_SESSION_HISTORY to 1 (true).
So this question boils down to: Why is the history saved even though HISTFILE isn't set to a unique file name?
Well it still functions the same way. Once the shell exits, it appends to ~/.bash_history. The difference is that you don't have unique files logging each session.
Why would I want unique files logging each session?
Check out this Reddit post:

(~/.bash_sessions/) is used to store HISTFILE's and .session files
that are unique to sessions. If $BASH_SESSION or $TERM_SESSION_ID is
set upon launching the shell (i.e. if Terminal is resuming from a
saved state), the associated HISTFILE is merged into the current one,
and the .session file is ran. Session saving is facilitated by means
of an EXIT trap being set for a function bash_update_session_state.
Essentially, this lays the groundwork for us to be able to extend
Terminal's session-resuming using our own rc files. By implementing
our own extension of bash_update_session_state, we can, say, add
functionality to the .session files that are run upon resume.