Commit Graph

22435 Commits

Author SHA1 Message Date
Michael Gottesman
18a6109c47 [region-isolation] Re-group diagnostics in header based on which diagnostic emitter they are used by.
It just makes it easier to reason about which diagnostics one is changing as one
is working on them.

This is NFC.
2024-08-05 16:59:06 -07:00
Holly Borla
976d92143c [Concurrency] Split up the non-Sendable property diagnostics and improve
wording.
2024-08-05 14:56:45 -07:00
Allan Shortlidge
3ef1600747 Sema: Add an access level to the fix-its for missing imports when appropriate.
When emitting fix-its for missing imports, include an access level when the
module has been imported with an access level in other source files. For now,
the suggested access level for will always be `internal`, even when uses of
members in the file would actually require `public` or `package` visibility. In
order to suggest the correct access level, name lookup will need to be
refactored to repair references to inaccessible declarations, instead of
leaving error nodes in the AST. In anticipation of that refactoring of name
lookup, missing import diagnostics are now delayed until type checking a source
file is finished so that a consistent access level can be suggested for each
import fix-it for a given module.

Partially resolves rdar://126637855.
2024-08-05 11:33:35 -07:00
Allan Shortlidge
02255d2c42 Sema: Move diagnoseMissingImportForMember() to Sema.
This will make it possible to use type checking APIs to determine the
appropriate access level for suggested imports.

NFC.
2024-08-05 11:28:26 -07:00
Allan Shortlidge
fff4bebc44 AST: Clarify SourceFile's existing missing imports record.
In anticipation of adding a new kind of missing import record to `SourceFile`,
clarify the purpose of the existing "missing imports" record with more specific
naming and documentation.
2024-08-05 11:28:26 -07:00
Holly Borla
9f0b2ec746 [Concurrency] Minor wording change to witness and override Sendable diagnostics. 2024-08-05 10:05:08 -07:00
Holly Borla
bd1653e497 [Concurrency] Split up the non-Sendable result diagnostics and improve
wording.
2024-08-05 09:56:11 -07:00
Holly Borla
933f8eb8a0 [Concurrency] Split up the non-Sendable argument diagnostics and improve
wording.

Splitting up the diagnostic into separate diagnostics based on the reference
kind is easier for me to read. The wording of the error message now puts
the problem -- crossing an isolation boundary -- at the center of the message,
and attempts to clarify how the value crosses an isolation boundary. E.g. for
the witness diagnostics, the value crosses an isolation boundary when calling
the witness through the protocol requirement in generic code.

