From: Tuukka Lehtonen Date: Thu, 13 Jun 2019 11:37:04 +0000 (+0000) Subject: Merge "Fix endless loop in type inference for over-applied functions" X-Git-Tag: v1.43.0~136^2~147 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=d85a4d990c5cac9d0c70781a265f02888b3aaa43;hp=d09b3768f601b5ee977c2e80c23ef96e9879f8f1 Merge "Fix endless loop in type inference for over-applied functions" --- diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index b2951cb27..5a37257e2 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -2296,67 +2296,16 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap @Override final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException(); + try { -// assert(subject != null); -// assert(procedure != null); -// -// final ListenerBase listener = getListenerBase(procedure); -// -// IntProcedure ip = new IntProcedure() { -// -// AtomicBoolean first = new AtomicBoolean(true); -// -// @Override -// public void execute(ReadGraphImpl graph, int i) { -// try { -// if(first.get()) { -// procedure.execute(graph, querySupport.getResource(i)); -// } else { -// procedure.execute(impl.newRestart(graph), querySupport.getResource(i)); -// } -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// @Override -// public void finished(ReadGraphImpl graph) { -// try { -// if(first.compareAndSet(true, false)) { -// procedure.finished(graph); -//// impl.state.barrier.dec(this); -// } else { -// procedure.finished(impl.newRestart(graph)); -// } -// -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// @Override -// public void exception(ReadGraphImpl graph, Throwable t) { -// try { -// if(first.compareAndSet(true, false)) { -// procedure.exception(graph, t); -// } else { -// procedure.exception(impl.newRestart(graph), t); -// } -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// }; -// -// int sId = querySupport.getId(subject); -// -// try { -// QueryCache.runnerPredicates(impl, sId, impl.parent, listener, ip); -// } catch (DatabaseException e) { -// Logger.defaultLogError(e); -// } + for(Resource predicate : getPredicates(impl, subject)) + procedure.execute(impl, predicate); + + procedure.finished(impl); + + } catch (Throwable e) { + procedure.exception(impl, e); + } } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/EdgeRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/EdgeRequest.java index 651228ce1..826827f76 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/EdgeRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/EdgeRequest.java @@ -16,6 +16,7 @@ import org.simantics.db.common.procedure.adapter.ListenerSupport; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.diagram.content.EdgeResource; +import org.simantics.diagram.internal.DebugPolicy; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.ErrorHandler; import org.simantics.g2d.canvas.ICanvasContext; @@ -30,16 +31,19 @@ import org.simantics.g2d.element.impl.Element; */ public class EdgeRequest extends BaseRequest2 { + final GraphToDiagramSynchronizer synchronizer; final ErrorHandler errorHandler; final ListenerSupport listenerSupport; final IDiagram diagram; final ConnectionSegmentAdapter adapter; - public EdgeRequest(ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) { + public EdgeRequest(GraphToDiagramSynchronizer synchronizer, ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) { super(canvas, resource); assert(adapter != null); + assert(synchronizer != null); + this.synchronizer = synchronizer; this.errorHandler = errorHandler; this.listenerSupport = listenerSupport; this.diagram = diagram; @@ -96,6 +100,13 @@ public class EdgeRequest extends BaseRequest2 { @Override public void execute(AsyncReadGraph graph, IElement element) { + + if (DebugPolicy.DEBUG_EDGE_LOAD) + System.out.println(" SPAWNED EDGE SEGMENT: " + element + " " + data); + + // Register this for updates to work correctly + synchronizer.mapElementIfNew(data, element); + // task.finish(); // Tell the procedure to use this element procedure.execute(graph, element); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java index aa35c6334..03cedfcb3 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java @@ -616,6 +616,17 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID */ ConcurrentMap dataConnection = new ConcurrentHashMap(); + + void mapElementIfNew(final Object data, final IElement element) { + IElement mapped = getMappedElement(data); + if(mapped == null) { + mapElement(data, element); + currentUpdater.addedElements.add(element); + currentUpdater.addedElementMap.put(data, element); + } + } + + /** * @param data * @param element @@ -1744,9 +1755,15 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID @Override public void execute(Resource connectionType) { synchronized (GraphToDiagramUpdater.this) { + IElement mapped = getMappedElement(element); + assert(mapped != null); + + if (DebugPolicy.DEBUG_CONNECTION_LISTENER) + System.out.println("CONNECTION ENTITY CREATED " + e + " " + element); + //System.out.println("new connection entity " + e); - ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, e); - e.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity); + ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, mapped); + mapped.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity); addedConnectionEntities.put(element, entity); } } @@ -2223,13 +2240,13 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID } }); - graph.syncRequest(new EdgeRequest(canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure() { + graph.syncRequest(new EdgeRequest(GraphToDiagramSynchronizer.this, canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure() { @Override public void execute(AsyncReadGraph graph, IElement e) { if (DebugPolicy.DEBUG_EDGE_LOAD) - System.out.println("ADDED EDGE LOADED: " + e); + System.out.println("ADDED EDGE LOADED: " + e + " " + seg); + if (e != null) { - mapElement(seg, e); synchronized (GraphToDiagramUpdater.this) { addedConnectionSegments.add(e); addedElementMap.put(seg, e); @@ -2428,8 +2445,6 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID @Override public void execute(IElement loaded) { // Invoked when the element has been loaded. - if (DebugPolicy.DEBUG_EDGE_LISTENER) - System.out.println("EDGE LoadListener for " + loaded); if (loaded == null) { disposeListener(); @@ -2437,6 +2452,10 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID } Object data = loaded.getHint(ElementHints.KEY_OBJECT); + + if (DebugPolicy.DEBUG_EDGE_LISTENER) + System.out.println("EDGE LoadListener for " + loaded + " " + data); + if (addedElementMap.containsKey(data)) { // This element was just loaded, in // which case its hints need to diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java index 8c052561e..0ca3b1b04 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java @@ -13,6 +13,8 @@ package org.simantics.modeling.ui.diagramEditor; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import org.eclipse.ui.PlatformUI; import org.simantics.Simantics; @@ -103,16 +105,21 @@ public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorA Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, r); if(diagram != null) return diagram; - if(selectedObjects.size() == 1) { - Object o = selectedObjects.iterator().next(); - if(o instanceof Resource) { - Resource res = (Resource)o; - if(graph.isInstanceOf(res, DIA.Element)) { - return graph.getPossibleObject(res, L0.PartOf); - } - } + // TODO: what if the selected objects are from different diagrams? + if (selectedObjects.size() > 0) { + Set diagrams = new HashSet<>(); + for (Object o : selectedObjects) { + if (o instanceof Resource) { + Resource res = (Resource)o; + if (graph.isInstanceOf(res, DIA.Element)) { + diagrams.add(graph.getPossibleObject(res, L0.PartOf)); + } + } + } + if (diagrams.size() == 1) { + return diagrams.iterator().next(); + } } - return null; } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/ComponentNamingUtil.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/ComponentNamingUtil.java index fc629bdb0..1ac81874e 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/ComponentNamingUtil.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/ComponentNamingUtil.java @@ -22,6 +22,7 @@ import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.PossibleRelatedValueImplied2; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.Versions; import org.simantics.db.exception.DatabaseException; import org.simantics.layer0.Layer0; import org.simantics.operation.Layer0X; @@ -189,11 +190,13 @@ public final class ComponentNamingUtil { if (containerGeneratedNamePrefix != null) proposition.append(containerGeneratedNamePrefix); String componentPrefix = graph.getPossibleRelatedValue(componentType, L0X.HasGeneratedNamePrefix, Bindings.STRING); - if (componentPrefix == null) { + if (componentPrefix == null || "".equals(componentPrefix)) { Layer0 L0 = Layer0.getInstance(graph); - componentPrefix = graph.getPossibleRelatedValue(componentType, L0.HasName); - if (componentPrefix == null) + String name = graph.getPossibleRelatedValue(componentType, L0.HasName); + if (name == null) componentPrefix = "Entity"; + else + componentPrefix = Versions.getBaseName(name); } proposition.append(componentPrefix); return proposition.toString();