Adding a singleton to swift


(Vedant Kumar) #1

Hi all,

I'm experimenting with swift and would like to add a singleton to the compiler
in a way that's visible to SILGen. It seemed that CompilerInstance would be the
right place to store it, but I don't see a way to access the CI from SILGen. My
first question is: what's the best place to put this singleton?

While I was looking at CompilerInstance, I noticed that we're doing something
strange in its setup() method:

  // FrontendTool.cpp
  if (Instance.setup(Invocation)) { ... }
  ...
  Invocation.getDiagnosticOptions();

This code is copying a CompilerInvocation into a CompilerInstance, modifying it
within CompilerInstance::setup(), and then using the original (unmodified)
CompilerInvocation. I don't think this is causing any bugs, but it is a bit
confusing. My second question is: which invocation is the "right" one: the
unmodifed one, the modified one, or both? It seems like the CompilerInstance
should either own an invocation or just have a reference to one.

thanks!
vedant