Skip to content

Commit 20efac9

Browse files
committed
debugging progress
1 parent 0f9ee46 commit 20efac9

4 files changed

Lines changed: 124 additions & 9 deletions

File tree

src/main/java/org/variantsync/diffdetective/experiments/views/ViewAnalysis.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public void initializeResults(Analysis analysis) {
4343
private void runQueryExperiment(Analysis analysis, final DiffTree d, final Query q) {
4444
final long preprocessingTime, naiveTime, optimizedTime;
4545

46+
//Show.diff(d, "D").showAndAwait();
47+
4648
final Clock c = new Clock();
4749

4850
final BiPredicate<Time, Projection> inV = DiffView.computeWhenNodesAreRelevant(d, q);
@@ -114,9 +116,12 @@ else if (a.isConditionalAnnotation()) {
114116
features.remove(FixTrueFalse.False.var.toString());
115117

116118
final List<Query> queries = new ArrayList<>(3);
117-
addRandomQuery(deselectedPCs, this::randomVariantQuery, queries);
118-
addRandomQuery(features, this::randomFeatureQuery, queries);
119-
addRandomQuery(artifacts, this::randomArtifactQuery, queries);
119+
// addRandomQuery(deselectedPCs, this::randomVariantQuery, queries);
120+
// addRandomQuery(features, this::randomFeatureQuery, queries);
121+
// addRandomQuery(artifacts, this::randomArtifactQuery, queries);
122+
addAll(deselectedPCs, this::allVariantQueries, queries);
123+
addAll(features, this::allFeatureQueries, queries);
124+
addAll(artifacts, this::allArtifactQueries, queries);
120125
return queries;
121126
}
122127

@@ -133,6 +138,34 @@ private static <QueryData, QueryCandidates extends Collection<QueryData>> void a
133138
}
134139
}
135140

