@@ -98,20 +98,15 @@ Maybe<ProductionGraph> ::=
9898 | nothing() - > graph.cullSuspect (ntEnv)
9999 end;
100100
101- -- construct a production graph for each production
102- fun computeAllProductionGraphs
103- [ProductionGraph] :: = prods:: [ValueDclInfo] flowEnv:: FlowEnv realEnv:: Env =
104- if null (prods) then []
105- else constructProductionGraph(head(prods), flowEnv, realEnv) ::
106- computeAllProductionGraphs(tail(prods), flowEnv, realEnv);
107-
108101
109102--------------------------------------------------------------------------------
110103-- Below, we have various means of constructing a production graph.
111- -- Three types are used as part of inference:
104+ -- Four types are used as part of inference:
112105-- 1 . `constructProductionGraph ` builds a graph for a normal production.
113- -- 2 . `constructPhantomProductionGraph ` builds a " phantom graph" to guide inference.
114- -- 3 . `constructDispatchGraph ` builds a graph for a dispatch signature,
106+ -- 2 . `constructDefaultProductionGraph ` builds a graph for default equations for a nonterminal.
107+ -- (key: like phantom, LHS is stitch point, to make dependencies clear.)
108+ -- 3 . `constructPhantomProductionGraph ` builds a " phantom graph" to guide inference.
109+ -- 4 . `constructDispatchGraph ` builds a graph for a dispatch signature,
115110-- to make projection stitch points work for them.
116111--
117112-- There are more types of " production" graphs, used NOT for inference, but
@@ -120,8 +115,6 @@ fun computeAllProductionGraphs
120115-- (the key here: `aspect function` contributions `< - ` needs to be handled.)
121116-- 2 . `constructAnonymousGraph ` builds a graph for a global expression. (also action blocks)
122117-- (key: decorate/ patterns create stitch points and things that need to be handled.)
123- -- 3 . `constructDefaultProductionGraph ` builds a graph used locally in a default production.
124- -- (key: like phantom, LHS is stitch point, to make dependencies clear.)
125118--
126119-- This latter type should always call `updateGraph ` to fill in all edges after construction.
127120--------------------------------------------------------------------------------
@@ -307,23 +300,26 @@ ProductionGraph ::= defs::[FlowDef] realEnv::Env prodEnv::EnvTree<ProductionGr
307300}
308301
309302{ --
310- - An graph for checking dependencies in default equations.
311- -
312- - NOTE : Not used as part of inference. Instead, only used as part of error checking.
303+ - A graph for dependencies in default equations.
313304 -
305+ - This is used in checking, and also to handle dependencies of default equations during inference.
314306 - }
315307function constructDefaultProductionGraph
316- ProductionGraph :: = ns :: NamedSignature defs :: [FlowDef] realEnv :: Env prodEnv :: EnvTree < ProductionGraph > ntEnv :: EnvTree < FlowType >
308+ [ ProductionGraph] :: = nt :: NtName flowEnv :: FlowEnv realEnv :: Env
317309{
318- local prod :: String = ns.fullName ;
319- local nt :: NtName = ns.outputElement.typerep.typeName;
310+ -- The stand- in " full name" of this default production
311+ local prod :: String = nt ++ " :default" ;
312+ -- The flow defs for this default production
313+ local defs :: [FlowDef] = getGraphContribsFor (prod, flowEnv);
314+ -- Just synthesized attributes.
315+ local syns :: [String] = getSynAttrsOn (nt, realEnv);
320316
321317 local normalEdges :: [(FlowVertex, FlowVertex)] =
322318 flatMap ((.flowEdges), defs);
323319
324320 -- suspectEdges should always be empty! (No " aspects" where they could arise.)
325321 local suspectEdges :: [(FlowVertex, FlowVertex)] = [];
326-
322+
327323 local initialGraph :: g: Graph< FlowVertex> =
328324 createFlowGraph (normalEdges);
329325
@@ -334,16 +330,19 @@ ProductionGraph ::= ns::NamedSignature defs::[FlowDef] realEnv::Env prodEnv::
334330 localStitchPoints(realEnv, error(" default production shouldn't have a forwarding equation?" ), defs) ++
335331 patternStitchPoints(realEnv, defs);
336332
337- local flowTypeVertexes :: [FlowVertex] = []; -- Not used as part of inference.
333+ local flowTypeVertexesOverall :: [FlowVertex] = map (lhsSynVertex, syns);
334+ local flowTypeSpecs :: [String] = getSpecifiedSynsForNt (nt, flowEnv);
335+
336+ local flowTypeVertexes :: [FlowVertex] =
337+ filter (\x :: FlowVertex - > ! contains (x.flowTypeName, flowTypeSpecs), flowTypeVertexesOverall);
338338
339339 local g :: ProductionGraph =
340340 productionGraph (prod, nt, flowTypeVertexes, initialGraph, suspectEdges, stitchPoints).transitiveClosure;
341-
342- return fromMaybe (g, updateGraph (g, prodEnv, ntEnv));
341+
342+ -- Optimization: omit the default graph if there are no default equations for the NT .
343+ return if null (defs) then [] else [g];
343344}
344345
345-
346-
347346{ --
348347 - Constructs " phantom graphs" to enforce 'ft (syn) >= ft (fwd)'.
349348 -
@@ -353,7 +352,7 @@ ProductionGraph ::= ns::NamedSignature defs::[FlowDef] realEnv::Env prodEnv::
353352 - @ return A fixed up graph.
354353 - }
355354function constructPhantomProductionGraph
356- ProductionGraph :: = nt:: String flowEnv:: FlowEnv realEnv:: Env
355+ [ ProductionGraph] :: = nt:: String flowEnv:: FlowEnv realEnv:: Env
357356{
358357 -- Just synthesized attributes.
359358 local syns :: [String] = getSynAttrsOn(nt, realEnv);
@@ -373,7 +372,11 @@ ProductionGraph ::= nt::String flowEnv::FlowEnv realEnv::Env
373372 local initialGraph :: g: Graph< FlowVertex> = createFlowGraph (phantomEdges);
374373 local suspectEdges :: [(FlowVertex, FlowVertex)] = [];
375374
376- return productionGraph (" Phantom for " ++ nt, nt, flowTypeVertexes, initialGraph, suspectEdges, stitchPoints).transitiveClosure;
375+ local g :: ProductionGraph =
376+ productionGraph (" Phantom for " ++ nt, nt, flowTypeVertexes, initialGraph, suspectEdges, stitchPoints).transitiveClosure;
377+
378+ -- Optimization: omit the phantom graph if there are no extension syns for the NT .
379+ return if null (extSyns) then [] else [g];
377380}
378381
379382{ --
@@ -444,7 +447,7 @@ fun allFwdProdAttrs [String] ::= d::[FlowDef] =
444447 | _ :: rest - > allFwdProdAttrs(rest)
445448 end;
446449{ --
447- - Introduces default equations deps. Realistically, should be empty, always .
450+ - Introduces default equations deps.
448451 - }
449452fun addDefEqs
450453[(FlowVertex, FlowVertex)] :: = prod:: ProdName nt:: NtName syns:: [String] flowEnv :: FlowEnv =
0 commit comments