But this can take decades.
If Google wants to start a large new compiler project, them opening a job position with a high salary isn't going to convince anyone to go away and do a PhD in compilers, and if it does they wouldn't be available for five years.
If Google want to build a compiler now and they aren't able to hire anyone locally with the skills, what do you want them to do? Abandon the project? That's not great for the US economy is it?
And this can still be fixed by requiring above-market prices for H1B workers (eg. requiring 1.5x average pay for the position needed, so if an average compiler developer in california is paid 100k, you can only get a foreign developer if you pay them 150k - this would force companies to get local talent by raising their pay to 110k, 120k, 130k..., and when they really cannot get anyone, even at 150k, they are able to get someone on a visa).
But if you don't agree, take any example you like that requires at least a few years to come up to speed.
People aren't going to become an expert tomorrow on whatever subject you're hiring for, no matter how much you pay.
If you offered me a million dollars to play the trombone for you I'd love to accept that, but I can't do it until I go away and learn the trombone which would take me years. Offering me ten million dollars wouldn't make me learn it any faster, either.
We say that markets are 'inelastic' - they don't adapt to demand magically.
There are very very few positions, that you can't fill if you offer above-average pay and working conditions, and most H1B visa carriers now, are not unicorns, but usually just someone willing to work for less money than locals (example: https://www.nytimes.com/2015/06/04/us/last-task-after-layoff... )
What I often do see instead are situations where local markets seeking a skill can't or don't want to compete with the labor rates needed for to attract or contract the skills they desire. They instead have to look for more leveraged labor abroad to pass their desired cost savings onto who is willing to accept living in undesired locations, working at below market rates to escape even less desirable situations, etc.
Obviously, this is anecdotal. I'm sure the case does arise where you actually need some highly specialized labor abroad but nothing near the labor pools the H1B program allows. If there are labor supply shortages, you shouldn't need to artificially inflate the market with labor through visa programs. Raise compensation and let the markets adjust to attract talent. This sort of competition is what's forced on the labor market while businesses, yet again, avoid competition when it's against their interests.
If you truly need international labor you should absolutely be required to pay near the top of market rates for the talent is truly that rare. If businesses aren't willing to pay above market rates this talent, it must not be so critical or rare. This should prevent the case of manipulating labor markets under the guise of projected artificial scarcity.
I have nothing against immigration, let people move to this country if they so desire and seek opportunity but let them do so without being leveraged by a business holding their citizenship, freedoms, and future hope of prosperity hostage while suppressing local wages, all to make a quick buck.