Commit 5f860ebb authored by Brad King's avatar Brad King
Browse files

cmState: Avoid accumulating snapshot storage for short-lived scopes

We need to keep only certain snapshot types and their ancestors.
Also keep those needed for backtraces.
parent f21dc4a8
......@@ -403,6 +403,10 @@ cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot,
: Context(cc)
, Snapshot(snapshot)
{
if (this->Snapshot.IsValid())
{
this->Snapshot.Keep();
}
}
cmListFileBacktrace::~cmListFileBacktrace()
......
......@@ -27,6 +27,7 @@ struct cmState::SnapshotDataType
cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
cmState::SnapshotType SnapshotType;
bool Keep;
cmLinkedTree<std::string>::iterator ExecutionListFile;
cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
BuildSystemDirectory;
......@@ -755,6 +756,7 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
pos->DirectoryParent = this->SnapshotData.Root();
pos->ScopeParent = this->SnapshotData.Root();
pos->SnapshotType = BaseType;
pos->Keep = true;
pos->BuildSystemDirectory =
this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
pos->ExecutionListFile =
......@@ -787,6 +789,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
pos->DirectoryParent = originSnapshot.Position;
pos->ScopeParent = originSnapshot.Position;
pos->SnapshotType = BuildsystemDirectoryType;
pos->Keep = true;
pos->BuildSystemDirectory =
this->BuildsystemDirectory.Push(
originSnapshot.Position->BuildSystemDirectory);
......@@ -822,6 +825,7 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = FunctionCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos;
......@@ -846,6 +850,7 @@ cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = MacroCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid());
......@@ -865,6 +870,7 @@ cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = CallStackType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid());
......@@ -884,6 +890,7 @@ cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = VariableScopeType;
pos->Keep = false;
pos->PolicyScope = originSnapshot.Position->Policies;
assert(originSnapshot.Position->Vars.IsValid());
......@@ -906,6 +913,7 @@ cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = InlineListFileType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos;
......@@ -919,6 +927,7 @@ cmState::CreatePolicyScopeSnapshot(cmState::Snapshot originSnapshot)
PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
*originSnapshot.Position);
pos->SnapshotType = PolicyScopeType;
pos->Keep = false;
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
return cmState::Snapshot(this, pos);
......@@ -937,6 +946,21 @@ cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
prevPos->BuildSystemDirectory->CompileOptions.size();
prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
if (!pos->Keep && this->SnapshotData.IsLast(pos))
{
if (pos->Vars != prevPos->Vars)
{
assert(this->VarTree.IsLast(pos->Vars));
this->VarTree.Pop(pos->Vars);
}
if (pos->ExecutionListFile != prevPos->ExecutionListFile)
{
assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
this->ExecutionListFiles.Pop(pos->ExecutionListFile);
}
this->SnapshotData.Pop(pos);
}
return Snapshot(this, prevPos);
}
......@@ -999,6 +1023,11 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
this->ComputeRelativePathTopBinary();
}
void cmState::Snapshot::Keep()
{
this->Position->Keep = true;
}
void cmState::Snapshot::SetListFile(const std::string& listfile)
{
*this->Position->ExecutionListFile = listfile;
......
......@@ -62,6 +62,7 @@ public:
std::vector<std::string> ClosureKeys() const;
bool RaiseScope(std::string const& var, const char* varDef);
void Keep();
void SetListFile(std::string const& listfile);
std::string GetExecutionListFile() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment