Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace frontend inliner with backend inliner #14194

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

WalterBright
Copy link
Member

The front end inliner has some unfixable problems, and it is way overly complex. I made a mistake with this design, and am tired of it. This replaces it with one in the backend that inlines based on the optimized intermediate code. This is vastly simpler, and will inline much more.

It is currently in a draft state, and disables the frontend one, although the code for it remains for now.

Current shortcomings:

  1. it can only inline functions it has already compiled
  2. it can only inline functions that consist of one basic block

Comments are welcome, just remember it's only a draft at the moment! I expect the usual problems with it.

@WalterBright WalterBright added the Review:WIP Work In Progress - not ready for review or pulling label Jun 8, 2022
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#14194"

@WalterBright
Copy link
Member Author

Unfortunately, the test suite tries to compile the runtime library first. This is backwards. It should compile the compiler test suite first. Only when that passes should it attempt to compile the runtime library, as the test suite is designed to make it easy to track down problems.

@ibuclaw
Copy link
Member

ibuclaw commented Jun 8, 2022

Unfortunately, the test suite tries to compile the runtime library first. This is backwards. It should compile the compiler test suite first. Only when that passes should it attempt to compile the runtime library, as the test suite is designed to make it easy to track down problems.

The tests in the testsuite should not be importing the library then.

Can't you run the testsuite locally?

src/dmd/backend/inliner.d Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
src/dmd/backend/elem.d Outdated Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
src/dmd/backend/inliner.d Outdated Show resolved Hide resolved
@maxhaton
Copy link
Member

maxhaton commented Jun 8, 2022

If we could actually remove the frontend one entirely that would be a very nice red diff.

@WalterBright
Copy link
Member Author

checkwhitespace fails, but gives no clue about which file is errant.

@WalterBright WalterBright force-pushed the inliner branch 5 times, most recently from 7342849 to 2bc741e Compare June 9, 2022 06:10
@maxhaton
Copy link
Member

maxhaton commented Jun 9, 2022 via email

@WalterBright WalterBright force-pushed the inliner branch 2 times, most recently from 15d6f7c to 5a52488 Compare June 12, 2022 07:20
@WalterBright
Copy link
Member Author

The problems have been reduced to:

  1. dshell/dll.d fails on the mac. Don't know why
  2. the rest of the failures are all the compiler not warning when it can't inline a function. Since the backend is doing the inlining, this may not be fixable
  3. buildkite has some mysterious failures. Don't know if they are related or not. It seems that there are lots and lots of deprecation messages in those builds

@ibuclaw
Copy link
Member

ibuclaw commented Jun 12, 2022

The problems have been reduced to:

  1. dshell/dll.d fails on the mac. Don't know why

I'll see if I can spin up one of my macboxes to run the testsuite there later.

@rikkimax
Copy link
Contributor

This may not be possible, but it would be nice if this would work with inline assembly.

It would mean that we wouldn't have to replace the assembly in core.internal.atomic with intrinsics.

@maxhaton
Copy link
Member

This may not be possible, but it would be nice if this would work with inline assembly.

It would mean that we wouldn't have to replace the assembly in core.internal.atomic with intrinsics.

Why does it matter as long as the memory ordering is correct? The backend also isn't a proper load-store ISA so the intrinsics might look a bit weird internally, although with x86 you basically only need to emit the right prefix in a few cases so that plus volatile might be enough.

@rikkimax
Copy link
Contributor

Why does it matter as long as the memory ordering is correct?

Segfaults. You get segfaults.

Lock-free concurrent data structures are one of the few areas left of CS where instruction counting still persists. A function call will cause segfaults due to memory unmapping by the time the next step in the algorithm takes place.

@maxhaton
Copy link
Member

Why does it matter as long as the memory ordering is correct?

Segfaults. You get segfaults.

Lock-free concurrent data structures are one of the few areas left of CS where instruction counting still persists. A function call will cause segfaults due to memory unmapping by the time the next step in the algorithm takes place.

I'm going to need to see an example that segfaults with dmd today because that sounds backwards.

@rikkimax
Copy link
Contributor

Why does it matter as long as the memory ordering is correct?

Segfaults. You get segfaults.
Lock-free concurrent data structures are one of the few areas left of CS where instruction counting still persists. A function call will cause segfaults due to memory unmapping by the time the next step in the algorithm takes place.

I'm going to need to see an example that segfaults with dmd today because that sounds backwards.

Lock-free concurrent data structures have no way to synchronize free'ing of memory. They rely solely on timeing to get things right. Andrei has written an introductory paper on this topic. But he only barely touches upon the memory deallocation side of things (which are still to this day not solved).

We are getting pretty off-topic now.

@WalterBright WalterBright force-pushed the inliner branch 3 times, most recently from ef495db to 19b163c Compare June 13, 2022 19:49
@ibuclaw
Copy link
Member

ibuclaw commented Jun 13, 2022

Alls looking nice and green. There are still some fix-ups left to do in the implementation to make it nice and neat.

Are we going to switch to this proper now? Or hide it behind a preview flag? Moving forward with this should give us a ~3000 line removal.

Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to change this line too

dmd/src/dmd/expressionsem.d

Lines 1757 to 1758 in 13f9d97

arg = p.defaultArg;
arg = inlineCopy(arg, sc);

That should instead be:

arg = p.defaultArg.copy();

After that, then there'll really be no calls into the frontend inliner.

@WalterBright WalterBright force-pushed the inliner branch 2 times, most recently from f9874b6 to b2b52c8 Compare June 13, 2022 21:36
@WalterBright
Copy link
Member Author

I turned the original inliner back on so both are operating. This is because the backend one doesn't handle all the cases yet the front end one does.

This PR is ready to go. The one failing test is a heisenbug.

src/dmd/backend/gother.d Outdated Show resolved Hide resolved
@WalterBright WalterBright added Merge:auto-merge and removed Review:WIP Work In Progress - not ready for review or pulling labels Jun 13, 2022
@WalterBright WalterBright merged commit 1483b69 into dlang:master Jun 14, 2022
@WalterBright WalterBright deleted the inliner branch June 14, 2022 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants