I think the frame determines whether the rebuild is the "same" locomotive. The frame is kept, "same" loco. Different frame, different loco.
Ships, at least ones under sail, have a like tradition. Same keel and hull, same vessel even if the stuff above it changes. ELISSA in Galveston when through several changes, but she still has the same hull. She is as built condition, except for a radio room, and a diesel powered screw.