Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static scheduler #1830

Open
wants to merge 299 commits into
base: master
Choose a base branch
from
Open

Static scheduler #1830

wants to merge 299 commits into from

Conversation

lsk567
Copy link
Collaborator

@lsk567 lsk567 commented Jun 8, 2023

This is a PR for keeping track of the progress on a static scheduler.

Refer to the project board for more details. This PR contains all the items in the Done column.

@cmnrd
Copy link
Collaborator

cmnrd commented Jun 15, 2023

@ChadliaJerad it looks like several commits from master got rebased and pushed to this branch and are now duplicated. Please use git merge to update a feature branch or rebase the feature branch on top of master (not the other way around). This way, we can keep a clean history.

@ChadliaJerad
Copy link
Collaborator

@ChadliaJerad it looks like several commits from master got rebased and pushed to this branch and are now duplicated. Please use git merge to update a future branch or rebase the future branch on top of master (not the other way around). This way, we can keep a clean history.

Yes! I was indeed wondering why are all these commits there.

@lsk567
Copy link
Collaborator Author

lsk567 commented Jun 16, 2023

Thanks @cmnrd for catching this issue. I just cherry-picked the relevant commits and force-pushed to this branch. The history should be clean now.

Copy link
Collaborator

@oowekyala oowekyala left a comment

Choose a reason for hiding this comment

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

A couple of comments to improve code quality

@@ -0,0 +1,40 @@
package org.lflang.analyses.evm;

public abstract class Instruction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A suggestion to get rid of the boilerplate: use Kotlin :)

enum class OpCode {
    ADV,
    ADV2,
    BIT
}

// Sealed classes are abstract by default, and the compiler
// knows all their subtypes to allow for exhaustivity checking
// when pattern-matching.
sealed class EvmInstruction(val opcode: OpCode)

// Data classes get a nice toString generated
data class InstructionADV(
    val reactor: ReactorInstance,
    val nextTimeValue: TimeValue
) : EvmInstruction(OpCode.ADV2)

// Since this instruction has no fields it can be a singleton
object InstructionBIT : EvmInstruction(OpCode.BIT)

// ...

This entire package could fit in 100 lines in a single file :)

You can refer to Kotlin classes from Java as if they were regular Java classes. But if you want to stick to Java I would recommend making the supertype sealed (public abstract sealed class Instruction). (doc)

Also I would suggest giving this Instruction class a more specific name like EvmInstruction for clarity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the mini Kotlin tutorial here, @oowekyala ! Yes, Kotlin looks quite interesting. I will try to reimplement the instructions using your solution.


import java.util.PriorityQueue;

public class EventQueue extends PriorityQueue<Event> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest not extending this class but hiding it inside. As it is you inherit also the offer method which inserts an element, but does not constrain uniqueness as your implementation claims.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that makes sense!


import org.lflang.TimeValue;

public class Tag implements Comparable<Tag> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This class looks like it could be a record

public record Tag(long timestamp, long microstep, boolean forever)
   implements Comparable<Tag> { // ...

This would spare you the fields and ctor declaration, and the equals declaration.

String line;

// Pattern with which an edge starts:
Pattern pattern = Pattern.compile("^((\s*)(\\d+)(\s*)->(\s*)(\\d+))");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Constant patterns should be put into constant fields to avoid recompiling them

Comment on lines +262 to +269
FileReader fileReader;
BufferedReader bufferedReader;
// Read the file
try {
fileReader = new FileReader(dotFileName);
// Buffer the input stream from the file
bufferedReader = new BufferedReader(fileReader);
} catch (IOException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be put in a try-with-resources (TWR). The close method should be in a finally block, which isn't necessary with a TWR.

try (BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(dotFileName))) {
 // your code here
} catch (IOException e) {
  // your handler here
}
// no need to close explicitly

The exception handler doesn't look useful either. I think you should let the IOException propagate to the caller and let the caller handle it in a more sensible way. You can just omit the catch block of your TWR to do that. The boolean return value of this method would not be needed.

core/src/main/java/org/lflang/analyses/dag/Dag.java Outdated Show resolved Hide resolved
Comment on lines 290 to 313
// This line describes an edge
// Start by removing all white spaces. Only the nodes ids and the
// arrow remain in the string.
line = line.replaceAll("\\s", "");

// Remove the label and the ';' that may appear after the edge specification
StringTokenizer st = new StringTokenizer(line, ";");
line = st.nextToken();
st = new StringTokenizer(line, "[");
line = st.nextToken();

// Use a StringTokenizer to find the source and sink nodes' ids
st = new StringTokenizer(line, "->");
int srcNodeId, sinkNodeId;

// Get the source and sink nodes ids and add the edge
try {
srcNodeId = Integer.parseInt(st.nextToken());
sinkNodeId = Integer.parseInt(st.nextToken());
this.addEdge(srcNodeId, sinkNodeId);
} catch (NumberFormatException e) {
System.out.println("Parse error in line " + line + " : Expected a number!");
Exceptions.sneakyThrow(e);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually it occurs to me that this whole int extraction logic could be replaced by using the capture groups of the matcher. Consider rewriting your pattern

"^\\s*(\\d+)\\s*->\\s*(\\d+)"

to remove useless capture groups. Notice also that we use \\s and not \s which is a string escape and not what we want. Then after matcher.find() all you need is to write

int srcNodeId = Integer.parseInt(matcher.group(1));
int sinkNodeId = Integer.parseInt(matcher.group(2));
this.addEdge(srcNodeId, sinkNodeId);

This also makes it clear that what you're giving to your Integer.parseInt is a sequence of digits so you don't need to catch a NumberFormatException, that will never occur.

@lsk567
Copy link
Collaborator Author

lsk567 commented Jun 21, 2023

Thanks for your detailed review, @oowekyala! I will work on the issues you pointed out and try to make the implementation more robust.

@lhstrh
Copy link
Member

lhstrh commented Jun 25, 2023

@ChadliaJerad it looks like several commits from master got rebased and pushed to this branch and are now duplicated. Please use git merge to update a feature branch or rebase the feature branch on top of master (not the other way around). This way, we can keep a clean history.

Looks like there is a similar problem with duplicate commits in #1695.

@lsk567 lsk567 mentioned this pull request Jul 4, 2023
13 tasks
lsk567 and others added 30 commits March 28, 2024 20:10
…instantiation by refactoring operands and check delayed instantiation at the operand level. This also simplifies optimization.
…er between instructions. Now use a view-based approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants