Using IR sensor and IR receiver to measure the speed of the shaft

Please do an autoformat before posting, makes your code a lot more readable. Formatting is a mess.

You don't need to detach and then attach the interrupt. That's very bad practice. The normal way is to disable interrupts, copy the value to another variable, and re-enable interrupts:

noInterrupts();
int revCount = rev;
rev = 0;
interrupts();

Then the rpm calculation is probably going wrong as you're using 16-bit integers, and 60,000 is awfully close to the 65,535 limit of an unsigned int. As you're doing a division you probably best make the whole thing floating point:

rpm=(rev/time)*60000.0;      //calculates rpm

Otherwise, making that 60,000 an unsigned long should also do the job forcing the compiler to use a big enough variable:

rpm=(rev/time)*60000ul;      //calculates rpm