Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

better extend cycle detection#2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
jurgenvinju wants to merge25 commits intomain
base:main
Choose a base branch
Loading
frombetter-extend-cycle-detection
Draft
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
411cfa9
improving the cycle detector
jurgenvinjuSep 4, 2025
487f31e
cleaning
jurgenvinjuSep 4, 2025
0dac474
re-thinking extend cycle detection and recovery
jurgenvinjuSep 4, 2025
da4ab2c
Merge branch 'main' into better-extend-cycle-detection
jurgenvinjuSep 4, 2025
e5c7e8e
added "fawlty" flag to ModuleEnvironment to be able to filter fawlty …
jurgenvinjuSep 4, 2025
8c7bc85
fixed a nasty bug introduced yesterday; at every import a module was …
jurgenvinjuSep 5, 2025
2d4b9f0
added depth-first-search on a detected cycle to report only the edges…
jurgenvinjuSep 5, 2025
204b9df
removed rethrowing to get rid of double reporting of the same error h…
jurgenvinjuSep 5, 2025
e650c52
instrumenting the loading process with more import/extend graph analy…
jurgenvinjuSep 8, 2025
5b56bce
clean up to allow focus on new errors
jurgenvinjuSep 9, 2025
adcffa5
Merge branch 'main' into better-extend-cycle-detection
jurgenvinjuSep 9, 2025
f455209
fixed a bug in loading cyclic imports, which finally excaves the unde…
jurgenvinjuSep 9, 2025
ffe6173
accurately report import/extend cycles when they happen _and_ when th…
jurgenvinjuSep 9, 2025
17e89be
cleanup
jurgenvinjuSep 9, 2025
b5be7f2
slowly sanitizing the errors around module loading
jurgenvinjuSep 11, 2025
30e82be
better error handling
jurgenvinjuSep 12, 2025
81468ae
stack traces become causes to issues, which they are
jurgenvinjuSep 12, 2025
b93e416
stack traces become causes to issues, which they are
jurgenvinjuSep 12, 2025
64c4daf
Removing extend cycle
PaulKlintSep 12, 2025
41406e9
Changes needed to eliminate cycle
PaulKlintSep 14, 2025
068a3d1
Merge branch 'main' into remove-extend-cycle
PaulKlintSep 14, 2025
7ef0ece
Release --help
jurgenvinjuSep 15, 2025
de3b208
Merge remote-tracking branch 'origin/remove-extend-cycle' into better…
jurgenvinjuSep 15, 2025
2271487
added and _not_ used a complete module cyclic dependency test, for de…
jurgenvinjuSep 15, 2025
c78fce9
cleanup
jurgenvinjuSep 16, 2025
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
PrevPrevious commit
NextNext commit
instrumenting the loading process with more import/extend graph analy…
…ses; only for debugging purposes
  • Loading branch information
@jurgenvinju
jurgenvinju committedSep 8, 2025
commite650c5292200bd35d0c524738940ade515559f3b
19 changes: 18 additions & 1 deletionsrc/org/rascalmpl/interpreter/env/GlobalEnvironment.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,12 +245,29 @@ public List<String> findCyclicExtendPathFrom(String parent, String child) {
.collect(Collectors.toList());
}

/**
* This starts with an edge that is not yet in the graph because we are loading these
* modules. Then the rest of graph is loaded from what we already have in memory.
* @param parent the first and last node of a detected cycle.
* @return
*/
public List<String> findCyclicImportPathFrom(String parent, String child) {
SetMultimap.Transient<String, String> graph = getImportGraphFrom(child);
graph.__put(parent, child); // add the last edge that was not yet registered
IRascalValueFactory vf = IRascalValueFactory.getInstance();
return depthFirstSearch(parent, new HashSet<>(), vf.list(vf.string(parent)), graph)
.stream()
.map(IString.class::cast)
.map(IString::getValue)
.collect(Collectors.toList());
}

/*
* dfs uses an immutable IList for the path such that we don't have to maintain a stack, next to the
* recursion.
* otherwise this is a standard depth-first search for a directed graph
*/
private IList depthFirstSearch(String parent, Set<String> visited, IList path, SetMultimap.Transient<String, String> graph) {
public IList depthFirstSearch(String parent, Set<String> visited, IList path, SetMultimap.Transient<String, String> graph) {
visited.add(parent);
var vf = IRascalValueFactory.getInstance();

Expand Down
41 changes: 41 additions & 0 deletionssrc/org/rascalmpl/interpreter/env/ModuleEnvironment.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -999,6 +999,10 @@ public Set<String> getExtends() {
return Collections.<String>emptySet();
}

/**
* This collects only "extends" edges starting from the current module
* @return
*/
public SetMultimap.Transient<String, String> collectExtendsGraph() {
List<String> todo = new LinkedList<String>();
Set<String> done = new HashSet<String>();
Expand All@@ -1023,6 +1027,43 @@ public SetMultimap.Transient<String, String> collectExtendsGraph() {
return result;
}

/**
* This collects only "extends" edges starting from the current module
* @return
*/
public SetMultimap.Transient<String, String> collectModuleDependencyGraph() {
List<String> todo = new LinkedList<String>();
Set<String> done = new HashSet<String>();
SetMultimap.Transient<String, String> result = PersistentTrieSetMultimap.transientOf();
todo.add(this.getName());
GlobalEnvironment heap = getHeap();

while (!todo.isEmpty()) {
String mod = todo.remove(0);
done.add(mod);
ModuleEnvironment env = heap.getModule(mod);
if (env != null) {
for (String e : env.getExtends()) {
result.__put(mod, e);
if (!done.contains(e)) {
todo.add(e);
}
}

for (String e : env.getImports()) {
result.__put(mod, e);
if (!done.contains(e)) {
todo.add(e);
}
}
}
}

return result;
}



public Set<String> getExtendsTransitive() {
List<String> todo = new LinkedList<String>();
Set<String> done = new HashSet<String>();
Expand Down
16 changes: 15 additions & 1 deletionsrc/org/rascalmpl/semantics/dynamic/Import.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
import java.io.OutputStreamWriter;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
Expand DownExpand Up@@ -305,8 +306,20 @@ else if (eval.getCurrentEnvt() == eval.__getRootScope()) {
// abort the extend and the loading of the current module alltogether
throw new CyclicExtend(thisEnv.getName(), path, x);
}
else if (!other.isInitialized()) {
// TODO if this really happens we have to find a way to fix it.
// A user can't fix this.
throw new ModuleImport(other.getName(), "Internal error: extending a module which is not fully initialized yet.", x);
}
// else if (other.collectModuleDependencyGraph().values().contains(thisEnv.getName())) {
// // TODO THIS WHOLE BLOCK IS DEBUG CODE TO BE REMOVED
// // import+extend cycle
// var parent = other.getName();
// var cycle = heap.depthFirstSearch(other.getName(), new HashSet<>(), eval.getValueFactory().list(eval.getValueFactory().string(parent)) , other.collectModuleDependencyGraph());
// throw new CyclicExtend(thisEnv.getName(), cycle.stream().map(IString.class::cast).map(IString::getValue).collect(Collectors.toList()), x);
// }
else {
// good to go!
// good to go
thisEnv.extend(other);
}
}
Expand DownExpand Up@@ -356,6 +369,7 @@ public static ModuleEnvironment loadModule(ISourceLocation x, String name, IEval
handleLoadError(eval, name, e.getMessage(), x);
}
finally {
env.setInitialized();
eval.jobStep(jobName, name, 1);
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp