Skip to content

Better handling around #if conditionals - #227

Open
JonatanWaern wants to merge 2 commits into
mainfrom
select-hashif-branch
Open

Better handling around #if conditionals#227
JonatanWaern wants to merge 2 commits into
mainfrom
select-hashif-branch

Conversation

@JonatanWaern

Copy link
Copy Markdown
Contributor
  • Refactor how we store object conds for objectdecls
  • Add logic to select between hashif branches

@JonatanWaern
JonatanWaern force-pushed the select-hashif-branch branch from 88ae3a0 to 0c8cd42 Compare June 12, 2026 09:22
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Rather speculative for now, as exact future info required to make this
choice isn't well-known

Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>

Summary: hoooolder

info: patch template saved to `-`
@JonatanWaern
JonatanWaern requested review from TSonono and a lite review from Copilot September 1, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

This PR improves handling of #if/#else conditionals during analysis by introducing expression evaluation support and using existence conditions to avoid reporting conflicts across mutually exclusive branches.

Changes:

  • Added an evaluation module to evaluate a small subset of expressions for conditional existence checks.
  • Refactored ExistCondition storage to use Arc and added helpers (exists, guaranteed_exists, guaranteed_excluded_from) to reason about conditional branches.
  • Updated object/spec symbol collection and conflict detection to consider evaluated #if conditions and avoid conflicts between #if and corresponding #else.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/analysis/templating/objects.rs Uses ExistCondition evaluation to filter specs/decls and refines conflict reporting to ignore provably exclusive branches
src/analysis/templating/mod.rs Exposes the new evaluation module
src/analysis/templating/evaluation.rs Introduces expression evaluation utilities used for #if condition resolution
src/analysis/structure/toplevel.rs Stores conditional stacks in Arc and adds existence/exclusion helpers on ExistCondition
CHANGELOG.md Documents improved conflict handling across #if/#else and built-in version-condition behavior
Suppressed comments (1)

src/analysis/structure/toplevel.rs:97

  • is_same can return true for different-length conditional stacks because zip() truncates to the shorter iterator (e.g., [A] vs [A,B] will return true). Add an explicit length equality check before the loop (or compare the full vectors) so only identical conditional stacks are treated as the same.
            (ExistCondition::Conditional(selfvec),
             ExistCondition::Conditional(othervec)) => {
                // Currently we cannt check if a condition is equivalent with another,
                // so we will only check if they are literally the same condition expression
                for ((_, cond1),
                     (_, cond2)) in selfvec.iter().zip(othervec.iter()) {
                    if cond1 != cond2 {
                        return false;
                    }
                }
                true
            },

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/analysis/templating/evaluation.rs
Comment on lines 1458 to 1465
type SavedMapping = HashMap<String,
(bool,
(bool, ExistCondition,
Vec<(Rank,
(VariableDecl, Option<Initializer>))>)>;
type SessionMapping = HashMap<String,
(bool,
(bool, ExistCondition,
Vec<(Rank,
(VariableDecl, Option<Initializer>))>)>;
Comment on lines +1543 to +1544
saveds.insert(name, (false, saved_objectdecl.cond.clone(),
vec![to_insert]));
Comment on lines +1562 to +1563
sessions.insert(name, (false, session_objectdecl.cond.clone(),
vec![to_insert]));
ObjectDecl::conditional(obj, conds),
_ => ObjectDecl::always(obj),
}
ObjectDecl::conditional(obj, conds)
#[derive(Debug, Clone)]
pub struct EvaluationResult {
pub value: Option<EvaluatedValue>,
// Wether this value is 'true constant' and can be used to resolve #if's at compile time
Some(true)
}

// These are meaningfull to evaluate already, since we have sub-expressions used for logic
// same nested hashifs
// As it turns out, collision is guaranted regardless of
// which branch they are in
// Currently we cannt check if a condition is equivalent with another,
} else {
*used = true;
// We will duplicate the variable cond here for each declaration name,
// which is inefficient but in pratice should be small
Comment thread CHANGELOG.md
- Fix issue where the server would internally format URIs incorrectly in some cases
- The language server logs will now be in local time of whatever machine they are running on, rather than UTC.
- The DLS will now properly not report conflicts between statements in a `#if` and its corresponding `#else` branch
- The DLS will now consider all `#if` branches on conditions directly based on `dml\_1\_2` and `dml\_1\_4` dead or alive appropriately
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.

2 participants