141+
private static <QueryData, QueryCandidates extends Collection<? extends QueryData>> void addAll(
142+
QueryCandidates source,
143+
Function<? super QueryCandidates, ? extends Collection<? extends Query>> prepare,
144+
Collection<Query> target
145+
) {
146+
if (!source.isEmpty()) {
147+
target.addAll(prepare.apply(source));
148+
}
149+
}
150+
151+
private List<VariantQuery> allVariantQueries(final List<Node> deselectedPCs) {
152+
/*
153+
* Select a random satisfiable configuration (i.e., a non-false config).
154+
* Unsatisfiable configs cause empty views which
155+
* (1) we suspect to be rather useless and thus unused in practice
156+
* (2) cause a crash in view generation because everything is removed, even the mandatory root.
157+
*/
158+
final List<VariantQuery> all = new ArrayList<>();
159+
for (final Node deselectedPC : deselectedPCs) {
160+
final FixTrueFalse.Formula p = FixTrueFalse.EliminateTrueAndFalseInplace(deselectedPC);
161+
if (SAT.isSatisfiable(p)) {
162+
all.add(new VariantQuery(p));
163+
}
164+
}
165+
166+
return all;
167+
}
168+
136169
private Query randomVariantQuery(final List<Node> deselectedPCs) {
137170
/*
138171
Do we need this?
@@ -168,6 +201,10 @@ private Query randomVariantQuery(final List<Node> deselectedPCs) {
168201
return new VariantQuery(winner);
169202
}
170203

204+
private List<FeatureQuery> allFeatureQueries(final Set<String> features) {
205+
return features.stream().map(FeatureQuery::new).toList();
206+
}
207+
171208
private Query randomFeatureQuery(final Set<String> features) {
172209
/*
173210
Pick a random feature for our query.
@@ -177,6 +214,10 @@ private Query randomFeatureQuery(final Set<String> features) {
177214
return new FeatureQuery(CollectionUtils.getRandomElement(random, features));
178215
}
179216

217+
private List<ArtifactQuery> allArtifactQueries(final Set<String> artifacts) {
218+
return artifacts.stream().map(ArtifactQuery::new).toList();
219+
}
220+
180221
private Query randomArtifactQuery(final Set<String> artifacts) {
181222
/*
182223
Pick a random artifact for our query.

src/main/java/org/variantsync/diffdetective/variation/diff/view/DiffView.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,31 @@ Using our own formatter without diff headers (paired with a maximum context (?))
104104
//textDiff = HUNK_HEADER_REGEX.matcher(textDiff).replaceAll("");
105105
}
106106
// Logger.info("Full Diff\n" + textDiff);
107-
108-
final DiffTree view = DiffTreeParser.createDiffTree(textDiff,
109-
new DiffTreeParseOptions(
110-
true,
111-
true
112-
));
107+
final DiffTree view;
108+
try {
109+
view = DiffTreeParser.createDiffTree(textDiff,
110+
new DiffTreeParseOptions(
111+
true,
112+
true
113+
));
114+
} catch (DiffParseException e) {
115+
Logger.error("""
116+
Could not parse diff obtained with query {}:
117+
Text before:
118+
{}
119+
120+
Text after:
121+
{}
122+
123+
Diff:
124+
{}
125+
""",
126+
q,
127+
projectionViewText[0],
128+
projectionViewText[1],
129+
textDiff);
130+
throw e;
131+
}
113132
view.setSource(new ViewSource(d, q));
114133
// Logger.info("success");
115134
return view;

src/test/java/ViewTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ private static void showViews(
5555
);
5656
}
5757

58+
@ParameterizedTest
59+
@ValueSource(strings = {
60+
"emacsbug1"
61+
})
62+
void debugTest(String filename) throws IOException, DiffParseException {
63+
final String filenameWithEnding = filename + ".diff";
64+
final Path testfile = resDir.resolve(filenameWithEnding);
65+
Logger.debug("Testing " + testfile);
66+
// is( /* Check both of the above conditions, for symbols. */)
67+
final DiffTree D = DiffTree.fromFile(testfile, DiffTreeParseOptions.Default);
68+
D.assertConsistency();
69+
70+
final Query debugQuery = new ArtifactQuery(" /* Check both of the above conditions, for symbols. */");
71+
Show.diff(DiffView.optimized(D, debugQuery)).showAndAwait();
72+
Show.diff(DiffView.naive(D, debugQuery)).showAndAwait();
73+
}
74+
5875

5976
@ParameterizedTest
6077
@ValueSource(strings = {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifdef GC_CHECK_MARKED_OBJECTS
2+
3+
/* Check that the object pointed to by PO is known to be a Lisp
4+
structure allocated from the heap. */
5+
#define CHECK_ALLOCATED() \
6+
do { \
7+
m = mem_find (po); \
8+
if (m == MEM_NIL) \
9+
emacs_abort (); \
10+
} while (0)
11+
12+
/* Check that the object pointed to by PO is live, using predicate
13+
function LIVEP. */
14+
#define CHECK_LIVE(LIVEP) \
15+
do { \
16+
if (!LIVEP (m, po)) \
17+
emacs_abort (); \
18+
} while (0)
19+
20+
/* Check both of the above conditions, for non-symbols. */
21+
#define CHECK_ALLOCATED_AND_LIVE(LIVEP) \
22+
do { \
23+
CHECK_ALLOCATED (); \
24+
CHECK_LIVE (LIVEP); \
25+
} while (0) \
26+
27+
/* Check both of the above conditions, for symbols. */
28+
#define CHECK_ALLOCATED_AND_LIVE_SYMBOL() \
29+
do { \
30+
if (!c_symbol_p (ptr)) \
31+
{ \
32+
CHECK_ALLOCATED (); \
33+
CHECK_LIVE (live_symbol_p); \
34+
} \
35+
} while (0) \
36+
37+
#endif
38+

0 commit comments

Comments
 (0)