Skip to content

Commit 410bf03

Browse files
authored
Merge branch 'develop' into feature/revert-unify-trackedness
2 parents fd82d32 + e9f6dc9 commit 410bf03

File tree

11 files changed

+112
-43
lines changed

11 files changed

+112
-43
lines changed

Jenkinsfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ melt.trynode('silver') {
1414

1515
checkout scm
1616

17+
// Fetch tags, so that we can obtain the Silver version when building the compiler jar
18+
sh "git fetch --tags"
19+
1720
// Bootstrap logic to obtain jars
1821
if (params.OVERRIDE_JARS != 'no') {
1922
def source = params.OVERRIDE_JARS

grammars/silver/compiler/definition/flow/ast/Flow.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ abstract production defaultSynEq
187187
top::FlowDef ::= nt::String attr::String deps::[FlowVertex]
188188
{
189189
top.defTreeContribs := [(crossnames(nt, attr), top)];
190-
top.prodGraphContribs := []; -- defaults don't show up in the prod graph!!
190+
top.prodGraphContribs := [(nt ++ ":default", top)];
191191
top.flowEdges = map(pair(fst=lhsSynVertex(attr), snd=_), deps); -- but their edges WILL end up added to graphs in fixup-phase!!
192192
}
193193

grammars/silver/compiler/definition/flow/driver/ProductionGraph.sv

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
-}
315307
function 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
-}
355354
function 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
-}
449452
fun addDefEqs
450453
[(FlowVertex, FlowVertex)] ::= prod::ProdName nt::NtName syns::[String] flowEnv :: FlowEnv =

grammars/silver/compiler/definition/flow/env/ProductionDcl.sv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,19 @@ top::AspectRHSElem ::= '@' id::Name '::' t::TypeExpr
8585
{
8686
propagate flowEnv;
8787
}
88+
89+
aspect production aspectDefaultProduction
90+
top::AGDcl ::= 'aspect' 'default' 'production' ns::AspectDefaultProductionSignature body::ProductionBody
91+
{
92+
local myFlow :: EnvTree<FlowType> = head(searchEnvTree(top.grammarName, top.compiledGrammars)).grammarFlowTypes;
93+
local myGraphs :: EnvTree<ProductionGraph> = head(searchEnvTree(top.grammarName, top.compiledGrammars)).productionFlowGraphs;
94+
95+
{-- Used by core to send down with .frame -}
96+
production myFlowGraph :: ProductionGraph =
97+
case searchEnvTree(ns.namedSignature.fullName, myGraphs) of
98+
| g :: _ -> g
99+
-- In case we didn't find the flow graph (the nonterminal doesn't exist?)
100+
-- build an anonymous flow graph to use instead as a "best effort".
101+
| [] -> constructAnonymousGraph(body.flowDefs, top.env, myGraphs, myFlow)
102+
end;
103+
}