This change does not add any additional information to the diagnostics, but it'd
be valuable to show both the source and destination isolation.
2024-08-05 08:23:30 -07:00
swift-ci
1331a3eaa7 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-05 08:14:11 -07:00
Holly Borla
b24b0883bb Merge pull request #75668 from hborla/actor-isolation-inference-source
[Concurrency] Compute the source of actor isolation in `ActorIsolationRequest`.
2024-08-05 08:01:00 -07:00
swift-ci
a391834567 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-05 00:54:31 -07:00
Konrad `ktoso` Malawski
59c3dd20b0 [Concurrency] Warning and fixig to remove unsafe from nonisolated(unsafe) func (#75663) 2024-08-05 16:45:21 +09:00
Holly Borla
5fa35b5c3e [Concurrency] Compute the source of actor isolation in ActorIsolationRequest. 2024-08-04 18:48:57 -07:00
Doug Gregor
cfd0a3fc53 Thread a source location through canImport evaluation in CompilerBuildConfiguration
Unlike all of the other build configuration checks, `canImport` has
side effects including the emission of various diagnostics. Thread a
source location through here so the diagnostics end up on the right
line.
2024-08-04 05:58:53 -07:00
Hamish Knight
a73e44a78f [Sema] Split out result builder pre-checking
Use `preCheckTarget` to pre-check the body,
allowing us to replace `PreCheckResultBuilderRequest`
with a request that only checks the brace for
ReturnStmts.
2024-08-03 16:05:09 +01:00
Hamish Knight
816f0b97e9 [Sema] NFC: Remove SuppressDiagnostics from PreCheckResultBuilderRequest
This is always `false`.
2024-08-03 16:05:08 +01:00
swift-ci
d928d906eb Merge remote-tracking branch 'origin/main' into rebranch 2024-08-02 15:16:22 -07:00
Michael Gottesman
9c4da1ffb6 Merge pull request #75597 from gottesmm/incremental-diagnostics
[region-isolation] Incremental diagnostic updates
2024-08-02 15:10:34 -07:00
Doug Gregor
ddbbb5a71e Address code review comments and build failure 2024-08-02 10:04:28 -07:00
Doug Gregor
d06e40877f Re-implement SourceFile::getIfConfigClauseRanges on top of SwiftIfConfig
The SwiftIfConfig library provides APIs for evaluating and extracting
the active #if regions in source code. Use its "configured regions" API
along with the ASTContext-backed build configuration to reimplement the
extraction of active/inactive regions from the source.

This approach has the benefit of being effectively stateless: where the
existing solution relies on the C++ parser recording all of the `#if`
clauses it sees as it is parsing (and then might have to sort them later),
this version does a scan of source to collect the list without requiring
any other state. The newer implementation is also conceptually cleaner,
and can be shared with other clients that have their own take on the
build configuration.

The primary client of this information is the SourceKit request that
identifies "inactive" regions within the source file, which IDEs can
use to grey out inactive code within the current build configuration.
There is also some profiling information that uses it. Those clients
should be unaffected by this under-the-hood change.

For the moment, I'm leaving the old code path in place for compiler
builds that don't have swift-syntax. This should be considered
temporary, and that code should be removed in favor of request'ifying
this function and removing the incrementally-built state entirely.
2024-08-02 10:04:27 -07:00
Doug Gregor
5c3b7777e7 Implement a SwiftIfConfig.BuildConfiguration that queries the ASTContext
This concrete implementation of the BuildConfiguration allows the use of
the SwiftIfConfig library's APIs where the build configuration comes from
the compiler itself.
2024-08-02 10:04:26 -07:00
swift-ci
0523626179 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-02 09:56:04 -07:00
Allan Shortlidge
f810cbb258 Merge pull request #75639 from tshortli/refactor-import-access-level-diagnostics
Sema: Refactor superfluous public import tracking
2024-08-02 09:52:41 -07:00
swift-ci
ef054444fd Merge remote-tracking branch 'origin/main' into rebranch 2024-08-02 01:03:44 -07:00
Ben Langmuir
99daf886d5 Merge pull request #75594 from benlangmuir/script-load-foundation-early
[immediate] Load Foundation early enough for bridging
2024-08-02 00:36:14 -07:00
Allan Shortlidge
53a137b78f Sema: Refactor superfluous public import tracking.
In anticipation of reusing minimum access level information for diagnostics
related to the `MemberImportVisibility` feature, refactor the way the type
checker tracks the modules which must be imported publicly. Recording minimum
access levels is no longer restricted to modules that are already imported in a
source file since `MemberImportVisibility` diagnostics will need this
information when emitting fix-its for modules that are not already imported.

Unblocks rdar://126637855.
2024-08-01 17:15:47 -07:00
Ben Langmuir
8a824d70a0 [immediate] Load Foundation early enough for bridging
Foundation needs to be loaded early in the process for Swift's runtime
to properly initialize bridging support; otherwise it may cause issues
like unrecognized selectors. When scripting, load Foundation early in
performFrontend before any swift code runs.

rdar://129528115
2024-08-01 15:02:13 -07:00
swift-ci
ced1996cda Merge remote-tracking branch 'origin/main' into rebranch 2024-07-31 16:56:30 -07:00
Steven Wu
541ee12137 Merge pull request #75598 from cachemeifyoucan/eng/PR-127205953
[DependencyScanner] Use mutex to protect all accesses to contextCacheMap
2024-07-31 16:36:29 -07:00
swift-ci
e43aad6ad0 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-31 16:34:15 -07:00
Pavel Yaskevich
ceeb6ec23f Merge pull request #75526 from gregomni/specialize
[Sema] Improve diagnoses of generic specializations
2024-07-31 16:27:11 -07:00
swift-ci
2b0b954400 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-31 14:34:32 -07:00
Holly Borla
9c941920fa Merge pull request #75578 from hborla/correct-implicit-async-diagnostic
[Concurrency] Flip the implicitly async `select` in a concurrency error.
2024-07-31 14:33:50 -07:00
Steven Wu
9967e58624 [DependencyScanner] Use mutex to protect all accesses to contextCacheMap
Rather than only protecting the insertion and non-const access to
`ContextSpecificCacheMap` in ScanningService, extend the mutex
protection to all accesses. Even a 'const' lookup in the cache map is
not thread safe because the `StringMap` could be in the process of being
rehashed.

rdar://127205953
2024-07-31 13:17:04 -07:00
Michael Gottesman
e7e035f60c [region-isolation] Convert the transfer non sendable typed error to be a new short-error, long-note form error.
I also messed with the text a little bit.

This eliminates the last of the old style diagnostics.
2024-07-31 13:10:02 -07:00
Michael Gottesman
359ae52cc3 [region-isolation] Move from old style to new style the typed error for passing never sendable types as a sending parameter. 2024-07-31 13:10:02 -07:00
Michael Gottesman
c7d24e0003 [region-isolation] Convert the typed strongly transferred value diagnostic into a short error, longer note diagnostic.
Just finishing these diagnostics.
2024-07-31 13:10:02 -07:00
Michael Gottesman
2febd26861 [region-isolation] Convert emitTypedIsolationCrossingDueToCapture error to use a new form of error.
NOTE: To make testing these easier (since they are fallback paths), I
added an option that disables named errors only for use in asserts.
2024-07-31 13:10:02 -07:00
Michael Gottesman
bfdbc760cf [region-isolation] Convert UseAfterTransfer's typed isolation transfer error to the split small error/large note format we are standardizing on.
I also cleaned up the diagnostic a little bit.
2024-07-31 13:10:02 -07:00
Michael Gottesman
4e71e3248e [region-isolation] Delete an unused old form diagnostic. 2024-07-31 13:10:01 -07:00
swift-ci
21712d92b7 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-31 10:34:44 -07:00
Holly Borla
6ef6b25a0b Merge pull request #75579 from hborla/delete-sema-sendable-checking
[Concurrency] Delete sendable checking subsumed by region isolation.
2024-07-31 10:20:16 -07:00
swift-ci
09d9972801 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-31 09:16:05 -07:00
Artem Chikin
bd4827f7a3 Merge pull request #75556 from artemcm/DisableScannerValidationNonCachingBuild
[Dependency Scanning] Disable validation of Swift dependency modules' existing pre-built candidate binary module files in the scanner, on a non-caching build.
2024-07-31 08:55:51 -07:00
Holly Borla
d40663dd66 [Concurrency] Flip the implicitly async select in a concurrency error.
This diagnostic was presenting "implicitly async" for explicitly async calls,
and vice versa, because the `select` was incorrect.
2024-07-31 06:46:07 -07:00
Holly Borla
dfea802e51 [Concurrency] Delete sendable checking subsumed by region isolation.
Sema's sendable checking is subsumed by the region isolation SIL pass. Now
that region isolation is always enabled under complete concurrency checking,
the code can be deleted from the actor isolation checker. Note that this
removes these diagnostics from targeted concurrency checking. I think it's
better to remove these diagnostics from targeted checking because in many
cases, they're false positive data-race reports that the programmer ultimately
won't have to address. If we want these diagnostics in targeted checking, we
should do it via region isolation.
2024-07-30 22:11:49 -07:00
swift-ci
71c600f3a3 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-30 20:35:15 -07:00
Greg Titus
d87e049cde Improve diagnoses of generic specializations
Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
Degrade concrete type specialization fix to warning for macros.
2024-07-30 18:51:34 -07:00
Andrew Trick
50ee84a0b4 Infer LifetimeDependenceInfo on a mutating method
We need this at least until we have 'dependsOn(self)' syntax.

When 'self' is nonescapable and the result is 'void', assume that 'self' depends
on a single nonescapable argument.
2024-07-30 15:57:57 -07:00
Andrew Trick
11640461ef Lifetime dependence: add inferrence for setters.
A nonescapable computed property should always depend on 'newValue'. We simply
infer that now. There's no way to explicitly spell the dependence.
2024-07-30 15:57:57 -07:00