Skip to content

Fresh constants for configuration initializers#3557

Merged
rv-jenkins merged 14 commits intodevelopfrom
config-freshvars
Aug 9, 2023
Merged

Fresh constants for configuration initializers#3557
rv-jenkins merged 14 commits intodevelopfrom
config-freshvars

Conversation

@gtrepta
Copy link
Copy Markdown
Contributor

@gtrepta gtrepta commented Aug 3, 2023

fixes #3520

@rv-jenkins rv-jenkins changed the base branch from master to develop August 3, 2023 18:42
@gtrepta gtrepta marked this pull request as ready for review August 4, 2023 19:53
Copy link
Copy Markdown
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the solution a lot.
Added some minor comments/questions.

Comment thread k-distribution/tests/regression-new/freshConfig-fail/test.k.out Outdated
Comment thread k-distribution/tests/regression-new/freshConfig/Makefile
Comment thread k-distribution/tests/regression-new/freshConfig-fail/test.k
Comment thread k-distribution/tests/regression-new/freshConfig/test.k
@gtrepta gtrepta requested a review from radumereuta August 7, 2023 22:12
Copy link
Copy Markdown
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified ResolveAnonVar to carry over the location information from variables

@@ -104,16 +106,16 @@ public class ResolveAnonVar {
             @Override
             public K apply(KVariable k) {
                 if (ANON_VAR.equals(k)) {
-                    return newDotVariable("");
+                    return newDotVariable("", k);
                 }
                 if (FRESH_ANON_VAR.equals(k)) {
-                    return newDotVariable("?");
+                    return newDotVariable("?", k);
                 }
                 if (FRESH_ANON_CONSTANT.equals(k)) {
-                    return newDotVariable("!");
+                    return newDotVariable("!", k);
                 }
                 if (FRESH_LIST_VAR.equals(k)) {
-                    return newDotVariable("@");
+                    return newDotVariable("@", k);
                 }
                 return super.apply(k);
             }
@@ -121,9 +123,10 @@ public class ResolveAnonVar {
     }
 
     private int counter = 0;
-    KVariable newDotVariable(String prefix) {
+    KVariable newDotVariable(String prefix, K k) {
         KVariable newLabel;
-        Att att = Att().add(Att.ANONYMOUS());
+        Att att = Att().add(Att.ANONYMOUS()).add(Source.class, k.att().get(Source.class))
+                .add(Location.class, k.att().get(Location.class));
         if (prefix.equals("?")) {
             att = att.add(Att.FRESH());
         }

And got the error message to show like this:

[Error] Compiler: Can't resolve fresh configuration variable not of sort Int
  while executing phase "Resolve fresh variables in cell initializers" on sentence at
	<none>
	<none>
	Source(/home/radu/work/test/test.k)
	Location(16,14,16,16)
	16 |	  <freshFoo> !_:Foo </freshFoo>
	   .	             ^~

Comment thread k-distribution/tests/regression-new/checks/freshConfig-fail/test.k
@gtrepta gtrepta requested a review from radumereuta August 8, 2023 22:45
Copy link
Copy Markdown
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great

@Baltoli Baltoli mentioned this pull request Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault when using fresh variables in initial configuration

3 participants