grammars/silver/compiler/driver/BuildProcess.sv

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ fun computeEnv IOErrorable<(Decorated CmdArgs, BuildEnv)> ::= args::[String] =
4848
| right(a) -> do {
4949
-- Figure out build env from environment and args
5050
benv::BuildEnv <- determineBuildEnv(a);
51+
silverVersion::String <- lift(stateIO(getJarVersion));
5152
-- Because we want printing the version to work even if the environment is messed up
5253
-- we premptively handle that here. This is slightly unfortunate.
5354
-- Ideally, version printing would be just another thing we could have the command
5455
-- line decide to go do, but currently it's hard to re-use code if we do that.
5556
if a.displayVersion then
5657
throwRunError(127, -- error code so 'ant' isnt run
57-
"Silver Version 0.4.5-dev\n" ++
58+
"Silver Version " ++ silverVersion ++ "\n" ++
5859
"SILVER_HOME = " ++ benv.silverHome ++ "\n" ++
5960
"SILVER_GEN = " ++ benv.silverGen ++ "\n" ++
6061
"GRAMMAR_PATH:\n" ++ implode("\n", benv.grammarPath))
@@ -184,3 +185,11 @@ data RunError = runError
184185
type IOErrorable<a> = EitherT<RunError IO a>;
185186

186187
fun throwRunError IOErrorable<a> ::= c::Integer m::String = throwError(runError(code=c, errMsg=m));
188+
189+
function getJarVersion
190+
IOVal<String> ::= i::IOToken
191+
{
192+
return error("NYI");
193+
} foreign {
194+
"java" : return "new silver.core.Pioval(%i%, common.Util.getJarVersion(Init.class))";
195+
}

grammars/silver/compiler/driver/util/FlowTypes.sv

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ top::Compilation ::= g::Grammars r::Grammars buildGrammars::[String] a::Decor
3333

3434
-- Construct production graphs.
3535
production prodGraph :: [ProductionGraph] =
36-
computeAllProductionGraphs(allProds, allFlowEnv, allRealEnv) ++
37-
-- Add in phantom and dispatch graphs
38-
map(constructPhantomProductionGraph(_, allFlowEnv, allRealEnv), allNts) ++
39-
map(constructDispatchGraph(_, allFlowEnv, allRealEnv), allDispatchSigs);
36+
map(constructProductionGraph(_, allFlowEnv, allRealEnv), allProds) ++
37+
-- Add in phantom, default and dispatch graphs
38+
flatMap(constructPhantomProductionGraph(_, allFlowEnv, allRealEnv), allNts) ++
39+
flatMap(constructDefaultProductionGraph(_, allFlowEnv, allRealEnv), allNts) ++
40+
map(constructDispatchGraph(_, allFlowEnv, allRealEnv), allDispatchSigs);
4041

4142
local initialFT :: EnvTree<FlowType> =
4243
computeInitialFlowTypes(allSpecDefs);

grammars/silver/compiler/modification/defaultattr/DefaultAttr.sv

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ top::AGDcl ::= 'aspect' 'default' 'production' ns::AspectDefaultProductionSignat
2626

2727
local sigDefs :: [Def] = addNewLexicalTyVars(top.grammarName, ns.lexicalTyVarKinds, ns.lexicalTypeVariables);
2828

29-
-- oh no again!
30-
local myFlow :: EnvTree<FlowType> = head(searchEnvTree(top.grammarName, top.compiledGrammars)).grammarFlowTypes;
31-
local myProds :: EnvTree<ProductionGraph> = head(searchEnvTree(top.grammarName, top.compiledGrammars)).productionFlowGraphs;
32-
33-
local myFlowGraph :: ProductionGraph =
34-
constructDefaultProductionGraph(ns.namedSignature, body.flowDefs, top.env, myProds, myFlow);
35-
3629
ns.env = newScopeEnv(sigDefs, top.env);
3730

3831
body.env = newScopeEnv(ns.defs, ns.env);
@@ -55,7 +48,7 @@ top::AspectDefaultProductionSignature ::= lhs::Name '::' te::TypeExpr '::='
5548
top.unparse = lhs.unparse ++ "::" ++ te.unparse ++ " ::=";
5649
top.defs := [defaultLhsDef(top.grammarName, lhs.nameLoc, lhs.name, te.typerep)];
5750
top.namedSignature =
58-
namedSignature(top.grammarName ++ ":default" ++ te.typerep.typeName,
51+
namedSignature(top.grammarName ++ ":" ++ te.typerep.typeName ++ ":default",
5952
nilContext(), nilNamedSignatureElement(),
6053
namedSignatureElement(lhs.name, te.typerep, false),
6154
foldNamedSignatureElements(annotationsForNonterminal(te.typerep, top.env)));

grammars/silver/compiler/translation/java/driver/BuildProcess.sv

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ synthesized attribute relativeJar :: Boolean occurs on CmdArgs;
1414
synthesized attribute includeRTJars :: [String] occurs on CmdArgs;
1515
-- TODO: Should this be a Maybe?
1616
synthesized attribute buildXmlLocation :: [String] occurs on CmdArgs;
17+
synthesized attribute jarImplVersion :: String occurs on CmdArgs;
1718

1819
aspect production endCmdArgs
1920
top::CmdArgs ::= _
@@ -23,6 +24,7 @@ top::CmdArgs ::= _
2324
top.relativeJar = false;
2425
top.includeRTJars = [];
2526
top.buildXmlLocation = [];
27+
top.jarImplVersion = "";
2628
}
2729
abstract production dontTranslateFlag
2830
top::CmdArgs ::= rest::CmdArgs
@@ -54,6 +56,12 @@ top::CmdArgs ::= s::String rest::CmdArgs
5456
top.buildXmlLocation = s :: forward.buildXmlLocation;
5557
forwards to @rest;
5658
}
59+
abstract production jarImplVersionFlag
60+
top::CmdArgs ::= s::String rest::CmdArgs
61+
{
62+
top.jarImplVersion = s;
63+
forwards to @rest;
64+
}
5765

