Skip to content

Fix a pair of leaks related to FileUnit destructors not being run #26816

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

Merged
merged 4 commits into from
Aug 26, 2019

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Aug 24, 2019

  1. (d8c823e) Patch a latent bug in module trace emission (@varungandhi-apple) that's about to be exposed by…
  2. (e479e13) Simplify the filename resolution for a compiled module that comes from a module interface, both by storing it in a place where it doesn't require an allocation (SR-11365) and by passing it through an existing API. (@adrian-prantl, @harlanhaskins)
  3. (764e2b8) Sink private-file import support down to a place where it doesn't require an allocation (SR-11366), matching an existing table. (@aschwaighofer)
  4. (5c785d4) Add static_asserts to keep this from happening again.

I'm not sure why this wasn't already broken, but with the changes in
the next commit the multifile module trace test fails complaining that
it can't get a path for the main module. But we don't /need/ a path
for the main module because it's not a dependency of itself.
...rather than the buffer, for a compiled module that came from a
module interface.

This was already happening at a higher level
(ModuleDecl::getModuleFilename) so pushing it down to the low-level
ModuleFile::getModuleFilename doesn't really change things much. The
important fix that goes with this is that SerializedASTFile no longer
leaks this name by storing it outside of ModuleFile.

https://bugs.swift.org/browse/SR-11365
Implementing it in LoadedFile is nice in theory, but causes a leak in
practice because that type is ASTContext-allocated and usually never
destroyed.

https://bugs.swift.org/browse/SR-11366
We already do this for other ASTContext-allocated types (see
Decl.cpp). This will prevent the sort of mistakes in the previous two
commits.

Note that if any particular subclass of FileUnit wants to have its
destructor run, it can opt into that manually using
ASTContext::addDestructorCleanup. SourceFile and BuiltinUnit both do
this. But we generally don't /want/ to do this if we can avoid it
because it adds to compiler teardown time.
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@varungandhi-apple
Copy link
Contributor

varungandhi-apple commented Aug 24, 2019

W.r.t the module trace: perhaps I'm misunderstanding something -- the issue is that we're treating the main module as a dependency in the trace, correct? In that case, I'm surprised that a path for the main module is present in the dependency tracker, I would've expected that path to not be present at all. Is that a bug or is that intentional?

@varungandhi-apple
Copy link
Contributor

varungandhi-apple commented Aug 24, 2019

(Also, I think you reordered the commits and perhaps didn't update the commit messages? The last commit message says "prevents the mistakes in the past two commits" but that doesn't have anything to do with the module trace commit which comes right before AFAICT. I also don't understand what you mean by "that's about to be exposed by…" -- exposed by ???)

@jrose-apple
Copy link
Contributor Author

I blame GitHub for showing commits in chronological order instead of parent order. The real order is the one I wrote in the description.

The issue isn't actually that we're treating the main module as a dependency, but that we look at all loaded modules to build a path-to-module map (which is used later), and we can only do that if a particular module has a unique path. The main module does not have such a thing if it's made up of multiple files!

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants