Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"request": "launch",
"mainClass": "org.rascalmpl.shell.RascalShell",
"projectName": "rascal",
"vmArgs": "-Xss80m -Xmx2g -ea",
"vmArgs": "-Xss80m -Xmx2g -Dorg.rascalmpl.profiling.flameGraph.script=C:/Users/sung-/Desktop/FlameGraph-1.0/flamegraph.pl",
"console": "integratedTerminal"
},
{
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>typepal</artifactId>
<version>0.17.0-RC3</version>
<!-- <version>0.17.0-RC3</version> -->

Check warning on line 458 in pom.xml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=usethesource_rascal&issues=AZ-4UqG1zwevSuGvNi6E&open=AZ-4UqG1zwevSuGvNi6E&pullRequest=2832
<version>0.17.0-RC4-SNAPSHOT</version>
<!-- <scope>provided</scope> for shade plugin it can't be provided. At least the rascal dependency in typepal should be provided -->
<scope>compile</scope>
</dependency>
Expand Down
137 changes: 137 additions & 0 deletions src/org/rascalmpl/compiler/Scratch.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
module Scratch

import Prelude;
import lang::rascalcore::check::Checker;
import lang::rascalcore::check::ModuleLocations;
import util::FileSystem;
import util::SystemAPI;
import util::Benchmark;

import analysis::typepal::Solver;

loc rascalLib() {
loc rascalLib = resolveLocation(|std:///|);
if (/org.rascalmpl.library.?$/ := rascalLib.path) {
rascalLib = rascalLib.parent.parent.parent;
}
return rascalLib;
}

loc typepalLib() {
return |mvn://org.rascalmpl--typepal--0.17.0-RC4-SNAPSHOT/|;
}

int typecheckBirdCore(bool force = false) = realTimeOf(void() { typecheck(|home:///Desktop/bird/bird-core|, ["src/main/rascal"], force = force); });

int typecheckRascalLibraryAnalysis(bool force = false) = realTimeOf(void() { typecheck(|home:///Desktop/usethesource2/rascal|, ["src/org/rascalmpl/library"], dir = "analysis", force = force); });

int typecheckTypepal(bool force = false) = realTimeOf(void() { typecheck(|home:///Desktop/usethesource2/typepal|, ["src"], force = force); });
// 1454032
// 1207079 - remove check in Result constructor -- UNSOUND
// 1149042 - add cache for getSimpleVariable

bool typecheck(loc project, list[str] srcs, str dir = "", bool force = false) {

// Create path config

println();
println("## Create path config");
println();

PathConfig pcfg = pathConfig(
srcs = [project + src | str src <- srcs],
bin = project + "target/classes",
libs = [rascalLib()]
);

iprintln(pcfg);
println();

// Delete `bin`

if (force) {
println("## Delete `bin`");
println();

remove(pcfg.bin);

iprintln(sort([*find(pcfg.bin, "tpl")]));
println();
}

// Typecheck `srcs`

println("## Typecheck `srcs`");
println();

list[str] moduleNames = [getRascalModuleName(l, pcfg) | loc src <- pcfg.srcs, loc l <- find(src + dir, "rsc")];

iprintln(sort(moduleNames));
println();

calculatorFailureCount = 0;
calculatorFailureNanoTime = 0;
requirementFailureCount = 0;
requirementFailureNanoTime = 0;
ModuleStatus ms = rascalTModelForNames(moduleNames, rascalCompilerConfig(pcfg)[enableErrorFixes = false], dummy_compile1);

iprintln(sort([*find(pcfg.bin, "tpl")]));
println();

return (true | it && found | str moduleName <- moduleNames, <bool found, _, _> := getTModelForModule(moduleName, ms));
}

void z1(int n = 10) {
set[loc] locs = {};
for (int i <- [0..n]) {
locs += |unknown:///| + "<i>";
// if (i % 1000 == 0) {
// println(i);
// }
}
}

void z2(int n = 10) {
list[int] elems = [];
for (int i <- [0..n]) {
elems += i;
if (i % (10*1000) == 0) {
println(i);
}
}
}

void z3(int n = 10) {
set[value] elems = {};
for (int i <- [0..n]) {
elems += "<i>";
}
}

/*

6-tuples zijn duur, projectie is mogelijk goedkoper

- overloaded type zijn triples (bijv. alleen 3e element gebruikt)
- over het algemeen kort, sommige 100 overloads
- defines zijn 6-tuples


Misschien vergelijkbaar met lange ADT constructors


komen zowel in Rascal typechecker als in typepal voor




binaire relaties geoptimaliseerd in Vallang. n-ary relaties niet zo erg.
6-tuple vervangen door 6 binary relaties????



Aanpak:

- hoog niveau gaan meten welke delen van de checker de meeste tijd kosten

*/
30 changes: 17 additions & 13 deletions src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,6 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
set[MODID] filteredModuleScopes = {};
loc2moduleName = invertUnique(ms.moduleLocs);

bool isContainedInComponentScopes(loc inner, map[loc,loc] m){
return any(cs <- component_scopes, isContainedIn(inner, cs, m));
};

bool isContainedInFilteredModuleScopes(loc inner, map[loc,loc] m){
return any(cs <- filteredModuleScopes, isContainedIn(inner, cs, m));
};

for(currentModule <- component){
start_save = cpuTime();
tm = transient_tms[currentModule];
Expand All @@ -447,15 +439,27 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
extendedModuleScopes += {*tm.paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules
filteredModuleScopes = {m | MODID m <- (currentModule + imports), hasProperty(m, ms, checked())} + extendedModuleScopes;

map[str,loc] componentScopesByUri = (s.uri: s | loc s <- component_scopes, loc s := tm.logical2physical[s] ? s);
map[str,loc] filteredModuleScopesByUri = (s.uri: s | loc s <- filteredModuleScopes, loc s := tm.logical2physical[s] ? s);

bool isContainedInComponentScopes(loc key) {
key = tm.logical2physical[key] ? key;
return key.uri in componentScopesByUri ? isContainedIn(key, componentScopesByUri[key.uri]) : false;
}
bool isContainedInFilteredModuleScopes(loc key) {
key = tm.logical2physical[key] ? key;
return key.uri in filteredModuleScopesByUri ? isContainedIn(key, filteredModuleScopesByUri[key.uri]) : false;
}

TModel m1 = tmodel();
m1.version = getCurrentTplVersion();
m1.rascalTplVersion = compilerConfig.rascalTplVersion;
m1.modelName = moduleId2moduleName(currentModule);
m1.moduleLocs = (m1.modelName : currentModule);

m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInFilteredModuleScopes(key, tm.logical2physical));
m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInFilteredModuleScopes(key));

m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key, tm.logical2physical), any(fms <- filteredModuleScopes, isContainedIn(key, fms)));
m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key), isContainedInFilteredModuleScopes(key));
m1.facts += m1.specializedFacts;

m1.messages = [msg | msg <- tm.messages, isContainedIn(msg.at, currentModule, tm.logical2physical)];
Expand Down Expand Up @@ -492,11 +496,11 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
// Filter model for current module and replace functions in defType by their defined type

defs = for(tup:<loc _scope, str _id, str _orgId, IdRole idRole, loc defined, DefInfo _defInfo> <- tm.defines){
if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined, tm.logical2physical)
if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined)
)
: ( idRole in keepInTModelRoles
&& ( isContainedInComponentScopes(defined, tm.logical2physical)
|| isContainedInFilteredModuleScopes(defined, tm.logical2physical)
&& ( isContainedInComponentScopes(defined)
|| isContainedInFilteredModuleScopes(defined)
)
)
)
Expand Down
1 change: 1 addition & 0 deletions src/org/rascalmpl/interpreter/IEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* Interface needs to be properly split up in different compoments.
*/
public interface IEvaluator<T> extends IEvaluatorContext {
public static final boolean UNSAFE_MODE = true;
public static final String LOADING_JOB_CONSTANT = "loading modules";

/**
Expand Down
47 changes: 36 additions & 11 deletions src/org/rascalmpl/interpreter/env/ModuleEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void clearLookupCaches() {
importedModules.replaceAll((k, v) -> Optional.empty());
cachedGeneralKeywordParameters = null;
cachedPublicFunctions = null;
cachedImportedModulesResolved = null;
}

/**
Expand Down Expand Up @@ -382,12 +383,14 @@ public void addImport(String name, ModuleEnvironment env) {
typeStore.importStore(env.typeStore);
this.cachedGeneralKeywordParameters = null;
this.cachedPublicFunctions = null;
this.cachedImportedModulesResolved = null;
}

void removeModule(String name) {
importedModules.computeIfPresent(name, (k, v) -> Optional.empty());
this.cachedGeneralKeywordParameters = null;
this.cachedPublicFunctions = null;
this.cachedImportedModulesResolved = null;
}

public void addExtend(String name) {
Expand All @@ -397,6 +400,7 @@ public void addExtend(String name) {
extended.add(name);
this.cachedGeneralKeywordParameters = null;
this.cachedPublicFunctions = null;
this.cachedImportedModulesResolved = null;
}

public List<AbstractFunction> getTests() {
Expand Down Expand Up @@ -453,6 +457,7 @@ public void unImport(String moduleName) {
}
cachedGeneralKeywordParameters = null;
cachedPublicFunctions = null;
cachedImportedModulesResolved = null;
}

public void unExtend(String moduleName) {
Expand Down Expand Up @@ -884,24 +889,44 @@ public ModuleEnvironment getImport(String moduleName) {
return result.get();
}

private List<ModuleEnvironment> cachedImportedModulesResolved = null;

private Iterable<ModuleEnvironment> importedModulesResolved =
() -> new Iterator<ModuleEnvironment>() {
Iterator<Entry<String, Optional<ModuleEnvironment>>> iterator = importedModules.entrySet().iterator();
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public ModuleEnvironment next() {
var entry = iterator.next();
() -> getCachedImportedModulesResolved().iterator();
// () -> new Iterator<ModuleEnvironment>() {
// Iterator<Entry<String, Optional<ModuleEnvironment>>> iterator = importedModules.entrySet().iterator();
// @Override
// public boolean hasNext() {
// return iterator.hasNext();
// }
// @Override
// public ModuleEnvironment next() {
// var entry = iterator.next();
// var result = entry.getValue();
// if (result.isEmpty()) {
// result = Optional.ofNullable(heap.getModule(entry.getKey()));
// entry.setValue(result);
// }
// return result.orElse(null);
// }
// };

private List<ModuleEnvironment> getCachedImportedModulesResolved() {
if (cachedImportedModulesResolved == null) {
cachedImportedModulesResolved = new ArrayList<>();
for (Entry<String, Optional<ModuleEnvironment>> entry : importedModules.entrySet()) {
var result = entry.getValue();
if (result.isEmpty()) {
result = Optional.ofNullable(heap.getModule(entry.getKey()));
entry.setValue(result);
}
return result.orElse(null);
if (result.isPresent()) {
cachedImportedModulesResolved.add(result.get());
}
}
};
}
return cachedImportedModulesResolved;
}

@Override
public void storeVariable(QualifiedName name, Result<IValue> result) {
Expand Down
3 changes: 2 additions & 1 deletion src/org/rascalmpl/interpreter/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.rascalmpl.ast.Field;
import org.rascalmpl.ast.Name;
import org.rascalmpl.exceptions.ImplementationError;
import org.rascalmpl.interpreter.IEvaluator;
import org.rascalmpl.interpreter.IEvaluatorContext;
import org.rascalmpl.interpreter.control_exceptions.MatchFailed;
import org.rascalmpl.interpreter.env.Environment;
Expand Down Expand Up @@ -86,7 +87,7 @@ public abstract class Result<T extends IValue> implements Iterator<Result<IValue

protected Result(Type type, T value, Iterator<Result<IValue>> iter, IEvaluatorContext ctx) {
// Check for null in case of void result or uninit.
if (value != null && !value.getType().isSubtypeOf(type)) {
if (!IEvaluator.UNSAFE_MODE && value != null && !value.getType().isSubtypeOf(type)) {
throw new UnexpectedType(type, value.getType(), ctx.getCurrentAST());
}

Expand Down
Loading
Loading