Drasil: Remove Chunk Overwriting Warnings
Guys, let's tackle those pesky 'chunk overwriting' warnings in Drasil! These warnings pop up when running Drasil's case studies, like Projectile, and they're kinda annoying. We are going to dive deep into the issue, understand why it's happening, and lay out a plan to resolve it. This issue is all about cleaning up those warnings to make our development process smoother.
Understanding the Problem
The main problem revolves around these 'chunk overwriting' warnings that appear when running Drasil case studies. For example, when you run the Projectile case study, you might see warnings like:
WARNING! Overwriting `instance:verifyInVals` :: ConceptInstance
WARNING! Overwriting `instance:calcValues` :: ConceptInstance
WARNING! Overwriting `instance:outputValues` :: ConceptInstance
These warnings indicate that certain chunks, like instance:verifyInVals, instance:calcValues, and instance:outputValues, are being added to the ChunkDB more than once. Specifically, these chunks are already present, and the fillReqs function attempts to add them again, causing the overwriting.
The problematic code snippet is found in Drasil/DocumentLanguage.hs:
-- https://github.com/JacquesCarette/Drasil/blob/9af23cb94ee638f3fc264e25ee73394de782d9ab/code/drasil-docLang/lib/Drasil/DocumentLanguage.hs#L177-L185
The function fillReqs is the culprit here. It's designed to handle cases where examples generate "input-values" functional requirements (FRs) by passing a non-empty "input-values" FR description to FReqsSub in the SRSDecl. You can see examples of this in the glassbr case study:
-- https://github.com/JacquesCarette/Drasil/blob/9af23cb94ee638f3fc264e25ee73394de782d9ab/code/drasil-example/glassbr/lib/Drasil/GlassBR/Body.hs#L108-L111
-- https://github.com/JacquesCarette/Drasil/blob/9af23cb94ee638f3fc264e25ee73394de782d9ab/code/drasil-docLang/lib/Drasil/DocDecl.hs#L126-L129
-- https://github.com/JacquesCarette/Drasil/blob/9af23cb94ee638f3fc264e25ee73394de782d9ab/code/drasil-docLang/lib/Drasil/Sections/Requirements.hs#L40-L44
While generating input-values FRs is a good idea in principle, the current implementation tightly couples drasil-docLang to ICO (Input, Calculation, Output) problems. This is not ideal, and we aim to decouple this in the future.
Objective: Resolving Chunk Overwrites
The main goal here is to eliminate these chunk overwriting warnings. While a more comprehensive solution for generating input-values FRs will be addressed later (as discussed in #4352), the immediate focus is on preventing these warnings from cluttering our builds. Getting rid of these warnings makes the system more robust and easier to manage.
Proposed Solution
To address this, we're proposing a straightforward solution:
- Creating "input-values" FRs Manually: For each case study, we will explicitly create the "input-values" FR. This means defining these requirements directly rather than relying on automated generation. To avoid code duplication, we can import a common FR chunk from a shared location.
- Registering the Chunks: After creating the FRs, we need to register them properly in the
ChunkDB. This ensures that the system recognizes these chunks and prevents attempts to redefine them. - Removing
fillReqsandfullReqs: The final step involves removing thefillReqsandfullReqsfunctions. Since we're manually creating and registering the input-values FRs, these functions are no longer needed and can be safely removed. This simplifies the codebase and eliminates the source of the overwriting warnings.
Step-by-Step Implementation
Let's break down the implementation into actionable steps. Each step is crucial to ensure that we resolve the chunk overwriting issue effectively.
1. Manual Creation of Input-Values FRs
Instead of relying on the automated generation of "input-values" functional requirements, we will manually create these FRs for each case study. This approach gives us more control and flexibility.
-
Identify Required Inputs: Start by identifying the necessary input values for each case study. Consider what data the system needs to function correctly. For example, in the Projectile case study, inputs might include initial velocity, launch angle, and environmental factors.
-
Define FRs: Create functional requirements that explicitly state how these input values are handled. Each FR should describe what the system does with the input and how it uses it to produce the desired output. For instance, an FR might state, "The system shall verify that the initial velocity is within acceptable limits."
-
Centralize Common FR Chunks: To avoid redundancy, create a common FR chunk that can be imported and reused across multiple case studies. This chunk can contain common input validation routines or standard input processing steps. For example, a standard input validation FR can be defined once and then imported into various case studies.
-
Example Implementation: Here’s an example of how you might define an input-values FR in a case study:
inputValuesFR :: FunctionalRequirement inputValuesFR = FRCons “inputValues” “The system shall accept and validate the following input values: …”This FR explicitly states that the system will handle input values, and you can expand on this to include specific validation criteria.
2. Registering the Chunks
Once the input-values FRs are created, they must be properly registered in the ChunkDB. This ensures that the system recognizes these chunks and prevents any attempts to redefine them.
-
Update ChunkDB: Modify the
ChunkDBto include the newly created FR chunks. This typically involves adding the FRs to the appropriate data structures within theChunkDB. -
Verify Registration: Ensure that the chunks are correctly registered by querying the
ChunkDBafter adding them. This verification step confirms that the system recognizes the new FRs and can retrieve them when needed. -
Handle Naming Conflicts: If there are any naming conflicts (i.e., chunks with the same name), resolve them by renaming the new chunks or modifying the existing ones. Consistent and unique naming is crucial for maintaining the integrity of the
ChunkDB. -
Example Implementation: Here’s how you might register the inputValuesFR in the
ChunkDB:updateChunkDB :: ChunkDB -> ChunkDB updateChunkDB db = db { frs = inputValuesFR : frs db }This code adds the
inputValuesFRto the list of functional requirements in theChunkDB.
3. Removing fillReqs and fullReqs
With the input-values FRs manually created and registered, the fillReqs and fullReqs functions are no longer necessary. Removing these functions simplifies the codebase and eliminates the source of the chunk overwriting warnings.
-
Identify Usage: Locate all instances where
fillReqsandfullReqsare used in the codebase. Use code search tools to find all references to these functions. -
Remove Functions: Delete the
fillReqsandfullReqsfunctions from the codebase. Ensure that you remove all related code, including any calls to these functions. -
Update Dependencies: Check if any other parts of the system depend on
fillReqsorfullReqs. Update these dependencies to use the new, manual approach for handling input-values FRs. -
Test Thoroughly: After removing the functions, perform thorough testing to ensure that the system still functions correctly. Pay close attention to the areas where
fillReqsandfullReqswere previously used. -
Example Implementation: To remove the functions, simply delete the function definitions and any calls to them. For example:
-- Remove the following lines from Drasil/DocumentLanguage.hs fillReqs :: ... fillReqs = ... fullReqs :: ... fullReqs = ...Ensure that you also remove any calls to these functions in other modules.
Benefits of the Solution
Implementing this solution provides several key benefits:
- Elimination of Chunk Overwriting Warnings: The primary benefit is the removal of the annoying chunk overwriting warnings. This makes the development process cleaner and easier to manage.
- Decoupling of
drasil-docLang: By manually creating and registering input-values FRs, we reduce the tight coupling betweendrasil-docLangand ICO problems. This makes the system more modular and easier to extend. - Increased Control and Flexibility: Manual creation of FRs gives us more control over how input values are handled. This allows for more specific and tailored requirements.
- Simplified Codebase: Removing
fillReqsandfullReqssimplifies the codebase, making it easier to understand and maintain.
Potential Challenges
While the proposed solution is straightforward, there are a few potential challenges to be aware of:
- Increased Manual Effort: Manually creating and registering FRs requires more effort than relying on automated generation. However, this effort is offset by the benefits of increased control and reduced coupling.
- Risk of Human Error: Manual processes are prone to human error. Ensure that FRs are created and registered correctly to avoid issues. Thorough testing can help mitigate this risk.
- Maintenance Overhead: Maintaining the manual FRs may require more effort in the long run. However, a well-organized and documented approach can minimize this overhead.
Conclusion
By following these steps, we can effectively eliminate the chunk overwriting warnings in Drasil, decouple drasil-docLang from ICO problems, and simplify the codebase. This will result in a more robust, maintainable, and developer-friendly system. Let's get to it and clean up those warnings, guys!