Skip to content

Commit 6df085b

Browse files
MPS-28875 Cannot use a node from checkpoint model in reference macro
do not resolve nodes in a model scheduled for removal
1 parent 424548b commit 6df085b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

core/generator/source/jetbrains/mps/generator/TransientModelsModule.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
import org.jetbrains.mps.openapi.module.SModule;
4444
import org.jetbrains.mps.openapi.module.SModuleReference;
4545
import org.jetbrains.mps.openapi.module.SRepository;
46-
import org.jetbrains.mps.openapi.persistence.ModelSaveException;
4746
import org.jetbrains.mps.openapi.persistence.NullDataSource;
4847

49-
import java.io.IOException;
5048
import java.util.ArrayList;
5149
import java.util.HashMap;
5250
import java.util.HashSet;
@@ -200,7 +198,7 @@ public String toString() {
200198

201199
// Purpose of this implementation is to resolve references to yet not public transient models
202200
private SModel findInVault(SModelId reference) {
203-
for (SModel m : myModelVault.allModels()) {
201+
for (SModel m : myModelVault.allModelsExceptScheduled2Drop()) {
204202
if (reference.equals(m.getModelId())) {
205203
return m;
206204
}
@@ -211,7 +209,8 @@ private SModel findInVault(SModelId reference) {
211209
@Override
212210
public SModel getModel(SModelId id) {
213211
SModel rv = super.getModel(id);
214-
if (rv != null) {
212+
// we may find CP model published during previous generator run but already re-generated (and scheduled to drop) during actual run.
213+
if (rv != null && !myModelVault.isScheduled2Drop(rv)) {
215214
return rv;
216215
}
217216
return findInVault(id);
@@ -404,7 +403,7 @@ public boolean isChanged() {
404403
}
405404

406405
@Override
407-
protected boolean saveModel() throws IOException, ModelSaveException {
406+
protected boolean saveModel() {
408407
throw new UnsupportedOperationException();
409408
}
410409

core/generator/source/jetbrains/mps/generator/impl/ModelVault.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2003-2016 JetBrains s.r.o.
2+
* Copyright 2003-2018 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,6 +95,24 @@ public Iterable<T> allModels() {
9595
return new ArrayList<>(myModels);
9696
}
9797

98+
// XXX not sure there's need for distinct method or it shall be part of allModels() impl,
99+
// nor am I sure we shall not resolve references into models to drop (I'd rather do).
100+
// However, imagine there's already model m1@cp in a checkpoint module, and we generate m1 and m2 (latter needs to use m1@cp)
101+
// When we see m1's new checkpoint, CME.createBlankCheckpointModel recognizes there's already m1@cp and commands to forget it (vault.forgetModel())
102+
// Then, m2 restores a reference to m1@cp with a node from new CP model (m1'@cp), but the reference is kept as 'mature', and the moment we resolve it,
103+
// the code in TransientModelsModule.findInVault() just took the first model from allModels() with matching id, which could be the m1@cp one, not m1'@cp
104+
// (they share same module reference, after all).
105+
public Iterable<T> allModelsExceptScheduled2Drop() {
106+
final ArrayList<T> rv = new ArrayList<>(myModels);
107+
rv.removeAll(myExactModelsToDrop.keySet());
108+
return rv;
109+
}
110+
111+
public boolean isScheduled2Drop(SModel model) {
112+
return myExactModelsToDrop.containsKey(model);
113+
}
114+
115+
98116
public boolean known(@NotNull SModelReference mr) {
99117
for (SModel m : myModels) {
100118
if (mr.equals(m.getReference())) {

0 commit comments

Comments
 (0)