5866
aspect function parseArgs
5967
Either<String Decorated CmdArgs> ::= args::[String]
@@ -76,6 +84,9 @@ Either<String Decorated CmdArgs> ::= args::[String]
7684
, flagSpec(name="--build-xml-location", paramString=nothing(),
7785
help="sets the path the Ant build.xml will be saved to",
7886
flagParser=option(buildXmlFlag))
87+
, flagSpec(name="--jar-impl-version", paramString=nothing(),
88+
help="set the Implementation-Version header in the JAR's manifest",
89+
flagParser=option(jarImplVersionFlag))
7990
];
8091
}
8192
aspect production compilation
@@ -131,10 +142,12 @@ top::Compilation ::= g::Grammars _ buildGrammars::[String] a::Decorated CmdAr
131142

132143
classpathRuntime <- nub(g.includedJars); -- TODO: include in classpathCompiler too?
133144

145+
local jarImplVersion :: String = if a.jarImplVersion == "" then "${TIME}" else a.jarImplVersion;
146+
134147
production attribute extraManifestAttributes :: [String] with ++;
135148
extraManifestAttributes := [
136149
"<attribute name='Built-By' value='${user.name}' />",
137-
"<attribute name='Implementation-Version' value='${TIME}' />",
150+
"<attribute name='Implementation-Version' value='" ++ jarImplVersion ++ "' />",
138151
"<attribute name='Main-Class' value='" ++ makeName(buildGrammar) ++ ".Main' />"]; -- TODO: we "should" make main depend on whether there is a main...
139152

140153
extraManifestAttributes <-

make-compiler

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
set -euo pipefail
77

8+
silver_version=`git describe --tags`
9+
echo "Build version $silver_version"
10+
811
export SILVER_HOME=$PWD
9-
JVM_ARGS=(-Xss20M -Xmx6500M -jar ../jars/silver.compiler.composed.Default.jar --no-stdlib --include-jar ../jars/CopperCompiler.jar --include-jar ../jars/commonmark-0.17.1.jar --relative-jar "$@")
12+
JVM_ARGS=(-Xss20M -Xmx6500M -jar ../jars/silver.compiler.composed.Default.jar --no-stdlib --include-jar ../jars/CopperCompiler.jar --include-jar ../jars/commonmark-0.17.1.jar --relative-jar "$@" --jar-impl-version "$silver_version")
1013
export GRAMMAR_PATH="../grammars"
1114
export ANT_OPTS=-Xss10M
1215

runtime/java/src/common/Util.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.*;
77
import java.util.stream.Collectors;
88
import java.net.URI;
9+
import java.util.jar.JarInputStream;
10+
import java.util.jar.Attributes.Name;
911

1012
import common.exceptions.*;
1113
import common.javainterop.ConsCellCollection;
@@ -504,6 +506,16 @@ public static StringCatter determineSilverHomePath(Class<?> clazz) {
504506
File home = new File(jarLocation).getParentFile().getParentFile();
505507
return new StringCatter(home.getPath());
506508
}
509+
510+
public static StringCatter getJarVersion(Class<?> clazz) {
511+
try {
512+
URI jarLocation = clazz.getProtectionDomain().getCodeSource().getLocation().toURI();
513+
JarInputStream file = new JarInputStream(new FileInputStream(new File(jarLocation)));
514+
return new StringCatter(file.getManifest().getMainAttributes().getValue(Name.IMPLEMENTATION_VERSION));
515+
} catch (Throwable t) {
516+
throw new RuntimeException("Failed to get jar version.", t);
517+
}
518+
}
507519

508520
public static ConsCell bitSetToList(BitSet b) {
509521
ConsCell result = ConsCell.nil;

0 commit comments

Comments
 (0)