Skip to content

Commit 78d6237

Browse files
authored
Merge branch 'main' into cleanup-subtype-for-prods
2 parents b949554 + c361648 commit 78d6237

13 files changed

Lines changed: 234 additions & 58 deletions

File tree

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.rascalmpl</groupId>
55
<artifactId>rascal</artifactId>
6-
<version>0.42.2-RC2-SNAPSHOT</version>
6+
<version>0.42.2-RC3-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<scm>
@@ -458,7 +458,7 @@
458458
<dependency>
459459
<groupId>org.rascalmpl</groupId>
460460
<artifactId>typepal</artifactId>
461-
<version>0.16.6-RC2</version>
461+
<version>0.16.7</version>
462462
<!-- <scope>provided</scope> for shade plugin it can't be provided. At least the rascal dependency in typepal should be provided -->
463463
<scope>compile</scope>
464464
</dependency>

‎src/org/rascalmpl/compiler/lang/rascalcore/check/CollectDeclaration.rsc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ void collect(current: (Statement) `return <Statement statement>`, Collector c){
695695
assert !isEmpty(functionScopes);
696696
for(<_, scopeInfo> <- functionScopes){
697697
if(signatureInfo(Type returnType) := scopeInfo){
698-
c.require("check return type", current, [statement], makeReturnRequirement(statement, returnType));
698+
c.require("check return type", current, [statement, returnType], makeReturnRequirement(statement, returnType));
699699
c.fact(current, returnType); // Note that type of the return statement as a whole is the function's return type
700700
collect(statement, c);
701701
return;

‎src/org/rascalmpl/compiler/lang/rascalcore/check/CollectType.rsc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,13 @@ void collect(current:(TypeVar) `& <Name n>`, Collector c){
814814
}
815815
c.define(pname, typeVarId(), n, defType(aparameter(pname, bound, closed=closed)));
816816
}
817-
c.calculate("xxx", current, [n], AType (Solver s) { return s.getType(n)[closed=closed]; });
817+
c.calculate("type parameter without bound", current, [n], AType (Solver s) { return s.getType(n)[closed=closed]; });
818818
return;
819819

820820
} else if(<true, bool closed> := useTypeParameters(c)){
821821
c.use(n, {typeVarId() });
822822
//if(debugTP)println("Use <pname> at <current@\loc>, closed=<closed>");
823-
c.calculate("xxx", current, [n], AType (Solver s) { return s.getType(n)[closed=closed]; });
823+
c.calculate("type parameter without bound", current, [n], AType (Solver s) { return s.getType(n)[closed=closed]; });
824824
return;
825825
} else {
826826
if(<true, rel[str, Type] tpbounds> := useBoundedTypeParameters(c)){

‎src/org/rascalmpl/compiler/lang/rascalcore/check/Summary.rsc‎

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import IO;
4444
import Relation;
4545
import String;
4646
import ValueIO;
47-
// import lang::rascalcore::CompilerPathConfig;
4847

4948
// Duplicate in lang::rascalcore::compile::util::Names, factor out
5049
data PathConfig(
@@ -53,11 +52,8 @@ data PathConfig(
5352
loc generatedTestResources =|unknown:///|
5453
);
5554

56-
@doc{
57-
.Synopsis
58-
Summary of a Rascal module for use in IDE
59-
60-
.Description
55+
@synopsis{Summary of a Rascal module for use in IDE}
56+
@description{
6157
A `ModuleSummary` summarizes a Rascal module for the benefit of IDE support like
6258
* Show type of current symbol.
6359
* Goto definition.
@@ -104,53 +100,42 @@ ModuleSummary makeSummary(TModel tm, str qualifiedModuleName) {
104100
[vocabulary=getVocabulary(tm)]
105101
[synopses=synopses]
106102
[docLocs=docLocs];
107-
}
108-
109-
@doc{
110-
.Synopsis
111-
Make a ModuleSummary.
112103
}
104+
105+
ModuleSummary makeSummary(str qualifiedModuleName, loc tplLoc) {
106+
try {
107+
return makeSummary(readBinaryValueFile(#TModel, tplLoc), qualifiedModuleName);
108+
} catch IO(_): {
109+
return moduleSummary();
110+
}
111+
}
112+
113+
@synopsis{Make a ModuleSummary.}
113114
ModuleSummary makeSummary(str qualifiedModuleName, PathConfig pcfg){
114115
if(<true, tplLoc> := getTPLReadLoc(qualifiedModuleName, pcfg)){
115-
try {
116-
return makeSummary(readBinaryValueFile(#TModel, tplLoc), qualifiedModuleName);
117-
} catch IO(_): {
118-
return moduleSummary();
119-
}
116+
return makeSummary(qualifiedModuleName, tplLoc);
120117
}
121118
else {
122119
return moduleSummary();
123120
}
124121
}
125122

126-
@doc{
127-
.Synopsis
128-
Get all definitions for a given use.
129-
}
123+
@synopsis{Get all definitions for a given use.}
130124
set[loc] getDefinitions(ModuleSummary summary, loc use){
131125
return summary.useDef[use] ? {};
132126
}
133127

134-
@doc{
135-
.Synopsis
136-
Get the (pretty printed) type for a given use.
137-
}
128+
@synopsis{Get the (pretty printed) type for a given use.}
138129
str getType(ModuleSummary summary, loc use){
139130
return summary.locationTypes[use] ? "";
140131
}
141132

142-
@doc{
143-
.Synopsis
144-
Get all definitions for a given definition.
145-
}
133+
@synopsis{Get all definitions for a given definition.}
146134
set[loc] getUses(ModuleSummary s, loc def){
147135
return invert(s.useDef)[def];
148136
}
149137

150-
@doc{
151-
.Synopsis
152-
Get the doc string for a given definition.
153-
}
138+
@synopsis{Get the doc string for a given definition.}
154139
str getDocForDefinition(loc def){
155140
try {
156141
d = readFile(def);

‎src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ list[str] unexpectedDeclarationMsgs = [
455455
"Invalid initialization of _",
456456
"Undefined _",
457457
"Double declaration of _",
458+
"Duplicate declaration of _",
458459
"Multiple declarations of _ are applicable here",
459460
"Constructor _ overlaps with other declaration for type _, see _",
460461
"Incompatible field _ in _: _ in constructor _ clashes with _ in constructor _",

‎src/org/rascalmpl/interpreter/env/GlobalEnvironment.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.Set;
2525
import java.util.stream.Collectors;
26+
import java.util.stream.Stream;
2627

2728
import org.rascalmpl.ast.AbstractAST;
2829
import org.rascalmpl.ast.QualifiedName;
@@ -34,6 +35,7 @@
3435
import org.rascalmpl.values.IRascalValueFactory;
3536

3637
import io.usethesource.capsule.SetMultimap;
38+
import io.usethesource.vallang.IConstructor;
3739
import io.usethesource.vallang.IList;
3840
import io.usethesource.vallang.IString;
3941

@@ -329,4 +331,11 @@ public void clearLookupChaches() {
329331
public void clearModuleLoadMessage() {
330332
moduleEnvironment.values().forEach(ModuleEnvironment::clearLoadMessages);
331333
}
334+
335+
public Stream<IConstructor> streamModuleLoadMessages() {
336+
return moduleEnvironment
337+
.values()
338+
.stream()
339+
.flatMap(me -> me.streamLoadMessages());
340+
}
332341
}

‎src/org/rascalmpl/interpreter/env/ModuleEnvironment.java‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Optional;
3333
import java.util.Set;
3434
import java.util.function.Predicate;
35+
import java.util.stream.Stream;
3536

3637
import org.rascalmpl.ast.AbstractAST;
3738
import org.rascalmpl.ast.KeywordFormal;
@@ -143,6 +144,10 @@ public void clearLookupCaches() {
143144
public void clearLoadMessages() {
144145
this.loadMessages.clear();
145146
}
147+
148+
public Stream<IConstructor> streamLoadMessages() {
149+
return loadMessages.stream();
150+
}
146151

147152
public void extend(ModuleEnvironment other) {
148153
extendNameFlags(other);
@@ -583,22 +588,29 @@ public void getAllFunctions(String name, List<AbstractFunction> collection) {
583588
collection.addAll(lookupCachedFunctions(name));
584589
}
585590

591+
private List<AbstractFunction> lookupFunctionsNoCache(String name) {
592+
var result = new ArrayList<AbstractFunction>();
593+
super.getAllFunctions(name, result);
594+
595+
for (ModuleEnvironment mod : importedModulesResolved) {
596+
if (mod != null) {
597+
mod.getLocalPublicFunctions(name, result);
598+
}
599+
}
600+
return result;
601+
}
602+
586603
private List<AbstractFunction> lookupCachedFunctions(String name) {
587604
if (cachedPublicFunctions == null) {
588605
cachedPublicFunctions = io.usethesource.capsule.Map.Transient.of();
589606
}
590-
return cachedPublicFunctions.computeIfAbsent(name, n -> {
591-
var result = new ArrayList<AbstractFunction>();
592-
super.getAllFunctions(n, result);
593-
594-
for (ModuleEnvironment mod : importedModulesResolved) {
595-
596-
if (mod != null) {
597-
mod.getLocalPublicFunctions(n, result);
598-
}
599-
}
600-
return result;
601-
});
607+
608+
if (!initialized) {
609+
return lookupFunctionsNoCache(name);
610+
}
611+
else {
612+
return cachedPublicFunctions.computeIfAbsent(name, this::lookupFunctionsNoCache);
613+
}
602614
}
603615

604616
@Override
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module lang::rascal::tests::basic::FunctionCachesAndGlobals
2+
3+
default int f(int _) = 42;
4+
int x = f(0);
5+
int f(0) = 0;
6+
7+
8+
test bool noCacheDuringInit() = f(0) == 0;
9+
test bool globalInitLast() = x == 0;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
module lang::rascal::tests::loading::LoadingErrorModules
2+
3+
import IO;
4+
import util::Eval;
5+
import util::PathConfig;
6+
import Message;
7+
8+
PathConfig init() = pathConfig(srcs=[|memory://LoadingErrorModules/|]);
9+
10+
loc moduleFile(str name) = |memory://LoadingErrorModules/| + "<name>.rsc";
11+
12+
test bool moduleWithParseError() {
13+
exec = createRascalRuntime(pcfg=init());
14+
15+
writeFile(moduleFile("A"), "modle A");
16+
17+
try {
18+
exec.eval(#void, "import A;");
19+
return false;
20+
}
21+
catch ModuleLoadMessages([error(_,_)]): {
22+
// that's ok
23+
;
24+
}
25+
26+
writeFile(moduleFile("A"), "module A");
27+
28+
return exec.eval(#void, "import A;") == ok();
29+
}
30+
31+
test bool moduleWithTransientParseError() {
32+
exec = createRascalRuntime(pcfg=init());
33+
34+
writeFile(moduleFile("A"), "module A");
35+
assert exec.eval(#void, "import A;") == ok();
36+
writeFile(moduleFile("A"), "modle A");
37+
38+
try {
39+
exec.eval(#void, "import A;");
40+
return false;
41+
}
42+
catch ModuleLoadMessages([error(_,_)]): {
43+
// that's ok
44+
;
45+
}
46+
47+
writeFile(moduleFile("A"), "module A");
48+
49+
return exec.eval(#void, "import A;") == ok();
50+
}
51+
52+
test bool moduleWithTransitiveParseError() {
53+
exec = createRascalRuntime(pcfg=init());
54+
55+
writeFile(moduleFile("A"), "modle A");
56+
writeFile(moduleFile("B"), "module B import A;");
57+
58+
try {
59+
exec.eval(#void, "import B;");
60+
return false;
61+
}
62+
catch ModuleLoadMessages([error(_,_)]): {
63+
// that's ok
64+
;
65+
}
66+
67+
writeFile(moduleFile("A"), "module A");
68+
69+
return exec.eval(#void, "import A;") == ok()
70+
&& exec.eval(#void, "import B;") == ok();
71+
}
72+
73+
test bool moduleWithStaticError() {
74+
exec = createRascalRuntime(pcfg=init());
75+
76+
writeFile(moduleFile("A"), "module A str aap = 42;");
77+
78+
try {
79+
exec.eval(#void, "import A;");
80+
return false;
81+
}
82+
catch ModuleLoadMessages([error(_,_)]): {
83+
// that's ok
84+
;
85+
}
86+
87+
writeFile(moduleFile("A"), "module A str aap = \"42\";");
88+
89+
return exec.eval(#void, "import A;") == ok();
90+
}
91+
92+
test bool importNonExistingModule() {
93+
exec = createRascalRuntime(pcfg=init());
94+
95+
try {
96+
exec.eval(#void, "import Z;");
97+
return false;
98+
}
99+
catch ModuleLoadMessages([error(_,_)]): {
100+
// that's ok
101+
;
102+
}
103+
104+
writeFile(moduleFile("Z"), "module Z public str aap = \"aap\";");
105+
106+
return exec.eval(#void, "import Z;") == ok()
107+
&& result("aap") == exec.eval(#str, "aap");
108+
}
109+
110+
111+
test bool importBrokenModuleName() {
112+
exec = createRascalRuntime(pcfg=init());
113+
114+
writeFile(moduleFile("AAA"), "module AA public str aap = \"aap\";");
115+
116+
try {
117+
exec.eval(#void, "import AAA;");
118+
return false;
119+
}
120+
catch ModuleLoadMessages([error(_,_)]): {
121+
// that's ok
122+
;
123+
}
124+
125+
writeFile(moduleFile("AAA"), "module AAA public str aap = \"aap\";");
126+
127+
return exec.eval(#void, "import AAA;") == ok()
128+
&& result("aap") == exec.eval(#str, "aap");
129+
}
130+

0 commit comments

Comments
 (0)