mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
690dbc530c
`#if canImport(...)` conditions are evaluated by the parser's primary `EvaluateIfConditionRequest`, which emits `cannot_find_module_version` and records the result in `CanImportModuleVersions`. Several later analyses re-walk the same directives and, before this change, routed through that same emitting `canImportModule` path, duplicating the diagnostic: the `ExportedSourceFile.configuredRegions` region-tree rebuild that backs diagnostic-group control (which could also recurse indefinitely), and the `VarDeclUsageChecker` inactive-code scans behind unused-variable diagnostics. Introduce a `CanImportMode` on `CompilerBuildConfiguration` distinguishing the canonical, diagnostic-emitting `.driving` query from a side-effect-free `.analyzing` re-derivation. `.analyzing` routes to the new `BridgedASTContext.testCanImport` -> `ASTContext::testImportModule` bridge, which answers from the module loaders without emitting diagnostics or populating `CanImportModuleVersions`; `.driving` keeps the existing `canImport` behavior. The mode defaults to `.analyzing`, so only the canonical site `evaluatePoundIfCondition` drives, while every secondary walk re-derives `#if` activity without repeating the diagnostic.